Region: remove Clone from the trait, and also parameterize everything

i didn't necessarily *want* to parameterize it all,
but it turned out to be easier to do that than to force all users to
workaround the lack of Clone.
This commit is contained in:
2022-08-12 01:42:19 -07:00
parent d5fbb4e9b2
commit 084c5bc342
7 changed files with 133 additions and 145 deletions

View File

@@ -3,7 +3,20 @@
//! search for the conditions which maximize energy transfer from the one core to the other.
use coremem::{Driver, mat, meas};
use coremem::geom::{region, Cube, Dilate, Memoize, Meters, Spiral, SwapYZ, Torus, Translate, Wrap};
use coremem::geom::Meters;
use coremem::geom::region::{
self,
Cube,
Dilate,
Intersection,
InvertedRegion,
Memoize,
Spiral,
SwapYZ,
Torus,
Translate,
Wrap
};
use coremem::mat::{Ferroxcube3R1MH, IsoConductorOr};
use coremem::real::{R32, Real as _};
use coremem::render::CsvRenderer;
@@ -13,9 +26,8 @@ use coremem::stim::{CurlStimulus, Exp1, Gated, Sinusoid1, TimeVarying as _};
use log::{error, info, warn};
use serde::{Deserialize, Serialize};
// XXX: cache was disabled during Region rework.
// mod cache;
// use cache::DiskCache;
mod cache;
use cache::DiskCache;
type Mat = IsoConductorOr<f32, Ferroxcube3R1MH>;
@@ -142,14 +154,18 @@ struct Params {
dump_frames: (u64, Option<u64>),
}
#[derive(Clone, Default)]
#[derive(Clone, Default, Serialize, Deserialize)]
struct Geometries {
dim: Meters,
ferro1_region: Torus,
ferro2_region: Torus,
set1_region: Torus,
set2_region: Torus,
coupling_region: region::Union,
coupling_region: region::Union3<
Memoize<Dilate<Wrap<Translate<SwapYZ<Intersection<Spiral, Cube>>>>>>,
Memoize<Dilate<Wrap<Translate<SwapYZ<Intersection<Spiral, InvertedRegion<Cube>>>>>>>,
region::Union3<Cube, Cube, region::Union4<Cube, Cube, Cube, Cube>>
>,
coupling_wire_top: Cube,
coupling_wire_bot: Cube,
wrap1_len: f32,
@@ -285,29 +301,29 @@ fn derive_geometries(p: GeomParams) -> Option<Geometries> {
wrap2_bot - feat_sizes*2.0,
wrap2_bot.with_y(coupling_wire_bot.top()) + feat_sizes*2.0,
);
let coupling_stubs = region::Union::new()
.with(coupling_stub_top_left.clone())
.with(coupling_stub_top_right.clone())
.with(coupling_stub_bot_left.clone())
.with(coupling_stub_bot_right.clone())
;
let coupling_stubs = region::Union::new4(
coupling_stub_top_left.clone(),
coupling_stub_top_right.clone(),
coupling_stub_bot_left.clone(),
coupling_stub_bot_right.clone(),
);
let coupling_wires = region::Union::new()
.with(coupling_wire_top.clone())
.with(coupling_wire_bot.clone())
.with(coupling_stubs.clone())
;
let coupling_wires = region::Union::new3(
coupling_wire_top.clone(),
coupling_wire_bot.clone(),
coupling_stubs.clone(),
);
let coupling_region = region::Union::new()
.with(coupling_region1.clone())
.with(coupling_region2.clone())
.with(coupling_wires.clone())
;
let coupling_region = region::Union::new3(
coupling_region1.clone(),
coupling_region2.clone(),
coupling_wires.clone(),
);
let wrap1_with_coupling = region::union(
let wrap1_with_coupling = region::Union::new2(
coupling_region1.clone(), coupling_wires.clone()
);
let wrap2_with_coupling = region::union(
let wrap2_with_coupling = region::Union::new2(
coupling_region2.clone(), coupling_wires.clone()
);
@@ -657,14 +673,10 @@ fn main() {
variants.len() / post_times.len(),
);
// let mut geom_cache = DiskCache::new_with_supplier(
// &format!("{}/.geom_cache", ensure_out_dir(i)),
// |geom: &GeomParams| derive_geometries(geom.clone())
// );
// TODO: re-enable geometry cache. had to disable during Region serialization rework
fn geom_cache_get_or_insert_from_supplier(geom: GeomParams) -> Option<Geometries> {
derive_geometries(geom)
}
let mut geom_cache = DiskCache::new_with_supplier(
&format!("{}/.geom_cache", ensure_out_dir(i)),
|geom: &GeomParams| derive_geometries(geom.clone())
);
for (peak_clock_current, clock_duration, post_time, clock_type, ferro_major, wrap1_coverage, wrap2_coverage, wrap1_density, wrap2_density) in variants {
info!("{}A/{}s {}s {}m {}:{}cov {}:{}density", peak_clock_current, clock_duration, post_time, ferro_major, wrap1_coverage, wrap2_coverage, wrap1_density, wrap2_density);
@@ -713,7 +725,7 @@ fn main() {
wraps1: (wraps1 * 4) as f32,
..base_params.geom
};
let geoms = geom_cache_get_or_insert_from_supplier(params.clone())?;
let geoms = geom_cache.get_or_insert_from_supplier(params.clone())?;
Some((params, geoms))
})
.collect();
@@ -738,7 +750,7 @@ fn main() {
wraps2: (wraps2 * 4) as f32,
..base_params.geom
};
let geoms = geom_cache_get_or_insert_from_supplier(params.clone())?;
let geoms = geom_cache.get_or_insert_from_supplier(params.clone())?;
Some((params, geoms))
})
.collect();
@@ -759,7 +771,7 @@ fn main() {
let mut params = base_params;
params.geom.wraps1 = wraps1;
params.geom.wraps2 = wraps2;
match geom_cache_get_or_insert_from_supplier(params.geom.clone()) {
match geom_cache.get_or_insert_from_supplier(params.geom.clone()) {
Some(geoms) => {
run_sim(i, params, geoms);
},