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_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  // FIXME: why is it non-const
36  Teuchos::ParameterList& paramListIn)
37  {
38  using SC = double;
39  using LO = int;
40  using GO = int;
41  using NO = Xpetra::EpetraNode;
42 
44 
45  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
46  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
49 
50  Teuchos::ParameterList& userList = paramListIn.sublist("user data");
51  if (userList.isParameter("Coordinates")) {
53  try {
54  coordinates = EpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO>(userList.get<RCP<Epetra_MultiVector> >("Coordinates"));
56  coordinates = userList.get<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates");
57  }
58  if(Teuchos::nonnull(coordinates)){
59  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO> > >("Coordinates", coordinates);
60  }
61  }
62  if (userList.isParameter("Nullspace")) {
64  try {
65  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(userList.get<RCP<Epetra_MultiVector> >("Nullspace"));
67  nullspace = userList.get<RCP<Xpetra::MultiVector<SC, LO, GO, NO> > >("Nullspace");
68  }
69  if(Teuchos::nonnull(nullspace)){
70  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO> > >("Nullspace", nullspace);
71  }
72  }
73 
74  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
75  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC,LO,GO,NO>(A, paramListIn);
76  return rcp(new EpetraOperator(H));
77  }
78 
88  const std::string& xmlFileName)
89  {
90  Teuchos::ParameterList paramList;
91  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
92 
93  return CreateEpetraPreconditioner(A, paramList);
94  }
95 
104  {
105  Teuchos::ParameterList paramList;
106  return CreateEpetraPreconditioner(A, paramList);
107  }
108 
109  void ReuseEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA, MueLu::EpetraOperator& Op) {
110  using SC = double;
111  using LO = int;
112  using GO = int;
113  using NO = Xpetra::EpetraNode;
114 
116 
117  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
119 
120  RCP<Hierarchy> H = Op.GetHierarchy();
121  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC,LO,GO,NO>(inA);
122 
123  MueLu::ReuseXpetraPreconditioner<SC,LO,GO,NO>(A, H);
124  }
125 
126 
127 } //namespace
128 #endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA
129 
130 #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)
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)
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...
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
const Epetra_Comm & Comm() const
Provides methods to build a multigrid hierarchy and apply multigrid cycles.