diff --git a/dragonfly_grasshopper/json/DF_Write_Modelica_DES.json b/dragonfly_grasshopper/json/DF_Write_Modelica_DES.json index 4c227e8..93e7b03 100644 --- a/dragonfly_grasshopper/json/DF_Write_Modelica_DES.json +++ b/dragonfly_grasshopper/json/DF_Write_Modelica_DES.json @@ -1,5 +1,5 @@ { - "version": "1.8.3", + "version": "1.8.4", "nickname": "WriteDES", "outputs": [ [ @@ -43,7 +43,7 @@ } ], "subcategory": "5 :: District Thermal", - "code": "\nimport os\nimport subprocess\n\ntry:\n from ladybug.futil import nukedir\n from ladybug.config import folders as lb_folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the dragonfly_energy dependencies\n from dragonfly_energy.config import folders as df_folders\n from dragonfly_energy.run import run_des_sys_param, run_des_modelica\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.download import download_file_by_name\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\nUO_GMT_VERSION = '0.9.1'\nUO_TN_VERSION = '0.3.2'\nMBL_VERSION = '11.0.0'\n\n\nif all_required_inputs(ghenv.Component) and _write:\n # set up the custom python environment\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n\n # set global values\n ext = '.exe' if os.name == 'nt' else ''\n executor_path = os.path.join(\n lb_folders.ladybug_tools_folder, '{{plugin}}',\n 'ladybug_{{plugin}}_dotnet', 'Ladybug.Executor.exe')\n\n # check to see if the geojson-modelica-translator is installed\n uo_gmt = '{}/uo_des{}'.format(folders.python_scripts_path, ext)\n uo_gmt_pack = '{}/geojson_modelica_translator-{}.dist-info'.format(\n folders.python_package_path, UO_GMT_VERSION)\n if not os.path.isfile(uo_gmt) or not os.path.isdir(uo_gmt_pack):\n install_cmd = 'pip install geojson-modelica-translator=={}'.format(UO_GMT_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the ThermalNetwork package is installed\n uo_tn = '{}/thermalnetwork{}'.format(folders.python_scripts_path, ext)\n uo_tn_pack = '{}/ThermalNetwork-{}.dist-info'.format(\n folders.python_package_path, UO_TN_VERSION)\n if not os.path.isfile(uo_tn) or not os.path.isdir(uo_tn_pack):\n install_cmd = 'pip install thermalnetwork=={}'.format(UO_TN_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the Modelica Buildings Library is installed\n install_directory = os.path.join(lb_folders.ladybug_tools_folder, 'resources')\n final_dir = os.path.join(install_directory, 'mbl')\n version_file = os.path.join(final_dir, 'version.txt')\n already_installed = False\n if os.path.isdir(final_dir) and os.path.isfile(version_file):\n with open(version_file, 'r') as vf:\n install_version = vf.read()\n if install_version == MBL_VERSION:\n already_installed = True\n else:\n nukedir(final_dir, True)\n if not already_installed:\n install_cmd = 'dragonfly_energy install mbl --version {}'.format(MBL_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # run the command that adds the building loads to the system parameters\n sys_param = run_des_sys_param(_geojson, _scenario)\n\n # run the command that generates the modelica files\n modelica = run_des_modelica(sys_param, _geojson, _scenario)\n", + "code": "\nimport os\nimport subprocess\n\ntry:\n from ladybug.futil import nukedir\n from ladybug.config import folders as lb_folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry:\n from honeybee.config import folders\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the dragonfly_energy dependencies\n from dragonfly_energy.config import folders as df_folders\n from dragonfly_energy.run import run_des_sys_param, run_des_modelica\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly_energy:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.download import download_file_by_name\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\nUO_GMT_VERSION = '0.9.1'\nUO_TN_VERSION = '0.3.2'\nMBL_VERSION = '11.0.0'\n\n\nif all_required_inputs(ghenv.Component) and _write:\n # set up the custom python environment\n custom_env = os.environ.copy()\n custom_env['PYTHONHOME'] = ''\n\n # set global values\n ext = '.exe' if os.name == 'nt' else ''\n executor_path = os.path.join(\n lb_folders.ladybug_tools_folder, '{{plugin}}',\n 'ladybug_{{plugin}}_dotnet', 'Ladybug.Executor.exe')\n\n # check to see if the geojson-modelica-translator is installed\n uo_gmt = '{}/uo_des{}'.format(folders.python_scripts_path, ext)\n uo_gmt_pack = '{}/geojson_modelica_translator-{}.dist-info'.format(\n folders.python_package_path, UO_GMT_VERSION)\n if not os.path.isfile(uo_gmt) or not os.path.isdir(uo_gmt_pack):\n install_cmd = 'pip install geojson-modelica-translator=={}'.format(UO_GMT_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the ThermalNetwork package is installed\n uo_tn = '{}/thermalnetwork{}'.format(folders.python_scripts_path, ext)\n uo_tn_pack = '{}/ThermalNetwork-{}.dist-info'.format(\n folders.python_package_path, UO_TN_VERSION)\n if not os.path.isfile(uo_tn) or not os.path.isdir(uo_tn_pack):\n install_cmd = 'pip install thermalnetwork=={}'.format(UO_TN_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check to see if the Modelica Buildings Library is installed\n install_directory = os.path.join(lb_folders.ladybug_tools_folder, 'resources')\n final_dir = os.path.join(install_directory, 'mbl')\n version_file = os.path.join(final_dir, 'version.txt')\n already_installed = False\n if os.path.isdir(final_dir) and os.path.isfile(version_file):\n with open(version_file, 'r') as vf:\n install_version = vf.read()\n if install_version == MBL_VERSION:\n already_installed = True\n else:\n nukedir(final_dir, True)\n if not already_installed:\n install_cmd = 'dragonfly_energy install mbl --version {}'.format(MBL_VERSION)\n if os.name == 'nt' and os.path.isfile(executor_path) and \\\n 'Program Files' in executor_path:\n pip_cmd = [\n executor_path, folders.python_exe_path, '-m {}'.format(install_cmd)\n ]\n else:\n pip_cmd = '\"{py_exe}\" -m {uo_cmd}'.format(\n py_exe=folders.python_exe_path, uo_cmd=install_cmd)\n shell = True if os.name == 'nt' else False\n process = subprocess.Popen(\n pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env)\n stderr = process.communicate()\n\n # check the various files in the project folder\n proj_dir = os.path.dirname(_geojson)\n scn_name = os.path.basename(_scenario).replace('.csv', '')\n des_dir = os.path.join(proj_dir, 'run', scn_name, 'des_modelica')\n sys_param = os.path.join(proj_dir, 'system_params.json')\n\n # run the command that adds the building loads to the system parameters\n if not os.path.isdir(des_dir):\n sys_param = run_des_sys_param(_geojson, _scenario)\n\n # run the command that generates the modelica files\n modelica = run_des_modelica(sys_param, _geojson, _scenario)\n", "category": "Dragonfly", "name": "DF Write Modelica DES", "description": "Use an URBANopt geoJSON with a Distric Energy System (DES) loop assigned to it\nalong with the corresponding scenario (containing building loads) to generate\na Modelica model of the district system.\n_\nThe model is generated using the modules of the Modelica Buildings Library (MBL).\nMore information on the MBL can be found here:\nhttps://simulationresearch.lbl.gov/modelica/\n_\nThe Modelica model produced by this component can be opened and edited in any\nof the standard Modelica interfaces (eg. Dymola) or it can be simulated with\nOpenModelica inside a Docker image using the \"DF Run Modelica\" component.\n-" diff --git a/dragonfly_grasshopper/src/DF Write Modelica DES.py b/dragonfly_grasshopper/src/DF Write Modelica DES.py index e9b1108..34fabc8 100644 --- a/dragonfly_grasshopper/src/DF Write Modelica DES.py +++ b/dragonfly_grasshopper/src/DF Write Modelica DES.py @@ -44,7 +44,7 @@ ghenv.Component.Name = 'DF Write Modelica DES' ghenv.Component.NickName = 'WriteDES' -ghenv.Component.Message = '1.8.3' +ghenv.Component.Message = '1.8.4' ghenv.Component.Category = 'Dragonfly' ghenv.Component.SubCategory = '5 :: District Thermal' ghenv.Component.AdditionalHelpFromDocStrings = '1' @@ -156,8 +156,15 @@ pip_cmd, stderr=subprocess.PIPE, shell=shell, env=custom_env) stderr = process.communicate() + # check the various files in the project folder + proj_dir = os.path.dirname(_geojson) + scn_name = os.path.basename(_scenario).replace('.csv', '') + des_dir = os.path.join(proj_dir, 'run', scn_name, 'des_modelica') + sys_param = os.path.join(proj_dir, 'system_params.json') + # run the command that adds the building loads to the system parameters - sys_param = run_des_sys_param(_geojson, _scenario) + if not os.path.isdir(des_dir): + sys_param = run_des_sys_param(_geojson, _scenario) # run the command that generates the modelica files modelica = run_des_modelica(sys_param, _geojson, _scenario) diff --git a/dragonfly_grasshopper/user_objects/DF Write Modelica DES.ghuser b/dragonfly_grasshopper/user_objects/DF Write Modelica DES.ghuser index 5a23d62..c3f0e59 100644 Binary files a/dragonfly_grasshopper/user_objects/DF Write Modelica DES.ghuser and b/dragonfly_grasshopper/user_objects/DF Write Modelica DES.ghuser differ diff --git a/samples/ghe_custom_loads.gh b/samples/ghe_custom_loads.gh index 39d549e..d5bd406 100644 Binary files a/samples/ghe_custom_loads.gh and b/samples/ghe_custom_loads.gh differ diff --git a/samples/ghe_example.gh b/samples/ghe_example.gh index e5d9fb5..4ab7dbd 100644 Binary files a/samples/ghe_example.gh and b/samples/ghe_example.gh differ diff --git a/samples/ghe_multiple_example.gh b/samples/ghe_multiple_example.gh index 55f4299..126d85c 100644 Binary files a/samples/ghe_multiple_example.gh and b/samples/ghe_multiple_example.gh differ