10#ifndef PACKAGES_MUELU_ADAPTERS_XPETRA_MUELU_CREATEXPETRAPRECONDITIONER_HPP_
11#define PACKAGES_MUELU_ADAPTERS_XPETRA_MUELU_CREATEXPETRAPRECONDITIONER_HPP_
16#include <Teuchos_XMLParameterListHelpers.hpp>
17#include <Xpetra_CrsMatrix.hpp>
18#include <Xpetra_MultiVector.hpp>
23#include <MueLu_Hierarchy.hpp>
25#include <MueLu_ParameterListInterpreter.hpp>
26#include <MueLu_Utilities.hpp>
27#include <MueLu_HierarchyUtils.hpp>
43template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
44Teuchos::RCP<MueLu::Hierarchy<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
46 const Teuchos::ParameterList& inParamList) {
57 bool hasParamList = inParamList.numParams();
59 RCP<HierarchyManager> mueLuFactory;
62 Teuchos::ParameterList nonSerialList, paramList;
66 if (hasParamList && paramList.isParameter(
"hierarchy label")) {
67 label = paramList.get<std::string>(
"hierarchy label");
69 label = op->getObjectLabel();
71 RCP<Teuchos::Time> tm;
72 std::string timerName;
75 if (paramList.isSublist(
"kokkos tuning: muelu parameter mapping") &&
76 paramList.sublist(
"kokkos tuning: muelu parameter mapping").isParameter(
"kokkos context id")) {
79 timerName =
"MueLu tuning time (" + label +
")";
81 timerName =
"MueLu tuning time";
82 tm = Teuchos::TimeMonitor::getNewTimer(timerName);
89 tm->incrementNumCalls();
95 timerName =
"MueLu setup time (" + label +
")";
97 timerName =
"MueLu setup time";
99 tm = Teuchos::TimeMonitor::getNewTimer(timerName);
102 std::string syntaxStr =
"parameterlist: syntax";
103 if (hasParamList && paramList.isParameter(syntaxStr) && paramList.get<std::string>(syntaxStr) ==
"ml") {
104 paramList.remove(syntaxStr);
106 paramList = *Teuchos::getParametersFromXmlString(paramXML);
111 RCP<Hierarchy> H = mueLuFactory->CreateHierarchy(label);
112 H->setlib(op->getDomainMap()->lib());
115 H->GetLevel(0)->Set(
"A", op);
116 H->SetProcRankVerbose(op->getDomainMap()->getComm()->getRank());
121 mueLuFactory->SetupHierarchy(*H);
124 tm->incrementNumCalls();
127 const bool alwaysWriteLocal =
true;
128 const bool writeGlobalStats =
true;
129 const bool writeZeroTimers =
false;
130 const bool ignoreZeroTimers =
true;
131 const std::string filter = timerName;
132 Teuchos::TimeMonitor::summarize(op->getRowMap()->getComm().ptr(), H->GetOStream(
Statistics0), alwaysWriteLocal, writeGlobalStats,
133 writeZeroTimers, Teuchos::Union, filter, ignoreZeroTimers);
149template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
150Teuchos::RCP<MueLu::Hierarchy<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
152 const std::string& xmlFileName) {
153 Teuchos::ParameterList paramList;
154 Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(¶mList), *op->getDomainMap()->getComm());
155 return CreateXpetraPreconditioner<Scalar, LocalOrdinal, GlobalOrdinal, Node>(op, paramList);
165template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
166Teuchos::RCP<MueLu::Hierarchy<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
168 Teuchos::ParameterList paramList;
169 return CreateXpetraPreconditioner<Scalar, LocalOrdinal, GlobalOrdinal, Node>(op, paramList);
179template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
182 std::string label = H->GetLevel(0)->getObjectLabel();
184 std::string timerName;
186 timerName =
"MueLu setup time (" + label +
")";
188 timerName =
"MueLu setup time";
189 RCP<Teuchos::Time> tm = Teuchos::TimeMonitor::getNewTimer(timerName);
197 typedef Xpetra::Matrix<SC, LO, GO, NO> Matrix;
198 typedef Xpetra::Operator<SC, LO, GO, NO> Operator;
201 "MueLu::ReuseXpetraPreconditioner: Hierarchy has no levels in it");
203 "MueLu::ReuseXpetraPreconditioner: Hierarchy has no fine level operator");
204 RCP<Level> level0 = H->GetLevel(0);
206 RCP<Operator> O0 = level0->Get<RCP<Operator>>(
"A");
207 RCP<Matrix> A0 = Teuchos::rcp_dynamic_cast<Matrix>(O0);
213 A->SetFixedBlockSize(A0->GetFixedBlockSize());
220 tm->incrementNumCalls();
223 const bool alwaysWriteLocal =
true;
224 const bool writeGlobalStats =
true;
225 const bool writeZeroTimers =
false;
226 const bool ignoreZeroTimers =
true;
227 const std::string filter = timerName;
228 Teuchos::TimeMonitor::summarize(A->getRowMap()->getComm().ptr(), H->GetOStream(
Statistics0), alwaysWriteLocal, writeGlobalStats,
229 writeZeroTimers, Teuchos::Union, filter, ignoreZeroTimers);
237#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)
Add non-serializable data to Hierarchy.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
void SetParameterList(Teuchos::ParameterList &inParams)
void SetMueLuParameters(size_t kokkos_context_id, Teuchos::ParameterList &mueluParams, bool overwrite=true) const
static std::string translate(Teuchos::ParameterList ¶mList, const std::string &defaultVals="")
: Translate ML parameters to MueLu parameter XML string
Namespace for MueLu classes and methods.
long ExtractNonSerializableData(const Teuchos::ParameterList &inList, Teuchos::ParameterList &serialList, Teuchos::ParameterList &nonSerialList)
Extract non-serializable data from level-specific sublists and move it to a separate parameter list.
@ 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,...