MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_CreateEpetraPreconditioner.cpp
Go to the documentation of this file.
1 #ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
2 #define MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
3 
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_ParameterListInterpreter.hpp>
17 #include <MueLu_Utilities.hpp>
18 #include <MueLu_HierarchyUtils.hpp>
19 
22 #if defined(HAVE_MUELU_EPETRA)
23 namespace MueLu {
24 
34  // FIXME: why is it non-const
35  Teuchos::ParameterList& paramListIn) {
36  using SC = double;
37  using LO = int;
38  using GO = int;
39  using NO = Xpetra::EpetraNode;
40 
42 
43  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
44  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
47 
48  Teuchos::ParameterList& userList = paramListIn.sublist("user data");
49  if (userList.isParameter("Coordinates")) {
51  try {
52  coordinates = EpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO>(userList.get<RCP<Epetra_MultiVector> >("Coordinates"));
54  coordinates = userList.get<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates");
55  }
56  if (Teuchos::nonnull(coordinates)) {
57  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates", coordinates);
58  }
59  }
60  if (userList.isParameter("Nullspace")) {
62  try {
63  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC, LO, GO, NO>(userList.get<RCP<Epetra_MultiVector> >("Nullspace"));
65  nullspace = userList.get<RCP<Xpetra::MultiVector<SC, LO, GO, NO> > >("Nullspace");
66  }
67  if (Teuchos::nonnull(nullspace)) {
68  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Nullspace", nullspace);
69  }
70  }
71 
72  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
73  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC, LO, GO, NO>(A, paramListIn);
74  return rcp(new EpetraOperator(H));
75 }
76 
86  const std::string& xmlFileName) {
87  Teuchos::ParameterList paramList;
88  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
89 
90  return CreateEpetraPreconditioner(A, paramList);
91 }
92 
101  Teuchos::ParameterList paramList;
102  return CreateEpetraPreconditioner(A, paramList);
103 }
104 
105 void ReuseEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA, MueLu::EpetraOperator& Op) {
106  using SC = double;
107  using LO = int;
108  using GO = int;
109  using NO = Xpetra::EpetraNode;
110 
112 
113  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
115 
116  RCP<Hierarchy> H = Op.GetHierarchy();
117  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
118 
119  MueLu::ReuseXpetraPreconditioner<SC, LO, GO, NO>(A, H);
120 }
121 
122 } // namespace MueLu
123 #endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA
124 
125 #endif // ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
Various adapters that will create a MueLu preconditioner that is an Xpetra::Matrix.
void ReuseEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, MueLu::EpetraOperator &Op)
GlobalOrdinal GO
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool nonnull(const std::shared_ptr< T > &p)
LocalOrdinal LO
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
EpetraOperatorT< int > EpetraOperator
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< MueLu::EpetraOperator > CreateEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, Teuchos::ParameterList &paramListIn)
Helper function to create a MueLu preconditioner that can be used by Epetra.Given a EpetraCrs_Matrix...
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
Scalar SC
Node NO
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
const Epetra_Comm & Comm() const
Provides methods to build a multigrid hierarchy and apply multigrid cycles.