From b7716d2dea11fd8fe6f8ade0c11a81b20043dc21 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 6 Sep 2020 12:18:31 -0700 Subject: [PATCH] Repurpose mat::Conductor to mat::Static This will allow taking a material-independent snapshot of the SimState. --- examples/em_reflection.rs | 8 ++++---- examples/ferromagnet.rs | 7 ++++--- src/mat.rs | 21 +++++++++++++++++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/examples/em_reflection.rs b/examples/em_reflection.rs index 20c4984..fe2e896 100644 --- a/examples/em_reflection.rs +++ b/examples/em_reflection.rs @@ -8,11 +8,11 @@ fn main() { for inset in 0..20 { for x in 0..width { - *driver.state.get_mut(x, inset).mat_mut() = mat::Conductor { conductivity: 0.1*(20.0 - inset as f64) }.into(); + *driver.state.get_mut(x, inset).mat_mut() = mat::Static::conductor(0.1*(20.0 - inset as f64)).into(); } for y in 0..100 { - *driver.state.get_mut(inset, y).mat_mut() = mat::Conductor { conductivity: 0.1*(20.0 - inset as f64) }.into(); - *driver.state.get_mut(width-1 - inset, y).mat_mut() = mat::Conductor { conductivity: 0.1*(20.0 - inset as f64) }.into(); + *driver.state.get_mut(inset, y).mat_mut() = mat::Static::conductor(0.1*(20.0 - inset as f64)).into(); + *driver.state.get_mut(width-1 - inset, y).mat_mut() = mat::Static::conductor(0.1*(20.0 - inset as f64)).into(); } } for y in 75..100 { @@ -21,7 +21,7 @@ fn main() { // NB: different sources give pretty different values for this // NB: Simulation misbehaves for values > 10... Proably this model isn't so great. // Maybe use \eps or \xi instead of conductivity. - *driver.state.get_mut(x, y).mat_mut() = mat::Conductor { conductivity: 2.17 }.into(); + *driver.state.get_mut(x, y).mat_mut() = mat::Static::conductor(2.17).into(); } } diff --git a/examples/ferromagnet.rs b/examples/ferromagnet.rs index 6f7dd5b..a6c2ec7 100644 --- a/examples/ferromagnet.rs +++ b/examples/ferromagnet.rs @@ -4,11 +4,12 @@ fn main() { let width = 201; let height = 101; let mut driver = Driver::new(width, height, 1e-3 /* feature size */) - .with_y4m_renderer("ferromagnet.y4m"); + .with_y4m_renderer("ferromagnet.y4m") + ; for y in 0..height { for x in 50..60 { - *driver.state.get_mut(x, y).mat_mut() = mat::Conductor { conductivity: 1.0e1 }.into(); + *driver.state.get_mut(x, y).mat_mut() = mat::Static::conductor(1.0e1).into(); } // for x in 30..40 { // *state.get_mut(x, y).mat_mut() = mat::Conductor { conductivity: 1.0e8 }.into(); @@ -19,7 +20,7 @@ fn main() { // } // } for x in 72..80 { - *driver.state.get_mut(x, y).mat_mut() = mat::Conductor { conductivity: 1.0e1 }.into(); + *driver.state.get_mut(x, y).mat_mut() = mat::Static::conductor(1.0e1).into(); } } for y in 40..60 { diff --git a/src/mat.rs b/src/mat.rs index e477fc6..19b1625 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -22,14 +22,27 @@ pub trait Material { } #[derive(Clone, Default)] -pub struct Conductor { +pub struct Static { pub conductivity: f64, + pub mz: f64, } -impl Material for Conductor { +impl Static { + pub fn conductor(conductivity: f64) -> Self { + Self { + conductivity, + ..Default::default() + } + } +} + +impl Material for Static { fn conductivity(&self) -> f64 { self.conductivity } + fn mz(&self) -> f64 { + self.mz + } } #[derive(Clone, Default)] @@ -194,14 +207,14 @@ impl Material for PiecewiseLinearFerromagnet { #[enum_dispatch(Material)] #[derive(Clone)] pub enum GenericMaterial { - Conductor(Conductor), + Static(Static), // ComsolFerromagnet(ComsolFerromagnet), PiecewiseLinearFerromagnet(PiecewiseLinearFerromagnet) } impl Default for GenericMaterial { fn default() -> Self { - Conductor::default().into() + Static::default().into() } }