Skip to content

Commit 8ea5989

Browse files
committed
final rebase changes
1 parent 24520c2 commit 8ea5989

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

tests/test_components/test_heat_charge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ def test_gaussian_doping_sigma_calculation():
19271927
expected_sigma = np.sqrt(-(0.1**2) / (2 * np.log(1e15 / 1e18)))
19281928
assert np.isclose(box.sigma, expected_sigma), "Sigma calculation is incorrect."
19291929

1930-
with pytest.raises(pd.ValidationError, match="must be less than.*concentration"):
1930+
with pytest.raises(ValidationError, match="must be less than.*concentration"):
19311931
_ = td.GaussianDoping(
19321932
size=(1, 1, 1), ref_con=1e19, concentration=1e18, width=0.1, source="xmin"
19331933
)
@@ -1988,7 +1988,7 @@ def test_gaussian_doping_validator_source():
19881988
size=(1, 1, 1), ref_con=1e15, concentration=1e18, width=0.1, source=source
19891989
)
19901990

1991-
with pytest.raises(pd.ValidationError):
1991+
with pytest.raises(ValidationError):
19921992
_ = td.GaussianDoping(
19931993
size=(1, 1, 1), ref_con=1e15, concentration=1e18, width=0.1, source="invalid"
19941994
)

tidy3d/components/tcad/doping.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Literal, TYPE_CHECKING, Union
5+
from typing import TYPE_CHECKING, Literal, Union
66

77
import numpy as np
88
import xarray as xr
@@ -195,32 +195,32 @@ class GaussianDoping(AbstractDopingBox):
195195
"are [``xmin``, ``xmax``, ``ymin``, ``ymax``, ``zmin``, ``zmax``]",
196196
)
197197

198-
@pd.validator("concentration")
199-
def _validate_ref_con_less_than_concentration(cls, val, values):
198+
@model_validator(mode="after")
199+
def _validate_ref_con_less_than_concentration(self: Self) -> Self:
200200
"""Ensure ref_con < concentration to avoid negative sqrt in sigma calculation."""
201-
if "ref_con" in values:
202-
if values["ref_con"] >= val:
203-
raise ValueError(
204-
f"'ref_con' ({values['ref_con']}) must be less than 'concentration' ({val}) "
205-
"for GaussianDoping. The reference concentration at the edges must be lower "
206-
"than the peak concentration at the center."
207-
)
208-
return val
201+
val = self.concentration
202+
if self.ref_con >= val:
203+
raise ValueError(
204+
f"'ref_con' ({self.ref_con}) must be less than 'concentration' ({val}) "
205+
"for GaussianDoping. The reference concentration at the edges must be lower "
206+
"than the peak concentration at the center."
207+
)
208+
return self
209209

210-
@pd.validator("width")
211-
def _validate_width_vs_size(cls, val, values):
210+
@model_validator(mode="after")
211+
def _validate_width_vs_size(self: Self) -> Self:
212212
"""Warn if box size may be too small for the specified transition width."""
213-
if "size" in values:
214-
size = values["size"]
215-
for i, s in enumerate(size):
216-
if not np.isinf(s) and s < 2 * val:
217-
dim_name = ["x", "y", "z"][i]
218-
log.warning(
219-
f"Box size in '{dim_name}' direction ({s} μm) is less than "
220-
f"'2*width' ({2 * val} μm) for 'GaussianDoping'. "
221-
"This may result in unexpected behavior in the transition region."
222-
)
223-
return val
213+
val = self.width
214+
size = self.size
215+
for i, s in enumerate(size):
216+
if not np.isinf(s) and s < 2 * val:
217+
dim_name = ["x", "y", "z"][i]
218+
log.warning(
219+
f"Box size in '{dim_name}' direction ({s} μm) is less than "
220+
f"'2*width' ({2 * val} μm) for 'GaussianDoping'. "
221+
"This may result in unexpected behavior in the transition region."
222+
)
223+
return self
224224

225225
@cached_property
226226
def sigma(self) -> float:

0 commit comments

Comments
 (0)