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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
pub mod dim1;
pub mod dim2;
pub use dim1::StokesParams1D;
pub use dim1::StokesSolver1D;
pub use dim2::StokesParams2D;
pub type StaticPressureSolver = StokesSolver1D;
pub type StaticPressureParams = StokesParams1D;
pub type StaticPressureParamsBuilder = StokesParams1DBuilder;
pub struct StokesParams();
#[derive(Default)]
pub struct StokesParams1DBuilder {
hydrostatic_pressure: Option<f64>,
rho: Option<f64>,
force_function: Option<Box<dyn Fn(f64) -> f64>>
}
#[derive(Default)]
pub struct StokesParams2DBuilder {
boundary_conditions: Option<Vec<[f64;2]>>,
hydrostatic_pressure: Option<f64>,
force_function: Option<Box<dyn Fn([f64;2]) -> [f64;2]>>,
rho: Option<f64>,
nu: Option<f64>
}
impl StokesParams {
pub fn normal_1d() -> StokesParams1DBuilder {
StokesParams1DBuilder::default()
}
pub fn static_pressure() -> StaticPressureParamsBuilder {
StaticPressureParamsBuilder::default()
}
pub fn normal_2d() -> StokesParams2DBuilder {
StokesParams2DBuilder::default()
}
}
impl StokesParams1DBuilder {
pub fn hydrostatic_pressure(self, pressure_value: f64) -> Self {
Self {
hydrostatic_pressure: Some(pressure_value),
..self
}
}
pub fn density(self, rho: f64) -> Self {
Self {
rho: Some(rho),
..self
}
}
pub fn force_function(self, func: Box<dyn Fn(f64) -> f64>) -> Self {
Self {
force_function: Some(func),
..self
}
}
pub fn build(self) -> StokesParams1D {
let hydrostatic_pressure = if let Some(hydrostatic_pressure) = self.hydrostatic_pressure {
hydrostatic_pressure
} else {
panic!("Params lack 'pressure' term!");
};
let rho = if let Some(rho) = self.rho {
rho
} else {
panic!("Params lack 'density' term!");
};
let force_function = if let Some(func) = self.force_function {
func
} else {
panic!("Params lack force_function!");
};
StokesParams1D {
hydrostatic_pressure,
rho,
force_function
}
}
}
impl StokesParams2DBuilder {
pub fn boundary_conditions(self, boundary_conditions: Vec<[f64;2]>) -> Self {
Self {
boundary_conditions: Some(boundary_conditions),
..self
}
}
pub fn pressure(self, pressure_value: f64) -> Self {
Self {
hydrostatic_pressure: Some(pressure_value),
..self
}
}
pub fn kinematic_viscosity(self, viscosity_value: f64) -> Self {
Self {
nu: Some(viscosity_value),
..self
}
}
pub fn density(self, density_value: f64) -> Self {
Self {
rho: Some(density_value),
..self
}
}
pub fn force_function(self, func: Box<dyn Fn([f64;2]) -> [f64;2]>) -> Self {
Self {
force_function: Some(func),
..self
}
}
pub fn build(self) -> StokesParams2D {
let hydrostatic_pressure = if let Some(p) = self.hydrostatic_pressure {
p
} else {
panic!("Params lack 'pressure' term!");
};
let nu = if let Some(n) = self.nu {
n
} else {
panic!("Params lack 'kinematic viscosity' term!");
};
let force_function = if let Some(f) = self.force_function {
f
} else {
panic!("Params lack 'force_function!");
};
let boundary_conditions = if let Some(b) = self.boundary_conditions {
b
} else {
panic!("Params lack 'boundary_conditions'!");
};
let rho = if let Some(r) = self.rho {
r
} else {
panic!("Params lack 'density' term!");
};
StokesParams2D {
hydrostatic_pressure,
nu,
force_function,
boundary_conditions,
rho
}
}
}