Skip to content

Commit

Permalink
fix(des): Add checks to help avoid running out of RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Sep 16, 2023
1 parent c2bd83c commit a159fca
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 7 deletions.
Binary file modified dragonfly_grasshopper/icon/DF Run Modelica DES.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions dragonfly_grasshopper/json/DF_GHE_Thermal_Loop.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.1",
"version": "1.6.2",
"nickname": "GHELoop",
"outputs": [
[
Expand Down Expand Up @@ -85,7 +85,7 @@
}
],
"subcategory": "3 :: Energy",
"code": "\nimport math\n\ntry: # import the core honeybee dependencies\n from honeybee.typing import clean_ep_string\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the core dragonfly_energy dependencies\n from dragonfly_energy.des.connector import ThermalConnector\n from dragonfly_energy.des.ghe import GroundHeatExchanger\n from dragonfly_energy.des.loop import {{PLGN}}EThermalLoop\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_linesegment2d, to_polyline2d\n from ladybug_{{cad}}.togeometry import to_polygon2d\n from ladybug_{{cad}}.config import angle_tolerance\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # set a default name\n name = clean_ep_string(_name_) if _name_ is not None else 'unnamed'\n\n # create the {{PLGN}}E fields and the Thermal Connectors\n lines = []\n for geo in _connector_geo:\n try:\n lines.append(to_polyline2d(geo))\n except AttributeError:\n lines.append(to_linesegment2d(geo))\n connectors = []\n for i, lin in enumerate(lines):\n connectors.append(ThermalConnector('{}_ThermalConnector_{}'.format(name, i), lin))\n ghes = []\n for i, geo in enumerate(_ghe_geo):\n gp = to_polygon2d(geo)\n if not gp.is_rectangle(math.radians(angle_tolerance)):\n msg = 'The ground heat exchanger with index {} is not a perfect rectangle ' \\\n 'but it will be approximated as such in the DES simulation.'.format(i)\n print(msg)\n give_warning(ghenv.Component, msg)\n ghes.append(GroundHeatExchanger('{}_{{PLGN}}E_{}'.format(name, i), gp))\n\n # create the loop\n des_loop = {{PLGN}}EThermalLoop(name, ghes, connectors, _clockwise_)\n if _name_ is not None:\n des_loop.display_name = _name_\n\n # assign the properties to the loop\n if _bore_depth_ is not None:\n d_min, d_max = _bore_depth_\n if d_min != 0:\n des_loop.borehole_parameters.min_depth = d_min\n elif d_max < 60:\n des_loop.borehole_parameters.min_depth = d_max\n des_loop.borehole_parameters.max_depth = d_max\n if _bore_spacing_ is not None:\n s_min, s_max = _bore_spacing_\n if s_min != 0:\n des_loop.borehole_parameters.max_spacing = s_max\n des_loop.borehole_parameters.min_spacing = s_min\n elif s_max > 10:\n des_loop.borehole_parameters.max_spacing = s_max\n des_loop.borehole_parameters.min_spacing = s_max\n else:\n des_loop.borehole_parameters.min_spacing = s_max\n if _soil_conduct_:\n des_loop.soil_parameters.conductivity = _soil_conduct_\n if _soil_heat_cap_:\n des_loop.soil_parameters.heat_capacity = _soil_heat_cap_\n if _fluid_type_:\n des_loop.fluid_parameters.fluid_type = _fluid_type_.replace(' ', '')\n if concentration_:\n des_loop.fluid_parameters.concentration = concentration_\n",
"code": "\nimport math\n\ntry: # import the core honeybee dependencies\n from honeybee.typing import clean_ep_string\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the core dragonfly_energy dependencies\n from dragonfly_energy.des.connector import ThermalConnector\n from dragonfly_energy.des.ghe import GroundHeatExchanger\n from dragonfly_energy.des.loop import {{PLGN}}EThermalLoop\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_linesegment2d, to_polyline2d\n from ladybug_{{cad}}.togeometry import to_polygon2d\n from ladybug_{{cad}}.config import angle_tolerance, conversion_to_meters\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # set a default name\n name = clean_ep_string(_name_) if _name_ is not None else 'unnamed'\n\n # create the {{PLGN}}E fields and the Thermal Connectors\n lines = []\n for geo in _connector_geo:\n try:\n lines.append(to_polyline2d(geo))\n except AttributeError:\n lines.append(to_linesegment2d(geo))\n connectors = []\n for i, lin in enumerate(lines):\n connectors.append(ThermalConnector('{}_ThermalConnector_{}'.format(name, i), lin))\n ghes, total_area = [], 0\n for i, geo in enumerate(_ghe_geo):\n gp = to_polygon2d(geo)\n total_area += gp.area * conversion_to_meters()\n if not gp.is_rectangle(math.radians(angle_tolerance)):\n msg = 'The ground heat exchanger with index {} is not a perfect rectangle ' \\\n 'but it will be approximated as such in the DES simulation.'.format(i)\n print(msg)\n give_warning(ghenv.Component, msg)\n ghes.append(GroundHeatExchanger('{}_{{PLGN}}E_{}'.format(name, i), gp))\n\n # create the loop\n des_loop = {{PLGN}}EThermalLoop(name, ghes, connectors, _clockwise_)\n if _name_ is not None:\n des_loop.display_name = _name_\n\n # assign the properties to the loop\n if _bore_depth_ is not None:\n d_min, d_max = _bore_depth_\n if d_min != 0:\n des_loop.borehole_parameters.min_depth = d_min\n elif d_max < 60:\n des_loop.borehole_parameters.min_depth = d_max\n des_loop.borehole_parameters.max_depth = d_max\n if _bore_spacing_ is not None:\n s_min, s_max = _bore_spacing_\n if s_min != 0:\n des_loop.borehole_parameters.max_spacing = s_max\n des_loop.borehole_parameters.min_spacing = s_min\n elif s_max > 10:\n des_loop.borehole_parameters.max_spacing = s_max\n des_loop.borehole_parameters.min_spacing = s_max\n else:\n des_loop.borehole_parameters.min_spacing = s_max\n if _soil_conduct_:\n des_loop.soil_parameters.conductivity = _soil_conduct_\n if _soil_heat_cap_:\n des_loop.soil_parameters.heat_capacity = _soil_heat_cap_\n if _fluid_type_:\n des_loop.fluid_parameters.fluid_type = _fluid_type_.replace(' ', '')\n if concentration_:\n des_loop.fluid_parameters.concentration = concentration_\n\n # give a warning about RAM if the size of the borehole field is too large\n borehole_count = int(total_area / (des_loop.borehole_parameters.min_spacing ** 2))\n MAX_BOREHOLES = 8000\n if borehole_count > MAX_BOREHOLES:\n msg = 'The inputs suggest that there may be as many as {} boreholes in the ' \\\n '{{PLGN}}E field\\nand this can cause the {{PLGN}}E sizing routine to use ' \\\n 'more than 10GB of memory.\\nA smaller _ghe_geo or a larger '\\\n '_bore_spacing_ is recommended such that fewer\\nthan {} boreholes are ' \\\n 'generated.'.format(borehole_count, MAX_BOREHOLES)\n print(msg)\n give_warning(ghenv.Component, msg)\n",
"category": "Dragonfly",
"name": "DF GHE Thermal Loop",
"description": "Create an Ground Heat Exchanger Thermal Loop, which represents all infrastructure\nfor a District Energy Simulation (DES) simulation.\n_\nThis includes a ground heat exchanger and all thermal connectors needed\nto connect these objects to Dragonfly Buildings.\n-"
Expand Down
2 changes: 1 addition & 1 deletion dragonfly_grasshopper/json/DF_Run_Modelica_DES.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.1",
"version": "1.6.2",
"nickname": "RunDES",
"outputs": [
[
Expand Down
19 changes: 16 additions & 3 deletions dragonfly_grasshopper/src/DF GHE Thermal Loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

ghenv.Component.Name = 'DF GHE Thermal Loop'
ghenv.Component.NickName = 'GHELoop'
ghenv.Component.Message = '1.6.1'
ghenv.Component.Message = '1.6.2'
ghenv.Component.Category = 'Dragonfly'
ghenv.Component.SubCategory = '3 :: Energy'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
Expand All @@ -99,7 +99,7 @@
try:
from ladybug_rhino.togeometry import to_linesegment2d, to_polyline2d
from ladybug_rhino.togeometry import to_polygon2d
from ladybug_rhino.config import angle_tolerance
from ladybug_rhino.config import angle_tolerance, conversion_to_meters
from ladybug_rhino.grasshopper import all_required_inputs, give_warning
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))
Expand All @@ -119,9 +119,10 @@
connectors = []
for i, lin in enumerate(lines):
connectors.append(ThermalConnector('{}_ThermalConnector_{}'.format(name, i), lin))
ghes = []
ghes, total_area = [], 0
for i, geo in enumerate(_ghe_geo):
gp = to_polygon2d(geo)
total_area += gp.area * conversion_to_meters()
if not gp.is_rectangle(math.radians(angle_tolerance)):
msg = 'The ground heat exchanger with index {} is not a perfect rectangle ' \
'but it will be approximated as such in the DES simulation.'.format(i)
Expand Down Expand Up @@ -160,3 +161,15 @@
des_loop.fluid_parameters.fluid_type = _fluid_type_.replace(' ', '')
if concentration_:
des_loop.fluid_parameters.concentration = concentration_

