2#ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ILUT__
3#define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ILUT__
23template <
typename TAlgebra>
110 std::stringstream ss;
111 ss <<
"ILUT(threshold = " <<
m_eps <<
", sort = " << (
m_spOrderingAlgo.valid()?
"true":
"false") <<
")";
112 if(
m_eps == 0.0) ss <<
" = Sparse LU";
131 UG_LOG(
"\nILUT: please use 'set_ordering_algorithm(..)' in the future\n");
137 virtual const char*
name()
const {
return "ILUT";}
145 J.template cast_dynamic<MatrixOperator<matrix_type, vector_type> >();
150 "not based on matrix. This Preconditioner can only "
151 "handle matrix-based operators.");
156 return base_type::init(pOp);
163 L.template cast_dynamic<MatrixOperator<matrix_type, vector_type> >();
168 "not based on matrix. This Preconditioner can only "
169 "handle matrix-based operators.");
174 return base_type::init(pOp);
181 return base_type::init(Op);
200 std::vector<IndexLayout::Element> vIndex;
201 CollectUniqueElements(vIndex, mat.layouts()->slave());
217 size_t nInd = m2.num_rows();
219 for (
size_t i = 0; i < nInd; ++i)
221 if (!m2.num_connections(i))
228 if (cnt)
UG_LOG_ALL_PROCS(
"Converted "<<cnt<<
" zero rows into Dirichlet rows.\n");
241 STATIC_ASSERT(matrix_type::rows_sorted, Matrix_has_to_have_sorted_rows);
276 m_L.resize_and_clear(A->num_rows(), A->num_cols());
277 m_U.resize_and_clear(A->num_rows(), A->num_cols());
279 size_t totalentries=0;
282 if((A->num_rows() > 0) && (A->num_cols() > 0)){
286 std::vector<matrix_connection> con;
293 m_U.set_matrix_row(0, &con[0], con.size());
298 "Using ILUT(" <<
m_eps <<
") on " << A->num_rows() <<
" x " << A->num_rows() <<
" matrix...");
300 for(
size_t i=1; i<A->num_rows(); i++)
306 UG_COND_THROW(A->num_connections(i) == 0,
"row " << i <<
" has no connections");
318 for(
size_t i_it = 0; i_it < con.size(); ++i_it)
320 size_t k = con[i_it].iIndex;
327 if(con[i_it].dValue == 0.0)
continue;
334 con[i_it].dValue = con[i_it].dValue / ukk;
341 while(k_it !=
m_U.end_row(k) && j < con.size())
344 if(k_it.index() == con[j].iIndex)
347 con[j].dValue -= k_it.value() * d;
350 else if(k_it.index() < con[j].iIndex)
361 con.insert(con.begin()+j, c);
374 if (k_it!=
m_U.end_row(k)){
375 for (;k_it!=
m_U.end_row(k);++k_it){
386 totalentries+=con.size();
387 if(maxentries < con.size()) maxentries = con.size();
390 m_L.set_matrix_row(i, &con[0], u_part);
391 m_U.set_matrix_row(i, &con[u_part], con.size()-u_part);
404 UG_LOG(
"\n ILUT storage information:\n");
405 UG_LOG(
" A is " << A->num_rows() <<
" x " << A->num_cols() <<
" matrix.\n");
406 UG_LOG(
" A nr of connections: " << A->total_num_connections() <<
"\n");
407 UG_LOG(
" L+U nr of connections: " <<
m_L.total_num_connections()+
m_U.total_num_connections() <<
"\n");
408 UG_LOG(
" Increase factor: " << (
float)(
m_L.total_num_connections() +
m_U.total_num_connections() )/A->total_num_connections() <<
"\n");
409 UG_LOG(
reset_floats <<
" Total entries: " << totalentries <<
" (" << ((
double)totalentries) / (A->num_rows()*A->num_rows()) <<
"% of dense)\n");
416 UG_LOG(
"Not using sort.");
429 bool b =
solve(c, *spDtmp);
444 if(
applyLU(c, d) ==
false)
return false;
452 if(
applyLU(
c2, c) ==
false)
return false;
464 for(
size_t i=0; i <
m_L.num_rows(); i++)
469 MatMultAdd(c[i], 1.0, c[i], -1.0, it.value(), c[it.index()] );
477 if(
m_U.num_rows() > 0)
479 size_t i=
m_U.num_rows()-1;
492 UG_LOG(
"ILUT("<<
m_eps<<
") Warning: Near-zero diagonal entry "
493 "with norm "<<
BlockNorm(uii)<<
" in last row of U "
494 " with corresponding non-near-zero rhs with norm "
495 <<
BlockNorm(
s) <<
". Setting rhs to zero.\n");
505 if(
m_U.num_rows() > 1){
506 for(
size_t i=
m_U.num_rows()-2; ; i--)
515 for(; it !=
m_U.end_row(i); ++it){
517 MatMultAdd(
s, 1.0,
s, -1.0, it.value(), c[it.index()] );
528 virtual bool multi_apply(std::vector<vector_type> &vc,
const std::vector<vector_type> &vd)
533 for(
size_t i=0; i <
m_L.num_rows(); i++)
536 for(
size_t e=0; e<vc.size(); e++)
543 MatMultAdd(c[i], 1.0, c[i], -1.0, it.value(), c[it.index()] );
552 if(
m_U.num_rows() > 0)
554 for(
size_t e=0; e<vc.size(); e++)
557 size_t i=
m_U.num_rows()-1;
570 UG_LOG(
"ILUT("<<
m_eps<<
") Warning: Near-zero diagonal entry "
571 "with norm "<<
BlockNorm(uii)<<
" in last row of U "
572 " with corresponding non-near-zero rhs with norm "
573 <<
BlockNorm(
s) <<
". Setting rhs to zero.\n");
584 if(
m_U.num_rows() > 1){
585 for(
size_t i=
m_U.num_rows()-2; ; i--)
587 for(
size_t e=0; e<vc.size(); e++)
597 for(; it !=
m_U.end_row(i); ++it){
599 MatMultAdd(
s, 1.0,
s, -1.0, it.value(), c[it.index()] );
528 virtual bool multi_apply(std::vector<vector_type> &vc,
const std::vector<vector_type> &vd) {
…}
634template <
typename TAlgebra>
Definition smart_pointer.h:108
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:212
virtual void set_debug(SmartPtr< IDebugWriter< algebra_type > > spDebugWriter)
set debug writer
Definition debug_writer.h:384
void write_debug(const matrix_type &mat, const char *filename)
write debug output for a matrix (if debug writer set)
Definition debug_writer.h:399
SmartPtr< IDebugWriter< algebra_type > > debug_writer()
returns the debug writer
Definition debug_writer.h:391
ILUTPreconditioner(double eps=1e-6)
Constructor.
Definition ilut.h:60
TAlgebra algebra_type
Definition ilut.h:28
matrix_type::connection matrix_connection
Definition ilut.h:39
bool m_info
Definition ilut.h:619
TAlgebra::matrix_type matrix_type
Definition ilut.h:35
double m_eps
Definition ilut.h:618
void set_sort(bool b)
set cuthill-mckee sort on/off
Definition ilut.h:122
bool m_bSortIsIdentity
Definition ilut.h:628
virtual const char * name() const
returns the name of iterator
Definition ilut.h:137
void set_info(bool info)
sets storage information output to true or false
Definition ilut.h:97
virtual bool preprocess_mat2(matrix_type &mat)
Definition ilut.h:237
virtual ~ILUTPreconditioner()
Destructor.
Definition ilut.h:84
matrix_type m_U
Definition ilut.h:617
IOrderingAlgorithm< TAlgebra, ordering_container_type > ordering_algo_type
Definition ilut.h:43
virtual bool init(SmartPtr< ILinearOperator< vector_type > > J, const vector_type &u)
implements the ILinearIterator-interface for matrix based preconditioner
Definition ilut.h:140
std::vector< size_t > ordering_container_type
Ordering type.
Definition ilut.h:42
matrix_type::const_row_iterator const_matrix_row_iterator
Definition ilut.h:38
std::vector< size_t > newIndex
Definition ilut.h:622
bool init(SmartPtr< ILinearOperator< vector_type > > L)
Definition ilut.h:159
IPreconditioner< TAlgebra > base_type
Definition ilut.h:56
std::vector< size_t > oldIndex
Definition ilut.h:622
const vector_type * m_u
Definition ilut.h:630
void set_show_progress(bool s)
set whether the progress meter should be shown
Definition ilut.h:103
IPreconditioner< TAlgebra >::matrix_operator_type matrix_operator_type
Matrix Operator type.
Definition ilut.h:46
bool init(SmartPtr< MatrixOperator< matrix_type, vector_type > > Op)
Definition ilut.h:177
virtual bool preprocess_mat(matrix_type &mat)
Definition ilut.h:191
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition ilut.h:88
ILUTPreconditioner(const ILUTPreconditioner< TAlgebra > &parent)
clone constructor
Definition ilut.h:68
matrix_type::row_iterator matrix_row_iterator
Definition ilut.h:37
virtual bool multi_apply(std::vector< vector_type > &vc, const std::vector< vector_type > &vd)
Definition ilut.h:528
virtual std::string config_string() const
Definition ilut.h:108
SmartPtr< ordering_algo_type > m_spOrderingAlgo
for ordering algorithms
Definition ilut.h:625
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.h:424
void set_ordering_algorithm(SmartPtr< ordering_algo_type > ordering_algo)
sets an ordering algorithm
Definition ilut.h:117
virtual bool postprocess()
cleans the operator
Definition ilut.h:612
ordering_container_type m_old_ordering
Definition ilut.h:626
vector_type::value_type vector_value
Definition ilut.h:32
void set_threshold(number thresh)
sets threshold for incomplete LU factorisation (added 01122010ih)
Definition ilut.h:91
matrix_type m_L
Definition ilut.h:616
matrix_type::value_type block_type
Definition ilut.h:50
virtual bool applyLU(vector_type &c, const vector_type &d)
Definition ilut.h:459
TAlgebra::vector_type vector_type
Definition ilut.h:31
vector_type c2
Definition ilut.h:615
ordering_container_type m_ordering
Definition ilut.h:626
bool m_show_progress
Definition ilut.h:620
virtual bool solve(vector_type &c, const vector_type &d)
Definition ilut.h:440
static const number m_small
Definition ilut.h:621
virtual SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition ilut.h:77
virtual bool preprocess(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
initializes the preconditioner
Definition ilut.h:185
describes a linear mapping X->Y
Definition linear_operator.h:80
Definition IOrderingAlgorithm.h:52
describes a linear iterator that is based on a matrix operator
Definition preconditioner.h:103
Definition native_cuthill_mckee.h:96
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
void SetDirichletRow(TSparseMatrix &A, size_t i, size_t alpha)
Definition sparsematrix_util.h:796
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
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition smart_pointer.h:90
#define UG_LOG_ALL_PROCS(msg)
Definition log.h:371
#define UG_ASSERT(expr, msg)
Definition assert.h:70
#define UG_THROW(msg)
Definition error.h:57
#define STATIC_ASSERT(expr, msg)
Definition common.h:61
#define UG_LOG(msg)
Definition log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
double number
Definition types.h:124
static void SetVectorAsPermutation(TVector &Pv, const TVector &v, const std::vector< size_t > &perm)
Definition permutation_util.h:74
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
static void SetMatrixAsPermutation(TMatrix &PA, const TMatrix &A, const std::vector< size_t > &perm)
Definition permutation_util.h:50
bool GetInversePermutation(const std::vector< size_t > &perm, std::vector< size_t > &invPerm)
Definition permutation_util.cpp:39
bool BlockMatrixFiniteAndNotTooBig(TBlock &m, double tooBigValue=1e24)
Definition vector_util.h:56
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_GROUP(name, groups)
Definition profiler.h:255
#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
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836