Clean up vec.h
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 23 Dec 2015 14:55:43 +0000 (16:55 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 26 Dec 2015 15:15:08 +0000 (16:15 +0100)
- Remove cos_angle_no_table() and unitv_no_table(), since they are now
  essentially identical to the normal versions.
- Replace all uses of cos_angle_no_table() with gmx_angle(), since all
  were used in a numerically unstable way.
- Replace uses of m_rveccopy() with copy_rvecn(), which does the same
  thing.
- Move some functions that are not related to operations on rvec/friends
  to other files.
- Remove #includes made unnecessary by the above changes, and add them
  to source files that previously got them transitively.
- Remove extern "C" guards from the header, since it anyways does not
  compile as C.

Change-Id: I933e7257601ee6f0e9ccf516e0bdcb1a85834a51

44 files changed:
src/gromacs/domdec/domdec_setup.cpp
src/gromacs/essentialdynamics/edsam.cpp
src/gromacs/ewald/calculate-spline-moduli.cpp
src/gromacs/ewald/ewald.cpp
src/gromacs/ewald/pme-solve.cpp
src/gromacs/fileio/pdbio.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/fileio/vmdio.cpp
src/gromacs/gmxana/gmx_analyze.cpp
src/gromacs/gmxana/gmx_bundle.cpp
src/gromacs/gmxana/gmx_confrms.cpp
src/gromacs/gmxana/gmx_densmap.cpp
src/gromacs/gmxana/gmx_editconf.cpp
src/gromacs/gmxana/gmx_filter.cpp
src/gromacs/gmxana/gmx_genion.cpp
src/gromacs/gmxana/gmx_gyrate.cpp
src/gromacs/gmxana/gmx_helixorient.cpp
src/gromacs/gmxana/gmx_order.cpp
src/gromacs/gmxana/gmx_potential.cpp
src/gromacs/gmxana/gmx_rms.cpp
src/gromacs/gmxana/gmx_rmsf.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/solvate.cpp
src/gromacs/imd/imd.cpp
src/gromacs/listed-forces/bonded.cpp
src/gromacs/math/functions.h
src/gromacs/math/vec.h
src/gromacs/mdlib/constr.cpp
src/gromacs/mdlib/genborn.h
src/gromacs/mdlib/md_support.cpp
src/gromacs/mdlib/nbnxn_atomdata.cpp
src/gromacs/mdlib/perf_est.cpp
src/gromacs/mdlib/update.cpp
src/gromacs/pbcutil/pbc.cpp
src/gromacs/pbcutil/pbc.h
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/pulling/pullutil.cpp
src/gromacs/selection/params.cpp
src/gromacs/simd/tests/simd_math.cpp
src/gromacs/swap/swapcoords.cpp
src/gromacs/trajectoryanalysis/modules/angle.cpp
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/gromacs/trajectoryanalysis/modules/surfacearea.cpp
src/programs/mdrun/runner.cpp

index 48fa0b60343cb21793c92b768b47c6855d7cf889..11e4f7504c4b944865d4368df14a1bfcfa72e36d 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/domdec/domdec_struct.h"
 #include "gromacs/gmxlib/network.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/perf_est.h"
 #include "gromacs/mdtypes/commrec.h"
index 7915a09d3b2d389fdf286a3734e0958a1f1249b1..8a458714f3fe39e3388ffa564a1f87f9ab99ea96 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/gmxlib/nrnb.h"
 #include "gromacs/linearalgebra/nrjac.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/mdlib/groupcoord.h"
@@ -2704,7 +2705,7 @@ void init_edsam(const gmx_mtop_t *mtop,
         {
             /* Remove PBC, make molecule(s) subject to ED whole. */
             snew(x_pbc, mtop->natoms);
-            m_rveccopy(mtop->natoms, x, x_pbc);
+            copy_rvecn(x, x_pbc, 0, mtop->natoms);
             do_pbc_first_mtop(NULL, ir->ePBC, box, mtop, x_pbc);
         }
         /* Reset pointer to first ED data set which contains the actual ED data */
index 6ec9fd94043878cff55e95812f70da8ca97229ca..89767dc67fa09262b2efc26bbab4b412805254c3 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <algorithm>
 
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
index 37591e6c4db285d26a6daed1adc71bb542fa75f2..1f508cddc9fd98c144cc2edcfe60a2721064a43a 100644 (file)
@@ -58,6 +58,8 @@
 
 #include "gromacs/math/functions.h"
 #include "gromacs/math/gmxcomplex.h"
+#include "gromacs/math/units.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/mdtypes/commrec.h"
@@ -90,6 +92,14 @@ void init_ewald_tab(struct gmx_ewald_tab_t **et, const t_inputrec *ir, FILE *fp)
     (*et)->tab_qxyz = NULL;
 }
 
+//! Calculates wave vectors.
+static void calc_lll(const rvec box, rvec lll)
+{
+    lll[XX] = 2.0*M_PI/box[XX];
+    lll[YY] = 2.0*M_PI/box[YY];
+    lll[ZZ] = 2.0*M_PI/box[ZZ];
+}
+
 //! Make tables for the structure factor parts
 static void tabulateStructureFactors(int natom, rvec x[], int kmax, cvec **eir, rvec lll)
 {
index 168dd97fcbf5ff10e141358791d5ac8b0816e57e..5eed4c9274fa32aaee7d222b320c141ac9459ba4 100644 (file)
@@ -42,6 +42,8 @@
 #include <cmath>
 
 #include "gromacs/fft/parallel_3dfft.h"
+#include "gromacs/math/units.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/simd/simd.h"
 #include "gromacs/simd/simd_math.h"
index e99a9a6f44fedd520c4bf2e0cf8959c6875b054b..3719cc60b43bb79f797986a2ab80ce0723656811 100644 (file)
@@ -130,7 +130,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box)
 
     if (norm2(box[YY])*norm2(box[ZZ]) != 0)
     {
-        alpha = RAD2DEG*std::acos(cos_angle_no_table(box[YY], box[ZZ]));
+        alpha = RAD2DEG*gmx_angle(box[YY], box[ZZ]);
     }
     else
     {
@@ -138,7 +138,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box)
     }
     if (norm2(box[XX])*norm2(box[ZZ]) != 0)
     {
-        beta  = RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[ZZ]));
+        beta  = RAD2DEG*gmx_angle(box[XX], box[ZZ]);
     }
     else
     {
@@ -146,7 +146,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box)
     }
     if (norm2(box[XX])*norm2(box[YY]) != 0)
     {
-        gamma = RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[YY]));
+        gamma = RAD2DEG*gmx_angle(box[XX], box[YY]);
     }
     else
     {
index 79bb915431df9b8368c6b69971ce5d8c473039fd..71bdf23a189957bf86a58b0f4fd1947f84e6e4b0 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/fileio/filetypes.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/gmxfio-xdr.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdtypes/inputrec.h"
 #include "gromacs/mdtypes/md_enums.h"
index a722f9b61c4ba0aff2b8f2529c3472482eb365d9..34c79ed04acee2376b34deb829a32e74bed03b13 100644 (file)
 
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
 #include "gromacs/trajectory/trajectoryframe.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/fatalerror.h"
index fc1c9471169a0e54b790f1c9ba9a02881688922f..4d52829b7a042a840ccdde1d134219363a611fd3 100644 (file)
@@ -51,6 +51,7 @@
 #include "gromacs/gmxana/gstat.h"
 #include "gromacs/linearalgebra/matrix.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/statistics/statistics.h"
 #include "gromacs/utility/arraysize.h"
index 41f08cac259eab4bb07ed723c805f2f6ce749356..17c8167279ecf26f49f53b2a779b1a5db06ee6d5 100644 (file)
@@ -389,13 +389,13 @@ int gmx_bundle(int argc, char *argv[])
             {
                 rvec_sub(bun.end[0][i], bun.end[2][i], va);
                 rvec_sub(bun.end[2][i], bun.end[1][i], vb);
-                unitv_no_table(va, va);
-                unitv_no_table(vb, vb);
+                unitv(va, va);
+                unitv(vb, vb);
                 fprintf(fkink, " %6g", RAD2DEG*acos(iprod(va, vb)));
                 cprod(va, vb, vc);
                 copy_rvec(bun.mid[i], vr);
                 vr[ZZ] = 0;
-                unitv_no_table(vr, vr);
+                unitv(vr, vr);
                 fprintf(fkinkr, " %6g", RAD2DEG*std::asin(iprod(vc, vr)));
                 vl[XX] = vr[YY];
                 vl[YY] = -vr[XX];
index 7b4ed714dfcd052499715004061bdb34bff08be2..c1cd543517f35d901ba2983414cc277b56360097 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/math/do_fit.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
index 1fba1d92c92b2681036bf7f8458c4b075f8a7b86..6d376c47fe9064e30ad854804cbc79cbbf548f35 100644 (file)
@@ -46,6 +46,7 @@
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/gstat.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/index.h"
index 1a35b9af23ebd3de8309a7bb94c14beea6cb9027..87fa1bc7004d8142a5f1021c3885c67a9cd6be3f 100644 (file)
@@ -937,11 +937,11 @@ int gmx_editconf(int argc, char *argv[])
                norm(box[XX]), norm(box[YY]), norm(box[ZZ]));
         printf("    box angles  :%7.2f%7.2f%7.2f (degrees)\n",
                norm2(box[ZZ]) == 0 ? 0 :
-               RAD2DEG*std::acos(cos_angle_no_table(box[YY], box[ZZ])),
+               RAD2DEG*gmx_angle(box[YY], box[ZZ]),
                norm2(box[ZZ]) == 0 ? 0 :
-               RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[ZZ])),
+               RAD2DEG*gmx_angle(box[XX], box[ZZ]),
                norm2(box[YY]) == 0 ? 0 :
-               RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[YY])));
+               RAD2DEG*gmx_angle(box[XX], box[YY]));
         printf("    box volume  :%7.2f               (nm^3)\n", det(box));
     }
 
@@ -1191,11 +1191,11 @@ int gmx_editconf(int argc, char *argv[])
                norm(box[XX]), norm(box[YY]), norm(box[ZZ]));
         printf("new box angles  :%7.2f%7.2f%7.2f (degrees)\n",
                norm2(box[ZZ]) == 0 ? 0 :
-               RAD2DEG*std::acos(cos_angle_no_table(box[YY], box[ZZ])),
+               RAD2DEG*gmx_angle(box[YY], box[ZZ]),
                norm2(box[ZZ]) == 0 ? 0 :
-               RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[ZZ])),
+               RAD2DEG*gmx_angle(box[XX], box[ZZ]),
                norm2(box[YY]) == 0 ? 0 :
-               RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[YY])));
+               RAD2DEG*gmx_angle(box[XX], box[YY]));
         printf("new box volume  :%7.2f               (nm^3)\n", det(box));
     }
 
index 6e3937a26098e584d5f000da423aa46dff3fe515..ed353329e0cba7ee39cc2e033f95387cbeb1d856 100644 (file)
@@ -45,6 +45,7 @@
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/princ.h"
 #include "gromacs/math/do_fit.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
index 627884344b90d7d7b0dfcfa3d594c5bb041de81d..febbc3555045274d7a80306aafd6a5b62335c5f3 100644 (file)
@@ -44,6 +44,7 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/gmxana/gmx_ana.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/force.h"
index 1d0a666a7c65fcb27b8a04ff70f3087b180c2586..23fccd29519f034cfe9cb93ebe7a2d4babb60b0b 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/gmxana/gstat.h"
 #include "gromacs/gmxana/princ.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
index 29bd388bdc37aff2f8611cde63af0bbb6d95f5d6..7f40ea3697004000585111b8b456a05fb48bd1aa 100644 (file)
@@ -44,6 +44,7 @@
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/gstat.h"
 #include "gromacs/math/do_fit.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
index 2f98290c981f73077692c732d8d238c68ceb3238..c3c08ffbf2dd552b06c0453bc77cdd36c806bb8f 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/gstat.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
index 5e2a980acfd4b0a9993b9871d36ec3bf597dafe8..e8d61e5db56bf1d895ddf3ed4e009496eea03e21 100644 (file)
@@ -47,6 +47,7 @@
 #include "gromacs/gmxana/gmx_ana.h"
 #include "gromacs/gmxana/princ.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
index 72fc7cd2a81b2a58eb8ca7f500cd624f1fdd5751..80b637ba70c5e5acfa4f9351faa6b8eeff59240d 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/gmxana/princ.h"
 #include "gromacs/math/do_fit.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/ifunc.h"
