Skip to content

Commit

Permalink
changed if let ... to match to make it more readable and more idi…
Browse files Browse the repository at this point in the history
…omatic
  • Loading branch information
calbaker committed Dec 6, 2024
1 parent 94b1eb6 commit 6aed9c7
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions rust/fastsim-core/src/thermal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,41 +910,35 @@ impl SimDriveHot {
if let FcModelTypes::Internal(fc_temp_eff_model, fc_temp_eff_comp) =
&self.vehthrm.fc_model
{
if let FcTempEffModel::Linear(FcTempEffModelLinear {
offset,
slope,
minimum,
}) = fc_temp_eff_model
{
self.state.fc_eta_temp_coeff =
max(*minimum, min(1.0, offset + slope * self.state.fc_te_deg_c));
}

if let FcTempEffModel::Exponential(FcTempEffModelExponential {
offset,
lag,
minimum,
}) = fc_temp_eff_model
{
match fc_temp_eff_comp {
FcTempEffComponent::FuelConverter => {
self.state.fc_eta_temp_coeff = (1.0
self.state.fc_eta_temp_coeff = match fc_temp_eff_model {
FcTempEffModel::Linear(FcTempEffModelLinear {
offset,
slope,
minimum,
}) => max(*minimum, min(1.0, offset + slope * self.state.fc_te_deg_c)),
FcTempEffModel::Exponential(FcTempEffModelExponential {
offset,
lag,
minimum,
}) => {
match fc_temp_eff_comp {
FcTempEffComponent::FuelConverter => (1.0
- f64::exp(-1.0 / lag * (self.state.fc_te_deg_c - offset)))
.max(*minimum);
}
FcTempEffComponent::CatAndFC => {
if self.state.cat_te_deg_c < self.vehthrm.cat_te_lightoff_deg_c {
self.state.fc_eta_temp_coeff = (1.0
- f64::exp(-1.0 / lag * (self.state.fc_te_deg_c - offset)))
.max(*minimum);
// reduce efficiency to account for catalyst not being lit off
self.state.fc_eta_temp_coeff *= self.vehthrm.cat_fc_eta_coeff;
.max(*minimum),
FcTempEffComponent::CatAndFC => {
if self.state.cat_te_deg_c < self.vehthrm.cat_te_lightoff_deg_c {
let fc_eta_temp_coeff = (1.0
- f64::exp(-1.0 / lag * (self.state.fc_te_deg_c - offset)))
.max(*minimum);
// reduce efficiency to account for catalyst not being lit off
fc_eta_temp_coeff * self.vehthrm.cat_fc_eta_coeff
} else {
1.0
}
}
}
FcTempEffComponent::Catalyst => {
self.state.fc_eta_temp_coeff = (1.0
FcTempEffComponent::Catalyst => (1.0
- f64::exp(-1.0 / lag * (self.state.cat_te_deg_c - offset)))
.max(*minimum);
.max(*minimum),
}
}
}
Expand Down

0 comments on commit 6aed9c7

Please sign in to comment.