Skip to content

Commit 5c63398

Browse files
committed
Allow bend_radius to be negative, but not close to zero
1 parent b3e4065 commit 5c63398

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tidy3d/components/mode.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Defines specification for mode solver."""
22

33
from typing import Tuple, Union
4+
from math import isclose
45

56
import pydantic.v1 as pd
67
import numpy as np
@@ -77,7 +78,7 @@ class ModeSpec(Tidy3dBaseModel):
7778
"single precision, but more accurate under double precision.",
7879
)
7980

80-
bend_radius: pd.PositiveFloat = pd.Field(
81+
bend_radius: float = pd.Field(
8182
None,
8283
title="Bend radius",
8384
description="A curvature radius for simulation of waveguide bends. Can be negative, in "
@@ -115,9 +116,16 @@ class ModeSpec(Tidy3dBaseModel):
115116

116117
@pd.validator("bend_axis", always=True)
117118
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``"""
119120
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.")
121129
return val
122130

123131
@pd.validator("angle_theta", allow_reuse=True, always=True)

0 commit comments

Comments
 (0)