index d14be7a9c4bfb43c4b53b729087ef0f5db355b98..a7b9eb188f9ddaa38af44cfde1dc0daf609d1c4a 100644 (file)
@@ -50,6 +50,7 @@
 #include "gromacs/linearalgebra/eigensolver.h"
 #include "gromacs/math/do_fit.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/topology/index.h"
index 41bed8c30e5ea655e07b0a15ab1cb9e84acec1a7..4cdd35a256087df07759bcf3ff0a1f2f1f035157 100644 (file)
@@ -68,6 +68,7 @@
 #include "gromacs/gmxpreprocess/vsite_parm.h"
 #include "gromacs/imd/imd.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/calc_verletbuf.h"
 #include "gromacs/mdlib/compute_io.h"
index b1d3649ca0a92a8a0457ba299ba4a371b7f2eae1..23a3c88a9169bcdfa7ed600a55e7b4c4605a6291 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/gmxlib/conformation-utilities.h"
 #include "gromacs/gmxpreprocess/read-conformation.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/selection/nbsearch.h"
index e5e822898379e8e62ece32c7daa2258e4c29bc5d..674ce951faf2a91cca602853d5965bcc1d18db27 100644 (file)
@@ -68,6 +68,7 @@
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/gmxlib/network.h"
 #include "gromacs/imd/imdsocket.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/groupcoord.h"
 #include "gromacs/mdlib/mdrun.h"
index b41e0d473d58fc3b78dc297be1e05b7c30cf943d..a77612d43593bfa8c6610d7adbebba0e8a9c1e21 100644 (file)
@@ -54,6 +54,7 @@
 #include <algorithm>
 
 #include "gromacs/math/functions.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/ishift.h"
index 7ef4a5be33e903b86039bbac254a09c7af4f5404..67d6d96948270e916e959febc7ce3da53088a64c 100644 (file)
@@ -46,6 +46,8 @@
 #include <cmath>
 #include <cstdint>
 
+#include "gromacs/utility/real.h"
+
 namespace gmx
 {
 
@@ -409,6 +411,18 @@ power12(T x)
     return square(power6(x));
 }
 
+/*! \brief Maclaurin series for sinh(x)/x.
+ *
+ * Used for NH chains and MTTK pressure control.
+ * Here, we compute it to 10th order, which might be an overkill.
+ * 8th is probably enough, but it's not very much more expensive.
+ */
+static inline real series_sinhx(real x)
+{
+    real x2 = x*x;
+    return (1 + (x2/6.0)*(1 + (x2/20.0)*(1 + (x2/42.0)*(1 + (x2/72.0)*(1 + (x2/110.0))))));
+}
+
 } // namespace gmx
 
 
index 76940bf1f2af3f613bad21a95a584c6cb4556401..2b289fc8f72a431103be434573e591a26e8f6c9d 100644 (file)
    void dprod(rvec a,rvec b,rvec c)                 c = a x b (cross product)
    void dprod(rvec a,rvec b,rvec c)                 c = a * b (direct product)
    real cos_angle(rvec a,rvec b)
