53 #ifndef MUELU_INDEFBLOCKEDDIAGONALSMOOTHER_DEF_HPP_
54 #define MUELU_INDEFBLOCKEDDIAGONALSMOOTHER_DEF_HPP_
56 #include "Teuchos_ArrayViewDecl.hpp"
61 #include <Xpetra_Matrix.hpp>
62 #include <Xpetra_CrsMatrixWrap.hpp>
63 #include <Xpetra_BlockedCrsMatrix.hpp>
64 #include <Xpetra_MultiVectorFactory.hpp>
65 #include <Xpetra_VectorFactory.hpp>
66 #include <Xpetra_ReorderedBlockedCrsMatrix.hpp>
70 #include "MueLu_Utilities.hpp"
72 #include "MueLu_HierarchyUtils.hpp"
74 #include "MueLu_SubBlockAFactory.hpp"
77 #include "MueLu_SchurComplementFactory.hpp"
78 #include "MueLu_DirectSolver.hpp"
79 #include "MueLu_SmootherFactory.hpp"
80 #include "MueLu_FactoryManager.hpp"
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 : type_(
"IndefiniteBlockDiagonalSmoother"), A_(Teuchos::null)
90 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 validParamList->
set<
RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A (must be a 2x2 block matrix)");
98 validParamList->
set<
Scalar > (
"Damping factor", 1.0,
"Damping/Scaling factor");
99 validParamList->
set<
LocalOrdinal > (
"Sweeps", 1,
"Number of SIMPLE sweeps (default = 1)");
102 return validParamList;
106 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
110 size_t myPos = Teuchos::as<size_t>(pos);
112 if (myPos < FactManager_.size()) {
114 FactManager_.at(myPos) = FactManager;
115 }
else if( myPos == FactManager_.size()) {
117 FactManager_.push_back(FactManager);
120 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
123 FactManager_.push_back(FactManager);
127 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
129 currentLevel.
DeclareInput(
"A",this->GetFactory(
"A").
get());
131 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\"!");
134 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
135 for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
139 currentLevel.
DeclareInput(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
144 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 FactoryMonitor m(*
this,
"Setup for indefinite blocked diagonal smoother", currentLevel);
149 this->GetOStream(
Warnings0) <<
"MueLu::IndefBlockedDiagonalSmoother::Setup(): Setup() has already been called";
152 A_ = Factory::Get<RCP<Matrix> > (currentLevel,
"A");
158 rangeMapExtractor_ = bA->getRangeMapExtractor();
159 domainMapExtractor_ = bA->getDomainMapExtractor();
211 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
225 bool bRangeThyraMode = rangeMapExtractor_->getThyraMode();
226 bool bDomainThyraMode = domainMapExtractor_->getThyraMode();
233 bool bCopyResultX =
false;
239 if(bX.is_null() ==
true) {
245 if(bB.is_null() ==
true) {
251 bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
252 bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
256 if(rbA.is_null() ==
false) {
261 if(bX->getBlockedMap()->getNumMaps() != bA->getDomainMapExtractor()->NumMaps()) {
264 buildReorderedBlockedMultiVector(brm, bX);
267 if(bB->getBlockedMap()->getNumMaps() != bA->getRangeMapExtractor()->NumMaps()) {
270 buildReorderedBlockedMultiVector(brm, bB);
279 RCP<MultiVector> residual = MultiVectorFactory::Build(rcpB->getMap(), rcpB->getNumVectors());
285 RCP<MultiVector> xtilde = MultiVectorFactory::Build(rcpX->getMap(), rcpX->getNumVectors());
293 residual->update(one,*rcpB,zero);
304 bxtilde->putScalar(zero);
305 velPredictSmoo_->Apply(*xtilde1,*r1);
309 schurCompSmoo_->Apply(*xtilde2,*r2);
312 rcpX->update(omega,*bxtilde,one);
319 x1->update(omega,*xtilde1,one);
320 x2->update(omega,*xtilde2,one);
323 domainMapExtractor_->InsertVector(x1, 0, rcpX, bDomainThyraMode);
324 domainMapExtractor_->InsertVector(x2, 1, rcpX, bDomainThyraMode);
328 if (bCopyResultX ==
true) {
330 X.update(one, *Xmerged, zero);
334 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
340 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
342 std::ostringstream out;
344 out <<
"{type = " << type_ <<
"}";
348 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
353 out0 <<
"Prec. type: " << type_ << std::endl;
356 if (verbLevel &
Debug) {
360 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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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.
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()'.
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)