Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / mdlib / update.cpp
similarity index 97%
rename from src/gromacs/mdlib/update.c
rename to src/gromacs/mdlib/update.cpp
index c4bdfe3892908ec4b191ae80967367bb469df2a7..97712b74282ddb2120257a3777c995218963f615 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
+#include "gromacs/legacyheaders/update.h"
 
-#include <stdio.h>
 #include <math.h>
+#include <stdio.h>
 
-#include "types/commrec.h"
-#include "sysstuff.h"
-#include "gromacs/utility/smalloc.h"
-#include "typedefs.h"
-#include "nrnb.h"
-#include "physics.h"
-#include "macros.h"
-#include "vec.h"
-#include "main.h"
-#include "update.h"
-#include "gromacs/random/random.h"
-#include "mshift.h"
-#include "tgroup.h"
-#include "force.h"
-#include "names.h"
-#include "txtdump.h"
-#include "mdrun.h"
-#include "constr.h"
-#include "disre.h"
-#include "orires.h"
-#include "gmx_omp_nthreads.h"
+#include <algorithm>
 
 #include "gromacs/fileio/confio.h"
-#include "gromacs/fileio/futil.h"
+#include "gromacs/legacyheaders/constr.h"
+#include "gromacs/legacyheaders/disre.h"
+#include "gromacs/legacyheaders/force.h"
+#include "gromacs/legacyheaders/gmx_omp_nthreads.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/mdrun.h"
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/legacyheaders/nrnb.h"
+#include "gromacs/legacyheaders/orires.h"
+#include "gromacs/legacyheaders/tgroup.h"
+#include "gromacs/legacyheaders/txtdump.h"
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/types/commrec.h"
+#include "gromacs/math/units.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/mshift.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/pulling/pull.h"
+#include "gromacs/random/random.h"
 #include "gromacs/timing/wallcycle.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxomp.h"
-#include "gromacs/pulling/pull.h"
+#include "gromacs/utility/smalloc.h"
 
 /*For debugging, start at v(-dt/2) for velolcity verlet -- uncomment next line */
 /*#define STARTFROMDT2*/