-   real cos_angle_no_table(rvec a,rvec b)
    real distance2(rvec v1, rvec v2)                 = | v2 - v1 |^2
    void unitv(rvec src,rvec dest)                   dest = src / |src|
-   void unitv_no_table(rvec src,rvec dest)          dest = src / |src|
 
    matrix (3x3) operations:
     ! indicates that dest should not be the same as a, b or src
    real trace(matrix m)                             = trace(m)
  */
 
-#include <math.h>
+#include <cmath>
 
 #include "gromacs/math/functions.h"
-#include "gromacs/math/units.h"
-#include "gromacs/math/utilities.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
-#ifdef __cplusplus
-extern "C" {
-#elif 0
-} /* avoid screwing up indentation */
-#endif
-
-/* Maclaurin series for sinh(x)/x, useful for NH chains and MTTK pressure control
-   Here, we compute it to 10th order, which might be overkill, 8th is probably enough,
-   but it's not very much more expensive. */
-
-static gmx_inline real series_sinhx(real x)
-{
-    real x2 = x*x;
-    return (1 + (x2/6.0)*(1 + (x2/20.0)*(1 + (x2/42.0)*(1 + (x2/72.0)*(1 + (x2/110.0))))));
-}
-
 static gmx_inline void rvec_add(const rvec a, const rvec b, rvec c)
 {
     real x, y, z;
@@ -377,7 +357,7 @@ static gmx_inline double dnorm2(const dvec a)
  * don't need 1/dnorm(), otherwise use dnorm2()*dinvnorm(). */
 static gmx_inline double dnorm(const dvec a)
 {
-    return sqrt(diprod(a, a));
+    return std::sqrt(diprod(a, a));
 }
 
 /* WARNING:
@@ -385,7 +365,7 @@ static gmx_inline double dnorm(const dvec a)
  * don't need 1/norm(), otherwise use norm2()*invnorm(). */
 static gmx_inline real norm(const rvec a)
 {
-    return sqrt(iprod(a, a));
+    return std::sqrt(iprod(a, a));
 }
 
 static gmx_inline real invnorm(const rvec a)
@@ -447,44 +427,6 @@ cos_angle(const rvec a, const rvec b)
     return cosval;
 }
 
-/* WARNING:
- * Do _not_ use these routines to calculate the angle between two vectors
- * as acos(cos_angle(u,v)). While it might seem obvious, the acos function
- * is very flat close to -1 and 1, which will lead to accuracy-loss.
- * Instead, use the new gmx_angle() function directly.
- */
-static gmx_inline real
-cos_angle_no_table(const rvec a, const rvec b)
-{
-    /* This version does not need the invsqrt lookup table */
-    real   cosval;
-    int    m;
-    double aa, bb, ip, ipa, ipb; /* For accuracy these must be double! */
-
-    ip = ipa = ipb = 0.0;
-    for (m = 0; (m < DIM); m++) /* 18 */
-    {
-        aa   = a[m];
-        bb   = b[m];
-        ip  += aa*bb;
-        ipa += aa*aa;
-        ipb += bb*bb;
-    }
-    cosval = ip/sqrt(ipa*ipb);  /* 12 */
-    /* 30 TOTAL */
-    if (cosval > 1.0)
-    {
-        return 1.0;
-    }
-    if (cosval < -1.0)
-    {
-        return -1.0;
-    }
-
-    return cosval;
-}
-
-
 static gmx_inline void cprod(const rvec a, const rvec b, rvec c)
 {
     c[XX] = a[YY]*b[ZZ]-a[ZZ]*b[YY];
@@ -523,11 +465,11 @@ static gmx_inline void mmul_ur0(gmx_cxx_const matrix a, gmx_cxx_const matrix b,
     dest[XX][YY] = 0.0;
     dest[XX][ZZ] = 0.0;
     dest[YY][XX] = a[YY][XX]*b[XX][XX]+a[YY][YY]*b[YY][XX];
-    dest[YY][YY] =                    a[YY][YY]*b[YY][YY];
+    dest[YY][YY] =                     a[YY][YY]*b[YY][YY];
     dest[YY][ZZ] = 0.0;
     dest[ZZ][XX] = a[ZZ][XX]*b[XX][XX]+a[ZZ][YY]*b[YY][XX]+a[ZZ][ZZ]*b[ZZ][XX];
-    dest[ZZ][YY] =                    a[ZZ][YY]*b[YY][YY]+a[ZZ][ZZ]*b[ZZ][YY];
-    dest[ZZ][ZZ] =                                        a[ZZ][ZZ]*b[ZZ][ZZ];
+    dest[ZZ][YY] =                     a[ZZ][YY]*b[YY][YY]+a[ZZ][ZZ]*b[ZZ][YY];
+    dest[ZZ][ZZ] =                                         a[ZZ][ZZ]*b[ZZ][ZZ];
 }
 
 static gmx_inline void mmul(gmx_cxx_const matrix a, gmx_cxx_const matrix b, matrix dest)
@@ -667,56 +609,9 @@ static gmx_inline void unitv(const rvec src, rvec dest)
     dest[ZZ] = linv*src[ZZ];
 }
 
