1 /* ---------------------------------------------------------------------- 2 This is the 3 4 ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗████████╗███████╗ 5 ██║ ██║██╔════╝ ██╔════╝ ██╔════╝ ██║ ██║╚══██╔══╝██╔════╝ 6 ██║ ██║██║ ███╗██║ ███╗██║ ███╗███████║ ██║ ███████╗ 7 ██║ ██║██║ ██║██║ ██║██║ ██║██╔══██║ ██║ ╚════██║ 8 ███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║ ██║ ██║ ███████║ 9 ╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝® 10 11 DEM simulation engine, released by 12 DCS Computing Gmbh, Linz, Austria 13 http://www.dcs-computing.com, office@dcs-computing.com 14 15 LIGGGHTS® is part of CFDEM®project: 16 http://www.liggghts.com | http://www.cfdem.com 17 18 Core developer and main author: 19 Christoph Kloss, christoph.kloss@dcs-computing.com 20 21 LIGGGHTS® is open-source, distributed under the terms of the GNU Public 22 License, version 2 or later. It is distributed in the hope that it will 23 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 24 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have 25 received a copy of the GNU General Public License along with LIGGGHTS®. 26 If not, see http://www.gnu.org/licenses . See also top-level README 27 and LICENSE files. 28 29 LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH, 30 the producer of the LIGGGHTS® software and the CFDEM®coupling software 31 See http://www.cfdem.com/terms-trademark-policy for details. 32 33 ------------------------------------------------------------------------- 34 Contributing author and copyright for this file: 35 This file is from LAMMPS 36 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator 37 http://lammps.sandia.gov, Sandia National Laboratories 38 Steve Plimpton, sjplimp@sandia.gov 39 40 Copyright (2003) Sandia Corporation. Under the terms of Contract 41 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains 42 certain rights in this software. This software is distributed under 43 the GNU General Public License. 44 ------------------------------------------------------------------------- */ 45 46 #ifndef LMP_MATH_SPECIAL_H 47 #define LMP_MATH_SPECIAL_H 48 49 #include <cmath> 50 51 namespace LAMMPS_NS { 52 53 namespace MathSpecial { 54 55 // x**2, use instead of pow(x,2.0) 56 square(const double & x)57 static inline double square(const double &x) { return x*x; } 58 59 // x**3, use instead of pow(x,3.0) cube(const double & x)60 static inline double cube(const double &x) { return x*x*x; } 61 62 // return -1.0 for odd n, 1.0 for even n, like pow(-1.0,n) powsign(const int n)63 static inline double powsign(const int n) { return (n & 1) ? -1.0 : 1.0; } 64 65 // optimized version of pow(x,n) with n being integer 66 // up to 10x faster than pow(x,y) 67 powint(const double & x,const int n)68 static inline double powint(const double &x, const int n) { 69 double yy,ww; 70 71 if (x == 0.0) return 0.0; 72 int nn = (n > 0) ? n : -n; 73 ww = x; 74 75 for (yy = 1.0; nn != 0; nn >>= 1, ww *=ww) 76 if (nn & 1) yy *= ww; 77 78 return (n > 0) ? yy : 1.0/yy; 79 } 80 81 // optimized version of (sin(x)/x)**n with n being a _positive_ integer 82 powsinxx(const double & x,int n)83 static inline double powsinxx(const double &x, int n) { 84 double yy,ww; 85 86 if (x == 0.0) return 1.0; 87 88 ww = sin(x)/x; 89 90 for (yy = 1.0; n != 0; n >>= 1, ww *=ww) 91 if (n & 1) yy *= ww; 92 93 return yy; 94 } 95 } 96 } 97 98 #endif 99