Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / mdlib / mdebin_bar.cpp
index 6a6d467999fc41f2bfea111955cdb32f8502af67..a0db60909977cca9e8698b79871310818362bda6 100644 (file)
@@ -61,17 +61,21 @@ constexpr int c_subblockDNumPreEntries = 5;
 constexpr int c_subblockINumPreEntries = 2;
 
 /* reset the delta_h list to prepare it for new values */
-static void mde_delta_h_reset(t_mde_delta_h *dh)
+static void mde_delta_h_reset(t_mde_delta_hdh)
 {
     dh->ndh     = 0;
     dh->written = FALSE;
 }
 
 /* initialize the delta_h list */
-static void mde_delta_h_init(t_mde_delta_h *dh, int nbins,
-                             double dx, unsigned int  ndhmax,
-                             int type, int derivative, int nlambda,
-                             const double *lambda)
+static void mde_delta_h_init(t_mde_delta_h* dh,
+                             int            nbins,
+                             double         dx,
+                             unsigned int   ndhmax,
+                             int            type,
+                             int            derivative,
+                             int            nlambda,
+                             const double*  lambda)
 {
     int i;
 
@@ -87,9 +91,9 @@ static void mde_delta_h_init(t_mde_delta_h *dh, int nbins,
     }
 
 
-    snew(dh->subblock_meta_d, dh->nlambda+1);
+    snew(dh->subblock_meta_d, dh->nlambda + 1);
 
-    dh->ndhmax = ndhmax+2;
+    dh->ndhmax = ndhmax + 2;
     for (i = 0; i < 2; i++)
     {
         dh->bin[i] = nullptr;
@@ -98,7 +102,7 @@ static void mde_delta_h_init(t_mde_delta_h *dh, int nbins,
     snew(dh->dh, dh->ndhmax);
     snew(dh->dhf, dh->ndhmax);
 
-    if (nbins <= 0 || dx < GMX_REAL_EPS*10)
+    if (nbins <= 0 || dx < GMX_REAL_EPS * 10)
     {
         dh->nhist = 0;
     }
@@ -117,7 +121,7 @@ static void mde_delta_h_init(t_mde_delta_h *dh, int nbins,
     mde_delta_h_reset(dh);
 }
 
-static void done_mde_delta_h(t_mde_delta_h *dh)
+static void done_mde_delta_h(t_mde_delta_hdh)
 {
     sfree(dh->lambda);
     sfree(dh->subblock_meta_d);
@@ -130,7 +134,7 @@ static void done_mde_delta_h(t_mde_delta_h *dh)
 }
 
 /* Add a value to the delta_h list */
-static void mde_delta_h_add_dh(t_mde_delta_h *dh, double delta_h)
+static void mde_delta_h_add_dh(t_mde_delta_hdh, double delta_h)
 {
     if (dh->ndh >= dh->ndhmax)
     {
@@ -141,7 +145,7 @@ static void mde_delta_h_add_dh(t_mde_delta_h *dh, double delta_h)
 }
 
 /* construct histogram with index hi */
-static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
+static void mde_delta_h_make_hist(t_mde_delta_hdh, int hi, gmx_bool invert)
 {
     double       min_dh = FLT_MAX;
     double       max_dh = -FLT_MAX;
@@ -149,7 +153,7 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
     double       max_dh_hist; /* maximum binnable dh value */
     double       min_dh_hist; /* minimum binnable dh value */
     double       dx = dh->dx;
-    double       f;           /* energy mult. factor */
+    double       f; /* energy mult. factor */
 
     /* by applying a -1 scaling factor on the energies we get the same as
        having a negative dx, but we don't need to fix the min/max values
@@ -159,13 +163,13 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
     /* first find min and max */
     for (i = 0; i < dh->ndh; i++)
     {
-        if (f*dh->dh[i] < min_dh)
+        if (f * dh->dh[i] < min_dh)
         {
-            min_dh = f*dh->dh[i];
+            min_dh = f * dh->dh[i];
         }
-        if (f*dh->dh[i] > max_dh)
+        if (f * dh->dh[i] > max_dh)
         {
-            max_dh = f*dh->dh[i];
+            max_dh = f * dh->dh[i];
         }
     }
 
@@ -182,10 +186,10 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
        Get this start value in number of histogram dxs from zero,
        as an integer.*/
 
-    dh->x0[hi] = static_cast<int64_t>(floor(min_dh/dx));
+    dh->x0[hi] = static_cast<int64_t>(floor(min_dh / dx));
 
-    min_dh_hist = (dh->x0[hi])*dx;
-    max_dh_hist = (dh->x0[hi] + dh->nbins + 1)*dx;
+    min_dh_hist = (dh->x0[hi]) * dx;
+    max_dh_hist = (dh->x0[hi] + dh->nbins + 1) * dx;
 
     /* and fill the histogram*/
     for (i = 0; i < dh->ndh; i++)
@@ -196,18 +200,18 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
            add it to the last bin.
            We check the max_dh_int range because converting to integers
            might lead to overflow with unpredictable results.*/
-        if ( (f*dh->dh[i] >= min_dh_hist) && (f*dh->dh[i] <= max_dh_hist ) )
+        if ((f * dh->dh[i] >= min_dh_hist) && (f * dh->dh[i] <= max_dh_hist))
         {
-            bin = static_cast<unsigned int>( (f*dh->dh[i] - min_dh_hist)/dx );
+            bin = static_cast<unsigned int>((f * dh->dh[i] - min_dh_hist) / dx);
         }
         else
         {
-            bin = dh->nbins-1;
+            bin = dh->nbins - 1;
         }
         /* double-check here because of possible round-off errors*/
         if (bin >= dh->nbins)
         {
-            bin = dh->nbins-1;
+            bin = dh->nbins - 1;
         }
         if (bin > dh->maxbin[hi])
         {
@@ -220,14 +224,14 @@ static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
     /* make sure we include a bin with 0 if we didn't use the full
        histogram width. This can then be used as an indication that
        all the data was binned. */
-    if (dh->maxbin[hi] < dh->nbins-1)
+    if (dh->maxbin[hi] < dh->nbins - 1)
     {
         dh->maxbin[hi] += 1;
     }
 }
 
 
-static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
+static void mde_delta_h_handle_block(t_mde_delta_h* dh, t_enxblock* blk)
 {
     /* first check which type we should use: histogram or raw data */
     if (dh->nhist == 0)
@@ -248,9 +252,9 @@ static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
                                                     applicable (in indices
                                                     starting from first coord in
                                                     the main delta_h_coll) */
-        blk->sub[0].nr         = 2;
-        blk->sub[0].type       = xdr_datatype_int;
-        blk->sub[0].ival       = dh->subblock_meta_i;
+        blk->sub[0].nr   = 2;
+        blk->sub[0].type = xdr_datatype_int;
+        blk->sub[0].ival = dh->subblock_meta_i;
 
         /* subblock 2 */
         for (i = 0; i < dh->nlambda; i++)
@@ -309,7 +313,7 @@ static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
                     nhist_written++;
                     /* check whether this histogram contains all data: if the
                        last bin is 0, it does */
-                    if (dh->bin[i][dh->nbins-1] == 0)
+                    if (dh->bin[i][dh->nbins - 1] == 0)
                     {
                         prev_complete = TRUE;
                     }
@@ -325,7 +329,7 @@ static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
         /* A histogram consists of 2, 3 or 4 subblocks:
            the foreign lambda value + histogram spacing, the starting point,
            and the histogram data (0, 1 or 2 blocks). */
-        add_subblocks_enxblock(blk, nhist_written+2);
+        add_subblocks_enxblock(blk, nhist_written + 2);
         blk->id = enxDHHIST;
 
         /* subblock 1: the lambda value + the histogram spacing */
@@ -339,18 +343,18 @@ static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
             dh->subblock_meta_d[0] = -1;
             for (i = 0; i < dh->nlambda; i++)
             {
-                dh->subblock_meta_d[2+i] = dh->lambda[i];
+                dh->subblock_meta_d[2 + i] = dh->lambda[i];
             }
         }
         dh->subblock_meta_d[1] = dh->dx;
-        blk->sub[0].nr         = 2+ ((dh->nlambda > 1) ? dh->nlambda : 0);
+        blk->sub[0].nr         = 2 + ((dh->nlambda > 1) ? dh->nlambda : 0);
         blk->sub[0].type       = xdr_datatype_double;
         blk->sub[0].dval       = dh->subblock_meta_d;
 
         /* subblock 2: the starting point(s) as a long integer */
         dh->subblock_meta_l[0] = nhist_written;
         dh->subblock_meta_l[1] = dh->type; /*dh->derivative ? 1 : 0;*/
-        k = 2;
+        k                      = 2;
         for (i = 0; i < nhist_written; i++)
         {
             dh->subblock_meta_l[k++] = dh->x0[i];
@@ -358,39 +362,39 @@ static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
         /* append the derivative data */
         dh->subblock_meta_l[k++] = dh->derivative;
 
-        blk->sub[1].nr   = nhist_written+3;
+        blk->sub[1].nr   = nhist_written + 3;
         blk->sub[1].type = xdr_datatype_int64;
         blk->sub[1].lval = dh->subblock_meta_l;
 
         /* subblock 3 + 4 : the histogram data */
         for (i = 0; i < nhist_written; i++)
         {
-            blk->sub[i+2].nr   = dh->maxbin[i]+1; /* it's +1 because size=index+1
-                                                     in C */
-            blk->sub[i+2].type = xdr_datatype_int;
-            blk->sub[i+2].ival = dh->bin[i];
+            blk->sub[i + 2].nr = dh->maxbin[i] + 1; /* it's +1 because size=index+1
+                                                       in C */
+            blk->sub[i + 2].type = xdr_datatype_int;
+            blk->sub[i + 2].ival = dh->bin[i];
         }
     }
 }
 
 /* initialize the collection*/
-void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
+void mde_delta_h_coll_init(t_mde_delta_h_coll* dhc, const t_inputrec* ir)
 {
     int       i, j, n;
-    double   *lambda_vec;
-    int       ndhmax = ir->nstenergy/ir->nstcalcenergy;
-    t_lambda *fep    = ir->fepvals;
+    double*   lambda_vec;
+    int       ndhmax = ir->nstenergy / ir->nstcalcenergy;
+    t_lambdafep    = ir->fepvals;
 
     dhc->temperature    = ir->opts.ref_t[0]; /* only store system temperature */
     dhc->start_time     = 0.;
-    dhc->delta_time     = ir->delta_t*ir->fepvals->nstdhdl;
+    dhc->delta_time     = ir->delta_t * ir->fepvals->nstdhdl;
     dhc->start_time_set = FALSE;
 
     /* this is the compatibility lambda value. If it is >=0, it is valid,
        and there is either an old-style lambda or a slow growth simulation. */
     dhc->start_lambda = ir->fepvals->init_lambda;
     /* for continuous change of lambda values */
-    dhc->delta_lambda = ir->fepvals->delta_lambda*ir->fepvals->nstdhdl;
+    dhc->delta_lambda = ir->fepvals->delta_lambda * ir->fepvals->nstdhdl;
 
     if (dhc->start_lambda < 0)
     {
@@ -412,11 +416,9 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
             if (fep->separate_dvdl[i])
             {
                 dhc->native_lambda_components[j] = i;
-                if (fep->init_fep_state >= 0 &&
-                    fep->init_fep_state < fep->n_lambda)
+                if (fep->init_fep_state >= 0 && fep->init_fep_state < fep->n_lambda)
                 {
-                    dhc->native_lambda_vec[j] =
-                        fep->all_lambda[i][fep->init_fep_state];
+                    dhc->native_lambda_vec[j] = fep->all_lambda[i][fep->init_fep_state];
                 }
                 else
                 {
@@ -463,14 +465,14 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
             {
                 if (ir->fepvals->separate_dvdl[i])
                 {
-                    dhc->ndh   += 1;
+                    dhc->ndh += 1;
                     dhc->ndhdl += 1;
                 }
             }
         }
         /* add the lambdas */
         dhc->nlambda = ir->fepvals->lambda_stop_n - ir->fepvals->lambda_start_n;
-        dhc->ndh    += dhc->nlambda;
+        dhc->ndh += dhc->nlambda;
         /* another compatibility check */
         if (dhc->start_lambda < 0)
         {
@@ -485,12 +487,12 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
             if (ir->fepvals->edHdLPrintEnergy != edHdLPrintEnergyNO)
             {
                 dhc->ndh += 1;
-                bEnergy   = TRUE;
+                bEnergy = TRUE;
             }
             if (ir->epc > epcNO)
             {
-                dhc->ndh += 1;  /* include pressure-volume work */
-                bPV       = TRUE;
+                dhc->ndh += 1; /* include pressure-volume work */
+                bPV = TRUE;
             }
         }
         /* allocate them */
@@ -502,18 +504,16 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
         n = 0;
         if (bExpanded)
         {
-            dhc->dh_expanded = dhc->dh+n;
-            mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
-                             ir->fepvals->dh_hist_spacing, ndhmax,
-                             dhbtEXPANDED, 0, 0, nullptr);
+            dhc->dh_expanded = dhc->dh + n;
+            mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+                             ndhmax, dhbtEXPANDED, 0, 0, nullptr);
             n++;
         }
         if (bEnergy)
         {
-            dhc->dh_energy = dhc->dh+n;
-            mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
-                             ir->fepvals->dh_hist_spacing, ndhmax,
-                             dhbtEN, 0, 0, nullptr);
+            dhc->dh_energy = dhc->dh + n;
+            mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+                             ndhmax, dhbtEN, 0, 0, nullptr);
             n++;
         }
         /* add the dhdl's */
@@ -526,10 +526,8 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
                 if (ir->fepvals->separate_dvdl[i])
                 {
                     /* we give it init_lambda for compatibility */
-                    mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
-                                     ir->fepvals->dh_hist_spacing, ndhmax,
-                                     dhbtDHDL, n_lambda_components, 1,
-                                     &(fep->init_lambda));
+                    mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+                                     ndhmax, dhbtDHDL, n_lambda_components, 1, &(fep->init_lambda));
                     n++;
                     n_lambda_components++;
                 }
@@ -544,7 +542,6 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
                     n_lambda_components++; /* count the components */
                 }
             }
