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"
31#include "MueLu_PermutationFactory.hpp"
32#include "MueLu_Monitor.hpp"
33
34namespace MueLu {
35
36template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
37PermutingSmoother<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)
38 : type_(type)
39 , overlap_(overlap)
40 , permQT_(Teuchos::null)
41 , permP_(Teuchos::null)
42 , diagScalingOp_(Teuchos::null) {
43 this->SetParameterList(paramList);
44
45 permFact_ = permFact;
46 if (permFact_ == Teuchos::null) {
47 RCP<PermutationFactory> newPermFact = Teuchos::rcp(new PermutationFactory());
48 newPermFact->SetParameter("PermutationRowMapName", Teuchos::ParameterEntry(mapName));
49 newPermFact->SetFactory("PermutationRowMapFactory", mapFact);
50 permFact_ = newPermFact;
51 }
52
53 // create internal smoother
54 if (type_ == "ILU") {
55 TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::PermutingSmoother requires Epetra and Ifpack.");
56 } else {
57 s_ = Teuchos::rcp(new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
58 }
59 TEUCHOS_TEST_FOR_EXCEPTION(s_ == Teuchos::null, Exceptions::RuntimeError, "");
60
61 // Use permuted matrix A
62 s_->SetFactory("A", permFact_);
63}
64
65template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
67
68template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
70 currentLevel.DeclareInput("permP", permFact_.get());
71 currentLevel.DeclareInput("permQT", permFact_.get());
72 currentLevel.DeclareInput("permScaling", permFact_.get());
73
74 s_->DeclareInput(currentLevel);
75}
76
77template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
79 FactoryMonitor monitor(*this, "Permuting Smoother", currentLevel);
80
81 if (SmootherPrototype::IsSetup() == true)
82 this->GetOStream(Warnings0) << "MueLu::PermutingSmoother::Setup(): Setup() has already been called" << std::endl;
83
84 // extract information from level class
85 permP_ = currentLevel.Get<RCP<Matrix> >("permP", permFact_.get());
86 permQT_ = currentLevel.Get<RCP<Matrix> >("permQT", permFact_.get());
87 diagScalingOp_ = currentLevel.Get<RCP<Matrix> >("permScaling", permFact_.get());
88
89 s_->Setup(currentLevel);
90
92}
93
94template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
95void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
96 TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::PermutingSmoother::Apply(): Setup() has not been called");
97
98 typedef Teuchos::ScalarTraits<Scalar> STS;
99
100 Teuchos::RCP<MultiVector> Xtemp = MultiVectorFactory::Build(X.getMap(), 1, true);
101 Xtemp->update(STS::one(), X, STS::zero());
102
103 // TODO: unify scaling and left permutation operator
104 Teuchos::RCP<MultiVector> Btemp = MultiVectorFactory::Build(B.getMap(), 1, true);
105 Teuchos::RCP<MultiVector> Btemp2 = MultiVectorFactory::Build(B.getMap(), 1, true);
106 permP_->apply(B, *Btemp, Teuchos::NO_TRANS); // apply permutation operator to rhs
107 diagScalingOp_->apply(*Btemp, *Btemp2, Teuchos::NO_TRANS); // apply scaling operator to rhs
108
109 // apply smoother to permuted linear system
110 s_->Apply(*Xtemp, *Btemp2, InitialGuessIsZero);
111
112 // retransform smooth solution
113 permQT_->apply(*Xtemp, X, Teuchos::NO_TRANS);
114}
115
116template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
117RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
121
122template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
124 std::ostringstream out;
126 return out.str();
127}
128
129template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
130void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream& out, const VerbLevel verbLevel) const {
132 out0 << ""; // avoid warning
133}
134
135} // namespace MueLu
136
137#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)