Skip to content

Commit 3effb92

Browse files
marc-flexmomchil-flex
authored andcommitted
Add check for conduction
1 parent 64455ff commit 3effb92

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- `ModeSimulation.plot()` method that plots the mode simulation plane by default, or the containing FDTD simulation if any of ``x``, ``y``, or ``z`` is passed.
2222
- Enable singularity correction at PEC and lossy metal edges.
2323
- New `VolumeMesher` simulation type and associated `VolumeMeshMonitor` and `VolumeMesherData`, which can be used to run the unstructured meshing for a `HeatChargeSimulation` separately before running the solver.
24+
- The current validator for Conduction simulations has been modified so that it checks that in a Conduction simulation there is at least one structure defined with `ChargeConductorMedium` in the `charge` field of a `MultiPhysicsMedium`. This is necessary to ensure simulations are properly set up in the back-end since it relies on the `conductivity` field of `ChargeConductorMedium` and not that of `Medium`.
2425

2526
### Changed
2627
- Switched to an analytical gradient calculation for spatially-varying pole-residue models (`CustomPoleResidue`).

tests/test_components/test_heat_charge.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ def place_box(center_offset):
13641364
structures=[
13651365
td.Structure(
13661366
geometry=td.Box(size=(1, 1, 1), center=shifted_center),
1367-
medium=td.Medium(),
1367+
medium=td.MultiPhysicsMedium(charge=td.ChargeConductorMedium(conductivity=1)),
13681368
)
13691369
],
13701370
boundary_spec=[
@@ -1409,7 +1409,10 @@ def place_box(center_offset):
14091409
)
14101410
def test_sim_structure_extent(box_size, log_level):
14111411
"""Ensure we warn if structure extends exactly to simulation edges."""
1412-
box = td.Structure(geometry=td.Box(size=box_size), medium=td.Medium(permittivity=2))
1412+
box = td.Structure(
1413+
geometry=td.Box(size=box_size),
1414+
medium=td.MultiPhysicsMedium(charge=td.ChargeConductorMedium(conductivity=1)),
1415+
)
14131416

14141417
with AssertLogLevel(log_level):
14151418
_ = td.HeatChargeSimulation(
@@ -2040,3 +2043,15 @@ def test_heat_conduction_simulations():
20402043
with pytest.raises(pd.ValidationError):
20412044
# This should error since the conduction simulation doesn't have a monitor
20422045
_ = sim.updated_copy(monitors=[temp_monitor])
2046+
2047+
# test error if structures defined with Medium instead of MultiPhysicsMedium
2048+
with pytest.raises(pd.ValidationError):
2049+
struct_error = struct1.updated_copy(medium=td.Medium(conductivity=1))
2050+
_ = sim.updated_copy(structures=[struct_error])
2051+
2052+
# test error if structures aren't conducting
2053+
with pytest.raises(pd.ValidationError):
2054+
struct_error = struct1.updated_copy(
2055+
medium=struct1.medium.updated_copy(charge=td.ChargeInsulatorMedium)
2056+
)
2057+
_ = sim.updated_copy(structures=[struct_error])

tidy3d/components/tcad/simulation/heat_charge.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,19 @@ def check_conduction_sim(cls, values):
835835
"has been defined. This is not supported in Conduction simulations."
836836
)
837837

838+
# make sure that at least one structure has appropriate charge medium
839+
ValidConductionMediums = ChargeConductorMedium
840+
structures = values.get("structures")
841+
if all(isinstance(s.medium, Medium) for s in structures):
842+
raise SetupError(
843+
"Conduction simulations must be defined using 'MultiPhysicsMedium' but none have been defined."
844+
)
845+
if not any(isinstance(s.medium.charge, ValidConductionMediums) for s in structures):
846+
raise SetupError(
847+
"Conduction simulations require at least one structure with a 'ChargeConductorMedium' "
848+
"but none have been defined."
849+
)
850+
838851
return values
839852

840853
@pd.root_validator(skip_on_failure=True)

0 commit comments

Comments
 (0)