13 #include "libmesh/petsc_macro.h" 17 #include <petscblaslapack.h> 21 : _n_rows(rows), _n_cols(cols), _n_entries(rows * cols), _values(rows * cols, 0.0)
28 : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
35 : _n_rows(LIBMESH_DIM),
37 _n_entries(LIBMESH_DIM * LIBMESH_DIM),
38 _values(LIBMESH_DIM * LIBMESH_DIM)
42 (*this)(i, j) = rhs(i, j);
47 : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
54 : _n_rows(LIBMESH_DIM), _n_cols(LIBMESH_DIM), _n_entries(_n_cols * _n_cols)
61 const TypeVector<T> & col2,
62 const TypeVector<T> & col3)
63 : _n_rows(LIBMESH_DIM),
65 _n_entries(LIBMESH_DIM * LIBMESH_DIM),
66 _values(LIBMESH_DIM * LIBMESH_DIM)
68 unsigned int entry = 0;
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);
100 if (_n_rows != rhs.m() || _n_cols != rhs.n())
101 mooseError(
"ColumnMajorMatrix and DenseMatrix should be of the same shape.");
105 _n_entries = rhs.m() * rhs.n();
106 _values.resize(rhs.m() * rhs.n());
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);
115 template <
typename T>
119 if (_n_rows != rhs.size() || _n_cols != 1)
120 mooseError(
"ColumnMajorMatrix and DenseVector should be of the same shape.");
122 _n_rows = rhs.size();
124 _n_entries = rhs.size();
125 _values.resize(rhs.size());
127 for (
unsigned int i = 0; i < _n_rows; ++i)
133 template <
typename T>
138 this->checkSquareness();
142 PetscBLASInt n = _n_rows;
143 PetscBLASInt return_value = 0;
152 T * eval_data = eval.
rawData();
153 T * evec_data = evec.
rawData();
155 PetscBLASInt buffer_size = n * 64;
156 std::vector<T> buffer(buffer_size);
158 LAPACKsyev_(&jobz, &uplo, &n, evec_data, &n, eval_data, &buffer[0], &buffer_size, &return_value);
169 mooseError(
"Eigen solves with AD types is not supported.");
172 template <
typename T>
179 this->checkSquareness();
185 PetscBLASInt n = _n_rows;
186 PetscBLASInt return_value = 0;
191 eval_real.
_values.resize(_n_rows);
196 eval_img.
_values.resize(_n_rows);
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();
204 PetscBLASInt buffer_size = n * 64;
205 std::vector<T> buffer(buffer_size);
233 mooseError(
"Eigen solves with AD types is not supported.");
236 template <
typename T>
240 this->checkSquareness();
244 evals_real2(_n_rows, _n_cols);
248 a.
eigenNonsym(evals_real, evals_img, evec_right, evec_left);
250 for (
unsigned int i = 0; i < _n_rows; i++)
251 evals_real2(i, i) =
std::exp(evals_real(i, 0));
253 evec_right.inverse(evec_right_inverse);
255 z = evec_right * evals_real2 * evec_right_inverse;
258 template <
typename T>
262 this->checkSquareness();
263 this->checkShapeEquality(invA);
265 PetscBLASInt n = _n_rows;
266 PetscBLASInt return_value = 0;
270 std::vector<PetscBLASInt> ipiv(n);
271 T * invA_data = invA.
rawData();
273 PetscBLASInt buffer_size = n * 64;
274 std::vector<T> buffer(buffer_size);
276 LAPACKgetrf_(&n, &n, invA_data, &n, &ipiv[0], &return_value);
278 LAPACKgetri_(&n, invA_data, &n, &ipiv[0], &buffer[0], &buffer_size, &return_value);
281 mooseException(
"Error in LAPACK matrix-inverse calculation");
284 template <
typename T>
288 if (_n_rows != _n_cols)
289 mooseError(
"ColumnMajorMatrix error: Unable to perform the operation on a non-square matrix.");
292 template <
typename T>
297 mooseError(
"ColumnMajorMatrix error: Unable to perform the operation on matrices of different " 305 mooseError(
"Inverse solves with AD types is not supported for the ColumnMajorMatrix class.");
308 template <
typename T>
316 for (
unsigned int j = 0; j < _n_cols; j++)
317 for (
unsigned int i = 0; i < _n_rows; i++)
318 ret_matrix(i, j) =
std::abs(s(i, j));
323 template <
typename T>
327 return std::sqrt(doubleContraction(*
this));
void inverse(ColumnMajorMatrixTempl< T > &invA) const
Returns inverse of a general matrix.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
This class defines a Tensor that can change its shape.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
ColumnMajorMatrixTempl< T > abs()
Returns a matrix that is the absolute value of the matrix this was called on.
T norm()
The Euclidean norm of the matrix.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
ColumnMajorMatrixTempl< T > kronecker(const ColumnMajorMatrixTempl< T > &rhs) const
Kronecker Product.
void eigen(ColumnMajorMatrixTempl< T > &eval, ColumnMajorMatrixTempl< T > &evec) const
Returns eigen system solve for a symmetric real matrix.
void checkSquareness() const
Check if matrix is square.
T * rawData()
Returns a reference to the raw data pointer.
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 checkShapeEquality(const ColumnMajorMatrixTempl< T > &rhs) const
Check if matrices are of same shape.
ColumnMajorMatrixTempl(const unsigned int rows=Moose::dim, const unsigned int cols=Moose::dim)
Constructor that sets an initial number of entries and shape.
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
IntRange< T > make_range(T beg, T end)
ColumnMajorMatrixTempl< T > & operator=(const TypeTensor< T > &rhs)
Sets the values in this tensor to the values on the RHS.
void exp(ColumnMajorMatrixTempl< T > &z) const
Returns matrix that is the exponential of the matrix this was called on.