diff --git a/src/FLD/pair_brownian_poly.cpp b/src/FLD/pair_brownian_poly.cpp index 43a0d80628..906c62cc6d 100644 --- a/src/FLD/pair_brownian_poly.cpp +++ b/src/FLD/pair_brownian_poly.cpp @@ -84,8 +84,7 @@ void PairBrownianPoly::compute(int eflag, int vflag) double xl[3],a_sq,a_sh,a_pu,Fbmag; double p1[3],p2[3],p3[3]; - - // This section of code adjusts R0/RT0/RS0 if necessary due to changes + // this section of code adjusts R0/RT0/RS0 if necessary due to changes // in the volume fraction as a result of fix deform or moving walls double dims[3], wallcoord; diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 92fd759f47..7c2aad2e85 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -65,8 +65,6 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : { int i,ibody; - scalar_flag = 1; - extscalar = 0; time_integrate = 1; rigid_flag = 1; virial_flag = 1; diff --git a/src/input.cpp b/src/input.cpp index dc8df035f4..51772ffec2 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -383,7 +383,8 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) // else $x becomes x followed by NULL // beyond = points to text following variable - int n; + int i,n,paren_count; + char immediate[256]; char *var,*value,*beyond; char quote = '\0'; char *ptr = str; @@ -394,23 +395,56 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) char *ptr2 = str2; while (*ptr) { - // expand variable and append to str2 + // variable substitution if (*ptr == '$' && !quote) { + + // value = ptr to expanded variable + // variable name between curly braces, e.g. ${a} + if (*(ptr+1) == '{') { var = ptr+2; - int i = 0; + i = 0; + while (var[i] != '\0' && var[i] != '}') i++; + if (var[i] == '\0') error->one(FLERR,"Invalid variable name"); var[i] = '\0'; beyond = ptr + strlen(var) + 3; + value = variable->retrieve(var); + + // immediate variable between parenthesis, e.g. $(1/2) + + } else if (*(ptr+1) == '(') { + var = ptr+2; + paren_count = 0; + i = 0; + + while (var[i] != '\0' && !(var[i] == ')' && paren_count == 0)) { + switch (var[i]) { + case '(': paren_count++; break; + case ')': paren_count--; break; + default: ; + } + i++; + } + + if (var[i] == '\0') error->one(FLERR,"Invalid immediate variable"); + var[i] = '\0'; + beyond = ptr + strlen(var) + 3; + sprintf(immediate,"%.20g",variable->compute_equal(var)); + value = immediate; + + // single character variable name, e.g. $a + } else { var = ptr; var[0] = var[1]; var[1] = '\0'; beyond = ptr + 2; + value = variable->retrieve(var); } - value = variable->retrieve(var); + if (value == NULL) error->one(FLERR,"Substitution for illegal variable"); // check if storage in str2 needs to be expanded @@ -428,8 +462,10 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) if (echo_screen && screen) fprintf(screen,"%s%s\n",str2,beyond); if (echo_log && logfile) fprintf(logfile,"%s%s\n",str2,beyond); } + continue; } + if (*ptr == quote) quote = '\0'; else if (*ptr == '"' || *ptr == '\'') quote = *ptr; diff --git a/src/variable.cpp b/src/variable.cpp index d588ba959e..c75964b911 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -526,6 +526,16 @@ double Variable::compute_equal(int ivar) return value; } +/* ---------------------------------------------------------------------- + return result of immediate equal-style variable evaluation + called from Input::substitute() +------------------------------------------------------------------------- */ + +double Variable::compute_equal(char *str) +{ + return evaluate(str,NULL); +} + /* ---------------------------------------------------------------------- compute result of atom-style variable evaluation only computed for atoms in igroup, else result is 0.0 diff --git a/src/variable.h b/src/variable.h index 98bdb08dad..1d7ff83952 100644 --- a/src/variable.h +++ b/src/variable.h @@ -31,6 +31,7 @@ class Variable : protected Pointers { int atomstyle(int); char *retrieve(char *); double compute_equal(int); + double compute_equal(char *); void compute_atom(int, int, double *, int, int); int int_between_brackets(char *&); double evaluate_boolean(char *);