Skip to content
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

Particle Names from AMReX #805

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/dependencies/ABLASTR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ set(ImpactX_openpmd_src ""
set(ImpactX_ablastr_repo "https://github.com/ECP-WarpX/WarpX.git"
CACHE STRING
"Repository URI to pull and build ABLASTR from if(ImpactX_ablastr_internal)")
set(ImpactX_ablastr_branch "25.01"
set(ImpactX_ablastr_branch "958a39463c9e3fea0bbe1da0306104ccf9a2164c"
CACHE STRING
"Repository branch for ImpactX_ablastr_repo if(ImpactX_ablastr_internal)")

# AMReX is transitively pulled through ABLASTR
set(ImpactX_amrex_repo "https://github.com/AMReX-Codes/amrex.git"
CACHE STRING
"Repository URI to pull and build AMReX from if(ImpactX_amrex_internal)")
set(ImpactX_amrex_branch "f6d3d70cadfc03036f5fdc4f89b7fcb225792716"
set(ImpactX_amrex_branch ""
CACHE STRING
"Repository branch for ImpactX_amrex_repo if(ImpactX_amrex_internal)")

Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies/pyAMReX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ option(ImpactX_pyamrex_internal "Download & build pyAMReX" ON)
set(ImpactX_pyamrex_repo "https://github.com/AMReX-Codes/pyamrex.git"
CACHE STRING
"Repository URI to pull and build pyamrex from if(ImpactX_pyamrex_internal)")
set(ImpactX_pyamrex_branch "25.01"
set(ImpactX_pyamrex_branch "458c9ae7ab3cd4ca4e4e9736e82c60f9a7e7606c"
CACHE STRING
"Repository branch for ImpactX_pyamrex_repo if(ImpactX_pyamrex_internal)")

Expand Down
4 changes: 3 additions & 1 deletion examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
-r ../requirements.txt
# Work-Around for https://github.com/nkarast/PyNAFF/pull/10
# pynaff
git+https://github.com/ax3l/PyNAFF.git@fix-complex-warning
matplotlib
numpy
openpmd-api
pandas
pynaff
scipy
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
numpy~=1.15
numpy>=1.15
quantiphy~=2.19
8 changes: 4 additions & 4 deletions src/particles/CollectLost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace impactx
ImpactXParticleContainer& dest = *source.GetLostParticleContainer();

// Check destination has the same attributes as source + "s_lost"
for (auto & name : source.RealSoA_names())
for (auto & name : source.GetRealSoANames())
{
if (!dest.HasRealComp(name)) {
amrex::Print() << "adding " << name << std::endl;
Expand All @@ -67,7 +67,7 @@ namespace impactx
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetRealCompIndex(name) == dest.GetRealCompIndex(name),
"Source and destination Real attributes misaligned!");
}
for (auto & name : source.intSoA_names())
for (auto & name : source.GetIntSoANames())
{
if (!dest.HasIntComp(name)) {
dest.AddIntComp(name);
Expand All @@ -81,9 +81,9 @@ namespace impactx
bool comm = true;
dest.AddRealComp("s_lost", comm);
}
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.RealSoA_names().size() + 1 == dest.RealSoA_names().size(),
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetRealSoANames().size() + 1 == dest.GetRealSoANames().size(),
"Source and destination have different Real attributes!");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.intSoA_names().size() == dest.intSoA_names().size(),
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetIntSoANames().size() == dest.GetIntSoANames().size(),
"Source and destination have different Int attributes!");

const int s_runtime_index = dest.GetRealCompIndex("s_lost") - dest.NArrayReal;
Expand Down
60 changes: 0 additions & 60 deletions src/particles/ImpactXParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,6 @@ namespace impactx
//! Destruct a particle container
virtual ~ImpactXParticleContainer() = default;

/** Check if a container has a ParticleReal component
*
* @param name component name to check
* @return true if found, else false
*/
bool HasRealComp (std::string const & name);

/** Check if a container has an Integer component
*
* @param name component name to check
* @return true if found, else false
*/
bool HasIntComp (std::string const & name);

/** Get the ParticleReal SoA index of a component
*
* This throws a runtime exception if the component does not exist.
*
* @param name component name to query index for
* @return zero-based index
*/
int GetRealCompIndex (std::string const & name);

/** Get the Integer SoA index of a component
*
* This throws a runtime exception if the component does not exist.
*
* @param name component name to query index for
* @return zero-based index
*/
int GetIntCompIndex (std::string const & name);

/** Add a ParticleReal component
*
* @param name a unique name of the component, not colliding with RealSoA
* @param communicate participate in MPI communication when particles move
*/
void AddRealComp (std::string const & name, bool communicate=true);

/** Add an Integer component
*
* @param name a unique name of the component, not colliding with IntSoA
* @param communicate participate in MPI communication when particles move
*/
void AddIntComp (std::string const & name, bool communicate=true);

/** Add new particles to the container for fixed s.
*
* Note: This can only be used *after* the initialization (grids) have
Expand Down Expand Up @@ -309,14 +263,6 @@ namespace impactx
DepositCharge (std::unordered_map<int, amrex::MultiFab> & rho,
amrex::Vector<amrex::IntVect> const & ref_ratio);

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

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

/** Get the current coordinate system of particles in this container */
CoordSystem
GetCoordSystem () const;
Expand All @@ -342,12 +288,6 @@ namespace impactx
//! the current coordinate system of particles in this container
CoordSystem m_coordsystem = CoordSystem::s;

//! ParticleReal component names
std::vector<std::string> m_real_soa_names;

//! Int component names
std::vector<std::string> m_int_soa_names;

}; // ImpactXParticleContainer

} // namespace impactx
Expand Down
72 changes: 4 additions & 68 deletions src/particles/ImpactXParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,62 +59,10 @@ namespace impactx
: amrex::ParticleContainerPureSoA<RealSoA::nattribs, IntSoA::nattribs>(amr_core->GetParGDB())
{
SetParticleSize();

// name compile-time attributes
m_real_soa_names.resize(RealSoA::names_s.size());
m_int_soa_names.resize(IntSoA::names_s.size());
std::copy(RealSoA::names_s.begin(), RealSoA::names_s.end(), m_real_soa_names.begin());
std::copy(IntSoA::names_s.begin(), IntSoA::names_s.end(), m_int_soa_names.begin());
}

bool ImpactXParticleContainer::HasRealComp (std::string const & name)
{
return std::find(m_real_soa_names.begin(), m_real_soa_names.end(), name) != std::end(m_real_soa_names);
}

bool ImpactXParticleContainer::HasIntComp (std::string const & name)
{
return std::find(m_int_soa_names.begin(), m_int_soa_names.end(), name) != std::end(m_int_soa_names);
}

int ImpactXParticleContainer::GetRealCompIndex (std::string const & name)
{
const auto it = std::find(m_real_soa_names.begin(), m_real_soa_names.end(), name);

if (it == m_real_soa_names.end())
throw std::runtime_error("GetRealCompIndex: Component " + name + " does not exist!");
else
return std::distance(m_real_soa_names.begin(), it);
}

int ImpactXParticleContainer::GetIntCompIndex (std::string const & name)
{
const auto it = std::find(m_int_soa_names.begin(), m_int_soa_names.end(), name);

if (it == m_int_soa_names.end())
throw std::runtime_error("GetIntCompIndex: Component " + name + " does not exist!");
else
return std::distance(m_int_soa_names.begin(), it);
}

void
ImpactXParticleContainer::AddRealComp (std::string const & name, bool communicate)
{
if (std::find(m_real_soa_names.begin(), m_real_soa_names.end(), name) != std::end(m_real_soa_names))
throw std::runtime_error("AddRealComp: Component " + name + " already exists!");

m_real_soa_names.push_back(name);
amrex::ParticleContainerPureSoA<RealSoA::nattribs, IntSoA::nattribs>::AddRealComp(communicate);
}

void
ImpactXParticleContainer::AddIntComp (std::string const & name, bool communicate)
{
if (std::find(m_int_soa_names.begin(), m_int_soa_names.end(), name) != std::end(m_int_soa_names))
throw std::runtime_error("AddIntComp: Component " + name + " already exists!");

m_int_soa_names.push_back(name);
amrex::ParticleContainerPureSoA<RealSoA::nattribs, IntSoA::nattribs>::AddIntComp(communicate);
SetSoACompileTimeNames(
{RealSoA::names_s.begin(), RealSoA::names_s.end()},
{IntSoA::names_s.begin(), IntSoA::names_s.end()}
);
}

void
Expand Down Expand Up @@ -300,18 +248,6 @@ namespace impactx
>(*this);
}

