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,
15    Default,
16    Debug,
17    Serialize,
18    Deserialize,
19    PartialEq,
20    IsVariant,
21    derive_more::From,
22    TryInto,
23    derive_more::Display,
24)]
25pub enum HVACOption {
26    /// HVAC system for [LumpedCabin]
27    #[display("LumpedCabin")]
28    LumpedCabin(Box<HVACSystemForLumpedCabin>),
29    /// HVAC system for [LumpedCabin] and [ReversibleEnergyStorage]
30    #[display("LumpedCabinAndRES")]
31    LumpedCabinAndRES(Box<HVACSystemForLumpedCabinAndRES>),
32    /// Cabin with interior and shell capacitances
33    #[display("LumpedCabinWithShell")]
34    LumpedCabinWithShell,
35    /// [ReversibleEnergyStorage] thermal management with no cabin
36    #[display("ReversibleEnergyStorageOnly")]
37    ReversibleEnergyStorageOnly,
38    /// no cabin thermal model
39    #[default]
40    #[display("None")]
41    None,
42}
43impl Init for HVACOption {
44    fn init(&mut self) -> Result<(), Error> {
45        match self {
46            Self::LumpedCabin(cab) => cab.init()?,
47            Self::LumpedCabinAndRES(cab) => cab.init()?,
48            Self::LumpedCabinWithShell => {
49                todo!()
50            }
51            Self::ReversibleEnergyStorageOnly => {
52                todo!()
53            }
54            Self::None => {}
55        }
56        Ok(())
57    }
58}
59impl SerdeAPI for HVACOption {}
60impl SetCumulative for HVACOption {
61    fn set_cumulative<F: Fn() -> String>(&mut self, dt: si::Time, loc: F) -> anyhow::Result<()> {
62        match self {
63            HVACOption::LumpedCabin(lc) => {
64                lc.set_cumulative(dt, || format!("{}\n{}", loc(), format_dbg!()))?
65            }
66            HVACOption::LumpedCabinAndRES(lcr) => {
67                lcr.set_cumulative(dt, || format!("{}\n{}", loc(), format_dbg!()))?
68            }
69            HVACOption::LumpedCabinWithShell => todo!(),
70            HVACOption::ReversibleEnergyStorageOnly => todo!(),
71            HVACOption::None => {}
72        }
73        Ok(())
74    }
75}
76impl HistoryMethods for HVACOption {
77    fn save_interval(&self) -> anyhow::Result<Option<usize>> {
78        match self {
79            HVACOption::LumpedCabin(lc) => lc.save_interval(),
80            HVACOption::LumpedCabinAndRES(lcr) => lcr.save_interval(),
81            HVACOption::LumpedCabinWithShell => todo!(),
82            HVACOption::ReversibleEnergyStorageOnly => todo!(),
83            HVACOption::None => Ok(None),
84        }
85    }
86    fn set_save_interval(&mut self, save_interval: Option<usize>) -> anyhow::Result<()> {
87        match self {
88            HVACOption::LumpedCabin(lc) => lc.set_save_interval(save_interval),
89            HVACOption::LumpedCabinAndRES(lcr) => lcr.set_save_interval(save_interval),
90            HVACOption::LumpedCabinWithShell => todo!(),
91            HVACOption::ReversibleEnergyStorageOnly => todo!(),
92            HVACOption::None => Ok(()),
93        }
94    }
95    fn clear(&mut self) {
96        match self {
97            HVACOption::LumpedCabin(lc) => lc.clear(),
98            HVACOption::LumpedCabinAndRES(lcr) => lcr.clear(),
99            HVACOption::LumpedCabinWithShell => todo!(),
100            HVACOption::ReversibleEnergyStorageOnly => todo!(),
101            HVACOption::None => {}
102        }
103    }
104}
105
106impl StateMethods for HVACOption {}
107
108impl SaveState for HVACOption {
109    fn save_state<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
110        match self {
111            Self::LumpedCabin(lc) => lc.save_state(loc)?,
112            Self::LumpedCabinAndRES(lcr) => lcr.save_state(loc)?,
113            Self::LumpedCabinWithShell => {
114                todo!()
115            }
116            Self::ReversibleEnergyStorageOnly => todo!(),
117            Self::None => {}
118        }
119        Ok(())
120    }
121}
122impl TrackedStateMethods for HVACOption {
123    fn check_and_reset<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
124        match self {
125            Self::LumpedCabin(lc) => {
126                lc.check_and_reset(|| format!("{}\n{}", loc(), format_dbg!()))?
127            }
128            Self::LumpedCabinAndRES(lcr) => {
129                lcr.check_and_reset(|| format!("{}\n{}", loc(), format_dbg!()))?
130            }
131            Self::LumpedCabinWithShell => {
132                todo!()
133            }
134            Self::ReversibleEnergyStorageOnly => todo!(),
135            Self::None => {}
136        }
137        Ok(())
138    }
139
140    fn mark_fresh<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
141        match self {
142            Self::LumpedCabin(lc) => lc.mark_fresh(|| format!("{}\n{}", loc(), format_dbg!()))?,
143            Self::LumpedCabinAndRES(lcr) => {
144                lcr.mark_fresh(|| format!("{}\n{}", loc(), format_dbg!()))?
145            }
146            Self::LumpedCabinWithShell => {
147                todo!()
148            }
149            Self::ReversibleEnergyStorageOnly => todo!(),
150            Self::None => {}
151        }
152        Ok(())
153    }
154}
155impl Step for HVACOption {
156    fn step<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
157        match self {
158            Self::LumpedCabin(lc) => lc.step(|| format!("{}\n{}", loc(), format_dbg!())),
159            Self::LumpedCabinAndRES(lcr) => lcr.step(|| format!("{}\n{}", loc(), format_dbg!())),
160            Self::LumpedCabinWithShell => {
161                todo!()
162            }
163            Self::ReversibleEnergyStorageOnly => todo!(),
164            Self::None => Ok(()),
165        }
166    }
167
168    fn reset_step<F: Fn() -> String>(&mut self, loc: F) -> anyhow::Result<()> {
169        match self {
170            Self::LumpedCabin(lc) => lc.reset_step(|| format!("{}\n{}", loc(), format_dbg!())),
171            Self::LumpedCabinAndRES(lcr) => {
172                lcr.reset_step(|| format!("{}\n{}", loc(), format_dbg!()))
173            }
174            Self::LumpedCabinWithShell => {
175                todo!()
176            }
177            Self::ReversibleEnergyStorageOnly => todo!(),
178            Self::None => Ok(()),
179        }
180    }
181}