Formatting changes
This commit is contained in:
29
src/ode.rs
29
src/ode.rs
@@ -4,8 +4,8 @@ use nalgebra::SVector;
|
||||
/// determined upon creation of the object
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ODE<'a, const D: usize, P> {
|
||||
pub f: &'a dyn Fn(f64, SVector<f64,D>, &P) -> SVector<f64,D>,
|
||||
pub y: SVector<f64,D>,
|
||||
pub f: &'a dyn Fn(f64, SVector<f64, D>, &P) -> SVector<f64, D>,
|
||||
pub y: SVector<f64, D>,
|
||||
pub t: f64,
|
||||
pub params: P,
|
||||
pub t0: f64,
|
||||
@@ -14,28 +14,27 @@ pub struct ODE<'a, const D: usize, P> {
|
||||
pub finished: bool,
|
||||
}
|
||||
|
||||
impl<'a, const D: usize, P> ODE<'a,D, P> {
|
||||
impl<'a, const D: usize, P> ODE<'a, D, P> {
|
||||
pub fn new(
|
||||
f: &'a (dyn Fn(f64, SVector<f64,D>, &P) -> SVector<f64,D>),
|
||||
f: &'a (dyn Fn(f64, SVector<f64, D>, &P) -> SVector<f64, D>),
|
||||
t0: f64,
|
||||
t_end: f64,
|
||||
y0: SVector<f64,D>,
|
||||
y0: SVector<f64, D>,
|
||||
params: P,
|
||||
) -> Self {
|
||||
Self {
|
||||
f: f,
|
||||
f,
|
||||
y: y0,
|
||||
t: t0,
|
||||
params: params,
|
||||
t0: t0,
|
||||
t_end: t_end,
|
||||
params,
|
||||
t0,
|
||||
t_end,
|
||||
h: 0.001,
|
||||
finished: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -44,7 +43,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_ode_creation() {
|
||||
type Params = ();
|
||||
fn derivative(_t: f64, y: Vector3<f64>, _p: &Params) -> Vector3<f64> { -y }
|
||||
fn derivative(_t: f64, y: Vector3<f64>, _p: &Params) -> Vector3<f64> {
|
||||
-y
|
||||
}
|
||||
|
||||
let y0 = Vector3::new(1.0, 0.0, 0.0);
|
||||
let ode = ODE::new(&derivative, 0.0, 10.0, y0, ());
|
||||
@@ -62,7 +63,11 @@ mod tests {
|
||||
let params = (34.0, true);
|
||||
|
||||
fn derivative(t: f64, y: Vector3<f64>, p: &Params) -> Vector3<f64> {
|
||||
if p.1 { -y } else { y * t }
|
||||
if p.1 {
|
||||
-y
|
||||
} else {
|
||||
y * t
|
||||
}
|
||||
}
|
||||
|
||||
let y0 = Vector3::new(1.0, 0.0, 0.0);
|
||||
|
||||
Reference in New Issue
Block a user