# give a warning about RAM if the size of the borehole field is too large
borehole_count = int(total_area / (des_loop.borehole_parameters.min_spacing ** 2))
MAX_BOREHOLES = 8000
if borehole_count > MAX_BOREHOLES:
msg = 'The inputs suggest that there may be as many as {} boreholes in the ' \
'GHE field\nand this can cause the GHE sizing routine to use ' \
'more than 10GB of memory.\nA smaller _ghe_geo or a larger '\
'_bore_spacing_ is recommended such that fewer\nthan {} boreholes are ' \
'generated.'.format(borehole_count, MAX_BOREHOLES)
print(msg)
give_warning(ghenv.Component, msg)
2 changes: 1 addition & 1 deletion dragonfly_grasshopper/src/DF Run Modelica DES.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

ghenv.Component.Name = 'DF Run Modelica DES'
ghenv.Component.NickName = 'RunDES'
ghenv.Component.Message = '1.6.1'
ghenv.Component.Message = '1.6.2'
ghenv.Component.Category = 'Dragonfly'
ghenv.Component.SubCategory = '3 :: Energy'
ghenv.Component.AdditionalHelpFromDocStrings = '0'
Expand Down
Binary file modified dragonfly_grasshopper/user_objects/DF GHE Thermal Loop.ghuser
Binary file not shown.
Binary file modified dragonfly_grasshopper/user_objects/DF Run Modelica DES.ghuser
Binary file not shown.
Binary file modified samples/des_example.gh
Binary file not shown.
Binary file modified samples/ghe_example.gh
Binary file not shown.

0 comments on commit a159fca

Please sign in to comment.