Skip to content

Commit

Permalink
add eig_vol argument to EigenModeSource class constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi committed Jan 23, 2024
1 parent 9cc041e commit 15b221f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions python/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def __init__(
volume=None,
eig_lattice_size=None,
eig_lattice_center=None,
eig_vol=None,
component=mp.ALL_COMPONENTS,
direction=mp.AUTOMATIC,
eig_band=1,
Expand Down Expand Up @@ -551,7 +552,7 @@ def __init__(
optional `eig_lattice_size` and `eig_lattice_center`, which define a volume
(which must enclose `size` and `center`) that is used for the unit cell in MPB
with the dielectric function ε taken from the corresponding region in the Meep
simulation.
simulation. Alternatively, a volume object `eig_vol` can be specified.
"""

super().__init__(src, component, center, volume, **kwargs)
Expand All @@ -566,6 +567,21 @@ def __init__(
self.eig_resolution = eig_resolution
self.eig_tolerance = eig_tolerance

if eig_vol:
self.eig_vol = eig_vol.swigobj
elif self.eig_lattice_center and self.eig_lattice_size:
self.eig_vol = mp.Volume(
self.eig_lattice_center,
self.eig_lattice_size,
sim.dimensions,
is_cylindrical=sim.is_cylindrical,
).swigobj
else:
raise ValueError(
"only one of eig_vol or (eig_lattice_center, eig_lattice_size) "
"can be specified."
)

@property
def eig_lattice_size(self):
return self._eig_lattice_size
Expand Down Expand Up @@ -643,13 +659,6 @@ def add_source(self, sim):
else:
direction = self.direction

eig_vol = mp.Volume(
self.eig_lattice_center,
self.eig_lattice_size,
sim.dimensions,
is_cylindrical=sim.is_cylindrical,
).swigobj

if isinstance(self.eig_band, mp.DiffractedPlanewave):
eig_band = 1
diffractedplanewave = mp.simulation.bands_to_diffractedplanewave(
Expand All @@ -663,7 +672,7 @@ def add_source(self, sim):
self.src.swigobj,
direction,
where,
eig_vol,
self.eig_vol,
eig_band,
mp.py_v3_to_vec(
sim.dimensions, self.eig_kpoint, is_cylindrical=sim.is_cylindrical
Expand Down

0 comments on commit 15b221f

Please sign in to comment.