Skip to content

Commit

Permalink
added proper writing of files
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliocanor committed Jan 27, 2023
1 parent f7d5933 commit 2768a81
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/model/resources/thermal_storage/thermal_storage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function thermal_storage(EP::Model, inputs::Dict, setup::Dict)
- (1 / dfGen[y, :Eff_Down] * dfGen[y, :Start_Fuel_MMBTU_per_MW] * dfGen[y,:Cap_Size] * EP[:vSTART][y,t])
+ (dfGen[y,:Eff_Up] * vCP[y,t])
- (dfGen[y,:Self_Disch] * vTS[y,t-1])
+ (vRH[y, t])) #100% resistive heating efficiency
+ vRH[y, t]) #100% resistive heating efficiency
)

# add resistive heating to power balance
Expand Down
76 changes: 54 additions & 22 deletions src/write_outputs/write_thermal_storage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ received this license file. If not, see <http://www.gnu.org/licenses/>.



function write_core_behaviors(EP::Model, inputs::Dict, symbol::Symbol, filename::AbstractString)
function write_core_behaviors(EP::Model, inputs::Dict, symbol::Symbol, SET::Vector{Int}, filename::AbstractString)
dfTS = inputs["dfTS"]
T = inputs["T"]

df = DataFrame(Resource = dfTS.Resource, Zone = dfTS.Zone)
THERMAL_STORAGE = dfTS.R_ID
event = value.(EP[symbol][THERMAL_STORAGE,:]).data
resources = by_rid_df(SET, :Resource, dfTS)
zones = by_rid_df(SET, :Zone, dfTS)

df = DataFrame(Resource = resources, Zone = zones)
event = value.(EP[symbol][SET,:]).data
df.Sum = vec(sum(event, dims=2))

