53 #include "Teuchos_oblackholestream.hpp"
54 #include "Teuchos_RCP.hpp"
55 #include "Teuchos_BLAS.hpp"
56 #include "Teuchos_GlobalMPISession.hpp"
58 using namespace Intrepid;
70 polydeg[0] = xDeg; polydeg[1] = yDeg; polydeg[2] = zDeg;
72 val *= std::pow(p(i),polydeg[i]);
81 void computeIntegral(Teuchos::Array<double>& testIntFixDeg,
int cubDegree) {
85 int cubDim = myCub.getDimension();
86 int numCubPoints = myCub.getNumPoints();
87 int numPolys = (cubDegree+1)*(cubDegree+2)*(cubDegree+3)/6;
94 myCub.getCubature(cubPoints, cubWeights);
97 for (
int xDeg=0; xDeg <= cubDegree; xDeg++) {
98 for (
int yDeg=0; yDeg <= cubDegree-xDeg; yDeg++) {
99 for (
int zDeg=0; zDeg <= cubDegree-xDeg-yDeg; zDeg++) {
100 for (
int i=0; i<numCubPoints; i++) {
101 for (
int j=0; j<cubDim; j++) {
102 point(j) = cubPoints(i,j);
104 functValues(i,polyCt) = computeMonomial(point, xDeg, yDeg, zDeg);
111 Teuchos::BLAS<int, double> myblas;
115 myblas.GEMV(Teuchos::NO_TRANS, numPolys, numCubPoints, alpha, &functValues[0], numPolys,
116 &cubWeights[0], inc, beta, &testIntFixDeg[0], inc);
120 int main(
int argc,
char *argv[]) {
122 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
126 int iprint = argc - 1;
127 Teuchos::RCP<std::ostream> outStream;
128 Teuchos::oblackholestream bhs;
130 outStream = Teuchos::rcp(&std::cout,
false);
132 outStream = Teuchos::rcp(&bhs,
false);
135 Teuchos::oblackholestream oldFormatState;
136 oldFormatState.copyfmt(std::cout);
139 <<
"===============================================================================\n" \
141 <<
"| Unit Test (CubatureSparse) |\n" \
143 <<
"| 1) Computing integrals of monomials on reference cells in 3D |\n" \
144 <<
"| - using Level 2 BLAS - |\n" \
146 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \
147 <<
"| Denis Ridzal (dridzal@sandia.gov) or |\n" \
148 <<
"| Matthew Keegan (mskeega@sandia.gov). |\n" \
150 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
151 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
153 <<
"===============================================================================\n"\
154 <<
"| TEST 1: integrals of monomials in 3D (Level 2 BLAS version) using Sparse |\n"\
155 <<
"| Grid Construction |\n"\
156 <<
"===============================================================================\n";
162 Teuchos::Array< Teuchos::Array<double> > testInt;
163 Teuchos::Array< Teuchos::Array<double> > analyticInt;
164 Teuchos::Array<double> tmparray(1);
165 double reltol = 1.0e+04 * INTREPID_TOL;
168 int numPoly = (maxDeg+1)*(maxDeg+2)*(maxDeg+3)/6;
169 int numAnalytic = (maxOffset+1)*(maxOffset+2)*(maxOffset+3)/6;
170 testInt.assign(numPoly, tmparray);
171 analyticInt.assign(numAnalytic, tmparray);
174 std::string basedir =
"./data";
175 std::stringstream namestream;
176 std::string filename;
177 namestream << basedir <<
"/HEX_integrals" <<
".dat";
178 namestream >> filename;
181 TypeOfExactData dataFormat = INTREPID_UTILS_FRACTION;
185 *outStream <<
"\nIntegrals of monomials:\n";
186 std::ifstream filecompare(&filename[0]);
188 for (
int cubDeg=0; cubDeg <= maxDeg; cubDeg++) {
189 int numMonomials = (cubDeg+1)*(cubDeg+2)*(cubDeg+3)/6;
190 testInt[cubDeg].resize(numMonomials);
191 computeIntegral(testInt[cubDeg], cubDeg);
194 if (filecompare.is_open()) {
195 getAnalytic(analyticInt, filecompare, dataFormat);
200 for (
int cubDeg=0; cubDeg <= maxDeg; cubDeg++) {
203 int oldErrorFlag = errorFlag;
204 for (
int xDeg=0; xDeg <= cubDeg; xDeg++) {
205 for (
int yDeg=0; yDeg <= cubDeg-xDeg; yDeg++) {
206 for (
int zDeg=0; zDeg <= cubDeg-xDeg-yDeg; zDeg++) {
207 double abstol = ( analyticInt[polyCt+offset][0] == 0.0 ? reltol : std::fabs(reltol*analyticInt[polyCt+offset][0]) );
208 double absdiff = std::fabs(analyticInt[polyCt+offset][0] - testInt[cubDeg][polyCt]);
209 if (absdiff > abstol) {
210 *outStream <<
"Cubature order " << std::setw(2) << std::left << cubDeg <<
" integrating "
211 <<
"x^" << std::setw(2) << std::left << xDeg <<
" * y^" << std::setw(2) << yDeg
212 <<
" * z^" << std::setw(2) << zDeg <<
":" <<
" "
213 << std::scientific << std::setprecision(16)
214 << testInt[cubDeg][polyCt] <<
" " << analyticInt[polyCt+offset][0] <<
" "
215 << std::setprecision(4) << absdiff <<
" " <<
"<?" <<
" " << abstol <<
"\n";
217 *outStream << std::right << std::setw(118) <<
"^^^^---FAILURE!\n";
221 offset = offset + maxOffset - cubDeg;
223 offset = offset + (maxOffset - cubDeg)*(maxOffset - cubDeg + 1)/2;
225 *outStream <<
"Cubature order " << std::setw(2) << std::left << cubDeg;
226 if (errorFlag == oldErrorFlag)
227 *outStream <<
" passed.\n";
229 *outStream <<
" failed.\n";
233 catch (
const std::logic_error & err) {
234 *outStream << err.what() <<
"\n";
240 std::cout <<
"End Result: TEST FAILED\n";
242 std::cout <<
"End Result: TEST PASSED\n";
245 std::cout.copyfmt(oldFormatState);
Header file for the Intrepid::CubatureSparse class.
int dimension(const int whichDim) const
Returns the specified dimension.
#define INTREPID_CUBATURE_LINE_GAUSS_MAX
The maximum degree of the polynomial that can be integrated exactly by a direct line rule of the Gaus...