use pantometry::prelude::*;
use pantometry_electrical::Winding;
#[test]
fn a_winding_warms_a_plate_by_the_joules_it_dissipated() {
let volume = Volume::from_si(60e-3 * 60e-3 * 3e-3);
let start = Temperature::celsius(20.0);
let seconds = 5.0;
let coil = Winding::of_resistance("coil", Resistance::ohm(2.0), 0.0, start)
.driven_at(Current::a(1.5))
.with_reserve(1_000.0);
let watts = coil.dissipation().to_si();
assert!(
(watts - 4.5).abs() < 1e-12,
"I^2 R = 1.5^2 * 2 = 4.5, got {watts}"
);
let plate = LumpedMass::new(
"plate",
Substance::aluminium_6061(),
volume,
Length::mm(1.5),
start,
Environment::still_air(start, Area::from_si(0.0)),
);
let mut sim = Simulation::new(Schedule::Staggered)
.conservation_tolerance(1e-9)
.with(coil)
.with(plate);
let dt = 0.01;
for _ in 0..(seconds / dt) as usize {
sim.advance(Time::s(dt)).expect("the books close");
}
let capacity = Substance::aluminium_6061()
.heat_capacity(volume)
.expect("aluminium has a specific heat")
.to_si();
let want = watts * seconds / capacity;
let got = sim
.domain_as::<LumpedMass>("plate")
.expect("the plate is there")
.temperature()
.to_si()
- start.to_si();
assert!(
(got / want - 1.0).abs() < 1e-9,
"rise {got:.9} K against {want:.9} K"
);
let coil = sim.domain_as::<Winding>("coil").expect("the coil is there");
assert!((coil.dissipated_energy().to_si() - watts * seconds).abs() < 1e-9);
assert!((coil.reserve().to_si() - (1_000.0 - watts * seconds)).abs() < 1e-9);
}
#[test]
fn a_winding_with_no_reserve_is_caught_by_the_audit() {
let coil = Winding::of_resistance(
"coil",
Resistance::ohm(2.0),
0.0,
Temperature::celsius(20.0),
)
.driven_at(Current::a(1.5));
let plate = LumpedMass::new(
"plate",
Substance::aluminium_6061(),
Volume::from_si(1e-4),
Length::mm(1.5),
Temperature::celsius(20.0),
Environment::still_air(Temperature::celsius(20.0), Area::from_si(0.0)),
);
let mut sim = Simulation::new(Schedule::Staggered)
.conservation_tolerance(1e-9)
.with(coil)
.with(plate);
let violation = sim
.advance(Time::s(1.0))
.expect_err("joules from an infinite tank are joules from nowhere");
assert_eq!(violation.site, "coil", "the winding names itself");
assert!(
violation.quantity.contains("with_reserve"),
"{}",
violation.quantity
);
assert_eq!(sim.time().to_si(), 0.0, "a refused step keeps the clock");
}