things
This commit is contained in:
parent
a7497d6629
commit
bff0f8faf1
762
Cargo.lock
generated
762
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -182,6 +182,7 @@ impl Grid {
|
||||
rotation_angle, step_distance,
|
||||
width, height);
|
||||
});
|
||||
self.deposit_all();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@ -57,6 +57,16 @@ impl ThinGridData {
|
||||
.select_nth_unstable_by(index, |a, b| a.partial_cmp(b).unwrap());
|
||||
sorted[index]
|
||||
}
|
||||
|
||||
pub fn size_of(&self) -> usize {
|
||||
let mut output: usize = 0;
|
||||
output = output + std::mem::size_of_val(&self.width);
|
||||
output = output + std::mem::size_of_val(&self.height);
|
||||
for i in self.data.iter() {
|
||||
output = output + std::mem::size_of_val(&i);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
// Class for storing data that will be used to create images
|
||||
@ -85,6 +95,16 @@ impl ImgData {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn size_of(&self) -> usize {
|
||||
let mut output: usize = 0;
|
||||
output = output + std::mem::size_of_val(&self.iteration);
|
||||
output = output + std::mem::size_of_val(&self.palette);
|
||||
for grid in self.grids.iter() {
|
||||
output = output + grid.size_of();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn save_to_image(&self) {
|
||||
let (width, height) = (self.grids[0].width, self.grids[0].height);
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@ -4,23 +4,25 @@ fn main() {
|
||||
// # of iterations to go through
|
||||
let n_iterations = 1024;
|
||||
// let n_iterations = 2048;
|
||||
// let n_iterations = 1 << 14;
|
||||
|
||||
// Size of grid and pictures
|
||||
let (width, height) = (256, 256);
|
||||
// let (width, height) = (256, 256);
|
||||
// let (width, height) = (512, 512);
|
||||
// let (width, height) = (1024, 1024);
|
||||
let (width, height) = (1024, 1024);
|
||||
|
||||
// # of agents
|
||||
// let n_particles = 1 << 10;
|
||||
// let n_particles = 1 << 16;
|
||||
let n_particles = 1 << 20;
|
||||
// let n_particles = 1 << 20;
|
||||
let n_particles = 1 << 24;
|
||||
println!("n_particles: {}", n_particles);
|
||||
|
||||
let diffusivity = 1;
|
||||
|
||||
// `n_populations` is the # of types of agents
|
||||
let n_populations = 4;
|
||||
// let n_populations = 3;
|
||||
// let n_populations = 4;
|
||||
let n_populations = 1;
|
||||
// let n_populations = 1 + rng.gen_range(1..4); // make # of populations between 2 and 5
|
||||
|
||||
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity); // Create the model
|
||||
|
||||
27
src/model.rs
27
src/model.rs
@ -123,19 +123,10 @@ impl Model {
|
||||
let agents_tick_time = Instant::now();
|
||||
|
||||
// Tick agents
|
||||
for grid in grids.iter_mut() {
|
||||
grid.tick();
|
||||
}
|
||||
|
||||
// Deposit
|
||||
for grid in self.grids.iter_mut() {
|
||||
grid.deposit_all();
|
||||
}
|
||||
|
||||
// Diffuse + Decay
|
||||
let diffusivity = self.diffusivity;
|
||||
let diffusivity = self.diffusivity;
|
||||
self.grids.par_iter_mut().for_each(|grid| {
|
||||
grid.diffuse(diffusivity);
|
||||
grid.tick();
|
||||
grid.diffuse(diffusivity); // Diffuse + Decay
|
||||
});
|
||||
|
||||
self.save_image_data();
|
||||
@ -167,11 +158,21 @@ impl Model {
|
||||
);
|
||||
}
|
||||
|
||||
fn size_of_imgdata_vec(&self) -> usize {
|
||||
return (self.img_data_vec[0].size_of() as usize) * (self.img_data_vec.len() as usize);
|
||||
}
|
||||
|
||||
fn save_image_data(&mut self) {
|
||||
let grids = ThinGridData::new_from_grid_vec(self.grids.clone());
|
||||
let img_data = ImgData::new(grids, self.palette, self.iteration);
|
||||
self.img_data_vec.push(img_data);
|
||||
if self.grids[0].width > 1024 && self.grids[0].height > 1024 && self.img_data_vec.len() > 100 {
|
||||
let size: usize = self.size_of_imgdata_vec();
|
||||
let mb = size/1024/1024;
|
||||
// println!("{} B | {} KB | {} MB", size, size/1024, size/1024/1024);
|
||||
|
||||
let max_mb = 6000;
|
||||
if mb >= max_mb {
|
||||
println!("ram usage is over {} MB (and len of {}), flushing to disk\n", max_mb, self.img_data_vec.len());
|
||||
self.render_all_imgdata();
|
||||
self.flush_image_data();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user