Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "SundanceQuadQuadrature.hpp"
00044 #include "SundanceOut.hpp"
00045 #include "SundanceGauss1D.hpp"
00046 #include "PlayaTabs.hpp"
00047
00048 using namespace Sundance;
00049 using namespace Teuchos;
00050
00051 void QuadQuadrature::getPoints(int order, Array<double>& wgt, Array<double>& x,
00052 Array<double>& y)
00053 {
00054 int p = order + 1;
00055 p = p + (p % 2);
00056 int nNodes = p / 2;
00057 Gauss1D rule(nNodes, 0.0, 1.0);
00058 Array<double> s = rule.nodes();
00059 Array<double> t = s;
00060 Array<double> w = rule.weights();
00061 int n = rule.nPoints();
00062
00063 wgt.resize(n * n);
00064 x.resize(n * n);
00065 y.resize(n * n);
00066
00067 int k = 0;
00068 for (int i = 0; i < n; i++)
00069 {
00070 double p = s[i];
00071 for (int j = 0; j < n; j++, k++)
00072 {
00073 double q = t[j];
00074 x[k] = p;
00075 y[k] = q;
00076 wgt[k] = w[i] * w[j];
00077 }
00078 }
00079 }
00080
00081 bool QuadQuadrature::test(int p)
00082 {
00083 Array<double> w;
00084 Array<double> x;
00085 Array<double> y;
00086
00087 getPoints(p, w, x, y);
00088 bool pass = true;
00089 for (int a = 0; a <= p; a++)
00090 {
00091 int bMax = p - a;
00092 for (int b = 0; b <= bMax; b++)
00093 {
00094 double sum = 0.0;
00095 for (int q = 0; q < w.length(); q++)
00096 {
00097 sum += w[q] * pow(x[q], (double) a) * pow(y[q], (double) b);
00098 }
00099 double err = fabs(sum - exact(a, b));
00100 bool localPass = err < 1.0e-14;
00101 pass = pass && localPass;
00102 if (!localPass)
00103 {
00104 fprintf(stderr,
00105 "order=%d m (%d, %d) q=%22.15g exact=%22.15g\n", p, a,
00106 b, sum, exact(a, b));
00107 std::cerr << "error = " << err << std::endl;
00108 }
00109 }
00110 }
00111 return pass;
00112 }
00113
00114 double QuadQuadrature::exact(int a, int b)
00115 {
00116 return 1.0 / (a + 1) / (b + 1);
00117 }
00118