diff --git a/crates/applications/buffer_proto5/src/main.rs b/crates/applications/buffer_proto5/src/main.rs index 33a1e7a..bc3e378 100644 --- a/crates/applications/buffer_proto5/src/main.rs +++ b/crates/applications/buffer_proto5/src/main.rs @@ -2,13 +2,14 @@ //! to couple them. i parameterize the entire setup over a bunch of different factors in order to //! search for the conditions which maximize energy transfer from the one core to the other. -use coremem::{Driver, mat, meas, SpirvDriver}; +use coremem::{Driver, mat, meas}; use coremem::geom::{region, Cube, Dilate, Memoize, Meters, Spiral, SwapYZ, Torus, Translate, Wrap}; use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr}; use coremem::real::{R32, Real as _}; use coremem::render::CsvRenderer; -use coremem::stim::{CurlStimulus, Exp1, Gated, Sinusoid1, TimeVarying as _}; +use coremem::sim::spirv::{SpirvSim, WgpuBackend}; use coremem::sim::units::{Seconds, Time as _}; +use coremem::stim::{CurlStimulus, Exp1, Gated, Sinusoid1, TimeVarying as _}; use coremem::util::cache::DiskCache; use log::{error, info, warn}; use serde::{Deserialize, Serialize}; @@ -389,7 +390,9 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results { p.clock_type, ); - let mut driver: SpirvDriver = Driver::new_spirv(g.dim, p.geom.feat_size); + let mut driver = Driver::new_with_state(SpirvSim::::new( + g.dim.to_index(p.geom.feat_size), p.geom.feat_size + )); driver.set_steps_per_stim(1000); if !driver.add_state_file(&*format!("{}/state.bc", prefix), 16000) { // mu_r=881.33, starting at H=25 to H=75. @@ -414,7 +417,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results { info!("loaded state file: skipping geometry calculations"); } - let add_drive_sine_pulse = |driver: &mut SpirvDriver, region: &Torus, start: f32, duration: f32, amp: f32| { + let add_drive_sine_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| { let wave = Sinusoid1::from_wavelength(amp, duration * 2.0) .half_cycle() .shifted(start); @@ -426,7 +429,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results { )); }; - let add_drive_square_pulse = |driver: &mut SpirvDriver, region: &Torus, start: f32, duration: f32, amp: f32| { + let add_drive_square_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| { let wave = Gated::new(amp, start, start+duration); driver.add_stimulus(CurlStimulus::new( region.clone(), @@ -436,7 +439,7 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results { )); }; - let add_drive_exp_pulse = |driver: &mut SpirvDriver, region: &Torus, start: f32, duration: f32, amp: f32| { + let add_drive_exp_pulse = |driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| { let wave = Exp1::new_at(amp, start, 0.5*duration); driver.add_stimulus(CurlStimulus::new( region.clone(), @@ -447,11 +450,11 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results { }; // step function: "permanently" increase the current by `amp`. - let _add_drive_step = |driver: &mut SpirvDriver, region: &Torus, start: f32, amp: f32| { + let _add_drive_step = |driver: &mut Driver<_>, region: &Torus, start: f32, amp: f32| { add_drive_square_pulse(driver, region, start, 1.0 /* effectively infinite duration */, amp); }; - let add_drive_pulse = |ty: PulseType, driver: &mut SpirvDriver, region: &Torus, start: f32, duration: f32, amp: f32| { + let add_drive_pulse = |ty: PulseType, driver: &mut Driver<_>, region: &Torus, start: f32, duration: f32, amp: f32| { match ty { PulseType::Square => add_drive_square_pulse(driver, region, start, duration, amp), PulseType::Sine => add_drive_sine_pulse(driver, region, start, duration, amp), diff --git a/crates/applications/multi_core_inverter/src/main.rs b/crates/applications/multi_core_inverter/src/main.rs index 838b587..50d2cf4 100644 --- a/crates/applications/multi_core_inverter/src/main.rs +++ b/crates/applications/multi_core_inverter/src/main.rs @@ -36,10 +36,11 @@ //! $ pushd crates/coremem; cargo run --release --bin viewer ../../out/applications/multi_core_inverter/0/ ; popd //! ``` -use coremem::geom::{Meters, Torus}; +use coremem::geom::{Coord as _, Meters, Torus}; +use coremem::sim::spirv::{SpirvSim, WgpuBackend}; use coremem::sim::units::Seconds; use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr, IsomorphicConductor}; -use coremem::{Driver, SpirvDriver}; +use coremem::Driver; type Mat = IsoConductorOr; @@ -76,7 +77,9 @@ fn main() { let ferro_mat = wire_mat; // let ferro_mat = Ferroxcube3R1MH::new(); // uncomment when ready to simulate for real - let mut driver: SpirvDriver = Driver::new_spirv(sim_bounds, feat_size); + let mut driver = Driver::new_with_state(SpirvSim::::new( + sim_bounds.to_index(feat_size), feat_size, + )); driver.add_classical_boundary(sim_padding); driver.fill_region(&drive0, wire_mat); driver.fill_region(&sense3, wire_mat); diff --git a/crates/applications/sr_latch/src/main.rs b/crates/applications/sr_latch/src/main.rs index c733fb3..5f44401 100644 --- a/crates/applications/sr_latch/src/main.rs +++ b/crates/applications/sr_latch/src/main.rs @@ -3,8 +3,9 @@ /// the SR latch in this example is wired to a downstream latch, mostly to show that it's /// possible to transfer the state (with some limitation) from one latch to another. -use coremem::{Driver, mat, meas, SpirvDriver}; -use coremem::geom::{Meters, Torus}; +use coremem::{Driver, mat, meas}; +use coremem::geom::{Coord as _, Meters, Torus}; +use coremem::sim::spirv::{SpirvSim, WgpuBackend}; use coremem::sim::units::Seconds; use coremem::stim::{CurlStimulus, Sinusoid1, TimeVarying as _}; @@ -58,7 +59,9 @@ fn main() { let coupling_region = Torus::new_xz(Meters::new(0.5*(ferro1_center + ferro2_center), ferro_center_y, half_depth), wire_coupling_major, wire_minor); let sense_region = Torus::new_xz(Meters::new(ferro2_center + ferro_major, ferro_center_y, half_depth), wire_major, wire_minor); - let mut driver: SpirvDriver> = Driver::new_spirv(Meters::new(width, height, depth), feat_size); + let mut driver = Driver::new_with_state(SpirvSim::, WgpuBackend>::new( + Meters::new(width, height, depth).to_index(feat_size), feat_size + )); // mu_r=881.33, starting at H=25 to H=75. driver.fill_region(&ferro1_region, mat::MHPgram::new(25.0, 881.33, 44000.0)); diff --git a/crates/applications/wavefront/src/main.rs b/crates/applications/wavefront/src/main.rs index a65a794..3baf112 100644 --- a/crates/applications/wavefront/src/main.rs +++ b/crates/applications/wavefront/src/main.rs @@ -7,12 +7,15 @@ //! with something that absorbs energy. since this example doesn't, it lets you see what //! happens when you just use the default boundary conditions. -use coremem::{mat, driver}; +use coremem::{mat, Driver}; use coremem::geom::{Coord as _, Cube, Index}; use coremem::units::Seconds; +use coremem::sim::spirv::{self, SpirvSim}; use coremem::stim::{Stimulus, TimeVarying as _, UniformStimulus}; use coremem::types::vec::Vec3; +type Mat = mat::FullyGenericMaterial; + fn main() { coremem::init_logging(); // create a 2d simulation with so many grid cells @@ -23,13 +26,12 @@ fn main() { let feature_size = 1e-6; // create the simulation "driver". - // by default all the computations are done with R32: a f32 which panics on NaN/Inf. - // you can parameterize it to use R64, or unchecked f32 -- see src/driver.rs for definition. - let mut driver: driver::SpirvDriver = driver::Driver::new_spirv(size, feature_size); - - // uncomment to use the Spirv/GPU driver. this one is restricted to unchecked f32. - // note: this won't have better perf unless you reduce the y4m/term renderer framerate below. - // let mut driver: driver::SpirvDriver = driver::Driver::new_spirv(size, feature_size); + // the first parameter is the float type to use: f32 for unchecked math, coremem::real::R32 + // to guard against NaN/Inf (useful for debugging). + // to run this on the gpu instead of the gpu, replace `CpuBackend` with `WgpuBackend`. + let mut driver = Driver::new_with_state(SpirvSim::::new( + size, feature_size + )); // create a conductor on the left side. let conductor = Cube::new( diff --git a/crates/coremem/src/driver.rs b/crates/coremem/src/driver.rs index 82d41be..7f367ee 100644 --- a/crates/coremem/src/driver.rs +++ b/crates/coremem/src/driver.rs @@ -38,16 +38,6 @@ pub struct Driver { sim_end_time: Option, } -impl SpirvDriver -{ - pub fn new_spirv(size: C, feature_size: f32) -> Self { - Self::new_with_state(SpirvSim::new( - size.to_index(feature_size), - feature_size, - )) - } -} - impl Driver { pub fn new_with_state(state: S) -> Self { Self {