Skip to content

Commit

Permalink
remove repeated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Jan 27, 2024
1 parent a809ea0 commit bcc2316
Showing 1 changed file with 0 additions and 61 deletions.
61 changes: 0 additions & 61 deletions src/devices_models/devices/common/rateofchange_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,64 +256,3 @@ function add_semicontinuous_ramp_constraints!(
end
return
end

function add_semicontinuous_ramp_constraints!(
container::OptimizationContainer,
T::Type{<:ConstraintType},
U::Type{<:VariableType},
devices::IS.FlattenIteratorWrapper{V},
model::DeviceModel{V, W},
X::Type{<:PM.AbstractPowerModel},
) where {V <: PSY.Component, W <: AbstractDeviceFormulation}
parameters = built_for_recurrent_solves(container)
time_steps = get_time_steps(container)
variable = get_variable(container, U(), V)
varstart = get_variable(container, StartVariable(), V)
varstop = get_variable(container, StopVariable(), V)

ramp_devices = _get_ramp_constraint_devices(container, devices)
minutes_per_period = _get_minutes_per_period(container)
IC = _get_initial_condition_type(T, V, W)
initial_conditions_power = get_initial_condition(container, IC(), V)

set_name = [PSY.get_name(r) for r in ramp_devices]
con_up =
add_constraints_container!(container, T(), V, set_name, time_steps; meta = "up")
con_down =
add_constraints_container!(container, T(), V, set_name, time_steps; meta = "dn")

for ic in initial_conditions_power
name = get_component_name(ic)
# This is to filter out devices that dont need a ramping constraint
name set_name && continue
device = get_component(ic)
ramp_limits = PSY.get_ramp_limits(device)
power_limits = PSY.get_active_power_limits(device)
ic_power = get_value(ic)
@debug "add rate_of_change_constraint" name ic_power
@assert (parameters && isa(ic_power, JuMP.VariableRef)) || !parameters
con_up[name, 1] = JuMP.@constraint(
get_jump_model(container),
variable[name, 1] - ic_power <=
ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, 1]
)
con_down[name, 1] = JuMP.@constraint(
get_jump_model(container),
ic_power - variable[name, 1] <=
ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, 1]
)
for t in time_steps[2:end]
con_up[name, t] = JuMP.@constraint(
get_jump_model(container),
variable[name, t] - variable[name, t - 1] <=
ramp_limits.up * minutes_per_period + power_limits.min * varstart[name, t]
)
con_down[name, t] = JuMP.@constraint(
get_jump_model(container),
variable[name, t - 1] - variable[name, t] <=
ramp_limits.down * minutes_per_period + power_limits.min * varstop[name, t]
)
end
end
return
end

0 comments on commit bcc2316

Please sign in to comment.