45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import numpy
|
|
import pytest
|
|
|
|
from ..fdtd.misc import gaussian_beam, gaussian_packet, ricker_pulse
|
|
|
|
|
|
@pytest.mark.parametrize('one_sided', [False, True])
|
|
def test_gaussian_packet_accepts_array_input(one_sided: bool) -> None:
|
|
dt = 0.01
|
|
source, delay = gaussian_packet(1.55, 0.1, dt, one_sided=one_sided)
|
|
steps = numpy.array([0, int(numpy.ceil(delay / dt)) + 5])
|
|
envelope, cc, ss = source(steps)
|
|
assert isinstance(envelope, numpy.ndarray)
|
|
assert isinstance(cc, numpy.ndarray)
|
|
assert isinstance(ss, numpy.ndarray)
|
|
|
|
assert envelope.shape == (2,)
|
|
assert numpy.isfinite(envelope).all()
|
|
assert numpy.isfinite(cc).all()
|
|
assert numpy.isfinite(ss).all()
|
|
if one_sided:
|
|
assert envelope[-1] == pytest.approx(1.0)
|
|
|
|
|
|
def test_ricker_pulse_returns_finite_values() -> None:
|
|
source, delay = ricker_pulse(1.55, 0.01)
|
|
envelope, cc, ss = source(numpy.array([0, 1, 2]))
|
|
|
|
assert numpy.isfinite(delay)
|
|
assert numpy.isfinite(envelope).all()
|
|
assert numpy.isfinite(cc).all()
|
|
assert numpy.isfinite(ss).all()
|
|
|
|
|
|
def test_gaussian_beam_centered_grid_is_finite_and_normalized() -> None:
|
|
beam = gaussian_beam(
|
|
xyz=[numpy.linspace(-1, 1, 3), numpy.linspace(-1, 1, 3), numpy.linspace(-1, 1, 3)],
|
|
center=[0, 0, 0],
|
|
waist_radius=1.0,
|
|
wl=1.55,
|
|
)
|
|
|
|
row = beam[:, :, beam.shape[2] // 2]
|
|
assert numpy.isfinite(beam).all()
|
|
assert numpy.linalg.norm(row) == pytest.approx(1.0)
|