21 typedef mpfr::mpreal
mpREAL;
22 typedef const mpREAL & mpREAL_t;
24 typedef std::function<int(
unsigned yn,
mpREAL *y,
mpREAL *e,
const mpREAL & x,
void *fdata)> f1Type;
25 typedef const f1Type & f1Type_t;
26 typedef std::function<int(
unsigned yn,
mpREAL *y,
mpREAL *e,
unsigned xdim,
const mpREAL *x,
void *fdata)> fnType;
27 typedef const fnType & fnType_t;
28 typedef void (*PrintHookerType) (
mpREAL *,
mpREAL *,
size_t *,
void *);
39 int QuadPack1(
unsigned yn,
mpREAL *oval,
mpREAL *oerr, f1Type_t f, mpREAL_t epsabs, PrintHookerType PrintHooker,
void *fdata) {
41 Function F(yn,f,fdata);
43 return gk.QAG(F, 0, 1, epsabs, 0, oval, oerr, PrintHooker);
44 }
catch (
const char* reason) {
45 cout << reason << endl;
51 int QuadPackN(
unsigned yn,
mpREAL *oval,
mpREAL *oerr,
unsigned xdim, fnType_t f, mpREAL_t eps, PrintHookerType PrintHooker,
void *fdata) {
53 auto f1 = [f,
eps](
unsigned yn,
mpREAL *y,
mpREAL *e, mpREAL_t x,
void *fdata)->
int {
56 return f(yn,y,e,1,xs,fdata);
58 return QuadPack1(yn, oval, oerr, f1, eps, PrintHooker, fdata);
61 auto f1 = [f,
eps,xdim](
unsigned yn,
mpREAL *y,
mpREAL *e, mpREAL_t x,
void *fdata)->
int {
62 auto f2 =[f,x](
unsigned yn,
mpREAL *y1,
mpREAL *e1,
unsigned xdim1,
const mpREAL *xs1,
void *fdata1)->
int {
66 for(
int i=0; i<xdim1; i++) xs[i+1] = xs1[i];
68 for(
int i=0; i<xdim1; i++) xs[i] = xs1[i];
71 return f(yn,y1,e1,xdim1+1,xs,fdata1);
73 return QuadPackN(yn,y,e,xdim-1,f2,eps/xdim,NULL,fdata);
75 return QuadPack1(yn, oval, oerr, f1, eps, PrintHooker, fdata);
86ex QuadMP_vec::mp2ex(
const mpREAL & num) {
90 string sn = oss.str();
91 numeric ret(sn.c_str());
97 self->IntegrandMP(xdim, x, ydim, y, self->mpParameter, self->mpLambda);
100 for(
int j=0; j<ydim; j++) {
101 if(!isfinite(y[j])) { ok =
false;
break; }
104 mpfr::mpreal::set_default_prec(mpfr::digits2bits(self->MPDigits*10));
105 self->IntegrandMP(xdim, x, ydim, y, self->mpParameter, self->mpLambda);
106 mpfr::mpreal::set_default_prec(mpfr::digits2bits(self->MPDigits));
108 for(
int j=0; j<ydim; j++) e[j] = 0;
114 if(*nrun == self->nGK + 1979)
return;
115 if(self->RunTime>0) {
116 auto cur_timer = time(NULL);
117 auto used_time = difftime(cur_timer,self->StartTimer);
118 if(used_time>self->RunTime) {
120 *nrun = self->nGK + 1979;
129 auto e0 = epsabs[0].toString(3);
130 auto e1 = epsabs[1].toString(3);
131 cout <<
" L: " << (*nrun) <<
", ";
132 if(self->ReIm==3 || self->ReIm==1) cout <<
"[" << r0 <<
", " << e0 <<
"]";
133 if(self->ReIm==3 || self->ReIm==2) cout <<
"+I*[" << r1 <<
", " << e1 <<
"]";
136 for(
int j=0; j<self->YDim; j++) {
138 auto e = epsabs[j].toString(3);
139 if(j==0) cout <<
" L: " << (*nrun) <<
", ";
140 else cout <<
" >>L: " << (*nrun) <<
", ";
141 cout <<
"[" << r <<
", " << e <<
"]";
149 for(
int j=0; j<self->YDim; j++) {
150 if((epsabs[j] > self->EpsAbs+1E-50Q) && (epsabs[j] > fabs(result[j])*self->EpsRel+1E-50Q)) {
157 *nrun = self->nGK + 1979;
163 fn << pid <<
".int.done";
166 *nrun = self->nGK + 1979;
168 cmd <<
"rm " << fn.str();
169 auto rc = system(cmd.str().c_str());
170 if(
Verbose>10) cout <<
" Exit: " << fn.str() << endl;
175 if(mpfr_buildopt_tls_p()<=0)
throw Error(
"Integrate: mpfr_buildopt_tls_p()<=0.");
177 mpfr::mpreal::set_default_prec(mpfr::digits2bits(
MPDigits));
178 mpPi = mpfr::const_pi();
180 mpiEpsilon = complex<mpREAL>(0,mpfr::machine_epsilon()*100);
182 unsigned int xdim =
XDim;
183 unsigned int ydim =
YDim;
184 mpREAL result[ydim], estabs[ydim];
188 _nGK_ = n==0 ?
nGK : n;
194 for(
int j=0; j<ydim; j++) abs_res += result[j]*result[j];
195 abs_res = sqrt(abs_res);
197 for(
int j=0; j<ydim; j++) abs_est += estabs[j]*estabs[j];
198 abs_est = sqrt(abs_est);
199 mpREAL mpfr_eps = 10*mpfr::machine_epsilon();
200 if( (abs_res < mpfr_eps) && (abs_est < mpfr_eps) ) {
201 cout <<
ErrColor <<
"QuadMP_vec Failed with 0 result returned!" <<
RESET << endl;
207 bool any_NAN =
false;
208 for(
int j=0; j<ydim; j++) {
209 if(isnan(result[j])) {
214 if(any_NAN) FResult =
NaN;
218 FResult = VE(mp2ex(result[0]), mp2ex(estabs[0])) + VE(mp2ex(result[1]), mp2ex(estabs[1])) * I;
221 for(
int j=0; j<ydim; j++) res.append(VE(mp2ex(result[j]), mp2ex(estabs[j])));
complex< mpREAL > mpCOMPLEX
class used to wrap error message
almost the same as QuadMP, using vector to avoid stack overflow for large dimension in Y
PrintHookerType PrintHooker
static void DefaultPrintHooker(mpREAL *, mpREAL *, size_t *, void *)
virtual ex Integrate(size_t n=0) override
static int Wrapper(unsigned yn, mpREAL *y, mpREAL *e, unsigned xdim, const mpREAL *x, void *fdata)
bool file_exists(string fn)