diff --git a/examples/coremem.rs b/examples/coremem.rs index 686aa3f..71788c0 100644 --- a/examples/coremem.rs +++ b/examples/coremem.rs @@ -1,14 +1,19 @@ use coremem::SimState; use coremem::render::NumericTermRenderer; +use coremem::consts; use std::{thread, time}; fn main() { let mut state = SimState::new(16); + state.impulse_b(0, 1.0/consts::C); state.impulse_e(0, 1.0); + state.impulse_b(7, 1.0/consts::C); + state.impulse_e(7, 1.0); + state.impulse_b(15, 1.0/consts::C); state.impulse_e(15, 1.0); loop { NumericTermRenderer.render(&state); state.step(); - thread::sleep(time::Duration::from_millis(500)); + thread::sleep(time::Duration::from_millis(100)); } } diff --git a/src/lib.rs b/src/lib.rs index 437a5b6..e258955 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ pub mod render; // mu_0 = vacuum permeability = 1.25663706212(19)×10−6 H/m // c_0 = speed of light in vacuum = 299792458 -mod consts { +pub mod consts { /// Speed of light in a vacuum; m/s. /// Also equal to 1/sqrt(epsilon_0 mu_0) pub const C: f32 = 299792458f32; @@ -57,6 +57,10 @@ impl SimState { self.cells[idx].ez += e; } + pub fn impulse_b(&mut self, idx: usize, y: f32) { + self.cells[idx].by += y; + } + pub fn cells(&self) -> &[Cell] { &*self.cells } diff --git a/src/render.rs b/src/render.rs index 00e61db..fd305d6 100644 --- a/src/render.rs +++ b/src/render.rs @@ -4,14 +4,14 @@ pub struct NumericTermRenderer; impl NumericTermRenderer { pub fn render(&self, state: &SimState) { - print!("E:"); - for cell in state.cells() { - print!("{:>10.1e} ", cell.ez()); - } - print!("\nB: "); + print!("B: "); for cell in state.cells() { print!("{:>10.1e} ", cell.by()); } + print!("\nE:"); + for cell in state.cells() { + print!("{:>10.1e} ", cell.ez()); + } print!("\n"); } }