Skip to content

Commit 026f415

Browse files
authored
Fix bug in definition of polar and azimuth angles of planewave wavevector and add test case for oblique incidence (#3013)
* fix bug in definition of polar and azimuth angles and add test case for oblique incidence * raise exception if polar_rad is greater than 90 degrees
1 parent b8de2ee commit 026f415

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

python/tests/test_planewave_1D.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ def planewave_in_vacuum(
2828
2929
Args:
3030
resolution_um: resolution of the grid (number of pixels per um).
31-
polar_rad: polar angle of the incident planewave. 0 is +x axis.
32-
azimuth_rad: azimuth angle of the incident planewave. 0 is +z axis.
31+
polar_rad: polar angle of the incident planewave in [0, π/2].
32+
0 is +z axis.
33+
azimuth_rad: azimuth angle of the incident planewave in [0, 2π].
34+
Rotation around the z axis. 0 is +x axis.
3335
cell_dim: dimension of the cell (1 or 3).
3436
yee_grid: whether the DFT fields are on a centered or Yee grid.
3537
"""
38+
if polar_rad > 0.5 * np.pi:
39+
raise ValueError("polar_rad must be less than π/2.")
40+
3641
print(
3742
f"Testing planewaves in vacuum using {cell_dim}D simulation and "
3843
f"{'yee' if yee_grid else 'centered'} grid..."
@@ -46,9 +51,9 @@ def planewave_in_vacuum(
4651

4752
wavelength_um = 1.0
4853
frequency = 1 / wavelength_um
49-
kx = frequency * np.sin(azimuth_rad) * np.cos(azimuth_rad)
50-
ky = frequency * np.sin(azimuth_rad) * np.sin(azimuth_rad)
51-
kz = frequency * np.cos(azimuth_rad)
54+
kx = frequency * np.sin(polar_rad) * np.cos(azimuth_rad)
55+
ky = frequency * np.sin(polar_rad) * np.sin(azimuth_rad)
56+
kz = frequency * np.cos(polar_rad)
5257

5358
if cell_dim == 1 and polar_rad != 0 and azimuth_rad != 0:
5459
raise ValueError("An oblique planewave cannot be simulated in 1D.")
@@ -145,11 +150,18 @@ def planewave_in_vacuum(
145150
print("PASSED.")
146151

147152
def test_planewave_1D(self):
148-
self.planewave_in_vacuum(400.0, 0.0, 0.0, 1, False)
149-
self.planewave_in_vacuum(200.0, 0.0, 0.0, 3, False)
150-
151-
self.planewave_in_vacuum(400.0, 0.0, 0.0, 1, True)
152-
self.planewave_in_vacuum(200.0, 0.0, 0.0, 3, True)
153+
# Case 1: normal incidence with k = (0, 0, kz).
154+
polar_rad = 0
155+
azimuth_rad = 0
156+
self.planewave_in_vacuum(400.0, polar_rad, azimuth_rad, 1, False)
157+
self.planewave_in_vacuum(200.0, polar_rad, azimuth_rad, 3, False)
158+
self.planewave_in_vacuum(400.0, polar_rad, azimuth_rad, 1, True)
159+
self.planewave_in_vacuum(200.0, polar_rad, azimuth_rad, 3, True)
160+
161+
# Case 2: oblique incidence with k = (kx, ky, kz).
162+
polar_rad = np.deg2rad(10.3)
163+
azimuth_rad = np.deg2rad(35.7)
164+
self.planewave_in_vacuum(200.0, polar_rad, azimuth_rad, 3, True)
153165

154166

155167
if __name__ == "__main__":

0 commit comments

Comments
 (0)