use Output::add_dump() and the dump_creator map and templates etc.

This commit is contained in:
Axel Kohlmeyer
2022-05-12 14:47:16 -04:00
parent aff72c56a5
commit 0577bb6269
2 changed files with 18 additions and 33 deletions

View File

@ -735,15 +735,15 @@ void Output::reset_dt()
add a Dump to list of Dumps
------------------------------------------------------------------------- */
Dump *Output::add_dump(int narg, char **arg)
void Output::add_dump(int narg, char **arg)
{
if (narg < 5) error->all(FLERR,"Illegal dump command");
// error checks
for (int idump = 0; idump < ndump; idump++)
if (strcmp(arg[0],dump[idump]->id) == 0) error->all(FLERR,"Reuse of dump ID: {}", arg[0]);
if (strcmp(arg[0],dump[idump]->id) == 0)
error->all(FLERR,"Reuse of dump ID: {}", arg[0]);
int igroup = group->find(arg[1]);
if (igroup == -1) error->all(FLERR,"Could not find dump group ID: {}", arg[1]);
if (utils::inumeric(FLERR,arg[3],false,lmp) <= 0)
@ -765,27 +765,25 @@ Dump *Output::add_dump(int narg, char **arg)
}
// create the Dump
int idump = ndump;
if (dump_map->find(arg[2]) != dump_map->end()) {
DumpCreator &dump_creator = (*dump_map)[arg[2]];
dump[idump] = dump_creator(lmp, narg, arg);
dump[ndump] = dump_creator(lmp, narg, arg);
} else error->all(FLERR,utils::check_packages_for_style("dump",arg[2],lmp));
// initialize per-dump data to suitable default values
mode_dump[idump] = 0;
every_dump[idump] = utils::inumeric(FLERR,arg[3],false,lmp);
if (every_dump[idump] <= 0) error->all(FLERR,"Illegal dump command");
every_time_dump[idump] = 0.0;
next_time_dump[idump] = -1.0;
last_dump[idump] = -1;
var_dump[idump] = nullptr;
ivar_dump[idump] = -1;
next_dump[idump] = 0;
mode_dump[ndump] = 0;
every_dump[ndump] = utils::inumeric(FLERR,arg[3],false,lmp);
if (every_dump[ndump] <= 0) error->all(FLERR,"Illegal dump command");
every_time_dump[ndump] = 0.0;
next_time_dump[ndump] = -1.0;
last_dump[ndump] = -1;
var_dump[ndump] = nullptr;
ivar_dump[ndump] = -1;
next_dump[ndump] = 0;
ndump++;
return dump[idump];
}
/* ----------------------------------------------------------------------

View File

@ -17,12 +17,13 @@
------------------------------------------------------------------------- */
#include "write_dump.h"
#include "style_dump.h" // IWYU pragma: keep
#include "comm.h"
#include "dump.h"
#include "dump_cfg.h"
#include "dump_image.h"
#include "error.h"
#include "output.h"
#include "update.h"
#include <cstring>
@ -45,8 +46,6 @@ void WriteDump::command(int narg, char **arg)
// create the Dump instance
// create dump command line with extra required args
Dump *dump = nullptr;
auto dumpargs = new char*[modindex+2];
dumpargs[0] = (char *) "WRITE_DUMP"; // dump id
dumpargs[1] = arg[0]; // group
@ -54,21 +53,9 @@ void WriteDump::command(int narg, char **arg)
std::string ntimestep = std::to_string(MAX(update->ntimestep,1));
dumpargs[3] = (char *) ntimestep.c_str(); // dump frequency
for (int i = 2; i < modindex; ++i)
dumpargs[i+2] = arg[i];
if (false) { // NOLINT
return; // dummy branch to enable else-if macro expansion
#define DUMP_CLASS
#define DumpStyle(key,Class) \
} else if (strcmp(arg[1],#key) == 0) { \
dump = new Class(lmp,modindex+2,dumpargs);
#include "style_dump.h" // IWYU pragma: keep
#undef DUMP_CLASS
} else error->all(FLERR,utils::check_packages_for_style("dump",arg[1],lmp));
for (int i = 2; i < modindex; ++i) dumpargs[i+2] = arg[i];
Dump *dump = output->add_dump(modindex+2, dumpargs);
if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]);
// write out one frame and then delete the dump again
@ -88,6 +75,6 @@ void WriteDump::command(int narg, char **arg)
// delete the Dump instance and local storage
delete dump;
output->delete_dump(dumpargs[0]);
delete[] dumpargs;
}