Compare commits

..

4 Commits

Author SHA1 Message Date
7bd7b680b3 Update hub/version.py 2024-12-12 14:14:34 -05:00
Guille
765784135d Correct old ep export and optimize code 2024-12-12 20:09:58 +01:00
08e7f68adf Update hub/version.py 2024-12-07 02:48:32 -05:00
Guille
464abea93a Correct package 2024-12-07 08:46:05 +01:00
10 changed files with 24 additions and 260 deletions

View File

@ -1,116 +0,0 @@
from typing import List, Dict, Union
from hub.city_model_structure.attributes.edge import Edge
class DHNEdge(Edge):
"""
District Heating Network Edge class, inherits from Edge.
"""
def __init__(self, name, nodes=None, length=0.0, diameter=0.0, nominal_diameter=0,
mass_flow_rate=None, roughness=0.0, pressure_drop=0.0):
super().__init__(name, nodes)
self._length = length
self._diameter = diameter
self._nominal_diameter = nominal_diameter
self._mass_flow_rate = mass_flow_rate if mass_flow_rate else {} # Initialize as empty dictionary
self._roughness = roughness
self._pressure_drop = pressure_drop
@property
def length(self) -> float:
"""
Get length of the edge
:return: float
"""
return self._length
@length.setter
def length(self, value: Union[None, float]):
"""
Set length of the edge
:param value: float
"""
self._length = max(value or 0.0, 0.0)
@property
def diameter(self) -> float:
"""
Get diameter of the edge
:return: float
"""
return self._diameter
@diameter.setter
def diameter(self, value: Union[None, float]):
"""
Set diameter of the edge
:param value: float
"""
self._diameter = value if value and value > 0 else 0.1 # Default to 0.1 if invalid
@property
def nominal_diameter(self) -> int:
"""
Get nominal diameter of the edge
:return: int
"""
return self._nominal_diameter
@nominal_diameter.setter
def nominal_diameter(self, value: Union[None, int]):
"""
Set nominal diameter of the edge
:param value: int
"""
self._nominal_diameter = value if value and value > 0 else 1 # Default to 1 if invalid
@property
def mass_flow_rate(self) -> Dict:
"""
Get mass flow rate data
:return: dict
"""
return self._mass_flow_rate
@mass_flow_rate.setter
def mass_flow_rate(self, value: Union[None, Dict]):
"""
Set mass flow rate data
:param value: dict
"""
if value and isinstance(value, dict):
self._mass_flow_rate = value
else:
self._mass_flow_rate = {} # Default to empty dictionary
@property
def roughness(self) -> float:
"""
Get roughness of the edge
:return: float
"""
return self._roughness
@roughness.setter
def roughness(self, value: Union[None, float]):
"""
Set roughness of the edge
:param value: float
"""
self._roughness = max(value or 0.0, 0.0)
@property
def pressure_drop(self) -> float:
"""
Get pressure drop across the edge
:return: float
"""
return self._pressure_drop
@pressure_drop.setter
def pressure_drop(self, value: Union[None, float]):
"""
Set pressure drop across the edge
:param value: float
"""
self._pressure_drop = max(value or 0.0, 0.0)

View File

@ -1,81 +0,0 @@
from typing import Union
from hub.city_model_structure.attributes.node import Node
class DHNNode(Node):
"""
District Heating Network Node class, inherits from Node.
"""
def __init__(self, name, edges=None, pos=(0, 0), heat_exchanger_resistance=0, building=None, valve_resistance=0):
super().__init__(name, edges)
self._pos = pos
self._heat_exchanger_resistance = heat_exchanger_resistance
self._building = building
self._valve_resistance = valve_resistance
@property
def pos(self) -> tuple:
"""
Get the position of the node
:return: tuple
"""
return self._pos
@pos.setter
def pos(self, value: Union[None, tuple]):
"""
Set the position of the node
:param value: tuple
"""
if value and isinstance(value, tuple) and len(value) == 2:
self._pos = value
else:
self._pos = (0, 0) # Default position
@property
def heat_exchanger_resistance(self) -> int:
"""
Get heat exchanger resistance
:return: int
"""
return self._heat_exchanger_resistance
@heat_exchanger_resistance.setter
def heat_exchanger_resistance(self, value: Union[None, int]):
"""
Set heat exchanger resistance
:param value: int
"""
self._heat_exchanger_resistance = max(value or 0, 0)
@property
def building(self):
"""
Get the associated building
:return: object
"""
return self._building
@building.setter
def building(self, value):
"""
Set the associated building
:param value: object
"""
self._building = value
@property
def valve_resistance(self) -> int:
"""
Get valve resistance
:return: int
"""
return self._valve_resistance
@valve_resistance.setter
def valve_resistance(self, value: Union[None, int]):
"""
Set valve resistance
:param value: int
"""
self._valve_resistance = max(value or 0, 0)

View File

