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
use ndarray::*;
use ndarray_linalg::*;
pub trait ModelSpec: Clone {
type Scalar: Scalar;
type Dim: Dimension;
fn model_size(&self) -> <Self::Dim as Dimension>::Pattern;
}
pub trait TimeStep {
type Time: RealScalar;
fn get_dt(&self) -> Self::Time;
fn set_dt(&mut self, dt: Self::Time);
}
pub trait Explicit: ModelSpec {
fn rhs<'a, S>(&mut self, &'a mut ArrayBase<S, Self::Dim>) -> &'a mut ArrayBase<S, Self::Dim>
where
S: DataMut<Elem = Self::Scalar>;
}
pub trait SemiImplicit: ModelSpec {
fn nlin<'a, S>(&mut self, &'a mut ArrayBase<S, Self::Dim>) -> &'a mut ArrayBase<S, Self::Dim>
where
S: DataMut<Elem = Self::Scalar>;
fn diag(&self) -> Array<Self::Scalar, Self::Dim>;
}
pub trait TimeEvolution: ModelSpec + TimeStep {
fn iterate<'a, S>(
&mut self,
&'a mut ArrayBase<S, Self::Dim>,
) -> &'a mut ArrayBase<S, Self::Dim>
where
S: DataMut<Elem = Self::Scalar>;
fn iterate_n<'a, S>(
&mut self,
a: &'a mut ArrayBase<S, Self::Dim>,
n: usize,
) -> &'a mut ArrayBase<S, Self::Dim>
where
S: DataMut<Elem = Self::Scalar>,
{
for _ in 0..n {
self.iterate(a);
}
a
}
}
pub trait Scheme: TimeEvolution {
type Core: ModelSpec<Scalar = Self::Scalar, Dim = Self::Dim>;
fn new(f: Self::Core, dt: Self::Time) -> Self;
fn core(&self) -> &Self::Core;
fn core_mut(&mut self) -> &mut Self::Core;
}