6#define M_PI 3.14159265358979323846
10#include <thrust/random/linear_congruential_engine.h>
11#include <thrust/random/normal_distribution.h>
12#include <thrust/random/uniform_real_distribution.h>
29template <
class T =
double>
37 PLUS( T value): x_(value){}
45template<
class T =
double >
55template <
class T =
double>
66template <
class T =
double>
83template <
class T =
double>
93template <
class T =
double>
100template <
class T =
double>
114template <
class T =
double>
121template <
class T =
double>
126 T absx =
x>0 ?
x : -
x;
127 T absy =
y>0 ?
y : -
y;
128 return absx > absy ? absx : absy;
133template <
class T =
double>
138 T absx =
x<0 ? -
x :
x;
139 T absy =
y<0 ? -
y :
y;
140 return absx < absy ? absx : absy;
152template <
class T =
double>
156 if (
x >= 0.0)
return x;
167template <
class T=
double>
179 return (fmod(
x,m_m) < 0 ) ? (m_m + fmod(
x,m_m)) : fmod(
x,m_m);
231 if(
x > 1e100 ||
x < -1e100)
237 if( !std::isfinite(
x))
239 if(
x > 1e100 ||
x < -1e100)
264 if( x1 > 0 && x2 > 0)
266 else if( x1 < 0 && x2 < 0)
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);
285 return this->
operator()( this->
operator()( x1, x2), x3);
297 template<
class ...Ts>
300 return m_dist(m_rng);
303 thrust::minstd_rand m_rng;
304 thrust::uniform_real_distribution<T> m_dist;
326 return 2.*x1*x2/(x1+x2);
372template<
class Limiter>
380 return +hm*m_l( g0, gm);
382 return -hp*m_l( gp, g0);
397template<
class Limiter>
404 return v*m_s(v,gm,g0,gp,hm,hp);
431 Iris(
double psi_min,
double psi_max ):
432 m_psimin(psi_min), m_psimax(psi_max) { }
436 if( psi > m_psimax)
return 0.;
437 if( psi < m_psimin)
return 0.;
441 double m_psimin, m_psimax;
457 if( psi > psimax_)
return 0.;
477 if( psi > psimax_)
return psimax_;
503 m_xb(xb), m_s(sign){ }
508 if( (
x < m_xb && m_s == 1) || (
x > m_xb && m_s == -1))
return 0.;
522 Distance(
double x0,
double y0): m_x0(x0), m_y0(y0){}
525 return sqrt( (
x-m_x0)*(
x-m_x0) + (
y-m_y0)*(
y-m_y0));
537 Line(
double x0,
double y0,
double x1,
double y1) :
538 m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1){}
540 return m_y1*(
x-m_x0)/(m_x1-m_x0) + m_y0*(
x-m_x1)/(m_x0-m_x1);
543 double m_x0, m_y0, m_x1, m_y1;
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");
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) );
662 double m_x0, m_y0, m_sigma_x, m_sigma_y, m_amp;
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");
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.) );
702 double xbar = (
x-x0_)/sigmaX_;
703 double ybar = (
y-y0_)/sigmaY_;
704 if( xbar*xbar + ybar*ybar < 1.)
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;
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;
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;
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;
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_
744 double x0_, y0_, sigmaX_, sigmaY_, amp_;
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");
772 double xbar = (
x-x0_)/sigmaX_;
774 return amp_*exp( 1. + 1./( xbar*xbar -1.) );
779 double xbar = (
x-x0_)/sigmaX_;
785 double x0_, sigmaX_, amp_;
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");
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) );
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) );
852 double m_x0, m_y0, m_z0, m_sigma_x, m_sigma_y, m_sigma_z, m_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");
877 return m_amp* exp( -((
x-m_x0)*(
x-m_x0)/2./m_sigma_x/m_sigma_x ));
890 double m_x0, m_sigma_x, m_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");
925 return m_amp*exp( -((
y-m_y0)*(
y-m_y0)/2./m_sigma_y/m_sigma_y) );
928 double m_y0, m_sigma_y, m_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");
963 return m_amp*exp( -((
z-m_z0)*(
z-m_z0)/2./m_sigma_z/m_sigma_z) );
978 return m_amp*exp( -((
z-m_z0)*(
z-m_z0)/2./m_sigma_z/m_sigma_z) );
981 double m_z0, m_sigma_z, m_amp;
996 IslandXY(
double lambda,
double eps):lambda_(lambda), eps_(eps){
997 assert( lambda != 0 &&
"Lambda parameter in IslandXY must not be zero!");
1007 double operator()(
double x,
double y)
const{
return lambda_*log(cosh(
x/lambda_)+eps_*cos(
y/lambda_));}
1009 double lambda_,eps_;
1024 SinXSinY(
double amp,
double bamp,
double kx,
double ky):amp_(
amp), bamp_(bamp),kx_(kx),ky_(ky){}
1034 double operator()(
double x,
double y)
const{
return bamp_+amp_*sin(
x*kx_)*sin(
y*ky_);}
1036 double amp_,bamp_,kx_,ky_;
1052 CosXCosY(
double amp,
double bamp,
double kx,
double ky):amp_(
amp), bamp_(bamp),kx_(kx),ky_(ky){}
1062 double operator()(
double x,
double y)
const{
return bamp_+amp_*cos(
x*kx_)*cos(
y*ky_);}
1064 double amp_,bamp_,kx_,ky_;
1080 SinXCosY(
double amp,
double bamp,
double kx,
double ky):amp_(
amp), bamp_(bamp),kx_(kx),ky_(ky){}
1090 double operator()(
double x,
double y)
const{
return bamp_+amp_*sin(
x*kx_)*cos(
y*ky_);}
1092 double amp_,bamp_,kx_,ky_;
1107 SinX(
double amp,
double bamp,
double kx):amp_(
amp), bamp_(bamp),kx_(kx){}
1115 double amp_,bamp_,kx_;
1130 SinY(
double amp,
double bamp,
double ky):amp_(
amp), bamp_(bamp),ky_(ky){}
1134 double amp_,bamp_,ky_;
1149 CosY(
double amp,
double bamp,
double ky):amp_(
amp), bamp_(bamp),ky_(ky){}
1153 double amp_,bamp_,ky_;
1169 double operator()(
double x)
const{
return m_amp/cosh(
x*m_kx)/cosh(
x*m_kx);}
1190 SinProfX(
double amp,
double bamp,
double kx):m_amp(
amp), m_bamp(bamp),m_kx(kx){}
1192 double operator()(
double x)
const{
return m_bamp+m_amp*(1.-sin(
x*m_kx));}
1198 double m_amp, m_bamp, m_kx;
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!");
1223 double m_amp, m_bamp, m_ln;
1241 m_psimax(psimax), m_alpha(
alpha) {
1242 assert(
alpha!= 0 &&
"Damping width in GaussianDamping must not be zero");
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);
1252 double m_psimax, m_alpha;
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!");
1279 return profa_*0.5*(1.+s_*tanh((
x-xb_)/w_))+bga_;
1315 x0(xb), a(a), m_s(sign){
1316 assert( a!=0 &&
"PolynomialHeaviside width must not be zero");
1321 if( m_s == -1)
x = 2*x0-
x;
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);
1367 m_hl( xl, al, +1), m_hr( xr, ar, -1) {
1368 assert( xl < xr &&
"left boundary must be left of right boundary");
1373 return m_hl(
x)*m_hr(
x);
1405 x0(xb), a(a), m_s(sign){
1406 assert( a!=0 &&
"IPolynomialHeaviside width must not be zero");
1411 if( m_s == -1)
x = 2*x0-
x;
1413 if (
x < x0-a) result = x0;
1414 else if (
x > x0+a) result =
x;
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;
1458 assert( a!=0 &&
"DPolynomialHeaviside width must not be zero");
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);
1504 m_alpha(
alpha), m_etac(eta_c), m_s(order), m_n(
n) {}
1507 double eta = (double)i/(
double)(m_n-1);
1508 if( m_n == 1) eta = 0.;
1512 return exp( -m_alpha*pow( (eta-m_etac)/(1.-m_etac), 2*m_s));
1516 double m_alpha, m_etac;
1544 Lamb(
double x0,
double y0,
double R,
double U):R_(R), U_(U), x0_(x0), y0_(y0)
1546 gamma_ = 3.83170597020751231561;
1566 double radius = sqrt( (
x-x0_)*(
x-x0_) + (
y-y0_)*(
y-y0_));
1567 double theta = atan2( (
y-y0_),(
x-x0_));
1571 return 2.*lambda_*U_*_j1(lambda_*radius)/j_*cos( theta);
1573 return 2.*lambda_*U_*j1( lambda_*radius)/j_*cos( theta);
1594 double R_, U_, x0_, y0_, lambda_, gamma_, j_;
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;
1636 b_[0] = 0.03827327723;
1637 b_[1] = 0.07071067810 ;
1638 b_[2] = 0.07071067810 ;
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;
1668 - R_*
beta*
beta/g_[s_]/g_[s_] *_j1(g_[s_]*r/R_)/_j1(g_[s_])
1670 - R_ *
beta*
beta/g_[s_]/g_[s_] * j1(g_[s_]*r/R_)/ j1(g_[s_])
1673 return u_d * R_* bessk1(
beta*r/R_)/bessk1(
beta)*cos(theta)/norm;
1701 double bessk1(
double x)
const
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)))))));
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)))))));
1722 double bessi1(
double x)
const
1726 if ((ax=fabs(x)) < 3.75)
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))))));
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));
1741 return x < 0.0 ? -ans : ans;
1745 double R_, b_[3], u_d;
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)
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);
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.;
1797 thrust::minstd_rand generator;
1798 thrust::normal_distribution<double> ndistribution( 0.0, 1.0);
1799 thrust::uniform_real_distribution<double> udistribution(0.0,tpi);
1800 for (
unsigned j=1;j<=N_kZ_;j++)
1802 double kZ2=tpi2*(j-N_kZh)*(j-N_kZh)/(N_kZ2);
1803 for (
unsigned i=1;i<=N_kR_;i++)
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);
1808 sqEkvec[
z]=pow(kvec[
z]*4.*k0/(kvec[
z]+k0)/(kvec[
z]+k0),gamma_/2.);
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]);
1844 double f, kappa, RR, ZZ;
1848 for (
unsigned j=0;j<N_kZ_;j++)
1850 for (
unsigned i=0;i<N_kR_;i++)
1853 kappa= RR*unif1[
z]+ZZ*unif2[
z];
1854 f+= sqEkvec[
z]*alpha[
z]*cos(kvec[
z]*kappa+theta[
z]);
1857 return amp_*norm_*f;
1889 for (
unsigned j=0;j<N_kZ_;j++)
1891 for (
unsigned i=0;i<N_kR_;i++)
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]);
1898 return amp_*norm_*f;
1901 unsigned N_kR_,N_kZ_;
1902 double R_min_, Z_min_;
1903 double gamma_, L_E_;
1906 std::vector<double> kvec;
1907 std::vector<double> sqEkvec;
1908 std::vector<double> unif1, unif2, normal1,normal2,alpha,theta;
1914inline double horner(
const double * c,
unsigned M,
double x)
1917 for(
unsigned i=0; i<M-1; i++)
1940 Horner1d(
const std::vector<double>& c): m_c(c), m_M(c.size()), m_prev( {1e300,1e300}){
1952 m_prev[1] = detail::horner( &m_c[0], m_M,
x);
1957 std::vector<double> m_c;
1959 mutable std::array<double,2> m_prev;
1970 Horner2d(): m_c( 1, 1), m_cx( 1,1), m_M(1), m_N(1), m_prev( {0,0,1}){}
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)
1996 if( m_prev[1] ==
y && m_prev[0] ==
x)
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;
2006 std::vector<double> m_c;
2007 mutable std::vector<double> m_cx;
2009 mutable std::array<double,3> m_prev;
2016template <
class container = thrust::host_vector<
double> >
2027 binwidth_(g1d_.h()),
2030 for (
unsigned j=0;j<in_.size();j++)
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));
2038 unsigned Ampmax = (unsigned)thrust::reduce( count_.begin(), count_.end(),0., thrust::maximum<double>() );
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));
2066 const std::vector<double> in_;
2075template <
class container = thrust::host_vector<
double> >
2088 binwidthx_(g2d_.hx()),
2089 binwidthy_(g2d_.hy()),
2093 for (
unsigned j=0;j<iny_.size();j++)
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));
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.;
2106 unsigned Ampmax = (unsigned)thrust::reduce( count_.begin(), count_.end(),0.,thrust::maximum<double>() );
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 ];
2132 const std::vector<double> inx_,iny_;
2133 double binwidthx_,binwidthy_;
2153 WallDistance( std::vector<double> vertical, std::vector<double> horizontal) :
2154 m_vertical(vertical), m_horizontal( horizontal) {}
2161 m_horizontal({walls.y0(), walls.y1()}){}
2167 std::vector<double> dist( 1, 1e100);
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());
2175 std::vector<double> m_vertical;
2176 std::vector<double> m_horizontal;
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
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
@ 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
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
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
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
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
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
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
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
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
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
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
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