-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output the potential phi on the macroparticles #4599
Changes from all commits
96c0643
9670ecc
abc846d
776d106
40d88aa
9e29cf4
c502717
cbe8172
e260a0a
cc9caf7
10cf0fe
d123e91
e0df6e1
288a771
f9f84b5
b429847
8493d01
317aa16
423414e
06dbe71
82181ca
7c3f679
21d8058
3b5b1b7
f540222
b79720d
f977aa6
a918c69
d8ce701
a43a65f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -548,48 +548,6 @@ for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { | |||||
pinned_pc->make_alike<amrex::PinnedArenaAllocator>() : | ||||||
pc->make_alike<amrex::PinnedArenaAllocator>(); | ||||||
|
||||||
// names of amrex::Real and int particle attributes in SoA data | ||||||
amrex::Vector<std::string> real_names; | ||||||
amrex::Vector<std::string> int_names; | ||||||
amrex::Vector<int> int_flags; | ||||||
amrex::Vector<int> real_flags; | ||||||
|
||||||
// see openPMD ED-PIC extension for namings | ||||||
// note: an underscore separates the record name from its component | ||||||
// for non-scalar records | ||||||
// note: in RZ, we reconstruct x,y,z positions from r,z,theta in WarpX | ||||||
#if !defined (WARPX_DIM_1D_Z) | ||||||
real_names.push_back("position_x"); | ||||||
#endif | ||||||
#if defined (WARPX_DIM_3D) || defined(WARPX_DIM_RZ) | ||||||
real_names.push_back("position_y"); | ||||||
#endif | ||||||
real_names.push_back("position_z"); | ||||||
real_names.push_back("weighting"); | ||||||
real_names.push_back("momentum_x"); | ||||||
real_names.push_back("momentum_y"); | ||||||
real_names.push_back("momentum_z"); | ||||||
|
||||||
// get the names of the real comps | ||||||
real_names.resize(tmp.NumRealComps()); | ||||||
auto runtime_rnames = tmp.getParticleRuntimeComps(); | ||||||
for (auto const& x : runtime_rnames) | ||||||
{ | ||||||
real_names[x.second+PIdx::nattribs] = detail::snakeToCamel(x.first); | ||||||
} | ||||||
// plot any "extra" fields by default | ||||||
real_flags = particle_diags[i].m_plot_flags; | ||||||
real_flags.resize(tmp.NumRealComps(), 1); | ||||||
// and the names | ||||||
int_names.resize(tmp.NumIntComps()); | ||||||
auto runtime_inames = tmp.getParticleRuntimeiComps(); | ||||||
for (auto const& x : runtime_inames) | ||||||
{ | ||||||
int_names[x.second+0] = detail::snakeToCamel(x.first); | ||||||
} | ||||||
// plot by default | ||||||
int_flags.resize(tmp.NumIntComps(), 1); | ||||||
|
||||||
const auto mass = pc->AmIA<PhysicalSpecies::photon>() ? PhysConst::m_e : pc->getMass(); | ||||||
RandomFilter const random_filter(particle_diags[i].m_do_random_filter, | ||||||
particle_diags[i].m_random_fraction); | ||||||
|
@@ -631,6 +589,76 @@ for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { | |||||
particlesConvertUnits(ConvertDirection::SI_to_WarpX, pc, mass); | ||||||
} | ||||||
|
||||||
// Gather the electrostatic potential (phi) on the macroparticles | ||||||
if ( particle_diags[i].m_plot_phi ) { | ||||||
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( | ||||||
Comment on lines
+592
to
+594
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this if block a function call please so it does separate out nicely and does not make this sub-function longer? I would call it |
||||||
(WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame) || | ||||||
(WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic), | ||||||
"Output of the electrostatic potential (phi) on the particles was requested, " | ||||||
"but this is only available for `warpx.do_electrostatic=labframe` or `labframe-electromagnetostatic`."); | ||||||
// Using pinned PC indicates that the particles are not written at the same physical time (i.e. PIC iteration) | ||||||
// that they were collected. This happens for diagnostics that use buffering (e.g. BackTransformed, BoundaryScraping). | ||||||
// Here `phi` is gathered at the iteration when particles are written (not collected) and is thus mismatched. | ||||||
// To avoid confusion, we raise an error in this case. | ||||||
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( | ||||||
use_pinned_pc == false, | ||||||
"Output of the electrostatic potential (phi) on the particles was requested, " | ||||||
"but this is only available with `diag_type = Full`."); | ||||||
tmp.AddRealComp("phi"); | ||||||
int const phi_index = tmp.getParticleComps().at("phi"); | ||||||
auto& warpx = WarpX::GetInstance(); | ||||||
#ifdef AMREX_USE_OMP | ||||||
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) | ||||||
#endif | ||||||
for (int lev=0; lev<=warpx.finestLevel(); lev++) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const amrex::Geometry& geom = warpx.Geom(lev); | ||||||
auto plo = geom.ProbLoArray(); | ||||||
auto dxi = geom.InvCellSizeArray(); | ||||||
amrex::MultiFab const& phi = warpx.getField( FieldType::phi_fp, lev, 0 ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For less overhead, we should add a helper that returns an mf on all levels. -> follow-up pr |
||||||
storeFieldOnParticles( tmp, plo, dxi, phi, phi_index, lev ); | ||||||
} | ||||||
} | ||||||
|
||||||
// names of amrex::Real and int particle attributes in SoA data | ||||||
amrex::Vector<std::string> real_names; | ||||||
amrex::Vector<std::string> int_names; | ||||||
amrex::Vector<int> int_flags; | ||||||
amrex::Vector<int> real_flags; | ||||||
// see openPMD ED-PIC extension for namings | ||||||
// note: an underscore separates the record name from its component | ||||||
// for non-scalar records | ||||||
// note: in RZ, we reconstruct x,y,z positions from r,z,theta in WarpX | ||||||
#if !defined (WARPX_DIM_1D_Z) | ||||||
real_names.push_back("position_x"); | ||||||
#endif | ||||||
#if defined (WARPX_DIM_3D) || defined(WARPX_DIM_RZ) | ||||||
real_names.push_back("position_y"); | ||||||
#endif | ||||||
real_names.push_back("position_z"); | ||||||
real_names.push_back("weighting"); | ||||||
real_names.push_back("momentum_x"); | ||||||
real_names.push_back("momentum_y"); | ||||||
real_names.push_back("momentum_z"); | ||||||
// get the names of the real comps | ||||||
real_names.resize(tmp.NumRealComps()); | ||||||
auto runtime_rnames = tmp.getParticleRuntimeComps(); | ||||||
for (auto const& x : runtime_rnames) | ||||||
{ | ||||||
real_names[x.second+PIdx::nattribs] = detail::snakeToCamel(x.first); | ||||||
} | ||||||
// plot any "extra" fields by default | ||||||
real_flags = particle_diags[i].m_plot_flags; | ||||||
real_flags.resize(tmp.NumRealComps(), 1); | ||||||
// and the names | ||||||
int_names.resize(tmp.NumIntComps()); | ||||||
auto runtime_inames = tmp.getParticleRuntimeiComps(); | ||||||
for (auto const& x : runtime_inames) | ||||||
{ | ||||||
int_names[x.second+0] = detail::snakeToCamel(x.first); | ||||||
} | ||||||
// plot by default | ||||||
int_flags.resize(tmp.NumIntComps(), 1); | ||||||
|
||||||
// real_names contains a list of all real particle attributes. | ||||||
// real_flags is 1 or 0, whether quantity is dumped or not. | ||||||
DumpToFile(&tmp, | ||||||
|
@@ -640,9 +668,8 @@ for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { | |||||
int_flags, | ||||||
real_names, int_names, | ||||||
pc->getCharge(), pc->getMass(), | ||||||
isBTD, isLastBTDFlush | ||||||
); | ||||||
} | ||||||
isBTD, isLastBTDFlush); | ||||||
} | ||||||
} | ||||||
|
||||||
void | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to move this code further down, so that it comes after
tmp.AddRealComp("phi");
(This is because the code below reads
tmp.getParticleRuntimeComps();
and sets the output flags accordingly.)