|
1 | 1 | """Defines specification for mode solver."""
|
2 | 2 |
|
3 | 3 | from typing import Tuple, Union
|
| 4 | +from math import isclose |
4 | 5 |
|
5 | 6 | import pydantic.v1 as pd
|
6 | 7 | import numpy as np
|
@@ -77,7 +78,7 @@ class ModeSpec(Tidy3dBaseModel):
|
77 | 78 | "single precision, but more accurate under double precision.",
|
78 | 79 | )
|
79 | 80 |
|
80 |
| - bend_radius: pd.PositiveFloat = pd.Field( |
| 81 | + bend_radius: float = pd.Field( |
81 | 82 | None,
|
82 | 83 | title="Bend radius",
|
83 | 84 | description="A curvature radius for simulation of waveguide bends. Can be negative, in "
|
@@ -115,9 +116,16 @@ class ModeSpec(Tidy3dBaseModel):
|
115 | 116 |
|
116 | 117 | @pd.validator("bend_axis", always=True)
|
117 | 118 | def bend_axis_given(cls, val, values):
|
118 |
| - """check that ``bend_axis`` is provided if ``bend_radius`` is not ``None``""" |
| 119 | + """Check that ``bend_axis`` is provided if ``bend_radius`` is not ``None``""" |
119 | 120 | if val is None and values.get("bend_radius") is not None:
|
120 |
| - raise SetupError("bend_axis must also be defined if bend_radius is defined.") |
| 121 | + raise SetupError("'bend_axis' must also be defined if 'bend_radius' is defined.") |
| 122 | + return val |
| 123 | + |
| 124 | + @pd.validator("bend_radius", always=True) |
| 125 | + def bend_radius_not_zero(cls, val, values): |
| 126 | + """Check that ``bend_raidus`` magnitude is not close to zero.`""" |
| 127 | + if val and isclose(val, 0): |
| 128 | + raise SetupError("The magnitude of 'bend_radius' must be larger than 0.") |
121 | 129 | return val
|
122 | 130 |
|
123 | 131 | @pd.validator("angle_theta", allow_reuse=True, always=True)
|
|
0 commit comments