⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toyfdtd1 c source code listing.htm

📁 toyFDTD GNU
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- saved from url=(0054)http://www.borg.umn.edu/toyfdtd/ToyFDTD1_C_Source.html --><HTML><HEAD><TITLE>ToyFDTD1 C source code listing</TITLE><META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><META content="MSHTML 5.50.4522.1800" name=GENERATOR><META content="Laurie E. Miller" name=Author><META content="FDTD, ToyFDTD, computational electromagnetics, time domain, simulation, open source, volume visualization, source code, C" name=Keywords><META content="Source code in C for ToyFDTD1, the first in the ToyFDTD series of codes.  The original If-I-Can-Do-It-You-Can-Do-It FDTD!" name=Description><META content="Mozilla/4.51C-SGI [en] (X11; U; IRIX64 6.5-ALPHA-1285894620 IP27) [Netscape]" name=GENERATOR></HEAD><BODY background="ToyFDTD1 C source code listing.files/JD_border.jpg" SGI_SRC="/hosts/congo.borg.umn.edu/usr/local/www/toyfdtd/JD_border.jpeg" nosave><MAP name=CemTach_logo_map-4><AREA shape=RECT coords=910,75,977,95   href="http://www.cemtach.org/sponsors.html"><AREA shape=RECT   coords=853,75,903,95 href="http://www.cemtach.org/people.html"><AREA   shape=RECT coords=766,75,845,94   href="http://www.cemtach.org/references/references.html"><AREA shape=RECT   coords=722,76,760,94 href="http://www.cemtach.org/faq.html"><AREA shape=RECT   coords=647,75,715,94   href="http://www.cemtach.org/software/software.html"><AREA shape=RECT   coords=552,75,640,95   href="http://www.cemtach.org/simulations/simulations.html"><AREA shape=RECT   coords=497,75,544,94 href="http://www.cemtach.org/index.html"></MAP><P><A href="http://www.borg.umn.edu/toyfdtd/CemTach_logo_map-4.map"><IMG height=104 alt="CEM TACH image map" isMap src="ToyFDTD1 C source code listing.files/CemTach_logo_map.gif" width=980 useMap=#CemTach_logo_map-4 border=0 SGI_SRC="/hosts/congo.borg.umn.edu/usr/local/www/toyfdtd/CemTach_logo_map.gif" NOSAVE></A> <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <P><IMG height=136 src="ToyFDTD1 C source code listing.files/Toy_FDTD_logo.gif" width=979 SGI_SRC="/hosts/congo.borg.umn.edu/usr/local/www/toyfdtd/logos/Toy_FDTD_logo.gif" NOSAVE> <BR>&nbsp; <BR>&nbsp; <BR>&nbsp; <TABLE cellSpacing=0 cols=2 cellPadding=0 width=900 border=0 NOSAVE>  <TBODY>  <TR NOSAVE>    <TD width=170 NOSAVE></TD>    <TD NOSAVE>      <CENTER>      <TABLE cellSpacing=5 cellPadding=8 border=3>        <TBODY>        <TR>          <TD><B><FONT face=Arial,Helvetica><FONT size=+2>ToyFDTD1 C Source             Code Listing</FONT></FONT></B></TD></TR></TBODY></TABLE></CENTER></TD></TR>  <TR>    <TD></TD>    <TD>      <CENTER><FONT face=Arial,Helvetica>(Note: I'm almost but not quite sure       the code pasted into this page flawlessly.</FONT> <BR><FONT       face=Arial,Helvetica>So if you are going to run the code, download the tar       file from the link on the main ToyFDTD page.)</FONT>       <P><B><FONT face=Arial,Helvetica><FONT size=+2><A       href="http://www.borg.umn.edu/toyfdtd/ToyFDTD.html">ToyFDTD       Home</A></FONT></FONT></B>       <P><B><FONT face=Arial,Helvetica><FONT size=+1><A       href="http://www.borg.umn.edu/toyfdtd/ToyFDTD1.html">back to ToyFDTD1 main       page</A></FONT></FONT></B> <BR><B><FONT face=Arial,Helvetica><FONT       size=+1><A       href="mailto:lemiller@borg.umn.edu">lemiller@borg.umn.edu</A></FONT></FONT></B></CENTER></P></TD></TR>  <TR>    <TD></TD>    <TD><BR>&nbsp; <PRE><FONT face=Arial,Helvetica><FONT size=+2><FONT color=#000000>// ToyFDTD1, version 1.03&nbsp;</FONT>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The if-I-can-do-it-you-can-do-it FDTD!&nbsp;// Copyright (C) 1998,1999 Laurie E. Miller, Paul Hayes, Matthew O'Keefe&nbsp;// This program is free software; you can redistribute it and/or&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; modify it under the terms of the GNU General Public License&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; as published by the Free Software Foundation; either version 2//&nbsp;&nbsp;&nbsp;&nbsp; of the License, or any later version, with the following conditions//&nbsp;&nbsp;&nbsp;&nbsp; attached in addition to any and all conditions of the GNU//&nbsp;&nbsp;&nbsp;&nbsp; General Public License://&nbsp;&nbsp;&nbsp;&nbsp; When reporting or displaying any results or animations created//&nbsp;&nbsp;&nbsp;&nbsp; using this code or modification of this code, make the appropriate//&nbsp;&nbsp;&nbsp;&nbsp; citation referencing ToyFDTD1 by name and including the version//&nbsp;&nbsp;&nbsp;&nbsp; number.&nbsp;&nbsp;//// This program is distributed in the hope that it will be useful,//&nbsp;&nbsp;&nbsp;&nbsp; but WITHOUT ANY WARRANTY; without even the implied warranty&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.//&nbsp;&nbsp;&nbsp;&nbsp; See the GNU General Public License for more details.//// You should have received a copy of the GNU General Public License//&nbsp;&nbsp;&nbsp;&nbsp; along with this program; if not, write to the Free Software//&nbsp;&nbsp;&nbsp;&nbsp; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; 02111-1307&nbsp; USA// Contacting the authors://// Laurie E. Miller, Paul Hayes, Matthew O'Keefe// Department of Electrical and Computer Engineering//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 200 Union Street S. E.//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Minneapolis, MN 55455//// lemiller@borg.umn.edu//&nbsp;// http://www.borg.umn.edu/toyfdtd/// http://www.borg.umn.edu/toyfdtd/ToyFDTD1.html// http://www.toyfdtd.org/// This code is here for everyone, but not everyone will need something&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; so simple, and not everyone will need to read all the comments.&nbsp;&nbsp;// This file is over 700 lines long, but less than 400 of that is actually//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; code.&nbsp;// This ToyFDTD1 is a stripped-down, minimalist 3D FDTD code.&nbsp; It&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; illustrates the minimum factors that must be considered to&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; create a simple FDTD simulation.///////////////////////////////////////////////////////////////////////////////// Changes to version 1.02 from version 1.03: updating contact &amp; web info.//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For further notes on the revision history, see the changelog file.///////////////////////////////////////////////////////////////////////////////// This is a very simple Yee algorithm 3D FDTD code in C implementing//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the free space form of Maxwell's equations on a Cartesian grid.// There are no internal materials or geometry.&nbsp;&nbsp;// The code as delivered simulates an idealized rectangular waveguide&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; by treating the interior of the mesh as free space/air and enforcing//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PEC (Perfect Electric Conductor) conditions on the faces of the mesh.// The problem is taken from Field and Wave Electromagnetics, 2nd ed., by&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; David K. Cheng, pages 554-555.&nbsp; It is a WG-16 waveguide&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; useful for X-band applications, interior width = 2.29cm,&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; interior height = 1.02cm.&nbsp; The frequency (10 GHz) is chosen to be&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in the middle of the frequency range for TE10 operation.&nbsp;&nbsp;// Boundaries: PEC (Perfect Electric Conductor).// Stimulus: A simplified sinusoidal plane wave emanates from x = 0 face.// 3D output: The electric field intensity vector components in the direction&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; of the height of the guide (ez) are output to file every&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PLOT_MODULUS timesteps (and for the last timestep), scaled to&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the range of integers from zero through 254.&nbsp; (The colormap&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; included in the tar file assigns rgb values to the range zero through//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 255.)&nbsp;&nbsp; Scaling is performed on each timestep individually, since&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; it is not known in advance what the maximum and minimum&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; values will be for the entire simulation.&nbsp; The integer value 127 is&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; held to be equal to the data zero for every timestep.&nbsp; This method&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; of autoscaling every timestep can be very helpful in a simulation&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where the intensities are sometimes strong and sometimes faint,&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; since it will highlight the presence and structure of faint signals&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when stronger signals have left the mesh.&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Each timestep has it's own output file.&nbsp; This data output file format//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; can be used in several visualization tools, such as animabob and viz.&nbsp;// Other output: Notes on the progress of the simulation are written to standard//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output as the program runs.&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A .viz file is output to feed parameters to viz, should viz later be//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; used to view the data files.// Some terminology used here://// This code implements a Cartesian mesh with space differentials&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; of dx, dy, dz.// This means that a point in the mesh has neighboring points dx meters&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; away in the direction of the positive and negative x-axis,//&nbsp;&nbsp;&nbsp;&nbsp; and neighboring points dy meters away in the directions&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; of the +- y-axis, and neighboring points dz meters away&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; in the directions of the +- z-axis,// The mesh has nx cells in the x direction, ny in the y direction,&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; and nz in the z direction.// ex, ey, and ez refer to the arrays of electric field intensity vectors&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; -- for example, ex is a 3-dimensional array consisting of the&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; x component of the E field intensity vector for every point in the&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; mesh.&nbsp; ex[i][j][k] refers to the x component of the E field intensity&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; vector at point [i][j][k].&nbsp;&nbsp;// hx, hy, and hz refer to the arrays of magnetic field intensity vectors.//// dt is the time differential -- the length of each timestep in seconds.//// bob is a file format that stands for "brick of bytes", meaning a string&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; of bytes that can be interpreted as a 3-dimensional array of byte&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; values (integers from zero through 255).&nbsp; animabob is a free&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; visualization tool that displays and animates a sequence of bricks&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; of bytes.&nbsp; For more information on animabob or to download a copy,&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; see the ToyFDTD website at http://www.borg.umn.edu/toyfdtd///// viz is another free visualization tool that displays and animates&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; brick-of-byte files. For more information on viz or to download a copy,&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp; see the ToyFDTD website at http://www.borg.umn.edu/toyfdtd/#include &lt;math.h&gt;&nbsp;#include &lt;stdio.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#include &lt;float.h&gt;// program control constants

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -