53 #ifndef MUELU_BLOCKEDGAUSSSEIDELSMOOTHER_DEF_HPP_
54 #define MUELU_BLOCKEDGAUSSSEIDELSMOOTHER_DEF_HPP_
56 #include "Teuchos_ArrayViewDecl.hpp"
70 #include "MueLu_Utilities.hpp"
72 #include "MueLu_HierarchyUtils.hpp"
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 : type_(
"blocked GaussSeidel"), A_(Teuchos::null)
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
92 validParamList->
set< Scalar > (
"Damping factor", 1.0,
"Damping/Scaling factor in BGS");
93 validParamList->
set< LocalOrdinal > (
"Sweeps", 1,
"Number of BGS sweeps (default = 1)");
95 return validParamList;
98 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 size_t myPos = Teuchos::as<size_t>(pos);
104 if (myPos < FactManager_.size()) {
106 FactManager_.at(myPos) = FactManager;
107 }
else if( myPos == FactManager_.size()) {
109 FactManager_.push_back(FactManager);
112 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
115 FactManager_.push_back(FactManager);
119 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 currentLevel.
DeclareInput(
"A",this->GetFactory(
"A").
get());
126 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
127 for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
131 currentLevel.
DeclareInput(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
134 currentLevel.
DeclareInput(
"A",(*it)->GetFactory(
"A").get());
140 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 FactoryMonitor m(*
this,
"Setup blocked Gauss-Seidel Smoother", currentLevel);
150 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
155 TEUCHOS_TEST_FOR_EXCEPTION(bA->Rows() != FactManager_.size(),
Exceptions::RuntimeError,
"MueLu::BlockedGaussSeidelSmoother::Setup: number of block rows of A is " << bA->Rows() <<
" and does not match number of SubFactoryManagers " << FactManager_.size() <<
". error.");
156 TEUCHOS_TEST_FOR_EXCEPTION(bA->Cols() != FactManager_.size(),
Exceptions::RuntimeError,
"MueLu::BlockedGaussSeidelSmoother::Setup: number of block cols of A is " << bA->Cols() <<
" and does not match number of SubFactoryManagers " << FactManager_.size() <<
". error.");
159 rangeMapExtractor_ = bA->getRangeMapExtractor();
160 domainMapExtractor_ = bA->getDomainMapExtractor();
163 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
164 for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
169 Inverse_.push_back(Smoo);
173 bIsBlockedOperator_.push_back(Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(Aii)!=Teuchos::null);
179 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
184 #if 0 // def HAVE_MUELU_DEBUG
191 if(rcpBDebugB.is_null() ==
false) {
198 if(rcpBDebugX.
is_null() ==
false) {
215 bool bCopyResultX =
false;
221 if(bX.is_null() ==
true) {
227 if(bB.is_null() ==
true) {
233 bX = Teuchos::rcp_dynamic_cast<BlockedMultiVector>(rcpX);
234 bB = Teuchos::rcp_dynamic_cast<
const BlockedMultiVector>(rcpB);
238 if(rbA.is_null() ==
false) {
243 if(bX->getBlockedMap()->getNumMaps() != bA->getDomainMapExtractor()->NumMaps()) {
249 if(bB->getBlockedMap()->getNumMaps() != bA->getRangeMapExtractor()->NumMaps()) {
297 RCP<MultiVector> residual = MultiVectorFactory::Build(rcpB->getMap(), rcpB->getNumVectors());
298 RCP<MultiVector> tempres = MultiVectorFactory::Build(rcpB->getMap(), rcpB->getNumVectors());
302 LocalOrdinal nSweeps = pL.get<LocalOrdinal>(
"Sweeps");
303 Scalar omega = pL.get<Scalar>(
"Damping factor");
306 for (LocalOrdinal run = 0; run < nSweeps; ++run) {
309 for(
size_t i = 0; i<Inverse_.size(); i++) {
313 residual->update(1.0,*rcpB,0.0);
314 if(InitialGuessIsZero ==
false || i > 0 || run > 0)
319 bool bRangeThyraMode = rangeMapExtractor_->getThyraMode();
320 bool bDomainThyraMode = domainMapExtractor_->getThyraMode();
326 Inverse_.at(i)->Apply(*tXi, *ri,
false);
329 Xi->update(omega,*tXi,1.0);
332 domainMapExtractor_->InsertVector(Xi, i, rcpX, bDomainThyraMode);
336 if (bCopyResultX ==
true) {
338 X.update(one, *Xmerged, zero);
342 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
347 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
349 std::ostringstream out;
351 out <<
"{type = " << type_ <<
"}";
355 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 LocalOrdinal nSweeps = pL.
get<LocalOrdinal>(
"Sweeps");
362 Scalar omega = pL.
get<Scalar>(
"Damping factor");
365 out0 <<
"Prec. type: " << type_ <<
" Sweeps: " << nSweeps <<
" damping: " << omega << std::endl;
368 if (verbLevel &
Debug) {
372 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.
virtual ~BlockedGaussSeidelSmoother()
Destructor.
T & get(const std::string &name, T def_value)
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
block Gauss-Seidel method for blocked matrices
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.
std::string description() const
Return a simple one-line description of this object.
void DeclareInput(Level ¤tLevel) const
Input.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
void Setup(Level ¤tLevel)
Setup routine In the Setup method the Inverse_ vector is filled with the corresponding SmootherBase o...
bool IsSetup() const
Get the state of a smoother prototype.
std::vector< Teuchos::RCP< const FactoryManagerBase > > FactManager_
vector of factory managers
BlockedGaussSeidelSmoother()
Constructor.
RCP< SmootherPrototype > Copy() const
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
RCP< const ParameterList > GetValidParameterList() const
Input.
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.
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 AddFactoryManager(RCP< const FactoryManagerBase > FactManager, int pos)
Add a factory manager.
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)