Dear MEEP users, I've hacked in the option to save DFT/flux data to disk in the HDF5 file format to MEEP. This means that, for example, frequency-domain electromagnetic fields, acquired by DFT during time stepping, can be written to disk in a format that is understandable for humans (with MATLAB). It is far from perfect, but it might already help some of you or perhaps is a start to get this feature supported. Basically it dumps the DFT data in memory to disk, reordering the data from a linear format to more or less the format one expects given the plane/volume the DFT is acquired over. I say more or less, since there are a few quirks one has to be wary of (see below).
*Use of this function or the modified source code is at your own risk* Example output (after h5topng): http://www.xs4all.nl/~mp2004/dft_output.pdf A simple example ctl file can be obtained from here: http://www.xs4all.nl/~mp2004/dft_test.scm The test ctl file simply contains a single dipole in vacuum, and 3 flux objects are created, one in each principal direction. After the simulation, the 3 flux objects are exported to disk and one can find 3 HDF5 files, each containing the appropriate E- and H-fields (real and imaginary parts) for each flux object, for just as many frequencies as are specified in the ctl file. The function to save the dft data in human readable form (well, with the help of MATLAB) is called pretty-save-flux, and is called like (pretty-save-flux "pretty-flux" fx) where fx is a flux object (also see the example). The modified source can be obtained from here: http://www.xs4all.nl/~mp2004/meep-1.1.1_rjm0.1.zip The quirks: 1) When exporting *fluxes* to disk, the data is always exported such, that multiplying, in a point-wise fashion, the relevant e-field and h-field components and summing the resulting matrix over all rows and columns gives the flux. In MATLAB language: assume Ex and Ey are 2d matrices containing the x-component and y-component of the electric field, as exported from the computer memory to disk. Similarly, assume Hx and Hy to be the same for the H-field. Then the total flux is given by sum(sum(Ex.*Hy+Ey.*Hx)). Note the plus, and not a minus. This is due to MEEP, as it creates flux objects that internally weigh the 2nd electric field component with a negative factor. 2) Related to the above, the 2nd exported electric field component is exported with an additional -1 factor. Therefore, to get the actual electric field component, multiply with -1. These fields are: Flux in x-direction: Ez Flux in y-direction: Ex Flux in z-direction: Ey 3) When exporting fluxes, the electric field component is exported with the necessary weights to include the surface area/volume. 4) when a flux plane is defined between grid points, MEEP will use 2 planes with DFT data, both located on grid points, and weigh them accordingly such that the fluxes shown with (display-fluxes ...) correspond with the flux at the requested position. When this data is saved by the function I've introduced, both DFT planes are exported including the proper weight factors. ! 5) Adding multiple flux regions to a single flux object, and then exporting it, is not tested by me. Probably doesn't work! ! 6) Exporting flux objects when periodic boundary conditions are in use is not tested by me! However, I think it should work. ! 7) I haven't tested cylindrical coordinates. Quirks 2-4 are actually just because of the way MEEP sets up the flux objects and the corresponding DFT objects. Nothing to worry about, but something one should know. An additional quirk is that in contrast to the normal output-Xfield functions, the exported data just contains the contents in memory. This means that if symmetry planes are used, you don't get the full solution on disk, but just the part that is actually calculated. You have to unfold the symmetry yourself. This is because I simply didn't get how in the source code the output-Xfield functions take care of the symmetry. Finally, it should be possible to directly add DFT objects instead of using flux objects with (define mydft (meep-fields-add-dft Ez (volume (size ...) (center ...)) freqmin freqmax Nfreq false)) (source: http://article.gmane.org/gmane.comp.science.electromagnetism.meep.general/2834/match=add_dft), but I got errors ("No matching method for generic function `meep_fields_add_dft'"). If anyone finds out how to to this, the dft should be exported to disk with (pretty-save-dft "ez" mydft) but I couldn't test this. Hacking/Improving: most of the modifications of MEEP are in dft.cpp, but some too in meep.hpp. Also, I modified meep.scm and meep.scm.i (don't know if both are necessary to modify) to have a nice scheme function. Thanks for reading/trying/commenting/debugging. Robert Moerland _______________________________________________ meep-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

