42 lines
900 B
Rust
42 lines
900 B
Rust
use crate::{
|
|
model::{Model, Settings},
|
|
solver::Solver,
|
|
util::*,
|
|
};
|
|
|
|
use nalgebra::{base::*, ComplexField};
|
|
|
|
#[derive(Clone)]
|
|
pub struct ExplicitEuler<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 ExplicitEuler<T>
|
|
{
|
|
fn f(&self, model: &M, x: Vect<T, D>) -> Vect<T, D> {
|
|
model.f(x) * self.dt + x
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct ImplicitEuler<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 ImplicitEuler<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)
|
|
}
|
|
}
|