diff --git a/src/driver.rs b/src/driver.rs index b1dbfed..3c05f66 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -1,5 +1,5 @@ use crate::{flt, flt::Flt, mat}; -use crate::geom::{Coord, Index, Meters, Region, Vec3, Vec3u}; +use crate::geom::{Coord, Meters, Region, Vec3}; use crate::mat::{GenericMaterial, Material, Pml}; use crate::meas::{self, AbstractMeasurement}; use crate::real::Real as _; diff --git a/src/geom/vec.rs b/src/geom/vec.rs index 6d3ddaa..68801d2 100644 --- a/src/geom/vec.rs +++ b/src/geom/vec.rs @@ -1,4 +1,4 @@ -use crate::flt::{self, Flt}; +use crate::flt; use crate::real::{Real, ToFloat}; use super::Vec3u; diff --git a/src/geom/vecu.rs b/src/geom/vecu.rs index 117447a..fee8746 100644 --- a/src/geom/vecu.rs +++ b/src/geom/vecu.rs @@ -1,5 +1,5 @@ use crate::geom::Vec3; -use crate::real::{Real as _, ToFloat as _}; +use crate::real::ToFloat as _; use serde::{Serialize, Deserialize}; use std::fmt::{self, Display}; diff --git a/src/mat.rs b/src/mat.rs index 6068aac..4f9f8e3 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -5,7 +5,7 @@ use crate::real::Real as _; use crate::sim::{PmlParameters, PmlState, StepParameters, StepParametersMut}; use lazy_static::lazy_static; -use log::{debug, trace}; +use log::trace; use enum_dispatch::enum_dispatch; use serde::{Serialize, Deserialize}; use std::cmp::Ordering; diff --git a/src/meas.rs b/src/meas.rs index c321009..9c7c5bc 100644 --- a/src/meas.rs +++ b/src/meas.rs @@ -1,6 +1,5 @@ use crate::flt::{Flt, Real}; use crate::geom::{Meters, Region, Torus, Vec3, WorldRegion}; -use crate::mat::Material as _; use crate::real::Real as _; use crate::sim::GenericSim; use common_macros::b_tree_map; @@ -65,7 +64,7 @@ impl AbstractMeasurement for Label { fn eval(&self, _state: &dyn GenericSim) -> String { self.0.clone() } - fn key_value(&self, state: &dyn GenericSim) -> BTreeMap { + fn key_value(&self, _state: &dyn GenericSim) -> BTreeMap { b_tree_map! { self.0.clone() => self.0.clone(), } @@ -229,7 +228,7 @@ impl MagneticLoop { let to_coord = *coord - *self.region.center(); let tangent = normal.cross(to_coord).norm(); - let m = cell.mat().m(); + let m = cell.m(); let directed_m = m.dot(tangent); let b = cell.b(); let directed_b = b.dot(tangent); @@ -334,7 +333,7 @@ impl Magnetization { } fn data(&self, state: &dyn GenericSim) -> Vec3 { let FieldSample(volume, _directed_mag, mag_vec) = state.map_sum_over(&*self.region, |cell| { - let m = cell.mat().m(); + let m = cell.m(); let mag = m.mag(); FieldSample(1, mag, m) }); @@ -368,11 +367,11 @@ pub struct MagnetizationAt(pub Meters); #[typetag::serde] impl AbstractMeasurement for MagnetizationAt { fn eval(&self, state: &dyn GenericSim) -> String { - let m = state.sample(self.0).mat().m(); + let m = state.sample(self.0).m(); format!("M{}: {:.2e}", loc(self.0), m) } fn key_value(&self, state: &dyn GenericSim) -> BTreeMap { - let m = state.sample(self.0).mat().m(); + let m = state.sample(self.0).m(); b_tree_map! { format!("M{}", loc(self.0)) => m.to_string(), } diff --git a/src/render.rs b/src/render.rs index bc9ffc8..220b552 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,7 +1,6 @@ use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u}; -use crate::{Material as _, MaterialExt as _}; use crate::mat; -use crate::real::{Real as _, ToFloat as _}; +use crate::real::ToFloat as _; use crate::sim::{Cell, GenericSim, StaticSim}; use crate::meas::AbstractMeasurement; use crossterm::{cursor, QueueableCommand as _}; @@ -153,7 +152,8 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { trace!("rendering at {}x{} with z={}", width, height, z); let mut me = Self::new(state, measurements, width, height, z); me.render_scalar_field(10.0, false, 2, |cell| { - cell.mat().conductivity().mag().to_f32() + if cell.mat().is_vacuum() { + let is_vacuum = cell.conductivity() != Vec3::zero() || cell.m() != Vec3::zero(); + cell.conductivity().mag().to_f32() + if is_vacuum { 0.0 } else { 5.0 @@ -205,7 +205,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 100.0 * scale, |cell| cell.e().xy().to_f32()); // current self.render_vector_field(Rgb([0x00, 0xa0, 0x30]), 1.0e-12 * scale, |cell| { - cell.e().elem_mul(cell.mat().conductivity()).xy().to_f32() + cell.e().elem_mul(cell.conductivity()).xy().to_f32() }); } ////////////// Magnitude configuration ///////////// @@ -214,7 +214,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { } fn render_current(&mut self, scale: f32) { self.render_scalar_field(1.0e1 * scale, false, 0, |cell| { - cell.e().elem_mul(cell.mat().conductivity()).mag().to_f32() + cell.e().elem_mul(cell.conductivity()).mag().to_f32() }); } @@ -227,8 +227,8 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { } fn render_m(&mut self, scale: f32) { - self.render_scalar_field(1.0e5 * scale, false, 1, |cell| cell.mat().m().mag().to_f32()); - self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 1.0e5 * scale, |cell| cell.mat().m().xy().to_f32()); + self.render_scalar_field(1.0e5 * scale, false, 1, |cell| cell.m().mag().to_f32()); + self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 1.0e5 * scale, |cell| cell.m().xy().to_f32()); } fn render_vector_field) -> Vec2>(&mut self, color: Rgb, typical: f32, measure: F) { @@ -559,15 +559,16 @@ impl Renderer for PlotlyRenderer { yv.push(y); zv.push(z); // opacities.push((cell.e().mag() * 0.1).min(1.0) as f64) - let mat = cell.mat().conductivity().mag().to_f32() + if cell.mat().is_vacuum() { + let is_vacuum = cell.conductivity() == Vec3::zero() && cell.m() == Vec3::zero(); + let mat = cell.conductivity().mag().to_f32() + if is_vacuum { 0.0 } else { 5.0 }; //let g = scale_unsigned_to_u8(mat, 10.0); - //let r = scale_unsigned_to_u8(cell.mat().m().mag(), 100.0); + //let r = scale_unsigned_to_u8(cell.m().mag(), 100.0); //let b = scale_unsigned_to_u8(cell.e().mag(), 1e2); - let r = scale_unsigned_to_u8(cell.mat().m().mag().to_f32(), 100.0); + let r = scale_unsigned_to_u8(cell.m().mag().to_f32(), 100.0); let g = scale_unsigned_to_u8(cell.e().mag().to_f32(), 1e2); let b = scale_unsigned_to_u8(mat, 10.0); let alpha = 1.0; diff --git a/src/sim.rs b/src/sim.rs index b44849a..db897ba 100644 --- a/src/sim.rs +++ b/src/sim.rs @@ -429,7 +429,7 @@ impl SimState { let e_field = &self.e; Zip::from(ndarray::indices_of(&self.cells)).and(&mut self.cells).and(&mut self.h).par_apply( |(z, y, x), mat, h| { - let neighbors = Neighbors::new_field(e_field, [z, y, x]); + let neighbors = Neighbors::new(e_field, [z, y, x]); let e = &e_field[[z, y, x]]; HCell { mat, h, e }.step(neighbors, half_time_step, inv_feature_size); }); @@ -440,7 +440,7 @@ impl SimState { let h_field = &self.h; Zip::from(ndarray::indices_of(&self.cells)).and(&mut self.cells).and(&mut self.e).par_apply( |(z, y, x), mat, e| { - let neighbors = Neighbors::new_field(h_field, [z, y, x]); + let neighbors = Neighbors::new(h_field, [z, y, x]); let h = &h_field[[z, y, x]]; ECell { mat, e, h }.step(neighbors, half_time_step, inv_feature_size); }); @@ -594,6 +594,7 @@ impl GenericSim for SimState { } } +#[allow(unused)] impl SimState { fn get_mat(&self, c: C) -> &M { let at = c.to_index(self.feature_size.into()); @@ -711,28 +712,7 @@ struct Neighbors<'a> { } impl<'a> Neighbors<'a> { - fn new) -> &'a Vec3>(array: &'a Array3>, location: [usize; 3], m: F) -> Self { - let [z, y, x] = location; - let left = array.get([z, y, x.wrapping_sub(1)]).map(&m); - let right = array.get([z, y, x + 1]).map(&m); - let up = array.get([z, y.wrapping_sub(1), x]).map(&m); - let down = array.get([z, y + 1, x]).map(&m); - let out = array.get([z.wrapping_sub(1), y, x]).map(&m); - let in_ = array.get([z + 1, y, x]).map(&m); - Self { - left, right, up, down, out, in_ - } - } - - fn new_e(array: &'a Array3>, location: [usize; 3]) -> Self { - Self::new(array, location, |c| &c.state.e) - } - - fn new_h(array: &'a Array3>, location: [usize; 3]) -> Self { - Self::new(array, location, |c| &c.state.h) - } - - fn new_field(array: &'a Array3, location: [usize; 3]) -> Self { + fn new(array: &'a Array3, location: [usize; 3]) -> Self { let [z, y, x] = location; let left = array.get([z, y, x.wrapping_sub(1)]); let right = array.get([z, y, x + 1]); @@ -776,7 +756,7 @@ impl Cell { impl Cell { pub fn b(&self) -> Vec3 { - (self.state.h() + self.mat.m()) * consts::real::MU0() + (self.h() + self.m()) * consts::real::MU0() } pub fn bx(&self) -> Flt { Flt::from_primitive(self.b().x()) @@ -788,16 +768,16 @@ impl Cell { Flt::from_primitive(self.b().z()) } - pub fn mat(&self) -> &M { - &self.mat + pub fn m(&self) -> Vec3 { + self.mat.m() } - pub fn mat_mut(&mut self) -> &mut M { - &mut self.mat + pub fn conductivity(&self) -> Vec3 { + self.mat.conductivity() } pub fn current_density(&self) -> Vec3 { // TODO: does this make sense for Pml? - let conductivity = self.mat.conductivity(); + let conductivity = self.conductivity(); self.e().elem_mul(conductivity) }