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>
92 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
93 ::Checkpoint (
const std::string& dir,
const std::string& name,
99 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
100 real_comp_names, int_comp_names,
104 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
105 template<
class>
class Allocator,
class CellAssignor>
113 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
114 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
116 write_real_comp.push_back(1);
117 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
122 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
124 write_int_comp.push_back(1);
125 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
128 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
129 real_comp_names, int_comp_names,
133 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
134 template<
class>
class Allocator,
class CellAssignor>
141 if constexpr(ParticleType::is_soa_particle) {
149 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
150 for (
int i = 0; i < nrc; ++i) {
151 write_real_comp.push_back(1);
155 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
156 write_int_comp.push_back(1);
159 WriteBinaryParticleData(dir, name,
160 write_real_comp, write_int_comp,
161 real_comp_names, int_comp_names,
165 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
166 template<
class>
class Allocator,
class CellAssignor>
172 if constexpr(ParticleType::is_soa_particle) {
179 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
180 for (
int i = 0; i < nrc; ++i) {
181 write_real_comp.push_back(1);
185 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
186 write_int_comp.push_back(1);
190 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
192 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
195 WriteBinaryParticleData(dir, name,
196 write_real_comp, write_int_comp,
197 real_comp_names, int_comp_names,
201 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
202 template<
class>
class Allocator,
class CellAssignor>
206 const std::string& name,
211 if constexpr(ParticleType::is_soa_particle) {
219 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
220 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
222 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
226 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
228 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
231 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
232 real_comp_names, int_comp_names,
236 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
237 template<
class>
class Allocator,
class CellAssignor>
240 WritePlotFile (
const std::string& dir,
const std::string& name,
246 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
248 WriteBinaryParticleData(dir, name,
249 write_real_comp, write_int_comp,
250 real_comp_names, int_comp_names,
254 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
255 template<
class>
class Allocator,
class CellAssignor>
256 template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
264 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
265 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
267 write_real_comp.push_back(1);
268 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
273 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
275 write_int_comp.push_back(1);
276 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
279 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
280 real_comp_names, int_comp_names,
284 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
285 template<
class>
class Allocator,
class CellAssignor>
293 if constexpr(ParticleType::is_soa_particle) {
301 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
302 for (
int i = 0; i < nrc; ++i) {
303 write_real_comp.push_back(1);
307 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
308 write_int_comp.push_back(1);
311 WriteBinaryParticleData(dir, name,
312 write_real_comp, write_int_comp,
313 real_comp_names, int_comp_names,
317 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
318 template<
class>
class Allocator,
class CellAssignor>
319 template <
class F, std::enable_if_t<!std::is_same_v<std::decay_t<F>, Vector<std::
string>>>*>
325 if constexpr(ParticleType::is_soa_particle) {
332 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
333 for (
int i = 0; i < nrc; ++i) {
334 write_real_comp.push_back(1);
338 for (
int i = 0; i < NStructInt + NumIntComps(); ++i) {
339 write_int_comp.push_back(1);
343 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
345 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
348 WriteBinaryParticleData(dir, name,
349 write_real_comp, write_int_comp,
350 real_comp_names, int_comp_names,
354 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
355 template<
class>
class Allocator,
class CellAssignor>
360 const std::string& name,
364 if constexpr(ParticleType::is_soa_particle) {
372 int first_rcomp = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0;
373 for (
int i = first_rcomp; i < NStructReal + NumRealComps(); ++i )
375 real_comp_names.push_back(getDefaultCompNameReal<ParticleType>(i));
379 for (
int i = 0; i < NStructInt + NumIntComps(); ++i )
381 int_comp_names.push_back(getDefaultCompNameInt<ParticleType>(i));
384 WriteBinaryParticleData(dir, name, write_real_comp, write_int_comp,
385 real_comp_names, int_comp_names,
389 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
390 template<
class>
class Allocator,
class CellAssignor>
394 WritePlotFile (
const std::string& dir,
const std::string& name,
401 BL_PROFILE(
"ParticleContainer::WritePlotFile()");
403 WriteBinaryParticleData(dir, name,
404 write_real_comp, write_int_comp,
405 real_comp_names, int_comp_names,
409 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
410 template<
class>
class Allocator,
class CellAssignor>
419 F&&
f,
bool is_checkpoint)
const
423 write_real_comp, write_int_comp,
424 real_comp_names, int_comp_names, is_checkpoint);
428 write_real_comp, write_int_comp,
429 real_comp_names, int_comp_names,
430 std::forward<F>(
f), is_checkpoint);
434 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
435 template<
class>
class Allocator,
class CellAssignor>
444 BL_PROFILE(
"ParticleContainer::CheckpointPre()");
448 Long maxnextid = ParticleType::NextID();
450 for (
int lev = 0; lev < m_particles.size(); lev++) {
451 const auto& pmap = m_particles[lev];
452 for (
const auto& kv : pmap) {
453 const auto& aos = kv.second.GetArrayOfStructs();
454 for (
int k = 0; k < aos.numParticles(); ++k) {
467 ParticleType::NextID(maxnextid);
470 nparticlesPrePost = nparticles;
471 maxnextidPrePost =
int(maxnextid);
473 nParticlesAtLevelPrePost.clear();
474 nParticlesAtLevelPrePost.resize(finestLevel() + 1, 0);
475 for(
int lev(0); lev <= finestLevel(); ++lev) {
476 nParticlesAtLevelPrePost[lev] = NumberOfParticlesAtLevel(lev);
479 whichPrePost.clear();
480 whichPrePost.resize(finestLevel() + 1);
481 countPrePost.clear();
482 countPrePost.resize(finestLevel() + 1);
483 wherePrePost.clear();
484 wherePrePost.resize(finestLevel() + 1);
486 filePrefixPrePost.clear();
487 filePrefixPrePost.resize(finestLevel() + 1);
491 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
492 template<
class>
class Allocator,
class CellAssignor>
501 BL_PROFILE(
"ParticleContainer::CheckpointPost()");
504 std::ofstream HdrFile;
505 HdrFile.open(HdrFileNamePrePost.c_str(), std::ios::out | std::ios::app);
507 for(
int lev(0); lev <= finestLevel(); ++lev) {
514 for(
int j(0); j < whichPrePost[lev].size(); ++j) {
515 HdrFile << whichPrePost[lev][j] <<
' ' << countPrePost[lev][j] <<
' ' << wherePrePost[lev][j] <<
'\n';
518 const bool gotsome = (nParticlesAtLevelPrePost[lev] > 0);
519 if(gotsome && doUnlink) {
524 for(
int i(0), N = countPrePost[lev].
size(); i < N; ++i) {
525 cnt[whichPrePost[lev][i]] += countPrePost[lev][i];
528 for(
int i(0), N =
int(cnt.
size()); i < N; ++i) {
530 std::string FullFileName = NFilesIter::FileName(i, filePrefixPrePost[lev]);
541 if( ! HdrFile.good()) {
542 amrex::Abort(
"ParticleContainer::CheckpointPost(): problem writing HdrFile");
547 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
548 template<
class>
class Allocator,
class CellAssignor>
557 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
558 template<
class>
class Allocator,
class CellAssignor>
567 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
568 template<
class>
class Allocator,
class CellAssignor>
575 const Vector<std::map<std::pair<int, int>,
IntVector>>& particle_io_flags,
576 bool is_checkpoint)
const
578 BL_PROFILE(
"ParticleContainer::WriteParticles()");
581 std::map<int, Vector<int> > tile_map;
583 for (
const auto& kv : m_particles[lev])
585 const int grid = kv.first.first;
586 const int tile = kv.first.second;
587 tile_map[grid].push_back(tile);
588 const auto& pflags = particle_io_flags[lev].at(kv.first);
596 MultiFab state(ParticleBoxArray(lev), ParticleDistributionMap(lev), 1,0,info);
600 const int grid = mfi.index();
603 where[grid] = VisMF::FileOffset(ofs);
605 if (count[grid] == 0) {
continue; }
610 write_real_comp, write_int_comp,
611 particle_io_flags, tile_map[grid], count[grid], is_checkpoint);
616 WriteParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ofs);
622 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
623 template<
class>
class Allocator,
class CellAssignor>
626 ::Restart (
const std::string& dir,
const std::string& file,
bool )
631 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
632 template<
class>
class Allocator,
class CellAssignor>
634 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
635 ::Restart (
const std::string& dir,
const std::string& file)
643 int DATA_Digits_Read(5);
645 pp.
query(
"datadigits_read",DATA_Digits_Read);
647 std::string fullname = dir;
648 if (!fullname.empty() && fullname[fullname.size()-1] !=
'/') {
652 std::string HdrFileName = fullname;
653 if (!HdrFileName.empty() && HdrFileName[HdrFileName.size()-1] !=
'/') {
656 HdrFileName +=
"Header";
660 std::string fileCharPtrString(fileCharPtr.
dataPtr());
661 std::istringstream HdrFile(fileCharPtrString, std::istringstream::in);
675 bool convert_ids =
false;
676 if (version.find(
"Version_Two_Dot_One") != std::string::npos) {
679 if (version.find(
"Version_One_Dot_Zero") != std::string::npos) {
682 else if (version.find(
"Version_One_Dot_One") != std::string::npos ||
683 version.find(
"Version_Two_Dot_Zero") != std::string::npos ||
684 version.find(
"Version_Two_Dot_One") != std::string::npos) {
685 if (version.find(
"_single") != std::string::npos) {
688 else if (version.find(
"_double") != std::string::npos) {
692 std::string msg(
"ParticleContainer::Restart(): bad version string: ");
698 std::string msg(
"ParticleContainer::Restart(): unknown version string: ");
705 if (dm != AMREX_SPACEDIM) {
706 amrex::Abort(
"ParticleContainer::Restart(): dm != AMREX_SPACEDIM");
711 int nrc = ParticleType::is_soa_particle ? NStructReal + NumRealComps() - AMREX_SPACEDIM : NStructReal + NumRealComps();
713 amrex::Abort(
"ParticleContainer::Restart(): nr not the expected value");
716 std::string comp_name;
717 for (
int i = 0; i < nr; ++i) {
718 HdrFile >> comp_name;
723 if (ni != NStructInt + NumIntComps()) {
724 amrex::Abort(
"ParticleContainer::Restart(): ni != NStructInt");
727 for (
int i = 0; i < ni; ++i) {
728 HdrFile >> comp_name;
732 HdrFile >> checkpoint;
735 HdrFile >> nparticles;
739 HdrFile >> maxnextid;
741 ParticleType::NextID(maxnextid);
743 int finest_level_in_file;
744 HdrFile >> finest_level_in_file;
751 bool dual_grid =
false;
753 bool have_pheaders =
false;
754 for (
int lev = 0; lev <= finest_level_in_file; lev++)
756 std::string phdr_name = fullname;
757 phdr_name +=
"/Level_";
759 phdr_name +=
"/Particle_H";
762 have_pheaders =
true;
769 for (
int lev = 0; lev <= finestLevel(); lev++)
771 old_dms[lev] = ParticleDistributionMap(lev);
772 old_bas[lev] = ParticleBoxArray(lev);
773 std::string phdr_name = fullname;
774 phdr_name +=
"/Level_";
776 phdr_name +=
"/Particle_H";
780 Vector<char> phdr_chars;
782 std::string phdr_string(phdr_chars.dataPtr());
783 std::istringstream phdr_file(phdr_string, std::istringstream::in);
785 particle_box_arrays[lev].readFrom(phdr_file);
786 if (! particle_box_arrays[lev].CellEqual(ParticleBoxArray(lev))) { dual_grid =
true; }
794 for (
int lev = 0; lev <= finestLevel(); lev++) {
796 if (particle_box_arrays[lev].empty()) {
797 particle_box_arrays[lev] = BoxArray(Geom(lev).Domain());
799 SetParticleBoxArray(lev, particle_box_arrays[lev]);
800 DistributionMapping pdm(particle_box_arrays[lev]);
801 SetParticleDistributionMap(lev, pdm);
805 Vector<int> ngrids(finest_level_in_file+1);
806 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
807 HdrFile >> ngrids[lev];
813 if (finest_level_in_file > finestLevel()) {
814 m_particles.resize(finest_level_in_file+1);
817 for (
int lev = 0; lev <= finest_level_in_file; lev++) {
821 for (
int i = 0; i < ngrids[lev]; i++) {
822 HdrFile >> which[i] >> count[i] >> where[i];
826 if (lev <= finestLevel()) {
828 grids_to_read.push_back(mfi.index());
836 const int NReaders = MaxReaders();
837 if (rank >= NReaders) {
return; }
839 const int Navg = ngrids[lev] / NReaders;
840 const int Nleft = ngrids[lev] - Navg * NReaders;
844 lo = rank*(Navg + 1);
848 lo = rank * Navg + Nleft;
852 for (
int i = lo; i < hi; ++i) {
853 grids_to_read.push_back(i);
857 for(
int grid : grids_to_read) {
858 if (count[grid] <= 0) {
continue; }
861 std::string name = fullname;
863 if (!name.empty() && name[name.size()-1] !=
'/') {
870 name += DataPrefix();
873 std::ifstream ParticleFile;
875 ParticleFile.open(name.c_str(), std::ios::in | std::ios::binary);
877 if (!ParticleFile.good()) {
881 ParticleFile.seekg(where[grid], std::ios::beg);
886 if (how ==
"single") {
887 if constexpr (std::is_same_v<ParticleReal, float>) {
888 ReadParticles<float>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
890 amrex::Error(
"File contains single-precision data, while AMReX is compiled with ParticleReal==double");
893 else if (how ==
"double") {
894 if constexpr (std::is_same_v<ParticleReal, double>) {
895 ReadParticles<double>(count[grid], grid, lev, ParticleFile, finest_level_in_file, convert_ids);
897 amrex::Error(
"File contains double-precision data, while AMReX is compiled with ParticleReal==float");
901 std::string msg(
"ParticleContainer::Restart(): bad parameter: ");
906 ParticleFile.close();
908 if (!ParticleFile.good()) {
909 amrex::Abort(
"ParticleContainer::Restart(): problem reading particles");
915 for (
int lev = 0; lev <= finestLevel(); lev++) {
916 SetParticleBoxArray(lev, old_bas[lev]);
917 SetParticleDistributionMap(lev, old_dms[lev]);
928 amrex::Print() <<
"ParticleContainer::Restart() time: " << stoptime <<
'\n';
933 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
934 template<
class>
class Allocator,
class CellAssignor>
935 template <
class RTYPE>
937 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
938 ::ReadParticles (
int cnt,
int grd,
int lev, std::ifstream& ifs,
939 int finest_level_in_file,
bool convert_ids)
941 BL_PROFILE(
"ParticleContainer::ReadParticles()");
948 const int iChunkSize = 2 + NStructInt + NumIntComps();
953 const int rChunkSize = ParticleType::is_soa_particle ? NStructReal + NumRealComps() : AMREX_SPACEDIM + NStructReal + NumRealComps();
955 ReadParticleRealData(rstuff.
dataPtr(), rstuff.
size(), ifs);
959 RTYPE* rptr = rstuff.
dataPtr();
965 host_particles.reserve(15);
966 host_particles.resize(finest_level_in_file+1);
969 std::vector<Gpu::HostVector<RTYPE> > > > host_real_attribs;
970 host_real_attribs.reserve(15);
971 host_real_attribs.resize(finest_level_in_file+1);
974 std::vector<Gpu::HostVector<int> > > > host_int_attribs;
975 host_int_attribs.reserve(15);
976 host_int_attribs.resize(finest_level_in_file+1);
979 host_idcpu.reserve(15);
980 host_idcpu.resize(finestLevel()+1);
982 for (
int i = 0; i < cnt; i++) {
987 std::uint32_t xu, yu;
992 ptemp.
m_idcpu = ((std::uint64_t)xu) << 32 | yu;
994 ptemp.
id() = iptr[0];
995 ptemp.
cpu() = iptr[1];
999 for (
int j = 0; j < NStructInt; j++)
1001 ptemp.
idata(j) = *iptr;
1008 ptemp.
pos(1) = ParticleReal(rptr[1]);,
1009 ptemp.
pos(2) = ParticleReal(rptr[2]););
1011 rptr += AMREX_SPACEDIM;
1013 for (
int j = 0; j < NStructReal; j++)
1015 ptemp.
rdata(j) = ParticleReal(*rptr);
1019 locateParticle(ptemp, pld, 0, finestLevel(), 0);
1021 std::pair<int, int> ind(grd, pld.
m_tile);
1023 host_real_attribs[lev][ind].resize(NumRealComps());
1024 host_int_attribs[lev][ind].resize(NumIntComps());
1027 if constexpr(!ParticleType::is_soa_particle)
1029 host_particles[lev][ind].push_back(ptemp);
1032 for (
int icomp = 0; icomp < NumRealComps(); icomp++) {
1033 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1038 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1039 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1043 host_particles[lev][ind];
1045 for (
int j = 0; j < AMREX_SPACEDIM; j++) {
1046 host_real_attribs[pld.
m_lev][ind][j].push_back(ptemp.
pos(j));
1053 for (
int icomp = AMREX_SPACEDIM; icomp < NumRealComps(); icomp++) {
1054 host_real_attribs[lev][ind][icomp].push_back(*rptr);
1059 for (
int icomp = 0; icomp < NumIntComps(); icomp++) {
1060 host_int_attribs[lev][ind][icomp].push_back(*iptr);
1066 for (
int host_lev = 0; host_lev < static_cast<int>(host_particles.
size()); ++host_lev)
1068 for (
auto& kv : host_particles[host_lev]) {
1069 auto grid = kv.first.first;
1070 auto tile = kv.first.second;
1071 const auto& src_tile = kv.second;
1073 auto& dst_tile = DefineAndReturnParticleTile(host_lev, grid, tile);
1074 auto old_size = dst_tile.size();
1075 auto new_size = old_size;
1076 if constexpr(!ParticleType::is_soa_particle)
1078 new_size += src_tile.size();
1081 new_size += host_real_attribs[host_lev][std::make_pair(grid,tile)][0].
size();
1083 dst_tile.resize(new_size);
1085 if constexpr(!ParticleType::is_soa_particle)
1088 dst_tile.GetArrayOfStructs().begin() + old_size);
1091 host_idcpu[host_lev][std::make_pair(grid,tile)].
begin(),
1092 host_idcpu[host_lev][std::make_pair(grid,tile)].
end(),
1093 dst_tile.GetStructOfArrays().GetIdCPUData().begin() + old_size);
1096 for (
int i = 0; i < NumRealComps(); ++i) {
1098 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1099 host_real_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1100 dst_tile.GetStructOfArrays().GetRealData(i).begin() + old_size);
1103 for (
int i = 0; i < NumIntComps(); ++i) {
1105 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
begin(),
1106 host_int_attribs[host_lev][std::make_pair(grid,tile)][i].
end(),
1107 dst_tile.GetStructOfArrays().GetIntData(i).begin() + old_size);
1115 template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
1116 template<
class>
class Allocator,
class CellAssignor>
1118 ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>
1119 ::WriteAsciiFile (
const std::string& filename)
1121 BL_PROFILE(
"ParticleContainer::WriteAsciiFile()");
1128 Long nparticles = 0;
1130 for (
int lev = 0; lev < m_particles.size(); lev++) {
1131 auto& pmap = m_particles[lev];
1132 for (
const auto& kv : pmap) {
1133 const auto& aos = kv.second.GetArrayOfStructs();
1134 auto np = aos.numParticles();
1137 for (
int k = 0; k < np; ++k) {
1161 File.open(filename.c_str(), std::ios::out|std::ios::trunc);
1167 File << nparticles <<
'\n';
1168 File << NStructReal <<
'\n';
1169 File << NStructInt <<
'\n';
1170 File << NumRealComps() <<
'\n';
1171 File << NumIntComps() <<
'\n';
1178 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1197 File.rdbuf()->pubsetbuf(io_buffer.
dataPtr(), io_buffer.
size());
1199 File.open(filename.c_str(), std::ios::out|std::ios::app);
1207 for (
int lev = 0; lev < m_particles.size(); lev++) {
1208 auto& pmap = m_particles[lev];
1209 for (
const auto& kv : pmap) {
1212 pinned_ptile.define(NumRuntimeRealComps(), NumRuntimeIntComps());
1213 pinned_ptile.resize(kv.second.numParticles());
1215 const auto& host_aos = pinned_ptile.GetArrayOfStructs();
1216 const auto& host_soa = pinned_ptile.GetStructOfArrays();
1218 auto np = host_aos.numParticles();
1219 for (
int index = 0; index < np; ++index) {
1225 << it->pos(1) <<
' ',
1226 << it->pos(2) <<
' ');
1228 for (
int i = 0; i < NStructReal; i++) {
1229 File << it->rdata(i) <<
' ';
1232 File << it->id() <<
' ';
1233 File << it->cpu() <<
' ';
1235 for (
int i = 0; i < NStructInt; i++) {
1236 File << it->idata(i) <<
' ';
1240 for (
int i = 0; i < NumRealComps(); i++) {
1241 File << host_soa.GetRealData(i)[index] <<
' ';
1244 for (
int i = 0; i < NumIntComps(); i++) {
1245 File << host_soa.GetIntData(i)[index] <<
' ';
1259 amrex::Abort(
"ParticleContainer::WriteAsciiFile(): problem writing file");
1273 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