https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends | List of all members
ColumnMajorMatrixTempl< T > Class Template Reference

This class defines a Tensor that can change its shape. More...

#include <ColumnMajorMatrix.h>

Public Member Functions

 ColumnMajorMatrixTempl (const unsigned int rows=Moose::dim, const unsigned int cols=Moose::dim)
 Constructor that sets an initial number of entries and shape.
 
 ColumnMajorMatrixTempl (const ColumnMajorMatrixTempl< T > &rhs)
 Copy Constructor defined in terms of operator=()
 
 ColumnMajorMatrixTempl (const TypeTensor< T > &tensor)
 Constructor that fills in the ColumnMajorMatrixTempl with values from a libMesh TypeTensor.
 
 ColumnMajorMatrixTempl (const DenseMatrix< T > &rhs)
 
 ColumnMajorMatrixTempl (const DenseVector< T > &rhs)
 
 ColumnMajorMatrixTempl (const TypeVector< T > &col1, const TypeVector< T > &col2, const TypeVector< T > &col3)
 Constructor that takes in 3 vectors and uses them to create columns.
 
unsigned int numEntries () const
 The total number of entries in the Tensor.
 
void reshape (const unsigned int rows, const unsigned int cols)
 Change the shape of the tensor.
 
T & operator() (const unsigned int i, const unsigned int j=0)
 Get the i,j entry j defaults to zero so you can use it as a column vector.
 
operator() (const unsigned int i, const unsigned int j=0) const
 Get the i,j entry.
 
void print ()
 Print the tensor.
 
void print_scientific (std::ostream &os)
 Prints to file.
 
void fill (TypeTensor< T > &tensor)
 Fills the passed in tensor with the values from this tensor.
 
void fill (DenseMatrix< T > &rhs)
 Fills the passed in dense matrix with the values from this tensor.
 
void fill (DenseVector< T > &rhs)
 Fills the passed in dense vector with the values from this tensor.
 
ColumnMajorMatrixTempl< T > transpose () const
 Returns a matrix that is the transpose of the matrix this was called on.
 
ColumnMajorMatrixTempl< T > deviatoric ()
 Returns a matrix that is the deviatoric of the matrix this was called on.
 
ColumnMajorMatrixTempl< T > abs ()
 Returns a matrix that is the absolute value of the matrix this was called on.
 
void setDiag (T value)
 Set the value of each of the diagonals to the passed in value.
 
void addDiag (T value)
 Add to each of the diagonals the passsed in value.
 
tr () const
 The trace of the CMM.
 
void zero ()
 Zero the matrix.
 
void identity ()
 Turn the matrix into an identity matrix.
 
doubleContraction (const ColumnMajorMatrixTempl< T > &rhs) const
 Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)
 
norm ()
 The Euclidean norm of the matrix.
 
unsigned int n () const
 Returns the number of rows.
 
unsigned int m () const
 Returns the number of columns.
 
void eigen (ColumnMajorMatrixTempl< T > &eval, ColumnMajorMatrixTempl< T > &evec) const
 Returns eigen system solve for a symmetric real matrix.
 
void eigenNonsym (ColumnMajorMatrixTempl< T > &eval_real, ColumnMajorMatrixTempl< T > &eval_img, ColumnMajorMatrixTempl< T > &evec_right, ColumnMajorMatrixTempl< T > &eve_left) const
 Returns eigen system solve for a non-symmetric real matrix.
 
void exp (ColumnMajorMatrixTempl< T > &z) const
 Returns matrix that is the exponential of the matrix this was called on.
 
void inverse (ColumnMajorMatrixTempl< T > &invA) const
 Returns inverse of a general matrix.
 
T * rawData ()
 Returns a reference to the raw data pointer.
 
const T * rawData () const
 
ColumnMajorMatrixTempl< T > kronecker (const ColumnMajorMatrixTempl< T > &rhs) const
 Kronecker Product.
 
ColumnMajorMatrixTempl< T > & operator= (const TypeTensor< T > &rhs)
 Sets the values in this tensor to the values on the RHS.
 
ColumnMajorMatrixTempl< T > & operator= (const DenseMatrix< T > &rhs)
 Sets the values in this dense matrix to the values on the RHS.
 
ColumnMajorMatrixTempl< T > & operator= (const DenseVector< T > &rhs)
 Sets the values in this dense vector to the values on the RHS.
 
template<typename T2 >
ColumnMajorMatrixTempl< T > & operator= (const ColumnMajorMatrixTempl< T2 > &rhs)
 Sets the values in this tensor to the values on the RHS Will also reshape this tensor if necessary.
 
ColumnMajorMatrixTempl< T > & operator= (const ColumnMajorMatrixTempl< T > &rhs)=default
 defaulted operator=
 
ColumnMajorMatrixTempl< T > operator* (T scalar) const
 Scalar multiplication of the ColumnMajorMatrixTempl.
 
