Skip to content

Commit

Permalink
Update wave summary energy calc
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Jul 5, 2024
1 parent 7e3dee6 commit f34b103
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/tools/waves.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{f64::consts::PI, ops::Sub, vec};

use crate::{
dimensional_data::DimensionalData,
swell::Swell,
units::{direction::DirectionConvention, Direction, UnitSystem},
units::{direction::DirectionConvention, Direction, Unit, UnitSystem},
};

const GRAVITY: f64 = 9.81;
Expand Down Expand Up @@ -485,7 +486,11 @@ pub fn pt_mean(
}
}

let energy = wave_energy(hs, peak_period);
let energy = if ip == 0 {
Some(wave_energy(hs, peak_period))
} else {
None
};

// let wind_sea_fraction = sumew[ip] / sume[ip];

Expand All @@ -495,18 +500,30 @@ pub fn pt_mean(
peak_period,
Direction::from_degrees(mean_wave_direction as i32),
Some(spectral_density),
Some(energy),
Some(ip)
energy,
Some(ip),
);

if ip == 0 {
summary = component;
} else {
components.push(component);
}

components.sort_by(|sl, sr| sr.energy.partial_cmp(&sl.energy).unwrap());
}

// Sort components by energy
components.sort_by(|sl, sr| sr.energy.partial_cmp(&sl.energy).unwrap());

// Calculate the total energy by simply summing the energy of all swell components
let summary_energy = components.iter().fold(0.0, |acc, x| {
acc + &x.energy.as_ref().map(|x| x.get_value()).unwrap_or(0.0)
});

summary.energy = Some(DimensionalData {
value: Some(summary_energy),
variable_name: "energy".into(),
unit: Unit::KiloJoules,
});

(summary, components)
}

0 comments on commit f34b103

Please sign in to comment.