Skip to content

Commit 60cf9f1

Browse files
committed
Add tests
1 parent a1edefb commit 60cf9f1

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

tests/test_components/test_heat_charge.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -952,23 +952,30 @@ def Si_p(self):
952952
semiconductor = CHARGE_SIMULATION.intrinsic_Si.charge
953953
semiconductor = semiconductor.updated_copy(
954954
N_a=CHARGE_SIMULATION.acceptors,
955+
)
956+
return CHARGE_SIMULATION.intrinsic_Si.updated_copy(
957+
charge=semiconductor,
958+
heat=td.SolidMedium(conductivity=1),
955959
name="Si_p",
956960
)
957-
return CHARGE_SIMULATION.intrinsic_Si.updated_copy(charge=semiconductor)
958961

959962
@pytest.fixture(scope="class")
960963
def Si_n(self):
961964
semiconductor = CHARGE_SIMULATION.intrinsic_Si.charge
962965
semiconductor = semiconductor.updated_copy(
963966
N_d=CHARGE_SIMULATION.donors,
967+
)
968+
return CHARGE_SIMULATION.intrinsic_Si.updated_copy(
969+
charge=semiconductor,
970+
heat=td.SolidMedium(conductivity=1),
964971
name="Si_n",
965972
)
966-
return CHARGE_SIMULATION.intrinsic_Si.updated_copy(charge=semiconductor)
967973

968974
@pytest.fixture(scope="class")
969975
def SiO2(self):
970976
return td.MultiPhysicsMedium(
971977
charge=td.ChargeInsulatorMedium(permittivity=3.9),
978+
heat=td.SolidMedium(conductivity=2),
972979
name="SiO2",
973980
)
974981

@@ -1049,18 +1056,13 @@ def capacitance_global_mnt(self):
10491056
# Define charge settings as fixtures within the class
10501057
@pytest.fixture(scope="class")
10511058
def charge_tolerance(self):
1052-
return td.IsothermalSteadyChargeDCAnalysis(
1053-
temperature=300,
1054-
tolerance_settings=td.ChargeToleranceSpec(rel_tol=1e5, abs_tol=1e3, max_iters=400),
1055-
fermi_dirac=True,
1056-
)
1057-
1058-
@pytest.fixture(scope="class")
1059-
def charge_dc_regime(self):
1060-
return td.DCVoltageSource(voltage=[1])
1059+
return td.ChargeToleranceSpec(rel_tol=1e5, abs_tol=1e3, max_iters=400)
10611060

10621061
def test_charge_simulation(
10631062
self,
1063+
Si_n,
1064+
Si_p,
1065+
SiO2,
10641066
oxide,
10651067
p_side,
10661068
n_side,
@@ -1070,9 +1072,14 @@ def test_charge_simulation(
10701072
bc_n,
10711073
bc_p,
10721074
charge_tolerance,
1073-
charge_dc_regime,
10741075
):
10751076
"""Ensure charge simulation produces the correct errors when needed."""
1077+
# NOTE: start tests with isothermal spec
1078+
isothermal_spec = td.IsothermalSteadyChargeDCAnalysis(
1079+
temperature=300,
1080+
tolerance_settings=charge_tolerance,
1081+
fermi_dirac=True,
1082+
)
10761083
sim = td.HeatChargeSimulation(
10771084
structures=[oxide, p_side, n_side],
10781085
medium=td.MultiPhysicsMedium(
@@ -1083,7 +1090,7 @@ def test_charge_simulation(
10831090
size=CHARGE_SIMULATION.sim_size,
10841091
grid_spec=td.UniformUnstructuredGrid(dl=0.05),
10851092
boundary_spec=[bc_n, bc_p],
1086-
analysis_spec=charge_tolerance,
1093+
analysis_spec=isothermal_spec,
10871094
)
10881095

10891096
# At least one ChargeSimulationMonitor should be added
@@ -1118,6 +1125,35 @@ def test_charge_simulation(
11181125
)
11191126
_ = sim.updated_copy(boundary_spec=[new_bc_p, bc_n])
11201127

1128+
# test non isothermal spec
1129+
non_isothermal_spec = td.SteadyChargeDCAnalysis(tolerance_settings=charge_tolerance)
1130+
1131+
sim = sim.updated_copy(analysis_spec=non_isothermal_spec)
1132+
with pytest.raises(pd.ValidationError):
1133+
# remove heat from mediums
1134+
new_structs = []
1135+
for struct in sim.structures:
1136+
new_structs.append(
1137+
struct.updated_copy(medium=struct.medium.updated_copy(heat=None))
1138+
)
1139+
_ = sim.updated_copy(structures=new_structs)
1140+
1141+
with pytest.raises(pd.ValidationError):
1142+
# make sure there is at least one semiconductor
1143+
new_structs = []
1144+
for struct in sim.structures:
1145+
if isinstance(struct.medium.charge, td.SemiconductorMedium):
1146+
new_structs.append(
1147+
struct.updated_copy(
1148+
medium=struct.medium.updated_copy(
1149+
charge=td.ChargeInsulatorMedium(permittivity=1)
1150+
)
1151+
)
1152+
)
1153+
else:
1154+
new_structs.append(struct)
1155+
_ = sim.updated_copy(structures=new_structs)
1156+
11211157
def test_doping_distributions(self):
11221158
"""Test doping distributions."""
11231159
# Implementation needed

tidy3d/components/tcad/simulation/heat_charge.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,6 @@ def check_non_isothermal_is_possible(cls, values):
968968
has_elec = False
969969
structures = values.get("structures")
970970
for struct in structures:
971-
if isinstance(struct.medium, SolidMedium):
972-
if struct.medium.heat_spec is not None:
973-
has_heat = True
974-
if isinstance(struct.medium, SemiconductorMedium):
975-
has_elec = True
976971
if isinstance(struct.medium, MultiPhysicsMedium):
977972
if struct.medium.heat is not None:
978973
if isinstance(struct.medium.heat, SolidMedium):

0 commit comments

Comments
 (0)