ug4
Loading...
Searching...
No Matches
core_smoothers.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-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 __H__UG__CPU_ALGEBRA__CORE_SMOOTHERS__
34#define __H__UG__CPU_ALGEBRA__CORE_SMOOTHERS__
36
37namespace ug
38{
39
42
45
93// gs_step_LL
105template<typename Matrix_type, typename Vector_type>
106void gs_step_LL(const Matrix_type &A, Vector_type &c, const Vector_type &d, const number relaxFactor)
107{
108 // gs LL has preconditioning matrix N = (D-L)^{-1}
109
110 typedef typename Matrix_type::value_type matrix_block;
111 typedef typename Matrix_type::const_row_iterator const_row_it;
112 typename Vector_type::value_type s;
113
114 const size_t sz = c.size();
115 for (size_t i = 0; i < sz; ++i)
116 {
117 s = d[i];
118
119 // loop over all lower left matrix entries.
120 // Note: Here the corrections c, which have already been computed in previous loops (wrt. i),
121 // are taken to compute the i-th correction. For example the correction of the second row
122 // is computed by s[2] = (d[2] - A[2][1] * c[1]); and c[2] = s[2]/A[2][2];
123 const const_row_it rowEnd = A.end_row(i);
124 const_row_it it = A.begin_row(i);
125 for(; it != rowEnd && it.index() < i; ++it)
126 // s -= it.value() * c[it.index()];
127 MatMultAdd(s, 1.0, s, -1.0, it.value(), c[it.index()]);
128
129 // c[i] = relaxFactor * s/A(i,i)
130 const matrix_block& A_ii = it.index() == i ? it.value() : matrix_block(0);
131 InverseMatMult(c[i], relaxFactor, A_ii, s);
132 }
133}
134
136// gs_step_UR
149template<typename Matrix_type, typename Vector_type>
150void gs_step_UR(const Matrix_type &A, Vector_type &c, const Vector_type &d, const number relaxFactor)
151{
152 // gs UR has preconditioning matrix N = (D-U)^{-1}
153
154 typename Vector_type::value_type s;
155
156 if(c.size() == 0) return;
157 size_t i = c.size()-1;
158 do
159 {
160 s = d[i];
161 typename Matrix_type::const_row_iterator diag = A.get_connection(i, i);
162
163 typename Matrix_type::const_row_iterator it = diag; ++it;
164 for(; it != A.end_row(i); ++it)
165 // s -= it.value() * x[it.index()];
166 MatMultAdd(s, 1.0, s, -1.0, it.value(), c[it.index()]);
167
168 // c[i] = relaxFactor * s/A(i,i)
169 InverseMatMult(c[i], relaxFactor, diag.value(), s);
170 } while(i-- != 0);
171
172}
173
175// sgs_step
188template<typename Matrix_type, typename Vector_type>
189void sgs_step(const Matrix_type &A, Vector_type &c, const Vector_type &d, const number relaxFactor)
190{
191 // sgs has preconditioning matrix N = (D-U)^{-1} D (D-L)^{-1}
192
193 // c1 = (D-L)^{-1} d
194 gs_step_LL(A, c, d, relaxFactor);
195
196 // c2 = D c1
197 typename Vector_type::value_type s;
198 for(size_t i = 0; i<c.size(); i++)
199 {
200 s=c[i];
201 MatMult(c[i], 1.0, A(i, i), s);
202 }
203
204 // c3 = (D-U)^{-1} c2
205 gs_step_UR(A, c, c, relaxFactor);
206}
207
209// diag_step
217template<typename Matrix_type, typename Vector_type>
218void diag_step(const Matrix_type& A, Vector_type& c, const Vector_type& d, number damp)
219{
220 //exit(3);
221 UG_ASSERT(c.size() == d.size() && c.size() == A.num_rows(), c << ", " << d <<
222 " and " << A << " need to have same size.");
223
224 for(size_t i=0; i < c.size(); i++)
225 // c[i] = damp * d[i]/A(i,i)
226 InverseMatMult(c[i], damp, A(i,i), d[i]);
227}
228
229
231}
232#endif // __H__UG__CPU_ALGEBRA__CORE_SMOOTHERS__
parameterString s
void gs_step_UR(const Matrix_type &A, Vector_type &c, const Vector_type &d, const number relaxFactor)
Performs a backward gauss-seidel-step, that is, solve on the upper right of A. Using gs_step_UR withi...
Definition core_smoothers.h:150
void gs_step_LL(const Matrix_type &A, Vector_type &c, const Vector_type &d, const number relaxFactor)
Gauss-Seidel-Iterations.
Definition core_smoothers.h:106
void diag_step(const Matrix_type &A, Vector_type &c, const Vector_type &d, number damp)
Performs a jacobi-step.
Definition core_smoothers.h:218
void sgs_step(const Matrix_type &A, Vector_type &c, const Vector_type &d, const number relaxFactor)
Performs a symmetric gauss-seidel step. Using sgs_step within a preconditioner-scheme leads to the fa...
Definition core_smoothers.h:189
#define UG_ASSERT(expr, msg)
Definition assert.h:70
double number
Definition types.h:124
the ug namespace
bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition operations_mat.h:68
bool MatMult(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1;
Definition operations_mat.h:59
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult