MueLu  Version of the Day
MueLu_Ifpack2Smoother_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_IFPACK2SMOOTHER_DECL_HPP
47 #define MUELU_IFPACK2SMOOTHER_DECL_HPP
48 
50 
51 #include <Xpetra_BlockedCrsMatrix_fwd.hpp>
52 #include <Xpetra_CrsMatrixWrap.hpp>
53 #include <Xpetra_Matrix_fwd.hpp>
54 #include <Xpetra_Matrix.hpp>
55 #include <Xpetra_MultiVectorFactory_fwd.hpp>
56 #ifdef HAVE_XPETRA_TPETRA // needed for clone()
57 #include <Xpetra_TpetraCrsMatrix.hpp>
58 #endif
59 
60 #include "MueLu_ConfigDefs.hpp"
62 
63 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_IFPACK2)
64 
65 #include <Tpetra_CrsMatrix.hpp>
66 
67 #include <Ifpack2_Factory_decl.hpp>
68 #include <Ifpack2_Factory_def.hpp>
69 #include <Ifpack2_Preconditioner.hpp>
70 
73 #include "MueLu_Level_fwd.hpp"
74 #include "MueLu_SmootherPrototype.hpp"
75 #include "MueLu_Utilities_fwd.hpp"
76 
77 namespace MueLu {
78 
89  template <class Scalar = SmootherPrototype<>::scalar_type,
90  class LocalOrdinal = typename SmootherPrototype<Scalar>::local_ordinal_type,
93  class Ifpack2Smoother : public SmootherPrototype<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
94 #undef MUELU_IFPACK2SMOOTHER_SHORT
95 #include "MueLu_UseShortNames.hpp"
96 
97  public:
98 
100 
101  //TODO: update doc for Ifpack2. Right now, it's a copy of the doc of IfpackSmoother
137 #ifndef _MSC_VER
138  // Avoid error C3772: invalid friend template declaration
139  template<class Scalar2, class LocalOrdinal2, class GlobalOrdinal2, class Node2>
140  friend class Ifpack2Smoother;
141 #endif
142 
143  Ifpack2Smoother(const std::string& type, const Teuchos::ParameterList& paramList = Teuchos::ParameterList(), const LO& overlap = 0); //TODO: empty paramList valid for Ifpack??
144 
146  virtual ~Ifpack2Smoother() { }
147 
149 
150  void SetParameterList(const Teuchos::ParameterList& paramList);
151 
153 
154 
155  void DeclareInput(Level &currentLevel) const;
156 
158 
160 
161 
169  void Setup(Level &currentLevel);
170 
179  void Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero = false) const;
180 
182 
184 
185 
187 
189 
191  template<typename Node2>
193  clone(const RCP<Node2>& node2, const Teuchos::RCP<const Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >& A_newnode) const;
194 
196 
197 
199  std::string description() const;
200 
202  //using MueLu::Describable::describe; // overloading, not hiding
203  //void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const
204  void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const;
205 
207 
208  private:
210 
211  void SetupSchwarz (Level& currentLevel);
212  void SetupChebyshev (Level& currentLevel);
213  void SetupLineSmoothing (Level& currentLevel);
214  void SetupGeneric (Level& currentLevel);
215 
216  private:
217 
219  std::string type_;
220 
223 
226 
229 
230  }; // class Ifpack2Smoother
231 
232  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
233  template<typename Node2>
235  Ifpack2Smoother<Scalar,LocalOrdinal,GlobalOrdinal,Node>::clone(const RCP<Node2>& node2, const RCP<const Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >& A_newnode) const {
236 #ifdef HAVE_XPETRA_TPETRA
237  const ParameterList& paramList = this->GetParameterList();
238  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix1;
239  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> Matrix2;
241  rcp(new Ifpack2Smoother<Scalar, LocalOrdinal, GlobalOrdinal, Node2>(type_, paramList, overlap_));
242 
243  //Get Tpetra::CrsMatrix from Xpetra::Matrix
245  rcp_dynamic_cast<const Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >(A_newnode);
247  rcp_dynamic_cast<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >(crsOp->getCrsMatrix());
248 
249  Ifpack2::Factory factory;
250  cloneSmoother->prec_ = factory.clone<Matrix1, Matrix2>(prec_, tmp->getTpetra_CrsMatrix(), paramList);
251  cloneSmoother->type_ = type_;
252  cloneSmoother->SetParameterList(paramList);
253  cloneSmoother->IsSetup(this->IsSetup());
254  return cloneSmoother;
255 #else
257  "MueLu::Ifpack2Smoother::clone(): clone only available with Tpetra.");
258 #endif
259  }
260 
261 #ifdef HAVE_MUELU_EPETRA
262 
263 # if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
264  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
265  // Stub specialization for missing Epetra template args
266  template<>
267  class Ifpack2Smoother<double,int,int,Xpetra::EpetraNode> : public SmootherPrototype<double,int,int,Xpetra::EpetraNode> {
268  typedef double Scalar;
269  typedef int LocalOrdinal;
270  typedef int GlobalOrdinal;
272 #undef MUELU_AMESOS2SMOOTHER_SHORT
273 #include "MueLu_UseShortNames.hpp"
274 
275  public:
276 #ifndef _MSC_VER
277  // Avoid error C3772: invalid friend template declaration
278  template<class Scalar2, class LocalOrdinal2, class GlobalOrdinal2, class Node2>
279  friend class Ifpack2Smoother;
280 #endif
281 
282  Ifpack2Smoother(const std::string& type, const Teuchos::ParameterList& paramList = Teuchos::ParameterList(), const LocalOrdinal& overlap = 0) {
283  MUELU_TPETRA_ETI_EXCEPTION("Ifpack2Smoother<double,int,int,EpetraNode>","Ifpack2Smoother<double,int,int,EpetraNode>","int");
284  };
285 
286  virtual ~Ifpack2Smoother() { }
287 
288  void SetParameterList(const Teuchos::ParameterList& paramList) {}
289  void DeclareInput(Level &currentLevel) const {}
290  void Setup(Level &currentLevel) {}
291  void Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero = false) const {}
292  RCP<SmootherPrototype> Copy() const { return Teuchos::null;}
293 
294  template<typename Node2>
296  clone(const RCP<Node2>& node2, const Teuchos::RCP<const Matrix >& A_newnode) const { return Teuchos::null; }
297  std::string description() const { return std::string(""); }
298  void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const {}
299  private:
301  };
302 # endif
303 
304 #endif // HAVE_MUELU_EPETRA
305 
306 } // namespace MueLu
307 
308 #define MUELU_IFPACK2SMOOTHER_SHORT
309 #endif // HAVE_MUELU_TPETRA && HAVE_MUELU_IFPACK2
310 #endif // MUELU_IFPACK2SMOOTHER_DECL_HPP
Ifpack2Smoother(const std::string &type, const Teuchos::ParameterList &paramList=Teuchos::ParameterList(), const LocalOrdinal &overlap=0)
void SetupGeneric(Level &currentLevel)
RCP< SmootherPrototype > Copy() const
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
std::string description() const
Return a simple one-line description of this object.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply smoother.
friend class Ifpack2Smoother
Constructor.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< Matrix > A_
matrix, used in apply if solving residual equation
Base class for smoother prototypes.
void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
Namespace for MueLu classes and methods.
LO overlap_
overlap when using the smoother in additive Schwarz mode
void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
RCP< MueLu::Ifpack2Smoother< Scalar, LocalOrdinal, GlobalOrdinal, Node2 > > clone(const RCP< Node2 > &node2, const Teuchos::RCP< const Matrix > &A_newnode) const
std::string type_
ifpack2-specific key phrase that denote smoother type
void SetupSchwarz(Level &currentLevel)
void SetupLineSmoothing(Level &currentLevel)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
RCP< MueLu::Ifpack2Smoother< Scalar, LocalOrdinal, GlobalOrdinal, Node2 > > clone(const RCP< Node2 > &node2, const Teuchos::RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2 > > &A_newnode) const
Clone the smoother to a different node type.
void Setup(Level &currentLevel)
Set up the smoother.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
#define MUELU_TPETRA_ETI_EXCEPTION(cl, obj, go)
void DeclareInput(Level &currentLevel) const
Input.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
virtual ~Ifpack2Smoother()
Destructor.
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
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.
void SetupChebyshev(Level &currentLevel)
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
Class that encapsulates Ifpack2 smoothers.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
RCP< Ifpack2::Preconditioner< Scalar, LocalOrdinal, GlobalOrdinal, Node > > prec_
pointer to Ifpack2 preconditioner object