aboutsummaryrefslogtreecommitdiff
path: root/Examples/Tests/collision/analysis_collision_rz.py
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/Tests/collision/analysis_collision_rz.py')
-rwxr-xr-xExamples/Tests/collision/analysis_collision_rz.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Examples/Tests/collision/analysis_collision_rz.py b/Examples/Tests/collision/analysis_collision_rz.py
new file mode 100755
index 000000000..82b2e6da7
--- /dev/null
+++ b/Examples/Tests/collision/analysis_collision_rz.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+# Copyright 2019-2021 Yinjian Zhao
+#
+# This file is part of WarpX.
+#
+# License: BSD-3-Clause-LBNL
+
+# This script tests the collision module in RZ.
+# Electrons are set with the same vr,
+# and thus particles are traveling locally in the same direction.
+# Physically, the collision rate should therefore be very low.
+# Thus the initial electron momentum will be compared with the final momentum.
+
+# Possible errors:
+# tolerance: 1.0e-30
+# Possible running time: ~ 1.0 s
+
+import os
+import sys
+import yt
+import numpy as np
+from glob import glob
+sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
+import checksumAPI
+
+tolerance = 1.0e-15
+
+last_fn = sys.argv[1]
+if (last_fn[-1] == "/"): last_fn = last_fn[:-1]
+fn_list = glob(last_fn[:-5] + "?????")
+
+for fn in fn_list:
+ # get time index j
+ j = int(fn[-5:])
+ if j==0:
+ # load file
+ ds = yt.load( fn )
+ ad = ds.all_data()
+ px1 = ad['particle_momentum_x'].to_ndarray()
+ py1 = ad['particle_momentum_y'].to_ndarray()
+ if j==150:
+ # load file
+ ds = yt.load( fn )
+ ad = ds.all_data()
+ px2 = ad['particle_momentum_x'].to_ndarray()
+ py2 = ad['particle_momentum_y'].to_ndarray()
+
+error = np.max( abs(px1-px2)+abs(py1-py2) )
+
+print('error = ', error)
+print('tolerance = ', tolerance)
+assert(error < tolerance)
+
+test_name = os.path.split(os.getcwd())[1]
+checksumAPI.evaluate_checksum(test_name, fn, do_particles=False)