Skip to content

Commit

Permalink
WarpX class: move out PSATDCurrentCorrection and PSATDVayDeposition (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
lucafedeli88 authored Mar 6, 2025
1 parent cade319 commit 0bb3c26
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
72 changes: 42 additions & 30 deletions Source/FieldSolver/WarpXPushFieldsEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename SpectralSolverType>
void PSATDCurrentCorrection (
const int finest_level,
amrex::Vector<std::unique_ptr<SpectralSolverType>>& spectral_solver_fp,
amrex::Vector<std::unique_ptr<SpectralSolverType>>& 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 <typename SpectralSolverType>
void PSATDVayDeposition (
const int finest_level,
amrex::Vector<std::unique_ptr<SpectralSolverType>>& spectral_solver_fp,
amrex::Vector<std::unique_ptr<SpectralSolverType>>& 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 ()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand Down
10 changes: 0 additions & 10 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 0bb3c26

Please sign in to comment.