diff --git a/src/meas.rs b/src/meas.rs index 75cb206..ca33bea 100644 --- a/src/meas.rs +++ b/src/meas.rs @@ -40,7 +40,7 @@ pub struct Current(pub u32, pub u32); impl AbstractMeasurement for Current { fn eval(&self, state: &SimSnapshot) -> String { let current = state.get(self.0, self.1).current(); - format!("current({}, {}): ({:.2e}, {:.2e})", self.0, self.1, current.x, current.y) + format!("current({}, {}): ({:.2e}, {:.2e}, {:.2e})", self.0, self.1, current.x(), current.y(), current.z()) } } diff --git a/src/render.rs b/src/render.rs index 6516ef3..b5c1cd7 100644 --- a/src/render.rs +++ b/src/render.rs @@ -106,11 +106,11 @@ impl<'a> RenderSteps<'a> { } } fn render_e_field(&mut self) { - self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 100.0, |cell| cell.e()); + self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 100.0, |cell| cell.e().xy()); // current self.render_vector_field(Rgb([0x00, 0xa0, 0x30]), 1.0e-12, |cell| { //if cell.mat().conductivity() >= 1.0e3 { - cell.e()*cell.mat().conductivity() + cell.e().xy()*cell.mat().conductivity() //} else { // Default::default() //} diff --git a/src/sim.rs b/src/sim.rs index 1b4b47c..68f89c2 100644 --- a/src/sim.rs +++ b/src/sim.rs @@ -125,6 +125,9 @@ impl SimState { pub fn impulse_ey(&mut self, x: u32, y: u32, ey: Flt) { self.get_mut(x, y).state.e += Vec3::new(0.0, ey, 0.0); } + pub fn impulse_ez(&mut self, x: u32, y: u32, ez: Flt) { + self.get_mut(x, y).state.e += Vec3::new(0.0, 0.0, ez); + } pub fn width(&self) -> u32 { self.cells.shape()[1] as _ @@ -178,8 +181,8 @@ impl Cell { pub fn ez(&self) -> Flt { self.state.e().z() } - pub fn e(&self) -> Point { - Point::new(self.ex(), self.ey()) + pub fn e(&self) -> Vec3 { + self.state.e() } pub fn hx(&self) -> Flt { self.state.h().x() @@ -209,9 +212,9 @@ impl Cell { self.b().z() } - pub fn current(&self) -> Point { + pub fn current(&self) -> Vec3 { let conductivity = self.mat.conductivity(); - Point::new(self.ex()*conductivity, self.ey()*conductivity) + self.e()*conductivity } fn impulse_bz(&mut self, delta_bz: Flt) { diff --git a/src/vec3.rs b/src/vec3.rs index ad06979..f0dcc9c 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -1,4 +1,5 @@ use crate::flt::{Flt, Real}; +use crate::geom::Point; use std::convert::From; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub}; @@ -32,6 +33,9 @@ impl Vec3 { pub fn z(&self) -> Flt { self.z.into() } + pub fn xy(&self) -> Point { + Point::new(self.x(), self.y()) + } } impl From<(Real, Real, Real)> for Vec3 { @@ -96,6 +100,23 @@ impl Mul for Vec3 { } } +impl MulAssign for Vec3 { + fn mul_assign(&mut self, other: Flt) { + self.x *= other; + self.y *= other; + self.z *= other; + } +} + +impl Mul for Vec3 { + type Output = Self; + fn mul(self, other: Flt) -> Self { + let mut work = self.clone(); + work *= other; + work + } +} + impl DivAssign for Vec3 { fn div_assign(&mut self, other: Real) { *self *= Real::from_inner(1.0) / other; @@ -110,3 +131,18 @@ impl Div for Vec3 { work } } + +impl DivAssign for Vec3 { + fn div_assign(&mut self, other: Flt) { + *self *= (1.0 / other); + } +} + +impl Div for Vec3 { + type Output = Self; + fn div(self, other: Flt) -> Self { + let mut work = self.clone(); + work /= other; + work + } +}