/home/runner/work/kynema/kynema/kynema/src/interfaces/turbine/turbine_interface.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/interfaces/turbine/turbine_interface.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
turbine_interface.hpp
Go to the documentation of this file.
1#pragma once
2
11#include "model/model.hpp"
14
16struct SolutionInput;
17struct TurbineInput;
18struct OutputsConfig;
19} // namespace kynema::interfaces::components
20
21namespace kynema::interfaces {
22
30public:
31 using DeviceType =
32 Kokkos::Device<Kokkos::DefaultExecutionSpace, Kokkos::DefaultExecutionSpace::memory_space>;
33
42 explicit TurbineInterface(
43 const components::SolutionInput& solution_input,
44 const components::TurbineInput& turbine_input,
45 const components::AerodynamicsInput& aerodynamics_input = {},
46 const components::ControllerInput& controller_input = {},
47 const components::OutputsConfig& outputs_config = {}
48 );
49
51
53
55
57
58 ~TurbineInterface() = default;
59
61 [[nodiscard]] components::Turbine& Turbine() { return this->turbine; }
62
65 if (!aerodynamics) {
66 throw std::runtime_error("Aerodynamics component not initialized in TurbineInterface.");
67 }
68 return *aerodynamics;
69 }
70
79 double fluid_density,
80 const std::function<std::array<double, 3>(const std::array<double, 3>&)>& inflow_function
81 );
82
83 std::array<double, 3> GetHubNodePosition() const;
84
85 void SetHubInflow(const std::array<double, 3>& inflow);
86
90 void ApplyController(double t);
91
100 [[nodiscard]] bool Step();
101
103 void SaveState();
104
106 void RestoreState();
107
109 Model& GetModel() { return model; }
110
112 HostState<DeviceType>& GetHostState() { return host_state; }
113
118 [[nodiscard]] double CalculateAzimuthAngle() const;
119
124 [[nodiscard]] double CalculateRotorSpeed() const;
125
126 void WriteOutput();
127
128 void OpenOutputFile();
129
130 void CloseOutputFile();
131
132private:
133 Model model;
134 components::Turbine turbine;
135 State<DeviceType> state;
136 Elements<DeviceType> elements;
137 Constraints<DeviceType> constraints;
138 StepParameters parameters;
139 Solver<DeviceType> solver;
140 State<DeviceType> state_save;
141 HostState<DeviceType> host_state;
142 HostConstraints<DeviceType> host_constraints;
143 std::unique_ptr<Outputs> outputs;
144 std::unique_ptr<util::TurbineController> controller;
145 std::unique_ptr<components::Aerodynamics> aerodynamics;
146 std::array<double, 3> hub_inflow{0., 0., 0.};
147
157 void WriteTimeSeriesData();
158
163 void InitializeController(
164 const components::TurbineInput& turbine_input,
165 const components::SolutionInput& solution_input
166 );
167
168 //------------------------------------------
169 // support for time-series outputs
170 //------------------------------------------
171
172 struct TimeSeriesIndexMap {
173 // Basic simulation parameter and other misc. channels
174 size_t time_seconds{}; //< Time in seconds
175 size_t num_convergence_iterations{}; //< Number of convergence iterations
176 size_t convergence_error{}; //< Last convergence error
177 size_t azimuth_angle_degrees{}; //< Azimuth angle in degrees
178 size_t rotor_speed_rpm{}; //< Rotor speed in RPM
179
180 // Yaw position channel
181 size_t yaw_position_degrees{}; //< Yaw position in degrees
182
183 // Tower top and base state channels (contiguous groups, 3 entries each)
184 size_t tower_top_displacement_start{}; //< Start of [x, y, z] displacement
185 size_t tower_top_velocity_start{}; //< Start of [x, y, z] velocity
186 size_t tower_top_acceleration_start{}; //< Start of [x, y, z] acceleration
187 size_t tower_base_force_start{}; //< Start of [Fx, Fy, Fz] forces
188 size_t tower_base_moment_start{}; //< Start of [Mx, My, Mz] moments
189
190 // Rotor thrust channel
191 size_t rotor_thrust_kN{}; //< Thrust in kiloNewtons
192
193 // Blade data channels (dynamic per blade: root forces and moments, pitch angle, tip
194 // velocities and rotational velocities)
195 static constexpr size_t kBladeChannelStride{13}; //< Channels per blade
196 std::vector<size_t> blade_channel_offsets; //< Base offset per blade
197
198 // Controller channels (optional: generator torque and power)
199 bool has_controller_channels{false}; //< True if controller channels are present
200 size_t generator_torque_kNm{}; //< Generator torque in kiloNewton-meters
201 size_t generator_power_kW{}; //< Generator power in kiloWatts
202
203 // Hub inflow valocity channels
204 size_t hub_inflow_start{}; //< Start of [x, y, z] inflow velocity
205
206 // Aerodynamic channels (dynamic per blade and section:
207 // relative velocity, angle of attack, lift coefficient, drag coefficient, moment
208 // coefficient, force in x-direction, forces (3) and moments (3)
209 static constexpr size_t kAeroChannelStride{11}; //< Vrel, Alpha, Cn, Ct, Cm, Fxi-Mzi
210 std::vector<size_t> aero_body_offsets; //< Base offset per body
211 std::vector<size_t> aero_section_counts; //< Number of sections per body
212 };
213
214 bool time_series_enabled_{false};
215 std::vector<std::string> time_series_channels_;
216 TimeSeriesIndexMap index_map_{};
217 std::vector<double> time_series_row_buffer_;
218
219 void BuildTimeSeriesSchema();
220};
221
222} // namespace kynema::interfaces
Struct to define the connectivity structure of elements, nodes, and constraints defining an Kynema pr...
Definition model.hpp:75
Interface for blade simulation that manages state, solver, and components.
Definition turbine_interface.hpp:29
std::array< double, 3 > GetHubNodePosition() const
Definition turbine_interface.cpp:495
HostState< DeviceType > & GetHostState()
Return a reference to this interface's host state.
Definition turbine_interface.hpp:112
TurbineInterface & operator=(const TurbineInterface &)=delete
void SaveState()
Saves the current state for potential restoration (in correction step)
Definition turbine_interface.cpp:321
void CloseOutputFile()
Definition turbine_interface.cpp:618
TurbineInterface(TurbineInterface &other)=delete
components::Aerodynamics & Aerodynamics()
Returns a reference to the aerodynamics model.
Definition turbine_interface.hpp:64
void WriteOutput()
Definition turbine_interface.cpp:624
void ApplyController(double t)
Update controller inputs from current system state.
Definition turbine_interface.cpp:546
void RestoreState()
Restores the previously saved state (in correction step)
Definition turbine_interface.cpp:325
bool Step()
Steps forward in time.
Definition turbine_interface.cpp:281
double CalculateRotorSpeed() const
Calculates rotor speed from constraint output.
Definition turbine_interface.cpp:490
void SetHubInflow(const std::array< double, 3 > &inflow)
Definition turbine_interface.cpp:501
components::Turbine & Turbine()
Returns a reference to the turbine model.
Definition turbine_interface.hpp:61
TurbineInterface(TurbineInterface &&other)=delete
void UpdateAerodynamicLoads(double fluid_density, const std::function< std::array< double, 3 >(const std::array< double, 3 > &)> &inflow_function)
Updates the aerodynamic loads to be applied to the structure based on a provided function.
Definition turbine_interface.cpp:259
double CalculateAzimuthAngle() const
Calculates and normalizes azimuth angle from constraint output.
Definition turbine_interface.cpp:477
void OpenOutputFile()
Definition turbine_interface.cpp:612
Kokkos::Device< Kokkos::DefaultExecutionSpace, Kokkos::DefaultExecutionSpace::memory_space > DeviceType
Definition turbine_interface.hpp:32
TurbineInterface & operator=(TurbineInterface &&)=delete
Model & GetModel()
Return a reference of the model owned by this interface.
Definition turbine_interface.hpp:109
Definition aerodynamics_input.hpp:27
Definition aerodynamics.hpp:335
Represents a turbine with nodes, elements, and constraints.
Definition turbine.hpp:87
Definition aerodynamics.cpp:5
Definition blade_interface.cpp:9
Container class for managing multiple constraints in a simulation.
Definition constraints.hpp:29
A container providing handle to all structural elements present in the model.
Definition elements.hpp:20
This object manages the assembly and solution of linear system arising from the generalized-alpha bas...
Definition solver.hpp:21
Container for storing the complete system state of the simulation at a given time increment.
Definition state.hpp:18
A Struct containing the paramters used to control the time stepping process.
Definition step_parameters.hpp:12
Host-side mirror of the constraint input, output, and loads for a given time increment.
Definition host_constraints.hpp:21
Host-side mirror of the simulation state for a given time increment.
Definition host_state.hpp:22
Configuration parameters for a DISCON-style turbine controller.
Definition controller_input.hpp:15
A configuration object used to create the low level StepParameters object.
Definition solution_input.hpp:13
Complete input specification for a turbine.
Definition turbine_input.hpp:17