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;

// Aliasing
pub type StaticPressureSolver = StokesSolver1D;
pub type StaticPressureParams = StokesParams1D;
pub type StaticPressureParamsBuilder = StokesParams1DBuilder;

/// Struct to initialize builders params for either time-dependent or time-independent diffussion solvers.
pub struct StokesParams();

#[derive(Default)]
/// # General Information
/// 
/// Builder for stokes params in 1D
/// 
/// # Fields
/// 
/// * `hydrostatic_pressure` - hydrostatic pressure
/// * `rho` - density
/// * `force_function` - force applied on the fluid
/// 
pub struct StokesParams1DBuilder {
    hydrostatic_pressure: Option<f64>,
    rho: Option<f64>,
    force_function: Option<Box<dyn Fn(f64) -> f64>>
}

#[derive(Default)]
/// # General Information
/// 
/// Builder for stokes params in 2D. Equation not implemented
/// 
/// # Fields
/// 
/// * `boundary_condtions` - conditions on 2D boundary
/// * `hydrostatic_pressure` - hydrostatic pressure
/// * `force_function` - force applied on the fluid
/// * `rho` - density
/// * `nu` - viscosity
/// 
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 {
    /// Redirects to 1e Stokes params
    pub fn normal_1d() -> StokesParams1DBuilder {
        StokesParams1DBuilder::default()
    }
    /// Redirects to 1d Stokes params with aliasing
    pub fn static_pressure() -> StaticPressureParamsBuilder {
        StaticPressureParamsBuilder::default()
    }
    /// Redirects to 2d stokes params
    pub fn normal_2d() -> StokesParams2DBuilder {
        StokesParams2DBuilder::default()
    }
}

impl StokesParams1DBuilder {
    /// Set pressure
    pub fn hydrostatic_pressure(self, pressure_value: f64) -> Self {
        Self {
            hydrostatic_pressure: Some(pressure_value),
            ..self
        }
    }
    /// Set rho
    pub fn density(self, rho: f64) -> Self {
        Self {
            rho: Some(rho),
            ..self
        }
    }
    /// Set force function 
    pub fn force_function(self, func: Box<dyn Fn(f64) -> f64>) -> Self {
        Self {
            force_function: Some(func),
            ..self
        }
    }
    /// Build StokesParams1D
    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 {
    /// Set boundary conditions
    pub fn boundary_conditions(self, boundary_conditions: Vec<[f64;2]>) -> Self {
        Self {
            boundary_conditions: Some(boundary_conditions),
            ..self
        }
    }
    /// Set pressure
    pub fn pressure(self, pressure_value: f64) -> Self {
        Self {
            hydrostatic_pressure: Some(pressure_value),
            ..self
        }
    }
    /// Set nu
    pub fn kinematic_viscosity(self, viscosity_value: f64) -> Self {
        Self {
            nu: Some(viscosity_value),
            ..self
        }
    }
    /// Set density
    pub fn density(self, density_value: f64) -> Self {
        Self {
            rho: Some(density_value),
            ..self
        }
    }
    /// Set force function
    pub fn force_function(self, func: Box<dyn Fn([f64;2]) -> [f64;2]>) -> Self {
        Self {
            force_function: Some(func),
            ..self
        }
    }
    /// Build params
    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
        }
    }
}