-
Couldn't load subscription status.
- Fork 65
feat: automatic directivity monitors in terminal component modelers #2904
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
feat: automatic directivity monitors in terminal component modelers #2904
Conversation
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.
4 files reviewed, 5 comments
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/plugins/smatrix/component_modelers/terminal.pyLines 641-649 641 lumped_elements = simulation.lumped_elements
642
643 # If no structures or lumped elements, validation passes
644 if not structures and not lumped_elements:
! 645 return
646
647 # Calculate union of bounding boxes for all structures and lumped elements
648 all_geoms = []Lines 684-692 684
685 # Check plus side: union should be at least BUFFER cells away from monitor end
686 buffer_plus = mnt_end - union_end
687 if buffer_plus < buffer:
! 688 raise ValueError(
689 f"Automatically generated radiation monitor is too close to structures on the positive {axis_name} side. "
690 f"Buffer: {buffer_plus} cells, required: {buffer} cells. "
691 f"Please increase simulation domain size."
692 ) |
Yea I think users might want to change a few of these parameters (I am also curious if the size of the buffer will affect the far field results). I got used to the Spec pattern, like AutoGridSpec, which is a description of how to build the object. So maybe we can support the current manual approach and in addition the user can supply a |
|
And maybe we should keep the list/tuple pattern as you have, for computational efficiency it is nice to be able to make different monitors with different frequency/spatial sampling. |
|
Basically though I think this PR addresses the issue! Thanks for the quick turn around. |
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.
Looks good to me! Just have a few minor comments regarding naming conventions and docstrings.
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.
Looks good to me, thanks again! Just a few minor comments
fa07f54 to
ea4b48b
Compare
ea4b48b to
b5ed563
Compare
Here's a working version for automatic generation of directivity monitors in terminal component modelers. It creates a directivity monitor 2 cells away from pml/domain boundaries, and also checks that it is at least 2 cells away from structures and lumped elements. Re-runs of a couple of cases using this feature:
A bit unsure about the API. Currently, it works as
but maybe a better way is to introduce some sort of
AutoDirectivityMonitorwhere it is possible to adjust parameters
AutoDirectivityMonitor(freqs=..., num_theta_points=..., num_phi_points=..., name=..., buffer=...)what do you think?
Greptile Overview
Updated On: 2025-10-17 04:49:09 UTC
Greptile Summary
This PR introduces automatic directivity monitor generation for antenna calculations in terminal component modelers. The key feature allows users to specify
radiation_monitors="auto"inTerminalComponentModeler, which automatically creates and positions aDirectivityMonitorfor far-field radiation pattern analysis.The implementation intelligently positions the monitor 2 grid cells away from PML/domain boundaries while ensuring adequate clearance from structures and lumped elements. The auto-generated monitor samples the full sphere with configurable angular resolution (100 theta points, 200 phi points by default) and includes comprehensive validation to prevent placement issues.
The change maintains backward compatibility - users can still provide custom
DirectivityMonitorobjects as before, or use the new "auto" convenience feature. The implementation uses proper separation of concerns with dedicated methods for monitor generation, validation, and simulation finalization. This feature significantly improves the usability of antenna modeling workflows by automating the complex geometry considerations typically required for proper monitor placement.Important Files Changed
Changed Files
Confidence score: 4/5
Sequence Diagram
sequenceDiagram participant User participant TerminalComponentModeler participant Simulation participant RadiationMonitorGenerator participant ValidationEngine User->>TerminalComponentModeler: "Create modeler with radiation_monitors='auto'" TerminalComponentModeler->>TerminalComponentModeler: "_finalized_radiation_monitors property accessed" TerminalComponentModeler->>RadiationMonitorGenerator: "_generate_radiation_monitor()" RadiationMonitorGenerator->>Simulation: "Get PML thicknesses from num_pml_layers" RadiationMonitorGenerator->>Simulation: "Get grid boundaries" RadiationMonitorGenerator->>RadiationMonitorGenerator: "Calculate monitor span with AUTO_RADIATION_MONITOR_BUFFER" RadiationMonitorGenerator->>RadiationMonitorGenerator: "Create Box.from_bounds()" RadiationMonitorGenerator->>RadiationMonitorGenerator: "Generate theta and phi arrays" RadiationMonitorGenerator->>RadiationMonitorGenerator: "Create DirectivityMonitor" RadiationMonitorGenerator->>ValidationEngine: "_validate_radiation_monitor_buffer()" ValidationEngine->>Simulation: "Get finalized structures" ValidationEngine->>ValidationEngine: "Calculate union of structure bounds" ValidationEngine->>ValidationEngine: "Check buffer distances" alt Buffer validation passes ValidationEngine-->>RadiationMonitorGenerator: "Validation successful" RadiationMonitorGenerator-->>TerminalComponentModeler: "Return DirectivityMonitor" else Buffer validation fails ValidationEngine->>ValidationEngine: "Raise ValueError" ValidationEngine-->>User: "ValueError: Monitor too close to structures" end TerminalComponentModeler->>TerminalComponentModeler: "Add monitor to base_sim" TerminalComponentModeler-->>User: "Return modeler with auto radiation monitor"