|
2 | 2 | #define PHARE_PARTICLES_DATA_SPLIT_HPP
|
3 | 3 |
|
4 | 4 |
|
| 5 | +#include "core/def.hpp" |
| 6 | +#include "phare_core.hpp" |
5 | 7 | #include "core/def/phare_mpi.hpp"
|
| 8 | +#include "core/utilities/constants.hpp" |
6 | 9 |
|
7 |
| -#include "core/def.hpp" |
8 |
| -#include "amr/data/particles/particles_data.hpp" |
9 |
| -#include "amr/resources_manager/amr_utils.hpp" |
10 | 10 | #include "split.hpp"
|
11 |
| -#include "core/utilities/constants.hpp" |
12 |
| -#include "phare_core.hpp" |
13 | 11 | #include "amr/amr_constants.hpp"
|
| 12 | +#include "amr/utilities/box/amr_box.hpp" |
| 13 | +#include "amr/resources_manager/amr_utils.hpp" |
| 14 | +#include "amr/data/particles/particles_data.hpp" |
14 | 15 |
|
15 | 16 | #include <SAMRAI/geom/CartesianPatchGeometry.h>
|
16 | 17 | #include <SAMRAI/hier/Box.h>
|
17 | 18 | #include <SAMRAI/hier/RefineOperator.h>
|
18 | 19 | #include <SAMRAI/pdat/CellOverlap.h>
|
19 | 20 |
|
20 |
| -#include <functional> |
21 | 21 |
|
22 | 22 |
|
23 | 23 | namespace PHARE
|
@@ -53,6 +53,12 @@ namespace amr
|
53 | 53 | template<typename ParticleArray, ParticlesDataSplitType splitType, typename Splitter>
|
54 | 54 | class ParticlesRefineOperator : public SAMRAI::hier::RefineOperator
|
55 | 55 | {
|
| 56 | + using Particle_t = typename ParticleArray::value_type; |
| 57 | + static constexpr bool putParticlesInCoarseBoundary |
| 58 | + = splitType == ParticlesDataSplitType::coarseBoundary |
| 59 | + || splitType == ParticlesDataSplitType::coarseBoundaryOld |
| 60 | + || splitType == ParticlesDataSplitType::coarseBoundaryNew; |
| 61 | + |
56 | 62 | public:
|
57 | 63 | static constexpr auto dim = Splitter::dimension;
|
58 | 64 | static constexpr auto interpOrder = Splitter::interp_order;
|
@@ -99,7 +105,7 @@ namespace amr
|
99 | 105 | = std::dynamic_pointer_cast<ParticlesData<ParticleArray>>(
|
100 | 106 | source.getPatchData(sourceComponent));
|
101 | 107 |
|
102 |
| - // Finnaly we need the cartesion geometry of both patch. |
| 108 | + // Finaly we need the cartesion geometry of both patch. |
103 | 109 | auto patchGeomDestination
|
104 | 110 | = std::dynamic_pointer_cast<SAMRAI::geom::CartesianPatchGeometry>(
|
105 | 111 | destination.getPatchGeometry());
|
@@ -133,9 +139,14 @@ namespace amr
|
133 | 139 | }
|
134 | 140 | }
|
135 | 141 |
|
| 142 | + static void _reserve(ParticleArray& particles, std::size_t const& size) |
| 143 | + { |
| 144 | + if constexpr (!putParticlesInCoarseBoundary) |
| 145 | + particles.reserve(size); |
| 146 | + } |
136 | 147 |
|
137 | 148 | /** @brief given two ParticlesData (destination and source),
|
138 |
| - * an overlap , a ratio and the geometry of both patches, perform the |
| 149 | + * an overlap, a ratio and the geometry of both patches, perform the |
139 | 150 | * splitting of coarse particles onto the destination patch
|
140 | 151 | */
|
141 | 152 | void refine_(ParticlesData<ParticleArray>& destParticlesData,
|
@@ -166,43 +177,43 @@ namespace amr
|
166 | 177 | // same for destinationGhostBox and destinationDomainBox the later will allow to get an
|
167 | 178 | // index relative to the interior
|
168 | 179 |
|
| 180 | + std::array const particlesArrays{&srcInteriorParticles, &srcGhostParticles}; |
| 181 | + |
| 182 | + { |
| 183 | + std::size_t incoming_estimate = 0; |
| 184 | + for (auto const& destinationBox : destBoxes) |
| 185 | + for (auto const& sourceParticlesArray : particlesArrays) |
| 186 | + incoming_estimate += sourceParticlesArray->nbr_particles_in( |
| 187 | + phare_box_from<dim>(destinationBox)); |
| 188 | + _reserve(destDomainParticles, (incoming_estimate * nbRefinedPart)); |
| 189 | + } |
| 190 | + |
169 | 191 | Splitter split;
|
170 | 192 |
|
171 | 193 | // The PatchLevelFillPattern had compute boxes that correspond to the expected filling.
|
172 | 194 | // In case of a coarseBoundary it will most likely give multiple boxes
|
173 | 195 | // in case of interior, this will be just one box usually
|
174 | 196 | for (auto const& destinationBox : destBoxes)
|
175 | 197 | {
|
176 |
| - std::array particlesArrays{&srcInteriorParticles, &srcGhostParticles}; |
177 |
| - auto splitBox = getSplitBox(destinationBox); |
| 198 | + auto const splitBox = getSplitBox(destinationBox); |
178 | 199 |
|
179 |
| - auto isInDest = [&destinationBox](auto const& particle) // |
| 200 | + auto const isInDest = [&destinationBox](auto const& particle) // |
180 | 201 | { return isInBox(destinationBox, particle); };
|
181 | 202 |
|
182 |
| - |
183 | 203 | for (auto const& sourceParticlesArray : particlesArrays)
|
184 | 204 | {
|
185 | 205 | for (auto const& particle : *sourceParticlesArray)
|
186 | 206 | {
|
187 |
| - std::array<typename ParticleArray::value_type, nbRefinedPart> |
188 |
| - refinedParticles; |
189 |
| - auto particleRefinedPos = toFineGrid<interpOrder>(particle); |
| 207 | + auto const particleRefinedPos = toFineGrid<interpOrder>(particle); |
190 | 208 |
|
191 | 209 | if (isInBox(splitBox, particleRefinedPos))
|
192 | 210 | {
|
| 211 | + std::array<Particle_t, nbRefinedPart> refinedParticles; |
193 | 212 | split(particleRefinedPos, refinedParticles);
|
194 | 213 |
|
195 |
| - |
196 | 214 | // we need to know in which of interior or levelGhostParticlesXXXX
|
197 | 215 | // arrays we must put particles
|
198 | 216 |
|
199 |
| - bool constexpr putParticlesInCoarseBoundary |
200 |
| - = splitType == ParticlesDataSplitType::coarseBoundary |
201 |
| - || splitType == ParticlesDataSplitType::coarseBoundaryOld |
202 |
| - || splitType == ParticlesDataSplitType::coarseBoundaryNew; |
203 |
| - |
204 |
| - |
205 |
| - |
206 | 217 | if constexpr (putParticlesInCoarseBoundary)
|
207 | 218 | {
|
208 | 219 | if constexpr (splitType == ParticlesDataSplitType::coarseBoundary)
|
@@ -243,9 +254,9 @@ namespace amr
|
243 | 254 | std::back_inserter(destDomainParticles), isInDest);
|
244 | 255 | }
|
245 | 256 | } // end is candidate for split
|
246 |
| - } // end loop on particles |
247 |
| - } // end loop on source particle arrays |
248 |
| - } // loop on destination box |
| 257 | + } // end loop on particles |
| 258 | + } // end loop on source particle arrays |
| 259 | + } // loop on destination box |
249 | 260 | }
|
250 | 261 |
|
251 | 262 |
|
|
0 commit comments