19#include <Kokkos_Core.hpp>
67 return Kokkos::sqrt(
norm);
73 return Kokkos::sqrt(v[0] * v[0] + v[1] * v[1]);
79 return Kokkos::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
128 if constexpr (
N_DIM == 2) {
134 const rtype ax = Kokkos::fabs(n[0]),
ay = Kokkos::fabs(n[1]),
az = Kokkos::fabs(n[2]);
139 t2[0] = n[1] *
t1[2] - n[2] *
t1[1];
140 t2[1] = n[2] *
t1[0] - n[0] *
t1[2];
141 t2[2] = n[0] *
t1[1] - n[1] *
t1[0];
178 Kokkos::abort(
"Matrix is singular.");
200 Kokkos::abort(
"Matrix is singular.");
205 const rtype c21 = -(
A[1] *
A[8] -
A[2] *
A[7]);
208 const rtype c31 =
A[1] *
A[5] -
A[2] *
A[4];
209 const rtype c32 = -(
A[0] *
A[5] -
A[2] *
A[3]);
282 if (C ==
A || C ==
B) {
291 Kokkos::abort(
"Invalid matrix dimensions.");
297 sum +=
A[
i*n + k] *
B[k*
q +
j];
302 }
else if (
tA && !
tB) {
304 Kokkos::abort(
"Invalid matrix dimensions.");
310 sum +=
A[k*n +
i] *
B[k*
q +
j];
315 }
else if (!
tA &&
tB) {
317 Kokkos::abort(
"Invalid matrix dimensions.");
323 sum +=
A[
i*n + k] *
B[
j*
q + k];
330 Kokkos::abort(
"Invalid matrix dimensions.");
336 sum +=
A[k*n +
i] *
B[
j*
q + k];
344 if (C ==
A || C ==
B) {
355 printf(
"%8.3f ",
static_cast<double>(
A[
i*n +
j]));
362 printf(
"%8.3f ",
static_cast<double>(
B[
i*
q +
j]));
392 R[
i*n +
j] =
A[
i*n +
j];
417 v[k] = R[(
j+k)*n +
j];
432 Q_j[
i*
m + k] = (
i == k) ? 1.0 : 0.0;
509 for (
int i =
m - 1;
i >= 0;
i--) {
513 for (
int k =
i + 1; k < end; k++) {
542 return 0.5
_r * Kokkos::fabs(
v0[0] * (
v1[1] -
v2[1]) +
567 J[0] =
v1[0] -
v0[0];
568 J[1] =
v2[0] -
v0[0];
569 J[2] =
v1[1] -
v0[1];
570 J[3] =
v2[1] -
v0[1];
588 J[0] =
v1[0] -
v0[0];
589 J[1] =
v2[0] -
v0[0];
590 J[2] =
v3[0] -
v0[0];
591 J[3] =
v1[1] -
v0[1];
592 J[4] =
v2[1] -
v0[1];
593 J[5] =
v3[1] -
v0[1];
594 J[6] =
v1[2] -
v0[2];
595 J[7] =
v2[2] -
v0[2];
596 J[8] =
v3[2] -
v0[2];
607 std::array<rtype, N>
max;
609 rtype max_i = std::numeric_limits<rtype>::lowest();
610 Kokkos::parallel_reduce(
a.extent(0),
616 Kokkos::Max<rtype>(
max_i));
630 std::array<rtype, N>
min;
632 rtype min_i = std::numeric_limits<rtype>::max();
633 Kokkos::parallel_reduce(
a.extent(0),
639 Kokkos::Min<rtype>(
min_i));
KOKKOS_INLINE_FUNCTION void gemv< 3 >(const rtype *A, const rtype *x, rtype *y)
Definition common_math.h:245
KOKKOS_INLINE_FUNCTION void tetrahedron_J(const rtype *v0, const rtype *v1, const rtype *v2, const rtype *v3, rtype *J)
Get the transformation matrix into a tetrahedron's local coordinates.
Definition common_math.h:583
KOKKOS_INLINE_FUNCTION rtype norm_2(const rtype *v)
Compute the 2-norm of a vector.
Definition common_math.h:62
KOKKOS_INLINE_FUNCTION rtype dot< 2 >(const rtype *a, const rtype *b)
Definition common_math.h:42
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
KOKKOS_INLINE_FUNCTION void invert_matrix< 2 >(const rtype *A, rtype *A_inv)
Definition common_math.h:174
KOKKOS_INLINE_FUNCTION rtype norm_2< 2 >(const rtype *v)
Definition common_math.h:72
KOKKOS_INLINE_FUNCTION void unit< 2 >(const rtype *v, rtype *u)
Definition common_math.h:102
KOKKOS_INLINE_FUNCTION void QR_householder_noQ(const rtype *A, rtype *R, const uint16_t m, const uint16_t n)
Compute the R part of the QR decomposition of a matrix.
Definition common_math.h:385
KOKKOS_INLINE_FUNCTION void unit(const rtype *v, rtype *u)
Compute the unit vector of a vector.
Definition common_math.h:89
KOKKOS_INLINE_FUNCTION void forward_substitution(const rtype *L, const rtype *B, rtype *X, const uint16_t m, const uint16_t n, const uint16_t p, const bool tL, const bool tB)
Perform forward substitution to solve a lower triangular system.
Definition common_math.h:466
KOKKOS_INLINE_FUNCTION void tangent_basis(const rtype *n, rtype *t1, rtype *t2)
Unit tangents completing the unit normal n to an orthonormal, right-handed basis: (n,...
Definition common_math.h:127
KOKKOS_INLINE_FUNCTION void gemm(const rtype *A, const rtype *B, rtype *C, const uint16_t m, const uint16_t n, const uint16_t p, const uint16_t q, const bool tA, const bool tB, const bool print_debug=false)
General matrix-matrix multiplication. Only intended for use with small matrices within kernels.
Definition common_math.h:270
KOKKOS_INLINE_FUNCTION rtype triangle_area(const rtype *v0, const rtype *v1, const rtype *v2)
Compute the area of a triangle from its vertices.
KOKKOS_INLINE_FUNCTION void invert_matrix(const rtype *A, rtype *A_inv)
Invert a matrix. Will be instantiated for 2x2 and 3x3 matrices.
KOKKOS_INLINE_FUNCTION void transpose(const rtype *A, rtype *AT, const uint16_t m, const uint16_t n)
Transpose a matrix. Only intended for use with small matrices within kernels.
Definition common_math.h:155
KOKKOS_INLINE_FUNCTION void gemv(const rtype *A, const rtype *x, rtype *y)
General matrix-vector multiplication. Will be instantiated for 2x2 and 3x3 matrices.
KOKKOS_INLINE_FUNCTION rtype dot< 3 >(const rtype *a, const rtype *b)
Definition common_math.h:49
KOKKOS_INLINE_FUNCTION void back_substitution(const rtype *U, const rtype *B, rtype *X, const uint16_t m, const uint16_t n, const uint16_t p, const bool tU, const bool tB)
Perform back substitution to solve an upper triangular system.
Definition common_math.h:501
KOKKOS_INLINE_FUNCTION void triangle_J(const rtype *v0, const rtype *v1, const rtype *v2, rtype *J)
Get the transformation matrix into a triangle's local coordinates.
Definition common_math.h:563
KOKKOS_INLINE_FUNCTION rtype triangle_area< 2 >(const rtype *v0, const rtype *v1, const rtype *v2)
Definition common_math.h:539
KOKKOS_INLINE_FUNCTION void invert_matrix< 3 >(const rtype *A, rtype *A_inv)
Definition common_math.h:191
KOKKOS_INLINE_FUNCTION rtype norm_2< 3 >(const rtype *v)
Definition common_math.h:78
std::array< rtype, N > max_array(Kokkos::View< rtype ** > a)
Compute the maximum of each element along the first dimension of a.
Definition common_math.h:606
KOKKOS_INLINE_FUNCTION void unit< 3 >(const rtype *v, rtype *u)
Definition common_math.h:110
std::array< rtype, N > min_array(Kokkos::View< rtype ** > a)
Compute the minimum of each element along the first dimension of a.
Definition common_math.h:629
KOKKOS_INLINE_FUNCTION void gemv< 2 >(const rtype *A, const rtype *x, rtype *y)
Definition common_math.h:236
Typedefs for common types.
float rtype
Definition common_typedef.h:39
#define N_DIM
Definition common_typedef.h:28
SlotArray< double, Space > X
Definition teno_setup.cpp:478
SlotArray< double, Space > A
Definition teno_setup.cpp:478