use serde::{Serialize, Deserialize};
use stormath::type_aliases::Float;
use stormath::interpolation::linear_interpolation;
use crate::line_force_model::span_line::SpanLine;
use stormath::spatial_vector::SpatialVector;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct InputPowerData {
pub section_models_internal_state_data: Vec<Float>,
pub input_power_coefficient_data: Vec<Float>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub enum InputPowerModel {
NoPower,
InternalStateAsPowerCoefficient,
InterpolatePowerCoefficientFromInternalState(InputPowerData),
InterpolateFromInternalStateOnly(InputPowerData),
}
impl Default for InputPowerModel {
fn default() -> Self {
InputPowerModel::NoPower
}
}
impl InputPowerModel {
pub fn input_power_coefficient(&self, section_model_internal_state: Float) -> Float {
match self {
InputPowerModel::NoPower => 0.0,
InputPowerModel::InternalStateAsPowerCoefficient => {
section_model_internal_state.abs()
},
InputPowerModel::InterpolateFromInternalStateOnly(data) => {
linear_interpolation(
section_model_internal_state.abs(),
&data.section_models_internal_state_data,
&data.input_power_coefficient_data,
)
},
InputPowerModel::InterpolatePowerCoefficientFromInternalState(data) => {
linear_interpolation(
section_model_internal_state.abs(),
&data.section_models_internal_state_data,
&data.input_power_coefficient_data,
)
},
}
}
pub fn input_power_for_strip(
&self,
section_model_internal_state: Float,
span_line: SpanLine,
chord_length: Float,
density: Float,
velocity: SpatialVector
) -> Float {
let power_coefficient = self.input_power_coefficient(section_model_internal_state);
match self {
InputPowerModel::NoPower => 0.0,
InputPowerModel::InterpolateFromInternalStateOnly(_) => {
power_coefficient * chord_length * span_line.length()
},
InputPowerModel::InternalStateAsPowerCoefficient |
InputPowerModel::InterpolatePowerCoefficientFromInternalState(_) => {
let dynamic_pressure = 0.5 * density * velocity.length_squared();
let strip_area = chord_length * span_line.length();
power_coefficient * dynamic_pressure * strip_area * velocity.length()
},
}
}
}