MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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_IfpackSmoother.hpp"
32 #include "MueLu_PermutationFactory.hpp"
33 #include "MueLu_Monitor.hpp"
34 
35 namespace MueLu {
36 
37 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
38 PermutingSmoother<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) {
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 {
63  }
65 
66  // Use permuted matrix A
67  s_->SetFactory("A", permFact_);
68 }
69 
70 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
72 
73 template <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 
82 template <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 
99 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
100 void 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 
121 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
124  return rcp(new PermutingSmoother(*this));
125 }
126 
127 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
129  std::ostringstream out;
131  return out.str();
132 }
133 
134 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
137  out0 << ""; // avoid warning
138 }
139 
140 } // namespace MueLu
141 
142 #endif /* MUELU_PERMUTINGSMOOTHER_DEF_HPP */
Important warning messages (one line)
virtual const Teuchos::ParameterList & GetParameterList() const
std::string description() const
Return a simple one-line description of this object.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; use default factory.
RCP< SmootherPrototype > Copy() const
virtual ~PermutingSmoother()
Destructor.
Class that encapsulates external library smoothers.
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
LocalOrdinal LO
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...
LO overlap_
overlap when using the smoother in additive Schwarz mode
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void Setup(Level &currentLevel)
Set up the direct solver.
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
RCP< FactoryBase > permFact_
Permutation Factory.
void DeclareInput(Level &currentLevel) const
Input.
bool IsSetup() const
Get the state of a smoother prototype.
std::string type_
ifpack1/2-specific key phrase that denote smoother type
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
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.
Exception throws to report errors in the internal logical of the program.
RCP< SmootherPrototype > s_
Smoother.
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.