diff --git a/src/compute.cpp b/src/compute.cpp index a12373fd51..5d5a4d5246 100644 --- a/src/compute.cpp +++ b/src/compute.cpp @@ -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); } /* ---------------------------------------------------------------------- */ diff --git a/src/fix.cpp b/src/fix.cpp index 754948fdd1..1e1ab8c928 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -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 diff --git a/src/fix.h b/src/fix.h index ca0a1ef84b..594fbb51bf 100644 --- a/src/fix.h +++ b/src/fix.h @@ -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() {} diff --git a/src/modify.cpp b/src/modify.cpp index ba04c5969a..1a9c056027 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -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