Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the EigenmodeCoefficient adjont solver accept a DiffractedPlanewave object #2332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions python/adjoint/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class EigenmodeCoefficient(ObjectiveQuantity):
"""A frequency-dependent eigenmode coefficient.
Attributes:
volume: the volume over which the eigenmode coefficient is calculated.
mode: the eigenmode number.
mode: the eigenmode number or the DiffractedPlanewave object.
forward: whether the forward or backward mode coefficient is returned as
the result of the evaluation.
kpoint_func: an optional k-point function to use when evaluating the eigenmode
Expand Down Expand Up @@ -269,13 +269,24 @@ def __call__(self):
)
kpoint_func = lambda *not_used: kpoint if self.forward else -1 * kpoint
overlap_idx = 0

if isinstance(self.mode, int):
_mode = [self.mode]
elif isinstance(self.mode, mp.DiffractedPlanewave):
_mode = self.mode
else:
raise TypeError(
"mode in EigenmodeCoefficient must be an integer or a DiffractedPlanewave object"
)

ob = self.sim.get_eigenmode_coefficients(
self._monitor,
[self.mode],
_mode,
direction=mp.NO_DIRECTION,
kpoint_func=kpoint_func,
**self.eigenmode_kwargs,
)

overlaps = ob.alpha.squeeze(axis=0)
assert overlaps.ndim == 2
self._eval = overlaps[:, overlap_idx]
Expand Down