Skip to content

Commit

Permalink
Fix last of warnings, cleanup heat_2d_direct, rename naive in a few p…
Browse files Browse the repository at this point in the history
…laces
  • Loading branch information
SallySoul committed Dec 19, 2024
1 parent 47a39a6 commit 0ec4600
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 244 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
*.mp4
*.sh
*-e
*.txt
2 changes: 1 addition & 1 deletion examples/gen_1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nhls::stencil::*;
use nhls::util::*;
use rayon::prelude::*;

use nalgebra::{matrix, vector};
use nalgebra::matrix;

fn main() {
let name = "gen_1d.png";
Expand Down
81 changes: 0 additions & 81 deletions examples/heat_1d_ap_naive.rs

This file was deleted.

File renamed without changes.
85 changes: 85 additions & 0 deletions examples/heat_2d_p_direct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use fftw::array::AlignedVec;
use nhls::domain::*;
use nhls::image::*;
use nhls::stencil::*;
use nhls::util::*;

fn main() {
// Grid size
let grid_bound = AABB::new(matrix![0, 999; 0, 999]);

let steps_per_image = 64;

let n_images = 200;

let chunk_size = 1000;

// Step size t
let dt: f32 = 1.0;

// Step size x
let dx: f32 = 1.0;

// Step size y
let dy: f32 = 1.0;

// Heat transfer coefficient
let k_x: f32 = 0.2;
let k_y: f32 = 0.2;

let stencil = Stencil::new(
[[0, 0], [-1, 0], [1, 0], [0, -1], [0, 1]],
|args: &[f32; 5]| {
let middle = args[0];
let left = args[1];
let right = args[2];
let bottom = args[3];
let top = args[4];
middle
+ (k_x * dt / (dx * dx)) * (left - 2.0 * middle + right)
+ (k_y * dt / (dy * dy)) * (top - 2.0 * middle + bottom)
},
);

// Create domains
let buffer_size = grid_bound.buffer_size();
let mut input_buffer = AlignedVec::new(buffer_size);
let mut output_buffer = AlignedVec::new(buffer_size);
let mut input_domain = Domain::new(grid_bound, &mut input_buffer);
let mut output_domain = Domain::new(grid_bound, &mut output_buffer);

// Fill in with IC values (use normal dist for spike in the middle)
// Write out initial frame
let exclusive_bounds = grid_bound.exclusive_bounds();
let width_f = exclusive_bounds[0] as f32;
let height_f = exclusive_bounds[1] as f32;
let sigma_sq: f32 = (width_f / 25.0) * (width_f / 25.0);
let ic_gen = |coord: Coord<2>| {
let x = (coord[0] as f32) - (width_f / 2.0);
let y = (coord[1] as f32) - (height_f / 2.0);
let r = (x * x + y * y).sqrt();
let exp = -r * r / (2.0 * sigma_sq);
exp.exp()
};
input_domain.par_set_values(ic_gen, chunk_size);
image2d(&input_domain, "heat_2d_direct/frame_0000.png");

// Create boundary condition
let bc = ConstantCheck::new(
0.0,
grid_bound);

// Apply direct solver
for t in 1..n_images {
nhls::solver::direct::box_apply(
&bc,
&stencil,
&mut input_domain,
&mut output_domain,
steps_per_image,
chunk_size);

std::mem::swap(&mut input_domain, &mut output_domain);
image2d(&input_domain, &format!("heat_2d_direct/frame_{:04}.png", t));
}
}
3 changes: 1 addition & 2 deletions examples/heat_2d_p_fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ fn main() {
input_domain.par_set_values(ic_gen, chunk_size);
image2d(&input_domain, "heat_2d_fft/frame_0000.png");

// Apply periodic solver
let mut periodic_library =
nhls::solver::periodic_plan::PeriodicPlanLibrary::new(
&grid_bound,
&stencil,
);

// Backward FFT of result V
for t in 1..n_images {
periodic_library.apply(
&mut input_domain,
Expand Down
159 changes: 0 additions & 159 deletions examples/heat_2d_p_naive.rs

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/solver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod fft_plan;
pub mod naive;
pub mod direct;
pub mod periodic_naive;
pub mod periodic_plan;
pub mod trapezoid;

0 comments on commit 0ec4600

Please sign in to comment.