17 #ifndef MUELU_INDEFBLOCKEDDIAGONALSMOOTHER_DEF_HPP_
18 #define MUELU_INDEFBLOCKEDDIAGONALSMOOTHER_DEF_HPP_
20 #include "Teuchos_ArrayViewDecl.hpp"
26 #include <Xpetra_CrsMatrixWrap.hpp>
28 #include <Xpetra_MultiVectorFactory.hpp>
35 #include "MueLu_HierarchyUtils.hpp"
39 #include "MueLu_SchurComplementFactory.hpp"
40 #include "MueLu_FactoryManager.hpp"
44 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
46 : type_(
"IndefiniteBlockDiagonalSmoother")
50 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
53 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
57 validParamList->
set<
RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A (must be a 2x2 block matrix)");
58 validParamList->
set<
Scalar>(
"Damping factor", 1.0,
"Damping/Scaling factor");
59 validParamList->
set<
LocalOrdinal>(
"Sweeps", 1,
"Number of SIMPLE sweeps (default = 1)");
62 return validParamList;
66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 size_t myPos = Teuchos::as<size_t>(pos);
72 if (myPos < FactManager_.size()) {
74 FactManager_.at(myPos) = FactManager;
75 }
else if (myPos == FactManager_.size()) {
77 FactManager_.push_back(FactManager);
80 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
83 FactManager_.push_back(FactManager);
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 currentLevel.
DeclareInput(
"A", this->GetFactory(
"A").
get());
91 TEUCHOS_TEST_FOR_EXCEPTION(FactManager_.size() != 2,
Exceptions::RuntimeError,
"MueLu::IndefBlockedDiagonalSmoother::DeclareInput: You have to declare two FactoryManagers with a \"Smoother\" object: One for predicting the primary variable and one for the SchurComplement system. The smoother for the SchurComplement system needs a SchurComplementFactory as input for variable \"A\"!");
94 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
95 for (it = FactManager_.begin(); it != FactManager_.end(); ++it) {
99 currentLevel.
DeclareInput(
"PreSmoother", (*it)->GetFactory(
"Smoother").get());
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
105 FactoryMonitor m(*
this,
"Setup for indefinite blocked diagonal smoother", currentLevel);
108 this->GetOStream(
Warnings0) <<
"MueLu::IndefBlockedDiagonalSmoother::Setup(): Setup() has already been called";
111 A_ = Factory::Get<RCP<Matrix> >(currentLevel,
"A");
117 rangeMapExtractor_ = bA->getRangeMapExtractor();
118 domainMapExtractor_ = bA->getDomainMapExtractor();
170 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
183 bool bRangeThyraMode = rangeMapExtractor_->getThyraMode();
184 bool bDomainThyraMode = domainMapExtractor_->getThyraMode();
191 bool bCopyResultX =
false;
192 bool bReorderX =
false;
193 bool bReorderB =
false;
203 if (rbA.is_null() ==
false) {
208 if (bX.is_null() ==
true) {
210 rcpX.
swap(vectorWithBlockedMap);
216 if (bB.is_null() ==
true) {
218 rcpB.
swap(vectorWithBlockedMap);
223 if (bX.is_null() ==
true) {
225 rcpX.
swap(vectorWithBlockedMap);
229 if (bB.is_null() ==
true) {
231 rcpB.
swap(vectorWithBlockedMap);
236 bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
237 bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
240 if (rbA.is_null() ==
false) {
244 if (bX->getBlockedMap()->getNumMaps() != bA->getDomainMapExtractor()->NumMaps() || bReorderX) {
247 rcpX.
swap(reorderedBlockedVector);
250 if (bB->getBlockedMap()->getNumMaps() != bA->getRangeMapExtractor()->NumMaps() || bReorderB) {
253 rcpB.
swap(reorderedBlockedVector);
267 RCP<MultiVector> xtilde = MultiVectorFactory::Build(rcpX->getMap(), rcpX->getNumVectors());
275 residual->update(one, *rcpB, zero);
286 bxtilde->putScalar(zero);
287 velPredictSmoo_->Apply(*xtilde1, *r1);
291 schurCompSmoo_->Apply(*xtilde2, *r2);
294 rcpX->update(omega, *bxtilde, one);
301 x1->update(omega, *xtilde1, one);
302 x2->update(omega, *xtilde2, one);
305 domainMapExtractor_->InsertVector(x1, 0, rcpX, bDomainThyraMode);
306 domainMapExtractor_->InsertVector(x2, 1, rcpX, bDomainThyraMode);
310 if (bCopyResultX ==
true) {
312 X.update(one, *Xmerged, zero);
316 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
322 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
324 std::ostringstream out;
326 out <<
"{type = " << type_ <<
"}";
330 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
335 out0 <<
"Prec. type: " << type_ << std::endl;
338 if (verbLevel &
Debug) {
342 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
Important warning messages (one line)
virtual const Teuchos::ParameterList & GetParameterList() const
Exception indicating invalid cast attempted.
std::string description() const
Return a simple one-line description of this object.
MueLu::DefaultLocalOrdinal LocalOrdinal
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the Braess Sarazin smoother.
IndefBlockedDiagonalSmoother()
Constructor.
T & get(const std::string &name, T def_value)
void Setup(Level ¤tLevel)
Setup routine.
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void swap(RCP< T > &r_ptr)
Print additional debugging information.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void DeclareInput(Level ¤tLevel) const
Input.
virtual const RCP< const FactoryBase > GetFactory(const std::string &varName) const =0
Get.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Class that holds all level-specific information.
Cheap Blocked diagonal smoother for indefinite 2x2 block matrices.
RCP< const ParameterList > GetValidParameterList() const
Input.
bool IsSetup() const
Get the state of a smoother prototype.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
void AddFactoryManager(RCP< const FactoryManagerBase > FactManager, int pos=0)
Add a factory manager for BraessSarazin internal SchurComplement handling.
void residual(const Operator< SC, LO, GO, NO > &Aop, const MultiVector< SC, LO, GO, NO > &X_in, const MultiVector< SC, LO, GO, NO > &B_in, MultiVector< SC, LO, GO, NO > &R_in)
Exception throws to report errors in the internal logical of the program.
#define MUELU_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
An exception safe way to call the method 'Level::SetFactoryManager()'.
Teuchos::RCP< const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > buildReorderedBlockedMultiVector(Teuchos::RCP< const Xpetra::BlockReorderManager > brm, Teuchos::RCP< const Xpetra::BlockedMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > bvec)
virtual ~IndefBlockedDiagonalSmoother()
Destructor.
RCP< SmootherPrototype > Copy() const
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
virtual std::string description() const
Return a simple one-line description of this object.
std::string toString(const T &t)