Skip to content

Commit 5b7c11c

Browse files
marc-flexmomchil-flex
authored andcommitted
Added resistance calculation. Allowing ndarrays to be provided as voltage input
Array-like
1 parent ab44456 commit 5b7c11c

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

tests/test_components/test_heat_charge.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ def test_heat_charge_bcs_validation(boundary_conditions):
711711
with pytest.raises(pd.ValidationError):
712712
td.CurrentBC(source=td.DCCurrentSource(current=td.inf))
713713

714+
with pytest.raises(pd.ValidationError):
715+
td.VoltageBC(source=td.DCVoltageSource(voltage=np.array([td.inf, 0, 1])))
716+
714717

715718
def test_heat_charge_monitors_validation(monitors):
716719
"""Checks for no name and negative size in monitors."""
@@ -790,6 +793,7 @@ def test_device_characteristics():
790793
steady_dc_hole_capacitance=capacitance,
791794
steady_dc_electron_capacitance=capacitance,
792795
steady_dc_current_voltage=current_voltage,
796+
steady_dc_resistance_voltage=current_voltage,
793797
)
794798

795799

tidy3d/components/spice/sources/dc.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
2020
"""
2121

22-
from typing import Optional, Union
22+
from typing import Optional
2323

2424
import pydantic.v1 as pd
2525

2626
from tidy3d.components.base import Tidy3dBaseModel
27+
from tidy3d.components.types import ArrayFloat1D
2728
from tidy3d.constants import AMP, VOLT
29+
from tidy3d.constants import inf as td_inf
2830

2931

3032
class DCVoltageSource(Tidy3dBaseModel):
@@ -45,11 +47,19 @@ class DCVoltageSource(Tidy3dBaseModel):
4547
"""
4648

4749
name: Optional[str]
48-
voltage: Union[pd.FiniteFloat, list[pd.FiniteFloat]] = pd.Field(
50+
voltage: ArrayFloat1D = pd.Field(
51+
...,
4952
title="Voltage",
5053
description="DC voltage usually used as source in 'VoltageBC' boundary conditions.",
54+
units=VOLT,
5155
)
52-
units: str = VOLT
56+
57+
@pd.validator("voltage")
58+
def check_voltage(cls, val):
59+
for v in val:
60+
if v == td_inf:
61+
raise ValueError(f"Voltages must be finite. Currently voltage={val}.")
62+
return val
5363

5464

5565
class DCCurrentSource(Tidy3dBaseModel):

tidy3d/components/tcad/data/sim_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class DeviceCharacteristics(Tidy3dBaseModel):
7373
description="Device steady DC current-voltage relation for the device.",
7474
)
7575

76+
steady_dc_resistance_voltage: Optional[SteadyVoltageDataArray] = pd.Field(
77+
None,
78+
title="Small signal resistance",
79+
description="Steady DC computation of the small signal resistance. This is computed "
80+
"as the derivative of the current-voltage relation, delta(V)/delta(I) and the result "
81+
"is given in Ohms. Note that in 2D the resistance is given in :math:`\\Omega \\mu`.",
82+
)
83+
7684

7785
class HeatChargeSimulationData(AbstractSimulationData):
7886
"""Stores results of a :class:`HeatChargeSimulation`.

tidy3d/components/tcad/simulation/heat_charge.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,8 @@ def check_voltage_array_if_capacitance(cls, values):
434434
for bc in bounday_spec:
435435
if isinstance(bc.condition, VoltageBC):
436436
if isinstance(bc.condition.source, DCVoltageSource):
437-
if isinstance(bc.condition.source.voltage, list) or isinstance(
438-
bc.condition.source.voltage, tuple
439-
):
440-
if len(bc.condition.source.voltage) > 1:
441-
voltage_array_present = True
437+
if len(bc.condition.source.voltage) > 1:
438+
voltage_array_present = True
442439
if is_capacitance_mnt and not voltage_array_present:
443440
raise SetupError(
444441
"Monitors of type 'SteadyCapacitanceMonitor' have been defined but no array of voltages "
@@ -521,15 +518,14 @@ def check_only_one_voltage_array_provided(cls, val, values):
521518
if isinstance(bc.condition.source, DCVoltageSource):
522519
voltages = bc.condition.source.voltage
523520

524-
if isinstance(voltages, tuple):
525-
if len(voltages) > 1:
526-
if not array_already_provided:
527-
array_already_provided = True
528-
else:
529-
raise SetupError(
530-
"More than one voltage array has been provided. "
531-
"Currently voltage arrays are supported only for one of the BCs."
532-
)
521+
if len(voltages) > 1:
522+
if not array_already_provided:
523+
array_already_provided = True
524+
else:
525+
raise SetupError(
526+
"More than one voltage array has been provided. "
527+
"Currently voltage arrays are supported only for one of the BCs."
528+
)
533529
return val
534530

535531
@pd.root_validator(skip_on_failure=True)

0 commit comments

Comments
 (0)