Rename Cell -> Sample
This commit is contained in:
@@ -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<F: Fn(&Cell<mat::Static>) -> Vec2<f32>>(&mut self, color: Rgb<u8>, typical: f32, measure: F) {
|
||||
fn render_vector_field<F: Fn(&Sample) -> Vec2<f32>>(&mut self, color: Rgb<u8>, 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<F: Fn(&Cell<mat::Static>) -> f32 + Sync>(&mut self, typical: f32, signed: bool, slot: u32, measure: F) {
|
||||
fn render_scalar_field<F: Fn(&Sample) -> 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<F: Fn(&Cell<mat::Static>) -> Vec2<f32>>(&self, xidx: u32, yidx: u32, size: u32, measure: &F) -> Vec2<f32> {
|
||||
fn field_vector<F: Fn(&Sample) -> Vec2<f32>>(&self, xidx: u32, yidx: u32, size: u32, measure: &F) -> Vec2<f32> {
|
||||
let mut field = Vec2::default();
|
||||
let w = self.im.width();
|
||||
let h = self.im.height();
|
||||
|
37
src/sim.rs
37
src/sim.rs
@@ -196,7 +196,7 @@ impl<'a> From<StepParametersMut<'a>> for StepParameters<'a> {
|
||||
}
|
||||
|
||||
pub trait GenericSim: Send + Sync + DynClone {
|
||||
fn sample(&self, pos: Meters) -> Cell<mat::Static>;
|
||||
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<C: Coord>(&self, at: C) -> Cell<mat::Static> {
|
||||
pub fn get<C: Coord>(&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<F, Ret>(&self, f: F) -> Ret
|
||||
where
|
||||
F: Fn(&Cell<mat::Static>) -> Ret + Sync,
|
||||
F: Fn(&Sample) -> Ret + Sync,
|
||||
Ret: Sum<Ret> + Send,
|
||||
{
|
||||
self.map_sum_enumerated(|_at: Index, cell| f(cell))
|
||||
@@ -262,7 +265,7 @@ impl<'a> dyn GenericSim + 'a {
|
||||
|
||||
pub fn map_sum_enumerated<C, F, Ret>(&self, f: F) -> Ret
|
||||
where C: Coord,
|
||||
F: Fn(C, &Cell<mat::Static>) -> Ret + Sync,
|
||||
F: Fn(C, &Sample) -> Ret + Sync,
|
||||
Ret: Sum<Ret> + 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<F, Ret, Reg>(&self, region: &Reg, f: F) -> Ret
|
||||
where
|
||||
F: Fn(&Cell<mat::Static>) -> Ret + Sync,
|
||||
F: Fn(&Sample) -> Ret + Sync,
|
||||
Ret: Sum<Ret> + Default + Send,
|
||||
Reg: Region + ?Sized
|
||||
{
|
||||
@@ -292,7 +295,7 @@ impl<'a> dyn GenericSim + 'a {
|
||||
|
||||
pub fn map_sum_over_enumerated<C, F, Ret, Reg>(&self, region: &Reg, f: F) -> Ret
|
||||
where C: Coord,
|
||||
F: Fn(C, &Cell<mat::Static>) -> Ret + Sync,
|
||||
F: Fn(C, &Sample) -> Ret + Sync,
|
||||
Ret: Sum<Ret> + Default + Send,
|
||||
Reg: Region + ?Sized,
|
||||
{
|
||||
@@ -541,17 +544,18 @@ impl<M: Material> SimState<M> {
|
||||
}
|
||||
|
||||
impl<M: Material + Clone + Send + Sync + 'static> GenericSim for SimState<M> {
|
||||
fn sample(&self, pos: Meters) -> Cell<mat::Static> {
|
||||
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<M> SimState<M> {
|
||||
/// +------------+------------+
|
||||
///
|
||||
#[derive(Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Cell<M = mat::Static> {
|
||||
pub struct Sample {
|
||||
state: CellState,
|
||||
mat: M,
|
||||
m: Vec3,
|
||||
conductivity: Vec3,
|
||||
}
|
||||
|
||||
struct Neighbors<'a> {
|
||||
@@ -726,7 +731,7 @@ impl<'a> Neighbors<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<M> Cell<M> {
|
||||
impl Sample {
|
||||
pub fn e(&self) -> Vec3 {
|
||||
self.state.e()
|
||||
}
|
||||
@@ -752,9 +757,7 @@ impl<M> Cell<M> {
|
||||
pub fn hz(&self) -> Flt {
|
||||
Flt::from_primitive(self.h().z())
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Material> Cell<M> {
|
||||
pub fn b(&self) -> Vec3 {
|
||||
(self.h() + self.m()) * consts::real::MU0()
|
||||
}
|
||||
@@ -769,10 +772,10 @@ impl<M: Material> Cell<M> {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user