TEUCHOS_UNIT_TEST( Rythmos_HermiteInterpolator, interpolate ) { RCP<InterpolatorBase<double> > hi = hermiteInterpolator<double>(); double maxOrder = hi->order(); for (int order = 0 ; order <= maxOrder+1 ; ++order) { TEST_EQUALITY( order, order ); Polynomial<double> p(order,1.0); RCP<DataStore<double>::DataStoreVector_t> data_in = rcp( new DataStore<double>::DataStoreVector_t ); double T0 = 0.0; double T1 = 1.0; int N = 5; for (int i=0 ; i < N ; ++i) { double t = ((T1-T0)/(N-1.0))*i+T0; double x = 0.0; double xdot = 0.0; p.evaluate(t,&x,&xdot); RCP<Thyra::VectorBase<double> > xv, xvdot; double accuracy = 0.0; xv = createDefaultVector<double>(1,x); xvdot = createDefaultVector<double>(1,xdot); data_in->push_back(DataStore<double>(t,xv,xvdot,accuracy)); } Array<double> t_values; DataStore<double>::DataStoreVector_t data_out; N = 2*N; for (int i=0 ; i < N ; ++i) { double t = ((T1-T0)/(N-1.0))*i+T0; t_values.push_back(t); } interpolate<double>(*hi, data_in, t_values, &data_out); // Verify that the interpolated values are exactly the same as the polynomial values // unless the order of polynomial is greater than the order of the interpolator unsigned int N_out = data_out.size(); for (unsigned int i=0 ; i < N_out ; ++i ) { double x = 0.0; double xdot = 0.0; double t = data_out[i].time; RCP<const Thyra::VectorBase<double> > xv = data_out[i].x; RCP<const Thyra::VectorBase<double> > xvdot = data_out[i].xdot; { Thyra::ConstDetachedVectorView<double> xv_view(*xv); x = xv_view[0]; Thyra::ConstDetachedVectorView<double> xvdot_view(*xvdot); xdot = xvdot_view[0]; } double x_exact = 0.0; double xdot_exact = 0.0; p.evaluate(t,&x_exact,&xdot_exact); double tol = 1.0e-15; if ((order <= maxOrder) || (i == 0) || (i == N_out-1)) { TEST_FLOATING_EQUALITY( x, x_exact, tol ); TEST_FLOATING_EQUALITY( xdot, xdot_exact, tol ); } else { TEST_COMPARE( fabs((x-x_exact)/x_exact), >, tol ); TEST_COMPARE( fabs((xdot-xdot_exact)/xdot_exact), >, tol ); } } } }
//---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST( EpetraPointJacobiPreconditioner, tridiag_matrix ) { typedef Epetra_RowMatrix MatrixType; typedef Epetra_Vector VectorType; typedef MCLS::VectorTraits<VectorType> VT; typedef MCLS::MatrixTraits<VectorType,MatrixType> MT; Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); Teuchos::RCP<Epetra_Comm> epetra_comm = getEpetraComm( comm ); int comm_size = comm->getSize(); int local_num_rows = 10; int global_num_rows = local_num_rows*comm_size; Teuchos::RCP<Epetra_Map> map = Teuchos::rcp( new Epetra_Map( global_num_rows, 0, *epetra_comm ) ); Teuchos::RCP<Epetra_CrsMatrix> A = Teuchos::rcp( new Epetra_CrsMatrix( Copy, *map, 0 ) ); Teuchos::Array<int> global_columns( 3 ); double diag_val = 2.0; Teuchos::Array<double> values( 3, diag_val ); for ( int i = 1; i < global_num_rows-1; ++i ) { global_columns[0] = i-1; global_columns[1] = i; global_columns[2] = i+1; A->InsertGlobalValues( i, global_columns().size(), &values[0], &global_columns[0] ); } Teuchos::Array<int> single_col(1,0); Teuchos::Array<double> diag_elem(1,diag_val); A->InsertGlobalValues( 0, 1, diag_elem.getRawPtr(), single_col.getRawPtr() ); single_col[0] = global_num_rows-1; A->InsertGlobalValues( global_num_rows-1, 1, diag_elem.getRawPtr(), single_col.getRawPtr() ); A->FillComplete(); // Build the preconditioner. Teuchos::RCP<MCLS::Preconditioner<MatrixType> > preconditioner = Teuchos::rcp( new MCLS::EpetraPointJacobiPreconditioner() ); preconditioner->setOperator( A ); preconditioner->buildPreconditioner(); Teuchos::RCP<const MatrixType> M = preconditioner->getLeftPreconditioner(); // Check the preconditioner. Teuchos::RCP<VectorType> X = MT::cloneVectorFromMatrixRows(*A); MT::getLocalDiagCopy( *M, *X ); Teuchos::ArrayRCP<const double> X_view = VT::view( *X ); Teuchos::ArrayRCP<const double>::const_iterator view_iterator; for ( view_iterator = X_view.begin(); view_iterator != X_view.end(); ++view_iterator ) { TEST_EQUALITY( *view_iterator, 1.0/diag_val ); } }
TEUCHOS_UNIT_TEST(integration_values, volume) { PHX::KokkosDeviceSession session; Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); const int num_cells = 20; const int base_cell_dimension = 2; const panzer::CellData cell_data(num_cells,topo); const int cubature_degree = 2; RCP<IntegrationRule> int_rule = rcp(new IntegrationRule(cubature_degree, cell_data)); panzer::IntegrationValues2<double> int_values("prefix_",true); panzer::MDFieldArrayFactory af("prefix_",true); int_values.setupArrays(int_rule); const int num_vertices = int_rule->topology->getNodeCount(); PHX::MDField<double,Cell,NODE,Dim> node_coordinates = af.buildStaticArray<double,Cell,NODE,Dim>("nc",num_cells, num_vertices, base_cell_dimension); // Set up node coordinates. Here we assume the following // ordering. This needs to be consistent with shards topology, // otherwise we will get negative determinates // 3(0,1)---2(1,1) // | 0 | // | | // 0(0,0)---1(1,0) typedef panzer::ArrayTraits<double,PHX::MDField<double> >::size_type size_type; const size_type x = 0; const size_type y = 1; for (size_type cell = 0; cell < node_coordinates.dimension(0); ++cell) { node_coordinates(cell,0,x) = 0.0; node_coordinates(cell,0,y) = 0.0; node_coordinates(cell,1,x) = 1.0; node_coordinates(cell,1,y) = 0.0; node_coordinates(cell,2,x) = 1.0; node_coordinates(cell,2,y) = 1.0; node_coordinates(cell,3,x) = 0.0; node_coordinates(cell,3,y) = 1.0; } int_values.evaluateValues(node_coordinates); TEST_EQUALITY(int_values.ip_coordinates.dimension(1), 4); double realspace_x_coord = (1.0/std::sqrt(3.0) + 1.0) / 2.0; double realspace_y_coord = (1.0/std::sqrt(3.0) + 1.0) / 2.0; TEST_FLOATING_EQUALITY(int_values.ip_coordinates(0,0,0), realspace_x_coord, 1.0e-8); TEST_FLOATING_EQUALITY(int_values.ip_coordinates(0,0,1), realspace_y_coord, 1.0e-8); }
//---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST( BuhmannBasis, buhmann_basis ) { typedef DataTransferKit::BuhmannBasis<3> BasisType; typedef DataTransferKit::RadialBasisPolicy<BasisType> BP; int dim = 3; Teuchos::Array<double> x1(dim, 0.5); Teuchos::Array<double> x2(dim, 0.75); double radius_1 = 1.0; Teuchos::RCP<BasisType> basis_1 = BP::create( radius_1 ); double dist = DataTransferKit::EuclideanDistance<3>::distance( x1.getRawPtr(), x2.getRawPtr() ); double basis_value = BP::evaluateValue( *basis_1, dist ); double basis_grad = BP::evaluateGradient( *basis_1, dist ); double x = 0.0; for ( int i = 0; i < dim; ++i ) { x += (x2[i]-x1[i])*(x2[i]-x1[i]); } x = std::sqrt(x); double test_value = x*x*x*x*x*x*x*x - 84.0/5.0*x*x*x*x*x*x + 1024.0/5.0*x*std::sqrt(x*x*x*x*x*x*x) - 378.0*x*x*x*x + 1024.0/5.0*std::sqrt(x*x*x*x*x*x*x) - 84.0/5.0*x*x + 1.0; double test_grad = (8.0/5.0) * (576.0*x*std::sqrt(x*x*x*x*x) + 448.0*std::sqrt(x*x*x*x*x) + 5.0*x*x*x*x*x*x*x - 63.0*x*x*x*x*x - 945.0*x*x*x - 21.0*x); TEST_EQUALITY( test_value, basis_value ); TEST_EQUALITY( test_grad, basis_grad ); double radius_2 = 0.1; BasisType basis_2( radius_2 ); basis_value = BP::evaluateValue( basis_2, dist ); basis_grad = BP::evaluateGradient( basis_2, dist ); TEST_EQUALITY( 0.0, basis_value ); TEST_EQUALITY( 0.0, basis_grad ); }
//---------------------------------------------------------------------------// // Tests. //---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST( NanoflannTree, dim_1_test ) { int dim = 1; int num_points = 10; int num_coords = dim*num_points; Teuchos::Array<double> coords(num_coords); for ( int i = 0; i < num_points; ++i ) { coords[i] = 1.0*i; } int max_leaf_size = 3; DataTransferKit::NanoflannTree<1> tree( coords(), max_leaf_size ); Teuchos::Array<double> p1( dim ); p1[0] = 4.9; Teuchos::Array<double> p2( dim ); p2[0] = 11.4; int num_neighbors = 1; Teuchos::Array<unsigned> nnearest = tree.nnSearch( p1(), num_neighbors ); TEST_EQUALITY( num_neighbors, nnearest.size() ); TEST_EQUALITY( 5, nnearest[0] ); nnearest = tree.nnSearch( p2(), num_neighbors ); TEST_EQUALITY( num_neighbors, nnearest.size() ); TEST_EQUALITY( 9, nnearest[0] ); double radius = 1.1; nnearest = tree.radiusSearch( p1(), radius ); TEST_EQUALITY( 3, nnearest.size() ); TEST_EQUALITY( 5, nnearest[0] ) TEST_EQUALITY( 4, nnearest[1] ) TEST_EQUALITY( 6, nnearest[2] ) nnearest = tree.radiusSearch( p2(), radius ); TEST_EQUALITY( 0, nnearest.size() ); radius = 2.41; nnearest = tree.radiusSearch( p2(), radius ); TEST_EQUALITY( 1, nnearest.size() ); TEST_EQUALITY( 9, nnearest[0] ) }
//---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ForwardHistory, broadcast, Ordinal ) { Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); int comm_rank = comm->getRank(); MCLS::ForwardHistory<Ordinal>::setByteSize(); std::size_t packed_bytes = MCLS::ForwardHistory<Ordinal>::getPackedBytes(); Teuchos::Array<char> packed_history( packed_bytes ); if ( comm_rank == 0 ) { MCLS::ForwardHistory<Ordinal> h_1( 5, 2, 6 ); h_1.live(); h_1.setEvent( MCLS::Event::BOUNDARY ); h_1.addToHistoryTally( 1.98 ); h_1.addStep(); packed_history = h_1.pack(); } Teuchos::broadcast( *comm, 0, packed_history() ); MCLS::ForwardHistory<Ordinal> h_2( packed_history ); TEST_EQUALITY( h_2.weight(), 6 ); TEST_EQUALITY( h_2.globalState(), 5 ); TEST_EQUALITY( h_2.localState(), Teuchos::OrdinalTraits<Ordinal>::invalid() ); TEST_EQUALITY( h_2.startingState(), 5 ); TEST_ASSERT( h_2.alive() ); TEST_EQUALITY( h_2.event(), MCLS::Event::BOUNDARY ); TEST_EQUALITY( h_2.historyTally(), 1.98 ); TEST_EQUALITY( h_2.numSteps(), 1 ); }
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(ThresholdAFilterFactory, Basic, Scalar, LocalOrdinal, GlobalOrdinal, Node) { # include <MueLu_UseShortNames.hpp> MUELU_TESTING_SET_OSTREAM; MUELU_TESTING_LIMIT_EPETRA_SCOPE(Scalar,GlobalOrdinal,Node); out << "version: " << MueLu::Version() << std::endl; Level aLevel; TestHelpers::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(aLevel); RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(20); //can be an empty operator RCP<ThresholdAFilterFactory> AfilterFactory0 = rcp(new ThresholdAFilterFactory("A",0.1)); // keep all RCP<ThresholdAFilterFactory> AfilterFactory1 = rcp(new ThresholdAFilterFactory("A",1.1)); // keep only diagonal RCP<ThresholdAFilterFactory> AfilterFactory2 = rcp(new ThresholdAFilterFactory("A",3)); // keep only diagonal aLevel.Set("A",A); aLevel.Request("A",AfilterFactory0.get()); AfilterFactory0->Build(aLevel); TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory0.get()), true); RCP<Matrix> A0 = aLevel.Get< RCP<Matrix> >("A",AfilterFactory0.get()); aLevel.Release("A",AfilterFactory0.get()); TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory0.get()), false); TEST_EQUALITY(A0->getNodeNumEntries(), A->getNodeNumEntries()); TEST_EQUALITY(A0->getGlobalNumEntries(), A->getGlobalNumEntries()); aLevel.Request("A",AfilterFactory1.get()); AfilterFactory1->Build(aLevel); TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory1.get()), true); RCP<Matrix> A1 = aLevel.Get< RCP<Matrix> >("A",AfilterFactory1.get()); aLevel.Release("A",AfilterFactory1.get()); TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory1.get()), false); TEST_EQUALITY(A1->getGlobalNumEntries(), A1->getGlobalNumRows()); aLevel.Request("A",AfilterFactory2.get()); AfilterFactory2->Build(aLevel); TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory2.get()), true); RCP<Matrix> A2 = aLevel.Get< RCP<Matrix> >("A",AfilterFactory2.get()); aLevel.Release("A",AfilterFactory2.get()); TEST_EQUALITY(aLevel.IsAvailable("A",AfilterFactory2.get()), false); TEST_EQUALITY(A2->getGlobalNumEntries(), A2->getGlobalNumRows()); }
TEUCHOS_UNIT_TEST(physics_block, physicsBlockID) { PHX::KokkosDeviceSession session; Teuchos::RCP<panzer::PhysicsBlock> physics_block = panzer_test_utils::createPhysicsBlock(); TEST_EQUALITY(physics_block->physicsBlockID(), "4"); }
TEUCHOS_UNIT_TEST(physics_block, getBaseCellTopology) { PHX::KokkosDeviceSession session; Teuchos::RCP<panzer::PhysicsBlock> physics_block = panzer_test_utils::createPhysicsBlock(); TEST_EQUALITY(physics_block->getBaseCellTopology().getDimension(), 3); }
TEUCHOS_UNIT_TEST(RAPFactory, Constructor) { out << "version: " << MueLu::Version() << std::endl; RCP<RAPFactory> rapFactory = rcp(new RAPFactory); TEST_EQUALITY(rapFactory != Teuchos::null, true); out << *rapFactory << std::endl; } // Constructor test
TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, streamTests){ TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); std::stringstream ss; ss << simpleArray; TwoDArray<int> readArray; std::istringstream instream(ss.str()); instream >> readArray; TEST_EQUALITY(simpleArray, readArray); }
TEUCHOS_UNIT_TEST(Zoltan, Constructor) { out << "version: " << MueLu::Version() << std::endl; RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm(); RCP<ZoltanInterface> zoltan = rcp(new ZoltanInterface()); TEST_EQUALITY(zoltan != Teuchos::null, true); } //Constructor
TEUCHOS_UNIT_TEST(SaPFactory, Test0) { out << "version: " << MueLu::Version() << std::endl; RCP<SaPFactory> sapFactory = rcp(new SaPFactory); TEST_EQUALITY(sapFactory != Teuchos::null, true); out << *sapFactory << std::endl; }
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SpmdLocalDataAccess, zeroVS, Scalar ) { out << "Create a locally replicated vector space ...\n"; typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag; const RCP<const DefaultSpmdVectorSpace<Scalar> > vs = createZeroVS<Scalar>(); TEST_ASSERT(!vs->isLocallyReplicated()); TEST_EQUALITY_CONST(vs->dim(), 0); const RCP<const Teuchos::Comm<Ordinal> > comm = vs->getComm(); const Scalar val = as<Scalar>(1.5); PRINT_VAR(val); out << "Test locally replicated Vector ...\n"; const RCP<VectorBase<Scalar> > v = createMember<Scalar>(vs); { ECHO(RTOpPack::SubVectorView<Scalar> lsv = getNonconstLocalSubVectorView<Scalar>(v)); TEST_EQUALITY_CONST(lsv.globalOffset(), 0); TEST_EQUALITY(lsv.subDim(), 0); TEST_EQUALITY_CONST(lsv.stride(), 1); } { ECHO(RTOpPack::ConstSubVectorView<Scalar> lsv = getLocalSubVectorView<Scalar>(v)); TEST_EQUALITY_CONST(lsv.globalOffset(), 0); TEST_EQUALITY(lsv.subDim(), 0); TEST_EQUALITY_CONST(lsv.stride(), 1); } assign<Scalar>(v.ptr(), val); TEST_EQUALITY(sum<Scalar>(*v), as<Scalar>(0.0)); out << "Test locally replicated MultiVector ...\n"; const RCP<MultiVectorBase<Scalar> > mv = createMembers<Scalar>(vs, g_numCols); { ECHO(RTOpPack::SubMultiVectorView<Scalar> lsmv = getNonconstLocalSubMultiVectorView<Scalar>(mv)); TEST_EQUALITY(lsmv.globalOffset(), 0); TEST_EQUALITY(lsmv.subDim(), 0); TEST_EQUALITY(lsmv.leadingDim(), lsmv.subDim()); TEST_EQUALITY_CONST(lsmv.colOffset(), 0); TEST_EQUALITY(lsmv.numSubCols(), g_numCols); } { ECHO(RTOpPack::ConstSubMultiVectorView<Scalar> lsmv = getLocalSubMultiVectorView<Scalar>(mv)); } assign<Scalar>(mv.ptr(), val); for (int j = 0; j < g_numCols; ++j) { TEST_EQUALITY(sum<Scalar>(*mv->col(0)), as<Scalar>(0.0)); } }
TEUCHOS_UNIT_TEST(Teuchos_TwoDArrays, stringFunctions){ TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); std::string stringRep = TwoDArray<int>::toString(simpleArray); TwoDArray<int> convertedArray = TwoDArray<int>::fromString(stringRep); TEST_EQUALITY(simpleArray, convertedArray) std::string badStringRep = "4x4:{1.0,1.0}"; TEST_THROW(TwoDArray<int>::fromString(badStringRep), InvalidArrayStringRepresentation) }
/* This test is to make sure that stratimikos wrappers to belos correctly catch belos exceptions thrown and report back a failed solve. If belos detects a nan in the linear solve, it will throw an exception. This was causing the termination of the simulation. We have codes where cutting the time step allows recovery so it makes sense that stratimikos should catch the thrown exception and report that the solve failed. Then the time integrator can retake a time step. This test makes sure the stratimikos interface catches the exception and reports a failed solve. */ TEUCHOS_UNIT_TEST(belos, nan_handling) { Epetra_SerialComm comm; Teuchos::RCP<Epetra_CrsMatrix> epetra_A; std::string matrixFile = "FourByFour.mtx"; EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A ); Teuchos::RCP<const LinearOpBase<double> > A = epetraLinearOp(epetra_A); Teuchos::RCP<LinearOpWithSolveFactoryBase<double> > lowsFactory; { Teuchos::RCP<BelosLinearOpWithSolveFactory<double> > belosLowsFactory = Teuchos::rcp(new BelosLinearOpWithSolveFactory<double>()); lowsFactory = belosLowsFactory; } Teuchos::ParameterList belosLOWSFPL; { belosLOWSFPL.set("Solver Type","Block GMRES"); Teuchos::ParameterList& belosLOWSFPL_solver = belosLOWSFPL.sublist("Solver Types"); Teuchos::ParameterList& belosLOWSFPL_gmres = belosLOWSFPL_solver.sublist("Block GMRES"); belosLOWSFPL_gmres.set("Maximum Iterations",int(4)); belosLOWSFPL_gmres.set("Convergence Tolerance",double(1.0e-4)); belosLOWSFPL_gmres.set("Maximum Restarts",int(0)); belosLOWSFPL_gmres.set("Block Size",int(1)); belosLOWSFPL_gmres.set("Num Blocks",int(4)); belosLOWSFPL_gmres.set("Output Frequency",int(1)); belosLOWSFPL_gmres.set("Show Maximum Residual Norm Only",bool(false)); lowsFactory->setParameterList(Teuchos::rcp(&belosLOWSFPL,false)); } Teuchos::RCP<LinearOpWithSolveBase<double> > nsA = lowsFactory->createOp(); Thyra::initializeOp<double>(*lowsFactory, A, nsA.ptr()); Teuchos::RCP<Thyra::VectorBase<double> > x = Thyra::createMember(A->domain()); Teuchos::RCP<Thyra::VectorBase<double> > f = Thyra::createMember(A->range()); Thyra::put_scalar(0.0,x.ptr()); Thyra::put_scalar(1.0,f.ptr()); // Insert a nan Thyra::set_ele(0,Teuchos::ScalarTraits<double>::nan(),x.ptr()); Thyra::SolveStatus<double> status = Thyra::solve<double>(*nsA,Thyra::NOTRANS,*f,x.ptr()); TEST_EQUALITY(status.solveStatus, Thyra::SOLVE_STATUS_UNCONVERGED); }
//---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST( WuBasis, wu_basis_order_4 ) { typedef DataTransferKit::WuBasis<4> BasisType; typedef DataTransferKit::RadialBasisPolicy<BasisType> BP; int dim = 3; Teuchos::Array<double> x1(dim, 0.5); Teuchos::Array<double> x2(dim, 0.75); double radius_1 = 1.0; Teuchos::RCP<BasisType> basis_1 = BP::create( radius_1 ); double dist = DataTransferKit::EuclideanDistance<3>::distance( x1.getRawPtr(), x2.getRawPtr() ); double basis_value = BP::evaluateValue( *basis_1, dist ); double basis_grad = BP::evaluateGradient( *basis_1, dist ); double x = 0.0; for ( int i = 0; i < dim; ++i ) { x += (x2[i]-x1[i])*(x2[i]-x1[i]); } x = std::sqrt(x); double test_value = (1.0-x)*(1.0-x)*(1.0-x)*(1.0-x)*(1.0-x)*(1.0-x) * ( 5.0*x*x*x*x*x + 30.0*x*x*x*x + 72.0*x*x*x + 82.0*x*x + 36.0*x + 6.0 ); double test_grad = 11.0*(x-1.0)*(x-1.0)*(x-1.0)*(x-1.0)*(x-1.0)*x * ( 5.0*x*x*x*x + 25.0*x*x*x + 48.0*x*x + 40.0*x + 8.0 ); TEST_EQUALITY( test_value, basis_value ); TEST_EQUALITY( test_grad, basis_grad ); double radius_2 = 0.1; BasisType basis_2( radius_2 ); basis_value = BP::evaluateValue( basis_2, dist ); basis_grad = BP::evaluateGradient( basis_2, dist ); TEST_EQUALITY( 0.0, basis_value ); TEST_EQUALITY( 0.0, basis_grad ); }
TEUCHOS_UNIT_TEST(TransPFactory, Constructor) { out << "version: " << MueLu::Version() << std::endl; RCP<TransPFactory> transPFact = rcp(new TransPFactory); TEST_EQUALITY(transPFact != Teuchos::null, true); out << *transPFact << std::endl; }
TEUCHOS_UNIT_TEST(tOrientation, testFaceBasis_tri2) { out << note << std::endl; shards::CellTopology tri(shards::getCellTopologyData<shards::Triangle<3> >()); // basis to build patterns from RCP<Intrepid2::Basis<PHX::exec_space,double,double> > basisA = rcp(new Intrepid2::Basis_Constant_FEM<PHX::exec_space,double,double>(tri)); RCP<const FieldPattern> patternA = rcp(new Intrepid2FieldPattern(basisA)); TEST_EQUALITY(patternA->numberIds(),1); std::vector<std::vector<int> > topFaceIndices; orientation_helpers::computePatternFaceIndices(*patternA,topFaceIndices); TEST_EQUALITY(topFaceIndices.size(),1); TEST_EQUALITY(topFaceIndices[0].size(),3); TEST_EQUALITY(topFaceIndices[0][0],0); TEST_EQUALITY(topFaceIndices[0][1],1); TEST_EQUALITY(topFaceIndices[0][2],2); }
//---------------------------------------------------------------------------// // Tests. //---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( HistoryBuffer, sizes, Ordinal ) { typedef MCLS::AdjointHistory<Ordinal> HT; MCLS::HistoryBuffer<HT> buffer_1; TEST_EQUALITY( buffer_1.allocatedSize(), 0 ); TEST_ASSERT( buffer_1.isEmpty() ); TEST_ASSERT( !buffer_1.isFull() ); TEST_EQUALITY( MCLS::HistoryBuffer<HT>::maxNum(), 1000 ); TEST_EQUALITY( MCLS::HistoryBuffer<HT>::sizePackedHistory(), 0 ); HT::setByteSize(); MCLS::HistoryBuffer<HT>::setSizePackedHistory( HT::getPackedBytes() ); MCLS::HistoryBuffer<HT>::setMaxNumHistories( 10 ); TEST_EQUALITY( MCLS::HistoryBuffer<HT>::maxNum(), 10 ); TEST_EQUALITY( MCLS::HistoryBuffer<HT>::sizePackedHistory(), sizeof(double)+sizeof(Ordinal)+3*sizeof(int) ); MCLS::HistoryBuffer<HT> buffer_2; TEST_EQUALITY( buffer_2.allocatedSize(), 0 ); TEST_ASSERT( buffer_2.isEmpty() ); TEST_ASSERT( !buffer_2.isFull() ); buffer_2.allocate(); TEST_EQUALITY( buffer_2.allocatedSize(), 10 * MCLS::HistoryBuffer<HT>::sizePackedHistory() + sizeof(int) ); TEST_ASSERT( buffer_2.isEmpty() ); TEST_ASSERT( !buffer_2.isFull() ); buffer_2.deallocate(); TEST_EQUALITY( buffer_2.allocatedSize(), 0 ); TEST_ASSERT( buffer_2.isEmpty() ); TEST_ASSERT( !buffer_2.isFull() ); TEST_EQUALITY( MCLS::HistoryBuffer<HT>::maxNum(), 10 ); TEST_EQUALITY( MCLS::HistoryBuffer<HT>::sizePackedHistory(), sizeof(double) + sizeof(Ordinal) + 3*sizeof(int)); }
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(SaPFactory_kokkos, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) { # include "MueLu_UseShortNames.hpp" MUELU_TESTING_SET_OSTREAM; MUELU_TESTING_LIMIT_SCOPE(Scalar,GlobalOrdinal,Node); out << "version: " << MueLu::Version() << std::endl; RCP<SaPFactory_kokkos> sapFactory = rcp(new SaPFactory_kokkos); TEST_EQUALITY(sapFactory != Teuchos::null, true); out << *sapFactory << std::endl; }
//---------------------------------------------------------------------------// // Test the error code check. TEUCHOS_UNIT_TEST( DataTransferKitException, errorcode_test_1 ) { int value = 1; try { DTK_CHECK_ERROR_CODE( error_code_function(value) ); TEST_EQUALITY( value, 2 ); } catch( const DataTransferKit::DataTransferKitException& assertion ) { #if HAVE_DTK_DBC TEST_EQUALITY( value, 2 ); #else TEST_ASSERT( 0 ); #endif } catch( ... ) { TEST_ASSERT( 0 ); } }
TEUCHOS_UNIT_TEST(global_data, accessor_default_impl) { Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); TestObject t; t.setGlobalData(gd); TestObject2 t2(gd); TEST_EQUALITY(gd.get(), t2.getGlobalData().get()); }
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) { # include "MueLu_UseShortNames.hpp" MUELU_TESTING_SET_OSTREAM; MUELU_TESTING_LIMIT_SCOPE(Scalar,GlobalOrdinal,NO); out << "version: " << MueLu::Version() << std::endl; RCP<CoalesceDropFactory_kokkos> coalesceDropFact = rcp(new CoalesceDropFactory_kokkos()); TEST_EQUALITY(coalesceDropFact != Teuchos::null, true); out << *coalesceDropFact << std::endl; }
TEUCHOS_UNIT_TEST(MultiVectorTransferFactory, Constructor) { out << "version: " << MueLu::Version() << std::endl; RCP<Factory> TentativePFact = rcp(new TentativePFactory()); RCP<Factory> TentativeRFact = rcp(new TransPFactory()); // Use Ptent for coordinate projection RCP<MueLu::MultiVectorTransferFactory<SC, LO, GO, NO, LMO> > mvtf = rcp(new MueLu::MultiVectorTransferFactory<SC, LO, GO, NO, LMO>("Coordinates")); mvtf->SetFactory("R", TentativeRFact); TEST_EQUALITY(mvtf != Teuchos::null, true); } // Constructor test
//---------------------------------------------------------------------------// // Test the error code check. TEUCHOS_UNIT_TEST( Assertion, errorcode_test_1 ) { int value = 1; try { MCLS_CHECK_ERROR_CODE( error_code_function(value) ); TEST_EQUALITY( value, 2 ); } catch( const MCLS::Assertion& assertion ) { #if HAVE_MCLS_DBC TEST_EQUALITY( value, 2 ); #else TEST_ASSERT( 0 ); #endif } catch( ... ) { TEST_ASSERT( 0 ); } }
//---------------------------------------------------------------------------// TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( TpetraPointJacobiPreconditioner, tridiag_matrix, LO, GO, Scalar ) { typedef Tpetra::CrsMatrix<Scalar,LO,GO> MatrixType; typedef Tpetra::Vector<Scalar,LO,GO> VectorType; typedef MCLS::VectorTraits<VectorType> VT; typedef MCLS::MatrixTraits<VectorType,MatrixType> MT; Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); int comm_size = comm->getSize(); int local_num_rows = 10; int global_num_rows = local_num_rows*comm_size; Teuchos::RCP<const Tpetra::Map<LO,GO> > map = Tpetra::createUniformContigMap<LO,GO>( global_num_rows, comm ); Teuchos::RCP<MatrixType> A = Tpetra::createCrsMatrix<Scalar,LO,GO>( map ); Teuchos::Array<GO> global_columns( 3 ); Scalar diag_val = 2.0; Teuchos::Array<Scalar> values( 3, diag_val ); for ( int i = 1; i < global_num_rows-1; ++i ) { global_columns[0] = i-1; global_columns[1] = i; global_columns[2] = i+1; A->insertGlobalValues( i, global_columns(), values() ); } A->insertGlobalValues( 0, Teuchos::Array<GO>(1,0)(), Teuchos::Array<Scalar>(1,diag_val)() ); A->insertGlobalValues( global_num_rows-1, Teuchos::Array<GO>(1,global_num_rows-1)(), Teuchos::Array<Scalar>(1,diag_val)() ); A->fillComplete(); // Build the preconditioner. Teuchos::RCP<MCLS::Preconditioner<MatrixType> > preconditioner = Teuchos::rcp( new MCLS::TpetraPointJacobiPreconditioner<Scalar,LO,GO>() ); preconditioner->setOperator( A ); preconditioner->buildPreconditioner(); Teuchos::RCP<const MatrixType> M = preconditioner->getLeftPreconditioner(); // Check the preconditioner. Teuchos::RCP<VectorType> X = MT::cloneVectorFromMatrixRows(*A); MT::getLocalDiagCopy( *M, *X ); Teuchos::ArrayRCP<const Scalar> X_view = VT::view( *X ); typename Teuchos::ArrayRCP<const Scalar>::const_iterator view_iterator; for ( view_iterator = X_view.begin(); view_iterator != X_view.end(); ++view_iterator ) { TEST_EQUALITY( *view_iterator, 1.0/(diag_val*comm_size) ); } }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( DefaultSparseOps, NodeTest, Ordinal, Scalar, Node ) { RCP<Node> node = getNode<Node>(); typedef typename DefaultKernels<Scalar,Ordinal,Node>::SparseOps DSM; typedef typename DSM::template bind_scalar<Scalar>::other_type OPS; typedef typename OPS::template matrix<Scalar,Ordinal,Node>::matrix_type MAT; typedef typename OPS::template graph<Ordinal,Node>::graph_type GRPH; typedef MultiVector<Scalar,Node> MV; typedef Teuchos::ScalarTraits<Scalar> ST; OPS dsm(node); TEST_EQUALITY(dsm.getNode(), node); }
TEUCHOS_UNIT_TEST(Teuchos_Validator, anynumberValidatorConverter) { std::string xmlFileName = "AnyNumberValidatorList.xml"; std::string defaultParameterName = "default"; std::string nonDefaultParameterName = "preferred and accepted"; RCP<AnyNumberParameterEntryValidator> defaultValidator = rcp(new AnyNumberParameterEntryValidator()); AnyNumberParameterEntryValidator::AcceptedTypes acceptedTypes; acceptedTypes.allowDouble(false); RCP<AnyNumberParameterEntryValidator> nonDefaultValidator = rcp( new AnyNumberParameterEntryValidator( AnyNumberParameterEntryValidator::PREFER_INT, acceptedTypes ) ); ParameterList myList("AnyNumberValidatorList"); myList.set(defaultParameterName, 10.0, "A parameter with the default AnyNumberValidator on it", defaultValidator); myList.set(nonDefaultParameterName, 1, "A prameter with an AnyNumberValidator on it that has the preferred and accepted types differnet from the default", nonDefaultValidator); RCP<ParameterList> readInPL = writeThenReadPL(myList); RCP<const AnyNumberParameterEntryValidator> readinDefaultValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>( readInPL->getEntry(defaultParameterName).validator(), true); TEST_EQUALITY(readinDefaultValidator->isDoubleAllowed(), defaultValidator->isDoubleAllowed()); TEST_EQUALITY(readinDefaultValidator->isIntAllowed(), defaultValidator->isIntAllowed()); TEST_EQUALITY(readinDefaultValidator->isStringAllowed(), defaultValidator->isStringAllowed()); TEST_EQUALITY(readinDefaultValidator->getPreferredType(), defaultValidator->getPreferredType()); RCP<const AnyNumberParameterEntryValidator> readinNonDefaultValidator = rcp_dynamic_cast<const AnyNumberParameterEntryValidator>( readInPL->getEntry(nonDefaultParameterName).validator(), true); TEST_EQUALITY(readinNonDefaultValidator->isDoubleAllowed(), nonDefaultValidator->isDoubleAllowed()); TEST_EQUALITY(readinNonDefaultValidator->isIntAllowed(), nonDefaultValidator->isIntAllowed()); TEST_EQUALITY(readinNonDefaultValidator->isStringAllowed(), nonDefaultValidator->isStringAllowed()); TEST_EQUALITY(readinNonDefaultValidator->getPreferredType(), nonDefaultValidator->getPreferredType()); }
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdVector, getMultiVectorLocalData, Scalar ) { out << "Test that we can grab MV data from Vector ...\n"; typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag; RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim); const int procRank = Teuchos::DefaultComm<Ordinal>::getComm()->getRank(); RCP<VectorBase<Scalar> > v = createMember(*vs); const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps(); const Ordinal globalOffset = procRank * g_localDim; out << "Get non-const MV local data and set it ...\n"; { ArrayRCP<Scalar> localValues; Ordinal leadingDim = -1; rcp_dynamic_cast<SpmdMultiVectorBase<Scalar> >(v,true)->getNonconstLocalData( outArg(localValues), outArg(leadingDim)); TEST_EQUALITY(localValues.size(), g_localDim); TEST_EQUALITY(leadingDim, g_localDim); for (int i = 0; i < localValues.size(); ++i) { localValues[i] = globalOffset + i + 1; } } const Ordinal n = vs->dim(); TEST_FLOATING_EQUALITY(sum<Scalar>(*v), as<Scalar>((n*(n+1))/2.0), tol); out << "Get const MV local data and check it ...\n"; { ArrayRCP<const Scalar> localValues; Ordinal leadingDim = -1; rcp_dynamic_cast<const SpmdMultiVectorBase<Scalar> >(v,true)->getLocalData( outArg(localValues), outArg(leadingDim)); TEST_EQUALITY(localValues.size(), g_localDim); TEST_EQUALITY(leadingDim, g_localDim); for (int i = 0; i < localValues.size(); ++i) { TEST_EQUALITY(localValues[i], as<Scalar>(globalOffset + i + 1)); } } }