change error checks for computes that are not current

This commit is contained in:
Steve Plimpton
2023-05-08 08:55:40 -06:00
parent b3130a2878
commit 49ac79fcdd
7 changed files with 83 additions and 134 deletions

View File

@ -294,21 +294,15 @@ int DumpVTK::count()
} }
// invoke Computes for per-atom quantities // invoke Computes for per-atom quantities
// only if within a run or minimize // cannot invoke before first run, otherwise invoke if necessary
// else require that computes are current
// this prevents a compute from being invoked by the WriteDump class
if (ncompute) { if (ncompute) {
if (update->whichflag == 0) { if (update->first_update == 0)
for (i = 0; i < ncompute; i++) error->all(FLERR,"Dump compute cannot be invoked before first run");
if (compute[i]->invoked_peratom != update->ntimestep) for (i = 0; i < ncompute; i++) {
error->all(FLERR,"Compute used in dump between runs is not current"); if (!(compute[i]->invoked_flag & Compute::INVOKED_PERATOM)) {
} else { compute[i]->compute_peratom();
for (i = 0; i < ncompute; i++) { compute[i]->invoked_flag |= Compute::INVOKED_PERATOM;
if (!(compute[i]->invoked_flag & Compute::INVOKED_PERATOM)) {
compute[i]->compute_peratom();
compute[i]->invoked_flag |= Compute::INVOKED_PERATOM;
}
} }
} }
} }

View File

@ -556,21 +556,15 @@ int DumpCustom::count()
} }
// invoke Computes for per-atom quantities // invoke Computes for per-atom quantities
// only if within a run or minimize // cannot invoke before first run, otherwise invoke if necessary
// else require that computes are current
// this prevents a compute from being invoked by the WriteDump class
if (ncompute) { if (ncompute) {
if (update->whichflag == 0) { if (update->first_update == 0)
for (i = 0; i < ncompute; i++) error->all(FLERR,"Dump compute cannot be invoked before first run");
if (compute[i]->invoked_peratom != update->ntimestep) for (i = 0; i < ncompute; i++) {
error->all(FLERR,"Compute used in dump between runs is not current"); if (!(compute[i]->invoked_flag & Compute::INVOKED_PERATOM)) {
} else { compute[i]->compute_peratom();
for (i = 0; i < ncompute; i++) { compute[i]->invoked_flag |= Compute::INVOKED_PERATOM;
if (!(compute[i]->invoked_flag & Compute::INVOKED_PERATOM)) {
compute[i]->compute_peratom();
compute[i]->invoked_flag |= Compute::INVOKED_PERATOM;
}
} }
} }
} }

View File

@ -522,21 +522,15 @@ int DumpGrid::count()
} }
// invoke Computes for per-grid quantities // invoke Computes for per-grid quantities
// only if within a run or minimize // cannot invoke before first run, otherwise invoke if necessary
// else require that computes are current
// this prevents a compute from being invoked by the WriteDump class
if (ncompute) { if (ncompute) {
if (update->whichflag == 0) { if (update->first_update == 0)
for (i = 0; i < ncompute; i++) error->all(FLERR,"Dump compute cannot be invoked before first run");
if (compute[i]->invoked_pergrid != update->ntimestep) for (i = 0; i < ncompute; i++) {
error->all(FLERR,"Compute {} used in dump between runs is not current", compute[i]->id); if (!(compute[i]->invoked_flag & Compute::INVOKED_PERGRID)) {
} else { compute[i]->compute_pergrid();
for (i = 0; i < ncompute; i++) { compute[i]->invoked_flag |= Compute::INVOKED_PERGRID;
if (!(compute[i]->invoked_flag & Compute::INVOKED_PERGRID)) {
compute[i]->compute_pergrid();
compute[i]->invoked_flag |= Compute::INVOKED_PERGRID;
}
} }
} }
} }

View File

