Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 28, 2024
1 parent 2c50d64 commit d4c79c6
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions Examples/Tests/langmuir/analysis_rcylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import matplotlib

matplotlib.use('Agg')
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import yt

Expand All @@ -27,7 +27,7 @@
import numpy as np
from scipy.constants import c, e, epsilon_0, m_e

sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
sys.path.insert(1, "../../../../warpx/Regression/Checksum/")
import checksumAPI

# this will be the name of the plot file
Expand All @@ -36,56 +36,69 @@
test_name = 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
current_correction = True if re.search("current_correction", fn) else False

# Parameters (these parameters must match the parameters in `inputs_rcylinder`)
epsilon = 0.01
n = 2.e24
w0 = 5.e-6
rmin = 0e-6; rmax = 20.e-6; Nr = 64
n = 2.0e24
w0 = 5.0e-6
rmin = 0e-6
rmax = 20.0e-6
Nr = 64

# Plasma frequency
wp = np.sqrt((n*e**2)/(m_e*epsilon_0))
kp = wp/c
wp = np.sqrt((n * e**2) / (m_e * epsilon_0))
kp = wp / c

def Er( r, epsilon, w0, wp, t) :

def Er(r, epsilon, w0, wp, t):
"""
Return the radial electric field as an array
of the same length as r, in the half-plane theta=0
"""
Er_array = \
epsilon * m_e*c**2/e * 2*r/w0**2 * \
np.exp( -r**2/w0**2 ) * np.sin( wp*t )
return( Er_array )
Er_array = (
epsilon
* m_e
* c**2
/ e
* 2
* r
/ w0**2
* np.exp(-(r**2) / w0**2)
* np.sin(wp * t)
)
return Er_array


# Read the file
ds = yt.load(fn)
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
)

# Get cell centered coordinates
dr = (rmax - rmin)/Nr
coords = np.indices([Nr],'d')
rr = rmin + (coords[0] + 0.5)*dr
dr = (rmax - rmin) / Nr
coords = np.indices([Nr], "d")
rr = rmin + (coords[0] + 0.5) * dr

# Check the validity of the fields
overall_max_error = 0
Er_sim = data[('boxlib','Er')].to_ndarray()[:,0,0]
Er_sim = data[("boxlib", "Er")].to_ndarray()[:, 0, 0]
Er_th = Er(rr, epsilon, w0, wp, t0)
max_error = abs(Er_sim - Er_th).max()/abs(Er_th).max()
print('Er: Max error: %.2e' %(max_error))
overall_max_error = max( overall_max_error, max_error )
max_error = abs(Er_sim - Er_th).max() / abs(Er_th).max()
print("Er: Max error: %.2e" % (max_error))
overall_max_error = max(overall_max_error, max_error)

# Plot the last field from the loop (Er at iteration 40)
plt.subplot2grid((1,2), (0,0))
plt.subplot2grid((1, 2), (0, 0))
plt.plot(rr, Er_sim)
plt.title('Er, last iteration\n(simulation)')
plt.subplot2grid( (1,2), (0,1) )
plt.title("Er, last iteration\n(simulation)")
plt.subplot2grid((1, 2), (0, 1))
plt.plot(rr, Er_th)
plt.title('Er, last iteration\n(theory)')
plt.title("Er, last iteration\n(theory)")
plt.tight_layout()
plt.savefig(test_name+'_analysis.png')
plt.savefig(test_name + "_analysis.png")

error_rel = overall_max_error

Expand All @@ -94,6 +107,6 @@ def Er( r, epsilon, w0, wp, t) :
print("error_rel : " + str(error_rel))
print("tolerance_rel: " + str(tolerance_rel))

assert( error_rel < tolerance_rel )
assert error_rel < tolerance_rel

checksumAPI.reset_benchmark(test_name, fn)

0 comments on commit d4c79c6

Please sign in to comment.