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 
49 #include <Teuchos_ParameterList.hpp>
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>
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  {
95 #undef MUELU_IFPACK2SMOOTHER_SHORT
96 #include "MueLu_UseShortNames.hpp"
97 
98  public:
99 
101 
102  //TODO: update doc for Ifpack2. Right now, it's a copy of the doc of IfpackSmoother
138 #ifndef _MSC_VER
139  // Avoid error C3772: invalid friend template declaration
140  template<class Scalar2, class LocalOrdinal2, class GlobalOrdinal2, class Node2>
141  friend class Ifpack2Smoother;
142 #endif
143 
144  Ifpack2Smoother(const std::string& type, const Teuchos::ParameterList& paramList = Teuchos::ParameterList(), const LO& overlap = 0); //TODO: empty paramList valid for Ifpack??
145 
147  virtual ~Ifpack2Smoother() { }
148 
150 
151  void SetParameterList(const Teuchos::ParameterList& paramList);
152 
154 
155 
156  void DeclareInput(Level &currentLevel) const;
157 
159 
161 
162 
170  void Setup(Level &currentLevel);
171 
180  void Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero = false) const;
181 
183 
185 
186 
187  RCP<SmootherPrototype> Copy() const;
188 
190 
192  template<typename Node2>
193  RCP<MueLu::Ifpack2Smoother<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >
194  clone(const RCP<Node2>& node2, const Teuchos::RCP<const Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >& A_newnode) const;
195 
197 
198 
200  std::string description() const;
201 
203  //using MueLu::Describable::describe; // overloading, not hiding
204  //void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const
205  void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel = Default) const;
206 
208 
209  private:
210  void SetPrecParameters(const Teuchos::ParameterList& list = Teuchos::ParameterList()) const;
211 
212  private:
213 
215  std::string type_;
216 
219 
221  RCP<Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> > prec_;
222 
224  RCP<Matrix> A_;
225 
226  }; // class Ifpack2Smoother
227 
228  template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
229  template<typename Node2>
230  RCP<MueLu::Ifpack2Smoother<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >
231  Ifpack2Smoother<Scalar,LocalOrdinal,GlobalOrdinal,Node>::clone(const RCP<Node2>& node2, const RCP<const Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> >& A_newnode) const {
232 #ifdef HAVE_XPETRA_TPETRA
233  const ParameterList& paramList = this->GetParameterList();
234  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix1;
235  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2> Matrix2;
236  RCP<Ifpack2Smoother<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > cloneSmoother =
238 
239  //Get Tpetra::CrsMatrix from Xpetra::Matrix
240  RCP<const Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node2> > crsOp =
241  rcp_dynamic_cast<const Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >(A_newnode);
242  const RCP<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >& tmp =
243  rcp_dynamic_cast<const Xpetra::TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node2> >(crsOp->getCrsMatrix());
244 
245  Ifpack2::Factory factory;
246  cloneSmoother->prec_ = factory.clone<Matrix1, Matrix2>(prec_, tmp->getTpetra_CrsMatrix(), paramList);
247  cloneSmoother->type_ = type_;
248  cloneSmoother->SetParameterList(paramList);
249  cloneSmoother->IsSetup(this->IsSetup());
250  return cloneSmoother;
251 #else
252  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError,
253  "MueLu::Ifpack2Smoother::clone(): clone only available with Tpetra.");
254 #endif
255  }
256 
257 
258 } // namespace MueLu
259 
260 #define MUELU_IFPACK2SMOOTHER_SHORT
261 #endif // HAVE_MUELU_TPETRA && HAVE_MUELU_IFPACK2
262 #endif // MUELU_IFPACK2SMOOTHER_DECL_HPP
void DeclareInput(Level &currentLevel) const
Input.
friend class Ifpack2Smoother
Constructor.
RCP< Matrix > A_
matrix, used in apply if solving residual equation
Base class for smoother prototypes.
void SetParameterList(const Teuchos::ParameterList &paramList)
Namespace for MueLu classes and methods.
virtual const Teuchos::ParameterList & GetParameterList() const
static Teuchos::RCP< Preconditioner< typename OutputMatrixType::scalar_type, typename OutputMatrixType::local_ordinal_type, typename OutputMatrixType::global_ordinal_type, typename OutputMatrixType::node_type > > clone(const Teuchos::RCP< Preconditioner< typename InputMatrixType::scalar_type, typename InputMatrixType::local_ordinal_type, typename InputMatrixType::global_ordinal_type, typename InputMatrixType::node_type > > &prec, const Teuchos::RCP< const OutputMatrixType > &matrix, const Teuchos::ParameterList &params=Teuchos::ParameterList())
LO overlap_
overlap when using the smoother in additive Schwarz mode
std::string type_
ifpack2-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.
RCP< SmootherPrototype > Copy() const
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
void Setup(Level &currentLevel)
Set up the smoother.
std::string description() const
Return a simple one-line description of this object.
bool IsSetup() const
Get the state of a smoother prototype.
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
virtual ~Ifpack2Smoother()
Destructor.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
Exception throws to report errors in the internal logical of the program.
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.
Class that encapsulates Ifpack2 smoothers.
RCP< Ifpack2::Preconditioner< Scalar, LocalOrdinal, GlobalOrdinal, Node > > prec_
pointer to Ifpack2 preconditioner object