Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ddement committed Oct 22, 2024
1 parent 8defc03 commit d446ae1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 65 deletions.
17 changes: 9 additions & 8 deletions tests/unit_tests/math/test_matrix_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace openturbine::tests {

template <unsigned rows, unsigned cols>
Kokkos::View<double[rows][cols]> Create2DView(const std::array<double, rows*cols>& input) {
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);
Expand All @@ -23,10 +23,11 @@ inline void test_AX_Matrix() {
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());
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) {
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);
}
}
Expand All @@ -36,7 +37,6 @@ 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(
Expand All @@ -53,11 +53,12 @@ TEST(MatrixTest, AxialVectorOfMatrix) {
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());
const auto expected =
Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 3U; ++i) {
for (auto i = 0U; i < 3U; ++i) {
EXPECT_NEAR(v_mirror(i), expected(i), 1.e-15);
}
}

}
} // namespace openturbine::tests
118 changes: 68 additions & 50 deletions tests/unit_tests/math/test_quaternion_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ auto Create1DView(const std::array<double, size>& input) {
return view;
}

Kokkos::View<double[3][3]> TestQuaternionToRotationMatrix(const Kokkos::View<double[4]>::const_type& q) {
Kokkos::View<double[3][3]> TestQuaternionToRotationMatrix(
const Kokkos::View<double[4]>::const_type& q
) {
auto R_from_q = Kokkos::View<double[3][3]>("R_from_q");
Kokkos::parallel_for(
"QuaternionToRotationMatrix", 1,
Expand All @@ -32,9 +34,9 @@ TEST(QuaternionTest, ConvertQuaternionToRotationMatrix_90DegreeRotationAboutXAxi
Kokkos::deep_copy(R_from_q_mirror, R_from_q);
constexpr auto expected_data = std::array{1., 0., 0., 0., 0., -1., 0., 1., 0.};
const auto expected = Kokkos::View<const double[3][3], Kokkos::HostSpace>(expected_data.data());
for(auto i = 0U; i < 3U; ++i) {
for(auto j = 0U; j < 3U; ++j) {

for (auto i = 0U; i < 3U; ++i) {
for (auto j = 0U; j < 3U; ++j) {
EXPECT_NEAR(R_from_q_mirror(i, j), expected(i, j), 1.e-15);
}
}
Expand All @@ -50,9 +52,9 @@ TEST(QuaternionTest, ConvertQuaternionToRotationMatrix_90DegreeRotationAboutYAxi
Kokkos::deep_copy(R_from_q_mirror, R_from_q);
constexpr auto expected_data = std::array{0., 0., 1., 0., 1., 0., -1., 0., 0.};
const auto expected = Kokkos::View<const double[3][3], Kokkos::HostSpace>(expected_data.data());
for(auto i = 0U; i < 3U; ++i) {
for(auto j = 0U; j < 3U; ++j) {

for (auto i = 0U; i < 3U; ++i) {
for (auto j = 0U; j < 3U; ++j) {
EXPECT_NEAR(R_from_q_mirror(i, j), expected(i, j), 1.e-15);
}
}
Expand All @@ -68,15 +70,17 @@ TEST(QuaternionTest, ConvertQuaternionToRotationMatrix_90DegreeRotationAboutZAxi
Kokkos::deep_copy(R_from_q_mirror, R_from_q);
constexpr auto expected_data = std::array{0., -1., 0., 1., 0., 0., 0., 0., 1.};
const auto expected = Kokkos::View<const double[3][3], Kokkos::HostSpace>(expected_data.data());
for(auto i = 0U; i < 3U; ++i) {
for(auto j = 0U; j < 3U; ++j) {

for (auto i = 0U; i < 3U; ++i) {
for (auto j = 0U; j < 3U; ++j) {
EXPECT_NEAR(R_from_q_mirror(i, j), expected(i, j), 1.e-15);
}
}
}

Kokkos::View<double[3]> TestRotateVectorByQuaternion(const Kokkos::View<double[4]>::const_type& q, const Kokkos::View<double[3]>::const_type& v) {
Kokkos::View<double[3]> TestRotateVectorByQuaternion(
const Kokkos::View<double[4]>::const_type& q, const Kokkos::View<double[3]>::const_type& v
) {
auto v_rot = Kokkos::View<double[3]>("v_rot");
Kokkos::parallel_for(
"RotateVectorBoyQuaternion", 1, KOKKOS_LAMBDA(int) { RotateVectorByQuaternion(q, v, v_rot); }
Expand All @@ -90,13 +94,14 @@ TEST(QuaternionTest, RotateYAxisByIdentity) {

const auto v_rot = TestRotateVectorByQuaternion(rotation_identity, y_axis);

const auto v_rot_mirror =Kokkos::create_mirror(v_rot);
const auto v_rot_mirror = Kokkos::create_mirror(v_rot);
Kokkos::deep_copy(v_rot_mirror, v_rot);

constexpr auto expected_data = std::array{0., 1., 0.};
const auto expected = Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 3U; ++i) {
const auto expected =
Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for (auto i = 0U; i < 3U; ++i) {
EXPECT_NEAR(v_rot_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -107,13 +112,14 @@ TEST(QuaternionTest, RotateXAxis90DegreesAboutYAxis) {
auto x_axis = Create1DView<3>({1., 0., 0.});
const auto v_rot = TestRotateVectorByQuaternion(rotation_y_axis, x_axis);

const auto v_rot_mirror =Kokkos::create_mirror(v_rot);
const auto v_rot_mirror = Kokkos::create_mirror(v_rot);
Kokkos::deep_copy(v_rot_mirror, v_rot);

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) {
const auto expected =
Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for (auto i = 0U; i < 3U; ++i) {
EXPECT_NEAR(v_rot_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -124,13 +130,14 @@ TEST(QuaternionTest, RotateZAxis90DegreesAboutXAxis) {
auto z_axis = Create1DView<3>({0., 0., 1.});
const auto v_rot = TestRotateVectorByQuaternion(rotation_x_axis, z_axis);

const auto v_rot_mirror =Kokkos::create_mirror(v_rot);
const auto v_rot_mirror = Kokkos::create_mirror(v_rot);
Kokkos::deep_copy(v_rot_mirror, v_rot);

constexpr auto expected_data = std::array{0., -1., 0.};
const auto expected = Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 3U; ++i) {
const auto expected =
Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for (auto i = 0U; i < 3U; ++i) {
EXPECT_NEAR(v_rot_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -143,13 +150,14 @@ TEST(QuaternionTest, RotateXAxis45DegreesAboutZAxis) {
auto x_axis = Create1DView<3>({1., 0., 0.});
const auto v_rot = TestRotateVectorByQuaternion(rotation_z_axis, x_axis);

const auto v_rot_mirror =Kokkos::create_mirror(v_rot);
const auto v_rot_mirror = Kokkos::create_mirror(v_rot);
Kokkos::deep_copy(v_rot_mirror, v_rot);

const auto expected_data = std::array{inv_sqrt2, inv_sqrt2, 0.};
const auto expected = Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 3U; ++i) {
const auto expected =
Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for (auto i = 0U; i < 3U; ++i) {
EXPECT_NEAR(v_rot_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -162,13 +170,14 @@ TEST(QuaternionTest, RotateXAxisNeg45DegreesAboutZAxis) {
auto x_axis = Create1DView<3>({1., 0., 0.});
const auto v_rot = TestRotateVectorByQuaternion(rotation_z_axis, x_axis);

const auto v_rot_mirror =Kokkos::create_mirror(v_rot);
const auto v_rot_mirror = Kokkos::create_mirror(v_rot);
Kokkos::deep_copy(v_rot_mirror, v_rot);

const auto expected_data = std::array{inv_sqrt2, -inv_sqrt2, 0.};
const auto expected = Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 3U; ++i) {
const auto expected =
Kokkos::View<double[3], Kokkos::HostSpace>::const_type(expected_data.data());

for (auto i = 0U; i < 3U; ++i) {
EXPECT_NEAR(v_rot_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -189,10 +198,11 @@ TEST(QuaternionTest, QuaternionDerivative) {
Kokkos::deep_copy(derivative_mirror, derivative);

constexpr auto expected_data = std::array{-2., 1., -4., 3., -3., 4., 1., -2., -4., -3., 2., 1.};
const auto expected = Kokkos::View<double[3][4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[3][4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 3U; ++i) {
for(auto j = 0U; j < 4U; ++j) {
for (auto i = 0U; i < 3U; ++i) {
for (auto j = 0U; j < 4U; ++j) {
EXPECT_NEAR(derivative_mirror(i, j), expected(i, j), 1.e-15);
}
}
Expand All @@ -211,19 +221,22 @@ TEST(QuaternionTest, GetInverse) {
const auto q = Create1DView<4>({1. / coeff, 2. / coeff, 3. / coeff, 4. / coeff});

const auto q_inv = TestQuaternionInverse(q);

const auto q_inv_mirror = Kokkos::create_mirror(q_inv);
Kokkos::deep_copy(q_inv_mirror, q_inv);

const auto expected_data = std::array{1. / coeff, -2. / coeff, -3. / coeff, -4. / coeff};
const auto expected = Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 4U; ++i) {
for (auto i = 0U; i < 4U; ++i) {
EXPECT_NEAR(q_inv_mirror(i), expected(i), 1.e-15);
}
}

Kokkos::View<double[4]> TestQuaternionCompose(const Kokkos::View<double[4]>::const_type& q1, const Kokkos::View<double[4]>::const_type& q2) {
Kokkos::View<double[4]> TestQuaternionCompose(
const Kokkos::View<double[4]>::const_type& q1, const Kokkos::View<double[4]>::const_type& q2
) {
auto qn = Kokkos::View<double[4]>("qn");
Kokkos::parallel_for(
"QuaternionCompose", 1, KOKKOS_LAMBDA(int) { QuaternionCompose(q1, q2, qn); }
Expand All @@ -240,9 +253,10 @@ TEST(QuaternionTest, MultiplicationOfTwoQuaternions_Set1) {
Kokkos::deep_copy(qn_mirror, qn);

constexpr auto expected_data = std::array{8., -9., -2., 11.};
const auto expected = Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 4; ++i) {
for (auto i = 0U; i < 4; ++i) {
EXPECT_NEAR(qn_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -256,9 +270,10 @@ TEST(QuaternionTest, MultiplicationOfTwoQuaternions_Set2) {
Kokkos::deep_copy(qn_mirror, qn);

constexpr auto expected_data = std::array{-60., 12., 30., 24.};
const auto expected = Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 4; ++i) {
for (auto i = 0U; i < 4; ++i) {
EXPECT_NEAR(qn_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -281,9 +296,10 @@ TEST(QuaternionTest, RotationVectorToQuaternion_Set0) {
Kokkos::deep_copy(quaternion_mirror, quaternion);

const auto expected_data = std::array{inv_sqrt2, inv_sqrt2, 0., 0.};
const auto expected = Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 4U; ++i) {
for (auto i = 0U; i < 4U; ++i) {
EXPECT_NEAR(quaternion_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -297,9 +313,10 @@ TEST(QuaternionTest, RotationVectorToQuaternion_Set1) {
Kokkos::deep_copy(quaternion_mirror, quaternion);

const auto expected_data = std::array{inv_sqrt2, 0., inv_sqrt2, 0.};
const auto expected = Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 4U; ++i) {
for (auto i = 0U; i < 4U; ++i) {
EXPECT_NEAR(quaternion_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -313,9 +330,10 @@ TEST(QuaternionTest, RotationVectorToQuaternion_Set2) {
Kokkos::deep_copy(quaternion_mirror, quaternion);

const auto expected_data = std::array{inv_sqrt2, 0., 0., inv_sqrt2};
const auto expected = Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());
const auto expected =
Kokkos::View<double[4], Kokkos::HostSpace>::const_type(expected_data.data());

for(auto i = 0U; i < 4U; ++i) {
for (auto i = 0U; i < 4U; ++i) {
EXPECT_NEAR(quaternion_mirror(i), expected(i), 1.e-15);
}
}
Expand All @@ -336,10 +354,10 @@ void test_quaternion_to_rotation_vector_2() {
"RotationVectorToQuaternion", 1,
KOKKOS_LAMBDA(int) { QuaternionToRotationVector(q, phi2); }
);

const auto phi2_mirror = Kokkos::create_mirror(phi2);
Kokkos::deep_copy(phi2_mirror, phi2);
for(auto j = 0U; j < 3U; ++j) {
for (auto j = 0U; j < 3U; ++j) {
EXPECT_NEAR(phi2_mirror(j), rot_vec[j], 1.e-15);
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/unit_tests/math/test_vector_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace openturbine::tests {
template <unsigned size>
Kokkos::View<double[size]> Create1DView(const std::array<double, size>& input) {
auto view = Kokkos::View<double[size]>("view");
auto view_host = typename Kokkos::View<double[size], Kokkos::HostSpace>::const_type(input.data());
auto view_host =
typename Kokkos::View<double[size], Kokkos::HostSpace>::const_type(input.data());
Kokkos::deep_copy(view, view_host);
return view;
}
Expand All @@ -27,10 +28,11 @@ TEST(VectorTest, VecTilde) {
Kokkos::deep_copy(m_mirror, m);

constexpr auto expected_data = std::array{0., -3., 2., 3., 0., -1., -2., 1., 0.};
const auto expected = Kokkos::View<double[3][3], Kokkos::HostSpace>::const_type(expected_data.data());
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) {
for (auto i = 0U; i < 3U; ++i) {
for (auto j = 0U; j < 3U; ++j) {
EXPECT_NEAR(m_mirror(i, j), expected(i, j), 1.e-15);
}
}
Expand Down
10 changes: 7 additions & 3 deletions tests/unit_tests/utilities/test_turbine_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
namespace openturbine::tests {

TEST(ParserTest, ParseIEA15MWName) {
const std::string input = "name: IEA 15MW Offshore Reference Turbine, with taped chord tip design";
const std::string input =
"name: IEA 15MW Offshore Reference Turbine, with taped chord tip design";
const YAML::Node config = YAML::Load(input);
Turbine turbine;
turbine.parse(config);
ASSERT_EQ(turbine.name, "IEA 15MW Offshore Reference Turbine, with taped chord tip design");
}

TEST(ParserTest, ParseIEA15MWAssembly) {
const std::string input = "assembly:\n turbine_class: I\n turbulence_class: B\n drivetrain: direct_drive\n rotor_orientation: Upwind\n number_of_blades: 3\n hub_height: 150\n rotor_diameter: 241.94\n rated_power: 15.e+6\n lifetime: 25\n";
const std::string input =
"assembly:\n turbine_class: I\n turbulence_class: B\n drivetrain: direct_drive\n "
"rotor_orientation: Upwind\n number_of_blades: 3\n hub_height: 150\n rotor_diameter: "
"241.94\n rated_power: 15.e+6\n lifetime: 25\n";
const YAML::Node config = YAML::Load(input);
Turbine turbine;
turbine.parse(config);
Expand All @@ -30,7 +34,7 @@ TEST(ParserTest, ParseIEA15MWAssembly) {
}

TEST(ParserTest, ParseIEA15MWMultipleMaterials) {
const std::string input = "materials:\n [name: first, name: second]";
const std::string input = "materials:\n [name: first, name: second]";
const YAML::Node config = YAML::Load(input);
Turbine turbine;
turbine.parse(config);
Expand Down

0 comments on commit d446ae1

Please sign in to comment.