Fix the inverted sign so that the energy looks reasonable now

This commit is contained in:
2020-07-12 21:35:40 -07:00
parent 0ea06af0b0
commit 2174113e7d
3 changed files with 17 additions and 15 deletions

View File

@@ -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();

View File

@@ -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,

View File

@@ -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");
}