fastsim_core/vehicle/
hvac.rs

1use super::*;
2
3pub mod hvac_utils;
4pub use hvac_utils::*;
5
6pub mod hvac_sys_for_lumped_cabin;
7pub use hvac_sys_for_lumped_cabin::*;
8
9pub mod hvac_sys_for_lumped_cabin_and_res;
10pub use hvac_sys_for_lumped_cabin_and_res::*;
11
12/// Options for handling HVAC system
13#[derive(
14    Clone, Default, Debug, Serialize, Deserialize, PartialEq, IsVariant, derive_more::From, TryInto,
15)]
16pub enum HVACOption {
17    /// HVAC system for [LumpedCabin]
18    LumpedCabin(Box<HVACSystemForLumpedCabin>),
19    /// HVAC system for [LumpedCabin] and [ReversibleEnergyStorage]
20    LumpedCabinAndRES(Box<HVACSystemForLumpedCabinAndRES>),
21    /// Cabin with interior and shell capacitances
22    LumpedCabinWithShell,
23    /// [ReversibleEnergyStorage] thermal management with no cabin
24    ReversibleEnergyStorageOnly,
25    /// no cabin thermal model
26    #[default]
27    None,
28}
29impl Init for HVACOption {
30    fn init(&mut self) -> Result<(), Error> {
31        match self {
32            Self::LumpedCabin(cab) => cab.init()?,
33            Self::LumpedCabinAndRES(cab) => cab.init()?,
34            Self::LumpedCabinWithShell => {
35                todo!()
36            }
37            Self::ReversibleEnergyStorageOnly => {
38                todo!()
39            }
40            Self::None => {}
41        }
42        Ok(())
43    }
44}
45impl SerdeAPI for HVACOption {}
46impl SetCumulative for HVACOption {
47    fn set_cumulative(&mut self, dt: si::Time) -> anyhow::Result<()> {
48        match self {
49            HVACOption::LumpedCabin(lc) => lc.set_cumulative(dt)?,
50            HVACOption::LumpedCabinAndRES(lcr) => lcr.set_cumulative(dt)?,
51            HVACOption::LumpedCabinWithShell => todo!(),
52            HVACOption::ReversibleEnergyStorageOnly => todo!(),
53            HVACOption::None => {}
54        }
55        Ok(())
56    }
57}
58impl HistoryMethods for HVACOption {
59    fn save_interval(&self) -> anyhow::Result<Option<usize>> {
60        match self {
61            HVACOption::LumpedCabin(lc) => lc.save_interval(),
62            HVACOption::LumpedCabinAndRES(lcr) => lcr.save_interval(),
63            HVACOption::LumpedCabinWithShell => todo!(),
64            HVACOption::ReversibleEnergyStorageOnly => todo!(),
65            HVACOption::None => Ok(None),
66        }
67    }
68    fn set_save_interval(&mut self, save_interval: Option<usize>) -> anyhow::Result<()> {
69        match self {
70            HVACOption::LumpedCabin(lc) => lc.set_save_interval(save_interval),
71            HVACOption::LumpedCabinAndRES(lcr) => lcr.set_save_interval(save_interval),
72            HVACOption::LumpedCabinWithShell => todo!(),
73            HVACOption::ReversibleEnergyStorageOnly => todo!(),
74            HVACOption::None => Ok(()),
75        }
76    }
77    fn clear(&mut self) {
78        match self {
79            HVACOption::LumpedCabin(lc) => lc.clear(),
80            HVACOption::LumpedCabinAndRES(lcr) => lcr.clear(),
81            HVACOption::LumpedCabinWithShell => todo!(),
82            HVACOption::ReversibleEnergyStorageOnly => todo!(),
83            HVACOption::None => {}
84        }
85    }
86}
87impl SaveState for HVACOption {
88    fn save_state<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
89        match self {
90            Self::LumpedCabin(lc) => lc.save_state(loc)?,
91            Self::LumpedCabinAndRES(lcr) => lcr.save_state(loc)?,
92            Self::LumpedCabinWithShell => {
93                todo!()
94            }
95            Self::ReversibleEnergyStorageOnly => todo!(),
96            Self::None => {}
97        }
98        Ok(())
99    }
100}
101impl CheckAndResetState for HVACOption {
102    fn check_and_reset<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
103        match self {
104            Self::LumpedCabin(lc) => {
105                lc.check_and_reset(|| format!("{}\n{}", loc(), format_dbg!()))?
106            }
107            Self::LumpedCabinAndRES(lcr) => {
108                lcr.check_and_reset(|| format!("{}\n{}", loc(), format_dbg!()))?
109            }
110            Self::LumpedCabinWithShell => {
111                todo!()
112            }
113            Self::ReversibleEnergyStorageOnly => todo!(),
114            Self::None => {}
115        }
116        Ok(())
117    }
118}
119impl Step for HVACOption {
120    fn step<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
121        match self {
122            Self::LumpedCabin(lc) => lc.step(|| format!("{}\n{}", loc(), format_dbg!())),
123            Self::LumpedCabinAndRES(lcr) => lcr.step(|| format!("{}\n{}", loc(), format_dbg!())),
124            Self::LumpedCabinWithShell => {
125                todo!()
126            }
127            Self::ReversibleEnergyStorageOnly => todo!(),
128            Self::None => Ok(()),
129        }
130    }
131}