Initialize gmx_ekindata_t and t_vcm properly
authorMark Abraham <mark.j.abraham@gmail.com>
Thu, 8 Aug 2019 13:27:29 +0000 (15:27 +0200)
committerArtem Zhmurov <zhmurov@gmail.com>
Thu, 8 Aug 2019 17:26:31 +0000 (19:26 +0200)
Clean up in 0823a1e2e6591d76bcf15bdadfc3ec6, and 70bacbcfd639b17
left some fields initialized. The compute_globals code assumed it was
safe to reduce e.g. mvcos regardless of whether they were being used.
This is bad practice, but not a problem in the context of snew being
used for such structures.

Such fields are now initialized.

Change-Id: I12c462c9907ed34371e880cdd44ae162d44de67b

src/gromacs/mdlib/update.cpp
src/gromacs/mdlib/vcm.h
src/gromacs/mdtypes/group.h

index 35276d7c49cd4baef101ccbc691585ce6ff837d4..af0eb54ddcc7daae012761a6a50f5cadb767df57 100644 (file)
 
 using namespace gmx; // TODO: Remove when this file is moved into gmx namespace
 
-struct gmx_sd_const_t {
-    double em;
+struct gmx_sd_const_t
+{
+    double em = 0;
 };
 
-struct gmx_sd_sigma_t {
-    real V;
+struct gmx_sd_sigma_t
+{
+    real V = 0;
 };
 
 struct gmx_stochd_t
index 555d3e3c17b1b2d542f8845ee093286e2eefbb21..92b48b2c5cb6242302d0a459aa52f4dee4376fa9 100644 (file)
@@ -50,36 +50,59 @@ struct SimulationGroups;
 struct t_inputrec;
 struct t_mdatoms;
 
-struct t_vcm_thread{
-    rvec      p    = {0};   /* Linear momentum                     */
-    rvec      x    = {0};   /* Center of mass                      */
-    rvec      j    = {0};   /* Angular momentum                    */
-    tensor    i    = {{0}}; /* Moment of inertia                   */
-    real      mass = 0;     /* Mass                                */
+struct t_vcm_thread
+{
+    //! Linear momentum
+    rvec      p    = {0};
+    //! Center of mass
+    rvec      x    = {0};
+    //! Angular momentum
+    rvec      j    = {0};
+    //! Moment of inertia
+    tensor    i    = {{0}};
+    //! Mass
+    real      mass = 0;
 };
 
 struct t_vcm
 {
-    int                       nr;         /* Number of groups                    */
-    int                       size;       /* Size of group arrays                */
-    int                       stride;     /* Stride for thread data              */
-    int                       mode;       /* One of the enums above              */
-    int                       ndim;       /* The number of dimensions for corr.  */
-    real                      timeStep;   /* The time step for COMM removal      */
-    std::vector<real>         group_ndf;  /* Number of degrees of freedom        */
-    std::vector<real>         group_mass; /* Mass per group                      */
-    std::vector<gmx::RVec>    group_p;    /* Linear momentum per group           */
-    std::vector<gmx::RVec>    group_v;    /* Linear velocity per group           */
-    std::vector<gmx::RVec>    group_x;    /* Center of mass per group            */
-    std::vector<gmx::RVec>    group_j;    /* Angular momentum per group          */
-    std::vector<gmx::RVec>    group_w;    /* Angular velocity (omega)            */
-    tensor                   *group_i;    /* Moment of inertia per group         */
-    std::vector<char *>       group_name; /* These two are copies to pointers in */
-    ivec                     *nFreeze;    /* Tells whether dimensions are frozen per freeze group */
-    std::vector<t_vcm_thread> thread_vcm; /* Temporary data per thread and group */
+    //! Number of groups
+    int                       nr = 0;
+    //! Size of group arrays
+    int                       size = 0;
+    //! Stride for thread data
+    int                       stride = 0;
+    //! One of the enums above
+    int                       mode = 0;
+    //! The number of dimensions for corr.
+    int                       ndim = 0;
+    //! The time step for COMM removal
+    real                      timeStep = 0;
+    //! Number of degrees of freedom
+    std::vector<real>         group_ndf;
+    //! Mass per group
+    std::vector<real>         group_mass;
+    //! Linear momentum per group
+    std::vector<gmx::RVec>    group_p;
+    //! Linear velocity per group
+    std::vector<gmx::RVec>    group_v;
+    //! Center of mass per group
+    std::vector<gmx::RVec>    group_x;
+    //! Angular momentum per group
+    std::vector<gmx::RVec>    group_j;
+    //! Angular velocity (omega)
+    std::vector<gmx::RVec>    group_w;
+    //! Moment of inertia per group
+    tensor                   *group_i = nullptr;
+    //! These two are copies to pointers in
+    std::vector<char *>       group_name;
+    //! Tells whether dimensions are frozen per freeze group
+    ivec                     *nFreeze = nullptr;
+    //! Temporary data per thread and group
+    std::vector<t_vcm_thread> thread_vcm;
 
-    // Tell whether the integrator conserves momentum
-    bool integratorConservesMomentum;
+    //! Tell whether the integrator conserves momentum
+    bool integratorConservesMomentum = false;
 
     t_vcm(const SimulationGroups &groups, const t_inputrec &ir);
     ~t_vcm();
index 0dcd497ac16931855a7d7f5981af083205868acb..33738660b50b31b2043e10a987af3ae8db726eed 100644 (file)
 #include "gromacs/utility/smalloc.h"
 
 struct t_grp_tcstat{
-    real    Th             = 0;     /* Temperature at half step        */
-    real    T              = 0;     /* Temperature at full step        */
-    tensor  ekinh          = {{0}}; /* Kinetic energy at half step     */
-    tensor  ekinh_old      = {{0}}; /* Kinetic energy at old half step */
-    tensor  ekinf          = {{0}}; /* Kinetic energy at full step     */
-    real    lambda         = 0;     /* Berendsen coupling lambda       */
-    double  ekinscalef_nhc = 0;     /* Scaling factor for NHC- full step */
-    double  ekinscaleh_nhc = 0;     /* Scaling factor for NHC- half step */
-    double  vscale_nhc     = 0;     /* Scaling factor for NHC- velocity */
+    //! Temperature at half step
+    real    Th             = 0;
+    //! Temperature at full step
+    real    T              = 0;
+    //! Kinetic energy at half step
+    tensor  ekinh          = {{0}};
+    //! Kinetic energy at old half step
+    tensor  ekinh_old      = {{0}};
+    //! Kinetic energy at full step
+    tensor  ekinf          = {{0}};
+    //! Berendsen coupling lambda
+    real    lambda         = 0;
+    //! Scaling factor for NHC- full step
+    double  ekinscalef_nhc = 0;
+    //! Scaling factor for NHC- half step
+    double  ekinscaleh_nhc = 0;
+    //! Scaling factor for NHC- velocity
+    double  vscale_nhc     = 0;
 };
 
 struct t_grp_acc {
-    int     nat;    /* Number of atoms in this group           */
-    rvec    u;      /* Mean velocities of home particles        */
-    rvec    uold;   /* Previous mean velocities of home particles   */
-    double  mA;     /* Mass for topology A                             */
-    double  mB;     /* Mass for topology B                             */
+    //! Number of atoms in this group
+    int     nat = 0;
+    //! Mean velocities of home particles
+    rvec    u = { 0 };
+    //! Previous mean velocities of home particles
+    rvec    uold = { 0 };
+    //! Mass for topology A
+    double  mA = 0;
+    //! Mass for topology B
+    double  mB = 0;
 };
 
 struct t_cos_acc{
-    real    cos_accel;  /* The acceleration for the cosine profile      */
-    real    mvcos;      /* The cos momenta of home particles            */
-    real    vcos;       /* The velocity of the cosine profile           */
+    //! The acceleration for the cosine profile
+    real    cos_accel = 0;
+    //! The cos momenta of home particles
+    real    mvcos = 0;
+    //! The velocity of the cosine profile
+    real    vcos = 0;
 };
 
 struct gmx_ekindata_t {
+    //! Whether non-equilibrium MD is active (ie. constant or cosine acceleration)
     gmx_bool                  bNEMD;
-    int                       ngtc;            /* The number of T-coupling groups      */
-    int                       nthreads;        /* For size of ekin_work */
-    std::vector<t_grp_tcstat> tcstat;          /* T-coupling data            */
-    tensor                  **ekin_work_alloc; /* Allocated locations for *_work members */
-    tensor                  **ekin_work;       /* Work arrays for tcstat per thread    */
-    real                    **dekindl_work;    /* Work location for dekindl per thread */
-    int                       ngacc;           /* The number of acceleration groups    */
-    std::vector<t_grp_acc>    grpstat;         /* Acceleration data                    */
-    tensor                    ekin;            /* overall kinetic energy               */
-    tensor                    ekinh;           /* overall 1/2 step kinetic energy      */
-    real                      dekindl;         /* dEkin/dlambda at half step           */
-    real                      dekindl_old;     /* dEkin/dlambda at old half step       */
-    t_cos_acc                 cosacc;          /* Cosine acceleration data             */
+    //! The number of T-coupling groups
+    int                       ngtc = 0;
+    //! For size of ekin_work
+    int                       nthreads = 0;
+    //! T-coupling data
+    std::vector<t_grp_tcstat> tcstat;
+    //! Allocated locations for *_work members
+    tensor                  **ekin_work_alloc = nullptr;
+    //! Work arrays for tcstat per thread
+    tensor                  **ekin_work = nullptr;
+    //! Work location for dekindl per thread
+    real                    **dekindl_work = nullptr;
+    //! The number of acceleration groups
+    int                       ngacc = 0;
+    //! Acceleration data
+    std::vector<t_grp_acc>    grpstat;
+    //! overall kinetic energy
+    tensor                    ekin = {{ 0 }};
+    //! overall 1/2 step kinetic energy
+    tensor                    ekinh = {{ 0 }};
+    //! dEkin/dlambda at half step
+    real                      dekindl = 0;
+    //! dEkin/dlambda at old half step
+    real                      dekindl_old = 0;
+    //! Cosine acceleration data
+    t_cos_acc                 cosacc;
 
     ~gmx_ekindata_t();
 };