6#define M_PI 3.14159265358979323846
33 double operator()(
double x,
double y,
double z)
const{
return 0.;}
44 double operator()(
double x,
double y,
double z)
const{
return 1.;}
60 double operator()(
double x,
double y)
const{
return m_value;}
62 double operator()(
double x,
double y,
double z)
const{
return m_value;}
68template <
class T =
double>
76 PLUS( T value): x_(value){}
84template<
class T =
double >
94template <
class T =
double>
105template <
class T =
double>
122template <
class T =
double>
132template <
class T =
double>
139template <
class T =
double>
153template <
class T =
double>
160template <
class T =
double>
165 T absx =
x>0 ?
x : -
x;
166 T absy =
y>0 ?
y : -
y;
167 return absx > absy ? absx : absy;
172template <
class T =
double>
177 T absx =
x<0 ? -
x :
x;
178 T absy =
y<0 ? -
y :
y;
179 return absx < absy ? absx : absy;
191template <
class T =
double>
195 if (
x >= 0.0)
return x;
206template <
class T=
double>
218 return (fmod(
x,m_m) < 0 ) ? (m_m + fmod(
x,m_m)) : fmod(
x,m_m);
270 if(
x > 1e100 ||
x < -1e100)
276 if( !std::isfinite(
x))
278 if(
x > 1e100 ||
x < -1e100)
303 if( x1 > 0 && x2 > 0)
305 else if( x1 < 0 && x2 < 0)
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);
324 return this->
operator()( this->
operator()( x1, x2), x3);
343 return 2.*x1*x2/(x1+x2);
389template<
class Limiter>
397 return +hm*m_l( g0, gm);
399 return -hp*m_l( gp, g0);
414template<
class Limiter>
421 return v*m_s(v,gm,g0,gp,hm,hp);
448 Iris(
double psi_min,
double psi_max ):
449 m_psimin(psi_min), m_psimax(psi_max) { }
453 if( psi > m_psimax)
return 0.;
454 if( psi < m_psimin)
return 0.;
458 double m_psimin, m_psimax;
474 if( psi > psimax_)
return 0.;
494 if( psi > psimax_)
return psimax_;
520 m_xb(xb), m_s(sign){ }
525 if( (
x < m_xb && m_s == 1) || (
x > m_xb && m_s == -1))
return 0.;
539 Distance(
double x0,
double y0): m_x0(x0), m_y0(y0){}
542 return sqrt( (
x-m_x0)*(
x-m_x0) + (
y-m_y0)*(
y-m_y0));
554 Line(
double x0,
double y0,
double x1,
double y1) :
555 m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1){}
557 return m_y1*(
x-m_x0)/(m_x1-m_x0) + m_y0*(
x-m_x1)/(m_x0-m_x1);
560 double m_x0, m_y0, m_x1, m_y1;
599 double operator()(
double x,
double y,
double z)
const {
return a_*
y+b_;}
619 double operator()(
double x,
double y,
double z)
const{
return a_*
z+b_;}
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");
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) );
680 double m_x0, m_y0, m_sigma_x, m_sigma_y, m_amp;
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");
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.) );
720 double xbar = (
x-x0_)/sigmaX_;
721 double ybar = (
y-y0_)/sigmaY_;
722 if( xbar*xbar + ybar*ybar < 1.)
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;
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;
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;
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;
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_
762 double x0_, y0_, sigmaX_, sigmaY_, amp_;
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");
790 double xbar = (
x-x0_)/sigmaX_;
792 return amp_*exp( 1. + 1./( xbar*xbar -1.) );
797 double xbar = (
x-x0_)/sigmaX_;
803 double x0_, sigmaX_, amp_;
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");
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) );
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) );
870 double m_x0, m_y0, m_z0, m_sigma_x, m_sigma_y, m_sigma_z, m_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");
895 return m_amp* exp( -((
x-m_x0)*(
x-m_x0)/2./m_sigma_x/m_sigma_x ));
908 double m_x0, m_sigma_x, m_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");
944 return m_amp*exp( -((
y-m_y0)*(
y-m_y0)/2./m_sigma_y/m_sigma_y) );
947 double m_y0, m_sigma_y, m_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");
982 return m_amp*exp( -((
z-m_z0)*(
z-m_z0)/2./m_sigma_z/m_sigma_z) );
999 return m_amp*exp( -((
z-m_z0)*(
z-m_z0)/2./m_sigma_z/m_sigma_z) );
1002 double m_z0, m_sigma_z, m_amp;
1017 IslandXY(
double lambda,
double eps):lambda_(lambda), eps_(eps){
1018 assert( lambda != 0 &&
"Lambda parameter in IslandXY must not be zero!");
1028 double operator()(
double x,
double y)
const{
return lambda_*log(cosh(
x/lambda_)+eps_*cos(
y/lambda_));}
1030 double lambda_,eps_;
1045 SinXSinY(
double amp,
double bamp,
double kx,
double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1055 double operator()(
double x,
double y)
const{
return bamp_+amp_*sin(
x*kx_)*sin(
y*ky_);}
1057 double amp_,bamp_,kx_,ky_;
1073 CosXCosY(
double amp,
double bamp,
double kx,
double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1083 double operator()(
double x,
double y)
const{
return bamp_+amp_*cos(
x*kx_)*cos(
y*ky_);}
1085 double amp_,bamp_,kx_,ky_;
1101 SinXCosY(
double amp,
double bamp,
double kx,
double ky):amp_(amp), bamp_(bamp),kx_(kx),ky_(ky){}
1111 double operator()(
double x,
double y)
const{
return bamp_+amp_*sin(
x*kx_)*cos(
y*ky_);}
1113 double amp_,bamp_,kx_,ky_;
1128 SinX(
double amp,
double bamp,
double kx):amp_(amp), bamp_(bamp),kx_(kx){}
1136 double amp_,bamp_,kx_;
1151 SinY(
double amp,
double bamp,
double ky):amp_(amp), bamp_(bamp),ky_(ky){}
1153 double operator()(
double x,
double y)
const{
return bamp_+amp_*sin(
y*ky_);}
1155 double amp_,bamp_,ky_;
1170 CosY(
double amp,
double bamp,
double ky):amp_(amp), bamp_(bamp),ky_(ky){}
1172 double operator()(
double x,
double y)
const{
return bamp_+amp_*cos(
y*ky_);}
1174 double amp_,bamp_,ky_;
1190 double operator()(
double x)
const{
return m_amp/cosh(
x*m_kx)/cosh(
x*m_kx);}
1211 SinProfX(
double amp,
double bamp,
double kx):m_amp(amp), m_bamp(bamp),m_kx(kx){}
1213 double operator()(
double x)
const{
return m_bamp+m_amp*(1.-sin(
x*m_kx));}
1219 double m_amp, m_bamp, m_kx;
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!");
1244 double m_amp, m_bamp, m_ln;
1262 m_psimax(psimax), m_alpha(alpha) {
1263 assert( alpha!= 0 &&
"Damping width in GaussianDamping must not be zero");
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);
1273 double m_psimax, m_alpha;
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!");
1300 return profa_*0.5*(1.+s_*tanh((
x-xb_)/w_))+bga_;
1336 x0(xb), a(a), m_s(sign){
1337 assert( a!=0 &&
"PolynomialHeaviside width must not be zero");
1342 if( m_s == -1)
x = 2*x0-
x;
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);
1388 m_hl( xl, al, +1), m_hr( xr, ar, -1) {
1389 assert( xl < xr &&
"left boundary must be left of right boundary");
1394 return m_hl(
x)*m_hr(
x);
1426 x0(xb), a(a), m_s(sign){
1427 assert( a!=0 &&
"IPolynomialHeaviside width must not be zero");
1432 if( m_s == -1)
x = 2*x0-
x;
1434 if (
x < x0-a) result = x0;
1435 else if (
x > x0+a) result =
x;
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;
1478 assert( a!=0 &&
"DPolynomialHeaviside width must not be zero");
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);
1524 m_alpha(alpha), m_etac(eta_c), m_s(order), m_n(n) {}
1527 double eta = (double)i/(
double)(m_n-1);
1528 if( m_n == 1) eta = 0.;
1532 return exp( -m_alpha*pow( (eta-m_etac)/(1.-m_etac), 2*m_s));
1536 double m_alpha, m_etac;
1564 Lamb(
double x0,
double y0,
double R,
double U):R_(R), U_(U), x0_(x0), y0_(y0)
1566 gamma_ = 3.83170597020751231561;
1586 double radius = sqrt( (
x-x0_)*(
x-x0_) + (
y-y0_)*(
y-y0_));
1587 double theta = atan2( (
y-y0_),(
x-x0_));
1591 return 2.*lambda_*U_*_j1(lambda_*radius)/j_*cos( theta);
1593 return 2.*lambda_*U_*j1( lambda_*radius)/j_*cos( theta);
1614 double R_, U_, x0_, y0_, lambda_, gamma_, j_;
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;
1656 b_[0] = 0.03827327723;
1657 b_[1] = 0.07071067810 ;
1658 b_[2] = 0.07071067810 ;
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;
1686 r *( 1 +beta*beta/g_[s_]/g_[s_] )
1688 - R_* beta*beta/g_[s_]/g_[s_] *_j1(g_[s_]*r/R_)/_j1(g_[s_])
1690 - R_ * beta*beta/g_[s_]/g_[s_] * j1(g_[s_]*r/R_)/ j1(g_[s_])
1693 return u_d * R_* bessk1(beta*r/R_)/bessk1(beta)*cos(theta)/norm;
1720 double bessk1(
double x)
const
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)))))));
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)))))));
1741 double bessi1(
double x)
const
1745 if ((ax=fabs(x)) < 3.75)
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))))));
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));
1760 return x < 0.0 ? -ans : ans;
1764 double R_, b_[3], u_d;
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)
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);
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.;
1816 std::minstd_rand generator;
1817 std::normal_distribution<double> ndistribution( 0.0, 1.0);
1818 std::uniform_real_distribution<double> udistribution(0.0,tpi);
1819 for (
unsigned j=1;j<=N_kZ_;j++)
1821 double kZ2=tpi2*(j-N_kZh)*(j-N_kZh)/(N_kZ2);
1822 for (
unsigned i=1;i<=N_kR_;i++)
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);
1827 sqEkvec[
z]=pow(kvec[
z]*4.*k0/(kvec[
z]+k0)/(kvec[
z]+k0),gamma_/2.);
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]);
1863 double f, kappa, RR, ZZ;
1867 for (
unsigned j=0;j<N_kZ_;j++)
1869 for (
unsigned i=0;i<N_kR_;i++)
1872 kappa= RR*unif1[
z]+ZZ*unif2[
z];
1873 f+= sqEkvec[
z]*alpha[
z]*cos(kvec[
z]*kappa+theta[
z]);
1876 return amp_*norm_*f;
1909 for (
unsigned j=0;j<N_kZ_;j++)
1911 for (
unsigned i=0;i<N_kR_;i++)
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]);
1918 return amp_*norm_*f;
1921 unsigned N_kR_,N_kZ_;
1922 double R_min_, Z_min_;
1923 double gamma_, L_E_;
1926 std::vector<double> kvec;
1927 std::vector<double> sqEkvec;
1928 std::vector<double> unif1, unif2, normal1,normal2,alpha,theta;
1948 Horner2d( std::vector<double> c,
unsigned M,
unsigned N): m_c(c), m_M(M), m_N(N){}
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);
1957 double horner(
const double * c,
unsigned M,
double x)
const
1960 for(
unsigned i=0; i<M-1; i++)
1964 std::vector<double> m_c;
1973template <
class container = thrust::host_vector<
double> >
1984 binwidth_(g1d_.h()),
1987 for (
unsigned j=0;j<in_.size();j++)
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));
1995 unsigned Ampmax = (unsigned)
thrust::reduce( count_.begin(), count_.end(),0., thrust::maximum<double>() );
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));
2023 const std::vector<double> in_;
2032template <
class container = thrust::host_vector<
double> >
2045 binwidthx_(g2d_.hx()),
2046 binwidthy_(g2d_.hy()),
2050 for (
unsigned j=0;j<iny_.size();j++)
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));
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.;
2063 unsigned Ampmax = (unsigned)
thrust::reduce( count_.begin(), count_.end(),0.,thrust::maximum<double>() );
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 ];
2089 const std::vector<double> inx_,iny_;
2090 double binwidthx_,binwidthy_;
2110 WallDistance( std::vector<double> vertical, std::vector<double> horizontal) :
2111 m_vertical(vertical), m_horizontal( horizontal) {}
2118 m_horizontal({walls.y0(), walls.y1()}){}
2124 std::vector<double> dist( 1, 1e100);
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());
2132 std::vector<double> m_vertical;
2133 std::vector<double> m_horizontal;
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
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
@ 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
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