From 939eae9af1469034103dfddb903b8de079a693c2 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 21 Sep 2020 16:24:31 +0200 Subject: [PATCH] apply -d1.rev() on right boundary --- heat-equation/src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/heat-equation/src/main.rs b/heat-equation/src/main.rs index 7709826..7080b5e 100644 --- a/heat-equation/src/main.rs +++ b/heat-equation/src/main.rs @@ -47,7 +47,12 @@ fn dual_dirichlet(v: ArrayView1, v0: Float, vn: Float) { for (d, fut) in d1.iter().zip(fut.iter_mut()) { *fut += tau.0 / (h * h) * d * (prev[0] - v0); } - for (d, fut) in d1.iter().zip(fut.iter_mut().rev().take(d1.len()).rev()) { + for (d, fut) in d1 + .iter() + .rev() + .map(|d| -d) + .zip(fut.iter_mut().rev().take(d1.len()).rev()) + { *fut += tau.1 / (h * h) * d * (prev[nx - 1] - vn); } }; @@ -109,7 +114,12 @@ fn neumann_dirichlet(v: ArrayView1, v0: Float, vn: Float) { .map(|(x, y)| x * y) .sum::() - v0); - for (d, fut) in d1.iter().zip(fut.iter_mut().rev().take(d1.len()).rev()) { + for (d, fut) in d1 + .iter() + .rev() + .map(|d| -d) + .zip(fut.iter_mut().rev().take(d1.len()).rev()) + { *fut += tau.1 / (h * h) * d * (prev[nx - 1] - vn); } };