Skip to content

Commit

Permalink
move the variable and port generation from hybrid_dispatch into respe…
Browse files Browse the repository at this point in the history
…ctive technology dispatches
  • Loading branch information
bayc committed Apr 6, 2024
1 parent 8482bc1 commit 223fc0c
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 160 deletions.
33 changes: 33 additions & 0 deletions hopp/simulation/technologies/dispatch/grid_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,39 @@ def min_operating_cost_objective(self, blocks):
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,
)

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

@staticmethod
def _create_grid_parameters(grid):
##################################
Expand Down
178 changes: 23 additions & 155 deletions hopp/simulation/technologies/dispatch/hybrid_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ def dispatch_block_rule(self, hybrid, t):
##################################
# Variables / Ports #
##################################
for tech in self.power_sources.keys():
try:
getattr(self, "_create_" + tech + "_variables")(hybrid, t)
getattr(self, "_create_" + tech + "_port")(hybrid, t)
except AttributeError:
raise ValueError("'{}' is not supported in the hybrid dispatch model.".format(tech))
except Exception as e:
raise RuntimeError("Error in setting up dispatch for {}: {}".format(tech, e))
self._create_variables_and_ports(hybrid, t)
##################################
# Constraints #
##################################
Expand All @@ -78,153 +71,28 @@ def _create_parameters(hybrid):
units=u.dimensionless,
)

