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"
37template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
41 type_ =
"blocked direct solver (" + type +
")";
44template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
46 RCP<ParameterList> validParamList = rcp(
new ParameterList());
48 validParamList->set<RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A");
50 return validParamList;
53template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 s_->DeclareInput(currentLevel);
68template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
72 FactoryMonitor m(*
this,
"Setup BlockedDirectSolver", currentLevel);
74 this->
GetOStream(
Warnings0) <<
"MueLu::BlockedDirectSolver::Setup(): Setup() has already been called";
78 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
80 "MueLu::BlockedDirectSolver::Build: input matrix A is not of type BlockedCrsMatrix.");
82 s_->Setup(currentLevel);
87template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 "MueLu::BlockedDirectSolver::Apply(): Setup() has not been called");
92 RCP<MultiVector> rcpX = Teuchos::rcpFromRef(X);
93 RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
94 RCP<BlockedMultiVector> bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
95 RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(rcpB);
97#ifdef HAVE_MUELU_DEBUG
98 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
99 if (bB.is_null() ==
false) {
102 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.");
104 if (bX.is_null() ==
false) {
107 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.");
111 if (bB.is_null() ==
true && bX.is_null() ==
true) {
113 s_->Apply(X, B, InitialGuessIsZero);
114 }
else if (bB.is_null() ==
false && bX.is_null() ==
false) {
116 RCP<MultiVector> mergedX = bX->Merge();
117 RCP<const MultiVector> mergedB = bB->Merge();
118 s_->Apply(*mergedX, *mergedB, InitialGuessIsZero);
119 RCP<MultiVector> xx = Teuchos::rcp(
new BlockedMultiVector(bX->getBlockedMap(), mergedX));
120 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
121 X.update(one, *xx, zero);
122 }
else if (bB.is_null() ==
true && bX.is_null() ==
false) {
124 RCP<MultiVector> mergedX = bX->Merge();
125 s_->Apply(*mergedX, B, InitialGuessIsZero);
126 RCP<MultiVector> xx = Teuchos::rcp(
new BlockedMultiVector(bX->getBlockedMap(), mergedX));
127 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
128 X.update(one, *xx, zero);
129 }
else if (bB.is_null() ==
false && bX.is_null() ==
true) {
131 RCP<const MultiVector> mergedB = bB->Merge();
132 s_->Apply(X, *mergedB, InitialGuessIsZero);
136template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
142template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
144 std::ostringstream out;
146 out <<
"{type = " <<
type_ <<
"}";
150template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 out0 <<
"Prec. type: " <<
type_ << std::endl;
157 if (verbLevel &
Debug)
161template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 return Teuchos::OrdinalTraits<size_t>::invalid();
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
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.
Timer to be used in factories. Similar to Monitor but with additional timers.
T Get(Level &level, const std::string &varName) const
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory().
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.