3#ifndef DUNE_ISTL_ILDL_HH
4#define DUNE_ISTL_ILDL_HH
23 template<
class K,
int m,
int n >
26 for(
int i = 0; i < m; ++i )
28 for(
int j = 0; j < n; ++j )
30 for(
int k = 0; k < n; ++k )
31 A[ i ][ j ] -= B[ i ][ k ] * CT[ j ][ k ];
37 inline static void bildl_subtractBCT (
const K &B,
const K &CT, K &A,
43 template<
class Matrix >
44 inline static void bildl_subtractBCT (
const Matrix &B,
const Matrix &CT, Matrix &A,
47 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
50 auto &&B_i = B[ i.index() ];
51 const auto ikend = B_i.end();
52 for(
auto j = A_i.begin(), jend = A_i.end(); j != jend; ++j )
55 auto &&CT_j = CT[ j.index() ];
56 const auto jkend = CT_j.end();
57 for(
auto ik = B_i.begin(), jk = CT_j.begin(); (ik != ikend) && (jk != jkend); )
59 if( ik.index() == jk.index() )
61 bildl_subtractBCT( *ik, *jk, A_ij );
64 else if( ik.index() < jk.index() )
87 template<
class Matrix >
90 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
94 auto ij = A_i.begin();
95 for( ; ij.index() < i.index(); ++ij )
98 auto &&A_j = A[ ij.index() ];
102 auto ik = A_i.
begin();
103 auto jk = A_j.begin();
104 while( (ik != ij) && (jk.index() < ij.index()) )
106 if( ik.index() == jk.index() )
108 bildl_subtractBCT(*ik, *jk, A_ij);
111 else if( ik.index() < jk.index() )
118 if( ij.index() != i.index() )
123 for(
auto ik = A_i.begin(); ik != ij; ++ik )
126 const auto &A_k = A[ ik.index() ];
129 Impl::asMatrix(A_ik).rightmultiply( Impl::asMatrix(*A_k.find( ik.index() )) );
130 bildl_subtractBCT( B, A_ik, A_ii );
134 Impl::asMatrix(A_ii).invert();
138 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() );
148 template<
class Matrix,
class X,
class Y >
149 inline void bildl_backsolve (
const Matrix &A, X &v,
const Y &d,
bool isLowerTriangular =
false )
152 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
154 const auto &A_i = *i;
155 v[ i.index() ] = d[ i.index() ];
156 for(
auto ij = A_i.begin(); ij.index() < i.index(); ++ij )
158 auto&& vi = Impl::asVector( v[ i.index() ] );
159 Impl::asMatrix(*ij).mmv(Impl::asVector( v[ ij.index() ] ), vi);
164 if( isLowerTriangular )
168 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
170 const auto &A_i = *i;
171 const auto ii = A_i.beforeEnd();
172 assert( ii.index() == i.index() );
179 auto rhsValue = v[ i.index() ];
180 auto&& rhs = Impl::asVector(rhsValue);
181 auto&& vi = Impl::asVector( v[ i.index() ] );
182 Impl::asMatrix(*ii).mv(rhs, vi);
189 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
191 const auto &A_i = *i;
192 const auto ii = A_i.find( i.index() );
193 assert( ii.index() == i.index() );
200 auto rhsValue = v[ i.index() ];
201 auto&& rhs = Impl::asVector(rhsValue);
202 auto&& vi = Impl::asVector( v[ i.index() ] );
203 Impl::asMatrix(*ii).mv(rhs, vi);
211 const auto &A_i = *i;
212 for(
auto ij = A_i.begin(); ij.index() < i.index(); ++ij )
214 auto&& vij = Impl::asVector( v[ ij.index() ] );
215 Impl::asMatrix(*ij).mmtv(Impl::asVector( v[ i.index() ] ), vij);
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:126
derive error class from the base class in common
Definition: istlexception.hh:19
Error when performing an operation on a matrix block.
Definition: istlexception.hh:52
A generic dynamic dense matrix.
Definition: matrix.hh:561
RowIterator beforeBegin()
Definition: matrix.hh:630
RowIterator beforeEnd()
Definition: matrix.hh:623
RowIterator end()
Get iterator to one beyond last row.
Definition: matrix.hh:616
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:610
const char * what() const noexcept override
output internal message buffer
Definition: exceptions.cc:37
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
The incomplete LU factorization kernels.
Dune namespace.
Definition: alignedallocator.hh:13
void bildl_decompose(Matrix &A)
compute ILDL decomposition of a symmetric matrix A
Definition: ildl.hh:88
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