@ -664,20 +664,14 @@ void DumpImage::write()
} }
// invoke Compute for per-grid quantities // invoke Compute for per-grid quantities
// only if within a run or minimize // cannot invoke before first run, otherwise invoke if necessary
// else require the compute is current
// this prevents the compute from being invoked by the WriteDump class
if (grid_compute) { if (grid_compute) {
if (update->whichflag == 0) { if (update->first_update == 0)
if (grid_compute->invoked_pergrid != update->ntimestep) error->all(FLERR,"Grid compute used in dump image cannot be invoked before first run");
error->all(FLERR,"Grid compute {} used in dump image between runs is not current", if (!(grid_compute->invoked_flag & Compute::INVOKED_PERGRID)) {
grid_compute->id); grid_compute->compute_pergrid();
} else { grid_compute->invoked_flag |= Compute::INVOKED_PERGRID;
if (!(grid_compute->invoked_flag & Compute::INVOKED_PERGRID)) {
grid_compute->compute_pergrid();
grid_compute->invoked_flag |= Compute::INVOKED_PERGRID;
}
} }
} }

View File

@ -325,21 +325,15 @@ int DumpLocal::count()
int i; int i;
// invoke Computes for local quantities // invoke Computes for local quantities
// only if within a run or minimize // cannot invoke before first run, otherwise invoke if necessary
// else require that computes are current
// this prevents a compute from being invoked by the WriteDump class
if (ncompute) { if (ncompute) {
if (update->whichflag == 0) { if (update->first_update == 0)
for (i = 0; i < ncompute; i++) error->all(FLERR,"Dump compute cannot be invoked before first run");
if (compute[i]->invoked_local != update->ntimestep) for (i = 0; i < ncompute; i++) {
error->all(FLERR,"Compute used in dump between runs is not current"); if (!(compute[i]->invoked_flag & Compute::INVOKED_LOCAL)) {
} else { compute[i]->compute_local();
for (i = 0; i < ncompute; i++) { compute[i]->invoked_flag |= Compute::INVOKED_LOCAL;
if (!(compute[i]->invoked_flag & Compute::INVOKED_LOCAL)) {
compute[i]->compute_local();
compute[i]->invoked_flag |= Compute::INVOKED_LOCAL;
}
} }
} }
} }

View File

@ -1118,7 +1118,7 @@ int Thermo::add_variable(const char *id)
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
check whether temperature compute is defined, available, and current check whether temperature compute is defined, active, and needs invoking
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Thermo::check_temp(const std::string &keyword) void Thermo::check_temp(const std::string &keyword)
@ -1126,18 +1126,16 @@ void Thermo::check_temp(const std::string &keyword)
if (!temperature) if (!temperature)
error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init temperature", error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init temperature",
keyword); keyword);
if (update->whichflag == 0) { if (update->first_update == 0)
if (temperature->invoked_scalar != update->ntimestep) error->all(FLERR,"Thermo keyword {} cannot be invoked before first run",keyword);
error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) {
temperature->style, temperature->id);
} else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) {
temperature->compute_scalar(); temperature->compute_scalar();
temperature->invoked_flag |= Compute::INVOKED_SCALAR; temperature->invoked_flag |= Compute::INVOKED_SCALAR;
} }
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
check whether potential energy compute is defined, available, and current check whether potential energy compute is defined, active, and needs invoking
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Thermo::check_pe(const std::string &keyword) void Thermo::check_pe(const std::string &keyword)
@ -1147,47 +1145,41 @@ void Thermo::check_pe(const std::string &keyword)
if (!pe) if (!pe)
error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init potential energy", error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init potential energy",
keyword); keyword);
if (update->whichflag == 0) { if (update->first_update == 0)
if (pe->invoked_scalar != update->ntimestep) error->all(FLERR,"Thermo keyword {} cannot be invoked before first run",keyword);
error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", if (!(pe->invoked_flag & Compute::INVOKED_SCALAR)) {
pe->style, pe->id);
} else {
pe->compute_scalar(); pe->compute_scalar();
pe->invoked_flag |= Compute::INVOKED_SCALAR; pe->invoked_flag |= Compute::INVOKED_SCALAR;
} }
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
check whether scalar pressure compute is defined, available, and current check whether scalar pressure compute is defined, active, and needs invoking
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Thermo::check_press_scalar(const std::string &keyword) void Thermo::check_press_scalar(const std::string &keyword)
{ {
if (!pressure) if (!pressure)
error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init press", keyword); error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init press", keyword);
if (update->whichflag == 0) { if (update->first_update == 0)
if (pressure->invoked_scalar != update->ntimestep) error->all(FLERR,"Thermo keyword {} cannot be invoked before first run",keyword);
error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", if (!(pressure->invoked_flag & Compute::INVOKED_SCALAR)) {
pressure->style, pressure->id);
} else if (!(pressure->invoked_flag & Compute::INVOKED_SCALAR)) {
pressure->compute_scalar(); pressure->compute_scalar();
pressure->invoked_flag |= Compute::INVOKED_SCALAR; pressure->invoked_flag |= Compute::INVOKED_SCALAR;
} }
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
check whether pressure tensor compute is defined, available, and current check whether tensor pressure compute is defined, active, and needs invoking
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Thermo::check_press_vector(const std::string &keyword) void Thermo::check_press_vector(const std::string &keyword)
{ {
if (!pressure) if (!pressure)
error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init press", keyword); error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init press", keyword);
if (update->whichflag == 0) { if (update->first_update == 0)
if (pressure->invoked_vector != update->ntimestep) error->all(FLERR,"Thermo keyword {} cannot be invoked before first run",keyword);
error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) {
pressure->style, pressure->id);
} else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) {
pressure->compute_vector(); pressure->compute_vector();
pressure->invoked_flag |= Compute::INVOKED_VECTOR; pressure->invoked_flag |= Compute::INVOKED_VECTOR;
} }
@ -1214,8 +1206,6 @@ int Thermo::evaluate_keyword(const std::string &word, double *answer)
// invoke a lo-level thermo routine to compute the variable value // invoke a lo-level thermo routine to compute the variable value
// if keyword requires a compute, error if thermo doesn't use the compute // if keyword requires a compute, error if thermo doesn't use the compute
// if inbetween runs and needed compute is not current, error
// if in middle of run and needed compute is not current, invoke it
// for keywords that use energy (evdwl, ebond, etc): // for keywords that use energy (evdwl, ebond, etc):
// check if energy was tallied on this timestep and set pe->invoked_flag // check if energy was tallied on this timestep and set pe->invoked_flag
// this will trigger next timestep for energy tallying via addstep() // this will trigger next timestep for energy tallying via addstep()

View File

@ -1440,10 +1440,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (nbracket == 0 && compute->scalar_flag && lowercase) { if (nbracket == 0 && compute->scalar_flag && lowercase) {
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_scalar != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_SCALAR)) {
compute->compute_scalar(); compute->compute_scalar();
compute->invoked_flag |= Compute::INVOKED_SCALAR; compute->invoked_flag |= Compute::INVOKED_SCALAR;
} }
@ -1463,10 +1462,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index1 > compute->size_vector && if (index1 > compute->size_vector &&
compute->size_vector_variable == 0) compute->size_vector_variable == 0)
print_var_error(FLERR,"Variable formula compute vector is accessed out-of-range",ivar,0); print_var_error(FLERR,"Variable formula compute vector is accessed out-of-range",ivar,0);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_vector != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
compute->compute_vector(); compute->compute_vector();
compute->invoked_flag |= Compute::INVOKED_VECTOR; compute->invoked_flag |= Compute::INVOKED_VECTOR;
} }
@ -1490,10 +1488,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0);
if (index2 > compute->size_array_cols) if (index2 > compute->size_array_cols)
print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_array != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) {
compute->compute_array(); compute->compute_array();
compute->invoked_flag |= Compute::INVOKED_ARRAY; compute->invoked_flag |= Compute::INVOKED_ARRAY;
} }
@ -1518,10 +1515,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar); print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar);
if (compute->size_vector == 0) if (compute->size_vector == 0)
print_var_error(FLERR,"Variable formula compute vector is zero length",ivar); print_var_error(FLERR,"Variable formula compute vector is zero length",ivar);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_vector != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
compute->compute_vector(); compute->compute_vector();
compute->invoked_flag |= Compute::INVOKED_VECTOR; compute->invoked_flag |= Compute::INVOKED_VECTOR;
} }
@ -1543,10 +1539,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar); print_var_error(FLERR,"Compute global vector in atom-style variable formula",ivar);
if (compute->size_array_rows == 0) if (compute->size_array_rows == 0)
print_var_error(FLERR,"Variable formula compute array is zero length",ivar); print_var_error(FLERR,"Variable formula compute array is zero length",ivar);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_array != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) {
compute->compute_array(); compute->compute_array();
compute->invoked_flag |= Compute::INVOKED_ARRAY; compute->invoked_flag |= Compute::INVOKED_ARRAY;
} }
@ -1563,10 +1558,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
} else if (nbracket == 1 && compute->peratom_flag && } else if (nbracket == 1 && compute->peratom_flag &&
compute->size_peratom_cols == 0) { compute->size_peratom_cols == 0) {
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_peratom != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
compute->compute_peratom(); compute->compute_peratom();
compute->invoked_flag |= Compute::INVOKED_PERATOM; compute->invoked_flag |= Compute::INVOKED_PERATOM;
} }
@ -1581,10 +1575,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index2 > compute->size_peratom_cols) if (index2 > compute->size_peratom_cols)
print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_peratom != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
compute->compute_peratom(); compute->compute_peratom();
compute->invoked_flag |= Compute::INVOKED_PERATOM; compute->invoked_flag |= Compute::INVOKED_PERATOM;
} }
@ -1605,10 +1598,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
print_var_error(FLERR,"Per-atom compute in equal-style variable formula",ivar); print_var_error(FLERR,"Per-atom compute in equal-style variable formula",ivar);
if (treetype == VECTOR) if (treetype == VECTOR)
print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar); print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_peratom != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
compute->compute_peratom(); compute->compute_peratom();
compute->invoked_flag |= Compute::INVOKED_PERATOM; compute->invoked_flag |= Compute::INVOKED_PERATOM;
} }
@ -1630,10 +1622,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar); print_var_error(FLERR,"Per-atom compute in vector-style variable formula",ivar);
if (index1 > compute->size_peratom_cols) if (index1 > compute->size_peratom_cols)
print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_peratom != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
compute->compute_peratom(); compute->compute_peratom();
compute->invoked_flag |= Compute::INVOKED_PERATOM; compute->invoked_flag |= Compute::INVOKED_PERATOM;
} }
@ -4050,10 +4041,9 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t
print_var_error(FLERR,mesg,ivar); print_var_error(FLERR,mesg,ivar);
} }
if (index == 0 && compute->vector_flag) { if (index == 0 && compute->vector_flag) {
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_vector != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_VECTOR)) {
compute->compute_vector(); compute->compute_vector();
compute->invoked_flag |= Compute::INVOKED_VECTOR; compute->invoked_flag |= Compute::INVOKED_VECTOR;
} }
@ -4062,10 +4052,9 @@ int Variable::special_function(char *word, char *contents, Tree **tree, Tree **t
} else if (index && compute->array_flag) { } else if (index && compute->array_flag) {
if (index > compute->size_array_cols) if (index > compute->size_array_cols)
print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0); print_var_error(FLERR,"Variable formula compute array is accessed out-of-range",ivar,0);
if (update->whichflag == 0) { if (update->first_update == 0)
if (compute->invoked_array != update->ntimestep) print_var_error(FLERR,"Variable formula compute cannot be invoked before first run",ivar);
print_var_error(FLERR,"Compute used in variable between runs is not current",ivar); if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) {
} else if (!(compute->invoked_flag & Compute::INVOKED_ARRAY)) {
compute->compute_array(); compute->compute_array();
compute->invoked_flag |= Compute::INVOKED_ARRAY; compute->invoked_flag |= Compute::INVOKED_ARRAY;
} }