Skip to content

Commit

Permalink
fixed missing thermal connection between Cabin and ReversibleEnergySt…
Browse files Browse the repository at this point in the history
…orage

more `pwr_thrml_` state variables
changed `_thermal_` to `_thrml_`
  • Loading branch information
calbaker committed Jan 20, 2025
1 parent 270be10 commit a5e44c8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ hvac:
i_res: 0.0
pwr_i_max_res_watts: 5000.0
d_res: 0.0
pwr_thermal_max_watts: 10000.0
pwr_thrml_max_watts: 10000.0
frac_of_ideal_cop: 0.15
cabin_heat_source: ResistanceHeater
res_heat_source: ResistanceHeater
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ hvac:
i_res: 0.0
pwr_i_max_res_watts: 0.0
d_res: 0.0
pwr_thermal_max_watts: 10000.0
pwr_thrml_max_watts: 10000.0
frac_of_ideal_cop: 0.15
cabin_heat_source: FuelConverter
res_heat_source: None
Expand Down
36 changes: 22 additions & 14 deletions fastsim-core/src/vehicle/cabin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl LumpedCabin {
/// Arguments:
/// - `te_amb_air`: ambient air temperature
/// - `veh_state`: current [VehicleState]
/// - 'pwr_thermal_from_hvac`: power to cabin from [Vehicle::hvac] system
/// - 'pwr_thrml_from_hvac`: power to cabin from [Vehicle::hvac] system
/// - `dt`: simulation time step size
/// # Returns
/// - `te_cab`: current cabin temperature, after solving cabin for current
Expand All @@ -100,10 +100,12 @@ impl LumpedCabin {
&mut self,
te_amb_air: si::Temperature,
veh_state: &VehicleState,
pwr_thermal_from_hvac: si::Power,
pwr_thrml_from_hvac: si::Power,
pwr_thrml_to_res: si::Power,
dt: si::Time,
) -> anyhow::Result<si::Temperature> {
self.state.pwr_thermal_from_hvac = pwr_thermal_from_hvac;
self.state.pwr_thrml_from_hvac = pwr_thrml_from_hvac;
self.state.pwr_thrml_to_res = pwr_thrml_to_res;
// flat plate model for isothermal, mixed-flow from Incropera and deWitt, Fundamentals of Heat and Mass
// Transfer, 7th Edition
let cab_te_film_ext = 0.5 * (self.state.temperature + te_amb_air);
Expand All @@ -130,7 +132,7 @@ impl LumpedCabin {
* Air::get_pr(cab_te_film_ext).with_context(|| format_dbg!())?
};

self.state.pwr_thermal_from_amb = if veh_state.speed_ach > 2.0 * uc::MPH {
self.state.pwr_thrml_from_amb = if veh_state.speed_ach > 2.0 * uc::MPH {
let htc_overall_moving: si::HeatTransferCoeff = 1.0
/ (1.0
/ (nu_l_bar
Expand All @@ -145,8 +147,8 @@ impl LumpedCabin {
};

self.state.temp_prev = self.state.temperature;
self.state.temperature += (self.state.pwr_thermal_from_hvac
+ self.state.pwr_thermal_from_amb)
self.state.temperature += (self.state.pwr_thrml_from_hvac + self.state.pwr_thrml_from_amb
- self.state.pwr_thrml_to_res)
/ self.heat_capacitance
* dt;
Ok(self.state.temperature)
Expand All @@ -166,16 +168,20 @@ pub struct LumpedCabinState {
pub temp_prev: si::Temperature,
/// Thermal power coming to cabin from [Vehicle::hvac] system. Positive indicates
/// heating, and negative indicates cooling.
pub pwr_thermal_from_hvac: si::Power,
pub pwr_thrml_from_hvac: si::Power,
/// Cumulative thermal energy coming to cabin from [Vehicle::hvac] system. Positive indicates
/// heating, and negative indicates cooling.
pub energy_thermal_from_hvac: si::Energy,
pub energy_thrml_from_hvac: si::Energy,
/// Thermal power coming to cabin from ambient air. Positive indicates
/// heating, and negative indicates cooling.
pub pwr_thermal_from_amb: si::Power,
pub pwr_thrml_from_amb: si::Power,
/// Cumulative thermal energy coming to cabin from ambient air. Positive indicates
/// heating, and negative indicates cooling.
pub energy_thermal_from_amb: si::Energy,
pub energy_thrml_from_amb: si::Energy,
/// Thermal power flowing from [Cabin] to [ReversibleEnergyStorage] due to temperature delta
pub pwr_thrml_to_res: si::Power,
/// Cumulative thermal energy flowing from [Cabin] to [ReversibleEnergyStorage] due to temperature delta
pub energy_thrml_to_res: si::Energy,
/// Reynolds number for flow over cabin, treating cabin as a flat plate
pub reynolds_for_plate: si::Ratio,
}
Expand All @@ -186,10 +192,12 @@ impl Default for LumpedCabinState {
i: Default::default(),
temperature: *TE_STD_AIR,
temp_prev: *TE_STD_AIR,
pwr_thermal_from_hvac: Default::default(),
energy_thermal_from_hvac: Default::default(),
pwr_thermal_from_amb: Default::default(),
energy_thermal_from_amb: Default::default(),
pwr_thrml_from_hvac: Default::default(),
energy_thrml_from_hvac: Default::default(),
pwr_thrml_from_amb: Default::default(),
energy_thrml_from_amb: Default::default(),
pwr_thrml_to_res: Default::default(),
energy_thrml_to_res: Default::default(),
reynolds_for_plate: Default::default(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions fastsim-core/src/vehicle/hvac/hvac_sys_for_lumped_cabin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct HVACSystemForLumpedCabin {
/// NOTE: `uom` crate does not have this unit, but it may be possible to make a custom unit for this
pub d: f64,
/// max HVAC thermal power
pub pwr_thermal_max: si::Power,
pub pwr_thrml_max: si::Power,
/// coefficient between 0 and 1 to calculate HVAC efficiency by multiplying by
/// coefficient of performance (COP)
pub frac_of_ideal_cop: f64,
Expand All @@ -52,7 +52,7 @@ impl Default for HVACSystemForLumpedCabin {
i: Default::default(),
d: Default::default(),
pwr_i_max: 5. * uc::KW,
pwr_thermal_max: 10. * uc::KW,
pwr_thrml_max: 10. * uc::KW,
frac_of_ideal_cop: 0.15,
heat_source: CabinHeatSource::ResistanceHeater,
pwr_aux_for_hvac_max: uc::KW * 5.,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl HVACSystemForLumpedCabin {
}
let mut pwr_thrml_hvac_to_cab =
(self.state.pwr_p + self.state.pwr_i + self.state.pwr_d)
.max(-self.pwr_thermal_max);
.max(-self.pwr_thrml_max);

if (-pwr_thrml_hvac_to_cab / self.state.cop) > self.pwr_aux_for_hvac_max {
self.state.pwr_aux_for_hvac = self.pwr_aux_for_hvac_max;
Expand All @@ -152,7 +152,7 @@ impl HVACSystemForLumpedCabin {
}
let mut pwr_thrml_hvac_to_cabin =
(-self.state.pwr_p - self.state.pwr_i - self.state.pwr_d)
.min(self.pwr_thermal_max);
.min(self.pwr_thrml_max);

// Assumes blower has negligible impact on aux load, may want to revise later
let (pwr_thrml_fc_to_cabin, cop) = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct HVACSystemForLumpedCabinAndRES {
/// NOTE: `uom` crate does not have this unit, but it may be possible to make a custom unit for this
pub d_res: f64,
/// max HVAC thermal power
pub pwr_thermal_max: si::Power,
pub pwr_thrml_max: si::Power,
/// coefficient between 0 and 1 to calculate HVAC efficiency by multiplying by
/// coefficient of performance (COP)
pub frac_of_ideal_cop: f64,
Expand Down Expand Up @@ -71,7 +71,7 @@ impl Default for HVACSystemForLumpedCabinAndRES {
i_res: Default::default(),
d_res: Default::default(),
pwr_i_max_res: 5. * uc::KW,
pwr_thermal_max: 10. * uc::KW,
pwr_thrml_max: 10. * uc::KW,
frac_of_ideal_cop: 0.15,
cabin_heat_source: CabinHeatSource::ResistanceHeater,
res_heat_source: RESHeatSource::ResistanceHeater,
Expand Down Expand Up @@ -305,7 +305,7 @@ impl HVACSystemForLumpedCabinAndRES {
}
let mut pwr_thrml_hvac_to_cab =
(self.state.pwr_p + self.state.pwr_i + self.state.pwr_d)
.max(-self.pwr_thermal_max);
.max(-self.pwr_thrml_max);

if (-pwr_thrml_hvac_to_cab / self.state.cop) > self.pwr_aux_for_hvac_max {
self.state.pwr_aux_for_hvac = self.pwr_aux_for_hvac_max;
Expand All @@ -324,7 +324,7 @@ impl HVACSystemForLumpedCabinAndRES {
}
let mut pwr_thrml_hvac_to_cabin: si::Power =
(-self.state.pwr_p - self.state.pwr_i - self.state.pwr_d)
.min(self.pwr_thermal_max);
.min(self.pwr_thrml_max);

// Assumes blower has negligible impact on aux load, may want to revise later
self.handle_cabin_heat_source(
Expand Down Expand Up @@ -381,7 +381,7 @@ impl HVACSystemForLumpedCabinAndRES {
}
let mut pwr_thrml_hvac_to_res =
(self.state.pwr_p_res + self.state.pwr_i_res + self.state.pwr_d_res)
.max(-self.pwr_thermal_max);
.max(-self.pwr_thrml_max);

if (-pwr_thrml_hvac_to_res / self.state.cop) > self.pwr_aux_for_hvac_max {
self.state.pwr_aux_for_hvac = self.pwr_aux_for_hvac_max;
Expand All @@ -401,7 +401,7 @@ impl HVACSystemForLumpedCabinAndRES {
#[allow(clippy::let_and_return)] // for readability
let pwr_thrml_hvac_to_res =
(-self.state.pwr_p_res - self.state.pwr_i_res - self.state.pwr_d_res)
.min(self.pwr_thermal_max);
.min(self.pwr_thrml_max);
pwr_thrml_hvac_to_res
};
pwr_thrml_hvac_to_res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ impl RESLumpedThermal {
dt: si::Time,
) -> anyhow::Result<()> {
self.state.temp_prev = self.state.temperature;
// TODO: make sure this impacts cabin temperature
self.state.pwr_thrml_from_cabin =
self.conductance_to_cab * (te_cab - self.state.temperature);
self.state.pwr_thrml_from_amb = self.conductance_to_cab * (te_amb - self.state.temperature);
Expand Down
23 changes: 21 additions & 2 deletions fastsim-core/src/vehicle/vehicle_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ impl Vehicle {
let te_fc: Option<si::Temperature> = self.fc().and_then(|fc| fc.temperature());
let res_temp = self.res().and_then(|res| res.temperature());
let res_temp_prev = self.res().and_then(|res| res.temp_prev());
let pwr_thrml_cab_to_res: si::Power = self
.res()
.and_then(|res| match &res.thrml {
RESThermalOption::RESLumpedThermal(rlt) => Some(rlt.state.pwr_thrml_from_cabin),
RESThermalOption::None => None,
})
.unwrap_or_default();
let (pwr_thrml_fc_to_cabin, pwr_thrml_hvac_to_res, te_cab): (
Option<si::Power>,
Option<si::Power>,
Expand All @@ -463,7 +470,13 @@ impl Vehicle {
.solve(te_amb_air, te_fc, cab.state, cab.heat_capacitance, dt)
.with_context(|| format_dbg!())?;
let te_cab = cab
.solve(te_amb_air, &self.state, pwr_thrml_hvac_to_cabin, dt)
.solve(
te_amb_air,
&self.state,
pwr_thrml_hvac_to_cabin,
Default::default(),
dt,
)
.with_context(|| format_dbg!())?;
self.state.pwr_aux = self.pwr_aux_base + hvac.state.pwr_aux_for_hvac;
(Some(pwr_thrml_fc_to_cab), None, Some(te_cab))
Expand All @@ -486,7 +499,13 @@ impl Vehicle {
)
.with_context(|| format_dbg!())?;
let te_cab = cab
.solve(te_amb_air, &self.state, pwr_thrml_hvac_to_cabin, dt)
.solve(
te_amb_air,
&self.state,
pwr_thrml_hvac_to_cabin,
pwr_thrml_cab_to_res,
dt,
)
.with_context(|| format_dbg!())?;
self.state.pwr_aux = self.pwr_aux_base + hvac.state.pwr_aux_for_hvac;
(
Expand Down

0 comments on commit a5e44c8

Please sign in to comment.