Skip to content

Commit

Permalink
Updated restrictions in types and functions (#9)
Browse files Browse the repository at this point in the history
* Updated restrictions in types and functions
* Uniform argument indents for function calls
  • Loading branch information
JulStraus authored Feb 1, 2024
1 parent 9e92fd2 commit 4ac7fa6
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 178 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release notes

Version 0.6.5 (2024-01-31)
--------------------------
* Updated the restrictions on the fields of individual types to be consistent.

Version 0.6.4 (2024-01-18)
--------------------------
* Minor modification to the `EmissionsData` allowing now also time dependent process emissions. This is achieved through switching to a parametric type.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EnergyModelsBase"
uuid = "5d7e687e-f956-46f3-9045-6f5a5fd49f50"
authors = ["Lars Hellemo <[email protected]>, Julian Straus <[email protected]>"]
version = "0.6.4"
version = "0.6.5"

[deps]
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# EnergyModelsBase

[![Build Status](https://github.com/EnergyModelsX/EnergyModelsBase.jl/workflows/CI/badge.svg)](https://github.com/EnergyModelsX/EnergyModelsBase.jl/actions?query=workflow%3ACI)
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://energymodelsx.github.io/EnergyModelsBase.jl//stable)
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://energymodelsx.github.io/EnergyModelsBase.jl/stable/)
[![In Development](https://img.shields.io/badge/docs-dev-blue.svg)](https://energymodelsx.github.io/EnergyModelsBase.jl/dev/)

`EnergyModelsBase` is the core package for building flexible multi-energy-carrier energy systems models.
Expand Down
3 changes: 0 additions & 3 deletions examples/network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ function generate_data()
FixedProfile(30), # Variable OPEX in EUR/MW
FixedProfile(0), # Fixed OPEX in EUR/8h
Dict(NG => 1), # Output from the Node, in this gase, NG
[], # Potential additional data
),
RefSource(
3, # Node id
FixedProfile(1e12), # Capacity in MW
FixedProfile(9), # Variable OPEX in EUR/MWh
FixedProfile(0), # Fixed OPEX in EUR/8h
Dict(Coal => 1), # Output from the Node, in this gase, coal
[], # Potential additional data
),
RefNetworkNode(
4, # Node id
Expand Down Expand Up @@ -103,7 +101,6 @@ function generate_data()
# Line above: This implies that storing CO₂ requires Power
Dict(CO2 => 1), # Output from the node with output ratio
# In practice, for CO₂ storage, this is never used.
Array{Data}([]), # Potential additional data
),
RefSink(
7, # Node id
Expand Down
1 change: 0 additions & 1 deletion examples/sink_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function generate_data()
FixedProfile(30), # Variable OPEX in EUR/MW
FixedProfile(0), # Fixed OPEX in EUR/8h
Dict(Power => 1), # Output from the Node, in this gase, Power
[], # Potential additional data
),
RefSink(
2, # Node id
Expand Down
8 changes: 4 additions & 4 deletions src/constraint_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function constraints_level_sp(
t_inv::TS.StrategicPeriod{T, U},
𝒫,
modeltype::EnergyModel
) where {S<:ResourceCarrier, T, U<:SimpleTimes}
) where {S<:ResourceCarrier, T, U<:SimpleTimes}

# Mass/energy balance constraints for stored energy carrier.
for (t_prev, t) withprev(t_inv)
Expand Down Expand Up @@ -252,7 +252,7 @@ function constraints_level_sp(
t_inv::TS.StrategicPeriod{T, RepresentativePeriods{U, T, SimpleTimes{T}}},
𝒫,
modeltype::EnergyModel
) where {S<:ResourceCarrier, T, U}
) where {S<:ResourceCarrier, T, U}

# Declaration of the required subsets
𝒯ʳᵖ = repr_periods(t_inv)
Expand Down Expand Up @@ -350,7 +350,7 @@ function constraints_level_sp(
t_inv::TS.StrategicPeriod{T, U},
𝒫,
modeltype::EnergyModel
) where {S<:ResourceEmit, T, U<:SimpleTimes}
) where {S<:ResourceEmit, T, U<:SimpleTimes}

# Mass/energy balance constraints for stored energy carrier.
for (t_prev, t) withprev(t_inv)
Expand Down Expand Up @@ -388,7 +388,7 @@ function constraints_level_sp(
t_inv::TS.StrategicPeriod{T, RepresentativePeriods{U, T, SimpleTimes{T}}},
𝒫,
modeltype::EnergyModel
) where {S<:ResourceEmit, T, U}
) where {S<:ResourceEmit, T, U}

# Declaration of the required subsets
𝒯ʳᵖ = repr_periods(t_inv)
Expand Down
2 changes: 1 addition & 1 deletion src/data_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ process.
There exist several configurations:
- **`EmissionsEnergy`**: Only energy usage related emissions.\n
- **`EmissionsProcess`**: Both process and energy usage related emissions.\n
- **`CaptureEnergyEmissions`**: Capture of energy usage related emissions, can include
- **`CaptureEnergyEmissions`**: Capture of energy usage related emissions, can include \
process emissions.\n
- **`CaptureProcessEmissions`**: Capture of process emissions.\n
- **`CaptureProcessEnergyEmissions`**: Capture of both process and energy usage related
Expand Down
24 changes: 12 additions & 12 deletions src/legacy_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function RefSource(
opex_var::TimeProfile,
opex_fixed::TimeProfile,
output::Dict{<:Resource,<:Real},
data::Array,
data::Vector,
emissions::Dict{<:ResourceEmit,<:Real},
)
)

