Troubleshoot toroid2.5d
This commit is contained in:
@@ -1,106 +1,119 @@
|
||||
use coremem::{Driver, Flt, mat, meas};
|
||||
use coremem::geom::{Coord, CylinderZ, Index, Meters, Vec2, Vec3};
|
||||
use coremem::stim::{Stimulus, Sinusoid};
|
||||
use log::trace;
|
||||
|
||||
fn main() {
|
||||
coremem::init_logging();
|
||||
let feat_size = 10e-6; // feature size
|
||||
let from_m = |m| (m/feat_size) as u32;
|
||||
let m_to_um = |px| (px * 1e6) as u32;
|
||||
let to_m = |px| px as Flt * feat_size;
|
||||
let width = 1000e-6;
|
||||
let depth = 600e-6;
|
||||
let conductor_inner_rad = 0e-6;
|
||||
let conductor_outer_rad = 19e-6;
|
||||
let ferro_inner_rad = 100e-6;
|
||||
let ferro_outer_rad = 200e-6;
|
||||
let buffer = 50e-6;
|
||||
let peak_current = 2e3;
|
||||
let current_duration = 1e-9; // half-wavelength of the sine wave
|
||||
let conductivity = 1.0e5;
|
||||
let half_width = width * 0.5;
|
||||
let half_depth = depth * 0.5;
|
||||
for p in 0..20 {
|
||||
let ferro_depth = 10e-6 * (20-p) as Flt;
|
||||
let feat_size = 10e-6; // feature size
|
||||
let from_m = |m| (m/feat_size) as u32;
|
||||
let m_to_um = |px| (px * 1e6) as u32;
|
||||
let to_m = |px| px as Flt * feat_size;
|
||||
let width = 2500e-6;
|
||||
let depth = 200e-6;
|
||||
let conductor_inner_rad = 0e-6;
|
||||
let conductor_outer_rad = 19e-6;
|
||||
let ferro_inner_rad = 100e-6;
|
||||
let ferro_outer_rad = 200e-6;
|
||||
//let ferro_depth = 10e-6;
|
||||
let buffer = 250e-6;
|
||||
let peak_current = 2e3;
|
||||
let current_duration = 1e-9; // half-wavelength of the sine wave
|
||||
let conductivity = 1.0e5;
|
||||
let half_width = width * 0.5;
|
||||
let half_depth = depth * 0.5;
|
||||
|
||||
let width_px = from_m(width);
|
||||
let depth_px = from_m(depth);
|
||||
let size_px = Index((width_px, width_px, depth_px).into());
|
||||
let mut driver = Driver::new(size_px, feat_size);
|
||||
driver.set_steps_per_frame(8);
|
||||
//driver.set_steps_per_frame(40);
|
||||
//driver.set_steps_per_frame(200);
|
||||
driver.add_y4m_renderer(&*format!("toroid25d-flt{}-{}-feat{}um-{:.1e}A-{:.1e}s--radii{}um-{}um-{}um.y4m",
|
||||
std::mem::size_of::<Flt>() * 8,
|
||||
*size_px,
|
||||
m_to_um(feat_size),
|
||||
peak_current,
|
||||
current_duration,
|
||||
m_to_um(conductor_outer_rad),
|
||||
m_to_um(ferro_inner_rad),
|
||||
m_to_um(ferro_outer_rad),
|
||||
));
|
||||
let conductor_region = CylinderZ::new(
|
||||
Vec2::new(half_width, half_width),
|
||||
conductor_outer_rad);
|
||||
// driver.add_term_renderer();
|
||||
driver.add_measurement(meas::Label(format!("Conductivity: {}, Imax: {:.2e}", conductivity, peak_current)));
|
||||
driver.add_measurement(meas::Current(conductor_region.clone()));
|
||||
driver.add_measurement(meas::Magnetization(
|
||||
Meters((half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticFlux(
|
||||
Meters((half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticStrength(
|
||||
Meters((half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::Magnetization(
|
||||
Meters((half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticFlux(
|
||||
Meters((half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticStrength(
|
||||
Meters((half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::Magnetization(
|
||||
Meters((half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticFlux(
|
||||
Meters((half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticStrength(
|
||||
Meters((half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into())
|
||||
));
|
||||
let duration = 1e-9;
|
||||
|
||||
let center = Vec2::new(half_width as _, half_width as _);
|
||||
let width_px = from_m(width);
|
||||
let depth_px = from_m(depth);
|
||||
let size_px = Index((width_px, width_px, depth_px).into());
|
||||
let mut driver = Driver::new(size_px, feat_size);
|
||||
// driver.set_steps_per_frame(8);
|
||||
//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.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,
|
||||
*size_px,
|
||||
m_to_um(feat_size),
|
||||
peak_current,
|
||||
current_duration,
|
||||
m_to_um(conductor_outer_rad),
|
||||
m_to_um(ferro_inner_rad),
|
||||
m_to_um(ferro_outer_rad),
|
||||
m_to_um(ferro_depth),
|
||||
));
|
||||
let conductor_region = CylinderZ::new(
|
||||
Vec2::new(half_width, half_width),
|
||||
conductor_outer_rad);
|
||||
// driver.add_term_renderer();
|
||||
driver.add_measurement(meas::Label(format!("Conductivity: {}, Imax: {:.2e}", conductivity, peak_current)));
|
||||
driver.add_measurement(meas::Current(conductor_region.clone()));
|
||||
driver.add_measurement(meas::Magnetization(
|
||||
Meters((half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticFlux(
|
||||
Meters((half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticStrength(
|
||||
Meters((half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::Magnetization(
|
||||
Meters((half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticFlux(
|
||||
Meters((half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticStrength(
|
||||
Meters((half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::Magnetization(
|
||||
Meters((half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticFlux(
|
||||
Meters((half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into())
|
||||
));
|
||||
driver.add_measurement(meas::MagneticStrength(
|
||||
Meters((half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into())
|
||||
));
|
||||
|
||||
for z_px in 0..depth_px {
|
||||
for y_px in 0..width_px {
|
||||
for x_px in 0..width_px {
|
||||
let loc = Index((x_px, y_px, z_px).into());
|
||||
let d = Vec2::new(to_m(x_px), to_m(y_px)) - center;
|
||||
let r = d.mag();
|
||||
if (conductor_inner_rad as _..conductor_outer_rad as _).contains(&r) {
|
||||
*driver.state.get_mut(loc).mat_mut() = mat::Static::conductor(conductivity).into();
|
||||
} else if (ferro_inner_rad as _..ferro_outer_rad as _).contains(&r) {
|
||||
//if (half_depth_px-5..half_depth_px+5).contains(z_px) {
|
||||
*driver.state.get_mut(loc).mat_mut() = mat::db::ferroxcube_3r1();
|
||||
//}
|
||||
let center = Vec2::new(half_width as _, half_width as _);
|
||||
|
||||
for z_px in 0..depth_px {
|
||||
for y_px in 0..width_px {
|
||||
for x_px in 0..width_px {
|
||||
let loc = Index((x_px, y_px, z_px).into());
|
||||
let d = Vec2::new(to_m(x_px), to_m(y_px)) - center;
|
||||
let r = d.mag();
|
||||
if (conductor_inner_rad as _..conductor_outer_rad as _).contains(&r) {
|
||||
*driver.state.get_mut(loc).mat_mut() = mat::Static::conductor(conductivity).into();
|
||||
} else if (ferro_inner_rad as _..ferro_outer_rad as _).contains(&r) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let boundary_xy = half_width - ferro_outer_rad - buffer;
|
||||
println!("boundary: {}um", m_to_um(boundary_xy));
|
||||
let boundary = Index((from_m(boundary_xy), from_m(boundary_xy), 0).into());
|
||||
driver.add_upml_boundary(boundary);
|
||||
let boundary_xy = half_width - ferro_outer_rad - buffer;
|
||||
println!("boundary: {}um", m_to_um(boundary_xy));
|
||||
let boundary = Index((from_m(boundary_xy), from_m(boundary_xy), 0).into());
|
||||
driver.add_upml_boundary(boundary);
|
||||
|
||||
driver.add_stimulus(Stimulus::new(
|
||||
conductor_region.clone(),
|
||||
Sinusoid::from_wavelength(Vec3::new(0.0, 0.0, peak_current), current_duration * 2.0
|
||||
)));
|
||||
driver.add_stimulus(Stimulus::new(
|
||||
conductor_region.clone(),
|
||||
Sinusoid::from_wavelength(Vec3::new(0.0, 0.0, peak_current), current_duration * 2.0
|
||||
)));
|
||||
|
||||
loop {
|
||||
driver.step();
|
||||
while driver.dyn_state().time() < duration {
|
||||
driver.step();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user