Skip to content

Commit

Permalink
Merge pull request #223 from NREL/develop
Browse files Browse the repository at this point in the history
PVWatts timeout fix; add wind to outage_simulator
  • Loading branch information
hdunham authored Apr 24, 2023
2 parents cb50b08 + fc2f6e8 commit 2a6852b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Classify the change according to the following categories:
### Deprecated
### Removed

## v0.32.0
### Fixed
- Fixed calculation of `wind_kw_ac_hourly` in `outagesim/outage_simulator.jl`
- Add a test of multiple outages that includes wind
### Fixed
- Add a timeout to PVWatts API call so that if it does not connect within 10 seconds, it will retry. It seems to always work on the first retry.

## v0.31.0
### Added
- Created and exported easiur_data function (returns health emissions costs and escalations) for the API to be able to call for it's easiur_costs endpoint
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "REopt"
uuid = "d36ad4e8-d74a-4f7a-ace1-eaea049febf6"
authors = ["Nick Laws", "Hallie Dunham <[email protected]>", "Bill Becker <[email protected]>", "Bhavesh Rathod <[email protected]>", "Alex Zolan <[email protected]>", "Amanda Farthing <[email protected]>"]
version = "0.31.0"
version = "0.32.0"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand Down
3 changes: 2 additions & 1 deletion src/core/production_factor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function get_production_factor(pv::PV, latitude::Real, longitude::Real; timefram

try
@info "Querying PVWatts for production_factor with " pv.name
r = HTTP.get(url)
r = HTTP.get(url, keepalive=true, readtimeout=10)
@info "Response received from PVWatts"
response = JSON.parse(String(r.body))
if r.status != 200
throw(@error("Bad response from PVWatts: $(response["errors"])"))
Expand Down
19 changes: 13 additions & 6 deletions src/outagesim/outage_simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ function simulate_outages(;batt_kwh=0, batt_kw=0, pv_kw_ac_hourly=[], init_soc=[
if batt_kw == 0 || batt_kwh == 0
init_soc = repeat([0], n_time_steps) # default is 0

if (isempty(pv_kw_ac_hourly) || (sum(pv_kw_ac_hourly) == 0)) && diesel_kw == 0
# no pv, generator, nor battery --> no resilience
if (isempty(pv_kw_ac_hourly) || (sum(pv_kw_ac_hourly) == 0)) && (isempty(wind_kw_ac_hourly) || (sum(wind_kw_ac_hourly) == 0)) && diesel_kw == 0
# no pv, generator, wind, nor battery --> no resilience
return Dict(
"resilience_by_time_step" => r,
"resilience_hours_min" => 0,
Expand Down Expand Up @@ -257,16 +257,23 @@ function simulate_outages(d::Dict, p::REoptInputs; microgrid_only::Bool=false)

# TODO handle generic PV names
pv_kw_ac_hourly = zeros(length(p.time_steps))
if "PV" in keys(d)
if "PV" in keys(d) && !(microgrid_only && !Bool(get(d["Outages"], "PV_upgraded", false)))
pv_kw_ac_hourly = (
get(d["PV"], "electric_to_storage_series_kw", zeros(length(p.time_steps)))
+ get(d["PV"], "electric_curtailed_series_kw", zeros(length(p.time_steps)))
+ get(d["PV"], "electric_to_load_series_kw", zeros(length(p.time_steps)))
+ get(d["PV"], "electric_to_grid_series_kw", zeros(length(p.time_steps)))
)
end
if microgrid_only && !Bool(get(d["Outages"], "PV_upgraded", false))
pv_kw_ac_hourly = zeros(length(p.time_steps))

wind_kw_ac_hourly = zeros(length(p.time_steps))
if "Wind" in keys(d) && !(microgrid_only && !Bool(get(d["Outages"], "Wind_upgraded", false)))
wind_kw_ac_hourly = (
get(d["Wind"], "electric_to_storage_series_kw", zeros(length(p.time_steps)))
+ get(d["Wind"], "electric_curtailed_series_kw", zeros(length(p.time_steps)))
+ get(d["Wind"], "electric_to_load_series_kw", zeros(length(p.time_steps)))
+ get(d["Wind"], "electric_to_grid_series_kw", zeros(length(p.time_steps)))
)
end

batt_kwh = 0
Expand Down Expand Up @@ -303,7 +310,7 @@ function simulate_outages(d::Dict, p::REoptInputs; microgrid_only::Bool=false)
pv_kw_ac_hourly = pv_kw_ac_hourly,
init_soc = init_soc,
critical_loads_kw = p.s.electric_load.critical_loads_kw,
wind_kw_ac_hourly = [],
wind_kw_ac_hourly = wind_kw_ac_hourly,
batt_roundtrip_efficiency = batt_roundtrip_efficiency,
diesel_kw = diesel_kw,
fuel_available = p.s.generator.fuel_avail_gal,
Expand Down
11 changes: 11 additions & 0 deletions test/scenarios/outages_gen_pv_wind_stor.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions test/test_with_xpress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ end
results = run_reopt(m, "./scenarios/outages_gen_pv_stor.json")
@test results["Outages"]["expected_outage_cost"] 4.800393567995261e6 atol=10
@test results["Financial"]["lcc"] 8.9857671584e7 atol=100

# Scenario with generator, PV, wind, electric storage
m = Model(optimizer_with_attributes(Xpress.Optimizer, "OUTPUTLOG" => 0))
results = run_reopt(m, "./scenarios/outages_gen_pv_wind_stor.json")
@test value(m[:binMGTechUsed]["Generator"]) 1
@test value(m[:binMGTechUsed]["PV"]) 1
@test value(m[:binMGTechUsed]["Wind"]) 1
@test results["Outages"]["expected_outage_cost"] 50147.6 atol=1.0
@test results["Financial"]["lcc"] 6.84048993e7 rtol=0.001
end

@testset "Multiple Sites" begin
Expand Down

0 comments on commit 2a6852b

Please sign in to comment.