Skip to content

Conversation

@caseyflex
Copy link
Contributor

@caseyflex caseyflex commented Nov 6, 2025

Whenever a Medium2D and a ModeSolver are present, we get warnings Evaluating the permittivity of a Medium2D is unphysical. We should be checking the volumetric equivalent structure instead.

Greptile Overview

Updated On: 2025-11-06 16:49:01 UTC

Greptile Summary

Fixed spurious warnings when using Medium2D structures with ModeSolver by switching from self.simulation.structures to self.simulation.volumetric_structures in the _intersecting_media method.

  • The volumetric_structures property automatically converts Medium2D structures to their 3D AnisotropicMedium equivalents
  • This prevents the unphysical permittivity warning that was triggered when the mode solver accessed Medium2D.eps_diagonal() directly
  • The fix is minimal (one-line change) and uses the existing infrastructure designed specifically for this conversion
  • No test changes needed as this fixes a warning issue rather than functional behavior

Confidence Score: 4/5

  • This PR is safe to merge with low risk, pending a changelog entry
  • The change is well-targeted and uses existing infrastructure (volumetric_structures property) that was designed specifically for converting Medium2D to 3D equivalents. The fix is minimal (one line) and directly addresses the root cause of spurious warnings. However, the PR is missing a changelog entry as required by project conventions for bug fixes, which is the only reason for not scoring 5/5.
  • No files require special attention - the change is straightforward and correct

Important Files Changed

File Analysis

Filename Score Overview
tidy3d/components/mode/mode_solver.py 5/5 Changed from self.simulation.structures to self.simulation.volumetric_structures in _intersecting_media method to use converted 3D equivalents of Medium2D structures, avoiding unphysical permittivity warnings

Sequence Diagram

sequenceDiagram
    participant MS as ModeSolver
    participant Sim as Simulation
    participant Scene
    participant Medium2D
    participant VolumetricMedium as AnisotropicMedium

    Note over MS: _intersecting_media() called
    MS->>Sim: Get background_structure
    MS->>Sim: Get volumetric_structures
    Note over Sim: Returns structures with<br/>Medium2D converted to<br/>3D volumetric equivalents
    Sim->>Sim: _volumetric_structures_grid()
    loop For each structure
        alt Structure has Medium2D
            Sim->>Medium2D: volumetric_equivalent()
            Medium2D->>VolumetricMedium: Create AnisotropicMedium
            VolumetricMedium-->>Sim: Return 3D medium
            Note over Sim: Replace Medium2D structure<br/>with volumetric equivalent
        else Structure has 3D medium
            Note over Sim: Keep structure as is
        end
    end
    Sim-->>MS: Return volumetric_structures
    MS->>Scene: intersecting_media(plane, structures)
    Scene->>VolumetricMedium: Access permittivity
    Note over Scene: No warning since<br/>using physical 3D medium
    Scene-->>MS: Return intersecting media list
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.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Diff Coverage

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

  • tidy3d/components/mode/mode_solver.py (0.0%): Missing lines 1917

Summary

  • Total: 1 line
  • Missing: 1 line
  • Coverage: 0%

tidy3d/components/mode/mode_solver.py

  1913     @cached_property
  1914     def _intersecting_media(self) -> list:
  1915         """List of media (including simulation background) intersecting the mode plane."""
  1916         total_structures = [self.simulation.scene.background_structure]
! 1917         total_structures += list(self.simulation.volumetric_structures)
  1918         return self.simulation.scene.intersecting_media(self.plane, total_structures)
  1919 
  1920     @cached_property
  1921     def _has_fully_anisotropic_media(self) -> bool:

Copy link
Collaborator

@momchil-flex momchil-flex left a comment

Choose a reason for hiding this comment

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

I think it makes sense. But is the 2D medium included in the mode solve as well through the volumetric representation, or is it ignored?

@caseyflex
Copy link
Contributor Author

I think it makes sense. But is the 2D medium included in the mode solve as well through the volumetric representation, or is it ignored?

It should be included in the mode solver, either via simulation.epsilon_on_grid (which explicitly uses volumetric_structures) or via the subpixel processing

@caseyflex caseyflex force-pushed the hotfix/casey/modeintersectingmedia2d branch 2 times, most recently from 7d1306d to b3e5469 Compare November 7, 2025 18:38
@caseyflex caseyflex enabled auto-merge November 7, 2025 18:39
@caseyflex caseyflex added this pull request to the merge queue Nov 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2025
@caseyflex caseyflex force-pushed the hotfix/casey/modeintersectingmedia2d branch from b3e5469 to 1195830 Compare November 7, 2025 20:38
@caseyflex caseyflex enabled auto-merge November 7, 2025 20:38
@caseyflex caseyflex added this pull request to the merge queue Nov 7, 2025
Merged via the queue into develop with commit aa8e786 Nov 7, 2025
26 checks passed
@caseyflex caseyflex deleted the hotfix/casey/modeintersectingmedia2d branch November 7, 2025 22:29
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.

3 participants