Render the B/E fields in a way that's a little more insightful
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user