BIG rewrite and changes (too many to list)
This commit is contained in:
parent
dc2e46c51b
commit
4864ccae75
27
TODO.md
27
TODO.md
@ -1,13 +1,20 @@
|
|||||||
### Todo:
|
### Todo:
|
||||||
- Auto create a mp4 from generate images
|
1. `grid.rs`
|
||||||
- Instead of using the command `ffmpeg -r 20 -i tmp/out_%d.png -vcodec libx265 -crf 25 -s 512x512 test.mp4` maybe use a rust library to do the same (more research needed)
|
- Remove need for `deposit`/`deposit_all`
|
||||||
- GPU compute
|
- Possible solution: Make it so when data is called, it generates it in a function when needed
|
||||||
|
2. GPU compute
|
||||||
- Tried [ArrayFire-rust](https://github.com/arrayfire/arrayfire-rust) didn't work well, looking for another library
|
- Tried [ArrayFire-rust](https://github.com/arrayfire/arrayfire-rust) didn't work well, looking for another library
|
||||||
- Try using [emu](https://github.com/calebwin/emu) (seems to be a very good option)
|
- Try using [emu](https://github.com/calebwin/emu) (seems to be a very good option)
|
||||||
- sin and cos optimizations
|
- emu seems to be the way to go
|
||||||
- sin/cos table?
|
- May have to completely rewrite simulation to run on the gpu (that'll be fun *pain*)
|
||||||
- Make colisions for walls of grid
|
3. Auto create a video from generated images
|
||||||
- Add config and cmd arguments when running the binary to adjust simulation settings
|
- Instead of using the command `ffmpeg -r 20 -i tmp/out_%d.png -vcodec libx265 -crf 25 -s 512x512 test.mp4` maybe use a rust library to do the same (more research needed)
|
||||||
- Rewrite `grid.rs`
|
4. Live output
|
||||||
- Move agent list to grid type
|
- Might want to do after #3 ("Auto create a video from generated images")
|
||||||
- Remove need for `deposit` function
|
5. Make collisions for walls of grid
|
||||||
|
6. Add config and cmd arguments when running the binary to adjust simulation settings7.
|
||||||
|
7. sin and cos optimizations
|
||||||
|
- sin/cos table
|
||||||
|
- precompute before simulation
|
||||||
|
- Cache sin/cos values in hashmap to be recalled later
|
||||||
|
- In order to peruse this route, I have to figure out how to access a hashmap in parallel
|
||||||
@ -22,12 +22,8 @@ impl Display for Agent {
|
|||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{{\n (x,y): ({},{})\n angle: {}\n population id: {}, i: {} }}",
|
"{{\n(x,y): ({},{})\nangle: {}\npopulation id: {}\ni: {}}}",
|
||||||
self.x,
|
self.x, self.y, self.angle, self.population_id, self.i,
|
||||||
self.y,
|
|
||||||
self.angle,
|
|
||||||
self.population_id,
|
|
||||||
self.i,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/grid.rs
18
src/grid.rs
@ -4,8 +4,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use rand::{distributions::Uniform, Rng};
|
use rand::{distributions::Uniform, Rng};
|
||||||
|
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
use rayon::{iter::ParallelIterator, prelude::*};
|
||||||
|
|
||||||
// A population configuration.
|
// A population configuration.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -159,6 +159,22 @@ impl Grid {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn tick(&mut self) {
|
||||||
|
let self_immutable = self.clone();
|
||||||
|
self.agents.par_iter_mut().for_each(|agent| {
|
||||||
|
agent.tick(&self_immutable);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn deposit_all(&mut self) {
|
||||||
|
let agent_list = self.agents.clone();
|
||||||
|
for agent in agent_list.iter() {
|
||||||
|
self.deposit(agent.x, agent.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// No longer needed (moved to imgdata.rs)
|
// No longer needed (moved to imgdata.rs)
|
||||||
/*
|
/*
|
||||||
pub fn quantile(&self, fraction: f32) -> f32 {
|
pub fn quantile(&self, fraction: f32) -> f32 {
|
||||||
|
|||||||
@ -11,8 +11,8 @@ fn main() {
|
|||||||
// let (width, height) = (1024, 1024);
|
// let (width, height) = (1024, 1024);
|
||||||
|
|
||||||
// # of agents
|
// # of agents
|
||||||
let n_particles = 1 << 10;
|
// let n_particles = 1 << 10;
|
||||||
// let n_particles = 1 << 16;
|
let n_particles = 1 << 16;
|
||||||
println!("n_particles: {}", n_particles);
|
println!("n_particles: {}", n_particles);
|
||||||
|
|
||||||
let diffusivity = 1;
|
let diffusivity = 1;
|
||||||
|
|||||||
13
src/model.rs
13
src/model.rs
@ -118,23 +118,16 @@ impl Model {
|
|||||||
// Combine grids
|
// Combine grids
|
||||||
let grids = &mut self.grids;
|
let grids = &mut self.grids;
|
||||||
combine(grids, &self.attraction_table);
|
combine(grids, &self.attraction_table);
|
||||||
let grids_immutable_1 = &grids.clone();
|
|
||||||
|
|
||||||
let agents_tick_time = Instant::now();
|
let agents_tick_time = Instant::now();
|
||||||
|
|
||||||
// Tick agents
|
// Tick agents
|
||||||
for grid in grids.iter_mut() {
|
for grid in grids.iter_mut() {
|
||||||
grid.agents.par_iter_mut().for_each(|agent| {
|
grid.tick();
|
||||||
agent.tick(&grids_immutable_1[agent.population_id]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deposit
|
// Deposit
|
||||||
let grids_immutable_2 = &grids.clone();
|
for grid in self.grids.iter_mut() {
|
||||||
for grid in grids_immutable_2.iter() {
|
grid.deposit_all();
|
||||||
for agent in grid.agents.iter() {
|
|
||||||
self.grids[agent.population_id].deposit(agent.x, agent.y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diffuse + Decay
|
// Diffuse + Decay
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn wrap(x: f32, max: f32) -> f32 {
|
pub fn wrap(x: f32, max: f32) -> f32 {
|
||||||
x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32)
|
x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user