reimplement utils::gridid_parse() function and update related code
This commit is contained in:
@ -205,6 +205,9 @@ Argument processing
|
|||||||
.. doxygenfunction:: expand_args
|
.. doxygenfunction:: expand_args
|
||||||
:project: progguide
|
:project: progguide
|
||||||
|
|
||||||
|
.. doxygenfunction:: gridid_parse
|
||||||
|
:project: progguide
|
||||||
|
|
||||||
Convenience functions
|
Convenience functions
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|||||||
@ -132,9 +132,9 @@ class Compute : protected Pointers {
|
|||||||
|
|
||||||
virtual void reset_grid(){};
|
virtual void reset_grid(){};
|
||||||
|
|
||||||
virtual int get_grid_by_name(char *, int &) { return -1; };
|
virtual int get_grid_by_name(const std::string &, int &) { return -1; };
|
||||||
virtual void *get_grid_by_index(int) { return nullptr; };
|
virtual void *get_grid_by_index(int) { return nullptr; };
|
||||||
virtual int get_griddata_by_name(int, char *, int &) { return -1; };
|
virtual int get_griddata_by_name(int, const std::string &, int &) { return -1; };
|
||||||
virtual void *get_griddata_by_index(int) { return nullptr; };
|
virtual void *get_griddata_by_index(int) { return nullptr; };
|
||||||
|
|
||||||
virtual void dof_remove_pre() {}
|
virtual void dof_remove_pre() {}
|
||||||
|
|||||||
@ -32,9 +32,8 @@ enum { UNSCALED, SCALED };
|
|||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
ComputePropertyGrid::ComputePropertyGrid(LAMMPS *lmp, int narg, char **arg) :
|
ComputePropertyGrid::ComputePropertyGrid(LAMMPS *lmp, int narg, char **arg) :
|
||||||
Compute(lmp, narg, arg), pack_choice(nullptr),
|
Compute(lmp, narg, arg), grid2d(nullptr), grid3d(nullptr), vec2d(nullptr), vec3d(nullptr),
|
||||||
grid2d(nullptr), grid3d(nullptr),
|
array2d(nullptr), array3d(nullptr), pack_choice(nullptr)
|
||||||
vec2d(nullptr), array2d(nullptr), vec3d(nullptr), array3d(nullptr)
|
|
||||||
{
|
{
|
||||||
if (narg < 7) error->all(FLERR, "Illegal compute property/grid command");
|
if (narg < 7) error->all(FLERR, "Illegal compute property/grid command");
|
||||||
|
|
||||||
@ -164,9 +163,9 @@ void ComputePropertyGrid::reset_grid()
|
|||||||
return -1 if grid name not found
|
return -1 if grid name not found
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int ComputePropertyGrid::get_grid_by_name(char *name, int &dim)
|
int ComputePropertyGrid::get_grid_by_name(const std::string &name, int &dim)
|
||||||
{
|
{
|
||||||
if (strcmp(name,"grid") == 0) {
|
if (name == "grid") {
|
||||||
dim = dimension;
|
dim = dimension;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -200,9 +199,9 @@ void *ComputePropertyGrid::get_grid_by_index(int index)
|
|||||||
return -1 if data name not found
|
return -1 if data name not found
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int ComputePropertyGrid::get_griddata_by_name(int igrid, char *name, int &ncol)
|
int ComputePropertyGrid::get_griddata_by_name(int igrid, const std::string &name, int &ncol)
|
||||||
{
|
{
|
||||||
if (igrid == 0 && strcmp(name,"data") == 0) {
|
if ((igrid == 0) && (name == "data")) {
|
||||||
if (nvalues == 1) ncol = 0;
|
if (nvalues == 1) ncol = 0;
|
||||||
else ncol = nvalues;
|
else ncol = nvalues;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -33,9 +33,9 @@ class ComputePropertyGrid : public Compute {
|
|||||||
|
|
||||||
void reset_grid() override;
|
void reset_grid() override;
|
||||||
|
|
||||||
int get_grid_by_name(char *, int &) override;
|
int get_grid_by_name(const std::string &, int &) override;
|
||||||
void *get_grid_by_index(int) override;
|
void *get_grid_by_index(int) override;
|
||||||
int get_griddata_by_name(int, char *, int &) override;
|
int get_griddata_by_name(int, const std::string &, int &) override;
|
||||||
void *get_griddata_by_index(int) override;
|
void *get_griddata_by_index(int) override;
|
||||||
|
|
||||||
double memory_usage() override;
|
double memory_usage() override;
|
||||||
|
|||||||
@ -44,8 +44,7 @@ DumpGrid::DumpGrid(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
Dump(lmp, narg, arg), idregion(nullptr), earg(nullptr), vtype(nullptr),
|
Dump(lmp, narg, arg), idregion(nullptr), earg(nullptr), vtype(nullptr),
|
||||||
vformat(nullptr), columns(nullptr), columns_default(nullptr),
|
vformat(nullptr), columns(nullptr), columns_default(nullptr),
|
||||||
field2index(nullptr), field2grid(nullptr), field2data(nullptr),
|
field2index(nullptr), field2grid(nullptr), field2data(nullptr),
|
||||||
argindex(nullptr), id_compute(nullptr), compute(nullptr),
|
argindex(nullptr), id_compute(nullptr), id_fix(nullptr), pack_choice(nullptr)
|
||||||
id_fix(nullptr), fix(nullptr), pack_choice(nullptr)
|
|
||||||
{
|
{
|
||||||
if (narg == 5) error->all(FLERR,"No dump grid arguments specified");
|
if (narg == 5) error->all(FLERR,"No dump grid arguments specified");
|
||||||
|
|
||||||
@ -160,11 +159,9 @@ DumpGrid::~DumpGrid()
|
|||||||
|
|
||||||
for (int i = 0; i < ncompute; i++) delete[] id_compute[i];
|
for (int i = 0; i < ncompute; i++) delete[] id_compute[i];
|
||||||
memory->sfree(id_compute);
|
memory->sfree(id_compute);
|
||||||
delete[] compute;
|
|
||||||
|
|
||||||
for (int i = 0; i < nfix; i++) delete[] id_fix[i];
|
for (int i = 0; i < nfix; i++) delete[] id_fix[i];
|
||||||
memory->sfree(id_fix);
|
memory->sfree(id_fix);
|
||||||
delete[] fix;
|
|
||||||
|
|
||||||
if (vformat) {
|
if (vformat) {
|
||||||
for (int i = 0; i < nfield; i++) delete[] vformat[i];
|
for (int i = 0; i < nfield; i++) delete[] vformat[i];
|
||||||
@ -668,12 +665,9 @@ int DumpGrid::parse_fields(int narg, char **arg)
|
|||||||
|
|
||||||
for (int iarg = 0; iarg < narg; iarg++) {
|
for (int iarg = 0; iarg < narg; iarg++) {
|
||||||
|
|
||||||
int n,flag,cols;
|
|
||||||
ArgInfo argi(arg[iarg], ArgInfo::COMPUTE | ArgInfo::FIX);
|
ArgInfo argi(arg[iarg], ArgInfo::COMPUTE | ArgInfo::FIX);
|
||||||
argindex[iarg] = argi.get_index1();
|
argindex[iarg] = argi.get_index1();
|
||||||
auto name = argi.get_name();
|
auto name = argi.get_name();
|
||||||
Compute *icompute = nullptr;
|
|
||||||
Fix *ifix = nullptr;
|
|
||||||
|
|
||||||
switch (argi.get_type()) {
|
switch (argi.get_type()) {
|
||||||
|
|
||||||
@ -692,49 +686,37 @@ int DumpGrid::parse_fields(int narg, char **arg)
|
|||||||
|
|
||||||
// split name = idcompute:gname:dname into 3 strings
|
// split name = idcompute:gname:dname into 3 strings
|
||||||
|
|
||||||
char *idcompute,*gname,*dname;
|
auto words = utils::gridid_parse(FLERR,name,error);
|
||||||
utils::grid_parse(FLERR,name,idcompute,gname,dname,error);
|
const auto &idcompute = words[0];
|
||||||
|
const auto &gname = words[1];
|
||||||
|
const auto &dname = words[2];
|
||||||
|
|
||||||
icompute = modify->get_compute_by_id(idcompute);
|
auto icompute = modify->get_compute_by_id(idcompute);
|
||||||
if (!icompute)
|
if (!icompute) error->all(FLERR,"Could not find dump grid compute ID: {}",idcompute);
|
||||||
error->all(FLERR,"Could not find dump grid compute ID: {}",idcompute);
|
|
||||||
if (icompute->pergrid_flag == 0)
|
if (icompute->pergrid_flag == 0)
|
||||||
error->all(FLERR,"Dump grid compute {} does not compute per-grid info",
|
error->all(FLERR,"Dump grid compute {} does not compute per-grid info",idcompute);
|
||||||
idcompute);
|
|
||||||
|
|
||||||
int dim;
|
int dim;
|
||||||
int igrid = icompute->get_grid_by_name(gname,dim);
|
int igrid = icompute->get_grid_by_name(gname,dim);
|
||||||
if (igrid < 0)
|
if (igrid < 0)
|
||||||
error->all(FLERR,"Dump grid compute {} does not recognize grid name {}",
|
error->all(FLERR,"Dump grid compute {} does not recognize grid name {}",idcompute,gname);
|
||||||
idcompute,gname);
|
|
||||||
|
|
||||||
int ncol;
|
int ncol;
|
||||||
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
|
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
|
||||||
if (idata < 0)
|
if (idata < 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Dump grid compute {} does not recognize data name {}",idcompute,dname);
|
||||||
"Dump grid compute {} does not recognize data name {}",
|
|
||||||
idcompute,dname);
|
|
||||||
|
|
||||||
if (argi.get_dim() == 0 && ncol)
|
if (argi.get_dim() == 0 && ncol)
|
||||||
error->all(FLERR,"Dump grid compute {} data {} is not per-grid vector",
|
error->all(FLERR,"Dump grid compute {} data {} is not per-grid vector",idcompute,dname);
|
||||||
idcompute,dname);
|
|
||||||
if (argi.get_dim() && ncol == 0)
|
if (argi.get_dim() && ncol == 0)
|
||||||
error->all(FLERR,"Dump grid compute {} data {} is not per-grid array",
|
error->all(FLERR,"Dump grid compute {} data {} is not per-grid array",idcompute,dname);
|
||||||
idcompute,dname);
|
|
||||||
if (argi.get_dim() && argi.get_index1() > ncol)
|
if (argi.get_dim() && argi.get_index1() > ncol)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Dump grid compute {} array {} is accessed out-of-range",idcompute,dname);
|
||||||
"Dump grid compute {} array {} is accessed out-of-range",
|
|
||||||
idcompute,dname);
|
|
||||||
|
|
||||||
|
field2index[iarg] = add_compute(idcompute,icompute);
|
||||||
field2index[iarg] = add_compute(idcompute);
|
|
||||||
field2grid[iarg] = igrid;
|
field2grid[iarg] = igrid;
|
||||||
field2data[iarg] = idata;
|
field2data[iarg] = idata;
|
||||||
|
|
||||||
delete [] idcompute;
|
|
||||||
delete [] gname;
|
|
||||||
delete [] dname;
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// fix value = f_ID
|
// fix value = f_ID
|
||||||
@ -748,47 +730,39 @@ int DumpGrid::parse_fields(int narg, char **arg)
|
|||||||
|
|
||||||
// split name = idfix:gname:dname into 3 strings
|
// split name = idfix:gname:dname into 3 strings
|
||||||
|
|
||||||
char *idfix,*gname,*dname;
|
auto words = utils::gridid_parse(FLERR,name,error);
|
||||||
utils::grid_parse(FLERR,name,idfix,gname,dname,error);
|
const auto &idfix = words[0];
|
||||||
|
const auto &gname = words[1];
|
||||||
|
const auto &dname = words[2];
|
||||||
|
|
||||||
ifix = modify->get_fix_by_id(idfix);
|
auto ifix = modify->get_fix_by_id(idfix);
|
||||||
if (!ifix) error->all(FLERR,"Could not find dump grid fix ID: {}",idfix);
|
if (!ifix) error->all(FLERR,"Could not find dump grid fix ID: {}",idfix);
|
||||||
if (ifix->pergrid_flag == 0)
|
if (ifix->pergrid_flag == 0)
|
||||||
error->all(FLERR,"Dump grid fix {} does not compute per-grid info",
|
error->all(FLERR,"Dump grid fix {} does not compute per-grid info",idfix);
|
||||||
idfix);
|
|
||||||
if (update->ntimestep % ifix->pergrid_freq)
|
if (update->ntimestep % ifix->pergrid_freq)
|
||||||
error->all(FLERR,"Fix for dump grid not computed at compatible time");
|
error->all(FLERR,"Fix ID {} for dump grid not computed at compatible time",idfix);
|
||||||
|
|
||||||
int dim;
|
int dim;
|
||||||
int igrid = ifix->get_grid_by_name(gname,dim);
|
int igrid = ifix->get_grid_by_name(gname,dim);
|
||||||
if (igrid < 0)
|
if (igrid < 0)
|
||||||
error->all(FLERR,"Dump grid fix {} does not recognize grid name {}",
|
error->all(FLERR,"Dump grid fix {} does not recognize grid name {}",idfix,gname);
|
||||||
idfix,gname);
|
|
||||||
|
|
||||||
int ncol;
|
int ncol;
|
||||||
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
|
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
|
||||||
if (idata < 0)
|
if (idata < 0)
|
||||||
error->all(FLERR,"Dump grid fix {} does not recognize data name {}",
|
error->all(FLERR,"Dump grid fix {} does not recognize data name {}",idfix,dname);
|
||||||
idfix,dname);
|
|
||||||
|
|
||||||
if (argi.get_dim() == 0 && ncol)
|
if (argi.get_dim() == 0 && ncol)
|
||||||
error->all(FLERR,"Dump grid fix {} data {} is not per-grid vector",
|
error->all(FLERR,"Dump grid fix {} data {} is not per-grid vector",idfix,dname);
|
||||||
idfix,dname);
|
|
||||||
if (argi.get_dim() > 0 && ncol == 0)
|
if (argi.get_dim() > 0 && ncol == 0)
|
||||||
error->all(FLERR,"Dump grid fix {} data {} is not per-grid array",
|
error->all(FLERR,"Dump grid fix {} data {} is not per-grid array",idfix,dname);
|
||||||
idfix,dname);
|
|
||||||
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
|
if (argi.get_dim() > 0 && argi.get_index1() > ncol)
|
||||||
error->all(FLERR,"Dump grid fix {} array {} is accessed out-of-range",
|
error->all(FLERR,"Dump grid fix {} array {} is accessed out-of-range",idfix,dname);
|
||||||
idfix,dname);
|
|
||||||
|
|
||||||
field2index[iarg] = add_fix(idfix);
|
field2index[iarg] = add_fix(idfix,ifix);
|
||||||
field2grid[iarg] = igrid;
|
field2grid[iarg] = igrid;
|
||||||
field2data[iarg] = idata;
|
field2data[iarg] = idata;
|
||||||
|
|
||||||
delete [] idfix;
|
|
||||||
delete [] gname;
|
|
||||||
delete [] dname;
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// no match
|
// no match
|
||||||
@ -808,19 +782,17 @@ int DumpGrid::parse_fields(int narg, char **arg)
|
|||||||
if already in list, do not add, just return index, else add to list
|
if already in list, do not add, just return index, else add to list
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int DumpGrid::add_compute(const char *id)
|
int DumpGrid::add_compute(const std::string &id, Compute *cptr)
|
||||||
{
|
{
|
||||||
int icompute;
|
int icompute;
|
||||||
for (icompute = 0; icompute < ncompute; icompute++)
|
for (icompute = 0; icompute < ncompute; icompute++)
|
||||||
if (strcmp(id,id_compute[icompute]) == 0) break;
|
if (id == id_compute[icompute]) break;
|
||||||
if (icompute < ncompute) return icompute;
|
if (icompute < ncompute) return icompute;
|
||||||
|
|
||||||
id_compute = (char **)
|
id_compute = (char **) memory->srealloc(id_compute,(ncompute+1)*sizeof(char *),"dump:id_compute");
|
||||||
memory->srealloc(id_compute,(ncompute+1)*sizeof(char *),"dump:id_compute");
|
|
||||||
delete[] compute;
|
|
||||||
compute = new Compute*[ncompute+1];
|
|
||||||
|
|
||||||
id_compute[ncompute] = utils::strdup(id);
|
id_compute[ncompute] = utils::strdup(id);
|
||||||
|
compute.push_back(cptr);
|
||||||
|
|
||||||
ncompute++;
|
ncompute++;
|
||||||
return ncompute-1;
|
return ncompute-1;
|
||||||
}
|
}
|
||||||
@ -831,19 +803,17 @@ int DumpGrid::add_compute(const char *id)
|
|||||||
if already in list, do not add, just return index, else add to list
|
if already in list, do not add, just return index, else add to list
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int DumpGrid::add_fix(const char *id)
|
int DumpGrid::add_fix(const std::string &id, Fix *fptr)
|
||||||
{
|
{
|
||||||
int ifix;
|
int ifix;
|
||||||
for (ifix = 0; ifix < nfix; ifix++)
|
for (ifix = 0; ifix < nfix; ifix++)
|
||||||
if (strcmp(id,id_fix[ifix]) == 0) break;
|
if (id == id_fix[ifix]) break;
|
||||||
if (ifix < nfix) return ifix;
|
if (ifix < nfix) return ifix;
|
||||||
|
|
||||||
id_fix = (char **)
|
id_fix = (char **) memory->srealloc(id_fix,(nfix+1)*sizeof(char *),"dump:id_fix");
|
||||||
memory->srealloc(id_fix,(nfix+1)*sizeof(char *),"dump:id_fix");
|
|
||||||
delete[] fix;
|
|
||||||
fix = new Fix*[nfix+1];
|
|
||||||
|
|
||||||
id_fix[nfix] = utils::strdup(id);
|
id_fix[nfix] = utils::strdup(id);
|
||||||
|
fix.push_back(fptr);
|
||||||
|
|
||||||
nfix++;
|
nfix++;
|
||||||
return nfix-1;
|
return nfix-1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class DumpGrid : public Dump {
|
|||||||
|
|
||||||
int dimension;
|
int dimension;
|
||||||
|
|
||||||
int nxgrid,nygrid,nzgrid; // global grid size
|
int nxgrid, nygrid, nzgrid; // global grid size
|
||||||
|
|
||||||
int nfield; // # of keywords listed by user
|
int nfield; // # of keywords listed by user
|
||||||
int ioptional; // index of start of optional args
|
int ioptional; // index of start of optional args
|
||||||
@ -64,15 +64,15 @@ class DumpGrid : public Dump {
|
|||||||
|
|
||||||
int ncompute; // # of Computes accessed by dump
|
int ncompute; // # of Computes accessed by dump
|
||||||
char **id_compute; // their IDs
|
char **id_compute; // their IDs
|
||||||
class Compute **compute; // list of ptrs to the Computes
|
std::vector<class Compute *> compute; // list of ptrs to the Computes
|
||||||
|
|
||||||
int nfix; // # of Fixes used by dump
|
int nfix; // # of Fixes used by dump
|
||||||
char **id_fix; // their IDs
|
char **id_fix; // their IDs
|
||||||
class Fix **fix; // list of ptrs to the Fixes
|
std::vector<class Fix *> fix; // list of ptrs to the Fixes
|
||||||
|
|
||||||
int nxlo_in,nxhi_in; // bounds of this proc's portion of grids
|
int nxlo_in, nxhi_in; // bounds of this proc's portion of grids
|
||||||
int nylo_in,nyhi_in;
|
int nylo_in, nyhi_in;
|
||||||
int nzlo_in,nzhi_in;
|
int nzlo_in, nzhi_in;
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
|
|
||||||
@ -85,8 +85,8 @@ class DumpGrid : public Dump {
|
|||||||
double memory_usage() override;
|
double memory_usage() override;
|
||||||
|
|
||||||
int parse_fields(int, char **);
|
int parse_fields(int, char **);
|
||||||
int add_compute(const char *);
|
int add_compute(const std::string &, class Compute *);
|
||||||
int add_fix(const char *);
|
int add_fix(const std::string &, class Fix *);
|
||||||
int modify_param(int, char **) override;
|
int modify_param(int, char **) override;
|
||||||
|
|
||||||
void header_format_binary();
|
void header_format_binary();
|
||||||
|
|||||||
@ -220,9 +220,9 @@ class Fix : protected Pointers {
|
|||||||
virtual void pack_gather_grid(int, void *){};
|
virtual void pack_gather_grid(int, void *){};
|
||||||
virtual void unpack_gather_grid(int, void *, void *, int, int, int, int, int, int){};
|
virtual void unpack_gather_grid(int, void *, void *, int, int, int, int, int, int){};
|
||||||
|
|
||||||
virtual int get_grid_by_name(char *, int &) { return -1; };
|
virtual int get_grid_by_name(const std::string &, int &) { return -1; };
|
||||||
virtual void *get_grid_by_index(int) { return nullptr; };
|
virtual void *get_grid_by_index(int) { return nullptr; };
|
||||||
virtual int get_griddata_by_name(int, char *, int &) { return -1; };
|
virtual int get_griddata_by_name(int, const std::string &, int &) { return -1; };
|
||||||
virtual void *get_griddata_by_index(int) { return nullptr; };
|
virtual void *get_griddata_by_index(int) { return nullptr; };
|
||||||
|
|
||||||
virtual double compute_scalar() { return 0.0; }
|
virtual double compute_scalar() { return 0.0; }
|
||||||
|
|||||||
@ -53,7 +53,7 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
value2index(nullptr), value2grid(nullptr), value2data(nullptr),
|
value2index(nullptr), value2grid(nullptr), value2data(nullptr),
|
||||||
grid2d(nullptr), grid3d(nullptr),
|
grid2d(nullptr), grid3d(nullptr),
|
||||||
grid_buf1(nullptr), grid_buf2(nullptr),
|
grid_buf1(nullptr), grid_buf2(nullptr),
|
||||||
vec2d(nullptr), array2d(nullptr), vec3d(nullptr), array3d(nullptr),
|
vec2d(nullptr), vec3d(nullptr), array2d(nullptr), array3d(nullptr),
|
||||||
count2d(nullptr), count3d(nullptr)
|
count2d(nullptr), count3d(nullptr)
|
||||||
{
|
{
|
||||||
if (narg < 10) error->all(FLERR,"Illegal fix ave/grid command");
|
if (narg < 10) error->all(FLERR,"Illegal fix ave/grid command");
|
||||||
@ -232,7 +232,7 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
// if wildcard expansion occurred, free earg memory from exapnd_args()
|
// if wildcard expansion occurred, free earg memory from exapnd_args()
|
||||||
|
|
||||||
if (expand) {
|
if (expand) {
|
||||||
for (int i = 0; i < nvalues; i++) delete [] earg[i];
|
for (int i = 0; i < nvalues; i++) delete[] earg[i];
|
||||||
memory->sfree(earg);
|
memory->sfree(earg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,106 +322,78 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
for (int i = 0; i < nvalues; i++) {
|
for (int i = 0; i < nvalues; i++) {
|
||||||
if (which[i] == ArgInfo::COMPUTE) {
|
if (which[i] == ArgInfo::COMPUTE) {
|
||||||
|
|
||||||
char *idcompute,*gname,*dname;
|
auto words = utils::gridid_parse(FLERR,ids[i],error);
|
||||||
utils::grid_parse(FLERR,ids[i],idcompute,gname,dname,error);
|
const auto &idcompute = words[0];
|
||||||
delete [] ids[i];
|
const auto &gname = words[1];
|
||||||
ids[i] = new char[strlen(idcompute)+1];
|
const auto &dname = words[2];
|
||||||
strcpy(ids[i],idcompute);
|
|
||||||
|
|
||||||
Compute *icompute = modify->get_compute_by_id(idcompute);
|
delete[] ids[i];
|
||||||
if (!icompute)
|
ids[i] = utils::strdup(idcompute);
|
||||||
error->all(FLERR,"Could not find fix ave/grid compute ID: {}",
|
|
||||||
idcompute);
|
auto icompute = modify->get_compute_by_id(idcompute);
|
||||||
|
if (!icompute) error->all(FLERR,"Could not find fix ave/grid compute ID: {}",idcompute);
|
||||||
if (icompute->pergrid_flag == 0)
|
if (icompute->pergrid_flag == 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid compute {} does not compute per-grid info",idcompute);
|
||||||
"Fix ave/grid compute {} does not compute per-grid info",
|
|
||||||
idcompute);
|
|
||||||
|
|
||||||
int dim;
|
int dim;
|
||||||
int igrid = icompute->get_grid_by_name(gname,dim);
|
int igrid = icompute->get_grid_by_name(gname,dim);
|
||||||
if (igrid < 0)
|
if (igrid < 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid compute {} does not recognize grid name {}",
|
||||||
"Fix ave/grid compute {} does not recognize grid name {}",
|
|
||||||
idcompute,gname);
|
idcompute,gname);
|
||||||
|
|
||||||
int ncol;
|
int ncol;
|
||||||
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
|
int idata = icompute->get_griddata_by_name(igrid,dname,ncol);
|
||||||
if (idata < 0)
|
if (idata < 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid compute {} does not recognize data name {}",
|
||||||
"Fix ave/grid compute {} does not recognize data name {}",
|
|
||||||
idcompute,dname);
|
idcompute,dname);
|
||||||
|
|
||||||
if (argindex[i] == 0 && ncol)
|
if (argindex[i] == 0 && ncol)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid compute {} data {} is not per-grid vector",idcompute,dname);
|
||||||
"Fix ave/grid compute {} data {} is not per-grid vector",
|
|
||||||
idcompute,dname);
|
|
||||||
if (argindex[i] && ncol == 0)
|
if (argindex[i] && ncol == 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid compute {} data {} is not per-grid array",idcompute,dname);
|
||||||
"Fix ave/grid compute {} data {} is not per-grid array",
|
|
||||||
idcompute,dname);
|
|
||||||
if (argindex[i] && argindex[i] > ncol)
|
if (argindex[i] && argindex[i] > ncol)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid compute {} array {} is accessed out-of-range",
|
||||||
"Fix ave/grid compute {} array {} is accessed out-of-range",
|
|
||||||
idcompute,dname);
|
idcompute,dname);
|
||||||
|
|
||||||
value2grid[i] = igrid;
|
value2grid[i] = igrid;
|
||||||
value2data[i] = idata;
|
value2data[i] = idata;
|
||||||
|
|
||||||
delete [] idcompute;
|
|
||||||
delete [] gname;
|
|
||||||
delete [] dname;
|
|
||||||
|
|
||||||
} else if (which[i] == ArgInfo::FIX) {
|
} else if (which[i] == ArgInfo::FIX) {
|
||||||
|
|
||||||
char *idfix,*gname,*dname;
|
auto words = utils::gridid_parse(FLERR,ids[i],error);
|
||||||
utils::grid_parse(FLERR,ids[i],idfix,gname,dname,error);
|
const auto &idfix = words[0];
|
||||||
delete [] ids[i];
|
const auto &gname = words[1];
|
||||||
ids[i] = new char[strlen(idfix)+1];
|
const auto &dname = words[2];
|
||||||
strcpy(ids[i],idfix);
|
|
||||||
|
delete[] ids[i];
|
||||||
|
ids[i] = utils::strdup(idfix);
|
||||||
|
|
||||||
Fix *ifix = modify->get_fix_by_id(idfix);
|
Fix *ifix = modify->get_fix_by_id(idfix);
|
||||||
if (!ifix) error->all(FLERR,"Could not find fix ave/grid fix ID: {}",
|
if (!ifix) error->all(FLERR,"Could not find fix ave/grid fix ID: {}",idfix);
|
||||||
idfix);
|
|
||||||
if (ifix->pergrid_flag == 0)
|
if (ifix->pergrid_flag == 0)
|
||||||
error->all(FLERR,"Fix ave/grid fix {} does not compute per-grid info",
|
error->all(FLERR,"Fix ave/grid fix {} does not compute per-grid info",idfix);
|
||||||
idfix);
|
|
||||||
if (nevery % ifix->pergrid_freq)
|
if (nevery % ifix->pergrid_freq)
|
||||||
error->all(FLERR,
|
error->all(FLERR, "Fix ID {} for fix grid/atom not computed at compatible time",idfix);
|
||||||
"Fix for fix grid/atom not computed at compatible time");
|
|
||||||
|
|
||||||
int dim;
|
int dim;
|
||||||
int igrid = ifix->get_grid_by_name(gname,dim);
|
int igrid = ifix->get_grid_by_name(gname,dim);
|
||||||
if (igrid < 0)
|
if (igrid < 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid fix {} does not recognize grid name {}",idfix,gname);
|
||||||
"Fix ave/grid compute {} does not recognize grid name {}",
|
|
||||||
idfix,gname);
|
|
||||||
|
|
||||||
int ncol;
|
int ncol;
|
||||||
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
|
int idata = ifix->get_griddata_by_name(igrid,dname,ncol);
|
||||||
if (idata < 0)
|
if (idata < 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid fix {} does not recognize data name {}",idfix,dname);
|
||||||
"Fix ave/grid compute {} does not recognize data name {}",
|
|
||||||
idfix,dname);
|
|
||||||
|
|
||||||
if (argindex[i] == 0 && ncol)
|
if (argindex[i] == 0 && ncol)
|
||||||
error->all(FLERR,
|
error->all(FLERR, "Fix ave/grid fix {} data {} is not per-grid vector",idfix,dname);
|
||||||
"Fix ave/grid compute {} data {} is not per-grid vector",
|
|
||||||
idfix,dname);
|
|
||||||
if (argindex[i] && ncol == 0)
|
if (argindex[i] && ncol == 0)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid fix {} data {} is not per-grid array",idfix,dname);
|
||||||
"Fix ave/grid compute {} data {} is not per-grid array",
|
|
||||||
idfix,dname);
|
|
||||||
if (argindex[i] && argindex[i] > ncol)
|
if (argindex[i] && argindex[i] > ncol)
|
||||||
error->all(FLERR,
|
error->all(FLERR,"Fix ave/grid fix {} array {} is accessed out-of-range",idfix,dname);
|
||||||
"Fix ave/grid compute {} array {} is accessed out-of-range",
|
|
||||||
idfix,dname);
|
|
||||||
|
|
||||||
value2grid[i] = igrid;
|
value2grid[i] = igrid;
|
||||||
value2data[i] = idata;
|
value2data[i] = idata;
|
||||||
|
|
||||||
delete [] idfix;
|
|
||||||
delete [] gname;
|
|
||||||
delete [] dname;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -516,13 +488,13 @@ FixAveGrid::FixAveGrid(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
FixAveGrid::~FixAveGrid()
|
FixAveGrid::~FixAveGrid()
|
||||||
{
|
{
|
||||||
delete [] which;
|
delete[] which;
|
||||||
delete [] argindex;
|
delete[] argindex;
|
||||||
for (int m = 0; m < nvalues; m++) delete [] ids[m];
|
for (int m = 0; m < nvalues; m++) delete[] ids[m];
|
||||||
delete [] ids;
|
delete[] ids;
|
||||||
delete [] value2index;
|
delete[] value2index;
|
||||||
delete [] value2grid;
|
delete[] value2grid;
|
||||||
delete [] value2data;
|
delete[] value2data;
|
||||||
|
|
||||||
delete grid2d;
|
delete grid2d;
|
||||||
delete grid3d;
|
delete grid3d;
|
||||||
@ -715,7 +687,7 @@ void FixAveGrid::end_of_step()
|
|||||||
double mv2d = force->mv2d;
|
double mv2d = force->mv2d;
|
||||||
double boltz = force->boltz;
|
double boltz = force->boltz;
|
||||||
|
|
||||||
double count,invcount,norm;
|
double count,norm;
|
||||||
double repeat = nrepeat;
|
double repeat = nrepeat;
|
||||||
double invrepeat = 1.0/nrepeat;
|
double invrepeat = 1.0/nrepeat;
|
||||||
|
|
||||||
@ -751,7 +723,6 @@ void FixAveGrid::end_of_step()
|
|||||||
for (ix = nxlo_in; ix <= nxhi_in; ix++) {
|
for (ix = nxlo_in; ix <= nxhi_in; ix++) {
|
||||||
count = count2d[iy][ix];
|
count = count2d[iy][ix];
|
||||||
if (count) {
|
if (count) {
|
||||||
invcount = 1.0/count;
|
|
||||||
for (m = 0; m <= nvalues; m++) {
|
for (m = 0; m <= nvalues; m++) {
|
||||||
if (which[m] == ArgInfo::DENSITY_NUMBER)
|
if (which[m] == ArgInfo::DENSITY_NUMBER)
|
||||||
norm = 1.0 / (binvol * repeat);
|
norm = 1.0 / (binvol * repeat);
|
||||||
@ -792,7 +763,6 @@ void FixAveGrid::end_of_step()
|
|||||||
for (ix = nxlo_in; ix <= nxhi_in; ix++) {
|
for (ix = nxlo_in; ix <= nxhi_in; ix++) {
|
||||||
count = count3d[iz][iy][ix];
|
count = count3d[iz][iy][ix];
|
||||||
if (count) {
|
if (count) {
|
||||||
invcount = 1.0/count;
|
|
||||||
for (m = 0; m <= nvalues; m++) {
|
for (m = 0; m <= nvalues; m++) {
|
||||||
if (which[m] == ArgInfo::DENSITY_NUMBER)
|
if (which[m] == ArgInfo::DENSITY_NUMBER)
|
||||||
norm = 1.0 / (binvol * repeat);
|
norm = 1.0 / (binvol * repeat);
|
||||||
@ -850,7 +820,7 @@ void FixAveGrid::end_of_step()
|
|||||||
|
|
||||||
void FixAveGrid::atom2grid()
|
void FixAveGrid::atom2grid()
|
||||||
{
|
{
|
||||||
int i,j,k,m,n,ix,iy,iz;
|
int i,j,m,n,ix,iy,iz;
|
||||||
|
|
||||||
// bin[i][dim] = indices of bin each atom is in
|
// bin[i][dim] = indices of bin each atom is in
|
||||||
// not set if group mask does not match
|
// not set if group mask does not match
|
||||||
@ -1424,9 +1394,9 @@ void FixAveGrid::reset_grid()
|
|||||||
return -1 if grid name not found
|
return -1 if grid name not found
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixAveGrid::get_grid_by_name(char *name, int &dim)
|
int FixAveGrid::get_grid_by_name(const std::string &name, int &dim)
|
||||||
{
|
{
|
||||||
if (strcmp(name,"grid") == 0) {
|
if (name == "grid") {
|
||||||
dim = dimension;
|
dim = dimension;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1460,9 +1430,9 @@ void *FixAveGrid::get_grid_by_index(int index)
|
|||||||
return -1 if data name not found
|
return -1 if data name not found
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixAveGrid::get_griddata_by_name(int igrid, char *name, int &ncol)
|
int FixAveGrid::get_griddata_by_name(int igrid, const std::string &name, int &ncol)
|
||||||
{
|
{
|
||||||
if (igrid == 0 && strcmp(name,"data") == 0) {
|
if ((igrid == 0) && (name == "data")) {
|
||||||
if (nvalues == 1) ncol = 0;
|
if (nvalues == 1) ncol = 0;
|
||||||
else ncol = nvalues;
|
else ncol = nvalues;
|
||||||
return 0;
|
return 0;
|
||||||
@ -1470,7 +1440,7 @@ int FixAveGrid::get_griddata_by_name(int igrid, char *name, int &ncol)
|
|||||||
|
|
||||||
// count is only produced for ATOM mode
|
// count is only produced for ATOM mode
|
||||||
|
|
||||||
if (modeatom && igrid == 0 && strcmp(name,"count") == 0) {
|
if (modeatom && (igrid == 0) && (name == "count")) {
|
||||||
ncol = 0;
|
ncol = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,9 +38,9 @@ class FixAveGrid : public Fix {
|
|||||||
|
|
||||||
void reset_grid() override;
|
void reset_grid() override;
|
||||||
|
|
||||||
int get_grid_by_name(char *, int &) override;
|
int get_grid_by_name(const std::string &, int &) override;
|
||||||
void *get_grid_by_index(int) override;
|
void *get_grid_by_index(int) override;
|
||||||
int get_griddata_by_name(int, char *, int &) override;
|
int get_griddata_by_name(int, const std::string &, int &) override;
|
||||||
void *get_griddata_by_index(int) override;
|
void *get_griddata_by_index(int) override;
|
||||||
|
|
||||||
double memory_usage() override;
|
double memory_usage() override;
|
||||||
|
|||||||
@ -768,26 +768,21 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
Parse grid reference into id:gridname:dataname
|
Parse grid reference into id:gridname:dataname
|
||||||
return ptrs to 3 substrings
|
return vector of 3 substrings
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void utils::grid_parse(const char *file, int line, const std::string &name,
|
std::vector<std::string> utils::gridid_parse(const char *file, int line, const std::string &name,
|
||||||
char *&id, char *&gridname, char *&dataname, Error *error)
|
Error *error)
|
||||||
{
|
{
|
||||||
char *copy = strdup(name);
|
auto words = Tokenizer(name, ":").as_vector();
|
||||||
|
if (words.size() != 3) {
|
||||||
|
if (error)
|
||||||
|
error->all(FLERR, "Grid ID {} does not contain two ':' characters", name);
|
||||||
|
else
|
||||||
|
return {"", "", ""};
|
||||||
|
}
|
||||||
|
|
||||||
char *ptr1 = strchr(copy,':');
|
return words;
|
||||||
if (!ptr1)
|
|
||||||
error->all(FLERR,"Grid reference {} does not contain 2 ':' chars",name);
|
|
||||||
*ptr1 = '\0';
|
|
||||||
char *ptr2 = strchr(ptr1+1,':');
|
|
||||||
if (!ptr2)
|
|
||||||
error->all(FLERR,"Grid reference {} does not contain 2 ':' chars",name);
|
|
||||||
*ptr2 = '\0';
|
|
||||||
|
|
||||||
id = strdup(copy);
|
|
||||||
gridname = strdup(ptr1+1);
|
|
||||||
dataname = strdup(ptr2+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|||||||
26
src/utils.h
26
src/utils.h
@ -359,6 +359,19 @@ namespace utils {
|
|||||||
int expand_args(const char *file, int line, int narg, char **arg, int mode, char **&earg,
|
int expand_args(const char *file, int line, int narg, char **arg, int mode, char **&earg,
|
||||||
LAMMPS *lmp);
|
LAMMPS *lmp);
|
||||||
|
|
||||||
|
/*! Parse grid reference into 3 sub-strings
|
||||||
|
*
|
||||||
|
* Format of grid ID reference = id:gridname:dataname
|
||||||
|
* Return vector with the 3 sub-strings
|
||||||
|
*
|
||||||
|
* \param name = grid reference
|
||||||
|
* \param id = ptr to 1st substring
|
||||||
|
* \param gridname = ptr to 2nd substring
|
||||||
|
* \param dataname = ptr to 3rd substring */
|
||||||
|
|
||||||
|
std::vector<std::string> gridid_parse(const char *file, int line, const std::string &name,
|
||||||
|
Error *error);
|
||||||
|
|
||||||
/*! Make C-style copy of string in new storage
|
/*! Make C-style copy of string in new storage
|
||||||
*
|
*
|
||||||
* This allocates a storage buffer and copies the C-style or
|
* This allocates a storage buffer and copies the C-style or
|
||||||
@ -368,19 +381,6 @@ namespace utils {
|
|||||||
* \param text string that should be copied
|
* \param text string that should be copied
|
||||||
* \return new buffer with copy of string */
|
* \return new buffer with copy of string */
|
||||||
|
|
||||||
void grid_parse(const char *file, int line, const std::string &name,
|
|
||||||
char *&id, char *&gridname, char *&dataname, Error *error);
|
|
||||||
|
|
||||||
/*! Parse grid reference into 3 sub-strings
|
|
||||||
*
|
|
||||||
* Format of grid reference = id:gridname:dataname
|
|
||||||
* Return ptrs to the 3 sub-strings
|
|
||||||
*
|
|
||||||
* \param name = grid reference
|
|
||||||
* \param id = ptr to 1st substring
|
|
||||||
* \param gridname = ptr to 2nd substring
|
|
||||||
* \param dataname = ptr to 3rd substring */
|
|
||||||
|
|
||||||
char *strdup(const std::string &text);
|
char *strdup(const std::string &text);
|
||||||
|
|
||||||
/*! Convert string to lowercase
|
/*! Convert string to lowercase
|
||||||
|
|||||||
@ -785,6 +785,34 @@ TEST(Utils, boundsbig_case3)
|
|||||||
ASSERT_EQ(nhi, -1);
|
ASSERT_EQ(nhi, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Utils, gridid_parse)
|
||||||
|
{
|
||||||
|
auto words = utils::gridid_parse(FLERR, "c_1:full:density", nullptr);
|
||||||
|
ASSERT_THAT(words[0], StrEq("c_1"));
|
||||||
|
ASSERT_THAT(words[1], StrEq("full"));
|
||||||
|
ASSERT_THAT(words[2], StrEq("density"));
|
||||||
|
|
||||||
|
words = utils::gridid_parse(FLERR, "c_1_full_density", nullptr);
|
||||||
|
ASSERT_THAT(words[0], StrEq(""));
|
||||||
|
ASSERT_THAT(words[1], StrEq(""));
|
||||||
|
ASSERT_THAT(words[0], StrEq(""));
|
||||||
|
|
||||||
|
words = utils::gridid_parse(FLERR, "c_1:full:", nullptr);
|
||||||
|
ASSERT_THAT(words[0], StrEq("c_1"));
|
||||||
|
ASSERT_THAT(words[1], StrEq("full"));
|
||||||
|
ASSERT_THAT(words[0], StrEq(""));
|
||||||
|
|
||||||
|
words = utils::gridid_parse(FLERR, ":full:density", nullptr);
|
||||||
|
ASSERT_THAT(words[0], StrEq(""));
|
||||||
|
ASSERT_THAT(words[1], StrEq("full"));
|
||||||
|
ASSERT_THAT(words[0], StrEq("density"));
|
||||||
|
|
||||||
|
words = utils::gridid_parse(FLERR, "c_1:full", nullptr);
|
||||||
|
ASSERT_THAT(words[0], StrEq(""));
|
||||||
|
ASSERT_THAT(words[1], StrEq(""));
|
||||||
|
ASSERT_THAT(words[0], StrEq(""));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Utils, errorurl)
|
TEST(Utils, errorurl)
|
||||||
{
|
{
|
||||||
auto errmesg = utils::errorurl(10);
|
auto errmesg = utils::errorurl(10);
|
||||||
|
|||||||
Reference in New Issue
Block a user