MueLu  Version of the Day
MueLu_TrilinosSmoother_decl.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 #ifndef MUELU_TRILINOSSMOOTHER_DECL_HPP
47 #define MUELU_TRILINOSSMOOTHER_DECL_HPP
48 
49 #include <Teuchos_ParameterList.hpp>
50 
51 #include <Xpetra_Matrix_fwd.hpp>
52 
53 #include "MueLu_ConfigDefs.hpp"
55 #include "MueLu_SmootherPrototype.hpp"
56 
59 
60 #if defined(HAVE_MUELU_IFPACK2)
62 #include "MueLu_Ifpack2Smoother.hpp"
63 #endif
64 
65 // Note: TrilinosSmoother is a SmootherPrototype that cannot be turned into a smoother using Setup().
66 // When this prototype is cloned using Copy(), the clone is an Ifpack or an Ifpack2 smoother.
67 // The clone can be used as a smoother after calling Setup().
68 
69 namespace MueLu {
70 
79  template <class Scalar = SmootherPrototype<>::scalar_type,
80  class LocalOrdinal = typename SmootherPrototype<Scalar>::local_ordinal_type,
83  class TrilinosSmoother : public SmootherPrototype<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
84 #undef MUELU_TRILINOSSMOOTHER_SHORT
85 #include "MueLu_UseShortNames.hpp"
86 
87  public:
88 
90 
91 
104  TrilinosSmoother(const std::string& type = "", const Teuchos::ParameterList& paramList = Teuchos::ParameterList(), const LO& overlap = 0);
105 
107  virtual ~TrilinosSmoother() { }
108 
110 
112 
113 
114  void DeclareInput(Level& currentLevel) const;
115 
117 
119 
120 
122  void Setup(Level& currentLevel);
123 
125  void Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero = false) const;
126 
128 
130  void SetFactory(const std::string& varName, const RCP<const FactoryBase>& factory);
131 
133  RCP<SmootherPrototype> Copy() const;
134 
135 #ifndef _MSC_VER
136  template<class Scalar2, class LocalOrdinal2, class GlobalOrdinal2, class Node2>
138  friend class TrilinosSmoother;
139 #endif
140 
141  template<typename Node2>
142  RCP<MueLu::TrilinosSmoother<Scalar,LocalOrdinal,GlobalOrdinal,Node2> > clone(const RCP<Node2>& node2, const Teuchos::RCP<const Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >& A_newnode) const;
143 
144 
146  // As a temporary solution.
147  // See https://software.sandia.gov/bugzilla/show_bug.cgi?id=5283#c5 for what I proposed to do
148  static std::string Ifpack2ToIfpack1Type(const std::string& type);
149 
151  // As a temporary solution.
152  // See https://software.sandia.gov/bugzilla/show_bug.cgi?id=5283#c5 for what I proposed to do
153  /* TODO:
154  ifpackList.set("type", "Chebyshev");
155  ifpackList.set("chebyshev: degree", (int) 1);
156  ifpackList.set("chebyshev: max eigenvalue", (double) 2.0);
157  ifpackList.set("chebyshev: min eigenvalue", (double) 1.0);
158  ifpackList.set("chebyshev: zero starting solution", false);
159  */
160  static Teuchos::ParameterList Ifpack2ToIfpack1Param(const Teuchos::ParameterList& ifpack2List);
161 
163 
164 
166  std::string description() const;
167 
169  //using MueLu::Describable::describe; // overloading, not hiding
170  //void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const {
171  void print(Teuchos::FancyOStream& out, const VerbLevel verbLevel = Default) const;
172 
174 
175  private:
176 
178  std::string type_;
179 
182 
184  RCP<FactoryBase> AFact_;
185 
186  //
187  // Underlying Smoother
188  //
189 
191  RCP<SmootherPrototype> sEpetra_, sTpetra_;
192  mutable
193  RCP<SmootherPrototype> s_;
194 
195  // Records for the case if something goes wrong
198 
199  }; // class TrilinosSmoother
200 
201  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
202  template<typename Node2>
203  Teuchos::RCP<MueLu::TrilinosSmoother<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >
205 #if defined(HAVE_MUELU_IFPACK2)
206  RCP<TrilinosSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > cloneSmoother =
207  rcp(new TrilinosSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node2>(type_, this->GetParameterList(), overlap_));
208  Teuchos::RCP<MueLu::SmootherBase<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > cloneSB;
209 
210  Teuchos::RCP<MueLu::Ifpack2Smoother<Scalar, LocalOrdinal, GlobalOrdinal, Node> > ifpack2Smoother =
211  Teuchos::rcp_dynamic_cast<MueLu::Ifpack2Smoother<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(this->s_);
212  if (ifpack2Smoother != Teuchos::null){
213  cloneSB = ifpack2Smoother->template clone<Node2>(node2, A_newnode);
214  }
215  else {
216  TEUCHOS_TEST_FOR_EXCEPTION(
217  true, std::invalid_argument, "MueLu::TrilinosSmoother: "
218  "Invalid smoother type to clone (not type Ifpack2)\"");
219  }
220  RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > clonedProto =
222  cloneSmoother->s_ = clonedProto;
223  cloneSmoother->IsSetup(true);
224  return cloneSmoother;
225 #else
226  TEUCHOS_TEST_FOR_EXCEPTION(
227  true, std::invalid_argument, "MueLu::SmootherClone: "
228  "clone() only available with IFPACK2 enabled.");
229 #endif
230  }
231 
232 
233 } // namespace MueLu
234 
235 #define MUELU_TRILINOSSMOOTHER_SHORT
236 #endif // MUELU_TRILINOSSMOOTHER_DECL_HPP
RCP< SmootherPrototype > Copy() const
When this prototype is cloned using Copy(), the clone is an Ifpack or an Ifpack2 smoother.
RCP< MueLu::TrilinosSmoother< Scalar, LocalOrdinal, GlobalOrdinal, Node2 > > clone(const RCP< Node2 > &node2, const Teuchos::RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2 > > &A_newnode) const
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates external library smoothers.
static std::string Ifpack2ToIfpack1Type(const std::string &type)
Convert an Ifpack2 preconditioner name to Ifpack.
static Teuchos::ParameterList Ifpack2ToIfpack1Param(const Teuchos::ParameterList &ifpack2List)
Convert an Ifpack2 parameter list to Ifpack.
Base class for smoother prototypes.
void DeclareInput(Level &currentLevel) const
Input.
LocalOrdinal LO
Namespace for MueLu classes and methods.
void Setup(Level &currentLevel)
TrilinosSmoother cannot be turned into a smoother using Setup(). Setup() always returns a RuntimeErro...
friend class TrilinosSmoother
Friend declaration required for clone() functionality.
std::string description() const
Return a simple one-line description of this object.
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
std::string type_
ifpack1/2-specific key phrase that denote smoother type
RCP< FactoryBase > AFact_
A Factory.
RCP< SmootherPrototype > sEpetra_
Smoother.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
LO overlap_
overlap when using the smoother in additive Schwarz mode
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
TrilinosSmoother cannot be applied. Apply() always returns a RuntimeError exception.
Class that encapsulates Ifpack2 smoothers.
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.