@warn("This implementation of a `RefSource` will be discontinued in the near future. \
See the documentation for the new implementation using the `data` field.
Expand All @@ -36,8 +36,8 @@ function RefNetwork(
opex_fixed::TimeProfile,
input::Dict{<:Resource,<:Real},
output::Dict{<:Resource,<:Real},
data::Array,
)
data::Vector,
)

@warn("The implementation of a `RefNetwork` will be discontinued in \
the near future. The name is replaced by RefNetworkNode, while the fields remain \
Expand All @@ -63,8 +63,8 @@ function RefNetworkEmissions(
output::Dict{<:Resource,<:Real},
emissions::Dict{<:ResourceEmit,<:Real},
co2_capture::Real,
data::Array,
)
data::Vector,
)

@warn("The implementation of a `RefNetworkEmissions` will be discontinued in \
the near future. See the documentation for the new implementation using the `data` \
Expand Down Expand Up @@ -93,8 +93,8 @@ function RefStorageEmissions(
stor_res::ResourceEmit,
input::Dict{<:Resource,<:Real},
output::Dict{<:Resource,<:Real},
data::Array,
)
data::Vector,
)

@warn("The implementation of a `RefStorageEmissions` will be discontinued in \
the near future. See the documentation for the new implementation using a parametric \
Expand All @@ -111,7 +111,7 @@ function RefStorageEmissions(
stor_res,
input,
output,
Array{Data}(data),
Vector{Data}(data),
)
return tmp
end
Expand All @@ -126,7 +126,7 @@ function GenAvailability(
id,
input::Dict{<:Resource,<:Real},
output::Dict{<:Resource,<:Real},
)
)

@warn("This implementation of a `GenAvailability` will be discontinued in \
the near future. See the documentation for the new implementation not requiring using \
Expand All @@ -148,7 +148,7 @@ function RefSink(
penalty::Dict{<:Any,<:TimeProfile},
input::Dict{<:Resource,<:Real},
emissions::Dict{<:ResourceEmit,<:Real},
)
)

@warn("This implementation of a `RefSink` will be discontinued in the near future. \
See the documentation for the new implementation using the `data` field. \
Expand All @@ -171,7 +171,7 @@ price.
function OperationalModel(
emission_limit::Dict{<:ResourceEmit, <:TimeProfile},
co2_instance::ResourceEmit,
)
)

