Skip to content

Commit

Permalink
updates to mergelinks option, constraints for solar collector, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
nehadimri1991 committed Oct 16, 2024
1 parent 9145154 commit ba5d370
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
27 changes: 27 additions & 0 deletions optihood/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,31 @@ def PVTElectricalThermalCapacityConstraint(om, numBuildings):
"PVTSizeConstrT2Sh_B" + str(b),
pyo.Constraint(expr=expr3),
)
return om

def STCThermalCapacityConstraint(om, numBuildings):
stcShOutFlows = [(i, o) for (i, o) in om.flows if ("heatSource_SHsolarCollector" in i.label)]
stcDhwOutFlows = [(i, o) for (i, o) in om.flows if ("heatSource_DHWsolarCollector" in i.label)]
stcT2OutFlows = [(i, o) for (i, o) in om.flows if ("heatSource_T2solarCollector" in i.label)]
for b in range(1, numBuildings + 1):
shCapacity = [om.InvestmentFlowBlock.invest[i, o] for (i, o) in stcShOutFlows if ((f'__Building{b}') in o.label)]
dhwCapacity = [om.InvestmentFlowBlock.invest[i, o] for (i, o) in stcDhwOutFlows if ((f'__Building{b}') in o.label)]
T2Capacity = [om.InvestmentFlowBlock.invest[i, o] for (i, o) in stcT2OutFlows if ((f'__Building{b}') in o.label)]
if shCapacity:
shCapacity = shCapacity[0]
dhwCapacity = dhwCapacity[0]
expr1 = (dhwCapacity == shCapacity)
setattr(
om,
"STCSizeConstrDhwSh_B" + str(b),
pyo.Constraint(expr=expr1),
)
if T2Capacity:
T2Capacity = T2Capacity[0]
expr2 = (T2Capacity == shCapacity)
setattr(
om,
"STCSizeConstrT2Sh_B" + str(b),
pyo.Constraint(expr=expr2),
)
return om
19 changes: 12 additions & 7 deletions optihood/energy_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def setFromExcel(self, filePath, numberOfBuildings, clusterSize={}, opt="costs",
self.check_mutually_exclusive_inputs(mergeLinkBuses)
self._dispatchMode = dispatchMode
self._optimizationType = opt
self._mergeBuses = mergeBuses
logging.info("Defining the energy network from the excel file: {}".format(filePath))
data = pd.ExcelFile(filePath)
initial_nodal_data = self.get_nodal_data_from_Excel(data)
Expand Down Expand Up @@ -551,6 +552,9 @@ def optimize(self, numberOfBuildings, solver, envImpactlimit=1000000, clusterSiz
# constraint on PVT capacity if PVT technology is selected
if any("pvt" in n.label for n in self.nodes):
self._optimizationModel = PVTElectricalThermalCapacityConstraint(self._optimizationModel, numberOfBuildings)
# constraint on STC capacity if STC technology is selected
if any("solarCollector" in n.label for n in self.nodes):
self._optimizationModel = STCThermalCapacityConstraint(self._optimizationModel, numberOfBuildings)
# constraint on storage content for clustering
"""if clusterSize:
self._optimizationModel = dailySHStorageConstraint(self._optimizationModel)"""
Expand Down Expand Up @@ -587,7 +591,7 @@ def optimize(self, numberOfBuildings, solver, envImpactlimit=1000000, clusterSiz

def printbuildingModelTemperatures(self, filename):
df = pd.DataFrame()
df["timestamp"] = self.timeindex
df["timestamp"] = self.timeindex[0:-1]
for i in range(self.__noOfBuildings):
bNo = i + 1
tIndoor = [v for k, v in self._optimizationModel.SinkRCModelBlock.tIndoor.get_values().items() if
Expand Down Expand Up @@ -618,12 +622,12 @@ def saveUnprocessedResults(self, resultFile):
with pd.ExcelWriter(resultFile) as writer:
busLabelList = []
for i in self.nodes:
if str(type(i)).replace("<class 'oemof.solph.", "").replace("'>", "") == "network.bus.Bus":
if str(type(i)).replace("<class 'oemof.solph.", "").replace("'>", "") == "buses._bus.Bus":
busLabelList.append(i.label)
for i in busLabelList:
result = pd.DataFrame.from_dict(solph.views.node(self._optimizationResults, i)["sequences"])
result.to_excel(writer, sheet_name=i)
writer.save()
if "sequences" in solph.views.node(self._optimizationResults, i):
result = pd.DataFrame.from_dict(solph.views.node(self._optimizationResults, i)["sequences"])
result.to_excel(writer, sheet_name=i)

def _updateCapacityDictInputInvestment(self, transformerFlowCapacityDict):
components = ["CHP", "GWHP", "HP", "GasBoiler", "ElectricRod", "Chiller"]
Expand Down Expand Up @@ -827,7 +831,7 @@ def _calculateResultsPerBuilding(self, mergeLinkBuses):
gridBusLabel = "gridBus" + '__' + buildingLabel
naturalGasSourceLabel = "naturalGasResource" + '__' + buildingLabel
naturalGasBusLabel = "naturalGasBus" + '__' + buildingLabel
if mergeLinkBuses:
if mergeLinkBuses and ("electricity" in self._mergeBuses or "electricityBus" in self._mergeBuses):
electricityBusLabel = "electricityBus"
excessElectricityBusLabel = "excesselectricityBus"
else:
Expand Down Expand Up @@ -889,7 +893,7 @@ def _calculateResultsPerBuilding(self, mergeLinkBuses):
["sequences"][(electricityBusLabel, excessElectricityBusLabel), "flow"]) * self.__costParam[excessElectricityBusLabel]
else: # in case of merged links feed in for all buildings except Building1 is set to 0 (to avoid repetition)
self.__feedIn[buildingLabel] = 0
if mergeLinkBuses:
if mergeLinkBuses and ("electricity" in self._mergeBuses or "electricityInBus" in self._mergeBuses):
elInBusLabel = 'electricityInBus'
else:
elInBusLabel = 'electricityInBus__'+buildingLabel
Expand Down Expand Up @@ -1321,6 +1325,7 @@ def setFromExcel(self, filePath, numberOfBuildings, clusterSize={}, opt="costs",
logging.info("Defining the energy network from the excel file: {}".format(filePath))
self._dispatchMode = dispatchMode
self._optimizationType = opt
self._mergeBuses = mergeBuses
data = pd.ExcelFile(filePath)
initial_nodal_data = self.get_nodal_data_from_Excel(data)
# data.close()
Expand Down
4 changes: 3 additions & 1 deletion optihood/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def __init__(self, label, stratifiedStorageParams, inputs, outputs, initial_stor
self._numberOfLevels = len(stratifiedStorageParams.at[storageLabel, 'temp_h'].split(","))
if dispatchMode:
investArgs={'ep_costs':epc,
'custom_attributes': {'env_per_capa': env_capa}}
'custom_attributes': {'env_per_capa': env_capa},
'minimum': self.__capacityMin / self._numberOfLevels,
'maximum': self.__capacityMax}
else:
investArgs={'ep_costs':epc,
'existing':0,
Expand Down

0 comments on commit ba5d370

Please sign in to comment.