ug4
schur_complement_inverse.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015: G-CSC, Goethe University Frankfurt
3  * Author: Martin Rupp
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef SCHUR_COMPLEMENT_INVERSE_H_
34 #define SCHUR_COMPLEMENT_INVERSE_H_
35 
36 #ifdef UG_PARALLEL
37 
38 
39 
41 
42 
43 #include "schur.h"
45 
46 
47 namespace ug{
48 
49 
50 
51 template<typename TAlgebra>
53 {
54 public:
55  typedef TAlgebra algebra_type;
56  typedef typename TAlgebra::vector_type vector_type;
57  typedef typename TAlgebra::matrix_type matrix_type;
58 
60  {
61  m_linOpInv = linOpInv;
62  }
63 
65  {
66  op->set_skeleton_debug(m_linOpInv);
67  return m_linOpInv->init(op);
68  }
69 
70  virtual bool apply(vector_type& u, const vector_type& f)
71  {
72  return m_linOpInv->apply(u, f);
73  }
74 
76  {
77  return m_linOpInv->apply_return_defect(u, f);
78  }
79 
80  virtual std::string config_string() const
81  {
82  std::stringstream ss; ss << "SchurInverseWithOperator\n";
83  ss << " Solver: " << ConfigShift(m_linOpInv->config_string()) << "\n";
84  return ss.str();
85  }
86  virtual bool supports_parallel() const
87  {
88  return m_linOpInv->supports_parallel();
89  }
90 
91 protected:
93 
94 };
95 
96 
97 template<typename TAlgebra>
99 {
100 public:
101  typedef TAlgebra algebra_type;
102  typedef typename TAlgebra::vector_type vector_type;
103  typedef typename TAlgebra::matrix_type matrix_type;
104 
106  {
107  m_linOpInv = linOpInv;
108  }
109 
111  {
112  PROFILE_BEGIN(SchurInverseWithFullMatrix_init)
113 
115 
116  PROFILE_BEGIN(SchurInverseWithFullMatrix_compute_matrix)
117  op->compute_matrix(m_exactSchurOp->get_matrix());
118  PROFILE_END();
119 
120  op->set_skeleton_debug(m_linOpInv);
121 
122  PROFILE_BEGIN(SchurInverseWithFullMatrix_init_solver)
123  return m_linOpInv->init(m_exactSchurOp);
124  }
125 
126  virtual bool apply(vector_type& u, const vector_type& f)
127  {
128  PROFILE_BEGIN(SchurInverseWithFullMatrix_apply)
129  return m_linOpInv->apply(u, f);
130  }
131 
133  {
134  PROFILE_BEGIN(SchurInverseWithFullMatrix_apply_return_defect)
135  return m_linOpInv->apply_return_defect(u, f);
136  }
137 
138  virtual std::string config_string() const
139  {
140  std::stringstream ss; ss << "SchurInverseWithFullMatrix\n";
141  ss << " Solver: " << ConfigShift(m_linOpInv->config_string()) << "\n";
142  return ss.str();
143  }
144  virtual bool supports_parallel() const
145  {
146  return m_linOpInv->supports_parallel();
147  }
148 
149 protected:
152 
153 };
154 
155 
156 template<typename TAlgebra>
158 {
159 public:
160  typedef TAlgebra algebra_type;
161  typedef typename TAlgebra::vector_type vector_type;
162  typedef typename TAlgebra::matrix_type matrix_type;
163 
165  {
166  UG_COND_THROW(!linSolver.valid(), "?");
167  m_linSolver = linSolver;
168  }
169 
171  {
172  PROFILE_BEGIN(SchurInverseWithAGammaGamma_init)
173 
174  op->set_skeleton_debug(m_linSolver);
176  m_linSolver->preconditioner().template cast_dynamic< IPreconditioner<TAlgebra> > ();
177  UG_COND_THROW(!precond.valid(), "?");
178  precond->set_approximation(op->sub_operator(SD_SKELETON, SD_SKELETON));
179 // precond->set_damp(0.5);
180 // m_linSolver->set_preconditioner(precond);
181  return m_linSolver->init(op);
182  // do init of linsolver before or after set approximation?
183  }
184  virtual bool apply(vector_type& u, const vector_type& f)
185  {
186  PROFILE_BEGIN(SchurInverseWithAGammaGamma_apply)
187  return m_linSolver->apply(u, f);
188  }
189 
191  {
192  PROFILE_BEGIN(SchurInverseWithAGammaGamma_apply_return_defect)
193  return m_linSolver->apply_return_defect(u, f);
194  }
195  virtual std::string config_string() const
196  {
197  std::stringstream ss; ss << "SchurInverseWithAGammaGamma\n";
198  ss << " Solver: " << ConfigShift(m_linSolver->config_string()) << "\n";
199  return ss.str();
200  }
201  virtual bool supports_parallel() const
202  {
203  return m_linSolver->supports_parallel();
204  }
205 protected:
207 };
208 
209 
210 
211 template <typename TAlgebra, typename M, typename X, typename Y = X>
213 {
214  typedef M matrix_type;
215 
217 public:
218  bool invalid;
220  {
221  set_op(op);
222  }
223 
225  {
226  m_op = op;
227  invalid = true;
228  }
229 
230 // Init Operator J(u)
231  virtual void init(const X& u) { init(); }
232 
233 // Init Operator L
234  virtual void init()
235  {
236  if(invalid)
237  {
238  m_op->compute_matrix(get_matrix());
239  invalid = false;
240  }
241  }
242 
243  virtual void calculate_matrix()
244  {
245  init();
246  }
247 
248 // Apply Operator f = L*u (e.g. d = J(u)*c in iterative scheme)
249  virtual void apply(Y& f, const X& u) {m_op->apply(f,u);}
250 
251 // Apply Operator, i.e. f = f - L*u;
252  virtual void apply_sub(Y& f, const X& u) {m_op->apply_sub(f,u);}
253 
254 // Access to matrix
255  virtual M& get_matrix() {return *this;};
256 };
257 
258 // not completely working at the moment
259 template<typename TAlgebra>
261 {
262 public:
263  typedef TAlgebra algebra_type;
264  typedef typename TAlgebra::vector_type vector_type;
265  typedef typename TAlgebra::matrix_type matrix_type;
266 
268  {
269  m_linOpInv = linOpInv;
270  }
271 
273  {
274  if(m_exactSchurOp.valid() == false)
276  else
277  m_exactSchurOp->set_op(op);
278  return m_linOpInv->init(m_exactSchurOp);
279  }
280 
281  virtual bool apply(vector_type& u, const vector_type& f)
282  {
283  return m_linOpInv->apply(u, f);
284  }
285 
287  {
288  return m_linOpInv->apply_return_defect(u, f);
289  }
290 
291  virtual std::string config_string() const
292  {
293  std::stringstream ss; ss << "SchurInverseWithAutoFullMatrix\n";
294  ss << " Solver: " << ConfigShift(m_linOpInv->config_string()) << "\n";
295  return ss.str();
296  }
297  virtual bool supports_parallel() const
298  {
299  return m_linOpInv->supports_parallel();
300  }
301 
302 protected:
305 
306 };
307 
308 }
309 
310 #endif /* UG_PARALLEL */
311 #endif /* SCHUR_COMPLEMENT_INVERSE_H_ */
Definition: smart_pointer.h:108
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:206
describes an inverse linear mapping X->Y
Definition: linear_operator_inverse.h:80
describes an inverse linear mapping X->X
Definition: preconditioned_linear_operator_inverse.h:63
Definition: schur_complement_inverse_interface.h:46
Definition: matrix_operator.h:49
Definition: schur_complement_inverse.h:213
void set_op(SmartPtr< SchurComplementOperator< TAlgebra > > op)
Definition: schur_complement_inverse.h:224
virtual M & get_matrix()
Definition: schur_complement_inverse.h:255
virtual void calculate_matrix()
Definition: schur_complement_inverse.h:243
SchurComplementMatrixOperator(SmartPtr< SchurComplementOperator< TAlgebra > > op)
Definition: schur_complement_inverse.h:219
SmartPtr< SchurComplementOperator< TAlgebra > > m_op
Definition: schur_complement_inverse.h:216
virtual void apply_sub(Y &f, const X &u)
Definition: schur_complement_inverse.h:252
virtual void init()
init operator
Definition: schur_complement_inverse.h:234
virtual void apply(Y &f, const X &u)
Definition: schur_complement_inverse.h:249
bool invalid
Definition: schur_complement_inverse.h:218
M matrix_type
Definition: schur_complement_inverse.h:214
virtual void init(const X &u)
init operator depending on a function u
Definition: schur_complement_inverse.h:231
Definition: schur_complement_operator.h:69
Definition: schur_complement_inverse.h:158
SmartPtr< IPreconditionedLinearOperatorInverse< vector_type > > m_linSolver
Definition: schur_complement_inverse.h:206
virtual bool supports_parallel() const
Definition: schur_complement_inverse.h:201
TAlgebra::vector_type vector_type
Definition: schur_complement_inverse.h:161
SchurInverseWithAGammaGamma(SmartPtr< IPreconditionedLinearOperatorInverse< vector_type > > linSolver)
Definition: schur_complement_inverse.h:164
TAlgebra algebra_type
Definition: schur_complement_inverse.h:160
virtual bool apply(vector_type &u, const vector_type &f)
Definition: schur_complement_inverse.h:184
virtual bool init(SmartPtr< SchurComplementOperator< TAlgebra > > op)
Definition: schur_complement_inverse.h:170
virtual std::string config_string() const
Definition: schur_complement_inverse.h:195
virtual bool apply_return_defect(vector_type &u, vector_type &f)
Definition: schur_complement_inverse.h:190
TAlgebra::matrix_type matrix_type
Definition: schur_complement_inverse.h:162
Definition: schur_complement_inverse.h:261
virtual std::string config_string() const
Definition: schur_complement_inverse.h:291
TAlgebra::vector_type vector_type
Definition: schur_complement_inverse.h:264
SmartPtr< SchurComplementMatrixOperator< TAlgebra, matrix_type, vector_type > > m_exactSchurOp
Definition: schur_complement_inverse.h:303
SchurInverseWithAutoFullMatrix(SmartPtr< ILinearOperatorInverse< vector_type > > linOpInv)
Definition: schur_complement_inverse.h:267
SmartPtr< ILinearOperatorInverse< vector_type > > m_linOpInv
Definition: schur_complement_inverse.h:304
virtual bool init(SmartPtr< SchurComplementOperator< TAlgebra > > op)
Definition: schur_complement_inverse.h:272
virtual bool apply_return_defect(vector_type &u, vector_type &f)
Definition: schur_complement_inverse.h:286
TAlgebra::matrix_type matrix_type
Definition: schur_complement_inverse.h:265
virtual bool supports_parallel() const
Definition: schur_complement_inverse.h:297
virtual bool apply(vector_type &u, const vector_type &f)
Definition: schur_complement_inverse.h:281
TAlgebra algebra_type
Definition: schur_complement_inverse.h:263
Definition: schur_complement_inverse.h:99
TAlgebra::matrix_type matrix_type
Definition: schur_complement_inverse.h:103
SchurInverseWithFullMatrix(SmartPtr< ILinearOperatorInverse< vector_type > > linOpInv)
Definition: schur_complement_inverse.h:105
virtual bool apply_return_defect(vector_type &u, vector_type &f)
Definition: schur_complement_inverse.h:132
SmartPtr< MatrixOperator< matrix_type, vector_type > > m_exactSchurOp
Definition: schur_complement_inverse.h:150
SmartPtr< ILinearOperatorInverse< vector_type > > m_linOpInv
Definition: schur_complement_inverse.h:151
virtual bool init(SmartPtr< SchurComplementOperator< TAlgebra > > op)
Definition: schur_complement_inverse.h:110
virtual bool supports_parallel() const
Definition: schur_complement_inverse.h:144
TAlgebra::vector_type vector_type
Definition: schur_complement_inverse.h:102
virtual bool apply(vector_type &u, const vector_type &f)
Definition: schur_complement_inverse.h:126
virtual std::string config_string() const
Definition: schur_complement_inverse.h:138
TAlgebra algebra_type
Definition: schur_complement_inverse.h:101
Definition: schur_complement_inverse.h:53
SmartPtr< ILinearOperatorInverse< vector_type > > m_linOpInv
Definition: schur_complement_inverse.h:92
virtual bool supports_parallel() const
Definition: schur_complement_inverse.h:86
virtual bool apply_return_defect(vector_type &u, vector_type &f)
Definition: schur_complement_inverse.h:75
virtual std::string config_string() const
Definition: schur_complement_inverse.h:80
TAlgebra algebra_type
Definition: schur_complement_inverse.h:55
SchurInverseWithOperator(SmartPtr< ILinearOperatorInverse< vector_type > > linOpInv)
Definition: schur_complement_inverse.h:59
virtual bool init(SmartPtr< SchurComplementOperator< TAlgebra > > op)
Definition: schur_complement_inverse.h:64
virtual bool apply(vector_type &u, const vector_type &f)
Definition: schur_complement_inverse.h:70
TAlgebra::matrix_type matrix_type
Definition: schur_complement_inverse.h:57
TAlgebra::vector_type vector_type
Definition: schur_complement_inverse.h:56
Definition: auto_linear_solver.h:49
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
the ug namespace
string ConfigShift(string s)
Definition: string_util.cpp:457
@ SD_SKELETON
Definition: schur.h:63
#define PROFILE_BEGIN(name)
Definition: profiler.h:254
#define PROFILE_END()
Definition: profiler.h:256
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836