53#ifndef MUELU_BLOCKEDDIRECTSOLVER_DEF_HPP_
54#define MUELU_BLOCKEDDIRECTSOLVER_DEF_HPP_
56#include "Teuchos_ArrayViewDecl.hpp"
57#include "Teuchos_ScalarTraits.hpp"
61#include <Xpetra_Matrix.hpp>
62#include <Xpetra_BlockedCrsMatrix.hpp>
63#include <Xpetra_MultiVectorFactory.hpp>
66#include "MueLu_MergedBlockedMatrixFactory.hpp"
69#include "MueLu_DirectSolver.hpp"
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 type_ =
"blocked direct solver (" + type +
")";
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
83 RCP<ParameterList> validParamList = rcp(
new ParameterList());
85 validParamList->set< RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A");
87 return validParamList;
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 s_->DeclareInput(currentLevel);
105 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
109 FactoryMonitor m(*
this,
"Setup BlockedDirectSolver", currentLevel);
111 this->
GetOStream(
Warnings0) <<
"MueLu::BlockedDirectSolver::Setup(): Setup() has already been called";
115 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
117 "MueLu::BlockedDirectSolver::Build: input matrix A is not of type BlockedCrsMatrix.");
119 s_->Setup(currentLevel);
124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
127 "MueLu::BlockedDirectSolver::Apply(): Setup() has not been called");
129 RCP<MultiVector> rcpX = Teuchos::rcpFromRef(X);
130 RCP<const MultiVector> rcpB = Teuchos::rcpFromRef(B);
131 RCP<BlockedMultiVector> bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
132 RCP<const BlockedMultiVector> bB = Teuchos::rcp_dynamic_cast<const BlockedMultiVector>(rcpB);
134#ifdef HAVE_MUELU_DEBUG
135 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
136 if(bB.is_null() ==
false) {
139 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.");
141 if(bX.is_null() ==
false) {
144 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.");
148 if (bB.is_null() ==
true && bX.is_null() ==
true) {
150 s_->Apply(X, B, InitialGuessIsZero);
151 }
else if(bB.is_null() ==
false && bX.is_null() ==
false) {
153 RCP<MultiVector> mergedX = bX->Merge();
154 RCP<const MultiVector> mergedB = bB->Merge();
155 s_->Apply(*mergedX, *mergedB, InitialGuessIsZero);
156 RCP<MultiVector> xx = Teuchos::rcp(
new BlockedMultiVector(bX->getBlockedMap(),mergedX));
157 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
158 X.update(one,*xx,zero);
159 }
else if (bB.is_null() ==
true && bX.is_null() ==
false) {
161 RCP<MultiVector> mergedX = bX->Merge();
162 s_->Apply(*mergedX, B, InitialGuessIsZero);
163 RCP<MultiVector> xx = Teuchos::rcp(
new BlockedMultiVector(bX->getBlockedMap(),mergedX));
164 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
165 X.update(one,*xx,zero);
166 }
else if (bB.is_null() ==
false && bX.is_null() ==
true) {
168 RCP<const MultiVector> mergedB = bB->Merge();
169 s_->Apply(X, *mergedB, InitialGuessIsZero);
173 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
174 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
179 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
181 std::ostringstream out;
183 out <<
"{type = " <<
type_ <<
"}";
187 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 out0 <<
"Prec. type: " <<
type_ << std::endl;
194 if (verbLevel &
Debug)
198 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
201 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
MueLu::MergedBlockedMatrixFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > MergedBlockedMatrixFactory
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.