make expression string compact and easier restartable by removing quotes and whitespace

This commit is contained in:
Axel Kohlmeyer
2022-12-21 21:16:23 -05:00
parent 6c5a698be4
commit 969ac57256
2 changed files with 18 additions and 14 deletions

View File

@ -200,11 +200,15 @@ void PairLepton::coeff(int narg, char **arg)
utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error); utils::bounds(FLERR, arg[0], 1, atom->ntypes, ilo, ihi, error);
utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error); utils::bounds(FLERR, arg[1], 1, atom->ntypes, jlo, jhi, error);
std::string exp_one = arg[2];
double cut_one = cut_global; double cut_one = cut_global;
if (narg == 4) cut_one = utils::numeric(FLERR, arg[3], false, lmp); if (narg == 4) cut_one = utils::numeric(FLERR, arg[3], false, lmp);
// check if the expression can be parsed and evaluated as needed without error // remove whitespace and quotes from expression string and then
// check if the expression can be parsed and evaluated without error
std::string exp_one;
for (const auto &c : std::string(arg[2]))
if (!isspace(c) && (c != '"') && (c != '\'')) exp_one.push_back(c);
try { try {
auto epot = LMP_Lepton::Parser::parse(exp_one).createCompiledExpression(); auto epot = LMP_Lepton::Parser::parse(exp_one).createCompiledExpression();
auto force = LMP_Lepton::Parser::parse(exp_one).differentiate("r").createCompiledExpression(); auto force = LMP_Lepton::Parser::parse(exp_one).differentiate("r").createCompiledExpression();
@ -258,7 +262,7 @@ double PairLepton::init_one(int i, int j)
void PairLepton::write_data(FILE *fp) void PairLepton::write_data(FILE *fp)
{ {
for (int i = 1; i <= atom->ntypes; i++) for (int i = 1; i <= atom->ntypes; i++)
fprintf(fp, "%d '%s' %g\n", i, expressions[type2expression[i][i]].c_str(), cut[i][i]); fprintf(fp, "%d %s %g\n", i, expressions[type2expression[i][i]].c_str(), cut[i][i]);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -269,7 +273,7 @@ void PairLepton::write_data_all(FILE *fp)
{ {
for (int i = 1; i <= atom->ntypes; i++) for (int i = 1; i <= atom->ntypes; i++)
for (int j = i; j <= atom->ntypes; j++) for (int j = i; j <= atom->ntypes; j++)
fprintf(fp, "%d %d '%s' %g\n", i, j, expressions[type2expression[i][j]].c_str(), cut[i][j]); fprintf(fp, "%d %d %s %g\n", i, j, expressions[type2expression[i][j]].c_str(), cut[i][j]);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -14,17 +14,17 @@ input_file: in.fourmol
pair_style: lepton 8.0 pair_style: lepton 8.0
pair_coeff: ! | pair_coeff: ! |
* * "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.015;sig=3.1" * * "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.015;sig=3.1"
1 1 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=2.5" 1 1 '4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=2.5'
1 2 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.01;sig=1.75" 1 2 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.01;sig=1.75"
1 3 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=2.85" 1 3 '4.0*eps*((sig/r)^12-(sig/r)^6); eps=0.02;sig=2.85'
1 4*5 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.0173205;sig=2.8" 1 4*5 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.0173205; sig=2.8"
2 2 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.005;sig=1.0" 2 2 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.005;sig=1.0"
2 3 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.01;sig=2.1" 2 3 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.01;sig=2.1"
2 4 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.005;sig=0.5" 2 4 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.005;sig=0.5"
2 5 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.00866025;sig=2.05" 2 5 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.00866025;sig=2.05"
3 3 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.02;sig=3.2" 3 3 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.02;sig=3.2"
3 4 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.0173205;sig=3.15" 3 4 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.0173205;sig=3.15"
3 5 "4.0*eps*((sig/r)^12 - (sig/r)^6);eps=0.0173205;sig=3.15" 3 5 "4.0*eps*((sig/r)^12-(sig/r)^6);eps=0.0173205;sig=3.15"
extract: ! "" extract: ! ""
natoms: 29 natoms: 29
init_vdwl: 749.2370315373564 init_vdwl: 749.2370315373564