34 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ILU__
35 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__ILU__
62 template<
typename Matrix_type>
66 typedef typename Matrix_type::row_iterator row_iterator;
70 for(
size_t i=1; i < A.num_rows(); i++)
73 const row_iterator rowEnd = A.end_row(i);
74 for(row_iterator it_k = A.begin_row(i); it_k != rowEnd && (it_k.index() < i); ++it_k)
76 const size_t k = it_k.index();
77 block_type &a_ik = it_k.value();
83 UG_THROW(
"Diag is Zero for k="<<k<<
", cannot factorize ILU.");
87 row_iterator it_j = it_k;
88 for(++it_j; it_j != rowEnd; ++it_j)
90 const size_t j = it_j.index();
91 block_type& a_ij = it_j.value();
93 row_iterator
p = A.get_connection(k,j, bFound);
96 const block_type a_kj =
p.value();
109 template<
typename Matrix_type>
113 typedef typename Matrix_type::row_iterator row_iterator;
117 for(
size_t i=1; i < A.num_rows(); i++)
119 block_type &Aii = A(i,i);
120 block_type Nii(Aii); Nii*=0.0;
124 const row_iterator it_iEnd = A.end_row(i);
125 for(row_iterator it_ik = A.begin_row(i); it_ik != it_iEnd && (it_ik.index() < i); ++it_ik)
133 const size_t k = it_ik.index();
134 block_type &a_ik = it_ik.value();
139 const row_iterator it_kEnd = A.end_row(k);
140 for (row_iterator it_kj=A.begin_row(k); it_kj != it_kEnd ;++it_kj)
142 const size_t j = it_kj.index();
146 const block_type& a_kj = it_kj.value();
149 row_iterator pij = A.get_connection(i,j, aijFound);
153 block_type& a_ij = pij.value();
173 template<
typename Matrix_type>
177 typedef typename Matrix_type::row_iterator row_iterator;
181 for(
size_t i=1; i < A.num_rows(); i++)
185 for(row_iterator it_k = A.begin_row(i); it_k != A.end_row(i) && (it_k.index() < i); ++it_k)
187 const size_t k = it_k.index();
188 block_type &a_ik = it_k.value();
189 block_type &a_kk = A(k,k);
195 UG_THROW(
"ILU: Blocknorm of diagonal is near-zero for k="<<k<<
196 " with eps: "<< eps <<
", ||A_kk||="<<fabs(
BlockNorm(A(k,k)))
201 "with i = " << i <<
" and k = " << k <<
".");
204 typename Matrix_type::row_iterator it_ij = it_k;
206 typename Matrix_type::row_iterator it_kj = A.begin_row(k);
208 while(it_ij != A.end_row(i) && it_kj != A.end_row(k))
210 if(it_ij.index() > it_kj.index())
212 else if(it_ij.index() < it_kj.index())
216 block_type &a_ij = it_ij.value();
217 const block_type &a_kj = it_kj.value();
232 template<
typename Matrix_type,
typename Vector_type>
233 bool invert_L(
const Matrix_type &A, Vector_type &x,
const Vector_type &b)
236 typedef typename Matrix_type::const_row_iterator const_row_iterator;
239 for(
size_t i=0; i < x.size(); i++)
242 for(const_row_iterator it = A.begin_row(i); it != A.end_row(i); ++it)
244 if(it.index() >= i)
continue;
256 template<
typename Matrix_type,
typename Vector_type>
257 bool invert_U(
const Matrix_type &A, Vector_type &x,
const Vector_type &b,
261 typedef typename Matrix_type::const_row_iterator const_row_iterator;
286 UG_LOG(
"ILU Warning: Near-zero last diagonal entry "
287 "with norm "<<
BlockNorm(A(i,i))<<
" in U "
288 "for non-near-zero rhs entry with norm "
290 "NOTE: Reduce 'eps' using e.g. ILU::set_inversion_eps(...) "
291 "to avoid this warning. Current eps: " << eps <<
".\n")
300 if(x.size() <= 1)
return result;
303 for(
size_t i = x.size()-2; ; --i)
306 for(const_row_iterator it = A.begin_row(i); it != A.end_row(i); ++it)
308 if(it.index() <= i)
continue;
322 template <
typename TAlgebra>
409 UG_LOG(
"\nILU: please use 'set_ordering_algorithm(..)' in the future\n");
430 virtual const char*
name()
const {
return "ILU";}
438 UG_THROW (
"ILU: Ordering for overlap has not been implemented yet.");
451 UG_LOG(
"ILU: ordering took " << end-start <<
" seconds\n");
471 J.template cast_dynamic<MatrixOperator<matrix_type, vector_type> >();
476 "not based on matrix. This Preconditioner can only "
477 "handle matrix-based operators.");
489 L.template cast_dynamic<MatrixOperator<matrix_type, vector_type> >();
494 "not based on matrix. This Preconditioner can only "
495 "handle matrix-based operators.");
550 std::vector<IndexLayout::Element> vIndex;
626 static bool first =
true;
630 for(
size_t i = 0; i < d.size(); ++i)
632 for(
size_t i = d.size(); i <
m_oD.size(); ++i)
641 for(
size_t i = 0; i < c.size(); ++i)
662 if(first)
write_debug(*spDtmp,
"ILU_step_2_d_unique");
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
TAlgebra::matrix_type matrix_type
type of matrix
Definition: debug_writer.h:363
ILU / ILU(beta) preconditioner.
Definition: ilu.h:324
TAlgebra::matrix_type matrix_type
Matrix type.
Definition: ilu.h:333
virtual SmartPtr< ILinearIterator< vector_type > > clone()
Clone.
Definition: ilu.h:380
virtual bool postprocess()
Postprocess routine.
Definition: ilu.h:686
IOrderingAlgorithm< TAlgebra, ordering_container_type > ordering_algo_type
Definition: ilu.h:343
bool init(SmartPtr< ILinearOperator< vector_type > > L)
Definition: ilu.h:485
vector_type m_oD
for overlaps only
Definition: ilu.h:709
number m_sortEps
smallest allowed value for sorted factorization
Definition: ilu.h:719
vector_type m_h
help vector
Definition: ilu.h:706
void set_disable_preprocessing(bool bDisable)
disable preprocessing (if underlying matrix has not changed)
Definition: ilu.h:413
TAlgebra algebra_type
Algebra type.
Definition: ilu.h:327
void set_beta(double beta)
set factor for
Definition: ilu.h:392
void apply_ordering()
Definition: ilu.h:432
virtual const char * name() const
returns the name of iterator
Definition: ilu.h:430
SmartPtr< OverlapWriter< TAlgebra > > m_overlapWriter
Definition: ilu.h:712
IPreconditioner< TAlgebra > base_type
Base type.
Definition: ilu.h:339
virtual bool preprocess(SmartPtr< MatrixOperator< matrix_type, vector_type > > pOp)
initializes the preconditioner
Definition: ilu.h:513
bool m_bDisablePreprocessing
whether or not to disable preprocessing
Definition: ilu.h:725
void set_ordering_algorithm(SmartPtr< ordering_algo_type > ordering_algo)
sets an ordering algorithm
Definition: ilu.h:395
void enable_overlap(bool enable)
Definition: ilu.h:426
bool init(SmartPtr< MatrixOperator< matrix_type, vector_type > > Op)
Definition: ilu.h:503
bool m_useOverlap
Definition: ilu.h:728
std::vector< size_t > m_oldIndex
Definition: ilu.h:733
SmartPtr< ordering_algo_type > m_spOrderingAlgo
for ordering algorithms
Definition: ilu.h:731
bool m_useConsistentInterfaces
Definition: ilu.h:727
std::vector< size_t > ordering_container_type
Ordering type.
Definition: ilu.h:342
virtual bool supports_parallel() const
returns if parallel solving is supported
Definition: ilu.h:389
ILU(double beta=0.0)
Definition: ilu.h:353
vector_type m_oC
Definition: ilu.h:710
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: ilu.h:616
void applyLU(vector_type &c, const vector_type &d, vector_type &tmp)
Definition: ilu.h:590
void enable_consistent_interfaces(bool enable)
enables consistent interfaces.
Definition: ilu.h:424
std::vector< size_t > m_newIndex
Definition: ilu.h:733
number m_beta
factor for ILU-beta
Definition: ilu.h:716
IPreconditioner< TAlgebra >::matrix_operator_type matrix_operator_type
Matrix Operator type.
Definition: ilu.h:336
number m_invEps
smallest allowed value for the Aii/Bi quotient
Definition: ilu.h:722
void set_sort_eps(number eps)
sets the smallest allowed value for sorted factorization
Definition: ilu.h:416
ILU(const ILU< TAlgebra > &parent)
clone constructor
Definition: ilu.h:366
void write_overlap_debug(const T &t, std::string name)
Definition: ilu.h:690
ordering_container_type m_old_ordering
Definition: ilu.h:732
bool m_bSortIsIdentity
Definition: ilu.h:734
TAlgebra::vector_type vector_type
Vector type.
Definition: ilu.h:330
const vector_type * m_u
Definition: ilu.h:736
matrix_type m_ILU
storage for factorization
Definition: ilu.h:703
void set_sort(bool b)
set cuthill-mckee sort on/off
Definition: ilu.h:400
ordering_container_type m_ordering
Definition: ilu.h:732
virtual bool init(SmartPtr< ILinearOperator< vector_type > > J, const vector_type &u)
implements the ILinearIterator-interface for matrix based preconditioner
Definition: ilu.h:466
virtual ~ILU()
Destructor.
Definition: ilu.h:386
void set_inversion_eps(number eps)
sets the smallest allowed value for the Aii/Bi quotient
Definition: ilu.h:419
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
virtual bool init(SmartPtr< ILinearOperator< vector_type > > J, const vector_type &u)
implements the ILinearIterator-interface for matrix based preconditioner
Definition: preconditioner.h:192
Definition: matrix_operator.h:49
Definition: native_cuthill_mckee.h:96
Writes overlapping matrices and vectors.
Definition: overlap_writer.h:52
void print_debugger_message(std::string msg)
prints a debugger message (listing all the sections)
Definition: debug_writer.h:320
void SetLayoutValues(TVector *pVec, const IndexLayout &layout, typename TVector::value_type val)
sets the values of a vector to a given number only on the layout indices
Definition: parallelization_util.h:315
void MatAddSlaveRowsToMasterRowOverlap0(TMatrix &mat)
Generates a set of unique global algebra ids.
Definition: parallelization_util.h:106
void MatMakeConsistentOverlap0(TMatrix &mat)
Generates a set of unique global algebra ids.
Definition: parallelization_util.h:126
@ 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
void CollectUniqueElements(std::vector< typename TLayout::Element > &elemsOut, const TLayout &layout)
writes all elements in the interfaces into the resulting vector. avoids doubles.
Definition: pcl_layout_util.h:142
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
bool FactorizeILUBeta(Matrix_type &A, number beta)
Definition: ilu.h:110
bool FactorizeILUSorted(Matrix_type &A, const number eps=1e-50)
Definition: ilu.h:174
double get_clock_s()
Definition: stopwatch.h:103
bool invert_L(const Matrix_type &A, Vector_type &x, const Vector_type &b)
Definition: ilu.h:233
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
void CreateOverlap(TMatrix &matInOut)
Adds coefficients and connections to create an overlapping matrix.
Definition: matrix_overlap_impl.h:434
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 invert_U(const Matrix_type &A, Vector_type &x, const Vector_type &b, const number eps=1e-8)
Definition: ilu.h:257
void AddMult(A &dest, const B &b, const C &vec)
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
bool FactorizeILU(Matrix_type &A)
Definition: ilu.h:63
double BlockNorm(const TYPE &v)
Definition: blocks.h:57
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
#define PROFILE_BEGIN_GROUP(name, groups)
Definition: profiler.h:255
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
T value_type
Definition: sparsematrix_interface.h:2
stopwatch class for quickly taking times