diff --git a/src/render.rs b/src/render.rs index 220b552..9f2573c 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,7 +1,6 @@ use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u}; -use crate::mat; use crate::real::ToFloat as _; -use crate::sim::{Cell, GenericSim, StaticSim}; +use crate::sim::{GenericSim, Sample, StaticSim}; use crate::meas::AbstractMeasurement; use crossterm::{cursor, QueueableCommand as _}; use crossterm::style::{style, Color, PrintStyledContent}; @@ -188,7 +187,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { } } - fn get_at_px(&self, x_px: u32, y_px: u32) -> Cell { + fn get_at_px(&self, x_px: u32, y_px: u32) -> Sample { let x_prop = x_px as f32 / self.im.width() as f32; let x_m = x_prop * (self.sim.width() as f32 * self.sim.feature_size() as f32); let y_prop = y_px as f32 / self.im.height() as f32; @@ -231,7 +230,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { 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) { + fn render_vector_field Vec2>(&mut self, color: Rgb, typical: f32, measure: F) { let w = self.im.width(); let h = self.im.height(); let vec_spacing = 10; @@ -246,7 +245,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { } } } - fn render_scalar_field) -> f32 + Sync>(&mut self, typical: f32, signed: bool, slot: u32, measure: F) { + fn render_scalar_field f32 + Sync>(&mut self, typical: f32, signed: bool, slot: u32, measure: F) { // XXX: get_at_px borrows self, so we need to clone the image to operate on it mutably. let mut im = self.im.clone(); let w = im.width(); @@ -292,7 +291,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> { } } - fn field_vector) -> Vec2>(&self, xidx: u32, yidx: u32, size: u32, measure: &F) -> Vec2 { + fn field_vector Vec2>(&self, xidx: u32, yidx: u32, size: u32, measure: &F) -> Vec2 { let mut field = Vec2::default(); let w = self.im.width(); let h = self.im.height(); diff --git a/src/sim.rs b/src/sim.rs index db897ba..670cb8b 100644 --- a/src/sim.rs +++ b/src/sim.rs @@ -196,7 +196,7 @@ impl<'a> From> for StepParameters<'a> { } pub trait GenericSim: Send + Sync + DynClone { - fn sample(&self, pos: Meters) -> Cell; + fn sample(&self, pos: Meters) -> Sample; fn impulse_e_meters(&mut self, pos: Meters, amount: Vec3); fn impulse_h_meters(&mut self, pos: Meters, amount: Vec3); fn impulse_b_meters(&mut self, pos: Meters, amount: Vec3); @@ -240,7 +240,10 @@ pub trait GenericSim: Send + Sync + DynClone { let cell = self.sample(idx.to_meters(self.feature_size())); *e = cell.e(); *h = cell.h(); - cell.mat + mat::Static { + conductivity: cell.conductivity(), + m: cell.m(), + } }); state } @@ -248,13 +251,13 @@ pub trait GenericSim: Send + Sync + DynClone { dyn_clone::clone_trait_object!(GenericSim); impl<'a> dyn GenericSim + 'a { - pub fn get(&self, at: C) -> Cell { + pub fn get(&self, at: C) -> Sample { self.sample(at.to_meters(self.feature_size())) } /// Apply `F` to each Cell, and sum the results. pub fn map_sum(&self, f: F) -> Ret where - F: Fn(&Cell) -> Ret + Sync, + F: Fn(&Sample) -> Ret + Sync, Ret: Sum + Send, { self.map_sum_enumerated(|_at: Index, cell| f(cell)) @@ -262,7 +265,7 @@ impl<'a> dyn GenericSim + 'a { pub fn map_sum_enumerated(&self, f: F) -> Ret where C: Coord, - F: Fn(C, &Cell) -> Ret + Sync, + F: Fn(C, &Sample) -> Ret + Sync, Ret: Sum + Send, { let (w, h, d) = (self.width(), self.height(), self.depth()); @@ -283,7 +286,7 @@ impl<'a> dyn GenericSim + 'a { /// Apply `F` to each Cell, and sum the results. pub fn map_sum_over(&self, region: &Reg, f: F) -> Ret where - F: Fn(&Cell) -> Ret + Sync, + F: Fn(&Sample) -> Ret + Sync, Ret: Sum + Default + Send, Reg: Region + ?Sized { @@ -292,7 +295,7 @@ impl<'a> dyn GenericSim + 'a { pub fn map_sum_over_enumerated(&self, region: &Reg, f: F) -> Ret where C: Coord, - F: Fn(C, &Cell) -> Ret + Sync, + F: Fn(C, &Sample) -> Ret + Sync, Ret: Sum + Default + Send, Reg: Region + ?Sized, { @@ -541,17 +544,18 @@ impl SimState { } impl GenericSim for SimState { - fn sample(&self, pos: Meters) -> Cell { + fn sample(&self, pos: Meters) -> Sample { // TODO: smarter sampling than nearest neighbor? let pos_sim = pos.to_index(self.feature_size()); let idx = [pos_sim.z() as usize, pos_sim.y() as _, pos_sim.x() as _]; match self.cells.get(idx) { - Some(mat) => Cell { + Some(mat) => Sample { state: CellState { e: self.e[idx], h: self.h[idx], }, - mat: mat::Static::from_material(mat), + m: mat.m(), + conductivity: mat.step_parameters().conductivity(), }, None => Default::default(), } @@ -697,9 +701,10 @@ impl SimState { /// +------------+------------+ /// #[derive(Clone, Default, Serialize, Deserialize)] -pub struct Cell { +pub struct Sample { state: CellState, - mat: M, + m: Vec3, + conductivity: Vec3, } struct Neighbors<'a> { @@ -726,7 +731,7 @@ impl<'a> Neighbors<'a> { } } -impl Cell { +impl Sample { pub fn e(&self) -> Vec3 { self.state.e() } @@ -752,9 +757,7 @@ impl Cell { pub fn hz(&self) -> Flt { Flt::from_primitive(self.h().z()) } -} -impl Cell { pub fn b(&self) -> Vec3 { (self.h() + self.m()) * consts::real::MU0() } @@ -769,10 +772,10 @@ impl Cell { } pub fn m(&self) -> Vec3 { - self.mat.m() + self.m } pub fn conductivity(&self) -> Vec3 { - self.mat.conductivity() + self.conductivity } pub fn current_density(&self) -> Vec3 {