honeybee-openstudio 2.14.0 → 2.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/honeybee-openstudio.gemspec +1 -1
  3. data/lib/from_openstudio/geometry/aperture.rb +1 -1
  4. data/lib/from_openstudio/geometry/door.rb +1 -1
  5. data/lib/from_openstudio/geometry/face.rb +1 -1
  6. data/lib/from_openstudio/geometry/room.rb +1 -1
  7. data/lib/from_openstudio/geometry/shade.rb +2 -2
  8. data/lib/from_openstudio/material/window_gas.rb +51 -0
  9. data/lib/from_openstudio/material/window_gas_custom.rb +94 -0
  10. data/lib/from_openstudio/material/window_gas_mixture.rb +70 -0
  11. data/lib/from_openstudio/model.rb +17 -0
  12. data/lib/honeybee/model_object.rb +1 -1
  13. data/lib/measures/from_gbxml_model/LICENSE.md +23 -0
  14. data/lib/measures/from_gbxml_model/README.md +32 -0
  15. data/lib/measures/from_gbxml_model/measure.rb +114 -0
  16. data/lib/measures/from_gbxml_model/measure.xml +131 -0
  17. data/lib/measures/from_gbxml_model/tests/from_gbxml_model_test.rb +107 -0
  18. data/lib/measures/from_honeybee_model/README.md +1 -1
  19. data/lib/measures/from_honeybee_model_to_gbxml/LICENSE.md +23 -0
  20. data/lib/measures/from_honeybee_model_to_gbxml/README.md +32 -0
  21. data/lib/measures/from_honeybee_model_to_gbxml/measure.rb +113 -0
  22. data/lib/measures/from_honeybee_model_to_gbxml/measure.xml +88 -0
  23. data/lib/measures/from_honeybee_model_to_gbxml/tests/from_honeybee_model_to_gbxml_test.rb +105 -0
  24. data/lib/measures/from_idf_model/LICENSE.md +23 -0
  25. data/lib/measures/from_idf_model/README.md +32 -0
  26. data/lib/measures/from_idf_model/measure.rb +114 -0
  27. data/lib/measures/from_idf_model/measure.xml +110 -0
  28. data/lib/measures/from_idf_model/tests/from_idf_model_test.rb +107 -0
  29. data/lib/measures/from_openstudio_model/LICENSE.md +23 -0
  30. data/lib/measures/from_openstudio_model/README.md +32 -0
  31. data/lib/measures/from_openstudio_model/measure.rb +114 -0
  32. data/lib/measures/from_openstudio_model/measure.xml +95 -0
  33. data/lib/measures/from_openstudio_model/tests/from_openstudio_model_test.rb +107 -0
  34. data/lib/to_openstudio/hvac/template.rb +13 -5
  35. metadata +25 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d55946adb807546ddf9ab4f0301b2e1cffb35cd8c82410ebe5356917ae477a3
4
- data.tar.gz: c514dc1640e95f715b5823850ac33473289646883fd33b1927eb956263a8243f
3
+ metadata.gz: 66ae9758cba208e8afec207691b30cbb6a04609dae3bec493012d80c4cac90ea
4
+ data.tar.gz: 2c1855d1205a09c4ec772ed387e4faaf70ed50d608502f1a239b41a12fe1d744
5
5
  SHA512:
6
- metadata.gz: 7504924fd9d88b8e6edc1f7294dffb0e8dad834d4131b269c443ffabf4c24158b4c6b64d8900acd58e4135cfb7e95b675754691d81e2ff7bf28e5e9148bbc8c9
7
- data.tar.gz: cfd4957cdeadead04d873cc4c98a2d81b701f8ad7e45aa6fe7f368e1c0f6e352062119d4ee52492efee7c8294421d60a4e18981c68a31bd2d4577134a3eccde1
6
+ metadata.gz: e777c64f22ee4219970724d5ab904361707eb8fdff93578bfb627dee782cc518c57a7bab963b04fdd92d72638be0897f742f2e05a5b658ef62537a880a1343e1
7
+ data.tar.gz: 3c469b7d70a7c9ee1375b3781a92f13ec4f66b1a1af860dfa4b8f5839db9194281e61159f0b7e6de00b067f539eedbb052941e66d0f142e8bea08e34eeb20e7a
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'honeybee-openstudio'
7
- spec.version = '2.14.0'
7
+ spec.version = '2.16.3'
8
8
  spec.authors = ['Tanushree Charan', 'Dan Macumber', 'Chris Mackey', 'Mostapha Sadeghipour Roudsari']
