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::rngs::SmallRng;
|
||||||
use rand::SeedableRng;
|
use rand::{Rng, SeedableRng};
|
||||||
use crate::system::grid::{Position, VectorStorage};
|
use crate::system::grid::{Position, VectorStorage};
|
||||||
use crate::system::model::DLASystem;
|
use crate::system::model::DLASystem;
|
||||||
use crate::system::nd::{NDPosition, NDVectorStorage};
|
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> {
|
pub fn initial_config(seed: u64, max_particles: usize) -> DLASystem<SmallRng, Position, VectorStorage, LocalRandomWalker> {
|
||||||
DLASystem::new_g(
|
DLASystem::new_g(
|
||||||
|
|||||||
29
src/main.rs
29
src/main.rs
@ -6,10 +6,14 @@ mod system;
|
|||||||
mod example_systems;
|
mod example_systems;
|
||||||
|
|
||||||
use clap::Parser;
|
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)]
|
#[derive(Parser, Debug)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
#[arg(short, long, default_value_t = 2)]
|
||||||
|
dim: u32,
|
||||||
|
|
||||||
seed: u64,
|
seed: u64,
|
||||||
max_particles: usize,
|
max_particles: usize,
|
||||||
stick_probability: f32,
|
stick_probability: f32,
|
||||||
@ -21,16 +25,27 @@ fn main() {
|
|||||||
|
|
||||||
println!("Running: {:?}", cli);
|
println!("Running: {:?}", cli);
|
||||||
|
|
||||||
|
match cli.dim {
|
||||||
|
2 => {
|
||||||
let mut sys = stick_probability(
|
let mut sys = stick_probability(
|
||||||
cli.seed,
|
cli.seed,
|
||||||
cli.max_particles,
|
cli.max_particles,
|
||||||
cli.stick_probability
|
cli.stick_probability,
|
||||||
);
|
);
|
||||||
|
|
||||||
while sys.running {
|
execute(&mut sys, &cli.csv_path);
|
||||||
sys.update();
|
},
|
||||||
}
|
|
||||||
|
|
||||||
sys.export_data(&cli.csv_path)
|
3 => {
|
||||||
.expect("Failed to write");
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use bevy::render::color::HexColorError::Hex;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use crate::system::GriddedPosition;
|
use crate::system::GriddedPosition;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user