/home/runner/work/kynema/kynema/kynema/src/math/matrix_operations.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/math/matrix_operations.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
matrix_operations.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
5#include <Eigen/Geometry>
6#include <Kokkos_Core.hpp>
7
8namespace kynema::math {
9
16template <typename Matrix>
17KOKKOS_INLINE_FUNCTION void AX_Matrix(const Matrix& A, const Matrix& AX_A) {
18 double trace{0.};
19 for (auto i = 0; i < A.extent_int(0); ++i) {
20 trace += A(i, i);
21 }
22
23 trace /= 2.;
24
25 for (auto i = 0; i < A.extent_int(0); ++i) {
26 for (auto j = 0; j < A.extent_int(1); ++j) {
27 AX_A(i, j) = -A(i, j) / 2.;
28 }
29 AX_A(i, i) += trace;
30 }
31}
32
44template <typename Matrix, typename Vector>
45KOKKOS_INLINE_FUNCTION void AxialVectorOfMatrix(const Matrix& m, const Vector& v) {
46 v(0) = (m(2, 1) - m(1, 2)) / 2.;
47 v(1) = (m(0, 2) - m(2, 0)) / 2.;
48 v(2) = (m(1, 0) - m(0, 1)) / 2.;
49}
50
51inline std::array<std::array<double, 6>, 6> RotateMatrix6(
52 const std::array<std::array<double, 6>, 6>& m, const std::array<double, 4>& q
53) {
54 const auto quat = Eigen::Quaternion<double>(q[0], q[1], q[2], q[3]);
55 auto rm = quat.toRotationMatrix();
56
57 const auto m_mat = Eigen::Matrix<double, 6, 6>{
58 {m[0][0], m[0][1], m[0][2], m[0][3], m[0][4], m[0][5]},
59 {m[1][0], m[1][1], m[1][2], m[1][3], m[1][4], m[1][5]},
60 {m[2][0], m[2][1], m[2][2], m[2][3], m[2][4], m[2][5]},
61 {m[3][0], m[3][1], m[3][2], m[3][3], m[3][4], m[3][5]},
62 {m[4][0], m[4][1], m[4][2], m[4][3], m[4][4], m[4][5]},
63 {m[5][0], m[5][1], m[5][2], m[5][3], m[5][4], m[5][5]},
64 };
65
66 auto mt = Eigen::Matrix<double, 6, 6>();
67 mt.block<3, 6>(0, 0) = rm * m_mat.block<3, 6>(0, 0);
68 mt.block<3, 6>(3, 0) = rm * m_mat.block<3, 6>(3, 0);
69
70 rm.transposeInPlace();
71 auto mo = Eigen::Matrix<double, 6, 6>();
72 mo.block<6, 3>(0, 0) = mt.block<6, 3>(0, 0) * rm;
73 mo.block<6, 3>(0, 3) = mt.block<6, 3>(0, 3) * rm;
74
75 return std::array{
76 std::array{mo(0, 0), mo(0, 1), mo(0, 2), mo(0, 3), mo(0, 4), mo(0, 5)},
77 std::array{mo(1, 0), mo(1, 1), mo(1, 2), mo(1, 3), mo(1, 4), mo(1, 5)},
78 std::array{mo(2, 0), mo(2, 1), mo(2, 2), mo(2, 3), mo(2, 4), mo(2, 5)},
79 std::array{mo(3, 0), mo(3, 1), mo(3, 2), mo(3, 3), mo(3, 4), mo(3, 5)},
80 std::array{mo(4, 0), mo(4, 1), mo(4, 2), mo(4, 3), mo(4, 4), mo(4, 5)},
81 std::array{mo(5, 0), mo(5, 1), mo(5, 2), mo(5, 3), mo(5, 4), mo(5, 5)},
82 };
83}
84
85} // namespace kynema::math
Definition gl_quadrature.hpp:8
KOKKOS_INLINE_FUNCTION void AX_Matrix(const Matrix &A, const Matrix &AX_A)
Computes AX(A) of a square matrix.
Definition matrix_operations.hpp:17
std::array< std::array< double, 6 >, 6 > RotateMatrix6(const std::array< std::array< double, 6 >, 6 > &m, const std::array< double, 4 > &q)
Definition matrix_operations.hpp:51
KOKKOS_INLINE_FUNCTION void AxialVectorOfMatrix(const Matrix &m, const Vector &v)
Computes the axial vector (also known as the vector representation) of a 3x3 skew-symmetric matrix.
Definition matrix_operations.hpp:45