Skip to content

Commit

Permalink
Output Runtime Attribute "s_lost"
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Nov 22, 2023
1 parent 317e2c1 commit d0f3f4f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 50 deletions.
20 changes: 20 additions & 0 deletions src/particles/ImpactXParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ namespace impactx
DepositCharge (std::unordered_map<int, amrex::MultiFab> & rho,
amrex::Vector<amrex::IntVect> const & ref_ratio);

/** Get the name of each Real AoS component */
std::vector<std::string>
RealAoS_names () const;

/** Get the name of each Real SoA component */
std::vector<std::string>
RealSoA_names () const;

private:

//! the reference particle for the beam in the particle container
Expand All @@ -282,6 +290,18 @@ namespace impactx

}; // ImpactXParticleContainer

/** Get the name of each Real AoS component */
std::vector<std::string>
get_RealAoS_names ();

/** Get the name of each Real SoA component
*
* @param num_real_comps number of compile-time + runtime arrays
* @return names
*/
std::vector<std::string>
get_RealSoA_names (int num_real_comps);

} // namespace impactx

#endif // IMPACTX_PARTICLE_CONTAINER_H
41 changes: 41 additions & 0 deletions src/particles/ImpactXParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,45 @@ namespace impactx
ImpactXParticleContainer, RealSoA::w
>(*this);
}

std::vector<std::string>
ImpactXParticleContainer::RealAoS_names () const
{
return get_RealAoS_names();
}

std::vector<std::string>
ImpactXParticleContainer::RealSoA_names () const
{
return get_RealSoA_names(this->NumRealComps());
}

std::vector<std::string>
get_RealAoS_names ()
{
std::vector<std::string> real_aos_names(RealAoS::names_s.size());

// compile-time attributes
std::copy(RealAoS::names_s.begin(), RealAoS::names_s.end(), real_aos_names.begin());

return real_aos_names;
}

std::vector<std::string>
get_RealSoA_names (int num_real_comps)
{
std::vector<std::string> real_soa_names(num_real_comps);

// compile-time attributes
std::copy(RealSoA::names_s.begin(), RealSoA::names_s.end(), real_soa_names.begin());

// runtime attributes
if (num_real_comps > int(RealSoA::names_s.size()))
{
// particles lost record their "s" position where they got lost
real_soa_names[RealSoA::nattribs] = "s_lost";
}

return real_soa_names;
}
} // namespace impactx
14 changes: 5 additions & 9 deletions src/particles/elements/diagnostics/openPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ namespace detail

