use coremem::{Driver, MaterialSim as _, SimState}; use coremem::geom::{Cube, Index, Meters, Vec3}; use coremem::mat::Static; use coremem::real::R64; use coremem::stim::{Stimulus, Sinusoid3}; use coremem::units::Seconds; fn main() { coremem::init_logging(); let feat_size = 1e-3; let s = 200; let steps_per_frame = 10; let size = Index::new(s, s, 1); let duration = 10e-8; let current_duration = 1e-10; let peak_stim = 1.0e18; let mut driver: Driver>> = Driver::new(size, feat_size); let timestep = driver.state.timestep(); driver.state.fill_boundary_using(size/4, |boundary_ness| { let b = boundary_ness.elem_pow(3.0); let coord_stretch = b * (0.5 / timestep); Static { conductivity: coord_stretch.cast(), ..Default::default() // TODO PML coord_stretch } }); // for y in 0..size.y() { // for x in 0..size.x() { // // if y >= x { // let mut m = driver.state.mat_mut(Index::new(x, y, 0)); // // Force the stretch to be only along one axis // m.conductivity = match m.conductivity.to_tuple() { // TODO PML coord_stretch // (cs_x, cs_y, cs_z) if x < s/2 || y < s/2 => (cs_x, cs_y, cs_z), // // (x, y, _) if x == y => (0.0, 0.0, 0.0), // // (cs_x, cs_y, cs_z) if cs_x >= cs_y && cs_x >= cs_z && (y > 5 || x > 5) => (cs_x, 0.0, 0.0), // // (cs_x, cs_y, cs_z) if cs_y >= cs_x && cs_y >= cs_z && (y > 5 || x > 5) => (0.0, cs_y, 0.0), // // (cs_x, cs_y, cs_z) if cs_z >= cs_x && cs_z >= cs_y => (0.0, 0.0, 0.0), // // (cs_x, cs_y, cs_z) if cs_y >= cs_x && cs_y >= cs_z && y > size.y()/2 => (0.0, cs_y - cs_x, 0.0), // // (cs_x, cs_y, cs_z) if (x == 0 && y == 0) => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if (x == 200 && y == 0) => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if (x == 200 && y == 200) => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if (x == 0 && y == 200) => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if x == y && y >= 100 => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if x == 200 - y && y <= 100 => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if x == y && (x <= 19 || x >= 181) => (cs_x, cs_y, cs_z), // // (cs_x, cs_y, cs_z) if x == 200 - y && (x <= 19 || x >= 181) => (cs_x, cs_y, cs_z), // (_) => (0.0, 0.0, 0.0), // // _ => unreachable!(), // }.into(); // // if x <= 7 || x >= 193 || y <= 7 || y >= 193 { // // m.coord_stretch = (0.0, 0.0, 0.0).into(); // // //m.conductivity = (1e3, 1e3, 1e3).into(); // // } // // } // } // } let drive_region = Cube::new( Meters(Vec3::new((size.x() - 1) as f32 * 0.5 * feat_size, (size.y() - 1) as f32 * 0.5 * feat_size, 0.0)), Meters(Vec3::new((size.x() + 1) as f32 * 0.5 * feat_size, (size.y() + 1) as f32 * 0.5 * feat_size, 1.0 * feat_size)), ); let pos_wave = Sinusoid3::from_wavelength(Vec3::new(0.0, 0.0, peak_stim), current_duration * 2.0) .half_cycle(); driver.add_stimulus(Stimulus::new(drive_region, pos_wave)); let prefix = "out/pml-mono-200-200-border-25-only-lower-right".to_string(); let _ = std::fs::create_dir_all(&prefix); driver.add_serializer_renderer(&*format!("{}/frame-", prefix), steps_per_frame, None); driver.step_until(Seconds(duration)); }