Render the B/E fields in a way that's a little more insightful

This commit is contained in:
2020-07-12 21:52:20 -07:00
parent 2174113e7d
commit 52c2b5be5a
3 changed files with 16 additions and 7 deletions

View File

@@ -1,14 +1,19 @@
use coremem::SimState; use coremem::SimState;
use coremem::render::NumericTermRenderer; use coremem::render::NumericTermRenderer;
use coremem::consts;
use std::{thread, time}; use std::{thread, time};
fn main() { fn main() {
let mut state = SimState::new(16); let mut state = SimState::new(16);
state.impulse_b(0, 1.0/consts::C);
state.impulse_e(0, 1.0); 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); state.impulse_e(15, 1.0);
loop { loop {
NumericTermRenderer.render(&state); NumericTermRenderer.render(&state);
state.step(); state.step();
thread::sleep(time::Duration::from_millis(500)); thread::sleep(time::Duration::from_millis(100));
} }
} }

View File

@@ -14,7 +14,7 @@ pub mod render;
// mu_0 = vacuum permeability = 1.25663706212(19)×106 H/m // mu_0 = vacuum permeability = 1.25663706212(19)×106 H/m
// c_0 = speed of light in vacuum = 299792458 // c_0 = speed of light in vacuum = 299792458
mod consts { pub mod consts {
/// Speed of light in a vacuum; m/s. /// Speed of light in a vacuum; m/s.
/// Also equal to 1/sqrt(epsilon_0 mu_0) /// Also equal to 1/sqrt(epsilon_0 mu_0)
pub const C: f32 = 299792458f32; pub const C: f32 = 299792458f32;
@@ -57,6 +57,10 @@ impl SimState {
self.cells[idx].ez += e; 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] { pub fn cells(&self) -> &[Cell] {
&*self.cells &*self.cells
} }

View File

@@ -4,14 +4,14 @@ pub struct NumericTermRenderer;
impl NumericTermRenderer { impl NumericTermRenderer {
pub fn render(&self, state: &SimState) { pub fn render(&self, state: &SimState) {
print!("E:"); print!("B: ");
for cell in state.cells() {
print!("{:>10.1e} ", cell.ez());
}
print!("\nB: ");
for cell in state.cells() { for cell in state.cells() {
print!("{:>10.1e} ", cell.by()); print!("{:>10.1e} ", cell.by());
} }
print!("\nE:");
for cell in state.cells() {
print!("{:>10.1e} ", cell.ez());
}
print!("\n"); print!("\n");
} }
} }