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,32 @@ 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 const & nparts, std::size_t narrays)
166
+ {
167
+ if (narrays < sizes.capacity ())
168
+ narrays += narrays * .01 ;
169
+ return std::forward_as_tuple (particles (nparts), sizes (narrays), maps (narrays));
170
+ }
171
+
172
+ ParticleVec_t particles;
173
+ SizeVec_t sizes;
174
+ CellMapVec_t maps;
175
+ };
176
+
177
+ // extend lifespan
178
+ SaveState domainState, patchGhostState;
171
179
172
180
}; // end solverPPC
173
181
@@ -214,19 +222,42 @@ void SolverPPC<HybridModel, AMR_Types>::fillMessengerInfo(
214
222
215
223
216
224
template <typename HybridModel, typename AMR_Types>
217
- void SolverPPC<HybridModel, AMR_Types>::saveState_(level_t & level, ModelViews_t& views)
225
+ void SolverPPC<HybridModel, AMR_Types>::saveState_(level_t const & level, ModelViews_t const & views)
218
226
{
219
227
PHARE_LOG_SCOPE (1 , " SolverPPC::saveState_" );
220
228
229
+ std::size_t arrays = 0 , dcount = 0 , pcount = 0 ;
221
230
for (auto & state : views)
222
- {
223
- std::stringstream ss;
224
- ss << state.patch ->getGlobalId ();
225
231
for (auto & pop : state.ions )
226
232
{
227
- std::string const key = ss.str () + " _" + pop.name ();
228
- add_to (tmpDomain, key, pop.domainParticles ());
229
- add_to (patchGhost, key, pop.patchGhostParticles ());
233
+ ++arrays;
234
+ dcount += pop.domainParticles ().capacity ();
235
+ pcount += pop.patchGhostParticles ().capacity ();
236
+ }
237
+
238
+ auto [dParts, dSizes, dMaps] = domainState (dcount, arrays);
239
+ auto [pParts, pSizes, pMaps] = patchGhostState (pcount, arrays);
240
+
241
+ std::size_t arr_idx = 0 , doff = 0 , poff = 0 ;
242
+ for (auto const & state : views)
243
+ {
244
+ for (auto const & pop : state.ions )
245
+ {
246
+ auto & dInParts = pop.domainParticles ();
247
+ auto & pInParts = pop.patchGhostParticles ();
248
+
249
+ dMaps[arr_idx] = dInParts.map ();
250
+ pMaps[arr_idx] = pInParts.map ();
251
+
252
+ dSizes[arr_idx] = dInParts.size ();
253
+ pSizes[arr_idx] = pInParts.size ();
254
+
255
+ std::copy (dInParts.data (), dInParts.data () + dSizes[arr_idx], dParts.data () + doff);
256
+ std::copy (pInParts.data (), pInParts.data () + pSizes[arr_idx], pParts.data () + poff);
257
+
258
+ doff += dSizes[arr_idx];
259
+ poff += pSizes[arr_idx];
260
+ ++arr_idx;
230
261
}
231
262
}
232
263
}
@@ -236,15 +267,22 @@ void SolverPPC<HybridModel, AMR_Types>::restoreState_(level_t& level, ModelViews
236
267
{
237
268
PHARE_LOG_SCOPE (1 , " SolverPPC::restoreState_" );
238
269
270
+ auto const [dInParts, dSizes, dMaps] = domainState ();
271
+ auto const [pInParts, pSizes, pMaps] = patchGhostState ();
272
+
273
+ std::size_t arr_idx = 0 , doff = 0 , poff = 0 ;
239
274
for (auto & state : views)
240
275
{
241
- std::stringstream ss;
242
- ss << state.patch ->getGlobalId ();
243
-
244
276
for (auto & pop : state.ions )
245
277
{
246
- pop.domainParticles () = std::move (tmpDomain.at (ss.str () + " _" + pop.name ()));
247
- pop.patchGhostParticles () = std::move (patchGhost.at (ss.str () + " _" + pop.name ()));
278
+ pop.domainParticles ().replace_from (dInParts.data () + doff, dSizes[arr_idx],
279
+ dMaps[arr_idx]);
280
+ pop.patchGhostParticles ().replace_from (pInParts.data () + poff, pSizes[arr_idx],
281
+ pMaps[arr_idx]);
282
+
283
+ doff += dSizes[arr_idx];
284
+ poff += pSizes[arr_idx];
285
+ ++arr_idx;
248
286
}
249
287
}
250
288
}
0 commit comments