9
9
  spec.email = ['tanushree.charan@nrel.gov', 'chris@ladybug.tools']
10
10
 
@@ -71,7 +71,7 @@ module Honeybee
71
71
 
72
72
  construction = sub_surface.construction
73
73
  if !construction.empty?
74
- hash[:construction] = clean_identifier(construction.get.nameString)
74
+ hash[:construction] = construction.get.nameString
75
75
  end
76
76
 
77
77
  hash
@@ -71,7 +71,7 @@ module Honeybee
71
71
 
72
72
  construction = sub_surface.construction
73
73
  if !construction.empty?
74
- hash[:construction] = clean_identifier(construction.get.nameString)
74
+ hash[:construction] = construction.get.nameString
75
75
  end
76
76
 
77
77
  hash
@@ -73,7 +73,7 @@ module Honeybee
73
73
 
74
74
  construction = surface.construction
75
75
  if !construction.empty?
76
- hash[:construction] = clean_identifier(construction.get.nameString)
76
+ hash[:construction] = construction.get.nameString
77
77
  end
78
78
 
79
79
  hash
@@ -112,7 +112,7 @@ module Honeybee
112
112
  def self.story_from_space(space)
113
113
  story = space.buildingStory
114
114
  if !story.empty?
115
- return clean_identifier(story.get.nameString)
115
+ return story.get.nameString
116
116
  end
117
117
  nil
118
118
  end
@@ -61,12 +61,12 @@ module Honeybee
61
61
 
62
62
  construction = shading_surface.construction
63
63
  if !construction.empty?
64
- hash[:construction] = clean_identifier(construction.get.nameString)
64
+ hash[:construction] = construction.get.nameString
65
65
  end
66
66
 
67
67
  transmittance_schedule = shading_surface.transmittanceSchedule
68
68
  if !transmittance_schedule.empty?
69
- hash[:transmittance_schedule] = clean_identifier(transmittance_schedule.get.nameString)
69
+ hash[:transmittance_schedule] = transmittance_schedule.get.nameString
70
70
  end
71
71
 
72
72
  hash
@@ -0,0 +1,51 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'honeybee/material/window_gas'
33
+ require 'to_openstudio/model_object'
34
+
35
+ module Honeybee
36
+ class EnergyWindowMaterialGas
37
+
38
+ def self.from_material(material)
39
+ # create an empty hash
40
+ hash = {}
41
+ hash[:type] = 'EnergyWindowMaterialGas'
42
+ # set hash values from OpenStudio Object
43
+ hash[:identifier] = material.nameString
44
+ hash[:thickness] = material.thickness
45
+ hash[:gas_type] = material.gasType
46
+
47
+ hash
48
+ end
49
+
50
+ end # EnergyWindowMaterialGas
51
+ end # Honeybee
@@ -0,0 +1,94 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'honeybee/material/window_gas_custom'
33
+ require 'to_openstudio/model_object'
34
+
35
+ module Honeybee
36
+ class EnergyWindowMaterialGasCustom
37
+
38
+ def self.from_material(material)
39
+ # create an empty hash
40
+ hash = {}
41
+ hash[:type] = 'EnergyWindowMaterialGasCustom'
42
+ # set hash values from OpenStudio Object
43
+ hash[:identifier] = material.nameString
44
+ hash[:thickness] = material.thickness
45
+ # check if boost optional object is empty
46
+ unless material.customConductivityCoefficientA.empty?
47
+ hash[:conductivity_coeff_a] = material.customConductivityCoefficientA.get
48
+ end
49
+ # check if boost optional object is empty
50
+ unless material.customConductivityCoefficientB.empty?
51
+ hash[:conductivity_coeff_b] = material.customConductivityCoefficientB.get
52
+ end
53
+ # check if boost optional object is empty
54
+ unless material.customConductivityCoefficientC.empty?
55
+ hash[:conductivity_coeff_c] = material.customConductivityCoefficientC.get
56
+ end
57
+ # check if boost optional object is empty
58
+ unless material.viscosityCoefficientA.empty?
59
+ hash[:viscosity_coeff_a] = material.viscosityCoefficientA.get
60
+ end
61
+ # check if boost optional object is empty
62
+ unless material.viscosityCoefficientB.empty?
63
+ hash[:viscosity_coeff_b] = material.viscosityCoefficientB.get
64
+ end
65
+ # check if boost optional object is empty
66
+ unless material.viscosityCoefficientC.empty?
67
+ hash[:viscosity_coeff_c] = material.viscosityCoefficientC.get
68
+ end
69
+ # check if boost optional object is empty
70
+ unless material.specificHeatCoefficientA.empty?
71
+ hash[:specific_heat_coeff_a] = material.specificHeatCoefficientA.get
72
+ end
73
+ # check if boost optional object is empty
74
+ unless material.specificHeatCoefficientB.empty?
75
+ hash[:specific_heat_coeff_b] = material.specificHeatCoefficientB.get
76
+ end
77
+ # check if boost optional object is empty
78
+ unless material.specificHeatCoefficientC.empty?
79
+ hash[:specific_heat_coeff_c] = material.specificHeatCoefficientC.get
80
+ end
81
+ # check if boost optional object is empty
82
+ unless material.specificHeatRatio.empty?
83
+ hash[:specific_heat_ratio] = material.specificHeatRatio.get
84
+ end
85
+ # check if boost optional object is empty
86
+ unless material.molecularWeight.empty?
87
+ hash[:molecular_weight] = material.molecularWeight.get
88
+ end
89
+
90
+ hash
91
+ end
92
+
93
+ end # EnergyWindowMaterialGasCustom
94
+ end # Honeybee
@@ -0,0 +1,70 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'honeybee/material/window_gas_mixture'
33
+ require 'to_openstudio/model_object'
34
+
35
+ module Honeybee
36
+ class EnergyWindowMaterialGasMixture
37
+
38
+ def self.from_material(material)
39
+ # create an empty hash
40
+ hash = {}
41
+ hash[:type] = 'EnergyWindowMaterialGasMixture'
42
+ # set hash values from OpenStudio Object
43
+ hash[:identifier] = material.nameString
44
+ hash[:thickness] = material.thickness
45
+ hash[:gas_types] = []
46
+ hash[:gas_fractions] = []
47
+ number_of_gases = material.numberofGasesinMixture
48
+ if number_of_gases > 1
49
+ (1..number_of_gases).each do |n|
50
+ hash[:gas_types] << material.send('gas' + n.to_s + 'Type')
51
+ end
52
+ hash[:gas_fractions] << material.gas1Fraction
53
+ hash[:gas_fractions] << material.gas2Fraction
54
+ if number_of_gases > 2
55
+ unless material.gas3Fraction.empty?
56
+ hash[:gas_fractions] << material.gas3Fraction.get
57
+ end
58
+ if number_of_gases > 3
59
+ unless material.gas4Fraction.empty?
60
+ hash[:gas_fractions] << material.gas4Fraction.get
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ hash
67
+ end
68
+
69
+ end # EnergyWindowMaterialGasMixture
70
+ end # Honeybee
@@ -38,6 +38,9 @@ require 'from_openstudio/material/opaque_no_mass'
38
38
  require 'from_openstudio/material/window_simpleglazsys'
39
39
  require 'from_openstudio/material/window_glazing'
40
40
  require 'from_openstudio/material/window_blind'
41
+ require 'from_openstudio/material/window_gas'
42
+ require 'from_openstudio/material/window_gas_custom'
43
+ require 'from_openstudio/material/window_gas_mixture'
41
44
 
42
45
  require 'openstudio'
43
46
 
@@ -150,6 +153,20 @@ module Honeybee
150
153
  openstudio_model.getBlinds.each do |material|
151
154
  result << EnergyWindowMaterialBlind.from_material(material)
152
155
  end
156
+ openstudio_model.getGass.each do |material|
157
+ # Create HB WindowGasCustom from OpenStudio Material
158
+ if material.gasType == 'Custom'
159
+ result << EnergyWindowMaterialGasCustom.from_material(material)
160
+ else
161
+ # Create HB WindowGas from OpenStudio Material
162
+ result << EnergyWindowMaterialGas.from_material(material)
163
+ end
164
+ end
165
+ # Create HB EnergyWindowMaterialGasMixture from OpenStudio Material
166
+ openstudio_model.getGasMixtures.each do |material|
167
+ result << EnergyWindowMaterialGasMixture.from_material(material)
168
+ end
169
+
153
170
  result
154
171
  end
155
172
 
@@ -100,7 +100,7 @@ module Honeybee
100
100
 
101
101
  # remove illegal characters in identifier
102
102
  def self.clean_identifier(str)
103
- str.gsub(' ', '_')
103
+ str.gsub(/[^.A-Za-z0-9_-] /, '_').gsub(' ', '_')
104
104
  end
105
105
 
106
106
 
@@ -0,0 +1,23 @@
1
+ Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable Energy, LLC,
2
+ Ladybug Tools LLC and other contributors. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5
+ following conditions are met:
6
+
7
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8
+ disclaimer.
9
+
10
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11
+ disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
14
+ derived from this software without specific prior written permission from the respective party.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
19
+ STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,32 @@
1
+
2
+
3
+ ###### (Automatically generated documentation)
4
+
5
+ # From gbXML Model
6
+
7
+ ## Description
8
+ Translate a gbXML model into a JSON file of a Honeybee Model.
9
+
10
+ ## Modeler Description
11
+ Translate a gbXML model into a JSON file of a Honeybee Model.
12
+
13
+ ## Measure Type
14
+ ModelMeasure
15
+
16
+ ## Taxonomy
17
+
18
+
19
+ ## Arguments
20
+
21
+
22
+ ### Path to the gbXML Model file
23
+
24
+ **Name:** gbxml_model,
25
+ **Type:** String,
26
+ **Units:** ,
27
+ **Required:** true,
28
+ **Model Dependent:** false
29
+
30
+
31
+
32
+
@@ -0,0 +1,114 @@
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ # see the URL below for information on how to write OpenStudio measures
33
+ # http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
34
+
35
+ require 'from_openstudio'
36
+
37
+ # start the measure
38
+ class FromGbxmlModel < OpenStudio::Measure::ModelMeasure
39
+ # human readable name
40
+ def name
41
+ return "From Gbxml Model"
42
+ end
43
+
44
+ # human readable description
45
+ def description
46
+ return "Translate a gbXML into a JSON file of a Honeybee Model."
47
+ end
48
+
49
+ # human readable description of modeling approach
50
+ def modeler_description
51
+ return "Translate a gbXML into a JSON file of a Honeybee Model."
52
+ end
53
+
54
+ # define the arguments that the user will input
55
+ def arguments(model)
56
+ args = OpenStudio::Measure::OSArgumentVector.new
57
+
58
+ # Make an argument for the OpenStudio model
59
+ gbxml_model = OpenStudio::Measure::OSArgument.makeStringArgument('gbxml_model', true)
60
+ gbxml_model.setDisplayName('Path to the gbXML Model')
61
+ args << gbxml_model
62
+
63
+ # Make an argument for the output file path
64
+ output_file_path = OpenStudio::Measure::OSArgument.makeStringArgument('output_file_path', false)
65
+ output_file_path.setDisplayName('Output file path')
66
+ output_file_path.setDescription('If set, the output Honeybee JSON file will be exported to this path. Othervise The file will be exported to the same path as the gbXML model.')
67
+ output_file_path.setDefaultValue('')
68
+ args << output_file_path
69
+
70
+ return args
71
+ end
72
+
73
+ # define what happens when the measure is run
74
+ def run(model, runner, user_arguments)
75
+ super(model, runner, user_arguments)
76
+ STDOUT.flush
77
+ if !runner.validateUserArguments(arguments(model), user_arguments)
78
+ return false
79
+ end
80
+
81
+ gbxml_model = runner.getStringArgumentValue('gbxml_model', user_arguments)
82
+
83
+ gbxml_model_path, gbxml_model_name = File.split(gbxml_model)
84
+ honeybee_model_name = gbxml_model_name.split('.')[0] + '.hbjson'
85
+
86
+ if !File.exist?(gbxml_model)
87
+ runner.registerError("Cannot find file '#{gbxml_model}'")
88
+ return false
89
+ end
90
+
91
+ honeybee_model = Honeybee::Model.translate_from_gbxml_file(gbxml_model)
92
+ honeybee_hash = honeybee_model.hash
93
+
94
+ output_file_path = runner.getStringArgumentValue('output_file_path', user_arguments)
95
+
96
+ if output_file_path && !output_file_path.empty?
97
+ unless File.exist?(output_file_path)
98
+ output_folder = File.split(output_file_path)[0]
99
+ FileUtils.mkdir_p(output_folder)
100
+ end
101
+ else
102
+ output_file_path = File.join(gbxml_model_path, honeybee_model_name)
103
+ end
104
+
105
+ File.open(output_file_path, 'w') do |f|
106
+ f.puts JSON::pretty_generate(honeybee_hash)
107
+ end
108
+
109
+ return true
110
+ end
111
+ end
112
+
113
+ # register the measure to be used by the application
114
+ FromGbxmlModel.new.registerWithApplication