PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::Matrix3 Struct Reference

A structure to represent 3d matrices. More...

#include <matrix.h>

Collaboration diagram for util::Matrix3:

Public Member Functions

 Matrix3 ()
 Constructor.
 
 Matrix3 (const util::Point &diagonal)
 Constructor.
 
 Matrix3 (const util::Point &a1, const util::Point &a2, const util::Point &a3)
 Constructor.
 
 Matrix3 (const std::vector< std::vector< double > > &m)
 Constructor.
 
 Matrix3 (const Matrix3 &m)
 Constructor.
 
std::string printStr (int nt=0, int lvl=0) const
 Prints the information.
 
void print (int nt=0, int lvl=0) const
 Prints the information.
 
Point operator() (size_t i)
 Returns row of matrix.
 
Point operator() (size_t i) const
 Returns row of matrix.
 
float & operator() (size_t i, size_t j)
 Returns element of matrix.
 
const float & operator() (size_t i, size_t j) const
 Returns element of matrix.
 
util::Point dot (const util::Point &v)
 Computes the dot product between matrix and vector.
 
std::vector< double > dot (const std::vector< double > &v) const
 Computes the dot product between matrix and vector.
 
Matrix3 transpose () const
 Computes the tranpose of matrix.
 
double det () const
 Computes the determinant of matrix.
 
Matrix3 inv () const
 Computes the determinant of matrix.
 

Data Fields

Data members
float d_data [3][3] {}
 data
 

Detailed Description

A structure to represent 3d matrices.

Definition at line 19 of file matrix.h.

Constructor & Destructor Documentation

◆ Matrix3() [1/5]

util::Matrix3::Matrix3 ( )
inline

Constructor.

Definition at line 34 of file matrix.h.

34 {
35
36 d_data[0][0] = 0.;
37 d_data[0][1] = 0.;
38 d_data[0][2] = 0.;
39
40 d_data[1][0] = 0.;
41 d_data[1][1] = 0.;
42 d_data[1][2] = 0.;
43
44 d_data[2][0] = 0.;
45 d_data[2][1] = 0.;
46 d_data[2][2] = 0.;
47 };
float d_data[3][3]
data
Definition matrix.h:27

References d_data.

Referenced by inv(), and transpose().

Here is the caller graph for this function:

◆ Matrix3() [2/5]

util::Matrix3::Matrix3 ( const util::Point diagonal)
inline

Constructor.

Parameters
diagonalDiagonal vector

Definition at line 54 of file matrix.h.

54 {
55
56 d_data[0][0] = diagonal.d_x;
57 d_data[0][1] = 0.;
58 d_data[0][2] = 0.;
59
60 d_data[1][0] = 0.;
61 d_data[1][1] = diagonal.d_y;
62 d_data[1][2] = 0.;
63
64 d_data[2][0] = 0.;
65 d_data[2][1] = 0.;
66 d_data[2][2] = diagonal.d_z;
67 };
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double d_x
the x coordinate
Definition point.h:33

References d_data, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

◆ Matrix3() [3/5]

util::Matrix3::Matrix3 ( const util::Point a1,
const util::Point a2,
const util::Point a3 
)
inline

Constructor.

Parameters
a1first row
a2second row
a3third row

Definition at line 76 of file matrix.h.

76 {
77
78 d_data[0][0] = a1.d_x;
79 d_data[0][1] = a1.d_y;
80 d_data[0][2] = a1.d_z,
81 d_data[1][0] = a2.d_x;
82 d_data[1][1] = a2.d_y;
83 d_data[1][2] = a2.d_z;
84 d_data[2][0] = a3.d_x;
85 d_data[2][1] = a3.d_y;
86 d_data[2][2] = a3.d_z;
87 };

References d_data, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

◆ Matrix3() [4/5]

util::Matrix3::Matrix3 ( const std::vector< std::vector< double > > &  m)
inline

Constructor.

Parameters
mMatrix in vector template

Definition at line 94 of file matrix.h.

94 {
95 for (size_t i=0; i<3; i++)
96 for (size_t j=0; j<3; j++)
97 d_data[i][j] = m[i][j];
98 }

References d_data.

◆ Matrix3() [5/5]

util::Matrix3::Matrix3 ( const Matrix3 m)
inline

Constructor.

Parameters
mMatrix in vector template

Definition at line 105 of file matrix.h.

105 {
106 for (size_t i=0; i<3; i++)
107 for (size_t j=0; j<3; j++)
108 d_data[i][j] = m(i,j);
109 }

References d_data.

Member Function Documentation

◆ det()

double util::Matrix3::det ( ) const
inline

Computes the determinant of matrix.

Returns
det Determinant

Definition at line 215 of file matrix.h.

215 {
216 return (*this)(0,0) * ((*this)(1,1) * (*this)(2,2) - (*this)(2,1) * (*this)(1,2)) -
217 (*this)(0,1) * ((*this)(1,0) * (*this)(2,2) - (*this)(2,0) * (*this)(1,2)) +
218 (*this)(0,2) * ((*this)(1,0) * (*this)(2,1) - (*this)(2,0) * (*this)(1,1));
219 }

Referenced by inv().

Here is the caller graph for this function:

◆ dot() [1/2]

std::vector< double > util::Matrix3::dot ( const std::vector< double > &  v) const
inline

Computes the dot product between matrix and vector.

Parameters
vvector
Returns
vector Dot product

Definition at line 180 of file matrix.h.

