aboutsummaryrefslogtreecommitdiff
path: root/Source/FieldSolver
diff options
context:
space:
mode:
Diffstat (limited to 'Source/FieldSolver')
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralAlgorithms/Make.package2
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.H34
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.cpp146
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithm.H14
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H4
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralFieldData.H19
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp6
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralSolver.H3
-rw-r--r--Source/FieldSolver/SpectralSolver/SpectralSolver.cpp24
-rw-r--r--Source/FieldSolver/WarpXPushFieldsEM.cpp215
10 files changed, 418 insertions, 49 deletions
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/Make.package b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/Make.package
index c62c21f44..ee8376865 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/Make.package
+++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/Make.package
@@ -1,6 +1,8 @@
CEXE_headers += SpectralBaseAlgorithm.H
CEXE_headers += PsatdAlgorithm.H
CEXE_sources += PsatdAlgorithm.cpp
+CEXE_headers += PMLPsatdAlgorithm.H
+CEXE_sources += PMLPsatdAlgorithm.cpp
INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/FieldSolver/SpectralSolver/SpectralAlgorithms
VPATH_LOCATIONS += $(WARPX_HOME)/Source/FieldSolver/SpectralSolver/SpectralAlgorithms
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.H
new file mode 100644
index 000000000..a2511b6b7
--- /dev/null
+++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.H
@@ -0,0 +1,34 @@
+#ifndef WARPX_PML_PSATD_ALGORITHM_H_
+#define WARPX_PML_PSATD_ALGORITHM_H_
+
+#include <SpectralBaseAlgorithm.H>
+
+/* \brief Class that updates the field in spectral space
+ * and stores the coefficients of the corresponding update equation.
+ */
+class PMLPsatdAlgorithm : public SpectralBaseAlgorithm
+{
+ public:
+ PMLPsatdAlgorithm(const SpectralKSpace& spectral_kspace,
+ const amrex::DistributionMapping& dm,
+ const int norder_x, const int norder_y,
+ const int norder_z, const bool nodal,
+ const amrex::Real dt);
+
+ void InitializeSpectralCoefficients(
+ const SpectralKSpace& spectral_kspace,
+ const amrex::DistributionMapping& dm,
+ const amrex::Real dt);
+
+ // Redefine functions from base class
+ virtual void pushSpectralFields(SpectralFieldData& f) const override final;
+ virtual int getRequiredNumberOfFields() const override final {
+ return SpectralPMLIndex::n_fields;
+ }
+
+ private:
+ SpectralCoefficients C_coef, S_ck_coef;
+
+};
+
+#endif // WARPX_PML_PSATD_ALGORITHM_H_
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.cpp
new file mode 100644
index 000000000..d76259d4c
--- /dev/null
+++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PMLPsatdAlgorithm.cpp
@@ -0,0 +1,146 @@
+#include <PMLPsatdAlgorithm.H>
+#include <WarpXConst.H>
+#include <cmath>
+
+using namespace amrex;
+
+/* \brief Initialize coefficients for the update equation */
+PMLPsatdAlgorithm::PMLPsatdAlgorithm(
+ const SpectralKSpace& spectral_kspace,
+ const DistributionMapping& dm,
+ const int norder_x, const int norder_y,
+ const int norder_z, const bool nodal, const Real dt)
+ // Initialize members of base class
+ : SpectralBaseAlgorithm( spectral_kspace, dm,
+ norder_x, norder_y, norder_z, nodal )
+{
+ const BoxArray& ba = spectral_kspace.spectralspace_ba;
+
+ // Allocate the arrays of coefficients
+ C_coef = SpectralCoefficients(ba, dm, 1, 0);
+ S_ck_coef = SpectralCoefficients(ba, dm, 1, 0);
+
+ InitializeSpectralCoefficients(spectral_kspace, dm, dt);
+}
+
+/* Advance the E and B field in spectral space (stored in `f`)
+ * over one time step */
+void
+PMLPsatdAlgorithm::pushSpectralFields(SpectralFieldData& f) const{
+
+ // Loop over boxes
+ for (MFIter mfi(f.fields); mfi.isValid(); ++mfi){
+
+ const Box& bx = f.fields[mfi].box();
+
+ // Extract arrays for the fields to be updated
+ Array4<Complex> fields = f.fields[mfi].array();
+ // Extract arrays for the coefficients
+ Array4<const Real> C_arr = C_coef[mfi].array();
+ Array4<const Real> S_ck_arr = S_ck_coef[mfi].array();
+ // Extract pointers for the k vectors
+ const Real* modified_kx_arr = modified_kx_vec[mfi].dataPtr();
+#if (AMREX_SPACEDIM==3)
+ const Real* modified_ky_arr = modified_ky_vec[mfi].dataPtr();
+#endif
+ const Real* modified_kz_arr = modified_kz_vec[mfi].dataPtr();
+
+ // Loop over indices within one box
+ ParallelFor(bx,
+ [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
+ {
+ // Record old values of the fields to be updated
+ using Idx = SpectralPMLIndex;
+ const Complex Ex_old = fields(i,j,k,Idx::Exy) \
+ + fields(i,j,k,Idx::Exz);
+ const Complex Ey_old = fields(i,j,k,Idx::Eyx) \
+ + fields(i,j,k,Idx::Eyz);
+ const Complex Ez_old = fields(i,j,k,Idx::Ezx) \
+ + fields(i,j,k,Idx::Ezy);
+ const Complex Bx_old = fields(i,j,k,Idx::Bxy) \
+ + fields(i,j,k,Idx::Bxz);
+ const Complex By_old = fields(i,j,k,Idx::Byx) \
+ + fields(i,j,k,Idx::Byz);
+ const Complex Bz_old = fields(i,j,k,Idx::Bzx) \
+ + fields(i,j,k,Idx::Bzy);
+ // k vector values, and coefficients
+ const Real kx = modified_kx_arr[i];
+#if (AMREX_SPACEDIM==3)
+ const Real ky = modified_ky_arr[j];
+ const Real kz = modified_kz_arr[k];
+#else
+ constexpr Real ky = 0;
+ const Real kz = modified_kz_arr[j];
+#endif
+ constexpr Real c2 = PhysConst::c*PhysConst::c;
+ const Complex I = Complex{0,1};
+ const Real C = C_arr(i,j,k);
+ const Real S_ck = S_ck_arr(i,j,k);
+
+ // Update E
+ fields(i,j,k,Idx::Exy) = C*fields(i,j,k,Idx::Exy) + S_ck*c2*I*ky*Bz_old;
+ fields(i,j,k,Idx::Exz) = C*fields(i,j,k,Idx::Exz) - S_ck*c2*I*kz*By_old;
+ fields(i,j,k,Idx::Eyz) = C*fields(i,j,k,Idx::Eyz) + S_ck*c2*I*kz*Bx_old;
+ fields(i,j,k,Idx::Eyx) = C*fields(i,j,k,Idx::Eyx) - S_ck*c2*I*kx*Bz_old;
+ fields(i,j,k,Idx::Ezx) = C*fields(i,j,k,Idx::Ezx) + S_ck*c2*I*kx*By_old;
+ fields(i,j,k,Idx::Ezy) = C*fields(i,j,k,Idx::Ezy) - S_ck*c2*I*ky*Bx_old;
+ // Update B
+ fields(i,j,k,Idx::Bxy) = C*fields(i,j,k,Idx::Bxy) - S_ck*I*ky*Ez_old;
+ fields(i,j,k,Idx::Bxz) = C*fields(i,j,k,Idx::Bxz) + S_ck*I*kz*Ey_old;
+ fields(i,j,k,Idx::Byz) = C*fields(i,j,k,Idx::Byz) - S_ck*I*kz*Ex_old;
+ fields(i,j,k,Idx::Byx) = C*fields(i,j,k,Idx::Byx) + S_ck*I*kx*Ez_old;
+ fields(i,j,k,Idx::Bzx) = C*fields(i,j,k,Idx::Bzx) - S_ck*I*kx*Ey_old;
+ fields(i,j,k,Idx::Bzy) = C*fields(i,j,k,Idx::Bzy) + S_ck*I*ky*Ex_old;
+ });
+ }
+};
+
+void PMLPsatdAlgorithm::InitializeSpectralCoefficients (
+ const SpectralKSpace& spectral_kspace,
+ const amrex::DistributionMapping& dm,
+ const amrex::Real dt)
+{
+ const BoxArray& ba = spectral_kspace.spectralspace_ba;
+ // Fill them with the right values:
+ // Loop over boxes and allocate the corresponding coefficients
+ // for each box owned by the local MPI proc
+ for (MFIter mfi(ba, dm); mfi.isValid(); ++mfi){
+
+ const Box& bx = ba[mfi];
+
+ // Extract pointers for the k vectors
+ const Real* modified_kx = modified_kx_vec[mfi].dataPtr();
+#if (AMREX_SPACEDIM==3)
+ const Real* modified_ky = modified_ky_vec[mfi].dataPtr();
+#endif
+ const Real* modified_kz = modified_kz_vec[mfi].dataPtr();
+ // Extract arrays for the coefficients
+ Array4<Real> C = C_coef[mfi].array();
+ Array4<Real> S_ck = S_ck_coef[mfi].array();
+
+ // Loop over indices within one box
+ ParallelFor(bx,
+ [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
+ {
+ // Calculate norm of vector
+ const Real k_norm = std::sqrt(
+ std::pow(modified_kx[i], 2) +
+#if (AMREX_SPACEDIM==3)
+ std::pow(modified_ky[j], 2) +
+ std::pow(modified_kz[k], 2));
+#else
+ std::pow(modified_kz[j], 2));
+#endif
+
+ // Calculate coefficients
+ constexpr Real c = PhysConst::c;
+ if (k_norm != 0){
+ C(i,j,k) = std::cos(c*k_norm*dt);
+ S_ck(i,j,k) = std::sin(c*k_norm*dt)/(c*k_norm);
+ } else { // Handle k_norm = 0, by using the analytical limit
+ C(i,j,k) = 1.;
+ S_ck(i,j,k) = dt;
+ }
+ });
+ }
+};
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithm.H
index 12718e38b..825d04dc2 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithm.H
+++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithm.H
@@ -13,14 +13,18 @@ class PsatdAlgorithm : public SpectralBaseAlgorithm
PsatdAlgorithm(const SpectralKSpace& spectral_kspace,
const amrex::DistributionMapping& dm,
const int norder_x, const int norder_y,
- const int norder_z, const bool nodal, const amrex::Real dt);
-
+ const int norder_z, const bool nodal,
+ const amrex::Real dt);
+ // Redefine functions from base class
+ virtual void pushSpectralFields(SpectralFieldData& f) const override final;
+ virtual int getRequiredNumberOfFields() const override final {
+ return SpectralFieldIndex::n_fields;
+ }
+
void InitializeSpectralCoefficients(const SpectralKSpace& spectral_kspace,
- const amrex::DistributionMapping& dm,
+ const amrex::DistributionMapping& dm,
const amrex::Real dt);
- void pushSpectralFields(SpectralFieldData& f) const override final;
-
private:
SpectralCoefficients C_coef, S_ck_coef, X1_coef, X2_coef, X3_coef;
};
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H
index 602eb2473..5d5e376c1 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H
+++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H
@@ -14,9 +14,9 @@
class SpectralBaseAlgorithm
{
public:
- // Member function that updates the fields in spectral space ;
- // meant to be overridden in subclasses
+ // Virtual member function ; meant to be overridden in subclasses
virtual void pushSpectralFields(SpectralFieldData& f) const = 0;
+ virtual int getRequiredNumberOfFields() const = 0;
// The destructor should also be a virtual function, so that
// a pointer to subclass of `SpectraBaseAlgorithm` actually
// calls the subclass's destructor.
diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldData.H b/Source/FieldSolver/SpectralSolver/SpectralFieldData.H
index 7954414b8..6a2446981 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralFieldData.H
+++ b/Source/FieldSolver/SpectralSolver/SpectralFieldData.H
@@ -8,18 +8,24 @@
// Declare type for spectral fields
using SpectralField = amrex::FabArray< amrex::BaseFab <Complex> >;
-/* Index for the fields that will be stored in spectral space */
+/* Index for the regular fields, when stored in spectral space */
struct SpectralFieldIndex {
enum { Ex=0, Ey, Ez, Bx, By, Bz, Jx, Jy, Jz, rho_old, rho_new, n_fields };
// n_fields is automatically the total number of fields
};
+/* Index for the PML fields, when stored in spectral space */
+struct SpectralPMLIndex {
+ enum { Exy=0, Exz, Eyx, Eyz, Ezx, Ezy,
+ Bxy, Bxz, Byx, Byz, Bzx, Bzy, n_fields };
+ // n_fields is automatically the total number of fields
+};
+
/* \brief Class that stores the fields in spectral space, and performs the
* Fourier transforms between real space and spectral space
*/
class SpectralFieldData
{
- friend class PsatdAlgorithm;
// Define the FFTplans type, which holds one fft plan per box
// (plans are only initialized for the boxes that are owned by
@@ -32,8 +38,9 @@ class SpectralFieldData
public:
SpectralFieldData( const amrex::BoxArray& realspace_ba,
- const SpectralKSpace& k_space,
- const amrex::DistributionMapping& dm );
+ const SpectralKSpace& k_space,
+ const amrex::DistributionMapping& dm,
+ const int n_field_required );
SpectralFieldData() = default; // Default constructor
SpectralFieldData& operator=(SpectralFieldData&& field_data) = default;
~SpectralFieldData();
@@ -41,10 +48,10 @@ class SpectralFieldData
const int field_index, const int i_comp);
void BackwardTransform( amrex::MultiFab& mf,
const int field_index, const int i_comp);
-
- private:
// `fields` stores fields in spectral space, as multicomponent FabArray
SpectralField fields;
+
+ private:
// tmpRealField and tmpSpectralField store fields
// right before/after the Fourier transform
SpectralField tmpSpectralField; // contains Complexs
diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp b/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp
index 948baf0a6..8f0853484 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp
+++ b/Source/FieldSolver/SpectralSolver/SpectralFieldData.cpp
@@ -5,14 +5,14 @@ using namespace amrex;
/* \brief Initialize fields in spectral space, and FFT plans */
SpectralFieldData::SpectralFieldData( const BoxArray& realspace_ba,
const SpectralKSpace& k_space,
- const DistributionMapping& dm )
+ const DistributionMapping& dm,
+ const int n_field_required )
{
const BoxArray& spectralspace_ba = k_space.spectralspace_ba;
// Allocate the arrays that contain the fields in spectral space
// (one component per field)
- fields = SpectralField(spectralspace_ba, dm,
- SpectralFieldIndex::n_fields, 0);
+ fields = SpectralField(spectralspace_ba, dm, n_field_required, 0);
// Allocate temporary arrays - in real space and spectral space
// These arrays will store the data just before/after the FFT
diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolver.H b/Source/FieldSolver/SpectralSolver/SpectralSolver.H
index d4019a9a3..c570b017b 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralSolver.H
+++ b/Source/FieldSolver/SpectralSolver/SpectralSolver.H
@@ -23,7 +23,8 @@ class SpectralSolver
const amrex::DistributionMapping& dm,
const int norder_x, const int norder_y,
const int norder_z, const bool nodal,
- const amrex::RealVect dx, const amrex::Real dt );
+ const amrex::RealVect dx, const amrex::Real dt,
+ const bool pml=false );
/* \brief Transform the component `i_comp` of MultiFab `mf`
* to spectral space, and store the corresponding result internally
diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp b/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp
index c21c3cfb1..4b9def013 100644
--- a/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp
+++ b/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp
@@ -1,19 +1,29 @@
#include <SpectralKSpace.H>
#include <SpectralSolver.H>
#include <PsatdAlgorithm.H>
+#include <PMLPsatdAlgorithm.H>
/* \brief Initialize the spectral Maxwell solver
*
* This function selects the spectral algorithm to be used, allocates the
* corresponding coefficients for the discretized field update equation,
* and prepares the structures that store the fields in spectral space.
+ *
+ * \param norder_x Order of accuracy of the spatial derivatives along x
+ * \param norder_y Order of accuracy of the spatial derivatives along y
+ * \param norder_z Order of accuracy of the spatial derivatives along z
+ * \param nodal Whether the solver is applied to a nodal or staggered grid
+ * \param dx Cell size along each dimension
+ * \param dt Time step
+ * \param pml Whether the boxes in which the solver is applied are PML boxes
*/
SpectralSolver::SpectralSolver(
const amrex::BoxArray& realspace_ba,
const amrex::DistributionMapping& dm,
const int norder_x, const int norder_y,
const int norder_z, const bool nodal,
- const amrex::RealVect dx, const amrex::Real dt ) {
+ const amrex::RealVect dx, const amrex::Real dt,
+ const bool pml ) {
// Initialize all structures using the same distribution mapping dm
@@ -24,12 +34,16 @@ SpectralSolver::SpectralSolver(
// - Select the algorithm depending on the input parameters
// Initialize the corresponding coefficients over k space
- // TODO: Add more algorithms + selection depending on input parameters
- // For the moment, this only uses the standard PsatdAlgorithm
- algorithm = std::unique_ptr<PsatdAlgorithm>( new PsatdAlgorithm(
+ if (pml) {
+ algorithm = std::unique_ptr<PMLPsatdAlgorithm>( new PMLPsatdAlgorithm(
+ k_space, dm, norder_x, norder_y, norder_z, nodal, dt ) );
+ } else {
+ algorithm = std::unique_ptr<PsatdAlgorithm>( new PsatdAlgorithm(
k_space, dm, norder_x, norder_y, norder_z, nodal, dt ) );
+ }
// - Initialize arrays for fields in spectral space + FFT plans
- field_data = SpectralFieldData( realspace_ba, k_space, dm );
+ field_data = SpectralFieldData( realspace_ba, k_space, dm,
+ algorithm->getRequiredNumberOfFields() );
};
diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp
index 4fce4717b..1df05bc0f 100644
--- a/Source/FieldSolver/WarpXPushFieldsEM.cpp
+++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp
@@ -18,6 +18,40 @@
using namespace amrex;
#ifdef WARPX_USE_PSATD
+namespace {
+ void
+ PushPSATDSinglePatch (
+ SpectralSolver& solver,
+ std::array<std::unique_ptr<amrex::MultiFab>,3>& Efield,
+ std::array<std::unique_ptr<amrex::MultiFab>,3>& Bfield,
+ std::array<std::unique_ptr<amrex::MultiFab>,3>& current,
+ std::unique_ptr<amrex::MultiFab>& rho ) {
+
+ using Idx = SpectralFieldIndex;
+
+ // Perform forward Fourier transform
+ solver.ForwardTransform(*Efield[0], Idx::Ex);
+ solver.ForwardTransform(*Efield[1], Idx::Ey);
+ solver.ForwardTransform(*Efield[2], Idx::Ez);
+ solver.ForwardTransform(*Bfield[0], Idx::Bx);
+ solver.ForwardTransform(*Bfield[1], Idx::By);
+ solver.ForwardTransform(*Bfield[2], Idx::Bz);
+ solver.ForwardTransform(*current[0], Idx::Jx);
+ solver.ForwardTransform(*current[1], Idx::Jy);
+ solver.ForwardTransform(*current[2], Idx::Jz);
+ solver.ForwardTransform(*rho, Idx::rho_old, 0);
+ solver.ForwardTransform(*rho, Idx::rho_new, 1);
+ // Advance fields in spectral space
+ solver.pushSpectralFields();
+ // Perform backward Fourier Transform
+ solver.BackwardTransform(*Efield[0], Idx::Ex);
+ solver.BackwardTransform(*Efield[1], Idx::Ey);
+ solver.BackwardTransform(*Efield[2], Idx::Ez);
+ solver.BackwardTransform(*Bfield[0], Idx::Bx);
+ solver.BackwardTransform(*Bfield[1], Idx::By);
+ solver.BackwardTransform(*Bfield[2], Idx::Bz);
+ }
+}
void
WarpX::PushPSATD (amrex::Real a_dt)
@@ -31,38 +65,25 @@ WarpX::PushPSATD (amrex::Real a_dt)
} else {
PushPSATD_localFFT(lev, a_dt);
}
+
+ // Evolve the fields in the PML boxes
+ if (do_pml && pml[lev]->ok()) {
+ pml[lev]->PushPSATD();
+ }
}
}
-void WarpX::PushPSATD_localFFT (int lev, amrex::Real /* dt */)
+void
+WarpX::PushPSATD_localFFT (int lev, amrex::Real /* dt */)
{
- auto& solver = *spectral_solver_fp[lev];
-
- // Perform forward Fourier transform
- solver.ForwardTransform(*Efield_fp[lev][0], SpectralFieldIndex::Ex);
- solver.ForwardTransform(*Efield_fp[lev][1], SpectralFieldIndex::Ey);
- solver.ForwardTransform(*Efield_fp[lev][2], SpectralFieldIndex::Ez);
- solver.ForwardTransform(*Bfield_fp[lev][0], SpectralFieldIndex::Bx);
- solver.ForwardTransform(*Bfield_fp[lev][1], SpectralFieldIndex::By);
- solver.ForwardTransform(*Bfield_fp[lev][2], SpectralFieldIndex::Bz);
- solver.ForwardTransform(*current_fp[lev][0], SpectralFieldIndex::Jx);
- solver.ForwardTransform(*current_fp[lev][1], SpectralFieldIndex::Jy);
- solver.ForwardTransform(*current_fp[lev][2], SpectralFieldIndex::Jz);
- solver.ForwardTransform(*rho_fp[lev], SpectralFieldIndex::rho_old, 0);
- solver.ForwardTransform(*rho_fp[lev], SpectralFieldIndex::rho_new, 1);
-
- // Advance fields in spectral space
- solver.pushSpectralFields();
-
- // Perform backward Fourier Transform
- solver.BackwardTransform(*Efield_fp[lev][0], SpectralFieldIndex::Ex);
- solver.BackwardTransform(*Efield_fp[lev][1], SpectralFieldIndex::Ey);
- solver.BackwardTransform(*Efield_fp[lev][2], SpectralFieldIndex::Ez);
- solver.BackwardTransform(*Bfield_fp[lev][0], SpectralFieldIndex::Bx);
- solver.BackwardTransform(*Bfield_fp[lev][1], SpectralFieldIndex::By);
- solver.BackwardTransform(*Bfield_fp[lev][2], SpectralFieldIndex::Bz);
+ // Update the fields on the fine and coarse patch
+ PushPSATDSinglePatch( *spectral_solver_fp[lev],
+ Efield_fp[lev], Bfield_fp[lev], current_fp[lev], rho_fp[lev] );
+ if (spectral_solver_cp[lev]) {
+ PushPSATDSinglePatch( *spectral_solver_cp[lev],
+ Efield_cp[lev], Bfield_cp[lev], current_cp[lev], rho_cp[lev] );
+ }
}
-
#endif
void
@@ -560,3 +581,143 @@ WarpX::EvolveF (int lev, PatchType patch_type, Real a_dt, DtType a_dt_type)
}
}
+#ifdef WARPX_DIM_RZ
+// This scales the current by the inverse volume and wraps around the depostion at negative radius.
+// It is faster to apply this on the grid than to do it particle by particle.
+// It is put here since there isn't another nice place for it.
+void
+WarpX::ApplyInverseVolumeScalingToCurrentDensity (MultiFab* Jx, MultiFab* Jy, MultiFab* Jz, int lev)
+{
+ const long ngJ = Jx->nGrow();
+ const std::array<Real,3>& dx = WarpX::CellSize(lev);
+ const Real dr = dx[0];
+
+ Box tilebox;
+
+ for ( MFIter mfi(*Jx, TilingIfNotGPU()); mfi.isValid(); ++mfi )
+ {
+
+ Array4<Real> const& Jr_arr = Jx->array(mfi);
+ Array4<Real> const& Jt_arr = Jy->array(mfi);
+ Array4<Real> const& Jz_arr = Jz->array(mfi);
+
+ tilebox = mfi.tilebox();
+ Box tbr = convert(tilebox, WarpX::jx_nodal_flag);
+ Box tbt = convert(tilebox, WarpX::jy_nodal_flag);
+ Box tbz = convert(tilebox, WarpX::jz_nodal_flag);
+
+ // Lower corner of tile box physical domain
+ // Note that this is done before the tilebox.grow so that
+ // these do not include the guard cells.
+ const std::array<Real, 3>& xyzmin = WarpX::LowerCorner(tilebox, lev);
+ const Dim3 lo = lbound(tilebox);
+ const Real rmin = xyzmin[0];
+ const int irmin = lo.x;
+
+ // Rescale current in r-z mode since the inverse volume factor was not
+ // included in the current deposition.
+ amrex::ParallelFor(tbr,
+ [=] AMREX_GPU_DEVICE (int i, int j, int k)
+ {
+ // Wrap the current density deposited in the guard cells around
+ // to the cells above the axis.
+ // Note that Jr(i==0) is at 1/2 dr.
+ if (rmin == 0. && 0 <= i && i < ngJ) {
+ Jr_arr(i,j,0) -= Jr_arr(-1-i,j,0);
+ }
+ // Apply the inverse volume scaling
+ // Since Jr is not cell centered in r, no need for distinction
+ // between on axis and off-axis factors
+ const amrex::Real r = std::abs(rmin + (i - irmin + 0.5)*dr);
+ Jr_arr(i,j,0) /= (2.*MathConst::pi*r);
+ });
+ amrex::ParallelFor(tbt,
+ [=] AMREX_GPU_DEVICE (int i, int j, int k)
+ {
+ // Wrap the current density deposited in the guard cells around
+ // to the cells above the axis.
+ // Jt is located on the boundary
+ if (rmin == 0. && 0 < i && i <= ngJ) {
+ Jt_arr(i,j,0) += Jt_arr(-i,j,0);
+ }
+
+ // Apply the inverse volume scaling
+ // Jt is forced to zero on axis.
+ const amrex::Real r = std::abs(rmin + (i - irmin)*dr);
+ if (r == 0.) {
+ Jt_arr(i,j,0) = 0.;
+ } else {
+ Jt_arr(i,j,0) /= (2.*MathConst::pi*r);
+ }
+ });
+ amrex::ParallelFor(tbz,
+ [=] AMREX_GPU_DEVICE (int i, int j, int k)
+ {
+ // Wrap the current density deposited in the guard cells around
+ // to the cells above the axis.
+ // Jz is located on the boundary
+ if (rmin == 0. && 0 < i && i <= ngJ) {
+ Jz_arr(i,j,0) += Jz_arr(-i,j,0);
+ }
+
+ // Apply the inverse volume scaling
+ const amrex::Real r = std::abs(rmin + (i - irmin)*dr);
+ if (r == 0.) {
+ // Verboncoeur JCP 164, 421-427 (2001) : corrected volume on axis
+ Jz_arr(i,j,0) /= (MathConst::pi*dr/3.);
+ } else {
+ Jz_arr(i,j,0) /= (2.*MathConst::pi*r);
+ }
+ });
+ }
+}
+
+void
+WarpX::ApplyInverseVolumeScalingToChargeDensity (MultiFab* Rho, int lev)
+{
+ const long ngRho = Rho->nGrow();
+ const std::array<Real,3>& dx = WarpX::CellSize(lev);
+ const Real dr = dx[0];
+
+ Box tilebox;
+
+ for ( MFIter mfi(*Rho, TilingIfNotGPU()); mfi.isValid(); ++mfi )
+ {
+
+ Array4<Real> const& Rho_arr = Rho->array(mfi);
+
+ tilebox = mfi.tilebox();
+ Box tb = convert(tilebox, IntVect::TheUnitVector());
+
+ // Lower corner of tile box physical domain
+ // Note that this is done before the tilebox.grow so that
+ // these do not include the guard cells.
+ const std::array<Real, 3>& xyzmin = WarpX::LowerCorner(tilebox, lev);
+ const Dim3 lo = lbound(tilebox);
+ const Real rmin = xyzmin[0];
+ const int irmin = lo.x;
+
+ // Rescale charge in r-z mode since the inverse volume factor was not
+ // included in the charge deposition.
+ amrex::ParallelFor(tb, Rho->nComp(),
+ [=] AMREX_GPU_DEVICE (int i, int j, int k, int icomp)
+ {
+ // Wrap the charge density deposited in the guard cells around
+ // to the cells above the axis.
+ // Rho is located on the boundary
+ if (rmin == 0. && 0 < i && i <= ngRho) {
+ Rho_arr(i,j,0,icomp) += Rho_arr(-i,j,0,icomp);
+ }
+
+ // Apply the inverse volume scaling
+ const amrex::Real r = std::abs(rmin + (i - irmin)*dr);
+ if (r == 0.) {
+ // Verboncoeur JCP 164, 421-427 (2001) : corrected volume on axis
+ Rho_arr(i,j,0,icomp) /= (MathConst::pi*dr/3.);
+ } else {
+ Rho_arr(i,j,0,icomp) /= (2.*MathConst::pi*r);
+ }
+ });
+ }
+}
+#endif