当前位置: 首页>>代码示例>>C++>>正文


C++ thyra::LinearOpTester类代码示例

本文整理汇总了C++中thyra::LinearOpTester的典型用法代码示例。如果您正苦于以下问题:C++ LinearOpTester类的具体用法?C++ LinearOpTester怎么用?C++ LinearOpTester使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LinearOpTester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Comm

TEUCHOS_UNIT_TEST(tIterativePreconditionerFactory, inverse_test)
{
   // build global (or serial communicator)
   #ifdef HAVE_MPI
      Epetra_MpiComm Comm(MPI_COMM_WORLD);
   #else
      Epetra_SerialComm Comm;
   #endif

   Teko::LinearOp  A = build2x2(Comm,1,2,3,4);
   RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromStratimikos();
   RCP<Teko::InverseFactory> invFact = invLib->getInverseFactory("Amesos");
   Teko::LinearOp iP = Teko::buildInverse(*invFact,A);

   Thyra::LinearOpTester<double> tester;
   tester.dump_all(true);
   tester.show_all_tests(true);

   {
      RCP<Teko::InverseFactory> precOpFact = rcp(new Teko::StaticOpInverseFactory(iP));
      RCP<Teko::IterativePreconditionerFactory> precFact = rcp(new Teko::IterativePreconditionerFactory(9,precOpFact));
      RCP<Teko::InverseFactory> invFact = rcp(new Teko::PreconditionerInverseFactory(precFact,Teuchos::null));

      Teko::LinearOp prec = Teko::buildInverse(*invFact,A);

      const bool result = tester.compare( *prec, *iP, Teuchos::ptrFromRef(out));
      if (!result) {
         out << "Apply 0: FAILURE" << std::endl;
         success = false;
      }
      else
         out << "Apply 0: SUCCESS" << std::endl;
   }
}
开发者ID:00liujj,项目名称:trilinos,代码行数:34,代码来源:tIterativePreconditionerFactory.cpp

示例2: test_invLumping

bool tLumping::test_invLumping(int verbosity,std::ostream & os)
{
   bool status = false;
   bool allPassed = true;

   Thyra::LinearOpTester<double> tester;
   tester.show_all_tests(true);
   tester.set_all_error_tol(tolerance_);

   Epetra_Map map(100,0,*GetComm());

   // A matrix...to be lumped
   Epetra_CrsMatrix A(Copy,map,5,false);
   int indices[5];
   double values[5] = {1,2,3,4,5};
   for(int i=0;i<A.NumMyRows()-5;i++) {
      int index = A.RowMap().GID(i);
      for(int j=0;j<5;j++)
         indices[j] = A.RowMap().GID(i+j);
      A.InsertGlobalValues(index,5,values,indices);
   }
   for(int i=A.NumMyRows()-5;i<A.NumMyRows();i++) {
      int index = A.RowMap().GID(i);
      for(int j=0;j<5;j++)
         indices[j] = A.RowMap().GID(j);
      A.InsertGlobalValues(index,5,values,indices);
   }
   A.FillComplete();

   // B matrix...already lumped
   Epetra_CrsMatrix B(Copy,map,1,true);
   double number = 1.0/15.0;
   for(int i=0;i<B.NumMyRows();i++) {
      int index = B.RowMap().GID(i);
      B.InsertGlobalValues(index,1,&number,&index);
   }
   B.FillComplete();

   Teko::LinearOp pA = Thyra::epetraLinearOp(rcpFromRef(A));
   Teko::LinearOp pB = Thyra::epetraLinearOp(rcpFromRef(B));
   Teko::LinearOp lumpedA = getInvLumpedMatrix(pA);

   {
      std::stringstream ss;
      Teuchos::FancyOStream fos(rcpFromRef(ss),"      |||");
      const bool result = tester.compare( *pB, *lumpedA, Teuchos::ptrFromRef(fos) );
      TEST_ASSERT(result,
             std::endl << "   tLummping::test_invLumping "
             << ": Testing basic inv lumping functionality");
      if(not result || verbosity>=10)
         os << ss.str();
   }

   return allPassed;
}
开发者ID:00liujj,项目名称:trilinos,代码行数:55,代码来源:tLumping.cpp

示例3:

TEUCHOS_UNIT_TEST(tLU2x2InverseOp, exact_test_tpetra)
{
   Kokkos::initialize();

   // build global (or serial communicator)
   RCP<const Teuchos::Comm<int> > Comm = Tpetra::DefaultPlatform::getDefaultPlatform ().getComm ();

   Teko::LinearOp  A_00 = build2x2(Comm,1,2,3,4);
   Teko::LinearOp  A_01 = build2x2(Comm,5,6,7,8);
   Teko::LinearOp  A_02 = build2x2(Comm,9,10,11,12);
   Teko::LinearOp  A_10 = build2x2(Comm,9,10,11,12);
   Teko::LinearOp  A_11 = build2x2(Comm,-13,-14,-15,-16);
   Teko::LinearOp  A_12 = build2x2(Comm,-1,-4,-5,-6);
   Teko::LinearOp  A_20 = build2x2(Comm,-9,-10,-11,-12);
   Teko::LinearOp  A_21 = build2x2(Comm,13,14,15,16);
   Teko::LinearOp  A_22 = build2x2(Comm,1,4,5,6);
   Teko::BlockedLinearOp A = Teko::createBlockedOp();
   Teko::beginBlockFill(A,3,3);
      Teko::setBlock(0,0,A,A_00);
      Teko::setBlock(0,1,A,A_01);
      Teko::setBlock(0,2,A,A_02);

      Teko::setBlock(1,0,A,A_10);
      Teko::setBlock(1,1,A,A_11);
      Teko::setBlock(1,2,A,A_12);

      Teko::setBlock(2,0,A,A_20);
      Teko::setBlock(2,1,A,A_21);
      Teko::setBlock(2,2,A,A_22);
   Teko::endBlockFill(A);

   std::string reorderType = "[ [0 1] 2]";
   Teuchos::RCP<const Teko::BlockReorderManager> brm = Teko::blockedReorderFromString(reorderType);
   Teko::ModifiableLinearOp re_A = Teuchos::rcp_const_cast<Thyra::LinearOpBase<double> >(Teko::buildReorderedLinearOp(*brm,A));
   Teko::ModifiableLinearOp final_A = Teuchos::rcp(new Teko::ReorderedLinearOp(brm,re_A));

   Thyra::LinearOpTester<double> tester;
   tester.dump_all(true);
   tester.show_all_tests(true);

   {
      const bool result = tester.compare( *final_A, *A, Teuchos::ptrFromRef(out));
      if (!result) {
         out << "Apply: FAILURE" << std::endl;
         success = false;
      }
      else
         out << "Apply: SUCCESS" << std::endl;
   }

   Kokkos::finalize();
}
开发者ID:agrippa,项目名称:Trilinos,代码行数:52,代码来源:tReorderBlocking.cpp

示例4: comm

