Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi committed Sep 15, 2023
1 parent 800a4e6 commit 4fc6d08
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions python/adjoint/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,30 @@ def place_adjoint_source(self, dJ):
if self.kpoint_func:
eig_kpoint = -1 * self.kpoint_func(time_src.frequency, self.mode)
else:
center_frequency = 0.5 * (np.min(self.frequencies) + np.max(
self.frequencies))
center_frequency = 0.5 * (
np.min(self.frequencies) + np.max(self.frequencies)
)
direction = mp.Vector3(
*(np.eye(3)[self._monitor.normal_direction] *
np.abs(center_frequency)))
*(
np.eye(3)[self._monitor.normal_direction]
* np.abs(center_frequency)
)
)
eig_kpoint = -1 * direction if self.forward else direction

elif isinstance(self.mode, mp.DiffractedPlanewave):
new_dp = mp.DiffractedPlanewave(
[-1*gg for gg in self.mode.g] if self.forward else self.mode.g,
[-1 * gg for gg in self.mode.g] if self.forward else self.mode.g,
self.mode.axis,
self.mode.s,
self.mode.p
self.mode.p,
)

else:
raise TypeError("mode property of EigenModeCoefficient must be either an"
"integer or DiffractedPlaneWave object.")

raise TypeError(
"mode property of EigenModeCoefficient must be either an"
"integer or DiffractedPlaneWave class object."
)

if self._frequencies.size == 1:
amp = da_dE * dJ * scale
Expand All @@ -285,12 +290,8 @@ def place_adjoint_source(self, dJ):
center=self.volume.center,
**self.eigenmode_kwargs,
)
<<<<<<< HEAD

else isinstance(self.mode, mp.DiffractedPlanewave):
=======
elif isinstance(self.mode,mp.DiffractedPlanewave):
>>>>>>> 9b8bf646 (whoops)
else:
source = mp.EigenModeSource(
src,
eig_band=new_dp,
Expand All @@ -315,10 +316,15 @@ def __call__(self):
kpoint_func = self.kpoint_func
overlap_idx = self.kpoint_func_overlap_idx
else:
center_frequency = 0.5 * (np.min(self.frequencies) + np.max(
self.frequencies))
kpoint = mp.Vector3(*(np.eye(3)[self._monitor.normal_direction] *
np.abs(center_frequency)))
center_frequency = 0.5 * (
np.min(self.frequencies) + np.max(self.frequencies)
)
kpoint = mp.Vector3(
*(
np.eye(3)[self._monitor.normal_direction]
* np.abs(center_frequency)
)
)
kpoint_func = lambda *not_used: kpoint if self.forward else -1 * kpoint
overlap_idx = 0
ob = self.sim.get_eigenmode_coefficients(
Expand All @@ -329,13 +335,13 @@ def __call__(self):
**self.eigenmode_kwargs,
)

elif isinstance(self.mode,mp.DiffractedPlanewave):
elif isinstance(self.mode, mp.DiffractedPlanewave):
overlap_idx = 0
new_dp = mp.DiffractedPlanewave(
self.mode.g if self.forward else [-1*gg for gg in self.mode.g],
self.mode.g if self.forward else [-1 * gg for gg in self.mode.g],
self.mode.axis,
self.mode.s,
self.mode.p
self.mode.p,
)
ob = self.sim.get_eigenmode_coefficients(
self._monitor,
Expand Down

0 comments on commit 4fc6d08

Please sign in to comment.