Add support for ND systems

This commit is contained in:
Joshua Coles 2023-03-04 12:56:31 +00:00
parent 1c49bf92c8
commit 7cfa5092e8
2 changed files with 32 additions and 0 deletions

View File

@ -8,6 +8,7 @@ use crate::system::{GriddedPosition, Position};
use crate::system::storage::{Storage, VectorStorage}; use crate::system::storage::{Storage, VectorStorage};
use crate::system::walker::{LocalRandomWalker, Walker}; use crate::system::walker::{LocalRandomWalker, Walker};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use crate::system::nd::{NDPosition, NDVectorStorage};
pub struct DLASystem<R: Rng, P: GriddedPosition, S: Storage<P>, W: Walker<P>> { pub struct DLASystem<R: Rng, P: GriddedPosition, S: Storage<P>, W: Walker<P>> {
rng: R, rng: R,
@ -55,6 +56,31 @@ impl<R: Rng, P: GriddedPosition, S: Storage<P>, W: Walker<P>> DLASystem<R, P, S,
sys sys
} }
pub fn new_nd<const DIM: usize>(rng: R, max_particles: usize, stick_probability: f32) -> DLASystem<R, NDPosition<DIM>, NDVectorStorage<DIM>, LocalRandomWalker> {
let mut sys: DLASystem<R, NDPosition<DIM>, NDVectorStorage<DIM>, LocalRandomWalker> = DLASystem {
rng,
stick_probability,
max_particles,
running: true,
space: NDVectorStorage::new(1600),
walker: LocalRandomWalker,
particles: vec![],
active_particle: None,
add_ratio: 1.2,
kill_ratio: 1.7,
add_circle: 10.0,
kill_circle: 20.0,
cluster_radius: 0.0,
};
sys.deposit(&NDPosition::zero());
sys
}
pub fn update(&mut self) { pub fn update(&mut self) {
if self.active_particle.is_some() { if self.active_particle.is_some() {
self.move_particle(); self.move_particle();

View File

@ -10,6 +10,12 @@ pub struct NDVectorStorage<const DIM: usize> {
grid_size: u32, grid_size: u32,
} }
impl<const DIM: usize> NDVectorStorage<DIM> {
pub fn new(grid_size: u32) -> Self {
Self { grid_size, backing: vec![false; grid_size.pow(DIM as u32) as usize] }
}
}
impl<const DIM: usize> Storage<NDPosition<DIM>> for NDVectorStorage<DIM> { impl<const DIM: usize> Storage<NDPosition<DIM>> for NDVectorStorage<DIM> {
fn at(&self, position: &NDPosition<DIM>) -> bool { fn at(&self, position: &NDPosition<DIM>) -> bool {
return self.backing[position.linear_index(self.grid_size)]; return self.backing[position.linear_index(self.grid_size)];