// AoS: Real
{
std::vector<std::string> real_aos_names(RealAoS::names_s.size());
std::copy(RealAoS::names_s.begin(), RealAoS::names_s.end(), real_aos_names.begin());
std::vector<std::string> real_aos_names = get_RealAoS_names();
for (auto real_idx=0; real_idx < RealAoS::nattribs; real_idx++) {
auto const component_name = real_aos_names.at(real_idx);
getComponentRecord(component_name).resetDataset(d_fl);
Expand Down Expand Up @@ -293,9 +292,8 @@ namespace detail

// SoA: Real
{
std::vector<std::string> real_soa_names(RealSoA::names_s.size());
std::copy(RealSoA::names_s.begin(), RealSoA::names_s.end(), real_soa_names.begin());
for (auto real_idx = 0; real_idx < RealSoA::nattribs; real_idx++) {
std::vector<std::string> real_soa_names = get_RealSoA_names(pc.NumRealComps());
for (auto real_idx = 0; real_idx < pc.NumRealComps(); real_idx++) {
auto const component_name = real_soa_names.at(real_idx);
getComponentRecord(component_name).resetDataset(d_fl);
}
Expand Down Expand Up @@ -426,10 +424,8 @@ namespace detail
auto const& soa = pti.GetStructOfArrays();
// SoA floating point (ParticleReal) properties
{
std::vector<std::string> real_soa_names(RealSoA::names_s.size());
std::copy(RealSoA::names_s.begin(), RealSoA::names_s.end(), real_soa_names.begin());

for (auto real_idx=0; real_idx < RealSoA::nattribs; real_idx++) {
std::vector<std::string> real_soa_names = get_RealSoA_names(soa.NumRealComps());
for (auto real_idx=0; real_idx < soa.NumRealComps(); real_idx++) {
auto const component_name = real_soa_names.at(real_idx);
getComponentRecord(component_name).storeChunkRaw(
soa.GetRealData(real_idx).data(), {offset}, {numParticleOnTile64});
Expand Down
47 changes: 13 additions & 34 deletions src/python/ImpactXParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,6 @@ using namespace impactx;

void init_impactxparticlecontainer(py::module& m)
{
py::class_<RealAoS>(m, "RealAoS")
.def_property_readonly_static("names_s",
[](py::object) {
std::vector<std::string> real_aos_names(RealAoS::names_s.size());
std::copy(RealAoS::names_s.begin(), RealAoS::names_s.end(), real_aos_names.begin());
return real_aos_names;
},
"named labels for fixed s")
.def_property_readonly_static("names_t",
[](py::object) {
std::vector<std::string> real_aos_names(RealAoS::names_t.size());
std::copy(RealAoS::names_t.begin(), RealAoS::names_t.end(), real_aos_names.begin());
return real_aos_names;
},
"named labels for fixed t")
;

py::class_<RealSoA>(m, "RealSoA")
.def_property_readonly_static("names_s",
[](py::object) {
std::vector<std::string> real_soa_names(RealSoA::names_s.size());
std::copy(RealSoA::names_s.begin(), RealSoA::names_s.end(), real_soa_names.begin());
return real_soa_names;
},
"named labels for fixed s")
.def_property_readonly_static("names_t",
[](py::object) {
std::vector<std::string> real_soa_names(RealSoA::names_t.size());
std::copy(RealSoA::names_t.begin(), RealSoA::names_t.end(), real_soa_names.begin());
return real_soa_names;
},
"named labels for fixed t")
;

py::class_<
ParIter,
amrex::ParIter<0, 0, RealSoA::nattribs, IntSoA::nattribs>
Expand Down Expand Up @@ -150,5 +116,18 @@ void init_impactxparticlecontainer(py::module& m)
"Charge deposition"
)
*/

.def_property_readonly("RealAoS_names", &ImpactXParticleContainer::RealAoS_names,
"Get the name of each Real AoS component")

.def_property_readonly("RealSoA_names", &ImpactXParticleContainer::RealSoA_names,
"Get the name of each Real SoA component")
;

m.def("get_RealAoS_names", &get_RealAoS_names,
"Get the name of each Real AoS component");

m.def("get_RealSoA_names", &get_RealSoA_names,
py::arg("num_real_comps"),
"Get the name of each Real SoA component\n\nnum_real_comps: pass number of compile-time + runtime arrays");
}
11 changes: 4 additions & 7 deletions src/python/impactx/ImpactXParticleContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def ix_pc_to_df(self, local=True, comm=None, root_rank=0):
Parameters
----------
self : amrex.ParticleContainer_*
A ParticleContainer class in pyAMReX
self : ImpactXParticleContainer_*
The particle container class in ImpactX
local : bool
MPI-local particles
comm : MPI Communicator
Expand All @@ -36,17 +36,14 @@ def ix_pc_to_df(self, local=True, comm=None, root_rank=0):
# todo: check if currently in fixed s or fixed t and pick name accordingly

names = []
for n in self.RealAoS.names_s:
for n in self.RealAoS_names:
names.append(n)
names.append("cpuid")
for n in self.RealSoA.names_s:
for n in self.RealSoA_names:
names.append(n)

df.columns.values[0 : len(names)] = names

# todo: also rename runtime attributes (e.g., "s_lost")
# https://github.com/ECP-WarpX/impactx/pull/398

return df


Expand Down

0 comments on commit d0f3f4f

Please sign in to comment.