From 2174113e7df8fd25f4af51c6ad6c54143b5d2d80 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 12 Jul 2020 21:35:40 -0700 Subject: [PATCH] Fix the inverted sign so that the energy looks reasonable now --- examples/coremem.rs | 3 ++- src/lib.rs | 21 +++++++++++---------- src/render.rs | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/coremem.rs b/examples/coremem.rs index b36e1af..686aa3f 100644 --- a/examples/coremem.rs +++ b/examples/coremem.rs @@ -4,7 +4,8 @@ use std::{thread, time}; fn main() { let mut state = SimState::new(16); - state.impulse_e(10, 1.0); + state.impulse_e(0, 1.0); + state.impulse_e(15, 1.0); loop { NumericTermRenderer.render(&state); state.step(); diff --git a/src/lib.rs b/src/lib.rs index 5271aaf..437a5b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,8 @@ pub mod render; mod consts { /// Speed of light in a vacuum; m/s. /// Also equal to 1/sqrt(epsilon_0 mu_0) - pub const C:f32 = 299792458f32; + pub const C: f32 = 299792458f32; + // pub const Z0: f32 = 376.73031366857f32; } #[derive(Default)] @@ -103,16 +104,16 @@ impl Cell { fn step_e(self, left: Cell) -> Self { // Maxwell's equation: del x B = mu_0 eps_0 dE/dt - // Expands: -dB_z/dx = mu_0 eps_0 dE_y/dt - // Rearrange: dE_y/dt = -1/(mu_0 eps_0) dB_z/dx - // Discretize: (delta E_y)/(delta t) = -1/(mu_0 eps_0) (delta dB_z)/(delta x) - // Rearrange: delta E_y = (delta t)/(delta x) 1/(mu_0 eps_0) (-delta B_z) - // Substitute c as in step_b: delta E_y = (mu_0 eps_0)/c (-delta B_z) + // Expands: dB_y/dx = mu_0 eps_0 dE_y/dt + // Rearrange: dE_y/dt = 1/(mu_0 eps_0) dB_y/dx + // Discretize: (delta E_y)/(delta t) = 1/(mu_0 eps_0) (delta dB_y)/(delta x) + // Rearrange: delta E_y = (delta t)/(delta x) 1/(mu_0 eps_0) (delta B_y) + // Substitute c as in step_b: delta E_y = (mu_0 eps_0)/c (delta B_y) // Note that c = 1/sqrt(mu_0 eps_0), so this becomes: - // delta E_y = c (-delta B_z) - // XXX once again this diffes from [1] - let delta_b = self.by - left.by; - let delta_e = (-delta_b) * consts::C; + // delta E_y = c (delta B_y) + // XXX once again this differs from [1] + let delta_b = self.by - left.by; //< delta B_y + let delta_e = delta_b * consts::C; //< delta E_z Cell { ez: self.ez + delta_e, by: self.by, diff --git a/src/render.rs b/src/render.rs index f921559..00e61db 100644 --- a/src/render.rs +++ b/src/render.rs @@ -4,13 +4,13 @@ pub struct NumericTermRenderer; impl NumericTermRenderer { pub fn render(&self, state: &SimState) { - print!("E: "); + print!("E:"); for cell in state.cells() { - print!("{:>8.1e} ", cell.ez()); + print!("{:>10.1e} ", cell.ez()); } - print!("\nB: "); + print!("\nB: "); for cell in state.cells() { - print!("{:>8.1e} ", cell.by()); + print!("{:>10.1e} ", cell.by()); } print!("\n"); }