From e843554c9f14d1fd79e4bc715a77ce607951bc57 Mon Sep 17 00:00:00 2001 From: Jacob Schwartz Date: Thu, 30 Nov 2023 20:35:45 -0500 Subject: [PATCH] Experimental use of expressions --- src/model/resources/thermal/thermal_commit.jl | 19 ++++++++++++++----- .../effective_capacity.jl | 10 +++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/model/resources/thermal/thermal_commit.jl b/src/model/resources/thermal/thermal_commit.jl index 47949bb557..88b1815963 100644 --- a/src/model/resources/thermal/thermal_commit.jl +++ b/src/model/resources/thermal/thermal_commit.jl @@ -361,11 +361,20 @@ function thermal_maintenance_capacity_reserve_margin_adjustment!(EP::Model, MAINT = resources_with_maintenance(dfGen) applicable_resources = intersect(MAINT, THERM_COMMIT) - resource_component(y) = dfGen[y, :Resource] - capresfactor(y, capres) = dfGen[y, Symbol("CapRes_$capres")] - cap_size(y) = dfGen[y, :Cap_Size] - down_var(y) = EP[Symbol(maintenance_down_name(resource_component(y)))] maint_adj = @expression(EP, [capres in 1:ncapres, t in 1:T], - -sum(capresfactor(y, capres) * down_var(y)[t] * cap_size(y) for y in applicable_resources)) + sum(thermal_maintenance_capacity_reserve_margin_adjustment(EP, inputs, y, capres, t) for y in applicable_resources)) add_similar_to_expression!(EP[:eCapResMarBalance], maint_adj) end + +function thermal_maintenance_capacity_reserve_margin_adjustment(EP::Model, + inputs::Dict, + y::Int, + capres::Int, + t) + dfGen = inputs["dfGen"] + resource_component = dfGen[y, :Resource] + capresfactor = dfGen[y, Symbol("CapRes_$capres")] + cap_size = dfGen[y, :Cap_Size] + down_var = EP[Symbol(GenX.maintenance_down_name(resource_component))] + return -capresfactor * down_var[t] * cap_size +end diff --git a/src/write_outputs/capacity_reserve_margin/effective_capacity.jl b/src/write_outputs/capacity_reserve_margin/effective_capacity.jl index d3e25e0a1c..76ae63a001 100644 --- a/src/write_outputs/capacity_reserve_margin/effective_capacity.jl +++ b/src/write_outputs/capacity_reserve_margin/effective_capacity.jl @@ -46,13 +46,9 @@ function thermal_plant_effective_capacity( effective_capacity = fill(capresfactor(y, capres_zone) * eTotalCap, length(timesteps)) if has_maintenance(inputs) && y in resources_with_maintenance(dfGen) - resource_component = dfGen[y, :Resource] - cap_size = dfGen[y, :Cap_Size] - down_var = EP[Symbol(maintenance_down_name(resource_component))] - vDOWN = value.(down_var[timesteps]) - effective_capacity = - effective_capacity .- capresfactor(y, capres_zone) * vDOWN * cap_size - end + adjustment = thermal_maintenance_capacity_reserve_margin_adjustment(EP, inputs, y, capres_zone, timesteps) + effective_capacity = effective_capacity .+ value.(adjustment) + end return effective_capacity end