Skip to content

Commit

Permalink
Fixes errors when building for GPU.
Browse files Browse the repository at this point in the history
This commit also adds extra instrumentation to the new regression test
to time how much time is spent in ADI vs OpenTurbine.

It also sets ADI to not output VTK, which speeds up the test considerably.
  • Loading branch information
ddement committed Oct 18, 2024
1 parent 22157a2 commit 61e3559
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions tests/unit_tests/external/test_rotor_aero_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ namespace openturbine::tests {

constexpr bool use_node_loads = true;

KOKKOS_INLINE_FUNCTION Array_6 GetNodeData(const size_t index, const View_Nx6& state_matrix) {
Array_6 GetNodeData(const size_t index, const View_Nx6::HostMirror& state_matrix) {
return Array_6{
state_matrix(index, 0), state_matrix(index, 1), state_matrix(index, 2),
state_matrix(index, 3), state_matrix(index, 4), state_matrix(index, 5),
};
}

KOKKOS_INLINE_FUNCTION Array_7 GetNodeData(const size_t index, const View_Nx7& state_matrix) {
Array_7 GetNodeData(const size_t index, const View_Nx7::HostMirror& state_matrix) {
return Array_7{
state_matrix(index, 0), state_matrix(index, 1), state_matrix(index, 2),
state_matrix(index, 3), state_matrix(index, 4), state_matrix(index, 5),
Expand All @@ -50,16 +50,15 @@ KOKKOS_INLINE_FUNCTION Array_7 GetNodeData(const size_t index, const View_Nx7& s
}

template <typename T1, typename T2>
KOKKOS_INLINE_FUNCTION Array_6
GetQPData(const size_t i, const size_t j, const T1& translation_data, const T2& rotation_data) {
Array_6 GetQPData(const size_t i, const size_t j, const T1& translation_data, const T2& rotation_data) {
return Array_6{
translation_data(i, j, 0), translation_data(i, j, 1), translation_data(i, j, 2),
rotation_data(i, j, 0), rotation_data(i, j, 1), rotation_data(i, j, 2),
};
}

template <typename T1>
KOKKOS_INLINE_FUNCTION Array_7 GetQPData(const size_t i, const size_t j, const T1& position_matrix) {
Array_7 GetQPData(const size_t i, const size_t j, const T1& position_matrix) {
return Array_7{
position_matrix(i, j, 0), position_matrix(i, j, 1), position_matrix(i, j, 2),
position_matrix(i, j, 3), position_matrix(i, j, 4), position_matrix(i, j, 5),
Expand Down Expand Up @@ -184,7 +183,7 @@ TEST(Milestone, IEA15RotorAeroController) {
constexpr size_t max_iter{6};
constexpr double step_size{0.01}; // seconds
constexpr double rho_inf{0.0};
constexpr double t_end{1.0}; // seconds
constexpr double t_end{30.0}; // seconds
constexpr auto num_steps{static_cast<size_t>(t_end / step_size + 1.)};

// Create model for adding nodes and constraints
Expand Down Expand Up @@ -490,7 +489,7 @@ TEST(Milestone, IEA15RotorAeroController) {

// VTK settings
util::VTKSettings vtk_settings;
vtk_settings.write_vtk = util::VTKSettings::WriteType::kAnimation; // Animation
vtk_settings.write_vtk = util::VTKSettings::WriteType::kNone; // Animation
vtk_settings.vtk_type = util::VTKSettings::OutputType::kLine; // Lines
vtk_settings.vtk_nacelle_dimensions = {-2.5F, -2.5F, 0.F, 10.F, 5.F, 5.F};
vtk_settings.vtk_hub_radius = static_cast<float>(hub_radius);
Expand Down Expand Up @@ -560,6 +559,7 @@ TEST(Milestone, IEA15RotorAeroController) {

// Perform time steps and check for convergence within max_iter iterations
for (size_t i = 0; i < num_steps; ++i) {
auto time_step_region = Kokkos::Profiling::ScopedRegion("Time Step");
#ifdef OpenTurbine_ENABLE_VTK
auto tmp = std::to_string(i);
tmp.insert(0, 5 - tmp.size(), '0');
Expand All @@ -571,33 +571,37 @@ TEST(Milestone, IEA15RotorAeroController) {
const auto current_time{step_size * static_cast<double>(i)};
const auto next_time{step_size * static_cast<double>(i + 1)};

// Copy state matrices from device to host
Kokkos::deep_copy(host_state_x, state.x);
Kokkos::deep_copy(host_state_q, state.q);
Kokkos::deep_copy(host_state_v, state.v);
Kokkos::deep_copy(host_state_vd, state.vd);

Kokkos::deep_copy(host_qp_x, beams.qp_x);
Kokkos::deep_copy(host_qp_u_dot, beams.qp_u_dot);
Kokkos::deep_copy(host_qp_omega, beams.qp_omega);
Kokkos::deep_copy(host_qp_u_ddot, beams.qp_u_ddot);
Kokkos::deep_copy(host_qp_omega_dot, beams.qp_omega_dot);

// Set rotor motion from nodes or quadrature points
SetRotorMotion(
adi.turbines[0], beam_elems, root_nodes, hub_node, host_state_x, host_state_v,
host_state_vd, host_qp_x, host_qp_u_dot, host_qp_omega, host_qp_u_ddot, host_qp_omega_dot
);
adi.SetRotorMotion();
{
auto aerodyn_region = Kokkos::Profiling::ScopedRegion("AeroDyn");
// Copy state matrices from device to host
Kokkos::deep_copy(host_state_x, state.x);
Kokkos::deep_copy(host_state_q, state.q);
Kokkos::deep_copy(host_state_v, state.v);
Kokkos::deep_copy(host_state_vd, state.vd);

Kokkos::deep_copy(host_qp_x, beams.qp_x);
Kokkos::deep_copy(host_qp_u_dot, beams.qp_u_dot);
Kokkos::deep_copy(host_qp_omega, beams.qp_omega);
Kokkos::deep_copy(host_qp_u_ddot, beams.qp_u_ddot);
Kokkos::deep_copy(host_qp_omega_dot, beams.qp_omega_dot);

// Set rotor motion from nodes or quadrature points
SetRotorMotion(
adi.turbines[0], beam_elems, root_nodes, hub_node, host_state_x, host_state_v,
host_state_vd, host_qp_x, host_qp_u_dot, host_qp_omega, host_qp_u_ddot,
host_qp_omega_dot
);
adi.SetRotorMotion();

// Advance ADI library from current time to end of step
adi.UpdateStates(current_time, next_time);
// Advance ADI library from current time to end of step
adi.UpdateStates(current_time, next_time);

// Calculate outputs and loads at the end of the step
adi.CalculateOutput(next_time);
// Calculate outputs and loads at the end of the step
adi.CalculateOutput(next_time);

// Copy aerodynamic loads to structure
SetAeroLoads(beams, beam_elems, adi.turbines[0], host_node_FX, host_qp_Fe);
// Copy aerodynamic loads to structure
SetAeroLoads(beams, beam_elems, adi.turbines[0], host_node_FX, host_qp_Fe);
}

// Set controller inputs and call controller to get commands for this step
const auto generator_speed = rotor_speed * gear_box_ratio;
Expand Down

0 comments on commit 61e3559

Please sign in to comment.