Make measurements also be 3d

This commit is contained in:
2020-09-18 17:11:05 -07:00
parent 7029c8bcfa
commit 8a70276c78
4 changed files with 46 additions and 7 deletions

View File

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

View File

@@ -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()
//}

View File

@@ -125,6 +125,9 @@ impl<M> SimState<M> {
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<M> Cell<M> {
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<M: Material> Cell<M> {
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) {

View File

@@ -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<Real> for Vec3 {
}
}
impl MulAssign<Flt> for Vec3 {
fn mul_assign(&mut self, other: Flt) {
self.x *= other;
self.y *= other;
self.z *= other;
}
}
impl Mul<Flt> for Vec3 {
type Output = Self;
fn mul(self, other: Flt) -> Self {
let mut work = self.clone();
work *= other;
work
}
}
impl DivAssign<Real> for Vec3 {
fn div_assign(&mut self, other: Real) {
*self *= Real::from_inner(1.0) / other;
@@ -110,3 +131,18 @@ impl Div<Real> for Vec3 {
work
}
}
impl DivAssign<Flt> for Vec3 {
fn div_assign(&mut self, other: Flt) {
*self *= (1.0 / other);
}
}
impl Div<Flt> for Vec3 {
type Output = Self;
fn div(self, other: Flt) -> Self {
let mut work = self.clone();
work /= other;
work
}
}