bool ScratchPadTests::testConstantFunctionProduct() { bool success = true; // set up basisCache (even though it won't really be used here) BasisCachePtr basisCache = Teuchos::rcp( new BasisCache( _elemType, _spectralConfusionMesh ) ); vector<GlobalIndexType> cellIDs; int cellID = 0; cellIDs.push_back(cellID); basisCache->setPhysicalCellNodes( _spectralConfusionMesh->physicalCellNodesForCell(cellID), cellIDs, true ); int numCells = _basisCache->getPhysicalCubaturePoints().dimension(0); int numPoints = _testPoints.dimension(0); FunctionPtr three = Function::constant(3.0); FunctionPtr two = Function::constant(2.0); FieldContainer<double> values(numCells,numPoints); two->values(values,basisCache); three->scalarMultiplyBasisValues( values, basisCache ); FieldContainer<double> expectedValues(numCells,numPoints); expectedValues.initialize( 3.0 * 2.0 ); double tol = 1e-15; double maxDiff = 0.0; if ( ! fcsAgree(expectedValues, values, tol, maxDiff) ) { success = false; cout << "Expected product differs from actual; maxDiff: " << maxDiff << endl; } return success; }
bool ScratchPadTests::testSpatiallyFilteredFunction() { bool success = true; FunctionPtr one = Function::constant(1.0); SpatialFilterPtr positiveX = Teuchos::rcp( new PositiveX ); FunctionPtr heaviside = Teuchos::rcp( new SpatiallyFilteredFunction<double>(one, positiveX) ); int numCells = _basisCache->getPhysicalCubaturePoints().dimension(0); int numPoints = _testPoints.dimension(0); FieldContainer<double> values(numCells,numPoints); FieldContainer<double> expectedValues(numCells,numPoints); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = _basisCache->getPhysicalCubaturePoints()(cellIndex,ptIndex,0); if (x > 0) { expectedValues(cellIndex,ptIndex) = 1.0; } else { expectedValues(cellIndex,ptIndex) = 0.0; } } } heaviside->values(values,_basisCache); double tol = 1e-15; double maxDiff = 0.0; if ( ! fcsAgree(expectedValues, values, tol, maxDiff) ) { success = false; cout << "testSpatiallyFilteredFunction: Expected values differ from actual; maxDiff: " << maxDiff << endl; } return success; }
TEST_F(MPIWrapperTests, TestEntryWiseSum) { int numProcs = Teuchos::GlobalMPISession::getNProc(); int rank = Teuchos::GlobalMPISession::getRank(); FieldContainer<double> expectedValues(2); for (int i=0; i<numProcs; i++) { expectedValues[0] += i*i; expectedValues[1] += 1; } FieldContainer<double> values(2); values[0] = rank*rank; values[1] = 1; MPIWrapper::entryWiseSum(values); double tol = 1e-16; double maxDiff = 0; EXPECT_TRUE(fcsAgree(values, expectedValues, tol, maxDiff)) << "MPIWrapperTests::testentryWiseSum() failed with maxDiff " << maxDiff << endl; // EXPECT_EQ(rank, 2) << "rank " << rank << endl; }
bool MPIWrapperTests::testentryWiseSum() { bool success = true; int numProcs = Teuchos::GlobalMPISession::getNProc(); int rank = Teuchos::GlobalMPISession::getRank(); FieldContainer<double> expectedValues(2); for (int i=0; i<numProcs; i++) { expectedValues[0] += i*i; expectedValues[1] += 1; } FieldContainer<double> values(2); values[0] = rank*rank; values[1] = 1; MPIWrapper::entryWiseSum(values); double tol = 1e-16; double maxDiff = 0; if (! fcsAgree(values, expectedValues, tol, maxDiff) ) { success = false; cout << "MPIWrapperTests::testentryWiseSum() failed with maxDiff " << maxDiff << endl; } return success; }
bool FunctionTests::testJacobianOrdering() { bool success = true; FunctionPtr y = Function::yn(1); FunctionPtr f = Function::vectorize(y, Function::zero()); // test 1: Jacobian ordering is f_i,j int spaceDim = 2; int cellID = 0; BasisCachePtr basisCache = BasisCache::basisCacheForCell(_spectralConfusionMesh, cellID); FieldContainer<double> physicalPoints = basisCache->getPhysicalCubaturePoints(); int numCells = physicalPoints.dimension(0); int numPoints = physicalPoints.dimension(1); FieldContainer<double> expectedValues(numCells, numPoints, spaceDim, spaceDim); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { expectedValues(cellIndex,ptIndex,0,0) = 0; expectedValues(cellIndex,ptIndex,0,1) = 1; expectedValues(cellIndex,ptIndex,1,0) = 0; expectedValues(cellIndex,ptIndex,1,1) = 0; } } FieldContainer<double> values(numCells, numPoints, spaceDim, spaceDim); f->grad(spaceDim)->values(values, basisCache); double maxDiff = 0; double tol = 1e-14; if (! fcsAgree(expectedValues, values, tol, maxDiff)) { cout << "expectedValues does not match values in testJacobianOrdering().\n"; reportFunctionValueDifferences(physicalPoints, expectedValues, values, tol); success = false; } // test 2: ordering of VectorizedBasis agrees // (actually implemented where it belongs, in Vectorized_BasisTestSuite) // test 3: ordering of CellTools::getJacobian FieldContainer<double> nodes(1,4,2); nodes(0,0,0) = 1; nodes(0,0,1) = -2; nodes(0,1,0) = 1; nodes(0,1,1) = 2; nodes(0,2,0) = -1; nodes(0,2,1) = 2; nodes(0,3,0) = -1; nodes(0,3,1) = -2; shards::CellTopology quad_4(shards::getCellTopologyData<shards::Quadrilateral<4> >() ); int cubDegree = 4; BasisCachePtr rotatedCache = Teuchos::rcp( new BasisCache(nodes, quad_4, cubDegree) ); physicalPoints = rotatedCache->getPhysicalCubaturePoints(); numCells = physicalPoints.dimension(0); numPoints = physicalPoints.dimension(1); FieldContainer<double> expectedJacobian(numCells,numPoints,spaceDim,spaceDim); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { expectedJacobian(cellIndex,ptIndex,0,0) = 0; expectedJacobian(cellIndex,ptIndex,0,1) = -1; expectedJacobian(cellIndex,ptIndex,1,0) = 2; expectedJacobian(cellIndex,ptIndex,1,1) = 0; } } FieldContainer<double> jacobianValues = rotatedCache->getJacobian(); maxDiff = 0; if (! fcsAgree(expectedJacobian, jacobianValues, tol, maxDiff)) { cout << "expectedJacobian does not match jacobianValues in testJacobianOrdering().\n"; reportFunctionValueDifferences(physicalPoints, expectedJacobian, jacobianValues, tol); success = false; } return success; }