Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / mdlib / calcmu.c
index bab3ad8ad9098752b2de28e9f9ac0bd75a41d00f..618b9cf0a26e4114117134aa39930e4e4e06fb62 100644 (file)
 /*
- * 
- *                This source code is part of
- * 
- *                 G   R   O   M   A   C   S
- * 
- *          GROningen MAchine for Chemical Simulations
- * 
- *                        VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
+ * This file is part of the GROMACS molecular simulation package.
+ *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2012,2014, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * of the License, or (at your option) any later version.
- * 
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
- * 
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- * 
- * For more info, check our website at http://www.gromacs.org
- * 
- * And Hey:
- * GROwing Monsters And Cloning Shrimps
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /* This file is completely threadsafe - keep it that way! */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "typedefs.h"
-#include "network.h"
-#include "vec.h"
-#include "gmx_fatal.h"
-#include "physics.h"
-#include "main.h"
-#include "calcmu.h"
 
-void calc_mu(int start,int homenr,rvec x[],real q[],real qB[],
-            int nChargePerturbed,
-            dvec mu,dvec mu_B)
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/network.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/math/units.h"
+#include "gromacs/legacyheaders/calcmu.h"
+#include "gromacs/legacyheaders/gmx_omp_nthreads.h"
+
+void calc_mu(int start, int homenr, rvec x[], real q[], real qB[],
+             int nChargePerturbed,
+             dvec mu, dvec mu_B)
 {
-  int i,end,m;
-  
-  end   = start + homenr;  
-  
-  clear_dvec(mu);
-  for(i=start; (i<end); i++)
-    for(m=0; (m<DIM); m++)
-      mu[m] += q[i]*x[i][m];
-  
-  for(m=0; (m<DIM); m++)
-    mu[m] *= ENM2DEBYE;
-  
-  if (nChargePerturbed) {
-    clear_dvec(mu_B);
-    for(i=start; (i<end); i++)
-      for(m=0; (m<DIM); m++)
-       mu_B[m] += qB[i]*x[i][m];
-    
-    for(m=0; (m<DIM); m++)
-      mu_B[m] *= ENM2DEBYE;
-  } else {
-    copy_dvec(mu,mu_B);
-  }
+    int    i, end, m;
+    double mu_x, mu_y, mu_z;
+
+    end   = start + homenr;
+
+    mu_x = mu_y = mu_z = 0.0;
+#pragma omp parallel for reduction(+: mu_x, mu_y, mu_z) schedule(static) \
+    num_threads(gmx_omp_nthreads_get(emntDefault))
+    for (i = start; i < end; i++)
+    {
+        mu_x += q[i]*x[i][XX];
+        mu_y += q[i]*x[i][YY];
+        mu_z += q[i]*x[i][ZZ];
+    }
+    mu[XX] = mu_x;
+    mu[YY] = mu_y;
+    mu[ZZ] = mu_z;
+
+    for (m = 0; (m < DIM); m++)
+    {
+        mu[m] *= ENM2DEBYE;
+    }
+
+    if (nChargePerturbed)
+    {
+        mu_x = mu_y = mu_z = 0.0;
+#pragma omp parallel for reduction(+: mu_x, mu_y, mu_z) schedule(static) \
+        num_threads(gmx_omp_nthreads_get(emntDefault))
+        for (i = start; i < end; i++)
+        {
+            mu_x += qB[i]*x[i][XX];
+            mu_y += qB[i]*x[i][YY];
+            mu_z += qB[i]*x[i][ZZ];
+        }
+        mu_B[XX] = mu_x * ENM2DEBYE;
+        mu_B[YY] = mu_y * ENM2DEBYE;
+        mu_B[ZZ] = mu_z * ENM2DEBYE;
+    }
+    else
+    {
+        copy_dvec(mu, mu_B);
+    }
 }
 
-gmx_bool read_mu(FILE *fp,rvec mu,real *vol)
+gmx_bool read_mu(FILE *fp, rvec mu, real *vol)
 {
-  /* For backward compatibility */
-  real mmm[4];
-  
-  if (fread(mmm,(size_t)(4*sizeof(real)),1,fp) != 1)
-    return FALSE;
-    
-  copy_rvec(mmm,mu);
-  *vol = mmm[3];
-  
-  return TRUE;
-}
+    /* For backward compatibility */
+    real mmm[4];
+
+    if (fread(mmm, (size_t)(4*sizeof(real)), 1, fp) != 1)
+    {
+        return FALSE;
+    }
 
+    copy_rvec(mmm, mu);
+    *vol = mmm[3];
+
+    return TRUE;
+}