1 #ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_HPP 2 #define MUELU_CREATE_EPETRA_PRECONDITIONER_HPP 4 #include <Teuchos_XMLParameterListHelpers.hpp> 5 #include <Xpetra_CrsMatrix.hpp> 6 #include <Xpetra_MultiVector.hpp> 7 #include <Xpetra_MultiVectorFactory.hpp> 13 #include <MueLu_Hierarchy.hpp> 15 #include <MueLu_MLParameterListInterpreter.hpp> 16 #include <MueLu_ParameterListInterpreter.hpp> 17 #include <MueLu_Utilities.hpp> 18 #include <MueLu_HierarchyHelpers.hpp> 22 #if defined(HAVE_MUELU_EPETRA) 34 Teuchos::RCP<MueLu::EpetraOperator>
37 Teuchos::ParameterList& paramListIn,
38 const Teuchos::RCP<Epetra_MultiVector>& inCoords = Teuchos::null,
39 const Teuchos::RCP<Epetra_MultiVector>& inNullspace = Teuchos::null)
46 using Teuchos::ParameterList;
48 typedef Xpetra::MultiVector<SC, LO, GO, NO> MultiVector;
49 typedef Xpetra::Matrix<SC, LO, GO, NO> Matrix;
53 bool hasParamList = paramListIn.numParams();
55 RCP<HierarchyManager> mueLuFactory;
56 ParameterList paramList = paramListIn;
58 std::string syntaxStr =
"parameterlist: syntax";
59 if (hasParamList && paramList.isParameter(syntaxStr) && paramList.get<std::string>(syntaxStr) ==
"ml") {
60 paramList.remove(syntaxStr);
67 RCP<Hierarchy> H = mueLuFactory->CreateHierarchy();
68 H->setlib(Xpetra::UseEpetra);
71 RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC, LO, GO, NO>(inA);
72 H->GetLevel(0)->Set(
"A", A);
75 if (inCoords != Teuchos::null) {
76 RCP<MultiVector> coordinates = EpetraMultiVector_To_XpetraMultiVector<SC,LO,GO,NO>(inCoords);
77 H->GetLevel(0)->Set(
"Coordinates", coordinates);
81 RCP<MultiVector> nullspace;
82 if (inNullspace != Teuchos::null) {
83 nullspace = EpetraMultiVector_To_XpetraMultiVector<SC, LO, GO, NO>(inNullspace);
86 int nPDE = MasterList::getDefault<int>(
"number of equations");
87 if (paramList.isSublist(
"Matrix")) {
89 const Teuchos::ParameterList& operatorList = paramList.sublist(
"Matrix");
90 if (operatorList.isParameter(
"PDE equations"))
91 nPDE = operatorList.get<
int>(
"PDE equations");
93 }
else if (paramList.isParameter(
"number of equations")) {
95 nPDE = paramList.get<
int>(
"number of equations");
98 nullspace = Xpetra::MultiVectorFactory<SC,LO,GO,NO>::Build(A->getDomainMap(), nPDE);
100 nullspace->putScalar(Teuchos::ScalarTraits<SC>::one());
103 for (
int i = 0; i < nPDE; i++) {
104 Teuchos::ArrayRCP<SC> nsData = nullspace->getDataNonConst(i);
105 for (
int j = 0; j < nsData.size(); j++) {
106 GO GID = A->getDomainMap()->getGlobalElement(j) - A->getDomainMap()->getIndexBase();
108 if ((GID-i) % nPDE == 0)
109 nsData[j] = Teuchos::ScalarTraits<SC>::one();
114 H->GetLevel(0)->Set(
"Nullspace", nullspace);
116 Teuchos::ParameterList nonSerialList,dummyList;
120 mueLuFactory->SetupHierarchy(*H);
122 return rcp(
new EpetraOperator(H));
133 Teuchos::RCP<MueLu::EpetraOperator>
135 const Teuchos::RCP<Epetra_MultiVector>& inCoords = Teuchos::null,
136 const Teuchos::RCP<Epetra_MultiVector>& inNullspace = Teuchos::null) {
137 Teuchos::ParameterList paramList;
150 Teuchos::RCP<MueLu::EpetraOperator>
152 const std::string& xmlFileName,
153 const Teuchos::RCP<Epetra_MultiVector>& inCoords = Teuchos::null,
154 const Teuchos::RCP<Epetra_MultiVector>& inNullspace = Teuchos::null)
156 Teuchos::ParameterList paramList;
157 Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(¶mList), *Xpetra::toXpetra(A->Comm()));
168 typedef Xpetra::Matrix<SC,LO,GO,NO> Matrix;
169 typedef Xpetra::Operator<SC,LO,GO,NO> Operator;
172 RCP<Hierarchy> H = Op.GetHierarchy();
175 "ReuseTpetraPreconditioner: Hierarchy has no levels in it");
177 "ReuseTpetraPreconditioner: Hierarchy has no fine level operator");
180 RCP<Operator> O0 = level0->Get<RCP<Operator> >(
"A");
181 RCP<Matrix> A0 = Teuchos::rcp_dynamic_cast<Matrix>(O0);
183 RCP<Matrix> A = EpetraCrs_To_XpetraMatrix<SC,LO,GO,NO>(inA);
188 A->SetFixedBlockSize(A0->GetFixedBlockSize());
195 #endif // HAVE_MUELU_SERIAL and HAVE_MUELU_EPETRA 197 #endif //ifndef MUELU_CREATE_EPETRA_PRECONDITIONER_HPP RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
void ReuseEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, MueLu::EpetraOperator &Op)
static void AddNonSerializableDataToHierarchy(HierarchyManager &HM, Hierarchy &H, const ParameterList &nonSerialList)
Namespace for MueLu classes and methods.
Teuchos::RCP< MueLu::EpetraOperator > CreateEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, Teuchos::ParameterList ¶mListIn, 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...
Class that accepts ML-style parameters and builds a MueLu preconditioner. This interpreter uses the s...
Exception throws to report errors in the internal logical of the program.
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
long ExtractNonSerializableData(const Teuchos::ParameterList &inList, Teuchos::ParameterList &serialList, Teuchos::ParameterList &nonSerialList)