Skip to content

Conversation

George-Guryev-flxcmp
Copy link
Contributor

@George-Guryev-flxcmp George-Guryev-flxcmp commented Sep 4, 2025

This PR adds automatic extrusion of structures intersecting waveports that are placed on boundaries.

Key changes:

  • Introduced the field in to mark ports for which material should be extruded.
  • Implemented the extrusion logic in , ensuring mode sources, internal absorbers, and PEC frames are fully contained within the extruded structures.
  • Extrusion occurs only when is set to .

This improves simulation accuracy when waveports are located on structure boundaries and simplifies user workflow.

Greptile Summary

Updated On: 2025-09-04 15:39:10 UTC

This PR implements automatic structure extrusion for waveports positioned on simulation boundaries. The main functionality adds a new extrude_structures boolean field to the WavePort class that, when set to True, triggers automatic extension of intersecting structures to ensure mode sources, internal absorbers, and PEC frames are fully contained within the material geometry.

The core implementation resides in the TerminalComponentModeler class with the addition of a new _extrude_port_structures method that performs the geometric operations. This method identifies structures intersecting the waveport plane and creates extended PolySlab geometries that stretch from the port location to cover all necessary simulation components. The extrusion logic handles complex geometries with holes using ClipOperation and integrates seamlessly into the existing simulation pipeline.

This feature addresses a common simulation accuracy issue where waveports placed directly on structure boundaries might not provide adequate material coverage for electromagnetic field calculations. By automating the extrusion process, the PR simplifies user workflow while ensuring proper containment of all port-related simulation elements.

Important Files Changed

Changed Files
Filename Score Overview
tidy3d/plugins/smatrix/component_modelers/terminal.py 3/5 Implements core extrusion logic with potential bounds checking issues
tidy3d/plugins/smatrix/ports/wave.py 5/5 Clean addition of extrude_structures boolean field with proper defaults
tests/test_plugins/smatrix/test_terminal_component_modeler.py 4/5 Comprehensive test validating extrusion functionality for coaxial geometry
CHANGELOG.md 4/5 Documents new feature with clear user-facing descriptions

Confidence score: 3/5

  • This PR requires careful review due to potential runtime errors in the extrusion logic
  • Score lowered due to unsafe array access without bounds checking and complex geometric operations that could fail
  • Pay close attention to tidy3d/plugins/smatrix/component_modelers/terminal.py, specifically the _extrude_port_structures method

Sequence Diagram

sequenceDiagram
    participant User
    participant TerminalComponentModeler as TCM
    participant WavePort
    participant Simulation as Sim
    participant Structure
    participant GeometryGroup as GeoGroup
    participant PolySlab
    participant ClipOperation as ClipOp

    User->>WavePort: "Create WavePort with extrude_structures=True"
    User->>TCM: "Create TerminalComponentModeler with WavePort"
    
    User->>TCM: "Access sim_dict property"
    TCM->>TCM: "_add_source_to_sim(network_index)"
    TCM->>WavePort: "to_source(source_time, snap_center)"
    WavePort-->>TCM: "ModeSource"
    TCM->>Sim: "updated_copy(sources=[port_source])"
    Sim-->>TCM: "simulation with source"
    
    TCM->>TCM: "_extrude_port_structures(sim_with_src)"
    
    loop "For each WavePort with extrude_structures=True"
        TCM->>WavePort: "Check extrude_structures flag"
        WavePort-->>TCM: "True"
        
        TCM->>TCM: "Calculate mode source position and offset"
        TCM->>TCM: "Define extrusion bounding box"
        TCM->>TCM: "Get slice planes (left and right)"
        
        loop "For each structure in simulation"
            TCM->>Structure: "Get geometry intersections with slice planes"
            Structure-->>TCM: "Shapely polygons"
            
            loop "For each intersecting polygon"
                TCM->>PolySlab: "Create outer shell from exterior vertices"
                PolySlab-->>TCM: "Outer PolySlab"
                
                alt "Polygon has holes"
                    loop "For each hole"
                        TCM->>PolySlab: "Create hole PolySlab from interior vertices"
                        PolySlab-->>TCM: "Hole PolySlab"
                    end
                    TCM->>GeoGroup: "Create GeometryGroup(hole_polyslabs)"
                    GeoGroup-->>TCM: "Holes geometry group"
                    TCM->>ClipOp: "ClipOperation(difference, outer_shell, holes)"
                    ClipOp-->>TCM: "Extruded geometry with holes"
                else "No holes"
                    TCM->>TCM: "Use outer shell as extruded geometry"
                end
                
                TCM->>TCM: "Add extruded geometry to new_geoms list"
            end
            
            TCM->>TCM: "Add original structure geometry to new_geoms"
            TCM->>GeoGroup: "Create GeometryGroup(new_geoms)"
            GeoGroup-->>TCM: "Combined geometry group"
            TCM->>Structure: "Create new Structure with combined geometry"
            Structure-->>TCM: "Extended structure"
            TCM->>TCM: "Add to new_structures list"
        end
    end
    
    TCM->>Sim: "updated_copy(structures=new_structures)"
    Sim-->>TCM: "Simulation with extruded structures"
    TCM-->>User: "SimulationMap with extruded structures"
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

@George-Guryev-flxcmp George-Guryev-flxcmp force-pushed the george/waveport branch 2 times, most recently from f844379 to 8fcbe0b Compare September 4, 2025 15:48
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/components/geometry/utils.py (100%)
  • tidy3d/components/simulation.py (92.9%): Missing lines 5716
  • tidy3d/plugins/smatrix/component_modelers/terminal.py (100%)
  • tidy3d/plugins/smatrix/ports/wave.py (100%)

Summary

  • Total: 64 lines
  • Missing: 1 line
  • Coverage: 98%

tidy3d/components/simulation.py

Lines 5712-5720

  5712             length = obj.frame.length
  5713             if direction == "+":
  5714                 span_inds[axis][1] += length - 1
  5715             else:
! 5716                 span_inds[axis][0] -= length - 1
  5717         else:
  5718             axis = obj.size.index(0.0)
  5719 
  5720         box_bounds = [

@George-Guryev-flxcmp George-Guryev-flxcmp force-pushed the george/waveport branch 2 times, most recently from a469ec2 to f1007a7 Compare September 5, 2025 00:46
@dmarek-flex
Copy link
Contributor

Looking good, just testing it on a simple example though and I think I found a bug. In this 2 waveport example, the extrusion works properly, but the final list of structures is out of order. In this case, the extended substrate is added later in the list which overlaps previously extended strips.

image

extrude_stripline.ipynb

Copy link
Contributor

@dbochkov-flexcompute dbochkov-flexcompute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, a couple of comments + let's add an example where a waveguide assembly contains a geometry which is a union of two disjoint objects (something like GeometryGroup(geometries=[box_left, box_right]), like a differential strip

Copy link
Contributor

@dmarek-flex dmarek-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looking like a good feature, just a couple of minor style comments.

@George-Guryev-flxcmp George-Guryev-flxcmp force-pushed the george/waveport branch 3 times, most recently from 66fe302 to c01d9fa Compare September 10, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants