Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PML for the outer RZ boundary with PSATD #2211

Merged
merged 39 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7b98da7
Initial version of RZ PSATD PML BCs
dpgrote Aug 18, 2021
de5a72b
Cleaned up some bugs
dpgrote Aug 18, 2021
30ca30c
Add support of do_pml_in_domain option
dpgrote Aug 19, 2021
7bc35ac
Cleaned up stuff for building
dpgrote Aug 19, 2021
5f5d4c3
Fix PMLPsatdAlgorithm macro
dpgrote Aug 19, 2021
7f48397
Removed unneeded variable from SpectralSolverRZ
dpgrote Aug 20, 2021
4d41190
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Aug 24, 2021
76cdfa3
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Sep 1, 2021
2519c7e
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Oct 11, 2021
1b1160f
Change length 3 arrays to length 2 (for 2D)
dpgrote Oct 12, 2021
3ec7931
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Oct 13, 2021
a86192d
Cleanup around DampPML
dpgrote Oct 13, 2021
fe3ae84
Added more checks of pml[lev]
dpgrote Oct 13, 2021
1f54148
Added CI test for RZ PML
dpgrote Oct 13, 2021
0b9105c
Added code to update the corner guard cells
dpgrote Oct 19, 2021
47da308
Further updates
dpgrote Oct 19, 2021
862e411
Added CI test
dpgrote Oct 19, 2021
9e1cfd4
Fixed EOL space
dpgrote Oct 19, 2021
2fa0bb1
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Oct 19, 2021
4747a29
Updated CI benchmarks, removing round off fields
dpgrote Oct 20, 2021
a30ba04
Changes to CI missed on previous commit
dpgrote Oct 20, 2021
0497dfb
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Oct 20, 2021
80fbf99
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Nov 16, 2021
d338b72
Various fixes for clean up
dpgrote Nov 16, 2021
81a22c5
More fixes for clean up
dpgrote Nov 16, 2021
7011f51
Further cleanup
dpgrote Nov 17, 2021
0e55515
Updated benchmark
dpgrote Nov 17, 2021
0f0c2c9
Fixed benchmarks file
dpgrote Nov 19, 2021
fccf166
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Nov 19, 2021
576b135
Minor cleanup
dpgrote Nov 24, 2021
9c2adcc
Added round off benchmark values
dpgrote Nov 24, 2021
a736c35
Fixed testname in analysis_pml_psatd_rz.py
dpgrote Nov 24, 2021
9c15106
Update comment in analysis file
dpgrote Nov 29, 2021
693f903
Merge branch 'development' into RZ_psatd_pml
RemiLehe Dec 6, 2021
47d762f
Put pml_rz code in RZ and PSATD macro blocks
dpgrote Dec 6, 2021
aae6a9c
Merge remote-tracking branch 'ECPwarpx/development' into RZ_psatd_pml
dpgrote Jan 10, 2022
1824ae2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2022
edd8041
Add geometry.dims input to CI test input file, inputs_rz
dpgrote Jan 11, 2022
76d85ea
Cleanup to match recent changes
dpgrote Jan 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Examples/Tests/PML/analysis_pml_psatd_rz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! /usr/bin/env python

# Copyright 2021 David Grote
#
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL

"""
This script tests the absorption of fields in the PML in RZ geometry.

The input file inputs_particle_rz is used: it features an electron
moving radially that launches a pulse. This scripts runs until
most of the pulse escapes the radial boundary. If the PML fails,
the pulse will remain with in the domain.
"""
import sys
import os
import numpy as np
import yt
yt.funcs.mylog.setLevel(0)
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI

# Open plotfile specified in command line
filename = sys.argv[1]
ds = yt.load( filename )

EZoni marked this conversation as resolved.
Show resolved Hide resolved
# yt 4.0+ has rounding issues with our domain data:
# RuntimeError: yt attempted to read outside the boundaries
# of a non-periodic domain along dimension 0.
if 'force_periodicity' in dir(ds): ds.force_periodicity()

# Check that the field is low enough
ad0 = ds.covering_grid(level=0, left_edge=ds.domain_left_edge, dims=ds.domain_dimensions)
Ex_array = ad0['boxlib', 'Ex'].to_ndarray()
Ez_array = ad0['boxlib', 'Ez'].to_ndarray()
max_Ex = np.abs(Ex_array).max()
max_Ez = np.abs(Ez_array).max()
print( f'max Ex = {max_Ex}' )
print( f'max Ez = {max_Ez}' )
max_Efield = max(max_Ex, max_Ez)

# This tolerance was obtained empirically. As the simulation progresses, the field energy is leaking
# out through PML so that the max field diminishes with time. When the PML is working properly,
# the field level falls below 2 at the end of the simulation.
tolerance_abs = 2.
print('tolerance_abs: ' + str(tolerance_abs))
assert max_Efield < tolerance_abs
EZoni marked this conversation as resolved.
Show resolved Hide resolved

test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
48 changes: 48 additions & 0 deletions Examples/Tests/PML/inputs_rz
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#################################
####### GENERAL PARAMETERS ######
#################################
max_step = 500
amr.n_cell = 32 128
amr.max_level = 0
geometry.coord_sys = 1 # 1: Cylindrical
geometry.prob_lo = 0. -100.e-6
geometry.prob_hi = 50.e-6 +100.e-6

warpx.n_rz_azimuthal_modes = 2

#################################
######## Boundary condition #####
#################################
boundary.field_lo = none periodic
boundary.field_hi = pml periodic

# PML
warpx.pml_ncell = 10
warpx.do_pml_in_domain = 0

#################################
############ NUMERICS ###########
#################################
algo.maxwell_solver = psatd
warpx.use_filter = 0
algo.particle_shape = 1

#################################
############ PARTICLE ###########
#################################
particles.species_names = electron

electron.charge = -q_e
electron.mass = m_e
electron.injection_style = "singleparticle"
electron.single_particle_pos = 0. 0. 0.
electron.single_particle_vel = 10. 0. 0.
electron.single_particle_weight = 1.

#################################
########## DIAGNOSTICS ##########
#################################
diagnostics.diags_names = diag1
diag1.intervals = 500
diag1.fields_to_plot = Bx By Bz Ex Ey Ez jx jy jz rho
diag1.diag_type = Full
14 changes: 14 additions & 0 deletions Regression/Checksum/benchmarks_json/pml_psatd_rz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"lev=0": {
"Ex": 1317.2337418101674,
"Ey": 7.056477765087081e-12,
"Ez": 1156.1377910176022,
"Bx": 2.594232124519114e-20,
"By": 3.2688462949057505e-06,
"Bz": 4.292128402662449e-21,
"jx": 0.0,
"jy": 0.0,
"jz": 0.0,
"rho": 0.0
}
}
16 changes: 16 additions & 0 deletions Regression/WarpX-tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ doVis = 0
analysisRoutine = Examples/analysis_default_regression.py
tolerance = 1.e-14

[pml_psatd_rz]
buildDir = .
inputFile = Examples/Tests/PML/inputs_rz
runtime_params =
dim = 2
addToCompileString = USE_RZ=TRUE USE_PSATD=TRUE
restartTest = 0
useMPI = 1
numprocs = 2
useOMP = 1
numthreads = 1
compileTest = 0
doVis = 0
analysisRoutine = Examples/Tests/PML/analysis_pml_psatd_rz.py
tolerance = 1.e-14

[silver_mueller_2d_x]
buildDir = .
inputFile = Examples/Tests/SilverMueller/inputs_2d_x
Expand Down
7 changes: 7 additions & 0 deletions Source/BoundaryConditions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ target_sources(WarpX
WarpXFieldBoundaries.cpp
WarpX_PEC.cpp
)

if(WarpX_DIMS STREQUAL RZ)
RemiLehe marked this conversation as resolved.
Show resolved Hide resolved
target_sources(WarpX
PRIVATE
PML_RZ.cpp
)
endif()
3 changes: 3 additions & 0 deletions Source/BoundaryConditions/Make.package
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CEXE_sources += PML.cpp WarpXEvolvePML.cpp
CEXE_sources += WarpXFieldBoundaries.cpp WarpX_PEC.cpp

ifeq ($(USE_RZ),TRUE)
CEXE_sources += PML_RZ.cpp
RemiLehe marked this conversation as resolved.
Show resolved Hide resolved
endif

VPATH_LOCATIONS += $(WARPX_HOME)/Source/BoundaryConditions
75 changes: 75 additions & 0 deletions Source/BoundaryConditions/PML_RZ.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Copyright 2021 David Grote
*
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#ifndef WARPX_PML_RZ_H_
#define WARPX_PML_RZ_H_

#include "PML_RZ_fwd.H"

#ifdef WARPX_USE_PSATD
RemiLehe marked this conversation as resolved.
Show resolved Hide resolved
# include "FieldSolver/SpectralSolver/SpectralSolverRZ.H"
#endif

#include <AMReX_MultiFab.H>
#include <AMReX_BoxArray.H>
#include <AMReX_Config.H>
#include <AMReX_REAL.H>

#include <AMReX_BaseFwd.H>

#include <array>
#include <string>

enum struct PatchType : int;

class PML_RZ
{
public:
PML_RZ (const int lev, const amrex::BoxArray& grid_ba, const amrex::DistributionMapping& grid_dm,
const amrex::Geometry* geom, const int ncell, const int do_pml_in_domain);

void ApplyDamping(amrex::MultiFab* Et_fp, amrex::MultiFab* Ez_fp,
amrex::MultiFab* Bt_fp, amrex::MultiFab* Bz_fp,
amrex::Real dt);

std::array<amrex::MultiFab*,2> GetE_fp ();
std::array<amrex::MultiFab*,2> GetB_fp ();

#ifdef WARPX_USE_PSATD
void PushPSATD (const int lev);
#endif

void FillBoundaryE ();
void FillBoundaryB ();
void FillBoundaryE (PatchType patch_type);
void FillBoundaryB (PatchType patch_type);

void CheckPoint (const std::string& dir) const;
void Restart (const std::string& dir);

~PML_RZ () = default;

private:

const int m_ncell;
const int m_do_pml_in_domain;
const amrex::Geometry* m_geom;

// Only contains Er and Et, and Br and Bt
std::array<std::unique_ptr<amrex::MultiFab>,2> pml_E_fp;
std::array<std::unique_ptr<amrex::MultiFab>,2> pml_B_fp;

#ifdef WARPX_USE_PSATD
void PushPMLPSATDSinglePatchRZ ( const int lev,
SpectralSolverRZ& solver,
std::array<std::unique_ptr<amrex::MultiFab>,2>& pml_E,
std::array<std::unique_ptr<amrex::MultiFab>,2>& pml_B);
#endif

};

#endif
Loading