ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
aslMatrices.h
Go to the documentation of this file.
1/*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
25
26#ifndef ASLMATRICES
27#define ASLMATRICES
28
29
30#include "../aslUtilities.h"
31#include "aslVectors.h"
32
33
34namespace asl
35{
38 template <typename T = double> class AMatr
39 {
40 private:
41 unsigned int nRow;
42 unsigned int nCol;
43 AVec<T> internalVec;
44 public:
45 inline AMatr();
46 inline AMatr(unsigned int nR, unsigned int nC);
47 inline AMatr(const AMatr<T> &a);
48 inline AMatr(unsigned int nR, unsigned int nC, AVec<T> v);
49 template <typename T1> AMatr(const AMatr<T1> &a);
50 const AMatr<T> & operator=(const AMatr & a);
52 inline T& operator()(int i, int j) {return internalVec[i*nCol+j];}
54 inline const T& operator()(int i, int j)const {return internalVec[i*nCol+j];}
56 inline T& operator[](int i) {return internalVec[i];}
58 inline const T& operator[](int i)const {return internalVec[i];}
59 inline unsigned int getNRow() const;
60 inline unsigned int getNCol() const;
61 inline void resize(unsigned int nR, unsigned int nCol);
62 inline const AVec<T> & getInternalVec() const;
64 void setRow(unsigned int r, const AVec<T> & a);
65 void setColumn(unsigned int c, const AVec<T> & a);
66 };
67
68
70 template <typename T> std::ostream& operator<<(std::ostream &f,const AMatr<T> & a);
72 template <typename T>
73 inline const AMatr<T> & operator+=(AMatr<T> & a, const AMatr<T> & b);
75 template <typename T>
76 inline const AMatr<T> operator+ (const AMatr<T> & a, const AMatr<T> & b);
78 template <typename T>
79 inline const AMatr<T> operator- (const AMatr<T> & a, const AMatr<T> & b);
81 template <typename T>
82 const AMatr<T> operator* (const AMatr<T> &a, const AMatr<T> & b);
83
85 template <typename T>
86 const AVec<T> operator* (const AMatr<T> &a, const AVec<T> & b);
87
89 template <typename T>
90 const AVec<T> operator* (const AVec<T> &a, const AMatr<T> & b);
91
93 template <typename T>
94 const AMatr<T> operator* (const AMatr<T> &a, const T & b);
95
97 template <typename T>
98 const AMatr<T> operator* (const T &a, const AMatr<T> & b);
99
101 template <typename T> const T trace(const AMatr<T> &a);
102
104 template <typename T> const T trace(const AMatr<T> & a, const AMatr<T> & b);
106 template <typename T>
107 inline const AMatr<T> operator/ (const AMatr<T> & b, const T & a);
108
110
127 template <typename T>
129
130
132 template <typename T> AMatr<T> makeAMatr(const AVec<T> & a);
133
135 template <typename T> AMatr<T> makeAMatr(const AVec<T> & a, const AVec<T> & b);
136
138 template <typename T> AMatr<T> makeAMatr(const AVec<T> & a,
139 const AVec<T> & b,
140 const AVec<T> & c);
141
143 template <typename T> AMatr<T> makeAMatr(AVec<T> *a, unsigned int n);
144
146 template <typename T=int>AMatr<T> makeAMatrUnit(unsigned int n);
147
148
150
154 template <typename T> AVec<T> getDiagonal(const AMatr<T> & a);
155
157
162 template <typename T> AVec<T> getOffDiagonalUp(const AMatr<T> & a);
163
165
168 template <typename T> T det(const AMatr<T> & m);
169
171
174 template <typename T> AVec<T> solveSystem(const AMatr<T> & a,
175 const AVec<T> & b);
176
178 template <typename T>
179 AMatr<T> replaceRow(const AMatr<T> & a, const AVec<T> & b, unsigned int r);
180
182 template <typename T>
183 AMatr<T> replaceColumn(const AMatr<T> & a, const AVec<T> & b, unsigned int c);
184
186 template <typename T>
188
189
190// ------------------------------ Implementation -----------------
191 template <typename T> inline AMatr<T>::AMatr():
192 nRow(0),
193 nCol(0)
194 {
195 }
196
197 template <typename T> inline AMatr<T>::AMatr(unsigned int nR, unsigned int nC):
198 nRow(nR),
199 nCol(nC),
200 internalVec(nR*nC)
201 {
202 }
203 template <typename T> inline AMatr<T>::AMatr(const AMatr<T> &a):
204 nRow(a.nRow),
205 nCol(a.nCol),
206 internalVec(a.internalVec)
207 {
208 }
209 template <typename T> inline AMatr<T>::AMatr(unsigned int nR, unsigned int nC, AVec<T> v):
210 nRow(nR),
211 nCol(nC),
212 internalVec(v)
213 {
214 }
215
216 template <typename T> inline AVec<T> & AMatr<T>::getInternalVec()
217 {
218 return internalVec;
219 }
220
221 template <typename T> inline const AVec<T> & AMatr<T>::getInternalVec() const
222 {
223 return internalVec;
224 }
225
226 template <typename T> inline unsigned int AMatr<T>::getNRow() const
227 {
228 return nRow;
229 }
230
231 template <typename T> inline unsigned int AMatr<T>::getNCol() const
232 {
233 return nCol;
234 }
235
236 template <typename T>
237 inline void AMatr<T>::resize(unsigned int nr, unsigned int nc)
238 {
239 nRow=nr;
240 nCol=nc;
241 internalVec.resize(nr*nc);
242 }
243
244 template <typename T>
245 inline const AMatr<T> & operator+=(AMatr<T> & a, const AMatr<T> & b)
246 {
247 a.getInternalVec += b.getInternalVec;
248 return a;
249 }
250
251 template <typename T>
252 inline const AMatr<T> operator+ (const AMatr<T> & a, const AMatr<T> & b)
253 {
254 return {a.getNRow(),a.getNCol(),a.getInternalVec() + b.getInternalVec()};
255 }
256
257 template <typename T>
258 inline const AMatr<T> operator- (const AMatr<T> & a,const AMatr<T> & b)
259 {
260 return {a.getNRow(),a.getNCol(),a.getInternalVec() - b.getInternalVec()};
261 }
262
263 template <typename T>
264 inline const AMatr<T> operator/ (const AMatr<T> & b, const T & a)
265 {
266 return {b.getNRow(), b.getNCol(), b.getInternalVec() / a};
267 }
268
270
290 void getEValEVecMatSym2x2(double a, double b, double c, double & l1, double & l2, double & v1x, double & v1y, double & v2x, double & v2y);
292
312 void getEValEVecMatSym2x2(double a, double b, double c, double & l1, double & l2, double & v1x, double & v1y, double & v2x, double & v2y);
313
315
345 void getEValEVecMatSym3x3(double a, double b, double c, double e, double f, double g,
346 double & l1, double & l2, double & l3,
347 double & v1x, double & v1y, double & v1z,
348 double & v2x, double & v2y, double & v2z,
349 double & v3x, double & v3y, double & v3z);
350
351} // asl
352
353#endif //ASLMATRICES
354
AMatr< T > makeAMatr(const AVec< T > &a, const AVec< T > &b)
generates a matrix with two rows
const T trace(const AMatr< T > &a, const AMatr< T > &b)
Trace of a matrix product .
void setColumn(unsigned int c, const AVec< T > &a)
const T & operator()(int i, int j) const
doesn't chek boundaries
Definition aslMatrices.h:54
AMatr< T > elementProduct(const AVec< T > &a, const AVec< T > &b)
element product of two vectors
const AVec< T > & getInternalVec() const
T & operator()(int i, int j)
doesn't chek boundaries
Definition aslMatrices.h:52
AVec< T > getOffDiagonalUp(const AMatr< T > &a)
returns AVec<T> containing the uper off diagonal elements
AMatr< T > inverseMatrix(const AMatr< T > &a)
returns inverse matrix for cases 2x2 and 3x3<T>
const T trace(const AMatr< T > &a)
Trace of a matrix .
const AMatr< T > & operator=(const AMatr &a)
std::ostream & operator<<(std::ostream &f, const AMatr< T > &a)
AMatr(unsigned int nR, unsigned int nC)
T & operator[](int i)
doesn't chek boundaries
Definition aslMatrices.h:56
AMatr(const AMatr< T > &a)
AMatr< T > replaceColumn(const AMatr< T > &a, const AVec< T > &b, unsigned int c)
generate matrix with content of the matrix a but with replaced column c by vector b<T>
AMatr(unsigned int nR, unsigned int nC, AVec< T > v)
AMatr(const AMatr< T1 > &a)
void setRow(unsigned int r, const AVec< T > &a)
T det(const AMatr< T > &m)
computes determinant expression fo cases 2x2 and 3x3 only
unsigned int getNCol() const
const T & operator[](int i) const
doesn't chek boundaries
Definition aslMatrices.h:58
AMatr< T > replaceRow(const AMatr< T > &a, const AVec< T > &b, unsigned int r)
generate matrix with content of the matrix a but with replaced row r by vector b<T>
unsigned int getNRow() const
void resize(unsigned int nR, unsigned int nCol)
AMatr< T > makeAMatr(const AVec< T > &a)
generates a matrix with a row
AMatr< T > makeAMatr(const AVec< T > &a, const AVec< T > &b, const AVec< T > &c)
generates a matrix with three rows
AVec< T > getDiagonal(const AMatr< T > &a)
returns AVec containing the diagonal elements
AVec< T > & getInternalVec()
AMatr< T > makeAMatrUnit(unsigned int n)
AMatr< T > makeAMatr(AVec< T > *a, unsigned int n)
generates a matrix with n rows
AVec< T > solveSystem(const AMatr< T > &a, const AVec< T > &b)
returns solution of a system of linear equations
SPDataWrapperACLData generateDataContainerACL_SP(const Block &b, unsigned int n=1)
generates pointer to ACL Data field with n components
SPDistanceFunction operator-(SPDistanceFunction a)
SPPositionFunction operator*(SPPositionFunction a, SPPositionFunction b)
Advanced Simulation Library.
Definition aslDataInc.h:31
const AMatr< T > operator+(const AMatr< T > &a, const AMatr< T > &b)
const AMatr< T > & operator+=(AMatr< T > &a, const AMatr< T > &b)
const T l2(const AVec< T > &a)
void getEValEVecMatSym3x3(double a, double b, double c, double e, double f, double g, double &l1, double &l2, double &l3, double &v1x, double &v1y, double &v1z, double &v2x, double &v2y, double &v2z, double &v3x, double &v3y, double &v3z)
Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2.
const AMatr< T > operator/(const AMatr< T > &b, const T &a)
void getEValEVecMatSym2x2(double a, double b, double c, double &l1, double &l2, double &v1x, double &v1y, double &v2x, double &v2y)
Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2.
definition of class АVec<T>