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 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 /*
47  * MueLu_PermutingSmoother_def.hpp
48  *
49  * Created on: Nov 28, 2012
50  * Author: wiesner
51  */
52 
53 #ifndef MUELU_PERMUTINGSMOOTHER_DEF_HPP
54 #define MUELU_PERMUTINGSMOOTHER_DEF_HPP
55 
56 #include <Xpetra_Matrix.hpp>
57 #include <Xpetra_MultiVector.hpp>
58 #include <Xpetra_MultiVectorFactory.hpp>
59 #include <Xpetra_Vector.hpp>
60 #include <Xpetra_VectorFactory.hpp>
61 
62 #include "MueLu_ConfigDefs.hpp"
63 
65 #include "MueLu_Level.hpp"
66 #include "MueLu_TrilinosSmoother.hpp"
67 #include "MueLu_IfpackSmoother.hpp"
68 #include "MueLu_PermutationFactory.hpp"
69 #include "MueLu_Monitor.hpp"
70 
71 namespace MueLu {
72 
73 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74 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)
75  : type_(type)
76  , overlap_(overlap)
77  , permQT_(Teuchos::null)
78  , permP_(Teuchos::null)
79  , diagScalingOp_(Teuchos::null) {
80  this->SetParameterList(paramList);
81 
82  permFact_ = permFact;
83  if (permFact_ == Teuchos::null) {
85  newPermFact->SetParameter("PermutationRowMapName", Teuchos::ParameterEntry(mapName));
86  newPermFact->SetFactory("PermutationRowMapFactory", mapFact);
87  permFact_ = newPermFact;
88  }
89 
90  // create internal smoother
91  if (type_ == "ILU") {
92 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
93  s_ = MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>(type_, this->GetParameterList(), overlap_);
94 #else
95  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::PermutingSmoother requires Epetra and Ifpack.");
96 #endif
97  } else {
99  }
101 
102  // Use permuted matrix A
103  s_->SetFactory("A", permFact_);
104 }
105 
106 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
108 
109 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
111  currentLevel.DeclareInput("permP", permFact_.get());
112  currentLevel.DeclareInput("permQT", permFact_.get());
113  currentLevel.DeclareInput("permScaling", permFact_.get());
114 
115  s_->DeclareInput(currentLevel);
116 }
117 
118 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
120  FactoryMonitor monitor(*this, "Permuting Smoother", currentLevel);
121 
122  if (SmootherPrototype::IsSetup() == true)
123  this->GetOStream(Warnings0) << "MueLu::PermutingSmoother::Setup(): Setup() has already been called" << std::endl;
124 
125  // extract information from level class
126  permP_ = currentLevel.Get<RCP<Matrix> >("permP", permFact_.get());
127  permQT_ = currentLevel.Get<RCP<Matrix> >("permQT", permFact_.get());
128  diagScalingOp_ = currentLevel.Get<RCP<Matrix> >("permScaling", permFact_.get());
129 
130  s_->Setup(currentLevel);
131 
133 }
134 
135 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
136 void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
137  TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::PermutingSmoother::Apply(): Setup() has not been called");
138 
139  typedef Teuchos::ScalarTraits<Scalar> STS;
140 
141  Teuchos::RCP<MultiVector> Xtemp = MultiVectorFactory::Build(X.getMap(), 1, true);
142  Xtemp->update(STS::one(), X, STS::zero());
143 
144  // TODO: unify scaling and left permutation operator
145  Teuchos::RCP<MultiVector> Btemp = MultiVectorFactory::Build(B.getMap(), 1, true);
146  Teuchos::RCP<MultiVector> Btemp2 = MultiVectorFactory::Build(B.getMap(), 1, true);
147  permP_->apply(B, *Btemp, Teuchos::NO_TRANS); // apply permutation operator to rhs
148  diagScalingOp_->apply(*Btemp, *Btemp2, Teuchos::NO_TRANS); // apply scaling operator to rhs
149 
150  // apply smoother to permuted linear system
151  s_->Apply(*Xtemp, *Btemp2, InitialGuessIsZero);
152 
153  // retransform smooth solution
154  permQT_->apply(*Xtemp, X, Teuchos::NO_TRANS);
155 }
156 
157 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
160  return rcp(new PermutingSmoother(*this));
161 }
162 
163 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
165  std::ostringstream out;
167  return out.str();
168 }
169 
170 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
173  out0 << ""; // avoid warning
174 }
175 
176 } // namespace MueLu
177 
178 #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
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:99
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.