aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Edoardo Zoni <59625522+EZoni@users.noreply.github.com> 2022-03-28 23:10:07 -0700
committerGravatar GitHub <noreply@github.com> 2022-03-28 23:10:07 -0700
commitbbe815dbd39dbd6066d43c75c798036c2059eb7e (patch)
treebcbc6e32b93643416ebea2467811709bb03c5975
parent2636b6b318fa0e4e14e7ea3c511722da4e8398e1 (diff)
downloadWarpX-bbe815dbd39dbd6066d43c75c798036c2059eb7e.tar.gz
WarpX-bbe815dbd39dbd6066d43c75c798036c2059eb7e.tar.zst
WarpX-bbe815dbd39dbd6066d43c75c798036c2059eb7e.zip
Langmuir 3D Tests: Better Analysis Plots (#2999)
-rwxr-xr-xExamples/Tests/Langmuir/analysis_langmuir_multi.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/Examples/Tests/Langmuir/analysis_langmuir_multi.py b/Examples/Tests/Langmuir/analysis_langmuir_multi.py
index 04ed86d98..c2ed0830a 100755
--- a/Examples/Tests/Langmuir/analysis_langmuir_multi.py
+++ b/Examples/Tests/Langmuir/analysis_langmuir_multi.py
@@ -17,10 +17,8 @@ import os
import re
import sys
-import matplotlib
-
-matplotlib.use('Agg')
import matplotlib.pyplot as plt
+from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
import yt
yt.funcs.mylog.setLevel(50)
@@ -105,30 +103,42 @@ for field in ['particle_momentum_x',
assert (species, field) not in ds.field_list
t0 = ds.current_time.to_value()
-data = ds.covering_grid(level=0, left_edge=ds.domain_left_edge,
- dims=ds.domain_dimensions)
+data = ds.covering_grid(level = 0, left_edge = ds.domain_left_edge, dims = ds.domain_dimensions)
+edge = np.array([(ds.domain_left_edge[2]).item(), (ds.domain_right_edge[2]).item(), \
+ (ds.domain_left_edge[0]).item(), (ds.domain_right_edge[0]).item()])
# Check the validity of the fields
error_rel = 0
for field in ['Ex', 'Ey', 'Ez']:
E_sim = data[('mesh',field)].to_ndarray()
-
E_th = get_theoretical_field(field, t0)
max_error = abs(E_sim-E_th).max()/abs(E_th).max()
print('%s: Max error: %.2e' %(field,max_error))
error_rel = max( error_rel, max_error )
# Plot the last field from the loop (Ez at iteration 40)
-plt.subplot2grid( (1,2), (0,0) )
-plt.imshow( E_sim[:,:,Ncell[2]//2] )
-plt.colorbar()
-plt.title('Ez, last iteration\n(simulation)')
-plt.subplot2grid( (1,2), (0,1) )
-plt.imshow( E_th[:,:,Ncell[2]//2] )
-plt.colorbar()
-plt.title('Ez, last iteration\n(theory)')
-plt.tight_layout()
-plt.savefig('langmuir_multi_analysis.png')
+fig, (ax1, ax2) = plt.subplots(1, 2, dpi = 100)
+vmin = min(E_sim.min(), E_th.min())
+vmax = max(E_sim.max(), E_th.max())
+# First plot
+cax1 = make_axes_locatable(ax1).append_axes('right', size = '5%', pad = '5%')
+# Plot slice at y=0
+im1 = ax1.imshow(E_sim[:,Ncell[1]//2+1,:], origin = 'lower', extent = edge, vmin = vmin, vmax = vmax)
+cb1 = fig.colorbar(im1, cax = cax1)
+ax1.set_xlabel(r'$z$')
+ax1.set_ylabel(r'$x$')
+ax1.set_title(r'$E_z$ (sim)')
+# Second plot
+cax2 = make_axes_locatable(ax2).append_axes('right', size = '5%', pad = '5%')
+# Plot slice at y=0
+im2 = ax2.imshow(E_th[:,Ncell[1]//2+1,:], origin = 'lower', extent = edge, vmin = vmin, vmax = vmax)
+cb2 = fig.colorbar(im2, cax = cax2)
+ax2.set_xlabel(r'$z$')
+ax2.set_ylabel(r'$x$')
+ax2.set_title(r'$E_z$ (theory)')
+# Save figure
+fig.tight_layout()
+fig.savefig('Langmuir_multi_analysis.png', dpi = 200)
tolerance_rel = 0.15