dzahui/solvers/fem/diffusion_solver/
mod.rs

1// Module declarations
2pub mod time_dependent;
3pub mod time_independent;
4
5// Internal dependencies + re-exports
6pub use time_dependent::{DiffussionParamsTimeDependent, DiffussionSolverTimeDependent};
7pub use time_independent::{DiffussionParamsTimeIndependent, DiffussionSolverTimeIndependent};
8
9
10/// Struct to initialize builders params for either time-dependent or time-independent diffussion solvers.
11pub struct DiffussionParams();
12
13#[derive(Default)]
14/// # General Information
15/// 
16/// Builder for diffussion params in 1D with time-dependance
17/// 
18/// # Fields
19/// 
20/// * `mu` - Movement term
21/// * `b` - Velocity term
22/// * `boundary_conditions` - Dirichlet conditions
23/// * `initial_conditions` - Internal initial conditions
24/// 
25pub struct DiffussionParamsTimeDependentBuilder {
26    mu: Option<f64>,
27    b: Option<f64>,
28    boundary_conditions: Option<[f64;2]>,
29    initial_conditions: Option<Vec<f64>>,
30}
31
32#[derive(Default)]
33/// # General Information
34/// 
35/// Builder for diffussion params in 1D
36/// 
37/// # Fields
38/// 
39/// * `mu` - Movement term
40/// * `b` - Velocity term
41/// * `boundary_conditions` - Dirichlet conditions
42/// 
43pub struct DiffussionParamsTimeIndependentBuilder {
44    mu: Option<f64>,
45    b: Option<f64>,
46    boundary_conditions: Option<[f64;2]>,
47}
48
49
50impl DiffussionParams {
51    pub fn time_dependent() -> DiffussionParamsTimeDependentBuilder {
52        DiffussionParamsTimeDependentBuilder::default()
53    }
54
55    pub fn time_independent() -> DiffussionParamsTimeIndependentBuilder {
56        DiffussionParamsTimeIndependentBuilder::default()
57    }
58}
59
60impl DiffussionParamsTimeDependentBuilder {
61    /// Set b
62    pub fn b(self, b: f64) -> Self {
63        Self {
64            b: Some(b),
65            ..self
66        }
67    }
68    /// Set mu
69    pub fn mu(self, mu: f64) -> Self {
70        Self {
71            mu: Some(mu),
72            ..self
73        }
74    }
75    /// Set boundary conditions
76    pub fn boundary_conditions(self, left: f64, right: f64) -> Self {
77        Self {
78            boundary_conditions: Some([left, right]),
79            ..self
80        }
81    }
82    /// Set initial conditions - basic
83    pub fn initial_conditions<A: IntoIterator<Item = f64>>(self, initial_conditions: A) -> Self {
84        Self {
85            initial_conditions: Some(initial_conditions.into_iter().collect()),
86            ..self
87        }
88    }
89    /// Use function 
90    pub fn initial_conditions_from_function<A: Fn(f64) -> f64, B: AsRef<str>>(_func: A, _mesh: B) -> Self {
91
92        
93
94        todo!()
95    }
96    /// Build DiffussionParams
97    pub fn build(self) -> DiffussionParamsTimeDependent {
98        
99        let mu = if let Some(mu) = self.mu {
100            mu
101        } else {
102            panic!("Params lack 'mu' term!");
103        };
104
105        let b = if let Some(b) = self.b {
106            b
107        } else {
108            panic!("Params lack 'b' term!");
109        };
110
111        let boundary_conditions = if let Some(boundary) = self.boundary_conditions {
112            boundary
113        } else {
114            panic!("Params lack boundary conditions!");
115        };
116
117        let initial_conditions = if let Some(initial) = self.initial_conditions {
118            initial
119        } else {
120            panic!("Params lack initial conditions!");
121        };
122        
123        DiffussionParamsTimeDependent {
124            mu,
125            boundary_conditions,
126            b,
127            initial_conditions
128        }
129    }
130}
131
132impl DiffussionParamsTimeIndependentBuilder {
133    /// Set mu
134    pub fn mu(self, mu: f64) -> Self {
135        Self {
136            mu: Some(mu),
137            ..self
138        }
139    }
140    /// Set b
141    pub fn b(self, b: f64) -> Self {
142        Self {
143            b: Some(b),
144            ..self
145        }
146    }
147    /// Set boundary cconditions
148    pub fn boundary_conditions(self, left: f64, right: f64) -> Self {
149        Self {
150            boundary_conditions: Some([left, right]),
151            ..self
152        }
153    }
154    /// Build DiffussionParams
155    pub fn build(self) -> DiffussionParamsTimeIndependent {
156        
157        let mu = if let Some(mu) = self.mu {
158            mu
159        } else {
160            panic!("Params lack 'mu' term!");
161        };
162
163        let b = if let Some(b) = self.b {
164            b
165        } else {
166            panic!("Params lack 'b' term!");
167        };
168
169        let boundary_conditions = if let Some(boundary) = self.boundary_conditions {
170            boundary
171        } else {
172            panic!("Params lack boundary conditions!");
173        };
174        
175        DiffussionParamsTimeIndependent {
176            mu,
177            boundary_conditions,
178            b,
179        }
180    }
181}