Skip to content

Commit e2f5f94

Browse files
authored
Merge pull request ComputationalRadiationPhysics#5425 from PrometheusPi/add_check_picmi_laser_origin_focus_direction
add test to picmi Gauss laser
2 parents 609a12d + a0c03fc commit e2f5f94

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/python/picongpu/picmi/gaussian_laser.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ def scalarProduct(self, a: typing.List[float], b: typing.List[float]) -> float:
2929

3030
return result
3131

32+
def crossProduct(self, a: typing.List[float], b: typing.List[float]) -> typing.List[float]:
33+
assert len(a) == len(b) == 3, "the cross product is only defined for 3d vectors"
34+
return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
35+
36+
def difference(self, a: typing.List[float], b: typing.List[float]) -> typing.List[float]:
37+
assert len(a) == len(b), "the difference between two vectors is only defined if they have the same length"
38+
result = []
39+
for i in range(len(a)):
40+
result.append(a[i] - b[i])
41+
return result
42+
3243
@staticmethod
3344
def testRelativeError(trueValue, testValue, relativeErrorLimit):
3445
return abs((testValue - trueValue) / trueValue) < relativeErrorLimit
@@ -140,6 +151,14 @@ def get_as_pypicongpu(self) -> laser.GaussianLaser:
140151
1e-9,
141152
), "polarization vector must be normalized"
142153

154+
# check that propagation_direction is parallel to the difference of focal_position and centroid_position
155+
diff_vec = self.difference(self.focal_position, self.centroid_position)
156+
cross_vec = self.crossProduct(diff_vec, self.propagation_direction)
157+
length_of_cross_product = self.scalarProduct(cross_vec, cross_vec)
158+
159+
assert length_of_cross_product < 1e-5, "propagation_direction must connect centroid_position and focus_position"
160+
del (diff_vec, cross_vec, length_of_cross_product) # clean up
161+
143162
pypicongpu_laser = laser.GaussianLaser()
144163
pypicongpu_laser.wavelength = self.wavelength
145164
pypicongpu_laser.waist = self.waist

test/python/picongpu/quick/picmi/gaussian_laser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_basic(self):
2222
propagation_direction=[0, 1, 0],
2323
polarization_direction=[0, 0, 1],
2424
focal_position=[5, 4, 5],
25-
centroid_position=[0, 0, 0],
25+
centroid_position=[5, 0, 5],
2626
E0=5,
2727
picongpu_laguerre_modes=[2.0, 3.0],
2828
picongpu_laguerre_phases=[4.0, 5.0],
@@ -76,7 +76,7 @@ def test_values_focal_pos(self):
7676
2,
7777
3,
7878
focal_position=[1, 2, -5],
79-
centroid_position=[0.5, 0, 0.5],
79+
centroid_position=[1, 0, -5],
8080
propagation_direction=[0, 1, 0],
8181
polarization_direction=[1, 0, 0],
8282
E0=1,

0 commit comments

Comments
 (0)