180 {
181
182 auto r = std::vector<double>(3,0.);
183 for (size_t i=0; i<3; i++)
184 for (size_t j=0; j<3; j++)
185 r[i] += (*this)(i,j) * v[j];
186
187 return r;
188 }

◆ dot() [2/2]

util::Point util::Matrix3::dot ( const util::Point v)
inline

Computes the dot product between matrix and vector.

Parameters
vvector
Returns
vector Dot product

Definition at line 174 of file matrix.h.

174 {
175
176 return {(*this)(0) * v, (*this)(1) * v, (*this)(2) * v};
177 }

◆ inv()

Matrix3 util::Matrix3::inv ( ) const
inline

Computes the determinant of matrix.

Returns
inv Inverse of m

Definition at line 226 of file matrix.h.

226 {
227
228 Matrix3 m = Matrix3();
229
230 auto det_inv = 1. / this->det();
231
232 m(0,0) = det_inv *
233 ((*this)(1,1) * (*this)(2,2) - (*this)(2,1) * (*this)(1,2));
234 m(0,1) = -det_inv *
235 ((*this)(0,1) * (*this)(2,2) - (*this)(2,1) * (*this)(0,2));
236 m(0,2) = det_inv *
237 ((*this)(0,1) * (*this)(1,2) - (*this)(1,1) * (*this)(0,2));
238
239 m(1,0) = -det_inv *
240 ((*this)(1,0) * (*this)(2,2) - (*this)(2,0) * (*this)(1,2));
241 m(1,1) = det_inv *
242 ((*this)(0,0) * (*this)(2,2) - (*this)(2,0) * (*this)(0,2));
243 m(1,2) = -det_inv *
244 ((*this)(0,0) * (*this)(1,2) - (*this)(1,0) * (*this)(0,2));
245
246 m(2,0) = det_inv *
247 ((*this)(1,0) * (*this)(2,1) - (*this)(2,0) * (*this)(1,1));
248 m(2,1) = -det_inv *
249 ((*this)(0,0) * (*this)(2,1) - (*this)(2,0) * (*this)(0,1));
250 m(2,2) = det_inv *
251 ((*this)(0,0) * (*this)(1,1) - (*this)(1,0) * (*this)(0,1));
252
253 return m;
254 }
Matrix3()
Constructor.
Definition matrix.h:34
double det() const
Computes the determinant of matrix.
Definition matrix.h:215

References det(), and Matrix3().

Here is the call graph for this function:

◆ operator()() [1/4]

Point util::Matrix3::operator() ( size_t  i)
inline

Returns row of matrix.

Parameters
iRow id
Returns
Row Row

Definition at line 147 of file matrix.h.

147 {
148 return Point(d_data[i]);
149 }

References d_data.

◆ operator()() [2/4]

Point util::Matrix3::operator() ( size_t  i) const
inline

Returns row of matrix.

Parameters
iRow id
Returns
Row Row

Definition at line 152 of file matrix.h.

152 {
153 return Point(d_data[i]);
154 }

References d_data.

◆ operator()() [3/4]

float & util::Matrix3::operator() ( size_t  i,
size_t  j 
)
inline

Returns element of matrix.

Parameters
iRow id
jColumn id
Returns
Element Element of matrix

Definition at line 163 of file matrix.h.

163{ return d_data[i][j]; }

References d_data.

◆ operator()() [4/4]

const float & util::Matrix3::operator() ( size_t  i,
size_t  j 
) const
inline

Returns element of matrix.

Parameters
iRow id
jColumn id
Returns
Element Element of matrix

Definition at line 166 of file matrix.h.

166{ return d_data[i][j]; }

References d_data.

◆ print()

void util::Matrix3::print ( int  nt = 0,
int  lvl = 0 
) const
inline

Prints the information.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Definition at line 139 of file matrix.h.

139{ std::cout << printStr(nt, lvl); }
std::string printStr(int nt=0, int lvl=0) const
Prints the information.
Definition matrix.h:118

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string util::Matrix3::printStr ( int  nt = 0,
int  lvl = 0 
) const
inline

Prints the information.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string Formatted string

Definition at line 118 of file matrix.h.

118 {
119
120 std::string tabS = "";
121 for (int i = 0; i < nt; i++)
122 tabS += "\t";
123
124 std::ostringstream oss;
125 for (size_t i=0; i<3; i++)
126 oss << tabS << "[" << (*this)(i, 0) << ", " << (*this)(i, 1) << ", "
127 << (*this)(i, 2) << "]" << std::endl;
128 oss << std::endl;
129
130 return oss.str();
131 }

Referenced by print().

Here is the caller graph for this function:

◆ transpose()

Matrix3 util::Matrix3::transpose ( ) const
inline

Computes the tranpose of matrix.

Returns
Matrix Transpose of m

Definition at line 194 of file matrix.h.

194 {
195
196 Matrix3 m = Matrix3(*this);
197
198 m(0,1) = (*this)(1,0);
199 m(0,2) = (*this)(2,0);
200
201 m(1,0) = (*this)(0,1);
202 m(1,2) = (*this)(2,1);
203
204 m(2,0) = (*this)(0,2);
205 m(2,1) = (*this)(1,2);
206
207 return m;
208 }

References Matrix3().

Here is the call graph for this function:

Field Documentation

◆ d_data

float util::Matrix3::d_data[3][3] {}

data

Definition at line 27 of file matrix.h.

27{};

Referenced by Matrix3(), Matrix3(), Matrix3(), Matrix3(), Matrix3(), operator()(), operator()(), operator()(), and operator()().


The documentation for this struct was generated from the following file: