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 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
11 #define MUELU_CREATE_EPETRA_PRECONDITIONER_CPP
12 
14 #include <Xpetra_CrsMatrix.hpp>
15 #include <Xpetra_MultiVector.hpp>
16 #include <Xpetra_MultiVectorFactory.hpp>
17 
18 #include <MueLu.hpp>
19 
20 #include <MueLu_EpetraOperator.hpp>
21 #include <MueLu_Exceptions.hpp>
22 #include <MueLu_Hierarchy.hpp>
24 #include <MueLu_MasterList.hpp>
25 #include <MueLu_ParameterListInterpreter.hpp>
26 #include <MueLu_Utilities.hpp>
27 #include <MueLu_HierarchyUtils.hpp>
28 
31 #if defined(HAVE_MUELU_EPETRA)
32 namespace MueLu {
33 
43  // FIXME: why is it non-const
44  Teuchos::ParameterList& paramListIn) {
45  using SC = double;
46  using LO = int;
47  using GO = int;
48  using NO = Xpetra::EpetraNode;
49 
51 
52  using MultiVector = Xpetra::MultiVector<SC, LO, GO, NO>;
53  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
56 
57  Teuchos::ParameterList& userList = paramListIn.sublist("user data");
58  if (userList.isParameter("Coordinates")) {
60  try {
61  coordinates = EpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO>(userList.get<RCP<Epetra_MultiVector> >("Coordinates"));
63  coordinates = userList.get<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates");
64  }
65  if (Teuchos::nonnull(coordinates)) {
66  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Coordinates", coordinates);
67  }
68  }
69  if (userList.isParameter("Nullspace")) {
71  try {
72  nullspace = EpetraMultiVector_To_XpetraMultiVector<SC, LO, GO, NO>(userList.get<RCP<Epetra_MultiVector> >("Nullspace"));
74  nullspace = userList.get<RCP<Xpetra::MultiVector<SC, LO, GO, NO> > >("Nullspace");
75  }
76  if (Teuchos::nonnull(nullspace)) {
77  userList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType, LO, GO, NO> > >("Nullspace", nullspace);
78  }
79  }
80 
81  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
82  RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner<SC, LO, GO, NO>(A, paramListIn);
83  return rcp(new EpetraOperator(H));
84 }
85 
95  const std::string& xmlFileName) {
96  Teuchos::ParameterList paramList;
97  Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(&paramList), *Xpetra::toXpetra(A->Comm()));
98 
99  return CreateEpetraPreconditioner(A, paramList);
100 }
101 
110  Teuchos::ParameterList paramList;
111  return CreateEpetraPreconditioner(A, paramList);
112 }
113 
114 void ReuseEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA, MueLu::EpetraOperator& Op) {
115  using SC = double;
116  using LO = int;
117  using GO = int;
118  using NO = Xpetra::EpetraNode;
119 
121 
122  using Matrix = Xpetra::Matrix<SC, LO, GO, NO>;
124 
125  RCP<Hierarchy> H = Op.GetHierarchy();
126  RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
127 
128  MueLu::ReuseXpetraPreconditioner<SC, LO, GO, NO>(A, H);
129 }
130 
131 } // namespace MueLu
132 #endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA
133 
134 #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)
bool nonnull(const std::shared_ptr< T > &p)
LocalOrdinal LO
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.