DUNE-FEM (unstable)

fieldmatrixhelper.hh
1#ifndef DUNE_FEM_FIELDMATRIXHELPER_HH
2#define DUNE_FEM_FIELDMATRIXHELPER_HH
3
7
8namespace Dune
9{
10
11 namespace Fem
12 {
13
14 namespace FieldMatrixHelper
15 {
16
17 template< class Field1, class Field2, class Field3, int m, int n >
18 inline void multiply ( const FieldMatrix< Field1, m, n > &A,
19 const FieldVector< Field2, n > &x,
20 FieldVector< Field3, m > &y )
21 {
22 for( int i = 0; i < m; ++i )
23 {
24 Field3 &value = y[ i ];
25
26 value = 0;
27 for( int j = 0; j < n; ++j )
28 value += A[ i ][ j ] * x[ j ];
29 }
30 }
31
32
33
34 template< class Field1, class Field2, class Field3, int m, int n, int p >
35 inline void multiply ( const FieldMatrix< Field1, m, n > &A,
36 const FieldMatrix< Field2, n, p > &B,
37 FieldMatrix< Field3, m, p > &C )
38 {
39 for( int i = 0; i < m; ++i )
40 {
41 for( int j = 0; j < p; ++j )
42 {
43 Field3 &value = C[ i ][ j ];
44
45 value = 0;
46 for( int k = 0; k < n; ++k )
47 value += A[ i ][ k ] * B[ k ][ j ];
48 }
49 }
50 }
51
52 template< class Field1, class Field2, class Field3 >
53 inline void multiply ( const DynamicMatrix< Field1 >& A,
54 const DynamicMatrix< Field2 >& B,
55 DynamicMatrix< Field3 >& C )
56 {
57 const int m = A.rows();
58 const int n = A.cols();
59 const int p = B.cols();
60
61 C.resize( m, p );
62
63 assert( A.cols() == B.rows() );
64 assert( A.rows() == C.rows() );
65 assert( B.cols() == C.cols() );
66
67 for( int i = 0; i < m; ++i )
68 {
69 for( int j = 0; j < p; ++j )
70 {
71 Field3 &value = C[ i ][ j ];
72
73 value = 0;
74 for( int k = 0; k < n; ++k )
75 value += A[ i ][ k ] * B[ k ][ j ];
76 }
77 }
78 }
79
80 template< class Field1, class Field2, class Field3, int m, int n, int p >
81 inline void multiply ( const FieldMatrix< Field1, m, n > &A,
82 const FieldMatrix< Field2, n, p > &B,
83 Field3* C)
84 {
85 for( int i = 0, ip = 0; i < m; ++i )
86 {
87 for( int j = 0; j < p; ++j , ++ ip )
88 {
89 Field3 &value = C[ ip ];
90 value = 0;
91 for( int k = 0; k < n; ++k )
92 value += A[ i ][ k ] * B[ k ][ j ];
93 }
94 }
95 }
96
97 }
98
99 } // namespace Fem
100
101} // namespace Dune
102
103#endif // #ifndef DUNE_FEM_FIELDMATRIXHELPER_HH
This file implements a dense matrix with dynamic numbers of rows and columns.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)