Track the simulation time, and configure the feature size

This commit is contained in:
2020-07-31 19:01:00 -07:00
parent 5e4699b3e6
commit 72c2ee599e
3 changed files with 22 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ use coremem::consts;
use std::{thread, time};
fn main() {
let mut state = SimState::new(101, 101);
let mut state = SimState::new(101, 101, 1e-3 /* feature size */);
for y in 70..100 {
for x in 0..100 {

View File

@@ -34,23 +34,35 @@ pub mod consts {
pub fn MU0() -> R64 {
super::MU0.into()
}
pub fn HALF() -> R64 {
0.5.into()
}
}
}
#[derive(Default)]
pub struct SimState {
cells: Array2<Cell<GenericMaterial>>,
feature_size: R64,
step_no: u64,
}
impl SimState {
pub fn new(width: usize, height: usize) -> Self {
pub fn new(width: usize, height: usize, feature_size: f64) -> Self {
Self {
cells: Array2::default((height, width)),
feature_size: feature_size.into(),
..Default::default()
}
}
pub fn time(&self) -> f64 {
(self.timestep() * self.step_no as f64).into()
}
pub fn step(&mut self) {
// feature size: 1mm.
use consts::real::*;
let half_time_step = HALF() * self.timestep();
let half_time_step = 0.0005 / consts::C;
let mut working_cells = Array2::default((self.height(), self.width()));
// first advance all the magnetic fields
@@ -74,6 +86,7 @@ impl SimState {
}
}
std::mem::swap(&mut working_cells, &mut self.cells);
self.step_no += 1;
}
pub fn impulse_ex(&mut self, x: usize, y: usize, ex: f64) {
@@ -98,6 +111,11 @@ impl SimState {
pub fn get_mut(&mut self, x: usize, y: usize) -> &mut Cell<GenericMaterial> {
&mut self.cells[[y, x]]
}
fn timestep(&self) -> R64 {
self.feature_size / consts::real::C()
}
}
/// Conceptually, one cell looks like this:

View File

@@ -60,6 +60,6 @@ impl ColorTermRenderer {
}
write!(&mut buf, "\n");
}
println!("{}", buf);
println!("{}\ntime: {:.3e}", buf, state.time());
}
}