38 #ifndef GMM_PRECOND_ILDLTT_H
39 #define GMM_PRECOND_ILDLTT_H
50 template <
typename Matrix>
53 typedef typename linalg_traits<Matrix>::value_type value_type;
54 typedef typename number_traits<value_type>::magnitude_type magnitude_type;
58 row_matrix<svector> U;
59 std::vector<magnitude_type> indiag;
65 template<
typename M>
void do_ildltt(
const M&, row_major);
66 void do_ildltt(
const Matrix&, col_major);
69 void build_with(
const Matrix& A,
int k_ = -1,
double eps_ =
double(-1)) {
71 if (eps_ >=
double(0)) eps = eps_;
73 indiag.resize(std::min(mat_nrows(A), mat_ncols(A)));
74 do_ildltt(A,
typename principal_orientation_type<
typename
75 linalg_traits<Matrix>::sub_orientation>::potype());
78 : U(mat_nrows(A),mat_ncols(A)), K(k_), eps(eps_) { build_with(A); }
81 size_type memsize()
const {
82 return sizeof(*this) +
nnz(U)*
sizeof(value_type) + indiag.size() *
sizeof(magnitude_type);
86 template<
typename Matrix>
template<
typename M>
89 typedef typename number_traits<T>::magnitude_type R;
91 size_type n = mat_nrows(A);
95 R prec = default_tol(R()), max_pivot = gmm::abs(A(0,0)) * prec;
98 for (size_type i = 0; i < n; ++i) {
102 for (size_type krow = 0, k; krow < w.nb_stored(); ++krow) {
103 typename svector::iterator wk = w.begin() + krow;
104 if ((k = wk->c) >= i)
break;
105 if (gmm::is_complex(wk->e)) {
106 tmp = gmm::conj(U(k, i))/indiag[k];
107 gmm::add(scaled(mat_row(U, k), -tmp), w);
111 if (gmm::abs(tmp) < eps * norm_row) { w.sup(k); --krow; }
112 else { wk->e += tmp;
gmm::add(scaled(mat_row(U, k), -tmp), w); }
117 if (gmm::abs(gmm::real(tmp)) <= max_pivot)
118 { GMM_WARNING2(
"pivot " << i <<
" is too small"); tmp = T(1); }
120 max_pivot = std::max(max_pivot, std::min(gmm::abs(tmp) * prec, R(1)));
121 indiag[i] = R(1) / gmm::real(tmp);
123 gmm::scale(w, T(indiag[i]));
124 std::sort(w.begin(), w.end(), elt_rsvector_value_less_<T>());
125 typename svector::const_iterator wit = w.begin(), wite = w.end();
126 for (
size_type nnu = 0; wit != wite; ++wit)
127 if (wit->c > i) {
if (nnu < K) { U(i, wit->c) = wit->e; ++nnu; } }
131 template<
typename Matrix>
132 void ildltt_precond<Matrix>::do_ildltt(
const Matrix& A, col_major)
133 { do_ildltt(gmm::conjugated(A), row_major()); }
135 template <
typename Matrix,
typename V1,
typename V2>
inline
136 void mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2) {
138 gmm::lower_tri_solve(gmm::conjugated(P.U), v2,
true);
139 for (
size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
140 gmm::upper_tri_solve(P.U, v2,
true);
143 template <
typename Matrix,
typename V1,
typename V2>
inline
144 void transposed_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2)
147 template <
typename Matrix,
typename V1,
typename V2>
inline
148 void left_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2) {
150 gmm::lower_tri_solve(gmm::conjugated(P.U), v2,
true);
151 for (
size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
154 template <
typename Matrix,
typename V1,
typename V2>
inline
155 void right_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1, V2 &v2)
156 {
copy(v1, v2); gmm::upper_tri_solve(P.U, v2,
true); }
158 template <
typename Matrix,
typename V1,
typename V2>
inline
159 void transposed_left_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1,
162 gmm::upper_tri_solve(P.U, v2,
true);
163 for (
size_type i = 0; i < P.indiag.size(); ++i) v2[i] *= P.indiag[i];
166 template <
typename Matrix,
typename V1,
typename V2>
inline
167 void transposed_right_mult(
const ildltt_precond<Matrix>& P,
const V1 &v1,
169 {
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