Skip to content

Commit 4bbf0b9

Browse files
committed
added/updated unit tests for test_source.py
1 parent 324fb89 commit 4bbf0b9

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

tests/test_components/test_source.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,20 @@ def test_dipole():
148148
_ = td.PointDipole(size=(1, 1, 1), source_time=g, center=(1, 2, 3), polarization="Ex")
149149

150150

151-
def test_FieldSource():
151+
@pytest.mark.parametrize("swap_axes", [True, False])
152+
def test_FieldSource(swap_axes):
152153
g = td.GaussianPulse(freq0=1e12, fwidth=0.1e12)
153154
mode_spec = td.ModeSpec(num_modes=2)
154155

155156
# test we can make planewave
156-
_ = td.PlaneWave(size=(0, td.inf, td.inf), source_time=g, pol_angle=np.pi / 2, direction="+")
157-
# s.plot(y=0)
158-
# plt.close()
157+
s = td.PlaneWave(size=(0, td.inf, td.inf), source_time=g, pol_angle=np.pi / 2, direction="+")
158+
s.plot(y=0, swap_axes=swap_axes)
159+
plt.close()
159160

160161
# test we can make gaussian beam
161-
_ = td.GaussianBeam(size=(0, 1, 1), source_time=g, pol_angle=np.pi / 2, direction="+")
162-
# s.plot(y=0)
163-
# plt.close()
162+
s = td.GaussianBeam(size=(0, 1, 1), source_time=g, pol_angle=np.pi / 2, direction="+")
163+
s.plot(y=0, swap_axes=swap_axes)
164+
plt.close()
164165

165166
# test we can make an astigmatic gaussian beam
166167
_ = td.AstigmaticGaussianBeam(
@@ -173,11 +174,11 @@ def test_FieldSource():
173174
)
174175

175176
# test we can make mode source
176-
_ = td.ModeSource(
177+
s = td.ModeSource(
177178
size=(0, 1, 1), direction="+", source_time=g, mode_spec=mode_spec, mode_index=0
178179
)
179-
# s.plot(y=0)
180-
# plt.close()
180+
s.plot(y=0, swap_axes=swap_axes)
181+
plt.close()
181182

182183
# test that non-planar geometry crashes plane wave and gaussian beams
183184
with pytest.raises(pydantic.ValidationError):
@@ -203,10 +204,25 @@ def test_FieldSource():
203204
with pytest.raises(pydantic.ValidationError):
204205
_ = td.TFSF(size=(1, 1, 0), direction="+", source_time=g, injection_axis=2)
205206

206-
# s.plot(z=0)
207+
# s.plot(z=0, swap_axes=swap_axes)
207208
# plt.close()
208209

209210

211+
@pytest.mark.parametrize("swap_axes", [True, False])
212+
def test_current_source(swap_axes):
213+
L: float = 5.0
214+
source = td.UniformCurrentSource(
215+
center=(0, -L / 3, 0),
216+
size=(L, 0, L / 2),
217+
polarization="Ex",
218+
source_time=td.GaussianPulse(
219+
freq0=100e14,
220+
fwidth=10e14,
221+
),
222+
)
223+
source.plot(z=0, swap_axes=swap_axes)
224+
225+
210226
def test_pol_arrow():
211227
g = td.GaussianPulse(freq0=1e12, fwidth=0.1e12)
212228

0 commit comments

Comments
 (0)