Compare commits

..

No commits in common. "183293fe7eecadab18c611c50f61d2f695b464f9" and "7216fd561e7d1fc17ffa94aaf9914704fbedfa44" have entirely different histories.

9 changed files with 116 additions and 115 deletions

View File

@ -4,8 +4,21 @@
#include <ostream> #include <ostream>
#include <new> #include <new>
struct CStorage;
struct CPosition {
int32_t _0;
int32_t _1;
};
extern "C" { extern "C" {
bool dla_rust_disabled(); CStorage *storage_new(uint32_t grid_size);
bool storage_at(const CStorage *storage, int32_t i, int32_t j);
void storage_deposit(CStorage *storage, int32_t i, int32_t j, uint8_t val);
CPosition walk(uint32_t d, int32_t i, int32_t j);
} // extern "C" } // extern "C"

View File

@ -53,7 +53,4 @@ pub struct ModelCli {
#[arg(value_enum, short, long)] #[arg(value_enum, short, long)]
pub output: PathBuf, pub output: PathBuf,
#[arg(short, long)]
pub notify_every: Option<usize>,
} }

View File

@ -8,20 +8,10 @@ use crate::system::walker::Walker;
pub mod cli; pub mod cli;
pub mod output; pub mod output;
pub fn drive_system<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, St: Sticker<P, S>>( pub fn drive_system<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, St: Sticker<P, S>>(sys: &mut DLASystem<R, P, S, W, Sp, St>, max_frames: Option<usize>) {
sys: &mut DLASystem<R, P, S, W, Sp, St>,
max_frames: Option<usize>,
notify_every: Option<usize>,
) {
let mut previous_n: usize = 0;
while sys.running { while sys.running {
sys.update(); sys.update();
if let Some(notify_every) = notify_every && (sys.history.len() % notify_every) == 0 && previous_n != sys.history.len() {
println!("On frame {}, deposited {} particles", sys.frame, sys.history.len());
previous_n = sys.history.len();
}
match max_frames { match max_frames {
Some(max_frames) if max_frames <= sys.frame => { Some(max_frames) if max_frames <= sys.frame => {
sys.running = false; sys.running = false;

View File

@ -39,6 +39,11 @@ fn write_csv_positions<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spa
fn write_json_full_data<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, St: Sticker<P, S>>(sys: &DLASystem<R, P, S, W, Sp, St>, output_path: &Path) { fn write_json_full_data<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, St: Sticker<P, S>>(sys: &DLASystem<R, P, S, W, Sp, St>, output_path: &Path) {
let file = File::create(output_path).expect("Failed to open file"); let file = File::create(output_path).expect("Failed to open file");
serde_json::to_writer(file, &sys.history) let vec: Vec<P> = sys.history
.iter()
.map(|l| l.position.clone())
.collect();
serde_json::to_writer(file, &vec)
.expect("Failed to write json"); .expect("Failed to write json");
} }

View File

@ -1,81 +1,75 @@
#![feature(array_zip)]
use system::Storage;
use crate::system::grid::{Pos2D, VectorStorage};
mod system;
#[derive(Eq, PartialEq, Debug)]
#[repr(C)]
pub struct CPosition(i32, i32);
pub struct CStorage(VectorStorage);
#[no_mangle] #[no_mangle]
pub extern "C" fn dla_rust_disabled() -> bool { pub extern "C" fn storage_new(grid_size: u32) -> &'static mut CStorage {
true let mut pntr = Box::new(CStorage(VectorStorage::new(grid_size)));
Box::leak(pntr)
} }
// #![feature(array_zip)] #[no_mangle]
// pub extern "C" fn storage_at(storage: &CStorage, i: i32, j: i32) -> bool {
// use system::Storage; storage.0.at(&Pos2D { x: i, y: j })
// use crate::system::spaces::square_grid::Grid2D; }
// use crate::system::spaces::VectorStorage;
// #[no_mangle]
// mod system; pub extern "C" fn storage_deposit(storage: &mut CStorage, i: i32, j: i32, val: u8) {
// storage.0.write(&Pos2D { x: i, y: j }, val == 1);
// #[derive(Eq, PartialEq, Debug)] }
// #[repr(C)]
// pub struct CPosition(i32, i32); #[no_mangle]
// pub extern "C" fn walk(d: u32, i: i32, j: i32) -> CPosition {
// pub struct CStorage(VectorStorage); return test::b(d, i, j);
// }
// #[no_mangle]
// pub extern "C" fn storage_new(grid_size: u32) -> &'static mut CStorage { mod test {
// let mut pntr = Box::new(CStorage(VectorStorage::new(grid_size))); use num_integer::Integer;
// Box::leak(pntr) use crate::CPosition;
// } use crate::system::grid::Pos2D;
//
// #[no_mangle] pub(crate) fn a(d: u32, i: i32, j: i32) -> CPosition {
// pub extern "C" fn storage_at(storage: &CStorage, i: i32, j: i32) -> bool { match d {
// storage.0.at(&Grid2D { x: i, y: j }) 0 => CPosition(i + 1, j),
// } 1 => CPosition(i - 1, j),
// 2 => CPosition(i, j + 1),
// #[no_mangle] 3 => CPosition(i, j - 1),
// pub extern "C" fn storage_deposit(storage: &mut CStorage, i: i32, j: i32, val: u8) { _ => panic!("Ahh"),
// storage.0.inner.(&Grid2D { x: i, y: j }, val == 1); }
// } }
//
// #[no_mangle] pub(crate) fn b(d: u32, i: i32, j: i32) -> CPosition {
// pub extern "C" fn walk(d: u32, i: i32, j: i32) -> CPosition { let (dim, sign) = d.div_rem(&2);
// return test::b(d, i, j); let sign = if sign == 0 { 1 } else { -1 };
// } // HACK: Our conventin and the MVA are different, since we are trying to strangle fig this, quick hack.
// let offset = Pos2D::in_direction(dim, sign);
// // mod test { let next = Pos2D { x: i, y: j } + offset;
// // use num_integer::Integer;
// // use crate::CPosition; CPosition(next.x, next.y)
// // use crate::system::grid::Grid2D; }
// //
// // pub(crate) fn a(d: u32, i: i32, j: i32) -> CPosition { #[test]
// // match d { fn test() {
// // 0 => CPosition(i + 1, j), let d = [0, 1, 2, 3];
// // 1 => CPosition(i - 1, j), d.iter()
// // 2 => CPosition(i, j + 1), .map(|d| d.div_rem(&2))
// // 3 => CPosition(i, j - 1), .for_each(|p| println!("{p:?}"));
// // _ => panic!("Ahh"), }
// // }
// // } #[test]
// // fn alignment() {
// // pub(crate) fn b(d: u32, i: i32, j: i32) -> CPosition { let d = [0, 1, 2, 3];
// // let (dim, sign) = d.div_rem(&2); d.iter()
// // let sign = if sign == 0 { 1 } else { -1 }; .map(|d| (a(*d, 0, 0), b(*d, 0, 0)))
// // // HACK: Our conventin and the MVA are different, since we are trying to strangle fig this, quick hack. .for_each(|p| assert_eq!(p.0, p.1));
// // let offset = Grid2D::in_direction(dim, sign); }
// // let next = Grid2D { x: i, y: j } + offset; }
// //
// // CPosition(next.x, next.y)
// // }
// //
// // #[test]
// // fn test() {
// // let d = [0, 1, 2, 3];
// // d.iter()
// // .map(|d| d.div_rem(&2))
// // .for_each(|p| println!("{p:?}"));
// // }
// //
// // #[test]
// // fn alignment() {
// // let d = [0, 1, 2, 3];
// // d.iter()
// // .map(|d| (a(*d, 0, 0), b(*d, 0, 0)))
// // .for_each(|p| assert_eq!(p.0, p.1));
// // }
// // }

View File

@ -1,6 +1,5 @@
#![feature(array_zip)] #![feature(array_zip)]
#![feature(generic_const_exprs)] #![feature(generic_const_exprs)]
#![feature(let_chains)]
use clap::Parser; use clap::Parser;
use rand::prelude::*; use rand::prelude::*;
@ -36,7 +35,7 @@ fn main() {
cli.max_particles, cli.max_particles,
); );
drive_system(&mut sys, cli.max_frames, cli.notify_every); drive_system(&mut sys, cli.max_frames);
write(&sys, cli.format, &cli.output); write(&sys, cli.format, &cli.output);
} }
@ -50,7 +49,7 @@ fn main() {
cli.max_particles, cli.max_particles,
); );
drive_system(&mut sys, cli.max_frames, cli.notify_every); drive_system(&mut sys, cli.max_frames);
write(&sys, cli.format, &cli.output); write(&sys, cli.format, &cli.output);
} }
@ -64,7 +63,7 @@ fn main() {
cli.max_particles, cli.max_particles,
); );
drive_system(&mut sys, cli.max_frames, cli.notify_every); drive_system(&mut sys, cli.max_frames);
write(&sys, cli.format, &cli.output); write(&sys, cli.format, &cli.output);
} }
@ -78,7 +77,7 @@ fn main() {
cli.max_particles, cli.max_particles,
); );
drive_system(&mut sys, cli.max_frames, cli.notify_every); drive_system(&mut sys, cli.max_frames);
write(&sys, cli.format, &cli.output); write(&sys, cli.format, &cli.output);
} }
@ -92,7 +91,7 @@ fn main() {
cli.max_particles, cli.max_particles,
); );
drive_system(&mut sys, cli.max_frames, cli.notify_every); drive_system(&mut sys, cli.max_frames);
write(&sys, cli.format, &cli.output); write(&sys, cli.format, &cli.output);
} }
} }

