refactor dump code to no longer need access to internal Modify class data

This commit is contained in:
Axel Kohlmeyer
2024-01-21 14:42:57 -05:00
parent fd0507bded
commit a473d6f347
4 changed files with 27 additions and 41 deletions

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -38,16 +37,16 @@ using namespace LAMMPS_NS;
Dump *Dump::dumpptr;
#endif
#define BIG 1.0e20
#define EPSILON 1.0e-6
static constexpr double BIG = 1.0e20;
static constexpr double EPSILON = 1.0e-6;
enum { ASCEND, DESCEND };
/* ---------------------------------------------------------------------- */
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),
Pointers(lmp), multiname(nullptr), idrefresh(nullptr), irefresh(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),
@ -119,21 +118,21 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) :
fileproc = 0;
char *ptr;
if ((ptr = strchr(filename,'%'))) {
if ((ptr = strchr(filename, '%'))) {
multiproc = 1;
nclusterprocs = 1;
filewriter = 1;
fileproc = me;
MPI_Comm_split(world,me,0,&clustercomm);
MPI_Comm_split(world, me, 0, &clustercomm);
*ptr = '\0';
multiname = utils::strdup(fmt::format("{}{}{}", filename, me, ptr+1));
multiname = utils::strdup(fmt::format("{}{}{}", filename, me, ptr + 1));
*ptr = '%';
}
if (strchr(filename,'*')) multifile = 1;
if (strchr(filename, '*')) multifile = 1;
if (utils::strmatch(filename, "\\.bin$")
|| utils::strmatch(filename, "\\.lammpsbin$")) binary = 1;
if (utils::strmatch(filename, "\\.bin$") || utils::strmatch(filename, "\\.lammpsbin$"))
binary = 1;
if (platform::has_compress_extension(filename)) compressed = 1;
}
@ -153,7 +152,7 @@ Dump::~Dump()
delete[] format_int_user;
delete[] format_bigint_user;
delete[] refresh;
delete[] idrefresh;
delete[] skipvar;
// format_column_user is deallocated by child classes that use it
@ -179,8 +178,7 @@ Dump::~Dump()
// delete storage for caching file names
if (maxfiles > 0) {
for (int idx=0; idx < numfiles; ++idx)
delete[] nameslist[idx];
for (int idx = 0; idx < numfiles; ++idx) delete[] nameslist[idx];
delete[] nameslist;
}
@ -196,6 +194,8 @@ Dump::~Dump()
}
}
// clang-format off
/* ---------------------------------------------------------------------- */
void Dump::init()
@ -288,11 +288,8 @@ void Dump::init()
// search for refresh compute specified by dump_modify refresh
if (refreshflag) {
int icompute;
for (icompute = 0; icompute < modify->ncompute; icompute++)
if (strcmp(refresh,modify->compute[icompute]->id) == 0) break;
if (icompute < modify->ncompute) irefresh = icompute;
else error->all(FLERR,"Dump could not find refresh compute ID");
irefresh = modify->get_compute_by_id(idrefresh);
if (!irefresh) error->all(FLERR,"Dump could not find refresh compute ID {}", idrefresh);
}
// if skipflag, check skip variable
@ -531,7 +528,7 @@ void Dump::write()
// trigger post-dump refresh by specified compute
// currently used for incremental dump files
if (refreshflag) modify->compute[irefresh]->refresh();
if (refreshflag) irefresh->refresh();
if (filewriter && fp != nullptr) write_footer();