aboutsummaryrefslogtreecommitdiff
path: root/Examples/Tests/collision/analysis_collision_rz.py
diff options
context:
space:
mode:
authorGravatar Yinjian Zhao <yinjianzhao@lbl.gov> 2021-12-06 14:14:32 -0700
committerGravatar GitHub <noreply@github.com> 2021-12-06 13:14:32 -0800
commit713f5aed32d052e60307c79d7f5dace7b96bb6f5 (patch)
treeb6b3eb1d27485fde0c0805abfccb63aeb19a666d /Examples/Tests/collision/analysis_collision_rz.py
parent4bc2f71bf27624e2bc2091e0c6eb53a4732274c1 (diff)
downloadWarpX-713f5aed32d052e60307c79d7f5dace7b96bb6f5.tar.gz
WarpX-713f5aed32d052e60307c79d7f5dace7b96bb6f5.tar.zst
WarpX-713f5aed32d052e60307c79d7f5dace7b96bb6f5.zip
Correct collision algorithm in RZ. (#2510)
* Add rotation. * Fix a small bug * Add automated test. * rename inputs_rz * Add json * minor * add comment. * Apply suggestions from code review Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja> * Update analysis_collision_rz.py * Fix missing import * Change tolerance. * Add warnings * Apply suggestions from code review * Move assert. * fix end-of-Line whitespaces. Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja> Co-authored-by: Remi Lehe <remi.lehe@normalesup.org>
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)