MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_PermutingSmoother_def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MueLu: A package for multigrid based preconditioning
4//
5// Copyright 2012 NTESS and the MueLu contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10/*
11 * MueLu_PermutingSmoother_def.hpp
12 *
13 * Created on: Nov 28, 2012
14 * Author: wiesner
15 */
16
17#ifndef MUELU_PERMUTINGSMOOTHER_DEF_HPP
18#define MUELU_PERMUTINGSMOOTHER_DEF_HPP
19
20#include <Xpetra_Matrix.hpp>
21#include <Xpetra_MultiVector.hpp>
22#include <Xpetra_MultiVectorFactory.hpp>
23#include <Xpetra_Vector.hpp>
24#include <Xpetra_VectorFactory.hpp>
25
26#include "MueLu_ConfigDefs.hpp"
27
29#include "MueLu_Level.hpp"
30#include "MueLu_TrilinosSmoother.hpp"
32#include "MueLu_PermutationFactory.hpp"
33#include "MueLu_Monitor.hpp"
34
35namespace MueLu {
36
37template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
38PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::PermutingSmoother(const std::string& mapName, const RCP<const FactoryBase>& mapFact, const std::string& type, const Teuchos::ParameterList& paramList, const LO& overlap, RCP<FactoryBase> permFact)
39 : type_(type)
40 , overlap_(overlap)
41 , permQT_(Teuchos::null)
42 , permP_(Teuchos::null)
43 , diagScalingOp_(Teuchos::null) {
44 this->SetParameterList(paramList);
45
46 permFact_ = permFact;
47 if (permFact_ == Teuchos::null) {
48 RCP<PermutationFactory> newPermFact = Teuchos::rcp(new PermutationFactory());
49 newPermFact->SetParameter("PermutationRowMapName", Teuchos::ParameterEntry(mapName));
50 newPermFact->SetFactory("PermutationRowMapFactory", mapFact);
51 permFact_ = newPermFact;
52 }
53
54 // create internal smoother
55 if (type_ == "ILU") {
56#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
57 s_ = MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>(type_, this->GetParameterList(), overlap_);
58#else
59 TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::PermutingSmoother requires Epetra and Ifpack.");
60#endif
61 } else {
62 s_ = Teuchos::rcp(new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
63 }
64 TEUCHOS_TEST_FOR_EXCEPTION(s_ == Teuchos::null, Exceptions::RuntimeError, "");
65
66 // Use permuted matrix A
67 s_->SetFactory("A", permFact_);
68}
69
70template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
72
73template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
75 currentLevel.DeclareInput("permP", permFact_.get());
76 currentLevel.DeclareInput("permQT", permFact_.get());
77 currentLevel.DeclareInput("permScaling", permFact_.get());
78
79 s_->DeclareInput(currentLevel);
80}
81
82template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
84 FactoryMonitor monitor(*this, "Permuting Smoother", currentLevel);
85
86 if (SmootherPrototype::IsSetup() == true)
87 this->GetOStream(Warnings0) << "MueLu::PermutingSmoother::Setup(): Setup() has already been called" << std::endl;
88
89 // extract information from level class
90 permP_ = currentLevel.Get<RCP<Matrix> >("permP", permFact_.get());
91 permQT_ = currentLevel.Get<RCP<Matrix> >("permQT", permFact_.get());
92 diagScalingOp_ = currentLevel.Get<RCP<Matrix> >("permScaling", permFact_.get());
93
94 s_->Setup(currentLevel);
95
97}
98
99template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
100void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
101 TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::PermutingSmoother::Apply(): Setup() has not been called");
102
103 typedef Teuchos::ScalarTraits<Scalar> STS;
104
105 Teuchos::RCP<MultiVector> Xtemp = MultiVectorFactory::Build(X.getMap(), 1, true);
106 Xtemp->update(STS::one(), X, STS::zero());
107
108 // TODO: unify scaling and left permutation operator
109 Teuchos::RCP<MultiVector> Btemp = MultiVectorFactory::Build(B.getMap(), 1, true);
110 Teuchos::RCP<MultiVector> Btemp2 = MultiVectorFactory::Build(B.getMap(), 1, true);
111 permP_->apply(B, *Btemp, Teuchos::NO_TRANS); // apply permutation operator to rhs
112 diagScalingOp_->apply(*Btemp, *Btemp2, Teuchos::NO_TRANS); // apply scaling operator to rhs
113
114 // apply smoother to permuted linear system
115 s_->Apply(*Xtemp, *Btemp2, InitialGuessIsZero);
116
117 // retransform smooth solution
118 permQT_->apply(*Xtemp, X, Teuchos::NO_TRANS);
119}
120
121template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
122RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
126
127template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
129 std::ostringstream out;
131 return out.str();
132}
133
134template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
135void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream& out, const VerbLevel verbLevel) const {
137 out0 << ""; // avoid warning
138}
139
140} // namespace MueLu
141
142#endif /* MUELU_PERMUTINGSMOOTHER_DEF_HPP */
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
virtual std::string description() const
Return a simple one-line description of this object.
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
virtual const Teuchos::ParameterList & GetParameterList() const
factory generates a row- and column permutation operators P and Q such that P*A*Q^T is a (hopefully) ...
This class first calculates row- and column permutation operators and applies a smoother to the permu...
std::string description() const
Return a simple one-line description of this object.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
RCP< FactoryBase > permFact_
Permutation Factory.
RCP< SmootherPrototype > Copy() const
void DeclareInput(Level &currentLevel) const
Input.
void Setup(Level &currentLevel)
Set up the direct solver.
LO overlap_
overlap when using the smoother in additive Schwarz mode
std::string type_
ifpack1/2-specific key phrase that denote smoother type
PermutingSmoother(std::string const &mapName, const RCP< const FactoryBase > &mapFact, std::string const &type="", const Teuchos::ParameterList &paramList=Teuchos::ParameterList(), LO const &overlap=0, RCP< FactoryBase > permFact=Teuchos::null)
Constructor.
RCP< SmootherPrototype > s_
Smoother.
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.
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates external library smoothers.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line)