use nalgebra::{Vector1, Vector2, Vector3};
use crate::{DynamicalSystem, State};
pub(crate) struct UniformMotion {
pub constant_velocity: Vector3<f64>,
}
impl DynamicalSystem for UniformMotion {
type State = State<3, 2>;
fn derivatives(&self, _t: f64, _state: &State<3, 2>) -> State<3, 2> {
State::from_derivative(self.constant_velocity, Vector3::zeros())
}
}
pub(crate) struct ConstantAcceleration {
pub acceleration: Vector3<f64>,
}
impl DynamicalSystem for ConstantAcceleration {
type State = State<3, 2>;
fn derivatives(&self, _t: f64, state: &State<3, 2>) -> State<3, 2> {
State::from_derivative(*state.dy(), self.acceleration)
}
}
pub(crate) struct HarmonicOscillator;
impl DynamicalSystem for HarmonicOscillator {
type State = State<3, 2>;
fn derivatives(&self, _t: f64, state: &State<3, 2>) -> State<3, 2> {
State::from_derivative(*state.dy(), -*state.y())
}
}
pub(crate) struct HarmonicOscillator1D;
impl DynamicalSystem for HarmonicOscillator1D {
type State = State<1, 2>;
fn derivatives(&self, _t: f64, state: &State<1, 2>) -> State<1, 2> {
State::from_derivative(*state.dy(), -*state.y())
}
}
pub(crate) struct ExponentialDecay {
pub k: f64,
}
impl DynamicalSystem for ExponentialDecay {
type State = State<1, 1>;
fn derivatives(&self, _t: f64, state: &Self::State) -> Self::State {
State {
components: [Vector1::new(-self.k * state.components[0][0])],
}
}
}
pub(crate) struct HarmonicOscillator2D;
impl DynamicalSystem for HarmonicOscillator2D {
type State = State<2, 2>;
fn derivatives(&self, _t: f64, state: &State<2, 2>) -> State<2, 2> {
State::from_derivative(*state.dy(), -*state.y())
}
}
pub(crate) struct LotkaVolterra {
pub alpha: f64,
pub beta: f64,
pub delta: f64,
pub gamma: f64,
}
impl DynamicalSystem for LotkaVolterra {
type State = State<2, 1>;
fn derivatives(&self, _t: f64, state: &Self::State) -> Self::State {
let x = state.components[0][0]; let y = state.components[0][1]; State {
components: [Vector2::new(
self.alpha * x - self.beta * x * y,
self.delta * x * y - self.gamma * y,
)],
}
}
}