2 #include "cubaint_internal.hpp"
8 int cubaint::integrate (integrand_t integrand, const intmethod& IntMethod,
9 const limits& Limits, const int& ncomp,
11 int& neval, int& fail, double integral[],
12 double error[], double prob[],
13 const unsigned int& verbosity,
14 void *userdata, const options& Options)
16 assert (verbosity < 4);
18 return _integrate( integrand, IntMethod, Limits, ncomp,
19 nregions, neval, fail, integral,
20 error, prob, verbosity, userdata, Options );
23 int cubaint::integrate (integrand_tc integrand, const intmethod& IntMethod,
24 const limits& Limits, const int& ncomp,
26 int& neval, int& fail, std::complex<double> integral[],
27 std::complex<double> error[], std::complex<double> prob[],
28 const unsigned int& verbosity,
29 void *userdata, const options& Options)
31 assert (verbosity < 4);
33 return _integrate( integrand, IntMethod, Limits, 2*ncomp,
34 nregions, neval, fail, integral,
35 error, prob, verbosity, userdata, Options );
38 template <typename integrandtype, typename compreal>
39 int cubaint::_integrate (integrandtype integrand, const intmethod& IntMethod,
40 const limits& Limits, const int& ncomp,
42 int& neval, int& fail, compreal integral[],
43 compreal error[], compreal prob[],
44 const unsigned int& verbosity,
45 void *userdata, const options& Options)
47 metauserdata<integrandtype> MetaUserData(userdata, Limits, integrand);
51 Suave( Limits.size(), ncomp,
52 &masterintegrand<integrandtype,compreal>, &MetaUserData, Options.nvec,
53 Options.epsrel, Options.epsabs,
54 Options.flags | verbosity, Options.seed,
55 Options.mineval, Options.maxeval,
56 Options.Suave.nnew, Options.Suave.nmin,
57 Options.Suave.flatness,
58 Options.statefile, Options.spin,
59 &nregions, &neval, &fail,
60 reinterpret_cast<double*>(integral),
61 reinterpret_cast<double*>(error),
62 reinterpret_cast<double*>(prob) );
65 Divonne( Limits.size(), ncomp,
66 &masterintegrand<integrandtype,compreal>,
67 &MetaUserData, Options.nvec,
68 Options.epsrel, Options.epsabs,
69 Options.flags | verbosity, Options.seed,
70 Options.mineval, Options.maxeval,
71 Options.Divonne.key1, Options.Divonne.key2,
72 Options.Divonne.key3, Options.Divonne.maxpass,
73 Options.Divonne.border, Options.Divonne.maxchisq,
74 Options.Divonne.mindeviation,
75 Options.Divonne.ngiven, Options.Divonne.ldxgiven,
76 Options.Divonne.xgiven,
77 Options.Divonne.nextra, Options.Divonne.peakfinder,
78 Options.statefile, Options.spin,
79 &nregions, &neval, &fail,
80 reinterpret_cast<double*>(integral),
81 reinterpret_cast<double*>(error),
82 reinterpret_cast<double*>(prob) );
85 Vegas( Limits.size(), ncomp,
86 &masterintegrand<integrandtype,compreal>,
87 &MetaUserData, Options.nvec,
88 Options.epsrel, Options.epsabs,
89 Options.flags | verbosity, Options.seed,
90 Options.mineval, Options.maxeval,
91 Options.Vegas.nstart, Options.Vegas.nincrease, Options.Vegas.nbatch,
92 Options.Vegas.gridno, Options.statefile, Options.spin,
94 reinterpret_cast<double*>(integral),
95 reinterpret_cast<double*>(error),
96 reinterpret_cast<double*>(prob) );
99 Cuhre( Limits.size(), ncomp,
100 &masterintegrand<integrandtype,compreal>,
101 &MetaUserData, Options.nvec,
102 Options.epsrel, Options.epsabs,
103 Options.flags, Options.mineval, Options.maxeval,
105 Options.statefile, Options.spin,
106 &nregions, &neval, &fail,
107 reinterpret_cast<double*>(integral),
108 reinterpret_cast<double*>(error),
109 reinterpret_cast<double*>(prob) );
116 const cubaint::options cubaint::DefaultOptions;
118 void cubaint::kernelmap_intvar_numnum(const double& x01, double& xab,
119 const std::array<limit,2>& range)
121 xab = range[0].number + x01*( range[1].number - range[0].number );
124 void cubaint::kernelmap_intvar_numinf(const double& x01, double& xab,
125 const std::array<limit,2>& range)
127 xab = range[0].number + (1-x01)/x01;
130 void cubaint::kernelmap_intvar_infnum(const double& x01, double& xab,
131 const std::array<limit,2>& range)
133 xab = range[1].number - (1-x01)/x01;
136 void cubaint::kernelmap_intvar_infinf(const double& x01, double& xab,
137 const std::array<limit,2>& range)
139 xab = (2*x01-1) / ( 1 - pow( 2*x01-1, 2 ) );
142 double cubaint::kernelmap_intmulti_numnum(const double& x01,
143 const std::array<limit,2>& range)
145 return range[1].number - range[0].number;
148 double cubaint::kernelmap_intmulti_numinf(const double& x01,
149 const std::array<limit,2>& range)
154 double cubaint::kernelmap_intmulti_infnum(const double& x01,
155 const std::array<limit,2>& range)
160 double cubaint::kernelmap_intmulti_infinf(const double& x01,
161 const std::array<limit,2>& range)
163 const double dings = pow( 2*x01-1, 2 );
164 return 2 * (1+dings) * pow( 1-dings, -2 );
167 const cubaint::kernelmap_intvar cubaint::kernelmap_intvars[] =
168 {&cubaint::kernelmap_intvar_numnum, &cubaint::kernelmap_intvar_numinf,
169 &cubaint::kernelmap_intvar_infnum, &cubaint::kernelmap_intvar_infinf};
171 const cubaint::kernelmap_intmulti cubaint::kernelmap_intmultis[] =
172 {&cubaint::kernelmap_intmulti_numnum, &cubaint::kernelmap_intmulti_numinf,
173 &cubaint::kernelmap_intmulti_infnum, &cubaint::kernelmap_intmulti_infinf};
175 cubaint::limit::limit(const double& _number) :
176 LimType(limtype::NUM), number(_number)
180 cubaint::limit::limit(const limtype& _LimType) :
181 LimType(_LimType), number(0)
185 template <typename integrandtype, typename compreal>
186 int cubaint::masterintegrand(const int *ndim, const double x01[],
187 const int *ncomp, double f[], void *_MetaUserData)
189 metauserdata<integrandtype> *MetaUserData = (metauserdata<integrandtype>*)_MetaUserData;
192 for (int idim=0; idim<*ndim; idim++)
193 kernelmap_intvars[ MetaUserData->Limits[idim][0].LimType*2 +
194 MetaUserData->Limits[idim][1].LimType ]
195 (x01[idim], xab[idim], MetaUserData->Limits[idim]);
197 MetaUserData->integrand( ndim, xab,
199 reinterpret_cast<compreal*>(f),
200 MetaUserData->userdata );
202 for (int idim=0; idim<*ndim; idim++)
203 for (int icomp=0; icomp<*ncomp; icomp++)
205 kernelmap_intmultis[ MetaUserData->Limits[idim][0].LimType*2 +
206 MetaUserData->Limits[idim][1].LimType ]
207 (x01[idim], MetaUserData->Limits[idim]);