diff --git a/src/fix_langevin.cpp b/src/fix_langevin.cpp index cf3161e8a8..9e857339b4 100644 --- a/src/fix_langevin.cpp +++ b/src/fix_langevin.cpp @@ -146,7 +146,13 @@ FixLangevin::FixLangevin(LAMMPS *lmp, int narg, char **arg) : temperature = NULL; energy = 0.0; + + // flangevin is unallocated until first call to setup() + // compute_scalar checks for this and returns 0.0 + // if flangevin_allocated is not set + flangevin = NULL; + flangevin_allocated = 0; franprev = NULL; tforce = NULL; maxatom1 = maxatom2 = 0; @@ -510,6 +516,7 @@ void FixLangevin::post_force_untemplated maxatom1 = atom->nmax; memory->create(flangevin,maxatom1,3,"langevin:flangevin"); } + flangevin_allocated = 1; } if (Tp_BIAS) temperature->compute_scalar(); @@ -824,7 +831,7 @@ int FixLangevin::modify_param(int narg, char **arg) double FixLangevin::compute_scalar() { - if (!tallyflag) return 0.0; + if (!tallyflag || !flangevin_allocated) return 0.0; // capture the very first energy transfer to thermal reservoir diff --git a/src/fix_langevin.h b/src/fix_langevin.h index 1e084c9e98..863c0f554c 100644 --- a/src/fix_langevin.h +++ b/src/fix_langevin.h @@ -47,6 +47,7 @@ class FixLangevin : public Fix { protected: int gjfflag,oflag,tallyflag,zeroflag,tbiasflag; + int flangevin_allocated; double ascale; double t_start,t_stop,t_period,t_target; double *gfactor1,*gfactor2,*ratio;