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

Add Particle I/O: restart & restart_checkpoint #342

Merged
merged 23 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions src/Particle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ foreach(D IN LISTS AMReX_SPACEDIM)
ParticleContainer_HiPACE.cpp
ParticleContainer_ImpactX.cpp
ParticleContainer_WarpX.cpp
ParticleContainer_FHDeX.cpp
ax3l marked this conversation as resolved.
Show resolved Hide resolved
)
endforeach()
36 changes: 32 additions & 4 deletions src/Particle/ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,34 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)
// const Vector<std::string>& int_comp_names = Vector<std::string>()) const
// void CheckpointPre ();
// void CheckpointPost ();

// void Restart (const std::string& dir, const std::string& file);
.def("restart",
[](
ParticleContainerType & pc,
std::string const & dir,
std::string const & file
){
return pc.Restart(dir, file);
},
ax3l marked this conversation as resolved.
Show resolved Hide resolved
py::arg("dir"),
py::arg("file")
)

// void Restart (const std::string& dir, const std::string& file, bool is_checkpoint);
.def("restart_checkpoint",
[](
ParticleContainerType & pc,
std::string const & dir,
std::string const & file,
bool is_checkpoint
){
return pc.Restart(dir, file, is_checkpoint);
},
ax3l marked this conversation as resolved.
Show resolved Hide resolved
py::arg("dir"),
py::arg("file"),
py::arg("is_checkpoint")
)

.def("write_plotfile",
//py::overload_cast<std::string const &, std::string const &>(&ParticleContainerType::WritePlotFile, py::const_),
Expand Down Expand Up @@ -436,10 +462,12 @@ void make_ParticleContainer_and_Iterators (py::module &m)
T_ParticleType::NReal,
T_ParticleType::NInt
>(m);
make_Particle< // superparticle
T_ParticleType::NReal + T_NArrayReal,
T_ParticleType::NInt + T_NArrayInt
>(m);
if (T_NArrayReal > 0 || T_NArrayInt > 0) {
make_Particle< // superparticle
T_ParticleType::NReal + T_NArrayReal,
T_ParticleType::NInt + T_NArrayInt
>(m);
}

make_ArrayOfStructs<T_ParticleType::NReal, T_ParticleType::NInt> (m);
make_StructOfArrays<T_NArrayReal, T_NArrayInt> (m);
Expand Down
2 changes: 2 additions & 0 deletions src/Particle/ParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace
void init_ParticleContainer_HiPACE(py::module& m);
void init_ParticleContainer_ImpactX(py::module& m);
void init_ParticleContainer_WarpX(py::module& m);
void init_ParticleContainer_FHDeX(py::module& m);
ax3l marked this conversation as resolved.
Show resolved Hide resolved

void init_ParticleContainer(py::module& m) {
using namespace amrex;
Expand All @@ -59,6 +60,7 @@ void init_ParticleContainer(py::module& m) {
init_ParticleContainer_HiPACE(m);
init_ParticleContainer_ImpactX(m);
init_ParticleContainer_WarpX(m);
init_ParticleContainer_FHDeX(m);
ax3l marked this conversation as resolved.
Show resolved Hide resolved

// for particle idcpu arrays
m.def("unpack_ids", py::vectorize(unpack_id));
Expand Down
12 changes: 12 additions & 0 deletions src/Particle/ParticleContainer_FHDeX.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#include "ParticleContainer.H"

#include <AMReX_Particle.H>
#include <AMReX_ParticleTile.H>


void init_ParticleContainer_FHDeX(py::module& m) {
using namespace amrex;

make_ParticleContainer_and_Iterators<Particle<16, 4>, 0, 0>(m);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JBlaschke do you need this for 1D, 2D and 3D AMReX builds or only for 3D?

}
50 changes: 50 additions & 0 deletions tests/test_plotfileparticledata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from dataclasses import dataclass

import amrex.space3d as amr

if not amr.initialized():
amr.initialize([])
ax3l marked this conversation as resolved.
Show resolved Hide resolved

plt_file_name = "plt0000600"


@dataclass
class Particle:
x: float
y: float
z: float

ib_id: int
idx: int


def load_data(plot_file_name):
plt = amr.PlotFileData(plt_file_name)

probDomain = plt.probDomain(0)
ax3l marked this conversation as resolved.
Show resolved Hide resolved
probLo = plt.probLo()
probHi = plt.probHi()
domain_box = amr.Box(probDomain.small_end, probDomain.big_end)
real_box = amr.RealBox(probLo, probHi)
std_geometry = amr.Geometry(domain_box, real_box, plt.coordSys(), [0, 0, 0])

pc = amr.ParticleContainer_16_4_0_0_default(
std_geometry,
plt.DistributionMap(plt.finestLevel()),
plt.boxArray(plt.finestLevel()),
)
pc.restart(plt_file_name, "immbdy_markers")

particles = list()
for pti in pc.iterator(pc, level=plt.finestLevel()):
aos = pti.aos()
for p in aos.to_numpy(copy=True):
particles.append(Particle(x=p[0], y=p[1], z=p[2], ib_id=p[-1], idx=p[-2]))

return particles


particles = load_data(plt_file_name)
for p in particles:
print(p)
print(p.x)
Loading