Skip to content

Commit

Permalink
thermostat is behaving correctly for cool ambient -- need to confirm hot
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Jan 22, 2025
1 parent 74487fb commit 4db7122
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
40 changes: 20 additions & 20 deletions fastsim-core/src/gas_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,18 @@ mod air_static_props {
.iter()
.map(|x| *x * uc::KELVIN + *uc::CELSIUS_TO_KELVIN)
.collect();
pub static ref TEMP_FROM_ENTHALPY: Interp1D = Interp1D::new(
pub static ref TEMP_FROM_ENTHALPY: Interpolator = Interpolator::Interp1D(Interp1D::new(
ENTHALPY_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram>()).collect::<Vec<f64>>(),
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
pub static ref TEMP_FROM_ENERGY: Interp1D = Interp1D::new(
).unwrap());
pub static ref TEMP_FROM_ENERGY: Interpolator= Interpolator::Interp1D(Interp1D::new(
ENERGY_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram>()).collect::<Vec<f64>>(),
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
/// Thermal conductivity values of air corresponding to temperature values
static ref THERMAL_CONDUCTIVITY_VALUES: Vec<si::ThermalConductivity> = [
0.019597,
Expand Down Expand Up @@ -316,12 +316,12 @@ mod air_static_props {
.iter()
.map(|x| *x * uc::WATT_PER_METER_KELVIN)
.collect();
pub static ref THERMAL_CONDUCTIVITY_INTERP: Interp1D = Interp1D::new(
pub static ref THERMAL_CONDUCTIVITY_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
THERMAL_CONDUCTIVITY_VALUES.iter().map(|x| x.get::<si::watt_per_meter_degree_celsius>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
/// Specific heat values of air corresponding to temperature values
static ref C_P_VALUES: Vec<si::SpecificHeatCapacity> = [
1006.2,
Expand Down Expand Up @@ -353,12 +353,12 @@ mod air_static_props {
.iter()
.map(|x| *x * uc::J_PER_KG_K)
.collect();
pub static ref C_P_INTERP: Interp1D = Interp1D::new(
pub static ref C_P_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
C_P_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram_kelvin>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
static ref ENTHALPY_VALUES: Vec<si::SpecificEnergy> = [
338940.,
341930.,
Expand Down Expand Up @@ -389,12 +389,12 @@ mod air_static_props {
.iter()
.map(|x| *x * uc::J_PER_KG)
.collect();
pub static ref ENTHALPY_INTERP: Interp1D = Interp1D::new(
pub static ref ENTHALPY_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
ENTHALPY_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
pub static ref ENERGY_VALUES: Vec<si::SpecificEnergy> = [
277880.,
280000.,
Expand Down Expand Up @@ -425,12 +425,12 @@ mod air_static_props {
.iter()
.map(|x| *x * uc::J_PER_KG)
.collect();
pub static ref ENERGY_INTERP: Interp1D = Interp1D::new(
pub static ref ENERGY_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
ENERGY_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
static ref DYN_VISCOSITY_VALUES: Vec<si::DynamicViscosity> = [
1.4067e-05,
1.4230e-05,
Expand Down Expand Up @@ -461,24 +461,24 @@ mod air_static_props {
.iter()
.map(|x| *x * uc::PASCAL_SECOND)
.collect();
pub static ref DYN_VISC_INTERP: Interp1D = Interp1D::new(
pub static ref DYN_VISC_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
DYN_VISCOSITY_VALUES.iter().map(|x| x.get::<si::pascal_second>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
static ref PRANDTL_VALUES: Vec<si::Ratio> = DYN_VISCOSITY_VALUES
.iter()
.zip(C_P_VALUES.iter())
.zip(THERMAL_CONDUCTIVITY_VALUES.iter())
.map(|((mu, c_p), k)| -> si::Ratio {*mu * *c_p / *k})
.collect::<Vec<si::Ratio>>();
pub static ref PRANDTL_INTERP: Interp1D = Interp1D::new(
pub static ref PRANDTL_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
PRANDTL_VALUES.iter().map(|x| x.get::<si::ratio>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
}
}

Expand Down Expand Up @@ -551,12 +551,12 @@ mod octane_static_props {
.iter()
.map(|x| *x * uc::KELVIN + *uc::CELSIUS_TO_KELVIN)
.collect();
pub static ref TEMP_FROM_ENERGY: Interp1D = Interp1D::new(
pub static ref TEMP_FROM_ENERGY: Interpolator = Interpolator::Interp1D(Interp1D::new(
ENERGY_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram>()).collect::<Vec<f64>>(),
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
pub static ref ENERGY_VALUES: Vec<si::SpecificEnergy> = [
-3.8247e+05,
-3.7645e+05,
Expand Down Expand Up @@ -587,12 +587,12 @@ mod octane_static_props {
.iter()
.map(|x| *x * uc::J_PER_KG)
.collect();
pub static ref ENERGY_INTERP: Interp1D = Interp1D::new(
pub static ref ENERGY_INTERP: Interpolator = Interpolator::Interp1D(Interp1D::new(
TEMPERATURE_VALUES.iter().map(|x| x.get::<si::kelvin>()).collect::<Vec<f64>>(),
ENERGY_VALUES.iter().map(|x| x.get::<si::joule_per_kilogram>()).collect::<Vec<f64>>(),
Strategy::Linear,
Extrapolate::Error
).unwrap();
).unwrap());
}
}

Expand Down
42 changes: 23 additions & 19 deletions fastsim-core/src/vehicle/powertrain/fuel_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,17 @@ pub struct FuelConverterThermal {
}

/// Dummy interpolator that will be overridden in [FuelConverterThermal::init]
fn tstat_interp_default() -> Interp1D {
Interp1D::new(
vec![85.0, 90.0],
vec![0.0, 1.0],
Strategy::Linear,
Extrapolate::Clamp,
fn tstat_interp_default() -> Interpolator {
Interpolator::Interp1D(
Interp1D::new(
vec![85.0, 90.0],
vec![0.0, 1.0],
Strategy::Linear,
Extrapolate::Clamp,
)
.with_context(|| format_dbg!())
.unwrap(),
)
.with_context(|| format_dbg!())
.unwrap()
}

lazy_static! {
Expand Down Expand Up @@ -690,17 +692,19 @@ impl Init for FuelConverterThermal {
.tstat_te_sto
.or(Some(85. * uc::KELVIN + *uc::CELSIUS_TO_KELVIN));
self.tstat_te_delta = self.tstat_te_delta.or(Some(5. * uc::KELVIN));
self.tstat_interp = Interp1D::new(
vec![
self.tstat_te_sto.unwrap().get::<si::kelvin>(),
self.tstat_te_sto.unwrap().get::<si::kelvin>()
+ self.tstat_te_delta.unwrap().get::<si::kelvin>(),
],
vec![0.0, 1.0],
Strategy::Linear,
Extrapolate::Clamp,
)
.with_context(|| format_dbg!())?;
self.tstat_interp = Interpolator::Interp1D(
Interp1D::new(
vec![
self.tstat_te_sto.unwrap().get::<si::kelvin>(),
self.tstat_te_sto.unwrap().get::<si::kelvin>()
+ self.tstat_te_delta.unwrap().get::<si::kelvin>(),
],
vec![0.0, 1.0],
Strategy::Linear,
Extrapolate::Clamp,
)
.with_context(|| format_dbg!())?,
);
Ok(())
}
}
Expand Down

0 comments on commit 4db7122

Please sign in to comment.