MueLu Version of the Day
Loading...
Searching...
No Matches
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
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
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)
24namespace MueLu {
25
33 Teuchos::RCP<MueLu::EpetraOperator>
34 CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix>& inA,
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
43 using Teuchos::ParameterList;
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")) {
52 RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO> > coordinates = Teuchos::null;
53 try {
54 coordinates = EpetraMultiVector_To_XpetraMultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO>(userList.get<RCP<Epetra_MultiVector> >("Coordinates"));
55 } catch(Teuchos::Exceptions::InvalidParameterType&) {
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")) {
63 RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<SC>::coordinateType,LO,GO,NO> > nullspace = Teuchos::null;
64 try {
65 nullspace = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(userList.get<RCP<Epetra_MultiVector> >("Nullspace"));
66 } catch(Teuchos::Exceptions::InvalidParameterType&) {
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
86 Teuchos::RCP<MueLu::EpetraOperator>
87 CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix> & A,
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
102 Teuchos::RCP<MueLu::EpetraOperator>
103 CreateEpetraPreconditioner(const Teuchos::RCP<Epetra_CrsMatrix> & A)
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
115 using Teuchos::ParameterList;
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.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Namespace for MueLu classes and methods.
void ReuseEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, MueLu::EpetraOperator &Op)
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,...