From 15b221f77e7ac921fe3f8486631ddf10950a1efa Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Mon, 22 Jan 2024 17:04:48 -0800 Subject: [PATCH 1/3] add eig_vol argument to EigenModeSource class constructor --- python/source.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/python/source.py b/python/source.py index 4104c0b30..e877cac7d 100644 --- a/python/source.py +++ b/python/source.py @@ -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, @@ -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) @@ -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 @@ -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( @@ -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 From 477da77d56deadbca96fa1f2560fa3479702dd32 Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Mon, 22 Jan 2024 21:29:15 -0800 Subject: [PATCH 2/3] define eig_vol within add_source rather than constructor --- python/source.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/python/source.py b/python/source.py index e877cac7d..c7823f5fb 100644 --- a/python/source.py +++ b/python/source.py @@ -567,20 +567,10 @@ def __init__( self.eig_resolution = eig_resolution self.eig_tolerance = eig_tolerance - if eig_vol: + if eig_vol is not None: 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." - ) + self.eig_vol = None @property def eig_lattice_size(self): @@ -659,6 +649,20 @@ def add_source(self, sim): else: direction = self.direction + if self.eig_lattice_center is not None and self.eig_lattice_size is not None: + if self.eig_vol is None: + 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." + ) + if isinstance(self.eig_band, mp.DiffractedPlanewave): eig_band = 1 diffractedplanewave = mp.simulation.bands_to_diffractedplanewave( From 62ea4534ab6d11df155d69fb5eb7b648e79fc5ad Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Mon, 22 Jan 2024 22:29:06 -0800 Subject: [PATCH 3/3] fixes --- python/source.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/python/source.py b/python/source.py index c7823f5fb..4d6622da8 100644 --- a/python/source.py +++ b/python/source.py @@ -558,6 +558,7 @@ def __init__( super().__init__(src, component, center, volume, **kwargs) self.eig_lattice_size = eig_lattice_size self.eig_lattice_center = eig_lattice_center + self.eig_vol = eig_vol self.component = component self.direction = direction self.eig_band = eig_band @@ -567,11 +568,6 @@ def __init__( self.eig_resolution = eig_resolution self.eig_tolerance = eig_tolerance - if eig_vol is not None: - self.eig_vol = eig_vol.swigobj - else: - self.eig_vol = None - @property def eig_lattice_size(self): return self._eig_lattice_size @@ -649,19 +645,13 @@ def add_source(self, sim): else: direction = self.direction - if self.eig_lattice_center is not None and self.eig_lattice_size is not None: - if self.eig_vol is None: - 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." - ) + if self.eig_vol is None: + self.eig_vol = mp.Volume( + self.eig_lattice_center, + self.eig_lattice_size, + sim.dimensions, + is_cylindrical=sim.is_cylindrical, + ) if isinstance(self.eig_band, mp.DiffractedPlanewave): eig_band = 1 @@ -676,7 +666,7 @@ def add_source(self, sim): self.src.swigobj, direction, where, - self.eig_vol, + self.eig_vol.swigobj, eig_band, mp.py_v3_to_vec( sim.dimensions, self.eig_kpoint, is_cylindrical=sim.is_cylindrical