Skip to content

Commit

Permalink
bev thermal demo runs!
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Dec 28, 2024
1 parent c204985 commit 3871234
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
9 changes: 6 additions & 3 deletions cal_and_val/thermal/f3-vehicles/2020 Chevrolet Bolt EV.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ pt_type:
res:
thrml:
RESLumpedThermal:
heat_capacitance_joules_per_kelvin: 0.0
htc_to_amb_watts_per_kelvin: 0.0
htc_to_cab_watts_per_kelvin: 0.0
# 200,000 is Chad's uncalibrated estimate
heat_capacitance_joules_per_kelvin: 200000
# 0.1 is Chad's uncalibrated estimate
conductance_to_amb_watts_per_kelvin: 0.1
# 0.5 is Chad's uncalibrated estimate
conductance_to_cab_watts_per_kelvin: 0.5
mass_kilograms: ~
specific_energy_joules_per_kilogram: ~
pwr_out_max_watts: 165000.0
Expand Down
21 changes: 14 additions & 7 deletions fastsim-core/src/vehicle/hvac/hvac_sys_for_lumped_cabin_and_res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ impl HVACSystemForLumpedCabinAndRES {
dt: si::Time,
) -> anyhow::Result<(si::Power, si::Power, si::Power)> {
let (res_temp, res_temp_prev) = res_temps;
ensure!(!res_temp.is_nan(), format_dbg!(res_temp));
ensure!(!res_temp_prev.is_nan(), format_dbg!(res_temp_prev));
let mut pwr_thrml_hvac_to_cabin = self
.solve_for_cabin(te_fc, cab_state, cab_heat_cap, dt)
.with_context(|| format_dbg!())?;
let mut pwr_thrml_hvac_to_res: si::Power = self
.solve_for_res(res_temp, res_temp_prev, dt)
.with_context(|| format_dbg!())?;
let cop_ideal: si::Ratio =
let (cop_ideal, te_ref) =
if pwr_thrml_hvac_to_res + pwr_thrml_hvac_to_cabin > si::Power::ZERO {
// heating mode
// TODO: account for cabin and battery heat sources in COP calculation!!!!
Expand Down Expand Up @@ -151,9 +153,9 @@ impl HVACSystemForLumpedCabinAndRES {
if te_delta_vs_amb.abs() < 5.0 * uc::KELVIN {
// cabin is cooler than ambient + threshold
// TODO: make this `5.0` not hardcoded
te_ref / (5.0 * uc::KELVIN)
(te_ref / (5.0 * uc::KELVIN), te_ref)
} else {
te_ref / te_delta_vs_amb.abs()
(te_ref / te_delta_vs_amb.abs(), te_ref)
}
} else if pwr_thrml_hvac_to_res + pwr_thrml_hvac_to_cabin < si::Power::ZERO {
// cooling mode
Expand Down Expand Up @@ -186,15 +188,20 @@ impl HVACSystemForLumpedCabinAndRES {
if te_delta_vs_amb.abs() < 5.0 * uc::KELVIN {
// cooling-dominating component is cooler than ambient + threshold
// TODO: make this `5.0` not hardcoded
te_ref / (5.0 * uc::KELVIN)
(te_ref / (5.0 * uc::KELVIN), te_ref)
} else {
te_ref / te_delta_vs_amb.abs()
(te_ref / te_delta_vs_amb.abs(), te_ref)
}
} else {
si::Ratio::ZERO
(si::Ratio::ZERO, f64::NAN * uc::KELVIN)
};
self.state.cop = cop_ideal * self.frac_of_ideal_cop;
ensure!(self.state.cop >= 0.0 * uc::R, "{}", format_dbg!(cop_ideal));
ensure!(
self.state.cop >= 0.0 * uc::R,
"{}\n{}",
format_dbg!(cop_ideal),
format_dbg!(te_ref)
);

let mut pwr_thrml_fc_to_cabin = si::Power::ZERO;
self.state.pwr_aux_for_hvac = if pwr_thrml_hvac_to_cabin > si::Power::ZERO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,9 @@ pub struct RESLumpedThermal {
/// [ReversibleEnergyStorage] thermal capacitance
pub heat_capacitance: si::HeatCapacity,
/// parameter for heat transfer coeff from [ReversibleEnergyStorage::thrml] to ambient
pub htc_to_amb: si::ThermalConductance,
pub conductance_to_amb: si::ThermalConductance,
/// parameter for heat transfer coeff from [ReversibleEnergyStorage::thrml] to cabin
pub htc_to_cab: si::ThermalConductance,
pub conductance_to_cab: si::ThermalConductance,
/// current state
#[serde(default, skip_serializing_if = "EqDefault::eq_default")]
pub state: RESLumpedThermalState,
Expand All @@ -797,8 +797,9 @@ impl RESLumpedThermal {
dt: si::Time,
) -> anyhow::Result<()> {
self.state.temp_prev = self.state.temperature;
self.state.pwr_thrml_from_cabin = self.htc_to_cab * (te_cab - self.state.temperature);
self.state.pwr_thrml_from_amb = self.htc_to_cab * (te_amb - self.state.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);
self.state.temperature += (pwr_thrml_hvac_to_res
+ res_state.pwr_out_electrical * (1.0 * uc::R - res_state.eff)
+ self.state.pwr_thrml_from_cabin
Expand Down
14 changes: 4 additions & 10 deletions python/fastsim/demos/demo_bev_thrml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

from plot_utils import *

# if enivronment var `DEBUG_LOG=true` is set, turns on debug logging
DEBUG_LOG = os.environ.get("DEBUG_LOG", "false").lower() == "true"
# if environment var `SHOW_PLOTS=false` is set, no plots are shown
SHOW_PLOTS = os.environ.get("SHOW_PLOTS", "true").lower() == "true"
# if environment var `SAVE_FIGS=true` is set, save plots
Expand All @@ -27,7 +25,9 @@
# %%

# load 2012 Ford Fusion from file
veh = fsim.Vehicle.from_file(fsim.package_root() / "../../cal_and_val/thermal/f3-vehicles/2020 Chevrolet Bolt EV.yaml")
veh = fsim.Vehicle.from_file(
fsim.package_root() / "../../cal_and_val/thermal/f3-vehicles/2020 Chevrolet Bolt EV.yaml"
)

# Set `save_interval` at vehicle level -- cascades to all sub-components with time-varying states
fsim.set_param_from_path(veh, "save_interval" , 1)
Expand All @@ -41,13 +41,7 @@
# simulation start time
t0 = time.perf_counter()
# run simulation
# toggle commented code to enable logging
if DEBUG_LOG:
print('Running `sd.walk()` with debug logging')
with fsim.utils.with_logging():
sd.walk()
else:
sd.walk()
sd.walk()
# simulation end time
t1 = time.perf_counter()
t_fsim3_si1 = t1 - t0
Expand Down

0 comments on commit 3871234

Please sign in to comment.