Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ilut_scalar.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-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__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ILUT_SCALAR__
34#define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ILUT_SCALAR__
35
38#ifdef UG_PARALLEL
40#endif
41#include "common/progress.h"
43
47#include "ilut.h"
48
49namespace ug{
50
51template <typename TAlgebra>
53{
54 public:
55 // Algebra type
56 typedef TAlgebra algebra_type;
57
58 // Vector type
59 typedef typename TAlgebra::vector_type vector_type;
60
61 // Matrix type
62 typedef typename TAlgebra::matrix_type matrix_type;
63
66
67 private:
68 typedef typename matrix_type::value_type block_type;
70
71 public:
72 // Constructor
73 ILUTScalarPreconditioner(double eps=1e-6) :
74 m_eps(eps), m_info(false), m_show_progress(true), m_bSort(true)
75 {};
76
79 : base_type(parent)
80 {
81 m_eps = parent.m_eps;
82 set_info(parent.m_info);
84 set_sort(parent.m_bSort);
85 }
86
92
93 // Destructor
95 {
96 };
97
99 virtual bool supports_parallel() const {return true;}
100
103 {
104 m_eps = thresh;
105 }
106
108 void set_info(bool info)
109 {
110 m_info = info;
111 }
112
114 void set_show_progress(bool b)
115 {
116 m_show_progress = b;
117 }
118
119 void set_sort(bool b)
120 {
121 m_bSort = b;
122 }
123
124 public:
125 void preprocess(const matrix_type &M)
126 {
127#ifdef UG_PARALLEL
128 matrix_type A;
129 A = M;
130
132
133 // set zero on slaves
134 std::vector<IndexLayout::Element> vIndex;
135 CollectUniqueElements(vIndex, M.layouts()->slave());
136 SetDirichletRow(A, vIndex);
137#else
138 const matrix_type &A = M;
139#endif
140
141 STATIC_ASSERT(matrix_type::rows_sorted, Matrix_has_to_have_sorted_rows);
142
144 ilut->set_info(m_info);
145 ilut->set_show_progress(m_show_progress);
146 ilut->set_sort(m_bSort);
147
149 CPUAlgebra::matrix_type &mat = mo->get_matrix();
150
151 #ifdef UG_PARALLEL
154 #endif
155
157
159 convCheck->set_maximum_steps(100);
160 convCheck->set_minimum_defect(1e-50);
161 convCheck->set_reduction(1e-20);
162 convCheck->set_verbose(false);
163
164 linearSolver.set_preconditioner(ilut);
165 linearSolver.set_convergence_check(convCheck);
166 linearSolver.init(mo);
167 }
168 protected:
169 // Name of preconditioner
170 virtual const char* name() const {return "ILUTScalar";}
171
172
173 // Preprocess routine
175 {
176 matrix_type &A = *pOp;
177 preprocess(A);
178
179 return true;
180 }
181
183 {
184 for(size_t i=0, k=0; i<v.size(); i++)
185 {
186 for(size_t j=0; j<GetSize(v[i]); j++)
187 v_scalar[k++] = BlockRef(v[i],j);
188 }
189 }
190
192 {
193 for(size_t i=0, k=0; i<v.size(); i++)
194 {
195 for(size_t j=0; j<GetSize(v[i]); j++)
196 BlockRef(v[i],j) = v_scalar[k++];
197 }
198 }
199
200 // Stepping routine
202 {
203#ifdef UG_PARALLEL
204 SmartPtr<vector_type> spDtmp = d.clone();
205 spDtmp->change_storage_type(PST_UNIQUE);
206 bool b = apply_double(c, *spDtmp);
207
208 c.set_storage_type(PST_ADDITIVE);
209 c.change_storage_type(PST_CONSISTENT);
210 return b;
211#else
212 return apply_double(c, d);
213#endif
214 return true;
215 }
216
218 {
221
222#ifdef UG_PARALLEL
227#endif
228 get_vector(m_d, d);
229 m_c.set(0.0);
230
231 //ApplyLinearSolver(mo, m_u, m_b, linearSolver);
232 ilut->apply(m_c, m_d);
233 //ilut->apply(m_c, m_d);
234
235 set_vector(m_c, c);
236 return true;
237 }
238
239
240
241 public:
242 bool solve(vector_type &c, const vector_type &d)
243 {
246
247#ifdef UG_PARALLEL
252#endif
253 get_vector(m_d, d);
254 m_c.set(0.0);
255
256 //ApplyLinearSolver(mo, m_u, m_b, linearSolver);
257 linearSolver.apply_return_defect(m_c, m_d);
258 //ilut->apply(m_c, m_d);
259
260 set_vector(m_c, c);
261 return true;
262 }
263
264 public:
265 virtual std::string config_string() const
266 {
267 std::stringstream ss ; ss << "ILUTScalar(threshold = " << m_eps << ", sort = " << (m_bSort?"true":"false") << ")";
268 if(m_eps == 0.0) ss << " = Sparse LU";
269 return ss.str();
270 }
271
272 protected:
273 // Postprocess routine
274 virtual bool postprocess() {return true;}
275
276protected:
281 double m_eps;
283 size_t m_size;
284};
285
286} // end namespace ug
287
288#endif
Definition smart_pointer.h:108
Definition ilut.h:25
Definition ilut_scalar.h:53
virtual std::string config_string() const
Definition ilut_scalar.h:265
void set_sort(bool b)
Definition ilut_scalar.h:119
bool solve(vector_type &c, const vector_type &d)
Definition ilut_scalar.h:242
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition ilut_scalar.h:99
void set_info(bool info)
sets storage information output to true or false
Definition ilut_scalar.h:108
void set_vector(CPUAlgebra::vector_type &v_scalar, vector_type &v)
Definition ilut_scalar.h:191
CPUAlgebra::vector_type m_d
Definition ilut_scalar.h:280
SmartPtr< MatrixOperator< CPUAlgebra::matrix_type, CPUAlgebra::vector_type > > mo
Definition ilut_scalar.h:278
bool m_bSort
Definition ilut_scalar.h:282
SmartPtr< ILUTPreconditioner< CPUAlgebra > > ilut
Definition ilut_scalar.h:277
size_t m_size
Definition ilut_scalar.h:283
TAlgebra algebra_type
Definition ilut_scalar.h:56
void set_show_progress(bool b)
sets the indication of the progress to true or false
Definition ilut_scalar.h:114
virtual bool postprocess()
cleans the operator
Definition ilut_scalar.h:274
double m_eps
Definition ilut_scalar.h:281
IPreconditioner< TAlgebra >::matrix_operator_type matrix_operator_type
Matrix Operator type.
Definition ilut_scalar.h:65
virtual bool preprocess(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
initializes the preconditioner
Definition ilut_scalar.h:174
LinearSolver< CPUAlgebra::vector_type > linearSolver
Definition ilut_scalar.h:279
bool apply_double(vector_type &c, const vector_type &d)
Definition ilut_scalar.h:217
virtual ~ILUTScalarPreconditioner()
Definition ilut_scalar.h:94
virtual bool step(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp, vector_type &c, const vector_type &d)
computes a new correction c = B*d
Definition ilut_scalar.h:201
TAlgebra::vector_type vector_type
Definition ilut_scalar.h:59
virtual SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition ilut_scalar.h:88
bool m_show_progress
Definition ilut_scalar.h:282
void preprocess(const matrix_type &M)
Definition ilut_scalar.h:125
bool m_info
Definition ilut_scalar.h:282
TAlgebra::matrix_type matrix_type
Definition ilut_scalar.h:62
void get_vector(CPUAlgebra::vector_type &v_scalar, const vector_type &v)
Definition ilut_scalar.h:182
ILUTScalarPreconditioner(const ILUTScalarPreconditioner< TAlgebra > &parent)
clone constructor
Definition ilut_scalar.h:78
matrix_type::value_type block_type
Definition ilut_scalar.h:68
void set_threshold(number thresh)
sets threshold for incomplete LU factorisation (added 01122010ih)
Definition ilut_scalar.h:102
IPreconditioner< TAlgebra > base_type
Definition ilut_scalar.h:69
virtual const char * name() const
returns the name of iterator
Definition ilut_scalar.h:170
ILUTScalarPreconditioner(double eps=1e-6)
Definition ilut_scalar.h:73
CPUAlgebra::vector_type m_c
Definition ilut_scalar.h:280
describes a linear iterator that is based on a matrix operator
Definition preconditioner.h:103
linear solver using abstract preconditioner interface
Definition linear_solver.h:57
Wrapper for sequential matrices to handle them in parallel.
Definition parallel_matrix.h:65
void set_storage_type(uint type)
sets the storage type
Definition parallel_matrix.h:101
void set_layouts(ConstSmartPtr< AlgebraLayouts > layouts)
sets the algebra layouts
Definition parallel_matrix.h:97
void set(number w, ParallelStorageType type)
set all entries to value and the storage type
Definition parallel_vector_impl.h:223
void set_storage_type(uint type)
sets the storage type
Definition parallel_vector.h:104
void set_layouts(ConstSmartPtr< AlgebraLayouts > layouts)
sets the algebra layouts
Definition parallel_vector.h:100
Definition convergence_check.h:179
void resize(size_t newSize, bool bCopyValues=true)
Definition vector.h:109
void MatAddSlaveRowsToMasterRowOverlap0(TMatrix &mat)
Generates a set of unique global algebra ids.
Definition parallelization_util.h:106
@ PST_CONSISTENT
Definition parallel_storage_type.h:68
@ PST_UNIQUE
Definition parallel_storage_type.h:70
@ PST_ADDITIVE
Definition parallel_storage_type.h:69
size_t GetDoubleSparseFromBlockSparse(TDoubleSparse &A, const TSparseMatrix &S)
Definition sparsematrix_util.h:1217
void SetDirichletRow(TSparseMatrix &A, size_t i, size_t alpha)
Definition sparsematrix_util.h:796
#define STATIC_ASSERT(expr, msg)
Definition common.h:61
double number
Definition types.h:124
the ug namespace
double & BlockRef(T &vec, size_t i)
Definition blocks.h:66
SmartPtr< AlgebraLayouts > CreateLocalAlgebraLayouts()
Definition parallelization_util.cpp:936
size_t GetSize(const T &t)
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836