Troubleshoot toroid2.5d

This commit is contained in:
2020-10-09 20:41:38 -07:00
parent b9a48641c1
commit f2ba6fdd1b
8 changed files with 123 additions and 98 deletions

View File

@@ -1,34 +1,42 @@
use coremem::{Driver, Flt, mat, meas}; use coremem::{Driver, Flt, mat, meas};
use coremem::geom::{Coord, CylinderZ, Index, Meters, Vec2, Vec3}; use coremem::geom::{Coord, CylinderZ, Index, Meters, Vec2, Vec3};
use coremem::stim::{Stimulus, Sinusoid}; use coremem::stim::{Stimulus, Sinusoid};
use log::trace;
fn main() { fn main() {
coremem::init_logging(); coremem::init_logging();
for p in 0..20 {
let ferro_depth = 10e-6 * (20-p) as Flt;
let feat_size = 10e-6; // feature size let feat_size = 10e-6; // feature size
let from_m = |m| (m/feat_size) as u32; let from_m = |m| (m/feat_size) as u32;
let m_to_um = |px| (px * 1e6) as u32; let m_to_um = |px| (px * 1e6) as u32;
let to_m = |px| px as Flt * feat_size; let to_m = |px| px as Flt * feat_size;
let width = 1000e-6; let width = 2500e-6;
let depth = 600e-6; let depth = 200e-6;
let conductor_inner_rad = 0e-6; let conductor_inner_rad = 0e-6;
let conductor_outer_rad = 19e-6; let conductor_outer_rad = 19e-6;
let ferro_inner_rad = 100e-6; let ferro_inner_rad = 100e-6;
let ferro_outer_rad = 200e-6; let ferro_outer_rad = 200e-6;
let buffer = 50e-6; //let ferro_depth = 10e-6;
let buffer = 250e-6;
let peak_current = 2e3; let peak_current = 2e3;
let current_duration = 1e-9; // half-wavelength of the sine wave let current_duration = 1e-9; // half-wavelength of the sine wave
let conductivity = 1.0e5; let conductivity = 1.0e5;
let half_width = width * 0.5; let half_width = width * 0.5;
let half_depth = depth * 0.5; let half_depth = depth * 0.5;
let duration = 1e-9;
let width_px = from_m(width); let width_px = from_m(width);
let depth_px = from_m(depth); let depth_px = from_m(depth);
let size_px = Index((width_px, width_px, depth_px).into()); let size_px = Index((width_px, width_px, depth_px).into());
let mut driver = Driver::new(size_px, feat_size); let mut driver = Driver::new(size_px, feat_size);
driver.set_steps_per_frame(8); // driver.set_steps_per_frame(8);
//driver.set_steps_per_frame(40); //driver.set_steps_per_frame(40);
//driver.set_steps_per_frame(80);
driver.set_steps_per_frame(120);
//driver.set_steps_per_frame(200); //driver.set_steps_per_frame(200);
driver.add_y4m_renderer(&*format!("toroid25d-flt{}-{}-feat{}um-{:.1e}A-{:.1e}s--radii{}um-{}um-{}um.y4m", driver.add_y4m_renderer(&*format!("toroid25d.5-flt{}-{}-feat{}um-{:.1e}A-{:.1e}s--radii{}um-{}um-{}um-{}um.y4m",
std::mem::size_of::<Flt>() * 8, std::mem::size_of::<Flt>() * 8,
*size_px, *size_px,
m_to_um(feat_size), m_to_um(feat_size),
@@ -37,6 +45,7 @@ fn main() {
m_to_um(conductor_outer_rad), m_to_um(conductor_outer_rad),
m_to_um(ferro_inner_rad), m_to_um(ferro_inner_rad),
m_to_um(ferro_outer_rad), m_to_um(ferro_outer_rad),
m_to_um(ferro_depth),
)); ));
let conductor_region = CylinderZ::new( let conductor_region = CylinderZ::new(
Vec2::new(half_width, half_width), Vec2::new(half_width, half_width),
@@ -83,9 +92,12 @@ fn main() {
if (conductor_inner_rad as _..conductor_outer_rad as _).contains(&r) { if (conductor_inner_rad as _..conductor_outer_rad as _).contains(&r) {
*driver.state.get_mut(loc).mat_mut() = mat::Static::conductor(conductivity).into(); *driver.state.get_mut(loc).mat_mut() = mat::Static::conductor(conductivity).into();
} else if (ferro_inner_rad as _..ferro_outer_rad as _).contains(&r) { } else if (ferro_inner_rad as _..ferro_outer_rad as _).contains(&r) {
//if (half_depth_px-5..half_depth_px+5).contains(z_px) { let half_depth_px = from_m(half_depth);
let ferro_depth_px = from_m(ferro_depth);
if (half_depth_px-ferro_depth_px/2 .. half_depth_px+(ferro_depth_px+1)/2).contains(&z_px) {
trace!("placing ferro at {:?}", loc);
*driver.state.get_mut(loc).mat_mut() = mat::db::ferroxcube_3r1(); *driver.state.get_mut(loc).mat_mut() = mat::db::ferroxcube_3r1();
//} }
} }
} }
} }
@@ -100,7 +112,8 @@ fn main() {
Sinusoid::from_wavelength(Vec3::new(0.0, 0.0, peak_current), current_duration * 2.0 Sinusoid::from_wavelength(Vec3::new(0.0, 0.0, peak_current), current_duration * 2.0
))); )));
loop { while driver.dyn_state().time() < duration {
driver.step(); driver.step();
} }
} }
}

