Skip to content

Commit

Permalink
Resetting charge buffers to zero. (#4916)
Browse files Browse the repository at this point in the history
* Resetting charge buffers to zero.

* Cleaning up: added braces.

* Added CI test ElectrostaticSphereLabFrame_MR_emass_10 (with large particle's mass).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Reverted ES sphere input script.

* Docs: Fix PASC Paper Formatting

* Highlights: Fix Formatting Issue

Render issue in RST in PASC24 entry.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated benchmarks for ElectrostaticSphereLabFrame_MR_emass_10.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
3 people authored May 12, 2024
1 parent e6c1eb5 commit 02f3897
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
inverse t(r) can be solved for exactly.
"""
import os
import re
import sys

import numpy as np
Expand All @@ -36,6 +37,15 @@
ds = yt.load( filename )
t_max = ds.current_time.item() # time of simulation

# Parse test name and check if particle_shape = 4 is used
emass_10 = True if re.search('emass_10', filename) else False

if emass_10:
l2_tolerance = 0.096
m_e = 10
else:
l2_tolerance = 0.05
m_e = 9.10938356e-31 #Electron mass in kg
ndims = np.count_nonzero(ds.domain_dimensions > 1)

if ndims == 2:
Expand All @@ -60,7 +70,6 @@

# Constants
eps_0 = 8.8541878128e-12 #Vacuum Permittivity in C/(V*m)
m_e = 9.10938356e-31 #Electron mass in kg
q_e = -1.60217662e-19 #Electron charge in C
pi = np.pi #Circular constant of the universe
r_0 = 0.1 #Initial radius of sphere
Expand Down Expand Up @@ -134,9 +143,9 @@ def calculate_error(E_axis, xmin, dx, nx):
print("L2 error along y-axis = %s" %L2_error_y)
print("L2 error along z-axis = %s" %L2_error_z)

assert L2_error_x < 0.05
assert L2_error_y < 0.05
assert L2_error_z < 0.05
assert L2_error_x < l2_tolerance
assert L2_error_y < l2_tolerance
assert L2_error_z < l2_tolerance

# Check conservation of energy
def return_energies(iteration):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"lev=0": {
"Ex": 7.110909624093144,
"Ey": 7.110909624093145,
"Ez": 7.110909624093143,
"rho": 0.0
},
"lev=1": {
"Ex": 14.281015560380963,
"Ey": 14.281015560380965,
"Ez": 14.281015560380965,
"rho": 2.6092568008333786e-10
},
"electron": {
"particle_momentum_x": 1.80842228672388e-24,
"particle_momentum_y": 1.8084222867238806e-24,
"particle_momentum_z": 1.7598771525647628e-24,
"particle_position_x": 327.46875,
"particle_position_y": 327.46875,
"particle_position_z": 327.46875,
"particle_weight": 6212.501525878906
}
}
17 changes: 17 additions & 0 deletions Regression/WarpX-tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,23 @@ doVis = 0
compareParticles = 0
analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py

[ElectrostaticSphereLabFrame_MR_emass_10]
buildDir = .
inputFile = Examples/Tests/electrostatic_sphere/inputs_3d
runtime_params = warpx.do_electrostatic=labframe diag2.electron.variables=ux uy uz w warpx.abort_on_warning_threshold=medium electron.mass = 10 amr.max_level = 1 amr.ref_ratio_vect = 2 2 2 warpx.fine_tag_lo = -0.5 -0.5 -0.5 warpx.fine_tag_hi = 0.5 0.5 0.5 max_step = 2
dim = 3
addToCompileString =
cmakeSetupOpts = -DWarpX_DIMS=3
restartTest = 0
useMPI = 1
numprocs = 2
useOMP = 1
numthreads = 1
compileTest = 0
doVis = 0
compareParticles = 0
analysisRoutine = Examples/Tests/electrostatic_sphere/analysis_electrostatic_sphere.py

[ElectrostaticSphereEB]
buildDir = .
inputFile = Examples/Tests/electrostatic_sphere_eb/inputs_3d
Expand Down
16 changes: 14 additions & 2 deletions Source/FieldSolver/ElectrostaticSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@ WarpX::AddSpaceChargeField (WarpXParticleContainer& pc)
pc.DepositCharge(rho, local, reset, apply_boundary_and_scale_volume,
interpolate_across_levels);
}

for (int lev = 0; lev <= max_level; lev++) {
if (lev > 0) {
if (charge_buf[lev]) {
charge_buf[lev]->setVal(0.);
}
}
}
SyncRho(rho, rho_coarse, charge_buf); // Apply filter, perform MPI exchange, interpolate across levels

// Get the particle beta vector
Expand Down Expand Up @@ -239,7 +245,13 @@ WarpX::AddSpaceChargeFieldLabFrame ()
int const lev = 0;
myfl->DepositCharge( lev, *rho_fp[lev] );
}

for (int lev = 0; lev <= max_level; lev++) {
if (lev > 0) {
if (charge_buf[lev]) {
charge_buf[lev]->setVal(0.);
}
}
}
SyncRho(rho_fp, rho_cp, charge_buf); // Apply filter, perform MPI exchange, interpolate across levels
#ifndef WARPX_DIM_RZ
for (int lev = 0; lev <= finestLevel(); lev++) {
Expand Down

0 comments on commit 02f3897

Please sign in to comment.