From 285950a5c36e419bc0d4fccadb26283b4b38a173 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Thu, 12 Dec 2019 19:24:22 +0100 Subject: [PATCH] add boundary terms skeleton --- main.js | 2 +- src/maxwell.rs | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 5bab799..cc88d30 100644 --- a/main.js +++ b/main.js @@ -180,7 +180,7 @@ import { Universe, default as init, set_panic_hook as setPanicHook } from "./max } const TIMEFACTOR = 10000.0; - const MAX_DT = 2.0/Math.max(width, height); + const MAX_DT = 1.0/Math.max(width, height); let t = 0; let firstDraw = true; diff --git a/src/maxwell.rs b/src/maxwell.rs index ae1d351..4bc79e1 100644 --- a/src/maxwell.rs +++ b/src/maxwell.rs @@ -122,6 +122,13 @@ impl Field { (&mut wb.y, &mut wb.buf, &mut wb.tmp) }; + let boundaries = BoundaryTerms { + north: Boundary::This, + south: Boundary::This, + west: Boundary::This, + east: Boundary::This, + }; + for i in 0..4 { // y = y0 + c*kn y.assign(&self); @@ -138,7 +145,7 @@ impl Field { } }; - RHS(&mut k[i], &y, grid, tmp); + RHS(&mut k[i], &y, grid, &boundaries, tmp); } Zip::from(&mut fut.0) @@ -166,11 +173,12 @@ fn RHS( k: &mut Field, y: &Field, grid: &Grid, + boundaries: &BoundaryTerms, tmp: &mut (Array2, Array2, Array2, Array2), ) { fluxes(k, y, grid, tmp); - SAT_characteristics(k, y, grid); + SAT_characteristics(k, y, grid, boundaries); azip!((k in &mut k.0, &detj in &grid.detj.broadcast((3, y.ny(), y.nx())).unwrap()) { @@ -252,9 +260,27 @@ fn fluxes( } } +#[derive(Clone, Debug)] +pub enum Boundary { + This, +} + +#[derive(Clone, Debug)] +pub struct BoundaryTerms { + pub north: Boundary, + pub south: Boundary, + pub east: Boundary, + pub west: Boundary, +} + #[allow(non_snake_case)] -fn SAT_characteristics(k: &mut Field, y: &Field, grid: &Grid) { - // Boundary conditions (SAT) +/// Boundary conditions (SAT) +fn SAT_characteristics( + k: &mut Field, + y: &Field, + grid: &Grid, + boundaries: &BoundaryTerms, +) { let ny = y.ny(); let nx = y.nx(); @@ -276,9 +302,11 @@ fn SAT_characteristics(k: &mut Field, y: &Field, grid: &Grid y.slice(s![.., .., 0]), + }; // East boundary let hinv = 1.0 / (SBP::h()[0] / (nx - 1) as f32); - let g = y.slice(s![.., .., 0]); for ((((mut k, v), g), &kx), &ky) in k .slice_mut(s![.., .., nx - 1]) .gencolumns_mut() @@ -309,8 +337,10 @@ fn SAT_characteristics(k: &mut Field, y: &Field, grid: &Grid y.slice(s![.., .., nx - 1]), + }; let hinv = 1.0 / (SBP::h()[0] / (nx - 1) as f32); - let g = y.slice(s![.., .., nx - 1]); for ((((mut k, v), g), &kx), &ky) in k .slice_mut(s![.., .., 0]) .gencolumns_mut() @@ -346,7 +376,9 @@ fn SAT_characteristics(k: &mut Field, y: &Field, grid: &Grid y.slice(s![.., 0, ..]), + }; let hinv = 1.0 / (SBP::h()[0] / (ny - 1) as f32); for ((((mut k, v), g), &kx), &ky) in k .slice_mut(s![.., ny - 1, ..]) @@ -377,7 +409,9 @@ fn SAT_characteristics(k: &mut Field, y: &Field, grid: &Grid y.slice(s![.., ny - 1, ..]), + }; let hinv = 1.0 / (SBP::h()[0] / (ny - 1) as f32); for ((((mut k, v), g), &kx), &ky) in k .slice_mut(s![.., 0, ..])