37 #ifndef GMM_PRECOND_ILDLTT_H
38 #define GMM_PRECOND_ILDLTT_H
49 template <
typename Matrix>
52 typedef typename linalg_traits<Matrix>::value_type value_type;
53 typedef typename number_traits<value_type>::magnitude_type magnitude_type;
57 row_matrix<svector> U;
58 std::vector<magnitude_type> indiag;
64 template<
typename M>
void do_ildltt(
const M&, row_major);
65 void do_ildltt(
const Matrix&, col_major);
68 void build_with(
const Matrix& A,
int k_ = -1,
double eps_ =
double(-1)) {
70 if (eps_ >=
double(0)) eps = eps_;
72 indiag.resize(std::min(mat_nrows(A), mat_ncols(A)));
73 do_ildltt(A,
typename principal_orientation_type<
typename
74 linalg_traits<Matrix>::sub_orientation>::potype());
77 : U(mat_nrows(A),mat_ncols(A)), K(k_), eps(eps_) { build_with(A); }
80 size_type memsize()
const {
81 return sizeof(*this) +
nnz(U)*
sizeof(value_type) + indiag.size() *
sizeof(magnitude_type);
85 template<
typename Matrix>
template<
typename M>
88 typedef typename number_traits<T>::magnitude_type R;
90 size_type n = mat_nrows(A);
94 R prec = default_tol(R()), max_pivot = gmm::abs(A(0,0)) * prec;
97 for (size_type i = 0; i < n; ++i) {
101 for (size_type krow = 0, k; krow < w.nb_stored(); ++krow) {
102 typename svector::iterator wk = w.begin() + krow;
103 if ((k = wk->c) >= i)
break;
104 if (gmm::is_complex(wk->e)) {
105 tmp = gmm::conj(U(k, i))/indiag[k];
106 gmm::add(scaled(mat_row(U, k), -tmp), w);
110 if (gmm::abs(tmp) < eps * norm_row) { w.sup(k); --krow; }
111 else { wk->e += tmp;
gmm::add(scaled(mat_row(U, k), -tmp), w); }
116 if (gmm::abs(gmm::real(tmp)) <= max_pivot)
117 { GMM_WARNING2(
"pivot " << i <<
" is too small"); tmp = T(1); }
119 max_pivot = std::max(max_pivot, std::min(gmm::abs(tmp) * prec, R(1)));
120 indiag[i] = R(1) / gmm::real(tmp);
122 gmm::scale(w, T(indiag[i]));
123 std::sort(w.begin(), w.end(), elt_rsvector_value_less_<T>());
124 typename svector::const_iterator wit = w.begin(), wite = w.end();
125 for (
size_type nnu = 0; wit != wite; ++wit)
126 if (wit->c > i) {
if (nnu < K) { U(i, wit->c) = wit->e; ++nnu; } }
130 template<
typename Matrix>
131 void ildltt_precond<Matrix>::do_ildltt(
const Matrix& A, col_major)
132 { do_ildltt(gmm::conjugated(A), row_major()); }
134 template <
typename Matrix,
typename V1,
typename V2>
inline
135 void mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2) {
137 gmm::lower_tri_solve(gmm::conjugated(P.U), v2,
true);
138 for (
size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
139 gmm::upper_tri_solve(P.U, v2,
true);
142 template <
typename Matrix,
typename V1,
typename V2>
inline
143 void transposed_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2)
146 template <
typename Matrix,
typename V1,
typename V2>
inline
147 void left_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2) {
149 gmm::lower_tri_solve(gmm::conjugated(P.U), v2,
true);
150 for (
size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
153 template <
typename Matrix,
typename V1,
typename V2>
inline
154 void right_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2)
155 {
copy(v1, v2); gmm::upper_tri_solve(P.U, v2,
true); }
157 template <
typename Matrix,
typename V1,
typename V2>
inline
158 void transposed_left_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1,
161 gmm::upper_tri_solve(P.U, v2,
true);
162 for (
size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
165 template <
typename Matrix,
typename V1,
typename V2>
inline
166 void transposed_right_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1,
168 {
copy(v1, v2); gmm::lower_tri_solve(gmm::conjugated(P.U), v2,
true); }
incomplete LDL^t (cholesky) preconditioner with fill-in and threshold.
sparse vector built upon std::vector.
size_type nnz(const L &l)
count the number of non-zero entries of a vector or matrix.
void copy(const L1 &l1, L2 &l2)
*/
number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2(const V &v)
Euclidean norm of a vector.
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void resize(V &v, size_type n)
*/
void clean(L &l, double threshold)
Clean a vector or matrix (replace near-zero entries with zeroes).
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
void add(const L1 &l1, L2 &l2)
*/
ILUT: Incomplete LU with threshold and K fill-in Preconditioner.
size_t size_type
used as the common size type in the library