Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial refactor of cost functions #1071

Merged
merged 50 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5818ed1
delete old cost data
jd-lara Mar 7, 2024
23c6e0d
add ProductionVariableCosts
jd-lara Mar 8, 2024
f7c1aab
add ThermalGenerationCost
jd-lara Mar 8, 2024
4f1a34a
delete old exports
jd-lara Mar 8, 2024
1fc21fb
delete outdated setter
jd-lara Mar 8, 2024
a39cff7
partially update the structs
jd-lara Mar 8, 2024
771b98b
add new cost functions
jd-lara Mar 8, 2024
779f537
format run
jd-lara Mar 8, 2024
f8c28fe
some updates
jd-lara Mar 8, 2024
6a267a6
Fix typos; minor refactors for legibility
GabrielKS Mar 21, 2024
6d19398
Add LoadCost
GabrielKS Mar 21, 2024
6ed554b
Add cost function includes
GabrielKS Mar 21, 2024
ddd5d08
Eliminate TwoPartCost in generated structs
GabrielKS Mar 21, 2024
2d434dd
Refine usage of `LoadCost`
GabrielKS Mar 22, 2024
3032e2d
Fix serialization, typos
GabrielKS Mar 22, 2024
cdfd673
Fix `OperationalCost` constructors, test
GabrielKS Mar 22, 2024
0156734
Make `OperationalCost` structs take the right kind of `ProductionVari…
GabrielKS Mar 25, 2024
7af370b
Remove `PolynomialFunctionData`
GabrielKS Mar 27, 2024
d7ff445
Accommodate `FunctionData` refactors
GabrielKS Mar 29, 2024
44e5f1a
Add `ValueCurve` for input-output, incremental, average rate curves
GabrielKS Mar 29, 2024
d9f1e1d
`ValueCurves`: add documentation, support serialization
GabrielKS Mar 29, 2024
652d09c
Redefine `CostCurve`, `FuelCurve` in terms of `ValueCurve`
GabrielKS Mar 31, 2024
d63dae6
Add some `zero` methods
GabrielKS Mar 31, 2024
31b848a
Standardize `OperationalCost` naming
GabrielKS Mar 31, 2024
f0fdd47
Make `test_cost_functions` pass
GabrielKS Mar 31, 2024
d055875
Export new cost structs
GabrielKS Apr 1, 2024
2d82421
Refine cost struct constructors
GabrielKS Apr 1, 2024
a292ca0
Make further use of new cost structs throughout PSY
GabrielKS Apr 1, 2024
3db189b
Fix cost struct parameterized type specifications
GabrielKS Apr 2, 2024
ccd9145
Revert `power_system_table_data` math, update accessors in test
GabrielKS Apr 2, 2024
187bdc0
Move `operational_cost.jl`
GabrielKS Apr 2, 2024
b824da4
Fine-tune exports
GabrielKS Apr 2, 2024
b114f59
Fix operational cost field types
GabrielKS Apr 2, 2024
5923544
Remove more references to old cost structs
GabrielKS Apr 3, 2024
28220f1
Add x-axis units in `CostCurve` and `FuelCurve`
GabrielKS Apr 3, 2024
dd537cb
Update Project.toml
jd-lara Mar 18, 2024
982861b
Add rough draft of cost function aliases and documentation
GabrielKS Apr 15, 2024
9346083
Add operational cost conversion logic
GabrielKS Apr 16, 2024
a25c586
Fine-tune cost structs
GabrielKS Apr 16, 2024
a49da75
Add cost aliases docs and tests
GabrielKS Apr 16, 2024
259b6cb
Rename `PiecewiseSlopeCurve`, revert ill-advised constructor refactor
GabrielKS Apr 17, 2024
0afc7bc
Save `MarketBidCost` refactor progress before HDF5 transformations work
GabrielKS Apr 19, 2024
bd1cfeb
Implement HDF serialization properly for `ValueCurve`s
GabrielKS Apr 20, 2024
d758391
Wrap up high-level cost structs in time series for MarketBidCost
GabrielKS Apr 20, 2024
b26d639
Run formatter
GabrielKS Apr 20, 2024
e8193dd
Update test for new cost structs
GabrielKS Apr 22, 2024
f524e21
Rename `MarketBidCost.ancillary_services` -> `ancillary_service_offers
GabrielKS Apr 22, 2024
234936e
Use cost function aliases
GabrielKS Apr 22, 2024
b0f4f60
Fix typo
GabrielKS Apr 27, 2024
39c87fb
Merge branch 'psy4' into jdgk/cost_functions
GabrielKS Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export get_points
export get_x_coords
export get_y0

