guard against not setting extscalar, extvector, or extarray when required

This commit is contained in:
Axel Kohlmeyer
2024-04-22 19:55:52 -04:00
parent d896f307ba
commit a88e8757e3
4 changed files with 38 additions and 3 deletions

View File

@ -59,6 +59,7 @@ Compute::Compute(LAMMPS *lmp, int narg, char **arg) :
// set child class defaults
scalar_flag = vector_flag = array_flag = 0;
extscalar = extvector = extarray = -1;
peratom_flag = local_flag = pergrid_flag = 0;
size_vector_variable = size_array_rows_variable = 0;
@ -116,6 +117,16 @@ void Compute::init_flags()
initialized_flag = 1;
invoked_scalar = invoked_vector = invoked_array = -1;
invoked_peratom = invoked_local = -1;
if (scalar_flag && (extscalar < 0))
error->all(FLERR, "Must set 'extscalar' when setting 'scalar_flag' for compute {}. "
"Contact the developer.", style);
if (vector_flag && (extvector < 0))
error->all(FLERR, "Must set 'extvector' when setting 'vector_flag' for compute {}. "
"Contact the developer.", style);
if (array_flag && (extarray < 0))
error->all(FLERR, "Must set 'extarray' when setting 'array_flag' for compute {}. "
"Contact the developer.", style);
}
/* ---------------------------------------------------------------------- */

View File

@ -81,6 +81,7 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) :
diam_flag = 0;
scalar_flag = vector_flag = array_flag = 0;
extscalar = extvector = extarray = -1;
peratom_flag = local_flag = pergrid_flag = 0;
global_freq = local_freq = peratom_freq = pergrid_freq = -1;
size_vector_variable = size_array_rows_variable = 0;
@ -119,13 +120,28 @@ Fix::~Fix()
{
if (copymode) return;
delete [] id;
delete [] style;
delete[] id;
delete[] style;
memory->destroy(eatom);
memory->destroy(vatom);
memory->destroy(cvatom);
}
/* ---------------------------------------------------------------------- */
void Fix::init_flags()
{
if (scalar_flag && (extscalar < 0))
error->all(FLERR, "Must set 'extscalar' when setting 'scalar_flag' for fix {}. "
"Contact the developer.", style);
if (vector_flag && (extvector < 0))
error->all(FLERR, "Must set 'extvector' when setting 'vector_flag' for fix {}. "
"Contact the developer.", style);
if (array_flag && (extarray < 0))
error->all(FLERR, "Must set 'extarray' when setting 'array_flag' for fix {}. "
"Contact the developer.", style);
}
/* ----------------------------------------------------------------------
process params common to all fixes here
if unknown param, call modify_param specific to the fix

View File

@ -145,6 +145,7 @@ class Fix : protected Pointers {
virtual void post_constructor() {}
virtual void init() {}
void init_flags();
virtual void init_list(int, class NeighList *) {}
virtual void setup(int) {}
virtual void setup_pre_exchange() {}

View File

@ -188,6 +188,8 @@ void Modify::init()
// since any of them may be invoked by initial thermo
// do not clear out invocation times stored within a compute,
// b/c some may be holdovers from previous run, like for ave fixes
// perform check whether extscalar, extvector, and extarray have been
// set when scalar_flag, vector_flag, or array_flag are true.
for (i = 0; i < ncompute; i++) {
compute[i]->init();
@ -200,8 +202,13 @@ void Modify::init()
// used to b/c temperature computes called fix->dof() in their init,
// and fix rigid required its own init before its dof() could be called,
// but computes now do their DOF in setup()
// perform check whether extscalar, extvector, and extarray have been
// set when scalar_flag, vector_flag, or array_flag are true.
for (i = 0; i < nfix; i++) fix[i]->init();
for (i = 0; i < nfix; i++) {
fix[i]->init();
fix[i]->init_flags();
}
// set global flag if any fix has its restart_pbc flag set