1#ifndef AMREX_PARTICLEIO_H
2#define AMREX_PARTICLEIO_H
3#include <AMReX_Config.H>
12template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
13 template<
class>
class Allocator,
class CellAssignor>
15ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
16::WriteParticleRealData (
void* data,
size_t size, std::ostream& os)
const
18 if (
sizeof(
typename ParticleType::RealType) == 4) {
21 else if (
sizeof(
typename ParticleType::RealType) == 8) {
26template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
27 template<
class>
class Allocator,
class CellAssignor>
32 if (
sizeof(
typename ParticleType::RealType) == 4) {
33 readFloatData((
float*) data, size, is, ParticleRealDescriptor);
35 else if (
sizeof(
typename ParticleType::RealType) == 8) {
44 return p.id().is_valid();
49template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
50 template<
class>
class Allocator,
class CellAssignor>
52ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
53::Checkpoint (
const std::string& dir,
54 const std::string& name,
bool ,
61 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
62 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
64 write_real_comp.push_back(1);
65 if (real_comp_names.empty())
67 tmp_real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
71 tmp_real_comp_names.push_back(real_comp_names[i-first_rcomp]);
77 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
79 write_int_comp.push_back(1);
80 if (int_comp_names.empty())
82 tmp_int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
86 tmp_int_comp_names.push_back(int_comp_names[i]);
90 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
91 tmp_real_comp_names, tmp_int_comp_names,
95template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
96 template<
class>
class Allocator,
class CellAssignor>
105 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
106 real_comp_names, int_comp_names,
111template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
112 template<
class>
class Allocator,
class CellAssignor>
120 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
121 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
123 write_real_comp.push_back(1);
124 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
129 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
131 write_int_comp.push_back(1);
132 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
135 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
136 real_comp_names, int_comp_names,
141template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
142 template<
class>
class Allocator,
class CellAssignor>
149 if constexpr(ParticleType::is_soa_particle) {
157 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
158 for (
int i = 0; i < nrc; ++i) {
159 write_real_comp.push_back(1);
163 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
164 write_int_comp.push_back(1);
167 WriteBinaryParticleData(dir, name,
168 write_real_comp, write_int_comp,
169 real_comp_names, int_comp_names,
174template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
175 template<
class>
class Allocator,
class CellAssignor>
181 if constexpr(ParticleType::is_soa_particle) {
188 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
189 for (
int i = 0; i < nrc; ++i) {
190 write_real_comp.push_back(1);
194 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
195 write_int_comp.push_back(1);
199 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
201 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
204 WriteBinaryParticleData(dir, name,
205 write_real_comp, write_int_comp,
206 real_comp_names, int_comp_names,
211template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
212 template<
class>
class Allocator,
class CellAssignor>
216 const std::string& name,
221 if constexpr(ParticleType::is_soa_particle) {
229 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
230 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
232 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
236 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
238 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
241 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
242 real_comp_names, int_comp_names,
247template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
248 template<
class>
class Allocator,
class CellAssignor>
251WritePlotFile (
const std::string& dir,
const std::string& name,
257 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
259 WriteBinaryParticleData(dir, name,
260 write_real_comp, write_int_comp,
261 real_comp_names, int_comp_names,
266template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
267 template<
class>
class Allocator,
class CellAssignor>
276 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
277 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
279 write_real_comp.push_back(1);
280 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
285 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
287 write_int_comp.push_back(1);
288 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
291 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
292 real_comp_names, int_comp_names, f);
296template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
297 template<
class>
class Allocator,
class CellAssignor>
305 if constexpr(ParticleType::is_soa_particle) {
313 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
314 for (
int i = 0; i < nrc; ++i) {
315 write_real_comp.push_back(1);
319 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
320 write_int_comp.push_back(1);
323 WriteBinaryParticleData(dir, name,
324 write_real_comp, write_int_comp,
325 real_comp_names, int_comp_names, f);
329template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
330 template<
class>
class Allocator,
class CellAssignor>
337 if constexpr(ParticleType::is_soa_particle) {
344 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
345 for (
int i = 0; i < nrc; ++i) {
346 write_real_comp.push_back(1);
350 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
351 write_int_comp.push_back(1);
355 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
357 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
360 WriteBinaryParticleData(dir, name,
361 write_real_comp, write_int_comp,
362 real_comp_names, int_comp_names, f);
366template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
367 template<
class>
class Allocator,
class CellAssignor>
372 const std::string& name,
376 if constexpr(ParticleType::is_soa_particle) {
384 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
385 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
387 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
391 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
393 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
396 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
397 real_comp_names, int_comp_names, f);
401template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
402 template<
class>
class Allocator,
class CellAssignor>
406WritePlotFile (
const std::string& dir,
const std::string& name,
413 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
415 WriteBinaryParticleData(dir, name,
416 write_real_comp, write_int_comp,
417 real_comp_names, int_comp_names, f);
420template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
421 template<
class>
class Allocator,
class CellAssignor>
430 F const& f,
bool is_checkpoint)
const
434 write_real_comp, write_int_comp,
435 real_comp_names, int_comp_names, is_checkpoint);
439 write_real_comp, write_int_comp,
440 real_comp_names, int_comp_names,
445template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
446 template<
class>
class Allocator,
class CellAssignor>
455 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
459 Long maxnextid = ParticleType::NextID();
461 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
462 const auto& pmap = m_particles[lev];
463 for (
const auto& kv : pmap) {
464 const auto& aos = kv.second.GetArrayOfStructs();
465 for (
int k = 0; k < aos.numParticles(); ++k) {
467 if (p.id().is_valid()) {
478 ParticleType::NextID(maxnextid);
481 nparticlesPrePost = nparticles;
482 maxnextidPrePost = maxnextid;
484 nParticlesAtLevelPrePost.clear();
485 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
486 for(
int lev(0); lev <= finestLevel(); ++lev) {
487 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
490 whichPrePost.clear();
491 whichPrePost.resize(finestLevel() + 1);
492 countPrePost.clear();
493 countPrePost.resize(finestLevel() + 1);
494 wherePrePost.clear();
495 wherePrePost.resize(finestLevel() + 1);
497 filePrefixPrePost.clear();
498 filePrefixPrePost.resize(finestLevel() + 1);
502template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
503 template<
class>
class Allocator,
class CellAssignor>
512 BL_PROFILE(
"ParticleContainer::CheckpointPost()");
515 std::ofstream HdrFile;
516 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
518 for(
int lev(0); lev <= finestLevel(); ++lev) {
525 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
526 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
529 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
530 if(gotsome && doUnlink) {
535 for(
int i(0), N = countPrePost[lev].size(); i < N; ++i) {
536 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
539 for(
int i = 0; i < std::ssize(cnt); ++i) {
552 if( ! HdrFile.good()) {
553 amrex::Abort(
"ParticleContainer::CheckpointPost(): problem writing HdrFile");
558template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
559 template<
class>
class Allocator,
class CellAssignor>
568template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
569 template<
class>
class Allocator,
class CellAssignor>
578template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
579 template<
class>
class Allocator,
class CellAssignor>
587 bool is_checkpoint)
const
589 BL_PROFILE(
"ParticleContainer::WriteParticles()");
592 std::map<int, Vector<int> > tile_map;
594 for (
const auto& kv : m_particles[lev])
596 const int grid = kv.first.first;
597 const int tile = kv.first.second;
598 tile_map[grid].push_back(tile);
599 const auto& pflags = particle_io_flags[lev].at(kv.first);
602 count[grid] += particle_detail::countFlags(pflags);
607 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
611 const int grid = mfi.index();
616 if (count[grid] <= 0) {
continue; }
620 particle_detail::packIOData(istuff, rstuff, *
this, lev, grid,
621 write_real_comp, write_int_comp,
622 particle_io_flags, tile_map[grid], count[grid], is_checkpoint);
629 WriteParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ofs);
637template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
638 template<
class>
class Allocator,
class CellAssignor>
641::Restart (
const std::string& dir,
const std::string& file,
bool )
646template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
647 template<
class>
class Allocator,
class CellAssignor>
650::Restart (
const std::string& dir,
const std::string& file)
658 int DATA_Digits_Read(5);
660 pp.
query(
"datadigits_read",DATA_Digits_Read);
662 std::string fullname = dir;
663 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
667 std::string HdrFileName = fullname;
668 if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] !=
'/') {
671 HdrFileName +=
"Header";
675 std::string fileCharPtrString(fileCharPtr.
dataPtr());
676 std::istringstream HdrFile(fileCharPtrString, std::istringstream::in);
690 bool convert_ids =
false;
691 if (version.find(
"Version_Two_Dot_One") != std::string::npos) {
694 if (version.find(
"Version_One_Dot_Zero") != std::string::npos) {
697 else if (version.find(
"Version_One_Dot_One") != std::string::npos ||
698 version.find(
"Version_Two_Dot_Zero") != std::string::npos ||
699 version.find(
"Version_Two_Dot_One") != std::string::npos) {
700 if (version.find(
"_single") != std::string::npos) {
703 else if (version.find(
"_double") != std::string::npos) {
707 std::string msg(
"ParticleContainer::Restart(): bad version string: ");
713 std::string msg(
"ParticleContainer::Restart(): unknown version string: ");
720 if (dm != AMREX_SPACEDIM) {
721 amrex::Abort(
"ParticleContainer::Restart(): dm != AMREX_SPACEDIM");
726 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
728 amrex::Abort(
"ParticleContainer::Restart(): nr not the expected value");
731 std::string comp_name;
732 for (
int i = 0; i < nr; ++i) {
733 HdrFile >> comp_name;
738 if (ni != NStructInt + NumIntComps()) {
739 amrex::Abort(
"ParticleContainer::Restart(): ni != NStructInt");
742 for (
int i = 0; i < ni; ++i) {
743 HdrFile >> comp_name;
747 HdrFile >> checkpoint;
750 HdrFile >> nparticles;
754 HdrFile >> maxnextid;
756 ParticleType::NextID(maxnextid);
758 int finest_level_in_file;
759 HdrFile >> finest_level_in_file;
766 int const max_level = std::max(finest_level_in_file, finestLevel());
770 bool dual_grid =
false;
772 bool have_pheaders =
false;
773 for (
int lev = 0; lev <= finest_level_in_file; lev++)
775 std::string phdr_name = fullname;
776 phdr_name +=
"/Level_";
778 phdr_name +=
"/Particle_H";
781 have_pheaders =
true;
788 for (
int lev = 0; lev <= finestLevel(); lev++)
790 old_dms[lev] = ParticleDistributionMap(lev);
791 old_bas[lev] = ParticleBoxArray(lev);
792 std::string phdr_name = fullname;
793 phdr_name +=
"/Level_";
795 phdr_name +=
"/Particle_H";
801 std::string phdr_string(phdr_chars.
dataPtr());
802 std::istringstream phdr_file(phdr_string, std::istringstream::in);
804 particle_box_arrays[lev].readFrom(phdr_file);
805 if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) { dual_grid =
true; }
813 for (
int lev = 0; lev <= finestLevel(); lev++) {
815 if (particle_box_arrays[lev].empty()) {
816 particle_box_arrays[lev] = BoxArray(Geom(lev).Domain());
818 SetParticleBoxArray(lev, particle_box_arrays[lev]);
820 SetParticleDistributionMap(lev, pdm);
824 Vector<int> ngrids(finest_level_in_file+1);
825 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
826 HdrFile >> ngrids[lev];
832 if (finest_level_in_file > finestLevel()) {
833 m_particles.resize(finest_level_in_file+1);
836 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
840 for (
int i = 0; i < ngrids[lev]; i++) {
841 HdrFile >> which[i] >> count[i] >> where[i];
845 if (lev <= finestLevel()) {
847 grids_to_read.push_back(mfi.index());
855 const int NReaders = MaxReaders();
856 if (rank >= NReaders) {
continue; }
858 const int Navg = ngrids[lev] / NReaders;
859 const int Nleft = ngrids[lev] - Navg * NReaders;
863 lo = rank*(Navg + 1);
867 lo = rank * Navg + Nleft;
871 for (
int i = lo; i < hi; ++i) {
872 grids_to_read.push_back(i);
876 for(
int grid : grids_to_read) {
877 if (count[grid] <= 0) {
continue; }
880 std::string name = fullname;
882 if (!name.empty() && name[name.size()-1] !=
'/') {
889 name += DataPrefix();
892 std::ifstream ParticleFile;
894 ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary);
896 if (!ParticleFile.good()) {
900 ParticleFile.seekg(where[grid], std::ios::beg);
905 if (how ==
"single") {
906 if constexpr (std::is_same_v<ParticleReal, float>) {
907 ReadParticles<float>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
909 amrex::Error(
"File contains single-precision data, while AMReX is compiled with ParticleReal==double");
912 else if (how ==
"double") {
913 if constexpr (std::is_same_v<ParticleReal, double>) {
914 ReadParticles<double>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
916 amrex::Error(
"File contains double-precision data, while AMReX is compiled with ParticleReal==float");
920 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
925 ParticleFile.close();
927 if (!ParticleFile.good()) {
928 amrex::Abort(
"ParticleContainer::Restart(): problem reading particles");
934 for (
int lev = 0; lev <= finestLevel(); lev++) {
935 SetParticleBoxArray(lev, old_bas[lev]);
936 SetParticleDistributionMap(lev, old_dms[lev]);
947 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
952template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
953 template<
class>
class Allocator,
class CellAssignor>
954template <
class RTYPE>
958 int finest_level_in_file,
bool convert_ids)
960 BL_PROFILE(
"ParticleContainer::ReadParticles()");
967 const int iChunkSize = 2 + NStructInt + NumIntComps();
972 const int rChunkSize = ParticleType::is_soa_particle ? NStructReal + NumRealComps() : AMREX_SPACEDIM + NStructReal + NumRealComps();
978 RTYPE* rptr = rstuff.
dataPtr();
984 host_particles.reserve(15);
985 host_particles.resize(finest_level_in_file+1);
988 std::vector<Gpu::HostVector<RTYPE> > > > host_real_attribs;
989 host_real_attribs.reserve(15);
990 host_real_attribs.resize(finest_level_in_file+1);
993 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
994 host_int_attribs.reserve(15);
995 host_int_attribs.resize(finest_level_in_file+1);
998 host_idcpu.reserve(15);
999 host_idcpu.resize(finest_level_in_file+1);
1001 for (
int i = 0; i < cnt; i++) {
1005 std::int32_t xi, yi;
1006 std::uint32_t xu, yu;
1009 std::memcpy(&xu, &xi,
sizeof(xi));
1010 std::memcpy(&yu, &yi,
sizeof(yi));
1011 ptemp.
m_idcpu = ((std::uint64_t)xu) << 32 | yu;
1013 ptemp.
id() = iptr[0];
1014 ptemp.
cpu() = iptr[1];
1018 for (
int j = 0; j < NStructInt; j++)
1020 ptemp.
idata(j) = *iptr;
1030 rptr += AMREX_SPACEDIM;
1032 for (
int j = 0; j < NStructReal; j++)
1038 locateParticle(ptemp, pld, 0, finestLevel(), 0);
1040 std::pair<int, int> ind(grd, pld.
m_tile);
1042 host_real_attribs[lev][ind].resize(NumRealComps());
1043 host_int_attribs[lev][ind].resize(NumIntComps());
1046 if constexpr(!ParticleType::is_soa_particle)
1048 host_particles[lev][ind].push_back(ptemp);
1051 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
1052 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1057 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1058 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1062 host_particles[lev][ind];
1064 for (
int j = 0; j < AMREX_SPACEDIM; j++) {
1065 host_real_attribs[lev][ind][j].push_back(ptemp.
pos(j));
1068 host_idcpu[lev][ind].push_back(ptemp.
m_idcpu);
1072 for (
int icomp = AMREX_SPACEDIM; icomp < NumRealComps(); icomp++) {
1073 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1078 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1079 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1085 for (
int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
1087 for (
auto& kv : host_particles[host_lev]) {
1088 auto grid = kv.first.first;
1089 auto tile = kv.first.second;
1090 const auto& src_tile = kv.second;
1092 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1093 auto old_size = dst_tile.size();
1094 auto new_size = old_size;
1095 if constexpr(!ParticleType::is_soa_particle)
1097 new_size += src_tile.size();
1100 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1102 dst_tile.resize(new_size);
1104 if constexpr(!ParticleType::is_soa_particle)
1107 dst_tile.GetArrayOfStructs().begin() + old_size);
1110 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
1111 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
1112 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1115 for (
int i = 0; i < NumRealComps(); ++i) {
1117 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1118 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1119 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1122 for (
int i = 0; i < NumIntComps(); ++i) {
1124 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1125 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1126 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1134template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1135 template<
class>
class Allocator,
class CellAssignor>
1137ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1138::WriteAsciiFile (
const std::string& filename)
1140 BL_PROFILE(
"ParticleContainer::WriteAsciiFile()");
1147 Long nparticles = 0;
1149 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
1150 auto& pmap = m_particles[lev];
1151 for (
const auto& kv : pmap) {
1152 const auto& aos = kv.second.GetArrayOfStructs();
1153 auto np = aos.numParticles();
1156 for (
int k = 0; k < np; ++k) {
1158 if (p.id().is_valid()) {
1180 File.open(filename.c_str(), std::ios::out|std::ios::trunc);
1186 File << nparticles <<
'\n';
1187 File << NStructReal <<
'\n';
1188 File << NStructInt <<
'\n';
1189 File << NumRealComps() <<
'\n';
1190 File << NumIntComps() <<
'\n';
1197 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1216 File.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
1218 File.open(filename.c_str(), std::ios::out|std::ios::app);
1226 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
1227 auto& pmap = m_particles[lev];
1228 for (
const auto& kv : pmap) {
1231 pinned_ptile.define(NumRuntimeRealComps(), NumRuntimeIntComps(),
1233 pinned_ptile.resize(kv.second.numParticles());
1235 const auto& host_aos = pinned_ptile.GetArrayOfStructs();
1236 const auto& host_soa = pinned_ptile.GetStructOfArrays();
1238 auto np = host_aos.numParticles();
1239 for (
int index = 0; index < np; ++index) {
1241 if (it->id().is_valid()) {
1245 << it->pos(1) <<
' ',
1246 << it->pos(2) <<
' ');
1248 for (
int i = 0; i < NStructReal; i++) {
1249 File << it->rdata(i) <<
' ';
1252 File << it->id() <<
' ';
1253 File << it->cpu() <<
' ';
1255 for (
int i = 0; i < NStructInt; i++) {
1256 File << it->idata(i) <<
' ';
1260 for (
int i = 0; i < NumRealComps(); i++) {
1261 File << host_soa.GetRealData(i)[index] <<
' ';
1264 for (
int i = 0; i < NumIntComps(); i++) {
1265 File << host_soa.GetIntData(i)[index] <<
' ';
1279 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1293 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:172
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
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
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:172
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
const std::string & FileName() const
Definition AMReX_NFiles.H:160
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
iterator begin() noexcept
Definition AMReX_PODVector.H:674
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:349
int query(std::string_view name, bool &ref, int ival=FIRST) const
Same as querykth() but searches for the last occurrence of name.
Definition AMReX_ParmParse.cpp:1947
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:149
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:151
Definition AMReX_GpuAllocators.H:156
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:28
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:49
Long size() const noexcept
Definition AMReX_Vector.H:53
static constexpr int IO_Buffer_Size
We try to do I/O with buffers of this size.
Definition AMReX_VisMFBuffer.H:16
static Long FileOffset(std::ostream &os)
The file offset of the passed ostream.
Definition AMReX_VisMF.cpp:580
static bool GetNoFlushAfterWrite()
Definition AMReX_VisMF.H:284
amrex_particle_real ParticleReal
Floating Point Type for Particles.
Definition AMReX_REAL.H:90
amrex_long Long
Definition AMReX_INT.H:30
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:115
Arena * The_Pinned_Arena()
Definition AMReX_Arena.cpp:860
int MyProc() noexcept
Definition AMReX_ParallelDescriptor.H:128
void Barrier(const std::string &)
Definition AMReX_ParallelDescriptor.cpp:1215
void ReduceIntSum(int &)
Definition AMReX_ParallelDescriptor.cpp:1265
void ReadAndBcastFile(const std::string &filename, Vector< char > &charBuf, bool bExitOnError, const MPI_Comm &comm)
Definition AMReX_ParallelDescriptor.cpp:1495
int NProcs() noexcept
Definition AMReX_ParallelDescriptor.H:255
void ReduceLongSum(Long &)
Definition AMReX_ParallelDescriptor.cpp:1236
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:1237
bool IOProcessor() noexcept
Is this CPU the I/O Processor? To get the rank number, call IOProcessorNumber()
Definition AMReX_ParallelDescriptor.H:289
bool UseAsyncOut()
Definition AMReX_AsyncOut.cpp:70
bool Remove(std::string const &filename)
Remove a file, symbolic link, or empty directory.
Definition AMReX_FileSystem.cpp:41
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:128
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 DeviceToHost deviceToHost
Definition AMReX_GpuContainers.H:106
static constexpr HostToDevice hostToDevice
Definition AMReX_GpuContainers.H:105
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
void ReduceRealMax(Vector< std::reference_wrapper< Real > > const &)
Definition AMReX_ParallelDescriptor.cpp:1228
Definition AMReX_Amr.cpp:50
void writeIntData(const From *data, std::size_t size, std::ostream &os, const amrex::IntDescriptor &id)
Definition AMReX_IntConv.H:23
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
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:485
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:137
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
void readFloatData(float *data, std::size_t size, std::istream &is, const RealDescriptor &rd)
Definition AMReX_VectorIO.cpp:136
void writeFloatData(const float *data, std::size_t size, std::ostream &os, const RealDescriptor &rd=FPC::Native32RealDescriptor())
Definition AMReX_VectorIO.cpp:130
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:145
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2006
std::string Concatenate(const std::string &root, int num, int mindigits)
Returns rootNNNN where NNNN == num.
Definition AMReX_String.cpp:35
double second() noexcept
Definition AMReX_Utility.cpp:940
void writeDoubleData(const double *data, std::size_t size, std::ostream &os, const RealDescriptor &rd=FPC::Native64RealDescriptor())
Definition AMReX_VectorIO.cpp:142
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:235
void readDoubleData(double *data, std::size_t size, std::istream &is, const RealDescriptor &rd)
Definition AMReX_VectorIO.cpp:148
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:241
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:784
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2015
void readIntData(To *data, std::size_t size, std::istream &is, const amrex::IntDescriptor &id)
Definition AMReX_IntConv.H:38
Definition AMReX_ParticleIO.H:40
__host__ __device__ int operator()(const P &p) const
Definition AMReX_ParticleIO.H:43
FabArray memory allocation information.
Definition AMReX_FabArray.H:67
MFInfo & SetAlloc(bool a) noexcept
Definition AMReX_FabArray.H:74
uint64_t m_idcpu
Definition AMReX_Particle.H:359
__host__ __device__ bool is_valid() const noexcept
Definition AMReX_Particle.H:252
A struct used for storing a particle's position in the AMR hierarchy.
Definition AMReX_ParticleContainer.H:93
int m_tile
Definition AMReX_ParticleContainer.H:96
Definition AMReX_ParticleTile.H:764
The struct used to store particles.
Definition AMReX_Particle.H:405
__host__ __device__ RealVect pos() const &
Definition AMReX_Particle.H:456
__host__ __device__ int & idata(int index) &
Definition AMReX_Particle.H:545
__host__ __device__ ParticleCPUWrapper cpu() &
Definition AMReX_Particle.H:424
__host__ __device__ ParticleIDWrapper id() &
Definition AMReX_Particle.H:427
__host__ __device__ RealType & rdata(int index) &
Definition AMReX_Particle.H:474