-static gmx_inline void unitv_no_table(const rvec src, rvec dest)
-{
-    real linv;
-
-    linv     = 1.0/sqrt(norm2(src));
-    dest[XX] = linv*src[XX];
-    dest[YY] = linv*src[YY];
-    dest[ZZ] = linv*src[ZZ];
-}
-
-static void calc_lll(const rvec box, rvec lll)
-{
-    lll[XX] = 2.0*M_PI/box[XX];
-    lll[YY] = 2.0*M_PI/box[YY];
-    lll[ZZ] = 2.0*M_PI/box[ZZ];
-}
-
 static gmx_inline real trace(gmx_cxx_const matrix m)
 {
     return (m[XX][XX]+m[YY][YY]+m[ZZ][ZZ]);
 }
 
-/* Operations on multidimensional rvecs, used e.g. in edsam.c */
-static gmx_inline void m_rveccopy(int dim, gmx_cxx_const rvec *a, rvec *b)
-{
-    /* b = a */
-    int i;
-
-    for (i = 0; i < dim; i++)
-    {
-        copy_rvec(a[i], b[i]);
-    }
-}
-
-/*computer matrix vectors from base vectors and angles */
-static gmx_inline void matrix_convert(matrix box, const rvec vec, rvec angle)
-{
-    svmul(DEG2RAD, angle, angle);
-    box[XX][XX] = vec[XX];
-    box[YY][XX] = vec[YY]*cos(angle[ZZ]);
-    box[YY][YY] = vec[YY]*sin(angle[ZZ]);
-    box[ZZ][XX] = vec[ZZ]*cos(angle[YY]);
-    box[ZZ][YY] = vec[ZZ]
-        *(cos(angle[XX])-cos(angle[YY])*cos(angle[ZZ]))/sin(angle[ZZ]);
-    box[ZZ][ZZ] = sqrt(gmx::square(vec[ZZ])
-                       -box[ZZ][XX]*box[ZZ][XX]-box[ZZ][YY]*box[ZZ][YY]);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
 #endif
index e6c1957147b5a5029a1522a22c17660b6ba5af3b..910298faff17f85601c84a399a0e9fec7c943bd6 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/gmxlib/nrnb.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
 #include "gromacs/mdlib/mdrun.h"
index b68f0db51558aefadfeb7c1afdd277000e96b1f0..a631788a0df603e0dd7ddb0a63d2174c816b0730 100644 (file)
@@ -37,6 +37,7 @@
 #ifndef GMX_MDLIB_GENBORN_H
 #define GMX_MDLIB_GENBORN_H
 
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vectypes.h"
 
 struct gmx_genborn_t;
index a21972ab61fb432c159629e88ca027aa619563e3..bc9db7ea511110eae808b0cf6a927f378d477ded 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "md_support.h"
 
+#include <climits>
+
 #include <algorithm>
 
 #include "gromacs/domdec/domdec.h"
index d81955d903f66c721571d5c95deff370b1ab33f0..33c9331f385002b0f2d2e0f4fe1e61529a3bbbb6 100644 (file)
@@ -50,6 +50,7 @@
 #include "thread_mpi/atomic.h"
 
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
 #include "gromacs/mdlib/nb_verlet.h"
index 33ac1dc6c717992a700c41a13e3c035b26c8cd91..2cd1f85bcb9da2fc64c9dac503b9a6b722210e2d 100644 (file)
@@ -41,6 +41,7 @@
 #include <cmath>
 
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/nbnxn_consts.h"
 #include "gromacs/mdlib/nbnxn_search.h"
index b58b1930dd621c475a6556341be40602d964f1e0..3d6e1f2c940d67034f3162f1bbb5ea292d67ab79 100644 (file)
@@ -281,7 +281,7 @@ static void do_update_vv_vel(int start, int nrend, double dt,
     {
         g        = 0.25*dt*veta*alpha;
         mv1      = exp(-g);
-        mv2      = series_sinhx(g);
+        mv2      = gmx::series_sinhx(g);
     }
     else
     {
@@ -329,7 +329,7 @@ static void do_update_vv_pos(int start, int nrend, double dt,
     {
         g        = 0.5*dt*veta;
         mr1      = exp(g);
-        mr2      = series_sinhx(g);
+        mr2      = gmx::series_sinhx(g);
     }
     else
     {
index 07d3e51ab903c76eac4cd3ba5a375f080d8d11de..40d72e2f4ea93806b8808c8c841e1b9852c3fb70 100644 (file)
@@ -50,6 +50,7 @@
 #include <algorithm>
 
 #include "gromacs/math/functions.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/math/vecdump.h"
@@ -165,6 +166,20 @@ const char *check_box(int ePBC, const matrix box)
     return ptr;
 }
 
+void matrix_convert(matrix box, const rvec vec, const rvec angleInDegrees)
+{
+    rvec angle;
+    svmul(DEG2RAD, angleInDegrees, angle);
+    box[XX][XX] = vec[XX];
+    box[YY][XX] = vec[YY]*cos(angle[ZZ]);
+    box[YY][YY] = vec[YY]*sin(angle[ZZ]);
+    box[ZZ][XX] = vec[ZZ]*cos(angle[YY]);
+    box[ZZ][YY] = vec[ZZ]
+        *(cos(angle[XX])-cos(angle[YY])*cos(angle[ZZ]))/sin(angle[ZZ]);
+    box[ZZ][ZZ] = sqrt(gmx::square(vec[ZZ])
+                       -box[ZZ][XX]*box[ZZ][XX]-box[ZZ][YY]*box[ZZ][YY]);
+}
+
 real max_cutoff2(int ePBC, const matrix box)
 {
     real       min_hv2, min_ss;
index 4608a8c60b48bdd5b0b6c47e959d5470baa93342..2811c5b33a5ca431a698f6713010005a62881010 100644 (file)
@@ -156,6 +156,9 @@ void dump_pbc(FILE *fp, t_pbc *pbc);
  */
 const char *check_box(int ePBC, const matrix box);
 
+/*! \brief Creates box matrix from edge lengths and angles. */
+void matrix_convert(matrix box, const rvec vec, const rvec angleInDegrees);
+
 /*! \brief Compute the maximum cutoff for the box
 
  * Returns the square of the maximum cut-off allowed for the box,
index 5d7f2dfe9793216c1afe6ec81bb2bd791557f16c..cb9d5cc5cfa9b120f61458c62e32322d2994c8e4 100644 (file)
@@ -55,6 +55,7 @@
 #include "gromacs/gmxlib/network.h"
 #include "gromacs/linearalgebra/nrjac.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/groupcoord.h"
 #include "gromacs/mdlib/mdrun.h"
@@ -3725,7 +3726,7 @@ extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[
         /* Remove pbc, make molecule whole.
          * When ir->bContinuation=TRUE this has already been done, but ok. */
         snew(x_pbc, mtop->natoms);
-        m_rveccopy(mtop->natoms, x, x_pbc);
+        copy_rvecn(x, x_pbc, 0, mtop->natoms);
         do_pbc_first_mtop(NULL, ir->ePBC, box, mtop, x_pbc);
         /* All molecules will be whole now, but not necessarily in the home box.
          * Additionally, if a rotation group consists of more than one molecule
index e5d5a006ad4934c9c4d26e6998d9fec33ad338f1..ea25d3568b012876cd948b850ccc39c1190fe186 100644 (file)
@@ -46,6 +46,7 @@
 #include "gromacs/fileio/confio.h"
 #include "gromacs/gmxlib/network.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdtypes/commrec.h"
 #include "gromacs/mdtypes/md_enums.h"
index bf387200f1dab898b3bd8896aacf1e60059d240a..1884a63821bb7e5b96091cc23a39946727c787f6 100644 (file)
@@ -44,6 +44,7 @@
 #include <algorithm>
 #include <string>
 
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/selection/position.h"
 #include "gromacs/utility/cstringutil.h"
index bc1a69f810c6e8dd4c2c8dfcd5356e307ed016c0..bb0a3573f554247cc7202509800c459dc04b4c47 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <vector>
 
+#include "gromacs/math/utilities.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/simd/simd.h"
 
index 09f97d3cc4de81a9646140e6864c0872faf79417..c2c0753e6af54480e3e1a876890f13ecf8c97584 100644 (file)
@@ -1275,7 +1275,7 @@ static void init_swapstate(
 
         /* Remove pbc, make molecule whole. */
         snew(x_pbc, mtop->natoms);
-        m_rveccopy(mtop->natoms, x, x_pbc);
+        copy_rvecn(x, x_pbc, 0, mtop->natoms);
 
         /* This can only make individual molecules whole, not multimers */
         do_pbc_mtop(NULL, ePBC, box, mtop, x_pbc);
index af1653fb1d73e49a73b10f80eb8eafe4d6ff33a5..46edbc9a7c0ae03ead8e71f352dd8ae933b292bd 100644 (file)
@@ -51,6 +51,7 @@
 #include "gromacs/analysisdata/modules/average.h"
 #include "gromacs/analysisdata/modules/histogram.h"
 #include "gromacs/analysisdata/modules/plot.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/filenameoption.h"
index a9031039cdeab3dfc710915d3afadae0cc1cb7c2..74f133e5d7d44dec1a29ce06be4da1959d156e9c 100644 (file)
@@ -49,6 +49,7 @@
 #include "gromacs/analysisdata/modules/average.h"
 #include "gromacs/analysisdata/modules/plot.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/filenameoption.h"
index 2b6e48f5ada2df1f2ce0a05343683552eefd8ae7..00aa76f12f5a800dd5b0358cb719314bb7d206b6 100644 (file)
@@ -47,6 +47,7 @@
 #include <vector>
 
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/selection/nbsearch.h"
index 1aebe4a4fca7fb8b3c43673665246afee8fb2ec3..7dd714c512c17974a0bc8383ba48afad2af93168 100644 (file)
@@ -70,6 +70,7 @@
 #include "gromacs/listed-forces/orires.h"
 #include "gromacs/math/calculate-ewald-splitting-coefficient.h"
 #include "gromacs/math/functions.h"
+#include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/calc_verletbuf.h"
 #include "gromacs/mdlib/constr.h"