Skip to content

Commit

Permalink
Merge pull request #140 from BuildingSync/update-os-measure
Browse files Browse the repository at this point in the history
BuildingSync Measure-Gem
  • Loading branch information
ThibaultMarzullo authored Dec 13, 2022
2 parents 99dce7a + 3169c4e commit c7f7177
Show file tree
Hide file tree
Showing 13 changed files with 17,475 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ schedules-*.csv

# measures tests
lib/measures/.rubocop.yml
lib/measures/test_results/*
lib/measures/building_sync_to_openstudio/tests/output

# OSW tests for gem
osw_test/generated_files
osw_test/run
osw_test/out.osw

spec/files/filecomparison/in.idf
spec/files/filecomparison/in.osm
Expand Down
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ task :remove_tabs do
end
end

desc 'Run measure test'
task :measure_test do
puts Dir.getwd
require_relative './lib/measures/building_sync_to_openstudio/tests/building_sync_to_openstudio_test'

end

task default: :spec
2 changes: 1 addition & 1 deletion lib/buildingsync/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
# provides features for reading BldgSync XML files, generating baseline models, creating scenario workflows, running simulations and adding simulation results to the BldgSync file
module BuildingSync
# version of the BuildingSync gem
VERSION = '0.2.2'
VERSION = '0.3.0'
end
29 changes: 29 additions & 0 deletions lib/measures/building_sync_to_openstudio/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
OpenStudio(R), Copyright (c) 2008-2022, Alliance for Sustainable Energy, LLC. All rights reserved.
BuildingSync(R), Copyright (c) 2015-2022, Alliance for Sustainable Energy, LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

(1) Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.

(2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.

(3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse
or promote products derived from this software without specific prior written permission from the
respective party.

(4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other
derivative works may not use the "OpenStudio" or "BuildingSync" trademarks, "OS", "os", "BSync" or any
other confusingly similar designation without specific prior written permission from Alliance for
Sustainable Energy, LLC.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT,
OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 changes: 46 additions & 0 deletions lib/measures/building_sync_to_openstudio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# BuildingSync Gem

## Description

This measure-gem converts a BuildingSync XML file into a series of OSWs. Each OSW corresponds to an energy efficiency package of measures defined in the BuildingSync XML file. The OSWs can then be simulated and the results are written back into the BuildingSync XML file.

## Modeler Description

The measure will use a BuildingSync XML file as an input. The XML can be created using tools such as [bsyncpy](https://pypi.org/project/bsync/).
The XML will be parsed and a new OpenStudio model will be created. A new OSW will be created for each energy efficiency package of measures defined in the XML, using the measures defined in the ./lib/buildingsync/makers/phase_zero_base.osw file.
The user has a choice for just generating OSWs or generating and simulating them. If the OSWs are simulated, then the results are collected and reports are generated. These reports will be written in the original BuildingSync XML file, and that XML file will be saved.

## Measure Type
ModelMeasure

## Taxonomy


## Arguments

### BSync XML path
The path to the XML file that should be translated.
**Name:** building_sync_xml_file_path,
**Type:** String,
**Units:** ,
**Required:** true,
**Model Dependent:** false

### BSync output path:
The output directory where all workflows and results will be written.
**Name:** out_path,
**Type:** String,
**Units:** ,
**Required:** true,
**Model Dependent:** false

### Simulate and record results?
The generated OSWs will be simulated and the results recorded into the original XML file.
**Name:** simulate_flag,
**Type:** Boolean,
**Units:** ,
**Required:** true,
**Model Dependent:** false



116 changes: 116 additions & 0 deletions lib/measures/building_sync_to_openstudio/measure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# insert your copyright here

# see the URL below for information on how to write OpenStudio measures
# http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/

# start the measure
require 'buildingsync/translator'

class BuildingSyncToOpenStudio < OpenStudio::Measure::ModelMeasure
# human readable name
def name
# Measure name should be the title case of the class name.
return 'Building Sync to OpenStudio'
end

# human readable description
def description
return "This measure-gem converts a BuildingSync XML file into a series of OSWs. Each OSW corresponds to an energy efficiency package of measures defined in the BuildingSync XML file. The OSWs can then be simulated and the results are written back into the BuildingSync XML file."
end

# human readable description of modeling approach
def modeler_description
return "The measure will use a BuildingSync XML file as an input. The XML can be created using tools such as [bsyncpy](https://pypi.org/project/bsync/).
The XML will be parsed and a new OpenStudio model will be created. A new OSW will be created for each energy efficiency package of measures defined in the XML, using the measures defined in the ./lib/buildingsync/makers/phase_zero_base.osw file.
The user has a choice for just generating OSWs or generating and simulating them. If the OSWs are simulated, then the results are collected and reports are generated. These reports will be written in the original BuildingSync XML file, and that XML file will be saved."
end

# define the arguments that the user will input
def arguments(model)
args = OpenStudio::Measure::OSArgumentVector.new

building_sync_xml_file_path = OpenStudio::Measure::OSArgument.makeStringArgument('building_sync_xml_file_path', true)
building_sync_xml_file_path.setDisplayName('BSync XML path')
building_sync_xml_file_path.setDescription('The path to the XML file that should be translated.')
args << building_sync_xml_file_path

out_path = OpenStudio::Measure::OSArgument.makeStringArgument('out_path', true)
out_path.setDisplayName('BSync output path')
out_path.setDescription('The output directory where all workflows and results will be written.')
args << out_path

simulate_flag = OpenStudio::Measure::OSArgument.makeBoolArgument('simulate_flag', true)
simulate_flag.setDisplayName('Simulate and record results?')
simulate_flag.setDescription('The generated OSWs will be simulated and the results recorded into the original XML file.')
simulate_flag.setDefaultValue(true)
args << simulate_flag
return args
end

# define what happens when the measure is run
def run(model, runner, user_arguments)
super(model, runner, user_arguments)

# use the built-in error checking
if !runner.validateUserArguments(arguments(model), user_arguments)
return false
end

# assign the user inputs to variables
building_sync_xml_file_path = runner.getStringArgumentValue('building_sync_xml_file_path', user_arguments)
out_path = runner.getStringArgumentValue('out_path', user_arguments)
simulate_flag = runner.getStringArgumentValue('simulate_flag', user_arguments)


# check the space_name for reasonableness
if building_sync_xml_file_path.empty?
runner.registerError('Empty space name was entered.')
return false
end

# report initial condition of model
runner.registerInitialCondition("The building started with #{model.getSpaces.size} spaces.")

# add a new space to the model
translator = BuildingSync::Translator.new(building_sync_xml_file_path, out_path)
translator.setup_and_sizing_run
# fetch the model from the output directory
ostranslator = OpenStudio::OSVersion::VersionTranslator.new
path = "#{out_path}/in.osm"
model = ostranslator.loadModel(path)#translator.output_dir)
model = model.get
runner.registerFinalCondition("The building finished with #{model.getSpaces.size} spaces.")


# generating the OpenStudio workflows and writing the osw files
# auc:Scenario elements with measures are turned into new simulation dirs
# path/to/output_dir/scenario_name
translator.write_osws
if simulate_flag
# run all simulations
translator.run_osws

# gather the results for all scenarios found in out_path,
# such as annual and monthly data for different energy
# sources (electricity, natural gas, etc.)
translator.gather_results

# Add in UserDefinedFields, which contain information about the
# OpenStudio model run
translator.prepare_final_xml

# write results to xml
# default file name is 'results.xml'
file_name = 'results.xml'
translator.save_xml(file_name)

# report final condition of model
runner.registerFinalCondition("File has been saved as #{file_name}")
end

return true
end
end

# register the measure to be used by the application
BuildingSyncToOpenStudio.new.registerWithApplication
122 changes: 122 additions & 0 deletions lib/measures/building_sync_to_openstudio/measure.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0"?>
<measure>
<schema_version>3.0</schema_version>
<name>building_sync_to_openstudio</name>
<uid>a1332e7f-c99d-48a1-83f5-956947cc3d9d</uid>
<version_id>1f614d85-5ebd-4ba0-b4be-3d8d0b18e34b</version_id>
<version_modified>20221212T163657Z</version_modified>
<xml_checksum>BABEA42F</xml_checksum>
<class_name>BuildingSyncToOpenStudio</class_name>
<display_name>Building Sync to OpenStudio</display_name>
<description>This measure-gem converts a BuildingSync XML file into a series of OSWs. Each OSW corresponds to an energy efficiency package of measures defined in the BuildingSync XML file. The OSWs can then be simulated and the results are written back into the BuildingSync XML file.</description>
<modeler_description>The measure will use a BuildingSync XML file as an input. The XML can be created using tools such as [bsyncpy](https://pypi.org/project/bsync/).
The XML will be parsed and a new OpenStudio model will be created. A new OSW will be created for each energy efficiency package of measures defined in the XML, using the measures defined in the ./lib/buildingsync/makers/phase_zero_base.osw file.
The user has a choice for just generating OSWs or generating and simulating them. If the OSWs are simulated, then the results are collected and reports are generated. These reports will be written in the original BuildingSync XML file, and that XML file will be saved.</modeler_description>
<arguments>
<argument>
<name>building_sync_xml_file_path</name>
<display_name>BSync XML path</display_name>
<description>The path to the XML file that should be translated.</description>
<type>String</type>
<required>true</required>
<model_dependent>false</model_dependent>
</argument>
<argument>
<name>out_path</name>
<display_name>BSync output path</display_name>
<description>The output directory where all workflows and results will be written.</description>
<type>String</type>
<required>true</required>
<model_dependent>false</model_dependent>
</argument>
<argument>
<name>simulate_flag</name>
<display_name>Simulate and record results?</display_name>
<description>The generated OSWs will be simulated and the results recorded into the original XML file.</description>
<type>Boolean</type>
<required>true</required>
<model_dependent>false</model_dependent>
<default_value>true</default_value>
<choices>
<choice>
<value>true</value>
<display_name>true</display_name>
</choice>
<choice>
<value>false</value>
<display_name>false</display_name>
</choice>
</choices>
</argument>
</arguments>
<outputs />
<provenances />
<tags>
<tag>Whole Building.Space Types</tag>
</tags>
<attributes>
<attribute>
<name>Measure Type</name>
<value>ModelMeasure</value>
<datatype>string</datatype>
</attribute>
<attribute>
<name>Intended Software Tool</name>
<value>OpenStudio Application</value>
<datatype>string</datatype>
</attribute>
<attribute>
<name>Intended Software Tool</name>
<value>Parametric Analysis Tool</value>
<datatype>string</datatype>
</attribute>
<attribute>
<name>Intended Use Case</name>
<value>Model Articulation</value>
<datatype>string</datatype>
</attribute>
</attributes>
<files>
<file>
<filename>example_model.osm</filename>
<filetype>osm</filetype>
<usage_type>test</usage_type>
<checksum>53D14E69</checksum>
</file>
<file>
<filename>building_151.xml</filename>
<filetype>xml</filetype>
<usage_type>test</usage_type>
<checksum>473F7333</checksum>
</file>
<file>
<filename>building_sync_to_openstudio_test.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>C559751A</checksum>
</file>
<file>
<filename>LICENSE.md</filename>
<filetype>md</filetype>
<usage_type>license</usage_type>
<checksum>59563DB3</checksum>
</file>
<file>
<filename>README.md</filename>
<filetype>md</filetype>
<usage_type>readme</usage_type>
<checksum>397303E4</checksum>
</file>
<file>
<version>
<software_program>OpenStudio</software_program>
<identifier>3.4.0</identifier>
<min_compatible>3.4.0</min_compatible>
</version>
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>623FB62E</checksum>
</file>
</files>
</measure>
Loading

0 comments on commit c7f7177

Please sign in to comment.