Debian Codegraph @

dune/istl/test/hilbertmatrix.hh

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 #ifndef HILBERTMATRIX_HH
4 #define HILBERTMATRIX_HH
5
6 #include <dune/common/fmatrix.hh>
7
8 #include <dune/istl/bcrsmatrix.hh>
9
10
11 template< class B >
12 void setupSP (Dune::BCRSMatrix< B >& A, int n )
13 {
14 using matrix_type = Dune::BCRSMatrix< B >;
15
16 A.setSize( n, n, n*n );
17 A.setBuildMode( matrix_type::row_wise );
18
19 for( auto i = A.createbegin(); i != A.createend(); ++i )
20 for( typename matrix_type::size_type j = 0; j < A.N(); ++j )
21 i.insert( j );
22 }
23
24 template < class B >
25 void setupHilbertMatrix ( Dune::BCRSMatrix< B >& A, B block, int n )
26 {
27 using matrix_type = Dune::BCRSMatrix< B >;
28 using field_type = typename matrix_type::field_type;
29 using size_type = typename matrix_type::size_type;
30
31 setupSP( A, n );
32
33 for ( size_type i = 0; i < A.N(); ++i )
34 for ( size_type j = 0; j < A.M(); ++j )
35 {
36 A[ i ][ j ] = block;
37 A[ i ][ j ] /= static_cast<field_type>( i + j + 1 );
38 }
39 }
40
41 template< class T >
42 void setupHilbertMatrix ( Dune::BCRSMatrix< Dune::FieldMatrix< T, 1, 1 > >& A, int n )
43 {
44 setupHilbertMatrix( A, Dune::FieldMatrix< T, 1, 1 >{ 1.0 }, n );
45 }
46
47 template< class T >
48 void setupHilbertMatrix ( Dune::BCRSMatrix< T >& A, int n )
49 {
50 setupHilbertMatrix( A, T{ 1.0 }, n );
51 }
52
53 #endif // #ifndef HILBERTMATRIX_HH