Skip to content

Commit

Permalink
Apply filtering for the charge density in full diagnostics RZ PSATD (E…
Browse files Browse the repository at this point in the history
…CP-WarpX#4624)

* Removed k-filtering when used RZ PSATD solver

* Updated CI benchmarks for galilean_rz_psatd and multi_J_rz_psatd tests

* Reversed k-space filtering for the charge density, but only in full diagnostics mode with RZ PSATD

* Clean up

* Updated CI benchmarks for galilean_rz_psatd and multi_J_rz_psatd tests

* silence the unused variable warning

* Clean up an include and move initialization to member initializer

* Removed unnecessary includes.

* Removed redundant class datamember.

* Renamed a variable from apply_rho_filter to apply_rz_psatd_filter.
  • Loading branch information
oshapoval authored Feb 8, 2024
1 parent 37a0338 commit c9bfc7e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 34 deletions.
34 changes: 17 additions & 17 deletions Regression/Checksum/benchmarks_json/galilean_rz_psatd.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"lev=0": {
"Bt": 0.0001427751611710155,
"Er": 42705.92836687861,
"Et": 198517.8121599192,
"Ez": 4124.588455632591,
"divE": 50681.523267918594,
"jr": 7.07688551916584,
"jz": 469.93281767722846,
"rho": 4.488636594605648e-07
},
"electrons": {
"particle_momentum_x": 7.188262495831869e-22,
"particle_momentum_y": 9.366670272998972e-24,
"particle_momentum_z": 8.903838605112867e-17,
"particle_momentum_x": 7.188262495831913e-22,
"particle_momentum_y": 9.366670273418532e-24,
"particle_momentum_z": 8.903838605112889e-17,
"particle_position_x": 633733.1377069331,
"particle_position_y": 7862152.008302979,
"particle_theta": 51471.82060096203,
"particle_weight": 1.0261080645329302e+20
},
"ions": {
"particle_momentum_x": 1.3139399113084718e-18,
"particle_momentum_y": 9.36530169181897e-24,
"particle_momentum_x": 1.313939911308472e-18,
"particle_momentum_y": 9.365301692233452e-24,
"particle_momentum_z": 1.6348806629857118e-13,
"particle_position_x": 633733.1365353089,
"particle_position_y": 7862152.007285856,
"particle_theta": 51471.6099169301,
"particle_weight": 1.0261080645329302e+20
},
"lev=0": {
"Bt": 0.00014277516113528766,
"Er": 42705.928351478186,
"Et": 198517.8121599189,
"Ez": 4124.588451444761,
"divE": 50681.52326965637,
"jr": 7.0768855187909985,
"jz": 469.9328176825038,
"rho": 4.488636594800136e-07
}
}
}
}
16 changes: 8 additions & 8 deletions Regression/Checksum/benchmarks_json/multi_J_rz_psatd.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"lev=0": {
"Bt": 24080.41671546337,
"Er": 4536303784778.673,
"Ez": 4298815071343.0728,
"Bt": 24080.416715463354,
"Er": 4536303784778.672,
"Ez": 4298815071343.07,
"jr": 361182004529074.8,
"jz": 1802215706551553.8,
"rho": 4884623.9573680265,
"jz": 1802215706551553.5,
"rho": 4884623.957368025,
"rho_driver": 6288266.101815153,
"rho_plasma_e": 49568366.405371524,
"rho_plasma_e": 49568366.40537152,
"rho_plasma_p": 50769182.21072973
},
"driver": {
Expand All @@ -31,10 +31,10 @@
"plasma_e": {
"particle_momentum_x": 6.655027717314839e-20,
"particle_momentum_y": 6.730480164464723e-20,
"particle_momentum_z": 2.807381166958142e-20,
"particle_momentum_z": 2.8073811669581434e-20,
"particle_position_x": 1.1423427658689635,
"particle_position_y": 0.6140113094028803,
"particle_theta": 20188.939948727297,
"particle_weight": 1002457942911.3788
}
}
}
2 changes: 1 addition & 1 deletion Source/Diagnostics/BTDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ BTDiagnostics::InitializeFieldFunctorsRZopenPMD (int lev)
} else if ( m_cellcenter_varnames_fields[comp] == "jz" ){
m_cell_center_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_current_fp(lev, 2), lev, m_crse_ratio, false, ncomp);
} else if ( m_cellcenter_varnames_fields[comp] == "rho" ){
m_cell_center_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, -1, false, ncomp);
m_cell_center_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, false, -1, false, ncomp);
}
}

Expand Down
4 changes: 4 additions & 0 deletions Source/Diagnostics/ComputeDiagFunctors/RhoFunctor.H
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public:
*/
RhoFunctor (int lev,
amrex::IntVect crse_ratio,
bool apply_rz_psatd_filter = false,
int species_index = -1,
bool convertRZmodes2cartesian = true,
int ncomp = 1);
Expand All @@ -44,6 +45,9 @@ private:
// Level on which source MultiFab mf_src is defined in RZ geometry
int const m_lev;

