8 #ifndef PACKAGES_MUELU_ADAPTERS_XPETRA_MUELU_CREATEXPETRAPRECONDITIONER_HPP_
9 #define PACKAGES_MUELU_ADAPTERS_XPETRA_MUELU_CREATEXPETRAPRECONDITIONER_HPP_
14 #include <Teuchos_XMLParameterListHelpers.hpp>
15 #include <Xpetra_CrsMatrix.hpp>
16 #include <Xpetra_MultiVector.hpp>
21 #include <MueLu_Hierarchy.hpp>
23 #include <MueLu_MLParameterListInterpreter.hpp>
24 #include <MueLu_ParameterListInterpreter.hpp>
25 #include <MueLu_Utilities.hpp>
26 #include <MueLu_HierarchyUtils.hpp>
40 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
41 Teuchos::RCP<MueLu::Hierarchy<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
43 const Teuchos::ParameterList& inParamList) {
55 bool hasParamList = inParamList.numParams();
57 RCP<HierarchyManager> mueLuFactory;
60 Teuchos::ParameterList nonSerialList,paramList;
64 if (hasParamList && paramList.isParameter(
"hierarchy label")) {
65 label = paramList.get<std::string>(
"hierarchy label");
66 paramList.remove(
"hierarchy label");
68 label = op->getObjectLabel();
70 std::string timerName;
72 timerName =
"MueLu setup time (" + label +
")";
74 timerName =
"MueLu setup time";
75 RCP<Teuchos::Time> tm = Teuchos::TimeMonitor::getNewTimer(timerName);
78 std::string syntaxStr =
"parameterlist: syntax";
79 if (hasParamList && paramList.isParameter(syntaxStr) && paramList.get<std::string>(syntaxStr) ==
"ml") {
80 paramList.remove(syntaxStr);
87 RCP<Hierarchy> H = mueLuFactory->CreateHierarchy(label);
88 H->setlib(op->getDomainMap()->lib());
94 H->GetLevel(0)->Set(
"A", op);
95 H->SetProcRankVerbose(op->getDomainMap()->getComm()->getRank());
97 mueLuFactory->SetupHierarchy(*H);
100 tm->incrementNumCalls();
103 const bool alwaysWriteLocal =
true;
104 const bool writeGlobalStats =
true;
105 const bool writeZeroTimers =
false;
106 const bool ignoreZeroTimers =
true;
107 const std::string filter = timerName;
108 Teuchos::TimeMonitor::summarize(op->getRowMap()->getComm().ptr(), std::cout, alwaysWriteLocal, writeGlobalStats,
109 writeZeroTimers, Teuchos::Union, filter, ignoreZeroTimers);
125 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 Teuchos::RCP<MueLu::Hierarchy<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
128 const std::string& xmlFileName) {
129 Teuchos::ParameterList paramList;
130 Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(¶mList), *op->getDomainMap()->getComm());
131 return CreateXpetraPreconditioner<Scalar, LocalOrdinal, GlobalOrdinal, Node>(op, paramList);
141 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
142 Teuchos::RCP<MueLu::Hierarchy<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
144 Teuchos::ParameterList paramList;
145 return CreateXpetraPreconditioner<Scalar, LocalOrdinal, GlobalOrdinal, Node>(op, paramList);
155 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 std::string label = H->GetLevel(0)->getObjectLabel();
160 std::string timerName;
162 timerName =
"MueLu setup time (" + label +
")";
164 timerName =
"MueLu setup time";
165 RCP<Teuchos::Time> tm = Teuchos::TimeMonitor::getNewTimer(timerName);
173 typedef Xpetra::Matrix<SC,LO,GO,NO> Matrix;
174 typedef Xpetra::Operator<SC,LO,GO,NO> Operator;
177 "MueLu::ReuseXpetraPreconditioner: Hierarchy has no levels in it");
179 "MueLu::ReuseXpetraPreconditioner: Hierarchy has no fine level operator");
180 RCP<Level> level0 = H->GetLevel(0);
182 RCP<Operator> O0 = level0->Get<RCP<Operator> >(
"A");
183 RCP<Matrix> A0 = Teuchos::rcp_dynamic_cast<Matrix>(O0);
189 A->SetFixedBlockSize(A0->GetFixedBlockSize());
196 tm->incrementNumCalls();
199 const bool alwaysWriteLocal =
true;
200 const bool writeGlobalStats =
true;
201 const bool writeZeroTimers =
false;
202 const bool ignoreZeroTimers =
true;
203 const std::string filter = timerName;
204 Teuchos::TimeMonitor::summarize(A->getRowMap()->getComm().ptr(), std::cout, alwaysWriteLocal, writeGlobalStats,
205 writeZeroTimers, Teuchos::Union, filter, ignoreZeroTimers);
212 #ifdef HAVE_MUELU_DEPRECATED_CODE
224 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 Teuchos::RCP<MueLu::Hierarchy<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
228 const Teuchos::ParameterList& inParamList,
230 Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > nullspace) {
232 Teuchos::ParameterList userParamList = inParamList.sublist(
"user data");
233 if (Teuchos::nonnull(coords)) {
234 userParamList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::coordinateType,
LocalOrdinal,
GlobalOrdinal,
Node> > >(
"Coordinates", coords);
236 if(Teuchos::nonnull(nullspace)) {
237 userParamList.set<RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > >(
"Nullspace", nullspace);
253 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
255 Teuchos::RCP<MueLu::Hierarchy<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
257 const Teuchos::ParameterList& inParamList,
260 Teuchos::ParameterList mueluParams = inParamList;
261 Teuchos::ParameterList& userParamList = mueluParams.sublist(
"user data");
262 if (Teuchos::nonnull(coords)) {
263 userParamList.set<RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::coordinateType,
LocalOrdinal,
GlobalOrdinal,
Node> > >(
"Coordinates", coords);
272 #define XPETRA_CREATEXPETRAPRECONDITIONER_SHORT
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Exception throws to report errors in the internal logical of the program.
static void AddNonSerializableDataToHierarchy(HierarchyManager &HM, Hierarchy &H, const ParameterList &nonSerialList)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Class that accepts ML-style parameters and builds a MueLu preconditioner. This interpreter uses the s...
Namespace for MueLu classes and methods.
long ExtractNonSerializableData(const Teuchos::ParameterList &inList, Teuchos::ParameterList &serialList, Teuchos::ParameterList &nonSerialList)
@ Statistics0
Print statistics that do not involve significant additional computation.
void ReuseXpetraPreconditioner(const Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &A, Teuchos::RCP< MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &H)
Helper function to reuse an existing MueLu preconditioner.
Teuchos::RCP< MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node > > CreateXpetraPreconditioner(Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > op, const Teuchos::ParameterList &inParamList)
Helper function to create a MueLu preconditioner that can be used by Xpetra.Given an Xpetra::Matrix,...