Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/simple/process_parameters.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
process_id,start_year,end_year,capital_cost,fixed_operating_cost,variable_operating_cost,lifetime,discount_rate,capacity_to_activity
GASDRV,2020,2030,10.0,0.3,2.0,25,0.1,1.0
GASPRC,2020,2030,7.0,0.21,0.5,25,0.1,1.0
WNDFRM,2020,2030,1000.0,30.0,0.4,25,0.1,31.54
GASCGT,2020,2030,700.0,21.0,0.55,30,0.1,31.54
RGASBR,2020,2030,55.56,1.6668,0.16,15,0.1,1.0
RELCHP,2020,2030,138.9,4.167,0.17,15,0.1,1.0
process_id,year,capital_cost,fixed_operating_cost,variable_operating_cost,lifetime,discount_rate,capacity_to_activity
GASDRV,all,10.0,0.3,2.0,25,0.1,1.0
GASPRC,all,7.0,0.21,0.5,25,0.1,1.0
WNDFRM,all,1000.0,30.0,0.4,25,0.1,31.54
GASCGT,all,700.0,21.0,0.55,30,0.1,31.54
RGASBR,all,55.56,1.6668,0.16,15,0.1,1.0
RELCHP,all,138.9,4.167,0.17,15,0.1,1.0
14 changes: 7 additions & 7 deletions examples/simple/processes.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id,description
GASDRV,Dry gas extraction
GASPRC,Gas processing
WNDFRM,Wind farm
GASCGT,Gas combined cycle turbine
RGASBR,Gas boiler
RELCHP,Heat pump
id,description,start_year,end_year
GASDRV,Dry gas extraction,2020,2030
GASPRC,Gas processing,2020,2030
WNDFRM,Wind farm,2020,2030
GASCGT,Gas combined cycle turbine,2020,2030
RGASBR,Gas boiler,2020,2030
RELCHP,Heat pump,2020,2030
39 changes: 32 additions & 7 deletions src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ impl Asset {

/// The last year in which this asset should be decommissioned
pub fn decommission_year(&self) -> u32 {
self.commission_year + self.process.parameter.lifetime
self.commission_year
+ self
.process
.parameters
.get(&self.commission_year)
.unwrap()
.lifetime
}

/// Get the energy limits for this asset in a particular time slice
Expand All @@ -74,7 +80,13 @@ impl Asset {

/// Maximum activity for this asset (PAC energy produced/consumed per year)
pub fn maximum_activity(&self) -> f64 {
self.capacity * self.process.parameter.capacity_to_activity
self.capacity
* self
.process
.parameters
.get(&self.commission_year)
.unwrap()
.capacity_to_activity
}
}

Expand Down Expand Up @@ -188,11 +200,14 @@ impl AssetPool {
mod tests {
use super::*;
use crate::commodity::{CommodityCostMap, CommodityType, DemandMap};
use crate::process::{EnergyLimitsMap, FlowType, Process, ProcessFlow, ProcessParameter};
use crate::process::{
EnergyLimitsMap, FlowType, Process, ProcessFlow, ProcessParameter, ProcessParameterMap,
};
use crate::region::RegionSelection;
use crate::time_slice::TimeSliceLevel;
use itertools::{assert_equal, Itertools};
use std::iter;
use std::ops::RangeInclusive;

#[test]
fn test_asset_get_energy_limits() {
Expand All @@ -201,14 +216,18 @@ mod tests {
time_of_day: "day".into(),
};
let process_param = ProcessParameter {
years: 2010..=2020,
capital_cost: 5.0,
fixed_operating_cost: 2.0,
variable_operating_cost: 1.0,
lifetime: 5,
discount_rate: 0.9,
capacity_to_activity: 3.0,
};
let years = RangeInclusive::new(2010, 2020).collect_vec();
let process_parameter_map: ProcessParameterMap = years
.iter()
.map(|&year| (year, process_param.clone()))
.collect();
let commodity = Rc::new(Commodity {
id: "commodity1".into(),
description: "Some description".into(),
Expand All @@ -230,9 +249,10 @@ mod tests {
let process = Rc::new(Process {
id: "process1".into(),
description: "Description".into(),
years: 2010..=2020,
energy_limits,
flows: vec![flow.clone()],
parameter: process_param.clone(),
parameters: process_parameter_map,
regions: RegionSelection::All,
});
let asset = Asset {
Expand All @@ -249,20 +269,25 @@ mod tests {

fn create_asset_pool() -> AssetPool {
let process_param = ProcessParameter {
years: 2010..=2020,
capital_cost: 5.0,
fixed_operating_cost: 2.0,
variable_operating_cost: 1.0,
lifetime: 5,
discount_rate: 0.9,
capacity_to_activity: 1.0,
};
let years = RangeInclusive::new(2010, 2020).collect_vec();
let process_parameter_map: ProcessParameterMap = years
.iter()
.map(|&year| (year, process_param.clone()))
.collect();
let process = Rc::new(Process {
id: "process1".into(),
description: "Description".into(),
years: 2010..=2020,
energy_limits: EnergyLimitsMap::new(),
flows: vec![],
parameter: process_param.clone(),
parameters: process_parameter_map,
regions: RegionSelection::All,
});
let future = [2020, 2010]
Expand Down
17 changes: 16 additions & 1 deletion src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use float_cmp::approx_eq;
use indexmap::IndexMap;
use itertools::Itertools;
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::hash::Hash;
use std::path::Path;

mod agent;
Expand Down Expand Up @@ -137,6 +138,20 @@ where
Ok(())
}

/// Inserts a key-value pair into a HashMap if the key does not already exist.
///
/// If the key already exists, it returns an error with a message indicating the key's existence.
pub fn try_insert<K, V>(map: &mut HashMap<K, V>, key: K, value: V) -> Result<()>
where
K: Eq + Hash + Clone + std::fmt::Display,
{
let existing = map.insert(key.clone(), value);
match existing {
Some(_) => bail!("Key {} already exists in the map", key),
None => Ok(()),
}
}

/// Read a model from the specified directory.
///
/// # Arguments
Expand Down
17 changes: 5 additions & 12 deletions src/input/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,20 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::process::{EnergyLimitsMap, Process, ProcessParameter};
use crate::process::{EnergyLimitsMap, Process, ProcessParameterMap};
use crate::region::RegionSelection;
use itertools::assert_equal;
use std::iter;

#[test]
fn test_read_assets_from_iter() {
let process_param = ProcessParameter {
years: 2010..=2020,
capital_cost: 5.0,
fixed_operating_cost: 2.0,
variable_operating_cost: 1.0,
lifetime: 5,
discount_rate: 0.9,
capacity_to_activity: 1.0,
};
let process = Rc::new(Process {
id: "process1".into(),
description: "Description".into(),
years: 2010..=2020,
energy_limits: EnergyLimitsMap::new(),
flows: vec![],
parameter: process_param.clone(),
parameters: ProcessParameterMap::new(),
regions: RegionSelection::All,
});
let processes = [(process.id.clone(), Rc::clone(&process))]
Expand Down Expand Up @@ -189,9 +181,10 @@ mod tests {
let process = Rc::new(Process {
id: "process1".into(),
description: "Description".into(),
years: 2010..=2020,
energy_limits: EnergyLimitsMap::new(),
flows: vec![],
parameter: process_param,
parameters: ProcessParameterMap::new(),
regions: RegionSelection::Some(["GBR".into()].into_iter().collect()),
});
let asset_in = AssetRaw {
Expand Down
Loading