|
10 | 10 | from tidy3d.components.scene import MAX_GEOMETRY_COUNT, MAX_NUM_MEDIUMS
|
11 | 11 | from tidy3d.components.simulation import MAX_NUM_SOURCES
|
12 | 12 | from tidy3d.exceptions import SetupError, Tidy3dError, Tidy3dKeyError
|
| 13 | +from tidy3d.plugins.mode import ModeSolver |
13 | 14 |
|
14 | 15 | from ..utils import (
|
15 | 16 | SIM_FULL,
|
@@ -2543,7 +2544,11 @@ def test_sim_subsection(unstructured, nz):
|
2543 | 2544 | sim_red = SIM_FULL.subsection(
|
2544 | 2545 | region=region, boundary_spec=td.BoundarySpec.all_sides(td.Periodic())
|
2545 | 2546 | )
|
2546 |
| - sim_red = SIM_FULL.subsection(region=region, sources=[], grid_spec=td.GridSpec.uniform(dl=20)) |
| 2547 | + sim_red = SIM_FULL.subsection( |
| 2548 | + region=region, |
| 2549 | + sources=[], |
| 2550 | + grid_spec=td.GridSpec.uniform(dl=20), |
| 2551 | + ) |
2547 | 2552 | assert len(sim_red.sources) == 0
|
2548 | 2553 | sim_red = SIM_FULL.subsection(region=region, monitors=[])
|
2549 | 2554 | assert len(sim_red.monitors) == 0
|
@@ -3085,6 +3090,81 @@ def test_validate_sources_monitors_in_bounds():
|
3085 | 3090 | )
|
3086 | 3091 |
|
3087 | 3092 |
|
| 3093 | +def test_mode_pml_warning(): |
| 3094 | + sim_size = (3, 3, 3) |
| 3095 | + lambda0 = 1.55 |
| 3096 | + freq0 = td.C_0 / lambda0 |
| 3097 | + si = td.material_library["cSi"]["Li1993_293K"] |
| 3098 | + sio2 = td.material_library["SiO2"]["Horiba"] |
| 3099 | + wg = td.Structure(geometry=td.Box(size=(0.22, 0.5, td.inf)), medium=si) |
| 3100 | + mode_plane = td.Box(size=(2, 2, 0)) |
| 3101 | + mode_spec = td.ModeSpec(num_pml=(22, 22)) |
| 3102 | + grid_spec = td.GridSpec.auto(wavelength=lambda0, min_steps_per_wvl=30) |
| 3103 | + symmetry = (0, 0, 0) |
| 3104 | + with AssertLogLevel(None): |
| 3105 | + sim = td.Simulation( |
| 3106 | + size=sim_size, |
| 3107 | + medium=sio2, |
| 3108 | + structures=[wg], |
| 3109 | + grid_spec=grid_spec, |
| 3110 | + run_time=1e-30, |
| 3111 | + monitors=[ |
| 3112 | + td.ModeSolverMonitor( |
| 3113 | + size=(2, 2, 0), |
| 3114 | + name="mode", |
| 3115 | + freqs=[freq0], |
| 3116 | + mode_spec=mode_spec.updated_copy(num_pml=(10, 10)), |
| 3117 | + ) |
| 3118 | + ], |
| 3119 | + symmetry=symmetry, |
| 3120 | + ) |
| 3121 | + with AssertLogLevel("WARNING", contains_str="covers more than"): |
| 3122 | + sim = td.Simulation( |
| 3123 | + size=sim_size, |
| 3124 | + medium=sio2, |
| 3125 | + structures=[wg], |
| 3126 | + grid_spec=grid_spec, |
| 3127 | + run_time=1e-30, |
| 3128 | + monitors=[ |
| 3129 | + td.ModeSolverMonitor( |
| 3130 | + size=(2, 2, 0), name="mode", freqs=[freq0], mode_spec=mode_spec |
| 3131 | + ) |
| 3132 | + ], |
| 3133 | + symmetry=symmetry, |
| 3134 | + ) |
| 3135 | + with AssertLogLevel("WARNING", contains_str="covers more than"): |
| 3136 | + sim = td.Simulation( |
| 3137 | + size=sim_size, |
| 3138 | + medium=sio2, |
| 3139 | + structures=[wg], |
| 3140 | + grid_spec=grid_spec, |
| 3141 | + run_time=1e-30, |
| 3142 | + sources=[ |
| 3143 | + td.ModeSource( |
| 3144 | + size=(2, 2, 0), |
| 3145 | + direction="+", |
| 3146 | + source_time=td.GaussianPulse(freq0=freq0, fwidth=0.1 * freq0), |
| 3147 | + mode_spec=mode_spec, |
| 3148 | + ) |
| 3149 | + ], |
| 3150 | + symmetry=symmetry, |
| 3151 | + ) |
| 3152 | + with AssertLogLevel("WARNING", contains_str="covers more than"): |
| 3153 | + mode_solver = ModeSolver( |
| 3154 | + simulation=sim, plane=mode_plane, mode_spec=mode_spec, freqs=[freq0] |
| 3155 | + ) |
| 3156 | + with AssertLogLevel("WARNING", contains_str="covers more than"): |
| 3157 | + mode_sim = td.ModeSimulation( |
| 3158 | + size=sim_size, |
| 3159 | + medium=sio2, |
| 3160 | + structures=[wg], |
| 3161 | + grid_spec=grid_spec, |
| 3162 | + plane=mode_plane, |
| 3163 | + mode_spec=mode_spec, |
| 3164 | + freqs=[freq0], |
| 3165 | + ) |
| 3166 | + |
| 3167 | + |
3088 | 3168 | def test_fixed_angle_sim():
|
3089 | 3169 | wvl_um = 1.0
|
3090 | 3170 | freq0 = td.C_0 / wvl_um
|
|
0 commit comments