54 #include "Teuchos_oblackholestream.hpp"
55 #include "Teuchos_RCP.hpp"
56 #include "Teuchos_GlobalMPISession.hpp"
58 using namespace Intrepid;
63 long double evalQuad(std::vector<int> power,
int dimension,
64 std::vector<int> order,
65 std::vector<EIntrepidBurkardt> rule) {
68 order[0]--; order[1]--;
70 lineCub.update(1.0,lineCub1,1.0);
72 int size = lineCub.getNumPoints();
75 lineCub.getCubature(cubPoints,cubWeights);
81 for (
int i=0; i<dimension; i++) {
82 Q *= powl(cubPoints(mid,i),(
long double)power[i]);
86 for (
int i=0; i<mid; i++) {
87 long double value1 = cubWeights(i);
88 long double value2 = cubWeights(size-i-1);
89 for (
int j=0; j<dimension; j++) {
90 value1 *= powl(cubPoints(i,j),(
long double)power[j]);
91 value2 *= powl(cubPoints(size-i-1,j),(
long double)power[j]);
98 long double evalInt(
int dimension, std::vector<int> power,
99 std::vector<EIntrepidBurkardt> rule) {
102 for (
int i=0; i<dimension; i++) {
103 if (rule[i]==BURK_CLENSHAWCURTIS||rule[i]==BURK_FEJER2||
104 rule[i]==BURK_LEGENDRE||rule[i]==BURK_PATTERSON ||
105 rule[i]==BURK_TRAPEZOIDAL) {
109 I *= 2.0/((
long double)power[i]+1.0);
111 else if (rule[i]==BURK_LAGUERRE) {
112 I *= tgammal((
long double)(power[i]+1));
114 else if (rule[i]==BURK_CHEBYSHEV1) {
115 long double bot, top;
118 for (
int j=2;j<=power[i];j+=2) {
119 top *= (
long double)(j-1);
120 bot *= (
long double)j;
128 else if (rule[i]==BURK_CHEBYSHEV2) {
129 long double bot, top;
132 for (
int j=2;j<=power[i];j+=2) {
133 top *= (
long double)(j-1);
134 bot *= (
long double)j;
136 bot *= (
long double)(power[i]+2);
143 else if (rule[i]==BURK_HERMITE||rule[i]==BURK_GENZKEISTER) {
148 long double value = 1.0;
149 if ((power[i]-1)>=1) {
150 int n_copy = power[i]-1;
152 value *= (
long double)n_copy;
156 I *= value*sqrt(M_PI)/powl(2.0,(
long double)power[i]/2.0);
163 int main(
int argc,
char *argv[]) {
165 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
169 int iprint = argc - 1;
170 Teuchos::RCP<std::ostream> outStream;
171 Teuchos::oblackholestream bhs;
173 outStream = Teuchos::rcp(&std::cout,
false);
175 outStream = Teuchos::rcp(&bhs,
false);
178 Teuchos::oblackholestream oldFormatState;
179 oldFormatState.copyfmt(std::cout);
182 <<
"===============================================================================\n" \
184 <<
"| Unit Test (CubatureTensorSorted) |\n" \
186 <<
"| 1) Computing integrals of monomials in 2D |\n" \
188 <<
"| Questions? Contact Drew Kouri (dpkouri@sandia.gov) or |\n" \
189 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
191 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
192 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
194 <<
"===============================================================================\n"\
195 <<
"| TEST 12: integrals of monomials in 2D - Anisotropic but no growth rules |\n"\
196 <<
"===============================================================================\n";
202 long double reltol = 1.0e+02*INTREPID_TOL;
204 long double analyticInt = 0;
205 long double testInt = 0;
207 std::vector<int> power(2,0);
208 std::vector<EIntrepidBurkardt> rule1(2,BURK_CLENSHAWCURTIS);
209 std::vector<int> order(2,0);
211 *outStream <<
"\nIntegrals of monomials on a reference line (edge):\n";
214 for (
int i=0; i<=maxOrder; i++) {
217 order[0] = i; order[1] = i;
218 for (
int j=0; j <= maxDeg; j++) {
220 for (
int k=0; k <= maxDeg; k++) {
222 analyticInt = 2.0*evalInt(dimension, power, rule1);
223 testInt = evalQuad(power,dimension,order,rule1);
225 long double abstol = (analyticInt == 0.0 ? reltol : std::fabs(reltol*analyticInt) );
226 long double absdiff = std::fabs(analyticInt - testInt);
227 *outStream <<
"Cubature order " << std::setw(2) << std::left << i
229 <<
"x^" << std::setw(2) << std::left << j <<
"y^"
230 << std::setw(2) << std::left
231 << k <<
":" <<
" " << std::scientific
232 << std::setprecision(16) << testInt
233 <<
" " << analyticInt <<
" " << std::setprecision(4)
235 <<
"<?" <<
" " << abstol <<
"\n";
236 if (absdiff > abstol) {
238 *outStream << std::right << std::setw(104) <<
"^^^^---FAILURE!\n";
246 catch (std::logic_error err) {
247 *outStream << err.what() <<
"\n";
253 std::cout <<
"End Result: TEST FAILED\n";
255 std::cout <<
"End Result: TEST PASSED\n";
258 std::cout.copyfmt(oldFormatState);
Implementation of a templated lexicographical container for a multi-indexed scalar quantity...
Header file for the Intrepid::CubatureTensorSorted class.
Utilizes 1D cubature (integration) rules contained in the library sandia_rules (John Burkardt...