diff --git a/crates/coremem/src/mat/linear.rs b/crates/coremem/src/mat/linear.rs index 01118d0..9550e2b 100644 --- a/crates/coremem/src/mat/linear.rs +++ b/crates/coremem/src/mat/linear.rs @@ -42,14 +42,6 @@ impl Into> for IsomorphicConductor { } } -impl AnisomorphicConductor { - pub fn new_anisotropic(c: Vec3) -> Self { - Self { - conductivity: Vec3::new(c.x().cast(), c.y().cast(), c.z().cast()) - } - } -} - impl Material for AnisomorphicConductor { fn step_parameters_mut<'a>(&'a mut self) -> StepParametersMut<'a, R> { StepParametersMut::default().with_conductivity(self.conductivity) diff --git a/crates/coremem/src/sim/mod.rs b/crates/coremem/src/sim/mod.rs index 961455f..875f4eb 100644 --- a/crates/coremem/src/sim/mod.rs +++ b/crates/coremem/src/sim/mod.rs @@ -1259,7 +1259,7 @@ impl CellStateWithM { mod test { use super::*; use crate::geom::{Cube, Region, WorldRegion}; - use crate::mat::{Conductor, Pml, Static}; + use crate::mat::{AnisomorphicConductor, IsomorphicConductor, Pml, Static}; use crate::real::{R64, ToFloat as _}; use float_eq::assert_float_eq; use more_asserts::*; @@ -1683,14 +1683,14 @@ mod test { #[test] fn conductor_dissipates_energy() { - let (energy_0, energy_1) = conductor_test(Conductor::new(R64::from_f32(1e3))); + let (energy_0, energy_1) = conductor_test(IsomorphicConductor::new(R64::from_f32(1e3))); assert_float_eq!(energy_1/energy_0, 0.0, abs <= 1e-6); } #[test] fn anisotropic_conductor_inactive_x() { - let (energy_0, energy_1) = conductor_test(Conductor::new_anisotropic( - Vec3::new_x(1e3) + let (energy_0, energy_1) = conductor_test(AnisomorphicConductor::new( + Vec3::new_x(1e3).cast() )); assert_gt!(energy_1, 0.9*energy_0); // XXX: I think this gains energy because we only set the E field and not the H field @@ -1699,8 +1699,8 @@ mod test { #[test] fn anisotropic_conductor_inactive_y() { - let (energy_0, energy_1) = conductor_test(Conductor::new_anisotropic( - Vec3::new_y(1e3) + let (energy_0, energy_1) = conductor_test(AnisomorphicConductor::new( + Vec3::new_y(1e3).cast() )); assert_gt!(energy_1, 0.9*energy_0); assert_lt!(energy_1, 1.5*energy_0); @@ -1708,8 +1708,8 @@ mod test { #[test] fn anisotropic_conductor_active_z() { - let (energy_0, energy_1) = conductor_test(Conductor::new_anisotropic( - Vec3::new_z(1e3) + let (energy_0, energy_1) = conductor_test(AnisomorphicConductor::new( + Vec3::new_z(1e3).cast() )); assert_float_eq!(energy_1/energy_0, 0.0, abs <= 1e-6); } @@ -1733,13 +1733,13 @@ mod test { } /// Like state_for_pml, but the boundary is an ordinary electric conductor -- not PML - fn state_for_graded_conductor(size: Index) -> SimState> { + fn state_for_graded_conductor(size: Index) -> SimState> { let mut state = SimState::new(size, 1e-6); let timestep = state.timestep(); state.fill_boundary_using(size/4, |boundary_ness| { let b = boundary_ness.elem_pow(3.0); let conductivity = f32::eps0() * b.mag() * 0.5 / timestep; - Conductor::new(conductivity.cast()) + IsomorphicConductor::new(conductivity.cast()) }); state } diff --git a/crates/coremem/src/sim/spirv/mod.rs b/crates/coremem/src/sim/spirv/mod.rs index 422162f..8521cd8 100644 --- a/crates/coremem/src/sim/spirv/mod.rs +++ b/crates/coremem/src/sim/spirv/mod.rs @@ -652,7 +652,7 @@ mod test { use super::*; use crate::real::ToFloat as _; use crate::sim::{SampleableSim, SimState}; - use crate::mat::{self, Conductor}; + use crate::mat::{self, AnisomorphicConductor}; use more_asserts::assert_lt; fn mean_magnitude_e(sim: &dyn SampleableSim) -> f32 { (sim.map_sum_enumerated(|_pos: Index, cell| { @@ -891,8 +891,8 @@ mod test { rng.gen_range(0.0..1e6), rng.gen_range(0.0..1e6), ); - ref_state.put_material(Index::new(x, y, z), Conductor::new_anisotropic(cond)); - dut_state.put_material(Index::new(x, y, z), Conductor::new_anisotropic(cond)); + ref_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); + dut_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); } } } @@ -1155,8 +1155,8 @@ mod test { rng.gen_range(0.0..1e6), rng.gen_range(0.0..1e6), ); - ref_state.put_material(Index::new(x, y, z), Conductor::new_anisotropic(cond)); - dut_state.put_material(Index::new(x, y, z), Conductor::new_anisotropic(cond)); + ref_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); + dut_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); } } } @@ -1236,7 +1236,7 @@ mod test { let m_max = rng.gen_range(0.0..1_000_000.0); dut_state.put_material(Index::new(x, y, z), mat::MHPgram::new(h_start, mu_r, m_max)); } else if rng.gen_range(0.0..1.0) < 0.5 { - dut_state.put_material(Index::new(x, y, z), mat::Conductor::new(rng.gen_range(0.0..1e7))); + dut_state.put_material(Index::new(x, y, z), mat::IsomorphicConductor::new(rng.gen_range(0.0..1e7))); } } } diff --git a/crates/types/src/real.rs b/crates/types/src/real.rs index 614afc7..9ecaf05 100644 --- a/crates/types/src/real.rs +++ b/crates/types/src/real.rs @@ -2,7 +2,7 @@ use core::fmt; use core::ops::{ Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign, }; -use core::cmp::{Ordering, PartialOrd}; +use core::cmp::{Eq, Ord, Ordering, PartialOrd}; use serde::{Deserialize, Serialize}; pub trait ToFloat { @@ -235,6 +235,14 @@ impl Finite { } } +impl Eq for Finite {} + +impl Ord for Finite { + fn cmp(&self, other: &Self) -> Ordering { + self.partial_cmp(other).unwrap() + } +} + impl fmt::Display for Finite { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f)