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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use {
serde::Deserialize,
std::{f64::consts::PI, path::PathBuf},
};
#[derive(Debug, PartialEq, Default, Deserialize)]
pub struct Parameters {
pub numerical: Numerical,
pub physical: Physical,
pub environment: Environment,
}
#[derive(Debug, PartialEq, Deserialize)]
pub struct Numerical {
pub grid_resolution: usize,
pub vertical_layers: usize,
pub time_step: f64,
pub duration: f64,
pub save_interval: f64,
pub max_pressure_difference: f64,
pub strip_width: f64,
pub a2: f64,
pub a3: f64,
}
impl Default for Numerical {
fn default() -> Self {
Self {
grid_resolution: 32,
vertical_layers: 4,
time_step: 1.0 / 32.0,
duration: 25.0,
save_interval: 0.25,
max_pressure_difference: 1.0e-9,
strip_width: 0.4,
a2: 0.02,
a3: -0.01,
}
}
}
#[derive(Debug, PartialEq, Deserialize)]
pub struct Physical {
pub coriolis_frequency: f64,
pub gravity_wave_speed: f64,
pub mean_fluid_depth: f64,
pub damping: f64,
pub nnu: f64,
}
impl Default for Physical {
fn default() -> Self {
Self {
coriolis_frequency: 4.0 * PI,
gravity_wave_speed: 2.0 * PI,
mean_fluid_depth: 0.4,
damping: 10.0,
nnu: 3.0,
}
}
}
#[derive(Debug, PartialEq, Deserialize)]
pub struct Environment {
pub threads: usize,
pub output_directory: PathBuf,
}
impl Default for Environment {
fn default() -> Self {
Self {
threads: 0,
output_directory: PathBuf::from(r"./out"),
}
}
}
#[cfg(test)]
mod test {
use {super::*, std::fs::File};
#[test]
fn defaults() {
assert_eq!(
Parameters::default(),
serde_yaml::from_reader::<_, Parameters>(File::open("parameters.yaml").unwrap())
.unwrap()
);
}
}