-
Notifications
You must be signed in to change notification settings - Fork 65
FXC-3275 - Adding gaussian monitors #2903
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
Open
momchil-flex
wants to merge
2
commits into
develop
Choose a base branch
from
momchil/gaussian_monitor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 2 comments
61d5146 to
61cebca
Compare
Contributor
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/data/monitor_data.pyLines 1607-1615 1607
1608 def normalize(self, source_spectrum_fn) -> AbstractOverlapData:
1609 """Return copy of self after normalization is applied using source spectrum function."""
1610 if self.amps is None:
! 1611 return self.copy()
1612 source_freq_amps = source_spectrum_fn(self.amps.f)[None, :, None]
1613 new_amps = (self.amps / source_freq_amps).astype(self.amps.dtype)
1614 return self.copy(update={"amps": new_amps})Lines 1630-1638 1630 mnt = self.monitor
1631 new_dir = "+" if mnt.store_fields_direction == "-" else "-"
1632 update_dict = {"store_fields_direction": new_dir}
1633 if hasattr(mnt, "direction"):
! 1634 update_dict["direction"] = new_dir
1635 new_data["monitor"] = mnt.updated_copy(**update_dict)
1636 return self.copy(update=new_data)
1637 Lines 1645-1653 1645 self, dataset_names: list[str], fwidth: float
1646 ) -> list[Union[CustomCurrentSource, PointDipole]]:
1647 """Converts a :class:`.FieldData` to a list of adjoint current or point sources."""
1648
! 1649 raise NotImplementedError("Could not formulate adjoint source for overlap monitor output.")
1650
1651
1652 class ModeData(ModeSolverDataset, AbstractOverlapData):
1653 """tidy3d/components/monitor.pyLines 384-406 384
385 @cached_property
386 def _dir_arrow(self) -> tuple[float, float, float]:
387 """Direction vector from angles used for overlap (children must define angles)."""
! 388 theta, phi = self._angles
! 389 dx = np.cos(phi) * np.sin(theta)
! 390 dy = np.sin(phi) * np.sin(theta)
! 391 dz = np.cos(theta)
! 392 return self.unpop_axis(dz, (dx, dy), axis=self.normal_axis)
393
394 @property
395 def _angles(self) -> tuple[float, float]:
396 """Angle tuple (theta, phi) in radians. Children override to supply values."""
! 397 return (0.0, 0.0)
398
399 def _storage_size_solver(self, num_cells: int, tmesh: ArrayFloat1D) -> int:
400 """Default size of intermediate data; store all fields on plane for overlap."""
! 401 num_sample = len(getattr(self, "freqs", [0]))
! 402 return BYTES_COMPLEX * num_cells * num_sample * 6
403
404
405 class AbstractModeMonitor(AbstractOverlapMonitor):
406 """:class:`Monitor` that records mode-related data."""Lines 466-474 466 return ax
467
468 @cached_property
469 def _angles(self) -> tuple[float, float]:
! 470 return (self.mode_spec.angle_theta, self.mode_spec.angle_phi)
471
472 @cached_property
473 def _dir_arrow(self) -> tuple[float, float, float]:
474 """Monitor direction normal vector in cartesian coordinates."""Lines 545-553 545 )
546
547 @property
548 def _angles(self) -> tuple[float, float]:
! 549 return (self.angle_theta, self.angle_phi)
550
551 def storage_size(self, num_cells: int, tmesh: ArrayFloat1D) -> int:
552 """Size of monitor storage given the number of points after discretization."""
553 # store complex amplitudes for +/- directions |
61cebca to
daddcfd
Compare
daddcfd to
a61be33
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greptile Overview
Updated On: 2025-10-16 09:46:16 UTC
Greptile Summary
This PR adds Gaussian overlap monitor functionality to the Tidy3D simulation system through FXC-3275. The implementation introduces two new monitor classes:
GaussianOverlapMonitorfor circular Gaussian beam overlap calculations andAstigmaticGaussianOverlapMonitorfor elliptical beams with different waist parameters in each direction.The change refactors the monitor class hierarchy by creating a new
AbstractOverlapMonitorbase class that contains shared functionality between existing mode monitors and the new Gaussian monitors. This includes fields forstore_fields_direction,colocate, andconjugated_dot_product, which were moved fromAbstractModeMonitorto enable code reuse. The Gaussian monitors add specialized fields for beam parameters including angles, polarization, and waist characteristics.The implementation follows established patterns in the codebase with proper inheritance, documentation, and type safety. Test coverage is included for both monitor classes with basic functionality verification and integration into the comprehensive monitor test suite.
Important Files Changed
Changed Files
tidy3d/components/monitor.pytidy3d/components/types/monitor.pytests/test_components/test_monitor.pyConfidence score: 4/5
Sequence Diagram
sequenceDiagram participant User participant Simulation as "Simulation" participant GaussianMonitor as "GaussianOverlapMonitor" participant AstigmaticGaussianMonitor as "AstigmaticGaussianOverlapMonitor" participant AbstractGaussianOverlapMonitor as "AbstractGaussianOverlapMonitor" participant FreqMonitor as "FreqMonitor" participant Solver as "FDTD Solver" User->>GaussianMonitor: "Create GaussianOverlapMonitor(size, freqs, waist_radius, waist_distance)" GaussianMonitor->>AbstractGaussianOverlapMonitor: "Inherit base functionality" AbstractGaussianOverlapMonitor->>FreqMonitor: "Inherit frequency domain processing" User->>AstigmaticGaussianMonitor: "Create AstigmaticGaussianOverlapMonitor(size, freqs, waist_sizes, waist_distances)" AstigmaticGaussianMonitor->>AbstractGaussianOverlapMonitor: "Inherit base functionality" User->>Simulation: "Add monitors to simulation" Simulation->>GaussianMonitor: "Validate monitor configuration" Simulation->>AstigmaticGaussianMonitor: "Validate monitor configuration" User->>Simulation: "Run simulation" Simulation->>Solver: "Initialize FDTD solver" Solver->>GaussianMonitor: "Record field data at frequencies" Solver->>AstigmaticGaussianMonitor: "Record field data at frequencies" GaussianMonitor->>AbstractGaussianOverlapMonitor: "Compute Gaussian beam overlap" AstigmaticGaussianMonitor->>AbstractGaussianOverlapMonitor: "Compute astigmatic Gaussian beam overlap" AbstractGaussianOverlapMonitor->>Solver: "Return complex amplitudes for +/- directions" Solver->>Simulation: "Store monitor data" Simulation->>User: "Return simulation results with Gaussian overlap data"