Skip to content

Commit a3b79d3

Browse files
committed
[Draft] AMReX SoA Named Components
Replace our own named SoA particle components implementation with the now upstream support in AMReX.
1 parent f3a7b11 commit a3b79d3

File tree

4 files changed

+36
-76
lines changed

4 files changed

+36
-76
lines changed

src/Particle/ParticleContainer.H

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ void make_ParticleContainer_and_Iterators (py::module &m, std::string allocstr)
224224
"add a new runtime component with type Int"
225225
)
226226

227+
.def_property_readonly("real_soa_names",
228+
&ParticleContainerType::GetRealSoANames,
229+
"Get the names for the Real SoA components"
230+
)
231+
.def_property_readonly("int_soa_names",
232+
&ParticleContainerType::GetIntSoANames,
233+
"Get the names for the int SoA components"
234+
)
235+
227236
.def_property_readonly("finest_level", &ParticleContainerBase::finestLevel)
228237

229238
// ParticleContainer ( const ParticleContainer &) = delete;

src/Particle/StructOfArrays.H

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <AMReX_GpuAllocators.H>
1111
#include <AMReX_StructOfArrays.H>
1212

13+
#include <stdexcept>
1314
#include <sstream>
1415

1516

@@ -56,6 +57,32 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
5657
py::arg("index"),
5758
"Get access to a particle Real component Array (compile-time and runtime component)")
5859

60+
// names
61+
.def_property_readonly("real_names",
62+
[](SOAType & self) {
63+
try {
64+
return self.GetRealNames();
65+
}
66+
catch (...)
67+
{
68+
return std::vector<std::string>{};
69+
}
70+
},
71+
"Names for the Real SoA components"
72+
)
73+
.def_property_readonly("int_names",
74+
[](SOAType & self) {
75+
try {
76+
return self.GetIntNames();
77+
}
78+
catch (...)
79+
{
80+
return std::vector<std::string>{};
81+
}
82+
},
83+
"Names for the int SoA components"
84+
)
85+
5986
.def("__len__", &SOAType::size,
6087
"Get the number of particles")
6188
.def_property_readonly("size", &SOAType::size,

src/amrex/extensions/ParticleComponentNames.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/amrex/extensions/StructOfArrays.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,6 @@
99
from collections import namedtuple
1010

1111

12-
def soa_real_comps(self, num_comps, spacedim=3, rotate=True):
13-
"""
14-
Name the ParticleReal components in SoA.
15-
16-
Parameters
17-
----------
18-
self : SoA Type
19-
maybe unused, depending on implementation
20-
num_comps : int
21-
number of components to generate names for.
22-
spacedim : int
23-
AMReX dimensionality
24-
rotate : bool = True
25-
start with "x", "y", "z", "a", "b", ...
26-
27-
Returns
28-
-------
29-
A list of length num_comps with values
30-
rotate=True (for pure SoA layout):
31-
- 3D: "x", "y", "z", "a", "b", ... "w", "r0", "r1", ...
32-
- 2D: "x", "y", "a", "b", ... "w", "r0", "r1", ...
33-
- 1D: "x", "a", "b", ... "w", "r0", "r1", ...
34-
rotate=False (for legacy layout):
35-
- 1D-3D: "a", "b", ... "w", "r0", "r1", ...
36-
"""
37-
import string
38-
39-
# x, y, z, a, b, ...
40-
comp_names = list(string.ascii_lowercase)
41-
if rotate:
42-
# rotate x, y, z to be beginning (positions)
43-
comp_names = comp_names[-3:] + comp_names[:-3]
44-
else:
45-
# cut off x, y, z to avoid confusion
46-
comp_names = comp_names[:-3]
47-
48-
num_named = len(comp_names)
49-
if num_comps < num_named:
50-
comp_names = list(comp_names)[0:num_comps]
51-
elif num_comps > num_named:
52-
comp_names.extend(["r" + str(i) for i in range(num_comps - num_named)])
53-
54-
return comp_names
55-
56-
57-
def soa_int_comps(self, num_comps):
58-
"""
59-
Name the int components in SoA.
60-
61-
Parameters
62-
----------
63-
self : SoA Type
64-
maybe unused, depending on implementation
65-
num_comps : int
66-
number of components to generate names for.
67-
68-
Returns
69-
-------
70-
A list of length num_comps with values "i1", "i2", "i3", ...
71-
"""
72-
comp_names = ["i" + str(i) for i in range(num_comps)]
73-
74-
return comp_names
75-
76-
7712
def soa_to_numpy(self, copy=False):
7813
"""
7914
Provide NumPy views into a StructOfArrays.
@@ -226,10 +161,6 @@ def register_SoA_extension(amr):
226161
and member.__module__ == amr.__name__
227162
and member.__name__.startswith("StructOfArrays_"),
228163
):
229-
# name providers
230-
SoA_type.soa_real_comps = soa_real_comps
231-
SoA_type.soa_int_comps = soa_int_comps
232-
233164
# converters
234165
SoA_type.to_numpy = soa_to_numpy
235166
SoA_type.to_cupy = soa_to_cupy

0 commit comments

Comments
 (0)