Skip to content

Commit

Permalink
More checksums updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EZoni committed Sep 19, 2024
1 parent da54839 commit 96dcba4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Examples/Physics_applications/capacitive_discharge/analysis_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

# Copyright 2022 Modern Electron, David Grote

import os
import sys

import numpy as np

sys.path.append("../../../../warpx/Regression/Checksum/")
from checksumAPI import evaluate_checksum

# fmt: off
ref_density = np.array([
1.27989677e+14, 2.23601330e+14, 2.55400265e+14, 2.55664972e+14,
Expand Down Expand Up @@ -45,3 +51,9 @@
density_data = np.load("ion_density_case_1.npy")
print(repr(density_data))
assert np.allclose(density_data, ref_density)

# compare checksums
evaluate_checksum(
test_name=os.path.split(os.getcwd())[1],
output_file=sys.argv[1],
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import sys

sys.path.append("../../../../warpx/Regression/Checksum/")
from checksumAPI import evaluate_checksum

import checksumAPI

my_check = checksumAPI.evaluate_checksum(
# compare checksums
evaluate_checksum(
test_name=os.path.split(os.getcwd())[1],
output_file=sys.argv[1],
rtol=5e-3,
do_particles=True,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
import numpy as np

sys.path.append("../../../../warpx/Regression/Checksum/")

import checksumAPI

# this will be the name of the plot file
fn = sys.argv[1]
test_name = os.path.split(os.getcwd())[1]

my_check = checksumAPI.evaluate_checksum(test_name, fn, do_particles=True)
from checksumAPI import evaluate_checksum

# fmt: off
ref_density = np.array([
Expand Down Expand Up @@ -58,3 +51,9 @@
density_data = np.load("ion_density_case_1.npy")
print(repr(density_data))
assert np.allclose(density_data, ref_density)

# compare checksums
evaluate_checksum(
test_name=os.path.split(os.getcwd())[1],
output_file=sys.argv[1],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"lev=0": {
"rho_electrons": 0.0044328572492614605,
"rho_he_ions": 0.005198609403474849
},
"electrons": {
"particle_momentum_x": 3.5020450942268976e-20,
"particle_momentum_y": 3.5342700024993965e-20,
"particle_momentum_z": 1.2596017960675146e-19,
"particle_position_x": 2139.5967568101983,
"particle_weight": 14577210937500.002
},
"he_ions": {
"particle_momentum_x": 2.770046913680294e-19,
"particle_momentum_y": 2.755651798947783e-19,
"particle_momentum_z": 3.619494241595636e-19,
"particle_position_x": 2200.218124999781,
"particle_weight": 17184714843750.002
}
}
9 changes: 3 additions & 6 deletions Regression/Checksum/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40):
)
print("Benchmark: %s" % ref_benchmark.data.keys())
print("Test file: %s" % self.data.keys())
print("\n----------------\nNew file for " + self.test_name + ":")
print(f"\nNew checksums file {self.test_name}.json:")
print(json.dumps(self.data, indent=2))
print("----------------")
sys.exit(1)

# Dictionaries have same inner keys (field and particle quantities)?
Expand All @@ -261,9 +260,8 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40):
% (key1, ref_benchmark.data[key1].keys())
)
print("Test file inner keys in %s: %s" % (key1, self.data[key1].keys()))
print("\n----------------\nNew file for " + self.test_name + ":")
print(f"\nNew checksums file {self.test_name}.json:")
print(json.dumps(self.data, indent=2))
print("----------------")
sys.exit(1)

# Dictionaries have same values?
Expand Down Expand Up @@ -298,7 +296,6 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40):
rel_err = abs_err / np.abs(x)
print("Relative error: {:.2e}".format(rel_err))
if checksums_differ:
print("\n----------------\nNew file for " + self.test_name + ":")
print(f"\nNew checksums file {self.test_name}.json:")
print(json.dumps(self.data, indent=2))
print("----------------")
sys.exit(1)

0 comments on commit 96dcba4

Please sign in to comment.