1#ifndef AMREX_PARTICLEINIT_H
2#define AMREX_PARTICLEINIT_H
3#include <AMReX_Config.H>
38template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
39 template<
class>
class Allocator,
class CellAssignor>
44 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitFromAsciiFile()");
63 else if (NProcs <= 4096)
65 NReaders = std::max(NReaders,128);
68 else if (NProcs <= 8192)
70 NReaders = std::max(NReaders,384);
73 else if (NProcs <= 16384)
75 NReaders = std::max(NReaders,512);
83 if (Nrep !=
nullptr) {
88 Long how_many_read = 0;
93 const int nsoa = std::max(extradata -
NStructReal, 0);
96 if (MyProc < NReaders)
102 ifs.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
104 ifs.open(file.c_str(), std::ios::in);
113 ifs >> cnt >> std::ws;
121 const int Chunk = cnt / NReaders;
123 for (
int i = 0; i < MyProc*Chunk; i++)
125 ifs.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
131 std::string msg(
"ParticleContainer::InitFromAsciiFile(");
133 msg +=
") failed @ 1";
139 if (MyProc == (NReaders - 1))
141 MyCnt += cnt % NReaders;
146 for (
int i = 0; i < MyCnt; i++)
152 for (
int n = 0; n < extradata; n++)
166 std::string msg(
"ParticleContainer::InitFromAsciiFile(");
167 msg += file; msg +=
") failed @ 2";
178 amrex::AllPrint() <<
"BAD PARTICLE ID WOULD BE " << ParticleType::NextID() <<
'\n'
179 <<
"BAD PARTICLE POS "
185 amrex::Abort(
"ParticleContainer::InitFromAsciiFile(): invalid particle");
190 p.id() = ParticleType::NextID();
204 const Real DomSize[AMREX_SPACEDIM] =
208 int rep[AMREX_SPACEDIM];
210#if AMREX_SPACEDIM > 2
211 for (rep[2] = 1; rep[2] <= lNrep[2]; rep[2]++)
214#if AMREX_SPACEDIM > 1
215 for (rep[1] = 1; rep[1] <= lNrep[1]; rep[1]++)
218 for (rep[0] = 1; rep[0] <= lNrep[0]; rep[0]++)
220 if (!(
AMREX_D_TERM( (rep[0] == 1), && (rep[1] == 1), && (rep[2] == 1) ) ) )
223 for (
int d=0; d<AMREX_SPACEDIM; ++d)
229 for (
int n = 0; n < extradata; n++)
233 p_rep.rdata(n) =
p.rdata(n);
237 if (!
Where(p_rep, pld))
240 if (!
Where(p_rep, pld))
243 amrex::AllPrint() <<
"BAD REPLICATED PARTICLE ID WOULD BE " << ParticleType::NextID() <<
"\n";
245 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromAsciiFile(): invalid replicated particle");
249 p_rep.id() = ParticleType::NextID();
250 p_rep.cpu() = MyProc;
264#if AMREX_SPACEDIM > 1
267#if AMREX_SPACEDIM > 2
276 int NRedist_chunk = NReaders / NRedist;
280 for (
int nr = 0; nr < NRedist; nr++)
283 host_particles.reserve(15);
287 host_real_attribs.reserve(15);
292 << nr*NRedist_chunk <<
" to "
293 << (nr+1)*NRedist_chunk-1 <<
'\n';
296 for (
int which = nr*NRedist_chunk; which < (nr+1)*NRedist_chunk; which++)
300 while (!nparticles.
empty())
309 auto& attribs = host_real_attribs[pld.
m_lev][std::make_pair(pld.
m_grid, pld.
m_tile)];
310 attribs.resize(nsoa);
330 for (
int lev = 0; lev < std::ssize(host_particles); ++lev)
332 for (
auto& kv : host_particles[lev])
335 auto grid = kv.first.first;
336 auto tile = kv.first.second;
337 const auto& src_tile = kv.second;
340 auto old_size = dst_tile.GetArrayOfStructs().size();
341 auto new_size = old_size + src_tile.size();
343 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size,
true);
346 dst_tile.GetArrayOfStructs().begin() + old_size);
348 auto const& attribs = host_real_attribs[lev][std::make_pair(grid, tile)];
349 for (
int i = 0; i < std::ssize(attribs); ++i) {
351 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
362 if (NRedist*NRedist_chunk < NReaders) {
364 << NRedist*NRedist_chunk <<
" to "
368 for (
int which = NRedist*NRedist_chunk; which < NReaders; which++)
371 host_particles.reserve(15);
375 host_real_attribs.reserve(15);
380 while (!nparticles.
empty())
387 auto& attribs = host_real_attribs[pld.
m_lev][std::make_pair(pld.
m_grid, pld.
m_tile)];
388 attribs.resize(nsoa);
406 for (
int lev = 0; lev < std::ssize(host_particles); ++lev)
408 for (
auto& kv : host_particles[lev])
410 auto grid = kv.first.first;
411 auto tile = kv.first.second;
412 const auto& src_tile = kv.second;
415 auto old_size = dst_tile.GetArrayOfStructs().size();
416 auto new_size = old_size + src_tile.size();
418 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size,
true);
421 dst_tile.GetArrayOfStructs().begin() + old_size);
423 auto const& attribs = host_real_attribs[lev][std::make_pair(grid, tile)];
424 for (
int i = 0; i < std::ssize(attribs); ++i) {
426 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
440 Long num_particles = how_many;
444 if (
AMREX_D_TERM(lNrep[0] == 1, && lNrep[1] == 1, && lNrep[2] == 1))
446 amrex::Print() <<
"Total number of particles: " << num_particles <<
'\n';
450 Long num_particles_read = how_many_read;
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';
471 amrex::Print() <<
"InitFromAsciiFile() time: " << runtime <<
'\n';
493 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitFromBinaryFile()");
516 amrex::Print() <<
"Reading with " << NReaders <<
" readers\n"
517 <<
"Redistributing after every " << NPartPerRedist <<
" particles for each reader\n";
525 tmp_particles.reserve(15);
544 std::set<int> readers;
550 if (NReaders == NProcs)
555 for (
int i = 0; i < NProcs; i++) {
582 while (std::ssize(readers) < NReaders);
588 for (
auto it = readers.cbegin(), End = readers.cend();
604 readers.insert(rprocs.begin(), rprocs.end());
611 int RealSizeInFile = 0;
613 if (readers.contains(MyProc))
617 ifs.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
619 ifs.open(file.c_str(), std::ios::in|std::ios::binary);
625 ifs.read((
char*)&NP,
sizeof(NP));
626 ifs.read((
char*)&DM,
sizeof(DM));
627 ifs.read((
char*)&NX,
sizeof(NX));
632 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): NP <= 0");
637 if (DM != AMREX_SPACEDIM) {
638 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): DM != AMREX_SPACEDIM");
644 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): NX < 0 || NX > N");
649 if (extradata > NX) {
650 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): extradata > NX");
657 const std::streamoff CURPOS = ifs.tellg();
661 ifs.seekg(0,std::ios::end);
665 const std::streamoff ENDPOS = ifs.tellg();
667 RealSizeInFile =
int((ENDPOS - CURPOS) / (NP*(DM+NX)));
669 AMREX_ASSERT(RealSizeInFile ==
sizeof(
float) || RealSizeInFile ==
sizeof(
double));
673 ifs.seekg(CURPOS, std::ios::beg);
678 for ( ;
id < NReaders;
id++) {
679 if (rprocs[
id] == MyProc) {
686 const std::streamoff NSKIP =
id * (NP/NReaders) * (DM+NX) * RealSizeInFile;
690 ifs.seekg(NSKIP, std::ios::cur);
695 std::string msg(
"ParticleContainer::InitFromBinaryFile(");
697 msg +=
") failed @ 1";
708 Long MyCnt = NP / NReaders;
710 if (MyProc == rprocs[NReaders-1]) {
714 MyCnt += NP % NReaders;
717 Long how_many_redists = NP / (NPartPerRedist*NReaders), how_many_read = 0;
719 if (NP % (NPartPerRedist*NReaders)) { how_many_redists++; }
726 fxtra.resize(extradata);
727 dxtra.resize(extradata);
730 if ((NX-extradata) > 0)
732 fignore.resize(NX-extradata);
733 dignore.resize(NX-extradata);
738 for (
int j = 0; j < how_many_redists; j++)
742 host_particles.reserve(15);
745 if (readers.contains(MyProc))
751 const Long NRead = std::min((MyCnt-how_many_read), NPartPerRedist);
753 for (
Long i = 0; i < NRead; i++)
759 if (RealSizeInFile ==
sizeof(
float))
761 float fpos[AMREX_SPACEDIM];
763 ifs.read((
char*)&fpos[0], AMREX_SPACEDIM*
sizeof(
float));
767 p.pos(2) = fpos[2];);
770 else if (RealSizeInFile ==
sizeof(
double))
772 double dpos[AMREX_SPACEDIM];
774 ifs.read((
char*)&dpos[0], AMREX_SPACEDIM*
sizeof(
double));
786 if (RealSizeInFile ==
sizeof(
float))
788 ifs.read((
char*)fxtra.data(), std::streamsize(extradata*
sizeof(
float)));
790 for (
int ii = 0; ii < extradata; ii++) {
794 else if (RealSizeInFile ==
sizeof(
double))
796 ifs.read((
char*)dxtra.data(), std::streamsize(extradata*
sizeof(
double)));
798 for (
int ii = 0; ii < extradata; ii++) {
806 if ((NX-extradata) > 0)
808 if (RealSizeInFile ==
sizeof(
float))
810 ifs.read((
char*)fignore.data(), std::streamsize((NX-extradata)*
sizeof(
float)));
812 else if (RealSizeInFile ==
sizeof(
double))
814 ifs.read((
char*)dignore.data(), std::streamsize((NX-extradata)*
sizeof(
double)));
820 std::string msg(
"ParticleContainer::InitFromBinaryFile(");
822 msg +=
") failed @ 2";
833 amrex::AllPrint() <<
"BAD PARTICLE ID WOULD BE " << ParticleType::NextID() <<
'\n'
834 <<
"BAD PARTICLE POS "
840 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitFromBinaryFile(): invalid particle");
844 p.id() = ParticleType::NextID();
850 how_many_read += NRead;
853 for (
int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
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;
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);
866 dst_tile.GetArrayOfStructs().begin() + old_size);
878 for (
int lev = 0; lev < std::ssize(m_particles); lev++)
880 auto& pmap = m_particles[lev];
881 auto& tmp_pmap = tmp_particles[lev];
883 for (
auto& kv : pmap) {
884 auto& aos = kv.second.GetArrayOfStructs()();
885 auto& tmp_aos = tmp_pmap[kv.first].GetArrayOfStructs()();
887 tmp_aos.insert(tmp_aos.end(), aos.begin(), aos.end());
897 tmp_particles.swap(m_particles);
902 for (
int lev = 0; lev < std::ssize(m_particles); ++lev) {
903 for (
auto& kv : m_particles[lev]) {
905 particle_detail::resizeAndZeroNewSoA(ptile, ptile.numParticles(),
true);
913 Long num_particles_read = how_many_read;
917 amrex::Print() <<
"\nTotal number of particles: " << num_particles_read <<
'\n';
930 amrex::Print() <<
"InitFromBinaryFile() time: " << runtime <<
'\n';
942template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
943 template<
class>
class Allocator,
class CellAssignor>
949 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitFromBinaryMetaFile()");
952 std::ifstream ifs(metafile.c_str(), std::ios::in);
958 std::getline(ifs,file);
960 if (!ifs.good()) {
break; }
963 amrex::Print() <<
"InitFromBinaryMetaFile: processing file: " << file <<
'\n';
977 amrex::Print() <<
"InitFromBinaryMetaFile() time: " << runtime <<
'\n';
981template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
982 template<
class>
class Allocator,
class CellAssignor>
991 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitRandom()");
1009 if (!containing_bx.
ok()) { containing_bx = geom.
ProbDomain(); }
1018 const Real* xlo = containing_bx.
lo();
1019 const Real* xhi = containing_bx.
hi();
1025 if(icount*AMREX_SPACEDIM >= std::numeric_limits<int>::max())
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 " +
1050 for (
Long j = 0; j < icount; j++)
1052 for (
int i = 0; i < AMREX_SPACEDIM; i++)
1057 x = geom.
ProbLo(i) + (r * len[i]);
1072 host_particles.reserve(15);
1076 host_real_attribs.reserve(15);
1080 host_int_attribs.reserve(15);
1084 host_idcpu.reserve(15);
1087 for (
Long j = 0; j < icount; j++)
1091 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1092 ptest.
pos(i) = pos[j*AMREX_SPACEDIM + i];
1095 if (!
Where(ptest, pld)) {
1096 amrex::Abort(
"ParticleContainer::InitRandom(): invalid particle");
1104 if (who == MyProc) {
1106 if constexpr(!ParticleType::is_soa_particle)
1109 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1110 p.pos(i) = pos[j*AMREX_SPACEDIM + i];
1114 p.id() = ParticleType::NextID();
1118 p.idata(i) =
pdata.int_struct_data[i];
1126 host_particles[pld.
m_lev][ind].push_back(
p);
1135 host_int_attribs[pld.
m_lev][ind][i].push_back(
pdata.int_array_data[i]);
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]);
1142 host_idcpu[pld.
m_lev][ind].push_back(0);
1146 host_particles[pld.
m_lev][ind];
1149 for (
int i = AMREX_SPACEDIM; i <
NArrayReal; i++) {
1155 host_int_attribs[pld.
m_lev][ind][i].push_back(
pdata.int_array_data[i]);
1161 for (
int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
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;
1169 auto old_size = dst_tile.size();
1170 auto new_size = old_size;
1171 if constexpr(!ParticleType::is_soa_particle)
1173 new_size += src_tile.size();
1175 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1177 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size);
1179 if constexpr(!ParticleType::is_soa_particle)
1182 dst_tile.GetArrayOfStructs().begin() + old_size);
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);
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);
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);
1212 Long M = icount / NProcs;
1215 M += (icount % NProcs);
1221 host_particles.reserve(15);
1225 host_real_attribs.reserve(15);
1229 host_int_attribs.reserve(15);
1233 host_idcpu.reserve(15);
1236 for (
Long icnt = 0; icnt < M; icnt++) {
1238 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1241 x = geom.
ProbLo(i) + (r * len[i]);
1250 ptest.
id() = ParticleType::NextID();
1254 if (!
Where(ptest, pld))
1256 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitRandom(): invalid particle");
1261 if constexpr(!ParticleType::is_soa_particle)
1264 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1265 p.pos(i) = ptest.
pos(i);;
1268 p.id() = ptest.
id();
1269 p.cpu() = ptest.
cpu();
1276 p.idata(i) =
pdata.int_struct_data[i];
1280 host_particles[pld.
m_lev][ind].push_back(
p);
1289 host_int_attribs[pld.
m_lev][ind][i].push_back(
pdata.int_array_data[i]);
1292 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1293 host_real_attribs[pld.
m_lev][ind][i].push_back(ptest.
pos(i));
1296 host_idcpu[pld.
m_lev][ind].push_back(0);
1300 host_particles[pld.
m_lev][ind];
1303 for (
int i = AMREX_SPACEDIM; i <
NArrayReal; i++) {
1309 host_int_attribs[pld.
m_lev][ind][i].push_back(
pdata.int_array_data[i]);
1314 for (
int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
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;
1322 auto old_size = dst_tile.size();
1323 auto new_size = old_size;
1324 if constexpr(!ParticleType::is_soa_particle)
1326 new_size += src_tile.size();
1328 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1330 particle_detail::resizeAndZeroNewSoA(dst_tile, new_size);
1332 if constexpr(!ParticleType::is_soa_particle)
1335 dst_tile.GetArrayOfStructs().begin() + old_size);
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);
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);
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);
1370 amrex::Print() <<
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitRandom() time: " << stoptime <<
'\n';
1376template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1377 template<
class>
class Allocator,
class CellAssignor>
1384 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitRandomPerBox()");
1401 std::mt19937 mt(iseed);
1402 std::uniform_real_distribution<double> dist(0.0, 1.0);
1404 m_particles.resize(
m_gdb->finestLevel()+1);
1406 for (
int lev = 0; lev < std::ssize(m_particles); lev++)
1414 Box grid =
m_gdb->ParticleBoxArray(0)[mfi.index()];
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++)
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));
1427 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1437 p.id() = ParticleType::NextID();
1441 p.idata(i) =
pdata.int_struct_data[i];
1446 amrex::Abort(
"ParticleContainer::InitRandomPerBox(): invalid particle");
1461 ptile.push_back_int(i,
pdata.int_array_data[i]);
1468 for (
auto& pmap : m_particles) {
1469 for (
auto& kv : pmap) {
1470 particle_detail::resizeAndZeroNewSoA(kv.second, kv.second.numParticles());
1480 amrex::Print() <<
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitRandomPerBox() time: " << stoptime <<
'\n';
1484template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1485 template<
class>
class Allocator,
class CellAssignor>
1492 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitOnePerCell()");
1498 AMREX_ASSERT(x_off >= 0. && y_off >= 0. && z_off >= 0.);
1499 AMREX_ASSERT(x_off <= 1. && y_off <= 1. && z_off <= 1.);
1512 auto ind = std::make_pair(mfi.index(), mfi.LocalTileIndex());
1516 &m_soa_rdata_names, &m_soa_idata_names);
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]););
1524 for (
int d = 0; d < AMREX_SPACEDIM; ++d) {
1533 p.id() = ParticleType::NextID();
1537 p.idata(i) =
pdata.int_struct_data[i];
1555 particle_detail::resizeAndZeroNewSoA(ptile_tmp, ptile_tmp.
numParticles());
1570 amrex::Print() <<
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitOnePerCell() time: " << stoptime <<
'\n';
1574template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1575 template<
class>
class Allocator,
class CellAssignor>
1580 BL_PROFILE(
"ParticleContainer<NSR, NSI, NAR, NAI>::InitNRandomPerCell()");
1593 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
1608 host_particles.reserve(15);
1612 host_real_attribs.reserve(15);
1616 host_int_attribs.reserve(15);
1622 for (
int n = 0; n < n_per_cell; n++)
1625 for (
int i = 0; i < AMREX_SPACEDIM; i++) {
1626 constexpr int max_iter = 10;
1628 while (iter < max_iter) {
1631 if (
p.pos(i) < grid_box.
hi(i)) {
break; }
1642 p.id() = ParticleType::NextID();
1646 p.idata(i) =
pdata.int_struct_data[i];
1651 amrex::Abort(
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitNRandomPerCell(): invalid particle");
1657 host_particles[pld.
m_lev][ind].push_back(
p);
1666 host_int_attribs[pld.
m_lev][ind][i].push_back(
pdata.int_array_data[i]);
1671 for (
int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
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;
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);
1684 dst_tile.GetArrayOfStructs().begin() + old_size);
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);
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);
1712 amrex::Print() <<
"ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt>::InitNRandomPerCell() time: " << stoptime <<
'\n';
#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