ColumnMajorMatrixTempl< T > operator* (const TypeVector< T > &rhs) const
 Matrix Vector Multiplication of the libMesh TypeVector Type.
 
ColumnMajorMatrixTempl< T > operator* (const ColumnMajorMatrixTempl< T > &rhs) const
 Matrix Matrix Multiplication.
 
ColumnMajorMatrixTempl< T > operator+ (const ColumnMajorMatrixTempl< T > &rhs) const
 Matrix Matrix Addition.
 
ColumnMajorMatrixTempl< T > operator- (const ColumnMajorMatrixTempl< T > &rhs) const
 Matrix Matrix Subtraction.
 
ColumnMajorMatrixTempl< T > & operator+= (const ColumnMajorMatrixTempl< T > &rhs)
 Matrix Matrix Addition plus assignment.
 
ColumnMajorMatrixTempl< T > & operator+= (const TypeTensor< T > &rhs)
 Matrix Tensor Addition Plus Assignment.
 
ColumnMajorMatrixTempl< T > & operator-= (const ColumnMajorMatrixTempl< T > &rhs)
 Matrix Matrix Subtraction plus assignment.
 
ColumnMajorMatrixTempl< T > operator+ (T scalar) const
 Scalar addition.
 
ColumnMajorMatrixTempl< T > & operator*= (T scalar)
 Scalar Multiplication plus assignment.
 
ColumnMajorMatrixTempl< T > & operator/= (T scalar)
 Scalar Division plus assignment.
 
ColumnMajorMatrixTempl< T > & operator+= (T scalar)
 Scalar Addition plus assignment.
 
void checkSquareness () const
 Check if matrix is square.
 
void checkShapeEquality (const ColumnMajorMatrixTempl< T > &rhs) const
 Check if matrices are of same shape.
 
bool operator== (const ColumnMajorMatrixTempl< T > &rhs) const
 Equality operators.
 
bool operator!= (const ColumnMajorMatrixTempl< T > &rhs) const
 
void eigen (ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &) const
 
void eigenNonsym (ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &, ColumnMajorMatrixTempl< ADReal > &) const
 
void inverse (ColumnMajorMatrixTempl< ADReal > &) const
 

Protected Attributes

unsigned int _n_rows
 
unsigned int _n_cols
 
unsigned int _n_entries
 
std::vector< T > _values
 

Friends

template<typename T2 >
void dataStore (std::ostream &, ColumnMajorMatrixTempl< T2 > &, void *)
 
template<typename T2 >
void dataLoad (std::istream &, ColumnMajorMatrixTempl< T2 > &, void *)
 

Detailed Description

template<typename T>
class ColumnMajorMatrixTempl< T >

This class defines a Tensor that can change its shape.

This means a 3x3x3x3 Tensor can be represented as a 9x9 or an 81x1. Further, the values of this tensor are COLUMN major ordered!

Definition at line 31 of file ColumnMajorMatrix.h.

Constructor & Destructor Documentation

◆ ColumnMajorMatrixTempl() [1/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const unsigned int  rows = Moose::dim,
const unsigned int  cols = Moose::dim 
)
explicit

Constructor that sets an initial number of entries and shape.

Defaults to creating the same size tensor as TensorValue

Definition at line 20 of file ColumnMajorMatrix.C.

21 : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
22{
23 _values.resize(rows * cols);
24}

◆ ColumnMajorMatrixTempl() [2/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const ColumnMajorMatrixTempl< T > &  rhs)

Copy Constructor defined in terms of operator=()

Definition at line 27 of file ColumnMajorMatrix.C.

28 : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
29{
30 *this = rhs;
31}

◆ ColumnMajorMatrixTempl() [3/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const TypeTensor< T > &  tensor)
explicit

Constructor that fills in the ColumnMajorMatrixTempl with values from a libMesh TypeTensor.

Definition at line 34 of file ColumnMajorMatrix.C.

35 : _n_rows(LIBMESH_DIM),
36 _n_cols(LIBMESH_DIM),
37 _n_entries(LIBMESH_DIM * LIBMESH_DIM),
38 _values(LIBMESH_DIM * LIBMESH_DIM)
39{
40 for (const auto j : make_range(Moose::dim))
41 for (const auto i : make_range(Moose::dim))
42 (*this)(i, j) = rhs(i, j);
43}
for(PetscInt i=0;i< nvars;++i)
unsigned int dim
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
IntRange< T > make_range(T beg, T end)

◆ ColumnMajorMatrixTempl() [4/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const DenseMatrix< T > &  rhs)
explicit

Definition at line 46 of file ColumnMajorMatrix.C.

47 : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
48{
49 *this = rhs;
50}

◆ ColumnMajorMatrixTempl() [5/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const DenseVector< T > &  rhs)
explicit

Definition at line 53 of file ColumnMajorMatrix.C.

54 : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
55{
56 *this = rhs;
57}

◆ ColumnMajorMatrixTempl() [6/6]

