fix test compilation failures from vec migration
This commit is contained in:
@@ -42,14 +42,6 @@ impl<R: Real> Into<AnisomorphicConductor<R>> for IsomorphicConductor<R> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Real> AnisomorphicConductor<R> {
|
||||
pub fn new_anisotropic<R2: Real>(c: Vec3<R2>) -> Self {
|
||||
Self {
|
||||
conductivity: Vec3::new(c.x().cast(), c.y().cast(), c.z().cast())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Real> Material<R> for AnisomorphicConductor<R> {
|
||||
fn step_parameters_mut<'a>(&'a mut self) -> StepParametersMut<'a, R> {
|
||||
StepParametersMut::default().with_conductivity(self.conductivity)
|
||||
|
@@ -1259,7 +1259,7 @@ impl<R: Real> CellStateWithM<R> {
|
||||
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<R64, Conductor<R64>> {
|
||||
fn state_for_graded_conductor(size: Index) -> SimState<R64, IsomorphicConductor<R64>> {
|
||||
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
|
||||
}
|
||||
|
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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<T: Real> Finite<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Real> Eq for Finite<T> {}
|
||||
|
||||
impl<T: Real> Ord for Finite<T> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Display> fmt::Display for Finite<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
|
Reference in New Issue
Block a user