Make measurements also be 3d
This commit is contained in:
@@ -40,7 +40,7 @@ pub struct Current(pub u32, pub u32);
|
|||||||
impl AbstractMeasurement for Current {
|
impl AbstractMeasurement for Current {
|
||||||
fn eval(&self, state: &SimSnapshot) -> String {
|
fn eval(&self, state: &SimSnapshot) -> String {
|
||||||
let current = state.get(self.0, self.1).current();
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -106,11 +106,11 @@ impl<'a> RenderSteps<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn render_e_field(&mut self) {
|
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
|
// current
|
||||||
self.render_vector_field(Rgb([0x00, 0xa0, 0x30]), 1.0e-12, |cell| {
|
self.render_vector_field(Rgb([0x00, 0xa0, 0x30]), 1.0e-12, |cell| {
|
||||||
//if cell.mat().conductivity() >= 1.0e3 {
|
//if cell.mat().conductivity() >= 1.0e3 {
|
||||||
cell.e()*cell.mat().conductivity()
|
cell.e().xy()*cell.mat().conductivity()
|
||||||
//} else {
|
//} else {
|
||||||
// Default::default()
|
// Default::default()
|
||||||
//}
|
//}
|
||||||
|
11
src/sim.rs
11
src/sim.rs
@@ -125,6 +125,9 @@ impl<M> SimState<M> {
|
|||||||
pub fn impulse_ey(&mut self, x: u32, y: u32, ey: Flt) {
|
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);
|
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 {
|
pub fn width(&self) -> u32 {
|
||||||
self.cells.shape()[1] as _
|
self.cells.shape()[1] as _
|
||||||
@@ -178,8 +181,8 @@ impl<M> Cell<M> {
|
|||||||
pub fn ez(&self) -> Flt {
|
pub fn ez(&self) -> Flt {
|
||||||
self.state.e().z()
|
self.state.e().z()
|
||||||
}
|
}
|
||||||
pub fn e(&self) -> Point {
|
pub fn e(&self) -> Vec3 {
|
||||||
Point::new(self.ex(), self.ey())
|
self.state.e()
|
||||||
}
|
}
|
||||||
pub fn hx(&self) -> Flt {
|
pub fn hx(&self) -> Flt {
|
||||||
self.state.h().x()
|
self.state.h().x()
|
||||||
@@ -209,9 +212,9 @@ impl<M: Material> Cell<M> {
|
|||||||
self.b().z()
|
self.b().z()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current(&self) -> Point {
|
pub fn current(&self) -> Vec3 {
|
||||||
let conductivity = self.mat.conductivity();
|
let conductivity = self.mat.conductivity();
|
||||||
Point::new(self.ex()*conductivity, self.ey()*conductivity)
|
self.e()*conductivity
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impulse_bz(&mut self, delta_bz: Flt) {
|
fn impulse_bz(&mut self, delta_bz: Flt) {
|
||||||
|
36
src/vec3.rs
36
src/vec3.rs
@@ -1,4 +1,5 @@
|
|||||||
use crate::flt::{Flt, Real};
|
use crate::flt::{Flt, Real};
|
||||||
|
use crate::geom::Point;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub};
|
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub};
|
||||||
|
|
||||||
@@ -32,6 +33,9 @@ impl Vec3 {
|
|||||||
pub fn z(&self) -> Flt {
|
pub fn z(&self) -> Flt {
|
||||||
self.z.into()
|
self.z.into()
|
||||||
}
|
}
|
||||||
|
pub fn xy(&self) -> Point {
|
||||||
|
Point::new(self.x(), self.y())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(Real, Real, Real)> for Vec3 {
|
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 {
|
impl DivAssign<Real> for Vec3 {
|
||||||
fn div_assign(&mut self, other: Real) {
|
fn div_assign(&mut self, other: Real) {
|
||||||
*self *= Real::from_inner(1.0) / other;
|
*self *= Real::from_inner(1.0) / other;
|
||||||
@@ -110,3 +131,18 @@ impl Div<Real> for Vec3 {
|
|||||||
work
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user