47 #ifndef MUELU_BLOCKEDJACOBISMOOTHER_DEF_HPP_
48 #define MUELU_BLOCKEDJACOBISMOOTHER_DEF_HPP_
50 #include "Teuchos_ArrayViewDecl.hpp"
55 #include <Xpetra_BlockReorderManager.hpp>
56 #include <Xpetra_Matrix.hpp>
57 #include <Xpetra_BlockedCrsMatrix.hpp>
58 #include <Xpetra_ReorderedBlockedCrsMatrix.hpp>
59 #include <Xpetra_ReorderedBlockedMultiVector.hpp>
60 #include <Xpetra_MultiVectorFactory.hpp>
64 #include "MueLu_Utilities.hpp"
66 #include "MueLu_HierarchyUtils.hpp"
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 : type_(
"blocked Jacobi"), A_(Teuchos::null)
78 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 validParamList->
set<
Scalar>(
"Damping factor", 1.0,
"Damping/Scaling factor in Jacobi");
87 validParamList->
set<
LocalOrdinal>(
"Sweeps", 1,
"Number of sweeps (default = 1)");
89 return validParamList;
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 size_t myPos = Teuchos::as<size_t>(pos);
98 if (myPos < FactManager_.size()) {
100 FactManager_.at(myPos) = FactManager;
101 }
else if( myPos == FactManager_.size()) {
103 FactManager_.push_back(FactManager);
106 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
109 FactManager_.push_back(FactManager);
113 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
117 currentLevel.
DeclareInput(
"A",this->GetFactory(
"A").
get());
120 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
121 for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
125 currentLevel.
DeclareInput(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
128 currentLevel.
DeclareInput(
"A",(*it)->GetFactory(
"A").get());
132 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 FactoryMonitor m(*
this,
"Setup blocked Jacobi Smoother", currentLevel);
141 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
146 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.");
147 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.");
150 rangeMapExtractor_ = bA->getRangeMapExtractor();
151 domainMapExtractor_ = bA->getDomainMapExtractor();
154 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
155 for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
160 Inverse_.push_back(Smoo);
164 bIsBlockedOperator_.push_back(Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(Aii)!=Teuchos::null);
170 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 #if 0 // def HAVE_MUELU_DEBUG
182 if(rcpBDebugB.is_null() ==
false) {
189 if(rcpBDebugX.
is_null() ==
false) {
206 bool bCopyResultX =
false;
212 if(bX.is_null() ==
true) {
218 if(bB.is_null() ==
true) {
224 bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
225 bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
229 if(rbA.is_null() ==
false) {
234 if(bX->getBlockedMap()->getNumMaps() != bA->getDomainMapExtractor()->NumMaps()) {
237 buildReorderedBlockedMultiVector(brm, bX);
240 if(bB->getBlockedMap()->getNumMaps() != bA->getRangeMapExtractor()->NumMaps()) {
243 buildReorderedBlockedMultiVector(brm, bB);
288 RCP<MultiVector> residual = MultiVectorFactory::Build(rcpB->getMap(), rcpB->getNumVectors());
289 RCP<MultiVector> tempres = MultiVectorFactory::Build(rcpB->getMap(), rcpB->getNumVectors());
299 for(
size_t i = 0; i<Inverse_.size(); i++) {
303 residual->update(1.0,*rcpB,0.0);
304 if(InitialGuessIsZero ==
false || i > 0 || run > 0)
308 bool bRangeThyraMode = rangeMapExtractor_->getThyraMode();
309 bool bDomainThyraMode = domainMapExtractor_->getThyraMode();
315 Inverse_.at(i)->Apply(*tXi, *ri,
false);
318 Xi->update(omega,*tXi,1.0);
323 if (bCopyResultX ==
true) {
325 X.update(one, *Xmerged, zero);
329 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
334 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
336 std::ostringstream out;
338 out <<
"{type = " << type_ <<
"}";
342 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
352 out0 <<
"Prec. type: " << type_ <<
" Sweeps: " << nSweeps <<
" damping: " << omega << std::endl;
355 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.
MueLu::DefaultLocalOrdinal LocalOrdinal
RCP< const ParameterList > GetValidParameterList() const
Input.
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 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.
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.
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()'.
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)