45 #ifndef MUELU_MULTIPHYS_DEF_HPP
46 #define MUELU_MULTIPHYS_DEF_HPP
51 #include "Xpetra_Map.hpp"
56 #include "MueLu_SaPFactory.hpp"
57 #include "MueLu_AggregationExportFactory.hpp"
58 #include "MueLu_Utilities.hpp"
60 #include "MueLu_Hierarchy.hpp"
61 #include "MueLu_RAPFactory.hpp"
63 #include "MueLu_PerfUtils.hpp"
64 #include "MueLu_ParameterListInterpreter.hpp"
66 #include <MueLu_HierarchyUtils.hpp>
67 #if defined(HAVE_MUELU_KOKKOS_REFACTOR)
68 #include "MueLu_Utilities_kokkos.hpp"
74 #ifdef HAVE_MUELU_CUDA
75 #include "cuda_profiler_api.h"
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 return AmatMultiphysics_->getDomainMap();
85 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 return AmatMultiphysics_->getRangeMap();
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94 list.
set(
"multigrid algorithm",
"combine");
95 list.
set(
"combine: numBlks", nBlks_);
98 std::string verbosity = list.
get(
"verbosity",
"high");
101 arrayOfParamLists_.resize(nBlks_);
102 for (
int i = 0; i < nBlks_; i++) {
105 arrayOfParamLists_[i] = Teuchos::rcpFromRef(list.
sublist(listName));
109 arrayOfParamLists_[i]->set(
"verbosity", arrayOfParamLists_[i]->
get(
"verbosity", verbosity));
110 arrayOfParamLists_[i]->set(
"smoother: pre or post",
"none");
111 arrayOfParamLists_[i]->set(
"smoother: type",
"none");
115 useKokkos_ = !Node::is_serial;
116 useKokkos_ = list.
get(
"use kokkos refactor", useKokkos_);
118 paramListMultiphysics_ = Teuchos::rcpFromRef(list);
121 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 std::string timerLabel;
136 timerLabel =
"MueLu MultiPhys: compute (reuse)";
138 timerLabel =
"MueLu MultiPhys: compute";
144 for (
int iii = 0; iii < nBlks_; iii++) {
145 arrayOfParamLists_[iii]->sublist(
"user data").set(
"Coordinates", arrayOfCoords_[iii]);
147 bool wantToRepartition =
false;
148 if (paramListMultiphysics_->isParameter(
"repartition: enable"))
149 wantToRepartition = paramListMultiphysics_->get<
bool>(
"repartition: enable");
151 arrayOfParamLists_[iii]->set(
"repartition: enable", wantToRepartition);
152 arrayOfParamLists_[iii]->set(
"repartition: rebalance P and R",
true);
153 arrayOfParamLists_[iii]->set(
"repartition: explicit via new copy rebalance P and R",
true);
155 if (paramListMultiphysics_->isParameter(
"repartition: use subcommunicators"))
156 arrayOfParamLists_[iii]->set(
"repartition: use subcommunicators", paramListMultiphysics_->isParameter(
"repartition: use subcommunicators"));
158 arrayOfParamLists_[iii]->set(
"repartition: use subcommunicators",
true);
163 paramListMultiphysics_->set<
bool>(
"repartition: enable",
false);
166 for (
int i = 0; i < nBlks_; i++) {
168 arrayOfAuxMatrices_[i]->setObjectLabel(operatorLabel);
170 LO tempNlevels = arrayOfHierarchies_[i]->GetGlobalNumLevels();
171 if (tempNlevels < maxLevels) maxLevels = tempNlevels;
175 for (
LO i = 0; i < maxLevels; i++) {
176 hierarchyMultiphysics_->AddNewLevel();
178 for (
int i = 0; i < nBlks_; i++) {
182 paramListMultiphysics_->set(
"coarse: max size", 1);
183 paramListMultiphysics_->set(
"max levels", maxLevels);
195 const std::string& levelName = inListEntry->first;
196 if (levelName.find(
"subblockList") != 0) stripped.
setEntry(inListEntry->first, inListEntry->second);
200 hierarchyMultiphysics_->setlib(AmatMultiphysics_->getDomainMap()->lib());
201 hierarchyMultiphysics_->SetProcRankVerbose(AmatMultiphysics_->getDomainMap()->getComm()->getRank());
204 hierarchyMultiphysics_->GetLevel(0)->Set(
"A", AmatMultiphysics_);
209 mueLuFactory->SetupHierarchy(*hierarchyMultiphysics_);
214 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 return Teuchos::null;
229 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
231 bool reuse = !AmatMultiphysics_.is_null();
232 AmatMultiphysics_ = AmatMultiphysics_new;
233 if (ComputePrec) compute(reuse);
236 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
238 hierarchyMultiphysics_->Iterate(RHS, X, 1,
true);
241 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
247 hierarchyMultiphysics_->Iterate(RHS, X, 1,
true);
250 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
255 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
263 arrayOfHierarchies_.resize(nBlks_);
264 for (
int i = 0; i < nBlks_; i++) arrayOfHierarchies_[i] = Teuchos::null;
268 enable_reuse_ =
false;
276 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
279 std::ostringstream oss;
283 oss <<
"\n--------------------------------------------------------------------------------\n"
284 <<
"--- MultiPhysics Summary ---\n"
285 "--------------------------------------------------------------------------------"
292 AmatMultiphysics_->getRowMap()->getComm()->barrier();
294 for (
int i = 0; i < nBlks_; i++) {
295 numRows = arrayOfAuxMatrices_[i]->getGlobalNumRows();
296 nnz = arrayOfAuxMatrices_[i]->getGlobalNumEntries();
310 oss <<
"block " << std::setw(rowspacer) <<
" rows " << std::setw(nnzspacer) <<
" nnz " << std::setw(9) <<
" nnz/row" << std::endl;
311 oss <<
"(" <<
Teuchos::toString(i) <<
", " <<
Teuchos::toString(i) <<
")" << std::setw(rowspacer) << numRows << std::setw(nnzspacer) << nnz << std::setw(9) << as<double>(nnz) / numRows << std::endl;
315 for (
int i = 0; i < nBlks_; i++) {
316 arrayOfHierarchies_[i]->describe(out, GetVerbLevel());
323 #define MUELU_MULTIPHYS_SHORT
324 #endif // ifdef MUELU_MULTIPHYS_DEF_HPP
ParameterList & setEntry(const std::string &name, U &&entry)
Various adapters that will create a MueLu preconditioner that is an Xpetra::Matrix.
ConstIterator end() const
static void AddNonSerializableDataToHierarchy(HierarchyManager &HM, Hierarchy &H, const ParameterList &nonSerialList)
Add non-serializable data to Hierarchy.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
One-liner description of what is happening.
void setParameters(Teuchos::ParameterList &list)
Set parameters.
MsgType toVerbLevel(const std::string &verbLevelStr)
static RCP< Time > getNewTimer(const std::string &name)
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...
static void SetDefaultVerbLevel(const VerbLevel defaultVerbLevel)
Set the default (global) verbosity level.
void applyInverse(const MultiVector &RHS, MultiVector &X) const
apply standard MultiPhys cycle
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
const Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
bool isSublist(const std::string &name) const
params_t::ConstIterator ConstIterator
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
ConstIterator begin() const
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int >> comm=Teuchos::null) const
get a (synced) timer
Print all timing information.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void apply(const MultiVector &X, MultiVector &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Exception throws to report errors in the internal logical of the program.
void initialize(const Teuchos::RCP< Matrix > &AmatMultiPhysics, const Teuchos::ArrayRCP< RCP< Matrix >> arrayOfAuxMatrices, const Teuchos::ArrayRCP< Teuchos::RCP< MultiVector >> arrayOfNullspaces, const Teuchos::ArrayRCP< Teuchos::RCP< RealValuedMultiVector >> arrayOfCoords, const int nBlks, Teuchos::ParameterList &List)
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
void compute(bool reuse=false)
Setup the preconditioner.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
std::string toString(const T &t)
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...
static void CopyBetweenHierarchies(Hierarchy &fromHierarchy, Hierarchy &toHierarchy, const std::string fromLabel, const std::string toLabel, const std::string dataType)