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>
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_Utilities.hpp"
69 #include "MueLu_PermutationFactory.hpp"
70 #include "MueLu_Monitor.hpp"
71 
72 namespace MueLu {
73 
74  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
75  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)
76  : type_(type), overlap_(overlap), permQT_(Teuchos::null), permP_(Teuchos::null), diagScalingOp_(Teuchos::null)
77  {
78  this->SetParameterList(paramList);
79 
80  permFact_ = permFact;
81  if (permFact_ == Teuchos::null) {
83  newPermFact->SetParameter("PermutationRowMapName", Teuchos::ParameterEntry(mapName));
84  newPermFact->SetFactory ("PermutationRowMapFactory", mapFact);
85  permFact_ = newPermFact;
86  }
87 
88  // create internal smoother
89  if (type_ == "ILU") {
90 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
91  s_ = MueLu::GetIfpackSmoother<Scalar,LocalOrdinal,GlobalOrdinal,Node>(type_, this->GetParameterList(), overlap_);
92 #else
93  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::PermutingSmoother requires Epetra and Ifpack.");
94 #endif
95  } else {
97  }
99 
100  // Use permuted matrix A
101  s_->SetFactory("A", permFact_);
102  }
103 
104  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
106 
107  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
109  currentLevel.DeclareInput("permP", permFact_.get());
110  currentLevel.DeclareInput("permQT", permFact_.get());
111  currentLevel.DeclareInput("permScaling", permFact_.get());
112 
113  s_->DeclareInput(currentLevel);
114  }
115 
116  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
118  FactoryMonitor monitor(*this, "Permuting Smoother", currentLevel);
119 
120  if (SmootherPrototype::IsSetup() == true)
121  this->GetOStream(Warnings0) << "MueLu::PermutingSmoother::Setup(): Setup() has already been called" << std::endl;
122 
123  // extract information from level class
124  permP_ = currentLevel.Get< RCP<Matrix> > ("permP", permFact_.get());
125  permQT_ = currentLevel.Get< RCP<Matrix> > ("permQT", permFact_.get());
126  diagScalingOp_ = currentLevel.Get< RCP<Matrix> > ("permScaling", permFact_.get());
127 
128  s_->Setup(currentLevel);
129 
131  }
132 
133  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
134  void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
135  TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::PermutingSmoother::Apply(): Setup() has not been called");
136 
137  typedef Teuchos::ScalarTraits<Scalar> STS;
138 
139  Teuchos::RCP<MultiVector> Xtemp = MultiVectorFactory::Build(X.getMap(), 1, true);
140  Xtemp->update(STS::one(), X, STS::zero());
141 
142  // TODO: unify scaling and left permutation operator
143  Teuchos::RCP<MultiVector> Btemp = MultiVectorFactory::Build(B.getMap(), 1, true);
144  Teuchos::RCP<MultiVector> Btemp2 = MultiVectorFactory::Build(B.getMap(), 1, true);
145  permP_->apply(B, *Btemp, Teuchos::NO_TRANS); // apply permutation operator to rhs
146  diagScalingOp_->apply(*Btemp, *Btemp2, Teuchos::NO_TRANS); // apply scaling operator to rhs
147 
148  // apply smoother to permuted linear system
149  s_->Apply(*Xtemp, *Btemp2, InitialGuessIsZero);
150 
151  // retransform smooth solution
152  permQT_->apply(*Xtemp, X, Teuchos::NO_TRANS);
153  }
154 
155  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
158  return rcp(new PermutingSmoother(*this));
159  }
160 
161  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
163  std::ostringstream out;
165  return out.str();
166  }
167 
168  template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
171  out0 << ""; // avoid warning
172  }
173 
174 } // namespace MueLu
175 
176 
177 #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.