-
Notifications
You must be signed in to change notification settings - Fork 66
feat(meshing): disable polygon cleanup in corner finder #3023
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(meshing): disable polygon cleanup in corner finder #3023
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.
Additional Comments (2)
6 files reviewed, 2 comments
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/components/geometry/base.pytidy3d/components/geometry/mesh.pytidy3d/components/geometry/primitives.pytidy3d/components/grid/mesher.py |
dbochkov-flexcompute
left a comment
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! any unit tests that could be added?
Sure, will add more. In the meantime, I just added another optional variable. |
gap refinement doesn't capture gaps and strips thinner than this limit relative to the grid size https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/components/grid/grid_spec.py#L45 |
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, no comments
943b0ba to
e3e70d9
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.
8 files reviewed, no comments
e3e70d9 to
bca0a59
Compare
bca0a59 to
05ef72c
Compare
|
Sorry for pushing some many pieces in one PR, but it's hard to separate them as they will have conflict with each other. @momchil-flex could you review the changes in mesher.py? After avoiding some computing repetition in #3019, one simulation still takes > 10min for meshing, as it contains too many geometries (it's a giant PCB). Now with this PR on top of the previous PR, it takes <3 min. |
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.
9 files reviewed, no comments
05ef72c to
bf0e9a1
Compare
Corner finder: reduce the number of vertices for smoothly curved cross section Mesher and gap refinement: performance improvement in parse_structures
bf0e9a1 to
0a1e13b
Compare
momchil-flex
left a comment
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.
Looked at mesher only, but looks great!
Cleaning up only helps in a few limited cases, e.g. mentioned here #2596. Even in this case, it is fine to classify that as a corner.
@dbochkov-flexcompute I'm not sure if this edge case matters to gap refinement or the convexity analysis for minimal feature size.
Greptile Overview
Greptile Summary
This PR disables polygon cleanup in the corner finder and adds performance optimizations to the meshing system.
Main Changes:
SHAPELY_CLEANUP = False) in corner detection to preserve all geometric features, addressing edge cases where cleanup was too aggressivecleanupandquad_segsparameters throughout the geometry intersection API, allowing fine-grained control over polygon processing and circular shape discretizationN_SHAPELY_QUAD_SEGS = 8) for meshing operations versus high-resolution (200) for visualizationbisectandnp.searchsorted, and vectorizing containment checksImpact:
The cleanup disabling means corner detection will now classify more vertices as corners, which may affect mesh refinement. The PR description mentions this is fine for corner classification, but questions remain about impact on gap refinement and convexity analysis for minimal feature size. The performance optimizations in mesher.py should significantly improve meshing speed for complex geometries.
Confidence Score: 4/5
tidy3d/components/grid/mesher.pyfor the complex caching and vectorization logic, and monitor downstream effects of disabling cleanup intidy3d/components/grid/corner_finder.pyImportant Files Changed
File Analysis
N_SHAPELY_QUAD_SEGSandSHAPELY_CLEANUP = Falseto disable polygon cleanup in corner detection, passing these tomerging_geometries_on_planecleanupandquad_segsparameters throughout the geometry intersection methods, threading them through the entire hierarchy to control polygon cleanup behavior_N_SHAPELY_QUAD_SEGSto_N_SHAPELY_QUAD_SEGS_VISUALIZATION, and updated circular shape intersection methods to use thequad_segsparameterbisectandnp.searchsorted, vectorized containment checksSequence Diagram
sequenceDiagram participant CF as CornerFinderSpec participant MGP as merging_geometries_on_plane participant BX as Box.intersections_with participant Geom as Geometry.intersections_plane participant TP as to_polygon_list Note over CF: SHAPELY_CLEANUP equals False<br/>N_SHAPELY_QUAD_SEGS equals 8 CF->>MGP: Call with cleanup False quad_segs 8 MGP->>BX: Call intersections_with cleanup False quad_segs 8 BX->>Geom: Call intersections_plane cleanup False quad_segs 8 alt Circular shapes Sphere or Cylinder Geom->>Geom: Use quad_segs 8 for discretization Note over Geom: Low resolution for meshing<br/>versus 200 for visualization else Non-circular shapes Geom->>Geom: quad_segs parameter ignored end Geom-->>BX: Return list of Shapely objects BX-->>MGP: Return list of Shapely objects MGP->>TP: Call to_polygon_list with cleanup False alt cleanup True old behavior TP->>TP: Call cleanup_shapely_object<br/>Remove tiny features else cleanup False new behavior Note over TP: Skip cleanup step<br/>preserve all vertices end TP-->>MGP: Return list of Polygons MGP-->>CF: Return merged geometries CF->>CF: Call filter_collinear_vertices Note over CF: Identify corners based on<br/>angle_threshold parameter