@@ -266,10 +264,8 @@ static void do_update_vv_vel(int start, int nrend, double dt,
                              unsigned short cACC[], rvec v[], rvec f[],
                              gmx_bool bExtended, real veta, real alpha)
 {
-    double imass, w_dt;
+    double w_dt;
     int    gf = 0, ga = 0;
-    rvec   vrel;
-    real   u, vn, vv, va, vb, vnrel;
     int    n, d;
     double g, mv1, mv2;
 
@@ -316,7 +312,6 @@ static void do_update_vv_pos(int start, int nrend, double dt,
                              rvec x[], rvec xprime[], rvec v[],
                              gmx_bool bExtended, real veta)
 {
-    double imass, w_dt;
     int    gf = 0;
     int    n, d;
     double g, mr1, mr2;
@@ -401,8 +396,6 @@ static void do_update_visc(int start, int nrend, double dt,
             }
             for (d = 0; d < DIM; d++)
             {
-                vn             = v[n][d];
-
                 if ((ptype[n] != eptVSite) && (ptype[n] != eptShell))
                 {
                     vn  = (lg*vrel[d] + dt*(imass*f[n][d] - 0.5*vxi*vrel[d]
@@ -469,7 +462,7 @@ static gmx_stochd_t *init_stochd(t_inputrec *ir)
 {
     gmx_stochd_t   *sd;
     gmx_sd_const_t *sdc;
-    int             ngtc, n, th;
+    int             ngtc, n;
     real            y;
 
     snew(sd, 1);
@@ -542,7 +535,7 @@ static gmx_stochd_t *init_stochd(t_inputrec *ir)
 
         for (n = 0; n < ngtc; n++)
         {
-            reft = max(0.0, opts->ref_t[n]);
+            reft = std::max<real>(0, opts->ref_t[n]);
             if ((opts->tau_t[n] > 0) && (reft > 0))  /* tau_t or ref_t = 0 means that no randomization is done */
             {
                 sd->randomize_group[n] = TRUE;
@@ -668,10 +661,6 @@ static void do_update_sd1(gmx_stochd_t *sd,
                 {
                     ga  = cACC[n];
                 }
-                if (cTC)
-                {
-                    gt  = cTC[n];
-                }
 
                 for (d = 0; d < DIM; d++)
                 {
@@ -701,10 +690,6 @@ static void do_update_sd1(gmx_stochd_t *sd,
                 {
                     gf  = cFREEZE[n];
                 }
-                if (cACC)
-                {
-                    ga  = cACC[n];
-                }
                 if (cTC)
                 {
                     gt  = cTC[n];
@@ -783,7 +768,6 @@ static void do_update_sd2(gmx_stochd_t *sd,
      * half of the update, needs to be remembered for the second half.
      */
     rvec  *sd_V;
-    real   kT;
     int    gf = 0, ga = 0, gt = 0;
     real   vn = 0, Vmh, Xmh;
     real   ism;
@@ -1337,7 +1321,7 @@ void update_tcouple(gmx_int64_t       step,
 {
     gmx_bool   bTCouple = FALSE;
     real       dttc;
-    int        i, start, end, homenr, offset;
+    int        i, offset;
 
     /* if using vv with trotter decomposition methods, we do this elsewhere in the code */
     if (inputrec->etc != etcNO &&
@@ -1559,12 +1543,11 @@ void update_constraints(FILE             *fplog,
                         gmx_bool          bCalcVir,
                         real              vetanew)
 {
-    gmx_bool             bExtended, bLastStep, bLog = FALSE, bEner = FALSE, bDoConstr = FALSE;
+    gmx_bool             bLastStep, bLog = FALSE, bEner = FALSE, bDoConstr = FALSE;
     double               dt;
-    real                 dt_1;
-    int                  start, homenr, nrend, i, n, m, g, d;
+    int                  start, homenr, nrend, i, m;
     tensor               vir_con;
-    rvec                *vbuf, *xprime = NULL;
+    rvec                *xprime = NULL;
     int                  nth, th;
 
     if (constr)
@@ -1584,7 +1567,6 @@ void update_constraints(FILE             *fplog,
     nrend  = start+homenr;
 
     dt   = inputrec->delta_t;
-    dt_1 = 1.0/dt;
 
     /*
      *  Steps (7C, 8C)
@@ -1775,6 +1757,7 @@ void update_constraints(FILE             *fplog,
         }
         else
         {
+            // cppcheck-suppress unreadVariable
             nth = gmx_omp_nthreads_get(emntUpdate);
 
 #pragma omp parallel for num_threads(nth) schedule(static)
@@ -1801,20 +1784,11 @@ void update_box(FILE             *fplog,
                 t_nrnb           *nrnb,
                 gmx_update_t      upd)
 {
-    gmx_bool             bExtended, bLastStep, bLog = FALSE, bEner = FALSE;
     double               dt;
-    real                 dt_1;
-    int                  start, homenr, nrend, i, n, m, g;
-    tensor               vir_con;
+    int                  start, homenr, i, n, m;
 
     start  = 0;
     homenr = md->homenr;
-    nrend  = start+homenr;
-
-    bExtended =
-        (inputrec->etc == etcNOSEHOOVER) ||
-        (inputrec->epc == epcPARRINELLORAHMAN) ||
-        (inputrec->epc == epcMTTK);
 
     dt = inputrec->delta_t;
 
@@ -1916,16 +1890,11 @@ void update_coords(FILE             *fplog,
                    gmx_constr_t      constr,
                    t_idef           *idef)
 {
-    gmx_bool          bNH, bPR, bLastStep, bLog = FALSE, bEner = FALSE, bDoConstr = FALSE;
+    gmx_bool          bNH, bPR, bDoConstr = FALSE;
     double            dt, alpha;
-    real             *imass, *imassin;
     rvec             *force;
-    real              dt_1;
-    int               start, homenr, nrend, i, j, d, n, m, g;
-    int               blen0, blen1, iatom, jatom, nshake, nsettle, nconstr, nexpand;
-    int              *icom = NULL;
-    tensor            vir_con;
-    rvec             *vcom, *xcom, *vall, *xall, *xin, *vin, *forcein, *fall, *xpall, *xprimein, *xprime;
+    int               start, homenr, nrend;
+    rvec             *xprime;
     int               nth, th;
 
     bDoConstr = (NULL != constr);
@@ -1944,7 +1913,6 @@ void update_coords(FILE             *fplog,
     xprime = get_xprime(state, upd);
 
     dt   = inputrec->delta_t;
-    dt_1 = 1.0/dt;
 
     /* We need to update the NMR restraint history when time averaging is used */
     if (state->flags & (1<<estDISRE_RM3TAV))
@@ -2160,7 +2128,6 @@ extern gmx_bool update_randomize_velocities(t_inputrec *ir, gmx_int64_t step, co
                                             t_mdatoms *md, t_state *state, gmx_update_t upd, gmx_constr_t constr)
 {
 
-    int  i;
     real rate = (ir->delta_t)/ir->opts.tau_t[0];
 
     if (ir->etc == etcANDERSEN && constr != NULL)