Class: Honeybee::Face

Inherits:
ModelObject show all
Defined in:
lib/honeybee/geometry/face.rb,
lib/to_openstudio/geometry/face.rb,
lib/from_openstudio/geometry/face.rb

Instance Attribute Summary

Attributes inherited from ModelObject

#errors, #openstudio_object, #warnings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelObject

#allowable_types, clean_identifier, clean_name, #initialize, #method_missing, read_from_disk, truncate

Constructor Details

This class inherits a constructor from Honeybee::ModelObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Honeybee::ModelObject

Class Method Details

.apertures_from_surface(surface, site_transformation) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/from_openstudio/geometry/face.rb', line 154

def self.apertures_from_surface(surface, site_transformation)
  result = []
  surface.subSurfaces.each do |sub_surface|
    sub_surface_type = sub_surface.subSurfaceType
    if !/Door/i.match(sub_surface_type)
      result << Aperture.from_sub_surface(sub_surface, site_transformation)
    end
  end
  result
end

.boundary_condition_from_surface(surface) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/from_openstudio/geometry/face.rb', line 116

def self.boundary_condition_from_surface(surface)
  result = {}
  surface_bc = surface.outsideBoundaryCondition
  adjacent_surface = surface.adjacentSurface
  if !adjacent_surface.empty?
    adjacent_space = clean_identifier(adjacent_surface.get.space.get.nameString)
    adjacent_surface = clean_identifier(adjacent_surface.get.nameString)
    result = {type: 'Surface', boundary_condition_objects: [adjacent_surface, adjacent_space]}
  elsif surface.isGroundSurface
    result = {type: 'Ground'}
  elsif surface_bc == 'Adiabatic'
    result = {type: 'Adiabatic'}
  elsif surface_bc == 'OtherSideCoefficients'
    result = {type: 'OtherSideTemperature'}
    unless surface.surfacePropertyOtherSideCoefficients.empty?
      srf_prop = surface.surfacePropertyOtherSideCoefficients.get
      if !srf_prop.isConstantTemperatureDefaulted
        result[:temperature] = srf_prop.constantTemperature
      end
      unless srf_prop.combinedConvectiveRadiativeFilmCoefficient.empty?
        result[:heat_transfer_coefficient] = srf_prop.combinedConvectiveRadiativeFilmCoefficient.get
      end
    end
  else
    sun_exposure = (surface.sunExposure == 'SunExposed')
    wind_exposure = (surface.windExposure == 'WindExposed')
    view_factor = surface.viewFactortoGround
    if view_factor.empty?
      view_factor = {type: 'Autocalculate'}
    else
      view_factor = view_factor.get
    end
    result = {type: 'Outdoors', sun_exposure: sun_exposure,
              wind_exposure: wind_exposure, view_factor: view_factor}
  end
  result
end

.doors_from_surface(surface, site_transformation) ⇒ Object



165
166
167
168
169
170
171
172
173
174
# File 'lib/from_openstudio/geometry/face.rb', line 165

def self.doors_from_surface(surface, site_transformation)
  result = []
  surface.subSurfaces.each do |sub_surface|
    sub_surface_type = sub_surface.subSurfaceType
    if /Door/i.match(sub_surface_type)
      result << Door.from_sub_surface(sub_surface, site_transformation)
    end
  end
  result
end

.energy_properties_from_surface(surface) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/from_openstudio/geometry/face.rb', line 72

def self.energy_properties_from_surface(surface)
  hash = {}
  hash[:type] = 'FaceEnergyPropertiesAbridged'

  unless surface.isConstructionDefaulted
    construction = surface.construction
    if !construction.empty?
      constr_id = clean_name(construction.get.nameString)
      unless $opaque_constructions[constr_id].nil?
        hash[:construction] = constr_id
      end
    end
  end

  hash
end

.face_type_from_surface(surface) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/from_openstudio/geometry/face.rb', line 100

def self.face_type_from_surface(surface)
  # "Wall", "Floor", "RoofCeiling", "AirBoundary"
  result = nil
  surface_type = surface.surfaceType
  if surface.isAirWall
    result = 'AirBoundary'
  elsif /Wall/i.match(surface_type)
    result = 'Wall'
  elsif /Floor/i.match(surface_type)
    result = 'Floor'
  elsif /RoofCeiling/i.match(surface_type)
    result = 'RoofCeiling'
  end
  result
end

.from_surface(surface, site_transformation) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/from_openstudio/geometry/face.rb', line 37

def self.from_surface(surface, site_transformation)
  hash = {}
  hash[:type] = 'Face'
  hash[:identifier] = clean_identifier(surface.nameString)
  unless surface.displayName.empty?
    hash[:display_name] = (surface.displayName.get).force_encoding("UTF-8")
  end
  hash[:user_data] = {handle: surface.handle.to_s}
  hash[:properties] = properties_from_surface(surface)
  hash[:geometry] = geometry_from_surface(surface, site_transformation)
  hash[:face_type] = face_type_from_surface(surface)
  hash[:boundary_condition] = boundary_condition_from_surface(surface)

  apertures = apertures_from_surface(surface, site_transformation)
  hash[:apertures] = apertures if !apertures.empty?

  doors = doors_from_surface(surface, site_transformation)
  hash[:doors] = doors if !doors.empty?

  indoor_shades = indoor_shades_from_surface(surface)
  hash[:indoor_shades] = indoor_shades if !indoor_shades.empty?

  outdoor_shades = outdoor_shades_from_surface(surface)
  hash[:outdoor_shades] = outdoor_shades if !outdoor_shades.empty?

  hash
end

.geometry_from_surface(surface, site_transformation) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/from_openstudio/geometry/face.rb', line 89

def self.geometry_from_surface(surface, site_transformation)
  result = {}
  result[:type] = 'Face3D'
  result[:boundary] = []
  vertices = site_transformation * surface.vertices
  vertices.each do |v|
    result[:boundary] << [v.x, v.y, v.z]
  end
  result
end

.indoor_shades_from_surface(surface) ⇒ Object



176
177
178
# File 'lib/from_openstudio/geometry/face.rb', line 176

def self.indoor_shades_from_surface(surface)
  []
end

.outdoor_shades_from_surface(surface) ⇒ Object



180
181
182
183
184
185
186
187
188
189
# File 'lib/from_openstudio/geometry/face.rb', line 180

def self.outdoor_shades_from_surface(surface)
  result = []
  surface.shadingSurfaceGroups.each do |shading_surface_group|
    site_transformation = shading_surface_group.siteTransformation
    shading_surface_group.shadingSurfaces.each do |shading_surface|
      result << Shade.from_shading_surface(shading_surface, site_transformation)
    end
  end
  result
end

.properties_from_surface(surface) ⇒ Object



65
66
67
68
69
70
# File 'lib/from_openstudio/geometry/face.rb', line 65

def self.properties_from_surface(surface)
  hash = {}
  hash[:type] = 'FacePropertiesAbridged'
  hash[:energy] = energy_properties_from_surface(surface)
  hash
end

Instance Method Details

#crack_defaultsObject



43
44
45
# File 'lib/honeybee/geometry/face.rb', line 43

def crack_defaults
  @@schema[:components][:schemas][:AFNCrack][:properties]
end

#defaultsObject



39
40
41
# File 'lib/honeybee/geometry/face.rb', line 39

def defaults
  @@schema[:components][:schemas][:FaceEnergyPropertiesAbridged][:properties]
end

#find_existing_openstudio_object(openstudio_model) ⇒ Object



39
40
41
42
43
# File 'lib/to_openstudio/geometry/face.rb', line 39

def find_existing_openstudio_object(openstudio_model)
  model_surf = openstudio_model.getSurfaceByName(@hash[:identifier])
  return model_surf.get unless model_surf.empty?
  nil
end

#to_openstudio(openstudio_model) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/to_openstudio/geometry/face.rb', line 45

def to_openstudio(openstudio_model)
  # get the vertices from the face
  if @hash[:geometry][:vertices].nil?
    hb_verts = @hash[:geometry][:boundary]
  else
    hb_verts = @hash[:geometry][:vertices]
  end

  # reorder the vertices to ensure they start from the upper-left corner
  os_vertices = OpenStudio::Point3dVector.new
  hb_verts.each do |vertex|
    os_vertices << OpenStudio::Point3d.new(vertex[0], vertex[1], vertex[2])
  end

  # create the openstudio surface
  os_surface = OpenStudio::Model::Surface.new(os_vertices, openstudio_model)
  os_surface.setName(@hash[:identifier])
  unless @hash[:display_name].nil?
    os_surface.setDisplayName(@hash[:display_name])
  end

  # assign the type
  os_surface.setSurfaceType(@hash[:face_type])

  if @hash[:properties].key?(:energy)
    # assign the construction if it is present
    if @hash[:properties][:energy][:construction]
      construction_identifier = @hash[:properties][:energy][:construction]
      construction = openstudio_model.getConstructionByName(construction_identifier)
      unless construction.empty?
        os_construction = construction.get
        os_surface.setConstruction(os_construction)
      end
    end

    # assign the AFN crack if it's specified and we are not using simple infiltration
    if !$use_simple_vent && @hash[:properties][:energy][:vent_crack]
      unless $interior_afn_srf_hash[@hash[:identifier]]  # interior crack that's been accounted for
        vent_crack = @hash[:properties][:energy][:vent_crack]
        # create the crack object for using default values
        flow_exponent = crack_defaults[:flow_exponent][:default].to_f
        os_crack = OpenStudio::Model::AirflowNetworkCrack.new(
          openstudio_model, vent_crack[:flow_coefficient], flow_exponent,
          $afn_reference_crack)

        # assign the flow exponent if it's specified
        if vent_crack[:flow_exponent]
          os_crack.setAirMassFlowExponent(vent_crack[:flow_exponent])
        end

        # if it's a Surface boundary condition ensure the neighbor is not written as a duplicate
        if @hash[:boundary_condition][:type] == 'Surface'
          $interior_afn_srf_hash[@hash[:boundary_condition][:boundary_condition_objects][0]] = true
        end

        # create the AirflowNetworkSurface
        os_afn_srf = os_surface.getAirflowNetworkSurface(os_crack)

      end
    end
  end

  # assign the boundary condition
  boundary_condition = @hash[:boundary_condition][:type]
  case boundary_condition
  when 'Outdoors'
    if @hash[:boundary_condition][:sun_exposure] == false
      os_surface.setSunExposure('NoSun')
    else
      os_surface.setSunExposure('SunExposed')
    end
    if @hash[:boundary_condition][:wind_exposure] == false
      os_surface.setWindExposure('NoWind')
    else
      os_surface.setWindExposure('WindExposed')
    end
    if @hash[:boundary_condition][:view_factor].is_a? Numeric
      os_surface.setViewFactortoGround(@hash[:boundary_condition][:view_factor])
    else
      os_surface.autocalculateViewFactortoGround
    end
  when 'Surface'
    # get adjacent surface by identifier from openstudio model
    adj_srf_identifier = @hash[:boundary_condition][:boundary_condition_objects][0]
    surface_object = openstudio_model.getSurfaceByName(adj_srf_identifier)
    unless surface_object.empty?
      surface = surface_object.get
      os_surface.setAdjacentSurface(surface)
    end
  when 'OtherSideTemperature'
    srf_prop = OpenStudio::Model::SurfacePropertyOtherSideCoefficients.new(openstudio_model)
    srf_prop.setName(@hash[:identifier] + '_OtherTemp')
    if @hash[:boundary_condition][:heat_transfer_coefficient].is_a? Numeric
      srf_prop.setCombinedConvectiveRadiativeFilmCoefficient(
        @hash[:boundary_condition][:heat_transfer_coefficient])
    else
      srf_prop.setCombinedConvectiveRadiativeFilmCoefficient(0)
    end
    if @hash[:boundary_condition][:temperature].is_a? Numeric
      srf_prop.setConstantTemperature(@hash[:boundary_condition][:temperature])
      srf_prop.setConstantTemperatureCoefficient(1)
      srf_prop.setExternalDryBulbTemperatureCoefficient(0)
    else
      srf_prop.setConstantTemperatureCoefficient(0)
      srf_prop.setExternalDryBulbTemperatureCoefficient(1)
    end
    os_surface.setSurfacePropertyOtherSideCoefficients(srf_prop)
  end

  unless boundary_condition == 'Surface' || boundary_condition == 'OtherSideTemperature'
    os_surface.setOutsideBoundaryCondition(boundary_condition)
  end

  # assign apertures if they exist
  if @hash[:apertures]
    @hash[:apertures].each do |aperture|
      ladybug_aperture = Aperture.new(aperture)
      os_subsurface_apertures = ladybug_aperture.to_openstudio(openstudio_model)
      os_subsurface_apertures.each do |os_subsurface_aperture|
        if @hash[:face_type] == 'RoofCeiling' or @hash[:face_type]  == 'Floor'
          if @hash[:boundary_condition][:type] == 'Outdoors' && aperture[:is_operable] == false
            os_subsurface_aperture.setSubSurfaceType('Skylight')
          end
        end
        os_subsurface_aperture.setSurface(os_surface)
      end
    end
  end

  # assign doors if they exist
  if @hash[:doors]
    @hash[:doors].each do |door|
      honeybee_door = Door.new(door)
      os_subsurface_doors = honeybee_door.to_openstudio(openstudio_model)
      os_subsurface_doors.each do |os_subsurface_door|
        os_subsurface_door.setSurface(os_surface)
        if door[:is_glass] == true
          os_subsurface_door.setSubSurfaceType('GlassDoor')
        elsif (@hash[:face_type] == 'RoofCeiling' or @hash[:face_type] == 'Floor') && @hash[:boundary_condition][:type] == 'Outdoors'
          os_subsurface_door.setSubSurfaceType('OverheadDoor')
        elsif door[:is_glass] == false or door[:is_glass].nil?
          os_subsurface_door.setSubSurfaceType('Door')
        end
      end
    end
  end

  os_surface.subSurfaces.each do |os_subsurface|
    if os_subsurface.hasAdditionalProperties
      adj_sub_srf_identifier = os_subsurface.additionalProperties.getFeatureAsString("AdjacentSubSurfaceName")
      unless adj_sub_srf_identifier.empty?
        adj_sub_srf = openstudio_model.getSubSurfaceByName(adj_sub_srf_identifier.get)
        unless adj_sub_srf.empty?
          os_subsurface.setAdjacentSubSurface(adj_sub_srf.get)
        end
      end

      # clean up, we don't need this object any more
      os_subsurface.removeAdditionalProperties
    end
  end

  os_surface
end

#to_openstudio_shade(openstudio_model, shading_surface_group) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/to_openstudio/geometry/face.rb', line 210

def to_openstudio_shade(openstudio_model, shading_surface_group)
  # get the vertices from the face
  if @hash[:geometry][:vertices].nil?
    hb_verts = @hash[:geometry][:boundary]
  else
    hb_verts = @hash[:geometry][:vertices]
  end

  # create the openstudio shading surface
  os_vertices = OpenStudio::Point3dVector.new
  hb_verts.each do |vertex|
    os_vertices << OpenStudio::Point3d.new(vertex[0], vertex[1], vertex[2])
  end

  os_shading_surface = OpenStudio::Model::ShadingSurface.new(os_vertices, openstudio_model)
  os_shading_surface.setName(@hash[:identifier])
  unless @hash[:display_name].nil?
    os_shading_surface.setDisplayName(@hash[:display_name])
  end

  # get the approriate construction id
  construction_id = nil
  if @hash[:properties].key?(:energy) && @hash[:properties][:energy][:construction]
    construction_id = @hash[:properties][:energy][:construction]
  elsif @hash[:face_type] == 'Wall'
    construction_id = 'Generic Exterior Wall'
  elsif @hash[:face_type] == 'RoofCeiling'
    construction_id = 'Generic Roof'
  elsif @hash[:face_type] == 'Floor'
    construction_id = 'Generic Exposed Floor'
  end
  
  # assign the construction
  unless construction_id.nil?
    construction = openstudio_model.getConstructionByName(construction_id)
    unless construction.empty?
      os_construction = construction.get
      os_shading_surface.setConstruction(os_construction)
    end
  end

  # add the shade to the group
  os_shading_surface.setShadingSurfaceGroup(shading_surface_group)

  # convert the apertures to shade objects
  if @hash[:apertures]
    @hash[:apertures].each do |aperture|
      hb_aperture = Aperture.new(aperture)
      os_subsurface_aperture = hb_aperture.to_openstudio_shade(openstudio_model, shading_surface_group)
    end
  end

  # convert the apertures to shade objects
  if @hash[:doors]
    @hash[:doors].each do |door|
      hb_door = Door.new(door)
      os_subsurface_door = hb_door.to_openstudio_shade(openstudio_model, shading_surface_group)
    end
  end

  os_shading_surface
end