1#ifndef AMREX_PARTICLEIO_H
2#define AMREX_PARTICLEIO_H
3#include <AMReX_Config.H>
9template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
10 template<
class>
class Allocator,
class CellAssignor>
12ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
13::WriteParticleRealData (
void* data,
size_t size, std::ostream& os)
const
15 if (
sizeof(
typename ParticleType::RealType) == 4) {
18 else if (
sizeof(
typename ParticleType::RealType) == 8) {
23template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
24 template<
class>
class Allocator,
class CellAssignor>
29 if (
sizeof(
typename ParticleType::RealType) == 4) {
30 readFloatData((
float*) data, size, is, ParticleRealDescriptor);
32 else if (
sizeof(
typename ParticleType::RealType) == 8) {
45template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
46 template<
class>
class Allocator,
class CellAssignor>
48ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
49::Checkpoint (
const std::string& dir,
50 const std::string& name,
bool ,
57 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
58 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
60 write_real_comp.push_back(1);
61 if (real_comp_names.empty())
63 tmp_real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
67 tmp_real_comp_names.push_back(real_comp_names[i-first_rcomp]);
73 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
75 write_int_comp.push_back(1);
76 if (int_comp_names.empty())
78 tmp_int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
82 tmp_int_comp_names.push_back(int_comp_names[i]);
86 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
87 tmp_real_comp_names, tmp_int_comp_names,
91template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
92 template<
class>
class Allocator,
class CellAssignor>
101 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
102 real_comp_names, int_comp_names,
106template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
107 template<
class>
class Allocator,
class CellAssignor>
115 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
116 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
118 write_real_comp.push_back(1);
119 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
124 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
126 write_int_comp.push_back(1);
127 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
130 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
131 real_comp_names, int_comp_names,
135template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
136 template<
class>
class Allocator,
class CellAssignor>
143 if constexpr(ParticleType::is_soa_particle) {
151 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
152 for (
int i = 0; i < nrc; ++i) {
153 write_real_comp.push_back(1);
157 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
158 write_int_comp.push_back(1);
161 WriteBinaryParticleData(dir, name,
162 write_real_comp, write_int_comp,
163 real_comp_names, int_comp_names,
167template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
168 template<
class>
class Allocator,
class CellAssignor>
174 if constexpr(ParticleType::is_soa_particle) {
181 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
182 for (
int i = 0; i < nrc; ++i) {
183 write_real_comp.push_back(1);
187 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
188 write_int_comp.push_back(1);
192 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
194 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
197 WriteBinaryParticleData(dir, name,
198 write_real_comp, write_int_comp,
199 real_comp_names, int_comp_names,
203template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
204 template<
class>
class Allocator,
class CellAssignor>
208 const std::string& name,
213 if constexpr(ParticleType::is_soa_particle) {
221 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
222 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
224 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
228 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
230 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
233 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
234 real_comp_names, int_comp_names,
238template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
239 template<
class>
class Allocator,
class CellAssignor>
242WritePlotFile (
const std::string& dir,
const std::string& name,
248 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
250 WriteBinaryParticleData(dir, name,
251 write_real_comp, write_int_comp,
252 real_comp_names, int_comp_names,
256template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
257 template<
class>
class Allocator,
class CellAssignor>
258template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
266 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
267 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
269 write_real_comp.push_back(1);
270 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
275 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
277 write_int_comp.push_back(1);
278 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
281 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
282 real_comp_names, int_comp_names,
286template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
287 template<
class>
class Allocator,
class CellAssignor>
295 if constexpr(ParticleType::is_soa_particle) {
303 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
304 for (
int i = 0; i < nrc; ++i) {
305 write_real_comp.push_back(1);
309 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
310 write_int_comp.push_back(1);
313 WriteBinaryParticleData(dir, name,
314 write_real_comp, write_int_comp,
315 real_comp_names, int_comp_names,
319template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
320 template<
class>
class Allocator,
class CellAssignor>
321template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
327 if constexpr(ParticleType::is_soa_particle) {
334 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
335 for (
int i = 0; i < nrc; ++i) {
336 write_real_comp.push_back(1);
340 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
341 write_int_comp.push_back(1);
345 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
347 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
350 WriteBinaryParticleData(dir, name,
351 write_real_comp, write_int_comp,
352 real_comp_names, int_comp_names,
356template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
357 template<
class>
class Allocator,
class CellAssignor>
362 const std::string& name,
366 if constexpr(ParticleType::is_soa_particle) {
374 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
375 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
377 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
381 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
383 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
386 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
387 real_comp_names, int_comp_names,
391template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
392 template<
class>
class Allocator,
class CellAssignor>
396WritePlotFile (
const std::string& dir,
const std::string& name,
403 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
405 WriteBinaryParticleData(dir, name,
406 write_real_comp, write_int_comp,
407 real_comp_names, int_comp_names,
411template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
412 template<
class>
class Allocator,
class CellAssignor>
421 F&& f,
bool is_checkpoint)
const
425 write_real_comp, write_int_comp,
426 real_comp_names, int_comp_names, is_checkpoint);
430 write_real_comp, write_int_comp,
431 real_comp_names, int_comp_names,
432 std::forward<F>(f), is_checkpoint);
436template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
437 template<
class>
class Allocator,
class CellAssignor>
446 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
450 Long maxnextid = ParticleType::NextID();
452 for (
int lev = 0; lev < m_particles.size(); lev++) {
453 const auto& pmap = m_particles[lev];
454 for (
const auto& kv : pmap) {
455 const auto& aos = kv.second.GetArrayOfStructs();
456 for (
int k = 0; k < aos.numParticles(); ++k) {
469 ParticleType::NextID(maxnextid);
472 nparticlesPrePost = nparticles;
473 maxnextidPrePost =
int(maxnextid);
475 nParticlesAtLevelPrePost.clear();
476 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
477 for(
int lev(0); lev <= finestLevel(); ++lev) {
478 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
481 whichPrePost.clear();
482 whichPrePost.resize(finestLevel() + 1);
483 countPrePost.clear();
484 countPrePost.resize(finestLevel() + 1);
485 wherePrePost.clear();
486 wherePrePost.resize(finestLevel() + 1);
488 filePrefixPrePost.clear();
489 filePrefixPrePost.resize(finestLevel() + 1);
493template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
494 template<
class>
class Allocator,
class CellAssignor>
503 BL_PROFILE(
"ParticleContainer::CheckpointPost()");
506 std::ofstream HdrFile;
507 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
509 for(
int lev(0); lev <= finestLevel(); ++lev) {
516 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
517 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
520 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
521 if(gotsome && doUnlink) {
526 for(
int i(0), N = countPrePost[lev].size(); i < N; ++i) {
527 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
530 for(
int i(0), N =
int(cnt.
size()); i < N; ++i) {
543 if( ! HdrFile.good()) {
544 amrex::Abort(
"ParticleContainer::CheckpointPost(): problem writing HdrFile");
549template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
550 template<
class>
class Allocator,
class CellAssignor>
559template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
560 template<
class>
class Allocator,
class CellAssignor>
569template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
570 template<
class>
class Allocator,
class CellAssignor>
577 const Vector<std::map<std::pair<int, int>,
IntVector>>& particle_io_flags,
578 bool is_checkpoint)
const
580 BL_PROFILE(
"ParticleContainer::WriteParticles()");
583 std::map<int, Vector<int> > tile_map;
585 for (
const auto& kv : m_particles[lev])
587 const int grid = kv.first.first;
588 const int tile = kv.first.second;
589 tile_map[grid].push_back(tile);
590 const auto& pflags = particle_io_flags[lev].at(kv.first);
598 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
602 const int grid = mfi.index();
607 if (count[grid] == 0) {
continue; }
612 write_real_comp, write_int_comp,
613 particle_io_flags, tile_map[grid], count[grid], is_checkpoint);
618 WriteParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ofs);
624template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
625 template<
class>
class Allocator,
class CellAssignor>
628::Restart (
const std::string& dir,
const std::string& file,
bool )
633template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
634 template<
class>
class Allocator,
class CellAssignor>
637::Restart (
const std::string& dir,
const std::string& file)
645 int DATA_Digits_Read(5);
647 pp.
query(
"datadigits_read",DATA_Digits_Read);
649 std::string fullname = dir;
650 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
654 std::string HdrFileName = fullname;
655 if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] !=
'/') {
658 HdrFileName +=
"Header";
662 std::string fileCharPtrString(fileCharPtr.
dataPtr());
663 std::istringstream HdrFile(fileCharPtrString, std::istringstream::in);
677 bool convert_ids =
false;
678 if (version.find(
"Version_Two_Dot_One") != std::string::npos) {
681 if (version.find(
"Version_One_Dot_Zero") != std::string::npos) {
684 else if (version.find(
"Version_One_Dot_One") != std::string::npos ||
685 version.find(
"Version_Two_Dot_Zero") != std::string::npos ||
686 version.find(
"Version_Two_Dot_One") != std::string::npos) {
687 if (version.find(
"_single") != std::string::npos) {
690 else if (version.find(
"_double") != std::string::npos) {
694 std::string msg(
"ParticleContainer::Restart(): bad version string: ");
700 std::string msg(
"ParticleContainer::Restart(): unknown version string: ");
707 if (dm != AMREX_SPACEDIM) {
708 amrex::Abort(
"ParticleContainer::Restart(): dm != AMREX_SPACEDIM");
713 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
715 amrex::Abort(
"ParticleContainer::Restart(): nr not the expected value");
718 std::string comp_name;
719 for (
int i = 0; i < nr; ++i) {
720 HdrFile >> comp_name;
725 if (ni != NStructInt + NumIntComps()) {
729 for (
int i = 0; i < ni; ++i) {
730 HdrFile >> comp_name;
734 HdrFile >> checkpoint;
737 HdrFile >> nparticles;
741 HdrFile >> maxnextid;
743 ParticleType::NextID(maxnextid);
745 int finest_level_in_file;
746 HdrFile >> finest_level_in_file;
753 bool dual_grid =
false;
755 bool have_pheaders =
false;
756 for (
int lev = 0; lev <= finest_level_in_file; lev++)
758 std::string phdr_name = fullname;
759 phdr_name +=
"/Level_";
761 phdr_name +=
"/Particle_H";
764 have_pheaders =
true;
771 for (
int lev = 0; lev <= finestLevel(); lev++)
773 old_dms[lev] = ParticleDistributionMap(lev);
774 old_bas[lev] = ParticleBoxArray(lev);
775 std::string phdr_name = fullname;
776 phdr_name +=
"/Level_";
778 phdr_name +=
"/Particle_H";
784 std::string phdr_string(phdr_chars.
dataPtr());
785 std::istringstream phdr_file(phdr_string, std::istringstream::in);
787 particle_box_arrays[lev].readFrom(phdr_file);
788 if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) { dual_grid =
true; }
796 for (
int lev = 0; lev <= finestLevel(); lev++) {
798 if (particle_box_arrays[lev].empty()) {
799 particle_box_arrays[lev] =
BoxArray(Geom(lev).Domain());
801 SetParticleBoxArray(lev, particle_box_arrays[lev]);
803 SetParticleDistributionMap(lev, pdm);
808 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
809 HdrFile >> ngrids[lev];
815 if (finest_level_in_file > finestLevel()) {
816 m_particles.resize(finest_level_in_file+1);
819 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
823 for (
int i = 0; i < ngrids[lev]; i++) {
824 HdrFile >> which[i] >> count[i] >> where[i];
828 if (lev <= finestLevel()) {
830 grids_to_read.push_back(mfi.index());
838 const int NReaders = MaxReaders();
839 if (rank >= NReaders) {
return; }
841 const int Navg = ngrids[lev] / NReaders;
842 const int Nleft = ngrids[lev] - Navg * NReaders;
846 lo = rank*(Navg + 1);
850 lo = rank * Navg + Nleft;
854 for (
int i = lo; i < hi; ++i) {
855 grids_to_read.push_back(i);
859 for(
int grid : grids_to_read) {
860 if (count[grid] <= 0) {
continue; }
863 std::string
name = fullname;
865 if (!
name.empty() && name[
name.size()-1] !=
'/') {
872 name += DataPrefix();
875 std::ifstream ParticleFile;
877 ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary);
879 if (!ParticleFile.good()) {
883 ParticleFile.seekg(where[grid], std::ios::beg);
888 if (how ==
"single") {
889 if constexpr (std::is_same_v<ParticleReal, float>) {
890 ReadParticles<float>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
892 amrex::Error(
"File contains single-precision data, while AMReX is compiled with ParticleReal==double");
895 else if (how ==
"double") {
896 if constexpr (std::is_same_v<ParticleReal, double>) {
897 ReadParticles<double>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
899 amrex::Error(
"File contains double-precision data, while AMReX is compiled with ParticleReal==float");
903 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
908 ParticleFile.close();
910 if (!ParticleFile.good()) {
911 amrex::Abort(
"ParticleContainer::Restart(): problem reading particles");
917 for (
int lev = 0; lev <= finestLevel(); lev++) {
918 SetParticleBoxArray(lev, old_bas[lev]);
919 SetParticleDistributionMap(lev, old_dms[lev]);
930 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
935template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
937template <
class RTYPE>
941 int finest_level_in_file,
bool convert_ids)
943 BL_PROFILE(
"ParticleContainer::ReadParticles()");
950 const int iChunkSize = 2 + NStructInt + NumIntComps();
955 const int rChunkSize = ParticleType::is_soa_particle ? NStructReal + NumRealComps() : AMREX_SPACEDIM + NStructReal + NumRealComps();
957 ReadParticleRealData(rstuff.dataPtr(), rstuff.size(), ifs);
960 int* iptr = istuff.dataPtr();
961 RTYPE* rptr = rstuff.dataPtr();
967 host_particles.reserve(15);
968 host_particles.resize(finest_level_in_file+1);
971 std::vector<Gpu::HostVector<RTYPE> > > > host_real_attribs;
972 host_real_attribs.reserve(15);
973 host_real_attribs.resize(finest_level_in_file+1);
976 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
977 host_int_attribs.reserve(15);
978 host_int_attribs.resize(finest_level_in_file+1);
981 host_idcpu.reserve(15);
982 host_idcpu.resize(finestLevel()+1);
984 for (
int i = 0; i < cnt; i++) {
989 std::uint32_t xu, yu;
992 std::memcpy(&xu, &xi,
sizeof(xi));
993 std::memcpy(&yu, &yi,
sizeof(yi));
994 ptemp.
m_idcpu = ((std::uint64_t)xu) << 32 | yu;
996 ptemp.
id() = iptr[0];
997 ptemp.
cpu() = iptr[1];
1001 for (
int j = 0; j < NStructInt; j++)
1003 ptemp.
idata(j) = *iptr;
1010 ptemp.
pos(1) = ParticleReal(rptr[1]);,
1011 ptemp.
pos(2) = ParticleReal(rptr[2]););
1013 rptr += AMREX_SPACEDIM;
1015 for (
int j = 0; j < NStructReal; j++)
1017 ptemp.
rdata(j) = ParticleReal(*rptr);
1021 locateParticle(ptemp, pld, 0, finestLevel(), 0);
1023 std::pair<int, int> ind(grd, pld.
m_tile);
1025 host_real_attribs[lev][ind].resize(NumRealComps());
1026 host_int_attribs[lev][ind].resize(NumIntComps());
1029 if constexpr(!ParticleType::is_soa_particle)
1031 host_particles[lev][ind].push_back(ptemp);
1034 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
1035 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1040 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1041 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1045 host_particles[lev][ind];
1047 for (
int j = 0; j < AMREX_SPACEDIM; j++) {
1048 host_real_attribs[pld.
m_lev][ind][j].push_back(ptemp.
pos(j));
1055 for (
int icomp = AMREX_SPACEDIM; icomp < NumRealComps(); icomp++) {
1056 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1061 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1062 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1068 for (
int host_lev = 0; host_lev < static_cast<int>(host_particles.
size()); ++host_lev)
1070 for (
auto& kv : host_particles[host_lev]) {
1071 auto grid = kv.first.first;
1072 auto tile = kv.first.second;
1073 const auto& src_tile = kv.second;
1075 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1076 auto old_size = dst_tile.size();
1077 auto new_size = old_size;
1078 if constexpr(!ParticleType::is_soa_particle)
1080 new_size += src_tile.size();
1083 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1085 dst_tile.resize(new_size);
1087 if constexpr(!ParticleType::is_soa_particle)
1090 dst_tile.GetArrayOfStructs().begin() + old_size);
1093 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
1094 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
1095 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1098 for (
int i = 0; i < NumRealComps(); ++i) {
1100 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1101 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1102 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1105 for (
int i = 0; i < NumIntComps(); ++i) {
1107 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1108 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1109 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1117template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1118 template<
class>
class Allocator,
class CellAssignor>
1120ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1121::WriteAsciiFile (
const std::string& filename)
1123 BL_PROFILE(
"ParticleContainer::WriteAsciiFile()");
1130 Long nparticles = 0;
1132 for (
int lev = 0; lev < m_particles.size(); lev++) {
1133 auto& pmap = m_particles[lev];
1134 for (
const auto& kv : pmap) {
1135 const auto& aos = kv.second.GetArrayOfStructs();
1136 auto np = aos.numParticles();
1139 for (
int k = 0; k < np; ++k) {
1163 File.open(filename.c_str(), std::ios::out|std::ios::trunc);
1169 File << nparticles <<
'\n';
1170 File << NStructReal <<
'\n';
1171 File << NStructInt <<
'\n';
1172 File << NumRealComps() <<
'\n';
1173 File << NumIntComps() <<
'\n';
1180 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1199 File.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
1201 File.open(filename.c_str(), std::ios::out|std::ios::app);
1209 for (
int lev = 0; lev < m_particles.size(); lev++) {
1210 auto& pmap = m_particles[lev];
1211 for (
const auto& kv : pmap) {
1214 pinned_ptile.define(NumRuntimeRealComps(), NumRuntimeIntComps());
1215 pinned_ptile.resize(kv.second.numParticles());
1217 const auto& host_aos = pinned_ptile.GetArrayOfStructs();
1218 const auto& host_soa = pinned_ptile.GetStructOfArrays();
1220 auto np = host_aos.numParticles();
1221 for (
int index = 0; index < np; ++index) {
1227 << it->pos(1) <<
' ',
1228 << it->pos(2) <<
' ');
1230 for (
int i = 0; i < NStructReal; i++) {
1231 File << it->rdata(i) <<
' ';
1234 File << it->id() <<
' ';
1235 File << it->cpu() <<
' ';
1237 for (
int i = 0; i < NStructInt; i++) {
1238 File << it->idata(i) <<
' ';
1242 for (
int i = 0; i < NumRealComps(); i++) {
1243 File << host_soa.GetRealData(i)[index] <<
' ';
1246 for (
int i = 0; i < NumIntComps(); i++) {
1247 File << host_soa.GetIntData(i)[index] <<
' ';
1261 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1275 amrex::Print() <<
"ParticleContainer::WriteAsciiFile() time: " << stoptime <<
'\n';
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
amrex::ParmParse pp
Input file parser instance for the given namespace.
Definition AMReX_HypreIJIface.cpp:15
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:129
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:550
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:41
static const IntDescriptor & NativeIntDescriptor()
Returns a constant reference to an IntDescriptor describing the native "int" under which AMReX was co...
Definition AMReX_FPC.cpp:76
Definition AMReX_MFIter.H:57
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:141
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:38
const std::string & FileName() const
Definition AMReX_NFiles.H:160
Definition AMReX_PODVector.H:262
iterator begin() noexcept
Definition AMReX_PODVector.H:617
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:320
int query(const char *name, bool &ref, int ival=FIRST) const
Same as querykth() but searches for the last occurrence of name.
Definition AMReX_ParmParse.cpp:1311
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:146
typename SoA::IntVector IntVector
Definition AMReX_ParticleContainer.H:192
void WritePlotFile(const std::string &dir, const std::string &name) const
This version of WritePlotFile writes all components and assigns component names.
Definition AMReX_ParticleIO.H:110
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:148
Definition AMReX_GpuAllocators.H:126
This class provides the user with a few print options.
Definition AMReX_Print.H:35
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:27
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:46
Long size() const noexcept
Definition AMReX_Vector.H:50
@ IO_Buffer_Size
Definition AMReX_VisMFBuffer.H:16
static Long FileOffset(std::ostream &os)
The file offset of the passed ostream.
Definition AMReX_VisMF.cpp:575
bool UseAsyncOut()
Definition AMReX_AsyncOut.cpp:70
bool Remove(std::string const &filename)
Definition AMReX_FileSystem.cpp:190
void copy(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:121
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:233
static constexpr DeviceToHost deviceToHost
Definition AMReX_GpuContainers.H:99
static constexpr HostToDevice hostToDevice
Definition AMReX_GpuContainers.H:98
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:237
std::string const & name()
Definition AMReX_Machine.cpp:46
void ReduceIntSum(int &)
Integer sum reduction.
Definition AMReX_ParallelDescriptor.cpp:1255
int MyProc() noexcept
return the rank number local to the current Parallel Context
Definition AMReX_ParallelDescriptor.H:125
void ReadAndBcastFile(const std::string &filename, Vector< char > &charBuf, bool bExitOnError, const MPI_Comm &comm)
Definition AMReX_ParallelDescriptor.cpp:1462
void ReduceLongMax(Long &)
Long max reduction.
Definition AMReX_ParallelDescriptor.cpp:1227
void ReduceLongSum(Long &)
Long sum reduction.
Definition AMReX_ParallelDescriptor.cpp:1226
int NProcs() noexcept
return the number of MPI ranks local to the current Parallel Context
Definition AMReX_ParallelDescriptor.H:243
int IOProcessorNumber() noexcept
Definition AMReX_ParallelDescriptor.H:266
void Barrier(const std::string &)
Definition AMReX_ParallelDescriptor.cpp:1205
bool IOProcessor() noexcept
Is this CPU the I/O Processor? To get the rank number, call IOProcessorNumber()
Definition AMReX_ParallelDescriptor.H:275
void ReduceRealMax(Vector< std::reference_wrapper< Real > > const &)
Definition AMReX_ParallelDescriptor.cpp:1218
std::enable_if_t< RunOnGpu< typename PC::template AllocatorType< int > >::value, void > packIOData(Vector< int > &idata, Vector< ParticleReal > &rdata, const PC &pc, int lev, int grid, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::map< std::pair< int, int >, typename PC::IntVector > > &particle_io_flags, const Vector< int > &tiles, int np, bool is_checkpoint)
Definition AMReX_WriteBinaryParticleData.H:173
std::enable_if_t< RunOnGpu< typename Container< int, Allocator >::allocator_type >::value, amrex::Long > countFlags(const Vector< std::map< std::pair< int, int >, Container< int, Allocator > > > &particle_io_flags, const PC &pc)
Definition AMReX_WriteBinaryParticleData.H:78
Definition AMReX_Amr.cpp:49
void writeIntData(const From *data, std::size_t size, std::ostream &os, const amrex::IntDescriptor &id)
Definition AMReX_IntConv.H:23
void WriteBinaryParticleDataSync(PC const &pc, const std::string &dir, const std::string &name, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::string > &real_comp_names, const Vector< std::string > &int_comp_names, F const &f, bool is_checkpoint)
Definition AMReX_WriteBinaryParticleData.H:394
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:131
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:158
void readFloatData(float *data, std::size_t size, std::istream &is, const RealDescriptor &rd)
Definition AMReX_VectorIO.cpp:120
void writeFloatData(const float *data, std::size_t size, std::ostream &os, const RealDescriptor &rd=FPC::Native32RealDescriptor())
Definition AMReX_VectorIO.cpp:114
bool FileExists(const std::string &filename)
Check if a file already exists. Return true if the filename is an existing file, directory,...
Definition AMReX_Utility.cpp:139
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1890
std::string Concatenate(const std::string &root, int num, int mindigits)
Returns rootNNNN where NNNN == num.
Definition AMReX_String.cpp:34
double second() noexcept
Definition AMReX_Utility.cpp:922
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:127
void writeDoubleData(const double *data, std::size_t size, std::ostream &os, const RealDescriptor &rd=FPC::Native64RealDescriptor())
Definition AMReX_VectorIO.cpp:126
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:224
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1881
void readDoubleData(double *data, std::size_t size, std::istream &is, const RealDescriptor &rd)
Definition AMReX_VectorIO.cpp:132
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
const int[]
Definition AMReX_BLProfiler.cpp:1664
void WriteBinaryParticleDataAsync(PC const &pc, const std::string &dir, const std::string &name, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::string > &real_comp_names, const Vector< std::string > &int_comp_names, bool is_checkpoint)
Definition AMReX_WriteBinaryParticleData.H:686
void readIntData(To *data, std::size_t size, std::istream &is, const amrex::IntDescriptor &id)
Definition AMReX_IntConv.H:36
Definition AMReX_ParticleUtil.H:432
Definition AMReX_ParticleIO.H:37
AMREX_GPU_HOST_DEVICE int operator()(const P &p) const
Definition AMReX_ParticleIO.H:40
FabArray memory allocation information.
Definition AMReX_FabArray.H:66
MFInfo & SetAlloc(bool a) noexcept
Definition AMReX_FabArray.H:73
uint64_t m_idcpu
Definition AMReX_Particle.H:252
A struct used for storing a particle's position in the AMR hierarchy.
Definition AMReX_ParticleContainer.H:92
int m_tile
Definition AMReX_ParticleContainer.H:95
int m_lev
Definition AMReX_ParticleContainer.H:93
Definition AMReX_ParticleTile.H:702
The struct used to store particles.
Definition AMReX_Particle.H:295
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleIDWrapper id() &
Definition AMReX_Particle.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect pos() const &
Definition AMReX_Particle.H:338
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType & rdata(int index) &
Definition AMReX_Particle.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleCPUWrapper cpu() &
Definition AMReX_Particle.H:312
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int & idata(int index) &
Definition AMReX_Particle.H:427