def _create_pv_variables(self, hybrid, t):
hybrid.pv_generation = pyomo.Var(
doc="Power generation of photovoltaics [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
self.power_source_gen_vars[t].append(hybrid.pv_generation)

def _create_pv_port(self, hybrid, t):
hybrid.pv_port = Port(initialize={'generation': hybrid.pv_generation})
self.ports[t].append(hybrid.pv_port)

def _create_wind_variables(self, hybrid, t):
hybrid.wind_generation = pyomo.Var(
doc="Power generation of wind turbines [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
self.power_source_gen_vars[t].append(hybrid.wind_generation)

def _create_wind_port(self, hybrid, t):
hybrid.wind_port = Port(initialize={'generation': hybrid.wind_generation})
self.ports[t].append(hybrid.wind_port)

def _create_wave_variables(self, hybrid, t):
hybrid.wave_generation = pyomo.Var(
doc="Power generation of wave devices [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
self.power_source_gen_vars[t].append(hybrid.wave_generation)

def _create_wave_port(self, hybrid, t):
hybrid.wave_port = Port(initialize={'generation': hybrid.wave_generation})
self.ports[t].append(hybrid.wave_port)

def _create_tower_variables(self, hybrid, t):
hybrid.tower_generation = pyomo.Var(
doc="Power generation of CSP tower [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
hybrid.tower_load = pyomo.Var(
doc="Load of CSP tower [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
self.power_source_gen_vars[t].append(hybrid.tower_generation)
self.load_vars[t].append(hybrid.tower_load)

def _create_tower_port(self, hybrid, t):
hybrid.tower_port = Port(
initialize={
'cycle_generation': hybrid.tower_generation,
'system_load': hybrid.tower_load,
}
)
self.ports[t].append(hybrid.tower_port)

def _create_trough_variables(self, hybrid, t):
hybrid.trough_generation = pyomo.Var(
doc="Power generation of CSP trough [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
hybrid.trough_load = pyomo.Var(
doc="Load of CSP trough [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
self.power_source_gen_vars[t].append(hybrid.trough_generation)
self.load_vars[t].append(hybrid.trough_load)

def _create_trough_port(self, hybrid, t):
hybrid.trough_port = Port(
initialize={
'cycle_generation': hybrid.trough_generation,
'system_load': hybrid.trough_load,
}
)
self.ports[t].append(hybrid.trough_port)

def _create_battery_variables(self, hybrid, t):
hybrid.battery_charge = pyomo.Var(
doc="Power charging the electric battery [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
hybrid.battery_discharge = pyomo.Var(
doc="Power discharging the electric battery [MW]",
domain=pyomo.NonNegativeReals,
units=u.MW,
initialize=0.0,
)
self.power_source_gen_vars[t].append(hybrid.battery_discharge)
self.load_vars[t].append(hybrid.battery_charge)

def _create_battery_port(self, hybrid, t):
hybrid.battery_port = Port(
initialize={
'charge_power': hybrid.battery_charge,
'discharge_power': hybrid.battery_discharge,
}
)
self.ports[t].append(hybrid.battery_port)

@staticmethod
def _create_grid_variables(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,
)

def _create_grid_port(self, hybrid, t):
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,
}
)
self.ports[t].append(hybrid.grid_port)
def _create_variables_and_ports(self, hybrid, t):
for tech in self.power_sources.keys():
try:
# getattr(self, "_create_" + tech + "_variables")(hybrid, t)
# getattr(self, "_create_" + tech + "_port")(hybrid, t)

if tech in ["battery", "tower", "trough"]:
gen_var, load_var = self.power_sources[tech]._dispatch._create_variables(hybrid)
self.power_source_gen_vars[t].append(gen_var)
self.load_vars[t].append(load_var)
elif tech in ["grid"]:
self.power_sources[tech]._dispatch._create_variables(hybrid)
else:
self.power_source_gen_vars[t].append(
self.power_sources[tech]._dispatch._create_variables(hybrid)
)

self.ports[t].append(self.power_sources[tech]._dispatch._create_port(hybrid))
except AttributeError:
raise ValueError("'{}' is not supported in the hybrid dispatch model.".format(tech))
except Exception as e:
raise RuntimeError("Error in setting up dispatch for {}: {}".format(tech, e))

def _create_grid_constraints(self, hybrid, t):
hybrid.generation_total = pyomo.Constraint(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from pyomo.environ import ConcreteModel, Expression, Set
from pyomo.environ import ConcreteModel, Expression, NonNegativeReals, Set, units, Var
from pyomo.network import Port

import PySAM.Pvsamv1 as Pvsam
import PySAM.Pvwattsv8 as Pvwatts
Expand Down Expand Up @@ -56,3 +57,16 @@ def min_operating_cost_objective(self, blocks):
* blocks[t].pv_generation
for t in blocks.index_set()
)

def _create_variables(self, hybrid) -> Var:
hybrid.pv_generation = Var(
doc="Power generation of photovoltaics [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
return hybrid.pv_generation

def _create_port(self, hybrid) -> Port:
hybrid.pv_port = Port(initialize={'generation': hybrid.pv_generation})
return hybrid.pv_port
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from pyomo.environ import ConcreteModel, Expression, Set
from pyomo.environ import ConcreteModel, Expression, NonNegativeReals, Set, units, Var
from pyomo.network import Port

from hopp.simulation.technologies.financial import FinancialModelType
from hopp.simulation.technologies.dispatch.power_sources.csp_dispatch import CspDispatch
Expand Down Expand Up @@ -109,3 +110,27 @@ def min_operating_cost_objective(self, blocks):
)
for t in blocks.index_set()
)

def _create_variables(self, hybrid):
hybrid.tower_generation = Var(
doc="Power generation of CSP tower [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
hybrid.tower_load = Var(
doc="Load of CSP tower [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
return hybrid.tower_generation, hybrid.tower_load

def _create_port(self, hybrid):
hybrid.tower_port = Port(
initialize={
'cycle_generation': hybrid.tower_generation,
'system_load': hybrid.tower_load,
}
)
return hybrid.tower_port
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from pyomo.environ import ConcreteModel, Expression, Set
from pyomo.environ import ConcreteModel, Expression, NonNegativeReals, Set, units, Var
from pyomo.network import Port

from hopp.simulation.technologies.financial import FinancialModelType
from hopp.simulation.technologies.dispatch.power_sources.csp_dispatch import CspDispatch
Expand Down Expand Up @@ -93,3 +94,27 @@ def min_operating_cost_objective(self, blocks):
)
for t in blocks.index_set()
)

def _create_variables(self, hybrid):
hybrid.trough_generation = Var(
doc="Power generation of CSP trough [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
hybrid.trough_load = Var(
doc="Load of CSP trough [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
return hybrid.trough_generation, hybrid.trough_load

def _create_trough_port(self, hybrid):
hybrid.trough_port = Port(
initialize={
'cycle_generation': hybrid.trough_generation,
'system_load': hybrid.trough_load,
}
)
return hybrid.trough_port
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from pyomo.environ import ConcreteModel, Expression, Set
from pyomo.environ import ConcreteModel, Expression, NonNegativeReals, Set, units, Var
from pyomo.network import Port

import PySAM.MhkWave as MhkWave

Expand Down Expand Up @@ -51,3 +52,16 @@ def min_operating_cost_objective(self, blocks):
* blocks[t].wave_generation
for t in blocks.index_set()
)

def _create_variables(self, hybrid) -> Var:
hybrid.wave_generation = Var(
doc="Power generation of wind turbines [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
return hybrid.wave_generation

def _create_port(self, hybrid) -> Port:
hybrid.wave_port = Port(initialize={'generation': hybrid.wave_generation})
return hybrid.wave_port
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union, TYPE_CHECKING
from pyomo.environ import ConcreteModel, Expression, Set
from pyomo.environ import ConcreteModel, Expression, NonNegativeReals, Set, units, Var
from pyomo.network import Port

import PySAM.Windpower as Windpower

Expand Down Expand Up @@ -54,3 +55,16 @@ def min_operating_cost_objective(self, blocks):
* blocks[t].wind_generation
for t in blocks.index_set()
)

def _create_variables(self, hybrid) -> Var:
hybrid.wind_generation = Var(
doc="Power generation of wind turbines [MW]",
domain=NonNegativeReals,
units=units.MW,
initialize=0.0,
)
return hybrid.wind_generation

def _create_port(self, hybrid) -> Port:
hybrid.wind_port = Port(initialize={'generation': hybrid.wind_generation})
return hybrid.wind_port

0 comments on commit 223fc0c

Please sign in to comment.