Skip to content

Commit

Permalink
added constant of large freq to evaluate eps_model(inf) at
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflex committed Apr 19, 2022
1 parent b28f8e2 commit aa49e12
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tidy3d/components/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
from .viz import add_ax_if_none
from .validators import validate_name_str
from ..constants import C_0, pec_val, EPSILON_0, HERTZ, CONDUCTIVITY, PERMITTIVITY, RADPERSEC
from ..constants import LARGE_NUMBER
from ..log import log, ValidationError

# evaluate frequency as this number (Hz) if inf
FREQ_EVAL_INF = 1e50


def ensure_freq_in_range(eps_model: Callable[[float], complex]) -> Callable[[float], complex]:
"""Decorate ``eps_model`` to log warning if frequency supplied is out of bounds."""

def _eps_model(self, frequency: float) -> complex:
"""New eps_model function."""

# evaluate infs and None as LARGE_NUMBER
if frequency is None or np.isinf(frequency):
frequency = LARGE_NUMBER
# evaluate infs and None as FREQ_EVAL_INF
is_inf_scalar = isinstance(frequency, float) and np.isinf(frequency)
if frequency is None or is_inf_scalar:
frequency = FREQ_EVAL_INF

if isinstance(frequency, np.ndarray):
frequency[np.where(np.isinf(frequency))] = LARGE_NUMBER
frequency[np.where(np.isinf(frequency))] = FREQ_EVAL_INF

# if frequency range not present just return original function
if self.frequency_range is None:
Expand Down

0 comments on commit aa49e12

Please sign in to comment.