From 0bb3c26570d448715f8b0f22270ab47555b77c97 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 7 Mar 2025 00:23:38 +0100 Subject: [PATCH] WarpX class: move out PSATDCurrentCorrection and PSATDVayDeposition (#5684) `PSATDCurrentCorrection` and `PSATDVayDeposition` are member functions of the WarpX class, but they are used only in `WarpXPushFieldsEM.cpp` and they can be easily turned into pure functions. Therefore, this PR moves them inside an anonymous namespace in `WarpXPushFieldsEM.cpp` . The goal is the simplification of the WarpX class. --- Source/FieldSolver/WarpXPushFieldsEM.cpp | 72 ++++++++++++++---------- Source/WarpX.H | 10 ---- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Source/FieldSolver/WarpXPushFieldsEM.cpp b/Source/FieldSolver/WarpXPushFieldsEM.cpp index 0163d158dd0..6a40e625542 100644 --- a/Source/FieldSolver/WarpXPushFieldsEM.cpp +++ b/Source/FieldSolver/WarpXPushFieldsEM.cpp @@ -100,6 +100,44 @@ namespace { solver.BackwardTransform(lev, *vector_field[2], compz, fill_guards); #endif } + + /** + * \brief Correct current in Fourier space so that the continuity equation is satisfied + */ + template + void PSATDCurrentCorrection ( + const int finest_level, + amrex::Vector>& spectral_solver_fp, + amrex::Vector>& spectral_solver_cp) + { + for (int lev = 0; lev <= finest_level; ++lev) + { + spectral_solver_fp[lev]->CurrentCorrection(); + if (spectral_solver_cp[lev]) + { + spectral_solver_cp[lev]->CurrentCorrection(); + } + } + } + + /** + * \brief Vay deposition in Fourier space (https://doi.org/10.1016/j.jcp.2013.03.010) + */ + template + void PSATDVayDeposition ( + const int finest_level, + amrex::Vector>& spectral_solver_fp, + amrex::Vector>& spectral_solver_cp) + { + for (int lev = 0; lev <= finest_level; ++lev) + { + spectral_solver_fp[lev]->VayDeposition(); + if (spectral_solver_cp[lev]) + { + spectral_solver_cp[lev]->VayDeposition(); + } + } + } } void WarpX::PSATDForwardTransformEB () @@ -466,32 +504,6 @@ void WarpX::PSATDForwardTransformRho ( #endif } -void WarpX::PSATDCurrentCorrection () -{ - for (int lev = 0; lev <= finest_level; ++lev) - { - spectral_solver_fp[lev]->CurrentCorrection(); - - if (spectral_solver_cp[lev]) - { - spectral_solver_cp[lev]->CurrentCorrection(); - } - } -} - -void WarpX::PSATDVayDeposition () -{ - for (int lev = 0; lev <= finest_level; ++lev) - { - spectral_solver_fp[lev]->VayDeposition(); - - if (spectral_solver_cp[lev]) - { - spectral_solver_cp[lev]->VayDeposition(); - } - } -} - void WarpX::PSATDSubtractCurrentPartialSumsAvg () { using ablastr::fields::Direction; @@ -744,7 +756,7 @@ WarpX::PushPSATD (amrex::Real start_time) PSATDForwardTransformRho(rho_fp_string, rho_cp_string, 1, rho_new); // Correct J in k-space - PSATDCurrentCorrection(); + ::PSATDCurrentCorrection(finest_level, spectral_solver_fp, spectral_solver_cp); // Inverse FFT of J PSATDBackwardTransformJ(current_fp_string, current_cp_string); @@ -759,7 +771,7 @@ WarpX::PushPSATD (amrex::Real start_time) PSATDForwardTransformRho(rho_fp_string, rho_cp_string, 1, rho_new); // Compute J from D in k-space - PSATDVayDeposition(); + ::PSATDVayDeposition(finest_level, spectral_solver_fp, spectral_solver_cp); // Inverse FFT of J, subtract cumulative sums of D current_fp_string = "current_fp"; @@ -797,7 +809,7 @@ WarpX::PushPSATD (amrex::Real start_time) #endif // Correct J in k-space - PSATDCurrentCorrection(); + ::PSATDCurrentCorrection(finest_level, spectral_solver_fp, spectral_solver_cp); // Inverse FFT of J PSATDBackwardTransformJ(current_fp_string, current_cp_string); @@ -813,7 +825,7 @@ WarpX::PushPSATD (amrex::Real start_time) PSATDForwardTransformJ(current_fp_string, current_cp_string); // Compute J from D in k-space - PSATDVayDeposition(); + ::PSATDVayDeposition(finest_level, spectral_solver_fp, spectral_solver_cp); // Inverse FFT of J, subtract cumulative sums of D current_fp_string = "current_fp"; diff --git a/Source/WarpX.H b/Source/WarpX.H index b70d23b9e33..56dfa3e2f10 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -1655,16 +1655,6 @@ private: */ void PSATDBackwardTransformG (); - /** - * \brief Correct current in Fourier space so that the continuity equation is satisfied - */ - void PSATDCurrentCorrection (); - - /** - * \brief Vay deposition in Fourier space (https://doi.org/10.1016/j.jcp.2013.03.010) - */ - void PSATDVayDeposition (); - /** * \brief Update all necessary fields in spectral space */