19 using std::scientific;
20 using std::setprecision;
24 using namespace UA_CoMP::Num;
31 template <
typename Quad,
typename Integrand>
32 void verifyQuad(
double b,
double e, Quad quad, Integrand ftor)
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);
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)
50 }
catch (std::exception& e) {
51 cout <<
"std::exception: " << e.what() << endl;
53 cout <<
"Unknown exception in the verifyQuad procedure." << endl;
64 cout <<
"Using AdaptiveQuadrature: " << endl << endl;
65 string const separator =
"\n\n------------------------------------------------------\n";
70 cout << separator <<
"Simpson vs Simpson-Bisector:" << endl;
72 verifyQuad(-1.0, 15.0, quad, ftor1);
75 cout << separator <<
"GaussLegendre8 vs GaussLegendre8-Bisector:" << endl;
77 verifyQuad(-10.0, 35.0, quad, ftor1);
78 cout << endl <<
" reset convergenceTolerance and initialCellCount:" << endl;
81 verifyQuad(-10.0, 35.0, quad, ftor1);
84 cout << separator <<
"GaussLegendre 16 vs 32:" << endl;
86 verifyQuad(0.0, 50.0, quad, ftor2);
89 cout << separator <<
"GaussLegendre 16 vs 32 with initial cell count 20:" << endl;
92 verifyQuad(0.0, 50.0, quad, ftor2);
95 cout << separator <<
"Simpson vs GaussLegendre2 and AbsoluteDifference:" << endl;
98 verifyQuad(0.0, 5.0, quad, ftor2);
101 cout << separator <<
"AGL_Quadrature and AbsoluteDifference:" << endl;
103 verifyQuad(0.0, 5.0, quad, ftor2);
The AdaptiveQuadrature is a host class with policy classes QuadRule1, QuadRule2, ErrorPolicy and Conv...
Elementary Quadrature Rules.
AGL (Adaptive GaussLegendre) Quadrature.
void setConvergenceTolerance(double x)
Set the convergence tolerance.
void setInitialCellCount(unsigned int i)
Set initial cell count.
int main()
Demonstrate the use of the AdaptiveQuadrature algorithm with a variety of functors.
AGL (Adaptive GaussLegendre) Quadrature.