|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -from typing import Literal, TYPE_CHECKING, Union |
| 5 | +from typing import TYPE_CHECKING, Literal, Union |
6 | 6 |
|
7 | 7 | import numpy as np |
8 | 8 | import xarray as xr |
@@ -195,32 +195,32 @@ class GaussianDoping(AbstractDopingBox): |
195 | 195 | "are [``xmin``, ``xmax``, ``ymin``, ``ymax``, ``zmin``, ``zmax``]", |
196 | 196 | ) |
197 | 197 |
|
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: |
200 | 200 | """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 |
209 | 209 |
|
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: |
212 | 212 | """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 |
224 | 224 |
|
225 | 225 | @cached_property |
226 | 226 | def sigma(self) -> float: |
|
0 commit comments