GEOSX
fixedSizeSquareMatrixOps.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 #include "genericTensorOps.hpp"
17 
18 namespace LvArray
19 {
20 namespace tensorOps
21 {
22 
28 
36 template< std::ptrdiff_t M, typename MATRIX >
38 auto determinant( MATRIX const & matrix )
40 
51 template< std::ptrdiff_t M, typename DST_MATRIX, typename SRC_MATRIX >
53 auto invert( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
54  SRC_MATRIX const & LVARRAY_RESTRICT_REF srcMatrix )
55 {
56  static_assert( std::is_floating_point< std::decay_t< decltype( dstMatrix[ 0 ][ 0 ] ) > >::value,
57  "The destination matrix must be contain floating point values." );
58  return internal::SquareMatrixOps< M >::invert( std::forward< DST_MATRIX >( dstMatrix ), srcMatrix );
59 }
60 
69 template< std::ptrdiff_t M, typename MATRIX >
71 auto invert( MATRIX && matrix )
72 {
73  static_assert( std::is_floating_point< std::decay_t< decltype( matrix[ 0 ][ 0 ] ) > >::value,
74  "The matrix must be contain floating point values." );
75  return internal::SquareMatrixOps< M >::invert( std::forward< MATRIX >( matrix ) );
76 }
77 
79 
85 
98 template< std::ptrdiff_t M, typename DST_VECTOR, typename SYM_MATRIX_A, typename VECTOR_B >
100 void Ri_eq_symAijBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
101  SYM_MATRIX_A const & LVARRAY_RESTRICT_REF symMatrixA,
102  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
103 {
104  internal::SquareMatrixOps< M >::Ri_eq_symAijBj( std::forward< DST_VECTOR >( dstVector ),
105  symMatrixA,
106  vectorB );
107 }
108 
120 template< std::ptrdiff_t M, typename DST_VECTOR, typename SYM_MATRIX_A, typename VECTOR_B >
122 void Ri_add_symAijBj( DST_VECTOR && LVARRAY_RESTRICT_REF dstVector,
123  SYM_MATRIX_A const & LVARRAY_RESTRICT_REF symMatrixA,
124  VECTOR_B const & LVARRAY_RESTRICT_REF vectorB )
125 {
126  internal::SquareMatrixOps< M >::Ri_add_symAijBj( std::forward< DST_VECTOR >( dstVector ),
127  symMatrixA,
128  vectorB );
129 }
130 
143 template< std::ptrdiff_t M, typename DST_MATRIX, typename SYM_MATRIX_A, typename MATRIX_B >
145 void Rij_eq_symAikBjk( DST_MATRIX && LVARRAY_RESTRICT_REF dstMatrix,
146  SYM_MATRIX_A const & LVARRAY_RESTRICT_REF symMatrixA,
147  MATRIX_B const & LVARRAY_RESTRICT_REF matrixB )
148 {
149  internal::SquareMatrixOps< M >::Rij_eq_symAikBjk( std::forward< DST_MATRIX >( dstMatrix ),
150  symMatrixA,
151  matrixB );
152 }
153 
168 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename MATRIX_A, typename SYM_MATRIX_B >
170 void Rij_eq_AikSymBklAjl( DST_SYM_MATRIX && LVARRAY_RESTRICT_REF dstSymMatrix,
171  MATRIX_A const & LVARRAY_RESTRICT_REF matrixA,
172  SYM_MATRIX_B const & LVARRAY_RESTRICT_REF symMatrixB )
173 {
174  internal::SquareMatrixOps< M >::Rij_eq_AikSymBklAjl( std::forward< DST_SYM_MATRIX >( dstSymMatrix ),
175  matrixA,
176  symMatrixB );
177 }
178 
184 template< std::ptrdiff_t M, typename SYM_MATRIX >
186 auto symDeterminant( SYM_MATRIX const & symMatrix )
187 { return internal::SquareMatrixOps< M >::symDeterminant( symMatrix ); }
188 
199 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename SRC_SYM_MATRIX >
201 auto symInvert( DST_SYM_MATRIX && LVARRAY_RESTRICT_REF dstSymMatrix,
202  SRC_SYM_MATRIX const & LVARRAY_RESTRICT_REF srcSymMatrix )
203 {
204  static_assert( std::is_floating_point< std::decay_t< decltype( dstSymMatrix[ 0 ] ) > >::value,
205  "The destination matrix must be contain floating point values." );
206  return internal::SquareMatrixOps< M >::symInvert( std::forward< DST_SYM_MATRIX >( dstSymMatrix ), srcSymMatrix );
207 }
208 
217 template< std::ptrdiff_t M, typename SYM_MATRIX >
219 auto symInvert( SYM_MATRIX && symMatrix )
220 {
221  static_assert( std::is_floating_point< std::decay_t< decltype( symMatrix[ 0 ] ) > >::value,
222  "The matrix must be contain floating point values." );
223  return internal::SquareMatrixOps< M >::symInvert( std::forward< SYM_MATRIX >( symMatrix ) );
224 }
225 
240 template< std::ptrdiff_t M, typename DST_VECTOR, typename SYM_MATRIX >
242 void symEigenvalues( DST_VECTOR && LVARRAY_RESTRICT_REF eigenvalues,
243  SYM_MATRIX const & LVARRAY_RESTRICT_REF symMatrix )
244 {
245  static_assert( std::is_floating_point< std::decay_t< decltype( eigenvalues[ 0 ] ) > >::value,
246  "eigenvalues must be contain floating point values." );
247  internal::SquareMatrixOps< M >::symEigenvalues( std::forward< DST_VECTOR >( eigenvalues ), symMatrix );
248 }
249 
267 template< std::ptrdiff_t M, typename DST_VECTOR, typename DST_MATRIX, typename SYM_MATRIX >
269 void symEigenvectors( DST_VECTOR && LVARRAY_RESTRICT_REF eigenvalues,
270  DST_MATRIX && LVARRAY_RESTRICT_REF eigenvectors,
271  SYM_MATRIX const & LVARRAY_RESTRICT_REF symMatrix )
272 {
273  static_assert( std::is_floating_point< std::decay_t< decltype( eigenvalues[ 0 ] ) > >::value,
274  "eigenvalues must be contain floating point values." );
275  static_assert( std::is_floating_point< std::decay_t< decltype( eigenvectors[ 0 ][ 0 ] ) > >::value,
276  "eigenvectors must be contain floating point values." );
277  internal::SquareMatrixOps< M >::symEigenvectors( std::forward< DST_VECTOR >( eigenvalues ),
278  std::forward< DST_MATRIX >( eigenvectors ),
279  symMatrix );
280 }
281 
290 template< std::ptrdiff_t M, typename DST_SYM_MATRIX, typename SRC_MATRIX >
291 LVARRAY_HOST_DEVICE constexpr inline
292 void denseToSymmetric( DST_SYM_MATRIX && dstSymMatrix, SRC_MATRIX const & srcMatrix )
293 {
294  return internal::SquareMatrixOps< M >::denseToSymmetric( std::forward< DST_SYM_MATRIX >( dstSymMatrix ),
295  srcMatrix );
296 }
297 
306 template< std::ptrdiff_t M, typename DST_MATRIX, typename SRC_SYM_MATRIX >
307 LVARRAY_HOST_DEVICE constexpr inline
308 void symmetricToDense( DST_MATRIX && dstMatrix, SRC_SYM_MATRIX const & srcSymMatrix )
309 {
310  return internal::SquareMatrixOps< M >::symmetricToDense( std::forward< DST_MATRIX >( dstMatrix ),
311  srcSymMatrix );
312 }
313 
315 
316 } // namespace tensorOps
317 } // namespace LvArray
constexpr auto invert(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, SRC_MATRIX const &LVARRAY_RESTRICT_REF srcMatrix)
Invert the source matrix srcMatrix and store the result in dstMatrix.
constexpr void Ri_add_symAijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SYM_MATRIX_A const &LVARRAY_RESTRICT_REF symMatrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Multiply the vector vectorB by the symmetric matrix symMatrixA and add the result to dstVector...
constexpr auto determinant(MATRIX const &matrix)
Contains the implementation of arbitrary sized vector and matrix operations.
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
Expands to constexpr when array bound checking is disabled.
Definition: Macros.hpp:449
Contains the implementation of the 2x2 and 3x3 matrix operations.
constexpr void Ri_eq_symAijBj(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SYM_MATRIX_A const &LVARRAY_RESTRICT_REF symMatrixA, VECTOR_B const &LVARRAY_RESTRICT_REF vectorB)
Multiply the vector vectorB by the symmetric matrix symMatrixA and store the result in dstVector...
constexpr void Rij_eq_symAikBjk(DST_MATRIX &&LVARRAY_RESTRICT_REF dstMatrix, SYM_MATRIX_A const &LVARRAY_RESTRICT_REF symMatrixA, MATRIX_B const &LVARRAY_RESTRICT_REF matrixB)
Multiply the transpose of matrix matrixB by the symmetric matrix symMatrixA and store the result in d...
constexpr void symEigenvalues(DST_VECTOR &&LVARRAY_RESTRICT_REF eigenvalues, SYM_MATRIX const &LVARRAY_RESTRICT_REF symMatrix)
Compute the eigenvalues of the symmetric matrix symMatrix.
constexpr auto symInvert(SYM_MATRIX &&symMatrix)
Invert the symmetric matrix symMatrix overwritting it.
constexpr void symEigenvectors(DST_VECTOR &&LVARRAY_RESTRICT_REF eigenvalues, DST_MATRIX &&LVARRAY_RESTRICT_REF eigenvectors, SYM_MATRIX const &LVARRAY_RESTRICT_REF symMatrix)
Compute the eigenvalues and eigenvectors of the symmetric matrix symMatrix.
The top level namespace.
Definition: Array.hpp:24
constexpr void Rij_eq_AikSymBklAjl(DST_SYM_MATRIX &&LVARRAY_RESTRICT_REF dstSymMatrix, MATRIX_A const &LVARRAY_RESTRICT_REF matrixA, SYM_MATRIX_B const &LVARRAY_RESTRICT_REF symMatrixB)
Multiply the transpose of matrix matrixA by the symmetric matrix symMatrixB then by matrixA and store...
constexpr void denseToSymmetric(DST_SYM_MATRIX &&dstSymMatrix, SRC_MATRIX const &srcMatrix)
Convert the upper triangular part of srcMatrix to a symmetric matrix.
constexpr auto invert(MATRIX &&matrix)
Invert the matrix matrix overwritting it.
constexpr void symmetricToDense(DST_MATRIX &&dstMatrix, SRC_SYM_MATRIX const &srcSymMatrix)
Convert the srcSymMatrix into a dense matrix.
constexpr auto symInvert(DST_SYM_MATRIX &&LVARRAY_RESTRICT_REF dstSymMatrix, SRC_SYM_MATRIX const &LVARRAY_RESTRICT_REF srcSymMatrix)
Invert the symmetric matrix srcSymMatrix and store the result in dstSymMatrix.
constexpr auto symDeterminant(SYM_MATRIX const &symMatrix)
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:389