On Jul 28, 2008, at 12:19 AM, Jefferson Thomas wrote: > double ex = fields->field_energy_in_box(meep::Ex, > volume.surroundings()); > double ey = fields->field_energy_in_box(meep::Ey, > volume.surroundings()); > double ez = fields->field_energy_in_box(meep::Ez, > volume.surroundings()); > double hx = fields->field_energy_in_box(meep::Hx, > volume.surroundings()); > double hy = fields->field_energy_in_box(meep::Hy, > volume.surroundings()); > double hz = fields->field_energy_in_box(meep::Hz, > volume.surroundings());
Note that this is only first-order accurate, because it combines the E and H field energy from different times (because the H field is offset in time from E). See also: http://ab-initio.mit.edu/wiki/index.php/Synchronizing_the_magnetic_and_electric_fields for how to synchronize the fields before computing the energy. The reason that this is still fairly slow is that the energy-in-box routine is implemented using a very general field-integration function that supports integration of arbitrary user-defined functions of multiple field components over arbitrary volumes in the grid. This generality comes at a price. (Although it could probably be optimized much more. e.g. looking at the total_energy routine, I noticed that it performs integrals of some field components even in cases when it could easily figure out a priori that they are zero.) A specialized integration routine just for the field energy would certainly be far faster. Especially for a routine just to compute the total field energy over the entire grid. Especially if you want to add specialized code to your timestepping routines to keep track of this information as you update the fields. However, generality has been a much higher priority in Meep that optimizing particular functions that are normally not performance sensitive. e.g. I'm not sure what circumstance you are in that you need to calculate the total field energy in the grid at every time step, but it is pretty unusual in my experience; normally you need such integrals only every several timesteps at most. Could you say something about why your application requires this? Steven _______________________________________________ meep-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

