VertexCFD  0.0-dev
VertexCFD_LinearSolvers_Preconditioner.hpp
1 #ifndef VERTEXCFD_LINEARSOLVERS_PRECONDITIONER_HPP
2 #define VERTEXCFD_LINEARSOLVERS_PRECONDITIONER_HPP
3 
4 #include "VertexCFD_LinearSolvers_LocalDirectSolver.hpp"
5 
6 #include <Ifpack2_Details_CanChangeMatrix.hpp>
7 #include <Ifpack2_Preconditioner.hpp>
8 #include <Teuchos_FancyOStream.hpp>
9 #include <Tpetra_Map.hpp>
10 #include <Tpetra_MultiVector.hpp>
11 #include <Tpetra_RowMatrix.hpp>
12 
13 #include <memory>
14 
15 namespace VertexCFD
16 {
17 namespace LinearSolvers
18 {
19 //---------------------------------------------------------------------------//
20 /*
21  * This class is the Trilinos (Ifpack2) interface for local domain
22  * preconditioners as part of an additive Schwarz type scheme. It is assumed
23  * that the matrix provided via the setMatrix method will only contain the
24  * _local_ matrix elements with no off-processor components.
25  * It implements the Ifpack2::Preconditioner interface, which allows it to
26  * be used as the local solver within an Ifpack2::AdditiveSchwarz instance.
27  * This class is only an interface -- the local solve itself is handled by
28  * a subclass of LocalDirectSolver and built by the LocalSolverFactory. This
29  * design prevents every local solver class (e.g., CuSOLVER, SuperLU) from
30  * having to re-implement the full API inherited from Ifpack2::Preconditioner.
31  */
32 //---------------------------------------------------------------------------//
34  : public Ifpack2::Preconditioner<>,
35  public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<>>
36 {
37  private:
38  using MV = Tpetra::MultiVector<>;
39 
40  // Local matrix
41  Teuchos::RCP<const Tpetra::RowMatrix<>> _A;
42 
43  // Implementation of local solve
44  std::shared_ptr<LocalDirectSolver> _local_solver;
45 
46  // Tracking of calls and time to init, compute, apply
47  bool _initialized;
48  bool _computed;
49  int _num_initialize;
50  int _num_compute;
51  mutable int _num_apply; // Must be updated from within const "apply"
52  double _init_time;
53  double _compute_time;
54  mutable double _apply_time;
55 
56  // Timer labels
57  const std::string _set_label = "VertexCFD::Preconditioner::setMatrix";
58  const std::string _init_label = "VertexCFD::Preconditioner::initialize";
59  const std::string _compute_label = "VertexCFD::Preconditioner::compute";
60  const std::string _apply_label = "VertexCFD::Preconditioner::apply";
61 
62  public:
63  // Constructor
65 
66  // Inherited API from Ifpack2::CanChangeMatrix
67  void setMatrix(const Teuchos::RCP<const Tpetra::RowMatrix<>>& A) override;
68 
69  // Inherited API from Ifpack2::Preconditioner
70  Teuchos::RCP<const Tpetra::RowMatrix<>> getMatrix() const override
71  {
72  return _A;
73  }
74  bool isInitialized() const override { return _initialized; }
75  bool isComputed() const override { return _computed; }
76  int getNumInitialize() const override { return _num_initialize; }
77  int getNumCompute() const override { return _num_compute; }
78  int getNumApply() const override { return _num_apply; }
79  double getInitializeTime() const override { return _init_time; }
80  double getComputeTime() const override { return _compute_time; }
81  double getApplyTime() const override { return _apply_time; }
82  Teuchos::RCP<const Tpetra::Map<>> getDomainMap() const override
83  {
84  return _A->getDomainMap();
85  }
86  Teuchos::RCP<const Tpetra::Map<>> getRangeMap() const override
87  {
88  return _A->getRangeMap();
89  }
90  void setParameters(const Teuchos::ParameterList& pl) override;
91  void initialize() override;
92  void compute() override;
93  void apply(const Tpetra::MultiVector<>& x,
94  Tpetra::MultiVector<>& y,
95  Teuchos::ETransp mode,
96  double alpha,
97  double beta) const override;
98 };
99 
100 //---------------------------------------------------------------------------//
101 
102 } // namespace LinearSolvers
103 } // namespace VertexCFD
104 
105 #endif // VERTEXCFD_LINEARSOLVERS_PRECONDITIONER_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23
VertexCFD::LinearSolvers::Preconditioner
Definition: VertexCFD_LinearSolvers_Preconditioner.hpp:36