5
5
6
6
#include < SAMRAI/hier/Patch.h>
7
7
8
+ #include " core/vector.hpp"
8
9
9
10
#include " amr/messengers/hybrid_messenger.hpp"
10
11
#include " amr/messengers/hybrid_messenger_info.hpp"
18
19
#include " core/numerics/faraday/faraday.hpp"
19
20
#include " core/numerics/ohm/ohm.hpp"
20
21
22
+ #include " core/utilities/cellmap.hpp"
21
23
#include " core/data/vecfield/vecfield.hpp"
22
24
#include " core/data/grid/gridlayout_utils.hpp"
23
25
24
-
25
26
#include < iomanip>
26
27
#include < sstream>
28
+ #include < tuple>
27
29
28
30
namespace PHARE ::solver
29
31
{
@@ -130,7 +132,7 @@ class SolverPPC : public ISolver<AMR_Types>
130
132
double const currentTime, double const newTime, core::UpdaterMode mode);
131
133
132
134
133
- void saveState_ (level_t & level, ModelViews_t& views);
135
+ void saveState_ (level_t const & level, ModelViews_t const & views);
134
136
void restoreState_ (level_t & level, ModelViews_t& views);
135
137
136
138
@@ -148,26 +150,34 @@ class SolverPPC : public ISolver<AMR_Types>
148
150
};
149
151
150
152
151
- // extend lifespan
152
- std::unordered_map<std::string, ParticleArray> tmpDomain;
153
- std::unordered_map<std::string, ParticleArray> patchGhost;
154
-
155
- template <typename Map>
156
- static void add_to (Map& map, std::string const & key, ParticleArray const & ps)
153
+ struct SaveState
157
154
{
158
- // vector copy drops the capacity (over allocation of the source)
159
- // we want to keep the overallocation somewhat - how much to be assessed
160
- ParticleArray empty{ps.box ()};
161
-
162
- if (!map.count (key))
163
- map.emplace (key, empty);
164
- else
165
- map.at (key) = empty;
166
-
167
- auto & v = map.at (key);
168
- v.reserve (ps.capacity ());
169
- v.replace_from (ps);
170
- }
155
+ bool constexpr static copy_old = false ;
156
+ using box_t = core::Box<int , dimension>;
157
+ using CellMap_t = core::CellMap<dimension, int >;
158
+ using Particle_t = typename ParticleArray::value_type;
159
+ using ParticleVec_t = core::MinimizingVector<Particle_t, copy_old>;
160
+
161
+ using SizeVec_t = core::MinimizingVector<std::size_t , copy_old>;
162
+ using CellMapVec_t = core::MinimizingVector<CellMap_t, copy_old>;
163
+
164
+ auto operator ()() { return std::forward_as_tuple (particles (), sizes (), maps ()); }
165
+ auto operator ()(std::size_t nparts, std::size_t narrays)
166
+ {
167
+ if (nparts < particles.capacity ())
168
+ return std::forward_as_tuple (particles (nparts), sizes (narrays), maps (narrays));
169
+ narrays += narrays * .01 ;
170
+ nparts += nparts * .001 ;
171
+ return std::forward_as_tuple (particles (nparts), sizes (narrays), maps (narrays));
172
+ }
173
+
174
+ ParticleVec_t particles;
175
+ SizeVec_t sizes;
176
+ CellMapVec_t maps;
177
+ };
178
+
179
+ // extend lifespan
180
+ SaveState domainState, patchGhostState;
171
181
172
182
}; // end solverPPC
173
183
@@ -214,19 +224,45 @@ void SolverPPC<HybridModel, AMR_Types>::fillMessengerInfo(
214
224
215
225
216
226
template <typename HybridModel, typename AMR_Types>
217
- void SolverPPC<HybridModel, AMR_Types>::saveState_(level_t & level, ModelViews_t& views)
227
+ void SolverPPC<HybridModel, AMR_Types>::saveState_(level_t const & level, ModelViews_t const & views)
218
228
{
219
229
PHARE_LOG_SCOPE (1 , " SolverPPC::saveState_" );
220
230
231
+ std::size_t arrays = 0 , dcount = 0 , pcount = 0 ;
221
232
for (auto & state : views)
222
- {
223
- std::stringstream ss;
224
- ss << state.patch ->getGlobalId ();
225
233
for (auto & pop : state.ions )
226
234
{
227
- std::string const key = ss.str () + " _" + pop.name ();
228
- add_to (tmpDomain, key, pop.domainParticles ());
229
- add_to (patchGhost, key, pop.patchGhostParticles ());
235
+ ++arrays;
236
+ dcount += pop.domainParticles ().size ();
237
+ pcount += pop.patchGhostParticles ().size ();
238
+ }
239
+
240
+ auto [dParts, dSizes, dMaps] = domainState (dcount, arrays);
241
+ auto [pParts, pSizes, pMaps] = patchGhostState (pcount, arrays);
242
+
243
+ PHARE_LOG_LINE_SS (dSizes.size ());
244
+ PHARE_LOG_LINE_SS (pSizes.size ());
245
+
246
+ std::size_t arr_idx = 0 , doff = 0 , poff = 0 ;
247
+ for (auto const & state : views)
248
+ {
249
+ for (auto const & pop : state.ions )
250
+ {
251
+ auto & dInParts = pop.domainParticles ();
252
+ auto & pInParts = pop.patchGhostParticles ();
253
+
254
+ dMaps[arr_idx] = dInParts.map ();
255
+ pMaps[arr_idx] = pInParts.map ();
256
+
257
+ dSizes[arr_idx] = dInParts.size ();
258
+ pSizes[arr_idx] = pInParts.size ();
259
+
260
+ std::copy (dInParts.data (), dInParts.data () + dSizes[arr_idx], dParts.data () + doff);
261
+ std::copy (pInParts.data (), pInParts.data () + pSizes[arr_idx], pParts.data () + poff);
262
+
263
+ doff += dSizes[arr_idx];
264
+ poff += pSizes[arr_idx];
265
+ ++arr_idx;
230
266
}
231
267
}
232
268
}
@@ -236,15 +272,22 @@ void SolverPPC<HybridModel, AMR_Types>::restoreState_(level_t& level, ModelViews
236
272
{
237
273
PHARE_LOG_SCOPE (1 , " SolverPPC::restoreState_" );
238
274
275
+ auto const [dInParts, dSizes, dMaps] = domainState ();
276
+ auto const [pInParts, pSizes, pMaps] = patchGhostState ();
277
+
278
+ std::size_t arr_idx = 0 , doff = 0 , poff = 0 ;
239
279
for (auto & state : views)
240
280
{
241
- std::stringstream ss;
242
- ss << state.patch ->getGlobalId ();
243
-
244
281
for (auto & pop : state.ions )
245
282
{
246
- pop.domainParticles () = std::move (tmpDomain.at (ss.str () + " _" + pop.name ()));
247
- pop.patchGhostParticles () = std::move (patchGhost.at (ss.str () + " _" + pop.name ()));
283
+ pop.domainParticles ().replace_from (dInParts.data () + doff, dSizes[arr_idx],
284
+ dMaps[arr_idx]);
285
+ pop.patchGhostParticles ().replace_from (pInParts.data () + poff, pSizes[arr_idx],
286
+ pMaps[arr_idx]);
287
+
288
+ doff += dSizes[arr_idx];
289
+ poff += pSizes[arr_idx];
290
+ ++arr_idx;
248
291
}
249
292
}
250
293
}
0 commit comments