MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtendedMath.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 
27 #ifndef EXTENDEDMATH_H
28 #define EXTENDEDMATH_H
29 
30 #ifdef HIGH_PRECISION
31  typedef long double Mdouble;
32 #else
33  typedef double Mdouble;
34 #endif
35 
36 #define sqr(a) ((a)*(a))
37 #define cubic(a) ((a)*(a)*(a))
38 #define UNUSED __attribute__ ((__unused__))
39 //#define UNUSED
40 #include <algorithm>
41 //#include <cmath>
42 
43 /*
45 inline bool isnan(double x)
46 {
47  return (x != x);
48 }
49  */
50 
51 namespace constants
52 {
53  //Values from WolframAlpha
54  const Mdouble pi =3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068;
55  const Mdouble sqrt_pi =1.772453850905516027298167483341145182797549456122387128213807789852911284591032181374950656738544665;
56  const Mdouble sqr_pi =9.869604401089358618834490999876151135313699407240790626413349376220044822419205243001773403718552232;
57  const Mdouble sqrt_2 =1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573;
58  const Mdouble sqrt_3 =1.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248576;
59 }
60 
62 namespace mathsFunc
63 {
64 
66  Mdouble gamma(Mdouble gamma_in);
67 
69  Mdouble chi_squared(Mdouble x, int k);
70 
73 
75  template <typename T> int sign(T val)
76  {
77  return (T(0) < val) - (val < T(0));
78  }
79 }
80 
82 namespace besselFunc
83 {
84 
85  Mdouble chebyshev(Mdouble x, const Mdouble coef[], int N);
86 
88 
89  Mdouble I0(Mdouble x);
90 
91 }
92 
93 
94 namespace helperFunc
95 {
96 
98  class KAndDisp {
99  public:
102  };
103 
108 
111  public:
116  };
117 
123 
124 
127 
130 
133  Mdouble getMaximumVelocity(Mdouble k, Mdouble disp, Mdouble radius, Mdouble mass);
134 
135 }
136 
137 
138 
139 #include <sstream>
140 #include <iostream>
141 void getLineFromStringStream(std::istream& in, std::stringstream& out);
142 
143 #endif
Mdouble chebyshev(Mdouble x, const Mdouble coef[], int N)
Definition: ExtendedMath.cc:98
KAndDisp computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass)
Set disp and k such that is matches a given collision time tc and restitution coefficient r for a col...
Mdouble getMaximumVelocity(Mdouble k, Mdouble disp, Mdouble radius, Mdouble mass)
Calculates the maximum relative velocity allowed for a normal collision of two particles of radius r ...
return type specifically for fuctions returning k and disp at once
Definition: ExtendedMath.h:98
Mdouble I0_exp(Mdouble x)
const Mdouble sqrt_pi
Definition: ExtendedMath.h:55
int sign(T val)
This is a sign function, it returns -1 for negative numbers, 1 for positive numbers and 0 for 0...
Definition: ExtendedMath.h:75
const Mdouble pi
Definition: ExtendedMath.h:54
double Mdouble
Definition: ExtendedMath.h:33
return type specifically for fuctions returning k, disp, kt, dispt at once
Definition: ExtendedMath.h:110
const Mdouble sqrt_2
Definition: ExtendedMath.h:57
Mdouble getRestitutionCoefficient(Mdouble k, Mdouble disp, Mdouble mass)
Calculates restitution coefficient for two copies of given disp, k, effective mass.
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:37
KAndDispAndKtAndDispt computeDisptFromCollisionTimeAndRestitutionCoefficientAndTangentialRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble beta, Mdouble mass)
Set disp, k, dispt and kt such that is matches a given collision time tc and a normal andtangential r...
Mdouble I0(Mdouble x)
Mdouble chi_squared_prob(Mdouble x, int k)
This is the function which actually gives the probability back using a chi squared test...
Definition: ExtendedMath.cc:78
Mdouble getCollisionTime(Mdouble k, Mdouble disp, Mdouble mass)
Calculates collision time for two copies of a particle of given disp, k, effective mass...
const Mdouble sqrt_3
Definition: ExtendedMath.h:58
const Mdouble sqr_pi
Definition: ExtendedMath.h:56
Mdouble chi_squared(Mdouble x, int k)
This is a chi_squared function return the value x and degrees of freedom k.
Definition: ExtendedMath.cc:60