Skip to content

Commit e996669

Browse files
authored
Merge pull request #1145 from EnergySystemsModellingLab/unit_types_default
Remove `Default` implementation for unit types
2 parents e4b1990 + aba97e1 commit e996669

7 files changed

Lines changed: 23 additions & 14 deletions

File tree

src/asset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ impl Asset {
650650
flow.coeff
651651
* prices
652652
.get(&flow.commodity.id, &self.region_id, time_slice)
653-
.unwrap_or_default()
653+
.unwrap_or(MoneyPerFlow(0.0))
654654
})
655655
.sum()
656656
}

src/input/asset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::rc::Rc;
1717

1818
const ASSETS_FILE_NAME: &str = "assets.csv";
1919

20-
#[derive(Default, Deserialize, PartialEq)]
20+
#[derive(Deserialize, PartialEq)]
2121
struct AssetRaw {
2222
process_id: String,
2323
region_id: String,

src/simulation/investment/appraisal.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ mod tests {
363363
use crate::fixture::{agent_id, asset, process, region_id};
364364
use crate::process::Process;
365365
use crate::region::RegionID;
366-
use crate::units::{Money, MoneyPerActivity};
366+
use crate::units::{Money, MoneyPerActivity, MoneyPerFlow};
367367
use float_cmp::assert_approx_eq;
368368
use rstest::rstest;
369369
use std::rc::Rc;
@@ -551,7 +551,11 @@ mod tests {
551551
.map(|(asset, metric)| AppraisalOutput {
552552
asset: AssetRef::from(asset),
553553
capacity: AssetCapacity::Continuous(Capacity(10.0)),
554-
coefficients: ObjectiveCoefficients::default(),
554+
coefficients: ObjectiveCoefficients {
555+
capacity_coefficient: MoneyPerCapacity(0.0),
556+
activity_coefficients: IndexMap::new(),
557+
unmet_demand_coefficient: MoneyPerFlow(0.0),
558+
},
555559
activity: IndexMap::new(),
556560
demand: IndexMap::new(),
557561
unmet_demand: IndexMap::new(),
@@ -877,7 +881,11 @@ mod tests {
877881
.map(|metric| AppraisalOutput {
878882
asset: AssetRef::from(asset.clone()),
879883
capacity: AssetCapacity::Continuous(Capacity(0.0)),
880-
coefficients: ObjectiveCoefficients::default(),
884+
coefficients: ObjectiveCoefficients {
885+
capacity_coefficient: MoneyPerCapacity(0.0),
886+
activity_coefficients: IndexMap::new(),
887+
unmet_demand_coefficient: MoneyPerFlow(0.0),
888+
},
881889
activity: IndexMap::new(),
882890
demand: IndexMap::new(),
883891
unmet_demand: IndexMap::new(),

src/simulation/investment/appraisal/coefficients.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::collections::HashMap;
1515
/// the investment appraisal routines. The map contains the per-capacity and per-activity cost
1616
/// coefficients used in the appraisal optimisation, together with the unmet-demand penalty.
1717
#[derive(Clone)]
18-
#[cfg_attr(test, derive(Default))]
1918
pub struct ObjectiveCoefficients {
2019
/// Cost per unit of capacity
2120
pub capacity_coefficient: MoneyPerCapacity,

src/simulation/optimisation.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,11 @@ fn calculate_activity_coefficient(
795795
input_prices: Option<&CommodityPrices>,
796796
) -> MoneyPerActivity {
797797
let opex = asset.get_operating_cost(year, time_slice);
798-
let input_cost = input_prices
799-
.map(|prices| asset.get_input_cost_from_prices(prices, time_slice))
800-
.unwrap_or_default();
801-
opex + input_cost
798+
if let Some(prices) = input_prices {
799+
opex + asset.get_input_cost_from_prices(prices, time_slice)
800+
} else {
801+
opex
802+
}
802803
}
803804

804805
/// Calculate the cost coefficient for a capacity variable (for flexible capacity assets only).

src/simulation/prices.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ impl CommodityPrices {
180180
// NB: Time slice fractions will sum to one
181181
let weight = time_slice_info.time_slices[time_slice_id] / Year(1.0);
182182
let key = (commodity_id.clone(), region_id.clone());
183-
*weighted_prices.entry(key).or_default() += *price * weight;
183+
weighted_prices
184+
.entry(key)
185+
.and_modify(|v| *v += *price * weight)
186+
.or_insert_with(|| *price * weight);
184187
}
185188

186189
weighted_prices
@@ -352,7 +355,7 @@ where
352355
///
353356
/// Note: this should be similar to the "shadow price" strategy, which is also based on marginal
354357
/// costs of the most expensive producer, but may be more successful in cases where there are
355-
// multiple SED/SVD outputs per asset.
358+
/// multiple SED/SVD outputs per asset.
356359
///
357360
/// # Arguments
358361
///

src/units.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub trait UnitType:
2222
+ Sum
2323
+ ApproxEq<Margin = F64Margin>
2424
+ fmt::Display
25-
+ Default
2625
{
2726
/// Create from an f64 value
2827
fn new(value: f64) -> Self;
@@ -51,7 +50,6 @@ macro_rules! base_unit_struct {
5150
Copy,
5251
PartialEq,
5352
PartialOrd,
54-
Default,
5553
Serialize,
5654
derive_more::Add,
5755
derive_more::Sub,

0 commit comments

Comments
 (0)