2 #include "baseexception.h" 30 typedef uint32 size_type;
33 Mat(size_type m, size_type n);
39 Mat(
const DVect2 & v);
40 Mat(
const DVect3 & v);
41 template <
unsigned SX,
unsigned SY>
48 double& operator ()(size_type i, size_type j) {
49 return( arr[arr_idx(i,j)] ) ; }
50 const double& operator ()(size_type i, size_type j)
const {
51 return( arr[arr_idx(i,j)] ) ; }
53 Mat& operator =(
const Mat& mtx);
54 Mat& operator= (
Mat&& mtx);
56 Mat operator +(
const Mat& mtx)
const;
57 Mat operator -(
const Mat& mtx)
const;
58 Mat operator *(
const Mat& mtx)
const;
59 Mat operator *(
const double& scal)
const;
60 Mat operator* (
const DVect2 & v)
const;
61 Mat operator* (
const DVect3 & v)
const;
62 void operator*=(
const double &s);
63 void operator/=(
const double &s);
64 void operator+=(
const Mat &mtx);
65 void operator-=(
const Mat &mtx);
67 void fill(
const double& val) {
68 for( size_type i=0; i<len; ++i ) arr[i] = val; }
69 void zero() { fill( 0.0 ) ; }
71 Mat transpose()
const;
72 void scalMult(
const double& scal) {
73 for (size_type i=0; i<len; i++) arr[i] = scal*arr[i]; }
75 bool equals(
const Mat& mtx )
const;
76 bool operator== (
const Mat& mtx)
const {
return equals(mtx); }
78 virtual bool symmetric()
const;
79 virtual double maxNorm()
const;
80 UVect2 size()
const { UVect2 v(msize,nsize);
return v; }
82 UVect2 blockSize()
const { UVect2 v(blk_m,blk_n);
return v; }
83 void setBlockSize( size_type blk_msize, size_type blk_nsize ) { blk_m = blk_msize; blk_n = blk_nsize; }
84 void addBlock(
const Mat& src,
85 size_type src_bi, size_type src_bj,
86 size_type dst_bi, size_type dst_bj );
87 virtual void addGenBlock(
const Mat& src,
88 size_type src_i, size_type src_j,
89 size_type dst_i, size_type dst_j );
94 template <
unsigned SX,
unsigned SY>
96 double * data()
const {
return arr; }
98 double *arr =
nullptr;
99 size_type msize, nsize;
101 size_type blk_m=1, blk_n=1;
103 bool same(
const double* v1,
const double* v2 )
const;
104 inline virtual size_type arr_idx( size_type i, size_type j )
const;
107 template <
unsigned SX,
unsigned SY>
112 arr = NEWC(
double[SX*SY]);
113 for (uint32 i=0;i<SX;++i)
114 for (uint32 j=0;j<SY;++j)
115 operator()(i,j) = m(i,j);
118 template <
unsigned SX,
unsigned SY>
121 if (msize!=SX || nsize!=SY) {
122 if (msize==1 && SY==1 && nsize==SX) {
123 for (uint32 i=0;i<SX;++i)
124 ret(i,0) = operator()(0,i);
127 if (nsize==1 && SX==1 && msize==SY) {
128 for (uint32 i=0;i<SY;++i)
129 ret(0,i) = operator()(i,0);
132 throw iexception(
"Matrix size does not match {},{}, is {},{} instead.",SX,SY,msize,nsize);
134 for (uint32 i=0;i<SX;++i)
135 for (uint32 j=0;j<SY;++j)
136 ret(i,j) = operator()(i,j);
143 Mat::size_type Mat::arr_idx( size_type i, size_type j )
const {
145 if( (i >= msize) || (j >= nsize) )
146 throw iexception(
"Matrix ({} x {}) : index ({},{}) is out of bounds.", msize, nsize, i, j);
148 return nsize*(i) + j;
Comment point for memory allocation in all modules.
A Symmetric 2nd order tensor.
namespace Itasca
Definition: basememory.cpp:9
DMatrix is a Matrix that defaults to type double...
Definition: matrix.h:719
Base exception class for all Itasca code.
Definition: baseexception.h:9
const Vector2< T > & toVect2(const Vector2< T > &v)
Conversion between vectors of different dimension.
Definition: vect.h:337
#define BASE_EXPORT
Definition: basedef.h:21
A symmetric 2nd order tensor.
Definition: symtensor.h:19
A template-based matrix class, size fixed at compile time.
QString helper functions, plus some additions.
Vector3< T > toVect3(const Vector2< T > &v, const T &t=0)
Conversion between vectors of different dimension.
Definition: vect.h:339