nyx_space/mc/generator.rs
1/*
2 Nyx, blazing fast astrodynamics
3 Copyright (C) 2018-onwards Christopher Rabotin <christopher.rabotin@gmail.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19use crate::linalg::allocator::Allocator;
20use crate::linalg::DefaultAllocator;
21use crate::md::StateParameter;
22use crate::State;
23use rand_distr::{Distribution, Normal};
24
25/// A dispersions configuration, allows specifying min/max bounds (by default, they are not set)
26#[derive(Copy, Clone)]
27pub struct Dispersion<Distr: Distribution<f64> + Copy> {
28 pub param: StateParameter,
29 pub distr: Distr,
30 pub bound_min: Option<f64>,
31 pub bound_max: Option<f64>,
32}
33
34impl<Distr: Distribution<f64> + Copy> Dispersion<Distr> {
35 pub fn new(param: StateParameter, distr: Distr) -> Self {
36 Self {
37 param,
38 distr,
39 bound_min: None,
40 bound_max: None,
41 }
42 }
43}
44
45impl Dispersion<Normal<f64>> {
46 /// Initializes a new normal dispersion of zero mean from the 1σ
47 pub fn from_std_dev(param: StateParameter, std_dev: f64) -> Self {
48 Self::new(param, Normal::new(0.0, std_dev).unwrap())
49 }
50
51 /// Initializes a new normal dispersion of zero mean from the 3σ
52 pub fn from_3std_dev(param: StateParameter, std_dev: f64) -> Self {
53 Self::new(param, Normal::new(0.0, std_dev / 3.0).unwrap())
54 }
55}
56
57/// A dispersed state
58#[derive(Clone)]
59pub struct DispersedState<S: State>
60where
61 DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
62{
63 /// The dispersed state
64 pub state: S,
65 /// The dispersions applied to the template state (template state + self.actual_dispersions = self.state)
66 pub actual_dispersions: Vec<(StateParameter, f64)>,
67}