std::vector<std::string>
ImpactXParticleContainer::RealSoA_names () const
{
return m_real_soa_names;
}

std::vector<std::string>
ImpactXParticleContainer::intSoA_names () const
{
return m_int_soa_names;
}

CoordSystem
ImpactXParticleContainer::GetCoordSystem () const
{
Expand Down
4 changes: 2 additions & 2 deletions src/particles/elements/diagnostics/openPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ namespace detail
m_rbc = diagnostics::reduced_beam_characteristics(pc);

// component names
std::vector<std::string> real_soa_names = pc.RealSoA_names();
std::vector<std::string> int_soa_names = pc.intSoA_names();
std::vector<std::string> real_soa_names = pc.GetRealSoANames();
std::vector<std::string> int_soa_names = pc.GetIntSoANames();

// pinned memory copy
PinnedContainer pinned_pc = pc.make_alike<amrex::PinnedArenaAllocator>();
Expand Down
5 changes: 0 additions & 5 deletions src/python/ImpactXParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ void init_impactxparticlecontainer(py::module& m)
"Charge deposition"
)
*/

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

py_pariter_soa.def("pc", &ParIterSoA::pc);
Expand Down
2 changes: 0 additions & 2 deletions src/python/impactx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# import core bindings to C++
from . import impactx_pybind as cxx
from .distribution_input_helpers import twiss # noqa
from .extensions.ImpactXParIter import register_ImpactXParIter_extension
from .extensions.ImpactXParticleContainer import (
register_ImpactXParticleContainer_extension,
)
Expand All @@ -43,5 +42,4 @@
RefPart.load_file = read_beam # noqa

# Pure Python extensions to ImpactX types
register_ImpactXParIter_extension(cxx)
register_ImpactXParticleContainer_extension(cxx.ImpactXParticleContainer)
81 changes: 0 additions & 81 deletions src/python/impactx/extensions/ImpactXParIter.py

This file was deleted.

Loading
Loading