-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hvac): Add component for assigning detailed HVAC
- Loading branch information
1 parent
9150477
commit c9f8f1e
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"version": "1.6.0", | ||
"nickname": "DetailedHVAC", | ||
"outputs": [ | ||
[ | ||
{ | ||
"access": "None", | ||
"name": "report", | ||
"description": "Reports, errors, warnings, etc.", | ||
"type": null, | ||
"default": null | ||
}, | ||
{ | ||
"access": "None", | ||
"name": "hb_objs", | ||
"description": "The input Rooms or Model with the detailed HVAC system applied.", | ||
"type": null, | ||
"default": null | ||
} | ||
] | ||
], | ||
"inputs": [ | ||
{ | ||
"access": "list", | ||
"name": "_hb_objs", | ||
"description": "Honeybee Rooms to which the input Ironbug HVAC will be assigned.\nThis can also be a Honeybee Model for which the relevant Rooms\nreferenced in the _hvac_system will be assigned the HVAC system.", | ||
"type": "System.Object", | ||
"default": null | ||
}, | ||
{ | ||
"access": "item", | ||
"name": "_hvac_system", | ||
"description": "A fully-detailed Irongbug HVAC system to be assigned to the\ninput rooms (or model).", | ||
"type": "System.Object", | ||
"default": null | ||
}, | ||
{ | ||
"access": "item", | ||
"name": "_name_", | ||
"description": "Text to set the name for the HVAC system and to be incorporated into\nunique HVAC identifier. If the name is not provided, a random name\nwill be assigned.", | ||
"type": "string", | ||
"default": null | ||
} | ||
], | ||
"subcategory": "4 :: HVAC", | ||
"code": "\nimport json\n\ntry: # import the honeybee extension\n from honeybee.typing import clean_and_id_ep_string, clean_ep_string\n from honeybee.model import Model\n from honeybee.room import Room\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the honeybee-energy extension\n from honeybee_energy.config import folders\n from honeybee_energy.hvac.detailed import DetailedHVAC\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee_energy:\\n\\t{}'.format(e))\n\ntry:\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\nif folders.ironbug_exe is None:\n msg = 'An installation of Ironbug that is compatible with this component\\n' \\\n 'was not found on this machine. This component will not be usable.'\n print(msg)\n give_warning(ghenv.Component, msg)\nelif folders.ironbug_version is not None:\n if folders.ironbug_version < (1, 5, 3):\n msg = 'Ironbug version \"{}\" is not compatible with this component.\\n' \\\n 'This component will not be usable.'.format(\n '.'.join([str(i) for i in folders.ironbug_version]))\n print(msg)\n give_warning(ghenv.Component, msg)\n\n\nif all_required_inputs(ghenv.Component):\n # extract any rooms from input Models and duplicate the rooms\n rooms, hb_objs = [], []\n for hb_obj in _hb_objs:\n if isinstance(hb_obj, Model):\n new_obj = hb_obj.duplicate()\n hb_objs.append(new_obj)\n rooms.extend(new_obj.rooms)\n elif isinstance(hb_obj, Room):\n new_obj = hb_obj.duplicate()\n hb_objs.append(new_obj)\n rooms.append(new_obj)\n else:\n raise ValueError(\n 'Expected Honeybee Room or Model. Got {}.'.format(type(hb_obj)))\n\n # create the HVAC\n name = clean_and_id_ep_string('Detailed HVAC') if _name_ is None else \\\n clean_ep_string(_name_)\n specification = json.loads(_hvac_system.ToJson())\n hvac = DetailedHVAC(name, specification)\n if _name_ is not None:\n hvac.display_name = _name_\n\n # apply the HVAC system to the rooms\n hvac_rooms = set(hvac.thermal_zones)\n hvac_count, rel_rooms = 0, []\n for room in rooms:\n if room.identifier in hvac_rooms:\n room.properties.energy.hvac = hvac\n rel_rooms.append(room.identifier)\n hvac_count += 1\n\n # give a warning if no rooms were assigned the HVAC or if there are missing rooms\n if hvac_count == 0:\n msg = 'None of the connected Rooms are referenced under the Ironbug HVAC system.\\n' \\\n 'Make sure that the system has been set up with the correct Rooms.'\n print(msg)\n give_warning(ghenv.Component, msg)\n if len(rel_rooms) != len(hvac_rooms):\n missing_rooms = []\n found_rooms = set(rel_rooms)\n for rm_id in hvac_rooms:\n if rm_id not in found_rooms:\n missing_rooms.append(rm_id)\n msg = 'The Ironbug HVAC system contains the following rooms that are not ' \\\n 'in the connected _hb_objs.\\n{}'.format('\\n'.join(missing_rooms))\n print(msg)\n give_warning(ghenv.Component, msg)\n", | ||
"category": "HB-Energy", | ||
"name": "HB Detailed HVAC", | ||
"description": "Apply a detailed Ironbug HVAC to Honeybee Rooms or a Honeybee Model.\n-" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Honeybee: A Plugin for Environmental Analysis (GPL) | ||
# This file is part of Honeybee. | ||
# | ||
# Copyright (c) 2023, Ladybug Tools. | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Honeybee; If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later> | ||
|
||
""" | ||
Apply a detailed Ironbug HVAC to Honeybee Rooms or a Honeybee Model. | ||
- | ||
Args: | ||
_hb_objs: Honeybee Rooms to which the input Ironbug HVAC will be assigned. | ||
This can also be a Honeybee Model for which the relevant Rooms | ||
referenced in the _hvac_system will be assigned the HVAC system. | ||
_hvac_system: A fully-detailed Irongbug HVAC system to be assigned to the | ||
input rooms (or model). | ||
_name_: Text to set the name for the HVAC system and to be incorporated into | ||
unique HVAC identifier. If the name is not provided, a random name | ||
will be assigned. | ||
Returns: | ||
report: Reports, errors, warnings, etc. | ||
hb_objs: The input Rooms or Model with the detailed HVAC system applied. | ||
""" | ||
|
||
ghenv.Component.Name = "HB Detailed HVAC" | ||
ghenv.Component.NickName = 'DetailedHVAC' | ||
ghenv.Component.Message = '1.6.0' | ||
ghenv.Component.Category = 'HB-Energy' | ||
ghenv.Component.SubCategory = '4 :: HVAC' | ||
ghenv.Component.AdditionalHelpFromDocStrings = '0' | ||
|
||
import json | ||
|
||
try: # import the honeybee extension | ||
from honeybee.typing import clean_and_id_ep_string, clean_ep_string | ||
from honeybee.model import Model | ||
from honeybee.room import Room | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) | ||
|
||
try: # import the honeybee-energy extension | ||
from honeybee_energy.config import folders | ||
from honeybee_energy.hvac.detailed import DetailedHVAC | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) | ||
|
||
try: | ||
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)) | ||
|
||
if folders.ironbug_exe is None: | ||
msg = 'An installation of Ironbug that is compatible with this component\n' \ | ||
'was not found on this machine. This component will not be usable.' | ||
print(msg) | ||
give_warning(ghenv.Component, msg) | ||
elif folders.ironbug_version is not None: | ||
if folders.ironbug_version < (1, 5, 3): | ||
msg = 'Ironbug version "{}" is not compatible with this component.\n' \ | ||
'This component will not be usable.'.format( | ||
'.'.join([str(i) for i in folders.ironbug_version])) | ||
print(msg) | ||
give_warning(ghenv.Component, msg) | ||
|
||
|
||
if all_required_inputs(ghenv.Component): | ||
# extract any rooms from input Models and duplicate the rooms | ||
rooms, hb_objs = [], [] | ||
for hb_obj in _hb_objs: | ||
if isinstance(hb_obj, Model): | ||
new_obj = hb_obj.duplicate() | ||
hb_objs.append(new_obj) | ||
rooms.extend(new_obj.rooms) | ||
elif isinstance(hb_obj, Room): | ||
new_obj = hb_obj.duplicate() | ||
hb_objs.append(new_obj) | ||
rooms.append(new_obj) | ||
else: | ||
raise ValueError( | ||
'Expected Honeybee Room or Model. Got {}.'.format(type(hb_obj))) | ||
|
||
# create the HVAC | ||
name = clean_and_id_ep_string('Detailed HVAC') if _name_ is None else \ | ||
clean_ep_string(_name_) | ||
specification = json.loads(_hvac_system.ToJson()) | ||
hvac = DetailedHVAC(name, specification) | ||
if _name_ is not None: | ||
hvac.display_name = _name_ | ||
|
||
# apply the HVAC system to the rooms | ||
hvac_rooms = set(hvac.thermal_zones) | ||
hvac_count, rel_rooms = 0, [] | ||
for room in rooms: | ||
if room.identifier in hvac_rooms: | ||
room.properties.energy.hvac = hvac | ||
rel_rooms.append(room.identifier) | ||
hvac_count += 1 | ||
|
||
# give a warning if no rooms were assigned the HVAC or if there are missing rooms | ||
if hvac_count == 0: | ||
msg = 'None of the connected Rooms are referenced under the Ironbug HVAC system.\n' \ | ||
'Make sure that the system has been set up with the correct Rooms.' | ||
print(msg) | ||
give_warning(ghenv.Component, msg) | ||
if len(rel_rooms) != len(hvac_rooms): | ||
missing_rooms = [] | ||
found_rooms = set(rel_rooms) | ||
for rm_id in hvac_rooms: | ||
if rm_id not in found_rooms: | ||
missing_rooms.append(rm_id) | ||
msg = 'The Ironbug HVAC system contains the following rooms that are not ' \ | ||
'in the connected _hb_objs.\n{}'.format('\n'.join(missing_rooms)) | ||
print(msg) | ||
give_warning(ghenv.Component, msg) |
Binary file not shown.