template<typename T >
ColumnMajorMatrixTempl< T >::ColumnMajorMatrixTempl ( const TypeVector< T > &  col1,
const TypeVector< T > &  col2,
const TypeVector< T > &  col3 
)

Constructor that takes in 3 vectors and uses them to create columns.

Definition at line 60 of file ColumnMajorMatrix.C.

63 : _n_rows(LIBMESH_DIM),
64 _n_cols(LIBMESH_DIM),
65 _n_entries(LIBMESH_DIM * LIBMESH_DIM),
66 _values(LIBMESH_DIM * LIBMESH_DIM)
67{
68 unsigned int entry = 0;
69 for (const auto i : make_range(Moose::dim))
70 _values[entry++] = col1(i);
71
72 for (const auto i : make_range(Moose::dim))
73 _values[entry++] = col2(i);
74
75 for (const auto i : make_range(Moose::dim))
76 _values[entry++] = col3(i);
77}

Member Function Documentation

◆ abs()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::abs ( )
inline

Returns a matrix that is the absolute value of the matrix this was called on.

Definition at line 311 of file ColumnMajorMatrix.C.

312{
313 using std::abs;
314 ColumnMajorMatrixTempl<T> & s = (*this);
315
317
318 for (unsigned int j = 0; j < _n_cols; j++)
319 for (unsigned int i = 0; i < _n_rows; i++)
320 ret_matrix(i, j) = abs(s(i, j));
321
322 return ret_matrix;
323}
This class defines a Tensor that can change its shape.
ColumnMajorMatrixTempl< T > abs()
Returns a matrix that is the absolute value of the matrix this was called on.

◆ addDiag()

template<typename T >
void ColumnMajorMatrixTempl< T >::addDiag ( value)
inline

Add to each of the diagonals the passsed in value.

Definition at line 496 of file ColumnMajorMatrix.h.

497{
498 this->checkSquareness();
499
500 for (unsigned int i = 0; i < _n_rows; i++)
501 (*this)(i, i) += value;
502}
void checkSquareness() const
Check if matrix is square.

◆ checkShapeEquality()

template<typename T >
void ColumnMajorMatrixTempl< T >::checkShapeEquality ( const ColumnMajorMatrixTempl< T > &  rhs) const

Check if matrices are of same shape.

Definition at line 295 of file ColumnMajorMatrix.C.

296{
297 if (_n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
298 mooseError("ColumnMajorMatrix error: Unable to perform the operation on matrices of different "
299 "shapes.");
300}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311

◆ checkSquareness()

template<typename T >
void ColumnMajorMatrixTempl< T >::checkSquareness ( ) const

Check if matrix is square.

Definition at line 287 of file ColumnMajorMatrix.C.

288{
289 if (_n_rows != _n_cols)
290 mooseError("ColumnMajorMatrix error: Unable to perform the operation on a non-square matrix.");
291}

Referenced by ColumnMajorMatrixTempl< T >::kronecker().

◆ deviatoric()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::deviatoric ( )
inline

Returns a matrix that is the deviatoric of the matrix this was called on.

Definition at line 469 of file ColumnMajorMatrix.h.

470{
471 ColumnMajorMatrixTempl<T> & s = (*this);
472
474
475 I.identity();
476
477 for (unsigned int i = 0; i < _n_rows; i++)
478 for (unsigned int j = 0; j < _n_cols; j++)
479 ret_matrix(i, j) = s(i, j) - I(i, j) * (s.tr() / 3.0);
480
481 return ret_matrix;
482}
T tr() const
The trace of the CMM.

◆ doubleContraction()

template<typename T >
T ColumnMajorMatrixTempl< T >::doubleContraction ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)

Definition at line 540 of file ColumnMajorMatrix.h.

541{
542 this->checkShapeEquality(rhs);
543
544 T value = 0;
545
546 for (unsigned int j = 0; j < _n_cols; j++)
547 for (unsigned int i = 0; i < _n_rows; i++)
548 value += (*this)(i, j) * rhs(i, j);
549
550 return value;
551}
void checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ eigen() [1/2]

Definition at line 166 of file ColumnMajorMatrix.C.

168{
169 mooseError("Eigen solves with AD types is not supported.");
170}

◆ eigen() [2/2]

template<typename T >
void ColumnMajorMatrixTempl< T >::eigen ( ColumnMajorMatrixTempl< T > &  eval,
ColumnMajorMatrixTempl< T > &  evec 
) const

Returns eigen system solve for a symmetric real matrix.

Definition at line 135 of file ColumnMajorMatrix.C.

