Class: Honeybee::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/honeybee/model.rb,
lib/to_openstudio/model.rb,
lib/from_openstudio/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Model

Load ModelObject from symbolized hash



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/honeybee/model.rb', line 50

def initialize(hash)
  # initialize class variable @@extension only once
  @@extension ||= Extension.new
  @@schema ||= @@extension.schema
  @@standards ||= @@extension.standards
  $triangulate_sub_faces = false
  $simple_window_cons = false
  $orphan_groups = true

  @hash = hash
  @type = @hash[:type]
  raise 'Unknown model type' if @type.nil?
  raise "Incorrect model type '#{@type}'" unless @type == 'Model'

  if @hash[:version].nil?
    @hash[:version] = @@schema[:info][:version]
  end
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



37
38
39
# File 'lib/honeybee/model.rb', line 37

def errors
  @errors
end

#hashObject (readonly)

Returns the value of attribute hash.



37
38
39
# File 'lib/honeybee/model.rb', line 37

def hash
  @hash
end

#include_datetimesObject (readonly)

Returns the value of attribute include_datetimes.



66
67
68
# File 'lib/to_openstudio/model.rb', line 66

def include_datetimes
  @include_datetimes
end

#openstudio_modelObject (readonly)

Returns the value of attribute openstudio_model.



65
66
67
# File 'lib/to_openstudio/model.rb', line 65

def openstudio_model
  @openstudio_model
end

#schedule_csv_dirObject (readonly)

Returns the value of attribute schedule_csv_dir.



66
67
68
# File 'lib/to_openstudio/model.rb', line 66

def schedule_csv_dir
  @schedule_csv_dir
end

#schedule_csvsObject (readonly)

Returns the value of attribute schedule_csvs.



66
67
68
# File 'lib/to_openstudio/model.rb', line 66

def schedule_csvs
  @schedule_csvs
end

#warningsObject (readonly)

Returns the value of attribute warnings.



37
38
39
# File 'lib/honeybee/model.rb', line 37

def warnings
  @warnings
end

Class Method Details

.constructions_from_model(openstudio_model) ⇒ Object

Create HB Construction from OpenStudio Materials



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
# File 'lib/from_openstudio/model.rb', line 221

def self.constructions_from_model(openstudio_model)
  result = []

  # Create HB AirConstruction from OpenStudio Construction
  openstudio_model.getConstructionAirBoundarys.each do |construction|
    result << AirBoundaryConstructionAbridged.from_construction(construction)
  end

  # Create HB WindowConstruction from OpenStudio Construction
  openstudio_model.getConstructions.each do |construction|
    window_construction = false
    opaque_construction = false
    material = construction.layers[0]
    unless material.nil?
      if material.to_StandardGlazing.is_initialized or material.to_SimpleGlazing.is_initialized
        window_construction = true
      elsif material.to_StandardOpaqueMaterial.is_initialized or material.to_MasslessOpaqueMaterial.is_initialized or material.to_RoofVegetation.is_initialized
        opaque_construction = true
      end
      if window_construction == true
        constr_hash = WindowConstructionAbridged.from_construction(construction)
        $window_constructions[constr_hash[:identifier]] = constr_hash
        result << constr_hash
      end
      if opaque_construction == true
        constr_hash = OpaqueConstructionAbridged.from_construction(construction)
        $opaque_constructions[constr_hash[:identifier]] = constr_hash
        result << constr_hash
      end
    end
  end

  result
end

.constructionsets_from_model(openstudio_model) ⇒ Object

Create HB ConstructionSets from OpenStudio Construction Set



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/from_openstudio/model.rb', line 257

def self.constructionsets_from_model(openstudio_model)
  result = []

  openstudio_model.getDefaultConstructionSets.each do |construction_set|
    if construction_set.nameString != "Default Generic Construction Set"
      result << ConstructionSetAbridged.from_construction_set(construction_set)
    end
  end

  result
end

.energy_properties_from_model(openstudio_model) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/from_openstudio/model.rb', line 129

def self.energy_properties_from_model(openstudio_model)
  hash = {}
  hash[:type] = 'ModelEnergyProperties'
  hash[:constructions] = constructions_from_model(openstudio_model)
  hash[:materials] = materials_from_model(openstudio_model)
  hash[:construction_sets] = constructionsets_from_model(openstudio_model)
  hash[:schedule_type_limits] = schedtypelimits_from_model(openstudio_model)
  hash[:schedules] = schedules_from_model(openstudio_model)
  hash[:program_types] = programtype_from_model(openstudio_model)
  hash[:hvacs] = $hvacs

  hash
end

.materials_from_model(openstudio_model) ⇒ Object

Create HB Material from OpenStudio Materials



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
209
210
211
212
213
214
215
216
217
218
# File 'lib/from_openstudio/model.rb', line 166

def self.materials_from_model(openstudio_model)
  result = []

  # TODO: Loop through all materials and add puts statement for unsupported materials.
  
  # Create HB EnergyMaterial from OpenStudio Material
  openstudio_model.getStandardOpaqueMaterials.each do |material|
    result << EnergyMaterial.from_material(material)
  end

  # Create HB EnergyMaterialNoMass from OpenStudio MasslessOpaque Materials
  openstudio_model.getMasslessOpaqueMaterials.each do |material|
    result << EnergyMaterialNoMass.from_material(material)
  end

  # Create HB EnergyMaterialVegetation from OpenStudio RoofVegetation Materials
  openstudio_model.getRoofVegetations.each do |material|
    result << EnergyMaterialVegetation.from_material(material)
  end

  # Create HB EnergyMaterialNoMass from OpenStudio AirGap materials
  openstudio_model.getAirGaps.each do|material|
    result << EnergyMaterialNoMass.from_material(material)
  end

  # Create HB WindowMaterialSimpleGlazSys from OpenStudio Material
  openstudio_model.getSimpleGlazings.each do |material|
    result << EnergyWindowMaterialSimpleGlazSys.from_material(material)
  end
  # Create HB EnergyWindowMaterialGlazing from OpenStudio Material
  openstudio_model.getStandardGlazings.each do |material|
    result << EnergyWindowMaterialGlazing.from_material(material)
  end
  # Create HB EnergyWindowMaterialBlind from OpenStudio Material
  openstudio_model.getBlinds.each do |material|
    result << EnergyWindowMaterialBlind.from_material(material)
  end
  openstudio_model.getGass.each do |material|
    # Create HB WindowGasCustom from OpenStudio Material
    if material.gasType == 'Custom'
      result << EnergyWindowMaterialGasCustom.from_material(material)
    else
    # Create HB WindowGas from OpenStudio Material
      result << EnergyWindowMaterialGas.from_material(material)
    end
  end
  # Create HB EnergyWindowMaterialGasMixture from OpenStudio Material
  openstudio_model.getGasMixtures.each do |material|
    result << EnergyWindowMaterialGasMixture.from_material(material)
  end

  result
end

.orphaned_shades_from_model(openstudio_model) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/from_openstudio/model.rb', line 151

def self.orphaned_shades_from_model(openstudio_model)
  result = []
  openstudio_model.getShadingSurfaceGroups.each do |shading_surface_group|
    shading_surface_type = shading_surface_group.shadingSurfaceType
    if shading_surface_type == 'Site' || shading_surface_type == 'Building'
      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
  end
  result
end

.programtype_from_model(openstudio_model) ⇒ Object

Create HB Program Type from OpenStudio Space Type



307
308
309
310
311
312
313
# File 'lib/from_openstudio/model.rb', line 307

def self.programtype_from_model(openstudio_model)
  result = []
  openstudio_model.getSpaceTypes.each do |space_type|
    result << ProgramTypeAbridged.from_programtype(space_type)
  end
  result
end

.properties_from_model(openstudio_model) ⇒ Object



122
123
124
125
126
127
# File 'lib/from_openstudio/model.rb', line 122

def self.properties_from_model(openstudio_model)
  hash = {}
  hash[:type] = 'ModelProperties'
  hash[:energy] = energy_properties_from_model(openstudio_model)
  hash
end

.read_from_disk(file) ⇒ Object

Read Ladybug Energy Model JSON from disk



40
41
42
43
44
45
46
47
# File 'lib/honeybee/model.rb', line 40

def self.read_from_disk(file)
  hash = nil
  File.open(File.join(file), 'r') do |f|
    hash = JSON.parse(File.read(f, :external_encoding => 'UTF-8',
      :internal_encoding => 'UTF-8'), symbolize_names: true, encoding: 'UTF-8')
  end
  Model.new(hash)
end

.rooms_from_model(openstudio_model) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/from_openstudio/model.rb', line 143

def self.rooms_from_model(openstudio_model)
  result = []
  openstudio_model.getSpaces.each do |space|
    result << Room.from_space(space)
  end
  result
end

.schedtypelimits_from_model(openstudio_model) ⇒ Object

Create HB Schedule Type Limits from OpenStudio Schedule Type Limits



279
280
281
282
283
284
285
286
# File 'lib/from_openstudio/model.rb', line 279

def self.schedtypelimits_from_model(openstudio_model)
  result = []
  openstudio_model.getScheduleTypeLimitss.each do |sch_typ_lim|
    result << ScheduleTypeLimit.from_schedule_type_limit(sch_typ_lim)
  end

  result
end

.schedules_from_model(openstudio_model) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/from_openstudio/model.rb', line 288

def self.schedules_from_model(openstudio_model)
  result = []
  openstudio_model.getScheduleRulesets.each do |sch_ruleset|
    sched_hash = ScheduleRulesetAbridged.from_schedule_ruleset(sch_ruleset)
    $schedules[sched_hash[:identifier]] = sched_hash
    result << sched_hash
  end
  # check if it is a leap year 
  is_leap_year = openstudio_model.getYearDescription.isLeapYear
  openstudio_model.getScheduleFixedIntervals.each do |sch_fix_int|
    sched_fixed_hash = ScheduleFixedIntervalAbridged.from_schedule_fixedinterval(sch_fix_int, is_leap_year)
    $schedules[sched_fixed_hash[:identifier]] = sched_fixed_hash
    result << sched_fixed_hash
  end

  result
end

.shade_constructions_from_model(shade_constructions) ⇒ Object



269
270
271
272
273
274
275
276
# File 'lib/from_openstudio/model.rb', line 269

def self.shade_constructions_from_model(shade_constructions)
  result = []
  shade_constructions.each do |key, value|
    result << ShadeConstruction.from_construction(value)
  end

  result
end

.translate_from_gbxml_file(file) ⇒ Object

Create Honeybee Model JSON from gbXML file



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/from_openstudio/model.rb', line 91

def self.translate_from_gbxml_file(file)
  translator = OpenStudio::GbXML::GbXMLReverseTranslator.new
  openstudio_model = translator.loadModel(file)
  raise "Cannot load gbXML file at '#{}'" if openstudio_model.empty?
  # remove any shade groups that were translated as spaces
  os_model = openstudio_model.get
  spaces = os_model.getSpaces()
  spaces.each do |space|
    if space.surfaces.length() == 0
      space.remove()
    end
  end
  self.translate_from_openstudio(os_model)
end

.translate_from_idf_file(file) ⇒ Object

Create Honeybee Model JSON from IDF file



107
108
109
110
111
112
# File 'lib/from_openstudio/model.rb', line 107

def self.translate_from_idf_file(file)
  translator = OpenStudio::EnergyPlus::ReverseTranslator.new
  openstudio_model = translator.loadModel(file)
  raise "Cannot load IDF file at '#{}'" if openstudio_model.empty?
  self.translate_from_openstudio(openstudio_model.get)
end

.translate_from_openstudio(openstudio_model) ⇒ Object

Create Honeybee Model JSON from OpenStudio Model



40
41
42
43
44
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
# File 'lib/from_openstudio/model.rb', line 40

def self.translate_from_openstudio(openstudio_model)
  hash = {}
  hash[:type] = 'Model'
  hash[:identifier] = 'Model'
  hash[:display_name] = 'Model'
  hash[:units] = 'Meters'
  hash[:tolerance] = 0.01
  hash[:angle_tolerance] = 1.0

  # Hashes for various model properties
  $schedules = {}
  $opaque_constructions = {}
  $window_constructions = {}
  $shade_constructions = {}
  $hvacs = []

  hash[:properties] = properties_from_model(openstudio_model)

  rooms = rooms_from_model(openstudio_model)
  hash[:rooms] = rooms if !rooms.empty?

  # Add schedule created at the room level to the array of schedules in the model
  unless $heating_setpoint_schedule.nil?
    hash[:properties][:energy][:schedules] << $heating_setpoint_schedule
  end
  # Add schedule created at the room level to the array of schedules in the model
  unless $cooling_setpoint_schedule.nil?
    hash[:properties][:energy][:schedules] << $cooling_setpoint_schedule
  end

  orphaned_shades = orphaned_shades_from_model(openstudio_model)
  hash[:orphaned_shades] = orphaned_shades if !orphaned_shades.empty?

  unless $shade_constructions.empty?
    shade_constructions_from_model($shade_constructions).each do |shade_const|
      hash[:properties][:energy][:constructions] << shade_const
    end
  end

  Model.new(hash)
end

.translate_from_osm_file(file) ⇒ Object

Create Honeybee Model JSON from OSM file



83
84
85
86
87
88
# File 'lib/from_openstudio/model.rb', line 83

def self.translate_from_osm_file(file)
  vt = OpenStudio::OSVersion::VersionTranslator.new
  openstudio_model = vt.loadModel(file)
  raise "Cannot load OSM file at '#{}'" if openstudio_model.empty?
  self.translate_from_openstudio(openstudio_model.get)
end

.translate_from_sdd_file(file) ⇒ Object

Create Honeybee Model JSON from SDD file



115
116
117
118
119
120
# File 'lib/from_openstudio/model.rb', line 115

def self.translate_from_sdd_file(file)
  translator = OpenStudio::SDD::SddReverseTranslator.new
  openstudio_model = translator.loadModel(file)
  raise "Cannot load SDD file at '#{}'" if openstudio_model.empty?
  self.translate_from_openstudio(openstudio_model.get)
end

Instance Method Details

#defaultsObject



69
70
71
# File 'lib/honeybee/model.rb', line 69

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

#set_schedule_csv_dir(schedule_csv_dir, include_datetimes = false) ⇒ Object

if a schedule csv dir is specified then ScheduleFixedIntervalAbridged objects will be translated to ScheduleFile objects instead of ScheduleFixedInterval the optional schedule_csv_include_datetimes argument controls whether schedule csv files include a first column of date times for verification



72
73
74
75
# File 'lib/to_openstudio/model.rb', line 72

def set_schedule_csv_dir(schedule_csv_dir, include_datetimes = false)
  @schedule_csv_dir = schedule_csv_dir
  @include_datetimes = include_datetimes
end

#to_openstudio_model(openstudio_model = nil, log_report = true) ⇒ Object

convert to openstudio model, clears errors and warnings



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/to_openstudio/model.rb', line 78

def to_openstudio_model(openstudio_model=nil, log_report=true)
  @errors = []
  @warnings = []

  if log_report
    puts 'Starting Model translation from Honeybee to OpenStudio'
  end

  @openstudio_model = if openstudio_model
                        openstudio_model
                      else
                        OpenStudio::Model::Model.new
                      end

  # create all openstudio objects in the model
  create_openstudio_objects(log_report)

  @openstudio_model
end