Cache the timestep
field on the SimState.
This commit is contained in:
21
src/sim.rs
21
src/sim.rs
@@ -358,6 +358,7 @@ pub struct SimState<M=GenericMaterial> {
|
|||||||
scratch: Array3<Cell<M>>,
|
scratch: Array3<Cell<M>>,
|
||||||
feature_size: Real,
|
feature_size: Real,
|
||||||
step_no: u64,
|
step_no: u64,
|
||||||
|
timestep: Real,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M> SimState<M> {
|
impl<M> SimState<M> {
|
||||||
@@ -381,6 +382,12 @@ impl<M> SimState<M> {
|
|||||||
self.feature_size.into()
|
self.feature_size.into()
|
||||||
}
|
}
|
||||||
pub fn timestep(&self) -> Flt {
|
pub fn timestep(&self) -> Flt {
|
||||||
|
self.timestep.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<M: Default> SimState<M> {
|
||||||
|
pub fn new(size: Index, feature_size: Flt) -> Self {
|
||||||
// XXX this has to be multiplied by a Courant Number in order to ensure stability.
|
// XXX this has to be multiplied by a Courant Number in order to ensure stability.
|
||||||
// For 3d, we need 3 full timesteps in order to communicate information across the corner
|
// For 3d, we need 3 full timesteps in order to communicate information across the corner
|
||||||
// of a grid. The distance traveled during that time is \sqrt{3}. Hence each timestep needs
|
// of a grid. The distance traveled during that time is \sqrt{3}. Hence each timestep needs
|
||||||
@@ -388,16 +395,13 @@ impl<M> SimState<M> {
|
|||||||
// In 2d, this would be \sqrt{2}/2.
|
// In 2d, this would be \sqrt{2}/2.
|
||||||
// It's an upper limit though; it should be safe to go lower.
|
// It's an upper limit though; it should be safe to go lower.
|
||||||
let courant = 0.577;
|
let courant = 0.577;
|
||||||
(self.feature_size / consts::real::C() * courant).into()
|
let feature_size = Real::from(feature_size);
|
||||||
}
|
let timestep = feature_size / consts::real::C() * courant;
|
||||||
}
|
|
||||||
|
|
||||||
impl<M: Default> SimState<M> {
|
|
||||||
pub fn new(size: Index, feature_size: Flt) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
cells: Array3::default((size.z() as _, size.y() as _, size.x() as _)),
|
cells: Array3::default((size.z() as _, size.y() as _, size.x() as _)),
|
||||||
scratch: Array3::default((size.z() as _, size.y() as _, size.x() as _)),
|
scratch: Array3::default((size.z() as _, size.y() as _, size.x() as _)),
|
||||||
feature_size: feature_size.into(),
|
feature_size,
|
||||||
|
timestep,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,7 +410,7 @@ impl<M: Default> SimState<M> {
|
|||||||
impl<M: Material + Clone + Default + Send + Sync + 'static> SimState<M> {
|
impl<M: Material + Clone + Default + Send + Sync + 'static> SimState<M> {
|
||||||
pub fn step(&mut self) {
|
pub fn step(&mut self) {
|
||||||
use consts::real::*;
|
use consts::real::*;
|
||||||
let time_step = Real::from_inner(self.timestep());
|
let time_step = self.timestep;
|
||||||
let half_time_step = HALF() * time_step;
|
let half_time_step = HALF() * time_step;
|
||||||
let feature_size = self.feature_size;
|
let feature_size = self.feature_size;
|
||||||
let inv_feature_size = Real::from_inner(1.0) / feature_size;
|
let inv_feature_size = Real::from_inner(1.0) / feature_size;
|
||||||
@@ -843,7 +847,6 @@ impl<M: Material> Cell<M> {
|
|||||||
use consts::real::{HALF, ONE, TWO, ZERO};
|
use consts::real::{HALF, ONE, TWO, ZERO};
|
||||||
// let inv_feature_size = Real::from_inner(1.0) / feature_size;
|
// let inv_feature_size = Real::from_inner(1.0) / feature_size;
|
||||||
let twice_delta_t = TWO() * delta_t;
|
let twice_delta_t = TWO() * delta_t;
|
||||||
let half_delta_t = HALF() * delta_t;
|
|
||||||
|
|
||||||
let b_prev = self.b();
|
let b_prev = self.b();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user