137{
138 this->checkSquareness();
139
140 char jobz = 'V';
141 char uplo = 'U';
142 PetscBLASInt n = _n_rows;
143 PetscBLASInt return_value = 0;
144
145 eval._n_rows = _n_rows;
146 eval._n_cols = 1;
147 eval._n_entries = _n_rows;
148 eval._values.resize(_n_rows);
149
150 evec = *this;
151
152 T * eval_data = eval.rawData();
153 T * evec_data = evec.rawData();
154
155 PetscBLASInt buffer_size = n * 64;
156 std::vector<T> buffer(buffer_size);
157
158 LAPACKsyev_(&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
159
160 if (return_value)
161 mooseError("error in lapack eigen solve");
162}
unsigned int n() const
Returns the number of rows.
T * rawData()
Returns a reference to the raw data pointer.

◆ eigenNonsym() [1/2]

Definition at line 228 of file ColumnMajorMatrix.C.

232{
233 mooseError("Eigen solves with AD types is not supported.");
234}

◆ eigenNonsym() [2/2]

template<typename T >
void ColumnMajorMatrixTempl< T >::eigenNonsym ( ColumnMajorMatrixTempl< T > &  eval_real,
ColumnMajorMatrixTempl< T > &  eval_img,
ColumnMajorMatrixTempl< T > &  evec_right,
ColumnMajorMatrixTempl< T > &  eve_left 
) const

Returns eigen system solve for a non-symmetric real matrix.

Definition at line 174 of file ColumnMajorMatrix.C.

178{
179 this->checkSquareness();
180
182
183 char jobvl = 'V';
184 char jobvr = 'V';
185 PetscBLASInt n = _n_rows;
186 PetscBLASInt return_value = 0;
187
188 eval_real._n_rows = _n_rows;
189 eval_real._n_cols = 1;
190 eval_real._n_entries = _n_rows;
191 eval_real._values.resize(_n_rows);
192
193 eval_img._n_rows = _n_rows;
194 eval_img._n_cols = 1;
195 eval_img._n_entries = _n_rows;
196 eval_img._values.resize(_n_rows);
197
198 T * a_data = a.rawData();
199 T * eval_r = eval_real.rawData();
200 T * eval_i = eval_img.rawData();
201 T * evec_ri = evec_right.rawData();
202 T * evec_le = evec_left.rawData();
203
204 PetscBLASInt buffer_size = n * 64;
205 std::vector<T> buffer(buffer_size);
206
207 LAPACKgeev_(&jobvl,
208 &jobvr,
209 &n,
210 a_data,
211 &n,
212 eval_r,
213 eval_i,
214 evec_le,
215 &n,
216 evec_ri,
217 &n,
218 &buffer[0],
219 &buffer_size,
220 &return_value);
221
222 if (return_value)
223 mooseError("error in lapack eigen solve");
224}

Referenced by ColumnMajorMatrixTempl< T >::exp().

◆ exp()

template<typename T >
void ColumnMajorMatrixTempl< T >::exp ( ColumnMajorMatrixTempl< T > &  z) const

Returns matrix that is the exponential of the matrix this was called on.

Definition at line 238 of file ColumnMajorMatrix.C.

239{
240 using std::exp;
241 this->checkSquareness();
242
244 ColumnMajorMatrixTempl<T> evals_real(_n_rows, 1), evals_img(_n_rows, 1),
245 evals_real2(_n_rows, _n_cols);
246 ColumnMajorMatrixTempl<T> evec_right(_n_rows, _n_cols), evec_left(_n_rows, _n_cols);
247 ColumnMajorMatrixTempl<T> evec_right_inverse(_n_rows, _n_cols);
248
249 a.eigenNonsym(evals_real, evals_img, evec_right, evec_left);
250
251 for (unsigned int i = 0; i < _n_rows; i++)
252 evals_real2(i, i) = exp(evals_real(i, 0));
253
254 evec_right.inverse(evec_right_inverse);
255
256 z = evec_right * evals_real2 * evec_right_inverse;
257}
void exp(ColumnMajorMatrixTempl< T > &z) const
Returns matrix that is the exponential of the matrix this was called on.

◆ fill() [1/3]

template<typename T >
void ColumnMajorMatrixTempl< T >::fill ( DenseMatrix< T > &  rhs)
inline

Fills the passed in dense matrix with the values from this tensor.

Definition at line 430 of file ColumnMajorMatrix.h.

431{
432 if (rhs.n() * rhs.m() != _n_entries)
434 "Cannot fill dense matrix! The ColumnMajorMatrix doesn't have the same number of entries!");
435
436 for (unsigned int j = 0, index = 0; j < rhs.m(); ++j)
437 for (unsigned int i = 0; i < rhs.n(); ++i, ++index)
438 rhs(i, j) = _values[index];
439}
unsigned int n() const
unsigned int m() const

◆ fill() [2/3]

template<typename T >
void ColumnMajorMatrixTempl< T >::fill ( DenseVector< T > &  rhs)
inline

Fills the passed in dense vector with the values from this tensor.

Definition at line 443 of file ColumnMajorMatrix.h.

