Skip to content

Commit

Permalink
add ability to collect zonal data
Browse files Browse the repository at this point in the history
  • Loading branch information
cfe316 committed Nov 29, 2023
1 parent db7fc8b commit 7d9720b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/model/resources/fusion/fusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const FUSION_PULSE_UNDERWAY = "FusionPulseUnderwayVariables"
const FUSION_PARASITIC_POWER = "FusionParasiticPowerExpressions"
const FUSION_PULSE_START_POWER = "FusionPulseStartPowerExpressions"

const FUSION_COMPONENT_ZONE = "FusionComponentZones"

function fusion_pulse_start_name(resource_component::AbstractString)::String
"vFusionPulseStart_" * resource_component
end
Expand Down Expand Up @@ -44,6 +46,32 @@ function fusion_parasitic_power_expressions(dict::Dict)::Set{Symbol}
dict[FUSION_PARASITIC_POWER]
end

@doc raw"""
fusion_parasitic_power_expressions(inputs::Dict, zone::Int)
inputs: model inputs
get listings of parasitic power expressions in a zone.
This is available only after `fusion_formulation!` has been called.
"""
function fusion_parasitic_power_expressions(inputs::Dict, zone::Int)::Set{Symbol}
fusion_in_zone = inputs[FUSION_COMPONENT_ZONE][zone]
exprs = Symbol.(fusion_parasitic_total_name.(fusion_in_zone))
return Set(exprs)
end

@doc raw"""
fusion_parasitic_power_expressions(dict::Dict, zone::Int)
dict: a dictionary of model data
get listings of parasitic power expressions.
This is available only after `fusion_formulation!` has been called.
"""
function fusion_parasitic_power_expressions(dict::Dict, zone::Int)::Set{Symbol}
dict[FUSION_COMPONENT_ZONE]
end

@doc raw"""
fusion_pulse_start_expressions(dict::Dict)
Expand All @@ -70,8 +98,24 @@ function ensure_fusion_expression_records!(dict::Dict)
dict[var] = Set{Symbol}()
end
end
var = FUSION_COMPONENT_ZONE
if var keys(dict)
dict[var] = Dict{Int, Set{AbstractString}}()
end
end

function add_fusion_component_to_zone_listing(inputs::Dict, r_id::Int, resource_component::AbstractString)
zone = inputs["R_ZONES"][r_id]
d = inputs[FUSION_COMPONENT_ZONE]
new_set = Set([resource_component])
if zone in keys(d)
union!(d[zone], new_set)
else
d[zone] = new_set
end
end


# Base.@kwdef could be used if we enforce Julia >= 1.9
# That would replace need for the keyword-argument constructor below
struct FusionReactorData
Expand Down
2 changes: 2 additions & 0 deletions src/model/resources/thermal/thermal_commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ function fusion_formulation_thermal_commit!(EP::Model, inputs::Dict, setup::Dict
fusion_pulse_status_linking_constraints!(EP, inputs, name, y, reactor, :vCOMMIT)
fusion_pulse_thermal_power_generation_constraint!(EP, inputs, name, y, reactor, power_like)
fusion_parasitic_power!(EP, inputs, name, y, reactor, :eTotalCap)

add_fusion_component_to_zone_listing(inputs, y, name)
end
end

23 changes: 22 additions & 1 deletion src/write_outputs/write_fusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@ end
Prepare a vector of total fusion parasitic power, with values in MW.
"""
function prepare_fusion_total_parasitic_power(EP::Model, inputs::Dict, setup::Dict)::DataFrame
function prepare_fusion_total_parasitic_power(EP::Model, inputs::Dict, setup::Dict)::Vector{Float64}
df = prepare_fusion_parasitic_power(EP, inputs, setup)
return sum(eachcol(df))
end

@doc raw"""
prepare_fusion_total_parasitic_power(EP::Model, inputs::Dict, setup::Dict, zone::Int)::DataFrame
Prepare a vector of total fusion parasitic power in a zone, with values in MW.
"""
function prepare_fusion_total_parasitic_power(EP::Model, inputs::Dict, setup::Dict, zone::Int)::Vector{Float64}
return scale * prepare_fusion_total_parasitic_power_unscaled(EP, inputs, zone)
end

@doc raw"""
fusion_total_parasitic_power_unscaled(EP::Model, inputs::Dict, zone::Int)::DataFrame
Prepare a vector of total fusion parasitic power in a zone, with values in MW.
"""
function fusion_total_parasitic_power_unscaled(EP::Model, inputs::Dict, zone::Int)::Vector{Float64}
parasitic_expressions = fusion_parasitic_power_expressions(inputs, zone)
df = prepare_timeseries_variables(EP, parasitic_expressions)
@info df
return sum(eachcol(df))
end

@doc raw"""
prepare_fusion_pulse_starts(EP::Model, inputs::Dict, setup::Dict)::DataFrame
Expand Down

0 comments on commit 7d9720b

Please sign in to comment.