export ThreePartCost
export TwoPartCost
export MultiStartCost
export ThermalGenerationCost
export MarketBidCost
export StorageManagementCost

Expand Down
25 changes: 25 additions & 0 deletions src/models/cost_functions/CostCurves.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
abstract type CostCurve <: ProductionVariableCost end

get_function_data(curve::CostCurve) = curve.function_data

"""
Representation of the variable operation cost of a power plant in $/time at a particular power output level.

# Arguments
- `function_data::FunctionData`: Functional representation of the cost curve
"""
struct InputOutputCostCurve <: FuelCurve
function_data::FunctionData
end

"""
First derivative of the Input/Output cost curve.

# Arguments
- `function_data::FunctionData`: Functional representation of the incremental cost.
- `no_load_cost::Float64`: The estimated cost needed to theoretically operate a unit at zero power. This is not the cost of operating at mininum stable levels
"""
struct IncrementalCostCurve <: FuelCurve
function_data::FunctionData
no_load_cost::Float64
end
54 changes: 54 additions & 0 deletions src/models/cost_functions/FuelCurves.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
abstract type FuelCurve <: VariableProductionCost end

get_function_data(curve::FuelCurve) = curve.function_data
get_fixed_fuel_cost(curve::FuelCurve) = curve.fixed_fuel_cost
get_fuel_cost_time_series(curve::FuelCurve) = curve.fuel_cost_time_series

"""
Fuel consumption representation fuel input in Fuel/hr as a function of the power output.
This function indicates how much fuel rate is required to produce a power level. It can be used
for any generator like gas (MBTU/hr/MW), oil (Liters/hr/MW) or hydro (m^3/hr/MW).

# Arguments
- `function_data::FunctionData`: Functional representation of the input/output curve.
- `fixed_fuel_cost::Union{Nothing Float64}`: Fixed value for fuel cost for the total cost calculation.
- `fuel_cost_time_series::Union{Nothing, String}`: Fuel cost time series name for the total cost calculation.
"""
struct InputOutputFuelCurve <: FuelCurve
function_data::FunctionData
fixed_fuel_cost::Union{Nothing, Float64}
fuel_cost_time_series::Union{Nothing, String}
end

"""
Fuel usage representation of the amount of input energy required to produce an electric energy amount (e.g., MWhr)
at a given generation level. Usually calculated by dividing absolute values of fuel input rate by absolute values of electric output power

# Arguments
- `function_data::FunctionData`: Functional representation of the average heat rate for the unit
- `fixed_fuel_cost::Union{Nothing Float64}`: Fixed value for fuel cost for the total cost calculation.
- `fuel_cost_time_series::Union{Nothing, String}`: Fuel cost time series name for the total cost calculation.
"""
struct AverageHeatRateCurve <: FuelCurve
function_data::FunctionData
fixed_fuel_cost::Union{Nothing, Float64}
fuel_cost_time_series::Union{Nothing, String}
end

"""
First derivative of the Input/Output curve

# Arguments
- `function_data::FunctionData`: Functional representation of the heat rate.
- `no_load_heat::Float64`: The estimated amount of fuel needed to theoretically operate a unit at zero power. This is not the fuel required to operate at mininum stable levels.
- `fixed_fuel_cost::Union{Nothing Float64}`: Fixed value for fuel cost for the total cost calculation.
- `fuel_cost_time_series::Union{Nothing, String}`: Fuel cost time series name for the total cost calculation.
"""
struct IncrementalHeatRateCurve <: FuelCurve
function_data::FunctionData
no_load_heat::Float64
fixed_fuel_cost::Union{Nothing, Float64}
fuel_cost_time_series::Union{Nothing, String}
end

