Fix the inverted sign so that the energy looks reasonable now
This commit is contained in:
@@ -4,7 +4,8 @@ use std::{thread, time};
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut state = SimState::new(16);
|
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 {
|
loop {
|
||||||
NumericTermRenderer.render(&state);
|
NumericTermRenderer.render(&state);
|
||||||
state.step();
|
state.step();
|
||||||
|
21
src/lib.rs
21
src/lib.rs
@@ -17,7 +17,8 @@ pub mod render;
|
|||||||
mod consts {
|
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;
|
||||||
|
// pub const Z0: f32 = 376.73031366857f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -103,16 +104,16 @@ impl Cell {
|
|||||||
|
|
||||||
fn step_e(self, left: Cell) -> Self {
|
fn step_e(self, left: Cell) -> Self {
|
||||||
// Maxwell's equation: del x B = mu_0 eps_0 dE/dt
|
// Maxwell's equation: del x B = mu_0 eps_0 dE/dt
|
||||||
// Expands: -dB_z/dx = mu_0 eps_0 dE_y/dt
|
// Expands: dB_y/dx = mu_0 eps_0 dE_y/dt
|
||||||
// Rearrange: dE_y/dt = -1/(mu_0 eps_0) dB_z/dx
|
// 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_z)/(delta x)
|
// 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_z)
|
// 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_z)
|
// 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:
|
// Note that c = 1/sqrt(mu_0 eps_0), so this becomes:
|
||||||
// delta E_y = c (-delta B_z)
|
// delta E_y = c (delta B_y)
|
||||||
// XXX once again this diffes from [1]
|
// XXX once again this differs from [1]
|
||||||
let delta_b = self.by - left.by;
|
let delta_b = self.by - left.by; //< delta B_y
|
||||||
let delta_e = (-delta_b) * consts::C;
|
let delta_e = delta_b * consts::C; //< delta E_z
|
||||||
Cell {
|
Cell {
|
||||||
ez: self.ez + delta_e,
|
ez: self.ez + delta_e,
|
||||||
by: self.by,
|
by: self.by,
|
||||||
|
@@ -4,13 +4,13 @@ pub struct NumericTermRenderer;
|
|||||||
|
|
||||||
impl NumericTermRenderer {
|
impl NumericTermRenderer {
|
||||||
pub fn render(&self, state: &SimState) {
|
pub fn render(&self, state: &SimState) {
|
||||||
print!("E: ");
|
print!("E:");
|
||||||
for cell in state.cells() {
|
for cell in state.cells() {
|
||||||
print!("{:>8.1e} ", cell.ez());
|
print!("{:>10.1e} ", cell.ez());
|
||||||
}
|
}
|
||||||
print!("\nB: ");
|
print!("\nB: ");
|
||||||
for cell in state.cells() {
|
for cell in state.cells() {
|
||||||
print!("{:>8.1e} ", cell.by());
|
print!("{:>10.1e} ", cell.by());
|
||||||
}
|
}
|
||||||
print!("\n");
|
print!("\n");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user