1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::prelude::*;
pub trait SpectralCommon {
/// significant wave height in \[m\]
fn hs(&self) -> Result<f64, String>;
/// peak spectral wave period in \[s\]
fn tp(&self) -> Result<f64, String>;
/// frequency space in \[rad/s\]
fn omega(&self) -> &Array1<f64>;
/// return the frequency space in \[Hz\]
fn f_hz(&self) -> Array1<f64> {
self.omega() / TWO_PI
}
/// return the peak spectral frequency in \[rad/s\]
fn wp(&self) -> Result<f64, String> {
match self.tp() {
Ok(tp) => Ok(TWO_PI / tp),
Err(e) => Err(e),
}
}
/// return the peak spectral frequency in \[Hz\]
fn fp(&self) -> Result<f64, String> {
match self.wp() {
Ok(wp) => Ok(wp / TWO_PI),
Err(e) => Err(e),
}
}
/// calculate the energy density spectrum
fn energy(&self) -> Array1<f64>;
/// calculate the absolute error between the significant wave height and the integrated energy
fn abs_error(&self) -> Result<f64, String> {
let area = trapz(self.energy().view(), self.omega().view());
match self.hs() {
Ok(hs) => Ok((hs - 4.0 * area.sqrt()).abs()),
Err(e) => Err(e),
}
}
/// convert the spectrum to a 1D spectrum Type
fn to_spec1d(&self) -> Spectrum1D {
Spectrum1D::new(self.omega().to_owned(), self.energy())
}
/// convert the spectrum to a 2D spectrum Type for a given spreading Type
fn to_spec2d(&self, spreading: &Spreading) -> Spectrum2D {
Spectrum2D::from_spec1d(&self.to_spec1d(), spreading)
}
}