444{
445 if (_n_rows != rhs.size() || _n_cols != 1)
446 mooseError("ColumnMajorMatrix and DenseVector must be the same shape for a fill!");
447
448 for (unsigned int i = 0; i < _n_rows; ++i)
449 rhs(i) = (*this)(i);
450}
virtual unsigned int size() const override final

◆ fill() [3/3]

template<typename T >
void ColumnMajorMatrixTempl< T >::fill ( TypeTensor< T > &  tensor)
inline

Fills the passed in tensor with the values from this tensor.

Definition at line 417 of file ColumnMajorMatrix.h.

418{
421 "Cannot fill tensor! The ColumnMajorMatrix doesn't have the same number of entries!");
422
423 for (const auto j : libMesh::make_range(Moose::dim))
424 for (const auto i : libMesh::make_range(Moose::dim))
425 tensor(i, j) = _values[j * Moose::dim + i];
426}
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...

◆ identity()

template<typename T >
void ColumnMajorMatrixTempl< T >::identity ( )
inline

Turn the matrix into an identity matrix.

Definition at line 528 of file ColumnMajorMatrix.h.

529{
530 this->checkSquareness();
531
532 zero();
533
534 for (unsigned int i = 0; i < _n_rows; i++)
535 (*this)(i, i) = 1;
536}
void zero()
Zero the matrix.

Referenced by ColumnMajorMatrixTempl< T >::deviatoric().

◆ inverse() [1/2]

void ColumnMajorMatrixTempl< ADReal >::inverse ( ColumnMajorMatrixTempl< ADReal > &  ) const

Definition at line 304 of file ColumnMajorMatrix.C.

305{
306 mooseError("Inverse solves with AD types is not supported for the ColumnMajorMatrix class.");
307}

◆ inverse() [2/2]

template<typename T >
void ColumnMajorMatrixTempl< T >::inverse ( ColumnMajorMatrixTempl< T > &  invA) const

Returns inverse of a general matrix.

Definition at line 261 of file ColumnMajorMatrix.C.

262{
263 this->checkSquareness();
264 this->checkShapeEquality(invA);
265
266 PetscBLASInt n = _n_rows;
267 PetscBLASInt return_value = 0;
268
269 invA = *this;
270
271 std::vector<PetscBLASInt> ipiv(n);
272 T * invA_data = invA.rawData();
273
274 PetscBLASInt buffer_size = n * 64;
275 std::vector<T> buffer(buffer_size);
276
277 LAPACKgetrf_(&n, &n, invA_data, &n, &ipiv[0], &return_value);
278
279 LAPACKgetri_(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
280
281 if (return_value)
282 mooseException("Error in LAPACK matrix-inverse calculation");
283}

Referenced by ColumnMajorMatrixTempl< T >::exp().

◆ kronecker()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::kronecker ( const ColumnMajorMatrixTempl< T > &  rhs) const

Kronecker Product.

Definition at line 81 of file ColumnMajorMatrix.C.

82{
83 rhs.checkSquareness();
84
86
87 for (unsigned int i = 0; i < _n_rows; i++)
88 for (unsigned int j = 0; j < _n_cols; j++)
89 for (unsigned int k = 0; k < rhs._n_rows; k++)
90 for (unsigned int l = 0; l < rhs._n_cols; l++)
91 ret_matrix(((i * _n_rows) + k), ((j * _n_cols) + l)) = (*this)(i, j) * rhs(k, l);
92
93 return ret_matrix;
94}

◆ m()

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::m ( ) const
inline

◆ n()

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::n ( ) const
inline

◆ norm()

template<typename T >
T ColumnMajorMatrixTempl< T >::norm ( )
inline

The Euclidean norm of the matrix.

Definition at line 327 of file ColumnMajorMatrix.C.

328{
329 using std::sqrt;
330 return sqrt(doubleContraction(*this));
331}
T doubleContraction(const ColumnMajorMatrixTempl< T > &rhs) const
Double contraction of two matrices ie A : B = Sum(A_ab * B_ba)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh

◆ numEntries()

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::numEntries ( ) const
inline

The total number of entries in the Tensor.

i.e. cols * rows

Definition at line 340 of file ColumnMajorMatrix.h.

341{
342 return _n_entries;
343}

◆ operator!=()

template<typename T >
bool ColumnMajorMatrixTempl< T >::operator!= ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Definition at line 800 of file ColumnMajorMatrix.h.

801{
802 return !(*this == rhs);
803}

◆ operator()() [1/2]

template<typename T >
T & ColumnMajorMatrixTempl< T >::operator() ( const unsigned int  i,
const unsigned int  j = 0 
)
inline

Get the i,j entry j defaults to zero so you can use it as a column vector.

Definition at line 365 of file ColumnMajorMatrix.h.

366{
367 if ((i * j) >= _n_entries)
368 mooseError("Reference outside of ColumnMajorMatrix bounds!");
369
370 // Row major indexing!
371 return _values[(j * _n_rows) + i];
372}

◆ operator()() [2/2]

template<typename T >
T ColumnMajorMatrixTempl< T >::operator() ( const unsigned int  i,
const unsigned int  j = 0 
) const
inline

Get the i,j entry.

j defaults to zero so you can use it as a column vector. This is the version used for a const ColumnMajorMatrixTempl.

Definition at line 376 of file ColumnMajorMatrix.h.

377{
378 if ((i * j) >= _n_entries)
379 mooseError("Reference outside of ColumnMajorMatrix bounds!");
380
381 // Row major indexing!
382 return _values[(j * _n_rows) + i];
383}

◆ operator*() [1/3]

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator* ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Matrix Matrix Multiplication.

Definition at line 667 of file ColumnMajorMatrix.h.

668{
669 if (_n_cols != rhs._n_rows)
671 "Cannot perform matrix multiply! The shapes of the two operands are not compatible!");
672
674
675 for (unsigned int i = 0; i < ret_matrix._n_rows; ++i)
676 for (unsigned int j = 0; j < ret_matrix._n_cols; ++j)
677 for (unsigned int k = 0; k < _n_cols; ++k)
678 ret_matrix(i, j) += (*this)(i, k) * rhs(k, j);
679
680 return ret_matrix;
681}

