honeybee-openstudio 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -1
  3. data/.gitignore +32 -32
  4. data/.releaserc.json +7 -7
  5. data/.travis.yml +42 -41
  6. data/Gemfile +18 -18
  7. data/LICENSE.md +23 -23
  8. data/README.md +95 -95
  9. data/Rakefile +20 -20
  10. data/doc_templates/LICENSE.md +23 -23
  11. data/doc_templates/copyright_erb.txt +31 -31
  12. data/doc_templates/copyright_js.txt +4 -4
  13. data/doc_templates/copyright_ruby.txt +29 -29
  14. data/honeybee-openstudio.gemspec +35 -35
  15. data/lib/files/Honeybee.rb +112 -112
  16. data/lib/files/honeybee_workflow.osw +47 -47
  17. data/lib/files/urbanopt_Gemfile +32 -32
  18. data/lib/from_honeybee.rb +86 -86
  19. data/lib/from_honeybee/_openapi/model.json +8126 -8126
  20. data/lib/from_honeybee/_openapi/simulation-parameter.json +842 -842
  21. data/lib/from_honeybee/construction/air.rb +64 -64
  22. data/lib/from_honeybee/construction/opaque.rb +76 -76
  23. data/lib/from_honeybee/construction/shade.rb +107 -107
  24. data/lib/from_honeybee/construction/window.rb +80 -80
  25. data/lib/from_honeybee/construction_set.rb +278 -278
  26. data/lib/from_honeybee/extension.rb +109 -109
  27. data/lib/from_honeybee/geometry/aperture.rb +167 -167
  28. data/lib/from_honeybee/geometry/door.rb +160 -160
  29. data/lib/from_honeybee/geometry/face.rb +163 -163
  30. data/lib/from_honeybee/geometry/room.rb +392 -392
  31. data/lib/from_honeybee/geometry/shade.rb +89 -89
  32. data/lib/from_honeybee/hvac/ideal_air.rb +150 -150
  33. data/lib/from_honeybee/load/electric_equipment.rb +95 -95
  34. data/lib/from_honeybee/load/gas_equipment.rb +97 -97
  35. data/lib/from_honeybee/load/infiltration.rb +94 -94
  36. data/lib/from_honeybee/load/lighting.rb +98 -98
  37. data/lib/from_honeybee/load/people.rb +99 -99
  38. data/lib/from_honeybee/load/setpoint_humidistat.rb +74 -74
  39. data/lib/from_honeybee/load/setpoint_thermostat.rb +71 -71
  40. data/lib/from_honeybee/load/ventilation.rb +95 -95
  41. data/lib/from_honeybee/material/opaque.rb +94 -94
  42. data/lib/from_honeybee/material/opaque_no_mass.rb +94 -94
  43. data/lib/from_honeybee/material/window_blind.rb +238 -238
  44. data/lib/from_honeybee/material/window_gas.rb +76 -76
  45. data/lib/from_honeybee/material/window_gas_custom.rb +118 -118
  46. data/lib/from_honeybee/material/window_gas_mixture.rb +79 -79
  47. data/lib/from_honeybee/material/window_glazing.rb +166 -166
  48. data/lib/from_honeybee/material/window_shade.rb +160 -160
  49. data/lib/from_honeybee/material/window_simpleglazsys.rb +73 -73
  50. data/lib/from_honeybee/model.rb +434 -434
  51. data/lib/from_honeybee/model_object.rb +110 -110
  52. data/lib/from_honeybee/program_type.rb +124 -124
  53. data/lib/from_honeybee/schedule/fixed_interval.rb +115 -115
  54. data/lib/from_honeybee/schedule/ruleset.rb +164 -164
  55. data/lib/from_honeybee/schedule/type_limit.rb +88 -88
  56. data/lib/from_honeybee/simulation/designday.rb +105 -105
  57. data/lib/from_honeybee/simulation/extension.rb +46 -46
  58. data/lib/from_honeybee/simulation/parameter.rb +277 -277
  59. data/lib/from_honeybee/version.rb +34 -34
  60. data/lib/measures/from_honeybee_model/LICENSE.md +26 -26
  61. data/lib/measures/from_honeybee_model/README.md +32 -32
  62. data/lib/measures/from_honeybee_model/measure.rb +91 -91
  63. data/lib/measures/from_honeybee_model/measure.xml +103 -103
  64. data/lib/measures/from_honeybee_model/tests/from_honeybee_model_test.rb +126 -126
  65. data/lib/measures/from_honeybee_simulation_parameter/LICENSE.md +26 -26
  66. data/lib/measures/from_honeybee_simulation_parameter/README.md +32 -32
  67. data/lib/measures/from_honeybee_simulation_parameter/measure.rb +95 -95
  68. data/lib/measures/from_honeybee_simulation_parameter/measure.xml +91 -91
  69. data/lib/measures/from_honeybee_simulation_parameter/tests/from_honeybee_simulation_parameter_test.rb +109 -109
  70. metadata +2 -2
