Closed oskooi closed 6 years ago
This is not a bug but rather a feature that is not currently supported (it is stated as such in the documentation). Given that initializing structures with dispersive materials is often more time and compute intensive than non-dispersive ones, it would be good to extend this feature to support these class of materials. An example application is to model recombining excitons in organic light-emitting diodes (OLEDs) via stochastic dipole sources.
This is do-able. I think you would need to:
Add dump
and load
methods to the susceptibility
class and subclasses thereof that take an open h5file
object and a dataset prefix
, and write out the susceptibility.sigma
data to a prefix_sigma
and prefix_numsigma
in exactly the same way that structure::dump
outputs chi1inv
and num_chi1inv
now. Also output a prefix_params
data set that contains the other parameters needed to reconstruct the susceptibility, like the omega_0
and gamma
parameters of a lorenzian_susceptibility.
sigma
array is structured in exactly the same way as the chi1inv
array, with gv.ntot()
elements per non-NULL component.Have structure::dump loop through all of its susceptibilities and call their dump
methods, with a unique prefix
argument for each. structure::load
should do the inverse.
Parallelization: the key thing to realize is that, in parallel HDF5, creating the dataset has to be done once, by all processes together. Once this is done, individual processes can write non-overlapping portions of the data in parallel.
One way to do this here would be:
is_mine
chunks (the chunks on the current process), and all of the susceptibilities of the chunks, and add up the total number of points my_ntot
.structure::dump
, compute my_start
and ntotal
by summing over all processes. Use this to create a dataset of size ntotal
is_mine
chunks again and write the susceptibility data to the dataset at offset my_start
.
There is a bug in the load and dump structure routines for the case of dispersive materials (the non-dispersive case is fine). This is demonstrated in the following script which is a 2d simulation with a block of aluminum (taken from the materials library) and a point dipole source at the center of the cell. The
Ez
field is output at a random point in the computational cell at every 5 time units during the time stepping.The simulation consists of two separate runs: (1) the structure is defined using a geometry object and the structure is saved to an HDF5 file via
dump_structure
at the end of the time stepping, and (2) the structure is defined usingload_structure
. The fields from both runs should be nearly identical but they are not as shown in the output which follows the script.Script
Output
Note the large discrepancy in the time spent on "time stepping" for the two runs:
3.21455 s
vs.0.508693 s
. This suggests that the permittivity values defined on the grid are different.If we switch the block's material from
Al
tomp.Medium(index=3.5)
and rerun the simulation, the results are nearly identical as expected. The time spent on "time stepping" is also nearly identical:0.545928 s
vs.0.544215 s
.Output