Add 3D support from the CLI
This commit is contained in:
parent
bc4d870e74
commit
63d2bd9461
@ -1,9 +1,20 @@
|
||||
use std::path::Path;
|
||||
use rand::rngs::SmallRng;
|
||||
use rand::SeedableRng;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use crate::system::grid::{Position, VectorStorage};
|
||||
use crate::system::model::DLASystem;
|
||||
use crate::system::nd::{NDPosition, NDVectorStorage};
|
||||
use crate::system::walker::LocalRandomWalker;
|
||||
use crate::system::{GriddedPosition, Storage};
|
||||
use crate::system::walker::{LocalRandomWalker, Walker};
|
||||
|
||||
pub fn execute<R: Rng, P: GriddedPosition, S: Storage<P>, W: Walker<P>>(sys: &mut DLASystem<R, P, S, W>, csv_path: &Path) {
|
||||
while sys.running {
|
||||
sys.update();
|
||||
}
|
||||
|
||||
sys.export_data(csv_path)
|
||||
.expect("Failed to write");
|
||||
}
|
||||
|
||||
pub fn initial_config(seed: u64, max_particles: usize) -> DLASystem<SmallRng, Position, VectorStorage, LocalRandomWalker> {
|
||||
DLASystem::new_g(
|
||||
|
||||
37
src/main.rs
37
src/main.rs
@ -6,10 +6,14 @@ mod system;
|
||||
mod example_systems;
|
||||
|
||||
use clap::Parser;
|
||||
use crate::example_systems::stick_probability;
|
||||
use crate::example_systems::{execute, stick_probability, three_dimensional};
|
||||
use crate::system::model::DLASystem;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
struct Cli {
|
||||
#[arg(short, long, default_value_t = 2)]
|
||||
dim: u32,
|
||||
|
||||
seed: u64,
|
||||
max_particles: usize,
|
||||
stick_probability: f32,
|
||||
@ -21,16 +25,27 @@ fn main() {
|
||||
|
||||
println!("Running: {:?}", cli);
|
||||
|
||||
let mut sys = stick_probability(
|
||||
cli.seed,
|
||||
cli.max_particles,
|
||||
cli.stick_probability
|
||||
);
|
||||
match cli.dim {
|
||||
2 => {
|
||||
let mut sys = stick_probability(
|
||||
cli.seed,
|
||||
cli.max_particles,
|
||||
cli.stick_probability,
|
||||
);
|
||||
|
||||
while sys.running {
|
||||
sys.update();
|
||||
execute(&mut sys, &cli.csv_path);
|
||||
},
|
||||
|
||||
3 => {
|
||||
let mut sys = three_dimensional(
|
||||
cli.seed,
|
||||
cli.max_particles,
|
||||
cli.stick_probability,
|
||||
);
|
||||
|
||||
execute(&mut sys, &cli.csv_path);
|
||||
},
|
||||
|
||||
n => panic!("Model not compiled with {n} dimensional support")
|
||||
}
|
||||
|
||||
sys.export_data(&cli.csv_path)
|
||||
.expect("Failed to write");
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use std::ops::Add;
|
||||
use bevy::render::color::HexColorError::Hex;
|
||||
use rand::Rng;
|
||||
use crate::system::GriddedPosition;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user