Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
functors.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
5#ifndef M_PI
6#define M_PI 3.14159265358979323846
7#endif
8#include <vector>
9#include <functional>
10#include <thrust/random/linear_congruential_engine.h>
11#include <thrust/random/normal_distribution.h>
12#include <thrust/random/uniform_real_distribution.h>
13#include "blas1.h"
14#include "topology/grid.h"
15#include "topology/evaluation.h"
16#include "topology/functions.h"
20namespace dg
21{
22
25//Everything that is quite basic and simple
26
27
29template <class T = double>
30struct PLUS
31{
37 PLUS( T value): x_(value){}
39 T operator()( T x)const{ return x + x_;}
40 private:
41 T x_;
42};
43
45template< class T = double >
46struct EXP
47{
48 DG_DEVICE T operator() ( T x) const
49 {
50 return exp(x);
51 }
52};
53
55template < class T = double>
56struct LN
57{
58 DG_DEVICE T operator() (const T& x) const
59 {
60 return log(x);
61 }
62
63};
64
66template < class T = double>
67struct SQRT
68{
70 {
71 return sqrt(x);
72 }
73};
74
76struct Square
77{
78 template<class T>
79 DG_DEVICE T operator()( T x) const{ return x*x;}
80};
81
83template < class T = double>
84struct InvSqrt
85{
87 {
88 return 1./sqrt(x);
89 }
90};
91
93template <class T = double>
94struct INVERT
95{
96 DG_DEVICE T operator()( T x)const{ return 1./x;}
97};
98
100template <class T = double>
101struct ABS
102{
103 DG_DEVICE T operator()(T x)const{ return fabs(x);}
104};
105
114template <class T = double>
115struct Sign
116{
117 DG_DEVICE T operator()(T x)const{ return (T(0) < x) - (x < T(0));}
118};
119
121template <class T = double>
122struct AbsMax
123{
124 DG_DEVICE T operator() ( T x, T y) const
125 {
126 T absx = x>0 ? x : -x;
127 T absy = y>0 ? y : -y;
128 return absx > absy ? absx : absy;
129 }
130};
131
133template <class T = double>
134struct AbsMin
135{
136 DG_DEVICE T operator() (T x, T y) const
137 {
138 T absx = x<0 ? -x : x;
139 T absy = y<0 ? -y : y;
140 return absx < absy ? absx : absy;
141 }
142};
143
152template <class T = double>
154{
155 DG_DEVICE T operator()( T x)const{
156 if (x >= 0.0) return x;
157 return 0.0;
158 }
159};
160
167template <class T= double>
168struct MOD
169{
175 MOD( T m): m_m(m){}
176
178 T operator()( T x)const{
179 return (fmod(x,m_m) < 0 ) ? (m_m + fmod(x,m_m)) : fmod(x,m_m);
180 }
181 private:
182 T m_m;
183
184};
185
198template <class T>
200{
201#ifdef __CUDACC__
202 DG_DEVICE bool operator()(T x){ return !isfinite(x);}
203#else
204 bool operator()( T x){ return !std::isfinite(x);}
205#endif
206};
207
224template <class T>
226{
227#ifdef __CUDACC__
228 DG_DEVICE bool operator()(T x){
229 if( !isfinite(x))
230 return true;
231 if( x > 1e100 || x < -1e100)
232 return true;
233 return false;
234 }
235#else
236 bool operator()( T x){
237 if( !std::isfinite(x))
238 return true;
239 if( x > 1e100 || x < -1e100)
240 return true;
241 return false;
242 }
243#endif
244};
245
257struct MinMod
258{
260#ifdef __CUDACC__
261 template < class T>
262 DG_DEVICE T operator()( T x1, T x2) const
263 {
264 if( x1 > 0 && x2 > 0)
265 return min(x1,x2);
266 else if( x1 < 0 && x2 < 0)
267 return max(x1,x2);
268 return 0.;
269 }
270#else
271 template < class T>
272 T operator()( T x1, T x2) const
273 {
274 if( x1 > 0 && x2 > 0)
275 return std::min(x1,x2);
276 else if( x1 < 0 && x2 < 0)
277 return std::max(x1,x2);
278 return 0.;
279 }
280#endif
282 template<class T>
283 DG_DEVICE T operator() ( T x1, T x2, T x3)const
284 {
285 return this-> operator()( this-> operator()( x1, x2), x3);
286 }
287};
288
290template<class T>
292{
294 UniformRealDistribution( T a, T b): m_rng(), m_dist(a,b){}
295
297 template< class ...Ts>
299 {
300 return m_dist(m_rng); //what happens on GPU? Does every thread get the same?
301 }
302 private:
303 thrust::minstd_rand m_rng;
304 thrust::uniform_real_distribution<T> m_dist;
305};
306
308template<class T>
310
320{
321 template<class T>
322 DG_DEVICE T operator()( T x1, T x2) const
323 {
324 if( x1*x2 <= 0)
325 return 0.;
326 return 2.*x1*x2/(x1+x2);
327 }
328};
329
336struct Upwind
337{
338 template<class T>
339 DG_DEVICE T operator()( T velocity, T backward, T forward) const{
340 if( velocity >= 0)
341 return backward;
342 else
343 return forward;
344 }
345};
346
354{
355 template<class T>
356 DG_DEVICE T operator()( T velocity, T backward, T forward)const{
357 return velocity*m_up(velocity, backward, forward);
358 }
359 private:
360 Upwind m_up;
361};
362
372template<class Limiter>
374{
376 SlopeLimiter( Limiter l ) : m_l( l){}
377 template<class T>
378 DG_DEVICE T operator()( T v, T gm, T g0, T gp, T hm, T hp ) const{
379 if( v >= 0)
380 return +hm*m_l( g0, gm);
381 else
382 return -hp*m_l( gp, g0);
383 }
384 private:
385 Limiter m_l;
386};
387
397template<class Limiter>
399{
401 SlopeLimiterProduct( Limiter l ) : m_s( l){}
402 template<class T>
403 DG_DEVICE T operator()( T v, T gm, T g0, T gp, T hm, T hp ) const{
404 return v*m_s(v,gm,g0,gp,hm,hp);
405 }
406 private:
408};
410
411
417
420//
421
429struct Iris
430{
431 Iris( double psi_min, double psi_max ):
432 m_psimin(psi_min), m_psimax(psi_max) { }
434 double operator()(double psi)const
435 {
436 if( psi > m_psimax) return 0.;
437 if( psi < m_psimin) return 0.;
438 return 1.;
439 }
440 private:
441 double m_psimin, m_psimax;
442};
450struct Pupil
451{
452 Pupil( double psimax):
453 psimax_(psimax) { }
455 double operator()(double psi)const
456 {
457 if( psi > psimax_) return 0.;
458 return 1.;
459 }
460 private:
461 double psimax_;
462};
471{
472 PsiPupil(double psimax):
473 psimax_(psimax){ }
475 double operator()(double psi)const
476 {
477 if( psi > psimax_) return psimax_;
478 return psi;
479 }
480 private:
481 double psimax_;
482};
492{
493
502 Heaviside( double xb, int sign = +1):
503 m_xb(xb), m_s(sign){ }
504
506 double operator()(double x)const
507 {
508 if( (x < m_xb && m_s == 1) || (x > m_xb && m_s == -1)) return 0.;
509 return 1.;
510 }
511 private:
512 double m_xb;
513 int m_s;
514};
515
516
521{
522 Distance( double x0, double y0): m_x0(x0), m_y0(y0){}
524 double operator()(double x, double y){
525 return sqrt( (x-m_x0)*(x-m_x0) + (y-m_y0)*(y-m_y0));
526 }
527 private:
528 double m_x0, m_y0;
529};
536struct Line{
537 Line(double x0, double y0, double x1, double y1) :
538 m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1){}
539 double operator()(double x){
540 return m_y1*(x-m_x0)/(m_x1-m_x0) + m_y0*(x-m_x1)/(m_x0-m_x1);
541 }
542 private:
543 double m_x0, m_y0, m_x1, m_y1;
544};
545
551{
558 LinearX( double a, double b):a_(a), b_(b){}
560 double operator()(double x)const{ return a_*x+b_;}
562 double operator()( double x, double)const{ return this->operator()(x);}
564 double operator()( double x, double, double)const{ return this->operator()(x);}
565 private:
566 double a_,b_;
567};
573{
580 LinearY( double a, double b):a_(a), b_(b){}
582 double operator()( double, double y, double)const { return a_*y+b_;}
584 double operator()( double, double y)const{ return a_*y+b_;}
585 private:
586 double a_,b_;
587};
593{
600 LinearZ( double a, double b):a_(a), b_(b){}
602 double operator()( double, double, double z)const{ return a_*z+b_;}
603 private:
604 double a_,b_;
605};
613{
623 Gaussian( double x0, double y0, double sigma_x, double sigma_y, double amp)
624 : m_x0(x0), m_y0(y0), m_sigma_x(sigma_x), m_sigma_y(sigma_y), m_amp(amp){
625 assert( m_sigma_x != 0 && "sigma_x must not be 0 in Gaussian");
626 assert( m_sigma_y != 0 && "sigma_y must not be 0 in Gaussian");
627 }
640 double operator()(double x, double y) const
641 {
642 return m_amp*
643 exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x +
644 (y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
645 }
657 double operator()(double x, double y, double) const
658 {
659 return this->operator()(x,y);
660 }
661 private:
662 double m_x0, m_y0, m_sigma_x, m_sigma_y, m_amp;
663
664};
665
677struct Cauchy
678{
688 Cauchy( double x0, double y0, double sigma_x, double sigma_y, double amp): x0_(x0), y0_(y0), sigmaX_(sigma_x), sigmaY_(sigma_y), amp_(amp){
689 assert( sigma_x != 0 && "sigma_x must be !=0 in Cauchy");
690 assert( sigma_y != 0 && "sigma_y must be !=0 in Cauchy");
691 }
693 double operator()(double x, double y )const{
694 double xbar = (x-x0_)/sigmaX_;
695 double ybar = (y-y0_)/sigmaY_;
696 if( xbar*xbar + ybar*ybar < 1.)
697 return amp_*exp( 1. + 1./( xbar*xbar + ybar*ybar -1.) );
698 return 0.;
699 }
700 bool inside( double x, double y)const
701 {
702 double xbar = (x-x0_)/sigmaX_;
703 double ybar = (y-y0_)/sigmaY_;
704 if( xbar*xbar + ybar*ybar < 1.)
705 return true;
706 return false;
707 }
708
709 double dx( double x, double y )const{
710 double xbar = (x-x0_)/sigmaX_;
711 double ybar = (y-y0_)/sigmaY_;
712 double temp = sigmaX_*(xbar*xbar + ybar*ybar - 1.);
713 return -2.*(x-x0_)*this->operator()(x,y)/temp/temp;
714 }
715 double dxx( double x, double y)const{
716 double temp = sigmaY_*sigmaY_*(x-x0_)*(x-x0_) + sigmaX_*sigmaX_*((y-y0_)*(y-y0_) - sigmaY_*sigmaY_);
717 double bracket = sigmaX_*sigmaX_*((y-y0_)*(y-y0_)-sigmaY_*sigmaY_)*sigmaX_*sigmaX_*((y-y0_)*(y-y0_)-sigmaY_*sigmaY_)
718 -3.*sigmaY_*sigmaY_*sigmaY_*sigmaY_*(x-x0_)*(x-x0_)*(x-x0_)*(x-x0_)
719 -2.*sigmaY_*sigmaY_*sigmaX_*sigmaX_*(x-x0_)*(x-x0_)*(y-y0_)*(y-y0_);
720 return -2.*sigmaX_*sigmaX_*sigmaY_*sigmaY_*sigmaY_*sigmaY_*this->operator()(x,y)*bracket/temp/temp/temp/temp;
721 }
722 double dy( double x, double y)const{
723 double xbar = (x-x0_)/sigmaX_;
724 double ybar = (y-y0_)/sigmaY_;
725 double temp = sigmaY_*(xbar*xbar + ybar*ybar - 1.);
726 return -2.*(y-y0_)*this->operator()(x,y)/temp/temp;
727 }
728 double dyy( double x, double y)const{
729 double temp = sigmaX_*sigmaX_*(y-y0_)*(y-y0_) + sigmaY_*sigmaY_*((x-x0_)*(x-x0_) - sigmaX_*sigmaX_);
730 double bracket = sigmaY_*sigmaY_*((x-x0_)*(x-x0_)-sigmaX_*sigmaX_)*sigmaY_*sigmaY_*((x-x0_)*(x-x0_)-sigmaX_*sigmaX_)
731 -3.*sigmaX_*sigmaX_*sigmaX_*sigmaX_*(y-y0_)*(y-y0_)*(y-y0_)*(y-y0_)
732 -2.*sigmaX_*sigmaX_*sigmaY_*sigmaY_*(y-y0_)*(y-y0_)*(x-x0_)*(x-x0_);
733 return -2.*sigmaY_*sigmaY_*sigmaX_*sigmaX_*sigmaX_*sigmaX_*this->operator()(x,y)*bracket/temp/temp/temp/temp;
734 }
735 double dxy( double x, double y )const{
736 double xbar = (x-x0_)/sigmaX_;
737 double ybar = (y-y0_)/sigmaY_;
738 double temp = (xbar*xbar + ybar*ybar - 1.);
739 return 8.*xbar*ybar*this->operator()(x,y)/temp/temp/temp/sigmaX_/sigmaY_
740 + 4.*xbar*ybar*this->operator()(x,y)/temp/temp/temp/temp/sigmaX_/sigmaY_
741;
742 }
743 private:
744 double x0_, y0_, sigmaX_, sigmaY_, amp_;
745};
746
759{
767 CauchyX( double x0, double sigma_x, double amp): x0_(x0), sigmaX_(sigma_x), amp_(amp){
768 assert( sigma_x != 0 && "sigma_x must be !=0 in Cauchy");
769 }
771 double operator()(double x, double )const{
772 double xbar = (x-x0_)/sigmaX_;
773 if( xbar*xbar < 1.)
774 return amp_*exp( 1. + 1./( xbar*xbar -1.) );
775 return 0.;
776 }
777 bool inside( double x, double)const
778 {
779 double xbar = (x-x0_)/sigmaX_;
780 if( xbar*xbar < 1.)
781 return true;
782 return false;
783 }
784 private:
785 double x0_, sigmaX_, amp_;
786};
787
795{
807 Gaussian3d( double x0, double y0, double z0, double sigma_x, double sigma_y, double sigma_z, double amp)
808 : m_x0(x0), m_y0(y0), m_z0(z0), m_sigma_x(sigma_x), m_sigma_y(sigma_y), m_sigma_z(sigma_z), m_amp(amp){
809 assert( m_sigma_x != 0 && "sigma_x must be !=0 in Gaussian3d");
810 assert( m_sigma_y != 0 && "sigma_y must be !=0 in Gaussian3d");
811 assert( m_sigma_z != 0 && "sigma_z must be !=0 in Gaussian3d");
812 }
825 double operator()(double x, double y) const
826 {
827 return m_amp*
828 exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x +
829 (y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
830 }
844 double operator()(double x, double y, double z) const
845 {
846 return m_amp*
847 exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x +
848 (z-m_z0)*(z-m_z0)/2./m_sigma_z/m_sigma_z +
849 (y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
850 }
851 private:
852 double m_x0, m_y0, m_z0, m_sigma_x, m_sigma_y, m_sigma_z, m_amp;
853
854};
862{
870 GaussianX( double x0, double sigma_x, double amp)
871 :m_x0(x0), m_sigma_x(sigma_x), m_amp(amp){
872 assert( m_sigma_x != 0 && "sigma_x must be !=0 in GaussianX");
873 }
875 double operator()(double x) const
876 {
877 return m_amp* exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x ));
878 }
880 double operator()(double x, double) const
881 {
882 return this->operator()(x);
883 }
885 double operator()(double x, double, double) const
886 {
887 return this->operator()(x);
888 }
889 private:
890 double m_x0, m_sigma_x, m_amp;
891
892};
900{
908 GaussianY( double y0, double sigma_y, double amp)
909 : m_y0(y0), m_sigma_y(sigma_y), m_amp(amp){
910 assert( m_sigma_y != 0 && "sigma_x must be !=0 in GaussianY");
911 }
923 double operator()(double, double y) const
924 {
925 return m_amp*exp( -((y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
926 }
927 private:
928 double m_y0, m_sigma_y, m_amp;
929
930};
938{
946 GaussianZ( double z0, double sigma_z, double amp)
947 : m_z0(z0), m_sigma_z(sigma_z), m_amp(amp){
948 assert( m_sigma_z != 0 && "sigma_z must be !=0 in GaussianZ");
949 }
961 double operator()( double z) const
962 {
963 return m_amp*exp( -((z-m_z0)*(z-m_z0)/2./m_sigma_z/m_sigma_z) );
964 }
976 double operator()(double, double, double z) const
977 {
978 return m_amp*exp( -((z-m_z0)*(z-m_z0)/2./m_sigma_z/m_sigma_z) );
979 }
980 private:
981 double m_z0, m_sigma_z, m_amp;
982
983};
989{
996 IslandXY( double lambda, double eps):lambda_(lambda), eps_(eps){
997 assert( lambda != 0 && "Lambda parameter in IslandXY must not be zero!");
998 }
1006 DG_DEVICE
1007 double operator()( double x, double y)const{ return lambda_*log(cosh(x/lambda_)+eps_*cos(y/lambda_));}
1008 private:
1009 double lambda_,eps_;
1010};
1015{
1024 SinXSinY( double amp, double bamp, double kx, double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1033 DG_DEVICE
1034 double operator()( double x, double y)const{ return bamp_+amp_*sin(x*kx_)*sin(y*ky_);}
1035 private:
1036 double amp_,bamp_,kx_,ky_;
1037};
1043{
1052 CosXCosY( double amp, double bamp, double kx, double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1061 DG_DEVICE
1062 double operator()( double x, double y)const{ return bamp_+amp_*cos(x*kx_)*cos(y*ky_);}
1063 private:
1064 double amp_,bamp_,kx_,ky_;
1065};
1071{
1080 SinXCosY( double amp, double bamp, double kx, double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1089 DG_DEVICE
1090 double operator()( double x, double y)const{ return bamp_+amp_*sin(x*kx_)*cos(y*ky_);}
1091 private:
1092 double amp_,bamp_,kx_,ky_;
1093};
1098struct SinX
1099{
1107 SinX( double amp, double bamp, double kx):amp_(amp), bamp_(bamp),kx_(kx){}
1108 DG_DEVICE
1109 double operator()( double x)const{ return bamp_+amp_*sin(x*kx_);}
1110 DG_DEVICE
1111 double operator()( double x, double)const{ return this->operator()(x);}
1112 DG_DEVICE
1113 double operator()( double x, double, double)const{ return this->operator()(x);}
1114 private:
1115 double amp_,bamp_,kx_;
1116};
1121struct SinY
1122{
1130 SinY( double amp, double bamp, double ky):amp_(amp), bamp_(bamp),ky_(ky){}
1131 DG_DEVICE
1132 double operator()( double, double y)const{ return bamp_+amp_*sin(y*ky_);}
1133 private:
1134 double amp_,bamp_,ky_;
1135};
1140struct CosY
1141{
1149 CosY( double amp, double bamp, double ky):amp_(amp), bamp_(bamp),ky_(ky){}
1150 DG_DEVICE
1151 double operator()( double, double y)const{ return bamp_+amp_*cos(y*ky_);}
1152 private:
1153 double amp_,bamp_,ky_;
1154};
1160{
1167 InvCoshXsq( double amp, double kx):m_amp(amp), m_kx(kx){}
1168 DG_DEVICE
1169 double operator()( double x)const{ return m_amp/cosh(x*m_kx)/cosh(x*m_kx);}
1170 DG_DEVICE
1171 double operator()( double x, double)const{ return this->operator()(x);}
1172 DG_DEVICE
1173 double operator()( double x, double, double)const{ return this->operator()(x);}
1174 private:
1175 double m_amp, m_kx;
1176};
1182{
1190 SinProfX( double amp, double bamp, double kx):m_amp(amp), m_bamp(bamp),m_kx(kx){}
1191 DG_DEVICE
1192 double operator()( double x)const{ return m_bamp+m_amp*(1.-sin(x*m_kx));}
1193 DG_DEVICE
1194 double operator()( double x, double)const{ return this->operator()(x);}
1195 DG_DEVICE
1196 double operator()( double x, double, double)const{ return this->operator()(x);}
1197 private:
1198 double m_amp, m_bamp, m_kx;
1199};
1205{
1213 ExpProfX( double amp, double bamp, double ln):m_amp(amp),m_bamp(bamp),m_ln(ln){
1214 assert( ln!=0 && "ln parameter must be != 0 in ExpProfX!");
1215 }
1216 DG_DEVICE
1217 double operator()( double x)const{ return m_bamp+m_amp*exp(-x/m_ln);}
1218 DG_DEVICE
1219 double operator()( double x, double)const{ return this->operator()(x);}
1220 DG_DEVICE
1221 double operator()( double x, double, double)const{ return this->operator()(x);}
1222 private:
1223 double m_amp, m_bamp, m_ln;
1224};
1225
1226
1239{
1240 GaussianDamping( double psimax, double alpha):
1241 m_psimax(psimax), m_alpha(alpha) {
1242 assert( alpha!= 0 && "Damping width in GaussianDamping must not be zero");
1243 }
1244 DG_DEVICE
1245 double operator()(double psi)const
1246 {
1247 if( psi > m_psimax + 4.*m_alpha) return 0.;
1248 if( psi < m_psimax) return 1.;
1249 return exp( -( psi-m_psimax)*( psi-m_psimax)/2./m_alpha/m_alpha);
1250 }
1251 private:
1252 double m_psimax, m_alpha;
1253};
1271 TanhProfX(double xb, double width, int sign =1,double bgamp = 0.,
1272 double profamp = 1.) :
1273 xb_(xb),w_(width), s_(sign),bga_(bgamp),profa_(profamp) {
1274 assert( width != 0&& "Width in TanhProfX must not be zero!");
1275 }
1276 DG_DEVICE
1277 double operator() (double x)const
1278 {
1279 return profa_*0.5*(1.+s_*tanh((x-xb_)/w_))+bga_;
1280 }
1281 DG_DEVICE
1282 double operator()( double x, double)const{ return this->operator()(x);}
1283 DG_DEVICE
1284 double operator()( double x, double, double)const{ return this->operator()(x);}
1285 private:
1286 double xb_;
1287 double w_;
1288 int s_;
1289 double bga_;
1290 double profa_;
1291};
1292
1314 PolynomialHeaviside(double xb, double a, int sign = +1) :
1315 x0(xb), a(a), m_s(sign){
1316 assert( a!=0 && "PolynomialHeaviside width must not be zero");
1317 }
1318 DG_DEVICE
1319 double operator() (double x)const
1320 {
1321 if( m_s == -1) x = 2*x0-x; //mirror
1322 if ( x < x0-a) return 0;
1323 if ( x > x0+a) return 1;
1324 return ((16.*a*a*a - 29.*a*a*(x - x0)
1325 + 20.*a*(x - x0)*(x - x0)
1326 - 5.*(x - x0)*(x-x0)*(x-x0))
1327 *(a + x - x0)*(a + x - x0)
1328 *(a + x - x0)*(a + x - x0))/(32.*a*a*a * a*a*a*a);
1329 }
1330 DG_DEVICE
1331 double operator()( double x, double)const{ return this->operator()(x);}
1332 DG_DEVICE
1333 double operator()( double x, double, double)const{ return this->operator()(x);}
1334 private:
1335 double x0, a;
1336 int m_s;
1337};
1338
1366 PolynomialRectangle(double xl, double al, double xr, double ar) :
1367 m_hl( xl, al, +1), m_hr( xr, ar, -1) {
1368 assert( xl < xr && "left boundary must be left of right boundary");
1369 }
1370 DG_DEVICE
1371 double operator() (double x)const
1372 {
1373 return m_hl(x)*m_hr(x);
1374 }
1375 DG_DEVICE
1376 double operator()( double x, double)const{ return this->operator()(x);}
1377 DG_DEVICE
1378 double operator()( double x, double, double)const{ return this->operator()(x);}
1379 private:
1380 PolynomialHeaviside m_hl, m_hr;
1381};
1382
1404 IPolynomialHeaviside(double xb, double a, int sign = +1) :
1405 x0(xb), a(a), m_s(sign){
1406 assert( a!=0 && "IPolynomialHeaviside width must not be zero");
1407 }
1408 DG_DEVICE
1409 double operator() (double x)const
1410 {
1411 if( m_s == -1) x = 2*x0-x; //mirror
1412 double result;
1413 if ( x < x0-a) result = x0;
1414 else if ( x > x0+a) result = x;
1415 else
1416 result = x0 + ((35.* a*a*a - 47.* a*a*(x - x0) + 25.*a*(x - x0)*(x-x0)
1417 - 5.*(x - x0)*(x-x0)*(x-x0))
1418 *(a+x-x0)*(a+x-x0)*(a+x-x0)*(a+x-x0)*(a+x-x0))
1419 /(256.*a*a*a * a*a*a*a);
1420 if ( m_s == +1) return result;
1421 return 2*x0 - result;
1422
1423 }
1424 DG_DEVICE
1425 double operator()( double x, double)const{ return this->operator()(x);}
1426 DG_DEVICE
1427 double operator()( double x, double, double)const{ return this->operator()(x);}
1428 private:
1429 double x0, a;
1430 int m_s;
1431};
1432
1456 DPolynomialHeaviside(double xb, double a, int = +1) :
1457 x0(xb), a(a){
1458 assert( a!=0 && "DPolynomialHeaviside width must not be zero");
1459 }
1460 DG_DEVICE
1461 double operator() (double x)const
1462 {
1463 if ( (x < x0-a) || (x > x0+a)) return 0;
1464 return (35.*(a+x-x0)*(a+x-x0)*(a+x-x0)*(a-x+x0)*(a-x+x0)*(a-x+x0))
1465 /(32.*a*a*a * a*a*a*a);
1466 }
1467 DG_DEVICE
1468 double operator()( double x, double)const{ return this->operator()(x);}
1469 DG_DEVICE
1470 double operator()( double x, double, double)const{ return this->operator()(x);}
1471 private:
1472 double x0, a;
1473};
1474
1489{
1503 ExponentialFilter( double alpha, double eta_c, unsigned order, unsigned n):
1504 m_alpha(alpha), m_etac(eta_c), m_s(order), m_n(n) {}
1505 double operator()( unsigned i) const
1506 {
1507 double eta = (double)i/(double)(m_n-1);
1508 if( m_n == 1) eta = 0.;
1509 if( eta < m_etac)
1510 return 1.;
1511 if( eta <= 1.)
1512 return exp( -m_alpha*pow( (eta-m_etac)/(1.-m_etac), 2*m_s));
1513 return 0;
1514 }
1515 private:
1516 double m_alpha, m_etac;
1517 unsigned m_s, m_n;
1518};
1519
1534struct Lamb
1535{
1544 Lamb( double x0, double y0, double R, double U):R_(R), U_(U), x0_(x0), y0_(y0)
1545 {
1546 gamma_ = 3.83170597020751231561;
1547 lambda_ = gamma_/R;
1548#ifdef _MSC_VER
1549 j_ = _j0(gamma_);
1550#else
1551 j_ = j0( gamma_);
1552#endif
1553 //std::cout << r_ <<u_<<x0_<<y0_<<lambda_<<gamma_<<j_<<std::endl;
1554 }
1563 DG_DEVICE
1564 double operator() (double x, double y)const
1565 {
1566 double radius = sqrt( (x-x0_)*(x-x0_) + (y-y0_)*(y-y0_));
1567 double theta = atan2( (y-y0_),(x-x0_));
1568
1569 if( radius <= R_)
1570#ifdef _MSC_VER
1571 return 2.*lambda_*U_*_j1(lambda_*radius)/j_*cos( theta);
1572#else
1573 return 2.*lambda_*U_*j1( lambda_*radius)/j_*cos( theta);
1574#endif
1575 return 0;
1576 }
1584 double enstrophy( ) const { return M_PI*U_*U_*gamma_*gamma_;}
1585
1592 double energy() const { return 2.*M_PI*R_*R_*U_*U_;}
1593 private:
1594 double R_, U_, x0_, y0_, lambda_, gamma_, j_;
1595};
1596
1619{
1630 Vortex( double x0, double y0, unsigned state,
1631 double R, double u_dipole, double kz = 0):
1632 x0_(x0), y0_(y0), s_(state), R_(R), u_d( u_dipole), kz_(kz){
1633 g_[0] = 3.831896621;
1634 g_[1] = -3.832353624;
1635 g_[2] = 7.016;
1636 b_[0] = 0.03827327723;
1637 b_[1] = 0.07071067810 ;
1638 b_[2] = 0.07071067810 ;
1639 }
1656 DG_DEVICE
1657 double operator()( double x, double y)const
1658 {
1659 double r = sqrt( (x-x0_)*(x-x0_)+(y-y0_)*(y-y0_));
1660 double theta = atan2( y-y0_, x-x0_);
1661 double beta = b_[s_];
1662 double norm = 1.2965125;
1663
1664 if( r/R_<=1.)
1665 return u_d*(
1666 r *( 1 +beta*beta/g_[s_]/g_[s_] )
1667#ifdef _MSC_VER
1668 - R_* beta*beta/g_[s_]/g_[s_] *_j1(g_[s_]*r/R_)/_j1(g_[s_])
1669#else
1670 - R_ * beta*beta/g_[s_]/g_[s_] * j1(g_[s_]*r/R_)/ j1(g_[s_])
1671#endif
1672 )*cos(theta)/norm;
1673 return u_d * R_* bessk1(beta*r/R_)/bessk1(beta)*cos(theta)/norm;
1674 // TODO Can these be replaced by std::cyl_bessel_k? Not sure what to do on device though
1675 }
1693 DG_DEVICE
1694 double operator()( double x, double y, double z)const
1695 {
1696 return this->operator()(x,y)*cos(kz_*z);
1697 }
1698 private:
1699 // Returns the modified Bessel function K1(x) for positive real x.
1700 DG_DEVICE
1701 double bessk1(double x)const
1702 {
1703 double y,ans;
1704 if (x <= 2.0)
1705 {
1706 y=x*x/4.0;
1707 ans = (log(x/2.0)*bessi1(x))+(1.0/x)*(1.0+y*(0.15443144 +
1708 y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1 +
1709 y*(-0.110404e-2+y*(-0.4686e-4)))))));
1710 }
1711 else
1712 {
1713 y=2.0/x;
1714 ans = (exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +
1715 y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2 +
1716 y*(0.325614e-2+y*(-0.68245e-3)))))));
1717 }
1718 return ans;
1719 }
1720 //Returns the modified Bessel function I1(x) for any real x.
1721 DG_DEVICE
1722 double bessi1(double x) const
1723 {
1724 double ax,ans;
1725 double y;
1726 if ((ax=fabs(x)) < 3.75)
1727 {
1728 y=x/3.75;
1729 y*=y;
1730 ans = ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +
1731 y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
1732 }
1733 else
1734 {
1735 y=3.75/ax;
1736 ans = 0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -
1737 y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+
1738 y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
1739 ans *= (exp(ax)/sqrt(ax));
1740 }
1741 return x < 0.0 ? -ans : ans;
1742 }
1743 double x0_, y0_;
1744 unsigned s_;
1745 double R_, b_[3], u_d;
1746 double g_[3];
1747 double kz_;
1748};
1749
1768struct BathRZ{
1780 BathRZ( unsigned N_kR, unsigned N_kZ, double R_min, double Z_min, double gamma, double L_E, double amp) :
1781 N_kR_(N_kR), N_kZ_(N_kZ),
1782 R_min_(R_min), Z_min_(Z_min),
1783 gamma_(gamma), L_E_(L_E) , amp_(amp),
1784 kvec( N_kR_*N_kZ_, 0), sqEkvec(kvec), unif1(kvec), unif2(kvec),
1785 normal1(kvec), normal2(kvec), alpha(kvec), theta(kvec)
1786 {
1787 double N_kR2=(double)(N_kR_*N_kR_);
1788 double N_kZ2=(double)(N_kZ_*N_kZ_);
1789 double N_k= sqrt(N_kR2+N_kZ2);
1790
1791 norm_=sqrt(2./(double)N_kR_/(double)N_kZ_);
1792 double tpi=2.*M_PI, tpi2=tpi*tpi;
1793 double k0= tpi*L_E_/N_k;
1794 double N_kRh = N_kR_/2.;
1795 double N_kZh = N_kZ_/2.;
1796
1797 thrust::minstd_rand generator;
1798 thrust::normal_distribution<double> ndistribution( 0.0, 1.0); // ( mean, stddev)
1799 thrust::uniform_real_distribution<double> udistribution(0.0,tpi); //between [0 and 2pi)
1800 for (unsigned j=1;j<=N_kZ_;j++)
1801 {
1802 double kZ2=tpi2*(j-N_kZh)*(j-N_kZh)/(N_kZ2);
1803 for (unsigned i=1;i<=N_kR_;i++)
1804 {
1805 double kR2=tpi2*(i-N_kRh)*(i-N_kRh)/(N_kR2);
1806 int z=(j-1)*(N_kR_)+(i-1);
1807 kvec[z]= sqrt(kR2 + kZ2); //radial k number
1808 sqEkvec[z]=pow(kvec[z]*4.*k0/(kvec[z]+k0)/(kvec[z]+k0),gamma_/2.); //Energie in k space with max at 1.
1809 unif1[z]=cos(udistribution(generator));
1810 unif2[z]=sin(udistribution(generator));
1811 normal1[z]=ndistribution(generator);
1812 normal2[z]=ndistribution(generator);
1813 alpha[z]=sqrt(normal1[z]*normal1[z]+normal2[z]*normal2[z]);
1814 theta[z]=atan2(normal2[z],normal1[z]);
1815 }
1816 }
1817
1818 }
1842 double operator()(double R, double Z)const
1843 {
1844 double f, kappa, RR, ZZ;
1845 RR=R-R_min_;
1846 ZZ=Z-Z_min_;
1847 f=0.;
1848 for (unsigned j=0;j<N_kZ_;j++)
1849 {
1850 for (unsigned i=0;i<N_kR_;i++)
1851 {
1852 int z=j*N_kR_+i;
1853 kappa= RR*unif1[z]+ZZ*unif2[z];
1854 f+= sqEkvec[z]*alpha[z]*cos(kvec[z]*kappa+theta[z]);
1855 }
1856 }
1857 return amp_*norm_*f;
1858 }
1883 double operator()(double R, double Z, double)const {
1884 double f, kappa;
1885 double RR, ZZ;
1886 RR=R-R_min_;
1887 ZZ=Z-Z_min_;
1888 f=0;
1889 for (unsigned j=0;j<N_kZ_;j++)
1890 {
1891 for (unsigned i=0;i<N_kR_;i++)
1892 {
1893 int z=(j)*(N_kR_)+(i);
1894 kappa= RR*unif1[z]+ZZ*unif2[z];
1895 f+= sqEkvec[z]*alpha[z]*cos(kvec[z]*kappa+theta[z]);
1896 }
1897 }
1898 return amp_*norm_*f;
1899 }
1900 private:
1901 unsigned N_kR_,N_kZ_;
1902 double R_min_, Z_min_;
1903 double gamma_, L_E_;
1904 double amp_;
1905 double norm_;
1906 std::vector<double> kvec;
1907 std::vector<double> sqEkvec;
1908 std::vector<double> unif1, unif2, normal1,normal2,alpha,theta;
1909};
1910
1912namespace detail
1913{
1914inline double horner( const double * c, unsigned M, double x)
1915{
1916 double b = c[M-1];
1917 for( unsigned i=0; i<M-1; i++)
1918 b = c[M-2-i] + b*x;
1919 return b;
1920}
1921
1922} // namespace detail
1924
1931{
1933 Horner1d(): m_c( 1, 1), m_M(1), m_prev( {0,1}){}
1934
1940 Horner1d( const std::vector<double>& c): m_c(c), m_M(c.size()), m_prev( {1e300,1e300}){
1941 if( 0 == m_M )
1942 {
1943 // Make safe for zero coefficients
1944 m_c.resize(1, 0.);
1945 m_M = 1;
1946 }
1947 }
1948 double operator()( double x) const
1949 {
1950 if( m_prev[0] == x)
1951 return m_prev[1];
1952 m_prev[1] = detail::horner( &m_c[0], m_M, x);
1953 m_prev[0] = x;
1954 return m_prev[1];
1955 }
1956 private:
1957 std::vector<double> m_c;
1958 unsigned m_M;
1959 mutable std::array<double,2> m_prev;
1960};
1961
1968{
1970 Horner2d(): m_c( 1, 1), m_cx( 1,1), m_M(1), m_N(1), m_prev( {0,0,1}){}
1971
1979 Horner2d( const std::vector<double>& c, unsigned M, unsigned N): m_c(c), m_cx( M), m_M(M), m_N(N), m_prev( {1e300,1e300,1e300}){
1980 if( 0 == M || 0 == N)
1981 {
1982 // Make safe for zero coefficients
1983 m_c.resize(1, 0.);
1984 m_M = m_N = 1;
1985 m_cx.resize(1, 0.);
1986 }
1987 }
1988 double operator()( double x, double y) const
1989 {
1990 // Optimization rationale: Horner is typically repeatedly evaluated at
1991 // the same point (as it typically happens through the
1992 // dg::geo::polynomial::Psip classes in connection with magnetic field
1993 // quantities) or with constant y and varying x (such as when
1994 // dg::evaluate is called on Horner2d). In those cases significant
1995 // computation can be saved by storing the result of the previous call.
1996 if( m_prev[1] == y && m_prev[0] == x)
1997 return m_prev[2];
1998 if( m_prev[1] != y )
1999 for( unsigned i=0; i<m_M; i++)
2000 m_cx[i] = detail::horner( &m_c[i*m_N], m_N, y);
2001 m_prev[2] = detail::horner( &m_cx[0], m_M, x);
2002 m_prev[0] = x, m_prev[1] = y;
2003 return m_prev[2];
2004 }
2005 private:
2006 std::vector<double> m_c;
2007 mutable std::vector<double> m_cx;
2008 unsigned m_M, m_N;
2009 mutable std::array<double,3> m_prev;
2010};
2011
2016template <class container = thrust::host_vector<double> >
2018{
2024 Histogram(const dg::Grid1d& g1d, const std::vector<double>& in) :
2025 g1d_(g1d),
2026 in_(in),
2027 binwidth_(g1d_.h()),
2028 count_(dg::evaluate(dg::zero,g1d_))
2029 {
2030 for (unsigned j=0;j<in_.size();j++)
2031 {
2032 unsigned bin =floor( (in_[j]-g1d_.x0())/binwidth_ );
2033 bin = std::max(bin,(unsigned) 0);
2034 bin = std::min(bin,(unsigned)(g1d_.size()-1));
2035 count_[bin ]+=1.;
2036 }
2037 //Normalize
2038 unsigned Ampmax = (unsigned)thrust::reduce( count_.begin(), count_.end(),0., thrust::maximum<double>() );
2039 dg::blas1::scal(count_,1./Ampmax);
2040
2041 }
2042
2048 double binwidth() {return binwidth_;}
2056 double operator()(double x)const
2057 {
2058 unsigned bin = floor((x-g1d_.x0())/binwidth_+0.5);
2059 bin = std::max(bin,(unsigned) 0);
2060 bin = std::min(bin,(unsigned)(g1d_.size()-1));
2061 return count_[bin];
2062 }
2063
2064 private:
2065 dg::Grid1d g1d_;
2066 const std::vector<double> in_;
2067 double binwidth_;
2068 container count_;
2069};
2070
2075template <class container = thrust::host_vector<double> >
2077{
2084 Histogram2D(const dg::Grid2d& g2d, const std::vector<double>& inx,const std::vector<double>& iny) :
2085 g2d_(g2d),
2086 inx_(inx),
2087 iny_(iny),
2088 binwidthx_(g2d_.hx()),
2089 binwidthy_(g2d_.hy()),
2090 count_(dg::evaluate(dg::zero,g2d_))
2091 {
2092
2093 for (unsigned j=0;j<iny_.size();j++)
2094 {
2095 unsigned biny =floor((iny_[j]-g2d_.y0())/binwidthy_) ;
2096 biny = std::max(biny,(unsigned) 0);
2097 biny = std::min(biny,(unsigned)(g2d_.Ny()-1));
2098
2099 unsigned binx =floor((inx_[j]-g2d_.x0())/binwidthx_) ;
2100 binx = std::max(binx,(unsigned) 0);
2101 binx = std::min(binx,(unsigned)(g2d_.Nx()-1));
2102 count_[biny*g2d_.Nx()+binx ]+=1.;
2103
2104 }
2105 //Normalize
2106 unsigned Ampmax = (unsigned)thrust::reduce( count_.begin(), count_.end(),0.,thrust::maximum<double>() );
2107 dg::blas1::scal(count_, 1./Ampmax);
2108
2109 }
2110
2119 double operator()(double x, double y)const
2120 {
2121 unsigned binx = floor((x-g2d_.x0())/binwidthx_+0.5) ;
2122 binx = std::max(binx,(unsigned) 0);
2123 binx = std::min(binx,(unsigned)(g2d_.Nx()-1));
2124 unsigned biny = floor((y-g2d_.y0())/binwidthy_+0.5) ;
2125 biny = std::max(biny,(unsigned) 0);
2126 biny = std::min(biny,(unsigned)(g2d_.Ny()-1));
2127 return count_[biny*g2d_.Nx()+binx ];
2128
2129 }
2130 private:
2131 dg::Grid2d g2d_;
2132 const std::vector<double> inx_,iny_;
2133 double binwidthx_,binwidthy_;
2134 container count_;
2135};
2136
2137
2138
2146{
2153 WallDistance( std::vector<double> vertical, std::vector<double> horizontal) :
2154 m_vertical(vertical), m_horizontal( horizontal) {}
2160 WallDistance( dg::Grid2d walls) : m_vertical({walls.x0(), walls.x1()}),
2161 m_horizontal({walls.y0(), walls.y1()}){}
2165 double operator() (double R, double Z) const
2166 {
2167 std::vector<double> dist( 1, 1e100); //fill in at least one (large) number in case vectors are empty)
2168 for( auto v : m_vertical)
2169 dist.push_back(fabs( R-v));
2170 for( auto h : m_horizontal)
2171 dist.push_back(fabs( Z-h));
2172 return *std::min_element( dist.begin(), dist.end());
2173 }
2174 private:
2175 std::vector<double> m_vertical;
2176 std::vector<double> m_horizontal;
2177};
2178
2179
2181} //namespace dg
2182
Function discretization routines.
Some utility functions for the dg::evaluate routines.
#define M_PI
M_PI is non-standard ... so MSVC complains.
Definition functors.h:6
base topology classes
DG_DEVICE T zero(T, Ts ...)
This enum can be used in dg::evaluate.
Definition functions.h:19
void scal(ContainerType &x, value_type alpha)
Definition blas1.h:263
@ z
z direction
@ backward
backward derivative (cell to the left and current cell)
Definition enums.h:99
@ forward
forward derivative (cell to the right and current cell)
Definition enums.h:98
@ y
y direction
@ x
x direction
auto evaluate(Functor &&f, const Topology &g)
Evaluate a function on grid coordinates
Definition evaluation.h:74
#define DG_DEVICE
Expands to __host__ __device__ if compiled with nvcc else is empty.
Definition dg_doc.h:378
const double m
const double alpha
const double n
const double bgamp
const double amp
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
const double beta
Definition functors.h:102
DG_DEVICE T operator()(T x) const
Definition functors.h:103
Definition functors.h:123
DG_DEVICE T operator()(T x, T y) const
Definition functors.h:124
Definition functors.h:135
DG_DEVICE T operator()(T x, T y) const
Definition functors.h:136
Definition functors.h:1768
double operator()(double R, double Z) const
Return the value of the Bath.
Definition functors.h:1842
BathRZ(unsigned N_kR, unsigned N_kZ, double R_min, double Z_min, double gamma, double L_E, double amp)
Functor returning a random field in the RZ-plane or in the first RZ-plane.
Definition functors.h:1780
double operator()(double R, double Z, double) const
Return the value of the Bath.
Definition functors.h:1883
Definition functors.h:678
double dxx(double x, double y) const
Definition functors.h:715
Cauchy(double x0, double y0, double sigma_x, double sigma_y, double amp)
A blob that drops to zero.
Definition functors.h:688
double dxy(double x, double y) const
Definition functors.h:735
double dx(double x, double y) const
Definition functors.h:709
DG_DEVICE double operator()(double x, double y) const
Definition functors.h:693
double dy(double x, double y) const
Definition functors.h:722
double dyy(double x, double y) const
Definition functors.h:728
bool inside(double x, double y) const
Definition functors.h:700
Definition functors.h:759
bool inside(double x, double) const
Definition functors.h:777
CauchyX(double x0, double sigma_x, double amp)
A 1D-blob that drops to zero.
Definition functors.h:767
DG_DEVICE double operator()(double x, double) const
Definition functors.h:771
Definition functors.h:1043
CosXCosY(double amp, double bamp, double kx, double ky)
Construct.
Definition functors.h:1052
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition functors.h:1062
Definition functors.h:1141
DG_DEVICE double operator()(double, double y) const
Definition functors.h:1151
CosY(double amp, double bamp, double ky)
Construct.
Definition functors.h:1149
The derivative of PolynomialHeaviside approximates delta(x)
Definition functors.h:1445
DG_DEVICE double operator()(double x) const
Definition functors.h:1461
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1470
DPolynomialHeaviside(double xb, double a, int=+1)
Construct with xb, width and sign.
Definition functors.h:1456
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1468
Definition functors.h:521
Distance(double x0, double y0)
Definition functors.h:522
DG_DEVICE double operator()(double x, double y)
Definition functors.h:524
Definition functors.h:47
DG_DEVICE T operator()(T x) const
Definition functors.h:48
Definition functors.h:1205
DG_DEVICE double operator()(double x) const
Definition functors.h:1217
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1221
ExpProfX(double amp, double bamp, double ln)
Construct with three coefficients.
Definition functors.h:1213
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1219
Definition functors.h:1489
ExponentialFilter(double alpha, double eta_c, unsigned order, unsigned n)
Create exponential filter .
Definition functors.h:1503
double operator()(unsigned i) const
Definition functors.h:1505
Definition functors.h:795
DG_DEVICE double operator()(double x, double y) const
Return a 2d Gaussian.
Definition functors.h:825
DG_DEVICE double operator()(double x, double y, double z) const
Return the value of the Gaussian.
Definition functors.h:844
Gaussian3d(double x0, double y0, double z0, double sigma_x, double sigma_y, double sigma_z, double amp)
Functor returning a Gaussian.
Definition functors.h:807
Definition functors.h:1239
DG_DEVICE double operator()(double psi) const
Definition functors.h:1245
GaussianDamping(double psimax, double alpha)
Definition functors.h:1240
Definition functors.h:613
DG_DEVICE double operator()(double x, double y) const
Return the value of the Gaussian.
Definition functors.h:640
Gaussian(double x0, double y0, double sigma_x, double sigma_y, double amp)
Functor returning a Gaussian.
Definition functors.h:623
DG_DEVICE double operator()(double x, double y, double) const
Return the value of the Gaussian.
Definition functors.h:657
Definition functors.h:862
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:885
DG_DEVICE double operator()(double x) const
Definition functors.h:875
DG_DEVICE double operator()(double x, double) const
Definition functors.h:880
GaussianX(double x0, double sigma_x, double amp)
A Gaussian in x.
Definition functors.h:870
Definition functors.h:900
GaussianY(double y0, double sigma_y, double amp)
Functor returning a gaussian.
Definition functors.h:908
DG_DEVICE double operator()(double, double y) const
Return the value of the gaussian.
Definition functors.h:923
Definition functors.h:938
DG_DEVICE double operator()(double z) const
Return the value of the gaussian.
Definition functors.h:961
GaussianZ(double z0, double sigma_z, double amp)
Functor returning a gaussian.
Definition functors.h:946
DG_DEVICE double operator()(double, double, double z) const
Return the value of the gaussian.
Definition functors.h:976
Definition functors.h:492
DG_DEVICE double operator()(double x) const
Definition functors.h:506
Heaviside(double xb, int sign=+1)
Construct with xb and sign.
Definition functors.h:502
Compute a histogram on a 2D grid.
Definition functors.h:2077
Histogram2D(const dg::Grid2d &g2d, const std::vector< double > &inx, const std::vector< double > &iny)
Construct a histogram from number of bins and an input vector.
Definition functors.h:2084
double operator()(double x, double y) const
Access computed histogram.
Definition functors.h:2119
Compute a histogram on a 1D grid.
Definition functors.h:2018
Histogram(const dg::Grid1d &g1d, const std::vector< double > &in)
Construct a histogram from number of bins and an input vector.
Definition functors.h:2024
double binwidth()
get binwidth
Definition functors.h:2048
double operator()(double x) const
Access computed histogram.
Definition functors.h:2056
Definition functors.h:1931
Horner1d(const std::vector< double > &c)
Initialize coefficients and dimensions.
Definition functors.h:1940
double operator()(double x) const
Definition functors.h:1948
Horner1d()
Initialize 1 coefficient to 1.
Definition functors.h:1933
Definition functors.h:1968
Horner2d()
Initialize 1 coefficient to 1.
Definition functors.h:1970
Horner2d(const std::vector< double > &c, unsigned M, unsigned N)
Initialize coefficients and dimensions.
Definition functors.h:1979
double operator()(double x, double y) const
Definition functors.h:1988
Definition functors.h:95
DG_DEVICE T operator()(T x) const
Definition functors.h:96
The integral of PolynomialHeaviside approximates xH(x)
Definition functors.h:1396
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1425
IPolynomialHeaviside(double xb, double a, int sign=+1)
Construct with xb, width and sign.
Definition functors.h:1404
DG_DEVICE double operator()(double x) const
Definition functors.h:1409
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1427
Definition functors.h:200
bool operator()(T x)
Definition functors.h:204
Definition functors.h:226
bool operator()(T x)
Definition functors.h:236
Definition functors.h:1160
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1173
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1171
DG_DEVICE double operator()(double x) const
Definition functors.h:1169
InvCoshXsq(double amp, double kx)
Construct with two coefficients.
Definition functors.h:1167
Definition functors.h:85
DG_DEVICE T operator()(T x) const
Definition functors.h:86
Definition functors.h:430
DG_DEVICE double operator()(double psi) const
Definition functors.h:434
Iris(double psi_min, double psi_max)
Definition functors.h:431
Definition functors.h:989
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition functors.h:1007
IslandXY(double lambda, double eps)
Construct Island.
Definition functors.h:996
Definition functors.h:57
DG_DEVICE T operator()(const T &x) const
Definition functors.h:58
Definition functors.h:1535
double enstrophy() const
The total enstrophy of the dipole.
Definition functors.h:1584
Lamb(double x0, double y0, double R, double U)
Functor returning a Lamb-dipole.
Definition functors.h:1544
DG_DEVICE double operator()(double x, double y) const
Return the value of the dipole.
Definition functors.h:1564
double energy() const
The total energy of the dipole.
Definition functors.h:1592
Definition functors.h:536
double operator()(double x)
Definition functors.h:539
Line(double x0, double y0, double x1, double y1)
Definition functors.h:537
Definition functors.h:551
DG_DEVICE double operator()(double x) const
Definition functors.h:560
LinearX(double a, double b)
Construct with two coefficients.
Definition functors.h:558
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:564
DG_DEVICE double operator()(double x, double) const
Definition functors.h:562
Definition functors.h:573
LinearY(double a, double b)
Construct with two coefficients.
Definition functors.h:580
DG_DEVICE double operator()(double, double y) const
Definition functors.h:584
DG_DEVICE double operator()(double, double y, double) const
Definition functors.h:582
Definition functors.h:593
LinearZ(double a, double b)
Construct with two coefficients.
Definition functors.h:600
DG_DEVICE double operator()(double, double, double z) const
Definition functors.h:602
x mod m > 0 ? x mod m : x mod m + m
Definition functors.h:169
MOD(T m)
Construct from modulo.
Definition functors.h:175
DG_DEVICE T operator()(T x) const
Definition functors.h:178
Definition functors.h:258
T operator()(T x1, T x2) const
Definition functors.h:272
Definition functors.h:31
PLUS(T value)
Construct.
Definition functors.h:37
DG_DEVICE T operator()(T x) const
Definition functors.h:39
Definition functors.h:154
DG_DEVICE T operator()(T x) const
Definition functors.h:155
Definition functors.h:1305
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1333
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1331
DG_DEVICE double operator()(double x) const
Definition functors.h:1319
PolynomialHeaviside(double xb, double a, int sign=+1)
Construct with xb, width and sign.
Definition functors.h:1314
Definition functors.h:1357
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1378
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1376
DG_DEVICE double operator()(double x) const
Definition functors.h:1371
PolynomialRectangle(double xl, double al, double xr, double ar)
Construct with xb, width and sign.
Definition functors.h:1366
Definition functors.h:471
PsiPupil(double psimax)
Definition functors.h:472
DG_DEVICE double operator()(double psi) const
Definition functors.h:475
Definition functors.h:451
Pupil(double psimax)
Definition functors.h:452
DG_DEVICE double operator()(double psi) const
Definition functors.h:455
Definition functors.h:68
DG_DEVICE T operator()(T x) const
Definition functors.h:69
Definition functors.h:116
DG_DEVICE T operator()(T x) const
Definition functors.h:117
Definition functors.h:1182
SinProfX(double amp, double bamp, double kx)
Construct.
Definition functors.h:1190
DG_DEVICE double operator()(double x) const
Definition functors.h:1192
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1196
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1194
Definition functors.h:1071
SinXCosY(double amp, double bamp, double kx, double ky)
Construct.
Definition functors.h:1080
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition functors.h:1090
Definition functors.h:1099
DG_DEVICE double operator()(double x) const
Definition functors.h:1109
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1113
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1111
SinX(double amp, double bamp, double kx)
Construct.
Definition functors.h:1107
Definition functors.h:1015
SinXSinY(double amp, double bamp, double kx, double ky)
Construct.
Definition functors.h:1024
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition functors.h:1034
Definition functors.h:1122
SinY(double amp, double bamp, double ky)
Construct.
Definition functors.h:1130
DG_DEVICE double operator()(double, double y) const
Definition functors.h:1132
Definition functors.h:374
DG_DEVICE T operator()(T v, T gm, T g0, T gp, T hm, T hp) const
Definition functors.h:378
SlopeLimiter()
Definition functors.h:375
SlopeLimiter(Limiter l)
Definition functors.h:376
Definition functors.h:399
DG_DEVICE T operator()(T v, T gm, T g0, T gp, T hm, T hp) const
Definition functors.h:403
SlopeLimiterProduct(Limiter l)
Definition functors.h:401
SlopeLimiterProduct()
Definition functors.h:400
Definition functors.h:77
DG_DEVICE T operator()(T x) const
Definition functors.h:79
Definition functors.h:1260
DG_DEVICE double operator()(double x, double) const
Definition functors.h:1282
DG_DEVICE double operator()(double x, double, double) const
Definition functors.h:1284
DG_DEVICE double operator()(double x) const
Definition functors.h:1277
TanhProfX(double xb, double width, int sign=1, double bgamp=0., double profamp=1.)
Construct with xb, width and sign.
Definition functors.h:1271
std::uniform_real_distribution<T> as a functor to evaluate on our grids
Definition functors.h:292
DG_DEVICE T operator()(Ts...)
Definition functors.h:298
UniformRealDistribution(T a, T b)
Parameters of uniform_real_distribution<T>
Definition functors.h:294
Definition functors.h:337
DG_DEVICE T operator()(T velocity, T backward, T forward) const
Definition functors.h:339
Definition functors.h:354
DG_DEVICE T operator()(T velocity, T backward, T forward) const
Definition functors.h:356
Definition functors.h:320
DG_DEVICE T operator()(T x1, T x2) const
Definition functors.h:322
Definition functors.h:1619
DG_DEVICE double operator()(double x, double y) const
Definition functors.h:1657
Vortex(double x0, double y0, unsigned state, double R, double u_dipole, double kz=0)
Definition functors.h:1630
DG_DEVICE double operator()(double x, double y, double z) const
Definition functors.h:1694
Shortest Distance to a collection of vertical and horizontal lines.
Definition functors.h:2146
WallDistance(dg::Grid2d walls)
Allocate lines.
Definition functors.h:2160
WallDistance(std::vector< double > vertical, std::vector< double > horizontal)
Allocate lines.
Definition functors.h:2153
double operator()(double R, double Z) const
Distance to closest wall in a box.
Definition functors.h:2165
real_type x0() const
Equivalent to p(0)
Definition grid.h:285
unsigned size() const
The total number of points.
Definition grid.h:532
unsigned Nx() const
Equivalent to N(0)
Definition grid.h:334
real_type y0() const
Equivalent to p(2)
Definition grid.h:291
real_type x1() const
Equivalent to p(1)
Definition grid.h:288
unsigned Ny() const
Equivalent to N(1)
Definition grid.h:337