1#ifndef DUNE_ISTL_ILDL_HH
2#define DUNE_ISTL_ILDL_HH
21 template<
class K,
int m,
int n >
22 inline static void bildl_subtractBCT (
const FieldMatrix< K, m, n > &B,
const FieldMatrix< K, m, n > &CT, FieldMatrix< K, m, n > &A )
24 for(
int i = 0; i < m; ++i )
26 for(
int j = 0; j < n; ++j )
28 for(
int k = 0; k < n; ++k )
29 A[ i ][ j ] -= B[ i ][ k ] * CT[ j ][ k ];
35 inline static void bildl_subtractBCT (
const K &B,
const K &CT, K &A,
41 template<
class Matrix >
42 inline static void bildl_subtractBCT (
const Matrix &B,
const Matrix &CT, Matrix &A,
45 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
48 auto &&B_i = B[ i.index() ];
49 const auto ikend = B_i.end();
50 for(
auto j = A_i.begin(), jend = A_i.end(); j != jend; ++j )
53 auto &&CT_j = CT[ j.index() ];
54 const auto jkend = CT_j.end();
55 for(
auto ik = B_i.begin(), jk = CT_j.begin(); (ik != ikend) && (jk != jkend); )
57 if( ik.index() == jk.index() )
59 bildl_subtractBCT( *ik, *jk, A_ij );
62 else if( ik.index() < jk.index() )
85 template<
class Matrix >
88 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
92 auto ij = A_i.begin();
93 for( ; ij.index() < i.index(); ++ij )
96 auto &&A_j = A[ ij.index() ];
100 auto ik = A_i.
begin();
101 auto jk = A_j.begin();
102 while( (ik != ij) && (jk.index() < ij.index()) )
104 if( ik.index() == jk.index() )
106 bildl_subtractBCT(*ik, *jk, A_ij);
109 else if( ik.index() < jk.index() )
116 if( ij.index() != i.index() )
121 for(
auto ik = A_i.begin(); ik != ij; ++ik )
124 const auto &A_k = A[ ik.index() ];
127 Impl::asMatrix(A_ik).rightmultiply( Impl::asMatrix(*A_k.find( ik.index() )) );
128 bildl_subtractBCT( B, A_ik, A_ii );
132 Impl::asMatrix(A_ii).invert();
136 DUNE_THROW(
MatrixBlockError,
"ILDL failed to invert matrix block A[" << i.index() <<
"][" << ij.index() <<
"]" << e.what(); th__ex.r = i.index(); th__ex.c = ij.index() );
146 template<
class Matrix,
class X,
class Y >
147 inline void bildl_backsolve (
const Matrix &A, X &v,
const Y &d,
bool isLowerTriangular =
false )
150 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
152 const auto &A_i = *i;
153 v[ i.index() ] = d[ i.index() ];
154 for(
auto ij = A_i.begin(); ij.index() < i.index(); ++ij )
156 auto&& vi = Impl::asVector( v[ i.index() ] );
157 Impl::asMatrix(*ij).mmv(Impl::asVector( v[ ij.index() ] ), vi);
162 if( isLowerTriangular )
166 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
168 const auto &A_i = *i;
169 const auto ii = A_i.beforeEnd();
170 assert( ii.index() == i.index() );
177 auto rhsValue = v[ i.index() ];
178 auto&& rhs = Impl::asVector(rhsValue);
179 auto&& vi = Impl::asVector( v[ i.index() ] );
180 Impl::asMatrix(*ii).mv(rhs, vi);
187 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
189 const auto &A_i = *i;
190 const auto ii = A_i.find( i.index() );
191 assert( ii.index() == i.index() );
198 auto rhsValue = v[ i.index() ];
199 auto&& rhs = Impl::asVector(rhsValue);
200 auto&& vi = Impl::asVector( v[ i.index() ] );
201 Impl::asMatrix(*ii).mv(rhs, vi);
209 const auto &A_i = *i;
210 for(
auto ij = A_i.begin(); ij.index() < i.index(); ++ij )
212 auto&& vij = Impl::asVector( v[ ij.index() ] );
213 Impl::asMatrix(*ij).mmtv(Impl::asVector( v[ i.index() ] ), vij);
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:151
derive error class from the base class in common
Definition: istlexception.hh:17
Error when performing an operation on a matrix block.
Definition: istlexception.hh:59
A generic dynamic dense matrix.
Definition: matrix.hh:559
RowIterator beforeBegin()
Definition: matrix.hh:632
RowIterator beforeEnd()
Definition: matrix.hh:625
RowIterator end()
Get iterator to one beyond last row.
Definition: matrix.hh:618
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:612
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
The incomplete LU factorization kernels.
Dune namespace.
Definition: alignedallocator.hh:11
void bildl_decompose(Matrix &A)
compute ILDL decomposition of a symmetric matrix A
Definition: ildl.hh:86
Implements a scalar matrix view wrapper around an existing scalar.
Implements a scalar vector view wrapper around an existing scalar.
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition: typetraits.hh:194