Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_ParticleInit.H
Go to the documentation of this file.
1#ifndef AMREX_PARTICLEINIT_H
2#define AMREX_PARTICLEINIT_H
3#include <AMReX_Config.H>
4
5#include <iterator>
6#include <utility>
7
8namespace amrex {
9
10/*
11 \brief Initialize particles from an Ascii file in the following format:
12
13 8
14 0.1 0.1 16.2 1000.0 4.0 1.0 6.0
15 8.1 0.1 16.2 1000.0 -5 0.0 -7.0
16 16.1 0.1 16.2 1000.0 6.0 -8.0 2.0
17 24.1 0.1 16.2 1000.0 9.0 4.0 8.0
18 0.1 8.1 16.2 1000.0 -8.0 -3.0 -10.0
19 8.1 8.1 16.2 1000.0 2.0 1.0 0.0
20 16.1 8.1 16.2 1000.0 0.0 2.0 3.0
21 24.1 8.1 16.2 1000.0 -9.0 7.0 5.0
22
23 The first line is the number of particles. The remaining lines give the particle
24 data to read, one particle on each line. The first AMREX_SPACEDIM components are
25 positions. The next extradata components are the additional real data to read in.
26
27 Integer data is not currently supported by this function.
28
29 Parameters:
30
31 file: the name of the Ascii file with the particles
32 extradata: the number of real components to read in, beyond the AMREX_SPACEDIM
33 positions
34 Nrep: pointer to IntVect that lets you replicate the incoming particles
35 across the domain so that you only need to specify a sub-volume of
36 them. By default particles are not replicated.
37 */
38template <typename ParticleType, int NArrayReal, int NArrayInt,
39 template<class> class Allocator, class CellAssignor>
40void
42::InitFromAsciiFile (const std::string& file, int extradata, const IntVect* Nrep)
43{
44 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitFromAsciiFile()");
45 AMREX_ASSERT(!file.empty());
46 AMREX_ASSERT(extradata <= NStructReal + NumRealComps());
47
48 const int MyProc = ParallelDescriptor::MyProc();
49 const int NProcs = ParallelDescriptor::NProcs();
50 const auto strttime = amrex::second();
51
52 int NReaders = MaxReaders(); // num ranks to read with
53 int NRedist = 1; // number of times to redistribute while reading
54
55 // try to use some sensible heuristics
56 if (NProcs <= 1024)
57 {
58 if (NReaders > 1)
59 {
60 NRedist = 2;
61 }
62 }
63 else if (NProcs <= 4096)
64 {
65 NReaders = std::max(NReaders,128);
66 NRedist = 4;
67 }
68 else if (NProcs <= 8192)
69 {
70 NReaders = std::max(NReaders,384);
71 NRedist = 32;
72 }
73 else if (NProcs <= 16384)
74 {
75 NReaders = std::max(NReaders,512);
76 NRedist = 48;
77 }
78
79 resizeData();
80
81 IntVect lNrep(AMREX_D_DECL(1,1,1));
82
83 if (Nrep != nullptr) {
84 lNrep = *Nrep;
85 }
86
87 Long how_many = 0;
88 Long how_many_read = 0;
89
91 // the extra values beyond the first NStructReal go to the SoA real components,
92 // starting with component 0
93 const int nsoa = std::max(extradata - NStructReal, 0);
94 Vector<Gpu::HostVector<Real> > nreals(nsoa);
95
96 if (MyProc < NReaders)
97 {
99
100 std::ifstream ifs;
101
102 ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
103
104 ifs.open(file.c_str(), std::ios::in);
105
106 if (!ifs.good())
107 {
109 }
110
111 int cnt = 0;
112
113 ifs >> cnt >> std::ws;
114
115 ParticleLocData pld;
116 ParticleType p, p_rep;
117 Vector<Real> r;
118
119 r.resize(nsoa);
120
121 const int Chunk = cnt / NReaders;
122
123 for (int i = 0; i < MyProc*Chunk; i++)
124 {
125 ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
126 ifs >> std::ws; // Eat newline.
127 }
128
129 if (!ifs.good())
130 {
131 std::string msg("ParticleContainer::InitFromAsciiFile(");
132 msg += file;
133 msg += ") failed @ 1";
134 amrex::Error(msg.c_str());
135 }
136
137 int MyCnt = Chunk;
138
139 if (MyProc == (NReaders - 1))
140 {
141 MyCnt += cnt % NReaders;
142 }
143
144 const Geometry& geom = Geom(0);
145
146 for (int i = 0; i < MyCnt; i++)
147 {
148 AMREX_D_TERM(ifs >> p.pos(0);,
149 ifs >> p.pos(1);,
150 ifs >> p.pos(2););
151
152 for (int n = 0; n < extradata; n++)
153 {
154 if (n < NStructReal)
155 {
156 ifs >> p.rdata(n);
157 }
158 else
159 {
160 ifs >> r[n - NStructReal];
161 }
162 }
163
164 if (!ifs.good())
165 {
166 std::string msg("ParticleContainer::InitFromAsciiFile(");
167 msg += file; msg += ") failed @ 2";
168 amrex::Error(msg.c_str());
169 }
170
171 if (!Where(p, pld))
172 {
174
175 if (!Where(p, pld))
176 {
177 if (m_verbose) {
178 amrex::AllPrint() << "BAD PARTICLE ID WOULD BE " << ParticleType::NextID() << '\n'
179 << "BAD PARTICLE POS "
180 << AMREX_D_TERM( p.pos(0),
181 << p.pos(1),
182 << p.pos(2))
183 << "\n";
184 }
185 amrex::Abort("ParticleContainer::InitFromAsciiFile(): invalid particle");
186 }
187 }
188
189 // set these rather than reading them in
190 p.id() = ParticleType::NextID();
191 p.cpu() = MyProc;
192
193 nparticles.push_back(p);
194 if (nsoa > 0) {
195 for (int n = NStructReal; n < extradata; n++)
196 {
197 nreals[n-NStructReal].push_back(r[n-NStructReal]);
198 }
199 }
200
201 how_many++;
202 how_many_read++;
203
204 const Real DomSize[AMREX_SPACEDIM] =
205 { AMREX_D_DECL((geom.ProbHi(0)-geom.ProbLo(0))/lNrep[0],
206 (geom.ProbHi(1)-geom.ProbLo(1))/lNrep[1],
207 (geom.ProbHi(2)-geom.ProbLo(2))/lNrep[2]) };
208 int rep[AMREX_SPACEDIM];
209
210#if AMREX_SPACEDIM > 2
211 for (rep[2] = 1; rep[2] <= lNrep[2]; rep[2]++)
212 {
213#endif
214#if AMREX_SPACEDIM > 1
215 for (rep[1] = 1; rep[1] <= lNrep[1]; rep[1]++)
216 {
217#endif
218 for (rep[0] = 1; rep[0] <= lNrep[0]; rep[0]++)
219 {
220 if (!(AMREX_D_TERM( (rep[0] == 1), && (rep[1] == 1), && (rep[2] == 1) ) ) )
221 {
222 // Shift the position.
223 for (int d=0; d<AMREX_SPACEDIM; ++d)
224 {
225 p_rep.pos(d) = static_cast<ParticleReal>(p.pos(d) + Real(rep[d]-1)*DomSize[d]);
226 }
227
228 // Copy the extra data
229 for (int n = 0; n < extradata; n++)
230 {
231 if (n < NStructReal)
232 {
233 p_rep.rdata(n) = p.rdata(n);
234 }
235 }
236
237 if (!Where(p_rep, pld))
238 {
239 PeriodicShift(p_rep);
240 if (!Where(p_rep, pld))
241 {
242 if (m_verbose) {
243 amrex::AllPrint() << "BAD REPLICATED PARTICLE ID WOULD BE " << ParticleType::NextID() << "\n";
244 }
245 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromAsciiFile(): invalid replicated particle");
246 }
247 }
248
249 p_rep.id() = ParticleType::NextID();
250 p_rep.cpu() = MyProc;
251
252 nparticles.push_back(p_rep);
253
254 if (nsoa > 0) {
255 for (int n = NStructReal; n < extradata; n++)
256 {
257 nreals[n-NStructReal].push_back(r[n-NStructReal]);
258 }
259 }
260
261 how_many++;
262 }
263 }
264#if AMREX_SPACEDIM > 1
265 }
266#endif
267#if AMREX_SPACEDIM > 2
268 }
269#endif
270
271 }
272
273 }
274
275 // Now Redistribute() each chunk separately to minimize memory bloat.
276 int NRedist_chunk = NReaders / NRedist;
277
278 ParticleLocData pld;
279
280 for (int nr = 0; nr < NRedist; nr++)
281 {
283 host_particles.reserve(15);
284 host_particles.resize(finestLevel()+1);
285
287 host_real_attribs.reserve(15);
288 host_real_attribs.resize(finestLevel()+1);
289
290 if (m_verbose > 0) {
291 amrex::Print() << "Redistributing from processor "
292 << nr*NRedist_chunk << " to "
293 << (nr+1)*NRedist_chunk-1 << '\n';
294 }
295
296 for (int which = nr*NRedist_chunk; which < (nr+1)*NRedist_chunk; which++)
297 {
298 if (which == MyProc)
299 {
300 while (!nparticles.empty())
301 {
302 ParticleType& p = nparticles.back();
303 Where(p, pld);
304
305 host_particles[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)].push_back(p);
306
307 if (nsoa > 0)
308 {
309 auto& attribs = host_real_attribs[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)];
310 attribs.resize(nsoa);
311 for (int n = NStructReal; n < extradata; n++)
312 {
313 attribs[n-NStructReal].push_back(static_cast<ParticleReal>(nreals[n-NStructReal].back()));
314 }
315 }
316
317 nparticles.pop_back();
318
319 if (nsoa > 0)
320 {
321 for (int n = NStructReal; n < extradata; n++)
322 {
323 nreals[n-NStructReal].pop_back();
324 }
325 }
326 }
327 }
328 }
329
330 for (int lev = 0; lev < std::ssize(host_particles); ++lev)
331 {
332 for (auto& kv : host_particles[lev])
333 {
334
335 auto grid = kv.first.first;
336 auto tile = kv.first.second;
337 const auto& src_tile = kv.second;
338
339 auto& dst_tile = DefineAndReturnParticleTile(lev, grid, tile);
340 auto old_size = dst_tile.GetArrayOfStructs().size();
341 auto new_size = old_size + src_tile.size();
342 // the file may not give every SoA component: zero them all first
343 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size, true);
344
345 Gpu::copyAsync(Gpu::hostToDevice, src_tile.begin(), src_tile.end(),
346 dst_tile.GetArrayOfStructs().begin() + old_size);
347
348 auto const& attribs = host_real_attribs[lev][std::make_pair(grid, tile)];
349 for (int i = 0; i < std::ssize(attribs); ++i) {
350 Gpu::copyAsync(Gpu::hostToDevice, attribs[i].begin(), attribs[i].end(),
351 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
352 }
353 }
354 }
356
357 Redistribute();
358 }
359
360 if (m_verbose > 0)
361 {
362 if (NRedist*NRedist_chunk < NReaders) {
363 amrex::Print() << "Redistributing from processor "
364 << NRedist*NRedist_chunk << " to "
365 << NReaders << '\n';
366 }
367 }
368 for (int which = NRedist*NRedist_chunk; which < NReaders; which++)
369 {
371 host_particles.reserve(15);
372 host_particles.resize(finestLevel()+1);
373
375 host_real_attribs.reserve(15);
376 host_real_attribs.resize(finestLevel()+1);
377
378 if (which == MyProc)
379 {
380 while (!nparticles.empty())
381 {
382 ParticleType& p = nparticles.back();
383 Where(p, pld);
384
385 host_particles[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)].push_back(p);
386 if (nsoa > 0) {
387 auto& attribs = host_real_attribs[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)];
388 attribs.resize(nsoa);
389 for (int n = NStructReal; n < extradata; n++)
390 {
391 attribs[n-NStructReal].push_back(static_cast<ParticleReal>(nreals[n-NStructReal].back()));
392 }
393 }
394
395 nparticles.pop_back();
396
397 if (nsoa > 0) {
398 for (int n = NStructReal; n < extradata; n++)
399 {
400 nreals[n-NStructReal].pop_back();
401 }
402 }
404 }
406 for (int lev = 0; lev < std::ssize(host_particles); ++lev)
407 {
408 for (auto& kv : host_particles[lev])
409 {
410 auto grid = kv.first.first;
411 auto tile = kv.first.second;
412 const auto& src_tile = kv.second;
413
414 auto& dst_tile = DefineAndReturnParticleTile(lev, grid, tile);
415 auto old_size = dst_tile.GetArrayOfStructs().size();
416 auto new_size = old_size + src_tile.size();
417 // the file may not give every SoA component: zero them all first
418 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size, true);
419
420 Gpu::copyAsync(Gpu::hostToDevice, src_tile.begin(), src_tile.end(),
421 dst_tile.GetArrayOfStructs().begin() + old_size);
422
423 auto const& attribs = host_real_attribs[lev][std::make_pair(grid, tile)];
424 for (int i = 0; i < std::ssize(attribs); ++i) {
425 Gpu::copyAsync(Gpu::hostToDevice, attribs[i].begin(), attribs[i].end(),
426 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
427 }
428 }
429 }
431
432 Redistribute();
433
434 }
435
436 if (m_verbose > 0)
437 {
438 const int IOProcNumber = ParallelDescriptor::IOProcessorNumber();
439
440 Long num_particles = how_many;
441
442 ParallelDescriptor::ReduceLongSum(num_particles, IOProcNumber);
444 if (AMREX_D_TERM(lNrep[0] == 1, && lNrep[1] == 1, && lNrep[2] == 1))
445 {
446 amrex::Print() << "Total number of particles: " << num_particles << '\n';
447 }
448 else
449 {
450 Long num_particles_read = how_many_read;
451
452 ParallelDescriptor::ReduceLongSum(num_particles_read, IOProcNumber);
453
454 amrex::Print() << "Replication the domain with vector "
455 << AMREX_D_TERM(lNrep[0] << " ", << lNrep[1] << " ", << lNrep[2]) << "\n"
456 << "Total number of particles read in : " << num_particles_read << '\n'
457 << "Total number of particles after replication: " << num_particles << '\n';
458 }
459 }
461 AMREX_ASSERT(OK());
462
463 if (m_verbose > 1)
464 {
465 ByteSpread();
466
467 auto runtime = amrex::second() - strttime;
468
470
471 amrex::Print() << "InitFromAsciiFile() time: " << runtime << '\n';
472 }
473}
474
476// The format of a binary particle init file:
477//
478// NP -- The number of particles in the file. A "Long".
479// DM -- Our dimension. Either 1, 2, or 3. A "int".
480// NX -- The amount of "extra" data. A "int".
481// NP*(DM+NX) native floating-point numbers. A "float" or "double".
482//
483// Note that there is nothing separating all these values.
484// They're packed into the binary file like sardines.
485//
486template <typename ParticleType, int NArrayReal, int NArrayInt,
487 template<class> class Allocator, class CellAssignor>
488void
490InitFromBinaryFile (const std::string& file,
491 int extradata)
492{
493 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitFromBinaryFile()");
494 AMREX_ASSERT(!file.empty());
495 AMREX_ASSERT(extradata <= NStructReal);
496
497 const int MyProc = ParallelDescriptor::MyProc();
498 const int NProcs = ParallelDescriptor::NProcs();
499 const int IOProc = ParallelDescriptor::IOProcessorNumber();
500 const auto strttime = amrex::second();
501 //
502 // The number of MPI processes that read from the file.
503 // We limit this to a rather small number since there's a limit
504 // to the number of independent I/O channels on most filesystems.
505 //
506 const int NReaders = MaxReaders();
507
508 AMREX_ASSERT(NReaders <= NProcs);
509 //
510 // How many particles each NReaders reads before redistributing.
511 //
512 const Long NPartPerRedist = MaxParticlesPerRead();
513
514 if (m_verbose > 0)
515 {
516 amrex::Print() << "Reading with " << NReaders << " readers\n"
517 << "Redistributing after every " << NPartPerRedist << " particles for each reader\n";
518 }
519 //
520 // tmp_particles should mirror how m_particles is built.
521 // At the end of this routine it'll be the new m_particles.
522 //
523 Vector<ParticleLevel> tmp_particles;
524
525 tmp_particles.reserve(15); // So we don't ever have to do any copying on a resize.
526 tmp_particles.resize(finestLevel()+1);
527
528 resizeData();
529
530 //
531 // All the processors need to participate in Redistribute() though.
532 //
533 int NX = 0;
534 Long NP = 0;
535
537
538 std::ifstream ifs;
539
540 //
541 // The "set" of MPI processor numbers of the readers. We want
542 // to be able to easily check whether or not we're a reader.
543 //
544 std::set<int> readers;
545 //
546 // The same set but in ascending order.
547 //
548 Vector<int> rprocs(NReaders);
549
550 if (NReaders == NProcs)
551 {
552 //
553 // Just set'm.
554 //
555 for (int i = 0; i < NProcs; i++) {
556 rprocs[i] = i;
557 }
558 }
559 else
560 {
561 //
562 // The I/O Proc builds a set of NReader integers in the range: [0,NProcs-1].
563 //
564 // It then broadcast'm to all MPI procs.
565 //
566 // We want these to be as evenly distributed over the full set of
567 // [0,NProcs-1] MPI processors as possible, so that when reading we
568 // minimize the number of readers per Node, and hence can use more
569 // of the available Node memory for reading.
570 //
572 {
573 do
574 {
575 auto n = int(amrex::Random() * Real(NProcs-1));
576
577 AMREX_ASSERT(n >= 0);
578 AMREX_ASSERT(n < NProcs);
579
580 readers.insert(n);
581 }
582 while (std::ssize(readers) < NReaders);
583
584 AMREX_ASSERT(std::ssize(readers) == rprocs.size());
585
586 int i = 0;
587
588 for (auto it = readers.cbegin(), End = readers.cend();
589 it != End;
590 ++it, ++i)
591 {
592 rprocs[i] = *it;
593 }
594 }
595
596 ParallelDescriptor::Bcast(rprocs.dataPtr(), rprocs.size(), IOProc);
597 }
598
599 if (readers.empty())
600 {
601 //
602 // Set readers for non I/O procs.
603 //
604 readers.insert(rprocs.begin(), rprocs.end());
605
606 AMREX_ASSERT(std::ssize(readers) == rprocs.size());
607
608 AMREX_ASSERT(rprocs.size() == NReaders);
609 }
610
611 int RealSizeInFile = 0;
612
613 if (readers.contains(MyProc))
614 {
615 int DM = 0;
616
617 ifs.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
618
619 ifs.open(file.c_str(), std::ios::in|std::ios::binary);
620
621 if (!ifs.good()) {
623 }
624
625 ifs.read((char*)&NP, sizeof(NP));
626 ifs.read((char*)&DM, sizeof(DM));
627 ifs.read((char*)&NX, sizeof(NX));
628 //
629 // NP MUST be positive!
630 //
631 if (NP <= 0) {
632 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): NP <= 0");
633 }
634 //
635 // DM must equal AMREX_SPACEDIM.
636 //
637 if (DM != AMREX_SPACEDIM) {
638 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): DM != AMREX_SPACEDIM");
639 }
640 //
641 // NX MUST be in [0,N].
642 //
643 if (NX < 0 || NX > NStructReal) {
644 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): NX < 0 || NX > N");
645 }
646 //
647 // Can't ask for more data than exists in the file!
648 //
649 if (extradata > NX) {
650 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): extradata > NX");
651 }
652 //
653 // Figure out whether we're dealing with floats or doubles.
654 //
655 // First get our current position.
656 //
657 const std::streamoff CURPOS = ifs.tellg();
658 //
659 // Seek to end of file.
660 //
661 ifs.seekg(0,std::ios::end);
662 //
663 // ENDPOS - CURPOS should bracket the particle data.
664 //
665 const std::streamoff ENDPOS = ifs.tellg();
666
667 RealSizeInFile = int((ENDPOS - CURPOS) / (NP*(DM+NX)));
668
669 AMREX_ASSERT(RealSizeInFile == sizeof(float) || RealSizeInFile == sizeof(double));
670 //
671 // Now set stream back to earlier position.
672 //
673 ifs.seekg(CURPOS, std::ios::beg);
674 //
675 // Skip to our place in the file.
676 //
677 int id = 0;
678 for ( ; id < NReaders; id++) {
679 if (rprocs[id] == MyProc) {
680 break;
681 }
682 }
683
684 AMREX_ASSERT(id >= 0 && id < NReaders);
685
686 const std::streamoff NSKIP = id * (NP/NReaders) * (DM+NX) * RealSizeInFile;
687
688 if (NSKIP > 0)
689 {
690 ifs.seekg(NSKIP, std::ios::cur);
691 }
692
693 if (!ifs.good())
694 {
695 std::string msg("ParticleContainer::InitFromBinaryFile(");
696 msg += file;
697 msg += ") failed @ 1";
698 amrex::Error(msg.c_str());
699 }
700 }
701 //
702 // Everyone needs to know NP -- the number of particles in the file.
703 //
705 //
706 // How many particles each reader gets to read.
707 //
708 Long MyCnt = NP / NReaders;
709
710 if (MyProc == rprocs[NReaders-1]) {
711 //
712 // Give any remainder to the last reader.
713 //
714 MyCnt += NP % NReaders;
715 }
716
717 Long how_many_redists = NP / (NPartPerRedist*NReaders), how_many_read = 0;
718
719 if (NP % (NPartPerRedist*NReaders)) { how_many_redists++; }
720
721 Vector<float> fxtra, fignore;
722 Vector<double> dxtra, dignore;
723
724 if (extradata > 0)
725 {
726 fxtra.resize(extradata);
727 dxtra.resize(extradata);
728 }
729
730 if ((NX-extradata) > 0)
731 {
732 fignore.resize(NX-extradata);
733 dignore.resize(NX-extradata);
734 }
735
736 ParticleLocData pld;
737
738 for (int j = 0; j < how_many_redists; j++)
739 {
740
742 host_particles.reserve(15);
743 host_particles.resize(finestLevel()+1);
744
745 if (readers.contains(MyProc))
746 {
748
749 AMREX_ASSERT(MyCnt > how_many_read);
750
751 const Long NRead = std::min((MyCnt-how_many_read), NPartPerRedist);
752
753 for (Long i = 0; i < NRead; i++)
754 {
755 //
756 // We don't read in idata.id or idata.cpu. We'll set those later
757 // in a manner to guarantee the global uniqueness of the pair.
758 //
759 if (RealSizeInFile == sizeof(float))
760 {
761 float fpos[AMREX_SPACEDIM];
762
763 ifs.read((char*)&fpos[0], AMREX_SPACEDIM*sizeof(float));
764
765 AMREX_D_TERM(p.pos(0) = fpos[0];,
766 p.pos(1) = fpos[1];,
767 p.pos(2) = fpos[2];);
768
769 }
770 else if (RealSizeInFile == sizeof(double))
771 {
772 double dpos[AMREX_SPACEDIM];
773
774 ifs.read((char*)&dpos[0], AMREX_SPACEDIM*sizeof(double));
775
776 AMREX_D_TERM(p.pos(0) = static_cast<ParticleReal>(dpos[0]);,
777 p.pos(1) = static_cast<ParticleReal>(dpos[1]);,
778 p.pos(2) = static_cast<ParticleReal>(dpos[2]););
779 }
780
781 //
782 // Read in any "extradata".
783 //
784 if (extradata > 0)
785 {
786 if (RealSizeInFile == sizeof(float))
787 {
788 ifs.read((char*)fxtra.data(), std::streamsize(extradata*sizeof(float)));
789
790 for (int ii = 0; ii < extradata; ii++) {
791 p.rdata(ii) = static_cast<ParticleReal>(fxtra[ii]);
792 }
793 }
794 else if (RealSizeInFile == sizeof(double))
795 {
796 ifs.read((char*)dxtra.data(), std::streamsize(extradata*sizeof(double)));
797
798 for (int ii = 0; ii < extradata; ii++) {
799 p.rdata(ii) = static_cast<ParticleReal>(dxtra[ii]);
800 }
801 }
802 }
803 //
804 // Read any remaining data for this particle.
805 //
806 if ((NX-extradata) > 0)
807 {
808 if (RealSizeInFile == sizeof(float))
809 {
810 ifs.read((char*)fignore.data(), std::streamsize((NX-extradata)*sizeof(float)));
811 }
812 else if (RealSizeInFile == sizeof(double))
813 {
814 ifs.read((char*)dignore.data(), std::streamsize((NX-extradata)*sizeof(double)));
815 }
816 }
817
818 if (!ifs.good())
819 {
820 std::string msg("ParticleContainer::InitFromBinaryFile(");
821 msg += file;
822 msg += ") failed @ 2";
823 amrex::Error(msg.c_str());
824 }
825
826 if (!Where(p, pld))
827 {
829
830 if (!Where(p, pld))
831 {
832 if (m_verbose) {
833 amrex::AllPrint() << "BAD PARTICLE ID WOULD BE " << ParticleType::NextID() << '\n'
834 << "BAD PARTICLE POS "
835 << AMREX_D_TERM( p.pos(0),
836 << p.pos(1),
837 << p.pos(2))
838 << "\n";
839 }
840 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): invalid particle");
841 }
842 }
843
844 p.id() = ParticleType::NextID();
845 p.cpu() = MyProc;
846
847 host_particles[pld.m_lev][std::make_pair(pld.m_grid, pld.m_tile)].push_back(p);
848 }
849
850 how_many_read += NRead;
851 }
852
853 for (int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
854 {
855 for (auto& kv : host_particles[host_lev]) {
856 auto grid = kv.first.first;
857 auto tile = kv.first.second;
858 const auto& src_tile = kv.second;
859
860 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
861 auto old_size = dst_tile.GetArrayOfStructs().size();
862 auto new_size = old_size + src_tile.size();
863 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size, true);
864
865 Gpu::copyAsync(Gpu::hostToDevice, src_tile.begin(), src_tile.end(),
866 dst_tile.GetArrayOfStructs().begin() + old_size);
867 }
868 }
870
871 Redistribute();
872
873 //
874 // Move particles in m_particles into tmp_particles so that
875 // we don't keep trying to redistribute particles that have
876 // already been redistributed correctly.
877 //
878 for (int lev = 0; lev < std::ssize(m_particles); lev++)
879 {
880 auto& pmap = m_particles[lev];
881 auto& tmp_pmap = tmp_particles[lev];
882
883 for (auto& kv : pmap) {
884 auto& aos = kv.second.GetArrayOfStructs()();
885 auto& tmp_aos = tmp_pmap[kv.first].GetArrayOfStructs()();
886
887 tmp_aos.insert(tmp_aos.end(), aos.begin(), aos.end());
888 ParticleVector().swap(aos);
889 }
890
891 ParticleLevel().swap(pmap);
892 }
893 }
894 //
895 // Make tmp_particles the new m_particles.
896 //
897 tmp_particles.swap(m_particles);
898 //
899 // The tiles in tmp_particles were not defined: define them and size their
900 // SoA components to the particle count, with zero for the values they did not have.
901 //
902 for (int lev = 0; lev < std::ssize(m_particles); ++lev) {
903 for (auto& kv : m_particles[lev]) {
904 auto& ptile = DefineAndReturnParticleTile(lev, kv.first.first, kv.first.second);
905 particle_detail::resizeAndZeroNewSoA(ptile, ptile.numParticles(), true);
906 }
907 }
908 //
909 // Add up all the particles read in to get the total number of particles.
910 //
911 if (m_verbose > 0)
912 {
913 Long num_particles_read = how_many_read;
914
916
917 amrex::Print() << "\nTotal number of particles: " << num_particles_read << '\n';
918 }
919
920 AMREX_ASSERT(OK());
921
922 if (m_verbose > 1)
923 {
924 ByteSpread();
925
926 auto runtime = amrex::second() - strttime;
927
929
930 amrex::Print() << "InitFromBinaryFile() time: " << runtime << '\n';
931 }
932
934}
935
936//
937// This function expects to read a file containing the pathnames of
938// binary particles files needing to be read in for input. It expects
939// one file name per line.
940//
941
942template <typename ParticleType, int NArrayReal, int NArrayInt,
943 template<class> class Allocator, class CellAssignor>
944void
946InitFromBinaryMetaFile (const std::string& metafile,
947 int extradata)
948{
949 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitFromBinaryMetaFile()");
950 const auto strttime = amrex::second();
951
952 std::ifstream ifs(metafile.c_str(), std::ios::in);
953
954 std::string file;
955
956 for (;;)
957 {
958 std::getline(ifs,file);
959
960 if (!ifs.good()) { break; }
961
962 if (m_verbose > 1) {
963 amrex::Print() << "InitFromBinaryMetaFile: processing file: " << file << '\n';
964 }
965
966 InitFromBinaryFile(file, extradata);
967 }
968
969 if (m_verbose > 1)
970 {
971 ByteSpread();
972
973 auto runtime = amrex::second() - strttime;
974
976
977 amrex::Print() << "InitFromBinaryMetaFile() time: " << runtime << '\n';
978 }
979}
980
981template <typename ParticleType, int NArrayReal, int NArrayInt,
982 template<class> class Allocator, class CellAssignor>
983void
985InitRandom (Long icount,
986 ULong iseed,
987 const ParticleInitData& pdata,
988 bool serialize,
989 RealBox containing_bx)
990{
991 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitRandom()");
992 AMREX_ASSERT(iseed > 0);
993 AMREX_ASSERT(icount > 0);
994
995 AMREX_ASSERT(m_gdb != nullptr);
996
997 const int MyProc = ParallelDescriptor::MyProc();
998 const int NProcs = ParallelContext::NProcsSub();
999 const int IOProc = ParallelContext::IOProcessorNumberSub();
1000 const auto strttime = amrex::second();
1001 const Geometry& geom = Geom(0);
1002
1003 Real r, x, len[AMREX_SPACEDIM] = { AMREX_D_DECL(geom.ProbLength(0),
1004 geom.ProbLength(1),
1005 geom.ProbLength(2)) };
1006
1007 // We will enforce that the particles are within the containing_bx.
1008 // If containing_bx is not passed in, it defaults to the full domain.
1009 if (!containing_bx.ok()) { containing_bx = geom.ProbDomain(); }
1010
1011 // containing_bx is assumed to lie within the domain.
1012 if (!geom.ProbDomain().contains(containing_bx))
1013 {
1014 containing_bx.setLo(geom.ProbLo());
1015 containing_bx.setHi(geom.ProbHi());
1016 }
1017
1018 const Real* xlo = containing_bx.lo();
1019 const Real* xhi = containing_bx.hi();
1020
1021 amrex::InitRandom(iseed+MyProc);
1022
1023 if (serialize)
1024 {
1025 if(icount*AMREX_SPACEDIM >= std::numeric_limits<int>::max())
1026 {
1028 "InitRandom has serialize=true, but this would cause too much "
1029 "particle data to be sent from IOProc. Set serialize=false, "
1030 "or use fewer than " +
1031 std::to_string(
1032 amrex::Math::ceil(
1033 amrex::Real(std::numeric_limits<int>::max()) /
1034 amrex::Real(AMREX_SPACEDIM)
1035 )
1036 ) + " particles."
1037 );
1038 }
1039 //
1040 // We'll let IOProc generate the particles so we get the same
1041 // positions no matter how many CPUs we have. This is here
1042 // mainly for debugging purposes. It's not really useful for
1043 // very large numbers of particles.
1044 //
1045 //
1046 Vector<typename ParticleType::RealType> pos(icount*AMREX_SPACEDIM);
1047
1049 {
1050 for (Long j = 0; j < icount; j++)
1051 {
1052 for (int i = 0; i < AMREX_SPACEDIM; i++)
1053 {
1054 do
1055 {
1056 r = amrex::Random();
1057 x = geom.ProbLo(i) + (r * len[i]);
1058 }
1059 while (static_cast<ParticleReal>(x) < static_cast<ParticleReal>(xlo[i]) || static_cast<ParticleReal>(x) >= static_cast<ParticleReal>(xhi[i]));
1060
1061 pos[j*AMREX_SPACEDIM + i] = static_cast<ParticleReal>(x);
1062 }
1063 }
1064 }
1065
1066 ParallelDescriptor::Bcast(pos.dataPtr(), icount*AMREX_SPACEDIM, IOProc,
1068
1069 ParticleLocData pld;
1070
1072 host_particles.reserve(15);
1073 host_particles.resize(finestLevel()+1);
1074
1075 Vector<std::map<std::pair<int, int>, std::array<Gpu::HostVector<ParticleReal>, NArrayReal > > > host_real_attribs;
1076 host_real_attribs.reserve(15);
1077 host_real_attribs.resize(finestLevel()+1);
1078
1079 Vector<std::map<std::pair<int, int>, std::array<Gpu::HostVector<int>, NArrayInt > > > host_int_attribs;
1080 host_int_attribs.reserve(15);
1081 host_int_attribs.resize(finestLevel()+1);
1082
1084 host_idcpu.reserve(15);
1085 host_idcpu.resize(finestLevel()+1);
1086
1087 for (Long j = 0; j < icount; j++)
1088 {
1089 Particle<0, 0> ptest;
1090
1091 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1092 ptest.pos(i) = pos[j*AMREX_SPACEDIM + i];
1093 }
1094
1095 if (!Where(ptest, pld)) {
1096 amrex::Abort("ParticleContainer::InitRandom(): invalid particle");
1097 }
1098
1099 AMREX_ASSERT(pld.m_lev >= 0 && pld.m_lev <= finestLevel());
1100 std::pair<int, int> ind(pld.m_grid, pld.m_tile);
1101
1102 const int who = ParticleDistributionMap(pld.m_lev)[pld.m_grid];
1103
1104 if (who == MyProc) {
1105
1106 if constexpr(!ParticleType::is_soa_particle)
1107 {
1109 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1110 p.pos(i) = pos[j*AMREX_SPACEDIM + i];
1111 }
1112
1113 // We own it. Add it at the appropriate level.
1114 p.id() = ParticleType::NextID();
1115 p.cpu() = MyProc;
1116
1117 for (int i = 0; i < NStructInt; i++) {
1118 p.idata(i) = pdata.int_struct_data[i];
1119 }
1120
1121 for (int i = 0; i < NStructReal; i++) {
1122 p.rdata(i) = static_cast<ParticleReal>(pdata.real_struct_data[i]);
1123 }
1124
1125 // add the struct
1126 host_particles[pld.m_lev][ind].push_back(p);
1127
1128 // add the real...
1129 for (int i = 0; i < NArrayReal; i++) {
1130 host_real_attribs[pld.m_lev][ind][i].push_back(static_cast<ParticleReal>(pdata.real_array_data[i]));
1131 }
1132
1133 // ... and int array data
1134 for (int i = 0; i < NArrayInt; i++) {
1135 host_int_attribs[pld.m_lev][ind][i].push_back(pdata.int_array_data[i]);
1136 }
1137 } else {
1138 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1139 host_real_attribs[pld.m_lev][ind][i].push_back(pos[j*AMREX_SPACEDIM+i]);
1140 }
1141
1142 host_idcpu[pld.m_lev][ind].push_back(0);
1143 ParticleIDWrapper(host_idcpu[pld.m_lev][ind].back()) = ParticleType::NextID();
1144 ParticleCPUWrapper(host_idcpu[pld.m_lev][ind].back()) = ParallelDescriptor::MyProc();
1145
1146 host_particles[pld.m_lev][ind];
1147
1148 // add the real...
1149 for (int i = AMREX_SPACEDIM; i < NArrayReal; i++) {
1150 host_real_attribs[pld.m_lev][ind][i].push_back(static_cast<ParticleReal>(pdata.real_array_data[i]));
1151 }
1152
1153 // ... and int array data
1154 for (int i = 2; i < NArrayInt; i++) {
1155 host_int_attribs[pld.m_lev][ind][i].push_back(pdata.int_array_data[i]);
1156 }
1157 }
1158 }
1159 }
1160
1161 for (int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
1162 {
1163 for (auto& kv : host_particles[host_lev]) {
1164 auto grid = kv.first.first;
1165 auto tile = kv.first.second;
1166 const auto& src_tile = kv.second;
1167
1168 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1169 auto old_size = dst_tile.size();
1170 auto new_size = old_size;
1171 if constexpr(!ParticleType::is_soa_particle)
1172 {
1173 new_size += src_tile.size();
1174 } else {
1175 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].size();
1176 }
1177 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size);
1178
1179 if constexpr(!ParticleType::is_soa_particle)
1180 {
1181 Gpu::copyAsync(Gpu::hostToDevice, src_tile.begin(), src_tile.end(),
1182 dst_tile.GetArrayOfStructs().begin() + old_size);
1183 } else {
1185 host_idcpu[host_lev][std::make_pair(grid,tile)].begin(),
1186 host_idcpu[host_lev][std::make_pair(grid,tile)].end(),
1187 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1188 }
1189
1190 for (int i = 0; i < NArrayReal; ++i) { // NOLINT(readability-misleading-indentation)
1192 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].begin(),
1193 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].end(),
1194 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1195 }
1196
1197 for (int i = 0; i < NArrayInt; ++i) {
1199 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].begin(),
1200 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].end(),
1201 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1202 }
1203 }
1204 }
1206
1207 AMREX_ASSERT(OK());
1208 }
1209 else {
1210 // We'll generate the particles in parallel.
1211 // Each CPU will key off the given seed to get independent streams of random numbers.
1212 Long M = icount / NProcs;
1213 // Processor 0 will get the slop.
1214 if (ParallelContext::MyProcSub() == 0) {
1215 M += (icount % NProcs);
1216 }
1217
1218 ParticleLocData pld;
1219
1221 host_particles.reserve(15);
1222 host_particles.resize(finestLevel()+1);
1223
1224 Vector<std::map<std::pair<int, int>, std::array<Gpu::HostVector<ParticleReal>, NArrayReal > > > host_real_attribs;
1225 host_real_attribs.reserve(15);
1226 host_real_attribs.resize(finestLevel()+1);
1227
1228 Vector<std::map<std::pair<int, int>, std::array<Gpu::HostVector<int>, NArrayInt > > > host_int_attribs;
1229 host_int_attribs.reserve(15);
1230 host_int_attribs.resize(finestLevel()+1);
1231
1233 host_idcpu.reserve(15);
1234 host_idcpu.resize(finestLevel()+1);
1235
1236 for (Long icnt = 0; icnt < M; icnt++) {
1237 Particle<0, 0> ptest;
1238 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1239 do {
1240 r = amrex::Random();
1241 x = geom.ProbLo(i) + (r * len[i]);
1242 }
1243 while (static_cast<ParticleReal>(x) < static_cast<ParticleReal>(xlo[i]) || static_cast<ParticleReal>(x) >= static_cast<ParticleReal>(xhi[i]));
1244
1245 ptest.pos(i) = static_cast<ParticleReal>(x);
1246
1247 AMREX_ASSERT(ptest.pos(i) < geom.ProbHi(i));
1248 }
1249
1250 ptest.id() = ParticleType::NextID();
1251 ptest.cpu() = ParallelDescriptor::MyProc();
1252
1253 // locate the particle
1254 if (!Where(ptest, pld))
1255 {
1256 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitRandom(): invalid particle");
1257 }
1258 AMREX_ASSERT(pld.m_lev >= 0 && pld.m_lev <= finestLevel());
1259 std::pair<int, int> ind(pld.m_grid, pld.m_tile);
1260
1261 if constexpr(!ParticleType::is_soa_particle)
1262 {
1264 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1265 p.pos(i) = ptest.pos(i);;
1266 }
1267
1268 p.id() = ptest.id();
1269 p.cpu() = ptest.cpu();
1270
1271 for (int i = 0; i < NStructReal; i++) {
1272 p.rdata(i) = static_cast<ParticleReal>(pdata.real_struct_data[i]);
1273 }
1274
1275 for (int i = 0; i < NStructInt; i++) {
1276 p.idata(i) = pdata.int_struct_data[i];
1277 }
1278
1279 // add the struct
1280 host_particles[pld.m_lev][ind].push_back(p);
1281
1282 // add the real...
1283 for (int i = 0; i < NArrayReal; i++) {
1284 host_real_attribs[pld.m_lev][ind][i].push_back(static_cast<ParticleReal>(pdata.real_array_data[i]));
1285 }
1286
1287 // ... and int array data
1288 for (int i = 0; i < NArrayInt; i++) {
1289 host_int_attribs[pld.m_lev][ind][i].push_back(pdata.int_array_data[i]);
1290 }
1291 } else {
1292 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1293 host_real_attribs[pld.m_lev][ind][i].push_back(ptest.pos(i));
1294 }
1295
1296 host_idcpu[pld.m_lev][ind].push_back(0);
1297 ParticleIDWrapper(host_idcpu[pld.m_lev][ind].back()) = ParticleType::NextID();
1298 ParticleCPUWrapper(host_idcpu[pld.m_lev][ind].back()) = ParallelDescriptor::MyProc();
1299
1300 host_particles[pld.m_lev][ind];
1301
1302 // add the real...
1303 for (int i = AMREX_SPACEDIM; i < NArrayReal; i++) {
1304 host_real_attribs[pld.m_lev][ind][i].push_back(static_cast<ParticleReal>(pdata.real_array_data[i]));
1305 }
1306
1307 // ... and int array data
1308 for (int i = 2; i < NArrayInt; i++) {
1309 host_int_attribs[pld.m_lev][ind][i].push_back(pdata.int_array_data[i]);
1310 }
1311 }
1312 }
1313
1314 for (int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
1315 {
1316 for (auto& kv : host_particles[host_lev]) {
1317 auto grid = kv.first.first;
1318 auto tile = kv.first.second;
1319 const auto& src_tile = kv.second;
1320
1321 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1322 auto old_size = dst_tile.size();
1323 auto new_size = old_size;
1324 if constexpr(!ParticleType::is_soa_particle)
1325 {
1326 new_size += src_tile.size();
1327 } else {
1328 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].size();
1329 }
1330 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size);
1331
1332 if constexpr(!ParticleType::is_soa_particle)
1333 {
1334 Gpu::copyAsync(Gpu::hostToDevice, src_tile.begin(), src_tile.end(),
1335 dst_tile.GetArrayOfStructs().begin() + old_size);
1336 } else {
1338 host_idcpu[host_lev][std::make_pair(grid,tile)].begin(),
1339 host_idcpu[host_lev][std::make_pair(grid,tile)].end(),
1340 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1341 }
1342
1343 for (int i = 0; i < NArrayReal; ++i) { // NOLINT(readability-misleading-indentation)
1345 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].begin(),
1346 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].end(),
1347 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1348 }
1349
1350 for (int i = 0; i < NArrayInt; ++i) {
1352 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].begin(),
1353 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].end(),
1354 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1355 }
1356 }
1357 }
1359
1360 // Let Redistribute() sort out where the particles belong.
1361 Redistribute();
1362 }
1363
1364 if (m_verbose > 1)
1365 {
1366 auto stoptime = amrex::second() - strttime;
1367
1369
1370 amrex::Print() << "ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitRandom() time: " << stoptime << '\n';
1371 }
1372
1374}
1375
1376template <typename ParticleType, int NArrayReal, int NArrayInt,
1377 template<class> class Allocator, class CellAssignor>
1378void
1380::InitRandomPerBox (Long icount_per_box,
1381 ULong iseed,
1382 const ParticleInitData& pdata)
1383{
1384 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitRandomPerBox()");
1385 AMREX_ASSERT(iseed > 0);
1386 AMREX_ASSERT(icount_per_box > 0);
1387
1388 AMREX_ASSERT(m_gdb != nullptr);
1389
1390 const int IOProc = ParallelDescriptor::IOProcessorNumber();
1391 const auto strttime = amrex::second();
1392 const Geometry& geom = Geom(0);
1393
1394 ParticleLocData pld;
1396
1397 // This assumes level 0 since geom = m_gdb->Geom(0)
1398 const Real* dx = geom.CellSize();
1399
1400 // We use exactly the same seed for every grid
1401 std::mt19937 mt(iseed);
1402 std::uniform_real_distribution<double> dist(0.0, 1.0);
1403
1404 m_particles.resize(m_gdb->finestLevel()+1);
1405
1406 for (int lev = 0; lev < std::ssize(m_particles); lev++)
1407 {
1408 AMREX_ASSERT(m_particles[lev].empty());
1409 }
1410
1411 // We'll generate the particles in parallel -- but no tiling here.
1412 for (MFIter mfi(*m_dummy_mf[0], false); mfi.isValid(); ++mfi)
1413 {
1414 Box grid = m_gdb->ParticleBoxArray(0)[mfi.index()];
1415 RealBox grid_box = RealBox(grid,dx,geom.ProbLo());
1416
1417 for (Long icnt = 0; icnt < icount_per_box; icnt++) {
1418 for (Long jcnt = 0; jcnt < icount_per_box; jcnt++) {
1419 for (Long kcnt = 0; kcnt < icount_per_box; kcnt++)
1420 {
1422 p.pos(0) = static_cast<ParticleReal>(grid_box.lo(0) + (dist(mt) + double(icnt)) / double(icount_per_box) * grid_box.length(0));,
1423 p.pos(1) = static_cast<ParticleReal>(grid_box.lo(1) + (dist(mt) + double(jcnt)) / double(icount_per_box) * grid_box.length(1));,
1424 p.pos(2) = static_cast<ParticleReal>(grid_box.lo(2) + (dist(mt) + double(kcnt)) / double(icount_per_box) * grid_box.length(2));
1425 );
1426
1427 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1428 AMREX_ASSERT(p.pos(i) < grid_box.hi(i));
1429 }
1430
1431 // the real struct data
1432 for (int i = 0; i < NStructReal; i++) {
1433 p.rdata(i) = static_cast<ParticleReal>(pdata.real_struct_data[i]);
1434 }
1435
1436 // the int struct data
1437 p.id() = ParticleType::NextID();
1438 p.cpu() = ParallelDescriptor::MyProc();
1439
1440 for (int i = 0; i < NStructInt; i++) {
1441 p.idata(i) = pdata.int_struct_data[i];
1442 }
1443
1444 // locate the particle
1445 if (!Where(p, pld)) {
1446 amrex::Abort("ParticleContainer::InitRandomPerBox(): invalid particle");
1447 }
1448 AMREX_ASSERT(pld.m_lev >= 0 && pld.m_lev <= finestLevel());
1449 auto& ptile = DefineAndReturnParticleTile(pld.m_lev, pld.m_grid, pld.m_tile);
1450
1451 // add the struct
1452 ptile.push_back(p);
1453
1454 // add the real...
1455 for (int i = 0; i < NArrayReal; i++) {
1456 ptile.push_back_real(i, static_cast<ParticleReal>(pdata.real_array_data[i]));
1457 }
1458
1459 // ... and int array data
1460 for (int i = 0; i < NArrayInt; i++) {
1461 ptile.push_back_int(i, pdata.int_array_data[i]);
1462 }
1463
1464 } } }
1465 }
1466
1467 // size the runtime components, which the push_backs above do not fill, with zeros
1468 for (auto& pmap : m_particles) {
1469 for (auto& kv : pmap) {
1470 particle_detail::resizeAndZeroNewSoA(kv.second, kv.second.numParticles());
1471 }
1472 }
1473
1474 if (m_verbose > 1)
1475 {
1476 auto stoptime = amrex::second() - strttime;
1477
1478 ParallelDescriptor::ReduceRealMax(stoptime,IOProc);
1479
1480 amrex::Print() << "ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitRandomPerBox() time: " << stoptime << '\n';
1481 }
1482}
1483
1484template <typename ParticleType, int NArrayReal, int NArrayInt,
1485 template<class> class Allocator, class CellAssignor>
1486void
1488InitOnePerCell (Real x_off, Real y_off, Real z_off, const ParticleInitData& pdata)
1489{
1490 amrex::ignore_unused(y_off,z_off);
1491
1492 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitOnePerCell()");
1493
1494 AMREX_ASSERT(m_gdb != nullptr);
1495
1496 // Note that x_off, y_off and z_off are the offsets from the lower left corner
1497 // in each cell as measured in units of dx, so they must be in [0,1]
1498 AMREX_ASSERT(x_off >= 0. && y_off >= 0. && z_off >= 0.);
1499 AMREX_ASSERT(x_off <= 1. && y_off <= 1. && z_off <= 1.);
1500
1501 const int IOProc = ParallelDescriptor::IOProcessorNumber();
1502 const auto strttime = amrex::second();
1503 const Geometry& geom = Geom(0); // generates particles on level 0;
1504
1505 const Real* dx = geom.CellSize();
1506
1508
1509 // We'll generate the particles in parallel -- but no tiling of the grid here.
1510 for (MFIter mfi(*m_dummy_mf[0], false); mfi.isValid(); ++mfi) {
1511 Box grid = ParticleBoxArray(0)[mfi.index()];
1512 auto ind = std::make_pair(mfi.index(), mfi.LocalTileIndex());
1513 RealBox grid_box (grid,dx,geom.ProbLo());
1516 &m_soa_rdata_names, &m_soa_idata_names);
1517 for (IntVect beg = grid.smallEnd(), end=grid.bigEnd(), cell = grid.smallEnd(); cell <= end; grid.next(cell))
1518 {
1519 // the real struct data
1520 AMREX_D_TERM(p.pos(0) = static_cast<ParticleReal>(grid_box.lo(0) + (x_off + Real(cell[0]-beg[0]))*dx[0]);,
1521 p.pos(1) = static_cast<ParticleReal>(grid_box.lo(1) + (y_off + Real(cell[1]-beg[1]))*dx[1]);,
1522 p.pos(2) = static_cast<ParticleReal>(grid_box.lo(2) + (z_off + Real(cell[2]-beg[2]))*dx[2]););
1523
1524 for (int d = 0; d < AMREX_SPACEDIM; ++d) {
1525 AMREX_ASSERT(p.pos(d) < grid_box.hi(d));
1526 }
1527
1528 for (int i = 0; i < NStructReal; i++) {
1529 p.rdata(i) = static_cast<ParticleReal>(pdata.real_struct_data[i]);
1530 }
1531
1532 // the int struct data
1533 p.id() = ParticleType::NextID();
1534 p.cpu() = ParallelDescriptor::MyProc();
1535
1536 for (int i = 0; i < NStructInt; i++) {
1537 p.idata(i) = pdata.int_struct_data[i];
1538 }
1539
1540 // add the struct
1541 ptile_tmp.push_back(p);
1542
1543 // add the real...
1544 for (int i = 0; i < NArrayReal; i++) {
1545 ptile_tmp.push_back_real(i, static_cast<ParticleReal>(pdata.real_array_data[i]));
1546 }
1547
1548 // ... and int array data
1549 for (int i = 0; i < NArrayInt; i++) {
1550 ptile_tmp.push_back_int(i, pdata.int_array_data[i]);
1551 }
1552 }
1553
1554 // size the runtime components, which the push_backs above do not fill, with zeros
1555 particle_detail::resizeAndZeroNewSoA(ptile_tmp, ptile_tmp.numParticles());
1556
1557 auto& dst_tile = DefineAndReturnParticleTile(0, ind.first, ind.second);
1558 dst_tile.resize(ptile_tmp.numParticles());
1559 amrex::copyParticles(dst_tile, ptile_tmp);
1561 }
1562
1563 Redistribute();
1564
1565 if (m_verbose > 1) {
1566 auto stoptime = amrex::second() - strttime;
1567
1568 ParallelDescriptor::ReduceRealMax(stoptime,IOProc);
1569
1570 amrex::Print() << "ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitOnePerCell() time: " << stoptime << '\n';
1571 }
1572}
1573
1574template <typename ParticleType, int NArrayReal, int NArrayInt,
1575 template<class> class Allocator, class CellAssignor>
1576void
1578InitNRandomPerCell (int n_per_cell, const ParticleInitData& pdata)
1579{
1580 BL_PROFILE("ParticleContainer<NSR, NSI, NAR, NAI>::InitNRandomPerCell()");
1581
1582 AMREX_ASSERT(m_gdb != nullptr);
1583
1584 const int IOProc = ParallelDescriptor::IOProcessorNumber();
1585 const auto strttime = amrex::second();
1586 const Geometry& geom = Geom(0);
1587
1588 // This assumes level 0 since geom = Geom(0)
1589 const Real* dx = geom.CellSize();
1590
1591 resizeData();
1592
1593 for (int lev = 0; lev < std::ssize(m_particles); lev++) {
1594 AMREX_ASSERT(m_particles[lev].empty());
1595 }
1596
1597 ParticleLocData pld;
1599 Real r;
1600
1601 // We'll generate the particles in parallel -- but no tiling here.
1602 for (MFIter mfi(*m_dummy_mf[0], false); mfi.isValid(); ++mfi)
1603 {
1604 Box grid = ParticleBoxArray(0)[mfi.index()];
1605 RealBox grid_box (grid,dx,geom.ProbLo());
1606
1608 host_particles.reserve(15);
1609 host_particles.resize(finestLevel()+1);
1610
1611 Vector<std::map<std::pair<int, int>, std::array<Gpu::HostVector<ParticleReal>, NArrayReal > > > host_real_attribs;
1612 host_real_attribs.reserve(15);
1613 host_real_attribs.resize(finestLevel()+1);
1614
1615 Vector<std::map<std::pair<int, int>, std::array<Gpu::HostVector<int>, NArrayInt > > > host_int_attribs;
1616 host_int_attribs.reserve(15);
1617 host_int_attribs.resize(finestLevel()+1);
1618
1619 for (IntVect beg = grid.smallEnd(), end=grid.bigEnd(),
1620 cell = grid.smallEnd(); cell <= end; grid.next(cell)) {
1621
1622 for (int n = 0; n < n_per_cell; n++)
1623 {
1624 // the real struct data
1625 for (int i = 0; i < AMREX_SPACEDIM; i++) {
1626 constexpr int max_iter = 10;
1627 int iter = 0;
1628 while (iter < max_iter) {
1629 r = amrex::Random();
1630 p.pos(i) = static_cast<ParticleReal>(grid_box.lo(i) + (r + Real(cell[i]-beg[i]))*dx[i]);
1631 if (p.pos(i) < grid_box.hi(i)) { break; }
1632 iter++;
1633 }
1634 AMREX_ASSERT(p.pos(i) < grid_box.hi(i));
1635 }
1636
1637 for (int i = 0; i < NStructReal; i++) {
1638 p.rdata(i) = static_cast<ParticleReal>(pdata.real_struct_data[i]);
1639 }
1640
1641 // the int struct data
1642 p.id() = ParticleType::NextID();
1643 p.cpu() = ParallelDescriptor::MyProc();
1644
1645 for (int i = 0; i < NStructInt; i++) {
1646 p.idata(i) = pdata.int_struct_data[i];
1647 }
1648
1649 // locate the particle
1650 if (!Where(p, pld)) {
1651 amrex::Abort("ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitNRandomPerCell(): invalid particle");
1652 }
1653 AMREX_ASSERT(pld.m_lev >= 0 && pld.m_lev <= finestLevel());
1654 std::pair<int, int> ind(pld.m_grid, pld.m_tile);
1655
1656 // add the struct
1657 host_particles[pld.m_lev][ind].push_back(p);
1658
1659 // add the real...
1660 for (int i = 0; i < NArrayReal; i++) {
1661 host_real_attribs[pld.m_lev][ind][i].push_back(static_cast<ParticleReal>(pdata.real_array_data[i]));
1662 }
1663
1664 // ... and int array data
1665 for (int i = 0; i < NArrayInt; i++) {
1666 host_int_attribs[pld.m_lev][ind][i].push_back(pdata.int_array_data[i]);
1667 }
1668 }
1669 }
1670
1671 for (int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
1672 {
1673 for (auto& kv : host_particles[host_lev]) {
1674 auto gid = kv.first.first;
1675 auto tid = kv.first.second;
1676 const auto& src_tid = kv.second;
1677
1678 auto& dst_tile = DefineAndReturnParticleTile(host_lev, gid, tid);
1679 auto old_size = dst_tile.GetArrayOfStructs().size();
1680 auto new_size = old_size + src_tid.size();
1681 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size);
1682
1683 Gpu::copyAsync(Gpu::hostToDevice, src_tid.begin(), src_tid.end(),
1684 dst_tile.GetArrayOfStructs().begin() + old_size);
1685
1686 for (int i = 0; i < NArrayReal; ++i)
1687 {
1689 host_real_attribs[host_lev][std::make_pair(gid,tid)][i].begin(),
1690 host_real_attribs[host_lev][std::make_pair(gid,tid)][i].end(),
1691 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1692 }
1693
1694 for (int i = 0; i < NArrayInt; ++i)
1695 {
1697 host_int_attribs[host_lev][std::make_pair(gid,tid)][i].begin(),
1698 host_int_attribs[host_lev][std::make_pair(gid,tid)][i].end(),
1699 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1700 }
1701 }
1702 }
1704 }
1705
1706 if (m_verbose > 1)
1707 {
1708 auto stoptime = amrex::second() - strttime;
1709
1710 ParallelDescriptor::ReduceRealMax(stoptime,IOProc);
1711
1712 amrex::Print() << "ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitNRandomPerCell() time: " << stoptime << '\n';
1713 }
1714
1716}
1717
1718}
1719
1720#endif /*AMREX_PARTICLEINIT_H*/
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
while parser_exe_t p
Definition AMReX_Parser_Exe_Body.H:33
double pdata[AMREX_PARSER_STACK_SIZE]
Definition AMReX_Parser_Exe_Body.H:11
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Print on all processors of the default communicator.
Definition AMReX_Print.H:113
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
Return the inclusive upper bound of the box.
Definition AMReX_Box.H:136
__host__ __device__ void next(IntVectND< dim > &) const noexcept
Step through the rectangle. It is a runtime error to give a point not inside rectangle....
Definition AMReX_Box.H:1156
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:124
const Real * CellSize() const noexcept
Returns the cellsize for each coordinate direction.
Definition AMReX_CoordSys.H:79
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:87
const Real * ProbHi() const noexcept
Returns the hi end of the problem domain in each dimension.
Definition AMReX_Geometry.H:212
const RealBox & ProbDomain() const noexcept
Returns the problem domain.
Definition AMReX_Geometry.H:202
Real ProbLength(int dir) const noexcept
Returns length of problem domain in specified dimension.
Definition AMReX_Geometry.H:244
const Real * ProbLo() const noexcept
Returns the lo end of the problem domain in each dimension.
Definition AMReX_Geometry.H:210
static void streamSynchronize() noexcept
Definition AMReX_GpuDevice.cpp:992
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:176
void pop_back() noexcept
Definition AMReX_PODVector.H:650
T & back() noexcept
Definition AMReX_PODVector.H:668
bool empty() const noexcept
Definition AMReX_PODVector.H:658
void push_back(const T &a_value)
Definition AMReX_PODVector.H:633
const DistributionMapping & ParticleDistributionMap(int lev) const
Get the DistributionMapping for a given level.
Definition AMReX_ParticleContainerBase.H:207
ParGDBBase * m_gdb
Definition AMReX_ParticleContainerBase.H:320
const BoxArray & ParticleBoxArray(int lev) const
Get the BoxArray for a given level.
Definition AMReX_ParticleContainerBase.H:200
const Geometry & Geom(int lev) const
Get the Geometry for a given level.
Definition AMReX_ParticleContainerBase.H:214
static Long MaxParticlesPerRead()
Definition AMReX_ParticleContainerBase.cpp:324
int m_verbose
Definition AMReX_ParticleContainerBase.H:317
int finestLevel() const
the finest level actually defined for the ParticleContainer
Definition AMReX_ParticleContainerBase.H:223
Vector< std::unique_ptr< MultiFab > > m_dummy_mf
Definition AMReX_ParticleContainerBase.H:321
static int MaxReaders()
Definition AMReX_ParticleContainerBase.cpp:302
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:154
bool OK(int lev_min=0, int lev_max=-1, int nGrow=0) const
Definition AMReX_ParticleContainerI.H:1937
bool PeriodicShift(P &p) const
Returns true if the particle was shifted.
Definition AMReX_ParticleContainerI.H:381
std::map< std::pair< int, int >, ParticleTileType > ParticleLevel
Definition AMReX_ParticleContainer.H:201
static constexpr int NArrayInt
Definition AMReX_ParticleContainer.H:167
static constexpr int NArrayReal
Definition AMReX_ParticleContainer.H:165
void Redistribute(int lev_min=0, int lev_max=-1, int nGrow=0, int local=0, bool remove_negative=true)
Redistribute puts all the particles back in the right places (for some value of right).
Definition AMReX_ParticleContainer.H:519
ParticleInitType< NStructReal, NStructInt, NArrayReal, NArrayInt > ParticleInitData
Definition AMReX_ParticleContainer.H:197
void InitNRandomPerCell(int n_per_cell, const ParticleInitData &pdata)
This initializes the particle container with n_per_cell randomly distributed particles per cell,...
Definition AMReX_ParticleInit.H:1578
typename AoS::ParticleVector ParticleVector
Definition AMReX_ParticleContainer.H:209
static constexpr int NStructInt
Number of extra integer components in the particle struct.
Definition AMReX_ParticleContainer.H:163
int NumRealComps() const
Definition AMReX_ParticleContainer.H:1399
int NumRuntimeIntComps() const
Definition AMReX_ParticleContainer.H:1397
void InitOnePerCell(Real x_off, Real y_off, Real z_off, const ParticleInitData &pdata)
This initializes the particle container with one particle per cell, where the other particle data and...
Definition AMReX_ParticleInit.H:1488
DefaultAssignor CellAssignor
Definition AMReX_ParticleContainer.H:158
void InitRandom(Long icount, ULong iseed, const ParticleInitData &pdata, bool serialize=false, RealBox bx=RealBox())
This initializes the particle container with icount randomly distributed particles....
Definition AMReX_ParticleInit.H:985
void resizeData() override
This resizes the vector of dummy MultiFabs used by the ParticleContainer for the current number of le...
Definition AMReX_ParticleContainerI.H:440
int NumRuntimeRealComps() const
Definition AMReX_ParticleContainer.H:1396
static constexpr int NStructReal
Number of extra Real components in the particle struct.
Definition AMReX_ParticleContainer.H:161
void InitFromBinaryMetaFile(const std::string &file, int extradata)
Definition AMReX_ParticleInit.H:946
bool Where(const P &prt, ParticleLocData &pld, int lev_min=0, int lev_max=-1, IntVect nGrow=IntVect(0), int local_grid=-1) const
Checks a particle's location on levels lev_min and higher. Returns false if the particle does not exi...
Definition AMReX_ParticleContainerI.H:205
ParticleTileType & DefineAndReturnParticleTile(int lev, int grid, int tile)
Define and return the ParticleTile for level "lev", grid "grid" and tile "tile.".
Definition AMReX_ParticleContainer.H:1201
void InitFromBinaryFile(const std::string &file, int extradata)
Definition AMReX_ParticleInit.H:490
std::array< Long, 3 > ByteSpread() const
Definition AMReX_ParticleContainerI.H:639
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:156
This class provides the user with a few print options.
Definition AMReX_Print.H:35
A Box with real dimensions.
Definition AMReX_RealBox.H:28
__host__ __device__ bool contains(const Real *point, Real eps=0.0) const noexcept
Is the specified point contained in the RealBox, including points on the boundary?
Definition AMReX_RealBox.H:109
void setLo(const Real *a_lo) noexcept
Sets lo side.
Definition AMReX_RealBox.H:71
__host__ __device__ const Real * lo() const &noexcept
Returns lo side.
Definition AMReX_RealBox.H:53
__host__ __device__ const Real * hi() const &noexcept
Returns hide side.
Definition AMReX_RealBox.H:58
__host__ __device__ Real length(int dir) const noexcept
Returns length in specified direction.
Definition AMReX_RealBox.H:69
void setHi(const Real *a_hi) noexcept
Sets hi side.
Definition AMReX_RealBox.H:79
__host__ __device__ bool ok() const noexcept
Is the RealBox OK; i.e. does it have non-negative volume?
Definition AMReX_RealBox.H:88
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:50
Long size() const noexcept
Definition AMReX_Vector.H:54
Vector< Setbuf_Char_Type > IO_Buffer
A simple character buffer for setbuf() usage.
Definition AMReX_VisMFBuffer.H:24
static constexpr int IO_Buffer_Size
We try to do I/O with buffers of this size.
Definition AMReX_VisMFBuffer.H:16
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_particle_real ParticleReal
Floating Point Type for Particles.
Definition AMReX_REAL.H:91
amrex_ulong ULong
Unsigned integer type guaranteed to be wider than unsigned int.
Definition AMReX_INT.H:32
amrex_long Long
Definition AMReX_INT.H:30
PinnedVector< T > HostVector
A PODVector that uses pinned host memory. Same as PinnedVector. For a vector class that uses std::all...
Definition AMReX_GpuContainers.H:67
int MyProc() noexcept
Definition AMReX_ParallelDescriptor.H:128
void Max(KeyValuePair< K, V > &vi, int root, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:254
void Bcast(Gpu::DeviceVector< T > &v, int root, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:105
int NProcs() noexcept
Definition AMReX_ParallelDescriptor.H:255
void ReduceLongSum(Long &)
Definition AMReX_ParallelDescriptor.cpp:1240
int IOProcessorNumber() noexcept
The MPI rank number of the I/O Processor (probably rank 0). This rank is usually used to write to std...
Definition AMReX_ParallelDescriptor.H:279
void ReduceLongMax(Long &)
Definition AMReX_ParallelDescriptor.cpp:1241
bool IOProcessor() noexcept
Is this CPU the I/O Processor? To get the rank number, call IOProcessorNumber().
Definition AMReX_ParallelDescriptor.H:289
void InitRandom(ULong cpu_seed, int nprocs, ULong gpu_seed)
Set the seed of the random number generator.
Definition AMReX_Random.cpp:112
Real Random()
Generate a psuedo-random real from uniform distribution.
Definition AMReX_Random.cpp:155
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition AMReX_GpuContainers.H:228
static constexpr HostToDevice hostToDevice
Definition AMReX_GpuContainers.H:105
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
int MyProcSub() noexcept
my sub-rank in current frame
Definition AMReX_ParallelContext.H:76
int NProcsSub() noexcept
number of ranks in current frame
Definition AMReX_ParallelContext.H:74
int IOProcessorNumberSub() noexcept
IO sub-rank in current frame.
Definition AMReX_ParallelContext.H:78
bool IOProcessorSub() noexcept
Am IO processor for current frame?
Definition AMReX_ParallelContext.H:80
void ReduceRealMax(Vector< std::reference_wrapper< Real > > const &)
Definition AMReX_ParallelDescriptor.cpp:1232
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:62
void copyParticles(DstTile &dst, const SrcTile &src) noexcept
Copy particles from src to dst. This version copies all the particles, writing them to the beginning ...
Definition AMReX_ParticleTransformation.H:222
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Return the iterator begin coordinate of box as Dim3.
Definition AMReX_Box.H:2241
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
double second() noexcept
Definition AMReX_Utility.cpp:874
@ x
Definition AMReX_Orientation.H:14
void Error(const std::string &msg)
Print a message to stderr and abort the program.
Definition AMReX.cpp:233
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
const int[]
Definition AMReX_BLProfiler.cpp:1665
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2259
Definition AMReX_Particle.H:259
Definition AMReX_Particle.H:154
A struct used for storing a particle's position in the AMR hierarchy.
Definition AMReX_ParticleContainer.H:93
int m_grid
Definition AMReX_ParticleContainer.H:95
int m_tile
Definition AMReX_ParticleContainer.H:96
int m_lev
Definition AMReX_ParticleContainer.H:94
Definition AMReX_ParticleTile.H:764
void push_back(const ParticleType &p)
Definition AMReX_ParticleTile.H:1064
int numParticles() const
Returns the number of real particles (excluding neighbors).
Definition AMReX_ParticleTile.H:976
void push_back_int(int comp, int v)
Definition AMReX_ParticleTile.H:1168
void define(int a_num_runtime_real, int a_num_runtime_int, std::vector< std::string > *soa_rdata_names=nullptr, std::vector< std::string > *soa_idata_names=nullptr, Arena *a_arena=nullptr)
Definition AMReX_ParticleTile.H:810
void push_back_real(int comp, ParticleReal v)
Definition AMReX_ParticleTile.H:1113
The struct used to store particles.
Definition AMReX_Particle.H:405
__host__ __device__ RealVect pos() const &
Definition AMReX_Particle.H:456
__host__ __device__ ParticleCPUWrapper cpu() &
Definition AMReX_Particle.H:424
__host__ __device__ ParticleIDWrapper id() &
Definition AMReX_Particle.H:427