53 #ifndef MUELU_BLOCKEDGAUSSSEIDELSMOOTHER_DEF_HPP_ 54 #define MUELU_BLOCKEDGAUSSSEIDELSMOOTHER_DEF_HPP_ 56 #include "Teuchos_ArrayViewDecl.hpp" 57 #include "Teuchos_ScalarTraits.hpp" 61 #include <Xpetra_Matrix.hpp> 62 #include <Xpetra_BlockedCrsMatrix.hpp> 63 #include <Xpetra_MultiVectorFactory.hpp> 67 #include "MueLu_Utilities.hpp" 69 #include "MueLu_HierarchyHelpers.hpp" 74 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 : type_(
"blocked GaussSeidel"), A_(
Teuchos::null)
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 RCP<ParameterList> validParamList = rcp(
new ParameterList());
88 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A");
89 validParamList->set< Scalar > (
"Damping factor", 1.0,
"Damping/Scaling factor in BGS");
90 validParamList->set< LocalOrdinal > (
"Sweeps", 1,
"Number of BGS sweeps (default = 1)");
92 return validParamList;
95 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 TEUCHOS_TEST_FOR_EXCEPTION(pos < 0,
Exceptions::RuntimeError,
"MueLu::BlockedGaussSeidelSmoother::AddFactoryManager: parameter \'pos\' must not be negative! error.");
99 size_t myPos = Teuchos::as<size_t>(pos);
108 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
109 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
116 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
128 currentLevel.
DeclareInput(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
134 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
140 FactoryMonitor m(*
this,
"Setup blocked Gauss-Seidel Smoother", currentLevel);
144 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
145 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
146 TEUCHOS_TEST_FOR_EXCEPTION(bA==Teuchos::null,
Exceptions::BadCast,
"MueLu::BlockedPFactory::Build: input matrix A is not of type BlockedCrsMatrix! error.");
149 TEUCHOS_TEST_FOR_EXCEPTION(bA->Rows() !=
FactManager_.size(),
Exceptions::RuntimeError,
"MueLu::BlockedPFactory::Build: number of block rows of A does not match number of SubFactoryManagers. error.");
150 TEUCHOS_TEST_FOR_EXCEPTION(bA->Cols() !=
FactManager_.size(),
Exceptions::RuntimeError,
"MueLu::BlockedPFactory::Build: number of block cols of A does not match number of SubFactoryManagers. error.");
156 Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
159 size_t bgsOrderingIndex = 0;
161 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
166 RCP<const SmootherBase> Smoo = currentLevel.Get< RCP<SmootherBase> >(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
192 template <
class StdMapType>
193 const typename StdMapType::mapped_type &
at(
const StdMapType& map,
const typename StdMapType::key_type& x) {
194 typename StdMapType::const_iterator it = map.find(x);
195 TEUCHOS_TEST_FOR_EXCEPTION(it == map.end(), std::out_of_range,
"MueLu::at(): element does not exist in the map");
199 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
204 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > residual = MultiVectorFactory::Build(B.getMap(), B.getNumVectors());
205 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > tempres = MultiVectorFactory::Build(B.getMap(), B.getNumVectors());
206 RCP<MultiVector> rcpX = Teuchos::rcpFromRef(X);
213 LocalOrdinal nSweeps = pL.get<LocalOrdinal>(
"Sweeps");
214 Scalar omega = pL.get<Scalar>(
"Damping factor");
217 for (LocalOrdinal run = 0; run < nSweeps; ++run) {
220 for(
size_t i = 0; i<
Inverse_.size(); i++) {
224 residual->update(1.0,B,0.0);
225 A_->apply(X, *residual, Teuchos::NO_TRANS, -1.0, 1.0);
230 Teuchos::RCP<MultiVector> ri =
rangeMapExtractor_->ExtractVector(residual, blockRowIndex);
232 Teuchos::RCP<MultiVector> tXi =
domainMapExtractor_->getVector(blockRowIndex, X.getNumVectors());
235 Inverse_.at(i)->Apply(*tXi, *ri,
false);
238 Xi->update(omega,*tXi,1.0);
247 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
252 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
254 std::ostringstream out;
256 out <<
"{type = " <<
type_ <<
"}";
260 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
266 LocalOrdinal nSweeps = pL.get<LocalOrdinal>(
"Sweeps");
267 Scalar omega = pL.get<Scalar>(
"Damping factor");
270 out0 <<
"Prec. type: " <<
type_ <<
" Sweeps: " << nSweeps <<
" damping: " << omega << std::endl;
273 if (verbLevel &
Debug) {
274 std::map<size_t,size_t>::const_iterator itOrdering;
276 std::cout <<
"block GaussSeidel ordering index: " << (*itOrdering).first <<
" -> block row in blocked A: " << (*itOrdering).second << std::endl;
280 if (verbLevel & Debug) {
Important warning messages (one line)
Exception indicating invalid cast attempted.
virtual ~BlockedGaussSeidelSmoother()
Destructor.
RCP< const MapExtractorClass > domainMapExtractor_
domain map extractor (from A_ generated by AFact)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Timer to be used in factories. Similar to Monitor but with additional timers.
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.
Namespace for MueLu classes and methods.
virtual const Teuchos::ParameterList & GetParameterList() const
std::vector< Teuchos::RCP< const SmootherBase > > Inverse_
vector of smoother/solver factories
std::string description() const
Return a simple one-line description of this object.
void DeclareInput(Level ¤tLevel) const
Input.
RCP< const MapExtractorClass > rangeMapExtractor_
range map extractor (from A_ generated by AFact)
const StdMapType::mapped_type & at(const StdMapType &map, const typename StdMapType::key_type &x)
std::map< size_t, size_t > bgsOrderingIndex2blockRowIndex_
map: block GaussSeidel ordering to block row ordering
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.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
std::string type_
smoother type
RCP< Matrix > A_
block operator
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.
An exception safe way to call the method 'Level::SetFactoryManager()'.
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.
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory()