update utils::expand_args() to it can handle gridIDs
This commit is contained in:
126
src/utils.cpp
126
src/utils.cpp
@ -628,11 +628,79 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
std::string word(arg[iarg]);
|
std::string word(arg[iarg]);
|
||||||
expandflag = 0;
|
expandflag = 0;
|
||||||
|
|
||||||
// match compute, fix, or custom property array reference with a '*' wildcard
|
// match grids
|
||||||
// number range in the first pair of square brackets
|
|
||||||
|
|
||||||
if (strmatch(word, "^[cfv]_\\w+\\[\\d*\\*\\d*\\]") ||
|
if (strmatch(word, "^[cf]_\\w+:\\w+:\\w+\\[\\d*\\*\\d*\\]")) {
|
||||||
strmatch(word, "^[id]2_\\w+\\[\\d*\\*\\d*\\]")) {
|
auto gridid = utils::parse_gridid(FLERR, word, lmp->error);
|
||||||
|
|
||||||
|
size_t first = gridid[2].find('[');
|
||||||
|
size_t second = gridid[2].find(']', first + 1);
|
||||||
|
id = gridid[2].substr(0, first);
|
||||||
|
wc = gridid[2].substr(first + 1, second - first - 1);
|
||||||
|
tail = gridid[2].substr(second + 1);
|
||||||
|
|
||||||
|
// grids from compute
|
||||||
|
|
||||||
|
if (gridid[0][0] == 'c') {
|
||||||
|
|
||||||
|
auto compute = lmp->modify->get_compute_by_id(gridid[0].substr(2));
|
||||||
|
if (compute && compute->pergrid_flag) {
|
||||||
|
|
||||||
|
int dim = 0;
|
||||||
|
int igrid = compute->get_grid_by_name(gridid[1], dim);
|
||||||
|
|
||||||
|
if (igrid >= 0) {
|
||||||
|
|
||||||
|
int ncol = 0;
|
||||||
|
int idata = compute->get_griddata_by_name(igrid, id, ncol);
|
||||||
|
nmax = ncol;
|
||||||
|
|
||||||
|
expandflag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// grids from fix
|
||||||
|
|
||||||
|
} else if (gridid[0][0] == 'f') {
|
||||||
|
|
||||||
|
auto fix = lmp->modify->get_fix_by_id(gridid[0].substr(2));
|
||||||
|
if (fix && fix->pergrid_flag) {
|
||||||
|
|
||||||
|
int dim = 0;
|
||||||
|
int igrid = fix->get_grid_by_name(gridid[1], dim);
|
||||||
|
|
||||||
|
if (igrid >= 0) {
|
||||||
|
|
||||||
|
int ncol = 0;
|
||||||
|
int idata = fix->get_griddata_by_name(igrid, id, ncol);
|
||||||
|
nmax = ncol;
|
||||||
|
|
||||||
|
expandflag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// expand wild card string to nlo/nhi numbers
|
||||||
|
|
||||||
|
if (expandflag) {
|
||||||
|
utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error);
|
||||||
|
|
||||||
|
if (newarg + nhi - nlo + 1 > maxarg) {
|
||||||
|
maxarg += nhi - nlo + 1;
|
||||||
|
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int index = nlo; index <= nhi; index++) {
|
||||||
|
earg[newarg] =
|
||||||
|
utils::strdup(fmt::format("{}:{}:{}[{}]{}", gridid[0], gridid[1], id, index, tail));
|
||||||
|
newarg++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// match compute, fix, or custom property array reference with a '*' wildcard
|
||||||
|
// number range in the first pair of square brackets
|
||||||
|
|
||||||
|
} else if (strmatch(word, "^[cfv]_\\w+\\[\\d*\\*\\d*\\]") ||
|
||||||
|
strmatch(word, "^[id]2_\\w+\\[\\d*\\*\\d*\\]")) {
|
||||||
|
|
||||||
// split off the compute/fix/property ID, the wildcard and trailing text
|
// split off the compute/fix/property ID, the wildcard and trailing text
|
||||||
|
|
||||||
@ -726,30 +794,33 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expansion will take place
|
||||||
|
|
||||||
|
if (expandflag) {
|
||||||
|
|
||||||
|
// expand wild card string to nlo/nhi numbers
|
||||||
|
|
||||||
|
utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error);
|
||||||
|
|
||||||
|
if (newarg + nhi - nlo + 1 > maxarg) {
|
||||||
|
maxarg += nhi - nlo + 1;
|
||||||
|
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int index = nlo; index <= nhi; index++) {
|
||||||
|
if (word[1] == '2')
|
||||||
|
earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail));
|
||||||
|
else
|
||||||
|
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
|
||||||
|
newarg++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// expansion will take place
|
// no expansion: duplicate original string
|
||||||
|
|
||||||
if (expandflag) {
|
if (!expandflag) {
|
||||||
|
|
||||||
// expand wild card string to nlo/nhi numbers
|
|
||||||
|
|
||||||
utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error);
|
|
||||||
|
|
||||||
if (newarg + nhi - nlo + 1 > maxarg) {
|
|
||||||
maxarg += nhi - nlo + 1;
|
|
||||||
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int index = nlo; index <= nhi; index++) {
|
|
||||||
if (word[1] == '2')
|
|
||||||
earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail));
|
|
||||||
else
|
|
||||||
earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail));
|
|
||||||
newarg++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// no expansion: duplicate original string
|
|
||||||
if (newarg == maxarg) {
|
if (newarg == maxarg) {
|
||||||
maxarg++;
|
maxarg++;
|
||||||
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
|
earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg");
|
||||||
@ -759,10 +830,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("NEWARG %d\n",newarg);
|
// printf("NEWARG %d\n",newarg); for (int i = 0; i < newarg; i++) printf(" arg %d: %s\n",i,earg[i]);
|
||||||
//for (int i = 0; i < newarg; i++)
|
|
||||||
// printf(" arg %d: %s\n",i,earg[i]);
|
|
||||||
|
|
||||||
return newarg;
|
return newarg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/utils.h
12
src/utils.h
@ -334,13 +334,15 @@ namespace utils {
|
|||||||
/*! Expand list of arguments when containing fix/compute wildcards
|
/*! Expand list of arguments when containing fix/compute wildcards
|
||||||
*
|
*
|
||||||
* This function searches the list of arguments in *arg* for strings
|
* This function searches the list of arguments in *arg* for strings
|
||||||
* of the kind c_ID[*] or f_ID[*] referring to computes or fixes.
|
* of the kind c_ID[*], f_ID[*], v_ID[*], i2_ID[*], d2_ID[*], or
|
||||||
|
* c_ID:gname:dname[*] referring to computes, fixes, vector style
|
||||||
|
* variables, custom per-atom arrays, or grids, respectively.
|
||||||
* Any such strings are replaced by one or more strings with the
|
* Any such strings are replaced by one or more strings with the
|
||||||
* '*' character replaced by the corresponding possible numbers as
|
* '*' character replaced by the corresponding possible numbers as
|
||||||
* determined from the fix or compute instance. Other strings are
|
* determined from the fix, compute, variable, property, or grid instance.
|
||||||
* just copied. If the *mode* parameter is set to 0, expand global
|
* Unrecognized strings are just copied. If the *mode* parameter
|
||||||
* vectors, but not global arrays; if it is set to 1, expand global
|
* is set to 0, expand global vectors, but not global arrays; if it is
|
||||||
* arrays (by column) but not global vectors.
|
* set to 1, expand global arrays (by column) but not global vectors.
|
||||||
*
|
*
|
||||||
* If any expansion happens, the earg list and all its
|
* If any expansion happens, the earg list and all its
|
||||||
* strings are new allocations and must be freed explicitly by the
|
* strings are new allocations and must be freed explicitly by the
|
||||||
|
|||||||
Reference in New Issue
Block a user