Peano 4
Loading...
Searching...
No Matches
MatrixMatrixOperations.cpph
Go to the documentation of this file.
1template<int Rows, int Cols, int X, typename Scalar>
3 const Matrix<Rows,X,Scalar>& lhs,
4 const Matrix<X,Cols,Scalar>& rhs
5) {
6 Matrix<Rows,Cols,Scalar> result(0);
7
8 for (int i=0; i < Rows; i++) {
9 for (int j=0; j < Cols; j++) {
10 for (int k=0; k < X; k++) {
11 result(i,j) += lhs(i,k) * rhs(k,j);
12 }
13 }
14 }
15
16 return result;
17}
18
19
20template<int Rows, int Cols, int X, typename Scalar>
22 const Matrix<Rows,X,Scalar>& lhs,
23 const Matrix<X,Cols,Scalar>& rhs
24) {
25 Matrix<Rows,Cols,Scalar> result;
26
27 for (int i=0; i < Rows; i++) {
28 for (int j=0; j < Cols; j++) {
29 result(i,j) = lhs(i,j) * rhs(i,j);
30 }
31 }
32
33 return result;
34}
35
36
37
38template<int Rows, int Cols, int X, typename Scalar>
40 const Matrix<Rows,X,Scalar>& lhs,
41 const Matrix<X,Cols,Scalar>& rhs
42) {
43 return multiply(lhs,rhs);
44}
45
46
47template<int Rows, int Cols, typename Scalar>
49 const Matrix<Rows,Cols,Scalar>& lhs,
51) {
52 for (int i=0; i < Rows; i++) {
53 for (int j=0; j < Cols; j++) {
54 if (lhs(i,j) != rhs(i,j)) {
55 return false;
56 }
57 }
58 }
59 return true;
60}
61
62
63
64template<int Rows, int Cols, typename Scalar>
66 const Matrix<Rows,Cols,Scalar>& lhs,
67 const Matrix<Rows,Cols,Scalar>& rhs,
68 const Scalar& tolerance
69) {
70 for (int i=0; i < Rows; i++) {
71 for (int j=0; j < Cols; j++) {
72 if (!equals(lhs(i,j), rhs(i,j), tolerance)) {
73 return false;
74 }
75 }
76 }
77 return true;
78}
79
80
81template<int Rows, int Cols, typename Scalar>
83 const Matrix<Rows,Cols,Scalar>& lhs,
84 const Matrix<Rows,Cols,Scalar>& rhs
85) {
87 #ifdef CompilerICC
88 #pragma ivdep
89 #endif
90 for (int i=0; i < Rows; i++) {
91 for (int j=0; j < Cols; j++) {
92 result(i,j) = lhs(i,j) + rhs(i,j);
93 }
94 }
95 return result;
96}
97
98
99template<int Rows, int Cols, typename Scalar>
101 const Matrix<Rows,Cols,Scalar>& lhs,
102 const Matrix<Rows,Cols,Scalar>& rhs
103) {
105 #ifdef CompilerICC
106 #pragma ivdep
107 #endif
108 for (int i=0; i < Rows; i++) {
109 for (int j=0; j < Cols; j++) {
110 result(i,j) = lhs(i,j) - rhs(i,j);
111 }
112 }
113 return result;
114}
115
116
117template<int Rows, int Cols, typename Scalar>
119 const Matrix<Rows,Cols,Scalar>& lhs,
120 const Matrix<Rows,Cols,Scalar>& rhs,
121 const Scalar& tolerance
122 ){
123 for (int i=0; i < Rows; i++) {
124 for (int j=0; j < Cols; j++) {
125 if( std::abs(lhs(i,j) - rhs(i,j))>tolerance) return std::pair<int,int>(i,j);
126 }
127 }
128 return std::pair<int,int>(-1,-1);
129}
And from this we can write down f$ nabla phi_i nabla phi_i dx but since we are constructing matrix let s investigate the f$ j
we integrate over each cell and then take the sum across each of the cells We also consider the terms that enter the f$ k
Static (i.e.
Definition Matrix.h:31
int i
Definition makeIC.py:51
Matrix< Rows, Cols, Scalar > multiply(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
Performs a matrix x matrix multiplication.
bool operator==(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
Bitwise comparison of the components of two matrices on equality.
Matrix< Rows, Cols, Scalar > operator-(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
Matrix< Rows, Cols, Scalar > operator+(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
Matrix< Rows, Cols, Scalar > operator*(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
std::pair< int, int > equalsReturnIndex(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Return Index of element which is not equals.
Matrix< Rows, Cols, Scalar > multiplyComponents(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)