-
         }
         /* add the lambdas */
         dhc->dh_du = dhc->dh + n;
@@ -561,24 +558,22 @@ void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
                 }
             }
 
-            mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
-                             ir->fepvals->dh_hist_spacing, ndhmax,
-                             dhbtDH, 0, n_lambda_components, lambda_vec);
+            mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+                             ndhmax, dhbtDH, 0, n_lambda_components, lambda_vec);
             n++;
         }
         sfree(lambda_vec);
         if (bPV)
         {
-            dhc->dh_pv = dhc->dh+n;
-            mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
-                             ir->fepvals->dh_hist_spacing, ndhmax,
-                             dhbtPV, 0, 0, nullptr);
+            dhc->dh_pv = dhc->dh + n;
+            mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+                             ndhmax, dhbtPV, 0, 0, nullptr);
             n++;
         }
     }
 }
 
-void done_mde_delta_h_coll(t_mde_delta_h_coll *dhc)
+void done_mde_delta_h_coll(t_mde_delta_h_colldhc)
 {
     if (dhc == nullptr)
     {
@@ -597,12 +592,12 @@ void done_mde_delta_h_coll(t_mde_delta_h_coll *dhc)
 }
 
 /* add a bunch of samples - note fep_state is double to allow for better data storage */
-void mde_delta_h_coll_add_dh(t_mde_delta_h_coll *dhc,
+void mde_delta_h_coll_add_dh(t_mde_delta_h_colldhc,
                              double              fep_state,
                              double              energy,
                              double              pV,
-                             double             *dhdl,
-                             double             *foreign_dU,
+                             double*             dhdl,
+                             double*             foreign_dU,
                              double              time)
 {
     int i;
@@ -615,11 +610,11 @@ void mde_delta_h_coll_add_dh(t_mde_delta_h_coll *dhc,
 
     for (i = 0; i < dhc->ndhdl; i++)
     {
-        mde_delta_h_add_dh(dhc->dh_dhdl+i, dhdl[i]);
+        mde_delta_h_add_dh(dhc->dh_dhdl + i, dhdl[i]);
     }
     for (i = 0; i < dhc->nlambda; i++)
     {
-        mde_delta_h_add_dh(dhc->dh_du+i, foreign_dU[i]);
+        mde_delta_h_add_dh(dhc->dh_du + i, foreign_dU[i]);
     }
     if (dhc->dh_pv != nullptr)
     {
@@ -633,21 +628,19 @@ void mde_delta_h_coll_add_dh(t_mde_delta_h_coll *dhc,
     {
         mde_delta_h_add_dh(dhc->dh_expanded, fep_state);
     }
-
 }
 
 /* write the metadata associated with all the du blocks, and call
    handle_block to write out all the du blocks */
-void mde_delta_h_coll_handle_block(t_mde_delta_h_coll *dhc,
-                                   t_enxframe *fr, int nblock)
+void mde_delta_h_coll_handle_block(t_mde_delta_h_coll* dhc, t_enxframe* fr, int nblock)
 {
     int         i;
-    t_enxblock *blk;
+    t_enxblockblk;
 
     /* add one block with one subblock as the collection's own data */
     nblock++;
     add_blocks_enxframe(fr, nblock);
-    blk = fr->block + (nblock-1);
+    blk = fr->block + (nblock - 1);
 
     /* only allocate lambda vector component blocks if they must be written out
        for backward compatibility */
@@ -696,14 +689,14 @@ void mde_delta_h_coll_handle_block(t_mde_delta_h_coll *dhc,
     {
         nblock++;
         add_blocks_enxframe(fr, nblock);
-        blk = fr->block + (nblock-1);
+        blk = fr->block + (nblock - 1);
 
-        mde_delta_h_handle_block(dhc->dh+i, blk);
+        mde_delta_h_handle_block(dhc->dh + i, blk);
     }
 }
 
 /* reset the data for a new round */
-void mde_delta_h_coll_reset(t_mde_delta_h_coll *dhc)
+void mde_delta_h_coll_reset(t_mde_delta_h_colldhc)
 {
     int i;
     for (i = 0; i < dhc->ndh; i++)
@@ -718,8 +711,7 @@ void mde_delta_h_coll_reset(t_mde_delta_h_coll *dhc)
 }
 
 /* set the energyhistory variables to save state */
-void mde_delta_h_coll_update_energyhistory(const t_mde_delta_h_coll *dhc,
-                                           energyhistory_t          *enerhist)
+void mde_delta_h_coll_update_energyhistory(const t_mde_delta_h_coll* dhc, energyhistory_t* enerhist)
 {
     if (enerhist->deltaHForeignLambdas == nullptr)
     {
@@ -727,13 +719,15 @@ void mde_delta_h_coll_update_energyhistory(const t_mde_delta_h_coll *dhc,
         enerhist->deltaHForeignLambdas->dh.resize(dhc->ndh);
     }
 
-    delta_h_history_t * const deltaH = enerhist->deltaHForeignLambdas.get();
+    delta_h_history_t* const deltaH = enerhist->deltaHForeignLambdas.get();
 
-    GMX_RELEASE_ASSERT(deltaH->dh.size() == static_cast<size_t>(dhc->ndh), "energy history number of delta_h histograms should match inputrec's number");
+    GMX_RELEASE_ASSERT(
+            deltaH->dh.size() == static_cast<size_t>(dhc->ndh),
+            "energy history number of delta_h histograms should match inputrec's number");
 
     for (int i = 0; i < dhc->ndh; i++)
     {
-        std::vector<real> &dh = deltaH->dh[i];
+        std::vector<real>dh = deltaH->dh[i];
         dh.resize(dhc->dh[i].ndh);
         std::copy(dh.begin(), dh.end(), dhc->dh[i].dh);
     }
@@ -742,14 +736,14 @@ void mde_delta_h_coll_update_energyhistory(const t_mde_delta_h_coll *dhc,
 }
 
 
-
 /* restore the variables from an energyhistory */
-void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll      *dhc,
-                                            const delta_h_history_t *deltaH)
+void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll* dhc, const delta_h_history_t* deltaH)
 {
     GMX_RELEASE_ASSERT(dhc, "Should have delta_h histograms");
     GMX_RELEASE_ASSERT(deltaH, "Should have delta_h histograms in energy history");
-    GMX_RELEASE_ASSERT(deltaH->dh.size() == static_cast<size_t>(dhc->ndh), "energy history number of delta_h histograms should match inputrec's number");
+    GMX_RELEASE_ASSERT(
+            deltaH->dh.size() == static_cast<size_t>(dhc->ndh),
+            "energy history number of delta_h histograms should match inputrec's number");
 
     for (gmx::index i = 0; i < gmx::ssize(deltaH->dh); i++)
     {