Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ddement committed Oct 29, 2024
1 parent d468796 commit 1092c9f
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 149 deletions.
6 changes: 3 additions & 3 deletions src/constraints/calculate_constraint_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <Kokkos_Core.hpp>

#include "constraint_type.hpp"

#include "calculate_revolute_joint_output.hpp"
#include "constraint_type.hpp"

namespace openturbine {

Expand All @@ -22,7 +21,8 @@ struct CalculateConstraintOutput {
void operator()(const int i_constraint) const {
switch (type(i_constraint)) {
case ConstraintType::kRevoluteJoint: {
CalculateRevoluteJointOutput{target_node_index, axes, node_x0, node_u, node_udot, node_uddot, outputs}(i_constraint);
CalculateRevoluteJointOutput{target_node_index, axes, node_x0, node_u,
node_udot, node_uddot, outputs}(i_constraint);
} break;
default: {
// Do nothing
Expand Down
3 changes: 1 addition & 2 deletions src/constraints/calculate_revolute_joint_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ struct CalculateRevoluteJointOutput {
outputs(i_constraint, 0) = angular_rotation;
outputs(i_constraint, 1) = angular_velocity;
outputs(i_constraint, 2) = angular_acceleration;

}
};

}
} // namespace openturbine
2 changes: 1 addition & 1 deletion src/constraints/constraints.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <array>
#include <vector>
#include <numeric>
#include <vector>

#include <Kokkos_Core.hpp>

Expand Down
53 changes: 34 additions & 19 deletions tests/unit_tests/constraints/test_calculate_fixed_bc_constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,52 @@ namespace openturbine::tests {
TEST(CalculateFixedBCConstraintTests, OneConstraint) {
const auto target_node_index = Kokkos::View<size_t[1]>("target_node_index");
constexpr auto target_node_index_host_data = std::array<size_t, 1>{1ul};
const auto target_node_index_host = Kokkos::View<size_t[1], Kokkos::HostSpace>::const_type(target_node_index_host_data.data());
const auto target_node_index_host =
Kokkos::View<size_t[1], Kokkos::HostSpace>::const_type(target_node_index_host_data.data());
Kokkos::deep_copy(target_node_index, target_node_index_host);

const auto X0 = Kokkos::View<double[1][3]>("X0");
constexpr auto X0_host_data = std::array{1., 2., 3.};
const auto X0_host = Kokkos::View<double[1][3], Kokkos::HostSpace>::const_type(X0_host_data.data());
const auto X0_host =
Kokkos::View<double[1][3], Kokkos::HostSpace>::const_type(X0_host_data.data());
const auto X0_mirror = Kokkos::create_mirror(X0);
Kokkos::deep_copy(X0_mirror, X0_host);
Kokkos::deep_copy(X0, X0_mirror);

const auto constraint_inputs = Kokkos::View<double[1][7]>("constraint_inputs");
constexpr auto constraint_inputs_host_data = std::array{4., 5., 6., 7., 8., 9., 10.};
const auto constraint_inputs_host = Kokkos::View<double[1][7], Kokkos::HostSpace>::const_type(constraint_inputs_host_data.data());
const auto constraint_inputs_host =
Kokkos::View<double[1][7], Kokkos::HostSpace>::const_type(constraint_inputs_host_data.data()
);
const auto constraint_inputs_mirror = Kokkos::create_mirror(constraint_inputs);
Kokkos::deep_copy(constraint_inputs_mirror, constraint_inputs_host);
Kokkos::deep_copy(constraint_inputs, constraint_inputs_mirror);
Kokkos::deep_copy(constraint_inputs, constraint_inputs_mirror);

const auto node_u = Kokkos::View<double[2][7]>("node_u");
constexpr auto node_u_host_data = std::array{0., 0., 0., 0., 0., 0., 0., 11., 12., 13., 14., 15., 16., 17.};
const auto node_u_host = Kokkos::View<double[2][7], Kokkos::HostSpace>::const_type(node_u_host_data.data());
constexpr auto node_u_host_data =
std::array{0., 0., 0., 0., 0., 0., 0., 11., 12., 13., 14., 15., 16., 17.};
const auto node_u_host =
Kokkos::View<double[2][7], Kokkos::HostSpace>::const_type(node_u_host_data.data());
const auto node_u_mirror = Kokkos::create_mirror(node_u);
Kokkos::deep_copy(node_u_mirror, node_u_host);
Kokkos::deep_copy(node_u, node_u_mirror);

const auto residual_terms = Kokkos::View<double[1][6]>("residual_terms");
const auto target_gradient_terms = Kokkos::View<double[1][6][6]>("target_gradient_terms");

Kokkos::parallel_for("CalculateFixedBCConstraint", 1, CalculateFixedBCConstraint{target_node_index, X0, constraint_inputs, node_u, residual_terms, target_gradient_terms});
Kokkos::parallel_for(
"CalculateFixedBCConstraint", 1,
CalculateFixedBCConstraint{
target_node_index, X0, constraint_inputs, node_u, residual_terms, target_gradient_terms
}
);

const auto residual_terms_mirror = Kokkos::create_mirror(residual_terms);
Kokkos::deep_copy(residual_terms_mirror, residual_terms);

constexpr auto residual_terms_exact_data = std::array{11., 12., 13., 420., 448., 476.};
const auto residual_terms_exact = Kokkos::View<double[1][6], Kokkos::HostSpace>::const_type(residual_terms_exact_data.data());
const auto residual_terms_exact =
Kokkos::View<double[1][6], Kokkos::HostSpace>::const_type(residual_terms_exact_data.data());

for (auto i = 0U; i < 6U; ++i) {
EXPECT_NEAR(residual_terms_mirror(0, i), residual_terms_exact(0, i), 1.e-15);
Expand All @@ -50,21 +62,24 @@ TEST(CalculateFixedBCConstraintTests, OneConstraint) {
const auto target_gradient_terms_mirror = Kokkos::create_mirror(target_gradient_terms);
Kokkos::deep_copy(target_gradient_terms_mirror, target_gradient_terms);

constexpr auto target_gradient_terms_exact_data = std::array{1., 0., 0., 0., 0., 0., //
0., 1., 0., 0., 0., 0., //
0., 0., 1., 0., 0., 0., //
0., 0., 0., -29., -478., -31., //
0., 0., 0., -2., -60., -482., //
0., 0., 0., -479., -62., -93.}; //
const auto target_gradient_terms_exact = Kokkos::View<double[1][6][6], Kokkos::HostSpace>::const_type(target_gradient_terms_exact_data.data());
constexpr auto target_gradient_terms_exact_data = std::array{1., 0., 0., 0., 0., 0., //
0., 1., 0., 0., 0., 0., //
0., 0., 1., 0., 0., 0., //
0., 0., 0., -29., -478., -31., //
0., 0., 0., -2., -60., -482., //
0., 0., 0., -479., -62., -93.}; //
const auto target_gradient_terms_exact =
Kokkos::View<double[1][6][6], Kokkos::HostSpace>::const_type(
target_gradient_terms_exact_data.data()
);

for (auto i = 0U; i < 6U; ++i) {
for (auto j = 0U; j < 6U; ++j) {
EXPECT_NEAR(target_gradient_terms_mirror(0, i, j), target_gradient_terms_exact(0, i, j), 1.e-15);
EXPECT_NEAR(
target_gradient_terms_mirror(0, i, j), target_gradient_terms_exact(0, i, j), 1.e-15
);
}
}


}

}
} // namespace openturbine::tests
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,54 @@ namespace openturbine::tests {
TEST(CalculatePrescribedBCConstraintTests, OneConstraint) {
const auto target_node_index = Kokkos::View<size_t[1]>("target_node_index");
constexpr auto target_node_index_host_data = std::array<size_t, 1>{1ul};
const auto target_node_index_host = Kokkos::View<size_t[1], Kokkos::HostSpace>::const_type(target_node_index_host_data.data());
const auto target_node_index_host =
Kokkos::View<size_t[1], Kokkos::HostSpace>::const_type(target_node_index_host_data.data());
Kokkos::deep_copy(target_node_index, target_node_index_host);

const auto X0 = Kokkos::View<double[1][3]>("X0");
constexpr auto X0_host_data = std::array{1., 2., 3.};
const auto X0_host = Kokkos::View<double[1][3], Kokkos::HostSpace>::const_type(X0_host_data.data());
const auto X0_host =
Kokkos::View<double[1][3], Kokkos::HostSpace>::const_type(X0_host_data.data());
const auto X0_mirror = Kokkos::create_mirror(X0);
Kokkos::deep_copy(X0_mirror, X0_host);
Kokkos::deep_copy(X0, X0_mirror);

const auto constraint_inputs = Kokkos::View<double[1][7]>("constraint_inputs");
constexpr auto constraint_inputs_host_data = std::array{4., 5., 6., 7., 8., 9., 10.};
const auto constraint_inputs_host = Kokkos::View<double[1][7], Kokkos::HostSpace>::const_type(constraint_inputs_host_data.data());
const auto constraint_inputs_host =
Kokkos::View<double[1][7], Kokkos::HostSpace>::const_type(constraint_inputs_host_data.data()
);
const auto constraint_inputs_mirror = Kokkos::create_mirror(constraint_inputs);
Kokkos::deep_copy(constraint_inputs_mirror, constraint_inputs_host);
Kokkos::deep_copy(constraint_inputs, constraint_inputs_mirror);
Kokkos::deep_copy(constraint_inputs, constraint_inputs_mirror);

const auto node_u = Kokkos::View<double[2][7]>("node_u");
constexpr auto node_u_host_data = std::array{0., 0., 0., 0., 0., 0., 0., 11., 12., 13., 14., 15., 16., 17.};
const auto node_u_host = Kokkos::View<double[2][7], Kokkos::HostSpace>::const_type(node_u_host_data.data());
constexpr auto node_u_host_data =
std::array{0., 0., 0., 0., 0., 0., 0., 11., 12., 13., 14., 15., 16., 17.};
const auto node_u_host =
Kokkos::View<double[2][7], Kokkos::HostSpace>::const_type(node_u_host_data.data());
const auto node_u_mirror = Kokkos::create_mirror(node_u);
Kokkos::deep_copy(node_u_mirror, node_u_host);
Kokkos::deep_copy(node_u, node_u_mirror);

const auto residual_terms = Kokkos::View<double[1][6]>("residual_terms");
const auto target_gradient_terms = Kokkos::View<double[1][6][6]>("target_gradient_terms");

Kokkos::parallel_for("CalculatePrescribedBCConstraint", 1, CalculatePrescribedBCConstraint{target_node_index, X0, constraint_inputs, node_u, residual_terms, target_gradient_terms});
Kokkos::parallel_for(
"CalculatePrescribedBCConstraint", 1,
CalculatePrescribedBCConstraint{
target_node_index, X0, constraint_inputs, node_u, residual_terms, target_gradient_terms
}
);

const auto residual_terms_mirror = Kokkos::create_mirror(residual_terms);
Kokkos::deep_copy(residual_terms_mirror, residual_terms);

constexpr auto residual_terms_exact_data = std::array{-790., -411., -620., -50.666666666666657, -7.1054273576010019e-15, -101.33333333333343};
const auto residual_terms_exact = Kokkos::View<double[1][6], Kokkos::HostSpace>::const_type(residual_terms_exact_data.data());
constexpr auto residual_terms_exact_data = std::array{
-790., -411., -620., -50.666666666666657, -7.1054273576010019e-15, -101.33333333333343
};
const auto residual_terms_exact =
Kokkos::View<double[1][6], Kokkos::HostSpace>::const_type(residual_terms_exact_data.data());

for (auto i = 0U; i < 6U; ++i) {
EXPECT_NEAR(residual_terms_mirror(0, i), residual_terms_exact(0, i), 1.e-15);
Expand All @@ -50,21 +64,28 @@ TEST(CalculatePrescribedBCConstraintTests, OneConstraint) {
const auto target_gradient_terms_mirror = Kokkos::create_mirror(target_gradient_terms);
Kokkos::deep_copy(target_gradient_terms_mirror, target_gradient_terms);

constexpr auto target_gradient_terms_exact_data = std::array{1., 0., 0., 0., 0., 0., //
0., 1., 0., 0., 0., 0., //
0., 0., 1., 0., 0., 0., //
0., 0., 0., 961.99999999999977, 50.666666666666714, -1.3333333333333379, //
0., 0., 0., -50.666666666666714, 962.6666666666664, 25.333333333333329, //
0., 0., 0., -1.3333333333333308, -25.333333333333329, 959.99999999999977}; //
const auto target_gradient_terms_exact = Kokkos::View<double[1][6][6], Kokkos::HostSpace>::const_type(target_gradient_terms_exact_data.data());
// clang-format off
constexpr auto target_gradient_terms_exact_data =
std::array{1., 0., 0., 0., 0., 0.,
0., 1., 0., 0., 0., 0.,
0., 0., 1., 0., 0., 0.,
0., 0., 0., 961.99999999999977, 50.666666666666714, -1.3333333333333379,
0., 0., 0., -50.666666666666714, 962.6666666666664, 25.333333333333329,
0., 0., 0., -1.3333333333333308, -25.333333333333329, 959.99999999999977
};
// clang-format on
const auto target_gradient_terms_exact =
Kokkos::View<double[1][6][6], Kokkos::HostSpace>::const_type(
target_gradient_terms_exact_data.data()
);

for (auto i = 0U; i < 6U; ++i) {
for (auto j = 0U; j < 6U; ++j) {
EXPECT_NEAR(target_gradient_terms_mirror(0, i, j), target_gradient_terms_exact(0, i, j), 1.e-15);
EXPECT_NEAR(
target_gradient_terms_mirror(0, i, j), target_gradient_terms_exact(0, i, j), 1.e-15
);
}
}


}

}
} // namespace openturbine::tests
Loading

0 comments on commit 1092c9f

Please sign in to comment.