first stab at implementing dump_modify colname
This commit is contained in:
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 = { "", "", "", "", "", "", "", "" };
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -63,15 +66,25 @@ void DumpAtom::init_style()
|
||||
domain->boundary_string(boundstr);
|
||||
|
||||
// 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 +214,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 +314,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 +335,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
|
||||
|
||||
@ -631,8 +631,7 @@ void Thermo::modify_params(int narg, char **arg)
|
||||
} 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 (int i=0; i < nfield_initial + 1; ++i)
|
||||
keyword_user[i].clear();
|
||||
for (auto item : keyword_user) item.clear();
|
||||
iarg += 2;
|
||||
} else {
|
||||
if (iarg + 3 > narg) error->all(FLERR, "Illegal thermo_modify command");
|
||||
@ -660,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user