IFEM  90A354
ISTLSolParams.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
14 //==============================================================================
15 
16 #ifndef _ISTL_SOLPARAMS_H
17 #define _ISTL_SOLPARAMS_H
18 
19 #include "ISTLSupport.h"
20 #include <dune/common/version.hh>
21 #include <dune/istl/operators.hh>
22 #include <dune/istl/solvercategory.hh>
23 
24 #include <iostream>
25 #include <set>
26 #include <string>
27 #include <vector>
28 
29 
31 class LinSolParams;
32 class ProcessAdm;
33 
34 
35 namespace ISTL {
36 
49 class BlockPreconditioner : public Preconditioner {
50 public:
52  Dune::SolverCategory::Category category() const
53  { return Dune::SolverCategory::sequential; }
54 
59  BlockPreconditioner(const ISTL::Mat& A, const DomainDecomposition& dd_,
60  const std::string& schurType);
61 
64  {}
65 
67  void pre(ISTL::Vec& x, ISTL::Vec& b) override;
68 
72  void apply(ISTL::Vec& v, const ISTL::Vec& d) override;
73 
75  void post(ISTL::Vec& x) override;
76 
78  std::unique_ptr<ISTL::Preconditioner>& getBlockPre(size_t block)
79  {
80  return blockPre[block];
81  }
82 
84  ISTL::Mat& getBlock(size_t block)
85  {
86  return blocks[block];
87  }
88 
90  ISTL::Operator& getBlockOp(size_t block)
91  {
92  if (!blockOp[block])
93  blockOp[block].reset(new ISTL::Operator(blocks[block]));
94 
95  return *blockOp[block];
96  }
97 
98 protected:
100  static void extractBlock(ISTL::Mat& B, const ISTL::Mat& A,
101  const std::set<int>& eqs_row,
102  const std::set<int>& eqs_col,
103  const std::map<int,int>& eqs_col_g2l);
104 
106  static void subtractMatrices(ISTL::Mat& A,
107  const ISTL::Mat& B,
108  const ISTL::Mat& C);
109 
110  std::vector<std::unique_ptr<ISTL::Preconditioner>> blockPre;
111  std::vector<std::unique_ptr<ISTL::Operator>> blockOp;
112  std::vector<ISTL::Mat> blocks;
114 };
115 
116 #ifdef HAVE_MPI
138 template<class M, class X, class Y, class C>
139 class OverlappingSchwarzOperator : public Dune::AssembledLinearOperator<M,X,Y>
140 {
141 public:
146  using matrix_type = M;
151  using domain_type = X;
156  using range_type = Y;
158  using field_type = typename X::field_type;
163  using communication_type = C;
164 
166  Dune::SolverCategory::Category category() const
167  { return Dune::SolverCategory::sequential; }
168 
176  OverlappingSchwarzOperator (const matrix_type& A, const communication_type& com)
177  : _A_(A), communication(com)
178  {}
179 
181  void apply (const X& x, Y& y) const override
182  {
183 // Y y2(y.size());
184  _A_.umv(x,y);
185  communication.addOwnerOverlapToAll(y,y);
186  }
187 
189  void applyscaleadd (field_type alpha, const X& x, Y& y) const override
190  {
191  Y y2(y.size());
192  _A_.usmv(alpha, x, y2);
193  y = 0;
194  communication.addOwnerOverlapToAll(y2,y);
195  }
196 
198  const matrix_type& getmat () const override
199  {
200  return _A_;
201  }
202 
203 private:
204  const matrix_type& _A_;
205  const communication_type& communication;
206 };
207 
208 using ParMatrixAdapter =
209  OverlappingSchwarzOperator<ISTL::Mat,
210  ISTL::Vec,
211  ISTL::Vec,
212  Dune::OwnerOverlapCopyCommunication<int,int>>;
213 #endif
214 
215 }
216 
217 
225 {
226 public:
230  ISTLSolParams(const LinSolParams& spar, const ProcessAdm& padm) :
231  solParams(spar), adm(padm)
232  {}
233 
234 
238  std::tuple<std::unique_ptr<ISTL::InverseOperator>,
239  std::unique_ptr<ISTL::Preconditioner>,
240  std::unique_ptr<ISTL::Operator>>
241  setupPC(ISTL::Mat& A);
242 
244  const LinSolParams& get() const { return solParams; }
245 
246 protected:
252  ISTL::Preconditioner* setupPCInternal(ISTL::Mat& A,
253  ISTL::Operator& op,
254  size_t block,
255  std::unique_ptr<ISTL::InverseOperator>* solver);
256 
258  const ProcessAdm& adm;
259 };
260 
261 #endif
static SystemMatrix * M
Pointer to coefficient matrix B.
Definition: EigSolver.C:92
IFEM ISTL support.
Class containing domain decomposition related partitioning.
Definition: DomainDecomposition.h:38
Class for ISTL solver parameters.
Definition: ISTLSolParams.h:225
const LinSolParams & get() const
Obtain linear solver parameters.
Definition: ISTLSolParams.h:244
ISTL::Preconditioner * setupPCInternal(ISTL::Mat &A, ISTL::Operator &op, size_t block, std::unique_ptr< ISTL::InverseOperator > *solver)
Internal helper function for setting up a preconditioner.
Definition: ISTLSolParams.C:385
ISTLSolParams(const LinSolParams &spar, const ProcessAdm &padm)
Constructor.
Definition: ISTLSolParams.h:230
const LinSolParams & solParams
Reference to linear solver parameters.
Definition: ISTLSolParams.h:257
std::tuple< std::unique_ptr< ISTL::InverseOperator >, std::unique_ptr< ISTL::Preconditioner >, std::unique_ptr< ISTL::Operator > > setupPC(ISTL::Mat &A)
Setup solver and preconditioner.
Definition: ISTLSolParams.C:465
const ProcessAdm & adm
Reference to process administrator.
Definition: ISTLSolParams.h:258
Definition: ISTLSolParams.h:49
Dune::SolverCategory::Category category() const
The category the preconditioner is part of.
Definition: ISTLSolParams.h:52
std::vector< std::unique_ptr< ISTL::Operator > > blockOp
The matrix adaptors for the blocks.
Definition: ISTLSolParams.h:111
ISTL::Operator & getBlockOp(size_t block)
Obtain matrix adaptor for a block matrix.
Definition: ISTLSolParams.h:90
ISTL::Mat & getBlock(size_t block)
Obtain reference to a block matrix.
Definition: ISTLSolParams.h:84
void apply(ISTL::Vec &v, const ISTL::Vec &d) override
Applies the preconditioner.
Definition: ISTLSolParams.C:82
const DomainDecomposition & dd
Domain decomposition.
Definition: ISTLSolParams.h:113
static void subtractMatrices(ISTL::Mat &A, const ISTL::Mat &B, const ISTL::Mat &C)
Find A = B - C.
Definition: ISTLSolParams.C:168
std::vector< std::unique_ptr< ISTL::Preconditioner > > blockPre
The preconditioners.
Definition: ISTLSolParams.h:110
~BlockPreconditioner() override
Destructor.
Definition: ISTLSolParams.h:63
void pre(ISTL::Vec &x, ISTL::Vec &b) override
Preprocess preconditioner.
Definition: ISTLSolParams.C:58
std::vector< ISTL::Mat > blocks
Matrix blocks.
Definition: ISTLSolParams.h:112
void post(ISTL::Vec &x) override
Post-process function.
Definition: ISTLSolParams.C:106
BlockPreconditioner(const ISTL::Mat &A, const DomainDecomposition &dd_, const std::string &schurType)
Constructor.
Definition: ISTLSolParams.C:27
static void extractBlock(ISTL::Mat &B, const ISTL::Mat &A, const std::set< int > &eqs_row, const std::set< int > &eqs_col, const std::map< int, int > &eqs_col_g2l)
Build block from block equations.
Definition: ISTLSolParams.C:125
std::unique_ptr< ISTL::Preconditioner > & getBlockPre(size_t block)
Obtain reference to a block preconditioner.
Definition: ISTLSolParams.h:78
Class for linear solver parameters.
Definition: LinSolParams.h:67
Class for administration of MPI processes in IFEM library.
Definition: ProcessAdm.h:33
@ ISTL
Sparse matrices / Dune solver.
Definition: LinAlgenums.h:28