Extension: Matrix functions
#include "dg/matrix/matrix.h"
Loading...
Searching...
No Matches
functors.h
Go to the documentation of this file.
1#pragma once
2#include <boost/math/special_functions.hpp>
3#include "../dg/backend/config.h" // DG_DEVICE
4namespace dg {
5namespace mat {
11template < class T = double>
13{
22 T operator() ( T x) const
23 {
24 return boost::math::cyl_bessel_i(0, x);
25 }
26};
27
33template< class T = double >
34struct BesselJ
35{
36 BesselJ(unsigned n): m_n(n) {}
37
38 T operator() ( T x) const
39 {
40 return boost::math::cyl_bessel_j(m_n, x);
41 }
42 private:
43 unsigned m_n;
44};
45
51template< class T = double >
53{
54 LaguerreL(unsigned n): m_n(n) {}
55
56 T operator() ( T x) const
57 {
58 return boost::math::laguerre(m_n, x);
59 }
60 private:
61 unsigned m_n;
62};
63
64
70template < class T = double>
71struct GAMMA0
72{
73 GAMMA0( ) {}
81 T operator() ( T x) const
82 {
83 return exp(x)*boost::math::cyl_bessel_i(0, x);
84 }
85};
86
87
94template<class T>
95T phi1( T x){
96 if ( fabs( x) < 1e-16 )
97 return 1.;
98 if ( fabs(x) < 1)
99 return expm1( x)/x;
100 return (exp( x) - 1)/x;
101}
102
109template<class T>
110T phi2( T x){
111 if ( fabs( x) < 1e-16 )
112 return 1./2;
113 if ( fabs(x) < 1e-2)
114 return 1./2.+x*(1./6.+x*(1./24. + x/120.));
115 return ((exp( x) - 1)/x - 1)/x;
116}
117
124template<class T>
125T phi3( T x){
126 if ( fabs( x) < 1e-16 )
127 return 1./6.;
128 if ( fabs(x) < 1e-2)
129 return 1./6. + x*(1./24.+x*(1./120. +x/720.));
130 return (((exp( x) - 1)/x - 1)/x-1./2.)/x;
131}
138template<class T>
139T phi4( T x){
140 if ( fabs( x) < 1e-16 )
141 return 1./24.;
142 if ( fabs(x) < 1e-2)
143 return 1./24. + x*(1./120.+x*(1./720. + x/5040));
144 return ((((exp( x) - 1)/x - 1)/x-1./2.)/x-1./6.)/x;
145}
146
153template<class T = double>
155{
161 GyrolagK(unsigned n, T a = T(1)): m_n (n), m_a(a) {}
162
164 T operator()(T x) const {
165 // Factorials overflow int32 for n>12
166 static constexpr unsigned fact[] = {1, 1, 2, 6, 24, 120, 720,
167 5040, 40320, 362880, 3628800, 39916800, 479001600};
168
169 if( m_n == 0)
170 return exp(-x*m_a); // faster to evaluate than tgamma and pow ...
171 if( m_n == 1)
172 return (x*m_a)*exp( -x*m_a);
173 if( m_n == 2)
174 return 0.5*(x*m_a)*(x*m_a)*exp( -x*m_a);
175 if( m_n == 3)
176 return (x*m_a)*(x*m_a)*(x*m_a)*exp( -x*m_a)/6.0;
177 return pow(x*m_a,m_n)/fact[m_n]*exp(-x*m_a);
178 }
180 T operator()(T x, T y) const { return this->operator()(x*y); }
181
182 private:
183 unsigned m_n;
184 T m_a;
185};
186
192template<class T = double>
194{
195 DGyrolagK(unsigned n, T a = T(1)): m_n (n), m_a(a), m_kn(n,a), m_knm(n-1,a) {}
196 T DG_DEVICE operator()(T x) const {
197 if( m_n == 0)
198 return-m_a*exp(-x*m_a);
199 return m_a*(m_knm(x) - m_kn(x));
200 }
201 T DG_DEVICE operator()(T x, T y) const { return this->operator()(x*y); }
202
203 private:
204 unsigned m_n;
205 T m_a;
206 GyrolagK<T> m_kn, m_knm;
207};
208
209}//namespace mat
210}//namespace dg
#define DG_DEVICE
const double n
Definition lanczos_b.cpp:13
T phi1(T x)
Definition functors.h:95
T phi3(T x)
Definition functors.h:125
T phi4(T x)
Definition functors.h:139
T phi2(T x)
Definition functors.h:110
Functions for optimizing Contours.
with the zeroth order modified Bessel function
Definition functors.h:13
T operator()(T x) const
return with the zeroth order modified Bessel function
Definition functors.h:22
BESSELI0()
Definition functors.h:14
with the n-th order modified Bessel function
Definition functors.h:35
T operator()(T x) const
Definition functors.h:38
BesselJ(unsigned n)
Definition functors.h:36
Definition functors.h:194
DGyrolagK(unsigned n, T a=T(1))
Definition functors.h:195
T DG_DEVICE operator()(T x) const
Definition functors.h:196
T DG_DEVICE operator()(T x, T y) const
Definition functors.h:201
with the zeroth order modified Bessel function
Definition functors.h:72
GAMMA0()
Definition functors.h:73
T operator()(T x) const
return with the zeroth order modified Bessel function
Definition functors.h:81
Definition functors.h:155
DG_DEVICE T operator()(T x, T y) const
Definition functors.h:180
GyrolagK(unsigned n, T a=T(1))
Construct.
Definition functors.h:161
DG_DEVICE T operator()(T x) const
Definition functors.h:164
with the n-th order Laguerre polynomial
Definition functors.h:53
T operator()(T x) const
Definition functors.h:56
LaguerreL(unsigned n)
Definition functors.h:54