use crate::imports::*;
#[derive(HistoryMethods, BareClone, Default)]
#[common_derives]
#[pyo3_api(
#[new]
/// New thermal mass with capacitance `c` and initial temperature `t0`
pub fn __new__(c: f64, temp0: f64) -> Self {
Self {
c,
state: ThermalMassState {
temp: temp0,
dtemp: Default::default(),
},
history: Default::default(),
}
}
)]
pub struct ThermalMass {
pub c: f64,
pub state: ThermalMassState,
pub history: ThermalMassStateHistoryVec,
}
impl HasState for ThermalMass {
fn set_state(&mut self, val: f64) {
self.state.temp = val;
}
fn state(&self) -> f64 {
self.state.temp
}
fn deriv(&self) -> f64 {
self.state.dtemp
}
fn set_deriv(&mut self, val: f64) {
self.state.dtemp = val;
}
fn step_deriv(&mut self, val: f64) {
self.state.dtemp += val;
}
fn storage(&self) -> f64 {
self.c
}
}
#[derive(HistoryMethods, BareClone, Default)]
#[common_derives]
#[pyo3_api(
#[new]
/// New thermal reservoir with initial temperature `t0`
pub fn __new__(temp0: f64) -> Self {
Self {
state: ThermalMassState {
temp: temp0,
dtemp: Default::default(),
},
history: Default::default(),
}
}
)]
pub struct ThermalReservoir {
pub state: ThermalMassState,
pub history: ThermalMassStateHistoryVec,
}
impl HasState for ThermalReservoir {
fn set_state(&mut self, val: f64) {
self.state.temp = val;
}
fn state(&self) -> f64 {
self.state.temp
}
fn deriv(&self) -> f64 {
self.state.dtemp
}
fn set_deriv(&mut self, _val: f64) {
self.state.dtemp = 0.0;
}
fn step_deriv(&mut self, val: f64) {
self.state.dtemp += val;
}
fn storage(&self) -> f64 {
f64::INFINITY
}
}
#[derive(Copy, HistoryVec, Default)]
#[common_derives]
#[pyo3_api]
pub struct ThermalMassState {
pub temp: f64,
pub dtemp: f64,
}
#[derive(HistoryMethods, BareClone)]
#[pyo3_api(
#[new]
fn __new__(h: f64) -> Self {
Self {
h,
state: ConductanceState {
q: Default::default(),
},
history: ConductanceStateHistoryVec {
q: Default::default(),
},
}
}
)]
#[common_derives]
#[derive(Default)]
pub struct Conductance {
pub h: f64,
pub state: ConductanceState,
pub history: ConductanceStateHistoryVec,
}
impl Flow for Conductance {
fn flow(&self) -> f64 {
self.state.q
}
fn set_flow(&mut self, p0: &dyn HasState, p1: &dyn HasState) {
self.state.q = self.h * (p0.state() - p1.state());
}
}
#[derive(Copy, HistoryVec, Default)]
#[common_derives]
#[pyo3_api]
pub struct ConductanceState {
pub q: f64,
}