use coremem::{consts, Driver, Flt, mat, meas}; use coremem::geom::{Coord, CylinderZ, Vec2, Vec3}; use coremem::stim::{Stimulus, Sinusoid}; fn main() { coremem::init_logging(); let feat_size = 5e-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 = 2000e-6; let depth = 500e-6; let conductor_inner_rad = 0e-6; let conductor_outer_rad = 200e-6; let ferro_inner_rad = 220e-6; let ferro_outer_rad = 300e-6; let buffer = 100e-6; let peak_current = 100.0; 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 = (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-{}A--radii{}um-{}um-{}um.y4m", std::mem::size_of::() * 8, size_px, m_to_um(feat_size), peak_current as u32, 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( (half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into() )); driver.add_measurement(meas::MagneticFlux( (half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into() )); driver.add_measurement(meas::MagneticStrength( (half_width + ferro_inner_rad + 2.0*feat_size, half_width, half_depth).into() )); driver.add_measurement(meas::Magnetization( (half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into() )); driver.add_measurement(meas::MagneticFlux( (half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into() )); driver.add_measurement(meas::MagneticStrength( (half_width + ferro_inner_rad + 1.0*feat_size, half_width, half_depth).into() )); driver.add_measurement(meas::Magnetization( (half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into() )); driver.add_measurement(meas::MagneticFlux( (half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into() )); driver.add_measurement(meas::MagneticStrength( (half_width + 0.5 * (ferro_inner_rad + ferro_outer_rad), half_width, half_depth).into() )); 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 = Coord::new(x_px, y_px, z_px); 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 boundary_xy = half_width - ferro_outer_rad - buffer; println!("boundary: {}um", m_to_um(boundary_xy)); let boundary = Coord::new(from_m(boundary_xy), from_m(boundary_xy), 20); driver.add_upml_boundary(boundary); driver.add_stimulus(Stimulus::new( conductor_region.clone(), Sinusoid::new(Vec3::new(0.0, 0.0, peak_current * 1e-18), 1e9))); loop { driver.step(); } }