Initial commit
This commit is contained in:
commit
aaa212b9a9
22 changed files with 4778 additions and 0 deletions
41
examples/old/solver.rs
Normal file
41
examples/old/solver.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue