|
9 | 9 | from collections import namedtuple |
10 | 10 |
|
11 | 11 |
|
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 | | - |
77 | 12 | def soa_to_numpy(self, copy=False): |
78 | 13 | """ |
79 | 14 | Provide NumPy views into a StructOfArrays. |
@@ -107,18 +42,17 @@ def soa_to_numpy(self, copy=False): |
107 | 42 | else: |
108 | 43 | soa_view = SoA_np({}, {}, None) |
109 | 44 |
|
110 | | - # for the legacy data layout, do not start with x, y, z but with a, b, c, ... |
111 | | - if self.has_idcpu: |
112 | | - real_comp_names = self.soa_real_comps(self.num_real_comps) |
113 | | - else: |
114 | | - real_comp_names = self.soa_real_comps(self.num_real_comps, rotate=False) |
115 | | - |
| 45 | + real_comp_names = self.real_names |
| 46 | + if len(real_comp_names) != self.num_real_comps: |
| 47 | + raise ValueError("Missing names for SoA Real components.") |
116 | 48 | for idx_real in range(self.num_real_comps): |
117 | 49 | soa_view.real[real_comp_names[idx_real]] = self.get_real_data( |
118 | 50 | idx_real |
119 | 51 | ).to_numpy(copy=copy) |
120 | 52 |
|
121 | | - int_comp_names = self.soa_int_comps(self.num_int_comps) |
| 53 | + int_comp_names = self.int_names |
| 54 | + if len(int_comp_names) != self.num_int_comps: |
| 55 | + raise ValueError("Missing names for SoA int components.") |
122 | 56 | for idx_int in range(self.num_int_comps): |
123 | 57 | soa_view.int[int_comp_names[idx_int]] = self.get_int_data(idx_int).to_numpy( |
124 | 58 | copy=copy |
@@ -165,18 +99,17 @@ def soa_to_cupy(self, copy=False): |
165 | 99 | else: |
166 | 100 | soa_view = SoA_cp({}, {}, None) |
167 | 101 |
|
168 | | - # for the legacy data layout, do not start with x, y, z but with a, b, c, ... |
169 | | - if self.has_idcpu: |
170 | | - real_comp_names = self.soa_real_comps(self.num_real_comps) |
171 | | - else: |
172 | | - real_comp_names = self.soa_real_comps(self.num_real_comps, rotate=False) |
173 | | - |
| 102 | + real_comp_names = self.real_names |
| 103 | + if len(real_comp_names) != self.num_real_comps: |
| 104 | + raise ValueError("Missing names for SoA Real components.") |
174 | 105 | for idx_real in range(self.num_real_comps): |
175 | 106 | soa_view.real[real_comp_names[idx_real]] = self.get_real_data(idx_real).to_cupy( |
176 | 107 | copy=copy |
177 | 108 | ) |
178 | 109 |
|
179 | | - int_comp_names = self.soa_int_comps(self.num_int_comps) |
| 110 | + int_comp_names = self.int_names |
| 111 | + if len(int_comp_names) != self.num_int_comps: |
| 112 | + raise ValueError("Missing names for SoA int components.") |
180 | 113 | for idx_int in range(self.num_int_comps): |
181 | 114 | soa_view.int[int_comp_names[idx_int]] = self.get_int_data(idx_int).to_cupy( |
182 | 115 | copy=copy |
@@ -226,10 +159,6 @@ def register_SoA_extension(amr): |
226 | 159 | and member.__module__ == amr.__name__ |
227 | 160 | and member.__name__.startswith("StructOfArrays_"), |
228 | 161 | ): |
229 | | - # name providers |
230 | | - SoA_type.soa_real_comps = soa_real_comps |
231 | | - SoA_type.soa_int_comps = soa_int_comps |
232 | | - |
233 | 162 | # converters |
234 | 163 | SoA_type.to_numpy = soa_to_numpy |
235 | 164 | SoA_type.to_cupy = soa_to_cupy |
|
0 commit comments