1#ifndef DUNE_ISTL_ILDL_HH
2#define DUNE_ISTL_ILDL_HH
19 template<
class K,
int m,
int n >
20 inline static void bildl_subtractBCT (
const FieldMatrix< K, m, n > &B,
const FieldMatrix< K, m, n > &CT, FieldMatrix< K, m, n > &A )
22 for(
int i = 0; i < m; ++i )
24 for(
int j = 0; j < n; ++j )
26 for(
int k = 0; k < n; ++k )
27 A[ i ][ j ] -= B[ i ][ k ] * CT[ j ][ k ];
32 template<
class Matrix >
33 inline static void bildl_subtractBCT (
const Matrix &B,
const Matrix &CT, Matrix &A )
35 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
38 auto &&B_i = B[ i.index() ];
39 const auto ikend = B_i.end();
40 for(
auto j = A_i.begin(), jend = A_i.end(); j != jend; ++j )
43 auto &&CT_j = CT[ j.index() ];
44 const auto jkend = CT_j.end();
45 for(
auto ik = B_i.begin(), jk = CT_j.begin(); (ik != ikend) && (jk != jkend); )
47 if( ik.index() == jk.index() )
49 bildl_subtractBCT( *ik, *jk, A_ij );
52 else if( ik.index() < jk.index() )
75 template<
class Matrix >
78 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
82 auto ij = A_i.begin();
83 for( ; ij.index() < i.index(); ++ij )
86 auto &&A_j = A[ ij.index() ];
90 auto ik = A_i.
begin();
91 auto jk = A_j.begin();
92 while( (ik != ij) && (jk.index() < ij.index()) )
94 if( ik.index() == jk.index() )
96 bildl_subtractBCT(*ik, *jk, A_ij);
99 else if( ik.index() < jk.index() )
106 if( ij.index() != i.index() )
111 for(
auto ik = A_i.begin(); ik != ij; ++ik )
114 const auto &A_k = A[ ik.index() ];
117 A_ik.rightmultiply( *A_k.find( ik.index() ) );
118 bildl_subtractBCT( B, A_ik, A_ii );
126 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() );
136 template<
class Matrix,
class X,
class Y >
137 inline void bildl_backsolve (
const Matrix &A, X &v,
const Y &d,
bool isLowerTriangular =
false )
140 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
142 const auto &A_i = *i;
143 v[ i.index() ] = d[ i.index() ];
144 for(
auto ij = A_i.begin(); ij.index() < i.index(); ++ij )
145 (*ij).mmv( v[ ij.index() ], v[ i.index() ] );
149 if( isLowerTriangular )
153 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
155 const auto &A_i = *i;
156 const auto ii = A_i.beforeEnd();
157 assert( ii.index() == i.index() );
158 auto rhs = v[ i.index() ];
159 ii->mv( rhs, v[ i.index() ] );
166 for(
auto i = A.
begin(), iend = A.
end(); i != iend; ++i )
168 const auto &A_i = *i;
169 const auto ii = A_i.find( i.index() );
170 assert( ii.index() == i.index() );
171 auto rhs = v[ i.index() ];
172 ii->mv( rhs, v[ i.index() ] );
180 const auto &A_i = *i;
181 for(
auto ij = A_i.begin(); ij.index() < i.index(); ++ij )
182 (*ij).mmtv( v[ i.index() ], v[ ij.index() ] );
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:146
derive error class from the base class in common
Definition: istlexception.hh:16
A generic dynamic dense matrix.
Definition: matrix.hh:555
RowIterator beforeBegin()
Definition: matrix.hh:629
RowIterator beforeEnd()
Definition: matrix.hh:622
RowIterator end()
Get iterator to one beyond last row.
Definition: matrix.hh:615
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:609
const char * what() const noexcept override
output internal message buffer
Definition: exceptions.cc:35
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
void bildl_decompose(Matrix &A)
compute ILDL decomposition of a symmetric matrix A
Definition: ildl.hh:76