@@ -1,109 +1,109 @@
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 'openstudio/extension'
33
-
34
- # NOTE: This file has been derived from one within the openStudio-extension gem
35
- # The properties here are a standard part of openstudio extensions
36
-
37
- module FromHoneybee
38
- class Extension < OpenStudio::Extension::Extension
39
- @@schema = nil
40
-
41
- # Override parent class
42
- def initialize
43
- super
44
-
45
- # Note that the root_dir is only meaningful when the gem is in a github repository
46
- # When installed as a Ruby gem, the highest directory within the gem is the lib_dir
47
- @root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
48
- @lib_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..'))
49
-
50
- @instance_lock = Mutex.new
51
- @@schema ||= schema
52
- end
53
-
54
- # Return the absolute path of the measures or nil if there is none.
55
- # Can be used when configuring OSWs
56
- def measures_dir
57
- File.absolute_path(File.join(@lib_dir, 'measures'))
58
- end
59
-
60
- # Relevant files such as the openapi JSON schema files for the honeybee model.
61
- # Return the absolute path of the files or nil if there is none.
62
- # Used when configuring OSWs
63
- def files_dir
64
- File.absolute_path(File.join(@lib_dir, 'files'))
65
- end
66
-
67
- # Doc templates are common files like copyright files which are used to update measures
68
- # Doc templates will only be applied when the gem is a part of a repository
69
- # Return the absolute path of the doc templates dir or nil if there is none
70
- def doc_templates_dir
71
- File.absolute_path(File.join(@root_dir, 'doc_templates'))
72
- end
73
-
74
- # return path to the model schema file
75
- def schema_file
76
- File.join(@lib_dir, 'from_honeybee', '_openapi', 'model.json')
77
- end
78
-
79
- # return the model schema
80
- def schema
81
- @instance_lock.synchronize do
82
- if @@schema.nil?
83
- File.open(schema_file, 'r') do |f|
84
- @@schema = JSON.parse(f.read, symbolize_names: true)
85
- end
86
- end
87
- end
88
-
89
- @@schema
90
- end
91
-
92
- # check if the model schema is valid
93
- def schema_valid?
94
- if Gem.loaded_specs.has_key?("json-schema")
95
- require 'json-schema'
96
- metaschema = JSON::Validator.validator_for_name('draft6').metaschema
97
- JSON::Validator.validate(metaschema, @@schema)
98
- end
99
- end
100
-
101
- # return detailed schema validation errors
102
- def schema_validation_errors
103
- if Gem.loaded_specs.has_key?("json-schema")
104
- metaschema = JSON::Validator.validator_for_name('draft6').metaschema
105
- JSON::Validator.fully_validate(metaschema, @@schema)
106
- end
107
- end
108
- end
109
- end
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 'openstudio/extension'
33
+
34
+ # NOTE: This file has been derived from one within the openStudio-extension gem
35
+ # The properties here are a standard part of openstudio extensions
36
+
37
+ module FromHoneybee
38
+ class Extension < OpenStudio::Extension::Extension
39
+ @@schema = nil
40
+
41
+ # Override parent class
42
+ def initialize
43
+ super
44
+
45
+ # Note that the root_dir is only meaningful when the gem is in a github repository
46
+ # When installed as a Ruby gem, the highest directory within the gem is the lib_dir
47
+ @root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
48
+ @lib_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..'))
49
+
50
+ @instance_lock = Mutex.new
51
+ @@schema ||= schema
52
+ end
53
+
54
+ # Return the absolute path of the measures or nil if there is none.
55
+ # Can be used when configuring OSWs
56
+ def measures_dir
57
+ File.absolute_path(File.join(@lib_dir, 'measures'))
58
+ end
59
+
60
+ # Relevant files such as the openapi JSON schema files for the honeybee model.
61
+ # Return the absolute path of the files or nil if there is none.
62
+ # Used when configuring OSWs
63
+ def files_dir
64
+ File.absolute_path(File.join(@lib_dir, 'files'))
65
+ end
66
+
67
+ # Doc templates are common files like copyright files which are used to update measures
68
+ # Doc templates will only be applied when the gem is a part of a repository
69
+ # Return the absolute path of the doc templates dir or nil if there is none
70
+ def doc_templates_dir
71
+ File.absolute_path(File.join(@root_dir, 'doc_templates'))
72
+ end
73
+
74
+ # return path to the model schema file
75
+ def schema_file
76
+ File.join(@lib_dir, 'from_honeybee', '_openapi', 'model.json')
77
+ end
78
+
79
+ # return the model schema
80
+ def schema
81
+ @instance_lock.synchronize do
82
+ if @@schema.nil?
83
+ File.open(schema_file, 'r') do |f|
84
+ @@schema = JSON.parse(f.read, symbolize_names: true)
85
+ end
86
+ end
87
+ end
88
+
89
+ @@schema
90
+ end
91
+
92
+ # check if the model schema is valid
93
+ def schema_valid?
94
+ if Gem.loaded_specs.has_key?("json-schema")
95
+ require 'json-schema'
96
+ metaschema = JSON::Validator.validator_for_name('draft6').metaschema
97
+ JSON::Validator.validate(metaschema, @@schema)
98
+ end
99
+ end
100
+
101
+ # return detailed schema validation errors
102
+ def schema_validation_errors
103
+ if Gem.loaded_specs.has_key?("json-schema")
104
+ metaschema = JSON::Validator.validator_for_name('draft6').metaschema
105
+ JSON::Validator.fully_validate(metaschema, @@schema)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -1,167 +1,167 @@
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 'from_honeybee/model_object'
33
-
34
- require 'openstudio'
35
-
36
- module FromHoneybee
37
- class Aperture < ModelObject
38
- attr_reader :errors, :warnings
39
-
40
- def initialize(hash)
41
- super(hash)
42
- raise "Incorrect model type '#{@type}'" unless @type == 'Aperture'
43
- end
44
-
45
- def defaults
46
- @@schema[:components][:schemas][:ApertureEnergyPropertiesAbridged][:properties]
47
- end
48
-
49
- def find_existing_openstudio_object(openstudio_model)
50
- object = openstudio_model.getSubSurfaceByName(@hash[:identifier])
51
- return object.get if object.is_initialized
52
- nil
53
- end
54
-
55
- def to_openstudio(openstudio_model)
56
- # create the OpenStudio aperture object
57
- os_vertices = OpenStudio::Point3dVector.new
58
- @hash[:geometry][:boundary].each do |vertex|
59
- os_vertices << OpenStudio::Point3d.new(vertex[0], vertex[1], vertex[2])
60
- end
61
- reordered_vertices = OpenStudio.reorderULC(os_vertices)
62
-
63
- # triangulate subsurface if neccesary
64
- triangulated = false
65
- final_vertices_list = []
66
- matching_os_subsurfaces = []
67
- matching_os_subsurface_indices = []
68
- if reordered_vertices.size > 4
69
-
70
- # if this apeture has a matched apeture, see if the other one has already been created
71
- # the matched apeture should have been converted to multiple subsurfaces
72
- if @hash[:boundary_condition][:type] == 'Surface'
73
- adj_srf_identifier = @hash[:boundary_condition][:boundary_condition_objects][0]
74
- regex = Regexp.new("#{adj_srf_identifier}\.\.(\\d+)")
75
- openstudio_model.getSubSurfaces.each do |subsurface|
76
- if md = regex.match(subsurface.nameString)
77
- final_vertices_list << OpenStudio.reorderULC(OpenStudio::reverse(subsurface.vertices))
78
- matching_os_subsurfaces << subsurface
79
- matching_os_subsurface_indices << md[1]
80
- end
81
- end
82
- end
83
-
84
- # if other apeture is not already created, do the triangulation
85
- if final_vertices_list.empty?
86
-
87
- # transform to face coordinates
88
- t = OpenStudio::Transformation::alignFace(reordered_vertices)
89
- tInv = t.inverse
90
- face_vertices = OpenStudio::reverse(tInv*reordered_vertices)
91
-
92
- # no holes in the subsurface
93
- holes = OpenStudio::Point3dVectorVector.new
94
-
95
- # triangulate surface
96
- triangles = OpenStudio::computeTriangulation(face_vertices, holes)
97
- if triangles.empty?
98
- raise "Failed to triangulate aperture #{@hash[:identifier]} with #{reordered_vertices.size} vertices"
99
- end
100
-
101
- # create new list of surfaces
102
- triangles.each do |vertices|
103
- final_vertices_list << OpenStudio.reorderULC(OpenStudio::reverse(t*vertices))
104
- end
105
-
106
- triangulated = true
107
-
108
- end
109
-
110
- else
111
- # reordered_vertices are good as is
112
- final_vertices_list << reordered_vertices
113
- end
114
-
115
- result = []
116
- final_vertices_list.each_with_index do |reordered_vertices, index|
117
- os_subsurface = OpenStudio::Model::SubSurface.new(reordered_vertices, openstudio_model)
118
-
119
- if !matching_os_subsurfaces.empty?
120
- os_subsurface.setName(@hash[:identifier] + "..#{matching_os_subsurface_indices[index]}")
121
- elsif triangulated
122
- os_subsurface.setName(@hash[:identifier] + "..#{index}")
123
- else
124
- os_subsurface.setName(@hash[:identifier])
125
- end
126
-
127
- # assign the construction if it exists
128
- if @hash[:properties][:energy][:construction]
129
- construction_identifier = @hash[:properties][:energy][:construction]
130
- construction = openstudio_model.getConstructionByName(construction_identifier)
131
- unless construction.empty?
132
- os_construction = construction.get
133
- os_subsurface.setConstruction(os_construction)
134
- end
135
- end
136
-
137
- # assign the boundary condition object if it's a Surface
138
- if @hash[:boundary_condition][:type] == 'Surface'
139
- if !matching_os_subsurfaces.empty?
140
- # we already have the match because this was created from the matching_os_subsurfaces
141
- # setAdjacentSubSurface will fail at this point because sub surface is not assigned to surface yet, store data for later
142
- adj_srf_identifier = matching_os_subsurfaces[index].nameString
143
- os_subsurface.additionalProperties.setFeature("AdjacentSubSurfaceName", adj_srf_identifier)
144
- elsif triangulated
145
- # other subsurfaces haven't been created yet, no-op
146
- else
147
- # get adjacent sub surface by identifier from openstudio model
148
- # setAdjacentSubSurface will fail at this point because sub surface is not assigned to surface yet, store data for later
149
- adj_srf_identifier = @hash[:boundary_condition][:boundary_condition_objects][0]
150
- os_subsurface.additionalProperties.setFeature("AdjacentSubSurfaceName", adj_srf_identifier)
151
- end
152
- end
153
-
154
- # assign the operable property
155
- if @hash[:is_operable] == false
156
- os_subsurface.setSubSurfaceType('FixedWindow')
157
- else
158
- os_subsurface.setSubSurfaceType('OperableWindow')
159
- end
160
-
161
- result << os_subsurface
162
- end
163
-
164
- return result
165
- end
166
- end # Aperture
167
- end # FromHoneybee
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 'from_honeybee/model_object'
33
+
34
+ require 'openstudio'
35
+
36
+ module FromHoneybee
37
+ class Aperture < ModelObject
38
+ attr_reader :errors, :warnings
39
+
40
+ def initialize(hash)
41
+ super(hash)
42
+ raise "Incorrect model type '#{@type}'" unless @type == 'Aperture'
43
+ end
44
+
45
+ def defaults
46
+ @@schema[:components][:schemas][:ApertureEnergyPropertiesAbridged][:properties]
47
+ end
48
+
49
+ def find_existing_openstudio_object(openstudio_model)
50
+ object = openstudio_model.getSubSurfaceByName(@hash[:identifier])
51
+ return object.get if object.is_initialized
52
+ nil
53
+ end
54
+
55
+ def to_openstudio(openstudio_model)
56
+ # create the OpenStudio aperture object
57
+ os_vertices = OpenStudio::Point3dVector.new
58
+ @hash[:geometry][:boundary].each do |vertex|
59
+ os_vertices << OpenStudio::Point3d.new(vertex[0], vertex[1], vertex[2])
60
+ end
61
+ reordered_vertices = OpenStudio.reorderULC(os_vertices)
62
+
63
+ # triangulate subsurface if neccesary
64
+ triangulated = false
65
+ final_vertices_list = []
66
+ matching_os_subsurfaces = []
67
+ matching_os_subsurface_indices = []
68
+ if reordered_vertices.size > 4
69
+
70
+ # if this apeture has a matched apeture, see if the other one has already been created
71
+ # the matched apeture should have been converted to multiple subsurfaces
72
+ if @hash[:boundary_condition][:type] == 'Surface'
73
+ adj_srf_identifier = @hash[:boundary_condition][:boundary_condition_objects][0]
74
+ regex = Regexp.new("#{adj_srf_identifier}\.\.(\\d+)")
75
+ openstudio_model.getSubSurfaces.each do |subsurface|
76
+ if md = regex.match(subsurface.nameString)
77
+ final_vertices_list << OpenStudio.reorderULC(OpenStudio::reverse(subsurface.vertices))
78
+ matching_os_subsurfaces << subsurface
79
+ matching_os_subsurface_indices << md[1]
80
+ end
81
+ end
82
+ end
83
+
84
+ # if other apeture is not already created, do the triangulation
85
+ if final_vertices_list.empty?
86
+
87
+ # transform to face coordinates
88
+ t = OpenStudio::Transformation::alignFace(reordered_vertices)
89
+ tInv = t.inverse
90
+ face_vertices = OpenStudio::reverse(tInv*reordered_vertices)
91
+
92
+ # no holes in the subsurface
93
+ holes = OpenStudio::Point3dVectorVector.new
94
+
95
+ # triangulate surface
96
+ triangles = OpenStudio::computeTriangulation(face_vertices, holes)
97
+ if triangles.empty?
98
+ raise "Failed to triangulate aperture #{@hash[:identifier]} with #{reordered_vertices.size} vertices"
99
+ end
100
+
101
+ # create new list of surfaces
102
+ triangles.each do |vertices|
103
+ final_vertices_list << OpenStudio.reorderULC(OpenStudio::reverse(t*vertices))
104
+ end
105
+
106
+ triangulated = true
107
+
108
+ end
109
+
110
+ else
111
+ # reordered_vertices are good as is
112
+ final_vertices_list << reordered_vertices
113
+ end
114
+
115
+ result = []
116
+ final_vertices_list.each_with_index do |reordered_vertices, index|
117
+ os_subsurface = OpenStudio::Model::SubSurface.new(reordered_vertices, openstudio_model)
118
+
119
+ if !matching_os_subsurfaces.empty?
120
+ os_subsurface.setName(@hash[:identifier] + "..#{matching_os_subsurface_indices[index]}")
121
+ elsif triangulated
122
+ os_subsurface.setName(@hash[:identifier] + "..#{index}")
123
+ else
124
+ os_subsurface.setName(@hash[:identifier])
125
+ end
126
+
127
+ # assign the construction if it exists
128
+ if @hash[:properties][:energy][:construction]
129
+ construction_identifier = @hash[:properties][:energy][:construction]
130
+ construction = openstudio_model.getConstructionByName(construction_identifier)
131
+ unless construction.empty?
132
+ os_construction = construction.get
133
+ os_subsurface.setConstruction(os_construction)
134
+ end
135
+ end
136
+
137
+ # assign the boundary condition object if it's a Surface
138
+ if @hash[:boundary_condition][:type] == 'Surface'
139
+ if !matching_os_subsurfaces.empty?
140
+ # we already have the match because this was created from the matching_os_subsurfaces
141
+ # setAdjacentSubSurface will fail at this point because sub surface is not assigned to surface yet, store data for later
142
+ adj_srf_identifier = matching_os_subsurfaces[index].nameString
143
+ os_subsurface.additionalProperties.setFeature("AdjacentSubSurfaceName", adj_srf_identifier)
144
+ elsif triangulated
145
+ # other subsurfaces haven't been created yet, no-op
146
+ else
147
+ # get adjacent sub surface by identifier from openstudio model
148
+ # setAdjacentSubSurface will fail at this point because sub surface is not assigned to surface yet, store data for later
149
+ adj_srf_identifier = @hash[:boundary_condition][:boundary_condition_objects][0]
150
+ os_subsurface.additionalProperties.setFeature("AdjacentSubSurfaceName", adj_srf_identifier)
151
+ end
152
+ end
153
+
154
+ # assign the operable property
155
+ if @hash[:is_operable] == false
156
+ os_subsurface.setSubSurfaceType('FixedWindow')
157
+ else
158
+ os_subsurface.setSubSurfaceType('OperableWindow')
159
+ end
160
+
161
+ result << os_subsurface
162
+ end
163
+
164
+ return result
165
+ end
166
+ end # Aperture
167
+ end # FromHoneybee