Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor hopp solver #305

Merged
merged 15 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
126 changes: 112 additions & 14 deletions hopp/simulation/technologies/dispatch/grid_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

import pyomo.environ as pyomo
from pyomo.network import Port, Arc
from pyomo.environ import units as u
Expand All @@ -6,24 +8,29 @@


class GridDispatch(Dispatch):
grid_obj: Union[pyomo.Expression, float]
_model: pyomo.ConcreteModel
_blocks: pyomo.Block
"""

"""

def __init__(self,
pyomo_model: pyomo.ConcreteModel,
index_set: pyomo.Set,
system_model,
financial_model,
block_set_name: str = 'grid'):
def __init__(
self,
pyomo_model: pyomo.ConcreteModel,
index_set: pyomo.Set,
system_model,
financial_model,
block_set_name: str = 'grid',
):

super().__init__(pyomo_model,
index_set,
system_model,
financial_model,
block_set_name=block_set_name)
super().__init__(
pyomo_model,
index_set,
system_model,
financial_model,
block_set_name=block_set_name,
)

def dispatch_block_rule(self, grid):
# Parameters
Expand All @@ -35,6 +42,86 @@ def dispatch_block_rule(self, grid):
# Ports
self._create_grid_ports(grid)

def max_gross_profit_objective(self, blocks):
self.obj = pyomo.Expression(
bayc marked this conversation as resolved.
Show resolved Hide resolved
expr=sum(
blocks[t].time_weighting_factor
* self.blocks[t].time_duration
* self.blocks[t].electricity_sell_price
* blocks[t].electricity_sold
- (1/blocks[t].time_weighting_factor)
* self.blocks[t].time_duration
* self.blocks[t].electricity_purchase_price
* blocks[t].electricity_purchased
- self.blocks[t].epsilon
* self.blocks[t].is_generating
for t in blocks.index_set()
)
)

def min_operating_cost_objective(self, blocks):
self.obj = sum(
blocks[t].time_weighting_factor
* self.blocks[t].time_duration
* self.blocks[t].electricity_sell_price
* (
self.blocks[t].generation_transmission_limit
- blocks[t].electricity_sold
)
+ (
blocks[t].time_weighting_factor
* self.blocks[t].time_duration
* self.blocks[t].electricity_purchase_price
* blocks[t].electricity_purchased
)
+ (
self.blocks[t].epsilon
* self.blocks[t].is_generating
)
for t in blocks.index_set()
)

def _create_variables(self, hybrid):
hybrid.system_generation = pyomo.Var(
doc="System generation [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
)
hybrid.system_load = pyomo.Var(
doc="System load [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
)
hybrid.electricity_sold = pyomo.Var(
doc="Electricity sold [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
)
hybrid.electricity_purchased = pyomo.Var(
doc="Electricity purchased [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
)

return 0, 0

def _create_port(self, hybrid):
hybrid.grid_port = Port(
initialize={
'system_generation': hybrid.system_generation,
'system_load': hybrid.system_load,
'electricity_sold': hybrid.electricity_sold,
'electricity_purchased': hybrid.electricity_purchased,
}
)
return hybrid.grid_port

def _create_constraints(self, hybrid, t):
hybrid.generation_total = pyomo.Constraint(
doc="hybrid system generation total",
rule=hybrid.system_generation == sum(self.power_source_gen_vars[t]),
)

@staticmethod
def _create_grid_parameters(grid):
##################################
Expand Down Expand Up @@ -112,15 +199,24 @@ def _create_grid_constraints(grid):
##################################
grid.balance = pyomo.Constraint(
doc="Transmission energy balance",
expr=grid.electricity_sold - grid.electricity_purchased == grid.system_generation - grid.system_load
expr=(
grid.electricity_sold
- grid.electricity_purchased
== grid.system_generation
- grid.system_load
)
)
grid.sales_transmission_limit = pyomo.Constraint(
doc="Transmission limit on electricity sales",
expr=grid.electricity_sold <= grid.generation_transmission_limit * grid.is_generating
)
grid.purchases_transmission_limit = pyomo.Constraint(
doc="Transmission limit on electricity purchases",
expr=grid.electricity_purchased <= grid.load_transmission_limit * (1 - grid.is_generating)
expr=(
grid.electricity_purchased
<= grid.load_transmission_limit
* (1 - grid.is_generating)
)
)

@staticmethod
Expand Down Expand Up @@ -184,7 +280,9 @@ def generation_transmission_limit(self) -> list:
def generation_transmission_limit(self, limit_mw: list):
if len(limit_mw) == len(self.blocks):
for t, limit in zip(self.blocks, limit_mw):
self.blocks[t].generation_transmission_limit.set_value(round(limit, self.round_digits))
self.blocks[t].generation_transmission_limit.set_value(
round(limit, self.round_digits)
)
else:
raise ValueError("'limit_mw' list must be the same length as time horizon")

Expand Down