View File

@@ -137,7 +137,7 @@ impl Driver {
0.0 0.0
}; };
let cond = Vec3::new(cond_x, cond_y, cond_z); let cond = Vec3::new(cond_x, cond_y, cond_z);
trace!("cond: {:?}", cond); // trace!("cond: {:?}", cond);
let conductor = mat::Static::anisotropic_conductor(cond); let conductor = mat::Static::anisotropic_conductor(cond);
*self.state.get_mut(Index(Vec3u::new(x, y, z))).mat_mut() = conductor.into(); *self.state.get_mut(Index(Vec3u::new(x, y, z))).mat_mut() = conductor.into();
} }

View File

@@ -9,7 +9,7 @@ pub trait Coord: Copy + Clone {
fn from_index(other: Index, feature_size: Flt) -> Self; fn from_index(other: Index, feature_size: Flt) -> Self;
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub struct Meters(pub Vec3); pub struct Meters(pub Vec3);
impl Coord for Meters { impl Coord for Meters {
@@ -34,7 +34,7 @@ impl Deref for Meters {
} }
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub struct Index(pub Vec3u); pub struct Index(pub Vec3u);
impl Coord for Index { impl Coord for Index {

View File

@@ -199,7 +199,7 @@ impl From<(Real, Real, Real)> for Vec3 {
impl From<Vec3u> for Vec3 { impl From<Vec3u> for Vec3 {
fn from(v: Vec3u) -> Self { fn from(v: Vec3u) -> Self {
Self::new(v.x().into(), v.y().into(), v.z().into()) Self::new(v.x() as _, v.y() as _, v.z() as _)
} }
} }

View File

@@ -1,7 +1,7 @@
use super::Vec3; use super::Vec3;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
#[derive(Copy, Clone, Default, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct Vec3u { pub struct Vec3u {
y: u32, y: u32,
x: u32, x: u32,

View File

@@ -8,6 +8,9 @@ use std::cmp::Ordering;
#[enum_dispatch] #[enum_dispatch]
pub trait Material { pub trait Material {
fn is_vacuum(&self) -> bool {
false
}
/// Return \sigma, the electrical conductivity. /// Return \sigma, the electrical conductivity.
/// For a vacuum, this is zero. For a perfect conductor, \inf. /// For a vacuum, this is zero. For a perfect conductor, \inf.
fn conductivity(&self) -> Vec3 { fn conductivity(&self) -> Vec3 {
@@ -43,6 +46,9 @@ impl Static {
} }
impl Material for Static { impl Material for Static {
fn is_vacuum(&self) -> bool {
self.conductivity == Default::default()
}
fn conductivity(&self) -> Vec3 { fn conductivity(&self) -> Vec3 {
self.conductivity self.conductivity
} }

View File

@@ -70,9 +70,15 @@ impl<'a> RenderSteps<'a> {
width = (width as f32 * stretch) as _; width = (width as f32 * stretch) as _;
height = max_height; height = max_height;
} }
trace!("rendering at {}x{}", width, height); 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| cell.mat().conductivity().mag()); me.render_scalar_field(10.0, false, 2, |cell| {
cell.mat().conductivity().mag() + if cell.mat().is_vacuum() {
0.0
} else {
5.0
}
});
me.render_scalar_field(100.0, true, 0, |cell| cell.mat().m().mag()); me.render_scalar_field(100.0, true, 0, |cell| cell.mat().m().mag());
if false { if false {
me.render_b_z_field(); me.render_b_z_field();