Skip to content
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

simulation subsection to include lumped elements #1991

Closed
weiliangjin2021 opened this issue Oct 1, 2024 · 6 comments · Fixed by #1995
Closed

simulation subsection to include lumped elements #1991

weiliangjin2021 opened this issue Oct 1, 2024 · 6 comments · Fixed by #1995
Assignees
Labels
2.8 will go into version 2.8.* Bug something isnt working

Comments

@weiliangjin2021
Copy link
Collaborator

The following code will error at the last line.

# From https://docs.flexcompute.com/projects/tidy3d/en/latest/notebooks/ModeSolver.html
# Only modification: add a 2D material
import numpy as np
import matplotlib.pylab as plt

import tidy3d as td
from tidy3d.constants import C_0
import tidy3d.web as web
from tidy3d.plugins.mode import ModeSolver

# size of simulation domain
Lx, Ly, Lz = 8, 6, 6
dl = 0.05

# waveguide information
wg_width = 1.5
wg_height = 1.0
wg_permittivity = 4.0

# automatic grid specification
grid_spec = td.GridSpec.auto(min_steps_per_wvl=20, wavelength=1.0)

resistor = td.LumpedResistor(
	center=(2,1,0),
	size=(0, 1, 1),
	name="port",
	num_grid_cells=3,
	resistance=50.0,
	voltage_axis=2,
)

sim = td.Simulation(
    size=(Lx, Ly, Lz),
    grid_spec=grid_spec,
    lumped_elements=[resistor],
    run_time=1e-20,
    boundary_spec=td.BoundarySpec.all_sides(boundary=td.Periodic()),
)

plane = td.Box(center=(0, 0, 0), size=(4, 0, 3.5))


mode_spec = td.ModeSpec(
    num_modes=1,
    target_neff=2.0,
)


mode_solver = ModeSolver(
    simulation=sim,
    plane=plane,
    mode_spec=mode_spec,
    freqs=[1e14],
)

mode_solver.reduced_simulation_copy.simulation.volumetric_structures

This is because mode solver is using a reduced simulation (

solver = self.reduced_simulation_copy
), which comes from
def subsection(
self,
region: Box,
boundary_spec: BoundarySpec = None,
grid_spec: Union[GridSpec, Literal["identical"]] = None,
symmetry: Tuple[Symmetry, Symmetry, Symmetry] = None,
sources: Tuple[SourceType, ...] = None,
monitors: Tuple[MonitorType, ...] = None,
remove_outside_structures: bool = True,
remove_outside_custom_mediums: bool = False,
include_pml_cells: bool = False,
**kwargs,
) -> AbstractYeeGridSimulation:
. Lumped element outside the reduced simulation domain should be excluded.

@weiliangjin2021 weiliangjin2021 added Bug something isnt working 2.8 will go into version 2.8.* labels Oct 1, 2024
@momchil-flex
Copy link
Collaborator

Note that in his recent PR (merged in develop) Casey introduced a try-except for the reduced simulation copy in the mode solver to avoid unexpected issues like this (something like that popped up for nonlinear materials too). This would fix this in principle but always better to fix properly? https://github.com/flexcompute/tidy3d/pull/1977/files#diff-4d80d757aca9b68f3a9557ad726b40390e2b2185302fcfbf162b1cf3e874e79cR345-R357

@weiliangjin2021
Copy link
Collaborator Author

Note that in his recent PR (merged in develop) Casey introduced a try-except for the reduced simulation copy in the mode solver to avoid unexpected issues like this (something like that popped up for nonlinear materials too). This would fix this in principle but always better to fix properly? https://github.com/flexcompute/tidy3d/pull/1977/files#diff-4d80d757aca9b68f3a9557ad726b40390e2b2185302fcfbf162b1cf3e874e79cR345-R357

Well, try-except won't catch this because reduced simulation is generated fine, but only error if simulation.volumetric_structures is called.

@weiliangjin2021
Copy link
Collaborator Author

An easy fix (but not ideal) using try-except idea is to add a line to invoke the error,

try:
solver = self.reduced_simulation_copy
solver.simulation.volumetric_structures

@momchil-flex
Copy link
Collaborator

Oh I see. That makes sense if there's no obvious better fix.

@weiliangjin2021
Copy link
Collaborator Author

@dmarek-flex if we can just exclude lumped element outside the reduced domain, a better fix would be:

  • each lumped element has a bounds property
  • Similar to
    new_structures = [strc for strc in self.structures if new_box.intersects(strc.geometry)]
    , exclude lumped elements that are outside.

@dmarek-flex
Copy link
Contributor

@dmarek-flex if we can just exclude lumped element outside the reduced domain, a better fix would be:

  • each lumped element has a bounds property
  • Similar to
    new_structures = [strc for strc in self.structures if new_box.intersects(strc.geometry)]

    , exclude lumped elements that are outside.

Yes, each lumped element has an associated geometry that we can check. Shouldn't be hard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.8 will go into version 2.8.* Bug something isnt working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants