MueLu  Version of the Day
MueLu_CreateEpetraPreconditioner.hpp
Go to the documentation of this file.
1 #ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_HPP
2 #define MUELU_CREATE_EPETRA_PRECONDITIONER_HPP
3 
4 #include <Teuchos_XMLParameterListHelpers.hpp>
5 #include <Xpetra_CrsMatrix.hpp>
6 #include <Xpetra_MultiVector.hpp>
7 #include <Xpetra_MultiVectorFactory.hpp>
8 
9 #include <MueLu.hpp>
10 
11 #include <MueLu_EpetraOperator.hpp>
12 #include <MueLu_Exceptions.hpp>
13 #include <MueLu_Hierarchy.hpp>
15 #include <MueLu_MasterList.hpp>
16 #include <MueLu_MLParameterListInterpreter.hpp>
17 #include <MueLu_ParameterListInterpreter.hpp>
18 #include <MueLu_Utilities.hpp>
19 #include <MueLu_HierarchyUtils.hpp>
20 
23 #if defined(HAVE_MUELU_EPETRA)
24 namespace MueLu {
25 
35  Teuchos::RCP<MueLu::EpetraOperator>
36  CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA,
37  // FIXME: why is it non-const
38  Teuchos::ParameterList& paramListIn,
39  const Teuchos::RCP<Epetra_MultiVector>& inCoords = Teuchos::null,
40  const Teuchos::RCP<Epetra_MultiVector>& inNullspace = Teuchos::null)
41  {
42  typedef double SC;
43  typedef int LO;
44  typedef int GO;
45  typedef Xpetra::EpetraNode NO;
46 
47  using Teuchos::ParameterList;
48 
49  typedef Xpetra::MultiVector<SC, LO, GO, NO> MultiVector;
50  typedef Xpetra::Matrix<SC, LO, GO, NO> Matrix;
53 
54  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
55  RCP<MultiVector> coordinates = Teuchos::null;
56  if (inCoords != Teuchos::null) {
57  coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
58  }
59  RCP<MultiVector> nullspace = Teuchos::null;
60  if (inNullspace != Teuchos::null) {
61  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC, LO, GO, NO>(inNullspace);
62  }
63  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC,LO,GO,NO>(A,paramListIn,coordinates,nullspace);
64  return rcp(new EpetraOperator(H));
65  }
66 
75  Teuchos::RCP<MueLu::EpetraOperator>
76  CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix> & inA,
77  const Teuchos::RCP<Epetra_MultiVector>& inCoords = Teuchos::null,
78  const Teuchos::RCP<Epetra_MultiVector>& inNullspace = Teuchos::null) {
79  Teuchos::ParameterList paramList;
80  return CreateEpetraPreconditioner(inA, paramList, inCoords, inNullspace);
81  }
82 
92  Teuchos::RCP<MueLu::EpetraOperator>
93  CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix> & A,
94  const std::string& xmlFileName,
95  const Teuchos::RCP<Epetra_MultiVector>& inCoords = Teuchos::null,
96  const Teuchos::RCP<Epetra_MultiVector>& inNullspace = Teuchos::null)
97  {
98  Teuchos::ParameterList paramList;
99  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
100 
101  return CreateEpetraPreconditioner(A, paramList, inCoords, inNullspace);
102  }
103 
104  void ReuseEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA, MueLu::EpetraOperator& Op) {
105  typedef double SC;
106  typedef int LO;
107  typedef int GO;
108  typedef Xpetra::EpetraNode NO;
109 
110  typedef Xpetra::Matrix<SC,LO,GO,NO> Matrix;
111  typedef MueLu ::Hierarchy<SC,LO,GO,NO> Hierarchy;
112 
113  RCP<Hierarchy> H = Op.GetHierarchy();
114  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC,LO,GO,NO>(inA);
115 
116  MueLu::ReuseXpetraPreconditioner<SC,LO,GO,NO>(A, H);
117  }
118 
119 } //namespace
120 #endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA
121 
122 #endif //ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_HPP
void ReuseEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, MueLu::EpetraOperator &Op)
Namespace for MueLu classes and methods.
Teuchos::RCP< MueLu::EpetraOperator > CreateEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, Teuchos::ParameterList &paramListIn, const Teuchos::RCP< Epetra_MultiVector > &inCoords=Teuchos::null, const Teuchos::RCP< Epetra_MultiVector > &inNullspace=Teuchos::null)
Helper function to create a MueLu preconditioner that can be used by Epetra.Given a EpetraCrs_Matrix...
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
Provides methods to build a multigrid hierarchy and apply multigrid cycles.