42 lines
1,023 B
Rust
42 lines
1,023 B
Rust
use crate::{model::*, opti::*, utils::*};
|
|
|
|
use nalgebra::{base::*, ComplexField};
|
|
|
|
pub trait Solver<T, S: Settings, M: Model<T, S, D>, const D: usize> {
|
|
fn f(&self, model: &M, x: Vect<T, D>) -> Vect<T, D>;
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct ExplicitEulerSolver<T: Copy + ComplexField<RealField = T>> {
|
|
pub dt: T,
|
|
}
|
|
|
|
impl<T: Copy + ComplexField<RealField = T>, S: Settings, M: Model<T, S, D>, const D: usize>
|
|
Solver<T, S, M, D> for ExplicitEulerSolver<T>
|
|
{
|
|
fn f(&self, model: &M, x: Vect<T, D>) -> Vect<T, D> {
|
|
model.f(x) * self.dt + x
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct ImplicitEulerSolver<T: Clone + ComplexField<RealField = T>> {
|
|
pub dt: T,
|
|
pub tol: T,
|
|
pub niters: usize,
|
|
}
|
|
|
|
impl<
|
|
T: Copy + ComplexField<RealField = T> + PartialOrd,
|
|
S: Settings,
|
|
M: Model<T, S, D>,
|
|
const D: usize,
|
|
> Solver<T, S, M, D> for ImplicitEulerSolver<T>
|
|
where
|
|
Const<D>: ToTypenum + DimMin<Const<D>, Output = Const<D>>,
|
|
{
|
|
fn f(&self, model: &M, x: Vect<T, D>) -> Vect<T, D> {
|
|
newton(model, x, self.dt, self.tol, self.niters)
|
|
}
|
|
}
|