-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved math regression test to be true unit tests.
Moved matrix operations out of the quaternion operations file for better organization
- Loading branch information
Showing
13 changed files
with
569 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
/// Computes AX(A) of a square matrix | ||
template <typename Matrix> | ||
KOKKOS_INLINE_FUNCTION void AX_Matrix(const Matrix& A, const Matrix& AX_A) { | ||
double trace = 0.; | ||
for (int i = 0; i < A.extent_int(0); ++i) { | ||
trace += A(i, i); | ||
} | ||
trace /= 2.; | ||
for (int i = 0; i < A.extent_int(0); ++i) { | ||
for (int j = 0; j < A.extent_int(1); ++j) { | ||
AX_A(i, j) = -A(i, j) / 2.; | ||
} | ||
AX_A(i, i) += trace; | ||
} | ||
} | ||
|
||
/// Computes the axial vector of a 3x3 rotation matrix | ||
template <typename Matrix, typename Vector> | ||
KOKKOS_INLINE_FUNCTION void AxialVectorOfMatrix(const Matrix& m, const Vector& v) { | ||
v(0) = (m(2, 1) - m(1, 2)) / 2.; | ||
v(1) = (m(0, 2) - m(2, 0)) / 2.; | ||
v(2) = (m(1, 0) - m(0, 1)) / 2.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Specify the source files for the unit test executable | ||
target_sources( | ||
openturbine_unit_tests | ||
PRIVATE | ||
test_matrix_operations.cpp | ||
test_quaternion_operations.cpp | ||
test_vector_operations.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <Kokkos_Core.hpp> | ||
#include <gtest/gtest.h> | ||
|
||
#include "src/math/matrix_operations.hpp" | ||
|
||
namespace openturbine::tests { | ||
|
||
template <unsigned rows, unsigned cols> | ||
Kokkos::View<double[rows][cols]> Create2DView(const std::array<double, rows*cols>& input) { | ||
auto view = Kokkos::View<double[rows][cols]>("view"); | ||
auto view_host = Kokkos::View<const double[rows][cols], Kokkos::HostSpace>(input.data()); | ||
auto view_mirror = Kokkos::create_mirror(view); | ||
Kokkos::deep_copy(view_mirror, view_host); | ||
Kokkos::deep_copy(view, view_mirror); | ||
return view; | ||
} | ||
|
||
inline void test_AX_Matrix() { | ||
const auto A = Create2DView<3, 3>({1., 2., 3., 4., 5., 6., 7., 8., 9.}); | ||
const auto out = Kokkos::View<double[3][3]>("out"); | ||
Kokkos::parallel_for(1, KOKKOS_LAMBDA(int) { AX_Matrix(A, out); }); | ||
const auto out_mirror = Kokkos::create_mirror(out); | ||
Kokkos::deep_copy(out_mirror, out); | ||
|
||
constexpr auto expected_data = std::array{7., -1., -1.5, -2., 5., -3., -3.5, -4., 3.}; | ||
const auto expected = Kokkos::View<double[3][3], Kokkos::HostSpace>::const_type(expected_data.data()); | ||
|
||
for(auto i = 0U; i < 3U; ++i) { | ||
for(auto j = 0U; j < 3U; ++j) { | ||
EXPECT_NEAR(out_mirror(i, j), expected(i, j), 1.e-15); | ||
} | ||
} | ||
} | ||
|
||
TEST(MatrixTest, AX_Matrix) { | ||
test_AX_Matrix(); | ||
} | ||
|
||
|
||
Kokkos::View<double[3]> TestAxialVectorOfMatrix(const Kokkos::View<const double[3][3]>& m) { | ||
auto v = Kokkos::View<double[3]>("v"); | ||
Kokkos::parallel_for( | ||
"AxialVectorOfMatrix", 1, KOKKOS_LAMBDA(int) { AxialVectorOfMatrix(m, v); } | ||
); | ||
return v; | ||
} | ||
|
||
TEST(MatrixTest, AxialVectorOfMatrix) { | ||
const auto m = Create2DView<3, 3>({0., -1., 0., 1., 0., 0., 0., 0., 0.}); | ||
const auto v = TestAxialVectorOfMatrix(m); | ||
|
||
const auto v_mirror = Kokkos::create_mirror(v); | ||
Kokkos::deep_copy(v_mirror, v); | ||
|
||
constexpr auto expected_data = std::array{0., 0., 1.}; | ||
const auto expected = Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data()); | ||
|
||
for(auto i = 0U; i < 3U; ++i) { | ||
EXPECT_NEAR(v_mirror(i), expected(i), 1.e-15); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.