Skip to content

Commit

Permalink
Add more FunctionData fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Feb 20, 2024
1 parent 3267c45 commit 5ef6e69
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/data_format_conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function _convert_data!(
::Val{Symbol("3.0.0")},
::Val{Symbol("4.0.0")},
)
for component in raw["data"]["components"]
for component in vcat(raw["data"]["components"], raw["data"]["masked_components"])
if haskey(component, "operation_cost")
op_cost = component["operation_cost"]
if op_cost["__metadata__"]["type"] in COST_CONTAINERS &&
Expand Down
8 changes: 4 additions & 4 deletions src/descriptors/power_system_structs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@
"name": "operation_cost",
"null_value": "TwoPartCost(nothing)",
"data_type": "OperationalCost",
"default": "TwoPartCost(0.0, 0.0)",
"default": "TwoPartCost(LinearFunctionData(0.0), 0.0)",
"comment": "Operation Cost of Generation [`OperationalCost`](@ref)"
},
{
Expand Down Expand Up @@ -3052,7 +3052,7 @@
"name": "operation_cost",
"null_value": "TwoPartCost(nothing)",
"data_type": "OperationalCost",
"default": "TwoPartCost(0.0, 0.0)",
"default": "TwoPartCost(LinearFunctionData(0.0), 0.0)",
"comment": "Operation Cost of Generation [`OperationalCost`](@ref)"
},
{
Expand Down Expand Up @@ -3220,7 +3220,7 @@
"name": "operation_cost",
"null_value": "TwoPartCost(nothing)",
"data_type": "OperationalCost",
"default": "TwoPartCost(0.0, 0.0)",
"default": "TwoPartCost(LinearFunctionData(0.0), 0.0)",
"comment": "Operation Cost of Generation [`OperationalCost`](@ref)"
},
{
Expand Down Expand Up @@ -3468,7 +3468,7 @@
"name": "operation_cost",
"null_value": "TwoPartCost(nothing)",
"data_type": "OperationalCost",
"default": "TwoPartCost(0.0, 0.0)",
"default": "TwoPartCost(LinearFunctionData(0.0), 0.0)",
"comment": "Operation Cost of Generation [`OperationalCost`](@ref)"
},
{
Expand Down
7 changes: 5 additions & 2 deletions src/models/function_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ end
get_coefficients(fd::PolynomialFunctionData) = fd.coefficients

function _validate_piecewise_x(x_coords)
(length(x_coords) >= 2) ||
throw(ArgumentError("Must specify at least two x-coordinates"))
# TODO currently there exist cases where we are constructing a PiecewiseLinearPointData
# with only one point (e.g., `calculate_variable_cost` within
# `power_system_table_data.jl`) -- what does this represent?
# (length(x_coords) >= 2) ||
# throw(ArgumentError("Must specify at least two x-coordinates"))
issorted(x_coords) || throw(ArgumentError("Piecewise x-coordinates must be ascending"))
# TODO are there legitimate cases where we'd want negative x-coordinates?
# (x_coords[1] >= 0) || throw(ArgumentError("Piecewise x-coordinates cannot be negative"))
Expand Down
4 changes: 2 additions & 2 deletions src/models/generated/HydroDispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ mutable struct HydroDispatch <: HydroGen
internal::InfrastructureSystemsInternal
end

function HydroDispatch(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, operation_cost=TwoPartCost(0.0, 0.0), services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
function HydroDispatch(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
HydroDispatch(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, operation_cost, services, dynamic_injector, ext, time_series_container, InfrastructureSystemsInternal(), )
end

function HydroDispatch(; name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, operation_cost=TwoPartCost(0.0, 0.0), services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
function HydroDispatch(; name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
HydroDispatch(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, operation_cost, services, dynamic_injector, ext, time_series_container, internal, )
end

Expand Down
4 changes: 2 additions & 2 deletions src/models/generated/HydroEnergyReservoir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ mutable struct HydroEnergyReservoir <: HydroGen
internal::InfrastructureSystemsInternal
end

function HydroEnergyReservoir(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, storage_capacity, inflow, initial_storage, operation_cost=TwoPartCost(0.0, 0.0), storage_target=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
function HydroEnergyReservoir(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, storage_capacity, inflow, initial_storage, operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), storage_target=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
HydroEnergyReservoir(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, storage_capacity, inflow, initial_storage, operation_cost, storage_target, conversion_factor, time_at_status, services, dynamic_injector, ext, time_series_container, InfrastructureSystemsInternal(), )
end

function HydroEnergyReservoir(; name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, storage_capacity, inflow, initial_storage, operation_cost=TwoPartCost(0.0, 0.0), storage_target=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
function HydroEnergyReservoir(; name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, storage_capacity, inflow, initial_storage, operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), storage_target=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
HydroEnergyReservoir(name, available, bus, active_power, reactive_power, rating, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, base_power, storage_capacity, inflow, initial_storage, operation_cost, storage_target, conversion_factor, time_at_status, services, dynamic_injector, ext, time_series_container, internal, )
end

Expand Down
4 changes: 2 additions & 2 deletions src/models/generated/HydroPumpedStorage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ mutable struct HydroPumpedStorage <: HydroGen
internal::InfrastructureSystemsInternal
end

function HydroPumpedStorage(name, available, bus, active_power, reactive_power, rating, base_power, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, rating_pump, active_power_limits_pump, reactive_power_limits_pump, ramp_limits_pump, time_limits_pump, storage_capacity, inflow, outflow, initial_storage, storage_target=(up=1.0, down=1.0), operation_cost=TwoPartCost(0.0, 0.0), pump_efficiency=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
function HydroPumpedStorage(name, available, bus, active_power, reactive_power, rating, base_power, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, rating_pump, active_power_limits_pump, reactive_power_limits_pump, ramp_limits_pump, time_limits_pump, storage_capacity, inflow, outflow, initial_storage, storage_target=(up=1.0, down=1.0), operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), pump_efficiency=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
HydroPumpedStorage(name, available, bus, active_power, reactive_power, rating, base_power, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, rating_pump, active_power_limits_pump, reactive_power_limits_pump, ramp_limits_pump, time_limits_pump, storage_capacity, inflow, outflow, initial_storage, storage_target, operation_cost, pump_efficiency, conversion_factor, time_at_status, services, dynamic_injector, ext, time_series_container, InfrastructureSystemsInternal(), )
end

function HydroPumpedStorage(; name, available, bus, active_power, reactive_power, rating, base_power, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, rating_pump, active_power_limits_pump, reactive_power_limits_pump, ramp_limits_pump, time_limits_pump, storage_capacity, inflow, outflow, initial_storage, storage_target=(up=1.0, down=1.0), operation_cost=TwoPartCost(0.0, 0.0), pump_efficiency=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
function HydroPumpedStorage(; name, available, bus, active_power, reactive_power, rating, base_power, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, rating_pump, active_power_limits_pump, reactive_power_limits_pump, ramp_limits_pump, time_limits_pump, storage_capacity, inflow, outflow, initial_storage, storage_target=(up=1.0, down=1.0), operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), pump_efficiency=1.0, conversion_factor=1.0, time_at_status=INFINITE_TIME, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
HydroPumpedStorage(name, available, bus, active_power, reactive_power, rating, base_power, prime_mover_type, active_power_limits, reactive_power_limits, ramp_limits, time_limits, rating_pump, active_power_limits_pump, reactive_power_limits_pump, ramp_limits_pump, time_limits_pump, storage_capacity, inflow, outflow, initial_storage, storage_target, operation_cost, pump_efficiency, conversion_factor, time_at_status, services, dynamic_injector, ext, time_series_container, internal, )
end

Expand Down
4 changes: 2 additions & 2 deletions src/models/generated/InterconnectingConverter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ mutable struct InterconnectingConverter <: StaticInjection
internal::InfrastructureSystemsInternal
end

function InterconnectingConverter(name, available, bus, dc_bus, active_power, rating, active_power_limits, base_power, operation_cost=TwoPartCost(0.0, 0.0), efficiency=1.0, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
function InterconnectingConverter(name, available, bus, dc_bus, active_power, rating, active_power_limits, base_power, operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), efficiency=1.0, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), )
InterconnectingConverter(name, available, bus, dc_bus, active_power, rating, active_power_limits, base_power, operation_cost, efficiency, services, dynamic_injector, ext, time_series_container, InfrastructureSystemsInternal(), )
end

function InterconnectingConverter(; name, available, bus, dc_bus, active_power, rating, active_power_limits, base_power, operation_cost=TwoPartCost(0.0, 0.0), efficiency=1.0, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
function InterconnectingConverter(; name, available, bus, dc_bus, active_power, rating, active_power_limits, base_power, operation_cost=TwoPartCost(LinearFunctionData(0.0), 0.0), efficiency=1.0, services=Device[], dynamic_injector=nothing, ext=Dict{String, Any}(), time_series_container=InfrastructureSystems.TimeSeriesContainer(), internal=InfrastructureSystemsInternal(), )
InterconnectingConverter(name, available, bus, dc_bus, active_power, rating, active_power_limits, base_power, operation_cost, efficiency, services, dynamic_injector, ext, time_series_container, internal, )
end

Expand Down
6 changes: 3 additions & 3 deletions src/parsers/power_models_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ end

function make_hydro_gen(gen_name, d, bus, sys_mbase)
ramp_agc = get(d, "ramp_agc", get(d, "ramp_10", get(d, "ramp_30", abs(d["pmax"]))))
curtailcost = TwoPartCost(0.0, 0.0)
curtailcost = TwoPartCost(LinearFunctionData(0.0), 0.0)

base_conversion = sys_mbase / d["mbase"]
return HydroDispatch(; # No way to define storage parameters for gens in PM so can only make HydroDispatch
Expand Down Expand Up @@ -438,7 +438,7 @@ function make_thermal_gen(gen_name::AbstractString, d::Dict, bus::ACBus, sys_mba
fixed = max(0.0,
first_y - first(get_slopes(PiecewiseLinearPointData(points))) * first_x,
)
cost = PiecewiseLinearPointData((x, y - fixed) for (x, y) in points)
cost = PiecewiseLinearPointData([(x, y - fixed) for (x, y) in points])
elseif model == GeneratorCostModels.POLYNOMIAL
# For now, we make the variable cost a PolynomialFunctionData with all but the
# constant term and make the fixed cost the constant term; in a future update,
Expand All @@ -447,7 +447,7 @@ function make_thermal_gen(gen_name::AbstractString, d::Dict, bus::ACBus, sys_mba
# This transforms [3.0, 1.0, 4.0, 2.0] into [(1, 4.0), (2, 1.0), (3, 3.0)]
coeffs = enumerate(reverse(d["cost"][1:(end - 1)]))
cost = PolynomialFunctionData(Dict((i, c / sys_mbase^i) for (i, c) in coeffs))
fixed = d["cost"][end]
fixed = (d["ncost"] >= 1) ? last(d["cost"]) : 0.0
end
startup = d["startup"]
shutdn = d["shutdown"]
Expand Down
13 changes: 7 additions & 6 deletions src/parsers/power_system_table_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,11 @@ function calculate_variable_cost(
for i in 2:length(var_cost)
var_cost[i] = (var_cost[i - 1][1] + var_cost[i][1], var_cost[i][2])
end
var_cost = PiecewiseLinearPointData([(x, y) for (y, x) in var_cost])

elseif length(var_cost) == 1
# if there is only one point, use it to determine the constant $/MW cost
var_cost = var_cost[1][1] * fuel_cost + vom
var_cost = LinearFunctionData(var_cost[1][1] * fuel_cost + vom)
fixed = 0.0
end
return var_cost, fixed, fuel_cost
Expand Down Expand Up @@ -892,8 +893,9 @@ function calculate_variable_cost(
(var_cost[2][1] + vom / (var_cost[2][2] - var_cost[1][2]) * var_cost[1][2]),
)
var_cost = [(var_cost[i][1] - fixed, var_cost[i][2]) for i in 1:length(var_cost)]
var_cost = PiecewiseLinearPointData([(x, y) for (y, x) in var_cost])
elseif length(var_cost) == 1
var_cost = var_cost[1][1]
var_cost = LinearFunctionData(var_cost[1][1])
fixed = 0.0
end

Expand Down Expand Up @@ -1041,14 +1043,13 @@ function make_thermal_generator_multistart(
base_power = get_base_power(thermal_gen)
var_cost, fixed, fuel_cost =
calculate_variable_cost(data, gen, cost_colnames, base_power)
if var_cost isa Float64
if var_cost isa LinearFunctionData
no_load_cost = 0.0
var_cost = LinearFunctionData(var_cost)
else
no_load_cost = var_cost[1][1]
(no_load_x, no_load_cost) = first(var_cost)
var_cost =
PiecewiseLinearPointData([
(c - no_load_cost, pp - var_cost[1][2]) for (c, pp) in var_cost
(pp - no_load_x, c - no_load_cost) for (pp, c) in var_cost
])
end
lag_hot =
Expand Down
10 changes: 5 additions & 5 deletions test/data_14bus_pu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ thermal_generators14(nodes14) = [
reactive_power_limits = (min = 0.0, max = 0.1),
time_limits = nothing,
ramp_limits = nothing,
operation_cost = ThreePartCost((430.292599, 2000.0), 0.0, 0.0, 0.0),
operation_cost = ThreePartCost(QuadraticFunctionData(430.292599, 2000.0, 0.0), 0.0, 0.0, 0.0),
base_power = 100.0,
),
ThermalStandard(;
Expand All @@ -671,7 +671,7 @@ thermal_generators14(nodes14) = [
reactive_power_limits = (min = -0.4, max = 0.5),
time_limits = nothing,
ramp_limits = nothing,
operation_cost = ThreePartCost((2500.0, 2000.0), 0.0, 0.0, 0.0),
operation_cost = ThreePartCost(QuadraticFunctionData(2500.0, 2000.0, 0.0), 0.0, 0.0, 0.0),
base_power = 100.0,
),
ThermalStandard(;
Expand All @@ -688,7 +688,7 @@ thermal_generators14(nodes14) = [
reactive_power_limits = (min = 0.0, max = 0.4),
time_limits = nothing,
ramp_limits = nothing,
operation_cost = ThreePartCost((100.0, 4000.0), 0.0, 0.0, 0.0),
operation_cost = ThreePartCost(QuadraticFunctionData(100.0, 4000.0, 0.0), 0.0, 0.0, 0.0),
base_power = 100.0,
),
ThermalStandard(;
Expand All @@ -705,7 +705,7 @@ thermal_generators14(nodes14) = [
reactive_power_limits = (min = -0.06, max = 0.24),
time_limits = nothing,
ramp_limits = nothing,
operation_cost = ThreePartCost((100.0, 4000.0), 0.0, 0.0, 0.0),
operation_cost = ThreePartCost(QuadraticFunctionData(100.0, 4000.0, 0.0), 0.0, 0.0, 0.0),
base_power = 100.0,
),
ThermalStandard(;
Expand All @@ -722,7 +722,7 @@ thermal_generators14(nodes14) = [
reactive_power_limits = (min = -0.06, max = 0.24),
time_limits = nothing,
ramp_limits = nothing,
operation_cost = ThreePartCost((100.0, 4000.0), 0.0, 0.0, 0.0),
operation_cost = ThreePartCost(QuadraticFunctionData(100.0, 4000.0, 0.0), 0.0, 0.0, 0.0),
base_power = 100.0,
),
]
Expand Down
Loading

0 comments on commit 5ef6e69

Please sign in to comment.