@warn("this implementation of `OperationalModel` will be discontinued in the near \
future. See the documentation for the new implementation with the additional field:
Expand Down
14 changes: 7 additions & 7 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ resource `𝒫ᵉᵐ ∈ 𝒫`.
The emission variables are differentiated in:
* `:emissions_node` - emissions of a node in an operational period,
* `:emissions_total` - total emissions in an operational period, and
* `:emissions_strategic` - total strategic emissions, constrained to an upper limit based\
on the field `emission_limit` of the `EnergyModel`.
* `:emissions_strategic` - total strategic emissions, constrained to an upper limit \
based on the field `emission_limit` of the `EnergyModel`.
"""
function variables_emission(m, 𝒩, 𝒯, 𝒫, modeltype::EnergyModel)

Expand All @@ -124,7 +124,7 @@ end
"""
variables_opex(m, 𝒩, 𝒯, 𝒫, modeltype::EnergyModel)
Declaration of the OPEX variables (`:opex_var` and `:opex_fixed`) of the model for each investment
Declaration of the OPEX variables (`:opex_var` and `:opex_fixed`) of the model for each
period `𝒯ᴵⁿᵛ ∈ 𝒯`. Variable OPEX can be non negative to account for revenue streams.
"""
function variables_opex(m, 𝒩, 𝒯, 𝒫, modeltype::EnergyModel)
Expand Down Expand Up @@ -413,8 +413,8 @@ Set all constraints for a `Availability`. Can serve as fallback option for all u
subtypes of `Availability`.
Availability nodes can be seen as routing nodes. It is not necessary to have more than one
available node except if one wants to include as well transport between different availability
nodes with associated costs (not implemented at the moment).
available node except if one wants to include as well transport between different
`Availability` nodes with associated costs (not implemented at the moment).
"""
function create_node(m, n::Availability, 𝒯, 𝒫, modeltype::EnergyModel)

Expand All @@ -426,8 +426,8 @@ end
"""
create_link(m, 𝒯, 𝒫, l, formulation::Formulation)
Set the constraints for a simple `Link` (input = output). Can serve as fallback option for all
unspecified subtypes of `Link`.
Set the constraints for a simple `Link` (input = output). Can serve as fallback option for
all unspecified subtypes of `Link`.
"""
function create_link(m, 𝒯, 𝒫, l, formulation::Formulation)

Expand Down
32 changes: 16 additions & 16 deletions src/structures_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ an input as `TimeProfile` or `Float64`.\n
- **`co2_capture::Float64`**: CO₂ capture rate.\n
# Types
- **`CaptureProcessEnergyEmissions`**: Capture both the process emissions and the energy usage \
related emissions.\n
- **`CaptureProcessEmissions`**: Capture the process emissions, but not the energy usage related \
emissions.\n
- **`CaptureEnergyEmissions`**: Capture the energy usage related emissions, but not the process \
emissions. Does not require `emissions` as input.\n
- **`EmissionsProcess`**: No capture, but process emissions are present. Does not require \
`co2_capture` as input, but will ignore it, if provided.\n
- **`CaptureProcessEnergyEmissions`**: Capture both the process emissions and the \
energy usage related emissions.\n
- **`CaptureProcessEmissions`**: Capture the process emissions, but not the \
energy usage related emissions.\n
- **`CaptureEnergyEmissions`**: Capture the energy usage related emissions, but not the \
process emissions. Does not require `emissions` as input.\n
- **`EmissionsProcess`**: No capture, but process emissions are present. \
Does not require `co2_capture` as input, but will ignore it, if provided.\n
- **`EmissionsEnergy`**: No capture and no process emissions. Does not require \
`co2_capture` or `emissions` as input, but will ignore them, if provided.\n
"""
Expand Down Expand Up @@ -108,28 +108,28 @@ Returns the `ResourceEmit`s that have process emissions in the `data`.
process_emissions(data::EmissionsData) = collect(keys(data.emissions))

"""
process_emissions(data::EmissionsData, p)
process_emissions(data::EmissionsData{T}, p::ResourceEmit)
Returns the the process emissions of resource `p` in the `data` as `TimeProfile`.
If the process emissions are provided as `Float64`, it returns a FixedProfile(x).
If there are no process emissions, it returns a FixedProfile(0).
"""
process_emissions(data::EmissionsData{T}, p) where {T<:Float64} =
process_emissions(data::EmissionsData{T}, p::ResourceEmit) where {T<:Float64} =
haskey(data.emissions, p) ? FixedProfile(data.emissions[p]) : FixedProfile(0)
process_emissions(data::EmissionsData{T}, p) where {T<:TimeProfile} =
process_emissions(data::EmissionsData{T}, p::ResourceEmit) where {T<:TimeProfile} =
haskey(data.emissions, p) ? data.emissions[p] : FixedProfile(0)
process_emissions(data::EmissionsEnergy{T}, p) where {T} =
process_emissions(data::EmissionsEnergy{T}, p::ResourceEmit) where {T} =
@error("The type `EmissionsEnergy` should not be used in combination with calling \
the function `process_emissions`.")

"""
process_emissions(data::EmissionsData, p, t)
process_emissions(data::EmissionsData{T}, p:ResourceEmit, t)
Returns the the process emissions of resource `p` in the `data` at operational period t.
If there are no process emissions, it returns a value of 0.
"""
process_emissions(data::EmissionsData{T}, p, t) where {T<:Float64} =
process_emissions(data::EmissionsData{T}, p::ResourceEmit, t) where {T<:Float64} =
haskey(data.emissions, p) ? data.emissions[p] : 0
process_emissions(data::EmissionsData{T}, p, t) where {T<:TimeProfile} =
process_emissions(data::EmissionsData{T}, p::ResourceEmit, t) where {T<:TimeProfile} =
haskey(data.emissions, p) ? data.emissions[p][t] : 0
process_emissions(data::EmissionsEnergy{T}, p, t) where {T} =
process_emissions(data::EmissionsEnergy{T}, p::ResourceEmit, t) where {T} =
@error("The type `EmissionsEnergy` should not be used in combination with calling \
the function `process_emissions`.")
4 changes: 2 additions & 2 deletions src/structures_link.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Direct(id, from::Node, to::Node) = Direct(id, from, to, Linear())


"""
link_sub(ℒ, n::Node)
link_sub(ℒ::Vector{<:Link}, n::Node)
Return connected links for a given node `n`.
"""
function link_sub(ℒ, n::Node)
function link_sub(ℒ::Vector{<:Link}, n::Node)
return [ℒ[findall(x -> x.from == n, ℒ)],
ℒ[findall(x -> x.to == n, ℒ)]]
end
Expand Down
51 changes: 27 additions & 24 deletions src/structures_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,68 @@ abstract type EnergyModel end
Operational Energy Model without investments.
# Fields
- **`emission_limit`** is a dictionary with individual emission limits as `TimeProfile` for \
each emission resource `ResourceEmit`.\n
- **`emission_price::Dict{ResourceEmit, TimeProfile}`** are the prices for the different \
emissions types considered.\n
- **`emission_limit::Dict{<:ResourceEmit, <:TimeProfile}`** is a dictionary with \
individual emission limits as `TimeProfile` for each emission resource `ResourceEmit`.\n
- **`emission_price::Dict{<:ResourceEmit, <:TimeProfile}`** are the prices for the \
different emissions types considered.\n
- **`co2_instance`** is a `ResourceEmit` and corresponds to the type used for CO₂.\n
"""
struct OperationalModel <: EnergyModel
emission_limit::Dict{ResourceEmit, TimeProfile}
emission_price::Dict{ResourceEmit, TimeProfile}
emission_limit::Dict{<:ResourceEmit, <:TimeProfile}
emission_price::Dict{<:ResourceEmit, <:TimeProfile}
co2_instance::ResourceEmit
end

"""
emission_limit(model)
emission_limit(model::EnergyModel)
Returns the emission limit of EnergyModel `model` as dictionary with `TimeProfile`s for
each `ResourceEmit`.
"""
emission_limit(model) = model.emission_limit
emission_limit(model::EnergyModel) = model.emission_limit
"""
emission_limit(model, p)
emission_limit(model::EnergyModel, p::ResourceEmit)
Returns the emission limit of EnergyModel `model` and ResourceEmit `p` as `TimeProfile`.
"""
emission_limit(model, p) = model.emission_limit[p]
emission_limit(model::EnergyModel, p::ResourceEmit) = model.emission_limit[p]
"""
emission_limit(model, p, t)
emission_limit(model::EnergyModel, p::ResourceEmit, t_inv::TS.StrategicPeriod)
Returns the emission limit of EnergyModel `model` and ResourceEmit `p` in operational
period `t`.
Returns the emission limit of EnergyModel `model` and ResourceEmit `p` in strategic period
period `t_inv`.
"""
emission_limit(model, p, t) = model.emission_limit[p][t]
emission_limit(model::EnergyModel, p::ResourceEmit, t_inv::TS.StrategicPeriod) =
model.emission_limit[p][t_inv]

"""
emission_price(model)
emission_price(model::EnergyModel)
Returns the emission price of EnergyModel `model` as dictionary with `TimeProfile`s for
each `ResourceEmit`.
"""
emission_price(model) = model.emission_price
emission_price(model::EnergyModel) = model.emission_price
"""
emission_price(model, p)
emission_price(model::EnergyModel, p::ResourceEmit)
Returns the emission price of EnergyModel `model` and ResourceEmit `p` as `TimeProfile`.
If no emission price is specified for the ResourceEmit `p`, the function returns 0
"""
emission_price(model, p) = haskey(model.emission_price, p) ? model.emission_price[p] : 0
emission_price(model::EnergyModel, p::ResourceEmit) =
haskey(model.emission_price, p) ? model.emission_price[p] : 0
"""
emission_price(model, p, t)
emission_price(model::EnergyModel, p::ResourceEmit, t_inv::TS.StrategicPeriod)
Returns the emission price of EnergyModel `model` and ResourceEmit `p` in operational
period `t`.
Returns the emission price of EnergyModel `model` and ResourceEmit `p` in strategic
period `t_inv`.
If no emission price is specified for the ResourceEmit `p`, the function returns 0
"""
emission_price(model, p, t) = haskey(model.emission_price, p) ? model.emission_price[p][t] : 0
emission_price(model::EnergyModel, p::ResourceEmit, t_inv::TS.StrategicPeriod) =
haskey(model.emission_price, p) ? model.emission_price[p][t_inv] : 0

"""
co2_instance(model)
co2_instance(model::EnergyModel)
Returns the CO₂ instance used in modelling.
"""
co2_instance(model) = model.co2_instance
co2_instance(model::EnergyModel) = model.co2_instance
Loading

2 comments on commit 4ac7fa6

@JulStraus
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/100015

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.5 -m "<description of version>" 4ac7fa6e42ef73b94f245a036f6379c526f6545e
git push origin v0.6.5

Please sign in to comment.