Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
47namespace ug{
48
49
50
51template<typename TAlgebra>
53{
54public:
55 typedef TAlgebra algebra_type;
56 typedef typename TAlgebra::vector_type vector_type;
57 typedef typename TAlgebra::matrix_type matrix_type;
58
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 {
89 }
90
91protected:
93
94};
95
96
97template<typename TAlgebra>
99{
100public:
101 typedef TAlgebra algebra_type;
102 typedef typename TAlgebra::vector_type vector_type;
103 typedef typename TAlgebra::matrix_type matrix_type;
104
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)
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 {
147 }
148
149protected:
152
153};
154
155
156template<typename TAlgebra>
158{
159public:
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 }
205protected:
207};
208
209
210
211template <typename TAlgebra, typename M, typename X, typename Y = X>
213{
214 typedef M matrix_type;
215
217public:
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
259template<typename TAlgebra>
261{
262public:
263 typedef TAlgebra algebra_type;
264 typedef typename TAlgebra::vector_type vector_type;
265 typedef typename TAlgebra::matrix_type matrix_type;
266
271
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 {
300 }
301
302protected:
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
virtual bool apply(Y &u, const X &f)=0
applies inverse operator, i.e. returns u = A^{-1} f
virtual std::string config_string() const
returns information about configuration parameters
Definition linear_operator_inverse.h:122
virtual bool apply_return_defect(Y &u, X &f)=0
applies inverse operator, i.e. returns u = A^{-1} f and returns defect d := f - A*u
virtual bool supports_parallel() const =0
returns if parallel solving is supported
virtual bool init(SmartPtr< ILinearOperator< Y, X > > L)
initializes for the inverse for a linear operator
Definition linear_operator_inverse.h:135
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
virtual M & get_matrix()
Definition matrix_operator.h:74
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