10 #ifndef MUELU_BLOCKEDJACOBISMOOTHER_DEF_HPP_
11 #define MUELU_BLOCKEDJACOBISMOOTHER_DEF_HPP_
13 #include "Teuchos_ArrayViewDecl.hpp"
23 #include <Xpetra_MultiVectorFactory.hpp>
28 #include "MueLu_HierarchyUtils.hpp"
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
35 : type_(
"blocked Jacobi")
40 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
43 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
48 validParamList->
set<
Scalar>(
"Damping factor", 1.0,
"Damping/Scaling factor in Jacobi");
49 validParamList->
set<
LocalOrdinal>(
"Sweeps", 1,
"Number of sweeps (default = 1)");
51 return validParamList;
54 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
58 size_t myPos = Teuchos::as<size_t>(pos);
60 if (myPos < FactManager_.size()) {
62 FactManager_.at(myPos) = FactManager;
63 }
else if (myPos == FactManager_.size()) {
65 FactManager_.push_back(FactManager);
68 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
71 FactManager_.push_back(FactManager);
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 currentLevel.
DeclareInput(
"A", this->GetFactory(
"A").
get());
82 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
83 for (it = FactManager_.begin(); it != FactManager_.end(); ++it) {
87 currentLevel.
DeclareInput(
"PreSmoother", (*it)->GetFactory(
"Smoother").get());
90 currentLevel.
DeclareInput(
"A", (*it)->GetFactory(
"A").get());
94 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 FactoryMonitor m(*
this,
"Setup blocked Jacobi Smoother", currentLevel);
102 A_ = Factory::Get<RCP<Matrix> >(currentLevel,
"A");
107 TEUCHOS_TEST_FOR_EXCEPTION(bA->Rows() != FactManager_.size(),
Exceptions::RuntimeError,
"MueLu::BlockedJacobiSmoother::Setup: number of block rows of A is " << bA->Rows() <<
" and does not match number of SubFactoryManagers " << FactManager_.size() <<
". error.");
108 TEUCHOS_TEST_FOR_EXCEPTION(bA->Cols() != FactManager_.size(),
Exceptions::RuntimeError,
"MueLu::BlockedJacobiSmoother::Setup: number of block cols of A is " << bA->Cols() <<
" and does not match number of SubFactoryManagers " << FactManager_.size() <<
". error.");
111 rangeMapExtractor_ = bA->getRangeMapExtractor();
112 domainMapExtractor_ = bA->getDomainMapExtractor();
115 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
116 for (it = FactManager_.begin(); it != FactManager_.end(); ++it) {
121 Inverse_.push_back(Smoo);
125 bIsBlockedOperator_.push_back(Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(Aii) != Teuchos::null);
131 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
135 #if 0 // def HAVE_MUELU_DEBUG
142 if(rcpBDebugB.is_null() ==
false) {
149 if(rcpBDebugX.
is_null() ==
false) {
165 bool bCopyResultX =
false;
166 bool bReorderX =
false;
167 bool bReorderB =
false;
177 if (rbA.is_null() ==
false) {
182 if (bX.is_null() ==
true) {
184 rcpX.
swap(vectorWithBlockedMap);
190 if (bB.is_null() ==
true) {
192 rcpB.
swap(vectorWithBlockedMap);
197 if (bX.is_null() ==
true) {
199 rcpX.
swap(vectorWithBlockedMap);
203 if (bB.is_null() ==
true) {
205 rcpB.
swap(vectorWithBlockedMap);
210 bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
211 bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
214 if (rbA.is_null() ==
false) {
218 if (bX->getBlockedMap()->getNumMaps() != bA->getDomainMapExtractor()->NumMaps() || bReorderX) {
221 rcpX.
swap(reorderedBlockedVector);
224 if (bB->getBlockedMap()->getNumMaps() != bA->getRangeMapExtractor()->NumMaps() || bReorderB) {
227 rcpB.
swap(reorderedBlockedVector);
234 RCP<MultiVector> tempres = MultiVectorFactory::Build(rcpB->getMap(), rcpB->getNumVectors());
243 residual->update(1.0, *rcpB, 0.0);
244 if (InitialGuessIsZero ==
false || run > 0) {
248 for (
size_t i = 0; i < Inverse_.size(); i++) {
250 bool bRangeThyraMode = rangeMapExtractor_->getThyraMode();
251 bool bDomainThyraMode = domainMapExtractor_->getThyraMode();
257 Inverse_.at(i)->Apply(*tXi, *ri,
false);
260 if (InitialGuessIsZero && run == 0) {
261 Xi->update(omega, *tXi, 0.0);
263 Xi->update(omega, *tXi, 1.0);
268 if (bCopyResultX ==
true) {
270 X.update(one, *Xmerged, zero);
274 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
279 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
281 std::ostringstream out;
283 out <<
"{type = " << type_ <<
"}";
287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
297 out0 <<
"Prec. type: " << type_ <<
" Sweeps: " << nSweeps <<
" damping: " << omega << std::endl;
300 if (verbLevel &
Debug) {
305 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.
MueLu::DefaultLocalOrdinal LocalOrdinal
RCP< const ParameterList > GetValidParameterList() const
Input.
T & get(const std::string &name, T def_value)
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::string description() const
Return a simple one-line description of this object.
void swap(RCP< T > &r_ptr)
Print additional debugging information.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void Setup(Level ¤tLevel)
Setup routine In the Setup method the Inverse_ vector is filled with the corresponding SmootherBase o...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Class that holds all level-specific information.
void DeclareInput(Level ¤tLevel) const
Input.
bool IsSetup() const
Get the state of a smoother prototype.
std::vector< Teuchos::RCP< const FactoryManagerBase > > FactManager_
vector of factory managers
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
block Jacobi method for blocked matrices
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the direct solver.
BlockedJacobiSmoother()
Constructor.
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)
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
virtual ~BlockedJacobiSmoother()
Destructor.
RCP< SmootherPrototype > Copy() const
virtual std::string description() const
Return a simple one-line description of this object.
void AddFactoryManager(RCP< const FactoryManagerBase > FactManager, int pos)
Add a factory manager.
std::string toString(const T &t)