Flow123d  jenkins-Flow123d-linux-release-multijob-282
adaptivesimpson.cc
Go to the documentation of this file.
1 
2 #include "adaptivesimpson.hh"
3 #include "functors_impl.hh"
4 #include "system/xio.h"
5 
6 #include <math.h>
7 
8 double AdaptiveSimpson::Simpson(const double& h, const double &fa,
9  const double &fc, const double &fb)
10 {
11  return (fa + fb + 4.0*fc)*(h/6.0);
12 }
13 
15  const double& h, const double &a,
16  const double &c, const double &b,
17  const double &fa, const double &fc,
18  const double &fb, const double &sx,
19  const double &tol, long &recursion)
20 {
21  recursion++;
22  double ca = 0.5*(a+c);
23  double cb = 0.5*(c+b);
24  double fca = func(ca);
25  double fcb = func(cb);
26 
27  double h2 = 0.5*h;
28  double sa = Simpson(h2,fa,fca,fc);
29  double sb = Simpson(h2,fc,fcb,fb);
30 
31  double err_est = (sa+sb-sx)/15.0;
32  if (fabs(err_est) <= tol || recursion >= MAX_RECURSION)
33  {
34  return sa+sb+err_est;
35  }
36  else
37  {
38  //DBGMSG("simpsonad, recursion: %10d \t %E\n", recursion, err_est);
39  //std::cout << "simpsonad -else " << recursion << std::endl;
40  //std::cout << h2 << " " << a << " " << ca << " " << c << " " << fa << " " << fca << " " << fc << " " << sa << std::endl;
41  return SimpsonAd(func,h2,a,ca,c,fa,fca,fc,sa,tol,recursion)
42  + SimpsonAd(func,h2,c,cb,b,fc,fcb,fb,sb,tol,recursion);
43  }
44 }
45 
47  const double& a, const double& b,
48  const double& tol )
49 {
50  //DBGMSG("AdaptiveSimpson: a(%f) b(%f)\n",a,b);
51  double c = 0.5*(b+a);
52  double fa,fb,fc;
53  double sx,res;
54  fa = func(a);
55  fb = func(b);
56  fc = func(c);
57  long recursion = 0;
58  //DBGMSG("fa=%f \tfb=%f \tfc=%f\n",fa,fb,fc);
59  sx = Simpson(b-a, fa, fc, fb);
60  res = SimpsonAd(func,b-a,a,c,b,fa,fc,fb,sx,tol,recursion);
61  //DBGMSG("\trecursions: %f\n",recursion);
62  return res;
63 }
64 
65 
66 
67 
static double SimpsonAd(FunctorBase< double > &func, const double &h, const double &a, const double &c, const double &b, const double &fa, const double &fc, const double &fb, const double &sx, const double &tol, long &recursion)
the recursive method
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
static double AdaptSimpson(FunctorBase< double > &func, const double &a, const double &b, const double &tol)
main method that starts the evaluation and calls the recursion
static double Simpson(const double &h, const double &fa, const double &fc, const double &fb)
Evaluates the Simpson&#39;s rule.
#define MAX_RECURSION