17#ifndef MUELU_BLOCKEDDIRECTSOLVER_DEF_HPP_
18#define MUELU_BLOCKEDDIRECTSOLVER_DEF_HPP_
20#include "Teuchos_ArrayViewDecl.hpp"
21#include "Teuchos_ScalarTraits.hpp"
25#include <Xpetra_Matrix.hpp>
26#include <Xpetra_BlockedCrsMatrix.hpp>
27#include <Xpetra_MultiVectorFactory.hpp>
30#include "MueLu_MergedBlockedMatrixFactory.hpp"
33#include "MueLu_DirectSolver.hpp"
38template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
42 type_ =
"blocked direct solver (" + type +
")";
45template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
47 RCP<ParameterList> validParamList = rcp(
new ParameterList());
49 validParamList->set<RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A");
51 return validParamList;
54template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 s_->DeclareInput(currentLevel);
69template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
73 FactoryMonitor m(*
this,
"Setup BlockedDirectSolver", currentLevel);
75 this->
GetOStream(
Warnings0) <<
"MueLu::BlockedDirectSolver::Setup(): Setup() has already been called";
79 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
81 "MueLu::BlockedDirectSolver::Build: input matrix A is not of type BlockedCrsMatrix.");
83 s_->Setup(currentLevel);
88template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
91 "MueLu::BlockedDirectSolver::Apply(): Setup() has not been called");
93 RCP<MultiVector> rcpX = Teuchos::rcpFromRef(X);
94 RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
95 RCP<BlockedMultiVector> bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
96 RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(rcpB);
99 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
100 if (bB.is_null() ==
false) {
103 TEUCHOS_TEST_FOR_EXCEPTION(bA->getFullRangeMap()->isSameAs(*(B.getMap())) ==
false,
Exceptions::RuntimeError,
"MueLu::BlockedDirectSolver::Apply(): The map of RHS vector B is not the same as range map of the blocked operator A. Please check the map of B and A.");
105 if (bX.is_null() ==
false) {
108 TEUCHOS_TEST_FOR_EXCEPTION(bA->getFullDomainMap()->isSameAs(*(X.getMap())) ==
false,
Exceptions::RuntimeError,
"MueLu::BlockedDirectSolver::Apply(): The map of the solution vector X is not the same as domain map of the blocked operator A. Please check the map of X and A.");
112 if (bB.is_null() ==
true && bX.is_null() ==
true) {
114 s_->Apply(X, B, InitialGuessIsZero);
115 }
else if (bB.is_null() ==
false && bX.is_null() ==
false) {
117 RCP<MultiVector> mergedX = bX->Merge();
118 RCP<const MultiVector> mergedB = bB->Merge();
119 s_->Apply(*mergedX, *mergedB, InitialGuessIsZero);
120 RCP<MultiVector> xx = Teuchos::rcp(
new BlockedMultiVector(bX->getBlockedMap(), mergedX));
121 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
122 X.update(one, *xx, zero);
123 }
else if (bB.is_null() ==
true && bX.is_null() ==
false) {
125 RCP<MultiVector> mergedX = bX->Merge();
126 s_->Apply(*mergedX, B, InitialGuessIsZero);
127 RCP<MultiVector> xx = Teuchos::rcp(
new BlockedMultiVector(bX->getBlockedMap(), mergedX));
128 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
129 X.update(one, *xx, zero);
130 }
else if (bB.is_null() ==
false && bX.is_null() ==
true) {
132 RCP<const MultiVector> mergedB = bB->Merge();
133 s_->Apply(X, *mergedB, InitialGuessIsZero);
137template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
143template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
145 std::ostringstream out;
147 out <<
"{type = " <<
type_ <<
"}";
151template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
156 out0 <<
"Prec. type: " <<
type_ << std::endl;
158 if (verbLevel &
Debug)
162template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
165 return Teuchos::OrdinalTraits<size_t>::invalid();
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
static bool debug()
Whether MueLu is in debug mode.
void Setup(Level ¤tLevel)
Setup routine Call the underlaying Setup routine of the nested direct solver once the input block mat...
BlockedDirectSolver(const std::string &type="", const Teuchos::ParameterList ¶mList=Teuchos::ParameterList())
Constructor.
RCP< const ParameterList > GetValidParameterList() const
Input.
void DeclareInput(Level ¤tLevel) const
Input.
RCP< Matrix > A_
block operator
std::string type_
smoother type
RCP< DirectSolver > s_
Direct solver.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the direct solver. Solves the linear system AX=B using the constructed solver.
std::string description() const
Return a simple one-line description of this object.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
RCP< MergedBlockedMatrixFactory > MergedAFact_
Factory to generate merged block matrix.
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
RCP< SmootherPrototype > Copy() const
virtual std::string description() const
Return a simple one-line description of this object.
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
T Get(Level &level, const std::string &varName) const
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory().
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput().
bool IsSetup() const
Get the state of a smoother prototype.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line).
@ Debug
Print additional debugging information.
@ Parameters0
Print class parameters.