Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
aquad_demo.cpp
Go to the documentation of this file.
1 
8 #include "AGL_Quadrature.h"
9 #include "OscillatoryFunctor.h"
10 #include "PowerFunctor.h"
11 #include "SimpleRules.h"
12 
13 #include <iomanip>
14 
15 using std::boolalpha;
16 using std::cout;
17 using std::endl;
18 using std::get;
19 using std::scientific;
20 using std::setprecision;
21 using std::setw;
22 using std::string;
23 using std::tuple;
24 using namespace UA_CoMP::Num;
25 
26 namespace {
31 template <typename Quad, typename Integrand>
32 void verifyQuad(double b, double e, Quad quad, Integrand ftor)
33 {
34  try {
35  tuple<bool, typename Integrand::result_type, typename Integrand::result_type, unsigned int> const
36  retValue = quad.evaluate(b, e, ftor);
37  bool const stat = get<0>(retValue);
38  double const sum1 = get<1>(retValue);
39  double const sum2 = get<2>(retValue);
40  unsigned int const cellCount = get<3>(retValue);
41  double const check = ftor.getIntegral()(b, e);
42 
43  cout << boolalpha << scientific << setprecision(12);
44  cout << " AdaptiveQuadrature status: " << stat << endl
45  << " sum1: " << setw(20) << sum1 << endl
46  << " sum2: " << setw(20) << sum2 << " diff: " << setw(20) << fabs(sum1 - sum2) << endl
47  << " cellCount: " << cellCount << endl
48  << " exact value: " << setw(20) << check << " diff: " << setw(20) << fabs(sum2 - check)
49  << endl;
50  } catch (std::exception& e) {
51  cout << "std::exception: " << e.what() << endl;
52  } catch (...) {
53  cout << "Unknown exception in the verifyQuad procedure." << endl;
54  }
55 }
56 } // namespace
57 
62 int main()
63 {
64  cout << "Using AdaptiveQuadrature: " << endl << endl;
65  string const separator = "\n\n------------------------------------------------------\n";
66  OscillatoryFunctor const ftor1(0.0, 10.0);
67  OscillatoryFunctor const ftor2(-1.0, 20.0);
68 
69  {
70  cout << separator << "Simpson vs Simpson-Bisector:" << endl;
71  AdaptiveQuadrature<SimpsonRule> quad(1.0e-6, 50, 1000);
72  verifyQuad(-1.0, 15.0, quad, ftor1);
73  }
74  {
75  cout << separator << "GaussLegendre8 vs GaussLegendre8-Bisector:" << endl;
76  AdaptiveQuadrature<GaussLegendre8Rule> quad(1.0e-2, 1, 1500);
77  verifyQuad(-10.0, 35.0, quad, ftor1);
78  cout << endl << " reset convergenceTolerance and initialCellCount:" << endl;
79  quad.setConvergenceTolerance(1.0e-12);
80  quad.setInitialCellCount(10);
81  verifyQuad(-10.0, 35.0, quad, ftor1);
82  }
83  {
84  cout << separator << "GaussLegendre 16 vs 32:" << endl;
86  verifyQuad(0.0, 50.0, quad, ftor2);
87  }
88  {
89  cout << separator << "GaussLegendre 16 vs 32 with initial cell count 20:" << endl;
91  quad.setInitialCellCount(20);
92  verifyQuad(0.0, 50.0, quad, ftor2);
93  }
94  {
95  cout << separator << "Simpson vs GaussLegendre2 and AbsoluteDifference:" << endl;
97  2, 100);
98  verifyQuad(0.0, 5.0, quad, ftor2);
99  }
100  {
101  cout << separator << "AGL_Quadrature and AbsoluteDifference:" << endl;
102  AGL_Quadrature<8, 16, AbsoluteDifference> quad(1.0e-5, 2, 100);
103  verifyQuad(0.0, 5.0, quad, ftor2);
104  }
105 
106  return 0;
107 }
The AdaptiveQuadrature is a host class with policy classes QuadRule1, QuadRule2, ErrorPolicy and Conv...
Elementary Quadrature Rules.
AGL (Adaptive GaussLegendre) Quadrature.
Power functor.
void setConvergenceTolerance(double x)
Set the convergence tolerance.
void setInitialCellCount(unsigned int i)
Set initial cell count.
Oscillatory functor.
int main()
Demonstrate the use of the AdaptiveQuadrature algorithm with a variety of functors.
Definition: aquad_demo.cpp:62
AGL (Adaptive GaussLegendre) Quadrature.