Skip to content

Commit

Permalink
Inclusion of potential for TransmissionMode emissions (#26)
Browse files Browse the repository at this point in the history
* Include modeling of emissions based on initial proposal

* Changed the structure for inclusion of emissions

---------

Co-authored-by: Truls Flatberg <[email protected]>
  • Loading branch information
JulStraus and trulsf authored Aug 21, 2024
1 parent e34f545 commit 9e1909c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
* This approach required `EnergyModelsGeography` to include all functions and type declarations internally.
* An extension was introduced to handle these problems.

### Introduced potential for emissions of `TransmissionMode`s

* As outlined in [Issue 9](https://github.com/EnergyModelsX/EnergyModelsGeography.jl/issues/9), there is a requirement for potential emissions from `TransmissionMode`s.
* The clean approach was not achieved within a certain timeframe, hence, a limited approach is implemented based on the initial provided branches in both [`EMB`](https://github.com/EnergyModelsX/EnergyModelsBase.jl/tree/0.7/emissions) and [`EMG`](https://github.com/EnergyModelsX/EnergyModelsGeography.jl/tree/0.9/emissions).
* The implementation is **not** tested!

## Version 0.9.1 (2024-05-24)

### Bugfix
Expand Down
22 changes: 22 additions & 0 deletions src/constraint_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,25 @@ function constraints_opex_var(m, tm::TransmissionMode, 𝒯ᴵⁿᵛ, modeltype:
)
end
end

"""
constraints_emission(m, tm::TransmissionMode, 𝒯, modeltype::EnergyModel)
Function for creating the constraints on the emissions of a generic `TransmissionMode` `tm`.
This function serves as fallback option if no other function is specified for a
`TransmissionMode`.
"""
function constraints_emission(m, tm::TransmissionMode, 𝒯, modeltype::EnergyModel)

if is_bidirectional(tm)
@constraint(m, [t 𝒯, p_em emit_resources(tm)],
m[:emissions_trans][tm, t, p_em] ==
emission(tm, p_em, t) * (m[:trans_pos][tm, t] + m[:trans_neg][tm, t])
)
else
@constraint(m, [t 𝒯, p_em emit_resources(tm)],
m[:emissions_trans][tm, t, p_em] ==
emission(tm, p_em, t) * m[:trans_out][tm, t]
)
end
end
47 changes: 47 additions & 0 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ function create_model(case, modeltype::EnergyModel, m::JuMP.Model; check_timepro
variables_trans_opex(m, 𝒯, ℳ, modeltype)
variables_trans_capacity(m, 𝒯, ℳ, modeltype)
variables_trans_modes(m, 𝒯, ℳ, modeltype)
variables_trans_emission(m, 𝒯, ℳ, 𝒫, modeltype)

# Construction of constraints for areas and transmission corridors
constraints_area(m, 𝒜, 𝒯, ℒᵗʳᵃⁿˢ, 𝒫, modeltype)
constraints_transmission(m, 𝒯, ℳ, modeltype)

# Updates the global constraint on total emissions
update_total_emissions(m, 𝒯, ℳ, 𝒫, modeltype)

# Updates the objective function
update_objective(m, 𝒯, ℳ, modeltype)

Expand Down Expand Up @@ -173,6 +177,27 @@ function variables_trans_mode(m, 𝒯, ℳᴸᴾ::Vector{<:PipeLinepackSimple},
@variable(m, linepack_stor_level[ℳᴸᴾ, 𝒯] >= 0)
end

"""
variables_trans_emission(m, 𝒯, ℳ, 𝒫, modeltype)
Creates variables for the modeling of tranmission emissions. These variables
are only created for transmission modes where emissions are included.
All emission resources that are not included for a type are fixed to a value of 0.
The emission variables are differentiated in:
* `:emissions_node` - emissions of a transmission mode in an operational period,
"""
function variables_trans_emission(m, 𝒯, ℳ, 𝒫, modeltype)
ℳᵉᵐ = filter(m -> has_emissions(m), ℳ)
𝒫ᵉᵐ = EMB.res_sub(𝒫, ResourceEmit)

@variable(m, emissions_trans[ℳᵉᵐ, 𝒯, 𝒫ᵉᵐ] >= 0)

# Fix of unused emission variables to avoid free variables
for tm ℳᵉᵐ, p_em setdiff(𝒫ᵉᵐ, emit_resources(tm)), t 𝒯
fix(m[:emissions_trans][tm, t, p_em], 0; force = true)
end
end

"""
constraints_area(m, 𝒜, 𝒯, ℒᵗʳᵃⁿˢ, 𝒫, modeltype::EnergyModel)
Expand Down Expand Up @@ -277,6 +302,25 @@ function update_objective(m, 𝒯, ℳ, modeltype::EnergyModel)
@objective(m, Max, obj)
end

"""
update_total_emissions(m, 𝒯, ℳ, 𝒫, modeltype::EnergyModel)
Update the constraints aggregating total emissions in each time period
with contributions from transmission emissions.
"""
function update_total_emissions(m, 𝒯, ℳ, 𝒫, modeltype::EnergyModel)
ℳᵉᵐ = filter(m -> has_emissions(m), ℳ)
𝒫ᵉᵐ = EMB.res_sub(𝒫, EMB.ResourceEmit)

# Modify existing constraints on total emissions by adding contribution from
# transmission emissions. Note the coefficient is set to -1 since the total constraint
# has the variables on the RHS.
for tm ℳᵉᵐ, p 𝒫ᵉᵐ, t 𝒯
JuMP.set_normalized_coefficient(m[:con_em_tot][t, p], m[:emissions_trans][tm, t, p], -1.0)
end
end



"""
create_transmission_mode(m, tm::TransmissionMode, 𝒯, modeltype::EnergyModel)
Expand All @@ -299,6 +343,9 @@ function create_transmission_mode(m, tm::TransmissionMode, 𝒯, modeltype::Ener
# Call of the function for limiting the capacity to the maximum installed capacity
constraints_capacity(m, tm, 𝒯, modeltype)

# Call of the functions for transmission emissions
constraints_emission(m, tm, 𝒯, modeltype)

# Call of the functions for both fixed and variable OPEX constraints introduction
constraints_opex_fixed(m, tm, 𝒯ᴵⁿᵛ, modeltype)
constraints_opex_var(m, tm, 𝒯ᴵⁿᵛ, modeltype)
Expand Down
31 changes: 31 additions & 0 deletions src/structures/mode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
abstract type TransmissionMode end
Base.show(io::IO, t::TransmissionMode) = print(io, "$(t.id)")


""" A reference dynamic `TransmissionMode`.
Generic representation of dynamic transmission modes, using for example truck, ship or railway transport.
Expand Down Expand Up @@ -279,6 +280,36 @@ Returns the directions of transmission mode `tm`.
"""
directions(tm::TransmissionMode) = tm.directions

"""
has_emissions(tm::TransmissionMode)
Returns whether there are emissions associated with transmission mode `tm`.
Default behaviour is no emissions.
"""
has_emissions(tm::TransmissionMode) = false

"""
emit_resources(m::TransmissionMode)
Returns the types of emissions associated with transmission mode `tm`.
"""
emit_resources(tm::TransmissionMode) = EMB.ResourceEmit[]

"""
emission(tm::TransmissionMode, p::EMB.ResourceEmit)
Returns the emission of transmission mode `tm` of a specific resource `p` as `TimeProfile`
"""
emission(tm::TransmissionMode, p::EMB.ResourceEmit) = 0

"""
emission(tm::TransmissionMode, p::EMB.ResourceEmit, t)
Returns the emission of transmission mode `tm` of a specific resource `p` at time period `t`
per unit transmitted.
"""
emission(tm::TransmissionMode, p::EMB.ResourceEmit, t) = 0

"""
consumption_rate(tm::PipeMode)
Expand Down

0 comments on commit 9e1909c

Please sign in to comment.