View File

@ -1,12 +1,18 @@
use std::fs::File;
use std::path::Path;
use bevy::render::render_resource::AsBindGroupShaderType;
use kd_tree::KdTree;
use rand::rngs::SmallRng; use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use crate::system::model::DLASystem; use crate::system::model::DLASystem;
use crate::system::{Storage}; use crate::system::{Position, Storage};
use crate::system::spaces::square_grid::Grid2D; use crate::system::spaces::continuous::{ContinuousSticker, ContinuousStorage, ContinuousWalker, P3};
use crate::system::spaces::hexagonal::HexPosition;
use crate::system::spaces::square_grid::{Grid2D, Grid3D};
use crate::system::spaces::VectorStorage; use crate::system::spaces::VectorStorage;
use crate::system::spawner::UniformSpawner; use crate::system::spawner::{Spawner, UniformSpawner};
use crate::system::sticker::{ProbabilisticSticking, SimpleSticking, Sticker}; use crate::system::sticker::{ProbabilisticSticking, SimpleSticking, Sticker};
use crate::system::walker::LocalRandomWalker; use crate::system::walker::{LocalRandomWalker, Walker};
struct LoggerSticker { struct LoggerSticker {
inner: SimpleSticking inner: SimpleSticking
@ -36,7 +42,7 @@ impl Storage<Grid2D> for ReadOnlyVectorStorage {
} }
} }
pub fn surface_probability_measure(seed: u64, max_particles: usize, stick_probability: f32) -> DLASystem<SmallRng, Grid2D, VectorStorage, LocalRandomWalker, UniformSpawner, ProbabilisticSticking> { pub fn surface_probability_measure(seed: u64, max_particles: usize, stick_probability: f32) -> DLASystem<SmallRng, HexPosition, VectorStorage, LocalRandomWalker, UniformSpawner, ProbabilisticSticking> {
DLASystem::new( DLASystem::new(
SmallRng::seed_from_u64(seed), SmallRng::seed_from_u64(seed),
VectorStorage::new(1600, 3), VectorStorage::new(1600, 3),

View File

@ -140,19 +140,16 @@ impl GriddedPosition for Grid3D {
assert!(self.y < grid_size && -(grid_size) < self.y); assert!(self.y < grid_size && -(grid_size) < self.y);
assert!(self.z < grid_size && -(grid_size) < self.z); assert!(self.z < grid_size && -(grid_size) < self.z);
let half_grid = (grid_size) / 2; let x = (self.x + (grid_size) / 2) as usize;
let x = (self.x + half_grid) as usize; let y = (self.y + (grid_size) / 2) as usize;
let y = (self.y + half_grid) as usize; let z = (self.z + (grid_size) / 2) as usize;
let z = (self.z + half_grid) as usize;
let grid_size_usize = grid_size as usize;
let linear_index = let linear_index =
(grid_size_usize * grid_size_usize) * z (grid_size as usize * grid_size as usize) * z
+ (grid_size_usize) * y + (grid_size as usize) * y
+ x; + x;
if linear_index >= (grid_size_usize * grid_size_usize * grid_size_usize) as usize { if linear_index >= (grid_size * grid_size * grid_size) as usize {
eprintln!("AHHH SOMETHING WENT WRONG {:?} gives {}", self, linear_index); eprintln!("AHHH SOMETHING WENT WRONG {:?} gives {}", self, linear_index);
} }

View File

@ -8,7 +8,7 @@ pub struct VectorStorage {
impl VectorStorage { impl VectorStorage {
pub fn new(grid_size: u32, dimension: u32) -> VectorStorage { pub fn new(grid_size: u32, dimension: u32) -> VectorStorage {
VectorStorage { grid_size, dimension, backing: vec![false; (grid_size as usize).pow(dimension) as usize] } VectorStorage { grid_size, dimension, backing: vec![false; grid_size.pow(dimension) as usize] }
} }
} }