45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import numpy
|
|
|
|
from ..fdmath import functional as fd_functional
|
|
from ..fdtd import base
|
|
from ._test_builders import real_ramp
|
|
from .utils import assert_close
|
|
|
|
|
|
DT = 0.25
|
|
SHAPE = (3, 2, 2, 2)
|
|
E_FIELD = real_ramp(SHAPE, scale=1 / 5)
|
|
H_FIELD = real_ramp(SHAPE, scale=1 / 7, offset=1 / 7)
|
|
EPSILON = 1.5 + E_FIELD / 10.0
|
|
MU_FIELD = 2.0 + H_FIELD / 8.0
|
|
MU_SCALAR = 3.0
|
|
|
|
|
|
def test_maxwell_e_without_dxes_matches_unit_spacing_update() -> None:
|
|
updater = base.maxwell_e(dt=DT)
|
|
expected = E_FIELD + DT * fd_functional.curl_back()(H_FIELD) / EPSILON
|
|
|
|
updated = updater(E_FIELD.copy(), H_FIELD.copy(), EPSILON)
|
|
|
|
assert_close(updated, expected)
|
|
|
|
|
|
def test_maxwell_h_without_dxes_and_without_mu_matches_unit_spacing_update() -> None:
|
|
updater = base.maxwell_h(dt=DT)
|
|
expected = H_FIELD - DT * fd_functional.curl_forward()(E_FIELD)
|
|
|
|
updated = updater(E_FIELD.copy(), H_FIELD.copy())
|
|
|
|
assert_close(updated, expected)
|
|
|
|
|
|
def test_maxwell_h_without_dxes_accepts_scalar_and_field_mu() -> None:
|
|
updater = base.maxwell_h(dt=DT)
|
|
|
|
updated_scalar = updater(E_FIELD.copy(), H_FIELD.copy(), MU_SCALAR)
|
|
expected_scalar = H_FIELD - DT * fd_functional.curl_forward()(E_FIELD) / MU_SCALAR
|
|
assert_close(updated_scalar, expected_scalar)
|
|
|
|
updated_field = updater(E_FIELD.copy(), H_FIELD.copy(), MU_FIELD)
|
|
expected_field = H_FIELD - DT * fd_functional.curl_forward()(E_FIELD) / MU_FIELD
|
|
assert_close(updated_field, expected_field)
|