aboutsummaryrefslogtreecommitdiff
path: root/Examples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py
diff options
context:
space:
mode:
authorGravatar MaxThevenet <mthevenet@lbl.gov> 2019-08-21 13:38:25 -0700
committerGravatar GitHub <noreply@github.com> 2019-08-21 13:38:25 -0700
commit37c107f2d44ea2a2f7b1dbaa1205e1c008e26e6d (patch)
treeb42a50ecf72f677a16b9d5271809fc856d70168b /Examples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py
parentbc9bf550d8259c1295ce419f359e14ab34e7b13e (diff)
parent74b76124e2171249c2e7e98bb73a4322b7a13ec9 (diff)
downloadWarpX-37c107f2d44ea2a2f7b1dbaa1205e1c008e26e6d.tar.gz
WarpX-37c107f2d44ea2a2f7b1dbaa1205e1c008e26e6d.tar.zst
WarpX-37c107f2d44ea2a2f7b1dbaa1205e1c008e26e6d.zip
Merge pull request #273 from ECP-WarpX/rigid_test
Automated tests for rigid injection
Diffstat (limited to 'Examples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py')
-rwxr-xr-xExamples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/Examples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py b/Examples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py
new file mode 100755
index 000000000..86214ad72
--- /dev/null
+++ b/Examples/Modules/RigidInjection/analysis_rigid_injection_LabFrame.py
@@ -0,0 +1,70 @@
+#! /usr/bin/env python
+
+'''
+Analysis script of a WarpX simulation of rigid injection.
+
+A Gaussian electron beam starts from -5 microns, propagates rigidly up to
+20 microns after which it expands due to emittance only (the focal position is
+20 microns). The beam width is measured after ~50 microns, and compared with
+the theory (with a 5% error allowed).
+
+As a help to the user, the script also compares beam width to the theory in
+case rigid injection is OFF (i.e., the beam starts expanding from -5 microns),
+in which case a warning is raised.
+'''
+
+import sys
+import yt
+import numpy as np
+import scipy.constants as scc
+yt.funcs.mylog.setLevel(0)
+
+filename = sys.argv[1]
+
+# WarpX headers include more data when rigid injection is used,
+# which gives an error with the last yt release.
+# To avoid this issue, the three last lines of WarpXHeader are removed if
+# needed.
+def remove_rigid_lines(plotfile, nlines_if_rigid):
+ header_name = plotfile + '/WarpXHeader'
+ f = open(header_name, 'r')
+ file_lines = f.readlines()
+ nlines = len(file_lines)
+ f.close()
+ if nlines == nlines_if_rigid:
+ f = open(header_name, 'w')
+ f.writelines(file_lines[:-3])
+ f.close()
+
+# Remove rigid injection header lines
+remove_rigid_lines(filename, 18)
+# Read beam parameters
+ds = yt.load( filename )
+ad = ds.all_data()
+# Beam longitudinal position
+z = np.mean(ad['beam', 'particle_position_y'].v)
+# Beam width
+w = np.std(ad['beam', 'particle_position_x'].v)
+
+# initial parameters
+z0 = 20.e-6
+z0_no_rigid = -5.e-6
+w0 = 1.e-6
+theta0 = np.arcsin(0.1)
+
+# Theoretical beam width after propagation if rigid OFF
+# Inform the user if rigid injection simply off (just to be kind)
+wth_no_rigid = np.sqrt( w0**2 + (z-z0_no_rigid)**2*theta0**2 )
+error_no_rigid = np.abs((w-wth_no_rigid)/wth_no_rigid)
+if ( error_no_rigid < 0.05):
+ print("error no rigid: " + str(error_no_rigid))
+ print("Looks like the beam defocuses as if rigid injection were OFF")
+
+# Theoretical beam width after propagation if rigid ON
+wth = np.sqrt( w0**2 + (z-z0)**2*theta0**2 )
+error = np.abs((w-wth)/wth)
+# Print error and assert small error
+print("Beam position: " + str(z))
+print("Beam width : " + str(w))
+print("error: " + str(error))
+assert( error < 0.05 )
='fix/multi-images'>fix/multi-images Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/examples/minimal/.stackblitzrc (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2022-05-11Fix APIRoute type (#3344)Gravatar Matthew Phillips 3-11/+8
* Fix APIRoute type * Adds a changeset * Update usage of the two API route signatures
2022-05-11[create-astro] Finalize developer experience... with gradients 🚀 (#3313)Gravatar Ben Holmes 5-23/+123
* wip: port gradient helpers from sandbox ideas * feat: wire up rocket gradient 🚀 * feat: wire up rocket gradient on install step * refactor: update "next steps" wording * deps: add chalk (for rendering gradient) * chore: changeset * chore: clean up sstray template string