diff options
Diffstat (limited to 'Examples')
-rwxr-xr-x | Examples/Tests/Langmuir/analysis_langmuir_multi_rz.py | 21 | ||||
-rwxr-xr-x | Examples/Tests/galilean/analysis_2d.py | 26 | ||||
-rw-r--r-- | Examples/Tests/galilean/inputs_rz | 78 |
3 files changed, 116 insertions, 9 deletions
diff --git a/Examples/Tests/Langmuir/analysis_langmuir_multi_rz.py b/Examples/Tests/Langmuir/analysis_langmuir_multi_rz.py index e98c24d7e..9e3942803 100755 --- a/Examples/Tests/Langmuir/analysis_langmuir_multi_rz.py +++ b/Examples/Tests/Langmuir/analysis_langmuir_multi_rz.py @@ -13,6 +13,7 @@ # $$ E_r = -\partial_r \phi = \epsilon \,\frac{mc^2}{e}\frac{2\,r}{w_0^2} \exp\left(-\frac{r^2}{w_0^2}\right) \sin(k_0 z) \sin(\omega_p t) # $$ E_z = -\partial_z \phi = - \epsilon \,\frac{mc^2}{e} k_0 \exp\left(-\frac{r^2}{w_0^2}\right) \cos(k_0 z) \sin(\omega_p t) import sys +import re import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt @@ -28,6 +29,9 @@ fn = sys.argv[1] test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1] +# Parse test name and check if current correction (psatd.current_correction) is applied +current_correction = True if re.search('current_correction', fn) else False + # Parameters (these parameters must match the parameters in `inputs.multi.rz.rt`) epsilon = 0.01 n = 2.e24 @@ -102,11 +106,26 @@ plt.tight_layout() plt.savefig(test_name+'_analysis.png') error_rel = overall_max_error -tolerance_rel = 0.04 + +if current_correction: + tolerance_rel = 0.06 +else: + tolerance_rel = 0.04 print("error_rel : " + str(error_rel)) print("tolerance_rel: " + str(tolerance_rel)) assert( error_rel < tolerance_rel ) +# Check charge conservation (relative L-infinity norm of error) with current correction +if current_correction: + divE = data['divE'].to_ndarray() + rho = data['rho' ].to_ndarray() / epsilon_0 + error_rel = np.amax(np.abs(divE - rho)) / max(np.amax(divE), np.amax(rho)) + tolerance = 1.e-9 + print("Check charge conservation:") + print("error_rel = {}".format(error_rel)) + print("tolerance = {}".format(tolerance)) + assert( error_rel < tolerance ) + checksumAPI.evaluate_checksum(test_name, fn) diff --git a/Examples/Tests/galilean/analysis_2d.py b/Examples/Tests/galilean/analysis_2d.py index e51689969..ac4ea2efd 100755 --- a/Examples/Tests/galilean/analysis_2d.py +++ b/Examples/Tests/galilean/analysis_2d.py @@ -27,6 +27,7 @@ filename = sys.argv[1] # Parse test name averaged = True if re.search( 'averaged', filename ) else False current_correction = True if re.search( 'current_correction', filename ) else False +dims_RZ = True if re.search('rz', filename) else False ds = yt.load( filename ) @@ -38,15 +39,24 @@ if (averaged): # energyE_ref was calculated with Galilean PSATD method (v_galilean = (0,0,0.99498743710662)) energyE_ref = 26913.546573259937 tolerance_rel = 1e-5 -elif (current_correction): +elif (not dims_RZ and not current_correction): + # energyE_ref was calculated with standard PSATD method (v_galilean = (0.,0.,0.)) + energyE_ref = 38362.88743899688 + tolerance_rel = 1e-8 +elif (not dims_RZ and current_correction): # energyE_ref was calculated with standard PSATD method (v_galilean = (0.,0.,0.)): - # difference with respect to reference energy below due to absence of filter + # difference with respect to reference energy above due to absence of real-space filter energyE_ref = 745973.5742103161 - tolerance_rel = 1e-8; -else: + tolerance_rel = 1e-8 +elif (dims_RZ and not current_correction): # energyE_ref was calculated with standard PSATD method (v_galilean = (0.,0.,0.)) - energyE_ref = 38362.88743899688 - tolerance_rel = 1e-8; + energyE_ref = 178013.54481470847 + tolerance_rel = 1e-8 +elif (dims_RZ and current_correction): + # energyE_ref was calculated with standard PSATD method (v_galilean = (0.,0.,0.)) + # difference with respect to reference energy above due to absence of k-space filter + energyE_ref = 10955626.277865639 + tolerance_rel = 1e-8 energyE = np.sum(scc.epsilon_0/2*(Ex**2+Ey**2+Ez**2)) @@ -59,9 +69,9 @@ assert( error_rel < tolerance_rel ) # Check charge conservation (relative L-infinity norm of error) with current correction if current_correction: - rho = ds.index.grids[0]['boxlib', 'rho' ].squeeze().v divE = ds.index.grids[0]['boxlib', 'divE'].squeeze().v - error_rel = np.amax( np.abs( divE - rho/scc.epsilon_0 ) ) / np.amax( np.abs( rho/scc.epsilon_0 ) ) + rho = ds.index.grids[0]['boxlib', 'rho' ].squeeze().v / scc.epsilon_0 + error_rel = np.amax(np.abs(divE - rho)) / max(np.amax(divE), np.amax(rho)) tolerance = 1e-9 print("Check charge conservation:") print("error_rel = {}".format(error_rel)) diff --git a/Examples/Tests/galilean/inputs_rz b/Examples/Tests/galilean/inputs_rz new file mode 100644 index 000000000..ceaba5af9 --- /dev/null +++ b/Examples/Tests/galilean/inputs_rz @@ -0,0 +1,78 @@ +################################# +####### GENERAL PARAMETERS ###### +################################# +max_step = 400 + +amr.n_cell = 64 128 +amr.max_grid_size = 128 +amr.blocking_factor = 128 +amr.max_level = 0 +psatd.v_galilean = 0. 0. 0.99498743710662 + +geometry.coord_sys = 1 +geometry.is_periodic = 0 1 +geometry.prob_lo = 0. -38.68 +geometry.prob_hi = 38.68 38.68 + +################################# +############ NUMERICS ########### +################################# +warpx.verbose = 1 + +algo.current_deposition = direct +algo.particle_pusher = vay + +warpx.cfl = 1. +interpolation.nox = 3 +interpolation.noy = 3 +interpolation.noz = 3 + + +################################# +############ PLASMA ############# +################################# +particles.species_names = electrons ions + +warpx.do_nodal = 1 +warpx.use_kspace_filter = 1 +warpx.do_pml = 0 + +psatd.nox = 16 +psatd.noy = 16 +psatd.noz = 16 + +electrons.charge = -q_e +electrons.mass = m_e +electrons.injection_style = "NUniformPerCell" +electrons.num_particles_per_cell_each_dim = 2 2 +electrons.profile = constant +electrons.density = 282197938148984.7 +electrons.momentum_distribution_type = "gaussian" +electrons.uz_m = 9.9498743710661994 +electrons.xmin = 0. +electrons.xmax = 38.68 +electrons.zmin = -38.68 +electrons.zmax = 38.68 +electrons.ux_th = 0.0001 +electrons.uz_th = 0.0001 + +ions.charge = q_e +ions.mass = m_p +ions.injection_style = "NUniformPerCell" +ions.num_particles_per_cell_each_dim = 2 2 +ions.profile = constant +ions.density = 282197938148984.7 +ions.momentum_distribution_type = "gaussian" +ions.uz_m = 9.9498743710661994 +ions.xmin = 0. +ions.xmax = 38.68 +ions.zmin = -38.68 +ions.zmax =38.68 +ions.ux_th = 0.0001 +ions.uz_th = 0.0001 + +# Diagnostics +diagnostics.diags_names = diag1 +diag1.period = 100 +diag1.diag_type = Full +diag1.fields_to_plot = Ex Ey Ez By jx jz rho divE |