45#ifndef MUELU_MULTIPHYS_DEF_HPP
46#define MUELU_MULTIPHYS_DEF_HPP
51#include "Xpetra_Map.hpp"
52#include "Xpetra_CrsMatrixUtils.hpp"
53#include "Xpetra_MatrixUtils.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"
75#include "cuda_profiler_api.h"
81 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 list.set(
"multigrid algorithm",
"combine");
99 list.set(
"combine: numBlks",
nBlks_);
102 std::string verbosity = list.get(
"verbosity",
"high");
106 for (
int i = 0 ; i <
nBlks_; i++) {
107 std::string listName =
"subblockList" + Teuchos::toString(i);
108 if(list.isSublist(listName)) {
120#if !defined(HAVE_MUELU_KOKKOS_REFACTOR)
123# ifdef HAVE_MUELU_SERIAL
124 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosSerialWrapperNode).name())
127# ifdef HAVE_MUELU_OPENMP
128 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosOpenMPWrapperNode).name())
131# ifdef HAVE_MUELU_CUDA
132 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosCudaWrapperNode).name())
142 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 std::string timerLabel;
157 timerLabel =
"MueLu MultiPhys: compute (reuse)";
159 timerLabel =
"MueLu MultiPhys: compute";
160 RCP<Teuchos::TimeMonitor> tmCompute =
getTimer(timerLabel);
165 for (
int iii = 0; iii <
nBlks_; iii++) {
168 bool wantToRepartition =
false;
174 arrayOfParamLists_[iii]->set(
"repartition: explicit via new copy rebalance P and R",
true);
188 for (
int i = 0; i <
nBlks_; i++) {
189 std::string operatorLabel =
"MultiPhys (" + Teuchos::toString(i) +
"," + Teuchos::toString(i) +
")";
arrayOfAuxMatrices_[i]->setObjectLabel(operatorLabel);
192 if (tempNlevels < maxLevels) maxLevels = tempNlevels;
196 for (LO i = 0; i < maxLevels; i++) {
199 for (
int i = 0; i <
nBlks_; i++) {
200 std::string subblkName =
"Psubblock" + Teuchos::toString(i);
210 Teuchos::ParameterList nonSerialListMultiphysics, processedListMultiphysics;
215 Teuchos::ParameterList stripped;
216 for (ParameterList::ConstIterator inListEntry = processedListMultiphysics.begin(); inListEntry != processedListMultiphysics.end(); inListEntry++) {
217 const std::string& levelName = inListEntry->first;
218 if (levelName.find(
"subblockList") != 0) stripped.setEntry(inListEntry->first, inListEntry->second);
237 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
241 return Teuchos::rcp(
new Teuchos::TimeMonitor(*Teuchos::TimeMonitor::getNewTimer(name)));
244 return Teuchos::rcp(
new Teuchos::SyncTimeMonitor(*Teuchos::TimeMonitor::getNewTimer(name),
AmatMultiphysics_->getRowMap()->getComm().ptr()));
246 return Teuchos::rcp(
new Teuchos::SyncTimeMonitor(*Teuchos::TimeMonitor::getNewTimer(name), comm.ptr()));
249 return Teuchos::null;
252 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
256 if (ComputePrec)
compute(reuse);
259 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
264 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
269 RCP<Teuchos::TimeMonitor> tm =
getTimer(
"MueLu MultiPhys: solve");
275 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
281 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
283 initialize(
const Teuchos::RCP<Matrix> & AmatMultiPhysics,
284 const Teuchos::ArrayRCP<RCP<Matrix>> arrayOfAuxMatrices,
285 const Teuchos::ArrayRCP<Teuchos::RCP<MultiVector>> arrayOfNullspaces,
286 const Teuchos::ArrayRCP<Teuchos::RCP<RealValuedMultiVector>> arrayOfCoords,
288 Teuchos::ParameterList& List)
307 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
309 describe(Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel )
const {
311 std::ostringstream oss;
313 RCP<const Teuchos::Comm<int> > comm =
AmatMultiphysics_->getDomainMap()->getComm();
316 oss <<
"\n--------------------------------------------------------------------------------\n" <<
317 "--- MultiPhysics Summary ---\n"
318 "--------------------------------------------------------------------------------" << std::endl;
326 for (
int i = 0; i <
nBlks_; i++) {
329 Xpetra::global_size_t tt = numRows;
330 int rowspacer = 3;
while (tt != 0) { tt /= 10; rowspacer++; }
332 int nnzspacer = 2;
while (tt != 0) { tt /= 10; nnzspacer++; }
334 oss <<
"block " << std::setw(rowspacer) <<
" rows " << std::setw(nnzspacer) <<
" nnz " << std::setw(9) <<
" nnz/row" << std::endl;
335 oss <<
"(" << Teuchos::toString(i) <<
", " << Teuchos::toString(i) <<
")" << std::setw(rowspacer) << numRows << std::setw(nnzspacer) << nnz << std::setw(9) << as<double>(nnz) / numRows << std::endl;
340 for (
int i = 0; i <
nBlks_; i++) {
352#define MUELU_MULTIPHYS_SHORT
Various adapters that will create a MueLu preconditioner that is an Xpetra::Matrix.
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.
static void CopyBetweenHierarchies(Hierarchy &fromHierarchy, Hierarchy &toHierarchy, const std::string fromLabel, const std::string toLabel, const std::string dataType)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Teuchos::RCP< Hierarchy > hierarchyMultiphysics_
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int > > comm=Teuchos::null) const
get a (synced) timer
Teuchos::ArrayRCP< Teuchos::RCP< Matrix > > arrayOfAuxMatrices_
void compute(bool reuse=false)
Setup the preconditioner.
void applyInverse(const MultiVector &RHS, MultiVector &X) const
apply standard MultiPhys cycle
Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
void setParameters(Teuchos::ParameterList &list)
Set parameters.
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
Teuchos::RCP< Matrix > AmatMultiphysics_
Hierarchies: used to define P for (0,0)-block, .... (nBlks_-1,nBlks_-1) block.
Teuchos::ArrayRCP< Teuchos::RCP< Hierarchy > > arrayOfHierarchies_
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Teuchos::RCP< Teuchos::ParameterList > paramListMultiphysics_
Teuchos::ArrayRCP< Teuchos::RCP< RealValuedMultiVector > > arrayOfCoords_
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
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 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
Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
Teuchos::ArrayRCP< Teuchos::RCP< Teuchos::ParameterList > > arrayOfParamLists_
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
VerbLevel GetVerbLevel() const
Get the verbosity level.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
static void SetDefaultVerbLevel(const VerbLevel defaultVerbLevel)
Set the default (global) verbosity level.
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.
@ Runtime0
One-liner description of what is happening.
@ Timings
Print all timing information.
MsgType toVerbLevel(const std::string &verbLevelStr)
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,...