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)]; }
52 inline constexpr std::partial_ordering operator<=>(
const Mat &m)
const;
54 Mat &operator =(
const Mat &mtx);
55 Mat &operator= (
Mat &&mtx);
57 Mat operator +(
const Mat &mtx)
const;
58 Mat operator -(
const Mat &mtx)
const;
59 Mat operator *(
const Mat &mtx)
const;
60 Mat operator *(
double scal)
const;
61 Mat operator* (
const DVect2 &v)
const;
62 Mat operator* (
const DVect3 &v)
const;
63 void operator*=(
double s);
64 void operator/=(
double s);
65 void operator+=(
const Mat &mtx);
66 void operator-=(
const Mat &mtx);
69 void fill(
double val) { std::fill(arr, arr + len, val); }
70 void zero() { fill(0.0); }
72 Mat transpose()
const;
74 void scalMult(
double scal) {
auto *e = arr + len;
for (
auto *v = arr; v < e; ++v) *v *= scal; }
76 bool equals(
const Mat &mtx)
const;
77 bool exactEquals(
const Mat &mtx)
const;
78 bool operator== (
const Mat &mtx)
const {
return equals(mtx); }
79 virtual bool symmetric()
const;
80 virtual double maxNorm()
const;
81 UVect2 size()
const { UVect2 v(msize, nsize);
return v; }
83 UVect2 blockSize()
const { UVect2 v(blk_m, blk_n);
return v; }
84 void setBlockSize(size_type blk_msize, size_type blk_nsize) { blk_m = blk_msize; blk_n = blk_nsize; }
85 void addBlock(
const Mat &src,
86 size_type src_bi, size_type src_bj,
87 size_type dst_bi, size_type dst_bj);
88 virtual void addGenBlock(
const Mat &src,
89 size_type src_i, size_type src_j,
90 size_type dst_i, size_type dst_j);
95 template <
unsigned SX,
unsigned SY>
97 double *data()
const {
return arr; }
99 double *arr =
nullptr;
100 size_type msize, nsize;
102 size_type blk_m = 1, blk_n = 1;
104 bool same(
const double *v1,
const double *v2)
const;
105 inline size_type arr_idx(size_type i, size_type j)
const;
108 template <
unsigned SX,
unsigned SY>
113 arr = NEW
double[SX * SY];
114 for (uint32 i = 0; i < SX; ++i)
115 for (uint32 j = 0; j < SY; ++j)
116 operator()(i, j) = m(i, j);
119 template <
unsigned SX,
unsigned SY>
122 if (msize != SX || nsize != SY) {
123 if (msize == 1 && SY == 1 && nsize == SX) {
124 for (uint32 i = 0; i < SX; ++i)
125 ret(i, 0) = operator()(0, i);
128 if (nsize == 1 && SX == 1 && msize == SY) {
129 for (uint32 i = 0; i < SY; ++i)
130 ret(0, i) = operator()(i, 0);
133 throw Exception(
"Matrix size does not match {},{}, is {},{} instead.", SX, SY, msize, nsize);
135 for (uint32 i = 0; i < SX; ++i)
136 for (uint32 j = 0; j < SY; ++j)
137 ret(i, j) = operator()(i, j);
144 Mat::size_type Mat::arr_idx(size_type i, size_type j)
const {
146 if ((i >= msize) || (j >= nsize))
147 throw Exception(
"Matrix ({} x {}) : index ({},{}) is out of bounds.", msize, nsize, i, j);
149 return nsize * (i)+j;
152 constexpr std::partial_ordering Mat::operator<=>(
const Mat &m)
const {
153 auto c = size() <=> m.size();
154 if (c!=std::partial_ordering::equivalent)
return c;
156 for (size_type i=0;i<len;++i) {
157 auto j = arr[i] <=> m.arr[i];
158 if (j!=std::partial_ordering::equivalent)
return j;
160 return std::partial_ordering::equivalent;
166 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.
includes std::string and additional functions not included in the standard.
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:312
constexpr const Vector2< T > & toVect2(const Vector2< T > &v)
Conversion between vectors of different dimension.
Definition vect.h:310
#define BASE_EXPORT
Definition basedef.h:25
A template-based matrix class, size fixed at compile time.
namespace Itasca
Definition basememory.cpp:14
A Symmetric 2nd order tensor.