1use crate::{Result, StateStore, Topology};
4
5pub trait GridElement: Send + Sync {
7 fn element_type(&self) -> &'static str;
9
10 fn apply(&self, state: &mut StateStore);
12}
13
14pub trait Solver: Send + Sync {
16 fn name(&self) -> &'static str;
18
19 fn solve(&self, topology: &Topology, state: &mut StateStore) -> Result<SolverResult>;
21}
22
23#[derive(Debug, Clone)]
25pub struct SolverResult {
26 pub iterations: usize,
28 pub convergence_error: f64,
30 pub converged: bool,
32}
33
34impl SolverResult {
35 pub fn converged(iterations: usize, error: f64) -> Self {
37 Self {
38 iterations,
39 convergence_error: error,
40 converged: true,
41 }
42 }
43
44 pub fn failed(iterations: usize, error: f64) -> Self {
46 Self {
47 iterations,
48 convergence_error: error,
49 converged: false,
50 }
51 }
52}
53
54pub trait TimeStepper: Send + Sync {
56 fn step(&mut self, state: &mut StateStore, dt: f64) -> Result<()>;
58}
59
60pub trait OutputHandler: Send + Sync {
62 fn on_step(&mut self, step: usize, time: f64, state: &StateStore);
64
65 fn on_complete(&mut self, state: &StateStore);
67}