dzahui/solvers/fem/diffusion_solver/
mod.rs1pub mod time_dependent;
3pub mod time_independent;
4
5pub use time_dependent::{DiffussionParamsTimeDependent, DiffussionSolverTimeDependent};
7pub use time_independent::{DiffussionParamsTimeIndependent, DiffussionSolverTimeIndependent};
8
9
10pub struct DiffussionParams();
12
13#[derive(Default)]
14pub 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)]
33pub 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 pub fn b(self, b: f64) -> Self {
63 Self {
64 b: Some(b),
65 ..self
66 }
67 }
68 pub fn mu(self, mu: f64) -> Self {
70 Self {
71 mu: Some(mu),
72 ..self
73 }
74 }
75 pub fn boundary_conditions(self, left: f64, right: f64) -> Self {
77 Self {
78 boundary_conditions: Some([left, right]),
79 ..self
80 }
81 }
82 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 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 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 pub fn mu(self, mu: f64) -> Self {
135 Self {
136 mu: Some(mu),
137 ..self
138 }
139 }
140 pub fn b(self, b: f64) -> Self {
142 Self {
143 b: Some(b),
144 ..self
145 }
146 }
147 pub fn boundary_conditions(self, left: f64, right: f64) -> Self {
149 Self {
150 boundary_conditions: Some([left, right]),
151 ..self
152 }
153 }
154 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}