avoid access to uninitialized step_respa pointer in Nose-Hoover fixes
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "neighbor.h"
|
||||
#include "respa.h"
|
||||
#include "update.h"
|
||||
|
||||
#include <cmath>
|
||||
@ -339,8 +340,13 @@ void FixNHIntel::reset_dt()
|
||||
|
||||
// If using respa, then remap is performed in innermost level
|
||||
|
||||
if (utils::strmatch(update->integrate_style,"^respa"))
|
||||
if (utils::strmatch(update->integrate_style,"^respa")) {
|
||||
auto respa_ptr = dynamic_cast<Respa *>(update->integrate);
|
||||
if (!respa_ptr) error->all(FLERR, "Failure to access Respa style {}", update->integrate_style);
|
||||
nlevels_respa = respa_ptr->nlevels;
|
||||
step_respa = respa_ptr->step;
|
||||
dto = 0.5*step_respa[0];
|
||||
}
|
||||
|
||||
if (pstat_flag)
|
||||
pdrag_factor = 1.0 - (update->dt * p_freq_max * drag / nc_pchain);
|
||||
|
||||
@ -371,7 +371,9 @@ void FixShake::init()
|
||||
// if rRESPA, find associated fix that must exist
|
||||
// could have changed locations in fix list since created
|
||||
// set ptrs to rRESPA variables
|
||||
// set respa to 0 if verlet is used and to 1 otherwise
|
||||
|
||||
respa = 0;
|
||||
fix_respa = nullptr;
|
||||
if (utils::strmatch(update->integrate_style,"^respa")) {
|
||||
if (update->whichflag > 0) {
|
||||
@ -379,10 +381,12 @@ void FixShake::init()
|
||||
if (fixes.size() > 0) fix_respa = dynamic_cast<FixRespa *>(fixes.front());
|
||||
else error->all(FLERR,"Run style respa did not create fix RESPA");
|
||||
}
|
||||
auto respa_style = dynamic_cast<Respa *>(update->integrate);
|
||||
nlevels_respa = respa_style->nlevels;
|
||||
loop_respa = respa_style->loop;
|
||||
step_respa = respa_style->step;
|
||||
auto respa_ptr = dynamic_cast<Respa *>(update->integrate);
|
||||
if (!respa_ptr) error->all(FLERR, "Failure to access Respa style {}", update->integrate_style);
|
||||
respa = 1;
|
||||
nlevels_respa = respa_ptr->nlevels;
|
||||
loop_respa = respa_ptr->loop;
|
||||
step_respa = respa_ptr->step;
|
||||
}
|
||||
|
||||
// set equilibrium bond distances
|
||||
@ -473,18 +477,22 @@ void FixShake::setup(int vflag)
|
||||
next_output = (ntimestep/output_every)*output_every + output_every;
|
||||
} else next_output = -1;
|
||||
|
||||
// set respa to 0 if verlet is used and to 1 otherwise
|
||||
|
||||
if (utils::strmatch(update->integrate_style,"^verlet"))
|
||||
respa = 0;
|
||||
else
|
||||
respa = 1;
|
||||
|
||||
if (!respa) {
|
||||
dtv = update->dt;
|
||||
dtfsq = 0.5 * update->dt * update->dt * force->ftm2v;
|
||||
if (!rattle) dtfsq = update->dt * update->dt * force->ftm2v;
|
||||
} else {
|
||||
auto respa_ptr = dynamic_cast<Respa *>(update->integrate);
|
||||
if (!respa_ptr) error->all(FLERR, "Failure to access Respa style {}", update->integrate_style);
|
||||
if (update->whichflag > 0) {
|
||||
auto fixes = modify->get_fix_by_style("^RESPA");
|
||||
if (fixes.size() > 0) fix_respa = dynamic_cast<FixRespa *>(fixes.front());
|
||||
else error->all(FLERR,"Run style respa did not create fix RESPA");
|
||||
}
|
||||
respa = 1;
|
||||
nlevels_respa = respa_ptr->nlevels;
|
||||
loop_respa = respa_ptr->loop;
|
||||
step_respa = respa_ptr->step;
|
||||
dtv = step_respa[0];
|
||||
dtf_innerhalf = 0.5 * step_respa[0] * force->ftm2v;
|
||||
dtf_inner = dtf_innerhalf;
|
||||
|
||||
@ -53,12 +53,9 @@ enum{ISO,ANISO,TRICLINIC};
|
||||
---------------------------------------------------------------------- */
|
||||
|
||||
FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
rfix(nullptr), id_dilate(nullptr), irregular(nullptr),
|
||||
id_temp(nullptr), id_press(nullptr),
|
||||
eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr),
|
||||
eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr),
|
||||
etap_mass(nullptr)
|
||||
Fix(lmp, narg, arg), rfix(nullptr), id_dilate(nullptr), irregular(nullptr),step_respa(nullptr),
|
||||
id_temp(nullptr), id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr),
|
||||
eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr)
|
||||
{
|
||||
if (narg < 4) utils::missing_cmd_args(FLERR, std::string("fix ") + style, error);
|
||||
|
||||
@ -712,8 +709,10 @@ void FixNH::init()
|
||||
else kspace_flag = 0;
|
||||
|
||||
if (utils::strmatch(update->integrate_style,"^respa")) {
|
||||
nlevels_respa = (dynamic_cast<Respa *>(update->integrate))->nlevels;
|
||||
step_respa = (dynamic_cast<Respa *>(update->integrate))->step;
|
||||
auto respa_ptr = dynamic_cast<Respa *>(update->integrate);
|
||||
if (!respa_ptr) error->all(FLERR, "Failure to access Respa style {}", update->integrate_style);
|
||||
nlevels_respa = respa_ptr->nlevels;
|
||||
step_respa = respa_ptr->step;
|
||||
dto = 0.5*step_respa[0];
|
||||
}
|
||||
|
||||
@ -1706,8 +1705,13 @@ void FixNH::reset_dt()
|
||||
|
||||
// If using respa, then remap is performed in innermost level
|
||||
|
||||
if (utils::strmatch(update->integrate_style,"^respa"))
|
||||
if (utils::strmatch(update->integrate_style,"^respa")) {
|
||||
auto respa_ptr = dynamic_cast<Respa *>(update->integrate);
|
||||
if (!respa_ptr) error->all(FLERR, "Failure to access Respa style {}", update->integrate_style);
|
||||
nlevels_respa = respa_ptr->nlevels;
|
||||
step_respa = respa_ptr->step;
|
||||
dto = 0.5*step_respa[0];
|
||||
}
|
||||
|
||||
if (pstat_flag)
|
||||
pdrag_factor = 1.0 - (update->dt * p_freq_max * drag / nc_pchain);
|
||||
|
||||
Reference in New Issue
Block a user