1 #ifndef AMREX_PARTICLEIO_H
2 #define AMREX_PARTICLEIO_H
3 #include <AMReX_Config.H>
7 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
8 template<
class>
class Allocator,
class CellAssignor>
10 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
11 ::WriteParticleRealData (
void* data,
size_t size, std::ostream& os)
const
13 if (
sizeof(
typename ParticleType::RealType) == 4) {
16 else if (
sizeof(
typename ParticleType::RealType) == 8) {
21 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
22 template<
class>
class Allocator,
class CellAssignor>
27 if (
sizeof(
typename ParticleType::RealType) == 4) {
30 else if (
sizeof(
typename ParticleType::RealType) == 8) {
43 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
44 template<
class>
class Allocator,
class CellAssignor>
46 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
47 ::Checkpoint (
const std::string& dir,
48 const std::string& name,
bool ,
49 const Vector<std::string>& real_comp_names,
50 const Vector<std::string>& int_comp_names)
const
52 Vector<int> write_real_comp;
53 Vector<std::string> tmp_real_comp_names;
55 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
56 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
58 write_real_comp.push_back(1);
59 if (real_comp_names.empty())
61 tmp_real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
65 tmp_real_comp_names.push_back(real_comp_names[i-first_rcomp]);
69 Vector<int> write_int_comp;
70 Vector<std::string> tmp_int_comp_names;
71 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
73 write_int_comp.push_back(1);
74 if (int_comp_names.empty())
76 tmp_int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
80 tmp_int_comp_names.push_back(int_comp_names[i]);
84 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
85 tmp_real_comp_names, tmp_int_comp_names,
89 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
90 template<
class>
class Allocator,
class CellAssignor>
98 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
99 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
101 write_real_comp.push_back(1);
102 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
107 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
109 write_int_comp.push_back(1);
110 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
113 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
114 real_comp_names, int_comp_names,
118 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
119 template<
class>
class Allocator,
class CellAssignor>
126 if constexpr(ParticleType::is_soa_particle) {
134 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
135 for (
int i = 0; i < nrc; ++i) {
136 write_real_comp.push_back(1);
140 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
141 write_int_comp.push_back(1);
144 WriteBinaryParticleData(dir, name,
145 write_real_comp, write_int_comp,
146 real_comp_names, int_comp_names,
150 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
151 template<
class>
class Allocator,
class CellAssignor>
157 if constexpr(ParticleType::is_soa_particle) {
164 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
165 for (
int i = 0; i < nrc; ++i) {
166 write_real_comp.push_back(1);
170 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
171 write_int_comp.push_back(1);
175 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
177 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
180 WriteBinaryParticleData(dir, name,
181 write_real_comp, write_int_comp,
182 real_comp_names, int_comp_names,
186 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
187 template<
class>
class Allocator,
class CellAssignor>
191 const std::string& name,
196 if constexpr(ParticleType::is_soa_particle) {
204 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
205 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
207 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
211 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
213 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
216 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
217 real_comp_names, int_comp_names,
221 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
222 template<
class>
class Allocator,
class CellAssignor>
225 WritePlotFile (
const std::string& dir,
const std::string& name,
231 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
233 WriteBinaryParticleData(dir, name,
234 write_real_comp, write_int_comp,
235 real_comp_names, int_comp_names,
239 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
240 template<
class>
class Allocator,
class CellAssignor>
241 template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
249 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
250 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
252 write_real_comp.push_back(1);
253 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
258 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
260 write_int_comp.push_back(1);
261 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
264 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
265 real_comp_names, int_comp_names,
269 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
270 template<
class>
class Allocator,
class CellAssignor>
278 if constexpr(ParticleType::is_soa_particle) {
286 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
287 for (
int i = 0; i < nrc; ++i) {
288 write_real_comp.push_back(1);
292 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
293 write_int_comp.push_back(1);
296 WriteBinaryParticleData(dir, name,
297 write_real_comp, write_int_comp,
298 real_comp_names, int_comp_names,
302 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
303 template<
class>
class Allocator,
class CellAssignor>
304 template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
310 if constexpr(ParticleType::is_soa_particle) {
317 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
318 for (
int i = 0; i < nrc; ++i) {
319 write_real_comp.push_back(1);
323 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
324 write_int_comp.push_back(1);
328 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
330 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
333 WriteBinaryParticleData(dir, name,
334 write_real_comp, write_int_comp,
335 real_comp_names, int_comp_names,
339 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
340 template<
class>
class Allocator,
class CellAssignor>
345 const std::string& name,
349 if constexpr(ParticleType::is_soa_particle) {
357 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
358 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
360 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
364 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
366 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
369 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
370 real_comp_names, int_comp_names,
374 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
375 template<
class>
class Allocator,
class CellAssignor>
379 WritePlotFile (
const std::string& dir,
const std::string& name,
386 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
388 WriteBinaryParticleData(dir, name,
389 write_real_comp, write_int_comp,
390 real_comp_names, int_comp_names,
394 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
395 template<
class>
class Allocator,
class CellAssignor>
404 F&&
f,
bool is_checkpoint)
const
408 write_real_comp, write_int_comp,
409 real_comp_names, int_comp_names, is_checkpoint);
413 write_real_comp, write_int_comp,
414 real_comp_names, int_comp_names,
415 std::forward<F>(
f), is_checkpoint);
419 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
420 template<
class>
class Allocator,
class CellAssignor>
429 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
433 Long maxnextid = ParticleType::NextID();
435 for (
int lev = 0; lev < m_particles.size(); lev++) {
436 const auto& pmap = m_particles[lev];
437 for (
const auto& kv : pmap) {
438 const auto& aos = kv.second.GetArrayOfStructs();
439 for (
int k = 0; k < aos.numParticles(); ++k) {
452 ParticleType::NextID(maxnextid);
455 nparticlesPrePost = nparticles;
456 maxnextidPrePost =
int(maxnextid);
458 nParticlesAtLevelPrePost.clear();
459 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
460 for(
int lev(0); lev <= finestLevel(); ++lev) {
461 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
464 whichPrePost.clear();
465 whichPrePost.resize(finestLevel() + 1);
466 countPrePost.clear();
467 countPrePost.resize(finestLevel() + 1);
468 wherePrePost.clear();
469 wherePrePost.resize(finestLevel() + 1);
471 filePrefixPrePost.clear();
472 filePrefixPrePost.resize(finestLevel() + 1);
476 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
477 template<
class>
class Allocator,
class CellAssignor>
486 BL_PROFILE(
"ParticleContainer::CheckpointPost()");
489 std::ofstream HdrFile;
490 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
492 for(
int lev(0); lev <= finestLevel(); ++lev) {
499 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
500 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
503 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
504 if(gotsome && doUnlink) {
509 for(
int i(0), N = countPrePost[lev].
size(); i < N; ++i) {
510 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
513 for(
int i(0), N =
int(cnt.
size()); i < N; ++i) {
515 std::string FullFileName = NFilesIter::FileName(i, filePrefixPrePost[lev]);
526 if( ! HdrFile.good()) {
527 amrex::Abort(
"ParticleContainer::CheckpointPost(): problem writing HdrFile");
532 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
533 template<
class>
class Allocator,
class CellAssignor>
542 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
543 template<
class>
class Allocator,
class CellAssignor>
552 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
553 template<
class>
class Allocator,
class CellAssignor>
560 const Vector<std::map<std::pair<int, int>,
IntVector>>& particle_io_flags,
561 bool is_checkpoint)
const
563 BL_PROFILE(
"ParticleContainer::WriteParticles()");
566 std::map<int, Vector<int> > tile_map;
568 for (
const auto& kv : m_particles[lev])
570 const int grid = kv.first.first;
571 const int tile = kv.first.second;
572 tile_map[grid].push_back(tile);
573 const auto& pflags = particle_io_flags[lev].at(kv.first);
581 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
585 const int grid = mfi.index();
588 where[grid] = VisMF::FileOffset(ofs);
590 if (count[grid] == 0) {
continue; }
595 write_real_comp, write_int_comp,
596 particle_io_flags, tile_map[grid], count[grid], is_checkpoint);
601 WriteParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ofs);
607 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
608 template<
class>
class Allocator,
class CellAssignor>
611 ::Restart (
const std::string& dir,
const std::string& file,
bool )
616 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
617 template<
class>
class Allocator,
class CellAssignor>
619 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
620 ::Restart (
const std::string& dir,
const std::string& file)
628 int DATA_Digits_Read(5);
630 pp.
query(
"datadigits_read",DATA_Digits_Read);
632 std::string fullname = dir;
633 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
637 std::string HdrFileName = fullname;
638 if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] !=
'/') {
641 HdrFileName +=
"Header";
645 std::string fileCharPtrString(fileCharPtr.
dataPtr());
646 std::istringstream HdrFile(fileCharPtrString, std::istringstream::in);
660 bool convert_ids =
false;
661 if (version.find(
"Version_Two_Dot_One") != std::string::npos) {
664 if (version.find(
"Version_One_Dot_Zero") != std::string::npos) {
667 else if (version.find(
"Version_One_Dot_One") != std::string::npos ||
668 version.find(
"Version_Two_Dot_Zero") != std::string::npos ||
669 version.find(
"Version_Two_Dot_One") != std::string::npos) {
670 if (version.find(
"_single") != std::string::npos) {
673 else if (version.find(
"_double") != std::string::npos) {
677 std::string msg(
"ParticleContainer::Restart(): bad version string: ");
683 std::string msg(
"ParticleContainer::Restart(): unknown version string: ");
690 if (dm != AMREX_SPACEDIM) {
691 amrex::Abort(
"ParticleContainer::Restart(): dm != AMREX_SPACEDIM");
696 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
698 amrex::Abort(
"ParticleContainer::Restart(): nr not the expected value");
701 std::string comp_name;
702 for (
int i = 0; i < nr; ++i) {
703 HdrFile >> comp_name;
708 if (ni != NStructInt + NumIntComps()) {
709 amrex::Abort(
"ParticleContainer::Restart(): ni != NStructInt");
712 for (
int i = 0; i < ni; ++i) {
713 HdrFile >> comp_name;
717 HdrFile >> checkpoint;
720 HdrFile >> nparticles;
724 HdrFile >> maxnextid;
726 ParticleType::NextID(maxnextid);
728 int finest_level_in_file;
729 HdrFile >> finest_level_in_file;
736 bool dual_grid =
false;
738 bool have_pheaders =
false;
739 for (
int lev = 0; lev <= finest_level_in_file; lev++)
741 std::string phdr_name = fullname;
742 phdr_name +=
"/Level_";
744 phdr_name +=
"/Particle_H";
747 have_pheaders =
true;
754 for (
int lev = 0; lev <= finestLevel(); lev++)
756 old_dms[lev] = ParticleDistributionMap(lev);
757 old_bas[lev] = ParticleBoxArray(lev);
758 std::string phdr_name = fullname;
759 phdr_name +=
"/Level_";
761 phdr_name +=
"/Particle_H";
765 Vector<char> phdr_chars;
767 std::string phdr_string(phdr_chars.dataPtr());
768 std::istringstream phdr_file(phdr_string, std::istringstream::in);
770 particle_box_arrays[lev].readFrom(phdr_file);
771 if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) { dual_grid =
true; }
779 for (
int lev = 0; lev <= finestLevel(); lev++) {
781 if (particle_box_arrays[lev].empty()) {
782 particle_box_arrays[lev] = BoxArray(Geom(lev).Domain());
784 SetParticleBoxArray(lev, particle_box_arrays[lev]);
785 DistributionMapping pdm(particle_box_arrays[lev]);
786 SetParticleDistributionMap(lev, pdm);
790 Vector<int> ngrids(finest_level_in_file+1);
791 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
792 HdrFile >> ngrids[lev];
798 if (finest_level_in_file > finestLevel()) {
799 m_particles.resize(finest_level_in_file+1);
802 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
806 for (
int i = 0; i < ngrids[lev]; i++) {
807 HdrFile >> which[i] >> count[i] >> where[i];
811 if (lev <= finestLevel()) {
813 grids_to_read.push_back(mfi.index());
821 const int NReaders = MaxReaders();
822 if (rank >= NReaders) {
return; }
824 const int Navg = ngrids[lev] / NReaders;
825 const int Nleft = ngrids[lev] - Navg * NReaders;
829 lo = rank*(Navg + 1);
833 lo = rank * Navg + Nleft;
837 for (
int i = lo; i < hi; ++i) {
838 grids_to_read.push_back(i);
842 for(
int grid : grids_to_read) {
843 if (count[grid] <= 0) {
continue; }
846 std::string name = fullname;
848 if (!name.empty() && name[name.size()-1] !=
'/') {
855 name += DataPrefix();
858 std::ifstream ParticleFile;
860 ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary);
862 if (!ParticleFile.good()) {
866 ParticleFile.seekg(where[grid], std::ios::beg);
871 if (how ==
"single") {
872 if constexpr (std::is_same_v<ParticleReal, float>) {
873 ReadParticles<float>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
875 amrex::Error(
"File contains single-precision data, while AMReX is compiled with ParticleReal==double");
878 else if (how ==
"double") {
879 if constexpr (std::is_same_v<ParticleReal, double>) {
880 ReadParticles<double>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
882 amrex::Error(
"File contains double-precision data, while AMReX is compiled with ParticleReal==float");
886 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
891 ParticleFile.close();
893 if (!ParticleFile.good()) {
894 amrex::Abort(
"ParticleContainer::Restart(): problem reading particles");
900 for (
int lev = 0; lev <= finestLevel(); lev++) {
901 SetParticleBoxArray(lev, old_bas[lev]);
902 SetParticleDistributionMap(lev, old_dms[lev]);
913 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
918 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
919 template<
class>
class Allocator,
class CellAssignor>
920 template <
class RTYPE>
922 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
923 ::ReadParticles (
int cnt,
int grd,
int lev, std::ifstream& ifs,
924 int finest_level_in_file,
bool convert_ids)
926 BL_PROFILE(
"ParticleContainer::ReadParticles()");
933 const int iChunkSize = 2 + NStructInt + NumIntComps();
938 const int rChunkSize = ParticleType::is_soa_particle ? NStructReal + NumRealComps() : AMREX_SPACEDIM + NStructReal + NumRealComps();
940 ReadParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ifs);
944 RTYPE* rptr = rstuff.
dataPtr();
950 host_particles.reserve(15);
951 host_particles.resize(finest_level_in_file+1);
954 std::vector<Gpu::HostVector<RTYPE> > > > host_real_attribs;
955 host_real_attribs.reserve(15);
956 host_real_attribs.resize(finest_level_in_file+1);
959 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
960 host_int_attribs.reserve(15);
961 host_int_attribs.resize(finest_level_in_file+1);
964 host_idcpu.reserve(15);
965 host_idcpu.resize(finestLevel()+1);
967 for (
int i = 0; i < cnt; i++) {
972 std::uint32_t xu, yu;
977 ptemp.
m_idcpu = ((std::uint64_t)xu) << 32 | yu;
979 ptemp.
id() = iptr[0];
984 for (
int j = 0; j < NStructInt; j++)
986 ptemp.
idata(j) = *iptr;
993 ptemp.
pos(1) = ParticleReal(rptr[1]);,
994 ptemp.
pos(2) = ParticleReal(rptr[2]););
996 rptr += AMREX_SPACEDIM;
998 for (
int j = 0; j < NStructReal; j++)
1000 ptemp.
rdata(j) = ParticleReal(*rptr);
1004 locateParticle(ptemp, pld, 0, finestLevel(), 0);
1006 std::pair<int, int> ind(grd, pld.
m_tile);
1008 host_real_attribs[lev][ind].resize(NumRealComps());
1009 host_int_attribs[lev][ind].resize(NumIntComps());
1012 if constexpr(!ParticleType::is_soa_particle)
1014 host_particles[lev][ind].push_back(ptemp);
1017 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
1018 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1023 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1024 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1028 host_particles[lev][ind];
1030 for (
int j = 0; j < AMREX_SPACEDIM; j++) {
1031 host_real_attribs[pld.
m_lev][ind][j].push_back(ptemp.
pos(j));
1038 for (
int icomp = AMREX_SPACEDIM; icomp < NumRealComps(); icomp++) {
1039 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1044 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1045 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1051 for (
int host_lev = 0; host_lev < static_cast<int>(host_particles.
size()); ++host_lev)
1053 for (
auto& kv : host_particles[host_lev]) {
1054 auto grid = kv.first.first;
1055 auto tile = kv.first.second;
1056 const auto& src_tile = kv.second;
1058 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1059 auto old_size = dst_tile.size();
1060 auto new_size = old_size;
1061 if constexpr(!ParticleType::is_soa_particle)
1063 new_size += src_tile.size();
1066 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1068 dst_tile.resize(new_size);
1070 if constexpr(!ParticleType::is_soa_particle)
1073 dst_tile.GetArrayOfStructs().begin() + old_size);
1076 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
1077 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
1078 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1081 for (
int i = 0; i < NumRealComps(); ++i) {
1083 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1084 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1085 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1088 for (
int i = 0; i < NumIntComps(); ++i) {
1090 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1091 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1092 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1100 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1101 template<
class>
class Allocator,
class CellAssignor>
1103 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1104 ::WriteAsciiFile (
const std::string& filename)
1106 BL_PROFILE(
"ParticleContainer::WriteAsciiFile()");
1113 Long nparticles = 0;
1115 for (
int lev = 0; lev < m_particles.size(); lev++) {
1116 auto& pmap = m_particles[lev];
1117 for (
const auto& kv : pmap) {
1118 const auto& aos = kv.second.GetArrayOfStructs();
1119 auto np = aos.numParticles();
1122 for (
int k = 0; k < np; ++k) {
1146 File.open(filename.c_str(), std::ios::out|std::ios::trunc);
1152 File << nparticles <<
'\n';
1153 File << NStructReal <<
'\n';
1154 File << NStructInt <<
'\n';
1155 File << NumRealComps() <<
'\n';
1156 File << NumIntComps() <<
'\n';
1163 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1182 File.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
1184 File.open(filename.c_str(), std::ios::out|std::ios::app);
1192 for (
int lev = 0; lev < m_particles.size(); lev++) {
1193 auto& pmap = m_particles[lev];
1194 for (
const auto& kv : pmap) {
1197 pinned_ptile.define(NumRuntimeRealComps(), NumRuntimeIntComps());
1198 pinned_ptile.resize(kv.second.numParticles());
1200 const auto& host_aos = pinned_ptile.GetArrayOfStructs();
1201 const auto& host_soa = pinned_ptile.GetStructOfArrays();
1203 auto np = host_aos.numParticles();
1204 for (
int index = 0; index < np; ++index) {
1210 << it->pos(1) <<
' ',
1211 << it->pos(2) <<
' ');
1213 for (
int i = 0; i < NStructReal; i++) {
1214 File << it->rdata(i) <<
' ';
1217 File << it->id() <<
' ';
1218 File << it->cpu() <<
' ';
1220 for (
int i = 0; i < NStructInt; i++) {
1221 File << it->idata(i) <<
' ';
1225 for (
int i = 0; i < NumRealComps(); i++) {
1226 File << host_soa.GetRealData(i)[index] <<
' ';
1229 for (
int i = 0; i < NumIntComps(); i++) {
1230 File << host_soa.GetIntData(i)[index] <<
' ';
1244 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1258 amrex::Print() <<
"ParticleContainer::WriteAsciiFile() time: " << stoptime <<
'\n';
#define BL_PROFILE(a)
Definition: AMReX_BLProfiler.H:551
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition: AMReX_BLassert.H:50
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
amrex::ParmParse pp
Input file parser instance for the given namespace.
Definition: AMReX_HypreIJIface.cpp:15
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
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:684
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:392
Definition: AMReX_MFIter.H:57
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition: AMReX_MFIter.H:141
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
Definition: AMReX_PODVector.H:246
iterator begin() noexcept
Definition: AMReX_PODVector.H:601
Parse Parameters From Command Line and Input Files.
Definition: AMReX_ParmParse.H:320
int query(const char *name, bool &ref, int ival=FIRST) const
Same as querykth() but searches for the last occurrence of name.
Definition: AMReX_ParmParse.cpp:1309
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition: AMReX_ParticleContainer.H:145
typename SoA::IntVector IntVector
Definition: AMReX_ParticleContainer.H:191
T_ParticleType ParticleType
Definition: AMReX_ParticleContainer.H:147
Definition: AMReX_GpuAllocators.H:126
This class provides the user with a few print options.
Definition: AMReX_Print.H:35
Long size() const noexcept
Definition: AMReX_Vector.H:50
T * dataPtr() noexcept
get access to the underlying data pointer
Definition: AMReX_Vector.H:46
bool UseAsyncOut()
Definition: AMReX_AsyncOut.cpp:70
bool Remove(std::string const &filename)
Definition: AMReX_FileSystem.cpp:190
AMREX_GPU_HOST_DEVICE Long size(T const &b) noexcept
integer version
Definition: AMReX_GpuRange.H:26
void copy(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:121
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:233
static constexpr DeviceToHost deviceToHost
Definition: AMReX_GpuContainers.H:99
static constexpr HostToDevice hostToDevice
Definition: AMReX_GpuContainers.H:98
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void * memcpy(void *dest, const void *src, std::size_t count)
Definition: AMReX_GpuUtility.H:214
int NProcs()
Process ID in MPI_COMM_WORLD.
Definition: AMReX_MPMD.cpp:122
int MyProc()
Definition: AMReX_MPMD.cpp:117
void ReduceIntSum(int &)
Integer sum reduction.
Definition: AMReX_ParallelDescriptor.cpp:1252
void ReadAndBcastFile(const std::string &filename, Vector< char > &charBuf, bool bExitOnError, const MPI_Comm &comm)
Definition: AMReX_ParallelDescriptor.cpp:1459
void ReduceLongMax(Long &)
Long max reduction.
Definition: AMReX_ParallelDescriptor.cpp:1224
void ReduceLongSum(Long &)
Long sum reduction.
Definition: AMReX_ParallelDescriptor.cpp:1223
int IOProcessorNumber() noexcept
Definition: AMReX_ParallelDescriptor.H:266
void Barrier(const std::string &)
Definition: AMReX_ParallelDescriptor.cpp:1202
bool IOProcessor() noexcept
Is this CPU the I/O Processor? To get the rank number, call IOProcessorNumber()
Definition: AMReX_ParallelDescriptor.H:275
void ReduceRealMax(Vector< std::reference_wrapper< Real > > const &)
Definition: AMReX_ParallelDescriptor.cpp:1215
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
static constexpr int P
Definition: AMReX_OpenBC.H:14
void writeIntData(const From *data, std::size_t size, std::ostream &os, const amrex::IntDescriptor &id)
Definition: AMReX_IntConv.H:23
void FileOpenFailed(const std::string &file)
Output a message and abort when couldn't open the file.
Definition: AMReX_Utility.cpp:131
void copyParticles(DstTile &dst, const SrcTile &src) noexcept
Copy particles from src to dst. This version copies all the particles, writing them to the beginning ...
Definition: AMReX_ParticleTransformation.H:158
void readFloatData(float *data, std::size_t size, std::istream &is, const RealDescriptor &rd)
Definition: AMReX_VectorIO.cpp:120
void WritePlotFile(const Vector< MultiFab * > &mfa, const Vector< Box > &probDomain, AmrData &amrdToMimic, const std::string &oFile, bool verbose, const Vector< std::string > &varNames)
Definition: AMReX_WritePlotFile.cpp:292
void writeFloatData(const float *data, std::size_t size, std::ostream &os, const RealDescriptor &rd=FPC::Native32RealDescriptor())
Definition: AMReX_VectorIO.cpp:114
bool FileExists(const std::string &filename)
Check if a file already exists. Return true if the filename is an existing file, directory,...
Definition: AMReX_Utility.cpp:139
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 end(BoxND< dim > const &box) noexcept
Definition: AMReX_Box.H:1890
std::string Concatenate(const std::string &root, int num, int mindigits)
Returns rootNNNN where NNNN == num.
Definition: AMReX_String.cpp:34
double second() noexcept
Definition: AMReX_Utility.cpp:922
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition: AMReX.H:111
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:219
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 begin(BoxND< dim > const &box) noexcept
Definition: AMReX_Box.H:1881
void readDoubleData(double *data, std::size_t size, std::istream &is, const RealDescriptor &rd)
Definition: AMReX_VectorIO.cpp:132
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
const int[]
Definition: AMReX_BLProfiler.cpp:1664
void readIntData(To *data, std::size_t size, std::istream &is, const amrex::IntDescriptor &id)
Definition: AMReX_IntConv.H:36
std::enable_if_t< RunOnGpu< typename PC::template AllocatorType< int > >::value > packIOData(Vector< int > &idata, Vector< ParticleReal > &rdata, const PC &pc, int lev, int grid, const Vector< int > &write_real_comp, const Vector< int > &write_int_comp, const Vector< std::map< std::pair< int, int >, typename PC::IntVector >> &particle_io_flags, const Vector< int > &tiles, int np, bool is_checkpoint)
Definition: AMReX_WriteBinaryParticleData.H:171
std::enable_if_t< RunOnGpu< typename Container< int, Allocator >::allocator_type >::value, amrex::Long > countFlags(const Vector< std::map< std::pair< int, int >, Container< int, Allocator >>> &particle_io_flags, const PC &pc)
Definition: AMReX_WriteBinaryParticleData.H:76
Definition: AMReX_ParticleIO.H:35
AMREX_GPU_HOST_DEVICE int operator()(const P &p) const
Definition: AMReX_ParticleIO.H:38
FabArray memory allocation information.
Definition: AMReX_FabArray.H:66
MFInfo & SetAlloc(bool a) noexcept
Definition: AMReX_FabArray.H:73
uint64_t m_idcpu
Definition: AMReX_Particle.H:252
A struct used for storing a particle's position in the AMR hierarchy.
Definition: AMReX_ParticleContainer.H:91
int m_tile
Definition: AMReX_ParticleContainer.H:94
int m_lev
Definition: AMReX_ParticleContainer.H:92
Definition: AMReX_ParticleTile.H:693
The struct used to store particles.
Definition: AMReX_Particle.H:295
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleIDWrapper id() &
Definition: AMReX_Particle.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealVect pos() const &
Definition: AMReX_Particle.H:338
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RealType & rdata(int index) &
Definition: AMReX_Particle.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int & idata(int index) &
Definition: AMReX_Particle.H:427
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ParticleCPUWrapper cpu() &
Definition: AMReX_Particle.H:312