-
Notifications
You must be signed in to change notification settings - Fork 122
/
write_storagedual.jl
89 lines (80 loc) · 3.89 KB
/
write_storagedual.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
@doc raw"""
write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
Function for reporting dual of storage level (state of charge) balance of each resource in each time step.
"""
function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
gen = inputs["RESOURCES"]
zones = zone_id.(gen)
zones = convert.(Float64,zones)
G = inputs["G"] # Number of resources (generators, storage, DR, and DERs)
T = inputs["T"] # Number of time steps (hours)
START_SUBPERIODS = inputs["START_SUBPERIODS"]
INTERIOR_SUBPERIODS = inputs["INTERIOR_SUBPERIODS"]
REP_PERIOD = inputs["REP_PERIOD"]
STOR_ALL = inputs["STOR_ALL"]
VRE_STOR = inputs["VRE_STOR"]
if !isempty(VRE_STOR)
VS_STOR = inputs["VS_STOR"]
VS_LDS = inputs["VS_LDS"]
VS_NONLDS = setdiff(VS_STOR, VS_LDS)
end
# # Dual of storage level (state of charge) balance of each resource in each time step
dfStorageDual = DataFrame(Resource = inputs["RESOURCE_NAMES"], Zone = zones)
dual_values = zeros(G, T)
# Loop over W separately hours_per_subperiod
if !isempty(STOR_ALL)
STOR_ALL_NONLDS = setdiff(STOR_ALL, inputs["STOR_LONG_DURATION"])
STOR_ALL_LDS = intersect(STOR_ALL, inputs["STOR_LONG_DURATION"])
dual_values[STOR_ALL, INTERIOR_SUBPERIODS] = (dual.(EP[:cSoCBalInterior][
INTERIOR_SUBPERIODS,
STOR_ALL]).data ./ inputs["omega"][INTERIOR_SUBPERIODS])'
dual_values[STOR_ALL_NONLDS, START_SUBPERIODS] = (dual.(EP[:cSoCBalStart][
START_SUBPERIODS,
STOR_ALL_NONLDS]).data ./ inputs["omega"][START_SUBPERIODS])'
if !isempty(STOR_ALL_LDS)
if inputs["REP_PERIOD"] > 1
dual_values[STOR_ALL_LDS, START_SUBPERIODS] = (dual.(EP[:cSoCBalLongDurationStorageStart][
1:REP_PERIOD,
STOR_ALL_LDS]).data ./ inputs["omega"][START_SUBPERIODS])'
else
dual_values[STOR_ALL_LDS, START_SUBPERIODS] = (dual.(EP[:cSoCBalStart][
START_SUBPERIODS,
STOR_ALL_LDS]).data ./ inputs["omega"][START_SUBPERIODS])'
end
end
end
if !isempty(VRE_STOR)
dual_values[VS_STOR, INTERIOR_SUBPERIODS] = ((dual.(EP[:cSoCBalInterior_VRE_STOR][
VS_STOR,
INTERIOR_SUBPERIODS]).data)' ./ inputs["omega"][INTERIOR_SUBPERIODS])'
dual_values[VS_NONLDS, START_SUBPERIODS] = ((dual.(EP[:cSoCBalStart_VRE_STOR][
VS_NONLDS,
START_SUBPERIODS]).data)' ./ inputs["omega"][START_SUBPERIODS])'
if !isempty(VS_LDS)
if inputs["REP_PERIOD"] > 1
dual_values[VS_LDS, START_SUBPERIODS] = ((dual.(EP[:cVreStorSoCBalLongDurationStorageStart][
VS_LDS,
1:REP_PERIOD]).data)' ./ inputs["omega"][START_SUBPERIODS])'
else
dual_values[VS_LDS, START_SUBPERIODS] = ((dual.(EP[:cSoCBalStart_VRE_STOR][
VS_LDS,
START_SUBPERIODS]).data)' ./ inputs["omega"][START_SUBPERIODS])'
end
end
end
if setup["ParameterScale"] == 1
dual_values *= ModelScalingFactor
end
dfStorageDual = hcat(dfStorageDual, DataFrame(dual_values, :auto))
rename!(dfStorageDual,
["Resource"; "Zone"; [String("t$t") for t in 1:T]])
write_output_file(joinpath(path, setup["WriteResultsNamesDict"]["storagebal_duals"]),
dftranspose(dfStorageDual, true),
filetype = setup["ResultsFileType"],
compression = setup["ResultsCompressionType"])
if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1
write_full_time_series_reconstruction(
path, setup, dftranspose(dfStorageDual, true), setup["WriteResultsNamesDict"]["storagebal_duals"])
@info("Writing Full Time Series for Storage Duals")
end
end