get_no_load_heat(curve::IncrementalHeatRateCurve) = curve.no_load_heat
60 changes: 60 additions & 0 deletions src/models/cost_functions/ThermalGenerationCost.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const HEAT_STAGES = NamedTuple{(:hot, :warm, :cold), NTuple{3, Float64}}
"""
mutable struct ThermalGenerationCost <: OperationalCost
variable::ProductionVariableCost
no_load::Float64
fixed::Float64
start_up::NamedTuple{(:hot, :warm, :cold), NTuple{3, Float64}}
shut_down::Float64
end

Data Structure Operational Cost Data which includes fixed, variable cost, multiple start up cost and stop costs.

# Arguments
- `variable::ProductionVariableCost`: Production Variable Cost. Can take fuel curves or cost curve represenations
- `fixed::Union{Nothing, Float64}`: Fixed cost of keeping the unit online. For some cost represenations this field can be duplicative.
- `start_up::Union{NamedTuple{(:hot, :warm, :cold), NTuple{3, Float64}}, Float64}`: start-up cost can take linear of multi-stage costs
Comment on lines +13 to +14
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstrings don't match the types.

- `shut_down::Float64`: cost of turning the unit offline.
"""
mutable struct ThermalGenerationCost <: OperationalCost
"variable cost"
variable::ProductionVariableCost
"fixed cost"
fixed::Float64
"start-up cost"
start_up::Union{HEAT_STAGES, Float64}
"shut-down cost"
shut_down::Float64
end

function ThermalGenerationCost(; variable, fixed, start_up, shut_down)
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
ThermalGenerationCost(variable, fixed, start_up, shut_down)
end

# Constructor for demo purposes; non-functional.
function ThermalGenerationCost(::Nothing)
ThermalGenerationCost(;
variable = InputOutputCostCurve(LinearProductionVariableCost(0.0)),
fixed = 0.0,
start_up = 0.0,
shut_down = 0.0,
)
end

"""Get [`ThermalGenerationCost`](@ref) `variable`."""
get_variable(value::ThermalGenerationCost) = value.variable
"""Get [`ThermalGenerationCost`](@ref) `fixed`."""
get_fixed(value::ThermalGenerationCost) = value.fixed
"""Get [`ThermalGenerationCost`](@ref) `start_up`."""
get_start_up(value::ThermalGenerationCost) = value.start_up
"""Get [`ThermalGenerationCost`](@ref) `shut_down`."""
get_shut_down(value::ThermalGenerationCost) = value.shut_down

"""Set [`ThermalGenerationCost`](@ref) `variable`."""
set_variable!(value::ThermalGenerationCost, val) = value.variable = val
"""Set [`ThermalGenerationCost`](@ref) `fixed`."""
set_fixed!(value::ThermalGenerationCost, val) = value.fixed = val
"""Set [`ThermalGenerationCost`](@ref) `start_up`."""
set_start_up!(value::ThermalGenerationCost, val) = value.start_up = val
"""Set [`ThermalGenerationCost`](@ref) `shut_down`."""
set_shut_down!(value::ThermalGenerationCost, val) = value.shut_down = val
1 change: 1 addition & 0 deletions src/models/cost_functions/variable_cost.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abstract type ProductionVariableCost end
75 changes: 0 additions & 75 deletions src/models/generated/MarketBidCost.jl

This file was deleted.

74 changes: 0 additions & 74 deletions src/models/generated/MultiStartCost.jl

This file was deleted.

83 changes: 0 additions & 83 deletions src/models/generated/StorageManagementCost.jl

This file was deleted.

2 changes: 1 addition & 1 deletion src/models/generated/ThermalMultiStart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function ThermalMultiStart(::Nothing)
time_limits=nothing,
start_time_limits=nothing,
start_types=1,
operation_cost=MultiStartCost(nothing),
operation_cost=ThermalGenerationCost(nothing),
base_power=0.0,
services=Device[],
time_at_status=INFINITE_TIME,
Expand Down
Loading
Loading