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

bug fixes for max net metering benefit, multi-period and multi-tier demand charges #401

Merged
merged 29 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d1a682f
update bounds on wholesale, net metering benefits benefits
zolanaj May 22, 2024
5fd6399
Merge branch 'develop' into fix-net-metering-and-demand-charges
zolanaj May 22, 2024
f8ea5e6
obtain tier limits before scrubbing demand rate structures
zolanaj May 22, 2024
bd6acbc
new testset Multi-tier demand rates
zolanaj May 22, 2024
3a80c9c
update NM test value
zolanaj May 22, 2024
8637d62
Update CHANGELOG.md
zolanaj May 23, 2024
abc269d
reduce very large hand-entered numbers for maxes to bigM
zolanaj May 23, 2024
209ba63
Update CHANGELOG.md
zolanaj May 24, 2024
a42073a
Merge branch 'develop' into fix-net-metering-and-demand-charges
zolanaj May 31, 2024
3d623f0
use minimums for individual tier limits when more than one set of tie…
zolanaj May 31, 2024
0c5207f
increase energy tier limit
zolanaj May 31, 2024
fff3597
go back to general parse_urdb_demand_tiers using an array instead of …
zolanaj May 31, 2024
a91872a
simplify parse_urdb_demand_tiers
zolanaj May 31, 2024
25c5c51
get limits directly from demand parsers
zolanaj May 31, 2024
32dfaaa
ren parse_urdb_demand_tiers get_num_demand_tiers
zolanaj May 31, 2024
447f9ab
make monthly_demand_tier_limits, tou_demand_tier_limits 2-dimensional…
zolanaj May 31, 2024
60ed541
update indexing of p.s.electric_tariff.tou_demand_tier_limits, p.s.el…
zolanaj May 31, 2024
3091f0e
index tier limits on month or TOU period
zolanaj Jun 3, 2024
56ff653
ren scrub_urdb_demand_tiers scrub_urdb_tiers
zolanaj Jun 3, 2024
238b951
ren get_num_demand_tiers get_num_tiers
zolanaj Jun 3, 2024
2398e8b
update warning for scrub_urdb_tiers
zolanaj Jun 3, 2024
8502b1c
make energy limits 2-dimensional array instead of vector
zolanaj Jun 3, 2024
28d8917
expand mulitple tier testing
zolanaj Jun 3, 2024
202145c
Merge branch 'develop' into fix-net-metering-and-demand-charges
adfarth Jun 5, 2024
b53f9e4
changelog, add notes
adfarth Jun 6, 2024
226cd67
rm comment on URDB Dict modification from parsing function docstrings
zolanaj Jun 11, 2024
5fbc355
refactoring to remove get_num_tiers()
zolanaj Jun 11, 2024
f1301b2
add notes for dimension of tier limits
zolanaj Jun 11, 2024
ccfcb51
Update CHANGELOG.md
zolanaj Jun 11, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Classify the change according to the following categories:
## Develop
### Fixed
- Convert `max_electric_load_kw` to _Float64_ before passing to function `get_chp_defaults_prime_mover_size_class`
- Increased the big-M bound on maximum net metering benefit to prevent artificially low export benefits
adfarth marked this conversation as resolved.
Show resolved Hide resolved
- Fixed a bug in which tier limits did not load correctly when the number of tiers vary by period in the inputs
- Set a limit for demand and energy tier maxes to avoid errors returned by HiGHS due to numerical limits

## v0.46.1
### Changed
Expand Down
4 changes: 2 additions & 2 deletions src/constraints/electric_utility_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function add_export_constraints(m, p; _n="")
@warn "Adding binary variable for net metering choice. Some solvers are slow with binaries."

# Good to bound the benefit - we use max_bene as a lower bound because the benefit is treated as a negative cost
max_bene = sum([ld*rate for (ld,rate) in zip(p.s.electric_load.loads_kw, p.s.electric_tariff.export_rates[:NEM])])*10
max_bene = sum([ld*rate for (ld,rate) in zip(p.s.electric_load.loads_kw, p.s.electric_tariff.export_rates[:NEM])])*p.pwf_e*p.hours_per_time_step*10
adfarth marked this conversation as resolved.
Show resolved Hide resolved
NEM_benefit = @variable(m, lower_bound = max_bene)


Expand Down Expand Up @@ -135,7 +135,7 @@ function add_export_constraints(m, p; _n="")
else
binWHL = @variable(m, binary = true)
@warn "Adding binary variable for wholesale export choice. Some solvers are slow with binaries."
max_bene = sum([ld*rate for (ld,rate) in zip(p.s.electric_load.loads_kw, p.s.electric_tariff.export_rates[:WHL])])*10
max_bene = sum([ld*rate for (ld,rate) in zip(p.s.electric_load.loads_kw, p.s.electric_tariff.export_rates[:WHL])])*p.pwf_e*p.hours_per_time_step*100
WHL_benefit = @variable(m, lower_bound = max_bene)

@constraint(m, binNEM + binWHL == 1) # can either NEM or WHL export, not both
Expand Down
9 changes: 5 additions & 4 deletions src/core/urdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function parse_urdb_energy_costs(d::Dict, year::Int; time_steps_per_hour=1, bigM
energy_tier_max = get(energy_tier, "max", bigM)

if "rate" in keys(energy_tier) || "adj" in keys(energy_tier) || "sell" in keys(energy_tier)
append!(energy_tier_limits_kwh, energy_tier_max)
append!(energy_tier_limits_kwh, min(energy_tier_max, bigM))
adfarth marked this conversation as resolved.
Show resolved Hide resolved
end

if "unit" in keys(energy_tier) && string(energy_tier["unit"]) != "kWh"
Expand Down Expand Up @@ -313,8 +313,8 @@ Parse monthly ("flat") and TOU demand rates
"""
adfarth marked this conversation as resolved.
Show resolved Hide resolved
function parse_demand_rates(d::Dict, year::Int; bigM=1.0e8, time_steps_per_hour::Int)
adfarth marked this conversation as resolved.
Show resolved Hide resolved
if haskey(d, "flatdemandstructure")
scrub_urdb_demand_tiers!(d["flatdemandstructure"])
monthly_demand_tier_limits = parse_urdb_demand_tiers(d["flatdemandstructure"])
scrub_urdb_demand_tiers!(d["flatdemandstructure"])
n_monthly_demand_tiers = length(monthly_demand_tier_limits)
monthly_demand_rates = parse_urdb_monthly_demand(d, n_monthly_demand_tiers)
else
Expand All @@ -324,8 +324,8 @@ function parse_demand_rates(d::Dict, year::Int; bigM=1.0e8, time_steps_per_hour:
end

if haskey(d, "demandratestructure")
scrub_urdb_demand_tiers!(d["demandratestructure"])
tou_demand_tier_limits = parse_urdb_demand_tiers(d["demandratestructure"])
scrub_urdb_demand_tiers!(d["demandratestructure"])
n_tou_demand_tiers = length(tou_demand_tier_limits)
ratchet_time_steps, tou_demand_rates = parse_urdb_tou_demand(d, year=year, n_tiers=n_tou_demand_tiers, time_steps_per_hour=time_steps_per_hour)
else
Expand Down Expand Up @@ -391,7 +391,8 @@ function parse_urdb_demand_tiers(A::Array; bigM=1.0e8)
for period in range(1, stop=length(A))
demand_max = Float64[]
for tier in A[period]
append!(demand_max, get(tier, "max", bigM))
tier_max = get(tier, "max", bigM)
append!(demand_max, min(bigM, tier_max))
end
demand_tiers[period] = demand_max
append!(demand_maxes, demand_max[end]) # TODO should this be maximum(demand_max)?
Expand Down
12 changes: 11 additions & 1 deletion test/runtests.jl
adfarth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ else # run HiGHS tests
d["PV"]["can_wholesale"] = true
m = Model(optimizer_with_attributes(HiGHS.Optimizer, "output_flag" => false, "log_to_console" => false))
results = run_reopt(m, d)
@test results["PV"]["size_kw"] ≈ 84.029 atol=1e-3 #max benefit provides the upper bound
@test results["PV"]["size_kw"] ≈ 7440.0 atol=1e-3 #max benefit provides the upper bound

end
end
Expand Down Expand Up @@ -1186,6 +1186,16 @@ else # run HiGHS tests
@test results["PV"]["size_kw"] ≈ p.s.pvs[1].existing_kw
end

@testset "Multi-tier demand rates" begin
#This test ensures that when multiple demand regimes are included that the tier limits load appropriately
d = JSON.parsefile("./scenarios/no_techs.json")
d["ElectricTariff"] = Dict()
d["ElectricTariff"]["urdb_response"] = JSON.parsefile("./scenarios/multi_tier_urdb_response.json")
s = Scenario(d)
p = REoptInputs(s)
@test p.s.electric_tariff.tou_demand_tier_limits[1] ≈ 100.0 atol=1.0e-4
end

@testset "Tiered TOU Demand" begin
data = JSON.parsefile("./scenarios/tiered_tou_demand.json")
model = Model(optimizer_with_attributes(HiGHS.Optimizer, "output_flag" => false, "log_to_console" => false))
Expand Down
Loading
Loading