Repurpose mat::Conductor to mat::Static

This will allow taking a material-independent snapshot of the SimState.
This commit is contained in:
2020-09-06 12:18:31 -07:00
parent c8ac13f1b2
commit b7716d2dea
3 changed files with 25 additions and 11 deletions

View File

@@ -8,11 +8,11 @@ fn main() {
for inset in 0..20 { for inset in 0..20 {
for x in 0..width { 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 { 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(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::Conductor { conductivity: 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 { for y in 75..100 {
@@ -21,7 +21,7 @@ fn main() {
// NB: different sources give pretty different values for this // NB: different sources give pretty different values for this
// NB: Simulation misbehaves for values > 10... Proably this model isn't so great. // NB: Simulation misbehaves for values > 10... Proably this model isn't so great.
// Maybe use \eps or \xi instead of conductivity. // 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();
} }
} }

View File

@@ -4,11 +4,12 @@ fn main() {
let width = 201; let width = 201;
let height = 101; let height = 101;
let mut driver = Driver::new(width, height, 1e-3 /* feature size */) 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 y in 0..height {
for x in 50..60 { 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 { // for x in 30..40 {
// *state.get_mut(x, y).mat_mut() = mat::Conductor { conductivity: 1.0e8 }.into(); // *state.get_mut(x, y).mat_mut() = mat::Conductor { conductivity: 1.0e8 }.into();
@@ -19,7 +20,7 @@ fn main() {
// } // }
// } // }
for x in 72..80 { 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 { for y in 40..60 {

View File

@@ -22,14 +22,27 @@ pub trait Material {
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct Conductor { pub struct Static {
pub conductivity: f64, 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 { fn conductivity(&self) -> f64 {
self.conductivity self.conductivity
} }
fn mz(&self) -> f64 {
self.mz
}
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@@ -194,14 +207,14 @@ impl Material for PiecewiseLinearFerromagnet {
#[enum_dispatch(Material)] #[enum_dispatch(Material)]
#[derive(Clone)] #[derive(Clone)]
pub enum GenericMaterial { pub enum GenericMaterial {
Conductor(Conductor), Static(Static),
// ComsolFerromagnet(ComsolFerromagnet), // ComsolFerromagnet(ComsolFerromagnet),
PiecewiseLinearFerromagnet(PiecewiseLinearFerromagnet) PiecewiseLinearFerromagnet(PiecewiseLinearFerromagnet)
} }
impl Default for GenericMaterial { impl Default for GenericMaterial {
fn default() -> Self { fn default() -> Self {
Conductor::default().into() Static::default().into()
} }
} }