33 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__PILUT__
34 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__PILUT__
45 template <
typename TAlgebra>
78 newInst->set_damp(this->
damping());
108 virtual const char*
name()
const {
return "PILUTPreconditioner";}
114 mat.set_as_copy_of(*pOp);
115 STATIC_ASSERT(matrix_type::rows_sorted, Matrix_has_to_have_sorted_rows);
119 typedef typename matrix_type::connection connection;
120 m_L.resize_and_clear(A->num_rows(), A->num_cols());
121 m_U.resize_and_clear(A->num_rows(), A->num_cols());
126 std::vector<typename matrix_type::connection> con;
131 for(
typename matrix_type::row_iterator i_it = A->begin_row(0); i_it != A->end_row(0); ++i_it)
132 con.push_back(connection(i_it.index(), i_it.value()));
133 m_U.set_matrix_row(0, &con[0], con.size());
135 size_t totalentries=0;
140 "Using ILUT(" <<
m_eps <<
") on " << A->num_rows() <<
" x " << A->num_rows() <<
" matrix...");
143 for(
size_t i=1; i<A->num_rows()/2; i++)
151 for(
typename matrix_type::row_iterator i_it = A->begin_row(i); i_it != A->end_row(i); ++i_it)
153 con.push_back(connection(i_it.index(), i_it.value()));
160 totalentries+=con.size();
161 if(maxentries < con.size()) maxentries = con.size();
163 for(
size_t i_it=0; i_it<con.size(); i_it++)
165 if(con[i_it].iIndex < i)
m_L(i, con[i_it].iIndex) = con[i_it].dValue;
166 else m_U(i, con[i_it].iIndex) = con[i_it].dValue;
171 for(
size_t i=A->num_rows()/2; i<A->
num_rows(); i++)
178 for(
typename matrix_type::row_iterator i_it = A->begin_row(i); i_it != A->end_row(i); ++i_it)
180 con.push_back(connection(i_it.index(), i_it.value()));
187 totalentries+=con.size();
188 if(maxentries < con.size()) maxentries = con.size();
190 A->set_matrix_row(i, &con[0], con.size());
194 for(
typename matrix_type::row_iterator i_it = A->begin_row(A->num_rows()/2); i_it != A->end_row(A->num_rows()/2); ++i_it)
196 if(i_it.index() <= A->num_rows()/2)
198 con.push_back(connection(i_it.index(), i_it.value()));
200 m_L.set_matrix_row(A->num_rows()/2, &con[0], u_part);
201 m_U.set_matrix_row(A->num_rows()/2, &con[u_part], con.size()-u_part);
204 for(
size_t i=A->num_rows()/2+1; i<A->
num_rows(); i++)
212 for(
typename matrix_type::row_iterator i_it = A->begin_row(i); i_it != A->end_row(i); ++i_it)
214 con.push_back(connection(i_it.index(), i_it.value()));
221 totalentries+=con.size();
222 if(maxentries < con.size()) maxentries = con.size();
224 for(
size_t i_it=0; i_it<con.size(); i_it++)
226 if(con[i_it].iIndex < i)
m_L(i, con[i_it].iIndex) = con[i_it].dValue;
227 else m_U(i, con[i_it].iIndex) = con[i_it].dValue;
240 UG_LOG(
"\n ILUT storage information:\n");
241 UG_LOG(
" A nr of connections: " << A->total_num_connections() <<
"\n");
242 UG_LOG(
" L+U nr of connections: " <<
m_L.total_num_connections()+
m_U.total_num_connections() <<
"\n");
243 UG_LOG(
" Increase factor: " << (
float)(
m_L.total_num_connections() +
m_U.total_num_connections() )/A->total_num_connections() <<
"\n");
244 UG_LOG(
reset_floats <<
"Total entries: " << totalentries <<
" (" << ((
double)totalentries) / (A->num_rows()*A->num_rows()) <<
"% of dense)");
250 size_t eliminate_row(std::vector<typename matrix_type::connection> &con,
size_t start,
size_t stop,
double dmax)
254 for(
size_t i_it = 0; i_it < con.size(); ++i_it)
256 size_t k = con[i_it].iIndex;
257 if(k < start)
continue;
264 if(con[i_it].dValue == 0.0)
continue;
265 UG_ASSERT(
m_U.num_connections(k) != 0 &&
m_U.begin_row(k).index() == k,
"");
271 block_type &d = con[i_it].dValue = con[i_it].dValue / ukk;
273 typename matrix_type::row_iterator k_it =
m_U.begin_row(k);
276 while(k_it !=
m_U.end_row(k) && j < con.size())
279 if(k_it.index() == con[j].iIndex)
282 con[j].dValue -= k_it.value() * d;
285 else if(k_it.index() < con[j].iIndex)
290 typename matrix_type::connection
291 c(k_it.index(), k_it.value() * d * -1.0);
296 con.insert(con.begin()+j, c);
309 if (k_it!=
m_U.end_row(k)){
310 for (;k_it!=
m_U.end_row(k);++k_it){
311 typename matrix_type::connection c(k_it.index(),-k_it.value()*d);
328 for(
size_t i=0; i <
m_L.num_rows(); i++)
332 for(
typename matrix_type::row_iterator it =
m_L.begin_row(i); it !=
m_L.end_row(i); ++it)
333 MatMultAdd(c[i], 1.0, c[i], -1.0, it.value(), c[it.index()] );
341 size_t i=
m_U.num_rows()-1;
342 typename matrix_type::row_iterator it =
m_U.begin_row(i);
351 UG_LOG(
"Warning: near-zero diagonal entry in last row of U with corresponding non-near-zero rhs entry (" <<
BlockNorm(
s) <<
")\n");
359 for(
size_t i=
m_U.num_rows()-2; ; i--)
361 typename matrix_type::row_iterator it =
m_U.begin_row(i);
367 for(; it !=
m_U.end_row(i); ++it)
369 MatMultAdd(
s, 1.0,
s, -1.0, it.value(), c[it.index()] );
398 template <
typename TAlgebra>
Definition: smart_pointer.h:108
TAlgebra::vector_type vector_type
type of vector
Definition: debug_writer.h:360
SmartPtr< IDebugWriter< algebra_type > > debug_writer()
returns the debug writer
Definition: debug_writer.h:391
TAlgebra::matrix_type matrix_type
type of matrix
Definition: debug_writer.h:363
SmartPtr< IDamping< TAlgebra::vector_type, TAlgebra::vector_type > > damping()
returns the scaling
Definition: linear_iterator.h:173
describes a linear iterator that is based on a matrix operator
Definition: preconditioner.h:103
Definition: matrix_operator.h:49
matrix_type m_U
Definition: pilut.h:390
double m_eps
Definition: pilut.h:391
matrix_type m_L
Definition: pilut.h:389
virtual bool preprocess(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
initializes the preconditioner
Definition: pilut.h:111
TAlgebra::matrix_type matrix_type
Definition: pilut.h:56
void set_info(bool info)
sets storage information output to true or false
Definition: pilut.h:95
void set_threshold(number thresh)
sets threshold for incomplete LU factorisation (added 01122010ih)
Definition: pilut.h:89
virtual ~PILUTPreconditioner()
Definition: pilut.h:84
PILUTPreconditioner(double eps=0)
Definition: pilut.h:68
TAlgebra::vector_type vector_type
Definition: pilut.h:53
SmartPtr< ILinearIterator< vector_type > > clone()
clone
Definition: pilut.h:74
size_t eliminate_row(std::vector< typename matrix_type::connection > &con, size_t start, size_t stop, double dmax)
Definition: pilut.h:250
TAlgebra algebra_type
Definition: pilut.h:50
bool m_info
Definition: pilut.h:392
bool m_show_progress
Definition: pilut.h:393
void set_show_progress(bool s)
set whether the progress meter should be shown
Definition: pilut.h:101
virtual const char * name() const
returns the name of iterator
Definition: pilut.h:108
static const number m_small
Definition: pilut.h:394
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: pilut.h:324
matrix_type::value_type block_type
Definition: pilut.h:62
IPreconditioner< TAlgebra >::matrix_operator_type matrix_operator_type
Matrix Operator type.
Definition: pilut.h:59
virtual bool postprocess()
cleans the operator
Definition: pilut.h:386
Definition: progress.h:50
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
static std::ios_base & reset_floats(std::ios_base &o)
used to unset flags set by std::scientific or std::fixed.
Definition: ostream_util.h:52
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define STATIC_ASSERT(expr, msg)
Definition: common.h:61
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
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 InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
double BlockNorm(const TYPE &v)
Definition: blocks.h:57
#define PROFILE_BEGIN(name)
Definition: profiler.h:254
#define PROFILE_END()
Definition: profiler.h:256
#define PROGRESS_FINISH(progVarName)
Definition: progress.h:118
#define PROGRESS_START_WITH(progVarName, dSize, msg)
Definition: progress.h:114
#define PROGRESS_UPDATE(progVarName, d)
Definition: progress.h:117
T value_type
Definition: sparsematrix_interface.h:2
size_t num_rows() const
Definition: sparsematrix_interface.h:38