-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…4922) * Removal of asserttion which prevented from usung the averaged PSATD algorithms with PML BC * Clean-up * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed to arr_aux(j,k,l) = fine when ES solve is used * Removed temporary print statements * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Clean-up * Added CI test ElectrostaticSphereEB_RZ_MR_lev_1 to check the fields on the level=1 * Updated becnmarks for ElectrostaticSphereLabFrame_MR_emass_10 * Imported regular expression (re) in the analysis script. * Fixed typo * United two CI tests for different levels of MR in one test. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Updated CI test ElectrostaticSphereEB_RZ_MR and the corresponding analysis script with smaller MR patch. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Clean-up * Do deepcopy for lev>0 and collocated grid * Fix bugs to resolve failure of CI tests * Preserve plotfile output, update benchmark file * Working on CI test * Update benchmark of `ElectrostaticSphereEB_RZ_MR` * Initialize with value all `aux`, `cax` fields * Remove changes related to averaged Galilean PSATD with PML * Remove style changes (e.g., changes to empty lines) * Replace `MFIter`/`ParallelFor` loop with simple copy * Apply suggestions from code review * Revert part of the code to its previous, equivalent state * Removed DeepCopy & no need for ghost cells in temp phi_cp. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Source/ablastr/fields/PoissonSolver.H * Add inline comments * Update analysis script * Use `TilingIfNotGPU`, `growntilebox` in E loop --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Edoardo Zoni <ezoni@lbl.gov> Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> Co-authored-by: Remi Lehe <remi.lehe@normalesup.org> Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
- Loading branch information
1 parent
3413568
commit 4ac5962
Showing
8 changed files
with
508 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2024 Olga Shapoval, Edoardo Zoni | ||
# | ||
# This file is part of WarpX. | ||
# | ||
# License: BSD-3-Clause-LBNL | ||
|
||
# This script tests the embedded boundary in RZ. | ||
# A cylindrical surface (r=0.1) has a fixed potential 1 V. | ||
# The outer surface has 0 V fixed. | ||
# Thus the analytical solution has the form: | ||
# phi(r) = A+B*log(r), Er(r) = -B/r. | ||
|
||
import os | ||
import sys | ||
|
||
import numpy as np | ||
from openpmd_viewer import OpenPMDTimeSeries | ||
|
||
sys.path.insert(1, '../../../../warpx/Regression/Checksum/') | ||
import checksumAPI | ||
|
||
tolerance = 0.004 | ||
print(f'tolerance = {tolerance}') | ||
|
||
fn = sys.argv[1] | ||
|
||
def find_first_non_zero_from_bottom_left(matrix): | ||
for i in range(matrix.shape[0]): | ||
for j in range(matrix.shape[1]): | ||
if (matrix[i][j] != 0) and (matrix[i][j] != np.nan): | ||
return (i, j) | ||
return i, j | ||
|
||
def find_first_non_zero_from_upper_right(matrix): | ||
for i in range(matrix.shape[0]-1, -1, -1): | ||
for j in range(matrix.shape[1]-1, -1, -1): | ||
if (matrix[i][j] != 0) and (matrix[i][j] != np.nan): | ||
return (i, j) | ||
return i,j | ||
|
||
def get_fields(ts, level): | ||
if level == 0: | ||
Er, info = ts.get_field('E', 'r', iteration=0) | ||
phi, info = ts.get_field('phi', iteration=0) | ||
else: | ||
Er, info = ts.get_field(f'E_lvl{level}', 'r', iteration=0) | ||
phi, info = ts.get_field(f'phi_lvl{level}', iteration=0) | ||
return Er, phi, info | ||
|
||
def get_error_per_lev(ts,level): | ||
Er, phi, info = get_fields(ts, level) | ||
|
||
nr_half = info.r.shape[0] // 2 | ||
dr = info.dr | ||
|
||
Er_patch = Er[:,nr_half:] | ||
phi_patch = phi[:,nr_half:] | ||
r1 = info.r[nr_half:] | ||
patch_left_lower_i, patch_left_lower_j = find_first_non_zero_from_bottom_left(Er_patch) | ||
patch_right_upper_i, patch_right_upper_j = find_first_non_zero_from_upper_right(Er_patch) | ||
|
||
# phi and Er field on the MR patch | ||
phi_sim = phi_patch[patch_left_lower_i:patch_right_upper_i+1, patch_left_lower_j:patch_right_upper_j+1] | ||
Er_sim = Er_patch[patch_left_lower_i:patch_right_upper_i+1, patch_left_lower_j:patch_right_upper_j+1] | ||
r = r1[patch_left_lower_j:patch_right_upper_j+1] | ||
|
||
B = 1.0/np.log(0.1/0.5) | ||
A = -B*np.log(0.5) | ||
|
||
# outside EB and last cutcell | ||
rmin = np.min(np.argwhere(r >= (0.1+dr))) | ||
rmax = -1 | ||
r = r[rmin:rmax] | ||
phi_sim = phi_sim[:,rmin:rmax] | ||
Er_sim = Er_sim[:,rmin:rmax] | ||
|
||
phi_theory = A + B*np.log(r) | ||
phi_theory = np.tile(phi_theory, (phi_sim.shape[0],1)) | ||
phi_error = np.max(np.abs(phi_theory-phi_sim) / np.abs(phi_theory)) | ||
|
||
Er_theory = -B/r | ||
Er_theory = np.tile(Er_theory, (Er_sim.shape[0],1)) | ||
Er_error = np.max(np.abs(Er_theory-Er_sim) / np.abs(Er_theory)) | ||
|
||
print(f'max error of phi[lev={level}]: {phi_error}') | ||
print(f'max error of Er[lev={level}]: {Er_error}') | ||
assert(phi_error < tolerance) | ||
assert(Er_error < tolerance) | ||
|
||
ts = OpenPMDTimeSeries(fn) | ||
level_fields = [field for field in ts.avail_fields if 'lvl' in field] | ||
nlevels = 0 if level_fields == [] else int(level_fields[-1][-1]) | ||
for level in range(nlevels+1): | ||
get_error_per_lev(ts,level) | ||
|
||
test_name = os.path.split(os.getcwd())[1] | ||
checksumAPI.evaluate_checksum(test_name, fn, output_format="openpmd") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
Regression/Checksum/benchmarks_json/ElectrostaticSphereEB_RZ_MR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"lev=0": { | ||
"Er": 8487.661571739109, | ||
"phi": 2036.0428085225362 | ||
"Er": 16975.32314347822, | ||
"phi": 4072.085617045073 | ||
}, | ||
"lev=1": { | ||
"Er": 19519.172334977942, | ||
"phi": 3291.0262856782897 | ||
"Er": 26818.189739547757, | ||
"phi_lvl1": 8731.176548788893 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.