Merge pull request #3197 from akohlmey/custom-thermo-headers
add support for custom header keywords with thermo output and dump styles
This commit is contained in:
@ -238,6 +238,9 @@ void DumpAtomADIOS::init_style()
|
||||
columnNames = {"id", "type", "xs", "ys", "zs", "ix", "iy", "iz"};
|
||||
}
|
||||
|
||||
for (int icol = 0; icol < (int)columnNames.size(); ++icol)
|
||||
if (keyword_user[icol].size()) columnNames[icol] = keyword_user[icol];
|
||||
|
||||
// setup function ptrs
|
||||
|
||||
if (scale_flag == 1 && image_flag == 0 && domain->triclinic == 0)
|
||||
|
||||
@ -214,6 +214,19 @@ void DumpCustomADIOS::write()
|
||||
|
||||
void DumpCustomADIOS::init_style()
|
||||
{
|
||||
// assemble column string from defaults and user values
|
||||
|
||||
delete[] columns;
|
||||
std::string combined;
|
||||
int icol = 0;
|
||||
for (auto item : utils::split_words(columns_default)) {
|
||||
if (combined.size()) combined += " ";
|
||||
if (keyword_user[icol].size()) combined += keyword_user[icol];
|
||||
else combined += item;
|
||||
++icol;
|
||||
}
|
||||
columns = utils::strdup(combined);
|
||||
|
||||
// setup boundary string
|
||||
|
||||
domain->boundary_string(boundstr);
|
||||
|
||||
@ -234,14 +234,25 @@ void DumpAtomMPIIO::init_style()
|
||||
|
||||
// setup column string
|
||||
|
||||
std::string default_columns;
|
||||
|
||||
if (scale_flag == 0 && image_flag == 0)
|
||||
columns = (char *) "id type x y z";
|
||||
default_columns = "id type x y z";
|
||||
else if (scale_flag == 0 && image_flag == 1)
|
||||
columns = (char *) "id type x y z ix iy iz";
|
||||
default_columns = "id type x y z ix iy iz";
|
||||
else if (scale_flag == 1 && image_flag == 0)
|
||||
columns = (char *) "id type xs ys zs";
|
||||
default_columns = "id type xs ys zs";
|
||||
else if (scale_flag == 1 && image_flag == 1)
|
||||
columns = (char *) "id type xs ys zs ix iy iz";
|
||||
default_columns = "id type xs ys zs ix iy iz";
|
||||
|
||||
int icol = 0;
|
||||
columns.clear();
|
||||
for (auto item : utils::split_words(default_columns)) {
|
||||
if (columns.size()) columns += " ";
|
||||
if (keyword_user[icol].size()) columns += keyword_user[icol];
|
||||
else columns += item;
|
||||
++icol;
|
||||
}
|
||||
|
||||
// setup function ptrs
|
||||
|
||||
|
||||
@ -39,17 +39,6 @@ using namespace LAMMPS_NS;
|
||||
#define DUMP_BUF_CHUNK_SIZE 16384
|
||||
#define DUMP_BUF_INCREMENT_SIZE 4096
|
||||
|
||||
// clang-format off
|
||||
enum{ ID, MOL, TYPE, ELEMENT, MASS,
|
||||
X, Y, Z, XS, YS, ZS, XSTRI, YSTRI, ZSTRI, XU, YU, ZU, XUTRI, YUTRI, ZUTRI,
|
||||
XSU, YSU, ZSU, XSUTRI, YSUTRI, ZSUTRI,
|
||||
IX, IY, IZ, VX, VY, VZ, FX, FY, FZ,
|
||||
Q, MUX, MUY, MUZ, MU, RADIUS, DIAMETER,
|
||||
OMEGAX, OMEGAY, OMEGAZ, ANGMOMX, ANGMOMY, ANGMOMZ,
|
||||
TQX, TQY, TQZ, SPIN, ERADIUS, ERVEL, ERFORCE,
|
||||
COMPUTE, FIX, VARIABLE };
|
||||
enum{ LT, LE, GT, GE, EQ, NEQ };
|
||||
// clang-format on
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
DumpCustomMPIIO::DumpCustomMPIIO(LAMMPS *lmp, int narg, char **arg)
|
||||
@ -216,6 +205,19 @@ void DumpCustomMPIIO::write()
|
||||
|
||||
void DumpCustomMPIIO::init_style()
|
||||
{
|
||||
// assemble ITEMS: column string from defaults and user values
|
||||
|
||||
delete[] columns;
|
||||
std::string combined;
|
||||
int icol = 0;
|
||||
for (auto item : utils::split_words(columns_default)) {
|
||||
if (combined.size()) combined += " ";
|
||||
if (keyword_user[icol].size()) combined += keyword_user[icol];
|
||||
else combined += item;
|
||||
++icol;
|
||||
}
|
||||
columns = utils::strdup(combined);
|
||||
|
||||
// format = copy of default or user-specified line format
|
||||
|
||||
delete[] format;
|
||||
|
||||
@ -38,17 +38,6 @@ using namespace LAMMPS_NS;
|
||||
#define DUMP_BUF_CHUNK_SIZE 16384
|
||||
#define DUMP_BUF_INCREMENT_SIZE 4096
|
||||
|
||||
enum{ID,MOL,TYPE,ELEMENT,MASS,
|
||||
X,Y,Z,XS,YS,ZS,XSTRI,YSTRI,ZSTRI,XU,YU,ZU,XUTRI,YUTRI,ZUTRI,
|
||||
XSU,YSU,ZSU,XSUTRI,YSUTRI,ZSUTRI,
|
||||
IX,IY,IZ,
|
||||
VX,VY,VZ,FX,FY,FZ,
|
||||
Q,MUX,MUY,MUZ,MU,RADIUS,DIAMETER,
|
||||
OMEGAX,OMEGAY,OMEGAZ,ANGMOMX,ANGMOMY,ANGMOMZ,
|
||||
TQX,TQY,TQZ,SPIN,ERADIUS,ERVEL,ERFORCE,
|
||||
COMPUTE,FIX,VARIABLE};
|
||||
enum{LT,LE,GT,GE,EQ,NEQ};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
DumpXYZMPIIO::DumpXYZMPIIO(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
@ -356,7 +356,9 @@ void FixPOEMS::init()
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
if (utils::strmatch(ifix->style, "^poems")) pflag = true;
|
||||
if (pflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag)
|
||||
if (comm->me == 0) error->warning(FLERR, "Fix {} alters forces after fix poems", ifix->id);
|
||||
if (comm->me == 0)
|
||||
error->warning(FLERR,"Fix {} with ID {} alters forces after fix poems",
|
||||
ifix->style, ifix->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -693,7 +693,8 @@ void FixRigid::init()
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
if (ifix->rigid_flag) rflag = true;
|
||||
if ((comm->me == 0) && rflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag)
|
||||
error->warning(FLERR,"Fix {} alters forces after fix rigid", ifix->id);
|
||||
error->warning(FLERR,"Fix {} with ID {} alters forces after fix rigid",
|
||||
ifix->style, ifix->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -538,7 +538,8 @@ void FixRigidSmall::init()
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
if (ifix->rigid_flag) rflag = true;
|
||||
if ((comm->me == 0) && rflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag)
|
||||
error->warning(FLERR,"Fix {} alters forces after fix rigid", ifix->id);
|
||||
error->warning(FLERR,"Fix {} with ID {} alters forces after fix rigid/small",
|
||||
ifix->style, ifix->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
66
src/dump.cpp
66
src/dump.cpp
@ -150,19 +150,19 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
||||
|
||||
Dump::~Dump()
|
||||
{
|
||||
delete [] id;
|
||||
delete [] style;
|
||||
delete [] filename;
|
||||
delete [] multiname;
|
||||
delete[] id;
|
||||
delete[] style;
|
||||
delete[] filename;
|
||||
delete[] multiname;
|
||||
|
||||
delete [] format;
|
||||
delete [] format_default;
|
||||
delete [] format_line_user;
|
||||
delete [] format_float_user;
|
||||
delete [] format_int_user;
|
||||
delete [] format_bigint_user;
|
||||
delete[] format;
|
||||
delete[] format_default;
|
||||
delete[] format_line_user;
|
||||
delete[] format_float_user;
|
||||
delete[] format_int_user;
|
||||
delete[] format_bigint_user;
|
||||
|
||||
delete [] refresh;
|
||||
delete[] refresh;
|
||||
|
||||
// format_column_user is deallocated by child classes that use it
|
||||
|
||||
@ -1019,7 +1019,7 @@ void Dump::balance()
|
||||
memory->destroy(tmp);
|
||||
memory->destroy(proc_offsets);
|
||||
memory->destroy(proc_new_offsets);
|
||||
delete [] request;
|
||||
delete[] request;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -1059,7 +1059,7 @@ void Dump::modify_params(int narg, char **arg)
|
||||
if (strcmp(id,output->dump[idump]->id) == 0) break;
|
||||
int n;
|
||||
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
|
||||
delete [] output->var_dump[idump];
|
||||
delete[] output->var_dump[idump];
|
||||
output->var_dump[idump] = utils::strdup(&arg[iarg+1][2]);
|
||||
n = 0;
|
||||
} else {
|
||||
@ -1077,7 +1077,7 @@ void Dump::modify_params(int narg, char **arg)
|
||||
if (strcmp(id,output->dump[idump]->id) == 0) break;
|
||||
double delta;
|
||||
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
|
||||
delete [] output->var_dump[idump];
|
||||
delete[] output->var_dump[idump];
|
||||
output->var_dump[idump] = utils::strdup(&arg[iarg+1][2]);
|
||||
delta = 0.0;
|
||||
} else {
|
||||
@ -1107,7 +1107,7 @@ void Dump::modify_params(int narg, char **arg)
|
||||
MPI_Comm_free(&clustercomm);
|
||||
MPI_Comm_split(world,icluster,0,&clustercomm);
|
||||
|
||||
delete [] multiname;
|
||||
delete[] multiname;
|
||||
char *ptr = strchr(filename,'%');
|
||||
*ptr = '\0';
|
||||
multiname = utils::strdup(fmt::format("{}{}{}", filename, icluster, ptr+1));
|
||||
@ -1124,14 +1124,38 @@ void Dump::modify_params(int narg, char **arg)
|
||||
flush_flag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"colname") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
|
||||
if (strcmp(arg[iarg+1],"default") == 0) {
|
||||
for (auto item : keyword_user) item.clear();
|
||||
iarg += 2;
|
||||
} else {
|
||||
if (iarg+3 > narg) error->all(FLERR,"Illegal dump_modify command");
|
||||
int icol = -1;
|
||||
if (utils::is_integer(arg[iarg + 1])) {
|
||||
icol = utils::inumeric(FLERR,arg[iarg + 1],false,lmp);
|
||||
if (icol < 0) icol = keyword_user.size() + icol + 1;
|
||||
icol--;
|
||||
} else {
|
||||
try {
|
||||
icol = key2col.at(arg[iarg + 1]);
|
||||
} catch (std::out_of_range &) {
|
||||
icol = -1;
|
||||
}
|
||||
}
|
||||
if ((icol < 0) || (icol >= (int)keyword_user.size()))
|
||||
error->all(FLERR, "Illegal thermo_modify command");
|
||||
keyword_user[icol] = arg[iarg+2];
|
||||
iarg += 3;
|
||||
}
|
||||
} else if (strcmp(arg[iarg],"format") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
|
||||
|
||||
if (strcmp(arg[iarg+1],"none") == 0) {
|
||||
delete [] format_line_user;
|
||||
delete [] format_int_user;
|
||||
delete [] format_bigint_user;
|
||||
delete [] format_float_user;
|
||||
delete[] format_line_user;
|
||||
delete[] format_int_user;
|
||||
delete[] format_bigint_user;
|
||||
delete[] format_float_user;
|
||||
format_line_user = nullptr;
|
||||
format_int_user = nullptr;
|
||||
format_bigint_user = nullptr;
|
||||
@ -1146,7 +1170,7 @@ void Dump::modify_params(int narg, char **arg)
|
||||
if (iarg+3 > narg) error->all(FLERR,"Illegal dump_modify command");
|
||||
|
||||
if (strcmp(arg[iarg+1],"line") == 0) {
|
||||
delete [] format_line_user;
|
||||
delete[] format_line_user;
|
||||
format_line_user = utils::strdup(arg[iarg+2]);
|
||||
iarg += 3;
|
||||
} else { // pass other format options to child classes
|
||||
@ -1204,7 +1228,7 @@ void Dump::modify_params(int narg, char **arg)
|
||||
MPI_Comm_free(&clustercomm);
|
||||
MPI_Comm_split(world,icluster,0,&clustercomm);
|
||||
|
||||
delete [] multiname;
|
||||
delete[] multiname;
|
||||
char *ptr = strchr(filename,'%');
|
||||
*ptr = '\0';
|
||||
multiname = utils::strdup(fmt::format("{}{}{}", filename, icluster, ptr+1));
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
|
||||
#include "pointers.h" // IWYU pragma: export
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class Dump : protected Pointers {
|
||||
@ -100,6 +102,8 @@ class Dump : protected Pointers {
|
||||
char *format_bigint_user;
|
||||
char **format_column_user;
|
||||
enum { INT, DOUBLE, STRING, BIGINT };
|
||||
std::map<std::string, int> key2col;
|
||||
std::vector<std::string> keyword_user;
|
||||
|
||||
FILE *fp; // file to write dump to
|
||||
int size_one; // # of quantities for one atom
|
||||
|
||||
@ -38,6 +38,9 @@ DumpAtom::DumpAtom(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg)
|
||||
buffer_allow = 1;
|
||||
buffer_flag = 1;
|
||||
format_default = nullptr;
|
||||
key2col = { { "id", 0 }, { "type", 1 }, { "x", 2 }, { "y", 3 },
|
||||
{ "z", 4 }, { "ix", 5 }, { "iy", 6 }, { "iz", 7 } };
|
||||
keyword_user = { "", "", "", "", "", "", "", "" };
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -64,14 +67,25 @@ void DumpAtom::init_style()
|
||||
|
||||
// setup column string
|
||||
|
||||
std::string default_columns;
|
||||
|
||||
if (scale_flag == 0 && image_flag == 0)
|
||||
columns = (char *) "id type x y z";
|
||||
default_columns = "id type x y z";
|
||||
else if (scale_flag == 0 && image_flag == 1)
|
||||
columns = (char *) "id type x y z ix iy iz";
|
||||
default_columns = "id type x y z ix iy iz";
|
||||
else if (scale_flag == 1 && image_flag == 0)
|
||||
columns = (char *) "id type xs ys zs";
|
||||
default_columns = "id type xs ys zs";
|
||||
else if (scale_flag == 1 && image_flag == 1)
|
||||
columns = (char *) "id type xs ys zs ix iy iz";
|
||||
default_columns = "id type xs ys zs ix iy iz";
|
||||
|
||||
int icol = 0;
|
||||
columns.clear();
|
||||
for (auto item : utils::split_words(default_columns)) {
|
||||
if (columns.size()) columns += " ";
|
||||
if (keyword_user[icol].size()) columns += keyword_user[icol];
|
||||
else columns += item;
|
||||
++icol;
|
||||
}
|
||||
|
||||
// setup function ptrs
|
||||
|
||||
@ -201,9 +215,9 @@ void DumpAtom::header_unit_style_binary()
|
||||
|
||||
void DumpAtom::header_columns_binary()
|
||||
{
|
||||
int len = strlen(columns);
|
||||
int len = columns.size();
|
||||
fwrite(&len, sizeof(int), 1, fp);
|
||||
fwrite(columns, sizeof(char), len, fp);
|
||||
fwrite(columns.c_str(), sizeof(char), len, fp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -301,7 +315,7 @@ void DumpAtom::header_item(bigint ndump)
|
||||
fprintf(fp,"%-1.16e %-1.16e\n",boxxlo,boxxhi);
|
||||
fprintf(fp,"%-1.16e %-1.16e\n",boxylo,boxyhi);
|
||||
fprintf(fp,"%-1.16e %-1.16e\n",boxzlo,boxzhi);
|
||||
fprintf(fp,"ITEM: ATOMS %s\n",columns);
|
||||
fprintf(fp,"ITEM: ATOMS %s\n",columns.c_str());
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -322,7 +336,7 @@ void DumpAtom::header_item_triclinic(bigint ndump)
|
||||
fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxxlo,boxxhi,boxxy);
|
||||
fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxylo,boxyhi,boxxz);
|
||||
fprintf(fp,"%-1.16e %-1.16e %-1.16e\n",boxzlo,boxzhi,boxyz);
|
||||
fprintf(fp,"ITEM: ATOMS %s\n",columns);
|
||||
fprintf(fp,"ITEM: ATOMS %s\n",columns.c_str());
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -36,7 +36,7 @@ class DumpAtom : public Dump {
|
||||
int scale_flag; // 1 if atom coords are scaled, 0 if no
|
||||
int image_flag; // 1 if append box count to atom coords, 0 if no
|
||||
|
||||
char *columns; // column labels
|
||||
std::string columns; // column labels
|
||||
|
||||
void init_style() override;
|
||||
int modify_param(int, char **) override;
|
||||
|
||||
@ -53,26 +53,26 @@ DumpCFG::DumpCFG(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
if (strcmp(earg[2],"xs") == 0) {
|
||||
if (strcmp(earg[3],"ysu") == 0 || strcmp(earg[4],"zsu") == 0)
|
||||
error->all(FLERR,
|
||||
"Dump cfg arguments can not mix xs|ys|zs with xsu|ysu|zsu");
|
||||
error->all(FLERR,"Dump cfg arguments can not mix xs|ys|zs with xsu|ysu|zsu");
|
||||
unwrapflag = 0;
|
||||
} else {
|
||||
if (strcmp(earg[3],"ys") == 0 || strcmp(earg[4],"zs") == 0)
|
||||
error->all(FLERR,
|
||||
"Dump cfg arguments can not mix xs|ys|zs with xsu|ysu|zsu");
|
||||
error->all(FLERR,"Dump cfg arguments can not mix xs|ys|zs with xsu|ysu|zsu");
|
||||
unwrapflag = 1;
|
||||
}
|
||||
|
||||
// setup auxiliary property name strings
|
||||
// convert 'X_ID[m]' (X=c,f,v) to 'X_ID_m'
|
||||
|
||||
if (nfield > 5) auxname = new char*[nfield];
|
||||
if (nfield > 5) auxname = new char*[nfield-5];
|
||||
else auxname = nullptr;
|
||||
|
||||
int i = 0;
|
||||
key2col.clear();
|
||||
keyword_user.resize(nfield-5);
|
||||
for (int iarg = 5; iarg < nfield; iarg++, i++) {
|
||||
ArgInfo argi(earg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE
|
||||
|ArgInfo::DNAME|ArgInfo::INAME);
|
||||
ArgInfo argi(earg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE|
|
||||
ArgInfo::DNAME|ArgInfo::INAME);
|
||||
|
||||
if (argi.get_dim() == 1) {
|
||||
std::string newarg = fmt::format("{}_{}_{}", earg[iarg][0], argi.get_name(), argi.get_index1());
|
||||
@ -80,6 +80,8 @@ DumpCFG::DumpCFG(LAMMPS *lmp, int narg, char **arg) :
|
||||
} else {
|
||||
auxname[i] = utils::strdup(earg[iarg]);
|
||||
}
|
||||
key2col[earg[iarg]] = i;
|
||||
keyword_user[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,8 +90,8 @@ DumpCFG::DumpCFG(LAMMPS *lmp, int narg, char **arg) :
|
||||
DumpCFG::~DumpCFG()
|
||||
{
|
||||
if (auxname) {
|
||||
for (int i = 0; i < nfield-5; i++) delete [] auxname[i];
|
||||
delete [] auxname;
|
||||
for (int i = 0; i < nfield-5; i++) delete[] auxname[i];
|
||||
delete[] auxname;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,8 +138,12 @@ void DumpCFG::write_header(bigint n)
|
||||
fprintf(fp,"H0(3,3) = %g A\n",domain->zprd);
|
||||
fprintf(fp,".NO_VELOCITY.\n");
|
||||
fprintf(fp,"entry_count = %d\n",nfield-2);
|
||||
for (int i = 0; i < nfield-5; i++)
|
||||
fprintf(fp,"auxiliary[%d] = %s\n",i,auxname[i]);
|
||||
for (int i = 0; i < nfield-5; i++) {
|
||||
if (keyword_user[i].size())
|
||||
fprintf(fp,"auxiliary[%d] = %s\n",i,keyword_user[i].c_str());
|
||||
else
|
||||
fprintf(fp,"auxiliary[%d] = %s\n",i,auxname[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -55,14 +55,11 @@ 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), 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),
|
||||
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)
|
||||
{
|
||||
if (narg == 5) error->all(FLERR,"No dump custom arguments specified");
|
||||
@ -180,13 +177,14 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
|
||||
// setup column string
|
||||
|
||||
cols.clear();
|
||||
keyword_user.resize(nfield);
|
||||
for (int iarg = 0; iarg < nfield; iarg++) {
|
||||
key2col[earg[iarg]] = iarg;
|
||||
keyword_user[iarg].clear();
|
||||
if (cols.size()) cols += " ";
|
||||
cols += earg[iarg];
|
||||
cols += " ";
|
||||
}
|
||||
// remove trailing blank and copy
|
||||
cols.resize(cols.size()-1);
|
||||
columns = utils::strdup(cols);
|
||||
columns_default = utils::strdup(cols);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -257,6 +255,7 @@ DumpCustom::~DumpCustom()
|
||||
delete[] format_column_user;
|
||||
}
|
||||
|
||||
delete[] columns_default;
|
||||
delete[] columns;
|
||||
}
|
||||
|
||||
@ -264,6 +263,19 @@ DumpCustom::~DumpCustom()
|
||||
|
||||
void DumpCustom::init_style()
|
||||
{
|
||||
// assemble ITEMS: column string from defaults and user values
|
||||
|
||||
delete[] columns;
|
||||
std::string combined;
|
||||
int icol = 0;
|
||||
for (auto item : utils::split_words(columns_default)) {
|
||||
if (combined.size()) combined += " ";
|
||||
if (keyword_user[icol].size()) combined += keyword_user[icol];
|
||||
else combined += item;
|
||||
++icol;
|
||||
}
|
||||
columns = utils::strdup(combined);
|
||||
|
||||
// format = copy of default or user-specified line format
|
||||
|
||||
delete[] format;
|
||||
|
||||
@ -60,6 +60,7 @@ class DumpCustom : public Dump {
|
||||
char **vformat; // format string for each vector element
|
||||
//
|
||||
char *columns; // column labels
|
||||
char *columns_default;
|
||||
//
|
||||
int nchoose; // # of selected atoms
|
||||
int maxlocal; // size of atom selection and variable arrays
|
||||
|
||||
@ -249,11 +249,11 @@ void Modify::init()
|
||||
|
||||
for (i = 0; i < nfix; i++)
|
||||
if (!fix[i]->dynamic_group_allow && group->dynamic[fix[i]->igroup])
|
||||
error->all(FLERR, "Fix {} does not allow use with a dynamic group", fix[i]->id);
|
||||
error->all(FLERR, "Fix {} does not allow use with a dynamic group", fix[i]->style);
|
||||
|
||||
for (i = 0; i < ncompute; i++)
|
||||
if (!compute[i]->dynamic_group_allow && group->dynamic[compute[i]->igroup])
|
||||
error->all(FLERR, "Compute {} does not allow use with a dynamic group", compute[i]->id);
|
||||
error->all(FLERR, "Compute {} does not allow use with a dynamic group", compute[i]->style);
|
||||
|
||||
// warn if any particle is time integrated more than once
|
||||
|
||||
|
||||
@ -252,8 +252,12 @@ void Thermo::init()
|
||||
format[i] += format_this + " ";
|
||||
else if (lineflag == YAMLLINE)
|
||||
format[i] += format_this + ", ";
|
||||
else
|
||||
format[i] += fmt::format("{:<8} = {} ", keyword[i], format_this);
|
||||
else {
|
||||
if (keyword_user[i].size())
|
||||
format[i] += fmt::format("{:<8} = {} ", keyword_user[i], format_this);
|
||||
else
|
||||
format[i] += fmt::format("{:<8} = {} ", keyword[i], format_this);
|
||||
}
|
||||
}
|
||||
|
||||
// chop off trailing blank or add closing bracket if needed and then add newline
|
||||
@ -324,11 +328,13 @@ void Thermo::header()
|
||||
std::string hdr;
|
||||
if (lineflag == YAMLLINE) hdr = "---\nkeywords: [";
|
||||
for (int i = 0; i < nfield; i++) {
|
||||
auto head = keyword[i];
|
||||
if (keyword_user[i].size()) head = keyword_user[i];
|
||||
if (lineflag == ONELINE) {
|
||||
if (vtype[i] == FLOAT)
|
||||
hdr += fmt::format("{:^14} ", keyword[i]);
|
||||
hdr += fmt::format("{:^14} ", head);
|
||||
else if ((vtype[i] == INT) || (vtype[i] == BIGINT))
|
||||
hdr += fmt::format("{:^11} ", keyword[i]);
|
||||
hdr += fmt::format("{:^11} ", head);
|
||||
} else if (lineflag == YAMLLINE) {
|
||||
hdr += keyword[i];
|
||||
hdr += ", ";
|
||||
@ -622,6 +628,29 @@ void Thermo::modify_params(int narg, char **arg)
|
||||
error->all(FLERR, "Illegal thermo_modify command");
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg], "colname") == 0) {
|
||||
if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command");
|
||||
if (strcmp(arg[iarg + 1], "default") == 0) {
|
||||
for (auto item : keyword_user) item.clear();
|
||||
iarg += 2;
|
||||
} else {
|
||||
if (iarg + 3 > narg) error->all(FLERR, "Illegal thermo_modify command");
|
||||
int icol = -1;
|
||||
if (utils::is_integer(arg[iarg + 1])) {
|
||||
icol = utils::inumeric(FLERR,arg[iarg + 1],false,lmp);
|
||||
if (icol < 0) icol = nfield_initial + icol + 1;
|
||||
icol--;
|
||||
} else {
|
||||
try {
|
||||
icol = key2col.at(arg[iarg + 1]);
|
||||
} catch (std::out_of_range &) {
|
||||
icol = -1;
|
||||
}
|
||||
}
|
||||
if ((icol < 0) || (icol >= nfield_initial)) error->all(FLERR, "Illegal thermo_modify command");
|
||||
keyword_user[icol] = arg[iarg+2];
|
||||
iarg += 3;
|
||||
}
|
||||
} else if (strcmp(arg[iarg], "format") == 0) {
|
||||
if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command");
|
||||
|
||||
@ -630,7 +659,7 @@ void Thermo::modify_params(int narg, char **arg)
|
||||
format_int_user.clear();
|
||||
format_bigint_user.clear();
|
||||
format_float_user.clear();
|
||||
for (int i = 0; i < nfield_initial + 1; ++i) format_column_user[i].clear();
|
||||
for (auto item : format_column_user) item.clear();
|
||||
iarg += 2;
|
||||
continue;
|
||||
}
|
||||
@ -646,14 +675,24 @@ void Thermo::modify_params(int narg, char **arg)
|
||||
found = format_int_user.find('d', found);
|
||||
if (found == std::string::npos)
|
||||
error->all(FLERR, "Thermo_modify int format does not contain a d conversion character");
|
||||
format_bigint_user =
|
||||
format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1));
|
||||
format_bigint_user = format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1));
|
||||
} else if (strcmp(arg[iarg + 1], "float") == 0) {
|
||||
format_float_user = arg[iarg + 2];
|
||||
} else {
|
||||
int i = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1;
|
||||
if (i < 0 || i >= nfield_initial + 1) error->all(FLERR, "Illegal thermo_modify command");
|
||||
format_column_user[i] = arg[iarg + 2];
|
||||
int icol = -1;
|
||||
if (utils::is_integer(arg[iarg + 1])) {
|
||||
icol = utils::inumeric(FLERR, arg[iarg + 1], false, lmp);
|
||||
if (icol < 0) icol = nfield_initial + icol + 1;
|
||||
icol--;
|
||||
} else {
|
||||
try {
|
||||
icol = key2col.at(arg[iarg + 1]);
|
||||
} catch (std::out_of_range &) {
|
||||
icol = -1;
|
||||
}
|
||||
}
|
||||
if (icol < 0 || icol >= nfield_initial + 1) error->all(FLERR, "Illegal thermo_modify command");
|
||||
format_column_user[icol] = arg[iarg + 2];
|
||||
}
|
||||
iarg += 3;
|
||||
|
||||
@ -675,10 +714,12 @@ void Thermo::allocate()
|
||||
keyword.resize(n);
|
||||
format.resize(n);
|
||||
format_column_user.resize(n);
|
||||
keyword_user.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
keyword[i].clear();
|
||||
format[i].clear();
|
||||
format_column_user[i].clear();
|
||||
keyword_user[i].clear();
|
||||
}
|
||||
|
||||
vfunc = new FnPtr[n];
|
||||
@ -702,6 +743,12 @@ void Thermo::allocate()
|
||||
nvariable = 0;
|
||||
id_variable = new char *[n];
|
||||
variables = new int[n];
|
||||
|
||||
int i = 0;
|
||||
key2col.clear();
|
||||
for (auto item : utils::split_words(line)) {
|
||||
key2col[item] = i++;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#define LMP_THERMO_H
|
||||
|
||||
#include "pointers.h"
|
||||
#include <map>
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
@ -47,8 +48,9 @@ class Thermo : protected Pointers {
|
||||
int nfield, nfield_initial;
|
||||
int *vtype;
|
||||
std::string line;
|
||||
std::vector<std::string> keyword, format, format_column_user;
|
||||
std::vector<std::string> keyword, format, format_column_user, keyword_user;
|
||||
std::string format_line_user, format_float_user, format_int_user, format_bigint_user;
|
||||
std::map<std::string, int> key2col;
|
||||
|
||||
int normvalue; // use this for normflag unless natoms = 0
|
||||
int normuserflag; // 0 if user has not set, 1 if has
|
||||
|
||||
Reference in New Issue
Block a user