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

fix: Adding support for quadratic functions using the table data parser #1178

Merged
merged 8 commits into from
Aug 28, 2024
15 changes: 15 additions & 0 deletions src/descriptors/power_system_inputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@
"description": "Heat required to startup from cold",
"default_value": null
},
{
"name": "heat_rate_a0",
"description": "Heat rate Average 0 TODO",
pesap marked this conversation as resolved.
Show resolved Hide resolved
"default_value": null
},
{
"name": "heat_rate_a1",
"description": "Heat rate Average 0 TODO",
"default_value": null
},
{
"name": "heat_rate_a2",
"description": "Heat rate Average 0 TODO",
"default_value": null
},
{
"name": "heat_rate_avg_0",
"description": "Heat rate Average 0 TODO",
Expand Down
48 changes: 46 additions & 2 deletions src/parsers/power_system_table_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@
throw(IS.ConflictingInputsError("Heat rate and cost points are both defined"))
elseif length(heat_rate_fields) > 0
cost_colnames = _HeatRateColumns(zip(heat_rate_fields, output_point_fields))
@warn cost_colnames
pesap marked this conversation as resolved.
Show resolved Hide resolved
elseif length(cost_point_fields) > 0
cost_colnames = _CostPointColumns(zip(cost_point_fields, output_point_fields))
else
Expand Down Expand Up @@ -823,8 +824,17 @@
) where {T <: ThermalGen}
fuel_price = gen.fuel_price / 1000.0

cost_pairs = get_cost_pairs(gen, cost_colnames)
var_cost, fixed = create_pwinc_cost(cost_pairs)
# We check if there is any Quadratic or Linear Data defined. If not we fall back to create PowerLoad
@warn typeof(gen)
pesap marked this conversation as resolved.
Show resolved Hide resolved
quadratic_fields = (gen.heat_rate_a0, gen.heat_rate_a1, gen.heat_rate_a2)

if any(field -> field != nothing, quadratic_fields)
pesap marked this conversation as resolved.
Show resolved Hide resolved
var_cost, fixed =

Check warning on line 832 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L832

Added line #L832 was not covered by tests
create_poly_cost(gen, ["heat_rate_a0", "heat_rate_a1", "heat_rate_a2"])
else
cost_pairs = get_cost_pairs(gen, cost_colnames)
var_cost, fixed = create_pwinc_cost(cost_pairs)
end

startup_cost, shutdown_cost = calculate_uc_cost(data, gen, fuel_price)

Expand Down Expand Up @@ -956,6 +966,40 @@
return var_cost
end

function create_poly_cost(

Check warning on line 969 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L969

Added line #L969 was not covered by tests
gen, cost_colnames,
)
vals = []
for coeff in cost_colnames
a = getfield(gen, Symbol(coeff))
if a != nothing
push!(vals, tryparse(Float64, a))

Check warning on line 976 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L972-L976

Added lines #L972 - L976 were not covered by tests
end
end

Check warning on line 978 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L978

Added line #L978 was not covered by tests

# Three supported cases,
pesap marked this conversation as resolved.
Show resolved Hide resolved
# 1. If three values are passed then we have data looking like: a^2 + a + c,
# 2. If two then data is looking like: a + c
# 3. If two then data is looking like: c
pesap marked this conversation as resolved.
Show resolved Hide resolved
if length(vals) > 3
pesap marked this conversation as resolved.
Show resolved Hide resolved
throw(

Check warning on line 985 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L984-L985

Added lines #L984 - L985 were not covered by tests
DataFormatError(
"Higher order polynomial functions currently not supported.",
),
)
elseif length(vals) == 3
var_cost = QuadraticCurve(vals[3], vals[2], vals[1])
@debug "Quadratic curve created for $(gen.name)"
elseif length(vals) == 2
var_cost = LinearCurve(vals[2], vals[1])

Check warning on line 994 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L990-L994

Added lines #L990 - L994 were not covered by tests
else
length(vals) == 1
var_cost = LinearCurve(vals[1])

Check warning on line 997 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L996-L997

Added lines #L996 - L997 were not covered by tests
end

return var_cost, 0.0

Check warning on line 1000 in src/parsers/power_system_table_data.jl

View check run for this annotation

Codecov / codecov/patch

src/parsers/power_system_table_data.jl#L1000

Added line #L1000 was not covered by tests
end

function create_pwinc_cost(
cost_pairs,
)
Expand Down
Loading