55 #include "Shards_CellTopology.hpp"
56 #include "Teuchos_oblackholestream.hpp"
57 #include "Teuchos_RCP.hpp"
58 #include "Teuchos_GlobalMPISession.hpp"
60 using namespace Intrepid;
62 #define INTREPID_TEST_COMMAND( S ) \
67 catch (std::logic_error err) { \
68 *outStream << "Expected Error ----------------------------------------------------------------\n"; \
69 *outStream << err.what() << '\n'; \
70 *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
77 double computeRefVolume(shards::CellTopology & cellTopology,
int cubDegree) {
78 Teuchos::RCP< Cubature<double> > myCub;
81 switch (cellTopology.getBaseCellTopologyData()->key) {
83 case shards::Line<>::key:
86 case shards::Triangle<>::key:
89 case shards::Tetrahedron<>::key:
92 case shards::Quadrilateral<>::key: {
93 std::vector< Teuchos::RCP< Cubature<double> > > lineCubs(2);
99 case shards::Hexahedron<>::key: {
100 std::vector< Teuchos::RCP< Cubature<double> > > lineCubs(2);
101 std::vector< Teuchos::RCP< Cubature<double> > > miscCubs(2);
109 case shards::Wedge<>::key: {
117 TEUCHOS_TEST_FOR_EXCEPTION( ( (cellTopology.getBaseCellTopologyData()->key != shards::Line<>::key),
118 (cellTopology.getBaseCellTopologyData()->key != shards::Triangle<>::key),
119 (cellTopology.getBaseCellTopologyData()->key != shards::Tetrahedron<>::key),
120 (cellTopology.getBaseCellTopologyData()->key != shards::Quadrilateral<>::key),
121 (cellTopology.getBaseCellTopologyData()->key != shards::Hexahedron<>::key),
122 (cellTopology.getBaseCellTopologyData()->key != shards::Wedge<>::key) ),
123 std::invalid_argument,
124 ">>> ERROR (Unit Test -- Cubature -- Volume): Invalid cell type.");
127 int numCubPoints = myCub->getNumPoints();
131 myCub->getCubature(cubPoints, cubWeights);
133 for (
int i=0; i<numCubPoints; i++)
134 vol += cubWeights[i];
140 int main(
int argc,
char *argv[]) {
142 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
146 int iprint = argc - 1;
147 Teuchos::RCP<std::ostream> outStream;
148 Teuchos::oblackholestream bhs;
150 outStream = Teuchos::rcp(&std::cout,
false);
152 outStream = Teuchos::rcp(&bhs,
false);
155 Teuchos::oblackholestream oldFormatState;
156 oldFormatState.copyfmt(std::cout);
159 <<
"===============================================================================\n" \
161 <<
"| Unit Test (CubatureDirect,CubatureTensor) |\n" \
163 <<
"| 1) Computing volumes of reference cells |\n" \
165 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
166 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
168 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
169 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
171 <<
"===============================================================================\n"\
172 <<
"| TEST 1: construction and basic functionality |\n"\
173 <<
"===============================================================================\n";
177 int beginThrowNumber = Teuchos::TestForException_getThrowNumber();
178 int endThrowNumber = beginThrowNumber + 7;
185 std::string testName =
"INTREPID_CUBATURE_LINE_GAUSS";
186 std::string lineCubName = lineCub.
getName();
187 *outStream <<
"\nComparing strings: " << testName <<
" and " << lineCubName <<
"\n\n";
188 TEUCHOS_TEST_FOR_EXCEPTION( (testName != lineCubName), std::logic_error,
"Name mismatch!" ) );
190 std::vector<int> accuracy;
192 TEUCHOS_TEST_FOR_EXCEPTION( (accuracy[0] != 0), std::logic_error,
"Check member getAccuracy!" ) );
194 TEUCHOS_TEST_FOR_EXCEPTION( (lineCub.getNumPoints() != 28), std::logic_error,
"Check member getNumPoints!" ) );
196 TEUCHOS_TEST_FOR_EXCEPTION( (lineCub.getDimension() != 1),
198 "Check member dimension!" ) );
203 std::string testName =
"INTREPID_CUBATURE_TRI_DEFAULT";
204 std::string triCubName = triCub.
getName();
205 *outStream <<
"\nComparing strings: " << testName <<
" and " << triCubName <<
"\n\n";
206 TEUCHOS_TEST_FOR_EXCEPTION( (testName != triCubName), std::logic_error,
"Name mismatch!" ) );
208 std::vector<int> accuracy;
210 TEUCHOS_TEST_FOR_EXCEPTION( (accuracy[0] != 0), std::logic_error,
"Check member getAccuracy!" ) );
212 TEUCHOS_TEST_FOR_EXCEPTION( (triCub.getNumPoints() != 61), std::logic_error,
"Check member getNumPoints!" ) );
214 TEUCHOS_TEST_FOR_EXCEPTION( (triCub.getDimension() != 2),
216 "Check member dimension!" ) );
221 std::string testName =
"INTREPID_CUBATURE_TET_DEFAULT";
222 std::string tetCubName = tetCub.
getName();
223 *outStream <<
"\nComparing strings: " << testName <<
" and " << tetCubName <<
"\n\n";
224 std::vector< Teuchos::RCP< Cubature<double> > > lineCubs(2);
225 TEUCHOS_TEST_FOR_EXCEPTION( (testName != tetCubName), std::logic_error,
"Name mismatch!" ) );
227 std::vector<int> accuracy;
229 TEUCHOS_TEST_FOR_EXCEPTION( (accuracy[0] != 0), std::logic_error,
"Check member getAccuracy!" ) );
231 TEUCHOS_TEST_FOR_EXCEPTION( (tetCub.getNumPoints() != 495), std::logic_error,
"Check member getNumPoints!" ) );
233 TEUCHOS_TEST_FOR_EXCEPTION( (tetCub.getDimension() != 3),
235 "Check member getCellTopology!" ) );
237 INTREPID_TEST_COMMAND( std::vector< Teuchos::RCP<
Cubature<double> > > lineCubs(0);
239 INTREPID_TEST_COMMAND( std::vector< Teuchos::RCP<
Cubature<double> > > miscCubs(3);
240 std::vector< Teuchos::RCP< Cubature<double> > > lineCubs(2);
247 std::vector<int> a(4); a[0]=3; a[1]=16; a[2]=0; a[3]=19;
248 std::vector<int> atest(4);
249 tensorCub.getAccuracy(atest);
250 TEUCHOS_TEST_FOR_EXCEPTION( (a != atest), std::logic_error,
"Check member getAccuracy!" ) );
251 INTREPID_TEST_COMMAND( std::vector< Teuchos::RCP<
Cubature<double> > > lineCubs(2);
255 TEUCHOS_TEST_FOR_EXCEPTION( (tensorCub.getNumPoints() != 48), std::logic_error,
"Check member getNumPoints!" ) );
256 INTREPID_TEST_COMMAND( std::vector< Teuchos::RCP<
Cubature<double> > > miscCubs(3);
261 TEUCHOS_TEST_FOR_EXCEPTION( (tensorCub.getDimension() != 6), std::logic_error,
"Check member dimension!" ) );
262 INTREPID_TEST_COMMAND( std::vector< Teuchos::RCP<
Cubature<double> > > miscCubs(3);
269 tensorCub.getCubature(points, weights)
274 std::vector<int> a(2); a[0] = 15; a[1] = 12;
275 std::vector<int> atest(2);
276 tensorCub.getAccuracy(atest);
277 TEUCHOS_TEST_FOR_EXCEPTION( (tensorCub.getDimension() != 3) || (a != atest),
279 "Check constructormembers dimension and getAccuracy!" ) );
283 std::vector<int> a(3); a[0] = 12; a[1] = 15; a[2] = 12;
284 std::vector<int> atest(3);
285 tensorCub.getAccuracy(atest);
286 TEUCHOS_TEST_FOR_EXCEPTION( (tensorCub.getDimension() != 5) || (a != atest),
288 "Check constructor and members dimension and getAccuracy!" ) );
291 std::vector<int> a(5); a[0] = 12; a[1] = 12; a[2] = 12; a[3] = 12; a[4] = 12;
292 std::vector<int> atest(5);
293 tensorCub.getAccuracy(atest);
294 TEUCHOS_TEST_FOR_EXCEPTION( (tensorCub.getDimension() != 10) || (a != atest),
296 "Check constructor and members dimension and getAccuracy!" ) );
297 if (Teuchos::TestForException_getThrowNumber() != endThrowNumber) {
301 catch (std::logic_error err) {
302 *outStream << err.what() <<
"\n";
307 <<
"===============================================================================\n"\
308 <<
"| TEST 2: volume computations |\n"\
309 <<
"===============================================================================\n";
311 double testVol = 0.0;
312 double tol = 100.0 * INTREPID_TOL;
315 double volumeList[] = {0.0, 2.0, 1.0/2.0, 4.0, 1.0/6.0, 8.0, 1.0, 32.0};
317 *outStream <<
"\nReference cell volumes:\n\n";
320 shards::CellTopology line(shards::getCellTopologyData< shards::Line<> >());
322 testVol = computeRefVolume(line, deg);
323 *outStream << std::setw(30) <<
"Line volume --> " << std::setw(10) << std::scientific << testVol <<
324 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[1]) <<
"\n";
325 if (std::abs(testVol - volumeList[1]) > tol) {
327 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
330 *outStream <<
"\n\n";
331 shards::CellTopology tri(shards::getCellTopologyData< shards::Triangle<> >());
333 testVol = computeRefVolume(tri, deg);
334 *outStream << std::setw(30) <<
"Triangle volume --> " << std::setw(10) << std::scientific << testVol <<
335 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[2]) <<
"\n";
336 if (std::abs(testVol - volumeList[2]) > tol) {
338 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
341 *outStream <<
"\n\n";
342 shards::CellTopology quad(shards::getCellTopologyData< shards::Quadrilateral<> >());
344 testVol = computeRefVolume(quad, deg);
345 *outStream << std::setw(30) <<
"Quadrilateral volume --> " << std::setw(10) << std::scientific << testVol <<
346 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[3]) <<
"\n";
347 if (std::abs(testVol - volumeList[3]) > tol) {
349 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
352 *outStream <<
"\n\n";
353 shards::CellTopology tet(shards::getCellTopologyData< shards::Tetrahedron<> >());
355 testVol = computeRefVolume(tet, deg);
356 *outStream << std::setw(30) <<
"Tetrahedron volume --> " << std::setw(10) << std::scientific << testVol <<
357 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[4]) <<
"\n";
358 if (std::abs(testVol - volumeList[4]) > tol) {
360 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
363 *outStream <<
"\n\n";
364 shards::CellTopology hex(shards::getCellTopologyData< shards::Hexahedron<> >());
366 testVol = computeRefVolume(hex, deg);
367 *outStream << std::setw(30) <<
"Hexahedron volume --> " << std::setw(10) << std::scientific << testVol <<
368 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[5]) <<
"\n";
369 if (std::abs(testVol - volumeList[5]) > tol) {
371 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
374 *outStream <<
"\n\n";
375 shards::CellTopology wedge(shards::getCellTopologyData< shards::Wedge<> >());
377 testVol = computeRefVolume(wedge, deg);
378 *outStream << std::setw(30) <<
"Wedge volume --> " << std::setw(10) << std::scientific << testVol <<
379 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[6]) <<
"\n";
380 if (std::abs(testVol - volumeList[6]) > tol) {
382 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
385 *outStream <<
"\n\n";
386 for (
int deg=0; deg<=20; deg++) {
389 int numCubPoints = hypercubeCub.getNumPoints();
392 hypercubeCub.getCubature(cubPoints, cubWeights);
394 for (
int i=0; i<numCubPoints; i++)
395 testVol += cubWeights[i];
396 *outStream << std::setw(30) <<
"5-D Hypercube volume --> " << std::setw(10) << std::scientific << testVol <<
397 std::setw(10) <<
"diff = " << std::setw(10) << std::scientific << std::abs(testVol - volumeList[7]) <<
"\n";
398 if (std::abs(testVol - volumeList[7])/std::abs(testVol) > tol) {
400 *outStream << std::setw(70) <<
"^^^^----FAILURE!" <<
"\n";
404 catch (std::logic_error err) {
405 *outStream << err.what() <<
"\n";
411 std::cout <<
"End Result: TEST FAILED\n";
413 std::cout <<
"End Result: TEST PASSED\n";
416 std::cout.copyfmt(oldFormatState);
virtual void getAccuracy(std::vector< int > &accuracy) const
Returns max. degree of polynomials that are integrated exactly. The return vector has size 1...
Header file for the Intrepid::CubatureDirectLineGauss class.
Defines Gauss integration rules on a line.
const char * getName() const
Returns cubature name.
Defines direct integration rules on a tetrahedron.
#define INTREPID_CUBATURE_TRI_DEFAULT_MAX
The maximum degree of the polynomial that can be integrated exactly by a direct triangle rule of the ...
Header file for the Intrepid::CubatureTensor class.
#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...
#define INTREPID_CUBATURE_TET_DEFAULT_MAX
The maximum degree of the polynomial that can be integrated exactly by a direct tetrahedron rule of t...
Header file for the Intrepid::CubatureDirectTetDefault class.
const char * getName() const
Returns cubature name.
Header file for the Intrepid::CubatureDirectTriDefault class.
Defines direct integration rules on a triangle.
const char * getName() const
Returns cubature name.
Defines the base class for cubature (integration) rules in Intrepid.
Defines tensor-product cubature (integration) rules in Intrepid.
Defines direct cubature (integration) rules in Intrepid.