◆ operator*() [2/3]

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator* ( const TypeVector< T > &  rhs) const
inline

Matrix Vector Multiplication of the libMesh TypeVector Type.

Definition at line 633 of file ColumnMajorMatrix.h.

634{
635 if (_n_cols != Moose::dim)
636 mooseError("Cannot perform matvec operation! The column dimension of "
637 "the ColumnMajorMatrix does not match the TypeVector!");
638
639 ColumnMajorMatrixTempl<T> ret_matrix(_n_rows, 1);
640
641 for (unsigned int i = 0; i < _n_rows; ++i)
642 for (unsigned int j = 0; j < _n_cols; ++j)
643 ret_matrix._values[i] += (*this)(i, j) * rhs(j);
644
645 return ret_matrix;
646}

◆ operator*() [3/3]

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator* ( scalar) const
inline

Scalar multiplication of the ColumnMajorMatrixTempl.

Definition at line 621 of file ColumnMajorMatrix.h.

622{
624
625 for (unsigned int i = 0; i < _n_entries; i++)
626 ret_matrix._values[i] = _values[i] * scalar;
627
628 return ret_matrix;
629}

◆ operator*=()

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator*= ( scalar)
inline

Scalar Multiplication plus assignment.

Definition at line 764 of file ColumnMajorMatrix.h.

765{
766 for (unsigned int i = 0; i < _n_entries; i++)
767 _values[i] *= scalar;
768 return *this;
769}

◆ operator+() [1/2]

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator+ ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Matrix Matrix Addition.

Definition at line 685 of file ColumnMajorMatrix.h.

686{
687 this->checkShapeEquality(rhs);
688
690
691 for (unsigned int i = 0; i < _n_entries; i++)
692 ret_matrix._values[i] = _values[i] + rhs._values[i];
693
694 return ret_matrix;
695}

◆ operator+() [2/2]

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator+ ( scalar) const
inline

Scalar addition.

Definition at line 752 of file ColumnMajorMatrix.h.

753{
755
756 for (unsigned int i = 0; i < _n_entries; i++)
757 ret_matrix._values[i] = _values[i] + scalar;
758
759 return ret_matrix;
760}

◆ operator+=() [1/3]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator+= ( const ColumnMajorMatrixTempl< T > &  rhs)
inline

Matrix Matrix Addition plus assignment.

Note that this is faster than regular addition because the result doesn't have to get copied out

Definition at line 713 of file ColumnMajorMatrix.h.

714{
715 this->checkShapeEquality(rhs);
716
717 for (unsigned int i = 0; i < _n_entries; i++)
718 _values[i] += rhs._values[i];
719
720 return *this;
721}

◆ operator+=() [2/3]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator+= ( const TypeTensor< T > &  rhs)
inline

Matrix Tensor Addition Plus Assignment.

Definition at line 725 of file ColumnMajorMatrix.h.

726{
727 if ((_n_rows != Moose::dim) || (_n_cols != Moose::dim))
728 mooseError("Cannot perform matrix addition and assignment! The shapes of the two operands are "
729 "not compatible!");
730
731 for (const auto j : libMesh::make_range(Moose::dim))
732 for (const auto i : libMesh::make_range(Moose::dim))
733 (*this)(i, j) += rhs(i, j);
734
735 return *this;
736}

◆ operator+=() [3/3]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator+= ( scalar)
inline

Scalar Addition plus assignment.

Definition at line 782 of file ColumnMajorMatrix.h.

783{
784 for (unsigned int i = 0; i < _n_entries; i++)
785 _values[i] += scalar;
786 return *this;
787}

◆ operator-()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::operator- ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Matrix Matrix Subtraction.

Definition at line 699 of file ColumnMajorMatrix.h.

