Remove some unused imports; cleanup
The `Cell` type in sim.rs could be further improved: it doesn't need to be parameterized over Material. It should actually be renamed to `Sample`, and directly encode the magnetization, etc.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::{flt, flt::Flt, mat};
|
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::mat::{GenericMaterial, Material, Pml};
|
||||||
use crate::meas::{self, AbstractMeasurement};
|
use crate::meas::{self, AbstractMeasurement};
|
||||||
use crate::real::Real as _;
|
use crate::real::Real as _;
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
use crate::flt::{self, Flt};
|
use crate::flt;
|
||||||
use crate::real::{Real, ToFloat};
|
use crate::real::{Real, ToFloat};
|
||||||
use super::Vec3u;
|
use super::Vec3u;
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
use crate::geom::Vec3;
|
use crate::geom::Vec3;
|
||||||
use crate::real::{Real as _, ToFloat as _};
|
use crate::real::ToFloat as _;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
|
@@ -5,7 +5,7 @@ use crate::real::Real as _;
|
|||||||
use crate::sim::{PmlParameters, PmlState, StepParameters, StepParametersMut};
|
use crate::sim::{PmlParameters, PmlState, StepParameters, StepParametersMut};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::{debug, trace};
|
use log::trace;
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
11
src/meas.rs
11
src/meas.rs
@@ -1,6 +1,5 @@
|
|||||||
use crate::flt::{Flt, Real};
|
use crate::flt::{Flt, Real};
|
||||||
use crate::geom::{Meters, Region, Torus, Vec3, WorldRegion};
|
use crate::geom::{Meters, Region, Torus, Vec3, WorldRegion};
|
||||||
use crate::mat::Material as _;
|
|
||||||
use crate::real::Real as _;
|
use crate::real::Real as _;
|
||||||
use crate::sim::GenericSim;
|
use crate::sim::GenericSim;
|
||||||
use common_macros::b_tree_map;
|
use common_macros::b_tree_map;
|
||||||
@@ -65,7 +64,7 @@ impl AbstractMeasurement for Label {
|
|||||||
fn eval(&self, _state: &dyn GenericSim) -> String {
|
fn eval(&self, _state: &dyn GenericSim) -> String {
|
||||||
self.0.clone()
|
self.0.clone()
|
||||||
}
|
}
|
||||||
fn key_value(&self, state: &dyn GenericSim) -> BTreeMap<String, String> {
|
fn key_value(&self, _state: &dyn GenericSim) -> BTreeMap<String, String> {
|
||||||
b_tree_map! {
|
b_tree_map! {
|
||||||
self.0.clone() => self.0.clone(),
|
self.0.clone() => self.0.clone(),
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,7 @@ impl MagneticLoop {
|
|||||||
let to_coord = *coord - *self.region.center();
|
let to_coord = *coord - *self.region.center();
|
||||||
let tangent = normal.cross(to_coord).norm();
|
let tangent = normal.cross(to_coord).norm();
|
||||||
|
|
||||||
let m = cell.mat().m();
|
let m = cell.m();
|
||||||
let directed_m = m.dot(tangent);
|
let directed_m = m.dot(tangent);
|
||||||
let b = cell.b();
|
let b = cell.b();
|
||||||
let directed_b = b.dot(tangent);
|
let directed_b = b.dot(tangent);
|
||||||
@@ -334,7 +333,7 @@ impl Magnetization {
|
|||||||
}
|
}
|
||||||
fn data(&self, state: &dyn GenericSim) -> Vec3 {
|
fn data(&self, state: &dyn GenericSim) -> Vec3 {
|
||||||
let FieldSample(volume, _directed_mag, mag_vec) = state.map_sum_over(&*self.region, |cell| {
|
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();
|
let mag = m.mag();
|
||||||
FieldSample(1, mag, m)
|
FieldSample(1, mag, m)
|
||||||
});
|
});
|
||||||
@@ -368,11 +367,11 @@ pub struct MagnetizationAt(pub Meters);
|
|||||||
#[typetag::serde]
|
#[typetag::serde]
|
||||||
impl AbstractMeasurement for MagnetizationAt {
|
impl AbstractMeasurement for MagnetizationAt {
|
||||||
fn eval(&self, state: &dyn GenericSim) -> String {
|
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)
|
format!("M{}: {:.2e}", loc(self.0), m)
|
||||||
}
|
}
|
||||||
fn key_value(&self, state: &dyn GenericSim) -> BTreeMap<String, String> {
|
fn key_value(&self, state: &dyn GenericSim) -> BTreeMap<String, String> {
|
||||||
let m = state.sample(self.0).mat().m();
|
let m = state.sample(self.0).m();
|
||||||
b_tree_map! {
|
b_tree_map! {
|
||||||
format!("M{}", loc(self.0)) => m.to_string(),
|
format!("M{}", loc(self.0)) => m.to_string(),
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u};
|
use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u};
|
||||||
use crate::{Material as _, MaterialExt as _};
|
|
||||||
use crate::mat;
|
use crate::mat;
|
||||||
use crate::real::{Real as _, ToFloat as _};
|
use crate::real::ToFloat as _;
|
||||||
use crate::sim::{Cell, GenericSim, StaticSim};
|
use crate::sim::{Cell, GenericSim, StaticSim};
|
||||||
use crate::meas::AbstractMeasurement;
|
use crate::meas::AbstractMeasurement;
|
||||||
use crossterm::{cursor, QueueableCommand as _};
|
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);
|
trace!("rendering at {}x{} with z={}", width, height, z);
|
||||||
let mut me = Self::new(state, measurements, width, height, z);
|
let mut me = Self::new(state, measurements, width, height, z);
|
||||||
me.render_scalar_field(10.0, false, 2, |cell| {
|
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
|
0.0
|
||||||
} else {
|
} else {
|
||||||
5.0
|
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());
|
self.render_vector_field(Rgb([0xff, 0xff, 0xff]), 100.0 * scale, |cell| cell.e().xy().to_f32());
|
||||||
// current
|
// current
|
||||||
self.render_vector_field(Rgb([0x00, 0xa0, 0x30]), 1.0e-12 * scale, |cell| {
|
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 /////////////
|
////////////// Magnitude configuration /////////////
|
||||||
@@ -214,7 +214,7 @@ impl<'a, S: GenericSim> RenderSteps<'a, S> {
|
|||||||
}
|
}
|
||||||
fn render_current(&mut self, scale: f32) {
|
fn render_current(&mut self, scale: f32) {
|
||||||
self.render_scalar_field(1.0e1 * scale, false, 0, |cell| {
|
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) {
|
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_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.mat().m().xy().to_f32());
|
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(&Cell<mat::Static>) -> Vec2<f32>>(&mut self, color: Rgb<u8>, typical: f32, measure: F) {
|
||||||
@@ -559,15 +559,16 @@ impl<S: GenericSim> Renderer<S> for PlotlyRenderer {
|
|||||||
yv.push(y);
|
yv.push(y);
|
||||||
zv.push(z);
|
zv.push(z);
|
||||||
// opacities.push((cell.e().mag() * 0.1).min(1.0) as f64)
|
// 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
|
0.0
|
||||||
} else {
|
} else {
|
||||||
5.0
|
5.0
|
||||||
};
|
};
|
||||||
//let g = scale_unsigned_to_u8(mat, 10.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 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 g = scale_unsigned_to_u8(cell.e().mag().to_f32(), 1e2);
|
||||||
let b = scale_unsigned_to_u8(mat, 10.0);
|
let b = scale_unsigned_to_u8(mat, 10.0);
|
||||||
let alpha = 1.0;
|
let alpha = 1.0;
|
||||||
|
40
src/sim.rs
40
src/sim.rs
@@ -429,7 +429,7 @@ impl<M: Material + Clone + Send + Sync + 'static> SimState<M> {
|
|||||||
let e_field = &self.e;
|
let e_field = &self.e;
|
||||||
Zip::from(ndarray::indices_of(&self.cells)).and(&mut self.cells).and(&mut self.h).par_apply(
|
Zip::from(ndarray::indices_of(&self.cells)).and(&mut self.cells).and(&mut self.h).par_apply(
|
||||||
|(z, y, x), mat, h| {
|
|(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]];
|
let e = &e_field[[z, y, x]];
|
||||||
HCell { mat, h, e }.step(neighbors, half_time_step, inv_feature_size);
|
HCell { mat, h, e }.step(neighbors, half_time_step, inv_feature_size);
|
||||||
});
|
});
|
||||||
@@ -440,7 +440,7 @@ impl<M: Material + Clone + Send + Sync + 'static> SimState<M> {
|
|||||||
let h_field = &self.h;
|
let h_field = &self.h;
|
||||||
Zip::from(ndarray::indices_of(&self.cells)).and(&mut self.cells).and(&mut self.e).par_apply(
|
Zip::from(ndarray::indices_of(&self.cells)).and(&mut self.cells).and(&mut self.e).par_apply(
|
||||||
|(z, y, x), mat, e| {
|
|(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]];
|
let h = &h_field[[z, y, x]];
|
||||||
ECell { mat, e, h }.step(neighbors, half_time_step, inv_feature_size);
|
ECell { mat, e, h }.step(neighbors, half_time_step, inv_feature_size);
|
||||||
});
|
});
|
||||||
@@ -594,6 +594,7 @@ impl<M: Material + Clone + Send + Sync + 'static> GenericSim for SimState<M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
impl<M> SimState<M> {
|
impl<M> SimState<M> {
|
||||||
fn get_mat<C: Coord>(&self, c: C) -> &M {
|
fn get_mat<C: Coord>(&self, c: C) -> &M {
|
||||||
let at = c.to_index(self.feature_size.into());
|
let at = c.to_index(self.feature_size.into());
|
||||||
@@ -711,28 +712,7 @@ struct Neighbors<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Neighbors<'a> {
|
impl<'a> Neighbors<'a> {
|
||||||
fn new<M: 'a, F: Fn(&'a Cell<M>) -> &'a Vec3>(array: &'a Array3<Cell<M>>, location: [usize; 3], m: F) -> Self {
|
fn new(array: &'a Array3<Vec3>, location: [usize; 3]) -> 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<M: 'a>(array: &'a Array3<Cell<M>>, location: [usize; 3]) -> Self {
|
|
||||||
Self::new(array, location, |c| &c.state.e)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_h<M: 'a>(array: &'a Array3<Cell<M>>, location: [usize; 3]) -> Self {
|
|
||||||
Self::new(array, location, |c| &c.state.h)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_field(array: &'a Array3<Vec3>, location: [usize; 3]) -> Self {
|
|
||||||
let [z, y, x] = location;
|
let [z, y, x] = location;
|
||||||
let left = array.get([z, y, x.wrapping_sub(1)]);
|
let left = array.get([z, y, x.wrapping_sub(1)]);
|
||||||
let right = array.get([z, y, x + 1]);
|
let right = array.get([z, y, x + 1]);
|
||||||
@@ -776,7 +756,7 @@ impl<M> Cell<M> {
|
|||||||
|
|
||||||
impl<M: Material> Cell<M> {
|
impl<M: Material> Cell<M> {
|
||||||
pub fn b(&self) -> Vec3 {
|
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 {
|
pub fn bx(&self) -> Flt {
|
||||||
Flt::from_primitive(self.b().x())
|
Flt::from_primitive(self.b().x())
|
||||||
@@ -788,16 +768,16 @@ impl<M: Material> Cell<M> {
|
|||||||
Flt::from_primitive(self.b().z())
|
Flt::from_primitive(self.b().z())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mat(&self) -> &M {
|
pub fn m(&self) -> Vec3 {
|
||||||
&self.mat
|
self.mat.m()
|
||||||
}
|
}
|
||||||
pub fn mat_mut(&mut self) -> &mut M {
|
pub fn conductivity(&self) -> Vec3 {
|
||||||
&mut self.mat
|
self.mat.conductivity()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_density(&self) -> Vec3 {
|
pub fn current_density(&self) -> Vec3 {
|
||||||
// TODO: does this make sense for Pml?
|
// TODO: does this make sense for Pml?
|
||||||
let conductivity = self.mat.conductivity();
|
let conductivity = self.conductivity();
|
||||||
self.e().elem_mul(conductivity)
|
self.e().elem_mul(conductivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user