use serde::{Serialize, Deserialize};
use stormath::type_aliases::Float;
pub mod velocity_variation;
pub mod discretized_spectrum;
use velocity_variation::VelocityVariation;
use discretized_spectrum::DiscretizedSpectrum;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WindCondition {
pub direction_coming_from: Float,
pub velocity_variation: VelocityVariation,
#[serde(default)]
pub parallel_gust: Option<DiscretizedSpectrum>,
#[serde(default)]
pub perpendicular_gust: Option<DiscretizedSpectrum>,
#[serde(default)]
pub vertical_gust: Option<DiscretizedSpectrum>
}
impl WindCondition {
pub fn new_constant(direction_coming_from: Float, velocity: Float) -> Self {
Self{
direction_coming_from,
velocity_variation: VelocityVariation::Constant(velocity),
parallel_gust: None,
perpendicular_gust: None,
vertical_gust: None
}
}
pub fn steady_true_wind_velocity_at_height(&self, height: Float) -> Float {
self.velocity_variation.true_wind_velocity_at_height(height)
}
pub fn unsteady_parallel_true_wind_velocity_at_height(&self, height: Float, time: Float) -> Float {
let mut u = self.velocity_variation.true_wind_velocity_at_height(height);
if let Some(spectrum) = &self.parallel_gust {
u += spectrum.value_at_time(time);
}
u
}
pub fn unsteady_perpendicular_true_wind_velocity(&self, time: Float) -> Float {
if let Some(spectrum) = &self.perpendicular_gust {
spectrum.value_at_time(time)
} else {
0.0
}
}
pub fn unsteady_vertical_true_wind_velocity(&self, time: Float) -> Float {
if let Some(spectrum) = &self.vertical_gust {
spectrum.value_at_time(time)
} else {
0.0
}
}
pub fn set_parallel_gust_from_json_string(&mut self, gust_string: &str) {
let parallel_gust: DiscretizedSpectrum = serde_json::from_str(gust_string).unwrap();
self.parallel_gust = Some(parallel_gust);
}
pub fn set_perpendicular_gust_from_json_string(&mut self, gust_string: &str) {
let perpendicular_gust: DiscretizedSpectrum = serde_json::from_str(&gust_string).unwrap();
self.perpendicular_gust = Some(perpendicular_gust);
}
pub fn set_vertical_gust_from_json_string(&mut self, gust_string: &str) {
let vertical_gust: DiscretizedSpectrum = serde_json::from_str(gust_string).unwrap();
self.vertical_gust = Some(vertical_gust);
}
}