700{
701 this->checkShapeEquality(rhs);
702
704
705 for (unsigned int i = 0; i < _n_entries; i++)
706 ret_matrix._values[i] = _values[i] - rhs._values[i];
707
708 return ret_matrix;
709}

◆ operator-=()

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator-= ( const ColumnMajorMatrixTempl< T > &  rhs)
inline

Matrix Matrix Subtraction plus assignment.

Note that this is faster than regular subtraction because the result doesn't have to get copied out

Definition at line 740 of file ColumnMajorMatrix.h.

741{
742 this->checkShapeEquality(rhs);
743
744 for (unsigned int i = 0; i < _n_entries; i++)
745 _values[i] -= rhs._values[i];
746
747 return *this;
748}

◆ operator/=()

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator/= ( scalar)
inline

Scalar Division plus assignment.

Definition at line 773 of file ColumnMajorMatrix.h.

774{
775 for (unsigned int i = 0; i < _n_entries; i++)
776 _values[i] /= scalar;
777 return *this;
778}

◆ operator=() [1/5]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const ColumnMajorMatrixTempl< T > &  rhs)
default

defaulted operator=

◆ operator=() [2/5]

template<typename T >
template<typename T2 >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const ColumnMajorMatrixTempl< T2 > &  rhs)
inline

Sets the values in this tensor to the values on the RHS Will also reshape this tensor if necessary.

Definition at line 608 of file ColumnMajorMatrix.h.

609{
610 this->reshape(rhs.m(), rhs.n());
611
612 for (MooseIndex(rhs.m()) i = 0; i < rhs.m(); ++i)
613 for (MooseIndex(rhs.n()) j = 0; j < rhs.n(); ++j)
614 (*this)(i, j) = rhs(i, j);
615
616 return *this;
617}
void reshape(const unsigned int rows, const unsigned int cols)
Change the shape of the tensor.
unsigned int m() const
Returns the number of columns.

◆ operator=() [3/5]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const DenseMatrix< T > &  rhs)

Sets the values in this dense matrix to the values on the RHS.

Will also reshape this tensor if necessary.

Definition at line 98 of file ColumnMajorMatrix.C.

99{
100 if (_n_rows != rhs.m() || _n_cols != rhs.n())
101 mooseError("ColumnMajorMatrix and DenseMatrix should be of the same shape.");
102
103 _n_rows = rhs.m();
104 _n_cols = rhs.n();
105 _n_entries = rhs.m() * rhs.n();
106 _values.resize(rhs.m() * rhs.n());
107
108 for (unsigned int j = 0; j < _n_cols; ++j)
109 for (unsigned int i = 0; i < _n_rows; ++i)
110 (*this)(i, j) = rhs(i, j);
111
112 return *this;
113}

◆ operator=() [4/5]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const DenseVector< T > &  rhs)

Sets the values in this dense vector to the values on the RHS.

Will also reshape this tensor if necessary.

Definition at line 117 of file ColumnMajorMatrix.C.

118{
119 if (_n_rows != rhs.size() || _n_cols != 1)
120 mooseError("ColumnMajorMatrix and DenseVector should be of the same shape.");
121
122 _n_rows = rhs.size();
123 _n_cols = 1;
124 _n_entries = rhs.size();
125 _values.resize(rhs.size());
126
127 for (unsigned int i = 0; i < _n_rows; ++i)
128 (*this)(i) = rhs(i);
129
130 return *this;
131}

◆ operator=() [5/5]

template<typename T >
ColumnMajorMatrixTempl< T > & ColumnMajorMatrixTempl< T >::operator= ( const TypeTensor< T > &  rhs)
inline

Sets the values in this tensor to the values on the RHS.

Will also reshape this tensor if necessary.

Definition at line 583 of file ColumnMajorMatrix.h.

584{
585 // Resize the tensor if necessary
587 {
589 _values.resize(_n_entries);
590 }
591
592 // Make sure the shape is correct
594
595 ColumnMajorMatrixTempl<T> & s = (*this);
596
597 // Copy the values
598 for (unsigned int j = 0; j < _n_cols; j++)
599 for (unsigned int i = 0; i < _n_cols; i++)
600 s(i, j) = rhs(i, j);
601
602 return *this;
603}

◆ operator==()

template<typename T >
bool ColumnMajorMatrixTempl< T >::operator== ( const ColumnMajorMatrixTempl< T > &  rhs) const
inline

Equality operators.

Definition at line 791 of file ColumnMajorMatrix.h.

792{
793 if (_n_entries != rhs._n_entries || _n_rows != rhs._n_rows || _n_cols != rhs._n_cols)
794 return false;
795 return std::equal(_values.begin(), _values.end(), rhs._values.begin());
796}

◆ print()

template<typename T >
void ColumnMajorMatrixTempl< T >::print ( )
inline

Print the tensor.

Definition at line 387 of file ColumnMajorMatrix.h.

