1#ifndef AMREX_PARTICLEIO_H
2#define AMREX_PARTICLEIO_H
3#include <AMReX_Config.H>
10template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
11 template<
class>
class Allocator,
class CellAssignor>
13ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
14::WriteParticleRealData (
void* data,
size_t size, std::ostream& os)
const
16 if (
sizeof(
typename ParticleType::RealType) == 4) {
19 else if (
sizeof(
typename ParticleType::RealType) == 8) {
24template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
25 template<
class>
class Allocator,
class CellAssignor>
30 if (
sizeof(
typename ParticleType::RealType) == 4) {
31 readFloatData((
float*) data, size, is, ParticleRealDescriptor);
33 else if (
sizeof(
typename ParticleType::RealType) == 8) {
42 return p.id().is_valid();
47template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
48 template<
class>
class Allocator,
class CellAssignor>
50ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
51::Checkpoint (
const std::string& dir,
52 const std::string& name,
bool ,
59 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
60 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
62 write_real_comp.push_back(1);
63 if (real_comp_names.empty())
65 tmp_real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
69 tmp_real_comp_names.push_back(real_comp_names[i-first_rcomp]);
75 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
77 write_int_comp.push_back(1);
78 if (int_comp_names.empty())
80 tmp_int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
84 tmp_int_comp_names.push_back(int_comp_names[i]);
88 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
89 tmp_real_comp_names, tmp_int_comp_names,
93template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
94 template<
class>
class Allocator,
class CellAssignor>
103 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
104 real_comp_names, int_comp_names,
109template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
110 template<
class>
class Allocator,
class CellAssignor>
118 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
119 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
121 write_real_comp.push_back(1);
122 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
127 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
129 write_int_comp.push_back(1);
130 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
133 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
134 real_comp_names, int_comp_names,
139template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
140 template<
class>
class Allocator,
class CellAssignor>
147 if constexpr(ParticleType::is_soa_particle) {
155 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
156 for (
int i = 0; i < nrc; ++i) {
157 write_real_comp.push_back(1);
161 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
162 write_int_comp.push_back(1);
165 WriteBinaryParticleData(dir, name,
166 write_real_comp, write_int_comp,
167 real_comp_names, int_comp_names,
172template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
173 template<
class>
class Allocator,
class CellAssignor>
179 if constexpr(ParticleType::is_soa_particle) {
186 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
187 for (
int i = 0; i < nrc; ++i) {
188 write_real_comp.push_back(1);
192 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
193 write_int_comp.push_back(1);
197 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
199 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
202 WriteBinaryParticleData(dir, name,
203 write_real_comp, write_int_comp,
204 real_comp_names, int_comp_names,
209template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
210 template<
class>
class Allocator,
class CellAssignor>
214 const std::string& name,
219 if constexpr(ParticleType::is_soa_particle) {
227 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
228 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
230 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
234 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
236 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
239 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
240 real_comp_names, int_comp_names,
245template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
246 template<
class>
class Allocator,
class CellAssignor>
249WritePlotFile (
const std::string& dir,
const std::string& name,
255 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
257 WriteBinaryParticleData(dir, name,
258 write_real_comp, write_int_comp,
259 real_comp_names, int_comp_names,
264template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
265 template<
class>
class Allocator,
class CellAssignor>
266template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
274 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
275 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
277 write_real_comp.push_back(1);
278 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
283 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
285 write_int_comp.push_back(1);
286 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
289 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
290 real_comp_names, int_comp_names,
295template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
296 template<
class>
class Allocator,
class CellAssignor>
304 if constexpr(ParticleType::is_soa_particle) {
312 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
313 for (
int i = 0; i < nrc; ++i) {
314 write_real_comp.push_back(1);
318 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
319 write_int_comp.push_back(1);
322 WriteBinaryParticleData(dir, name,
323 write_real_comp, write_int_comp,
324 real_comp_names, int_comp_names,
329template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
330 template<
class>
class Allocator,
class CellAssignor>
331template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
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,
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,
403template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
404 template<
class>
class Allocator,
class CellAssignor>
408WritePlotFile (
const std::string& dir,
const std::string& name,
415 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
417 WriteBinaryParticleData(dir, name,
418 write_real_comp, write_int_comp,
419 real_comp_names, int_comp_names,
423template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
424 template<
class>
class Allocator,
class CellAssignor>
433 F&& f,
bool is_checkpoint)
const
437 write_real_comp, write_int_comp,
438 real_comp_names, int_comp_names, is_checkpoint);
442 write_real_comp, write_int_comp,
443 real_comp_names, int_comp_names,
444 std::forward<F>(f), is_checkpoint);
448template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
449 template<
class>
class Allocator,
class CellAssignor>
458 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
462 Long maxnextid = ParticleType::NextID();
464 for (
int lev = 0; lev < m_particles.size(); lev++) {
465 const auto& pmap = m_particles[lev];
466 for (
const auto& kv : pmap) {
467 const auto& aos = kv.second.GetArrayOfStructs();
468 for (
int k = 0; k < aos.numParticles(); ++k) {
470 if (p.id().is_valid()) {
481 ParticleType::NextID(maxnextid);
484 nparticlesPrePost = nparticles;
485 maxnextidPrePost = int(maxnextid);
487 nParticlesAtLevelPrePost.clear();
488 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
489 for(
int lev(0); lev <= finestLevel(); ++lev) {
490 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
493 whichPrePost.clear();
494 whichPrePost.resize(finestLevel() + 1);
495 countPrePost.clear();
496 countPrePost.resize(finestLevel() + 1);
497 wherePrePost.clear();
498 wherePrePost.resize(finestLevel() + 1);
500 filePrefixPrePost.clear();
501 filePrefixPrePost.resize(finestLevel() + 1);
505template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
506 template<
class>
class Allocator,
class CellAssignor>
515 BL_PROFILE(
"ParticleContainer::CheckpointPost()");
518 std::ofstream HdrFile;
519 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
521 for(
int lev(0); lev <= finestLevel(); ++lev) {
528 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
529 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
532 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
533 if(gotsome && doUnlink) {
538 for(
int i(0), N = countPrePost[lev].size(); i < N; ++i) {
539 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
542 for(
int i(0), N =
int(cnt.
size()); i < N; ++i) {
555 if( ! HdrFile.good()) {
556 amrex::Abort(
"ParticleContainer::CheckpointPost(): problem writing HdrFile");
561template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
562 template<
class>
class Allocator,
class CellAssignor>
571template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
572 template<
class>
class Allocator,
class CellAssignor>
581template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
582 template<
class>
class Allocator,
class CellAssignor>
589 const Vector<std::map<std::pair<int, int>,
IntVector>>& particle_io_flags,
590 bool is_checkpoint)
const
592 BL_PROFILE(
"ParticleContainer::WriteParticles()");
595 std::map<int, Vector<int> > tile_map;
597 for (
const auto& kv : m_particles[lev])
599 const int grid = kv.first.first;
600 const int tile = kv.first.second;
601 tile_map[grid].push_back(tile);
602 const auto& pflags = particle_io_flags[lev].at(kv.first);
605 count[grid] += particle_detail::countFlags(pflags);
610 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
614 const int grid = mfi.index();
619 if (count[grid] == 0) {
continue; }
623 particle_detail::packIOData(istuff, rstuff, *
this, lev, grid,
624 write_real_comp, write_int_comp,
625 particle_io_flags, tile_map[grid], count[grid], is_checkpoint);
632 WriteParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ofs);
640template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
641 template<
class>
class Allocator,
class CellAssignor>
644::Restart (
const std::string& dir,
const std::string& file,
bool )
649template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
650 template<
class>
class Allocator,
class CellAssignor>
653::Restart (
const std::string& dir,
const std::string& file)
661 int DATA_Digits_Read(5);
663 pp.
query(
"datadigits_read",DATA_Digits_Read);
665 std::string fullname = dir;
666 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
670 std::string HdrFileName = fullname;
671 if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] !=
'/') {
674 HdrFileName +=
"Header";
678 std::string fileCharPtrString(fileCharPtr.
dataPtr());
679 std::istringstream HdrFile(fileCharPtrString, std::istringstream::in);
693 bool convert_ids =
false;
694 if (version.find(
"Version_Two_Dot_One") != std::string::npos) {
697 if (version.find(
"Version_One_Dot_Zero") != std::string::npos) {
700 else if (version.find(
"Version_One_Dot_One") != std::string::npos ||
701 version.find(
"Version_Two_Dot_Zero") != std::string::npos ||
702 version.find(
"Version_Two_Dot_One") != std::string::npos) {
703 if (version.find(
"_single") != std::string::npos) {
706 else if (version.find(
"_double") != std::string::npos) {
710 std::string msg(
"ParticleContainer::Restart(): bad version string: ");
716 std::string msg(
"ParticleContainer::Restart(): unknown version string: ");
723 if (dm != AMREX_SPACEDIM) {
724 amrex::Abort(
"ParticleContainer::Restart(): dm != AMREX_SPACEDIM");
729 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
731 amrex::Abort(
"ParticleContainer::Restart(): nr not the expected value");
734 std::string comp_name;
735 for (
int i = 0; i < nr; ++i) {
736 HdrFile >> comp_name;
741 if (ni != NStructInt + NumIntComps()) {
742 amrex::Abort(
"ParticleContainer::Restart(): ni != NStructInt");
745 for (
int i = 0; i < ni; ++i) {
746 HdrFile >> comp_name;
750 HdrFile >> checkpoint;
753 HdrFile >> nparticles;
757 HdrFile >> maxnextid;
759 ParticleType::NextID(maxnextid);
761 int finest_level_in_file;
762 HdrFile >> finest_level_in_file;
769 bool dual_grid =
false;
771 bool have_pheaders =
false;
772 for (
int lev = 0; lev <= finest_level_in_file; lev++)
774 std::string phdr_name = fullname;
775 phdr_name +=
"/Level_";
777 phdr_name +=
"/Particle_H";
780 have_pheaders =
true;
787 for (
int lev = 0; lev <= finestLevel(); lev++)
789 old_dms[lev] = ParticleDistributionMap(lev);
790 old_bas[lev] = ParticleBoxArray(lev);
791 std::string phdr_name = fullname;
792 phdr_name +=
"/Level_";
794 phdr_name +=
"/Particle_H";
800 std::string phdr_string(phdr_chars.
dataPtr());
801 std::istringstream phdr_file(phdr_string, std::istringstream::in);
803 particle_box_arrays[lev].readFrom(phdr_file);
804 if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) { dual_grid =
true; }
812 for (
int lev = 0; lev <= finestLevel(); lev++) {
814 if (particle_box_arrays[lev].empty()) {
815 particle_box_arrays[lev] =
BoxArray(Geom(lev).Domain());
817 SetParticleBoxArray(lev, particle_box_arrays[lev]);
819 SetParticleDistributionMap(lev, pdm);
823 Vector<int> ngrids(finest_level_in_file+1);
824 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
825 HdrFile >> ngrids[lev];
831 if (finest_level_in_file > finestLevel()) {
832 m_particles.resize(finest_level_in_file+1);
835 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
839 for (
int i = 0; i < ngrids[lev]; i++) {
840 HdrFile >> which[i] >> count[i] >> where[i];
844 if (lev <= finestLevel()) {
846 grids_to_read.push_back(mfi.index());
854 const int NReaders = MaxReaders();
855 if (rank >= NReaders) {
return; }
857 const int Navg = ngrids[lev] / NReaders;
858 const int Nleft = ngrids[lev] - Navg * NReaders;
862 lo = rank*(Navg + 1);
866 lo = rank * Navg + Nleft;
870 for (
int i = lo; i < hi; ++i) {
871 grids_to_read.push_back(i);
875 for(
int grid : grids_to_read) {
876 if (count[grid] <= 0) {
continue; }
879 std::string
name = fullname;
881 if (!
name.empty() && name[
name.size()-1] !=
'/') {
888 name += DataPrefix();
891 std::ifstream ParticleFile;
893 ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary);
895 if (!ParticleFile.good()) {
899 ParticleFile.seekg(where[grid], std::ios::beg);
904 if (how ==
"single") {
905 if constexpr (std::is_same_v<ParticleReal, float>) {
906 ReadParticles<float>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
908 amrex::Error(
"File contains single-precision data, while AMReX is compiled with ParticleReal==double");
911 else if (how ==
"double") {
912 if constexpr (std::is_same_v<ParticleReal, double>) {
913 ReadParticles<double>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
915 amrex::Error(
"File contains double-precision data, while AMReX is compiled with ParticleReal==float");
919 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
924 ParticleFile.close();
926 if (!ParticleFile.good()) {
927 amrex::Abort(
"ParticleContainer::Restart(): problem reading particles");
933 for (
int lev = 0; lev <= finestLevel(); lev++) {
934 SetParticleBoxArray(lev, old_bas[lev]);
935 SetParticleDistributionMap(lev, old_dms[lev]);
946 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
951template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
952 template<
class>
class Allocator,
class CellAssignor>
953template <
class RTYPE>
955ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
956::ReadParticles (
int cnt,
int grd,
int lev, std::ifstream& ifs,
957 int finest_level_in_file,
bool convert_ids)
959 BL_PROFILE(
"ParticleContainer::ReadParticles()");
966 const int iChunkSize = 2 + NStructInt + NumIntComps();
971 const int rChunkSize = ParticleType::is_soa_particle ? NStructReal + NumRealComps() : AMREX_SPACEDIM + NStructReal + NumRealComps();
973 ReadParticleRealData(rstuff.dataPtr(), rstuff.size(), ifs);
976 int* iptr = istuff.dataPtr();
977 RTYPE* rptr = rstuff.dataPtr();
983 host_particles.reserve(15);
984 host_particles.resize(finest_level_in_file+1);
987 std::vector<Gpu::HostVector<RTYPE> > > > host_real_attribs;
988 host_real_attribs.reserve(15);
989 host_real_attribs.resize(finest_level_in_file+1);
992 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
993 host_int_attribs.reserve(15);
994 host_int_attribs.resize(finest_level_in_file+1);
997 host_idcpu.reserve(15);
998 host_idcpu.resize(finestLevel()+1);
1000 for (
int i = 0; i < cnt; i++) {
1004 std::int32_t xi, yi;
1005 std::uint32_t xu, yu;
1008 std::memcpy(&xu, &xi,
sizeof(xi));
1009 std::memcpy(&yu, &yi,
sizeof(yi));
1010 ptemp.
m_idcpu = ((std::uint64_t)xu) << 32 | yu;
1012 ptemp.
id() = iptr[0];
1013 ptemp.
cpu() = iptr[1];
1017 for (
int j = 0; j < NStructInt; j++)
1019 ptemp.
idata(j) = *iptr;
1029 rptr += AMREX_SPACEDIM;
1031 for (
int j = 0; j < NStructReal; j++)
1037 locateParticle(ptemp, pld, 0, finestLevel(), 0);
1039 std::pair<int, int> ind(grd, pld.
m_tile);
1041 host_real_attribs[lev][ind].resize(NumRealComps());
1042 host_int_attribs[lev][ind].resize(NumIntComps());
1045 if constexpr(!ParticleType::is_soa_particle)
1047 host_particles[lev][ind].push_back(ptemp);
1050 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
1051 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1056 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1057 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1061 host_particles[lev][ind];
1063 for (
int j = 0; j < AMREX_SPACEDIM; j++) {
1064 host_real_attribs[lev][ind][j].push_back(ptemp.
pos(j));
1067 host_idcpu[lev][ind].push_back(ptemp.
m_idcpu);
1071 for (
int icomp = AMREX_SPACEDIM; icomp < NumRealComps(); icomp++) {
1072 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1077 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1078 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1084 for (
int host_lev = 0; host_lev < static_cast<int>(host_particles.
size()); ++host_lev)
1086 for (
auto& kv : host_particles[host_lev]) {
1087 auto grid = kv.first.first;
1088 auto tile = kv.first.second;
1089 const auto& src_tile = kv.second;
1091 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1092 auto old_size = dst_tile.size();
1093 auto new_size = old_size;
1094 if constexpr(!ParticleType::is_soa_particle)
1096 new_size += src_tile.size();
1099 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1101 dst_tile.resize(new_size);
1103 if constexpr(!ParticleType::is_soa_particle)
1106 dst_tile.GetArrayOfStructs().begin() + old_size);
1109 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
1110 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
1111 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1114 for (
int i = 0; i < NumRealComps(); ++i) {
1116 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1117 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1118 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1121 for (
int i = 0; i < NumIntComps(); ++i) {
1123 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1124 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1125 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1133template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1134 template<
class>
class Allocator,
class CellAssignor>
1136ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1137::WriteAsciiFile (
const std::string& filename)
1139 BL_PROFILE(
"ParticleContainer::WriteAsciiFile()");
1146 Long nparticles = 0;
1148 for (
int lev = 0; lev < m_particles.size(); lev++) {
1149 auto& pmap = m_particles[lev];
1150 for (
const auto& kv : pmap) {
1151 const auto& aos = kv.second.GetArrayOfStructs();
1152 auto np = aos.numParticles();
1155 for (
int k = 0; k < np; ++k) {
1157 if (p.id().is_valid()) {
1179 File.open(filename.c_str(), std::ios::out|std::ios::trunc);
1185 File << nparticles <<
'\n';
1186 File << NStructReal <<
'\n';
1187 File << NStructInt <<
'\n';
1188 File << NumRealComps() <<
'\n';
1189 File << NumIntComps() <<
'\n';
1196 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1215 File.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
1217 File.open(filename.c_str(), std::ios::out|std::ios::app);
1225 for (
int lev = 0; lev < m_particles.size(); lev++) {
1226 auto& pmap = m_particles[lev];
1227 for (
const auto& kv : pmap) {
1230 pinned_ptile.define(NumRuntimeRealComps(), NumRuntimeIntComps(),
1232 pinned_ptile.resize(kv.second.numParticles());
1234 const auto& host_aos = pinned_ptile.GetArrayOfStructs();
1235 const auto& host_soa = pinned_ptile.GetStructOfArrays();
1237 auto np = host_aos.numParticles();
1238 for (
int index = 0; index < np; ++index) {
1240 if (it->id().is_valid()) {
1244 << it->pos(1) <<
' ',
1245 << it->pos(2) <<
' ');
1247 for (
int i = 0; i < NStructReal; i++) {
1248 File << it->rdata(i) <<
' ';
1251 File << it->id() <<
' ';
1252 File << it->cpu() <<
' ';
1254 for (
int i = 0; i < NStructInt; i++) {
1255 File << it->idata(i) <<
' ';
1259 for (
int i = 0; i < NumRealComps(); i++) {
1260 File << host_soa.GetRealData(i)[index] <<
' ';
1263 for (
int i = 0; i < NumIntComps(); i++) {
1264 File << host_soa.GetIntData(i)[index] <<
' ';
1278 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1292 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
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:567
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:63
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:147
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:345
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:1395
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:148
typename SoA::IntVector IntVector
Definition AMReX_ParticleContainer.H:196
T_ParticleType ParticleType
Definition AMReX_ParticleContainer.H:150
Definition AMReX_GpuAllocators.H:144
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
@ 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:579
static bool GetNoFlushAfterWrite()
Definition AMReX_VisMF.H:283
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:113
int MyProc() noexcept
Definition AMReX_ParallelDescriptor.H:126
void Barrier(const std::string &)
Definition AMReX_ParallelDescriptor.cpp:1211
void ReduceIntSum(int &)
Definition AMReX_ParallelDescriptor.cpp:1261
void ReadAndBcastFile(const std::string &filename, Vector< char > &charBuf, bool bExitOnError, const MPI_Comm &comm)
Definition AMReX_ParallelDescriptor.cpp:1491
int NProcs() noexcept
Definition AMReX_ParallelDescriptor.H:246
void ReduceLongSum(Long &)
Definition AMReX_ParallelDescriptor.cpp:1232
void ReduceLongMax(Long &)
Definition AMReX_ParallelDescriptor.cpp:1233
bool IOProcessor() noexcept
Is this CPU the I/O Processor? To get the rank number, call IOProcessorNumber()
Definition AMReX_ParallelDescriptor.H:281
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: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:263
std::string const & name()
Definition AMReX_Machine.cpp:46
int IOProcessorNumber() noexcept
Definition AMReX_ParallelDescriptor.H:271
void ReduceRealMax(Vector< std::reference_wrapper< Real > > const &)
Definition AMReX_ParallelDescriptor.cpp:1224
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
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:138
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:467
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:161
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: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:34
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:126
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:224
Arena * The_Pinned_Arena()
Definition AMReX_Arena.cpp:823
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
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:765
__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:36
Definition AMReX_ParticleIO.H:38
__host__ __device__ int operator()(const P &p) const
Definition AMReX_ParticleIO.H:41
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: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:92
int m_tile
Definition AMReX_ParticleContainer.H:95
Definition AMReX_ParticleTile.H:721
The struct used to store particles.
Definition AMReX_Particle.H:404
__host__ __device__ RealVect pos() const &
Definition AMReX_Particle.H:454
__host__ __device__ int & idata(int index) &
Definition AMReX_Particle.H:543
__host__ __device__ ParticleCPUWrapper cpu() &
Definition AMReX_Particle.H:422
__host__ __device__ ParticleIDWrapper id() &
Definition AMReX_Particle.H:425
__host__ __device__ RealType & rdata(int index) &
Definition AMReX_Particle.H:472