Merge branch 'master' into symbolic-atom-constants

This commit is contained in:
Axel Kohlmeyer
2020-09-15 17:44:31 -04:00
1186 changed files with 8448 additions and 8360 deletions

View File

@ -86,20 +86,20 @@ Variable::Variable(LAMMPS *lmp) : Pointers(lmp)
MPI_Comm_rank(world,&me);
nvar = maxvar = 0;
names = NULL;
style = NULL;
num = NULL;
which = NULL;
pad = NULL;
reader = NULL;
data = NULL;
dvalue = NULL;
vecs = NULL;
names = nullptr;
style = nullptr;
num = nullptr;
which = nullptr;
pad = nullptr;
reader = nullptr;
data = nullptr;
dvalue = nullptr;
vecs = nullptr;
eval_in_progress = NULL;
eval_in_progress = nullptr;
randomequal = NULL;
randomatom = NULL;
randomequal = nullptr;
randomatom = nullptr;
// customize by assigning a precedence level
@ -207,7 +207,7 @@ void Variable::set(int narg, char **arg)
num[nvar] = nlast;
which[nvar] = nfirst-1;
data[nvar] = new char*[1];
data[nvar][0] = NULL;
data[nvar][0] = nullptr;
// WORLD
// num = listed args, which = partition this proc is in, data = copied args
@ -251,7 +251,7 @@ void Variable::set(int narg, char **arg)
style[nvar] = ULOOP;
num[nvar] = utils::inumeric(FLERR,arg[2],false,lmp);
data[nvar] = new char*[1];
data[nvar][0] = NULL;
data[nvar][0] = nullptr;
if (narg == 4) {
char digits[12];
sprintf(digits,"%d",num[nvar]);
@ -265,12 +265,12 @@ void Variable::set(int narg, char **arg)
if (universe->me == 0) {
FILE *fp = fopen("tmp.lammps.variable","w");
if (fp == NULL)
if (fp == nullptr)
error->one(FLERR,"Cannot open temporary file for world counter: "
+ utils::getsyserror());
fprintf(fp,"%d\n",universe->nworlds);
fclose(fp);
fp = NULL;
fp = nullptr;
}
for (int jvar = 0; jvar < nvar; jvar++)
@ -355,7 +355,7 @@ void Variable::set(int narg, char **arg)
// ATOMFILE for numbers
// which = 1st value
// data = NULL
// data = nullptr
} else if (strcmp(arg[1],"atomfile") == 0) {
if (narg != 3) error->all(FLERR,"Illegal variable command");
@ -366,7 +366,7 @@ void Variable::set(int narg, char **arg)
which[nvar] = 0;
pad[nvar] = 0;
data[nvar] = new char*[num[nvar]];
data[nvar][0] = NULL;
data[nvar][0] = nullptr;
reader[nvar] = new VarReader(lmp,arg[0],arg[2],ATOMFILE);
int flag = reader[nvar]->read_peratom();
if (flag) error->all(FLERR,"Atomfile variable could not read values");
@ -706,7 +706,7 @@ int Variable::next(int narg, char **arg)
char buf[64];
for (int loopmax = 0; loopmax < 100; ++loopmax) {
fp = fopen("tmp.lammps.variable.lock","r");
if (fp == NULL) goto uloop_again;
if (fp == nullptr) goto uloop_again;
buf[0] = buf[1] = '\0';
fread(buf,1,64,fp);
@ -731,7 +731,7 @@ int Variable::next(int narg, char **arg)
fprintf(fp,"%d\n",nextindex+1);
//printf("WRITE %d %d\n",universe->me,nextindex+1);
fclose(fp);
fp = NULL;
fp = nullptr;
rename("tmp.lammps.variable.lock","tmp.lammps.variable");
if (universe->uscreen)
fprintf(universe->uscreen,
@ -840,15 +840,15 @@ int Variable::vectorstyle(int ivar)
check if variable with name is PYTHON and matches funcname
called by Python class before it invokes a Python function
return data storage so Python function can return a value for this variable
return NULL if not a match
return nullptr if not a match
------------------------------------------------------------------------- */
char *Variable::pythonstyle(char *name, char *funcname)
{
int ivar = find(name);
if (ivar < 0) return NULL;
if (style[ivar] != PYTHON) return NULL;
if (strcmp(data[ivar][0],funcname) != 0) return NULL;
if (ivar < 0) return nullptr;
if (style[ivar] != PYTHON) return nullptr;
if (strcmp(data[ivar][0],funcname) != 0) return nullptr;
return data[ivar][1];
}
@ -873,23 +873,23 @@ int Variable::internalstyle(int ivar)
if GETENV, query environment and put result in str
if PYTHON, evaluate Python function, it will put result in str
if INTERNAL, convert dvalue and put result in str
if ATOM or ATOMFILE or VECTOR, return NULL
return NULL if no variable with name, or which value is bad,
if ATOM or ATOMFILE or VECTOR, return nullptr
return nullptr if no variable with name, or which value is bad,
caller must respond
------------------------------------------------------------------------- */
char *Variable::retrieve(const char *name)
{
int ivar = find(name);
if (ivar < 0) return NULL;
if (which[ivar] >= num[ivar]) return NULL;
if (ivar < 0) return nullptr;
if (which[ivar] >= num[ivar]) return nullptr;
if (eval_in_progress[ivar])
print_var_error(FLERR,"Variable has a circular dependency",ivar);
eval_in_progress[ivar] = 1;
char *str = NULL;
char *str = nullptr;
if (style[ivar] == INDEX || style[ivar] == WORLD ||
style[ivar] == UNIVERSE || style[ivar] == STRING ||
style[ivar] == SCALARFILE) {
@ -908,19 +908,19 @@ char *Variable::retrieve(const char *name)
strcpy(data[ivar][0],result);
str = data[ivar][0];
} else if (style[ivar] == EQUAL) {
double answer = evaluate(data[ivar][0],NULL,ivar);
double answer = evaluate(data[ivar][0],nullptr,ivar);
sprintf(data[ivar][1],"%.15g",answer);
str = data[ivar][1];
} else if (style[ivar] == FORMAT) {
int jvar = find(data[ivar][0]);
if (jvar == -1) return NULL;
if (!equalstyle(jvar)) return NULL;
if (jvar == -1) return nullptr;
if (!equalstyle(jvar)) return nullptr;
double answer = compute_equal(jvar);
sprintf(data[ivar][2],data[ivar][1],answer);
str = data[ivar][2];
} else if (style[ivar] == GETENV) {
const char *result = getenv(data[ivar][0]);
if (result == NULL) result = (const char *) "";
if (result == nullptr) result = (const char *) "";
int n = strlen(result) + 1;
if (n > VALUELENGTH) {
delete [] data[ivar][1];
@ -943,7 +943,7 @@ char *Variable::retrieve(const char *name)
sprintf(data[ivar][0],"%.15g",dvalue[ivar]);
str = data[ivar][0];
} else if (style[ivar] == ATOM || style[ivar] == ATOMFILE ||
style[ivar] == VECTOR) return NULL;
style[ivar] == VECTOR) return nullptr;
eval_in_progress[ivar] = 0;
@ -965,7 +965,7 @@ double Variable::compute_equal(int ivar)
eval_in_progress[ivar] = 1;
double value = 0.0;
if (style[ivar] == EQUAL) value = evaluate(data[ivar][0],NULL,ivar);
if (style[ivar] == EQUAL) value = evaluate(data[ivar][0],nullptr,ivar);
else if (style[ivar] == INTERNAL) value = dvalue[ivar];
else if (style[ivar] == PYTHON) {
int ifunc = python->find(data[ivar][0]);
@ -987,7 +987,7 @@ double Variable::compute_equal(int ivar)
double Variable::compute_equal(char *str)
{
return evaluate(str,NULL,-1);
return evaluate(str,nullptr,-1);
}
/* ----------------------------------------------------------------------
@ -1000,7 +1000,7 @@ double Variable::compute_equal(char *str)
void Variable::compute_atom(int ivar, int igroup,
double *result, int stride, int sumflag)
{
Tree *tree = NULL;
Tree *tree = nullptr;
double *vstore;
if (eval_in_progress[ivar])
@ -1014,7 +1014,7 @@ void Variable::compute_atom(int ivar, int igroup,
collapse_tree(tree);
} else vstore = reader[ivar]->fixstore->vstore;
if (result == NULL) {
if (result == nullptr) {
if (style[ivar] == ATOM) free_tree(tree);
eval_in_progress[ivar] = 0;
return;
@ -1073,7 +1073,7 @@ void Variable::compute_atom(int ivar, int igroup,
int Variable::compute_vector(int ivar, double **result)
{
Tree *tree = NULL;
Tree *tree = nullptr;
if (vecs[ivar].currentstep == update->ntimestep) {
*result = vecs[ivar].values;
return vecs[ivar].n;
@ -1166,7 +1166,7 @@ void Variable::grow()
reader = (VarReader **)
memory->srealloc(reader,maxvar*sizeof(VarReader *),"var:reader");
for (int i = old; i < maxvar; i++) reader[i] = NULL;
for (int i = old; i < maxvar; i++) reader[i] = nullptr;
data = (char ***) memory->srealloc(data,maxvar*sizeof(char **),"var:data");
memory->grow(dvalue,maxvar,"var:dvalue");
@ -1175,7 +1175,7 @@ void Variable::grow()
for (int i = old; i < maxvar; i++) {
vecs[i].nmax = 0;
vecs[i].currentstep = -1;
vecs[i].values = NULL;
vecs[i].values = nullptr;
}
memory->grow(eval_in_progress,maxvar,"var:eval_in_progress");
@ -1214,9 +1214,9 @@ void Variable::copy(int narg, char **from, char **to)
compute = c_ID, c_ID[i], c_ID[i][j]
fix = f_ID, f_ID[i], f_ID[i][j]
variable = v_name, v_name[i]
equal-style variables passes in tree = NULL:
equal-style variables passes in tree = nullptr:
evaluate the formula, return result as a double
atom-style and vector-style variables pass in tree = non-NULL:
atom-style and vector-style variables pass in tree = non-nullptr:
parse the formula but do not evaluate it
create a parse tree and return it
------------------------------------------------------------------------- */
@ -1261,10 +1261,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
// evaluate contents and push on stack
if (tree) {
Tree *newtree = NULL;
Tree *newtree = nullptr;
evaluate(contents,&newtree,ivar);
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = evaluate(contents,NULL,ivar);
} else argstack[nargstack++] = evaluate(contents,nullptr,ivar);
delete [] contents;
@ -1297,7 +1297,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = atof(number);
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->extra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = atof(number);
@ -1389,7 +1389,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1418,7 +1418,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1450,7 +1450,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1459,7 +1459,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 0 && compute->vector_flag) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Compute global vector in "
"equal-style variable formula",ivar);
if (treetype == ATOM)
@ -1483,7 +1483,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->nvector = compute->size_vector;
newtree->nstride = 1;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1491,7 +1491,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 1 && compute->array_flag) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Compute global vector in "
"equal-style variable formula",ivar);
if (treetype == ATOM)
@ -1515,7 +1515,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->nvector = compute->size_array_rows;
newtree->nstride = compute->size_array_cols;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1533,7 +1533,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
compute->invoked_flag |= INVOKED_PERATOM;
}
peratom2global(1,NULL,compute->vector_atom,1,index1,
peratom2global(1,nullptr,compute->vector_atom,1,index1,
tree,treestack,ntreestack,argstack,nargstack);
// c_ID[i][j] = scalar from per-atom array
@ -1554,11 +1554,11 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
}
if (compute->array_atom)
peratom2global(1,NULL,&compute->array_atom[0][index2-1],
peratom2global(1,nullptr,&compute->array_atom[0][index2-1],
compute->size_peratom_cols,index1,
tree,treestack,ntreestack,argstack,nargstack);
else
peratom2global(1,NULL,NULL,
peratom2global(1,nullptr,nullptr,
compute->size_peratom_cols,index1,
tree,treestack,ntreestack,argstack,nargstack);
@ -1567,7 +1567,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 0 && compute->peratom_flag &&
compute->size_peratom_cols == 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Per-atom compute in "
"equal-style variable formula",ivar);
if (treetype == VECTOR)
@ -1587,7 +1587,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->array = compute->vector_atom;
newtree->nstride = 1;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1596,7 +1596,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 1 && compute->peratom_flag &&
compute->size_peratom_cols > 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Per-atom compute in "
"equal-style variable formula",ivar);
if (treetype == VECTOR)
@ -1619,10 +1619,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (compute->array_atom)
newtree->array = &compute->array_atom[0][index1-1];
else
newtree->array = NULL;
newtree->array = nullptr;
newtree->nstride = compute->size_peratom_cols;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1686,7 +1686,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1708,7 +1708,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1733,7 +1733,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1745,7 +1745,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
print_var_error(FLERR,"Fix in variable not computed at "
"compatible time",ivar);
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Fix global vector in "
"equal-style variable formula",ivar);
if (treetype == ATOM)
@ -1767,7 +1767,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->nvector = nvec;
newtree->nstride = 1;
newtree->selfalloc = 1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1778,7 +1778,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
print_var_error(FLERR,"Fix in variable not computed "
"at a compatible time",ivar);
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Fix global vector in "
"equal-style variable formula",ivar);
if (treetype == ATOM)
@ -1800,7 +1800,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->nvector = nvec;
newtree->nstride = 1;
newtree->selfalloc = 1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1814,7 +1814,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
print_var_error(FLERR,"Fix in variable not computed "
"at a compatible time",ivar);
peratom2global(1,NULL,fix->vector_atom,1,index1,
peratom2global(1,nullptr,fix->vector_atom,1,index1,
tree,treestack,ntreestack,argstack,nargstack);
// f_ID[i][j] = scalar from per-atom array
@ -1831,11 +1831,11 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
"at a compatible time",ivar);
if (fix->array_atom)
peratom2global(1,NULL,&fix->array_atom[0][index2-1],
peratom2global(1,nullptr,&fix->array_atom[0][index2-1],
fix->size_peratom_cols,index1,
tree,treestack,ntreestack,argstack,nargstack);
else
peratom2global(1,NULL,NULL,
peratom2global(1,nullptr,nullptr,
fix->size_peratom_cols,index1,
tree,treestack,ntreestack,argstack,nargstack);
@ -1844,7 +1844,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 0 && fix->peratom_flag &&
fix->size_peratom_cols == 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Per-atom fix in "
"equal-style variable formula",ivar);
if (update->whichflag > 0 &&
@ -1857,7 +1857,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->array = fix->vector_atom;
newtree->nstride = 1;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1866,7 +1866,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 1 && fix->peratom_flag &&
fix->size_peratom_cols > 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Per-atom fix in "
"equal-style variable formula",ivar);
if (index1 > fix->size_peratom_cols)
@ -1882,10 +1882,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (fix->array_atom)
newtree->array = &fix->array_atom[0][index1-1];
else
newtree->array = NULL;
newtree->array = nullptr;
newtree->nstride = fix->size_peratom_cols;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1929,7 +1929,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -1941,14 +1941,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
style[ivar] != ATOMFILE && style[ivar] != VECTOR) {
char *var = retrieve(word+2);
if (var == NULL)
if (var == nullptr)
print_var_error(FLERR,"Invalid variable evaluation in "
"variable formula",ivar);
if (tree) {
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = atof(var);
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = atof(var);
@ -1958,14 +1958,14 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 0 && style[ivar] == ATOM) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Atom-style variable in "
"equal-style variable formula",ivar);
if (treetype == VECTOR)
print_var_error(FLERR,"Atom-style variable in "
"vector-style variable formula",ivar);
Tree *newtree = NULL;
Tree *newtree = nullptr;
evaluate(data[ivar][0],&newtree,ivar);
treestack[ntreestack++] = newtree;
@ -1973,7 +1973,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 0 && style[ivar] == ATOMFILE) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Atomfile-style variable in "
"equal-style variable formula",ivar);
if (treetype == VECTOR)
@ -1985,7 +1985,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->array = reader[ivar]->fixstore->vstore;
newtree->nstride = 1;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -1994,7 +1994,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 0 && style[ivar] == VECTOR) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Vector-style variable in "
"equal-style variable formula",ivar);
if (treetype == ATOM)
@ -2010,7 +2010,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->nvector = nvec;
newtree->nstride = 1;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -2023,7 +2023,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
double *result;
memory->create(result,atom->nlocal,"variable:result");
compute_atom(ivar,0,result,1,0);
peratom2global(1,NULL,result,1,index,
peratom2global(1,nullptr,result,1,index,
tree,treestack,ntreestack,argstack,nargstack);
memory->destroy(result);
@ -2031,7 +2031,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket && style[ivar] == ATOMFILE) {
peratom2global(1,NULL,reader[ivar]->fixstore->vstore,1,index,
peratom2global(1,nullptr,reader[ivar]->fixstore->vstore,1,index,
tree,treestack,ntreestack,argstack,nargstack);
// v_name[N] = scalar from vector-style variable
@ -2050,7 +2050,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = vec[m-1];
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = vec[m-1];
@ -2098,7 +2098,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
tagint id = int_between_brackets(ptr,1);
i = ptr-str+1;
peratom2global(0,word,NULL,0,id,
peratom2global(0,word,nullptr,0,id,
tree,treestack,ntreestack,argstack,nargstack);
// ----------------
@ -2122,7 +2122,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -2144,7 +2144,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value1;
@ -2224,7 +2224,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
newtree->type = opprevious;
if ((opprevious == UNARY) || (opprevious == NOT)) {
newtree->first = treestack[--ntreestack];
newtree->second = NULL;
newtree->second = nullptr;
newtree->nextra = 0;
} else {
newtree->second = treestack[--ntreestack];
@ -2627,7 +2627,7 @@ double Variable::collapse_tree(Tree *tree)
if (tree->type == RANDOM) {
collapse_tree(tree->first);
collapse_tree(tree->second);
if (randomatom == NULL) {
if (randomatom == nullptr) {
int seed = static_cast<int> (collapse_tree(tree->extra[0]));
if (seed <= 0)
error->one(FLERR,"Invalid math function in variable formula");
@ -2641,7 +2641,7 @@ double Variable::collapse_tree(Tree *tree)
double sigma = collapse_tree(tree->second);
if (sigma < 0.0)
error->one(FLERR,"Invalid math function in variable formula");
if (randomatom == NULL) {
if (randomatom == nullptr) {
int seed = static_cast<int> (collapse_tree(tree->extra[0]));
if (seed <= 0)
error->one(FLERR,"Invalid math function in variable formula");
@ -3021,7 +3021,7 @@ double Variable::eval_tree(Tree *tree, int i)
if (tree->type == RANDOM) {
double lower = eval_tree(tree->first,i);
double upper = eval_tree(tree->second,i);
if (randomatom == NULL) {
if (randomatom == nullptr) {
int seed = static_cast<int> (eval_tree(tree->extra[0],i));
if (seed <= 0)
error->one(FLERR,"Invalid math function in variable formula");
@ -3034,7 +3034,7 @@ double Variable::eval_tree(Tree *tree, int i)
double sigma = eval_tree(tree->second,i);
if (sigma < 0.0)
error->one(FLERR,"Invalid math function in variable formula");
if (randomatom == NULL) {
if (randomatom == nullptr) {
int seed = static_cast<int> (eval_tree(tree->extra[0],i));
if (seed <= 0)
error->one(FLERR,"Invalid math function in variable formula");
@ -3344,7 +3344,7 @@ tagint Variable::int_between_brackets(char *&ptr, int varallow)
error->all(FLERR,"Invalid variable name in variable formula");
char *var = retrieve(id);
if (var == NULL)
if (var == nullptr)
error->all(FLERR,"Invalid variable evaluation in variable formula");
index = static_cast<tagint> (atof(var));
@ -3399,15 +3399,15 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
char *args[MAXFUNCARG];
int narg = parse_args(contents,args);
Tree *newtree = NULL;
Tree *newtree = nullptr;
double value1,value2;
double values[MAXFUNCARG-2];
if (tree) {
newtree = new Tree();
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
Tree *argtree = NULL;
Tree *argtree = nullptr;
evaluate(args[0],&argtree,ivar);
newtree->first = argtree;
if (narg > 1) {
@ -3425,12 +3425,12 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
treestack[ntreestack++] = newtree;
} else {
value1 = evaluate(args[0],NULL,ivar);
value1 = evaluate(args[0],nullptr,ivar);
if (narg > 1) {
value2 = evaluate(args[1],NULL,ivar);
value2 = evaluate(args[1],nullptr,ivar);
if (narg > 2) {
for (int i = 2; i < narg; i++)
values[i-2] = evaluate(args[i],NULL,ivar);
values[i-2] = evaluate(args[i],nullptr,ivar);
}
}
}
@ -3530,7 +3530,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
if (tree) newtree->type = RANDOM;
else {
if (randomequal == NULL) {
if (randomequal == nullptr) {
int seed = static_cast<int> (values[0]);
if (seed <= 0)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
@ -3545,7 +3545,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
else {
if (value2 < 0.0)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
if (randomequal == NULL) {
if (randomequal == nullptr) {
int seed = static_cast<int> (values[0]);
if (seed <= 0)
print_var_error(FLERR,"Invalid math function in variable formula",ivar);
@ -4029,7 +4029,7 @@ int Variable::group_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4107,8 +4107,8 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
if (narg != 1)
print_var_error(FLERR,"Invalid special function in variable formula",ivar);
Compute *compute = NULL;
Fix *fix = NULL;
Compute *compute = nullptr;
Fix *fix = nullptr;
int ivar = -1;
int index,nvec,nstride;
char *ptr1,*ptr2;
@ -4239,7 +4239,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
double *vec;
if (index) {
if (compute->array) vec = &compute->array[0][index-1];
else vec = NULL;
else vec = nullptr;
} else vec = compute->vector;
int j = 0;
@ -4320,7 +4320,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4328,7 +4328,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
// mask special functions
} else if (strcmp(word,"gmask") == 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Gmask function in equal-style "
"variable formula",ivar);
if (narg != 1)
@ -4341,12 +4341,12 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = GMASK;
newtree->ivalue1 = group->bitmask[igroup];
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else if (strcmp(word,"rmask") == 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Rmask function in equal-style "
"variable formula",ivar);
if (narg != 1)
@ -4358,12 +4358,12 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = RMASK;
newtree->ivalue1 = iregion;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else if (strcmp(word,"grmask") == 0) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Grmask function in equal-style "
"variable formula",ivar);
if (narg != 2)
@ -4379,7 +4379,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
newtree->type = GRMASK;
newtree->ivalue1 = group->bitmask[igroup];
newtree->ivalue2 = iregion;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -4409,7 +4409,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4419,7 +4419,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
// set selfalloc = 1 so result will be deleted by free_tree() after eval
} else if (style[ivar] == ATOMFILE) {
if (tree == NULL)
if (tree == nullptr)
print_var_error(FLERR,"Atomfile variable in "
"equal-style variable formula",ivar);
@ -4435,7 +4435,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
newtree->array = result;
newtree->nstride = 1;
newtree->selfalloc = 1;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -4456,7 +4456,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4475,7 +4475,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4494,7 +4494,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4579,7 +4579,7 @@ void Variable::peratom2global(int flag, char *word,
Tree *newtree = new Tree();
newtree->type = VALUE;
newtree->value = value;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
} else argstack[nargstack++] = value;
@ -4622,14 +4622,14 @@ int Variable::is_atom_vector(char *word)
void Variable::atom_vector(char *word, Tree **tree,
Tree **treestack, int &ntreestack)
{
if (tree == NULL)
if (tree == nullptr)
error->all(FLERR,"Atom vector in equal-style variable formula");
Tree *newtree = new Tree();
newtree->type = ATOMARRAY;
newtree->nstride = 3;
newtree->selfalloc = 0;
newtree->first = newtree->second = NULL;
newtree->first = newtree->second = nullptr;
newtree->nextra = 0;
treestack[ntreestack++] = newtree;
@ -4756,7 +4756,7 @@ int Variable::parse_args(char *str, char **args)
/* ----------------------------------------------------------------------
find next comma in str
skip commas inside one or more nested parenthesis
only return ptr to comma at level 0, else NULL if not found
only return ptr to comma at level 0, else nullptr if not found
------------------------------------------------------------------------- */
char *Variable::find_next_comma(char *str)
@ -4767,7 +4767,7 @@ char *Variable::find_next_comma(char *str)
else if (')' == *p) level--;
else if (',' == *p && !level) return p;
}
return NULL;
return nullptr;
}
@ -5069,11 +5069,11 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) :
{
me = comm->me;
style = flag;
fp = NULL;
fp = nullptr;
if (me == 0) {
fp = fopen(file,"r");
if (fp == NULL)
if (fp == nullptr)
error->one(FLERR,fmt::format("Cannot open file variable file {}: {}",
file, utils::getsyserror()));
}
@ -5082,9 +5082,9 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) :
// allocate a new fix STORE, so they persist
// id = variable-ID + VARIABLE_STORE, fix group = all
fixstore = NULL;
id_fix = NULL;
buffer = NULL;
fixstore = nullptr;
id_fix = nullptr;
buffer = nullptr;
if (style == ATOMFILE) {
if (atom->map_style == Atom::MAP_NONE)
@ -5109,7 +5109,7 @@ VarReader::~VarReader()
{
if (me == 0) {
fclose(fp);
fp = NULL;
fp = nullptr;
}
// check modify in case all fixes have already been deleted
@ -5137,12 +5137,12 @@ int VarReader::read_scalar(char *str)
if (me == 0) {
while (1) {
if (fgets(str,MAXLINE,fp) == NULL) n = 0;
if (fgets(str,MAXLINE,fp) == nullptr) n = 0;
else n = strlen(str);
if (n == 0) break; // end of file
str[n-1] = '\0'; // strip newline
if ((ptr = strchr(str,'#'))) *ptr = '\0'; // strip comment
if (strtok(str," \t\n\r\f") == NULL) continue; // skip if blank
if (strtok(str," \t\n\r\f") == nullptr) continue; // skip if blank
n = strlen(str) + 1;
break;
}
@ -5180,12 +5180,12 @@ int VarReader::read_peratom()
char str[MAXLINE];
if (me == 0) {
while (1) {
if (fgets(str,MAXLINE,fp) == NULL) n = 0;
if (fgets(str,MAXLINE,fp) == nullptr) n = 0;
else n = strlen(str);
if (n == 0) break; // end of file
str[n-1] = '\0'; // strip newline
if ((ptr = strchr(str,'#'))) *ptr = '\0'; // strip comment
if (strtok(str," \t\n\r\f") == NULL) continue; // skip if blank
if (strtok(str," \t\n\r\f") == nullptr) continue; // skip if blank
n = strlen(str) + 1;
break;
}