Thyra Package Browser (Single Doxygen Collection) Version of the Day
EpetraLinearOp_UnitTests.cpp
Go to the documentation of this file.
00001 #include "Thyra_EpetraLinearOp.hpp"
00002 #include "Thyra_LinearOpTester.hpp"
00003 #include "Thyra_DefaultBlockedLinearOp.hpp"
00004 #include "Thyra_MultiVectorBase.hpp"
00005 #include "Thyra_MultiVectorStdOps.hpp"
00006 #include "EpetraThyraAdaptersTestHelpers.hpp"
00007 
00008 #include "Teuchos_UnitTestHarness.hpp"
00009 
00010 
00011 namespace {
00012 
00013 
00014 //
00015 // Unit Tests
00016 //
00017 
00018 
00019 TEUCHOS_UNIT_TEST( EpetraLinearOp, rectangular )
00020 {
00021   const RCP<const Epetra_Comm> comm = getEpetraComm();
00022 
00023   const int numLocalRows = g_localDim;
00024   const int numRows = numLocalRows * comm->NumProc();
00025   const int numCols = numLocalRows / 2;
00026 
00027   RCP<Epetra_CrsMatrix> epetraCrsM = getEpetraMatrix(numRows,numCols);
00028 
00029   const RCP<const Thyra::LinearOpBase<double> > epetraOp =
00030     Thyra::epetraLinearOp(epetraCrsM);
00031 
00032   Thyra::LinearOpTester<double> linearOpTester;
00033 
00034   const bool result = linearOpTester.check(*epetraOp, &out);
00035 
00036   if (!result)
00037     success = false;
00038    
00039 }
00040 
00041 
00042 TEUCHOS_UNIT_TEST( EpetraLinearOp, blocked_op )
00043 {
00044 
00045   using Teuchos::describe;
00046   using Thyra::block2x2;
00047   using Thyra::block2x1;
00048   using Thyra::block1x2;
00049   using Thyra::LinearOpBase;
00050   using Thyra::MultiVectorBase;
00051   using Thyra::createMembers;
00052   
00053   // build sub operators
00054   RCP<const Thyra::LinearOpBase<double> > A00 = Thyra::epetraLinearOp(getEpetraMatrix(4,4,0));
00055   RCP<const Thyra::LinearOpBase<double> > A01 = Thyra::epetraLinearOp(getEpetraMatrix(4,3,1));
00056   RCP<const Thyra::LinearOpBase<double> > A02 = Thyra::epetraLinearOp(getEpetraMatrix(4,2,2));
00057   RCP<const Thyra::LinearOpBase<double> > A10 = Thyra::epetraLinearOp(getEpetraMatrix(3,4,3));
00058   RCP<const Thyra::LinearOpBase<double> > A11 = Thyra::epetraLinearOp(getEpetraMatrix(3,3,4));
00059   RCP<const Thyra::LinearOpBase<double> > A12 = Thyra::epetraLinearOp(getEpetraMatrix(3,2,5));
00060   RCP<const Thyra::LinearOpBase<double> > A20 = Thyra::epetraLinearOp(getEpetraMatrix(2,4,6));
00061   RCP<const Thyra::LinearOpBase<double> > A21 = Thyra::epetraLinearOp(getEpetraMatrix(2,3,8));
00062   RCP<const Thyra::LinearOpBase<double> > A22 = Thyra::epetraLinearOp(getEpetraMatrix(2,2,8));
00063   
00064   out << "Sub operators built" << std::endl;
00065 
00066   {
00067      // build composite operator
00068      RCP<const LinearOpBase<double> > A = block2x2<double>(
00069        block2x2<double>(A00, A01, A10, A11),   block2x1<double>(A02,A12),
00070        block1x2<double>(A20, A21),             A22
00071        );
00072    
00073      out << "First composite operator built" << std::endl;
00074      
00075      // build vectors for use in apply
00076      RCP<MultiVectorBase<double> > x = createMembers<double>(A->domain(), 3);
00077      RCP<MultiVectorBase<double> > y = createMembers<double>(A->range(), 3);
00078      
00079      Thyra::randomize(-1.0, 1.0, x.ptr());
00080    
00081      out << "A = \n" << describe(*A, Teuchos::VERB_HIGH) << std::endl;
00082      out << "x = \n" << describe(*x, Teuchos::VERB_HIGH) << std::endl;
00083      out << "y = \n" << describe(*y, Teuchos::VERB_HIGH) << std::endl;
00084      
00085      // perform a matrix vector multiply
00086      Thyra::apply(*A, Thyra::NOTRANS, *x, y.ptr());
00087 
00088      out << "First composite operator completed" << std::endl;
00089   }
00090 
00091   {
00092      RCP<const LinearOpBase<double> > A = block2x2<double>(
00093        A11, block1x2<double>(A10,A12),block2x1<double>(A01,A21),
00094        block2x2<double>(A00,A02,A20,A22));
00095      
00096      out << "Second composite operator built" << std::endl;
00097      
00098      // build vectors for use in apply
00099      RCP<MultiVectorBase<double> > x = createMembers<double>(A->domain(), 3);
00100      RCP<MultiVectorBase<double> > y = createMembers<double>(A->range(), 3);
00101      
00102      Thyra::randomize(-1.0, 1.0, x.ptr());
00103    
00104      out << "A = \n" << describe(*A, Teuchos::VERB_HIGH) << std::endl;
00105      out << "x = \n" << describe(*x, Teuchos::VERB_HIGH) << std::endl;
00106      out << "y = \n" << describe(*y, Teuchos::VERB_HIGH) << std::endl;
00107      
00108      // perform a matrix vector multiply
00109      Thyra::apply(*A, Thyra::NOTRANS, *x, y.ptr());
00110 
00111      out << "Second composite operator completed" << std::endl;
00112   }
00113 
00114   out << "Test complete" << std::endl;
00115 
00116 }
00117 
00118 
00119 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines