/
Prototype.Model.rb
2943 lines (2514 loc) · 132 KB
/
Prototype.Model.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
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
209
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Standard.class_eval do
# @!group Model
# creates an openstudio standards version of PNNL/DOE prototype buildings
#
# @param climate_zone [String] ASHRAE climate zone, e.g. 'ASHRAE 169-2013-4A'
# @param epw_file []
# @param sizing_run_dir [String]
# @param debug
# @param measure_model
# @return
def model_create_prototype_model(climate_zone, epw_file, sizing_run_dir = Dir.pwd, debug = false, measure_model = nil)
building_type = @instvarbuilding_type
raise 'no building_type!' if @instvarbuilding_type.nil?
model = nil
# There are no reference models for HighriseApartment and data centers at vintages Pre-1980 and 1980-2004,
# nor for NECB2011. This is a quick check.
case @instvarbuilding_type
when 'HighriseApartment', 'SmallDataCenterLowITE', 'SmallDataCenterHighITE', 'LargeDataCenterLowITE', 'LargeDataCenterHighITE', 'Laboratory', 'TallBuilding', 'SuperTallBuilding'
if template == 'DOE Ref Pre-1980' || template == 'DOE Ref 1980-2004'
OpenStudio.logFree(OpenStudio::Error, 'Not available', "DOE Reference models for #{@instvarbuilding_type} at are not available, the measure is disabled for this specific type.")
return false
end
end
# optionally determine the climate zone from the epw and stat files.
if climate_zone == 'NECB HDD Method'
weather_file_path = OpenstudioStandards::Weather.get_standards_weather_file_path(epw_file)
stat_file_path = weather_file_path.gsub('.epw', '.stat')
stat_file = OpenstudioStandards::Weather::StatFile.new(stat_file_path)
climate_zone = OpenstudioStandards::Weather.get_climate_zone_from_degree_days(stat_file.hdd18, stat_file.cdd10)
else
# this is required to be blank otherwise it may cause side effects.
epw_file = ''
end
model = load_geometry_osm(@geometry_file)
OpenstudioStandards::Weather.model_set_building_location(model, climate_zone: climate_zone)
model_custom_geometry_tweaks(model, building_type, climate_zone, @prototype_input)
model.getThermostatSetpointDualSetpoints(&:remove)
model.getBuilding.setName(self.class.to_s)
# save new basefile to new geometry folder as class name.
model.getBuilding.setName("-#{@instvarbuilding_type}-#{climate_zone} created: #{Time.new}")
model_add_loads(model)
model_apply_infiltration_standard(model)
model_modify_infiltration_coefficients(model, @instvarbuilding_type, climate_zone)
model_add_door_infiltration(model, climate_zone)
model_modify_surface_convection_algorithm(model)
model_create_thermal_zones(model, @space_multiplier_map)
model_add_hvac(model, @instvarbuilding_type, climate_zone, @prototype_input)
model.getAirLoopHVACs.each do |air_loop|
next unless air_loop_hvac_multizone_vav_system?(air_loop)
model_system_outdoor_air_sizing_vrp_method(air_loop)
air_loop_hvac_apply_vav_damper_action(air_loop)
end
model_add_constructions(model, @instvarbuilding_type, climate_zone)
model_fenestration_orientation(model, climate_zone)
model_custom_hvac_tweaks(model, building_type, climate_zone, @prototype_input)
model_add_transfer_air(model)
model_add_internal_mass(model, @instvarbuilding_type)
model_add_swh(model, @instvarbuilding_type, @prototype_input)
model_add_exterior_lights(model, @instvarbuilding_type, climate_zone, @prototype_input)
model_add_occupancy_sensors(model, @instvarbuilding_type, climate_zone)
model_add_daylight_savings(model)
model_apply_sizing_parameters(model, @instvarbuilding_type)
model.yearDescription.get.setDayofWeekforStartDay('Sunday')
model.getBuilding.setStandardsBuildingType(building_type)
model_add_lights_shutoff(model)
# Perform a sizing model_run(model)
return false if model_run_sizing_run(model, "#{sizing_run_dir}/SR1") == false
# If there are any multizone systems, reset damper positions
# to achieve a 60% ventilation effectiveness minimum for the system
# following the ventilation rate procedure from 62.1
model_apply_multizone_vav_outdoor_air_sizing(model)
# Apply the prototype HVAC assumptions
# which include sizing the fan pressure rises based
# on the flow rate of the system.
model_apply_prototype_hvac_assumptions(model, building_type, climate_zone)
# custom economizer controls
# For 90.1-2010 Outpatient, AHU1 doesn't have economizer and AHU2 set minimum outdoor air flow rate as 0
model_modify_oa_controller(model)
# For operating room 1&2 in 2010, 2013, 2016, and 2019, VAV minimum air flow is set by schedule
model_reset_or_room_vav_minimum_damper(@prototype_input, model)
# Apply the HVAC efficiency standard
model_apply_hvac_efficiency_standard(model, climate_zone)
# Apply prototype changes that supersede the HVAC efficiency standard
model_apply_prototype_hvac_efficiency_adjustments(model)
model_custom_swh_tweaks(model, @instvarbuilding_type, climate_zone, @prototype_input)
# Fix EMS references.
# Temporary workaround for OS issue #2598
model_temp_fix_ems_references(model)
# Add daylighting controls per standard
# only four zones in large hotel have daylighting controls
# @todo YXC to merge to the main function
model_add_daylighting_controls(model)
model_custom_daylighting_tweaks(model, building_type, climate_zone, @prototype_input)
model_update_exhaust_fan_efficiency(model)
model_update_fan_efficiency(model)
# rename air loop and plant loop nodes for readability
rename_air_loop_nodes(model)
rename_plant_loop_nodes(model)
# remove unused objects
model_remove_unused_resource_objects(model)
# Add output variables for debugging
model_request_timeseries_outputs(model) if debug
# If measure model is passed, then replace measure model with new model created here.
return model if measure_model.nil?
model_replace_model(measure_model, model)
return measure_model
end
# Replaces the contents of 'model_to_replace' with the contents of 'new_model.'
# This method can be used when the memory location of model_to_replace needs
# to be preserved, for example, when a measure is passed.
#
# @param model_to_replace [OpenStudio::Model::Model] OpenStudio model object
# @param new_model [OpenStudio::Model::Model] OpenStudio model object
# @return [OpenStudio::Model::Model] OpenStudio model object
def model_replace_model(model_to_replace, new_model, runner = nil)
# remove existing objects from model
handles = OpenStudio::UUIDVector.new
model_to_replace.objects.each do |obj|
handles << obj.handle
end
model_to_replace.removeObjects(handles)
# put contents of new_model into model_to_replace
model_to_replace.addObjects(new_model.toIdfFile.objects)
BTAP.runner_register('Info', "Model name is now #{model_to_replace.building.get.name}.", runner)
return model_to_replace
end
# Replaces all objects in the current model
# with the objects in the .osm. Typically used to
# load a model as a starting point.
#
# @param model [OpenStudio::Model::Model] OpenStudio model object
# @param rel_path_to_osm [String] the path to an .osm file, relative to this file
# @return [Boolean] returns true if successful, false if not
def model_replace_model_from_osm(model, rel_path_to_osm)
# Take the existing model and remove all the objects
# (this is cheesy), but need to keep the same memory block
handles = OpenStudio::UUIDVector.new
model.objects.each { |objects| handles << objects.handle }
model.removeObjects(handles)
model = nil
if File.dirname(__FILE__)[0] == ':'
# running from embedded location
# Load geometry from the saved geometry.osm
geom_model_string = load_resource_relative(rel_path_to_osm)
puts geom_model_string
# version translate from string
version_translator = OpenStudio::OSVersion::VersionTranslator.new
geom_model = version_translator.loadModelFromString(geom_model_string)
else
abs_path = File.join(File.dirname(__FILE__), rel_path_to_osm)
# version translate from string
version_translator = OpenStudio::OSVersion::VersionTranslator.new
geom_model = version_translator.loadModel(abs_path)
raise
end
if geom_model.empty?
OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "Version translation failed for #{rel_path_to_osm}")
return false
end
geom_model = geom_model.get
# Add the objects from the geometry model to the working model
model.addObjects(geom_model.toIdfFile.objects)
return true
end
# Read the space type to space map from the model
# instead of relying on an externally-defined mapping.
def get_space_type_maps_from_model(model)
# Do all spaces have Spacetypes?
# @todo is this necessary?
# all_spaces_have_space_types = true
# Do all spacetypes have StandardSpaceTypes
all_space_types_have_standard_space_types = true
space_type_map = {}
model.getSpaces.each do |space|
if space.spaceType.empty?
OpenStudio.logFree(OpenStudio::Warn, 'openstudio.model.Model', "Space #{space.name} does not have a Space Type assigned.")
else
if space.spaceType.get.standardsSpaceType.empty?
OpenStudio.logFree(OpenStudio::Warn, 'openstudio.model.Model', "SpaceType #{space.spaceType.get.name} does not have a standardsSpaceType assigned.")
all_space_types_have_standard_space_types = false
else
space_type_map[space.spaceType.get.standardsSpaceType.get.to_s] = [] if space_type_map[space.spaceType.get.standardsSpaceType.get.to_s].nil?
space_type_map[space.spaceType.get.standardsSpaceType.get.to_s] << space.name.get
end
end
end
if all_space_types_have_standard_space_types
return space_type_map
end
return nil
end
def model_add_full_space_type_libs(model)
space_type_properties_list = standards_lookup_table_many(table_name: 'space_types')
space_type_properties_list.each do |space_type_property|
stub_space_type = OpenStudio::Model::SpaceType.new(model)
stub_space_type.setStandardsBuildingType(space_type_property['building_type'])
stub_space_type.setStandardsSpaceType(space_type_property['space_type'])
stub_space_type.setName("-#{space_type_property['building_type']}-#{space_type_property['space_type']}")
space_type_apply_rendering_color(stub_space_type)
end
model_add_loads(model)
end
def model_assign_building_story(model, building_story_map = nil)
if building_story_map.nil? || building_story_map.empty?
model_assign_spaces_to_stories(model)
return true
end
building_story_map.each do |building_story_name, space_names|
stub_building_story = OpenStudio::Model::BuildingStory.new(model)
stub_building_story.setName(building_story_name)
space_names.each do |space_name|
space = model.getSpaceByName(space_name)
next if space.empty?
space = space.get
space.setBuildingStory(stub_building_story)
end
end
return true
end
# Adds the loads and associated schedules for each space type
# as defined in the OpenStudio_Standards_space_types.json file.
# This includes lights, plug loads, occupants, ventilation rate requirements,
# infiltration, gas equipment (for kitchens, etc.) and typical schedules for each.
# Some loads are governed by the standard, others are typical values
# pulled from sources such as the DOE Reference and DOE Prototype Buildings.
#
# @return [Boolean] returns true if successful, false if not
def model_add_loads(model)
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Started applying space types (loads)')
# Loop through all the space types currently in the model,
# which are placeholders, and give them appropriate loads and schedules
model.getSpaceTypes.sort.each do |space_type|
# Rendering color
space_type_apply_rendering_color(space_type)
# Loads
space_type_apply_internal_loads(space_type, true, true, true, true, true, true)
# Schedules
space_type_apply_internal_load_schedules(space_type, true, true, true, true, true, true, true)
end
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Finished applying space types (loads)')
return true
end
# Checks to see if the an adiabatic floor construction has been constructed in an OpenStudio model.
# If so, it returns it. If not, it constructs an adiabatic floor construction, adds it to the model,
# and then returns it.
# @return [OpenStudio::Model::Construction]
def model_get_adiabatic_floor_construction(model)
adiabatic_construction_name = 'Floor Adiabatic construction'
# Check if adiabatic floor construction already exists in the model
adiabatic_construct_exists = model.getConstructionByName(adiabatic_construction_name).is_initialized
# Check to see if adiabatic construction has been constructed. If so, return it. Else, construct it.
return model.getConstructionByName(adiabatic_construction_name).get if adiabatic_construct_exists
# Assign construction to adiabatic construction
cp02_carpet_pad = OpenStudio::Model::MasslessOpaqueMaterial.new(model)
cp02_carpet_pad.setName('CP02 CARPET PAD')
cp02_carpet_pad.setRoughness('VeryRough')
cp02_carpet_pad.setThermalResistance(0.21648)
cp02_carpet_pad.setThermalAbsorptance(0.9)
cp02_carpet_pad.setSolarAbsorptance(0.7)
cp02_carpet_pad.setVisibleAbsorptance(0.8)
normalweight_concrete_floor = OpenStudio::Model::StandardOpaqueMaterial.new(model)
normalweight_concrete_floor.setName('100mm Normalweight concrete floor')
normalweight_concrete_floor.setRoughness('MediumSmooth')
normalweight_concrete_floor.setThickness(0.1016)
normalweight_concrete_floor.setThermalConductivity(2.31)
normalweight_concrete_floor.setDensity(2322)
normalweight_concrete_floor.setSpecificHeat(832)
nonres_floor_insulation = OpenStudio::Model::MasslessOpaqueMaterial.new(model)
nonres_floor_insulation.setName('Nonres_Floor_Insulation')
nonres_floor_insulation.setRoughness('MediumSmooth')
nonres_floor_insulation.setThermalResistance(2.88291975297193)
nonres_floor_insulation.setThermalAbsorptance(0.9)
nonres_floor_insulation.setSolarAbsorptance(0.7)
nonres_floor_insulation.setVisibleAbsorptance(0.7)
floor_adiabatic_construction = OpenStudio::Model::Construction.new(model)
floor_adiabatic_construction.setName(adiabatic_construction_name)
floor_layers = OpenStudio::Model::MaterialVector.new
floor_layers << cp02_carpet_pad
floor_layers << normalweight_concrete_floor
floor_layers << nonres_floor_insulation
floor_adiabatic_construction.setLayers(floor_layers)
return floor_adiabatic_construction
end
# Checks to see if the an adiabatic wall construction has been constructed in an OpenStudio model.
# If so, it returns it. If not, it constructs an adiabatic wall construction, adds it to the model,
# and then returns it.
# @return [OpenStudio::Model::Construction]
def model_get_adiabatic_wall_construction(model)
adiabatic_construction_name = 'Wall Adiabatic construction'
# Check if adiabatic wall construction already exists in the model
adiabatic_construct_exists = model.getConstructionByName(adiabatic_construction_name).is_initialized
# Check to see if adiabatic construction has been constructed. If so, return it. Else, construct it.
return model.getConstructionByName(adiabatic_construction_name).get if adiabatic_construct_exists
g01_13mm_gypsum_board = OpenStudio::Model::StandardOpaqueMaterial.new(model)
g01_13mm_gypsum_board.setName('G01 13mm gypsum board')
g01_13mm_gypsum_board.setRoughness('Smooth')
g01_13mm_gypsum_board.setThickness(0.0127)
g01_13mm_gypsum_board.setThermalConductivity(0.1600)
g01_13mm_gypsum_board.setDensity(800)
g01_13mm_gypsum_board.setSpecificHeat(1090)
g01_13mm_gypsum_board.setThermalAbsorptance(0.9)
g01_13mm_gypsum_board.setSolarAbsorptance(0.7)
g01_13mm_gypsum_board.setVisibleAbsorptance(0.5)
wall_adiabatic_construction = OpenStudio::Model::Construction.new(model)
wall_adiabatic_construction.setName(adiabatic_construction_name)
wall_layers = OpenStudio::Model::MaterialVector.new
wall_layers << g01_13mm_gypsum_board
wall_layers << g01_13mm_gypsum_board
wall_adiabatic_construction.setLayers(wall_layers)
return wall_adiabatic_construction
end
# Adds code-minimum constructions based on the building type
# as defined in the OpenStudio_Standards_construction_sets.json file.
# Where there is a separate construction set specified for the
# individual space type, this construction set will be created and applied
# to this space type, overriding the whole-building construction set.
#
# @param model[OpenStudio::Model::Model] OpenStudio Model
# @param building_type [String] the building type
# @param climate_zone [String] ASHRAE climate zone, e.g. 'ASHRAE 169-2013-4A'
# @return [Boolean] returns true if successful, false if not
def model_add_constructions(model, building_type, climate_zone)
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Started applying constructions')
is_residential = 'No' # default is nonresidential for building level
# The constructions lookup table uses a slightly different list of building types.
@lookup_building_type = model_get_lookup_name(building_type)
# @todo this is a workaround. Need to synchronize the building type names
# across different parts of the code, including splitting of Office types
case building_type
when 'SmallOffice', 'MediumOffice', 'LargeOffice', 'SmallOfficeDetailed', 'MediumOfficeDetailed', 'LargeOfficeDetailed'
new_lookup_building_type = building_type
else
new_lookup_building_type = model_get_lookup_name(building_type)
end
# Construct adiabatic constructions
floor_adiabatic_construction = model_get_adiabatic_floor_construction(model)
wall_adiabatic_construction = model_get_adiabatic_wall_construction(model)
cp02_carpet_pad = OpenStudio::Model::MasslessOpaqueMaterial.new(model)
cp02_carpet_pad.setName('CP02 CARPET PAD')
cp02_carpet_pad.setRoughness('VeryRough')
cp02_carpet_pad.setThermalResistance(0.21648)
cp02_carpet_pad.setThermalAbsorptance(0.9)
cp02_carpet_pad.setSolarAbsorptance(0.7)
cp02_carpet_pad.setVisibleAbsorptance(0.8)
m10_200mm_concrete_block_basement_wall = OpenStudio::Model::StandardOpaqueMaterial.new(model)
m10_200mm_concrete_block_basement_wall.setName('M10 200mm concrete block basement wall')
m10_200mm_concrete_block_basement_wall.setRoughness('MediumRough')
m10_200mm_concrete_block_basement_wall.setThickness(0.2032)
m10_200mm_concrete_block_basement_wall.setThermalConductivity(1.326)
m10_200mm_concrete_block_basement_wall.setDensity(1842)
m10_200mm_concrete_block_basement_wall.setSpecificHeat(912)
basement_wall_construction = OpenStudio::Model::Construction.new(model)
basement_wall_construction.setName('Basement Wall construction')
basement_wall_layers = OpenStudio::Model::MaterialVector.new
basement_wall_layers << m10_200mm_concrete_block_basement_wall
basement_wall_construction.setLayers(basement_wall_layers)
basement_floor_construction = OpenStudio::Model::Construction.new(model)
basement_floor_construction.setName('Basement Floor construction')
basement_floor_layers = OpenStudio::Model::MaterialVector.new
basement_floor_layers << m10_200mm_concrete_block_basement_wall
basement_floor_layers << cp02_carpet_pad
basement_floor_construction.setLayers(basement_floor_layers)
# Constructs all relevant ground FC factor method constructions
model_set_below_grade_wall_constructions(model, @lookup_building_type, climate_zone)
model_set_floor_constructions(model, @lookup_building_type, climate_zone)
# Set all remaining wall and floor constructions
model.getSurfaces.sort.each do |surface|
if surface.outsideBoundaryCondition.to_s == 'Adiabatic'
if surface.surfaceType.to_s == 'Wall'
surface.setConstruction(wall_adiabatic_construction)
else
surface.setConstruction(floor_adiabatic_construction)
end
elsif surface.outsideBoundaryCondition.to_s == 'OtherSideCoefficients'
# Ground
if surface.surfaceType.to_s == 'Wall'
surface.setOutsideBoundaryCondition('Ground')
surface.setConstruction(basement_wall_construction)
else
surface.setOutsideBoundaryCondition('Ground')
surface.setConstruction(basement_floor_construction)
end
end
end
# Make the default construction set for the building
spc_type = nil
spc_type = 'WholeBuilding' if template == 'NECB2011'
bldg_def_const_set = model_add_construction_set(model, climate_zone, new_lookup_building_type, spc_type, is_residential)
if bldg_def_const_set.is_initialized
model.getBuilding.setDefaultConstructionSet(bldg_def_const_set.get)
else
OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', 'Could not create default construction set for the building.')
return false
end
# Make a construction set for each space type, if one is specified
model.getSpaceTypes.sort.each do |space_type|
# Get the standards building type
stds_building_type = nil
if space_type.standardsBuildingType.is_initialized
stds_building_type = space_type.standardsBuildingType.get
else
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', "Space type called '#{space_type.name}' has no standards building type.")
end
# Get the standards space type
stds_spc_type = nil
if space_type.standardsSpaceType.is_initialized
stds_spc_type = space_type.standardsSpaceType.get
else
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', "Space type called '#{space_type.name}' has no standards space type.")
end
# If the standards space type is Attic the building type should be blank.
if stds_spc_type == 'Attic'
stds_building_type = ''
end
# Attempt to make a construction set for this space type and assign it if it can be created.
spc_type_const_set = model_add_construction_set(model, climate_zone, stds_building_type, stds_spc_type, is_residential)
if spc_type_const_set.is_initialized
space_type.setDefaultConstructionSet(spc_type_const_set.get)
end
end
# Add construction from story level, especially for the case when there are residential and nonresidential construction in the same building
if new_lookup_building_type == 'SmallHotel' && template != 'NECB2011'
model.getBuildingStorys.sort.each do |story|
next if story.name.get == 'AtticStory'
# puts "story = #{story.name}"
is_residential = 'No' # default for building story level
exterior_spaces_area = 0
story_exterior_residential_area = 0
# calculate the propotion of residential area in exterior spaces, see if this story is residential or not
story.spaces.each do |space|
next if space.exteriorWallArea.zero?
space_type = space.spaceType.get
if space_type.standardsSpaceType.is_initialized
space_type_name = space_type.standardsSpaceType.get
end
data = standards_lookup_table_first(table_name: 'space_types', search_criteria: { 'template' => template,
'building_type' => new_lookup_building_type,
'space_type' => space_type_name })
exterior_spaces_area += space.floorArea
story_exterior_residential_area += space.floorArea if data['is_residential'] == 'Yes' # "Yes" is residential, "No" or nil is nonresidential
end
is_residential = 'Yes' if story_exterior_residential_area / exterior_spaces_area >= 0.5
next if is_residential == 'No'
# if the story is identified as residential, assign residential construction set to the spaces on this story.
building_story_const_set = model_add_construction_set(model, climate_zone, new_lookup_building_type, nil, is_residential)
if building_story_const_set.is_initialized
story.spaces.each do |space|
space.setDefaultConstructionSet(building_story_const_set.get)
end
end
end
# Standards: For whole buildings or floors where 50% or more of the spaces adjacent to exterior walls are used primarily for living and sleeping quarters
end
# loop through ceiling surfaces and assign the plenum acoustical tile construction if the adjacent surface is a plenum floor
model.getSurfaces.each do |surface|
next unless surface.surfaceType == 'RoofCeiling' && surface.outsideBoundaryCondition == 'Surface' && surface.adjacentSurface.is_initialized
adj_surface = surface.adjacentSurface.get
adj_space = adj_surface.space.get
if adj_space.spaceType.is_initialized && adj_space.spaceType.get.standardsSpaceType.is_initialized
adj_std_space_type = adj_space.spaceType.get.standardsSpaceType.get
if adj_std_space_type.downcase == 'plenum'
plenum_construction = adj_surface.construction
if plenum_construction.is_initialized
plenum_construction = plenum_construction.get
surface.setConstruction(plenum_construction)
end
end
end
end
# Make skylights have the same construction as fixed windows
# sub_surface = self.getBuilding.defaultConstructionSet.get.defaultExteriorSubSurfaceConstructions.get
# window_construction = sub_surface.fixedWindowConstruction.get
# sub_surface.setSkylightConstruction(window_construction)
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Finished applying constructions')
return true
end
# Creates and sets below grade wall constructions for 90.1 prototype building models. These utilize
# CFactorUndergroundWallConstruction and require some additional parameters when compared to Construction
#
# @param model[OpenStudio::Model::Model] OpenStudio Model
# @param climate_zone [String climate zone as described for prototype models. C-Factor is based on this parameter
# @param building_type [String the building type
# @return [void]
def model_set_below_grade_wall_constructions(model, building_type, climate_zone)
# Find ground contact wall building category
construction_set_data = model_get_construction_set(building_type)
building_type_category = construction_set_data['exterior_wall_building_category']
wall_construction_properties = model_get_construction_properties(model, 'GroundContactWall', 'Mass', building_type_category, climate_zone)
# If no construction properties are found at all, return and allow code to use default constructions
return if wall_construction_properties.nil?
c_factor_ip = wall_construction_properties['assembly_maximum_c_factor']
# If no c-factor is found in construction properties, return and allow code to use defaults
return if c_factor_ip.nil?
# convert to SI
c_factor_si = c_factor_ip * OpenStudio.convert(1.0, 'Btu/ft^2*h*R', 'W/m^2*K').get
# iterate through spaces and set any necessary CFactorUndergroundWallConstructions
model.getSpaces.each do |space|
# Get height of the first below grade wall in this space. Will return nil if none are found.
below_grade_wall_height = model_get_space_below_grade_wall_height(space)
next if below_grade_wall_height.nil?
c_factor_wall_name = "Basement Wall C-Factor #{c_factor_si.round(2)} Height #{below_grade_wall_height.round(2)}"
# Check if the wall construction has been constructed already. If so, look it up in the model
if model.getCFactorUndergroundWallConstructionByName(c_factor_wall_name).is_initialized
basement_wall_construction = model.getCFactorUndergroundWallConstructionByName(c_factor_wall_name).get
else
# Create CFactorUndergroundWallConstruction objects
basement_wall_construction = OpenStudio::Model::CFactorUndergroundWallConstruction.new(model)
basement_wall_construction.setCFactor(c_factor_si)
basement_wall_construction.setName(c_factor_wall_name)
basement_wall_construction.setHeight(below_grade_wall_height)
end
# Set surface construction for walls adjacent to ground (i.e. basement walls)
space.surfaces.each do |surface|
if surface.surfaceType == 'Wall' && surface.outsideBoundaryCondition == 'OtherSideCoefficients'
surface.setConstruction(basement_wall_construction)
surface.setOutsideBoundaryCondition('GroundFCfactorMethod')
end
end
end
end
# Finds heights of the first below grade walls and returns them as a numeric. Used when defining C Factor walls.
# Returns nil if the space is above grade.
# @param space [OpenStudio::Model::Space] space to determine below grade wall height
# @return [Numeric, nil]
def model_get_space_below_grade_wall_height(space)
# find height of first below-grade wall adjacent to the ground
space.surfaces.each do |surface|
next unless surface.surfaceType == 'Wall'
boundary_condition = surface.outsideBoundaryCondition
next unless boundary_condition == 'OtherSideCoefficients' || boundary_condition.to_s.downcase.include?('ground')
# calculate wall height as difference of maximum and minimum z values, assuming square, vertical walls
z_values = []
surface.vertices.each do |vertex|
z_values << vertex.z
end
surface_height = z_values.max - z_values.min
return surface_height
end
return nil
end
# Searches a model for spaces adjacent to ground. If the slab's perimeter is adjacent to ground, the length is
# calculated. Used for F-Factor floors that require additional parameters.
#
# @param model [OpenStudio Model] OpenStudio model being modified
# @param building_type [String the building type
# @param climate_zone [String climate zone as described for prototype models. F-Factor is based on this parameter
def model_set_floor_constructions(model, building_type, climate_zone)
# Find ground contact wall building category
construction_set_data = model_get_construction_set(building_type)
building_type_category = construction_set_data['ground_contact_floor_building_category']
# Find Floor F factor
floor_construction_properties = model_get_construction_properties(model, 'GroundContactFloor', 'Unheated', building_type_category, climate_zone)
# If no construction properties are found at all, return and allow code to use default constructions
return if floor_construction_properties.nil?
f_factor_ip = floor_construction_properties['assembly_maximum_f_factor']
# If no f-factor is found in construction properties, return and allow code to use defaults
return if f_factor_ip.nil?
f_factor_si = f_factor_ip * OpenStudio.convert(1.0, 'Btu/ft*h*R', 'W/m*K').get
# iterate through spaces and set FFactorGroundFloorConstruction to surfaces if applicable
model.getSpaces.each do |space|
# Find this space's exposed floor area and perimeter. NOTE: this assumes only only floor per space.
perimeter, area = model_get_f_floor_geometry(space)
next if area == 0 # skip floors not adjacent to ground
# Record combination of perimeter and area. Each unique combination requires a FFactorGroundFloorConstruction.
# @note periods '.' were causing issues and were therefore removed.
# Caused E+ error with duplicate names despite being different.
f_floor_const_name = "Foundation F #{f_factor_si.round(2)} Perim #{perimeter.round(2)} Area #{area.round(2)}".gsub('.', '')
# Check if the floor construction has been constructed already. If so, look it up in the model
if model.getFFactorGroundFloorConstructionByName(f_floor_const_name).is_initialized
f_floor_construction = model.getFFactorGroundFloorConstructionByName(f_floor_const_name).get
else
f_floor_construction = OpenStudio::Model::FFactorGroundFloorConstruction.new(model)
f_floor_construction.setName(f_floor_const_name)
f_floor_construction.setFFactor(f_factor_si)
f_floor_construction.setArea(area)
f_floor_construction.setPerimeterExposed(perimeter)
end
# Set surface construction for floors adjacent to ground
space.surfaces.each do |surface|
if surface.surfaceType == 'Floor' && surface.outsideBoundaryCondition == 'Ground'
surface.setConstruction(f_floor_construction)
surface.setOutsideBoundaryCondition('GroundFCfactorMethod')
end
end
end
end
# This function returns the space's ground perimeter and area. Assumes only one floor per space!
# @param space [OpenStudio::Model::Space] space object
# @return [Numeric, Numeric]
def model_get_f_floor_geometry(space)
perimeter = 0
floors = []
# Find space's floors
space.surfaces.each do |surface|
if surface.surfaceType == 'Floor' && surface.outsideBoundaryCondition.to_s.downcase.include?('ground')
floors << surface
end
end
# Raise a warning for any space with more than 1 ground contact floor surface.
if floors.length > 1
OpenStudio.logFree(OpenStudio::Warn, 'openstudio.model.Model', "Space: #{space.name} has more than one ground contact floor. FFactorGroundFloorConstruction constructions in this space may be incorrect")
elsif floors.empty? # If this space has no ground contact floors, return 0
return 0, 0
end
floor = floors[0]
# cycle through surfaces in space
space.surfaces.each do |surface|
# find perimeter of floor by finding intersecting outdoor walls and measuring the intersection
if surface.surfaceType == 'Wall' && surface.outsideBoundaryCondition == 'Outdoors'
perimeter += model_calculate_wall_and_floor_intersection(surface, floor)
end
end
# Get floor area
area = floor.netArea
return perimeter, area
end
# This function returns the length of intersection between a wall and floor sharing space. Primarily used for
# FFactorGroundFloorConstruction exposed perimeter calculations.
# @note this calculation has a few assumptions:
# - Floors are flat. This means they have a constant z-axis value.
# - If a wall shares an edge with a floor, it's assumed that edge intersects with only this floor.
# - The wall and floor share a common space. This space is assumed to only have one floor!
# @param wall[OpenStudio::Model::Surface] wall surface being compared to the floor of interest
# @param floor[OpenStudio::Model::Surface] floor occupying same space as wall. Edges checked for interesections with wall
# @return [Numeric] returns the intersection/overlap length of the wall and floor of interest
def model_calculate_wall_and_floor_intersection(wall, floor)
# Used for determining if two points are 'equal' if within this length
tolerance = 0.0001
# Get floor and wall edges
wall_edge_array = model_get_surface_edges(wall)
floor_edge_array = model_get_surface_edges(floor)
# Floor assumed flat and constant in x-y plane (i.e. a single z value)
floor_z_value = floor_edge_array[0][0].z
# Iterate through wall edges
wall_edge_array.each do |wall_edge|
wall_edge_p1 = wall_edge[0]
wall_edge_p2 = wall_edge[1]
# If points representing the wall surface edge have different z-coordinates, this edge is not parallel to the
# floor and can be skipped
if tolerance <= (wall_edge_p1.z - wall_edge_p2.z).abs
next
end
# If wall edge is parallel to the floor, ensure it's on the same x-y plane as the floor.
if tolerance <= (wall_edge_p1.z - floor_z_value).abs
next
end
# If the edge is parallel with the floor and in the same x-y plane as the floor, assume an intersection the
# length of the wall edge
intersect_vector = wall_edge_p1 - wall_edge_p2
edge_vector = OpenStudio::Vector3d.new(intersect_vector.x, intersect_vector.y, intersect_vector.z)
return(edge_vector.length)
end
# If no edges intersected, return 0
return 0
end
# Returns an array of OpenStudio::Point3D pairs of an OpenStudio::Model::Surface's edges. Used to calculate surface
# intersections.
# @param surface[OpenStudio::Model::Surface] - surface whose edges are being returned
# @return [Array<Array(OpenStudio::Point3D, OpenStudio::Point3D)>] - array of pair of points describing the line segment of an edge
def model_get_surface_edges(surface)
vertices = surface.vertices
n_vertices = vertices.length
# Create edge hash that keeps track of all edges in surface. An edge is defined here as an array of length 2
# containing two OpenStudio::Point3Ds that define the line segment representing a surface edge.
edge_array = [] # format edge_array[i] = [OpenStudio::Point3D, OpenStudio::Point3D]
# Iterate through each vertex in the surface and construct an edge for it
for edge_counter in 0..n_vertices - 1
# If not the last vertex in surface
if edge_counter < n_vertices - 1
edge_array << [vertices[edge_counter], vertices[edge_counter + 1]]
else # Make index adjustments for final index in vertices array
edge_array << [vertices[edge_counter], vertices[0]]
end
end
return edge_array
end
# Adds internal mass objects and constructions based on the building type
#
# @param model[OpenStudio::Model::Model] OpenStudio Model
# @param building_type [String] the building type
# @return [Boolean] returns true if successful, false if not
def model_add_internal_mass(model, building_type)
# Assign a material to all internal mass objects
material = OpenStudio::Model::StandardOpaqueMaterial.new(model)
material.setName('Std Wood 6inch')
material.setRoughness('MediumSmooth')
material.setThickness(0.15)
material.setThermalConductivity(0.12)
material.setDensity(540)
material.setSpecificHeat(1210)
material.setThermalAbsorptance(0.9)
material.setSolarAbsorptance(0.7)
material.setVisibleAbsorptance(0.7)
construction = OpenStudio::Model::Construction.new(model)
construction.setName('InteriorFurnishings')
layers = OpenStudio::Model::MaterialVector.new
layers << material
construction.setLayers(layers)
# Assign the internal mass construction to existing internal mass objects
model.getSpaces.sort.each do |space|
internal_masses = space.internalMass
internal_masses.each do |internal_mass|
internal_mass.internalMassDefinition.setConstruction(construction)
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', "Set internal mass construction for internal mass '#{internal_mass.name}' in space '#{space.name}'.")
end
end
# add internal mass
# not required for NECB2011
unless template == 'NECB2011' ||
building_type.include?('DataCenter') ||
((building_type == 'SmallHotel') &&
(template == '90.1-2004' || template == '90.1-2007' || template == '90.1-2010' || template == '90.1-2013' || template == '90.1-2016' || template == '90.1-2019' || template == 'NREL ZNE Ready 2017'))
internal_mass_def = OpenStudio::Model::InternalMassDefinition.new(model)
internal_mass_def.setSurfaceAreaperSpaceFloorArea(2.0)
internal_mass_def.setConstruction(construction)
model.getSpaces.each do |space|
# only add internal mass objects to conditioned spaces
next unless space_cooled?(space)
next unless space_heated?(space)
internal_mass = OpenStudio::Model::InternalMass.new(internal_mass_def)
internal_mass.setName("#{space.name} Mass")
internal_mass.setSpace(space)
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', "Added internal mass '#{internal_mass.name}' to space '#{space.name}'.")
end
end
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Finished adding internal mass')
return true
end
# Creates thermal zones to contain each space, as defined for each building in the
# system_to_space_map inside the Prototype.building_name
# e.g. (Prototype.secondary_school.rb) file.
#
# @param (see #add_constructions)
# @return [Boolean] returns true if successful, false if not
def model_create_thermal_zones(model, space_multiplier_map = nil)
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Started creating thermal zones')
# Retrieve zone multipliers if non assigned via the space_multiplier_map
if space_multiplier_map.nil?
space_multiplier_map = {}
model.getSpaces.each do |spc|
space_multiplier_map.store(spc.name.to_s, spc.thermalZone.get.multiplier.to_int)
end
end
# Remove any Thermal zones assigned
model.getThermalZones.each(&:remove)
# Create a thermal zone for each space in the self
thermostat_to_offset = []
model.getSpaces.sort.each do |space|
zone = OpenStudio::Model::ThermalZone.new(model)
zone.setName("#{space.name} ZN")
unless space_multiplier_map[space.name.to_s].nil? || (space_multiplier_map[space.name.to_s] == 1)
zone.setMultiplier(space_multiplier_map[space.name.to_s])
end
space.setThermalZone(zone)
# Skip thermostat for spaces with no space type
next if space.spaceType.empty?
# Add a thermostat
space_type_name = space.spaceType.get.name.get
thermostat_name = space_type_name + ' Thermostat'
thermostat = model.getThermostatSetpointDualSetpointByName(thermostat_name)
if thermostat.empty?
OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "Thermostat #{thermostat_name} not found for space name: #{space.name}")
else
thermostat_clone = thermostat.get.clone(model).to_ThermostatSetpointDualSetpoint.get
zone.setThermostatSetpointDualSetpoint(thermostat_clone)
if template == 'NECB2011'
# Set Ideal loads to thermal zone for sizing for NECB needs. We need this for sizing.
ideal_loads = OpenStudio::Model::ZoneHVACIdealLoadsAirSystem.new(model)
ideal_loads.addToThermalZone(zone)
end
end
# Modify thermostat schedules if space
# has standby mode occupancy requirements
if space_occupancy_standby_mode_required?(space)
next if thermostat_to_offset.include?(thermostat_clone.name)
space_occupancy_standby_mode(thermostat_clone)
thermostat_to_offset << thermostat_name
end
end
OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Finished creating thermal zones')
end
# Loop through thermal zones and model_run(model) thermal_zone.add_exhaust
# If kitchen_makeup is "None" then exhaust will be modeled in every kitchen zone without makeup air
# If kitchen_makeup is "Adjacent" then exhaust will be modeled in every kitchen zone. Makeup air will be provided when there as an adjacent dining,cafe, or cafeteria zone of the same building type.
# If kitchen_makeup is "Largest Zone" then exhaust will only be modeled in the largest kitchen zone, but the flow rate will be based on the kitchen area for all zones. Makeup air will be modeled in the largest dining,cafe, or cafeteria zone of the same building type.
#
# @param kitchen_makeup [String] Valid choices are None, Largest Zone, Adjacent
# @return [Hash] Hash of newly made exhaust fan objects along with secondary exhaust and zone mixing objects
def model_add_exhaust(model, kitchen_makeup = 'Adjacent')
zone_exhaust_fans = {}
# apply use specified kitchen_makup logic
if !['Adjacent', 'Largest Zone'].include?(kitchen_makeup)
if kitchen_makeup != 'None'
OpenStudio.logFree(OpenStudio::Warn, 'openstudio.model.Model', "#{kitchen_makeup} is an unexpected value for kitchen_makup arg, will use None.")
end
# loop through thermal zones
model.getThermalZones.sort.each do |thermal_zone|
zone_exhaust_hash = thermal_zone_add_exhaust(thermal_zone)
# populate zone_exhaust_fans
zone_exhaust_fans.merge!(zone_exhaust_hash)
end
else # common code for Adjacent and Largest Zone
# populate standard_space_types_with_makup_air
standard_space_types_with_makup_air = {}
standard_space_types_with_makup_air[['FullServiceRestaurant', 'Kitchen']] = ['FullServiceRestaurant', 'Dining']
standard_space_types_with_makup_air[['QuickServiceRestaurant', 'Kitchen']] = ['QuickServiceRestaurant', 'Dining']
standard_space_types_with_makup_air[['Hospital', 'Kitchen']] = ['Hospital', 'Dining']
standard_space_types_with_makup_air[['SecondarySchool', 'Kitchen']] = ['SecondarySchool', 'Cafeteria']
standard_space_types_with_makup_air[['PrimarySchool', 'Kitchen']] = ['PrimarySchool', 'Cafeteria']
standard_space_types_with_makup_air[['LargeHotel', 'Kitchen']] = ['LargeHotel', 'Cafe']
# gather information on zones organized by standards building type and space type. zone may be in this multiple times if it has multiple space types
zones_by_standards = {}
model.getThermalZones.sort.each do |thermal_zone|
# get space type ratio for spaces in zone
space_type_hash = {} # key is space type, value hash with floor area, standards building type, standards space type, and array of adjacent zones
thermal_zone.spaces.each do |space|
next unless space.spaceType.is_initialized
next unless space.partofTotalFloorArea
space_type = space.spaceType.get
next unless space_type.standardsBuildingType.is_initialized
next unless space_type.standardsSpaceType.is_initialized
# add entry in hash for space_type_standardsif it doesn't already exist
unless space_type_hash.key?(space_type)
space_type_hash[space_type] = {}
space_type_hash[space_type][:effective_floor_area] = 0.0
space_type_hash[space_type][:standards_array] = [space_type.standardsBuildingType.get, space_type.standardsSpaceType.get]
if kitchen_makeup == 'Adjacent'
space_type_hash[space_type][:adjacent_zones] = []
end
end
# populate floor area
space_type_hash[space_type][:effective_floor_area] += space.floorArea * space.multiplier
# @todo populate adjacent zones (need to add methods to space and zone for this)
if kitchen_makeup == 'Adjacent'
space_type_hash[space_type][:adjacent_zones] << nil
end
# populate zones_by_standards
unless zones_by_standards.key?(space_type_hash[space_type][:standards_array])
zones_by_standards[space_type_hash[space_type][:standards_array]] = {}
end
zones_by_standards[space_type_hash[space_type][:standards_array]][thermal_zone] = space_type_hash
end
end
if kitchen_makeup == 'Largest Zone'
zones_applied = [] # add thermal zones to this ones they have had thermal_zone.add_exhaust model_run(model) on it
# loop through standard_space_types_with_makup_air
standard_space_types_with_makup_air.each do |makeup_target, makeup_source|
# hash to manage lookups
markup_target_effective_floor_area = {}
markup_source_effective_floor_area = {}
if zones_by_standards.key?(makeup_target)
# process zones of each makeup_target
zones_by_standards[makeup_target].each do |thermal_zone, space_type_hash|
effective_floor_area = 0.0
space_type_hash.each do |space_type, hash|