http://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&action=history&feed=atomMeep C-plus-plus Tutorial - Revision history2024-03-28T14:36:23ZRevision history for this page on the wikiMediaWiki 1.7.3http://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=4934&oldid=prevArdavan at 15:05, 18 April 20172017-04-18T15:05:35Z<p></p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 15:05, 18 April 2017</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 1:</strong></td>
<td colspan="2" align="left"><strong>Line 1:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">{{Meep}}</td><td> </td><td style="background: #eee; font-size: smaller;">{{Meep}}</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Instead of using the libctl/Scheme interface described in the [[Meep tutorial]], <span style="color: red; font-weight: bold;">one can also access </span>Meep as a C++ library by writing a C++ program that links to it. The C++ interface provides the greatest level of flexibility in <span style="color: red; font-weight: bold;">designing </span>FDTD simulations.</td><td>+</td><td style="background: #cfc; font-size: smaller;">Instead of using the libctl/Scheme interface described in the [[Meep tutorial]], Meep <span style="color: red; font-weight: bold;">is also callable </span>as a C++ library by writing a C++ program that links to it. The C++ interface provides the greatest level of flexibility in <span style="color: red; font-weight: bold;">setting up </span>FDTD simulations. <span style="color: red; font-weight: bold;"> There are 19 examples </span>of <span style="color: red; font-weight: bold;">such C++ </span>programs in <span style="color: red; font-weight: bold;">the </span><code>tests/</code> directory <span style="color: red; font-weight: bold;">of the Meep codebase which cover a wide range of Meep's functionality. These </span>are <span style="color: red; font-weight: bold;">a good reference</span>. <span style="color: red; font-weight: bold;"> Finally, we </span>should also note that, while Meep is nominally in C++, it is perhaps better described as "C+". That is, most of the coding style is C-like with a few C++ features.</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"><span style="color: red; font-weight: bold;">(This is, in fact, the original way in which we used Meep, and the way in which all </span>of <span style="color: red; font-weight: bold;">the Meep test </span>programs<span style="color: red; font-weight: bold;">, </span>in <span style="color: red; font-weight: bold;">its </span><code>tests/</code> directory<span style="color: red; font-weight: bold;">, </span>are <span style="color: red; font-weight: bold;">written</span>.<span style="color: red; font-weight: bold;">)</span></td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"><span style="color: red; font-weight: bold;">We </span>should also note that, while Meep is nominally in C++, it is perhaps better described as "C+". That is, most of the coding style is C-like with a few C++ features.</td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">== Differences from libctl ==</td><td> </td><td style="background: #eee; font-size: smaller;">== Differences from libctl ==</td></tr>
<tr><td colspan="2" align="left"><strong>Line 158:</strong></td>
<td colspan="2" align="left"><strong>Line 154:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">== Compiling ==</td><td> </td><td style="background: #eee; font-size: smaller;">== Compiling ==</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">In order to compile your code and link against the Meep library, you must link in several additional libraries that Meep requires. There are <span style="color: red; font-weight: bold;">two </span>ways to do this:</td><td>+</td><td style="background: #cfc; font-size: smaller;">In order to compile your code and link against the Meep library, you must link in several additional libraries that Meep requires. There are <span style="color: red; font-weight: bold;">three possible </span>ways to do this:</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">1. After compiling the <span style="color: red; font-weight: bold;">MEEP </span>package following the instructions elsewhere in this wiki, place myfile.cpp (where myfile.cpp is a MEEP C++ file of your choosing) in the tests/ subdirectory, cd to the same directory, and <span style="color: red; font-weight: bold;">type</span>:</td><td>+</td><td style="background: #cfc; font-size: smaller;">1. After compiling the <span style="color: red; font-weight: bold;">Meep </span>package following the instructions elsewhere in this wiki, place myfile.cpp (where myfile.cpp is a MEEP C++ file of your choosing) in the <span style="color: red; font-weight: bold;"><code></span>tests/<span style="color: red; font-weight: bold;"></code> </span>subdirectory, cd to the same directory, and <span style="color: red; font-weight: bold;">invoke</span>:</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> make myfile.dac</td><td> </td><td style="background: #eee; font-size: smaller;"> make myfile.dac</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"><span style="color: red; font-weight: bold;">The </span>resulting executable <span style="color: red; font-weight: bold;">may be invoked from the tests/ directory </span>via:</td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;">Run the </span>resulting executable via:</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> ./myfile.dac</td><td> </td><td style="background: #eee; font-size: smaller;"> ./myfile.dac</td></tr>
</table>
Ardavanhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=4719&oldid=prevArdavan at 06:22, 22 November 20132013-11-22T06:22:01Z<p></p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 06:22, 22 November 2013</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 155:</strong></td>
<td colspan="2" align="left"><strong>Line 155:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">[[Image:Fabryperot.gif|center|Resonant mode of fabry-perot cavity]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Image:Fabryperot.gif|center|Resonant mode of fabry-perot cavity]]</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">== Calculating the flux through a close packed opal monolayer ==</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">In this example, we will look at a system that is a bit more computationally expensive: a 3D structure consisting of a close packed monolayer of silica opal spheres on a silicon substrate in an environment of air. We want to determine what the transmission spectrum is for such a structure over the visible frequency range between 400nm to 900nm normally incident on the monolayer. Our structure will include silica opal spheres having a diameter of 850nm. As usual, we begin with the header information for a MEEP control file: </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> #include "meep.hpp"</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> using namespace meep;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">The 3D unit cell is a rectangular box consisting of the opal monolayer in the middle surrounded by air and silicon. In the middle of the unit cell where the rectangular XY plane bisects the monolayer of opal spheres, 3 spheres touch along the main diagonal giving rise to the formula <math>2 / \sqrt{3}r=a</math>. We arbitrarily choose a lattice constant of one in the y-direction, and so our normalized radius is: </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> const double rad = 1/(2*sqrt(3));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">This means that our computational cell is 2r units in size in the X direction. This simulation will make use of a planar gaussian excitation, for which the amplitude of the field is specfieid at each position in the plane via a function which in our case will be constant everywhere in the plane:</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> complex<double> one(const vec &p) {</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 1.0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> }</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">When computing transmission through a given structure, we always need to normalize by the transmission through an empty structure. As a result, the empty dielectric function is:</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double empty(const vec &p) {</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 1.0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> }</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Now we need to define the dielectric function for our structure involving the monolayer of silica opal spheres. We break up the structure into three main regions, the top of the structure includes just air, the monolayer in the middle, and the glass substrate beneath.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double monolayer(const vec &p) {</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> const grid_volume v = vol3d(0.6,1.0,6.0,100);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> vec xx = p - v.center();</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">We fist check to see whether the Z location of the position vector is beyond the height of the spheres and return air if it is:</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> if (xx.z() > rad+1e-06) </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 1.0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Otherwise, we check to see whether we are below the monolayer and return glass:</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> else if (xx.z() < -rad-1e-06)</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 2.25;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Having eliminated the previous two cases, we thus determine that the position vector <code>p</code> is located somewhere within the monolayer of silica opal spheres. Prior to checking to see whether the position vector is located within one of the spheres of the unit cell, we first translate the position vector into the 2D unit cell, centered at the monolayer: </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">[[Image:Closepack.png|right|thumb|100px|Dielectric function, for close packed silica opal spheres]]</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> while (xx.x() > 0.3) xx -= vec(0.6,0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> while (xx.y() > 0.5) xx -= vec(0,1.0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> while (xx.x() < -0.3) xx += vec(0.6,0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> while (xx.y() < -0.5) xx += vec(0,1.0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">The basis vectors for the close packed monolayer are (r,r<math>\sqrt{3}</math>) and (2r,0). Starting from the center of the cell, we shift by several linear combination of the lattice vectors and check to see whether the current position is located within a circle centered at these locations. If it is, we return the dielectric of silica and if after having looped through all the lattice locations we have not found a match, we return air. </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> vec b1(0.3,0.52,0), b2(0.6,0,0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> for (int j=-1; j<=1; ++j)</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> for (int k=-1; k<=1; ++k) </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> if (sqrt((xx-b1*j-b2*k)&(xx-b1*j-b2*k)) < rad+1e-06)</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 2.25;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 1.0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> }</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">The 2D cross-section of the middle of the 3D unit cell, showing the close packed opal spheres can be seen in the image.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Having defined the dielectric functions, we are ready to create the computational cell, establish the volume sources, time step the fields and compute the transmission spectrum.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> void excitefilm(double a, component c) {</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> grid_volume v = vol3d(0.6,1.0,6.0,a);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">We create two separate structures and fields to include the empty structure and one including the opal monolayer.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> structure s0(v,empty,pml(0.5,Z));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> structure s(v,monolayer,pml(0.5,Z));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> fields f0(&s0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> fields f(&s);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> f0.use_bloch(vec(0,0,0));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> f.use_bloch(vec(0,0,0));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Remembering that Meep uses [[Meep Introduction Units in Meep| normalized units of frequency]], the frequencies corresponding to 400nm and 900nm wavelengths are: </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double freq_min = 0.34, freq_max = 2.125;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> int nfreq = 500;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> gaussian_src_time src((freq_min+freq_max)*0.5, 0.5/(freq_max-freq_min), 0, 5/(freq_max-freq_min));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">The source plane and flux plane are positioned at the top and bottom of the computational cell respectively.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> volume src_plane(vec(0,0,5.0),vec(0.6,1.0,5.0));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> volume flux_plane(vec(0,0,1.0),vec(0.6,1.0,1.0));</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> f0.add_volume_source(c,src,src_plane,one,1.0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> f.add_volume_source(c,src,src_plane,one,1.0);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("volume sources added...\n");</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> dft_flux ft0 = f0.add_dft_flux_plane(flux_plane,freq_min,freq_max,nfreq);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> dft_flux ft = f.add_dft_flux_plane(flux_plane,freq_min,freq_max,nfreq);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("simulating empty structure...\n");</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> while (f0.time() < nfreq / (freq_max-freq_min) / 2) f0.step();</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> ft -= ft0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("simulating silica opal monolayer...\n");</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> while (f.time() < nfreq / (freq_max-freq_min) / 2) f.step();</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double *flux = ft.flux();</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double *flux0 = ft0.flux();</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Finally, we normalize the flux and output the transmission spectrum.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double *T;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> T = new double[nfreq];</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> for (int i=0; i<nfreq; ++i)</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> T[i] = flux[i] / flux0[i];</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double dfreq = (freq_max-freq_min) / (nfreq-1);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("tranmission:, freq, T[i]\n");</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> for (int i=0; i<nfreq; ++i)</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("transmission:, %f, %f\n",freq_min+i*dfreq,T[i]);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> delete [] flux;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> delete [] flux0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> } </td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">The main part of the program then calls the <code>excitefilm</code> procedure with a resolution of 40 pixels per a to compute the transmission flux.</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"></td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> int main(int argc, char **argv) {</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> initialize mpi(argc, argv);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("beginning silica opal transmission tests...\n");</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> excitefilm(40, Ey);</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> master_printf("finished.\n");</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> return 0;</td><td colspan="2"> </td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> }</td><td colspan="2"> </td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">== Compiling ==</td><td> </td><td style="background: #eee; font-size: smaller;">== Compiling ==</td></tr>
</table>
Ardavanhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=3674&oldid=prevStevenj: volume -> grid_volume etc2009-08-21T05:19:24Z<p>volume -> grid_volume etc</p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 05:19, 21 August 2009</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 10:</strong></td>
<td colspan="2" align="left"><strong>Line 10:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">The C++ interface has several differences from the libctl interface besides the obvious difference in syntax.</td><td> </td><td style="background: #eee; font-size: smaller;">The C++ interface has several differences from the libctl interface besides the obvious difference in syntax.</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">The most notable difference is that, while the libctl interface puts the origin <math>(0,0,0)</math> at the ''center'' of the computational cell, the C++ interface by default puts the origin at the ''corner'' of the computational cell. That is, an <math>L\times L\times L</math> cell goes from <math>(-L/2,-L/2,-L/2)</math> to <math>(L/2,L/2,L/2)</math> in libctl, but from <math>(0,0,0)</math> to <math>(L,L,L)</math> in C++. (You can change this by calling <code><nowiki><span style="color: red; font-weight: bold;">volume</span>::shift_origin</nowiki></code>.)</td><td>+</td><td style="background: #cfc; font-size: smaller;">The most notable difference is that, while the libctl interface puts the origin <math>(0,0,0)</math> at the ''center'' of the computational cell, the C++ interface by default puts the origin at the ''corner'' of the computational cell. That is, an <math>L\times L\times L</math> cell goes from <math>(-L/2,-L/2,-L/2)</math> to <math>(L/2,L/2,L/2)</math> in libctl, but from <math>(0,0,0)</math> to <math>(L,L,L)</math> in C++. (You can change this by calling <code><nowiki><span style="color: red; font-weight: bold;">grid_volume</span>::shift_origin</nowiki></code>.)</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">== Overview ==</td><td> </td><td style="background: #eee; font-size: smaller;">== Overview ==</td></tr>
<tr><td colspan="2" align="left"><strong>Line 21:</strong></td>
<td colspan="2" align="left"><strong>Line 21:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">to include the definitions of the Meep routines. Later, when you compile (see below), you must also link to the Meep libraries.</td><td> </td><td style="background: #eee; font-size: smaller;">to include the definitions of the Meep routines. Later, when you compile (see below), you must also link to the Meep libraries.</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Your main program should then initialize Meep, and will generally then define a computational <code><span style="color: red; font-weight: bold;">volume</span></code> and the associated <code>structure</code> (describing the geometry and materials), initialize the <code>fields</code>, add sources, and then time-step. In short:</td><td>+</td><td style="background: #cfc; font-size: smaller;">Your main program should then initialize Meep, and will generally then define a computational <code><span style="color: red; font-weight: bold;">grid_volume</span></code> and the associated <code>structure</code> (describing the geometry and materials), initialize the <code>fields</code>, add sources, and then time-step. In short:</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> int main(int argc, char **argv) {</td><td> </td><td style="background: #eee; font-size: smaller;"> int main(int argc, char **argv) {</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> initialize mpi(argc, argv); // do this even for non-MPI Meep</td><td> </td><td style="background: #eee; font-size: smaller;"> initialize mpi(argc, argv); // do this even for non-MPI Meep</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> double resolution = 20; // pixels per distance</td><td> </td><td style="background: #eee; font-size: smaller;"> double resolution = 20; // pixels per distance</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> <span style="color: red; font-weight: bold;">volume </span>v = vol2d(5,10, resolution); // 5x10 2d cell</td><td>+</td><td style="background: #cfc; font-size: smaller;"> <span style="color: red; font-weight: bold;">grid_volume </span>v = vol2d(5,10, resolution); // 5x10 2d cell</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> structure s(v, eps, pml(1.0));</td><td> </td><td style="background: #eee; font-size: smaller;"> structure s(v, eps, pml(1.0));</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> fields f(&s);</td><td> </td><td style="background: #eee; font-size: smaller;"> fields f(&s);</td></tr>
<tr><td colspan="2" align="left"><strong>Line 97:</strong></td>
<td colspan="2" align="left"><strong>Line 97:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> initialize mpi(argc,argv);</td><td> </td><td style="background: #eee; font-size: smaller;"> initialize mpi(argc,argv);</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> const double amicron = 10.0;</td><td> </td><td style="background: #eee; font-size: smaller;"> const double amicron = 10.0;</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> const <span style="color: red; font-weight: bold;">volume </span>vol = vol1d(2*z_center,amicron);</td><td>+</td><td style="background: #cfc; font-size: smaller;"> const <span style="color: red; font-weight: bold;">grid_volume </span>vol = vol1d(2*z_center,amicron);</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> structure s(vol,eps,pml(pml_thickness));</td><td> </td><td style="background: #eee; font-size: smaller;"> structure s(vol,eps,pml(pml_thickness));</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> fields f(&s);</td><td> </td><td style="background: #eee; font-size: smaller;"> fields f(&s);</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">Note the constructor for the <span style="color: red; font-weight: bold;">volume </span>class in 1D which takes as parameters the size of the cell and the resolution. The sources in Meep are excitations of the polarization vector in <math>\mathbf{D}=\epsilon\mathbf{E}+\mathbf{P}</math>. The polarization can be any one of the six cartesian or cylindrical fields. There are a variety of sources including dipole and current sources, gaussian pulses and a continuous wave sources. For now, we use a gaussian source centered at the midgap frequency with a narrow width, along with the start time and end time of the source.</td><td>+</td><td style="background: #cfc; font-size: smaller;">Note the constructor for the <span style="color: red; font-weight: bold;"><code>grid_volume</code> </span>class in 1D which takes as parameters the size of the cell and the resolution. The sources in Meep are excitations of the polarization vector in <math>\mathbf{D}=\epsilon\mathbf{E}+\mathbf{P}</math>. The polarization can be any one of the six cartesian or cylindrical fields. There are a variety of sources including dipole and current sources, gaussian pulses and a continuous wave sources. For now, we use a gaussian source centered at the midgap frequency with a narrow width, along with the start time and end time of the source.</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> const double w_midgap = (sqrt(eps1)+sqrt(eps2))/(4*sqrt(eps1)*sqrt(eps2));</td><td> </td><td style="background: #eee; font-size: smaller;"> const double w_midgap = (sqrt(eps1)+sqrt(eps2))/(4*sqrt(eps1)*sqrt(eps2));</td></tr>
<tr><td colspan="2" align="left"><strong>Line 182:</strong></td>
<td colspan="2" align="left"><strong>Line 182:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> double monolayer(const vec &p) {</td><td> </td><td style="background: #eee; font-size: smaller;"> double monolayer(const vec &p) {</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> const <span style="color: red; font-weight: bold;">volume </span>v = vol3d(0.6,1.0,6.0,100);</td><td>+</td><td style="background: #cfc; font-size: smaller;"> const <span style="color: red; font-weight: bold;">grid_volume </span>v = vol3d(0.6,1.0,6.0,100);</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> vec xx = p - v.center();</td><td> </td><td style="background: #eee; font-size: smaller;"> vec xx = p - v.center();</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td colspan="2" align="left"><strong>Line 219:</strong></td>
<td colspan="2" align="left"><strong>Line 219:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> void excitefilm(double a, component c) {</td><td> </td><td style="background: #eee; font-size: smaller;"> void excitefilm(double a, component c) {</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> <span style="color: red; font-weight: bold;">volume </span>v = vol3d(0.6,1.0,6.0,a);</td><td>+</td><td style="background: #cfc; font-size: smaller;"> <span style="color: red; font-weight: bold;">grid_volume </span>v = vol3d(0.6,1.0,6.0,a);</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">We create two separate structures and fields to include the empty structure and one including the opal monolayer.</td><td> </td><td style="background: #eee; font-size: smaller;">We create two separate structures and fields to include the empty structure and one including the opal monolayer.</td></tr>
<tr><td colspan="2" align="left"><strong>Line 238:</strong></td>
<td colspan="2" align="left"><strong>Line 238:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">The source plane and flux plane are positioned at the top and bottom of the computational cell respectively.</td><td> </td><td style="background: #eee; font-size: smaller;">The source plane and flux plane are positioned at the top and bottom of the computational cell respectively.</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> <span style="color: red; font-weight: bold;">geometric_volume </span>src_plane(vec(0,0,5.0),vec(0.6,1.0,5.0));</td><td>+</td><td style="background: #cfc; font-size: smaller;"> <span style="color: red; font-weight: bold;">volume </span>src_plane(vec(0,0,5.0),vec(0.6,1.0,5.0));</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> <span style="color: red; font-weight: bold;">geometric_volume </span>flux_plane(vec(0,0,1.0),vec(0.6,1.0,1.0));</td><td>+</td><td style="background: #cfc; font-size: smaller;"> <span style="color: red; font-weight: bold;">volume </span>flux_plane(vec(0,0,1.0),vec(0.6,1.0,1.0));</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> f0.add_volume_source(c,src,src_plane,one,1.0);</td><td> </td><td style="background: #eee; font-size: smaller;"> f0.add_volume_source(c,src,src_plane,one,1.0);</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> f.add_volume_source(c,src,src_plane,one,1.0);</td><td> </td><td style="background: #eee; font-size: smaller;"> f.add_volume_source(c,src,src_plane,one,1.0);</td></tr>
</table>
Stevenjhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=3664&oldid=prevArdavan at 15:58, 7 August 20092009-08-07T15:58:26Z<p></p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 15:58, 7 August 2009</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 294:</strong></td>
<td colspan="2" align="left"><strong>Line 294:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">(Naturally, replace <code>g++</code> with the name of your C++ compiler if you are not using the GNU compilers.)</td><td> </td><td style="background: #eee; font-size: smaller;">(Naturally, replace <code>g++</code> with the name of your C++ compiler if you are not using the GNU compilers.)</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;">3. Compile with g++, this time invoking each library separately:</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"> g++ -malign-double foo.cpp -o foo -lmeep -lhdf5 -lz -lgsl -lharminv -llapack -lcblas -latlas -lfftw3 -lm</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep]]</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep examples]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep examples]]</td></tr>
</table>
Ardavanhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=3258&oldid=prevBermel: /* Compiling */2008-09-19T19:19:26Z<p><span class="autocomment">Compiling</span></p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 19:19, 19 September 2008</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 282:</strong></td>
<td colspan="2" align="left"><strong>Line 282:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">1. After compiling the MEEP package following the instructions elsewhere in this wiki, place myfile.cpp (where myfile.cpp is a MEEP C++ file of your choosing) in the tests/ subdirectory, cd to the same directory, and type:</td><td> </td><td style="background: #eee; font-size: smaller;">1. After compiling the MEEP package following the instructions elsewhere in this wiki, place myfile.cpp (where myfile.cpp is a MEEP C++ file of your choosing) in the tests/ subdirectory, cd to the same directory, and type:</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">make myfile.dac</td><td>+</td><td style="background: #cfc; font-size: smaller;"> </td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;"> </span>make myfile.dac</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"> </td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">The resulting executable may be invoked from the tests/ directory via:</td><td> </td><td style="background: #eee; font-size: smaller;">The resulting executable may be invoked from the tests/ directory via:</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">./myfile.dac</td><td>+</td><td style="background: #cfc; font-size: smaller;"> </td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;"> </span>./myfile.dac</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">2. Use the [[w:pkg-config]] program, which is installed by default on most GNU/Linux systems. Then, to compile a file <code>foo.cpp</code> using Meep, do:</td><td> </td><td style="background: #eee; font-size: smaller;">2. Use the [[w:pkg-config]] program, which is installed by default on most GNU/Linux systems. Then, to compile a file <code>foo.cpp</code> using Meep, do:</td></tr>
</table>
Bermelhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=3257&oldid=prevBermel: added second compilation method for cpp files2008-09-19T19:18:27Z<p>added second compilation method for cpp files</p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 19:18, 19 September 2008</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 279:</strong></td>
<td colspan="2" align="left"><strong>Line 279:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">== Compiling ==</td><td> </td><td style="background: #eee; font-size: smaller;">== Compiling ==</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;">In order to compile your code and link against the Meep library, you must link in several additional libraries that Meep requires. <span style="color: red; font-weight: bold;">The best way </span>to do this is to <span style="color: red; font-weight: bold;">use </span>the [[w:pkg-config]] program, which is installed by default on most GNU/Linux systems. Then, to compile a file <code>foo.cpp</code> using Meep, do:</td><td>+</td><td style="background: #cfc; font-size: smaller;">In order to compile your code and link against the Meep library, you must link in several additional libraries that Meep requires. <span style="color: red; font-weight: bold;">There are two ways </span>to do this<span style="color: red; font-weight: bold;">:</span></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"> </td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;">1. After compiling the MEEP package following the instructions elsewhere in this wiki, place myfile.cpp (where myfile.cpp </span>is <span style="color: red; font-weight: bold;">a MEEP C++ file of your choosing) in the tests/ subdirectory, cd </span>to <span style="color: red; font-weight: bold;">the same directory, and type:</span></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;">make myfile.dac</span></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;">The resulting executable may be invoked from the tests/ directory via:</span></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;">./myfile.dac</span></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"> </td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"><span style="color: red; font-weight: bold;">2. Use </span>the [[w:pkg-config]] program, which is installed by default on most GNU/Linux systems. Then, to compile a file <code>foo.cpp</code> using Meep, do:</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> g++ `pkg-config --cflags meep` foo.cpp -o foo `pkg-config --libs meep`</td><td> </td><td style="background: #eee; font-size: smaller;"> g++ `pkg-config --cflags meep` foo.cpp -o foo `pkg-config --libs meep`</td></tr>
</table>
Bermelhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=1993&oldid=prevStevenj: /* Calculating the flux through a close packed opal monolayer */ fix fence-post error2007-03-10T01:53:12Z<p><span class="autocomment">Calculating the flux through a close packed opal monolayer -</span> fix fence-post error</p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 01:53, 10 March 2007</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 259:</strong></td>
<td colspan="2" align="left"><strong>Line 259:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> for (int i=0; i<nfreq; ++i)</td><td> </td><td style="background: #eee; font-size: smaller;"> for (int i=0; i<nfreq; ++i)</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> T[i] = flux[i] / flux0[i];</td><td> </td><td style="background: #eee; font-size: smaller;"> T[i] = flux[i] / flux0[i];</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> double dfreq = (freq_max-freq_min) / nfreq;</td><td>+</td><td style="background: #cfc; font-size: smaller;"> double dfreq = (freq_max-freq_min) / <span style="color: red; font-weight: bold;">(</span>nfreq<span style="color: red; font-weight: bold;">-1)</span>;</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> master_printf("tranmission:, freq, T[i]\n");</td><td> </td><td style="background: #eee; font-size: smaller;"> master_printf("tranmission:, freq, T[i]\n");</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> for (int i=0; i<nfreq; ++i)</td><td> </td><td style="background: #eee; font-size: smaller;"> for (int i=0; i<nfreq; ++i)</td></tr>
</table>
Stevenjhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=893&oldid=prevArdavan at 22:36, 21 October 20062006-10-21T22:36:09Z<p></p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 22:36, 21 October 2006</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 247:</strong></td>
<td colspan="2" align="left"><strong>Line 247:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> master_printf("simulating empty structure...\n");</td><td> </td><td style="background: #eee; font-size: smaller;"> master_printf("simulating empty structure...\n");</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> while (f0.time() < nfreq / (freq_max-freq_min) / 2) f0.step();</td><td> </td><td style="background: #eee; font-size: smaller;"> while (f0.time() < nfreq / (freq_max-freq_min) / 2) f0.step();</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"> ft -= ft0;</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> master_printf("simulating silica opal monolayer...\n");</td><td> </td><td style="background: #eee; font-size: smaller;"> master_printf("simulating silica opal monolayer...\n");</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> while (f.time() < nfreq / (freq_max-freq_min) / 2) f.step();</td><td> </td><td style="background: #eee; font-size: smaller;"> while (f.time() < nfreq / (freq_max-freq_min) / 2) f.step();</td></tr>
</table>
Ardavanhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=878&oldid=prevStevenj: compilation instructions2006-06-01T00:37:19Z<p>compilation instructions</p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 00:37, 1 June 2006</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 275:</strong></td>
<td colspan="2" align="left"><strong>Line 275:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> return 0;</td><td> </td><td style="background: #eee; font-size: smaller;"> return 0;</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> }</td><td> </td><td style="background: #eee; font-size: smaller;"> }</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;">== Compiling ==</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;">In order to compile your code and link against the Meep library, you must link in several additional libraries that Meep requires. The best way to do this is to use the [[w:pkg-config]] program, which is installed by default on most GNU/Linux systems. Then, to compile a file <code>foo.cpp</code> using Meep, do:</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"> g++ `pkg-config --cflags meep` foo.cpp -o foo `pkg-config --libs meep`</td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;"></td></tr>
<tr><td colspan="2"> </td><td>+</td><td style="background: #cfc; font-size: smaller;">(Naturally, replace <code>g++</code> with the name of your C++ compiler if you are not using the GNU compilers.)</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep]]</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep examples]]</td><td> </td><td style="background: #eee; font-size: smaller;">[[Category:Meep examples]]</td></tr>
</table>
Stevenjhttp://ab-initio.mit.edu/wiki/index.php?title=Meep_C-plus-plus_Tutorial&diff=832&oldid=prevStevenj: /* Overview */ typo2005-12-19T08:06:59Z<p><span class="autocomment">Overview -</span> typo</p>
<table border='0' width='98%' cellpadding='0' cellspacing='4' style="background-color: white;">
<tr>
<td colspan='2' width='50%' align='center' style="background-color: white;">←Older revision</td>
<td colspan='2' width='50%' align='center' style="background-color: white;">Revision as of 08:06, 19 December 2005</td>
</tr>
<tr><td colspan="2" align="left"><strong>Line 24:</strong></td>
<td colspan="2" align="left"><strong>Line 24:</strong></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"></td><td> </td><td style="background: #eee; font-size: smaller;"></td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> int main(int argc, char **argv) {</td><td> </td><td style="background: #eee; font-size: smaller;"> int main(int argc, char **argv) {</td></tr>
<tr><td>-</td><td style="background: #ffa; font-size: smaller;"> initialize mpi(argc, <span style="color: red; font-weight: bold;">argc</span>); // do this even for non-MPI Meep</td><td>+</td><td style="background: #cfc; font-size: smaller;"> initialize mpi(argc, <span style="color: red; font-weight: bold;">argv</span>); // do this even for non-MPI Meep</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> double resolution = 20; // pixels per distance</td><td> </td><td style="background: #eee; font-size: smaller;"> double resolution = 20; // pixels per distance</td></tr>
<tr><td> </td><td style="background: #eee; font-size: smaller;"> volume v = vol2d(5,10, resolution); // 5x10 2d cell</td><td> </td><td style="background: #eee; font-size: smaller;"> volume v = vol2d(5,10, resolution); // 5x10 2d cell</td></tr>
</table>
Stevenj