diff options
author | 2021-07-15 15:39:34 -0700 | |
---|---|---|
committer | 2021-07-15 15:39:34 -0700 | |
commit | 300c1659c4bcdae104f828c01de8873743f73d94 (patch) | |
tree | 5a220db0c8c74c8d5689955a0d095d6c1cd9d057 /Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp | |
parent | 730e9f416363a6f31a19a06c8c0654aa79b928ce (diff) | |
download | WarpX-300c1659c4bcdae104f828c01de8873743f73d94.tar.gz WarpX-300c1659c4bcdae104f828c01de8873743f73d94.tar.zst WarpX-300c1659c4bcdae104f828c01de8873743f73d94.zip |
Spectral Index: Replace `struct`s of `enum` with Class (#2062)
* Add New Spectral Index Class
* Cleaning
* Use New Spectral Index Class in PML
* Cleaning
* Reuse Available Data for divE
* Allocate Rho Data Only when Necessary
* Cleaning
* Fix Bug in RZ Geometry
* Revert Commits for Allocation of Rho Data
* Cleaning
* Update Forward Declaration Header
* Do Not Include Unnecessary Header Files
* Doxygen
* Do Not Use Separate div() Cleaning Flags
* SpectralFieldIndex: Add Missing param to Doxygen
* Remove Unused getRequiredNumberOfFields
Diffstat (limited to 'Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp')
-rw-r--r-- | Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp index d78ece8f5..f80ee7749 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/ComovingPsatdAlgorithm.cpp @@ -22,6 +22,7 @@ using namespace amrex; ComovingPsatdAlgorithm::ComovingPsatdAlgorithm (const SpectralKSpace& spectral_kspace, const DistributionMapping& dm, + const SpectralFieldIndex& spectral_index, const int norder_x, const int norder_y, const int norder_z, const bool nodal, const amrex::IntVect& fill_guards, @@ -29,7 +30,8 @@ ComovingPsatdAlgorithm::ComovingPsatdAlgorithm (const SpectralKSpace& spectral_k const amrex::Real dt, const bool update_with_rho) // Members initialization - : SpectralBaseAlgorithm(spectral_kspace, dm, norder_x, norder_y, norder_z, nodal, fill_guards), + : SpectralBaseAlgorithm(spectral_kspace, dm, spectral_index, norder_x, norder_y, norder_z, nodal, fill_guards), + m_spectral_index(spectral_index), // Initialize the infinite-order k vectors (the argument n_order = -1 selects // the infinite order option, the argument nodal = false is then irrelevant) kx_vec(spectral_kspace.getModifiedKComponent(dm, 0, -1, false)), @@ -64,6 +66,8 @@ ComovingPsatdAlgorithm::ComovingPsatdAlgorithm (const SpectralKSpace& spectral_k void ComovingPsatdAlgorithm::pushSpectralFields (SpectralFieldData& f) const { + const SpectralFieldIndex& Idx = m_spectral_index; + // Loop over boxes for (amrex::MFIter mfi(f.fields); mfi.isValid(); ++mfi){ @@ -91,20 +95,19 @@ ComovingPsatdAlgorithm::pushSpectralFields (SpectralFieldData& f) const amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Record old values of the fields to be updated - using Idx = SpectralFieldIndex; - const Complex Ex_old = fields(i,j,k,Idx::Ex); - const Complex Ey_old = fields(i,j,k,Idx::Ey); - const Complex Ez_old = fields(i,j,k,Idx::Ez); - const Complex Bx_old = fields(i,j,k,Idx::Bx); - const Complex By_old = fields(i,j,k,Idx::By); - const Complex Bz_old = fields(i,j,k,Idx::Bz); + const Complex Ex_old = fields(i,j,k,Idx.Ex); + const Complex Ey_old = fields(i,j,k,Idx.Ey); + const Complex Ez_old = fields(i,j,k,Idx.Ez); + const Complex Bx_old = fields(i,j,k,Idx.Bx); + const Complex By_old = fields(i,j,k,Idx.By); + const Complex Bz_old = fields(i,j,k,Idx.Bz); // Shortcuts for the values of J and rho - const Complex Jx = fields(i,j,k,Idx::Jx); - const Complex Jy = fields(i,j,k,Idx::Jy); - const Complex Jz = fields(i,j,k,Idx::Jz); - const Complex rho_old = fields(i,j,k,Idx::rho_old); - const Complex rho_new = fields(i,j,k,Idx::rho_new); + const Complex Jx = fields(i,j,k,Idx.Jx); + const Complex Jy = fields(i,j,k,Idx.Jy); + const Complex Jz = fields(i,j,k,Idx.Jz); + const Complex rho_old = fields(i,j,k,Idx.rho_old); + const Complex rho_new = fields(i,j,k,Idx.rho_new); // k vector values const amrex::Real kx_mod = modified_kx_arr[i]; @@ -130,23 +133,23 @@ ComovingPsatdAlgorithm::pushSpectralFields (SpectralFieldData& f) const const Complex X4 = X4_arr(i,j,k); // Update E - fields(i,j,k,Idx::Ex) = C*Ex_old + S_ck*c2*I*(ky_mod*Bz_old - kz_mod*By_old) + fields(i,j,k,Idx.Ex) = C*Ex_old + S_ck*c2*I*(ky_mod*Bz_old - kz_mod*By_old) + X4*Jx - I*(X2*rho_new - X3*rho_old)*kx_mod; - fields(i,j,k,Idx::Ey) = C*Ey_old + S_ck*c2*I*(kz_mod*Bx_old - kx_mod*Bz_old) + fields(i,j,k,Idx.Ey) = C*Ey_old + S_ck*c2*I*(kz_mod*Bx_old - kx_mod*Bz_old) + X4*Jy - I*(X2*rho_new - X3*rho_old)*ky_mod; - fields(i,j,k,Idx::Ez) = C*Ez_old + S_ck*c2*I*(kx_mod*By_old - ky_mod*Bx_old) + fields(i,j,k,Idx.Ez) = C*Ez_old + S_ck*c2*I*(kx_mod*By_old - ky_mod*Bx_old) + X4*Jz - I*(X2*rho_new - X3*rho_old)*kz_mod; // Update B - fields(i,j,k,Idx::Bx) = C*Bx_old - S_ck*I*(ky_mod*Ez_old - kz_mod*Ey_old) + fields(i,j,k,Idx.Bx) = C*Bx_old - S_ck*I*(ky_mod*Ez_old - kz_mod*Ey_old) + X1*I*(ky_mod*Jz - kz_mod*Jy); - fields(i,j,k,Idx::By) = C*By_old - S_ck*I*(kz_mod*Ex_old - kx_mod*Ez_old) + fields(i,j,k,Idx.By) = C*By_old - S_ck*I*(kz_mod*Ex_old - kx_mod*Ez_old) + X1*I*(kz_mod*Jx - kx_mod*Jz); - fields(i,j,k,Idx::Bz) = C*Bz_old - S_ck*I*(kx_mod*Ey_old - ky_mod*Ex_old) + fields(i,j,k,Idx.Bz) = C*Bz_old - S_ck*I*(kx_mod*Ey_old - ky_mod*Ex_old) + X1*I*(kx_mod*Jy - ky_mod*Jx); }); } @@ -416,14 +419,14 @@ ComovingPsatdAlgorithm::CurrentCorrection (const int lev, // Profiling BL_PROFILE("ComovingAlgorithm::CurrentCorrection"); - using Idx = SpectralFieldIndex; + const SpectralFieldIndex& Idx = m_spectral_index; // Forward Fourier transform of J and rho - field_data.ForwardTransform(lev, *current[0], Idx::Jx, 0); - field_data.ForwardTransform(lev, *current[1], Idx::Jy, 0); - field_data.ForwardTransform(lev, *current[2], Idx::Jz, 0); - field_data.ForwardTransform(lev, *rho, Idx::rho_old, 0); - field_data.ForwardTransform(lev, *rho, Idx::rho_new, 1); + field_data.ForwardTransform(lev, *current[0], Idx.Jx, 0); + field_data.ForwardTransform(lev, *current[1], Idx.Jy, 0); + field_data.ForwardTransform(lev, *current[2], Idx.Jz, 0); + field_data.ForwardTransform(lev, *rho, Idx.rho_old, 0); + field_data.ForwardTransform(lev, *rho, Idx.rho_new, 1); const amrex::IntVect& fill_guards = m_fill_guards; @@ -457,11 +460,11 @@ ComovingPsatdAlgorithm::CurrentCorrection (const int lev, amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { // Shortcuts for the values of J and rho - const Complex Jx = fields(i,j,k,Idx::Jx); - const Complex Jy = fields(i,j,k,Idx::Jy); - const Complex Jz = fields(i,j,k,Idx::Jz); - const Complex rho_old = fields(i,j,k,Idx::rho_old); - const Complex rho_new = fields(i,j,k,Idx::rho_new); + const Complex Jx = fields(i,j,k,Idx.Jx); + const Complex Jy = fields(i,j,k,Idx.Jy); + const Complex Jz = fields(i,j,k,Idx.Jz); + const Complex rho_old = fields(i,j,k,Idx.rho_old); + const Complex rho_new = fields(i,j,k,Idx.rho_new); // k vector values, and coefficients const amrex::Real kx_mod = modified_kx_arr[i]; @@ -492,24 +495,24 @@ ComovingPsatdAlgorithm::CurrentCorrection (const int lev, const Complex theta = amrex::exp(- I * k_dot_v * dt * 0.5_rt); const Complex den = 1._rt - theta * theta; - fields(i,j,k,Idx::Jx) = Jx - (kmod_dot_J + k_dot_v * theta * (rho_new - rho_old) / den) * kx_mod / (knorm_mod * knorm_mod); - fields(i,j,k,Idx::Jy) = Jy - (kmod_dot_J + k_dot_v * theta * (rho_new - rho_old) / den) * ky_mod / (knorm_mod * knorm_mod); - fields(i,j,k,Idx::Jz) = Jz - (kmod_dot_J + k_dot_v * theta * (rho_new - rho_old) / den) * kz_mod / (knorm_mod * knorm_mod); + fields(i,j,k,Idx.Jx) = Jx - (kmod_dot_J + k_dot_v * theta * (rho_new - rho_old) / den) * kx_mod / (knorm_mod * knorm_mod); + fields(i,j,k,Idx.Jy) = Jy - (kmod_dot_J + k_dot_v * theta * (rho_new - rho_old) / den) * ky_mod / (knorm_mod * knorm_mod); + fields(i,j,k,Idx.Jz) = Jz - (kmod_dot_J + k_dot_v * theta * (rho_new - rho_old) / den) * kz_mod / (knorm_mod * knorm_mod); } else { - fields(i,j,k,Idx::Jx) = Jx - (kmod_dot_J - I * (rho_new - rho_old) / dt) * kx_mod / (knorm_mod * knorm_mod); - fields(i,j,k,Idx::Jy) = Jy - (kmod_dot_J - I * (rho_new - rho_old) / dt) * ky_mod / (knorm_mod * knorm_mod); - fields(i,j,k,Idx::Jz) = Jz - (kmod_dot_J - I * (rho_new - rho_old) / dt) * kz_mod / (knorm_mod * knorm_mod); + fields(i,j,k,Idx.Jx) = Jx - (kmod_dot_J - I * (rho_new - rho_old) / dt) * kx_mod / (knorm_mod * knorm_mod); + fields(i,j,k,Idx.Jy) = Jy - (kmod_dot_J - I * (rho_new - rho_old) / dt) * ky_mod / (knorm_mod * knorm_mod); + fields(i,j,k,Idx.Jz) = Jz - (kmod_dot_J - I * (rho_new - rho_old) / dt) * kz_mod / (knorm_mod * knorm_mod); } } }); } // Backward Fourier transform of J - field_data.BackwardTransform(lev, *current[0], Idx::Jx, 0, fill_guards); - field_data.BackwardTransform(lev, *current[1], Idx::Jy, 0, fill_guards); - field_data.BackwardTransform(lev, *current[2], Idx::Jz, 0, fill_guards); + field_data.BackwardTransform(lev, *current[0], Idx.Jx, 0, fill_guards); + field_data.BackwardTransform(lev, *current[1], Idx.Jy, 0, fill_guards); + field_data.BackwardTransform(lev, *current[2], Idx.Jz, 0, fill_guards); } void |