diff --git a/src/MPIIO/dump_atom_mpiio.cpp b/src/MPIIO/dump_atom_mpiio.cpp index 4e0fd47a29..844d1a46e4 100644 --- a/src/MPIIO/dump_atom_mpiio.cpp +++ b/src/MPIIO/dump_atom_mpiio.cpp @@ -283,6 +283,8 @@ void DumpAtomMPIIO::init_style() void DumpAtomMPIIO::write_header(bigint ndump) { + if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump"); + (this->*header_choice)(ndump); } diff --git a/src/MPIIO/dump_custom_mpiio.cpp b/src/MPIIO/dump_custom_mpiio.cpp index 32e09675a8..80adefa325 100644 --- a/src/MPIIO/dump_custom_mpiio.cpp +++ b/src/MPIIO/dump_custom_mpiio.cpp @@ -309,6 +309,8 @@ void DumpCustomMPIIO::init_style() void DumpCustomMPIIO::write_header(bigint ndump) { + if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump"); + (this->*header_choice)(ndump); } diff --git a/src/dump.cpp b/src/dump.cpp index 372773bbb2..c1a246ada2 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -1,4 +1,4 @@ -// clang-format off + // clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -41,14 +41,20 @@ Dump *Dump::dumpptr; #define BIG 1.0e20 #define EPSILON 1.0e-6 -enum{ASCEND,DESCEND}; +enum { ASCEND, DESCEND }; /* ---------------------------------------------------------------------- */ -Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) +Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : + Pointers(lmp), multiname(nullptr), refresh(nullptr), skipvar(nullptr), format(nullptr), + format_default(nullptr), format_line_user(nullptr), format_float_user(nullptr), + format_int_user(nullptr), format_bigint_user(nullptr), format_column_user(nullptr), fp(nullptr), + nameslist(nullptr), buf(nullptr), sbuf(nullptr), ids(nullptr), bufsort(nullptr), + idsort(nullptr), index(nullptr), proclist(nullptr), xpbc(nullptr), vpbc(nullptr), + imagepbc(nullptr), irregular(nullptr) { - MPI_Comm_rank(world,&me); - MPI_Comm_size(world,&nprocs); + MPI_Comm_rank(world, &me); + MPI_Comm_size(world, &nprocs); id = utils::strdup(arg[0]); @@ -64,17 +70,7 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) first_flag = 0; flush_flag = 1; - format = nullptr; - format_default = nullptr; - - format_line_user = nullptr; - format_float_user = nullptr; - format_int_user = nullptr; - format_bigint_user = nullptr; - format_column_user = nullptr; - refreshflag = 0; - refresh = nullptr; clearstep = 0; sort_flag = 0; @@ -92,25 +88,15 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) has_id = 1; skipflag = 0; - skipvar = nullptr; maxfiles = -1; numfiles = 0; fileidx = 0; - nameslist = nullptr; maxbuf = maxids = maxsort = maxproc = 0; - buf = bufsort = nullptr; - ids = idsort = nullptr; - index = proclist = nullptr; - irregular = nullptr; - maxsbuf = 0; - sbuf = nullptr; maxpbc = -1; - xpbc = vpbc = nullptr; - imagepbc = nullptr; // parse filename for special syntax // if contains '%', write one file per proc and replace % with proc-ID @@ -120,18 +106,17 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) // else if ends in .gz or other known extensions -> compressed text file // else ASCII text file - fp = nullptr; singlefile_opened = 0; compressed = 0; binary = 0; multifile = 0; + size_one = 0; multiproc = 0; nclusterprocs = nprocs; filewriter = 0; if (me == 0) filewriter = 1; fileproc = 0; - multiname = nullptr; char *ptr; if ((ptr = strchr(filename,'%'))) { diff --git a/src/dump_atom.cpp b/src/dump_atom.cpp index 1d3862ab26..656eef8c9d 100644 --- a/src/dump_atom.cpp +++ b/src/dump_atom.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -29,8 +28,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -DumpAtom::DumpAtom(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) +DumpAtom::DumpAtom(LAMMPS *lmp, int narg, char **arg) : + Dump(lmp, narg, arg), header_choice(nullptr), pack_choice(nullptr) { + // clang-format off if (narg != 5) error->all(FLERR,"Illegal dump atom command"); scale_flag = 1; @@ -146,6 +147,8 @@ int DumpAtom::modify_param(int narg, char **arg) void DumpAtom::write_header(bigint ndump) { + if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump"); + if (multiproc) (this->*header_choice)(ndump); else if (me == 0) (this->*header_choice)(ndump); } @@ -154,6 +157,8 @@ void DumpAtom::write_header(bigint ndump) void DumpAtom::pack(tagint *ids) { + if (!pack_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump"); + (this->*pack_choice)(ids); } diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 33cfba2cef..6a10641434 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -53,13 +52,14 @@ enum{LT,LE,GT,GE,EQ,NEQ,XOR}; /* ---------------------------------------------------------------------- */ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : - Dump(lmp, narg, arg), idregion(nullptr), thresh_array(nullptr), thresh_op(nullptr), - thresh_value(nullptr), thresh_last(nullptr), thresh_fix(nullptr), thresh_fixID(nullptr), - thresh_first(nullptr), earg(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr), - columns_default(nullptr), choose(nullptr), dchoose(nullptr), clist(nullptr), - field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr), id_fix(nullptr), - fix(nullptr), id_variable(nullptr), variable(nullptr), vbuf(nullptr), id_custom(nullptr), - custom(nullptr), custom_flag(nullptr), typenames(nullptr), pack_choice(nullptr) + Dump(lmp, narg, arg), idregion(nullptr), thresh_array(nullptr), thresh_op(nullptr), + thresh_value(nullptr), thresh_last(nullptr), thresh_fix(nullptr), thresh_fixID(nullptr), + thresh_first(nullptr), earg(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr), + columns_default(nullptr), choose(nullptr), dchoose(nullptr), clist(nullptr), + field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr), id_fix(nullptr), + fix(nullptr), id_variable(nullptr), variable(nullptr), vbuf(nullptr), id_custom(nullptr), + custom(nullptr), custom_flag(nullptr), typenames(nullptr), header_choice(nullptr), + pack_choice(nullptr) { if (narg == 5) error->all(FLERR,"No dump {} arguments specified", style); @@ -352,6 +352,8 @@ void DumpCustom::init_style() void DumpCustom::write_header(bigint ndump) { + if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump"); + if (multiproc) (this->*header_choice)(ndump); else if (me == 0) (this->*header_choice)(ndump); } diff --git a/src/dump_grid.cpp b/src/dump_grid.cpp index 056cac1095..39d80ade11 100644 --- a/src/dump_grid.cpp +++ b/src/dump_grid.cpp @@ -311,6 +311,8 @@ void DumpGrid::init_style() void DumpGrid::write_header(bigint ndump) { + if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump"); + if (multiproc) (this->*header_choice)(ndump); else if (me == 0) (this->*header_choice)(ndump); } diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index 83c4d180d6..241ec1c059 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -130,6 +130,8 @@ int DumpXYZ::modify_param(int narg, char **arg) void DumpXYZ::write_header(bigint n) { if (me == 0) { + if (!fp) error->one(FLERR, "Must not use 'run pre no' after creating a new dump"); + auto header = fmt::format("{}\n Atoms. Timestep: {}", n, update->ntimestep); if (time_flag) header += fmt::format(" Time: {:.6f}", compute_time()); header += "\n"; @@ -177,9 +179,8 @@ int DumpXYZ::convert_string(int n, double *mybuf) memory->grow(sbuf,maxsbuf,"dump:sbuf"); } - offset += sprintf(&sbuf[offset],format, - typenames[static_cast (mybuf[m+1])], - mybuf[m+2],mybuf[m+3],mybuf[m+4]); + offset += sprintf(&sbuf[offset], format, typenames[static_cast (mybuf[m+1])], + mybuf[m+2], mybuf[m+3], mybuf[m+4]); m += size_one; }