Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Domain trait, add owned and slice implementations #20

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions examples/gen_1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ fn main() {
// Create domains
let grid_bound = args.grid_bounds();
let buffer_size = grid_bound.buffer_size();
let mut grid_input = vec![0.0; buffer_size];
let mut input_domain = Domain::new(grid_bound, &mut grid_input);

let mut grid_output = vec![0.0; buffer_size];
let mut output_domain = Domain::new(grid_bound, &mut grid_output);
let mut input_domain = OwnedDomain::new(grid_bound);
let mut output_domain = OwnedDomain::new(grid_bound);

// Fill in with IC values (use normal dist for spike in the middle)
let n_f = buffer_size as f64;
Expand Down
9 changes: 2 additions & 7 deletions examples/gen_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ fn main() {
let chunk_size = 1000;

// Create domains
let buffer_size = grid_bound.buffer_size();
let mut grid_input = vec![0.0; buffer_size];
let mut input_domain: Domain<2> = Domain::new(grid_bound, &mut grid_input);

let mut grid_output = vec![0.0; buffer_size];
let mut output_domain: Domain<2> =
Domain::new(grid_bound, &mut grid_output);
let mut input_domain = OwnedDomain::new(grid_bound);
let mut output_domain = OwnedDomain::new(grid_bound);

// Fill in with IC values (use normal dist for spike in the middle)
let width_f = grid_bound.bounds[(0, 1)] as f64 + 1.0;
Expand Down
8 changes: 2 additions & 6 deletions examples/heat_1d_ap_direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ fn main() {

// Create domains
let grid_bound = args.grid_bounds();
let buffer_size = grid_bound.buffer_size();
let mut grid_input = vec![0.0; buffer_size];
let mut input_domain = Domain::new(grid_bound, &mut grid_input);

let mut grid_output = vec![0.0; buffer_size];
let mut output_domain = Domain::new(grid_bound, &mut grid_output);
let mut input_domain = OwnedDomain::new(grid_bound);
let mut output_domain = OwnedDomain::new(grid_bound);

// Create BC
let bc = ConstantCheck::new(1.0, grid_bound);
Expand Down
9 changes: 3 additions & 6 deletions examples/heat_1d_p_direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ fn main() {

// Create domains
let grid_bound = args.grid_bounds();
let buffer_size = grid_bound.buffer_size();
let mut grid_input = vec![0.0; buffer_size];
let mut input_domain = Domain::new(grid_bound, &mut grid_input);
let mut input_domain = OwnedDomain::new(grid_bound);

let mut grid_output = vec![0.0; buffer_size];
let mut output_domain = Domain::new(grid_bound, &mut grid_output);
let mut output_domain = OwnedDomain::new(grid_bound);

// Fill in with IC values (use normal dist for spike in the middle)
let n_f = buffer_size as f64;
let n_f = grid_bound.buffer_size() as f64;
let sigma_sq: f64 = (n_f / 25.0) * (n_f / 25.0);
let ic_gen = |world_coord: Coord<1>| {
let x = (world_coord[0] as f64) - (n_f / 2.0);
Expand Down
10 changes: 3 additions & 7 deletions examples/heat_1d_p_fft.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fftw::array::AlignedVec;
use nhls::domain::*;
use nhls::image_1d_example::*;
use nhls::util::*;
Expand All @@ -10,15 +9,12 @@ fn main() {

// Create domains
let grid_bound = args.grid_bounds();
let buffer_size = grid_bound.buffer_size();
let mut grid_input = AlignedVec::new(buffer_size);
let mut input_domain = Domain::new(grid_bound, &mut grid_input);
let mut input_domain = OwnedDomain::new(grid_bound);

let mut grid_output = AlignedVec::new(buffer_size);
let mut output_domain = Domain::new(grid_bound, &mut grid_output);
let mut output_domain = OwnedDomain::new(grid_bound);

// Fill in with IC values (use normal dist for spike in the middle)
let n_f = buffer_size as f64;
let n_f = grid_bound.buffer_size() as f64;
let sigma_sq: f64 = (n_f / 25.0) * (n_f / 25.0);
let ic_gen = |world_coord: Coord<1>| {
let x = (world_coord[0] as f64) - (n_f / 2.0);
Expand Down
8 changes: 2 additions & 6 deletions examples/heat_2d_p_direct.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fftw::array::AlignedVec;
use nhls::domain::*;
use nhls::image::*;
use nhls::util::*;
Expand All @@ -20,11 +19,8 @@ fn main() {
let stencil = nhls::standard_stencils::heat_2d(1.0, 1.0, 1.0, 0.2, 0.2);

// 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);
let mut input_domain = OwnedDomain::new(grid_bound);
let mut output_domain = OwnedDomain::new(grid_bound);

// Fill in with IC values (use normal dist for spike in the middle)
// Write out initial frame
Expand Down
8 changes: 2 additions & 6 deletions examples/heat_2d_p_fft.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fftw::array::AlignedVec;
use nhls::domain::*;
use nhls::image::*;
use nhls::util::*;
Expand All @@ -20,11 +19,8 @@ fn main() {
let stencil = nhls::standard_stencils::heat_2d(1.0, 1.0, 1.0, 0.2, 0.2);

// 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);
let mut input_domain = OwnedDomain::new(grid_bound);
let mut output_domain = OwnedDomain::new(grid_bound);

// Fill in with IC values (use normal dist for spike in the middle)
// Write out initial frame
Expand Down
39 changes: 24 additions & 15 deletions src/domain/bc/periodic.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
use crate::domain::bc::BCCheck;
use crate::domain::Domain;
use crate::domain::*;
use crate::util::*;

pub struct PeriodicCheck<'a, const GRID_DIMENSION: usize> {
domain: &'a Domain<'a, GRID_DIMENSION>,
pub struct PeriodicCheck<
'a,
const GRID_DIMENSION: usize,
DomainType: DomainView<GRID_DIMENSION>,
> {
domain: &'a DomainType,
}

impl<'a, const GRID_DIMENSION: usize> PeriodicCheck<'a, GRID_DIMENSION> {
pub fn new(domain: &'a Domain<'a, GRID_DIMENSION>) -> Self {
impl<
'a,
const GRID_DIMENSION: usize,
DomainType: DomainView<GRID_DIMENSION>,
> PeriodicCheck<'a, GRID_DIMENSION, DomainType>
{
pub fn new(domain: &'a DomainType) -> Self {
PeriodicCheck { domain }
}
}

impl<const GRID_DIMENSION: usize> BCCheck<GRID_DIMENSION>
for PeriodicCheck<'_, GRID_DIMENSION>
impl<
const GRID_DIMENSION: usize,
DomainType: DomainView<GRID_DIMENSION> + Sync,
> BCCheck<GRID_DIMENSION>
for PeriodicCheck<'_, GRID_DIMENSION, DomainType>
{
fn check(&self, world_coord: &Coord<GRID_DIMENSION>) -> Option<f64> {
let p_coord = &self.domain.aabb().periodic_coord(world_coord);
Expand All @@ -34,14 +45,11 @@ mod unit_tests {
fn periodic_check_test() {
{
let aabb = AABB::new(matrix![0, 10]);
let n_r = aabb.buffer_size();
let mut buffer = fftw::array::AlignedVec::new(n_r);
for i in 0..n_r {
buffer.as_slice_mut()[i] = i as f64;
}
let domain = Domain::new(aabb, buffer.as_slice_mut());

let mut domain = OwnedDomain::new(aabb);
domain.par_set_values(|coord| coord[0] as f64, 1);
let bc = PeriodicCheck::new(&domain);
for i in 0..n_r {
for (i, _) in domain.buffer().iter().enumerate() {
let v = bc.check(&vector![i as i32]);
assert_eq!(v, None);
}
Expand Down Expand Up @@ -70,5 +78,6 @@ mod unit_tests {
buffer_a[i] = i as f64;
buffer_b[i] = (n_r - i) as f64;
}
// TODO: Not sure what I wanted to do here, but clearly didn't finish
}
}
Empty file removed src/domain/bc_check.rs
Empty file.
123 changes: 0 additions & 123 deletions src/domain/domain_view.rs

This file was deleted.

24 changes: 9 additions & 15 deletions src/domain/gather_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ pub fn gather_args<
Operation,
const GRID_DIMENSION: usize,
const NEIGHBORHOOD_SIZE: usize,
DomainType: DomainView<GRID_DIMENSION>,
>(
stencil: &StencilF64<Operation, GRID_DIMENSION, NEIGHBORHOOD_SIZE>,
bc: &BC,
input: &Domain<GRID_DIMENSION>,
input: &DomainType,
world_coord: &Coord<GRID_DIMENSION>,
) -> [f64; NEIGHBORHOOD_SIZE]
where
Expand All @@ -23,12 +24,6 @@ where
result[i] = bc
.check(&n_world_coord)
.unwrap_or_else(|| input.view(&n_world_coord));
/*
println!(
"wc: {:?}, ni: {:?}, nwc: {:?}, r: {}\n",
world_coord, n_i, n_world_coord, result[i]
);
*/
}
result
}
Expand All @@ -42,13 +37,11 @@ mod unit_tests {
#[test]
fn gather_args_test_const() {
let bound = AABB::new(matrix![0, 9; 0, 9]);
let n_r = bound.buffer_size();
let mut buffer = fftw::array::AlignedVec::new(n_r);
for i in 0..n_r {
let coord = bound.linear_to_coord(i);
buffer.as_slice_mut()[i] = (coord[0] + 3 * coord[1]) as f64;
}
let domain = Domain::new(bound, buffer.as_slice_mut());
let mut domain = OwnedDomain::new(bound);
domain.par_set_values(
|coord: Coord<2>| (coord[0] + 3 * coord[1]) as f64,
1,
);
let bc = ConstantCheck::new(-4.0, bound);
let stencil = Stencil::new(
[[0, -1], [0, 1], [1, 0], [-1, 0], [0, 0]],
Expand Down Expand Up @@ -82,7 +75,8 @@ mod unit_tests {
buffer.as_slice_mut()[i]
);
}
let domain = Domain::new(bound, buffer.as_slice_mut());
let mut domain = OwnedDomain::new(bound);
domain.par_set_values(|coord| (coord[0] + 3 * coord[1]) as f64, 1);
let bc = PeriodicCheck::new(&domain);
let stencil = Stencil::new(
[[0, -1], [0, 1], [1, 0], [-1, 0], [0, 0]],
Expand Down
4 changes: 2 additions & 2 deletions src/domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//! and translate from world coordinates into view coordinates.

mod bc;
mod domain_view;
mod gather_args;
mod view;

pub use bc::*;
pub use domain_view::*;
pub use gather_args::*;
pub use view::*;
Loading
Loading