TEUCHOS_UNIT_TEST(tStratimikosFactory, test_Defaults) 
{
  using Teuchos::RCP;
  using Teuchos::ParameterList;

  // build global (or serial communicator)
  #ifdef HAVE_MPI
     Epetra_MpiComm comm(MPI_COMM_WORLD);
  #else
     Epetra_SerialComm comm;
  #endif

  // build epetra operator
  RCP<Epetra_Operator> eA = buildSystem(comm,5);
  RCP<Thyra::LinearOpBase<double> > tA = Thyra::nonconstEpetraLinearOp(eA);

  // build stratimikos factory, adding Teko's version
  Stratimikos::DefaultLinearSolverBuilder stratFactory;
  stratFactory.setPreconditioningStrategyFactory(
        Teuchos::abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,Teko::StratimikosFactory>(),
        "Teko");
  RCP<const ParameterList> validParams = stratFactory.getValidParameters();
  stratFactory.setParameterList(Teuchos::rcp(new Teuchos::ParameterList(*validParams)));

  // print out Teko's parameter list and fail if it doesn't exist!
  TEST_NOTHROW(validParams->sublist("Preconditioner Types").sublist("Teko").print(out,
        ParameterList::PrintOptions().showDoc(true).indent(2).showTypes(true)));

  // build teko preconditioner factory
  RCP<Thyra::PreconditionerFactoryBase<double> > precFactory
        = stratFactory.createPreconditioningStrategy("Teko");

  // make sure factory is built
  TEST_ASSERT(precFactory!=Teuchos::null);

  // build preconditioner
  RCP<Thyra::PreconditionerBase<double> > prec = Thyra::prec<double>(*precFactory,tA);
  TEST_ASSERT(prec!=Teuchos::null);

  // build an operator to test against
  RCP<const Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromStratimikos();
  RCP<const Teko::InverseFactory> invFact = invLib->getInverseFactory("Amesos");
  Teko::LinearOp testOp = Teko::buildInverse(*invFact,tA);

  Teko::LinearOp precOp = prec->getUnspecifiedPrecOp();
  TEST_ASSERT(precOp!=Teuchos::null);

  Thyra::LinearOpTester<double> tester;
  tester.show_all_tests(true);
  tester.set_all_error_tol(0);
  TEST_ASSERT(tester.compare(*precOp,*testOp,Teuchos::ptrFromRef(out)));
}
开发者ID:rainiscold,项目名称:trilinos,代码行数:52,代码来源:tStratimikosFactory.cpp

示例5: Comm

TEUCHOS_UNIT_TEST(tLU2x2InverseOp, exact_test)
{
   // build global (or serial communicator)
   #ifdef HAVE_MPI
      Epetra_MpiComm Comm(MPI_COMM_WORLD);
   #else
      Epetra_SerialComm Comm;
   #endif

   Teko::LinearOp  A_00 = build2x2(Comm,1,2,3,4);
   Teko::LinearOp  A_01 = build2x2(Comm,5,6,7,8);
   Teko::LinearOp  A_10 = build2x2(Comm,9,10,11,12);
   Teko::LinearOp  A_11 = build2x2(Comm,-13,-14,-15,-16);
   Teko::BlockedLinearOp A = Teko::toBlockedLinearOp(Thyra::block2x2(A_00,A_01,A_10,A_11));

   Teko::LinearOp  S = build2x2(Comm,26.000000000000000, 28.000000000000004, 30.000000000000000, 32.000000000000000);

   Teko::LinearOp iA_00 = build2x2(Comm,-1.000000000000000,  0.500000000000000,  0.749999999999998, -0.249999999999998);
   Teko::LinearOp iA_01 = build2x2(Comm,-3.000000000000004,  2.500000000000003,  2.750000000000008, -2.250000000000007);
   Teko::LinearOp iA_10 = build2x2(Comm,-1.999999999999999,  1.499999999999999,  1.749999999999999, -1.249999999999999);
   Teko::LinearOp iA_11 = build2x2(Comm, 4.000000000000001, -3.500000000000001, -3.750000000000001,  3.250000000000001);
   Teko::LinearOp iA = Thyra::block2x2(iA_00,iA_01,iA_10,iA_11);

   Thyra::LinearOpTester<double> tester;
   tester.dump_all(true);
   tester.show_all_tests(true);

   {
      RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromStratimikos();
      RCP<Teko::InverseFactory> invFact = invLib->getInverseFactory("Amesos");

      Teko::LinearOp invA_00 = Teko::buildInverse(*invFact,A_00);
      Teko::LinearOp invS    = Teko::buildInverse(*invFact,S);

      Teko::LinearOp invA = Teko::createLU2x2InverseOp(A,invA_00,invA_00,invS,"Approximation");
      
      const bool result = tester.compare( *invA, *iA, &out);
      if (!result) {
         out << "Apply: FAILURE" << std::endl;
         success = false;
      }
      else
         out << "Apply: SUCCESS" << std::endl;
   }
}
开发者ID:haripandey,项目名称:trilinos,代码行数:45,代码来源:tLU2x2InverseOp.cpp

示例6: Comm

TEUCHOS_UNIT_TEST(tProbingFactory, invlib_constr)
{
   // build global (or serial communicator)
   #ifdef HAVE_MPI
      Epetra_MpiComm Comm(MPI_COMM_WORLD);
   #else
      Epetra_SerialComm Comm;
   #endif

   Teko::LinearOp lo = buildSystem(Comm,10);

   Teuchos::ParameterList subList;
   subList.set("Type","Probing Preconditioner");
   subList.set("Inverse Type","Amesos");
   subList.set("Probing Graph Operator",lo);

   Teuchos::ParameterList pl;
   pl.set("Prober",subList);
   
   
   Teuchos::RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromParameterList(pl);
   Teuchos::RCP<Teko::InverseFactory> proberFactory = invLib->getInverseFactory("Prober");
   Teuchos::RCP<Teko::InverseFactory> directSolveFactory = invLib->getInverseFactory("Amesos");

   {
      Teko::LinearOp probedInverse = Teko::buildInverse(*proberFactory,lo);
      Teko::LinearOp invLo = Teko::buildInverse(*directSolveFactory,lo);
   
      Thyra::LinearOpTester<double> tester;
      tester.dump_all(true);
      tester.show_all_tests(true);
   
      {
         const bool result = tester.compare( *probedInverse, *invLo, &out);
         if (!result) {
            out << "Apply: FAILURE" << std::endl;
            success = false;
         }
         else
            out << "Apply: SUCCESS" << std::endl;
      }
   }
}
开发者ID:haripandey,项目名称:trilinos,代码行数:43,代码来源:tProbingFactory.cpp

示例7: Comm

TEUCHOS_UNIT_TEST(tDiagonalPreconditionerFactory, diag_inv_test)
{
   using Teuchos::RCP;

   // build global (or serial communicator)
   #ifdef HAVE_MPI
      Epetra_MpiComm Comm(MPI_COMM_WORLD);
   #else
      Epetra_SerialComm Comm;
   #endif

   // preconditioners to test
   std::string precName[] = {"AbsRowSum","Diagonal","Lumped"};
   int numPrec = 3;

   RCP<Teuchos::ParameterList> pl = buildLibPL(4);
   RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromParameterList(*pl); 

   Teko::LinearOp A = buildSystem(Comm,20);
   
   for(int i=0;i<numPrec;i++) {
      RCP<Teko::InverseFactory> invFact = invLib->getInverseFactory(precName[i]);
      Teko::LinearOp idA_fact = Teko::buildInverse(*invFact,A);
      Teko::LinearOp idA_drct = Teko::getInvDiagonalOp(A,Teko::getDiagonalType(precName[i])); 
  
      Thyra::LinearOpTester<double> tester;
      tester.show_all_tests(true);
   
      const bool result = tester.compare( *idA_fact, *idA_drct, Teuchos::ptrFromRef(out));
      if (!result) {
         out << "Apply 0: FAILURE (\"" << precName[i] << "\")" << std::endl;
         success = false;
      }
      else
         out << "Apply 0: SUCCESS (\"" << precName[i] << "\")" << std::endl;

      // test type
      Teko::LinearOp srcOp = Teko::extractOperatorFromPrecOp(idA_fact);
      TEST_ASSERT(Teuchos::rcp_dynamic_cast<const Thyra::DiagonalLinearOpBase<double> >(srcOp)!=Teuchos::null);
   }
}
开发者ID:00liujj,项目名称:trilinos,代码行数:41,代码来源:tDiagonalPreconditionerFactory.cpp

示例8: test_apply

bool tBlockLowerTriInverseOp_tpetra::test_apply(int verbosity,std::ostream & os)
{
   bool status = false;
   bool allPassed = true;

   RCP<Thyra::PhysicallyBlockedLinearOpBase<ST> > U = getLowerTriBlocks(A_);
   RCP<const Thyra::LinearOpBase<ST> > invTri = createBlockLowerTriInverseOp(U,invDiag_);

   Thyra::LinearOpTester<ST> tester;
   tester.show_all_tests(true);
   std::stringstream ss;
   Teuchos::FancyOStream fos(Teuchos::rcpFromRef(ss),"      |||");
   const bool result = tester.compare( *invA_, *invTri, Teuchos::ptrFromRef(fos) );
   TEST_ASSERT(result,
          std::endl << "   tBlockLowerTriInverseOp_tpetra::test_apply "
                    << ": Comparing implicitly generated operator to exact operator");
     if(not result || verbosity>=10) 
        os << ss.str(); 

   return allPassed;
}
开发者ID:agrippa,项目名称:Trilinos,代码行数:21,代码来源:tBlockLowerTriInverseOp_tpetra.cpp

示例9:

  TEUCHOS_UNIT_TEST(assembly_engine, z_basic_epetra_vtpetra)
  {
     TEUCHOS_ASSERT(tLinearOp!=Teuchos::null);
     TEUCHOS_ASSERT(eLinearOp!=Teuchos::null);

     TEUCHOS_ASSERT(tVector!=Teuchos::null);
     TEUCHOS_ASSERT(eVector!=Teuchos::null);

     Thyra::LinearOpTester<double> tester;
     tester.set_all_error_tol(1e-14);
     tester.show_all_tests(true);
     tester.dump_all(true);
     tester.num_random_vectors(200);

     {
        const bool result = tester.compare( *tLinearOp, *eLinearOp, Teuchos::ptrFromRef(out) );
        TEST_ASSERT(result);
     }

     {
        const bool result = Thyra::testRelNormDiffErr(
           "Tpetra",*tVector,
           "Epetra",*eVector,
           "linear_properties_error_tol()", 1e-14,
           "linear_properties_warning_tol()", 1e-14,
           &out);
        TEST_ASSERT(result);
     }
  }
开发者ID:00liujj,项目名称:trilinos,代码行数:29,代码来源:assembly_engine.cpp

示例10: test_scaledOp

bool tNeumannSeries::test_scaledOp(int verbosity,std::ostream & os)
{
   bool status = false;
   bool allPassed = true;

   // perform actual test
   Thyra::LinearOpTester<double> tester;
   tester.show_all_tests(true);
   std::stringstream ss;
   Teuchos::FancyOStream fos(rcpFromRef(ss),"      |||");

   {
      // build library parameter list
      Teuchos::RCP<Teuchos::ParameterList> pl = buildLibPL(2,"Diagonal");
      if(verbosity>=10) {
         os << "   tNeumannSeries::test_scaledOp :"
            << " printing library parameter list" << std::endl;
         pl->print(os);
      }

      RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromParameterList(*pl);
      RCP<Teko::InverseFactory> neumann = invLib->getInverseFactory("Neumann");
      RCP<Teko::InverseFactory> direct = invLib->getInverseFactory("Amesos");

      Teko::LinearOp op = buildExampleOp(2,*GetComm());
   
      Teko::LinearOp neuInv = Teko::buildInverse(*neumann,op);
      Teko::LinearOp dirInv = Teko::buildInverse(*direct,op);

      const bool result = tester.compare( *neuInv, *dirInv, Teuchos::ptrFromRef(fos) );
      TEST_ASSERT(result,
             std::endl << "   tNeumannSeries::test_scaledOp "
             << ": Comparing factory generated operator to correct operator");
      if(not result || verbosity>=10) 
         os << ss.str(); 
   }
 
   return allPassed;
}
开发者ID:00liujj,项目名称:trilinos,代码行数:39,代码来源:tNeumannSeries.cpp

示例11: ptrFromRef

TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( SimpleDenseLinearOp, basic,
  Scalar )
{

  using Teuchos::rcp_dynamic_cast;
  typedef ScalarTraits<Scalar> ST;

  const RCP<MultiVectorBase<Scalar> > mv =
    createSerialMultiVector<Scalar>(g_dim, g_dim/2, ST::one());
  const RCP<LinearOpBase<Scalar> > op =
    createNonconstSimpleDenseLinearOp<Scalar>(mv);

  TEST_EQUALITY(
    mv,
    rcp_dynamic_cast<SimpleDenseLinearOp<Scalar> >(op)->getNonconstMultiVector()
    );

  Thyra::LinearOpTester<Scalar> linearOpTester;
  linearOpTester.dump_all(g_dumpAll);
  TEST_ASSERT(linearOpTester.check(*op, ptrFromRef(out)));

}
开发者ID:00liujj,项目名称:trilinos,代码行数:22,代码来源:SimpleDenseLinearOp_UnitTests.cpp

示例12: comm

TEUCHOS_UNIT_TEST(tExplicitOps, transpose)
{
   // build global (or serial communicator)
   #ifdef HAVE_MPI
      Epetra_MpiComm comm(MPI_COMM_WORLD);
   #else
      Epetra_SerialComm comm;
   #endif

   int nx = 39; // essentially random values
   int ny = 53;

   // create some big blocks to play with
   Trilinos_Util::CrsMatrixGallery FGallery("recirc_2d",comm,false); // CJ TODO FIXME: change for Epetra64
   FGallery.Set("nx",nx);
   FGallery.Set("ny",ny);
   Epetra_CrsMatrix & epetraF = FGallery.GetMatrixRef();
   Teko::LinearOp F = Thyra::epetraLinearOp(rcp(new Epetra_CrsMatrix(epetraF)));
   Teko::LinearOp F_T = Teko::explicitTranspose(F);
   Teko::LinearOp aF = Thyra::adjoint(F);

   Teuchos::RCP<const Epetra_Operator> eOp = Thyra::get_Epetra_Operator(*F_T);
   TEST_ASSERT(eOp!=Teuchos::null);
   Teuchos::RCP<const Epetra_CrsMatrix> eCrs = Teuchos::rcp_dynamic_cast<const Epetra_CrsMatrix>(eOp);
   TEST_ASSERT(eCrs!=Teuchos::null);

   Thyra::LinearOpTester<double> tester;
   tester.set_all_error_tol(1e-14);
   tester.show_all_tests(true);

   {
      std::stringstream ss;
      const bool result = tester.compare( *aF, *F_T, Teuchos::ptrFromRef(out) );
      TEST_ASSERT(result);
   }
}
开发者ID:00liujj,项目名称:trilinos,代码行数:36,代码来源:tExplicitOps.cpp

示例13:

  TEUCHOS_UNIT_TEST(assembly_engine, z_basic_epetra_vtpetra)
  {
    PHX::InitializeKokkosDevice();

     TEUCHOS_ASSERT(tLinearOp!=Teuchos::null);
     TEUCHOS_ASSERT(eLinearOp!=Teuchos::null);

     TEUCHOS_ASSERT(tVector!=Teuchos::null);
     TEUCHOS_ASSERT(eVector!=Teuchos::null);

     Thyra::LinearOpTester<double> tester;
     tester.set_all_error_tol(1e-14);
     tester.show_all_tests(true);
     tester.dump_all(true);
     tester.num_random_vectors(200);

     {
        const bool result = tester.compare( *tLinearOp, *eLinearOp, Teuchos::ptrFromRef(out) );
        TEST_ASSERT(result);
     }

     {
        const bool result = Thyra::testRelNormDiffErr(
           "Tpetra",*tVector,
           "Epetra",*eVector,
           "linear_properties_error_tol()", 1e-14,
           "linear_properties_warning_tol()", 1e-14,
           &out);
        TEST_ASSERT(result);
     }


     // Need to kill global objects so that memory leaks on kokkos ref
     // count pointing doesn't trigger test failure.
     eLinearOp = Teuchos::null;
     tLinearOp = Teuchos::null;
     eVector = Teuchos::null;
     tVector = Teuchos::null;

     PHX::FinalizeKokkosDevice();
  }
开发者ID:rainiscold,项目名称:trilinos,代码行数:41,代码来源:assembly_engine.cpp

示例14: exampleImplicitlyComposedLinearOperators


//.........这里部分代码省略.........
    E = mvE,
    F = mvF,
    J = mvJ,
    K = mvK,
    L = mvL,
    N = mvN,
    P = mvP,
    Q = mvQ;

  out << describe(*A, verbLevel);
  out << describe(*B, verbLevel);
  out << describe(*C, verbLevel);
  out << describe(*E, verbLevel);
  out << describe(*F, verbLevel);
  out << describe(*J, verbLevel);
  out << describe(*K, verbLevel);
  out << describe(*L, verbLevel);
  out << describe(*N, verbLevel);
  out << describe(*P, verbLevel);
  out << describe(*Q, verbLevel);

  //
  // B) Create the composed linear operators
  //

  // I
  const RCP<const LinearOpBase<Scalar> > I = identity(space1, "I");

  // D = diag(d)
  const RCP<const LinearOpBase<Scalar> > D = diagonal(d, "D");

  // M00 = [ gama*B*A + C,  E + F ] ^H
  //       [ J^H * A,       I     ]
  const RCP<const LinearOpBase<Scalar> > M00 =
    adjoint(
      block2x2(
        add( scale(gamma,multiply(B,A)), C ),  add( E, F ),
        multiply(adjoint(J),A),                I
        ),
      "M00"
      );

  out << "\nM00 = " << describe(*M00, verbLevel);

  // M01 = beta * [ Q ]
  //              [ K ]
  const RCP<const LinearOpBase<Scalar> > M01 =
    scale(
      beta,
      block2x1( Q, K ),
      "M01"
      );

  out << "\nM01 = "  << describe(*M01, verbLevel);
            
  // M10 = [ L * N^H,  eta*P ]
  const RCP<const LinearOpBase<Scalar> > M10 =
    block1x2(
      multiply(L,adjoint(N)),  scale(eta,P),
      "M10"
      );

  out << "\nM10 = " << describe(*M10, verbLevel);

  // M11 = D - Q^H*Q
  const RCP<const LinearOpBase<Scalar> > M11 =
    subtract( D, multiply(adjoint(Q),Q), "M11" );

  out << "\nM11 = "  << describe(*M11, verbLevel);
  

  // M = [ M00, M01 ]
  //     [ M10, M11 ]
  const RCP<const LinearOpBase<Scalar> > M =
    block2x2(
      M00, M01,
      M10, M11,
      "M"
      );

  out << "\nM = " << describe(*M, verbLevel);

  
  //
  // C) Test the final composed operator
  //

  Thyra::LinearOpTester<Scalar> linearOpTester;
  linearOpTester.set_all_error_tol(errorTol);
  linearOpTester.check_adjoint(testAdjoint);
  if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH))
    linearOpTester.show_all_tests(true);
  if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME))
    linearOpTester.dump_all(true);

  const bool result = linearOpTester.check(*M,&out);

  return result;

}
开发者ID:haripandey,项目名称:trilinos,代码行数:101,代码来源:exampleImplicitlyComposedLinearOperators.cpp

示例15: test_PCDStrategy

bool tPCDStrategy::test_PCDStrategy(int verbosity,std::ostream & os)
{
   bool status = false;
   bool allPassed = true;

   Thyra::LinearOpTester<double> tester;
   tester.show_all_tests(true);
   tester.set_all_error_tol(tolerance_);

   Teko::LinearOp M1 = buildExampleOp(1,*GetComm(),1.0);
   Teko::LinearOp M2 = buildExampleOp(2,*GetComm(),1.0);
   Teko::LinearOp A = Thyra::nonconstBlock2x2<double>(buildExampleOp(2,*GetComm(),1.0),
                                      buildExampleOp(1,*GetComm(),2.0),
                                      buildExampleOp(1,*GetComm(),3.0),
                                      buildExampleOp(2,*GetComm(),4.0));
   Teko::BlockedLinearOp blkA = Teko::toBlockedLinearOp(A);

   Teko::LinearOp laplace = Teko::explicitMultiply(M2,M1);
   Teko::LinearOp Fp = M1;
   Teko::LinearOp Qp = buildExampleOp(3,*GetComm(),1.0);

   std::string pcdStr      = Teko::NS::PCDStrategy::getPCDString();
   std::string presLapStr  = Teko::NS::PCDStrategy::getPressureLaplaceString();
   std::string presMassStr = Teko::NS::PCDStrategy::getPressureMassString();

   RCP<Teko::StaticRequestCallback<Teko::LinearOp> > pcdCb
         = rcp(new Teko::StaticRequestCallback<Teko::LinearOp>(pcdStr,Fp));
   RCP<Teko::StaticRequestCallback<Teko::LinearOp> > lapCb
         = rcp(new Teko::StaticRequestCallback<Teko::LinearOp>(presLapStr,laplace));
   RCP<Teko::StaticRequestCallback<Teko::LinearOp> > massCb
         = rcp(new Teko::StaticRequestCallback<Teko::LinearOp>(presMassStr,Qp));

   RCP<Teko::RequestHandler> rh = rcp(new Teko::RequestHandler);
   rh->addRequestCallback(pcdCb);
   rh->addRequestCallback(lapCb);
   rh->addRequestCallback(massCb);

   RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromStratimikos();
   RCP<Teko::InverseFactory> inverseFact = invLib->getInverseFactory("Amesos");

   // test the inverse of the 00 block
   {
      bool result;
      std::stringstream ss;
      Teuchos::FancyOStream fos(Teuchos::rcpFromRef(ss),"      |||");

      Teko::LinearOp invA00 = inverseFact->buildInverse(M2);
      Teko::BlockPreconditionerState state;
      Teko::NS::PCDStrategy strategy(inverseFact,inverseFact);
      strategy.setRequestHandler(rh);

      // build the state object
      // state.addLinearOp(presLapStr,  laplace);
      // state.addLinearOp(pcdStr,      Fp);
      // state.addLinearOp(presMassStr, Qp);

      // test the 0,0 block inverses: hat
      Teko::LinearOp hatInvA00 = strategy.getHatInvA00(blkA,state);
      ss.str("");
      result = tester.compare( *hatInvA00, *invA00, Teuchos::ptrFromRef(fos) );
      TEST_ASSERT(result,
            std::endl << "   tPCDStrategy::test_PCDStrategy " << toString(status)
                      << " : Comparing invHatA00 operators");
      if(not result || verbosity>=10)
         os << ss.str();

      // test the 0,0 block inverses: tilde
      Teko::LinearOp tildeInvA00 = strategy.getTildeInvA00(blkA,state);
      ss.str("");
      result = tester.compare( *tildeInvA00, *invA00, Teuchos::ptrFromRef(fos) );
      TEST_ASSERT(result,
            std::endl << "   tPCDStrategy::test_PCDStrategy " << toString(status)
                      << " : Comparing invTildeA00 operators");
      if(not result || verbosity>=10)
         os << ss.str();
   }

   // test the inverse of the Schur complement
   {
      bool result;
      std::stringstream ss;
      Teuchos::FancyOStream fos(Teuchos::rcpFromRef(ss),"      |||");

      Teko::LinearOp invLaplace = inverseFact->buildInverse(laplace);
      Teko::LinearOp iQp = Teko::getInvDiagonalOp(Qp);
      Teko::LinearOp invSchur = multiply(iQp,Fp,invLaplace);

      Teko::BlockPreconditionerState state;
      Teko::NS::PCDStrategy strategy(inverseFact,inverseFact);
      strategy.setRequestHandler(rh);

      // build the state object
      // state.addLinearOp(presLapStr,  laplace);
      // state.addLinearOp(pcdStr,      Fp);
      // state.addLinearOp(presMassStr, Qp);

      // test the 0,0 block inverses: hat
      Teko::LinearOp invS_strategy = strategy.getInvS(blkA,state);
      ss.str("");
      result = tester.compare( *invS_strategy, *invSchur, Teuchos::ptrFromRef(fos) );
//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:trilinos,代码行数:101,代码来源:tPCDStrategy.cpp


注:本文中的thyra::LinearOpTester类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。