2#include "baseexception.h"
30 using size_type = uint32;
33 Mat(size_type m, size_type n);
41 template <
unsigned SX,
unsigned SY>
49 double &operator()(size_type i, size_type j) {
return arr[arr_idx(i, j)]; }
51 const double &operator()(size_type i, size_type j)
const {
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 *(
double scal)
const;
60 Mat operator* (
const DVect2 &v)
const;
61 Mat operator* (
const DVect3 &v)
const;
62 void operator*=(
double s);
63 void operator/=(
double s);
64 void operator+=(
const Mat &mtx);
65 void operator-=(
const Mat &mtx);
68 void fill(
double val) { std::fill(arr, arr + len, val); }
69 void zero() { fill(0.0); }
71 Mat transpose()
const;
73 void scalMult(
double scal) {
auto *e = arr + len;
for (
auto *v = arr; v < e; ++v) *v *= scal; }
75 bool equals(
const Mat &mtx)
const;
76 bool exactEquals(
const Mat &mtx)
const;
77 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 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 Exception(
"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 Exception(
"Matrix ({} x {}) : index ({},{}) is out of bounds.", msize, nsize, i, j);
148 return nsize * (i)+j;
155 BASE_EXPORT string ts(
const itasca::Mat &m,
int width = 0,
char notation =
'\0',
int precision = -1,
char fill =
' ');
Comment point for memory allocation in all modules.
QString helper functions, plus some additions.
DMatrix is a Matrix that defaults to type double...
Definition matrix.h:758
Base exception class for all Itasca code.
Definition baseexception.h:10
A template-based matrix class, size fixed at compile time. Defaults to symmetric sized matrix.
Definition matrix.h:22
A symmetric 2nd order tensor.
Definition symtensor.h:22
constexpr Vector3< T > toVect3(const Vector2< T > &v, const T &t=0)
Conversion between vectors of different dimension.
Definition vect.h:341
constexpr const Vector2< T > & toVect2(const Vector2< T > &v)
Conversion between vectors of different dimension.
Definition vect.h:339
#define BASE_EXPORT
Definition basedef.h:24
A template-based matrix class, size fixed at compile time.
namespace Itasca
Definition basememory.cpp:10
A Symmetric 2nd order tensor.