Skip to content

Commit

Permalink
Apply pairwise power constraint to fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
cfe316 committed Dec 14, 2023
1 parent fe56c5e commit 0ffe45f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/model/resources/fusion/fusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ function fusion_max_fpy_per_year_constraint!(
)
T = inputs["T"]
y = r_id
@info "Applying FPY constraint for $r_id"

Check warning on line 451 in src/model/resources/fusion/fusion.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/fusion/fusion.jl#L449-L451

Added lines #L449 - L451 were not covered by tests

capacity = sum(EP[component_capacity][r_id])
max_fpy_per_year = reactor.max_fpy_per_year
Expand Down
26 changes: 13 additions & 13 deletions src/model/resources/maintenance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,10 @@ end
# This also works for plants where they need maintenance every year:
# cap_maint * 0 = cap_nomain * 5 → 0 == cap_nomain
####
function capacity_proportional_link!(EP::Model, id_a, id_b, proportion_a, proportion_b)
@info "Linking capacities $id_a and $id_b in $proportion_a : $proportion_b"
cap = EP[:eTotalCap]
@constraint(EP, cap[id_a] * proportion_b == cap[id_b] * proportion_a)
end

function may_have_pairwise_capacity_links(df::DataFrame)
columns = names(df)
paired_resource = :Paired_Resource
proportion = :Resource_Pair_Proportion
proportion = :Paired_Resource_Proportion
return string(paired_resource) in columns && string(proportion) in columns
end

Expand Down Expand Up @@ -272,25 +266,31 @@ function find_paired_resources(df::DataFrame)
return linked

Check warning on line 266 in src/model/resources/maintenance.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/maintenance.jl#L266

Added line #L266 was not covered by tests
end

pairs = Pair{Int,Int}[]
_pairs = Pair{Int,Int}[]
has_link = findall(df[!, paired_resource] .!= "None")
for id_a in has_link
id_b = find_id_of_linked(id_a)
if id_a != find_id_of_linked(id_b)
error("Resources $id_a and $id_b must link to each other, via $paired_resource.")

Check warning on line 274 in src/model/resources/maintenance.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/maintenance.jl#L269-L274

Added lines #L269 - L274 were not covered by tests
end
if id_a < id_b # no need to create the constraint twice.
push!(pairs, Pair(id_a, id_b))
push!(_pairs, Pair(id_a, id_b))

Check warning on line 277 in src/model/resources/maintenance.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/maintenance.jl#L276-L277

Added lines #L276 - L277 were not covered by tests
end
end
return pairs
return _pairs

Check warning on line 280 in src/model/resources/maintenance.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/maintenance.jl#L279-L280

Added lines #L279 - L280 were not covered by tests
end

function capacity_proportional_link!(EP::Model, id_a, id_b, proportion_a, proportion_b)
@info "Linking capacities $id_a and $id_b in $proportion_a : $proportion_b"
cap = EP[:eTotalCap]
@constraint(EP, cap[id_a] * proportion_b == cap[id_b] * proportion_a)

Check warning on line 286 in src/model/resources/maintenance.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/maintenance.jl#L283-L286

Added lines #L283 - L286 were not covered by tests
end

function link_capacities!(EP::Model, df::DataFrame)
proportion = :Resource_Pair_Proportion
proportion = :Paired_Resource_Proportion

Check warning on line 290 in src/model/resources/maintenance.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/maintenance.jl#L289-L290

Added lines #L289 - L290 were not covered by tests

pairs = find_paired_resources(df)
for p in pairs
_pairs = find_paired_resources(df)
for p in _pairs
id_a = p.first
id_b = p.second
proportion_a = df[id_a, proportion]
Expand Down
13 changes: 12 additions & 1 deletion src/model/resources/thermal/thermal_commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ function fusion_formulation_thermal_commit!(EP::Model, inputs::Dict, setup::Dict

FUSION = resources_with_fusion(dfGen)

Check warning on line 414 in src/model/resources/thermal/thermal_commit.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/thermal/thermal_commit.jl#L414

Added line #L414 was not covered by tests

pairdict = Dict{Int, Int}[]
if may_have_pairwise_capacity_links(dfGen)
pairdict = Dict(find_paired_resources(dfGen))

Check warning on line 418 in src/model/resources/thermal/thermal_commit.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/thermal/thermal_commit.jl#L416-L418

Added lines #L416 - L418 were not covered by tests
end

resource_name(y) = dfGen[y, :Resource]
resource_component(y) = resource_name(y)

Check warning on line 422 in src/model/resources/thermal/thermal_commit.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/thermal/thermal_commit.jl#L421-L422

Added lines #L421 - L422 were not covered by tests

Expand All @@ -435,7 +440,13 @@ 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)

Check warning on line 442 in src/model/resources/thermal/thermal_commit.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/thermal/thermal_commit.jl#L436-L442

Added lines #L436 - L442 were not covered by tests
fusion_max_fpy_per_year_constraint!(EP, inputs, y, reactor, :eTotalCap, EP[:vP])

if y in keys(pairdict)
second = pairdict[y]
fusion_max_fpy_per_year_constraint!(EP, inputs, [y, second], reactor, :eTotalCap, EP[:vP])
elseif y values(pairdict)
fusion_max_fpy_per_year_constraint!(EP, inputs, y, reactor, :eTotalCap, EP[:vP])

Check warning on line 448 in src/model/resources/thermal/thermal_commit.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/thermal/thermal_commit.jl#L444-L448

Added lines #L444 - L448 were not covered by tests
end

add_fusion_component_to_zone_listing(inputs, y, name)
end

Check warning on line 452 in src/model/resources/thermal/thermal_commit.jl

View check run for this annotation

Codecov / codecov/patch

src/model/resources/thermal/thermal_commit.jl#L451-L452

Added lines #L451 - L452 were not covered by tests
Expand Down

0 comments on commit 0ffe45f

Please sign in to comment.