// Whether to apply k-space filtering of charge density in the diagnostics output in RZ PSATD
bool m_apply_rz_psatd_filter;

// Species index to dump rho per species
const int m_species_index;

Expand Down
6 changes: 5 additions & 1 deletion Source/Diagnostics/ComputeDiagFunctors/RhoFunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

RhoFunctor::RhoFunctor (const int lev,
const amrex::IntVect crse_ratio,
bool apply_rz_psatd_filter,
const int species_index,
bool convertRZmodes2cartesian,
const int ncomp)
: ComputeDiagFunctor(ncomp, crse_ratio),
m_lev(lev),
m_apply_rz_psatd_filter(apply_rz_psatd_filter),
m_species_index(species_index),
m_convertRZmodes2cartesian(convertRZmodes2cartesian)
{}
Expand Down Expand Up @@ -62,14 +64,16 @@ RhoFunctor::operator() ( amrex::MultiFab& mf_dst, const int dcomp, const int /*i
// Apply k-space filtering when using the PSATD solver
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD)
{
if (WarpX::use_kspace_filter) {
if (WarpX::use_kspace_filter && m_apply_rz_psatd_filter) {
auto & solver = warpx.get_spectral_solver_fp(m_lev);
const SpectralFieldIndex& Idx = solver.m_spectral_index;
solver.ForwardTransform(m_lev, *rho, Idx.rho_new);
solver.ApplyFilter(m_lev, Idx.rho_new);
solver.BackwardTransform(m_lev, *rho, Idx.rho_new);
}
}
#else
amrex::ignore_unused(m_apply_rz_psatd_filter);
#endif

InterpolateMFForDiag(mf_dst, *rho, dcomp, warpx.DistributionMap(m_lev),
Expand Down
11 changes: 5 additions & 6 deletions Source/Diagnostics/FullDiagnostics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "FullDiagnostics.H"

#include "ComputeDiagFunctors/CellCenterFunctor.H"
#include "ComputeDiagFunctors/DivBFunctor.H"
#include "ComputeDiagFunctors/DivEFunctor.H"
Expand Down Expand Up @@ -269,14 +268,14 @@ FullDiagnostics::InitializeFieldFunctorsRZopenPMD (int lev)
}
} else if ( m_varnames_fields[comp] == "rho" ){
// Initialize rho functor to dump total rho
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, -1,
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, true, -1,
false, ncomp);
if (update_varnames) {
AddRZModesToOutputNames(std::string("rho"), ncomp);
}
} else if ( m_varnames_fields[comp].rfind("rho_", 0) == 0 ){
// Initialize rho functor to dump rho per species
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, m_rho_per_species_index[i],
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, true, m_rho_per_species_index[i],
false, ncomp);
if (update_varnames) {
AddRZModesToOutputNames(std::string("rho_") + m_all_species_names[m_rho_per_species_index[i]], ncomp);
Expand Down Expand Up @@ -444,7 +443,7 @@ FullDiagnostics::AddRZModesToDiags (int lev)
}
// rho
if (rho_requested) {
m_all_field_functors[lev][icomp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, -1, false, ncomp_multimodefab);
m_all_field_functors[lev][icomp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, true, -1, false, ncomp_multimodefab);
icomp += 1;
AddRZModesToOutputNames(std::string("rho"), ncomp_multimodefab);
}
Expand Down Expand Up @@ -641,10 +640,10 @@ FullDiagnostics::InitializeFieldFunctors (int lev)
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_vector_potential_fp(lev, 2), lev, m_crse_ratio);
} else if ( m_varnames[comp] == "rho" ){
// Initialize rho functor to dump total rho
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio);
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, true);
} else if ( m_varnames[comp].rfind("rho_", 0) == 0 ){
// Initialize rho functor to dump rho per species
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, m_rho_per_species_index[i]);
m_all_field_functors[lev][comp] = std::make_unique<RhoFunctor>(lev, m_crse_ratio, true, m_rho_per_species_index[i]);
i++;
} else if ( m_varnames[comp] == "F" ){
m_all_field_functors[lev][comp] = std::make_unique<CellCenterFunctor>(warpx.get_pointer_F_fp(lev), lev, m_crse_ratio);
Expand Down
2 changes: 1 addition & 1 deletion Source/Diagnostics/ReducedDiags/RhoMaximum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RhoMaximum::RhoMaximum (std::string rd_name)
for (int lev = 0; lev < nLevel; ++lev)
{
// Initialize functors for the charge density of each charged species
m_rho_functors[lev].push_back(std::make_unique<RhoFunctor>(lev, crse_ratio, i));
m_rho_functors[lev].push_back(std::make_unique<RhoFunctor>(lev, crse_ratio, false, i));
}
}
}
Expand Down

0 comments on commit c9bfc7e

Please sign in to comment.