Skip to content

Commit

Permalink
almost to the point of being ready to merge into fastsim-3
Browse files Browse the repository at this point in the history
then make demos and re-merge after that
but first, troubleshoot compiler errors
  • Loading branch information
calbaker committed Dec 18, 2024
1 parent eca8d19 commit 95a2d03
Show file tree
Hide file tree
Showing 16 changed files with 841 additions and 733 deletions.
6 changes: 6 additions & 0 deletions fastsim-core/fastsim-proc-macros/src/history_vec_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ pub(crate) fn history_vec_derive(input: TokenStream) -> TokenStream {
}
state_vec
}

// TODO: flesh this out
// /// Returns fieldnames of any fields that are constant throughout history
// pub fn names_of_static_fields(&self) -> Vec<String> {

// }
}

impl Default for #new_name {
Expand Down
3 changes: 2 additions & 1 deletion fastsim-core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub use crate::vehicle::powertrain::fuel_converter::{
FuelConverterThermalOption,
};
pub use crate::vehicle::powertrain::reversible_energy_storage::{
ReversibleEnergyStorage, ReversibleEnergyStorageState, ReversibleEnergyStorageStateHistoryVec,
RESLumpedThermal, RESLumpedThermalState, RESThermalOption, ReversibleEnergyStorage,
ReversibleEnergyStorageState, ReversibleEnergyStorageStateHistoryVec,
};
pub use crate::vehicle::PowertrainType;
pub use crate::vehicle::Vehicle;
5 changes: 2 additions & 3 deletions fastsim-core/src/simdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ impl SimDrive {
let i = self.veh.state.i;
let dt = self.cyc.dt_at_i(i)?;
let speed_prev = self.veh.state.speed_ach;
// TODO: make sure `pwr_aux` is updated in here and propagated to `set_curr_pwr_out_max`
// maybe make a static `pwr_aux_max` and controls like:
// maybe make controls like:
// ```
// pub enum HVACAuxPriority {
// /// Prioritize [ReversibleEnergyStorage] thermal management
Expand All @@ -200,7 +199,7 @@ impl SimDrive {
// }
// ```
self.veh
.solve_thermal(self.cyc.temp_amb_air[i], self.veh.state, dt)
.solve_thermal(self.cyc.temp_amb_air[i], dt)
.with_context(|| format_dbg!())?;
self.veh
.set_curr_pwr_out_max(dt)
Expand Down
4 changes: 2 additions & 2 deletions fastsim-core/src/vehicle/bev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl Powertrain for BatteryElectricVehicle {
fn solve_thermal(
&mut self,
te_amb: si::Temperature,
_pwr_thrl_fc_to_cab: si::Power,
_veh_state: VehicleState,
_pwr_thrml_fc_to_cab: si::Power,
_veh_state: &mut VehicleState,
dt: si::Time,
) -> anyhow::Result<()> {
self.res
Expand Down
14 changes: 7 additions & 7 deletions fastsim-core/src/vehicle/cabin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ impl LumpedCabin {
pub fn solve(
&mut self,
te_amb_air: si::Temperature,
veh_state: VehicleState,
veh_state: &mut VehicleState,
pwr_thermal_from_hvac: si::Power,
dt: si::Time,
) -> anyhow::Result<()> {
self.state.pwr_thermal_from_hvac = pwr_thermal_from_hvac;
// 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.temp + te_amb_air);
let cab_te_film_ext = 0.5 * (self.state.temperature + te_amb_air);
self.state.reynolds_for_plate =
Air::get_density(Some(cab_te_film_ext), Some(veh_state.elev_curr))
* veh_state.speed_ach
Expand Down Expand Up @@ -107,15 +107,15 @@ impl LumpedCabin {
* Air::get_therm_cond(cab_te_film_ext).with_context(|| format_dbg!())?
/ self.length)
+ 1.0 / self.cab_htc_to_amb);
(self.length * self.width) * htc_overall_moving * (te_amb_air - self.state.temp)
(self.length * self.width) * htc_overall_moving * (te_amb_air - self.state.temperature)
} else {
(self.length * self.width)
/ (1.0 / self.cab_htc_to_amb_stop + 1.0 / self.cab_htc_to_amb)
* (te_amb_air - self.state.temp)
* (te_amb_air - self.state.temperature)
};

self.state.temp_prev = self.state.temp;
self.state.temp += (self.state.pwr_thermal_from_hvac + self.state.pwr_thermal_from_amb)
self.state.temp_prev = self.state.temperature;
self.state.temperature += (self.state.pwr_thermal_from_hvac + self.state.pwr_thermal_from_amb)
/ self.heat_capacitance
* dt;
Ok(())
Expand All @@ -130,7 +130,7 @@ pub struct LumpedCabinState {
/// time step counter
pub i: u32,
/// lumped cabin temperature
pub temp: si::Temperature,
pub temperature: si::Temperature,
/// lumped cabin temperature at previous simulation time step
// TODO: make sure this gets updated
pub temp_prev: si::Temperature,
Expand Down
2 changes: 1 addition & 1 deletion fastsim-core/src/vehicle/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Powertrain for Box<ConventionalVehicle> {
&mut self,
te_amb: si::Temperature,
pwr_thrl_fc_to_cab: si::Power,
veh_state: VehicleState,
veh_state: &mut VehicleState,
dt: si::Time,
) -> anyhow::Result<()> {
self.fc
Expand Down
2 changes: 1 addition & 1 deletion fastsim-core/src/vehicle/hev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Powertrain for Box<HybridElectricVehicle> {
&mut self,
te_amb: si::Temperature,
pwr_thrl_fc_to_cab: si::Power,
veh_state: VehicleState,
veh_state: &mut VehicleState,
dt: si::Time,
) -> anyhow::Result<()> {
self.fc
Expand Down
Loading

0 comments on commit 95a2d03

Please sign in to comment.