diff --git a/src/Particle/ParticleContainer.H b/src/Particle/ParticleContainer.H index ef103d3e..bf952190 100644 --- a/src/Particle/ParticleContainer.H +++ b/src/Particle/ParticleContainer.H @@ -224,6 +224,15 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr) "add a new runtime component with type Int" ) + .def_property_readonly("real_soa_names", + &ParticleContainerType::GetRealSoANames, + "Get the names for the Real SoA components" + ) + .def_property_readonly("int_soa_names", + &ParticleContainerType::GetIntSoANames, + "Get the names for the int SoA components" + ) + .def_property_readonly("finest_level", &ParticleContainerBase::finestLevel) // ParticleContainer ( const ParticleContainer &) = delete; diff --git a/src/Particle/StructOfArrays.H b/src/Particle/StructOfArrays.H index e21d67cf..791c5e67 100644 --- a/src/Particle/StructOfArrays.H +++ b/src/Particle/StructOfArrays.H @@ -10,6 +10,7 @@ #include #include +#include #include @@ -56,6 +57,32 @@ void make_StructOfArrays(py::module &m, std::string allocstr) py::arg("index"), "Get access to a particle Real component Array (compile-time and runtime component)") + // names + .def_property_readonly("real_names", + [](SOAType & self) { + try { + return self.GetRealNames(); + } + catch (...) + { + return std::vector{}; + } + }, + "Names for the Real SoA components" + ) + .def_property_readonly("int_names", + [](SOAType & self) { + try { + return self.GetIntNames(); + } + catch (...) + { + return std::vector{}; + } + }, + "Names for the int SoA components" + ) + .def("__len__", &SOAType::size, "Get the number of particles") .def_property_readonly("size", &SOAType::size, diff --git a/src/amrex/extensions/ParticleComponentNames.py b/src/amrex/extensions/ParticleComponentNames.py deleted file mode 100644 index 6922cdce..00000000 --- a/src/amrex/extensions/ParticleComponentNames.py +++ /dev/null @@ -1,7 +0,0 @@ -""" -This file is part of pyAMReX - -Copyright 2024 AMReX community -Authors: Axel Huebl -License: BSD-3-Clause-LBNL -""" diff --git a/src/amrex/extensions/StructOfArrays.py b/src/amrex/extensions/StructOfArrays.py index c23a5716..4d613f64 100644 --- a/src/amrex/extensions/StructOfArrays.py +++ b/src/amrex/extensions/StructOfArrays.py @@ -9,71 +9,6 @@ from collections import namedtuple -def soa_real_comps(self, num_comps, spacedim=3, rotate=True): - """ - Name the ParticleReal components in SoA. - - Parameters - ---------- - self : SoA Type - maybe unused, depending on implementation - num_comps : int - number of components to generate names for. - spacedim : int - AMReX dimensionality - rotate : bool = True - start with "x", "y", "z", "a", "b", ... - - Returns - ------- - A list of length num_comps with values - rotate=True (for pure SoA layout): - - 3D: "x", "y", "z", "a", "b", ... "w", "r0", "r1", ... - - 2D: "x", "y", "a", "b", ... "w", "r0", "r1", ... - - 1D: "x", "a", "b", ... "w", "r0", "r1", ... - rotate=False (for legacy layout): - - 1D-3D: "a", "b", ... "w", "r0", "r1", ... - """ - import string - - # x, y, z, a, b, ... - comp_names = list(string.ascii_lowercase) - if rotate: - # rotate x, y, z to be beginning (positions) - comp_names = comp_names[-3:] + comp_names[:-3] - else: - # cut off x, y, z to avoid confusion - comp_names = comp_names[:-3] - - num_named = len(comp_names) - if num_comps < num_named: - comp_names = list(comp_names)[0:num_comps] - elif num_comps > num_named: - comp_names.extend(["r" + str(i) for i in range(num_comps - num_named)]) - - return comp_names - - -def soa_int_comps(self, num_comps): - """ - Name the int components in SoA. - - Parameters - ---------- - self : SoA Type - maybe unused, depending on implementation - num_comps : int - number of components to generate names for. - - Returns - ------- - A list of length num_comps with values "i1", "i2", "i3", ... - """ - comp_names = ["i" + str(i) for i in range(num_comps)] - - return comp_names - - def soa_to_numpy(self, copy=False): """ Provide NumPy views into a StructOfArrays. @@ -226,10 +161,6 @@ def register_SoA_extension(amr): and member.__module__ == amr.__name__ and member.__name__.startswith("StructOfArrays_"), ): - # name providers - SoA_type.soa_real_comps = soa_real_comps - SoA_type.soa_int_comps = soa_int_comps - # converters SoA_type.to_numpy = soa_to_numpy SoA_type.to_cupy = soa_to_cupy