Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / mdlib / groupcoord.cpp
index 9e4ec821b0de98ee7860287e9f5e21eb09083fe0..bd8711ce77f5e85d3d0975913935adcc8a019e36 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2012,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
 
 
-
 /* Select the indices of the group's atoms which are local and store them in
  * anrs_loc[0..nr_loc]. The indices are saved in coll_ind[] for later reduction
  * in communicate_group_positions()
  */
-void
-dd_make_local_group_indices(const gmx_ga2la_t *ga2la,
-                            const int          nr,         /* IN:  Total number of atoms in the group */
-                            int                anrs[],     /* IN:  Global atom numbers of the groups atoms */
-                            int               *nr_loc,     /* OUT: Number of group atoms found locally */
-                            int               *anrs_loc[], /* OUT: Local atom numbers of the group  */
-                            int               *nalloc_loc, /* IN+OUT: Allocation size of anrs_loc */
-                            int                coll_ind[]) /* OUT (opt): Where is this position found in the collective array? */
+void dd_make_local_group_indices(const gmx_ga2la_t* ga2la,
+                                 const int nr,    /* IN:  Total number of atoms in the group */
+                                 int  anrs[],     /* IN:  Global atom numbers of the groups atoms */
+                                 int* nr_loc,     /* OUT: Number of group atoms found locally */
+                                 int* anrs_loc[], /* OUT: Local atom numbers of the group  */
+                                 int* nalloc_loc, /* IN+OUT: Allocation size of anrs_loc */
+                                 int  coll_ind[]) /* OUT (opt): Where is this position found in the collective array? */
 {
     GMX_ASSERT(ga2la, "We need a valid ga2la object");
 
@@ -69,12 +67,12 @@ dd_make_local_group_indices(const gmx_ga2la_t *ga2la,
     int localnr = 0;
     for (int i = 0; i < nr; i++)
     {
-        if (const int *ii = ga2la->findHome(anrs[i]))
+        if (const intii = ga2la->findHome(anrs[i]))
         {
             /* The atom with this index is a home atom */
             if (localnr >= *nalloc_loc) /* Check whether memory suffices */
             {
-                *nalloc_loc = over_alloc_dd(localnr+1);
+                *nalloc_loc = over_alloc_dd(localnr + 1);
                 /* We never need more memory than the number of atoms in the group */
                 *nalloc_loc = MIN(*nalloc_loc, nr);
                 srenew(*anrs_loc, *nalloc_loc);
@@ -100,13 +98,12 @@ dd_make_local_group_indices(const gmx_ga2la_t *ga2la,
 }
 
 
-static void get_shifts_group(
-        int           npbcdim,
-        const matrix  box,
-        rvec         *xcoll,     /* IN:  Collective set of positions [0..nr] */
-        int           nr,        /* IN:  Total number of atoms in the group */
-        rvec         *xcoll_old, /* IN:  Positions from the last time step [0...nr] */
-        ivec         *shifts)    /* OUT: Shifts for xcoll */
+static void get_shifts_group(int          npbcdim,
+                             const matrix box,
+                             rvec*        xcoll, /* IN:  Collective set of positions [0..nr] */
+                             int          nr,    /* IN:  Total number of atoms in the group */
+                             rvec* xcoll_old, /* IN:  Positions from the last time step [0...nr] */
+                             ivec* shifts)    /* OUT: Shifts for xcoll */
 {
     int  i, m, d;
     rvec dx;
@@ -127,9 +124,9 @@ static void get_shifts_group(
         /* If this is more than just a bit, it has changed its home pbc box */
         rvec_sub(xcoll[i], xcoll_old[i], dx);
 
-        for (m = npbcdim-1; m >= 0; m--)
+        for (m = npbcdim - 1; m >= 0; m--)
         {
-            while (dx[m] < -0.5*box[m][m])
+            while (dx[m] < -0.5 * box[m][m])
             {
                 for (d = 0; d < DIM; d++)
                 {
@@ -137,7 +134,7 @@ static void get_shifts_group(
                 }
                 shifts[i][m]++;
             }
-            while (dx[m] >= 0.5*box[m][m])
+            while (dx[m] >= 0.5 * box[m][m])
             {
                 for (d = 0; d < DIM; d++)
                 {
@@ -150,13 +147,12 @@ static void get_shifts_group(
 }
 
 
-static void shift_positions_group(
-        const matrix  box,
-        rvec          x[],     /* The positions [0..nr] */
-        ivec         *is,      /* The shifts [0..nr] */
-        int           nr)      /* The number of positions and shifts */
+static void shift_positions_group(const matrix box,
+                                  rvec         x[], /* The positions [0..nr] */
+                                  ivec*        is,  /* The shifts [0..nr] */
+                                  int          nr)           /* The number of positions and shifts */
 {
-    int      i, tx, ty, tz;
+    int i, tx, ty, tz;
 
 
     /* Loop over the group's atoms */
@@ -168,9 +164,9 @@ static void shift_positions_group(
             ty = is[i][YY];
             tz = is[i][ZZ];
 
-            x[i][XX] = x[i][XX]+tx*box[XX][XX]+ty*box[YY][XX]+tz*box[ZZ][XX];
-            x[i][YY] = x[i][YY]+ty*box[YY][YY]+tz*box[ZZ][YY];
-            x[i][ZZ] = x[i][ZZ]+tz*box[ZZ][ZZ];
+            x[i][XX] = x[i][XX] + tx * box[XX][XX] + ty * box[YY][XX] + tz * box[ZZ][XX];
+            x[i][YY] = x[i][YY] + ty * box[YY][YY] + tz * box[ZZ][YY];
+            x[i][ZZ] = x[i][ZZ] + tz * box[ZZ][ZZ];
         }
     }
     else
@@ -181,9 +177,9 @@ static void shift_positions_group(
             ty = is[i][YY];
             tz = is[i][ZZ];
 
-            x[i][XX] = x[i][XX]+tx*box[XX][XX];
-            x[i][YY] = x[i][YY]+ty*box[YY][YY];
-            x[i][ZZ] = x[i][ZZ]+tz*box[ZZ][ZZ];
+            x[i][XX] = x[i][XX] + tx * box[XX][XX];
+            x[i][YY] = x[i][YY] + ty * box[YY][YY];
+            x[i][ZZ] = x[i][ZZ] + tz * box[ZZ][ZZ];
         }
     }
 }
@@ -192,20 +188,19 @@ static void shift_positions_group(
 /* Assemble the positions of the group such that every node has all of them.
  * The atom indices are retrieved from anrs_loc[0..nr_loc]
  * Note that coll_ind[i] = i is needed in the serial case */
-extern void communicate_group_positions(
-        const t_commrec *cr,           /* Pointer to MPI communication data */
-        rvec            *xcoll,        /* Collective array of positions */
-        ivec            *shifts,       /* Collective array of shifts for xcoll (can be NULL) */
-        ivec            *extra_shifts, /* (optional) Extra shifts since last time step */
-        const gmx_bool   bNS,          /* (optional) NS step, the shifts have changed */
-        const rvec      *x_loc,        /* Local positions on this node */
-        const int        nr,           /* Total number of atoms in the group */
-        const int        nr_loc,       /* Local number of atoms in the group */
-        const int       *anrs_loc,     /* Local atom numbers */
-        const int       *coll_ind,     /* Collective index */
-        rvec            *xcoll_old,    /* (optional) Positions from the last time step,
-                                          used to make group whole */
-        const matrix     box)          /* (optional) The box */
+extern void communicate_group_positions(const t_commrec* cr, /* Pointer to MPI communication data */
+                                        rvec*            xcoll, /* Collective array of positions */
+                                        ivec* shifts, /* Collective array of shifts for xcoll (can be NULL) */
+                                        ivec* extra_shifts, /* (optional) Extra shifts since last time step */
+                                        const gmx_bool bNS, /* (optional) NS step, the shifts have changed */
+                                        const rvec* x_loc,  /* Local positions on this node */
+                                        const int   nr,     /* Total number of atoms in the group */
+                                        const int   nr_loc, /* Local number of atoms in the group */
+                                        const int*  anrs_loc, /* Local atom numbers */
+                                        const int*  coll_ind, /* Collective index */
+                                        rvec* xcoll_old,  /* (optional) Positions from the last time
+                                                             step,  used to make group whole */
+                                        const matrix box) /* (optional) The box */
 {
     int i;
 
@@ -223,7 +218,7 @@ extern void communicate_group_positions(
     if (PAR(cr))
     {
         /* Add the arrays from all nodes together */
-        gmx_sum(nr*3, xcoll[0], cr);
+        gmx_sum(nr * 3, xcoll[0], cr);
     }
     /* Now we have all the positions of the group in the xcoll array present on all
      * nodes.
@@ -318,10 +313,9 @@ extern void get_center(rvec x[], real weight[], const int nr, rvec rcenter)
     }
     else
     {
-        denom = nr;        /* Divide by the number of atoms */
-
+        denom = nr; /* Divide by the number of atoms */
     }
-    dsvmul(1.0/denom, dcenter, dcenter);
+    dsvmul(1.0 / denom, dcenter, dcenter);
 
     rcenter[XX] = dcenter[XX];
     rcenter[YY] = dcenter[YY];
@@ -331,13 +325,12 @@ extern void get_center(rvec x[], real weight[], const int nr, rvec rcenter)
 
 /* Get the center from local positions that already have the correct
  * PBC representation */
-extern void get_center_comm(
-        const t_commrec *cr,
-        rvec             x_loc[],      /* Local positions */
-        real             weight_loc[], /* Local masses or other weights */
-        int              nr_loc,       /* Local number of atoms */
-        int              nr_group,     /* Total number of atoms of the group */
-        rvec             center)       /* Weighted center */
+extern void get_center_comm(const t_commrec* cr,
+                            rvec             x_loc[],      /* Local positions */
+                            real             weight_loc[], /* Local masses or other weights */
+                            int              nr_loc,       /* Local number of atoms */
+                            int              nr_group,     /* Total number of atoms of the group */
+                            rvec             center)                   /* Weighted center */
 {
     double weight_sum, denom;
     dvec   dsumvec;
@@ -367,16 +360,15 @@ extern void get_center_comm(
 
     if (weight_loc != nullptr)
     {
-        denom = 1.0/weight_sum; /* Divide by the sum of weight to get center of mass e.g. */
+        denom = 1.0 / weight_sum; /* Divide by the sum of weight to get center of mass e.g. */
     }
     else
     {
-        denom = 1.0/nr_group;   /* Divide by the number of atoms to get the geometrical center */
-
+        denom = 1.0 / nr_group; /* Divide by the number of atoms to get the geometrical center */
     }
-    center[XX] = dsumvec[XX]*denom;
-    center[YY] = dsumvec[YY]*denom;
-    center[ZZ] = dsumvec[ZZ]*denom;
+    center[XX] = dsumvec[XX] * denom;
+    center[YY] = dsumvec[YY] * denom;
+    center[ZZ] = dsumvec[ZZ] * denom;
 }
 
 
@@ -411,7 +403,7 @@ extern void rotate_x(rvec x[], const int nr, matrix rmat)
             x[i][j] = 0;
             for (k = 0; k < 3; k++)
             {
-                x[i][j] += rmat[k][j]*x_old[k];
+                x[i][j] += rmat[k][j] * x_old[k];
             }
         }
     }