void main(int argc, char *argv[]) { FILE *fp1, *fp2; if(argc != 3) { fprintf(stderr,"com: need two file names\n"); exit(1); } else if((fp1 = fopen(*++argv,"r")) == NULL) { fprintf(stderr,"com: can't open %s\n",*argv); exit(1); } else if((fp2 = fopen(*++argv,"r")) == NULL) { fprintf(stderr,"com: can't open %s\n",*argv); exit(1); } else { filecompare(fp1,fp2); fclose(fp1); fclose(fp2); exit(0); } }
int Integration_Test10(const bool verbose) { Teuchos::RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (verbose) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); Teuchos::oblackholestream oldFormatState; oldFormatState.copyfmt(std::cout); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (CubaturePolylib) |\n" << "| |\n" << "| 1) Computing integrals of monomials on reference cells in 1D |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]) or |\n" << "| Denis Ridzal ([email protected]) or |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n" << "| TEST 1: integrals of monomials in 1D |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) typedef ValueType pointValueType; typedef ValueType weightValueType; typedef CubaturePolylib<DeviceSpaceType,pointValueType,weightValueType> CubatureLineType; const auto tol = 10.0 * tolerence(); int errorFlag = 0; // open file with analytic values std::string basedir = "../data"; std::stringstream namestream; std::string filename; namestream << basedir << "/EDGE_integrals" << ".dat"; namestream >> filename; *outStream << "filename = " << filename << std::endl; std::ifstream filecompare(filename); *outStream << "\n-> Integrals of monomials on a reference line (edge):\n"; // compute and compare integrals try { const auto maxDeg = Parameters::MaxCubatureDegreeEdge; const auto polySize = maxDeg + 1; // test inegral values DynRankView ConstructWithLabel(testInt, maxDeg+1, polySize); // analytic integral values DynRankView ConstructWithLabel(analyticInt, maxDeg+1, polySize); // get analytic values if (filecompare.is_open()) { getAnalytic(analyticInt, filecompare); filecompare.close(); } else { INTREPID2_TEST_FOR_EXCEPTION( true, std::runtime_error, ">>> ERROR (Integration::Test02): Cannot open analytic solution file" ); } // storage for cubatrue points and weights DynRankView ConstructWithLabel(cubPoints, Parameters::MaxIntegrationPoints, Parameters::MaxDimension); DynRankView ConstructWithLabel(cubWeights, Parameters::MaxIntegrationPoints); // compute integrals EPolyType polyType[4] = { POLYTYPE_GAUSS, POLYTYPE_GAUSS_RADAU_LEFT, POLYTYPE_GAUSS_RADAU_RIGHT, POLYTYPE_GAUSS_LOBATTO }; for (size_type pid=0;pid<4;++pid) { const auto ptype = polyType[pid]; *outStream << "\n -> Testing poly type " << EPolyTypeToString(ptype) << "\n"; for (size_type cubDeg=0;cubDeg<=maxDeg;++cubDeg) { CubatureLineType lineCub(cubDeg, ptype); for (auto polyDeg=0;polyDeg<=cubDeg;++polyDeg) testInt(cubDeg, polyDeg) = computeIntegralOfMonomial<ValueType>(lineCub, cubPoints, cubWeights, polyDeg); } // perform comparison for (size_type cubDeg=0;cubDeg<=maxDeg;++cubDeg) { for (auto polyDeg=0;polyDeg<=cubDeg;++polyDeg) { const auto abstol = ( analyticInt(polyDeg,0) == 0 ? tol : std::fabs(tol*analyticInt(polyDeg,0)) ); const auto absdiff = std::fabs(analyticInt(polyDeg,0) - testInt(cubDeg,polyDeg)); *outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << " integrating " << "x^" << std::setw(2) << std::left << polyDeg << ":" << " " << std::scientific << std::setprecision(16) << testInt(cubDeg,polyDeg) << " " << analyticInt(polyDeg,0) << " " << std::setprecision(4) << absdiff << " " << "<?" << " " << abstol << "\n"; if (absdiff > abstol) { errorFlag++; *outStream << std::right << std::setw(104) << "^^^^---FAILURE!\n"; } } *outStream << "\n"; } } } catch (std::logic_error err) { *outStream << err.what() << "\n"; errorFlag = -1; } if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
int Integration_Test04(const bool verbose) { Teuchos::RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (verbose) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); Teuchos::oblackholestream oldFormatState; oldFormatState.copyfmt(std::cout); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (CubatureDirect,CubatureTensor,DefaultCubatureFactory) |\n" << "| |\n" << "| 1) Computing integrals of monomials on reference cells in 3D |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]) or |\n" << "| Denis Ridzal ([email protected]) or |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n" << "| TEST 1: integrals of monomials in 3D |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) typedef ValueType pointValueType; typedef ValueType weightValueType; typedef CubatureDirectLineGauss<DeviceSpaceType,pointValueType,weightValueType> CubatureLineType; typedef CubatureTensor<DeviceSpaceType,pointValueType,weightValueType> CubatureTensorType; const auto tol = 10.0 * tolerence<ValueType>(); int errorFlag = 0; // get names of files with analytic values std::string basedir = "../data"; std::stringstream namestream; std::string filename; namestream << basedir << "/HEX_integrals" << ".dat"; namestream >> filename; *outStream << "filename = " << filename << std::endl; std::ifstream filecompare(filename); // compute and compare integrals try { // cannot test maxcubature degree edge (20) as max integration point is limited by 1001. const auto maxDeg = 19; //Parameters::MaxCubatureDegreeEdge; const auto polySize = (maxDeg+1)*(maxDeg+2)*(maxDeg+3)/6; // test inegral values DynRankView ConstructWithLabel(testInt, maxDeg+1, polySize); // analytic integral values const auto analyticMaxDeg = 61; const auto analyticPolySize = (analyticMaxDeg+1)*(analyticMaxDeg+2)*(analyticMaxDeg+3)/6; DynRankView ConstructWithLabel(analyticInt, analyticPolySize, 1); // storage for cubatrue points and weights DynRankView ConstructWithLabel(cubPoints, Parameters::MaxIntegrationPoints, Parameters::MaxDimension); DynRankView ConstructWithLabel(cubWeights, Parameters::MaxIntegrationPoints); // compute integrals for (auto cubDeg=0;cubDeg<=maxDeg;++cubDeg) { CubatureLineType line(cubDeg); CubatureTensorType hexCub( line, line, line ); *outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << " Testing\n"; ordinal_type cnt = 0; for (auto xDeg=0;xDeg<=cubDeg;++xDeg) for (auto yDeg=0;yDeg<=(cubDeg-xDeg);++yDeg) for (auto zDeg=0;zDeg<=(cubDeg-xDeg-yDeg);++zDeg,++cnt) { testInt(cubDeg, cnt) = computeIntegralOfMonomial<ValueType>(hexCub, cubPoints, cubWeights, xDeg, yDeg, zDeg); } } // get analytic values if (filecompare.is_open()) { getAnalytic(analyticInt, filecompare); filecompare.close(); } // perform comparison for (auto cubDeg=0;cubDeg<=maxDeg;++cubDeg) { const auto y_offs = (analyticMaxDeg - cubDeg); const auto x_offs = y_offs*(y_offs + 1)/2; ordinal_type offset = 0, cnt = 0; const auto oldFlag = errorFlag; for (auto xDeg=0;xDeg<=cubDeg;++xDeg,offset += x_offs) for (auto yDeg=0;yDeg<=(cubDeg-xDeg);++yDeg,offset += y_offs) for (auto zDeg=0;zDeg<=(cubDeg-xDeg-yDeg);++zDeg,++cnt) { const auto loc = cnt + offset; const auto abstol = ( analyticInt(loc,0) == 0.0 ? tol : std::fabs(tol*analyticInt(loc,0)) ); const auto absdiff = std::fabs(analyticInt(loc,0) - testInt(cubDeg,cnt)); if (absdiff > abstol) { *outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << " integrating " << "x^" << std::setw(2) << std::left << xDeg << " * y^" << std::setw(2) << yDeg << " * z^" << std::setw(2) << zDeg << ":" << " " << std::scientific << std::setprecision(16) << testInt(cubDeg,cnt) << " " << analyticInt(loc,0) << " " << std::setprecision(4) << absdiff << " " << "<?" << " " << abstol << "\n"; errorFlag++; *outStream << std::right << std::setw(118) << "^^^^---FAILURE!\n"; } } *outStream << "Cubature order " << std::setw(2) << std::left << cubDeg << (errorFlag == oldFlag ? " PASSED" : " FAILED") << std::endl; } *outStream << "\n"; } catch (std::logic_error err) { *outStream << err.what() << "\n"; errorFlag = -1; } if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }