/** * \file * \author Thomas Fischer * \date 2010-01-13 * \brief Definition of math helper functions. * * \copyright * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org) * Distributed under a Modified BSD License. * See accompanying file LICENSE.txt or * http://www.opengeosys.org/project/license * */ #ifndef MATHTOOLS_H_ #define MATHTOOLS_H_ #include #ifdef _OPENMP #include #endif namespace MathLib { /** * standard inner product in R^N * \param v0 array of type T representing the vector * \param v1 array of type T representing the vector * */ template inline T scalarProduct(T const * const v0, T const * const v1) { T res (v0[0] * v1[0]); #ifdef _OPENMP OPENMP_LOOP_TYPE k; #pragma omp parallel for reduction (+:res) for (k = 1; k inline double scalarProduct(double const * const v0, double const * const v1) { double res (v0[0] * v1[0]); for (std::size_t k(1); k < 3; k++) res += v0[k] * v1[k]; return res; } template inline T scalarProduct(T const * const v0, T const * const v1, unsigned n) { T res (v0[0] * v1[0]); #ifdef _OPENMP OPENMP_LOOP_TYPE k; #pragma omp parallel for reduction (+:res) #ifdef WIN32 #pragma warning ( push ) #pragma warning ( disable: 4018 ) #endif for (k = 1; k(v,v); } /** * Let \f$p_0, p_1, p_2 \in R^3\f$. The function getAngle * computes the angle between the edges \f$(p_0,p_1)\f$ and \f$(p_1,p_2)\f$ * @param p0 start point of edge 0 * @param p1 end point of edge 0 and start point of edge 1 * @param p2 end point of edge 1 * @return the angle between the edges */ double getAngle (const double p0[3], const double p1[3], const double p2[3]); /** * Template metaprogramming, compile-time version of pow() for integral * exponents. */ #ifdef WIN32 template struct POW { static T const value = B * POW::value; }; template struct POW { static T const value = 1; }; #else // WIN32 template inline constexpr T pow(T const x, unsigned const y) { return (y == 0) ? 1 : x * pow(x, y - 1); } #endif // WIN32 } // namespace #endif /* MATHTOOLS_H_ */