Discontinuous Galerkin Library
#include "dg/algorithm.h"
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 <random>
10#include <functional>
11#include "blas1.h"
12#include "topology/grid.h"
13#include "topology/evaluation.h"
14#include "topology/functions.h"
18namespace dg
19{
20
23//Everything that is quite basic and simple
24
26struct ZERO
27{
29 double operator()(double x)const{return 0.;}
31 double operator()(double x, double y)const{return 0.;}
33 double operator()(double x, double y, double z)const{return 0.;}
34};
35
37struct ONE
38{
40 double operator()(double x)const{return 1.;}
42 double operator()(double x, double y)const{return 1.;}
44 double operator()(double x, double y, double z)const{return 1.;}
45};
46
49{
55 CONSTANT( double cte): m_value(cte){}
56
58 double operator()(double x)const{return m_value;}
60 double operator()(double x, double y)const{return m_value;}
62 double operator()(double x, double y, double z)const{return m_value;}
63 private:
64 double m_value;
65};
66
68template <class T = double>
69struct PLUS
70{
76 PLUS( T value): x_(value){}
78 T operator()( T x)const{ return x + x_;}
79 private:
80 T x_;
81};
82
84template< class T = double >
85struct EXP
86{
87 DG_DEVICE T operator() ( T x) const
88 {
89 return exp(x);
90 }
91};
92
94template < class T = double>
95struct LN
96{
97 DG_DEVICE T operator() (const T& x) const
98 {
99 return log(x);
100 }
101
102};
103
105template < class T = double>
106struct SQRT
107{
109 {
110 return sqrt(x);
111 }
112};
113
115struct Square
116{
117 template<class T>
118 DG_DEVICE T operator()( T x) const{ return x*x;}
119};
120
122template < class T = double>
124{
126 {
127 return 1./sqrt(x);
128 }
129};
130
132template <class T = double>
133struct INVERT
134{
135 DG_DEVICE T operator()( T x)const{ return 1./x;}
136};
137
139template <class T = double>
140struct ABS
141{
142 DG_DEVICE T operator()(T x)const{ return fabs(x);}
143};
144
153template <class T = double>
154struct Sign
155{
156 DG_DEVICE T operator()(T x)const{ return (T(0) < x) - (x < T(0));}
157};
158
160template <class T = double>
161struct AbsMax
162{
163 DG_DEVICE T operator() ( T x, T y) const
164 {
165 T absx = x>0 ? x : -x;
166 T absy = y>0 ? y : -y;
167 return absx > absy ? absx : absy;
168 }
169};
170
172template <class T = double>
173struct AbsMin
174{
175 DG_DEVICE T operator() (T x, T y) const
176 {
177 T absx = x<0 ? -x : x;
178 T absy = y<0 ? -y : y;
179 return absx < absy ? absx : absy;
180 }
181};
182
191template <class T = double>
193{
194 DG_DEVICE T operator()( T x)const{
195 if (x >= 0.0) return x;
196 return 0.0;
197 }
198};
199
206template <class T= double>
207struct MOD
208{
214 MOD( T m): m_m(m){}
215
217 T operator()( T x)const{
218 return (fmod(x,m_m) < 0 ) ? (m_m + fmod(x,m_m)) : fmod(x,m_m);
219 }
220 private:
221 T m_m;
222
223};
224
237template <class T>
239{
240#ifdef __CUDACC__
241 DG_DEVICE bool operator()(T x){ return !isfinite(x);}
242#else
243 bool operator()( T x){ return !std::isfinite(x);}
244#endif
245};
246
263template <class T>
265{
266#ifdef __CUDACC__
267 DG_DEVICE bool operator()(T x){
268 if( !isfinite(x))
269 return true;
270 if( x > 1e100 || x < -1e100)
271 return true;
272 return false;
273 }
274#else
275 bool operator()( T x){
276 if( !std::isfinite(x))
277 return true;
278 if( x > 1e100 || x < -1e100)
279 return true;
280 return false;
281 }
282#endif
283};
284
296struct MinMod
297{
299#ifdef __CUDACC__
300 template < class T>
301 DG_DEVICE T operator()( T x1, T x2) const
302 {
303 if( x1 > 0 && x2 > 0)
304 return min(x1,x2);
305 else if( x1 < 0 && x2 < 0)
306 return max(x1,x2);
307 return 0.;
308 }
309#else
310 template < class T>
311 T operator()( T x1, T x2) const
312 {
313 if( x1 > 0 && x2 > 0)
314 return std::min(x1,x2);
315 else if( x1 < 0 && x2 < 0)
316 return std::max(x1,x2);
317 return 0.;
318 }
319#endif
321 template<class T>
322 DG_DEVICE T operator() ( T x1, T x2, T x3)const
323 {
324 return this-> operator()( this-> operator()( x1, x2), x3);
325 }
326};
327
337{
338 template<class T>
339 DG_DEVICE T operator()( T x1, T x2) const
340 {
341 if( x1*x2 <= 0)
342 return 0.;
343 return 2.*x1*x2/(x1+x2);
344 }
345};
346
353struct Upwind
354{
355 template<class T>
356 DG_DEVICE T operator()( T velocity, T backward, T forward) const{
357 if( velocity >= 0)
358 return backward;
359 else
360 return forward;
361 }
362};
363
371{
372 template<class T>
373 DG_DEVICE T operator()( T velocity, T backward, T forward)const{
374 return velocity*m_up(velocity, backward, forward);
375 }
376 private:
377 Upwind m_up;
378};
379
389template<class Limiter>
391{
393 SlopeLimiter( Limiter l ) : m_l( l){}
394 template<class T>
395 DG_DEVICE T operator()( T v, T gm, T g0, T gp, T hm, T hp ) const{
396 if( v >= 0)
397 return +hm*m_l( g0, gm);
398 else
399 return -hp*m_l( gp, g0);
400 }
401 private:
402 Limiter m_l;
403};
404
414template<class Limiter>
416{
418 SlopeLimiterProduct( Limiter l ) : m_s( l){}
419 template<class T>
420 DG_DEVICE T operator()( T v, T gm, T g0, T gp, T hm, T hp ) const{
421 return v*m_s(v,gm,g0,gp,hm,hp);
422 }
423 private:
425};
427
428
434
437//
438
446struct Iris
447{
448 Iris( double psi_min, double psi_max ):
449 m_psimin(psi_min), m_psimax(psi_max) { }
451 double operator()(double psi)const
452 {
453 if( psi > m_psimax) return 0.;
454 if( psi < m_psimin) return 0.;
455 return 1.;
456 }
457 private:
458 double m_psimin, m_psimax;
459};
467struct Pupil
468{
469 Pupil( double psimax):
470 psimax_(psimax) { }
472 double operator()(double psi)const
473 {
474 if( psi > psimax_) return 0.;
475 return 1.;
476 }
477 private:
478 double psimax_;
479};
488{
489 PsiPupil(double psimax):
490 psimax_(psimax){ }
492 double operator()(double psi)const
493 {
494 if( psi > psimax_) return psimax_;
495 return psi;
496 }
497 private:
498 double psimax_;
499};
509{
510
519 Heaviside( double xb, int sign = +1):
520 m_xb(xb), m_s(sign){ }
521
523 double operator()(double x)const
524 {
525 if( (x < m_xb && m_s == 1) || (x > m_xb && m_s == -1)) return 0.;
526 return 1.;
527 }
528 private:
529 double m_xb;
530 int m_s;
531};
532
533
538{
539 Distance( double x0, double y0): m_x0(x0), m_y0(y0){}
541 double operator()(double x, double y){
542 return sqrt( (x-m_x0)*(x-m_x0) + (y-m_y0)*(y-m_y0));
543 }
544 private:
545 double m_x0, m_y0;
546};
553struct Line{
554 Line(double x0, double y0, double x1, double y1) :
555 m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1){}
556 double operator()(double x){
557 return m_y1*(x-m_x0)/(m_x1-m_x0) + m_y0*(x-m_x1)/(m_x0-m_x1);
558 }
559 private:
560 double m_x0, m_y0, m_x1, m_y1;
561};
562
568{
575 LinearX( double a, double b):a_(a), b_(b){}
577 double operator()(double x)const{ return a_*x+b_;}
579 double operator()( double x, double y)const{ return this->operator()(x);}
581 double operator()( double x, double y, double z)const{ return this->operator()(x);}
582 private:
583 double a_,b_;
584};
590{
597 LinearY( double a, double b):a_(a), b_(b){}
599 double operator()( double x, double y, double z)const { return a_*y+b_;}
601 double operator()( double x, double y)const{ return a_*y+b_;}
602 private:
603 double a_,b_;
604};
610{
617 LinearZ( double a, double b):a_(a), b_(b){}
619 double operator()( double x, double y, double z)const{ return a_*z+b_;}
620 private:
621 double a_,b_;
622};
630{
640 Gaussian( double x0, double y0, double sigma_x, double sigma_y, double amp)
641 : m_x0(x0), m_y0(y0), m_sigma_x(sigma_x), m_sigma_y(sigma_y), m_amp(amp){
642 assert( m_sigma_x != 0 && "sigma_x must not be 0 in Gaussian");
643 assert( m_sigma_y != 0 && "sigma_y must not be 0 in Gaussian");
644 }
657 double operator()(double x, double y) const
658 {
659 return m_amp*
660 exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x +
661 (y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
662 }
675 double operator()(double x, double y, double z) const
676 {
677 return this->operator()(x,y);
678 }
679 private:
680 double m_x0, m_y0, m_sigma_x, m_sigma_y, m_amp;
681
682};
683
695struct Cauchy
696{
706 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){
707 assert( sigma_x != 0 && "sigma_x must be !=0 in Cauchy");
708 assert( sigma_y != 0 && "sigma_y must be !=0 in Cauchy");
709 }
711 double operator()(double x, double y )const{
712 double xbar = (x-x0_)/sigmaX_;
713 double ybar = (y-y0_)/sigmaY_;
714 if( xbar*xbar + ybar*ybar < 1.)
715 return amp_*exp( 1. + 1./( xbar*xbar + ybar*ybar -1.) );
716 return 0.;
717 }
718 bool inside( double x, double y)const
719 {
720 double xbar = (x-x0_)/sigmaX_;
721 double ybar = (y-y0_)/sigmaY_;
722 if( xbar*xbar + ybar*ybar < 1.)
723 return true;
724 return false;
725 }
726
727 double dx( double x, double y )const{
728 double xbar = (x-x0_)/sigmaX_;
729 double ybar = (y-y0_)/sigmaY_;
730 double temp = sigmaX_*(xbar*xbar + ybar*ybar - 1.);
731 return -2.*(x-x0_)*this->operator()(x,y)/temp/temp;
732 }
733 double dxx( double x, double y)const{
734 double temp = sigmaY_*sigmaY_*(x-x0_)*(x-x0_) + sigmaX_*sigmaX_*((y-y0_)*(y-y0_) - sigmaY_*sigmaY_);
735 double bracket = sigmaX_*sigmaX_*((y-y0_)*(y-y0_)-sigmaY_*sigmaY_)*sigmaX_*sigmaX_*((y-y0_)*(y-y0_)-sigmaY_*sigmaY_)
736 -3.*sigmaY_*sigmaY_*sigmaY_*sigmaY_*(x-x0_)*(x-x0_)*(x-x0_)*(x-x0_)
737 -2.*sigmaY_*sigmaY_*sigmaX_*sigmaX_*(x-x0_)*(x-x0_)*(y-y0_)*(y-y0_);
738 return -2.*sigmaX_*sigmaX_*sigmaY_*sigmaY_*sigmaY_*sigmaY_*this->operator()(x,y)*bracket/temp/temp/temp/temp;
739 }
740 double dy( double x, double y)const{
741 double xbar = (x-x0_)/sigmaX_;
742 double ybar = (y-y0_)/sigmaY_;
743 double temp = sigmaY_*(xbar*xbar + ybar*ybar - 1.);
744 return -2.*(y-y0_)*this->operator()(x,y)/temp/temp;
745 }
746 double dyy( double x, double y)const{
747 double temp = sigmaX_*sigmaX_*(y-y0_)*(y-y0_) + sigmaY_*sigmaY_*((x-x0_)*(x-x0_) - sigmaX_*sigmaX_);
748 double bracket = sigmaY_*sigmaY_*((x-x0_)*(x-x0_)-sigmaX_*sigmaX_)*sigmaY_*sigmaY_*((x-x0_)*(x-x0_)-sigmaX_*sigmaX_)
749 -3.*sigmaX_*sigmaX_*sigmaX_*sigmaX_*(y-y0_)*(y-y0_)*(y-y0_)*(y-y0_)
750 -2.*sigmaX_*sigmaX_*sigmaY_*sigmaY_*(y-y0_)*(y-y0_)*(x-x0_)*(x-x0_);
751 return -2.*sigmaY_*sigmaY_*sigmaX_*sigmaX_*sigmaX_*sigmaX_*this->operator()(x,y)*bracket/temp/temp/temp/temp;
752 }
753 double dxy( double x, double y )const{
754 double xbar = (x-x0_)/sigmaX_;
755 double ybar = (y-y0_)/sigmaY_;
756 double temp = (xbar*xbar + ybar*ybar - 1.);
757 return 8.*xbar*ybar*this->operator()(x,y)/temp/temp/temp/sigmaX_/sigmaY_
758 + 4.*xbar*ybar*this->operator()(x,y)/temp/temp/temp/temp/sigmaX_/sigmaY_
759;
760 }
761 private:
762 double x0_, y0_, sigmaX_, sigmaY_, amp_;
763};
764
777{
785 CauchyX( double x0, double sigma_x, double amp): x0_(x0), sigmaX_(sigma_x), amp_(amp){
786 assert( sigma_x != 0 && "sigma_x must be !=0 in Cauchy");
787 }
789 double operator()(double x, double y )const{
790 double xbar = (x-x0_)/sigmaX_;
791 if( xbar*xbar < 1.)
792 return amp_*exp( 1. + 1./( xbar*xbar -1.) );
793 return 0.;
794 }
795 bool inside( double x, double y)const
796 {
797 double xbar = (x-x0_)/sigmaX_;
798 if( xbar*xbar < 1.)
799 return true;
800 return false;
801 }
802 private:
803 double x0_, sigmaX_, amp_;
804};
805
813{
825 Gaussian3d( double x0, double y0, double z0, double sigma_x, double sigma_y, double sigma_z, double amp)
826 : 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){
827 assert( m_sigma_x != 0 && "sigma_x must be !=0 in Gaussian3d");
828 assert( m_sigma_y != 0 && "sigma_y must be !=0 in Gaussian3d");
829 assert( m_sigma_z != 0 && "sigma_z must be !=0 in Gaussian3d");
830 }
843 double operator()(double x, double y) const
844 {
845 return m_amp*
846 exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x +
847 (y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
848 }
862 double operator()(double x, double y, double z) const
863 {
864 return m_amp*
865 exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x +
866 (z-m_z0)*(z-m_z0)/2./m_sigma_z/m_sigma_z +
867 (y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
868 }
869 private:
870 double m_x0, m_y0, m_z0, m_sigma_x, m_sigma_y, m_sigma_z, m_amp;
871
872};
880{
888 GaussianX( double x0, double sigma_x, double amp)
889 :m_x0(x0), m_sigma_x(sigma_x), m_amp(amp){
890 assert( m_sigma_x != 0 && "sigma_x must be !=0 in GaussianX");
891 }
893 double operator()(double x) const
894 {
895 return m_amp* exp( -((x-m_x0)*(x-m_x0)/2./m_sigma_x/m_sigma_x ));
896 }
898 double operator()(double x, double y) const
899 {
900 return this->operator()(x);
901 }
903 double operator()(double x, double y, double z) const
904 {
905 return this->operator()(x);
906 }
907 private:
908 double m_x0, m_sigma_x, m_amp;
909
910};
918{
926 GaussianY( double y0, double sigma_y, double amp)
927 : m_y0(y0), m_sigma_y(sigma_y), m_amp(amp){
928 assert( m_sigma_y != 0 && "sigma_x must be !=0 in GaussianY");
929 }
942 double operator()(double x, double y) const
943 {
944 return m_amp*exp( -((y-m_y0)*(y-m_y0)/2./m_sigma_y/m_sigma_y) );
945 }
946 private:
947 double m_y0, m_sigma_y, m_amp;
948
949};
957{
965 GaussianZ( double z0, double sigma_z, double amp)
966 : m_z0(z0), m_sigma_z(sigma_z), m_amp(amp){
967 assert( m_sigma_z != 0 && "sigma_z must be !=0 in GaussianZ");
968 }
980 double operator()( double z) const
981 {
982 return m_amp*exp( -((z-m_z0)*(z-m_z0)/2./m_sigma_z/m_sigma_z) );
983 }
997 double operator()(double x, double y, double z) const
998 {
999 return m_amp*exp( -((z-m_z0)*(z-m_z0)/2./m_sigma_z/m_sigma_z) );
1000 }
1001 private:
1002 double m_z0, m_sigma_z, m_amp;
1003
1004};
1010{
1017 IslandXY( double lambda, double eps):lambda_(lambda), eps_(eps){
1018 assert( lambda != 0 && "Lambda parameter in IslandXY must not be zero!");
1019 }
1027 DG_DEVICE
1028 double operator()( double x, double y)const{ return lambda_*log(cosh(x/lambda_)+eps_*cos(y/lambda_));}
1029 private:
1030 double lambda_,eps_;
1031};
1036{
1045 SinXSinY( double amp, double bamp, double kx, double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1054 DG_DEVICE
1055 double operator()( double x, double y)const{ return bamp_+amp_*sin(x*kx_)*sin(y*ky_);}
1056 private:
1057 double amp_,bamp_,kx_,ky_;
1058};
1064{
1073 CosXCosY( double amp, double bamp, double kx, double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1082 DG_DEVICE
1083 double operator()( double x, double y)const{ return bamp_+amp_*cos(x*kx_)*cos(y*ky_);}
1084 private:
1085 double amp_,bamp_,kx_,ky_;
1086};
1092{
1101 SinXCosY( double amp, double bamp, double kx, double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1110 DG_DEVICE
1111 double operator()( double x, double y)const{ return bamp_+amp_*sin(x*kx_)*cos(y*ky_);}
1112 private:
1113 double amp_,bamp_,kx_,ky_;
1114};
1119struct SinX
1120{
1128 SinX( double amp, double bamp, double kx):amp_(amp), bamp_(bamp),kx_(kx){}
1129 DG_DEVICE
1130 double operator()( double x)const{ return bamp_+amp_*sin(x*kx_);}
1131 DG_DEVICE
1132 double operator()( double x, double y)const{ return this->operator()(x);}
1133 DG_DEVICE
1134 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1135 private:
1136 double amp_,bamp_,kx_;
1137};
1142struct SinY
1143{
1151 SinY( double amp, double bamp, double ky):amp_(amp), bamp_(bamp),ky_(ky){}
1152 DG_DEVICE
1153 double operator()( double x, double y)const{ return bamp_+amp_*sin(y*ky_);}
1154 private:
1155 double amp_,bamp_,ky_;
1156};
1161struct CosY
1162{
1170 CosY( double amp, double bamp, double ky):amp_(amp), bamp_(bamp),ky_(ky){}
1171 DG_DEVICE
1172 double operator()( double x, double y)const{ return bamp_+amp_*cos(y*ky_);}
1173 private:
1174 double amp_,bamp_,ky_;
1175};
1181{
1188 InvCoshXsq( double amp, double kx):m_amp(amp), m_kx(kx){}
1189 DG_DEVICE
1190 double operator()( double x)const{ return m_amp/cosh(x*m_kx)/cosh(x*m_kx);}
1191 DG_DEVICE
1192 double operator()( double x, double y)const{ return this->operator()(x);}
1193 DG_DEVICE
1194 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1195 private:
1196 double m_amp, m_kx;
1197};
1203{
1211 SinProfX( double amp, double bamp, double kx):m_amp(amp), m_bamp(bamp),m_kx(kx){}
1212 DG_DEVICE
1213 double operator()( double x)const{ return m_bamp+m_amp*(1.-sin(x*m_kx));}
1214 DG_DEVICE
1215 double operator()( double x, double y)const{ return this->operator()(x);}
1216 DG_DEVICE
1217 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1218 private:
1219 double m_amp, m_bamp, m_kx;
1220};
1226{
1234 ExpProfX( double amp, double bamp, double ln):m_amp(amp),m_bamp(bamp),m_ln(ln){
1235 assert( ln!=0 && "ln parameter must be != 0 in ExpProfX!");
1236 }
1237 DG_DEVICE
1238 double operator()( double x)const{ return m_bamp+m_amp*exp(-x/m_ln);}
1239 DG_DEVICE
1240 double operator()( double x, double y)const{ return this->operator()(x);}
1241 DG_DEVICE
1242 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1243 private:
1244 double m_amp, m_bamp, m_ln;
1245};
1246
1247
1260{
1261 GaussianDamping( double psimax, double alpha):
1262 m_psimax(psimax), m_alpha(alpha) {
1263 assert( alpha!= 0 && "Damping width in GaussianDamping must not be zero");
1264 }
1265 DG_DEVICE
1266 double operator()(double psi)const
1267 {
1268 if( psi > m_psimax + 4.*m_alpha) return 0.;
1269 if( psi < m_psimax) return 1.;
1270 return exp( -( psi-m_psimax)*( psi-m_psimax)/2./m_alpha/m_alpha);
1271 }
1272 private:
1273 double m_psimax, m_alpha;
1274};
1292 TanhProfX(double xb, double width, int sign =1,double bgamp = 0.,
1293 double profamp = 1.) :
1294 xb_(xb),w_(width), s_(sign),bga_(bgamp),profa_(profamp) {
1295 assert( width != 0&& "Width in TanhProfX must not be zero!");
1296 }
1297 DG_DEVICE
1298 double operator() (double x)const
1299 {
1300 return profa_*0.5*(1.+s_*tanh((x-xb_)/w_))+bga_;
1301 }
1302 DG_DEVICE
1303 double operator()( double x, double y)const{ return this->operator()(x);}
1304 DG_DEVICE
1305 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1306 private:
1307 double xb_;
1308 double w_;
1309 int s_;
1310 double bga_;
1311 double profa_;
1312};
1313
1335 PolynomialHeaviside(double xb, double a, int sign = +1) :
1336 x0(xb), a(a), m_s(sign){
1337 assert( a!=0 && "PolynomialHeaviside width must not be zero");
1338 }
1339 DG_DEVICE
1340 double operator() (double x)const
1341 {
1342 if( m_s == -1) x = 2*x0-x; //mirror
1343 if ( x < x0-a) return 0;
1344 if ( x > x0+a) return 1;
1345 return ((16.*a*a*a - 29.*a*a*(x - x0)
1346 + 20.*a*(x - x0)*(x - x0)
1347 - 5.*(x - x0)*(x-x0)*(x-x0))
1348 *(a + x - x0)*(a + x - x0)
1349 *(a + x - x0)*(a + x - x0))/(32.*a*a*a * a*a*a*a);
1350 }
1351 DG_DEVICE
1352 double operator()( double x, double y)const{ return this->operator()(x);}
1353 DG_DEVICE
1354 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1355 private:
1356 double x0, a;
1357 int m_s;
1358};
1359
1387 PolynomialRectangle(double xl, double al, double xr, double ar) :
1388 m_hl( xl, al, +1), m_hr( xr, ar, -1) {
1389 assert( xl < xr && "left boundary must be left of right boundary");
1390 }
1391 DG_DEVICE
1392 double operator() (double x)const
1393 {
1394 return m_hl(x)*m_hr(x);
1395 }
1396 DG_DEVICE
1397 double operator()( double x, double y)const{ return this->operator()(x);}
1398 DG_DEVICE
1399 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1400 private:
1401 PolynomialHeaviside m_hl, m_hr;
1402};
1403
1425 IPolynomialHeaviside(double xb, double a, int sign = +1) :
1426 x0(xb), a(a), m_s(sign){
1427 assert( a!=0 && "IPolynomialHeaviside width must not be zero");
1428 }
1429 DG_DEVICE
1430 double operator() (double x)const
1431 {
1432 if( m_s == -1) x = 2*x0-x; //mirror
1433 double result;
1434 if ( x < x0-a) result = x0;
1435 else if ( x > x0+a) result = x;
1436 else
1437 result = x0 + ((35.* a*a*a - 47.* a*a*(x - x0) + 25.*a*(x - x0)*(x-x0)
1438 - 5.*(x - x0)*(x-x0)*(x-x0))
1439 *(a+x-x0)*(a+x-x0)*(a+x-x0)*(a+x-x0)*(a+x-x0))
1440 /(256.*a*a*a * a*a*a*a);
1441 if ( m_s == +1) return result;
1442 return 2*x0 - result;
1443
1444 }
1445 DG_DEVICE
1446 double operator()( double x, double y)const{ return this->operator()(x);}
1447 DG_DEVICE
1448 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1449 private:
1450 double x0, a;
1451 int m_s;
1452};
1453
1476 DPolynomialHeaviside(double xb, double a, int sign = +1) :
1477 x0(xb), a(a){
1478 assert( a!=0 && "DPolynomialHeaviside width must not be zero");
1479 }
1480 DG_DEVICE
1481 double operator() (double x)const
1482 {
1483 if ( (x < x0-a) || (x > x0+a)) return 0;
1484 return (35.*(a+x-x0)*(a+x-x0)*(a+x-x0)*(a-x+x0)*(a-x+x0)*(a-x+x0))
1485 /(32.*a*a*a * a*a*a*a);
1486 }
1487 DG_DEVICE
1488 double operator()( double x, double y)const{ return this->operator()(x);}
1489 DG_DEVICE
1490 double operator()( double x, double y, double z)const{ return this->operator()(x);}
1491 private:
1492 double x0, a;
1493};
1494
1509{
1523 ExponentialFilter( double alpha, double eta_c, unsigned order, unsigned n):
1524 m_alpha(alpha), m_etac(eta_c), m_s(order), m_n(n) {}
1525 double operator()( unsigned i) const
1526 {
1527 double eta = (double)i/(double)(m_n-1);
1528 if( m_n == 1) eta = 0.;
1529 if( eta < m_etac)
1530 return 1.;
1531 if( eta <= 1.)
1532 return exp( -m_alpha*pow( (eta-m_etac)/(1.-m_etac), 2*m_s));
1533 return 0;
1534 }
1535 private:
1536 double m_alpha, m_etac;
1537 unsigned m_s, m_n;
1538};
1539
1554struct Lamb
1555{
1564 Lamb( double x0, double y0, double R, double U):R_(R), U_(U), x0_(x0), y0_(y0)
1565 {
1566 gamma_ = 3.83170597020751231561;
1567 lambda_ = gamma_/R;
1568#ifdef _MSC_VER
1569 j_ = _j0(gamma_);
1570#else
1571 j_ = j0( gamma_);
1572#endif
1573 //std::cout << r_ <<u_<<x0_<<y0_<<lambda_<<gamma_<<j_<<std::endl;
1574 }
1583 DG_DEVICE
1584 double operator() (double x, double y)const
1585 {
1586 double radius = sqrt( (x-x0_)*(x-x0_) + (y-y0_)*(y-y0_));
1587 double theta = atan2( (y-y0_),(x-x0_));
1588
1589 if( radius <= R_)
1590#ifdef _MSC_VER
1591 return 2.*lambda_*U_*_j1(lambda_*radius)/j_*cos( theta);
1592#else
1593 return 2.*lambda_*U_*j1( lambda_*radius)/j_*cos( theta);
1594#endif
1595 return 0;
1596 }
1604 double enstrophy( ) const { return M_PI*U_*U_*gamma_*gamma_;}
1605
1612 double energy() const { return 2.*M_PI*R_*R_*U_*U_;}
1613 private:
1614 double R_, U_, x0_, y0_, lambda_, gamma_, j_;
1615};
1616
1639{
1650 Vortex( double x0, double y0, unsigned state,
1651 double R, double u_dipole, double kz = 0):
1652 x0_(x0), y0_(y0), s_(state), R_(R), u_d( u_dipole), kz_(kz){
1653 g_[0] = 3.831896621;
1654 g_[1] = -3.832353624;
1655 g_[2] = 7.016;
1656 b_[0] = 0.03827327723;
1657 b_[1] = 0.07071067810 ;
1658 b_[2] = 0.07071067810 ;
1659 }
1676 DG_DEVICE
1677 double operator()( double x, double y)const
1678 {
1679 double r = sqrt( (x-x0_)*(x-x0_)+(y-y0_)*(y-y0_));
1680 double theta = atan2( y-y0_, x-x0_);
1681 double beta = b_[s_];
1682 double norm = 1.2965125;
1683
1684 if( r/R_<=1.)
1685 return u_d*(
1686 r *( 1 +beta*beta/g_[s_]/g_[s_] )
1687#ifdef _MSC_VER
1688 - R_* beta*beta/g_[s_]/g_[s_] *_j1(g_[s_]*r/R_)/_j1(g_[s_])
1689#else
1690 - R_ * beta*beta/g_[s_]/g_[s_] * j1(g_[s_]*r/R_)/ j1(g_[s_])
1691#endif
1692 )*cos(theta)/norm;
1693 return u_d * R_* bessk1(beta*r/R_)/bessk1(beta)*cos(theta)/norm;
1694 }
1712 DG_DEVICE
1713 double operator()( double x, double y, double z)const
1714 {
1715 return this->operator()(x,y)*cos(kz_*z);
1716 }
1717 private:
1718 // Returns the modified Bessel function K1(x) for positive real x.
1719 DG_DEVICE
1720 double bessk1(double x)const
1721 {
1722 double y,ans;
1723 if (x <= 2.0)
1724 {
1725 y=x*x/4.0;
1726 ans = (log(x/2.0)*bessi1(x))+(1.0/x)*(1.0+y*(0.15443144 +
1727 y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1 +
1728 y*(-0.110404e-2+y*(-0.4686e-4)))))));
1729 }
1730 else
1731 {
1732 y=2.0/x;
1733 ans = (exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +
1734 y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2 +
1735 y*(0.325614e-2+y*(-0.68245e-3)))))));
1736 }
1737 return ans;
1738 }
1739 //Returns the modified Bessel function I1(x) for any real x.
1740 DG_DEVICE
1741 double bessi1(double x) const
1742 {
1743 double ax,ans;
1744 double y;
1745 if ((ax=fabs(x)) < 3.75)
1746 {
1747 y=x/3.75;
1748 y*=y;
1749 ans = ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +
1750 y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
1751 }
1752 else
1753 {
1754 y=3.75/ax;
1755 ans = 0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -
1756 y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+
1757 y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
1758 ans *= (exp(ax)/sqrt(ax));
1759 }
1760 return x < 0.0 ? -ans : ans;
1761 }
1762 double x0_, y0_;
1763 unsigned s_;
1764 double R_, b_[3], u_d;
1765 double g_[3];
1766 double kz_;
1767};
1768
1787struct BathRZ{
1799 BathRZ( unsigned N_kR, unsigned N_kZ, double R_min, double Z_min, double gamma, double L_E, double amp) :
1800 N_kR_(N_kR), N_kZ_(N_kZ),
1801 R_min_(R_min), Z_min_(Z_min),
1802 gamma_(gamma), L_E_(L_E) , amp_(amp),
1803 kvec( N_kR_*N_kZ_, 0), sqEkvec(kvec), unif1(kvec), unif2(kvec),
1804 normal1(kvec), normal2(kvec), alpha(kvec), theta(kvec)
1805 {
1806 double N_kR2=(double)(N_kR_*N_kR_);
1807 double N_kZ2=(double)(N_kZ_*N_kZ_);
1808 double N_k= sqrt(N_kR2+N_kZ2);
1809
1810 norm_=sqrt(2./(double)N_kR_/(double)N_kZ_);
1811 double tpi=2.*M_PI, tpi2=tpi*tpi;
1812 double k0= tpi*L_E_/N_k;
1813 double N_kRh = N_kR_/2.;
1814 double N_kZh = N_kZ_/2.;
1815
1816 std::minstd_rand generator;
1817 std::normal_distribution<double> ndistribution( 0.0, 1.0); // ( mean, stddev)
1818 std::uniform_real_distribution<double> udistribution(0.0,tpi); //between [0 and 2pi)
1819 for (unsigned j=1;j<=N_kZ_;j++)
1820 {
1821 double kZ2=tpi2*(j-N_kZh)*(j-N_kZh)/(N_kZ2);
1822 for (unsigned i=1;i<=N_kR_;i++)
1823 {
1824 double kR2=tpi2*(i-N_kRh)*(i-N_kRh)/(N_kR2);
1825 int z=(j-1)*(N_kR_)+(i-1);
1826 kvec[z]= sqrt(kR2 + kZ2); //radial k number
1827 sqEkvec[z]=pow(kvec[z]*4.*k0/(kvec[z]+k0)/(kvec[z]+k0),gamma_/2.); //Energie in k space with max at 1.
1828 unif1[z]=cos(udistribution(generator));
1829 unif2[z]=sin(udistribution(generator));
1830 normal1[z]=ndistribution(generator);
1831 normal2[z]=ndistribution(generator);
1832 alpha[z]=sqrt(normal1[z]*normal1[z]+normal2[z]*normal2[z]);
1833 theta[z]=atan2(normal2[z],normal1[z]);
1834 }
1835 }
1836
1837 }
1861 double operator()(double R, double Z)const
1862 {
1863 double f, kappa, RR, ZZ;
1864 RR=R-R_min_;
1865 ZZ=Z-Z_min_;
1866 f=0.;
1867 for (unsigned j=0;j<N_kZ_;j++)
1868 {
1869 for (unsigned i=0;i<N_kR_;i++)
1870 {
1871 int z=j*N_kR_+i;
1872 kappa= RR*unif1[z]+ZZ*unif2[z];
1873 f+= sqEkvec[z]*alpha[z]*cos(kvec[z]*kappa+theta[z]);
1874 }
1875 }
1876 return amp_*norm_*f;
1877 }
1903 double operator()(double R, double Z, double phi)const {
1904 double f, kappa;
1905 double RR, ZZ;
1906 RR=R-R_min_;
1907 ZZ=Z-Z_min_;
1908 f=0;
1909 for (unsigned j=0;j<N_kZ_;j++)
1910 {
1911 for (unsigned i=0;i<N_kR_;i++)
1912 {
1913 int z=(j)*(N_kR_)+(i);
1914 kappa= RR*unif1[z]+ZZ*unif2[z];
1915 f+= sqEkvec[z]*alpha[z]*cos(kvec[z]*kappa+theta[z]);
1916 }
1917 }
1918 return amp_*norm_*f;
1919 }
1920 private:
1921 unsigned N_kR_,N_kZ_;
1922 double R_min_, Z_min_;
1923 double gamma_, L_E_;
1924 double amp_;
1925 double norm_;
1926 std::vector<double> kvec;
1927 std::vector<double> sqEkvec;
1928 std::vector<double> unif1, unif2, normal1,normal2,alpha,theta;
1929};
1930
1937{
1939 Horner2d(): m_c( 1, 1), m_M(1), m_N(1){}
1940
1948 Horner2d( std::vector<double> c, unsigned M, unsigned N): m_c(c), m_M(M), m_N(N){}
1949 double operator()( double x, double y) const
1950 {
1951 std::vector<double> cx( m_M);
1952 for( unsigned i=0; i<m_M; i++)
1953 cx[i] = horner( &m_c[i*m_N], m_N, y);
1954 return horner( &cx[0], m_M, x);
1955 }
1956 private:
1957 double horner( const double * c, unsigned M, double x) const
1958 {
1959 double b = c[M-1];
1960 for( unsigned i=0; i<M-1; i++)
1961 b = c[M-2-i] + b*x;
1962 return b;
1963 }
1964 std::vector<double> m_c;
1965 unsigned m_M, m_N;
1966};
1967
1968
1973template <class container = thrust::host_vector<double> >
1975{
1981 Histogram(const dg::Grid1d& g1d, const std::vector<double>& in) :
1982 g1d_(g1d),
1983 in_(in),
1984 binwidth_(g1d_.h()),
1985 count_(dg::evaluate(dg::zero,g1d_))
1986 {
1987 for (unsigned j=0;j<in_.size();j++)
1988 {
1989 unsigned bin =floor( (in_[j]-g1d_.x0())/binwidth_ );
1990 bin = std::max(bin,(unsigned) 0);
1991 bin = std::min(bin,(unsigned)(g1d_.size()-1));
1992 count_[bin ]+=1.;
1993 }
1994 //Normalize
1995 unsigned Ampmax = (unsigned)thrust::reduce( count_.begin(), count_.end(),0., thrust::maximum<double>() );
1996 dg::blas1::scal(count_,1./Ampmax);
1997
1998 }
1999
2005 double binwidth() {return binwidth_;}
2013 double operator()(double x)const
2014 {
2015 unsigned bin = floor((x-g1d_.x0())/binwidth_+0.5);
2016 bin = std::max(bin,(unsigned) 0);
2017 bin = std::min(bin,(unsigned)(g1d_.size()-1));
2018 return count_[bin];
2019 }
2020
2021 private:
2022 dg::Grid1d g1d_;
2023 const std::vector<double> in_;
2024 double binwidth_;
2025 container count_;
2026};
2027
2032template <class container = thrust::host_vector<double> >
2034{
2041 Histogram2D(const dg::Grid2d& g2d, const std::vector<double>& inx,const std::vector<double>& iny) :
2042 g2d_(g2d),
2043 inx_(inx),
2044 iny_(iny),
2045 binwidthx_(g2d_.hx()),
2046 binwidthy_(g2d_.hy()),
2047 count_(dg::evaluate(dg::zero,g2d_))
2048 {
2049
2050 for (unsigned j=0;j<iny_.size();j++)
2051 {
2052 unsigned biny =floor((iny_[j]-g2d_.y0())/binwidthy_) ;
2053 biny = std::max(biny,(unsigned) 0);
2054 biny = std::min(biny,(unsigned)(g2d_.Ny()-1));
2055
2056 unsigned binx =floor((inx_[j]-g2d_.x0())/binwidthx_) ;
2057 binx = std::max(binx,(unsigned) 0);
2058 binx = std::min(binx,(unsigned)(g2d_.Nx()-1));
2059 count_[biny*g2d_.Nx()+binx ]+=1.;
2060
2061 }
2062 //Normalize
2063 unsigned Ampmax = (unsigned)thrust::reduce( count_.begin(), count_.end(),0.,thrust::maximum<double>() );
2064 dg::blas1::scal(count_, 1./Ampmax);
2065
2066 }
2067
2076 double operator()(double x, double y)const
2077 {
2078 unsigned binx = floor((x-g2d_.x0())/binwidthx_+0.5) ;
2079 binx = std::max(binx,(unsigned) 0);
2080 binx = std::min(binx,(unsigned)(g2d_.Nx()-1));
2081 unsigned biny = floor((y-g2d_.y0())/binwidthy_+0.5) ;
2082 biny = std::max(biny,(unsigned) 0);
2083 biny = std::min(biny,(unsigned)(g2d_.Ny()-1));
2084 return count_[biny*g2d_.Nx()+binx ];
2085
2086 }
2087 private:
2088 dg::Grid2d g2d_;
2089 const std::vector<double> inx_,iny_;
2090 double binwidthx_,binwidthy_;
2091 container count_;
2092};
2093
2094
2095
2103{
2110 WallDistance( std::vector<double> vertical, std::vector<double> horizontal) :
2111 m_vertical(vertical), m_horizontal( horizontal) {}
2117 WallDistance( dg::Grid2d walls) : m_vertical({walls.x0(), walls.x1()}),
2118 m_horizontal({walls.y0(), walls.y1()}){}
2122 double operator() (double R, double Z) const
2123 {
2124 std::vector<double> dist( 1, 1e100); //fill in at least one (large) number in case vectors are empty)
2125 for( auto v : m_vertical)
2126 dist.push_back(fabs( R-v));
2127 for( auto h : m_horizontal)
2128 dist.push_back(fabs( Z-h));
2129 return *std::min_element( dist.begin(), dist.end());
2130 }
2131 private:
2132 std::vector<double> m_vertical;
2133 std::vector<double> m_horizontal;
2134};
2135
2136
2138} //namespace dg
2139
Function discretization routines.
Some utility functions for the dg::evaluate routines.
#define DG_DEVICE
Expands to __host__ __device__ if compiled with nvcc else is empty.
Definition: functions.h:9
#define M_PI
M_PI is non-standard ... so MSVC complains.
Definition: functors.h:6
base topology classes
static DG_DEVICE double zero(double x)
Definition: functions.h:29
OutputType reduce(const ContainerType &x, OutputType zero, BinaryOp binary_op, UnaryOp unary_op=UnaryOp())
Custom (transform) reduction
Definition: blas1.h:139
void scal(ContainerType &x, get_value_type< ContainerType > alpha)
Definition: blas1.h:185
@ 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
thrust::host_vector< real_type > evaluate(UnaryOp f, const RealGrid1d< real_type > &g)
Evaluate a 1d function on grid coordinates.
Definition: evaluation.h:67
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Definition: functors.h:141
DG_DEVICE T operator()(T x) const
Definition: functors.h:142
Definition: functors.h:162
DG_DEVICE T operator()(T x, T y) const
Definition: functors.h:163
Definition: functors.h:174
DG_DEVICE T operator()(T x, T y) const
Definition: functors.h:175
Definition: functors.h:1787
double operator()(double R, double Z, double phi) const
Return the value of the Bath.
Definition: functors.h:1903
double operator()(double R, double Z) const
Return the value of the Bath.
Definition: functors.h:1861
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:1799
Definition: functors.h:49
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:60
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:62
DG_DEVICE double operator()(double x) const
Definition: functors.h:58
CONSTANT(double cte)
Construct with a value.
Definition: functors.h:55
Definition: functors.h:696
double dxx(double x, double y) const
Definition: functors.h:733
Cauchy(double x0, double y0, double sigma_x, double sigma_y, double amp)
A blob that drops to zero.
Definition: functors.h:706
double dxy(double x, double y) const
Definition: functors.h:753
double dx(double x, double y) const
Definition: functors.h:727
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:711
double dy(double x, double y) const
Definition: functors.h:740
double dyy(double x, double y) const
Definition: functors.h:746
bool inside(double x, double y) const
Definition: functors.h:718
Definition: functors.h:777
bool inside(double x, double y) const
Definition: functors.h:795
CauchyX(double x0, double sigma_x, double amp)
A 1D-blob that drops to zero.
Definition: functors.h:785
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:789
Definition: functors.h:1064
CosXCosY(double amp, double bamp, double kx, double ky)
Construct.
Definition: functors.h:1073
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition: functors.h:1083
Definition: functors.h:1162
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1172
CosY(double amp, double bamp, double ky)
Construct.
Definition: functors.h:1170
The derivative of PolynomialHeaviside approximates delta(x)
Definition: functors.h:1466
DG_DEVICE double operator()(double x) const
Definition: functors.h:1481
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1488
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1490
DPolynomialHeaviside(double xb, double a, int sign=+1)
Construct with xb, width and sign.
Definition: functors.h:1476
Definition: functors.h:538
Distance(double x0, double y0)
Definition: functors.h:539
DG_DEVICE double operator()(double x, double y)
Definition: functors.h:541
Definition: functors.h:86
DG_DEVICE T operator()(T x) const
Definition: functors.h:87
Definition: functors.h:1226
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1242
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1240
DG_DEVICE double operator()(double x) const
Definition: functors.h:1238
ExpProfX(double amp, double bamp, double ln)
Construct with three coefficients.
Definition: functors.h:1234
Definition: functors.h:1509
ExponentialFilter(double alpha, double eta_c, unsigned order, unsigned n)
Create exponential filter .
Definition: functors.h:1523
double operator()(unsigned i) const
Definition: functors.h:1525
Definition: functors.h:813
DG_DEVICE double operator()(double x, double y) const
Return a 2d Gaussian.
Definition: functors.h:843
DG_DEVICE double operator()(double x, double y, double z) const
Return the value of the Gaussian.
Definition: functors.h:862
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:825
Definition: functors.h:1260
DG_DEVICE double operator()(double psi) const
Definition: functors.h:1266
GaussianDamping(double psimax, double alpha)
Definition: functors.h:1261
Definition: functors.h:630
DG_DEVICE double operator()(double x, double y) const
Return the value of the Gaussian.
Definition: functors.h:657
Gaussian(double x0, double y0, double sigma_x, double sigma_y, double amp)
Functor returning a Gaussian.
Definition: functors.h:640
DG_DEVICE double operator()(double x, double y, double z) const
Return the value of the Gaussian.
Definition: functors.h:675
Definition: functors.h:880
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:898
DG_DEVICE double operator()(double x) const
Definition: functors.h:893
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:903
GaussianX(double x0, double sigma_x, double amp)
A Gaussian in x.
Definition: functors.h:888
Definition: functors.h:918
GaussianY(double y0, double sigma_y, double amp)
Functor returning a gaussian.
Definition: functors.h:926
DG_DEVICE double operator()(double x, double y) const
Return the value of the gaussian.
Definition: functors.h:942
Definition: functors.h:957
DG_DEVICE double operator()(double z) const
Return the value of the gaussian.
Definition: functors.h:980
GaussianZ(double z0, double sigma_z, double amp)
Functor returning a gaussian.
Definition: functors.h:965
DG_DEVICE double operator()(double x, double y, double z) const
Return the value of the gaussian.
Definition: functors.h:997
Definition: functors.h:509
DG_DEVICE double operator()(double x) const
Definition: functors.h:523
Heaviside(double xb, int sign=+1)
Construct with xb and sign.
Definition: functors.h:519
Compute a histogram on a 2D grid.
Definition: functors.h:2034
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:2041
double operator()(double x, double y) const
Access computed histogram.
Definition: functors.h:2076
Compute a histogram on a 1D grid.
Definition: functors.h:1975
Histogram(const dg::Grid1d &g1d, const std::vector< double > &in)
Construct a histogram from number of bins and an input vector.
Definition: functors.h:1981
double binwidth()
get binwidth
Definition: functors.h:2005
double operator()(double x) const
Access computed histogram.
Definition: functors.h:2013
Definition: functors.h:1937
Horner2d()
Initialize 1 coefficient to 1.
Definition: functors.h:1939
double operator()(double x, double y) const
Definition: functors.h:1949
Horner2d(std::vector< double > c, unsigned M, unsigned N)
Initialize coefficients and dimensions.
Definition: functors.h:1948
Definition: functors.h:134
DG_DEVICE T operator()(T x) const
Definition: functors.h:135
The integral of PolynomialHeaviside approximates xH(x)
Definition: functors.h:1417
IPolynomialHeaviside(double xb, double a, int sign=+1)
Construct with xb, width and sign.
Definition: functors.h:1425
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1446
DG_DEVICE double operator()(double x) const
Definition: functors.h:1430
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1448
Definition: functors.h:239
bool operator()(T x)
Definition: functors.h:243
Definition: functors.h:265
bool operator()(T x)
Definition: functors.h:275
Definition: functors.h:1181
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1192
DG_DEVICE double operator()(double x) const
Definition: functors.h:1190
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1194
InvCoshXsq(double amp, double kx)
Construct with two coefficients.
Definition: functors.h:1188
Definition: functors.h:124
DG_DEVICE T operator()(T x) const
Definition: functors.h:125
Definition: functors.h:447
DG_DEVICE double operator()(double psi) const
Definition: functors.h:451
Iris(double psi_min, double psi_max)
Definition: functors.h:448
Definition: functors.h:1010
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition: functors.h:1028
IslandXY(double lambda, double eps)
Construct Island.
Definition: functors.h:1017
Definition: functors.h:96
DG_DEVICE T operator()(const T &x) const
Definition: functors.h:97
Definition: functors.h:1555
double enstrophy() const
The total enstrophy of the dipole.
Definition: functors.h:1604
Lamb(double x0, double y0, double R, double U)
Functor returning a Lamb-dipole.
Definition: functors.h:1564
DG_DEVICE double operator()(double x, double y) const
Return the value of the dipole.
Definition: functors.h:1584
double energy() const
The total energy of the dipole.
Definition: functors.h:1612
Definition: functors.h:553
double operator()(double x)
Definition: functors.h:556
Line(double x0, double y0, double x1, double y1)
Definition: functors.h:554
Definition: functors.h:568
DG_DEVICE double operator()(double x) const
Definition: functors.h:577
LinearX(double a, double b)
Construct with two coefficients.
Definition: functors.h:575
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:581
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:579
Definition: functors.h:590
LinearY(double a, double b)
Construct with two coefficients.
Definition: functors.h:597
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:599
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:601
Definition: functors.h:610
LinearZ(double a, double b)
Construct with two coefficients.
Definition: functors.h:617
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:619
x mod m > 0 ? x mod m : x mod m + m
Definition: functors.h:208
MOD(T m)
Construct from modulo.
Definition: functors.h:214
DG_DEVICE T operator()(T x) const
Definition: functors.h:217
Definition: functors.h:297
T operator()(T x1, T x2) const
Definition: functors.h:311
Definition: functors.h:38
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:42
DG_DEVICE double operator()(double x) const
Definition: functors.h:40
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:44
Definition: functors.h:70
PLUS(T value)
Construct.
Definition: functors.h:76
DG_DEVICE T operator()(T x) const
Definition: functors.h:78
Definition: functors.h:193
DG_DEVICE T operator()(T x) const
Definition: functors.h:194
Definition: functors.h:1326
DG_DEVICE double operator()(double x) const
Definition: functors.h:1340
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1354
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1352
PolynomialHeaviside(double xb, double a, int sign=+1)
Construct with xb, width and sign.
Definition: functors.h:1335
Definition: functors.h:1378
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1397
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1399
DG_DEVICE double operator()(double x) const
Definition: functors.h:1392
PolynomialRectangle(double xl, double al, double xr, double ar)
Construct with xb, width and sign.
Definition: functors.h:1387
Definition: functors.h:488
PsiPupil(double psimax)
Definition: functors.h:489
DG_DEVICE double operator()(double psi) const
Definition: functors.h:492
Definition: functors.h:468
Pupil(double psimax)
Definition: functors.h:469
DG_DEVICE double operator()(double psi) const
Definition: functors.h:472
unsigned size() const
n()*N() (Total number of grid points)
Definition: grid.h:191
real_type x0() const
left boundary
Definition: grid.h:111
Definition: functors.h:107
DG_DEVICE T operator()(T x) const
Definition: functors.h:108
Definition: functors.h:155
DG_DEVICE T operator()(T x) const
Definition: functors.h:156
Definition: functors.h:1203
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1215
SinProfX(double amp, double bamp, double kx)
Construct.
Definition: functors.h:1211
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1217
DG_DEVICE double operator()(double x) const
Definition: functors.h:1213
Definition: functors.h:1092
SinXCosY(double amp, double bamp, double kx, double ky)
Construct.
Definition: functors.h:1101
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition: functors.h:1111
Definition: functors.h:1120
DG_DEVICE double operator()(double x) const
Definition: functors.h:1130
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1132
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1134
SinX(double amp, double bamp, double kx)
Construct.
Definition: functors.h:1128
Definition: functors.h:1036
SinXSinY(double amp, double bamp, double kx, double ky)
Construct.
Definition: functors.h:1045
DG_DEVICE double operator()(double x, double y) const
Return profile.
Definition: functors.h:1055
Definition: functors.h:1143
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1153
SinY(double amp, double bamp, double ky)
Construct.
Definition: functors.h:1151
Definition: functors.h:391
DG_DEVICE T operator()(T v, T gm, T g0, T gp, T hm, T hp) const
Definition: functors.h:395
SlopeLimiter()
Definition: functors.h:392
SlopeLimiter(Limiter l)
Definition: functors.h:393
Definition: functors.h:416
DG_DEVICE T operator()(T v, T gm, T g0, T gp, T hm, T hp) const
Definition: functors.h:420
SlopeLimiterProduct(Limiter l)
Definition: functors.h:418
SlopeLimiterProduct()
Definition: functors.h:417
Definition: functors.h:116
DG_DEVICE T operator()(T x) const
Definition: functors.h:118
Definition: functors.h:1281
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1305
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1303
DG_DEVICE double operator()(double x) const
Definition: functors.h:1298
TanhProfX(double xb, double width, int sign=1, double bgamp=0., double profamp=1.)
Construct with xb, width and sign.
Definition: functors.h:1292
Definition: functors.h:354
DG_DEVICE T operator()(T velocity, T backward, T forward) const
Definition: functors.h:356
Definition: functors.h:371
DG_DEVICE T operator()(T velocity, T backward, T forward) const
Definition: functors.h:373
Definition: functors.h:337
DG_DEVICE T operator()(T x1, T x2) const
Definition: functors.h:339
Definition: functors.h:1639
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:1677
Vortex(double x0, double y0, unsigned state, double R, double u_dipole, double kz=0)
Definition: functors.h:1650
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:1713
Shortest Distance to a collection of vertical and horizontal lines.
Definition: functors.h:2103
WallDistance(dg::Grid2d walls)
Allocate lines.
Definition: functors.h:2117
WallDistance(std::vector< double > vertical, std::vector< double > horizontal)
Allocate lines.
Definition: functors.h:2110
double operator()(double R, double Z) const
Distance to closest wall in a box.
Definition: functors.h:2122
Definition: functors.h:27
DG_DEVICE double operator()(double x, double y) const
Definition: functors.h:31
DG_DEVICE double operator()(double x) const
Definition: functors.h:29
DG_DEVICE double operator()(double x, double y, double z) const
Definition: functors.h:33
real_type x0() const
Left boundary in x.
Definition: grid.h:288
real_type y0() const
left boundary in y
Definition: grid.h:300
unsigned Nx() const
number of cells in x
Definition: grid.h:346
real_type x1() const
Right boundary in x.
Definition: grid.h:294
unsigned Ny() const
number of cells in y
Definition: grid.h:352