Skip to content

Commit

Permalink
Merge pull request #1443 from quintel/offshore-converter-constraint
Browse files Browse the repository at this point in the history
Add constraint for hybrid offshore converter
  • Loading branch information
kndehaan authored Jun 26, 2024
2 parents 796093a + 9ef68de commit a755514
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ gem 'parallel'
gem 'ruby-progressbar'

# own gems
gem 'quintel_merit', ref: '918bd4d', github: 'quintel/merit'
gem 'quintel_merit', ref: '76f2343', github: 'quintel/merit'
gem 'atlas', ref: 'd71240e', github: 'quintel/atlas'
gem 'fever', ref: '2a91194', github: 'quintel/fever'
gem 'refinery', ref: '5439199', github: 'quintel/refinery'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ GIT

GIT
remote: https://github.com/quintel/merit.git
revision: 918bd4da31f115da990ea4a7162df9dac227c806
ref: 918bd4d
revision: 76f23430d584e27f023f4ab635c3a3691a291709
ref: 76f2343
specs:
quintel_merit (0.1.0)
numo-narray
Expand Down
8 changes: 8 additions & 0 deletions app/models/qernel/merit_facade/hybrid_offshore_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module MeritFacade
#
class HybridOffshoreAdapter < AlwaysOnAdapter
attr_reader :converter_curve
attr_reader :converter_constraint_curve

def initialize(node, context)
super
Expand All @@ -48,6 +49,10 @@ def initialize(node, context)
@output_input_capacity = (
output_node.node_api.input_capacity * output_node.node_api.number_of_units
)
# Output capacity of the input node
@input_output_capacity = (
input_node.node_api.electricity_output_capacity * input_node.node_api.number_of_units
)
# Input capacity of the converter node
@converter_input_capacity = (
converter_node.node_api.input_capacity *
Expand All @@ -57,6 +62,7 @@ def initialize(node, context)

@clearing = Array.new(8760, 0.0)
@curtailed = Array.new(8760, 0.0)
@converter_constraint_curve = Array.new(8760, @input_output_capacity)

@converter_curve = Qernel::Causality::ActiveLazyCurve.new do |frame|
@clearing[frame] * -1
Expand Down Expand Up @@ -130,6 +136,8 @@ def constrain(point, amount)
to_market = [amount - converted, @output_input_capacity].min
@curtailed[point] = amount - converted - to_market

@converter_constraint_curve[point] = [to_market, @input_output_capacity].max

to_market
end

Expand Down
17 changes: 16 additions & 1 deletion app/models/qernel/merit_facade/satisfied_demand_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ module MeritFacade
# A flex consumer whose demand is partly satisfied directly by another
# participant. Currently, the adapter satisfying the demand has to be of type
# HybridOffshore.
# Optionally, the related participant can also constrain the energy this
# partcicipant is allowed to bid on the market.
class SatisfiedDemandAdapter < FlexAdapter
private

def producer_attributes
attrs = super

attrs[:satisfied_demand_curve] = satisfied_demand_curve
attrs[:constraint] = -> (point, amount) { constrain(point, amount) }

attrs
end
Expand All @@ -21,7 +24,19 @@ def producer_class
end

def satisfied_demand_curve
@context.plugin.adapters[@config.relations[:input].to_sym].converter_curve
related_adapter.converter_curve
end

def constraint_curve
@constraint_curve ||= related_adapter.converter_constraint_curve
end

def constrain(point, amount)
[constraint_curve[point], amount].min
end

def related_adapter
@context.plugin.adapters[@config.relations[:input].to_sym]
end
end
end
Expand Down

0 comments on commit a755514

Please sign in to comment.