Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 45 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ indexmap = "2.9.0"
human-panic = "2.0.2"
clap-markdown = "0.1.5"
platform-info = "2.0.5"
derive_more = "0.99"

[dev-dependencies]
regex = "1.11.1"
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ pub mod commodity;
pub mod id;
pub mod input;
pub mod log;
pub mod metrics;
pub mod model;
pub mod output;
pub mod process;
pub mod region;
pub mod settings;
pub mod simulation;
pub mod time_slice;
pub mod units;
pub mod year;

#[cfg(test)]
Expand Down
65 changes: 65 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#![allow(missing_docs)]

use crate::units::*;

/// Calculates the capital recovery factor (CRF) for a given lifetime and discount rate.
///
/// The CRF is used to annualize capital costs over the lifetime of an asset.
pub fn capital_recovery_factor(lifetime: IYear, discount_rate: Dimensionless) -> Dimensionless {
if lifetime == IYear(0) {
return Dimensionless(0.0);
}
if discount_rate == Dimensionless(0.0) {
return Dimensionless(1.0 / lifetime.0 as f64);
}
let factor = (Dimensionless(1.0) + discount_rate).powi(lifetime.0 as i32);
(discount_rate * factor) / (factor - Dimensionless(1.0))
}

/// Calculates the annual capital cost for a technology
pub fn annual_capital_cost(
capital_cost: MoneyPerCapacity,
capacity: Capacity,
lifetime: IYear,
discount_rate: Dimensionless,
) -> MoneyPerYear {
let crf = capital_recovery_factor(lifetime, discount_rate);
let total_capital_cost = capital_cost * capacity * crf;
let annual_capital_cost = total_capital_cost * crf;
MoneyPerYear(annual_capital_cost.0) // this is an annualized quantity, so we return it as such
}

/// Calculates the annual fixed operating cost for a technology
pub fn annual_fixed_operating_cost(
fixed_operating_cost: MoneyPerCapacityPerYear,
capacity: Capacity,
) -> MoneyPerYear {
fixed_operating_cost * capacity
}

/// Calculates the annual fixed costs for a technology
///
/// This is the sum of the annual capital cost and the annual fixed operating cost.
pub fn annual_fixed_costs(
capital_cost: MoneyPerCapacity,
capacity: Capacity,
lifetime: IYear,
discount_rate: Dimensionless,
fixed_operating_cost: MoneyPerCapacityPerYear,
) -> MoneyPerYear {
let annual_capital_cost = annual_capital_cost(capital_cost, capacity, lifetime, discount_rate);
let annual_fixed_operating_cost = annual_fixed_operating_cost(fixed_operating_cost, capacity);
annual_capital_cost + annual_fixed_operating_cost
}

/// Calculates the annual variable cost for a technology
pub fn annual_variable_cost(
variable_operating_cost: MoneyPerActivity,
capacity: Capacity,
cap2act: ActivityPerCapacity,
utilization: Dimensionless,
) -> MoneyPerYear {
let capacity_a = capacity * cap2act;
let annual_variable_cost = variable_operating_cost * capacity_a * utilization;
MoneyPerYear(annual_variable_cost.0) // this is an annualized quantity, so we return it as such
}
Loading