1#ifndef AMREX_PARTICLEIO_H
2#define AMREX_PARTICLEIO_H
3#include <AMReX_Config.H>
13template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
14 template<
class>
class Allocator,
class CellAssignor>
16ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
17::WriteParticleRealData (
void* data,
size_t size, std::ostream& os)
const
19 if (
sizeof(
typename ParticleType::RealType) == 4) {
22 else if (
sizeof(
typename ParticleType::RealType) == 8) {
27template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
28 template<
class>
class Allocator,
class CellAssignor>
33 if (
sizeof(
typename ParticleType::RealType) == 4) {
34 readFloatData((
float*) data, size, is, ParticleRealDescriptor);
36 else if (
sizeof(
typename ParticleType::RealType) == 8) {
45 return p.id().is_valid();
50template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
51 template<
class>
class Allocator,
class CellAssignor>
53ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
54::Checkpoint (
const std::string& dir,
55 const std::string& name,
bool ,
62 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
63 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
65 write_real_comp.push_back(1);
66 if (real_comp_names.empty())
68 tmp_real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
72 tmp_real_comp_names.push_back(real_comp_names[i-first_rcomp]);
78 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
80 write_int_comp.push_back(1);
81 if (int_comp_names.empty())
83 tmp_int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
87 tmp_int_comp_names.push_back(int_comp_names[i]);
91 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
92 tmp_real_comp_names, tmp_int_comp_names,
96template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
97 template<
class>
class Allocator,
class CellAssignor>
106 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
107 real_comp_names, int_comp_names,
112template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
113 template<
class>
class Allocator,
class CellAssignor>
121 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
122 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
124 write_real_comp.push_back(1);
125 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
130 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
132 write_int_comp.push_back(1);
133 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
136 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
137 real_comp_names, int_comp_names,
142template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
143 template<
class>
class Allocator,
class CellAssignor>
150 if constexpr(ParticleType::is_soa_particle) {
158 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
159 for (
int i = 0; i < nrc; ++i) {
160 write_real_comp.push_back(1);
164 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
165 write_int_comp.push_back(1);
168 WriteBinaryParticleData(dir, name,
169 write_real_comp, write_int_comp,
170 real_comp_names, int_comp_names,
175template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
176 template<
class>
class Allocator,
class CellAssignor>
182 if constexpr(ParticleType::is_soa_particle) {
189 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
190 for (
int i = 0; i < nrc; ++i) {
191 write_real_comp.push_back(1);
195 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
196 write_int_comp.push_back(1);
200 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
202 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
205 WriteBinaryParticleData(dir, name,
206 write_real_comp, write_int_comp,
207 real_comp_names, int_comp_names,
212template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
213 template<
class>
class Allocator,
class CellAssignor>
217 const std::string& name,
222 if constexpr(ParticleType::is_soa_particle) {
230 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
231 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
233 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
237 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
239 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
242 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
243 real_comp_names, int_comp_names,
248template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
249 template<
class>
class Allocator,
class CellAssignor>
252WritePlotFile (
const std::string& dir,
const std::string& name,
258 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
260 WriteBinaryParticleData(dir, name,
261 write_real_comp, write_int_comp,
262 real_comp_names, int_comp_names,
267template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
268 template<
class>
class Allocator,
class CellAssignor>
277 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
278 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
280 write_real_comp.push_back(1);
281 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
286 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
288 write_int_comp.push_back(1);
289 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
292 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
293 real_comp_names, int_comp_names, f);
297template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
298 template<
class>
class Allocator,
class CellAssignor>
306 if constexpr(ParticleType::is_soa_particle) {
314 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
315 for (
int i = 0; i < nrc; ++i) {
316 write_real_comp.push_back(1);
320 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
321 write_int_comp.push_back(1);
324 WriteBinaryParticleData(dir, name,
325 write_real_comp, write_int_comp,
326 real_comp_names, int_comp_names, f);
330template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
331 template<
class>
class Allocator,
class CellAssignor>
338 if constexpr(ParticleType::is_soa_particle) {
345 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
346 for (
int i = 0; i < nrc; ++i) {
347 write_real_comp.push_back(1);
351 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
352 write_int_comp.push_back(1);
356 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
358 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
361 WriteBinaryParticleData(dir, name,
362 write_real_comp, write_int_comp,
363 real_comp_names, int_comp_names, f);
367template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
368 template<
class>
class Allocator,
class CellAssignor>
373 const std::string& name,
377 if constexpr(ParticleType::is_soa_particle) {
385 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
386 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
388 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
392 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
394 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
397 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
398 real_comp_names, int_comp_names, f);
402template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
403 template<
class>
class Allocator,
class CellAssignor>
407WritePlotFile (
const std::string& dir,
const std::string& name,
414 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
416 WriteBinaryParticleData(dir, name,
417 write_real_comp, write_int_comp,
418 real_comp_names, int_comp_names, f);
421template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
422 template<
class>
class Allocator,
class CellAssignor>
431 F const& f,
bool is_checkpoint)
const
435 write_real_comp, write_int_comp,
436 real_comp_names, int_comp_names, is_checkpoint);
440 write_real_comp, write_int_comp,
441 real_comp_names, int_comp_names,
446template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
447 template<
class>
class Allocator,
class CellAssignor>
456 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
460 Long maxnextid = ParticleType::NextID();
462 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
463 const auto& pmap = m_particles[lev];
464 for (
const auto& kv : pmap) {
465 const auto& aos = kv.second.GetArrayOfStructs();
466 for (
int k = 0; k < aos.numParticles(); ++k) {
468 if (p.id().is_valid()) {
479 ParticleType::NextID(maxnextid);
482 nparticlesPrePost = nparticles;
483 maxnextidPrePost = maxnextid;
485 nParticlesAtLevelPrePost.clear();
486 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
487 for(
int lev(0); lev <= finestLevel(); ++lev) {
488 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
491 whichPrePost.clear();
492 whichPrePost.resize(finestLevel() + 1);
493 countPrePost.clear();
494 countPrePost.resize(finestLevel() + 1);
495 wherePrePost.clear();
496 wherePrePost.resize(finestLevel() + 1);
498 filePrefixPrePost.clear();
499 filePrefixPrePost.resize(finestLevel() + 1);
503template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
504 template<
class>
class Allocator,
class CellAssignor>
513 BL_PROFILE(
"ParticleContainer::CheckpointPost()");
516 std::ofstream HdrFile;
517 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
519 for(
int lev(0); lev <= finestLevel(); ++lev) {
526 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
527 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
530 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
531 if(gotsome && doUnlink) {
536 for(
int i(0), N = countPrePost[lev].size(); i < N; ++i) {
537 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
540 for(
int i = 0; i < std::ssize(cnt); ++i) {
553 if( ! HdrFile.good()) {
554 amrex::Abort(
"ParticleContainer::CheckpointPost(): problem writing HdrFile");
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>
579template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
580 template<
class>
class Allocator,
class CellAssignor>
588 bool is_checkpoint)
const
590 BL_PROFILE(
"ParticleContainer::WriteParticles()");
593 std::map<int, Vector<int> > tile_map;
595 for (
const auto& kv : m_particles[lev])
597 const int grid = kv.first.first;
598 const int tile = kv.first.second;
599 tile_map[grid].push_back(tile);
600 const auto& pflags = particle_io_flags[lev].at(kv.first);
603 count[grid] += particle_detail::countFlags(pflags);
608 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
612 const int grid = mfi.index();
617 if (count[grid] <= 0) {
continue; }
621 particle_detail::packIOData(istuff, rstuff, *
this, lev, grid,
622 write_real_comp, write_int_comp,
623 particle_io_flags, tile_map[grid], count[grid], is_checkpoint);
630 WriteParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ofs);
638template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
639 template<
class>
class Allocator,
class CellAssignor>
642::Restart (
const std::string& dir,
const std::string& file,
bool )
647template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
648 template<
class>
class Allocator,
class CellAssignor>
651::Restart (
const std::string& dir,
const std::string& file)
659 int DATA_Digits_Read(5);
661 pp.
query(
"datadigits_read",DATA_Digits_Read);
663 std::string fullname = dir;
664 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
668 std::string HdrFileName = fullname;
669 if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] !=
'/') {
672 HdrFileName +=
"Header";
676 std::string fileCharPtrString(fileCharPtr.
dataPtr());
677 std::istringstream HdrFile(fileCharPtrString, std::istringstream::in);
684 header.
parse(HdrFile);
687 const std::string& how = header.
how;
690 if (header.
dim != AMREX_SPACEDIM) {
691 amrex::Abort(
"ParticleContainer::Restart(): dm != AMREX_SPACEDIM");
694 const int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
696 amrex::Abort(
"ParticleContainer::Restart(): nr not the expected value");
699 if (header.
num_int != NStructInt + NumIntComps()) {
700 amrex::Abort(
"ParticleContainer::Restart(): ni != NStructInt");
706 ParticleType::NextID(header.
next_id);
717 for (
int lev = 0; lev <= finest_level_in_file; lev++)
719 std::string phdr_name = fullname;
720 phdr_name +=
"/Level_";
722 phdr_name +=
"/Particle_H";
727 std::string phdr_string(phdr_chars.
dataPtr());
728 std::istringstream phdr_file(phdr_string, std::istringstream::in);
729 file_bas[lev].readFrom(phdr_file);
733 file_bas[lev] =
BoxArray(Geom(lev).Domain());
735 const int NReaders = MaxReaders();
740 for (
int i = 0; i < (
int)pmap.
size(); ++i) { pmap[i] = i % NReaders; }
747 if (finest_level_in_file > finestLevel()) {
748 m_particles.resize(finest_level_in_file+1);
751 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
752 auto const& grid_table = header.
grids[lev];
757 MultiFab file_mf(file_bas[lev], file_dms[lev], 1, 0, info);
760 grids_to_read.push_back(mfi.index());
763 for(
int grid : grids_to_read) {
764 if (grid_table[grid].count <= 0) {
continue; }
767 std::string name = fullname;
769 if (!name.empty() && name[name.size()-1] !=
'/') {
776 name += DataPrefix();
779 std::ifstream ParticleFile;
781 ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary);
783 if (!ParticleFile.good()) {
787 ParticleFile.seekg(grid_table[grid].where, std::ios::beg);
792 if (how ==
"single") {
793 if constexpr (std::is_same_v<ParticleReal, float>) {
794 ReadParticles<float>(grid_table[grid].count, grid, lev, ParticleFile, finest_level_in_file, convert_ids);
796 amrex::Error(
"File contains single-precision data, while AMReX is compiled with ParticleReal==double");
799 else if (how ==
"double") {
800 if constexpr (std::is_same_v<ParticleReal, double>) {
801 ReadParticles<double>(grid_table[grid].count, grid, lev, ParticleFile, finest_level_in_file, convert_ids);
803 amrex::Error(
"File contains double-precision data, while AMReX is compiled with ParticleReal==float");
807 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
812 ParticleFile.close();
814 if (!ParticleFile.good()) {
815 amrex::Abort(
"ParticleContainer::Restart(): problem reading particles");
827 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
832template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
833 template<
class>
class Allocator,
class CellAssignor>
834template <
class RTYPE>
838 int finest_level_in_file,
bool convert_ids)
840 BL_PROFILE(
"ParticleContainer::ReadParticles()");
847 const int iChunkSize = 2 + NStructInt + NumIntComps();
852 const int rChunkSize = ParticleType::is_soa_particle ? NStructReal + NumRealComps() : AMREX_SPACEDIM + NStructReal + NumRealComps();
854 ReadParticleRealData(rstuff.dataPtr(), rstuff.size(), ifs);
857 int* iptr = istuff.dataPtr();
858 RTYPE* rptr = rstuff.dataPtr();
864 host_particles.reserve(15);
865 host_particles.resize(finest_level_in_file+1);
868 std::vector<Gpu::HostVector<RTYPE> > > > host_real_attribs;
869 host_real_attribs.reserve(15);
870 host_real_attribs.resize(finest_level_in_file+1);
873 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
874 host_int_attribs.reserve(15);
875 host_int_attribs.resize(finest_level_in_file+1);
878 host_idcpu.reserve(15);
879 host_idcpu.resize(finest_level_in_file+1);
881 for (
int i = 0; i < cnt; i++) {
886 std::uint32_t xu, yu;
889 std::memcpy(&xu, &xi,
sizeof(xi));
890 std::memcpy(&yu, &yi,
sizeof(yi));
891 ptemp.
m_idcpu = ((std::uint64_t)xu) << 32 | yu;
893 ptemp.
id() = iptr[0];
894 ptemp.
cpu() = iptr[1];
898 for (
int j = 0; j < NStructInt; j++)
900 ptemp.
idata(j) = *iptr;
910 rptr += AMREX_SPACEDIM;
912 for (
int j = 0; j < NStructReal; j++)
918 locateParticle(ptemp, pld, 0, finestLevel(),
IntVect(0));
920 std::pair<int, int> ind(grd, pld.
m_tile);
922 host_real_attribs[lev][ind].resize(NumRealComps());
923 host_int_attribs[lev][ind].resize(NumIntComps());
926 if constexpr(!ParticleType::is_soa_particle)
928 host_particles[lev][ind].push_back(ptemp);
931 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
932 host_real_attribs[lev][ind][icomp].push_back(*rptr);
937 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
938 host_int_attribs[lev][ind][icomp].push_back(*iptr);
942 host_particles[lev][ind];
944 for (
int j = 0; j < AMREX_SPACEDIM; j++) {
945 host_real_attribs[lev][ind][j].push_back(ptemp.
pos(j));
948 host_idcpu[lev][ind].push_back(ptemp.
m_idcpu);
952 for (
int icomp = AMREX_SPACEDIM; icomp < NumRealComps(); icomp++) {
953 host_real_attribs[lev][ind][icomp].push_back(*rptr);
958 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
959 host_int_attribs[lev][ind][icomp].push_back(*iptr);
965 for (
int host_lev = 0; host_lev < std::ssize(host_particles); ++host_lev)
967 for (
auto& kv : host_particles[host_lev]) {
968 auto grid = kv.first.first;
969 auto tile = kv.first.second;
970 const auto& src_tile = kv.second;
972 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
973 auto old_size = dst_tile.size();
974 auto new_size = old_size;
975 if constexpr(!ParticleType::is_soa_particle)
977 new_size += src_tile.size();
980 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
982 dst_tile.resize(new_size);
984 if constexpr(!ParticleType::is_soa_particle)
987 dst_tile.GetArrayOfStructs().begin() + old_size);
990 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
991 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
992 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
995 for (
int i = 0; i < NumRealComps(); ++i) {
997 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
998 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
999 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1002 for (
int i = 0; i < NumIntComps(); ++i) {
1004 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1005 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1006 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1014template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1015 template<
class>
class Allocator,
class CellAssignor>
1017ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1018::WriteAsciiFile (
const std::string& filename)
1020 BL_PROFILE(
"ParticleContainer::WriteAsciiFile()");
1027 Long nparticles = 0;
1029 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
1030 auto& pmap = m_particles[lev];
1031 for (
const auto& kv : pmap) {
1032 const auto& aos = kv.second.GetArrayOfStructs();
1033 auto np = aos.numParticles();
1036 for (
int k = 0; k < np; ++k) {
1038 if (p.id().is_valid()) {
1060 File.open(filename.c_str(), std::ios::out|std::ios::trunc);
1066 File << nparticles <<
'\n';
1067 File << NStructReal <<
'\n';
1068 File << NStructInt <<
'\n';
1069 File << NumRealComps() <<
'\n';
1070 File << NumIntComps() <<
'\n';
1077 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1096 File.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
1098 File.open(filename.c_str(), std::ios::out|std::ios::app);
1106 for (
int lev = 0; lev < std::ssize(m_particles); lev++) {
1107 auto& pmap = m_particles[lev];
1108 for (
const auto& kv : pmap) {
1109 ParticleTile<ParticleType, NArrayReal, NArrayInt,
1111 pinned_ptile.define(NumRuntimeRealComps(), NumRuntimeIntComps(),
1113 pinned_ptile.resize(kv.second.numParticles());
1115 const auto& host_aos = pinned_ptile.GetArrayOfStructs();
1116 const auto& host_soa = pinned_ptile.GetStructOfArrays();
1118 auto np = host_aos.numParticles();
1119 for (
int index = 0; index < np; ++index) {
1120 const ParticleType* it = &host_aos[index];
1121 if (it->id().is_valid()) {
1125 << it->pos(1) <<
' ',
1126 << it->pos(2) <<
' ');
1128 for (
int i = 0; i < NStructReal; i++) {
1129 File << it->rdata(i) <<
' ';
1132 File << it->id() <<
' ';
1133 File << it->cpu() <<
' ';
1135 for (
int i = 0; i < NStructInt; i++) {
1136 File << it->idata(i) <<
' ';
1140 for (
int i = 0; i < NumRealComps(); i++) {
1141 File << host_soa.GetRealData(i)[index] <<
' ';
1144 for (
int i = 0; i < NumIntComps(); i++) {
1145 File << host_soa.GetIntData(i)[index] <<
' ';
1159 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1173 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
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:676
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
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:351
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: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
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
bool UseAsyncOut()
Query whether asynchronous output is enabled at runtime.
Definition AMReX_AsyncOut.cpp:70
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:116
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 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
int MyProc()
Definition AMReX_MPMD.cpp:117
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 &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition AMReX_Utility.cpp:116
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:786
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:2239
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:124
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:486
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:919
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
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 a message to stderr and abort the program.
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 a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:241
const int[]
Definition AMReX_BLProfiler.cpp:1664
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2257
void readIntData(To *data, std::size_t size, std::istream &is, const amrex::IntDescriptor &id)
Definition AMReX_IntConv.H:38
Definition AMReX_ParticleIO.H:41
__host__ __device__ int operator()(const P &p) const
Definition AMReX_ParticleIO.H:44
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
MFInfo & SetAlloc(bool a) noexcept
Control whether FAB storage is allocated when the FabArray is defined.
Definition AMReX_FabArray.H:81
uint64_t m_idcpu
Definition AMReX_Particle.H:359
Metadata prefix of an AMReX particle "Header" file.
Definition AMReX_ParticleHeader.H:38
void parse_grid_table(std::istream &is)
Parse the per-level grid table into grids.
Definition AMReX_ParticleHeader.cpp:82
int num_int
number of integer components
Definition AMReX_ParticleHeader.H:52
Vector< Vector< GridEntry > > grids
Per level and grid: where each grid's particle data is stored.
Definition AMReX_ParticleHeader.H:88
Long next_id
the next particle id to hand out (maxnextid)
Definition AMReX_ParticleHeader.H:60
int dim
AMREX_SPACEDIM the file was written with.
Definition AMReX_ParticleHeader.H:46
bool convert_ids
whether particle ids need to be converted (Version_Two_Dot_One and later)
Definition AMReX_ParticleHeader.H:44
void parse(std::istream &is)
Parse the metadata prefix from an input stream.
Definition AMReX_ParticleHeader.cpp:16
int finest_level
finest level present in the file
Definition AMReX_ParticleHeader.H:62
std::string how
precision the particle data was written in: "single" or "double"
Definition AMReX_ParticleHeader.H:42
int num_real
number of real components (pure SoA: excludes the AMREX_SPACEDIM positions)
Definition AMReX_ParticleHeader.H:48
Long num_particles
total number of particles in the file
Definition AMReX_ParticleHeader.H:58
__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
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:538
__host__ __device__ ParticleCPUWrapper cpu() &
Definition AMReX_Particle.H:424
__host__ __device__ RealType & rdata(int index) &
Definition AMReX_Particle.H:473
__host__ __device__ ParticleIDWrapper id() &
Definition AMReX_Particle.H:427