df = hcat(df, DataFrame(event, :auto))
Expand All @@ -37,13 +39,15 @@ function write_core_behaviors(EP::Model, inputs::Dict, symbol::Symbol, filename:
return df
end

function write_scaled_values(EP::Model, inputs::Dict, symbol::Symbol, filename::AbstractString, msf)
function write_scaled_values(EP::Model, inputs::Dict, symbol::Symbol, SET::Vector{Int}, filename::AbstractString, msf)
dfTS = inputs["dfTS"]
T = inputs["T"]

df = DataFrame(Resource = dfTS.Resource, Zone=dfTS.Zone)
THERMAL_STORAGE = dfTS.R_ID
quantity = value.(EP[symbol][THERMAL_STORAGE,:]).data * msf
resources = by_rid_df(SET, :Resource, dfTS)
zones = by_rid_df(SET, :Zone, dfTS)

df = DataFrame(Resource = resources, Zone=zones)
quantity = value.(EP[symbol][SET, :]).data * msf
df.AnnualSum = quantity * inputs["omega"]

df = hcat(df, DataFrame(quantity, :auto))
Expand Down Expand Up @@ -96,40 +100,68 @@ function write_thermal_storage(path::AbstractString, inputs::Dict, setup::Dict,
corecapenergy[i] = first(value.(EP[:vTSCAP][dfTS[i,:R_ID]]))
end

rhcapacity = zeros(TSG)
for i in 1:TSG
if dfTS[i, :RH] == 1
rhcapacity[i] = first(value.(EP[:vRHCAP][dfTS[i,:R_ID]]))
else
rhcapacity[i] = 0
end
end

dfCoreCap = DataFrame(
Resource = TSResources, Zone = dfTS[!,:Zone],
CorePowerCap = corecappower[:],
TSEnergyCap = corecapenergy[:]
TSEnergyCap = corecapenergy[:],
RHPowerCap = rhcapacity[:]
)

# set a single scalar to avoid future branching
msf = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1

dfCoreCap.CorePowerCap = dfCoreCap.CorePowerCap * msf
dfCoreCap.TSEnergyCap = dfCoreCap.TSEnergyCap * msf
dfCoreCap.RHPowerCap = dfCoreCap.RHPowerCap * msf
CSV.write(joinpath(path,"TS_capacity.csv"), dfCoreCap)

THERMAL_STORAGE = dfTS.R_ID
RH = dfTS[dfTS.RH .==1, :R_ID]
FUS = dfTS[dfTS.FUS .== 1, :R_ID]
NONFUS = dfTS[dfTS.FUS .== 0, :R_ID]
### CORE POWER TIME SERIES ###
dfCorePwr = write_scaled_values(EP, inputs, :vCP, joinpath(path, "TSCorePwr.csv"), msf)
dfCorePwr = write_scaled_values(EP, inputs, :vCP, THERMAL_STORAGE, joinpath(path, "TS_CorePwr.csv"), msf)

### THERMAL SOC TIME SERIES ###
dfTSOC = write_scaled_values(EP, inputs, :vTS, joinpath(path, "TS_SOC.csv"), msf)
dfTSOC = write_scaled_values(EP, inputs, :vTS, THERMAL_STORAGE, joinpath(path, "TS_SOC.csv"), msf)

### RESISTIVE HEATING TIME SERIES ###
if !isempty(RH)
dfRH = write_scaled_values(EP, inputs, :vRH, RH, joinpath(path, "TS_RH.csv"), msf)
end

### FUSION SPECIFIC OUTPUTS ###
if !isempty(FUS)
### RECIRCULATING POWER TIME SERIES ###
dfRecirc = write_scaled_values(EP, inputs, :eTotalRecircFus, FUS, joinpath(path, "TS_Recirc.csv"), msf)

### RECIRCULATING POWER TIME SERIES ###
dfRecirc = write_scaled_values(EP, inputs, :eTotalRecircFus, joinpath(path, "TS_Recirc.csv"), msf)
### CORE STARTS, SHUTS, COMMITS, and MAINTENANCE TIMESERIES ###
dfFStart = write_core_behaviors(EP, inputs, :vFSTART, FUS, joinpath(path, "TS_FUS_start.csv"))
dfFShut = write_core_behaviors(EP, inputs, :vFSHUT, FUS, joinpath(path, "TS_FUS_shut.csv"))
dfFCommit = write_core_behaviors(EP, inputs, :vFCOMMIT, FUS, joinpath(path, "TS_FUS_commit.csv"))

### CORE STARTS, SHUTS, COMMITS, and MAINTENANCE TIMESERIES ###
dfFStart = write_core_behaviors(EP, inputs, :vFSTART, joinpath(path, "f_start.csv"))
dfFShut = write_core_behaviors(EP, inputs, :vFSHUT, joinpath(path, "f_shut.csv"))
dfFCommit = write_core_behaviors(EP, inputs, :vFCOMMIT, joinpath(path, "f_commit.csv"))
if setup["OperationWrapping"] == 0 && !isempty(get_maintenance(inputs))
dfMaint = write_core_behaviors(EP, inputs, :vFMDOWN, FUS, joinpath(path, "TS_FUS_maint.csv"))
dfMShut = write_core_behaviors(EP, inputs, :vFMSHUT, FUS, joinpath(path, "TS_FUS_maintshut.csv"))
end
end

if setup["OperationWrapping"] == 0 && !isempty(get_maintenance(inputs))
dfMaint = write_core_behaviors(EP, inputs, :vFMDOWN, joinpath(path, "f_maint.csv"))
dfMShut = write_core_behaviors(EP, inputs, :vFMSHUT, joinpath(path, "f_maintshut.csv"))
### NON FUS CORE STARTS, SHUTS, COMMITS ###
if (!isempty(NONFUS) && setup["UCommit"] > 0)
dfNStart = write_core_behaviors(EP, inputs, :vCSTART, NONFUS, joinpath(path, "TS_NONFUS_start.csv"))
dfNShut = write_core_behaviors(EP, inputs, :vCSHUT, NONFUS, joinpath(path, "TS_NONFUS_shut.csv"))
dfNCommit = write_core_behaviors(EP, inputs, :vCCOMMIT, NONFUS, joinpath(path, "TS_NONFUS_commit.csv"))
end

# Write dual values of certain constraints
write_thermal_storage_system_max_dual(path, inputs, setup, EP)

return dfCoreCap, dfCorePwr, dfTSOC, dfFStart, dfFShut, dfFCommit
end

0 comments on commit 2768a81

Please sign in to comment.