-
Notifications
You must be signed in to change notification settings - Fork 66
Meshing performance in gap refinement #3019
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
Merged
weiliangjin2021
merged 1 commit into
develop
from
weiliang/FXC-4106-cached_parse_structures
Nov 26, 2025
Merged
Meshing performance in gap refinement #3019
weiliangjin2021
merged 1 commit into
develop
from
weiliang/FXC-4106-cached_parse_structures
Nov 26, 2025
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
122fc45 to
48a77e8
Compare
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.
7 files reviewed, 2 comments
Contributor
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/grid/grid_spec.py |
dbochkov-flexcompute
approved these changes
Nov 25, 2025
8add44f to
c170e05
Compare
c170e05 to
020a499
Compare
feat(meshing): gap refinement only insert snapping points
020a499 to
164b9e6
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
Greptile Summary
This PR optimizes meshing performance in gap refinement by implementing strategic caching of expensive geometry operations. The key improvements are:
parse_structuresresults: The_parse_structuresmethod is now called once per axis and its results (interval_coordsandmax_dl_list) are reused across all gap meshing iterations, eliminating redundant structure parsing_internal_layerrefinement_merged_geoscached property inSimulationto compute merged PEC geometries once and reuse them throughout gap meshing iterations_internal_layerfinement_corners_and_convexity_2dcached property_is_inplane_boundedfrom a@cached_propertyto a regular method that accepts aBoxparameter for more flexible geometry checking; added new_layer_boxand_merged_geoshelper methodsincrement_floatto a dedicatedfloat_utils.pymodule and addedslightly_enlarged_copymethod toBoxclassThe optimization maintains correctness by passing cached data through the call chain rather than recomputing it. Tests have been updated to match the new signatures.
Confidence Score: 4/5
Important Files Changed
File Analysis
increment_floatfunction fromutils_2d.pyfor better code organization and reusabilitymerged_geosand addedkeep_metal_onlyparameter for performance optimization; updated docstrings fromList/Tupletolist/tuple_parse_structuresto cache interval coordinates/max_dl_list across gap meshing iterations; added caching of merged geometries; changed_is_inplane_boundedfrom cached_property to method; added_layer_boxand_merged_geosmethods; updated gap meshing to use cached data_internal_layerrefinement_boundary_typesand_internal_layerrefinement_merged_geosto pre-compute and cache expensive geometry operations; updated method calls to pass cached dataSequence Diagram
sequenceDiagram participant Sim as Simulation participant GS as GridSpec participant LRS as LayerRefinementSpec participant CF as CornerFinderSpec Note over Sim: Grid Generation with Gap Meshing Sim->>Sim: _internal_layerrefinement_boundary_types<br/>(cached_property) Sim->>Sim: _internal_layerrefinement_merged_geos<br/>(cached_property) loop for each layer Sim->>LRS: _merged_geos() LRS->>CF: _merged_pec_on_plane() CF-->>LRS: merged geometries LRS-->>Sim: cache merged_geos end Sim->>Sim: _internal_layerfinement_corners_and_convexity_2d<br/>(cached_property) loop for each layer Sim->>LRS: _corners_and_convexity_2d(merged_geos) LRS->>CF: _corners_and_convexity(merged_geos) CF-->>LRS: corners & convexity LRS-->>Sim: cache corners data end Sim->>GS: make_grid() GS->>GS: _make_grid_and_snapping_lines() Note over GS: Pre-compute parse_structures once loop for each axis GS->>GS: _parse_structures() Note right of GS: Cache interval_coords<br/>and max_dl_list end GS->>GS: _make_grid_one_iteration(cached_data) Note right of GS: Initial grid with<br/>cached parse results Note over GS: Gap Meshing Iterations loop gap_meshing_iters loop for each layer GS->>LRS: _resolve_gaps(grid, cached_merged_geos) Note right of LRS: Use cached merged_geos<br/>instead of recomputing LRS-->>GS: snapping_lines end alt new snapping lines found GS->>GS: _make_grid_one_iteration(cached_data) Note right of GS: Reuse cached parse_structures<br/>interval_coords & max_dl_list alt grid unchanged Note over GS: Early exit end else no new snapping lines Note over GS: Early exit end end GS-->>Sim: final grid