@ -1,48 +0,0 @@
from hub.city_model_structure.network import Network
from typing import Union
from hub.city_model_structure.attributes.dhn_node import DHNNode
from hub.city_model_structure.attributes.dhn_edge import DHNEdge
class DHNNetwork(Network):
"""
District Heating Network class, inherits from Network.
"""
def __init__(self, name, edges=None, nodes=None):
super().__init__(name, edges, nodes)
def add_node(self, node: DHNNode):
"""
Add a DHN node to the network
:param node: DHNNode
"""
self._nodes.append(node)
def add_edge(self, edge: DHNEdge):
"""
Add a DHN edge to the network
:param edge: DHNEdge
"""
self._edges.append(edge)
def find_node_by_name(self, name: str) -> Union[None, DHNNode]:
"""
Find a node in the network by name
:param name: str
:return: DHNNode or None
"""
for node in self._nodes:
if node.name == name:
return node
return None
def find_edge_by_name(self, name: str) -> Union[None, DHNEdge]:
"""
Find an edge in the network by name
:param name: str
:return: DHNEdge or None
"""
for edge in self._edges:
if edge.name == name:
return edge
return None

View File

@ -10,7 +10,6 @@ import copy
import os
import shutil
import subprocess
from datetime import datetime
import hub.exports.building_energy.idf_helper as idf_cte
import hub.helpers.constants as cte
@ -48,7 +47,6 @@ class CercIdf(IdfBase):
_thermostat_added_to_idf = {}
def __init__(self, city, output_path, idf_file_path, idd_file_path, epw_file_path, target_buildings=None):
self._start = datetime.now()
super().__init__(city, output_path, idf_file_path, idd_file_path, epw_file_path, target_buildings)
self._add_surfaces = IdfSurfaces.add
self._add_file_schedule = IdfFileSchedule.add
@ -233,7 +231,6 @@ class CercIdf(IdfBase):
# Merge files
self._merge_files()
self._add_outputs()
print(f'{len(self._city.buildings)} buildings export completed in: {datetime.now() - self._start}')
@property
def _energy_plus(self):
@ -248,5 +245,4 @@ class CercIdf(IdfBase):
'--readvars',
'--output-prefix', f'{self._city.name}_',
self._output_file_path]
print(cmd)
subprocess.run(cmd, cwd=self._output_path)

View File

@ -8,10 +8,12 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
"""
import copy
import datetime
import glob
import os
import shutil
import subprocess
from pathlib import Path
from geomeppy import IDF
import hub.helpers.constants as cte
from hub.city_model_structure.attributes.schedule import Schedule
from hub.city_model_structure.building_demand.thermal_zone import ThermalZone
@ -529,6 +531,7 @@ class Idf:
self._remove_sizing_periods()
self._rename_building(self._city.name)
self._lod = self._city.level_of_detail.geometry
is_target = False
for building in self._city.buildings:
is_target = building.name in self._target_buildings or building.name in self._adjacent_buildings
for internal_zone in building.internal_zones:
@ -656,12 +659,20 @@ class Idf:
self._add_surfaces(building, building.name)
return self._idf
@property
def _energy_plus(self):
return shutil.which('energyplus')
def run(self):
"""
Start the energy plus simulation
"""
self._idf.run(expandobjects=False, readvars=True, output_directory=self._output_path,
output_prefix=f'{self._city.name}_')
cmd = [self._energy_plus,
'--weather', self._epw_file_path,
'--output-directory', self._output_path,
'--idd', self._idd_file_path,
'--expandobjects',
'--readvars',
'--output-prefix', f'{self._city.name}_',
self._idf_file_path]
subprocess.run(cmd, cwd=self._output_path)
def _add_block(self, building):
_points = self._matrix_to_2d_list(building.foot_print.coordinates)

View File

@ -20,7 +20,7 @@ class EnergyPlus:
header_parts = header.split(':')
building_name = header_parts[0]
variable = ':'.join(header_parts[1:]).strip() # concat the rest and ensure that : it's reintroduced just in case
if variable is '':
if variable == '':
continue
if building_name not in self._summary_variables:
self._building_energy_demands[variable] = [] # initialize the list of variables

View File

@ -1,4 +1,4 @@
"""
Hub version number
"""
__version__ = '0.3.0.3'
__version__ = '0.3.0.5'

View File

@ -1,5 +1,5 @@
xmltodict
numpy==1.26.4
numpy
trimesh[all]
pyproj
pandas

View File

@ -59,6 +59,7 @@ setup(
'hub.exports',
'hub.exports.building_energy',
'hub.exports.building_energy.idf_files',
'hub.exports.building_energy.idf_helper',
'hub.exports.building_energy.insel',
'hub.exports.energy_systems',
'hub.exports.formats',

View File

@ -144,7 +144,8 @@ class TestExports(TestCase):
UsageFactory('nrcan', city).enrich()
WeatherFactory('epw', city).enrich()
try:
idf = EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
_idf = EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
_idf.run()
except Exception:
self.fail("Idf ExportsFactory raised ExceptionType unexpectedly!")