388{
389 ColumnMajorMatrixTempl<T> & s = (*this);
390
391 for (unsigned int i = 0; i < _n_rows; i++)
392 {
393 for (unsigned int j = 0; j < _n_cols; j++)
394 Moose::out << std::setw(15) << s(i, j) << " ";
395
396 Moose::out << std::endl;
397 }
398}

◆ print_scientific()

template<typename T >
void ColumnMajorMatrixTempl< T >::print_scientific ( std::ostream &  os)
inline

Prints to file.

Definition at line 402 of file ColumnMajorMatrix.h.

403{
404 ColumnMajorMatrixTempl<T> & s = (*this);
405
406 for (unsigned int i = 0; i < _n_rows; i++)
407 {
408 for (unsigned int j = 0; j < _n_cols; j++)
409 os << std::setw(15) << std::scientific << std::setprecision(8) << s(i, j) << " ";
410
411 os << std::endl;
412 }
413}

◆ rawData() [1/2]

template<typename T >
T * ColumnMajorMatrixTempl< T >::rawData ( )
inline

Returns a reference to the raw data pointer.

Definition at line 569 of file ColumnMajorMatrix.h.

570{
571 return &_values[0];
572}

Referenced by ColumnMajorMatrixTempl< T >::eigen(), and ColumnMajorMatrixTempl< T >::inverse().

◆ rawData() [2/2]

template<typename T >
const T * ColumnMajorMatrixTempl< T >::rawData ( ) const
inline

Definition at line 576 of file ColumnMajorMatrix.h.

577{
578 return &_values[0];
579}

◆ reshape()

template<typename T >
void ColumnMajorMatrixTempl< T >::reshape ( const unsigned int  rows,
const unsigned int  cols 
)
inline

Change the shape of the tensor.

Note that cols * rows should be equal to numEntries()!

Definition at line 347 of file ColumnMajorMatrix.h.

348{
349 if (cols * rows == _n_entries)
350 {
351 _n_rows = rows;
352 _n_cols = cols;
353 }
354 else
355 {
356 _n_rows = rows;
357 _n_cols = cols;
359 _values.resize(_n_entries);
360 }
361}

Referenced by PiecewiseBilinear::parse(), and PiecewiseBilinear::PiecewiseBilinear().

◆ setDiag()

template<typename T >
void ColumnMajorMatrixTempl< T >::setDiag ( value)
inline

Set the value of each of the diagonals to the passed in value.

Definition at line 486 of file ColumnMajorMatrix.h.

487{
488 this->checkSquareness();
489
490 for (unsigned int i = 0; i < _n_rows; i++)
491 (*this)(i, i) = value;
492}

◆ tr()

template<typename T >
T ColumnMajorMatrixTempl< T >::tr ( ) const
inline

The trace of the CMM.

Definition at line 506 of file ColumnMajorMatrix.h.

507{
508 this->checkSquareness();
509
510 T trace = 0;
511
512 for (unsigned int i = 0; i < _n_rows; i++)
513 trace += (*this)(i, i);
514
515 return trace;
516}
Real trace(const RealTensor &A, const unsigned int &dim)

Referenced by ColumnMajorMatrixTempl< T >::deviatoric().

◆ transpose()

template<typename T >
ColumnMajorMatrixTempl< T > ColumnMajorMatrixTempl< T >::transpose ( ) const
inline

Returns a matrix that is the transpose of the matrix this was called on.

Definition at line 454 of file ColumnMajorMatrix.h.

455{
456 const ColumnMajorMatrixTempl<T> & s = (*this);
457
459
460 for (unsigned int i = 0; i < _n_rows; i++)
461 for (unsigned int j = 0; j < _n_cols; j++)
462 ret_matrix(j, i) = s(i, j);
463
464 return ret_matrix;
465}

◆ zero()

template<typename T >
void ColumnMajorMatrixTempl< T >::zero ( )
inline

Zero the matrix.

Definition at line 520 of file ColumnMajorMatrix.h.

521{
522 for (unsigned int i = 0; i < _n_entries; i++)
523 _values[i] = 0;
524}

Friends And Related Symbol Documentation

◆ dataLoad

template<typename T >
template<typename T2 >
void dataLoad ( std::istream &  ,
ColumnMajorMatrixTempl< T2 > &  ,
void *   
)
friend

◆ dataStore

template<typename T >
template<typename T2 >
void dataStore ( std::ostream &  ,
ColumnMajorMatrixTempl< T2 > &  ,
void *   
)
friend

Member Data Documentation

◆ _n_cols

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::_n_cols
protected

◆ _n_entries

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::_n_entries
protected

◆ _n_rows

template<typename T >
unsigned int ColumnMajorMatrixTempl< T >::_n_rows
protected

◆ _values

template<typename T >
std::vector<T> ColumnMajorMatrixTempl< T >::_values
protected

The documentation for this class was generated from the following files: