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

Kynema-FMB API: /home/runner/work/kynema-fmb/kynema-fmb/kynema-fmb/src/interfaces/turbine/turbine_interface.hpp Source File
Kynema-FMB 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
12#include "model/model.hpp"
14
16struct SolutionInput;
17struct TurbineInput;
18struct OutputsConfig;
19} // namespace kynema_fmb::interfaces::components
20
21namespace kynema_fmb::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
136 void WriteCheckpointFile(const std::string& file_path) const;
137
142 void ReadCheckpointFile(const std::string& file_path);
143
145 void SetTimeStepIndex(size_t idx) { this->state.time_step = idx; }
146
147private:
148 Model model;
149 components::Turbine turbine;
150 State<DeviceType> state;
151 Elements<DeviceType> elements;
153 constraints;
154 StepParameters parameters;
155 Solver<DeviceType> solver;
156 State<DeviceType> state_save;
157 HostState<DeviceType> host_state;
158 HostConstraints<DeviceType> host_constraints;
159 std::unique_ptr<Outputs> outputs;
160 std::unique_ptr<components::Controller> controller;
161 std::unique_ptr<components::Aerodynamics> aerodynamics;
162 std::array<double, 3> hub_inflow{0., 0., 0.};
163 double gearbox_ratio{1.0};
164 double generator_efficiency{1.0};
165
175 void WriteTimeSeriesData();
176
181 void InitializeController(const components::TurbineInput& turbine_input);
182
183 //------------------------------------------
184 // support for time-series outputs
185 //------------------------------------------
186
187 struct TimeSeriesIndexMap {
188 // Basic simulation parameter and other misc. channels
189 size_t time_seconds{}; //< Time in seconds
190 size_t num_convergence_iterations{}; //< Number of convergence iterations
191 size_t convergence_error{}; //< Last convergence error
192 size_t azimuth_angle_degrees{}; //< Azimuth angle in degrees
193 size_t rotor_speed_rpm{}; //< Rotor speed in RPM
194
195 // Yaw position channel
196 size_t yaw_position_degrees{}; //< Yaw position in degrees
197
198 // Tower top and base state channels (contiguous groups, 3 entries each)
199 size_t tower_top_displacement_start{}; //< Start of [x, y, z] displacement
200 size_t tower_top_velocity_start{}; //< Start of [x, y, z] velocity
201 size_t tower_top_acceleration_start{}; //< Start of [x, y, z] acceleration
202 size_t tower_base_force_start{}; //< Start of [Fx, Fy, Fz] forces
203 size_t tower_base_moment_start{}; //< Start of [Mx, My, Mz] moments
204
205 // Rotor thrust channel
206 size_t rotor_thrust_kN{}; //< Thrust in kiloNewtons
207
208 // Blade data channels (dynamic per blade: root forces and moments, pitch angle, tip
209 // velocities and rotational velocities)
210 static constexpr size_t kBladeChannelStride{13}; //< Channels per blade
211 std::vector<size_t> blade_channel_offsets; //< Base offset per blade
212
213 // Controller channels (optional: generator torque and power)
214 bool has_controller_channels{false}; //< True if controller channels are present
215 size_t generator_torque_kNm{}; //< Generator torque in kiloNewton-meters
216 size_t generator_power_kW{}; //< Generator power in kiloWatts
217
218 // Hub inflow valocity channels
219 size_t hub_inflow_start{}; //< Start of [x, y, z] inflow velocity
220
221 // Aerodynamic channels (dynamic per blade and section:
222 // relative velocity, angle of attack, lift coefficient, drag coefficient, moment
223 // coefficient, force in x-direction, forces (3) and moments (3)
224 static constexpr size_t kAeroChannelStride{11}; //< Vrel, Alpha, Cn, Ct, Cm, Fxi-Mzi
225 std::vector<size_t> aero_body_offsets; //< Base offset per body
226 std::vector<size_t> aero_section_counts; //< Number of sections per body
227 };
228
229 bool time_series_enabled_{false};
230 std::vector<std::string> time_series_channels_;
231 TimeSeriesIndexMap index_map_{};
232 std::vector<double> time_series_row_buffer_;
233
234 void BuildTimeSeriesSchema();
235};
236
237} // namespace kynema_fmb::interfaces
Struct to define the connectivity structure of elements, nodes, and constraints defining a Kynema-FMB...
Definition model.hpp:75
Interface for blade simulation that manages state, solver, and components.
Definition turbine_interface.hpp:29
void ReadCheckpointFile(const std::string &file_path)
Read checkpoint file and restore state.
Definition turbine_interface.cpp:659
void WriteOutput()
Definition turbine_interface.cpp:636
void RestoreState()
Restores the previously saved state (in correction step)
Definition turbine_interface.cpp:333
double CalculateAzimuthAngle() const
Calculates and normalizes azimuth angle from constraint output.
Definition turbine_interface.cpp:488
Model & GetModel()
Return a reference of the model owned by this interface.
Definition turbine_interface.hpp:109
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:266
TurbineInterface & operator=(TurbineInterface &&)=delete
TurbineInterface(TurbineInterface &&other)=delete
bool Step()
Steps forward in time.
Definition turbine_interface.cpp:288
HostState< DeviceType > & GetHostState()
Return a reference to this interface's host state.
Definition turbine_interface.hpp:112
TurbineInterface & operator=(const TurbineInterface &)=delete
components::Turbine & Turbine()
Returns a reference to the turbine model.
Definition turbine_interface.hpp:61
void SetTimeStepIndex(size_t idx)
Allows time step index to be set externally (e.g., for restart)
Definition turbine_interface.hpp:145
void SetHubInflow(const std::array< double, 3 > &inflow)
Definition turbine_interface.cpp:512
void ApplyController(double t)
Update controller inputs from current system state.
Definition turbine_interface.cpp:548
Kokkos::Device< Kokkos::DefaultExecutionSpace, Kokkos::DefaultExecutionSpace::memory_space > DeviceType
Definition turbine_interface.hpp:32
void SaveState()
Saves the current state for potential restoration (in correction step)
Definition turbine_interface.cpp:329
TurbineInterface(TurbineInterface &other)=delete
components::Aerodynamics & Aerodynamics()
Returns a reference to the aerodynamics model.
Definition turbine_interface.hpp:64
void CloseOutputFile()
Definition turbine_interface.cpp:630
void OpenOutputFile()
Definition turbine_interface.cpp:624
double CalculateRotorSpeed() const
Calculates rotor speed from constraint output.
Definition turbine_interface.cpp:501
std::array< double, 3 > GetHubNodePosition() const
Definition turbine_interface.cpp:506
void WriteCheckpointFile(const std::string &file_path) const
Write checkpoint file of current state.
Definition turbine_interface.cpp:648
Definition aerodynamics_input.hpp:52
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:26
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