Top Level Namespace

Defined Under Namespace

Modules: ASHRAE9012010CoolingTower, ASHRAE9012013CoolingTower, BTAP, CoilDX, CoolingTower, EnergyPlus, Fan, FullServiceRestaurant, HighriseApartment, Hospital, LargeHotel, LargeOffice, MediumOffice, MidriseApartment, NRELZNEReady2017CoolingTower, OpenstudioStandards, Outpatient, PrimarySchool, PrototypeFan, Pump, QuickServiceRestaurant, References, RetailStandalone, RetailStripmall, SecondarySchool, SmallHotel, SmallOffice, SuperMarket, Warehouse Classes: ASHRAE901, ASHRAE9012004, ASHRAE9012004FullServiceRestaurant, ASHRAE9012004HighriseApartment, ASHRAE9012004Hospital, ASHRAE9012004LargeHotel, ASHRAE9012004LargeOffice, ASHRAE9012004MediumOffice, ASHRAE9012004MidriseApartment, ASHRAE9012004Outpatient, ASHRAE9012004PrimarySchool, ASHRAE9012004QuickServiceRestaurant, ASHRAE9012004RetailStandalone, ASHRAE9012004RetailStripmall, ASHRAE9012004SecondarySchool, ASHRAE9012004SmallHotel, ASHRAE9012004SmallOffice, ASHRAE9012004SuperMarket, ASHRAE9012004Warehouse, ASHRAE9012004_Prototype, ASHRAE9012007, ASHRAE9012007FullServiceRestaurant, ASHRAE9012007HighriseApartment, ASHRAE9012007Hospital, ASHRAE9012007LargeHotel, ASHRAE9012007LargeOffice, ASHRAE9012007MediumOffice, ASHRAE9012007MidriseApartment, ASHRAE9012007Outpatient, ASHRAE9012007PrimarySchool, ASHRAE9012007QuickServiceRestaurant, ASHRAE9012007RetailStandalone, ASHRAE9012007RetailStripmall, ASHRAE9012007SecondarySchool, ASHRAE9012007SmallHotel, ASHRAE9012007SmallOffice, ASHRAE9012007SuperMarket, ASHRAE9012007Warehouse, ASHRAE9012007_Prototype, ASHRAE9012010, ASHRAE9012010FullServiceRestaurant, ASHRAE9012010HighriseApartment, ASHRAE9012010Hospital, ASHRAE9012010LargeHotel, ASHRAE9012010LargeOffice, ASHRAE9012010MediumOffice, ASHRAE9012010MidriseApartment, ASHRAE9012010Outpatient, ASHRAE9012010PrimarySchool, ASHRAE9012010QuickServiceRestaurant, ASHRAE9012010RetailStandalone, ASHRAE9012010RetailStripmall, ASHRAE9012010SecondarySchool, ASHRAE9012010SmallHotel, ASHRAE9012010SmallOffice, ASHRAE9012010SuperMarket, ASHRAE9012010Warehouse, ASHRAE9012010_Prototype, ASHRAE9012013, ASHRAE9012013FullServiceRestaurant, ASHRAE9012013HighriseApartment, ASHRAE9012013Hospital, ASHRAE9012013LargeHotel, ASHRAE9012013LargeOffice, ASHRAE9012013MediumOffice, ASHRAE9012013MidriseApartment, ASHRAE9012013Outpatient, ASHRAE9012013PrimarySchool, ASHRAE9012013QuickServiceRestaurant, ASHRAE9012013RetailStandalone, ASHRAE9012013RetailStripmall, ASHRAE9012013SecondarySchool, ASHRAE9012013SmallHotel, ASHRAE9012013SmallOffice, ASHRAE9012013SuperMarket, ASHRAE9012013Warehouse, ASHRAE9012013_Prototype, BTAPCosting, DEER, DEER1985, DEER1996, DEER2003, DEER2007, DEER2011, DEER2014, DEER2015, DEER2017, DEERPRE1975, DOERef1980to2004, DOERef1980to2004FullServiceRestaurant, DOERef1980to2004HighriseApartment, DOERef1980to2004Hospital, DOERef1980to2004LargeHotel, DOERef1980to2004LargeOffice, DOERef1980to2004MediumOffice, DOERef1980to2004MidriseApartment, DOERef1980to2004Outpatient, DOERef1980to2004PrimarySchool, DOERef1980to2004QuickServiceRestaurant, DOERef1980to2004RetailStandalone, DOERef1980to2004RetailStripmall, DOERef1980to2004SecondarySchool, DOERef1980to2004SmallHotel, DOERef1980to2004SmallOffice, DOERef1980to2004SuperMarket, DOERef1980to2004Warehouse, DOERef1980to2004_Prototype, DOERefPre1980, DOERefPre1980FullServiceRestaurant, DOERefPre1980HighriseApartment, DOERefPre1980Hospital, DOERefPre1980LargeHotel, DOERefPre1980LargeOffice, DOERefPre1980MediumOffice, DOERefPre1980MidriseApartment, DOERefPre1980Outpatient, DOERefPre1980PrimarySchool, DOERefPre1980QuickServiceRestaurant, DOERefPre1980RetailStandalone, DOERefPre1980RetailStripmall, DOERefPre1980SecondarySchool, DOERefPre1980SmallHotel, DOERefPre1980SmallOffice, DOERefPre1980SuperMarket, DOERefPre1980Warehouse, DOERefPre1980_Prototype, FalseClass, Fixnum, Hash, ICCIECC, ICCIECC2015, NECB2011, NECB2011FullServiceRestaurant, NECB2011HighriseApartment, NECB2011Hospital, NECB2011LargeHotel, NECB2011LargeOffice, NECB2011MediumOffice, NECB2011MidriseApartment, NECB2011Outpatient, NECB2011PrimarySchool, NECB2011QuickServiceRestaurant, NECB2011RetailStandalone, NECB2011RetailStripmall, NECB2011SecondarySchool, NECB2011SmallHotel, NECB2011SmallOffice, NECB2011SuperMarket, NECB2011Warehouse, NECB2011_Prototype, NECB2015, NECB2015FullServiceRestaurant, NECB2015HighriseApartment, NECB2015Hospital, NECB2015LargeHotel, NECB2015LargeOffice, NECB2015MediumOffice, NECB2015MidriseApartment, NECB2015Outpatient, NECB2015PrimarySchool, NECB2015QuickServiceRestaurant, NECB2015RetailStandalone, NECB2015RetailStripmall, NECB2015SecondarySchool, NECB2015SmallHotel, NECB2015SmallOffice, NECB2015SuperMarket, NECB2015Warehouse, NECB2015_Prototype, NRELZNEReady2017, NRELZNEReady2017FullServiceRestaurant, NRELZNEReady2017HighriseApartment, NRELZNEReady2017Hospital, NRELZNEReady2017LargeHotel, NRELZNEReady2017LargeOffice, NRELZNEReady2017MediumOffice, NRELZNEReady2017MidriseApartment, NRELZNEReady2017Outpatient, NRELZNEReady2017PrimarySchool, NRELZNEReady2017QuickServiceRestaurant, NRELZNEReady2017RetailStandalone, NRELZNEReady2017RetailStripmall, NRELZNEReady2017SecondarySchool, NRELZNEReady2017SmallHotel, NRELZNEReady2017SmallOffice, NRELZNEReady2017SuperMarket, NRELZNEReady2017Warehouse, NRELZNEReady2017_Prototype, NilClass, OEESC, OEESC2014, OSMArg, Standard, StandardsData, String, TrueClass, Utilities, Vintagizer

Instance Method Summary collapse

Instance Method Details

#check_boolean_value(value, varname) ⇒ Object



718
719
720
721
722
723
# File 'lib/openstudio-standards/btap/btap_result.rb', line 718

def check_boolean_value (value,varname)
  return true if value =~ (/^(true|t|yes|y|1)$/i)
  return false if value.empty? || value =~ (/^(false|f|no|n|0)$/i)

  raise ArgumentError.new "invalid value for #{varname}: #{value}"
end

#create_class_arrayObject



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
# File 'lib/openstudio-standards/prototypes/common/prototype_metaprogramming.rb', line 6

def create_class_array
  prototype_buildings = [
      'FullServiceRestaurant',
      'Hospital',
      'HighriseApartment',
      'LargeHotel',
      'LargeOffice',
      'MediumOffice',
      'MidriseApartment',
      'Outpatient',
      'PrimarySchool',
      'QuickServiceRestaurant',
      'RetailStandalone',
      'SecondarySchool',
      'SmallHotel',
      'SmallOffice',
      'RetailStripmall',
      'Warehouse',
      'SuperMarket'
  ]

  templates = ['ASHRAE9012004',
               'ASHRAE9012007',
               'ASHRAE9012010',
               'ASHRAE9012013',
               'DOERef1980to2004',
               'DOERefPre1980',
               'NRELZNEReady2017']
  class_array = []
  templates.each do |template|
    # Create Prototype base class (May not be needed...)
    # Ex: class NECB2011_Prototype < NECB2011
    class_array << "
  class #{template}_Prototype < #{template}
  attr_reader :instvarbuilding_type
  def initialize
    super()
  end
end
"

    # Create Building Specific classes for each building.
    # Example class NECB2011Hospital
    prototype_buildings.each do |name|
      class_array << "
  # This class represents a prototypical #{template} #{name}.
  class #{template}#{name} < #{template}
  @@building_type = \"#{name}\"
  register_standard (\"\#{@@template}_\#{@@building_type}\")
  attr_accessor :prototype_database
  attr_accessor :prototype_input
  attr_accessor :lookup_building_type
  attr_accessor :space_type_map
  attr_accessor :geometry_file
  attr_accessor :building_story_map
  attr_accessor :system_to_space_map
  def initialize
    super()
    @instvarbuilding_type = @@building_type
    @prototype_input = self.model_find_object(@standards_data['prototype_inputs'], {'template' => @template,'building_type' => @@building_type }, nil)
    if @prototype_input.nil?
      OpenStudio.logFree(OpenStudio::Error, 'openstudio.standards.Model', \"Could not find prototype inputs for \#{{'template' => @template,'building_type' => @@building_type }}, cannot create model.\")
      raise(\"Could not find prototype inputs for #{template}#{name}, cannot create model.\")
      return false
    end
    @lookup_building_type = self.model_get_lookup_name(@@building_type)
    #ideally we should map the data required to a instance variable.
    @geometry_file = 'geometry/' + self.class.name + '.osm'
    hvac_map_file =  'geometry/' + self.class.name + '.hvac_map.json'
    @system_to_space_map = load_hvac_map(hvac_map_file)
    self.set_variables()
  end
  # This method is used to extend the class with building-type-specific
  # methods, as defined in Prototype.SomeBuildingType.rb.  Each building type
  # has its own set of methods that change things which are not
  # common across all prototype buildings, even within a given Standard.
  def set_variables()
    # Will be overwritten in class reopen file.
    # add all building methods for now.
    self.extend(#{name}) unless @template == 'NECB 2011'
  end
  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the space types
  # available for this particular Standard.
  def define_space_type_map(building_type, climate_zone)
    return @space_type_map
  end
  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the HVAC system that will
  # be applied to those spaces.
  def define_hvac_system_map(building_type, climate_zone)
    return @system_to_space_map
  end
  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the building story
  # that they are located on.
  def define_building_story_map(building_type, climate_zone)
     return @building_story_map
  end
  # Does nothing unless implmented by the specific standard
  def model_modify_oa_controller(model)
  end
  # Does nothing unless implmented by the specific standard
  def model_reset_or_room_vav_minimum_damper(prototype_input, model)
  end
  # Does nothing unless implmented by the specific standard
  def model_update_exhaust_fan_efficiency(model)
  end
  # Does nothing unless implmented by the specific standard
  def model_update_fan_efficiency(model)
  end
  # Get the name of the building type used in lookups
  #
  # @param building_type [String] the building type
  # @return [String] returns the lookup name as a string
  # @todo Unify the lookup names and eliminate this method
  def model_get_lookup_name(building_type)
    lookup_name = building_type
    case building_type
      when 'SmallOffice'
        lookup_name = 'Office'
      when 'MediumOffice'
        lookup_name = 'Office'
      when 'LargeOffice'
        lookup_name = 'Office'
      when 'LargeOfficeDetail'
        lookup_name = 'Office'
      when 'RetailStandalone'
        lookup_name = 'Retail'
      when 'RetailStripmall'
        lookup_name = 'StripMall'
      when 'Office'
        lookup_name = 'Office'
    end
    return lookup_name
  end
end
"
    end
  end

  ['NECB2011',
   'NECB2015'].each do |template|
    # Create Prototype base class (May not be needed...)
    # Ex: class NECB2011_Prototype < NECB2011
    class_array << "
  class #{template}_Prototype < #{template}
  attr_reader :instvarbuilding_type
  def initialize
    super()
  end
end
"

    # Create Building Specific classes for each building.
    # Example class NECB2011Hospital
    prototype_buildings.each do |name|
      class_array << "
  # This class represents a prototypical #{template} #{name}.
  class #{template}#{name} < #{template}
    BUILDING_TYPE = \"#{name}\"
    TEMPLATE =  \"#{template}\"
    register_standard (\"\#{TEMPLATE}_\#{BUILDING_TYPE}\")
    attr_accessor :prototype_database
    attr_accessor :prototype_input
    attr_accessor :lookup_building_type
    attr_accessor :space_type_map
    attr_accessor :geometry_file
    attr_accessor :building_story_map
    attr_accessor :system_to_space_map

    def initialize
      super()
      @building_type = BUILDING_TYPE
      @template = TEMPLATE
      @instvarbuilding_type = @building_type
      @prototype_input = self.model_find_object(@standards_data['prototype_inputs'], {'template' => \"#{template}\",'building_type' => \"#{name}\" }, nil)
      if @prototype_input.nil?
        OpenStudio.logFree(OpenStudio::Error, 'openstudio.standards.Model', \"Could not find prototype inputs for \#{{'template' => \"#{template}\",'building_type' => \"#{name}\" }}, cannot create model.\")
        #puts JSON.pretty_generate(standards_data['prototype_inputs'])
        raise(\"Could not find prototype inputs for #{template} #{name}, cannot create model.\")
        return false
      end
      @lookup_building_type = self.model_get_lookup_name(@building_type)
      #ideally we should map the data required to a instance variable.
      @geometry_file = 'geometry/' + self.class.name + '.osm'
      hvac_map_file =  'geometry/' + self.class.name + '.hvac_map.json'
      # @system_to_space_map = load_hvac_map(hvac_map_file) # No HVAC map json files for NECB
      self.set_variables()
    end

  # This method is used to extend the class with building-type-specific
  # methods, as defined in Prototype.SomeBuildingType.rb.  Each building type
  # has its own set of methods that change things which are not
  # common across all prototype buildings, even within a given Standard.
    def set_variables()
    end

  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the space types
  # available for this particular Standard.
    def define_space_type_map(building_type, climate_zone)
      return @space_type_map
    end

  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the HVAC system that will
  # be applied to those spaces.
    def define_hvac_system_map(building_type, climate_zone)
      return @system_to_space_map
    end

  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the building story
  # that they are located on.
  def define_building_story_map(building_type, climate_zone)
     return @building_story_map
  end

  # Does nothing unless implmented by the specific standard
  def model_modify_oa_controller(model)
  end

  # Does nothing unless implmented by the specific standard
  def model_reset_or_room_vav_minimum_damper(prototype_input, model)
  end

  # Does nothing unless implmented by the specific standard
  def model_update_exhaust_fan_efficiency(model)
  end

  # Does nothing unless implmented by the specific standard
  def model_update_fan_efficiency(model)
  end

end
"
    end
  end


  return class_array
end

#create_deer_class_arrayObject



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
# File 'lib/openstudio-standards/prototypes/common/prototype_metaprogramming.rb', line 250

def create_deer_class_array
  prototype_buildings = [
      'Asm',
      'ECC',
      'EPr',
      'ERC',
      'ESe',
      'EUn',
      'Gro',
      'Hsp',
      'Nrs',
      'Htl',
      'Mtl',
      'MBT',
      'MLI',
      'OfL',
      'OfS',
      'RFF',
      'RSD',
      'Rt3',
      'RtL',
      'RtS',
      'SCn',
      'SUn',
      'WRf',
      'GHs',
      'DMo',
      'MFm',
      'SFm'
  ]

  # Only a subset of building type and HVAC type combinations are valid
  building_to_hvac_systems = {
      'Asm' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'ECC' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'EPr' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'WLHP'],
      'ERC' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'ESe' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'EUn' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG'],
      'Gro' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'Hsp' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG'],
      'Nrs' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'FPFC',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG'],
      'Htl' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'Mtl' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'MBT' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'MFm' => [
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'MLI' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'OfL' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'OfS' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'RFF' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'RSD' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'Rt3' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF',
          'PVVE',
          'PVVG',
          'SVVE',
          'SVVG',
          'WLHP'],
      'RtL' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'RtS' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'SCn' => [
          'DXEH',
          'DXGF',
          'DXHP',
          'NCEH',
          'NCGF'],
      'SUn' => ['Unc'],
      'WRf' => ['DXGF']
  }
  
  templates = ['DEERPRE1975',
                'DEER1985',
                'DEER1996',
                'DEER2003',
                'DEER2007',
                'DEER2011',
                'DEER2014',
                'DEER2015',
                'DEER2017']

  class_array = []
  templates.each do |template|
    # Create Prototype base class (May not be needed...)
    # Ex: class DEER_Prototype < DEER1985
    class_array << "
  class #{template}_Prototype < #{template}
  attr_reader :instvarbuilding_type
  def initialize
    super()
  end
end
"

    # Create Building Specific classes for each building.
    # Example class DEER1985AsmDXGF
    prototype_buildings.each do |building_type|
      next if building_to_hvac_systems[building_type].nil?
      building_to_hvac_systems[building_type].each do |hvac_system|
      class_array << "
  # This class represents a prototypical #{template} #{building_type} #{hvac_system}.
  class #{template}#{building_type}#{hvac_system} < #{template}
  @@building_type = \"#{building_type}\"
  @@hvac_system = \"#{hvac_system}\"
  register_standard (\"\#{@@template}_\#{@@building_type}_\#{@@hvac_system}\")
  attr_accessor :prototype_database
  attr_accessor :prototype_input
  attr_accessor :lookup_building_type
  attr_accessor :space_type_map
  attr_accessor :geometry_file
  attr_accessor :building_story_map
  attr_accessor :system_to_space_map

  def initialize
    super()
    @instvarbuilding_type = @@building_type
    @prototype_input = self.model_find_object(standards_data['prototype_inputs'], {'template' => @template,'building_type' => @@building_type, 'hvac_system' => @@hvac_system}, nil)
    if @prototype_input.nil?
      OpenStudio.logFree(OpenStudio::Error, 'openstudio.standards.Model', \"Could not find prototype inputs for \#{{'template' => @template,'building_type' => @@building_type, 'hvac' => @@hvac_system}}, cannot create model.\")
      raise(\"Could not find prototype inputs for #{template}#{building_type}#{hvac_system}, cannot create model.\")
      return false
    end
    @lookup_building_type = @@building_type
    #ideally we should map the data required to a instance variable.
    @geometry_file = 'geometry/' + @prototype_input['geometry_osm']
    hvac_map_file =  'geometry/' + @prototype_input['hvac_json']
    @system_to_space_map = load_hvac_map(hvac_map_file)
    self.set_variables()
  end

  # This method is used to extend the class with building-type-specific
  # methods, as defined in Prototype.SomeBuildingType.rb.  Each building type
  # has its own set of methods that change things which are not
  # common across all prototype buildings, even within a given Standard.
  def set_variables()
    # Will be overwritten in class reopen file.
    # add all building methods for now.
  end

  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the space types
  # available for this particular Standard.
  def define_space_type_map(building_type, climate_zone)
    return @space_type_map
  end

  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the HVAC system that will
  # be applied to those spaces.
  def define_hvac_system_map(building_type, climate_zone)
    return @system_to_space_map
  end

  # Returns the mapping between the names of the spaces
  # in the geometry .osm file and the building story
  # that they are located on.
  def define_building_story_map(building_type, climate_zone)
     return @building_story_map
  end

  # Does nothing unless implmented by the specific standard
  def model_modify_oa_controller(model)
  end

  # Does nothing unless implmented by the specific standard
  def model_reset_or_room_vav_minimum_damper(prototype_input, model)
  end

  # Does nothing unless implmented by the specific standard
  def model_update_exhaust_fan_efficiency(model)
  end

  # Does nothing unless implmented by the specific standard
  def model_update_fan_efficiency(model)
  end

  # Get the name of the building type used in lookups.
  # For DEER, this is the building type.
  #
  # @param building_type [String] the building type
  # @return [String] returns the lookup name as a string
  def model_get_lookup_name(building_type)
    return building_type
  end

  # Makes changes to the HVAC systems that are too
  # specific to be coded generically.
  #
  # @return [Bool] returns true if successful, false if not
  def model_custom_hvac_tweaks(building_type, climate_zone, prototype_input, model)
    return true
  end

  # Makes changes to the SWH systems that are too
  # specific to be coded generically.
  #
  # @return [Bool] returns true if successful, false if not
  def model_custom_swh_tweaks(building_type, climate_zone, prototype_input, model)
    return true
  end
end
"
      end
    end
  end
  return class_array
end

#create_meta_classesObject



604
605
606
607
# File 'lib/openstudio-standards/prototypes/common/prototype_metaprogramming.rb', line 604

def create_meta_classes
  create_class_array.each { |item| eval(item) } # rubocop:disable Security/Eval
  create_deer_class_array.each { |item| eval(item) } # rubocop:disable Security/Eval
end

#distance(loc1, loc2) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/openstudio-standards/utilities/necb_to_epw_map.rb', line 3

def distance(loc1, loc2)
  rad_per_deg = Math::PI/180 # PI / 180
  rkm = 6371 # Earth radius in kilometers
  rm = rkm * 1000 # Radius in meters

  dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad
  dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg

  lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg}
  lat2_rad, lon2_rad = loc2.map {|i| i * rad_per_deg}

  a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2
  c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
  rm * c # Delta in meters
end

#get_logs(log_type = OpenStudio::Error) ⇒ Object

Get an array of all messages of a given type in the log



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/openstudio-standards/utilities/logging.rb', line 85

def get_logs(log_type = OpenStudio::Error)
  errors = []

  $OPENSTUDIO_LOG.logMessages.each do |msg| # rubocop:disable Style/GlobalVars
    if /openstudio.*/ =~ msg.logChannel
      # Skip certain messages that are irrelevant/misleading
      next if msg.logMessage.include?('Skipping layer') || # Annoying/bogus "Skipping layer" warnings
              msg.logChannel.include?('runmanager') || # RunManager messages
              msg.logChannel.include?('setFileExtension') || # .ddy extension unexpected
              msg.logChannel.include?('Translator') || # Forward translator and geometry translator
              msg.logMessage.include?('UseWeatherFile') || # 'UseWeatherFile' is not yet a supported option for YearDescription
              msg.logMessage.include?('Successive data points') || # Successive data points (2004-Jan-31 to 2001-Feb-01, ending on line 753) are greater than 1 day apart in EPW file
              msg.logMessage.include?('has multiple parents') || # Bogus errors about curves having multiple parents
              msg.logMessage.include?('does not have an Output') # Warning from EMS translation
      # Only fail on the errors
      if msg.logLevel == log_type
        errors << "[#{msg.logChannel}] #{msg.logMessage}"
      end
    end
  end

  return errors
end

#get_total_nominal_capacity(model) ⇒ Object



726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/openstudio-standards/btap/btap_result.rb', line 726

def get_total_nominal_capacity (model)
  total_nominal_capacity = 0
  model.getSpaces.sort.each do |space|
    zone_name = space.thermalZone.get.name.get.upcase
    area = model.sqlFile().get().execAndReturnFirstDouble("SELECT Value FROM TabularDataWithStrings WHERE ReportName='InputVerificationandResultsSummary' AND ReportForString='Entire Facility' AND TableName='Zone Summary' AND ColumnName='Area' AND RowName='#{zone_name}'")
    area = validate_optional(area, model, -1)
    multiplier = model.sqlFile().get().execAndReturnFirstDouble("SELECT Value FROM TabularDataWithStrings WHERE ReportName='InputVerificationandResultsSummary' AND ReportForString='Entire Facility' AND TableName='Zone Summary' AND ColumnName='Multipliers' AND RowName='#{zone_name}'")
    multiplier = validate_optional(multiplier, model, -1)
    area_per_person = model.sqlFile().get().execAndReturnFirstDouble("SELECT Value FROM TabularDataWithStrings WHERE ReportName='InputVerificationandResultsSummary' AND ReportForString='Entire Facility' AND TableName='Zone Summary' AND ColumnName='People' AND RowName='#{zone_name}'")
    area_per_person = validate_optional(area_per_person, model, -1)
    next if area_per_person == 0
    puts "area: #{area}  multiplier: #{multiplier}   area_per_person: #{area_per_person}"
    total_nominal_capacity += area*multiplier/area_per_person
  end
  return total_nominal_capacity
end

#log_messages_to_file(file_path, debug = false) ⇒ Array<String>

Log the info, warning, and error messages to a file. runner @param [file_path] The path to the log file debug @param [Boolean] If true, include the debug messages in the log

Returns:

  • (Array<String>)

    The array of messages, which can be used elsewhere.



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
# File 'lib/openstudio-standards/utilities/logging.rb', line 42

def log_messages_to_file(file_path, debug = false)
  messages = []

  File.open(file_path, 'w') do |file|
    $OPENSTUDIO_LOG.logMessages.each do |msg| # rubocop:disable Style/GlobalVars
      # DLM: you can filter on log channel here for now
      if /openstudio.*/ =~ msg.logChannel # /openstudio\.model\..*/
        # Skip certain messages that are irrelevant/misleading
        next if msg.logMessage.include?('Skipping layer') || # Annoying/bogus "Skipping layer" warnings
                msg.logChannel.include?('runmanager') || # RunManager messages
                msg.logChannel.include?('setFileExtension') || # .ddy extension unexpected
                msg.logChannel.include?('Translator') || # Forward translator and geometry translator
                msg.logMessage.include?('UseWeatherFile') || # 'UseWeatherFile' is not yet a supported option for YearDescription
                msg.logMessage.include?('Successive data points') || # Successive data points (2004-Jan-31 to 2001-Feb-01, ending on line 753) are greater than 1 day apart in EPW file
                msg.logMessage.include?('has multiple parents') || # Bogus errors about curves having multiple parents
                msg.logMessage.include?('does not have an Output') # Warning from EMS translation

        # Report the message in the correct way
        if msg.logLevel == OpenStudio::Info
          s = "INFO  #{msg.logMessage}"
          file.puts(s)
          messages << s
        elsif msg.logLevel == OpenStudio::Warn
          s = "WARN  #{msg.logMessage}"
          file.puts(s)
          messages << s
        elsif msg.logLevel == OpenStudio::Error
          s = "ERROR #{msg.logMessage}"
          file.puts(s)
          messages << s
        elsif msg.logLevel == OpenStudio::Debug && debug
          s = "DEBUG #{msg.logMessage}"
          file.puts(s)
          messages << s
        end
      end
    end
  end

  return messages
end

#log_messages_to_runner(runner, debug = false) ⇒ Runner

Log the info, warning, and error messages to a runner. runner @param [Runner] The Measure runner to add the messages to debug @param [Boolean] If true, include the debug messages in the log

Returns:

  • (Runner)

    The same Measure runner, with messages from the openstudio-standards library added



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
# File 'lib/openstudio-standards/utilities/logging.rb', line 10

def log_messages_to_runner(runner, debug = false)
  $OPENSTUDIO_LOG.logMessages.each do |msg| # rubocop:disable Style/GlobalVars
    # DLM: you can filter on log channel here for now
    if /openstudio.*/ =~ msg.logChannel # /openstudio\.model\..*/
      # Skip certain messages that are irrelevant/misleading
      next if msg.logMessage.include?('Skipping layer') || # Annoying/bogus "Skipping layer" warnings
              msg.logChannel.include?('runmanager') || # RunManager messages
              msg.logChannel.include?('setFileExtension') || # .ddy extension unexpected
              msg.logChannel.include?('Translator') || # Forward translator and geometry translator
              msg.logMessage.include?('UseWeatherFile') || # 'UseWeatherFile' is not yet a supported option for YearDescription
              msg.logMessage.include?('Successive data points') || # Successive data points (2004-Jan-31 to 2001-Feb-01, ending on line 753) are greater than 1 day apart in EPW file
              msg.logMessage.include?('has multiple parents') || # Bogus errors about curves having multiple parents
              msg.logMessage.include?('does not have an Output') # Warning from EMS translation

      # Report the message in the correct way
      if msg.logLevel == OpenStudio::Info
        runner.registerInfo(msg.logMessage)
      elsif msg.logLevel == OpenStudio::Warn
        runner.registerWarning("[#{msg.logChannel}] #{msg.logMessage}")
      elsif msg.logLevel == OpenStudio::Error
        runner.registerError("[#{msg.logChannel}] #{msg.logMessage}")
      elsif msg.logLevel == OpenStudio::Debug && debug
        runner.registerInfo("DEBUG - #{msg.logMessage}")
      end
    end
  end
end

#look_up_csv_data(csv_fname, search_criteria) ⇒ Object



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
# File 'lib/openstudio-standards/btap/btap_result.rb', line 662

def look_up_csv_data(csv_fname, search_criteria)
  options = { :headers    => :first_row,
    :converters => [ :numeric ] }
  unless File.exist?(csv_fname)
    raise ("File: [#{csv_fname}] Does not exist")
  end
  # we'll save the matches here
  matches = nil
  # save a copy of the headers
  headers = nil
  CSV.open( csv_fname, "r", options ) do |csv|

    # Since CSV includes Enumerable we can use 'find_all'
    # which will return all the elements of the Enumerble for 
    # which the block returns true

    matches = csv.find_all do |row|
      match = true
      search_criteria.keys.each do |key|
        match = match && ( row[key].strip == search_criteria[key].strip )
      end
      match
    end
    headers = csv.headers
  end
  #puts matches
  raise("More than one match") if matches.size > 1
  puts "Zero matches found for [#{search_criteria}]" if matches.size == 0
  #return matches[0]
  return matches[0]
end

#necb_2011_qaqc(qaqc, model) ⇒ Object



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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
# File 'lib/openstudio-standards/btap/btap_result.rb', line 775

def necb_2011_qaqc(qaqc, model)
  #Now perform basic QA/QC on items for NECB2011 
  qaqc[:information] = []
  qaqc[:warnings] =[]
  qaqc[:errors] = []
  qaqc[:unique_errors]=[]
    

  #    #Padmassun's Code Start
  csv_file_name ="#{File.dirname(__FILE__)}/necb_2011_spacetype_info.csv"
  puts csv_file_name
  qaqc[:spaces].each do |space|
    building_type =""
    space_type =""
    if space[:space_type_name].include? 'Space Function '
      space_type = (space[:space_type_name].to_s.rpartition('Space Function '))[2].strip
      building_type = 'Space Function'
    elsif space[:space_type_name].include? ' WholeBuilding'
      space_type = (space[:space_type_name].to_s.rpartition(' WholeBuilding'))[0].strip
      building_type = 'WholeBuilding'
    end
    row = look_up_csv_data(csv_file_name,{2 => space_type, 1 => building_type})
    if row.nil?
      #raise ("space type of [#{space_type}] and/or building type of [#{building_type}] was not found in the excel sheet for space: [#{space[:name]}]")
      qaqc[:ruby_warnings] << "space type of [#{space_type}] and/or building type of [#{building_type}] was not found in the excel sheet for space: [#{space[:name]}]"
      puts "space type of [#{space_type}] and/or building type of [#{building_type}] was not found in the excel sheet for space: [#{space[:name]}]"
    else
      #correct the data from the csv file to include a multiplier of 0.9 for specific space types.
      
      reduceLPDSpaces = ["Classroom/lecture/training", "Conf./meet./multi-purpose", "Lounge/recreation",
        "Washroom-sch-A", "Washroom-sch-B", "Washroom-sch-C", "Washroom-sch-D", "Washroom-sch-E", 
        "Washroom-sch-F", "Washroom-sch-G", "Washroom-sch-H", "Washroom-sch-I", "Dress./fitt. - performance arts", 
        "Locker room", "Retail - dressing/fitting","Locker room-sch-A","Locker room-sch-B","Locker room-sch-C",
        "Locker room-sch-D","Locker room-sch-E","Locker room-sch-F","Locker room-sch-G","Locker room-sch-H",
        "Locker room-sch-I", "Office - open plan - occsens", "Office - enclosed - occsens", "Storage area - occsens",
        "Hospital - medical supply - occsens", "Storage area - refrigerated - occsens"]
      
      if reduceLPDSpaces.include?(space_type)
        row[3] = row[3]*0.9
        puts "\n============================\nspace_type: #{space_type}\n============================\n"
      end
      
      # Start of Space Compliance
      necb_section_name = "NECB2011-Section 8.4.3.6"
      data = {}
      data[:lighting_per_area] 		        = [ row[3],'==',space[:lighting_w_per_m2] , "Table 4.2.1.6"     ,1 ] unless space[:lighting_w_per_m2].nil?
      data[:occupancy_per_area]           = [ row[4],'==',space[:occ_per_m2]        , "Table A-8.4.3.3.1" ,3 ] unless space[:occ_per_m2].nil?
      data[:occupancy_schedule]           = [ row[5],'==',space[:occupancy_schedule], "Table A-8.4.3.3.1" ,nil ] unless space[:occupancy_schedule].nil?
      data[:electric_equipment_per_area]  = [ row[6],'==',space[:electric_w_per_m2] , "Table A-8.4.3.3.1" ,1 ] unless space[:electric_w_per_m2].nil?
      data.each do |key,value|
        #puts key
        necb_section_test(
          qaqc,
          value[0],
          value[1],
          value[2],
          value[3],
          "[SPACE][#{space[:name]}]-[TYPE:][#{space_type}]#{key}",
          value[4]
        )
      end
    end#space Compliance
  end
  #Padmassun's Code End
    

  # Envelope
  necb_section_name = "NECB2011-Section 3.2.1.4"
  #store hdd in short form
  hdd = qaqc[:geography][:hdd]
  #calculate fdwr based on hdd. 
  fdwr = 0
  if hdd < 4000
    fdwr = 0.40
  elsif hdd >= 4000 and hdd <=7000
    fdwr = (2000-0.2 * hdd)/3000
  elsif hdd >7000
    fdwr = 0.20
  end
  #hardset srr to 0.05 
  srr = 0.05
  #create table of expected values and results.
  data = {}
  data[:fenestration_to_door_and_window_percentage]  = [ fdwr * 100,qaqc[:envelope][:fdwr].round(3)]
  data[:skylight_to_roof_percentage]  = [  srr * 100,qaqc[:envelope][:srr].round(3)]
  #perform test. result must be less than or equal to.
  data.each {|key,value| necb_section_test( 
      qaqc, 
      value[0],
      '>=',
      value[1],
      necb_section_name,
      "[ENVELOPE]#{key}",
      1 #padmassun added tollerance
    )
  }

  #Infiltration
  necb_section_name = "NECB2011-Section 8.4.3.6"
  qaqc[:spaces].each do |spaceinfo|
    data = {}
    data[:infiltration_method] 		= [ "Flow/ExteriorArea", spaceinfo[:infiltration_method] , nil ] 
    data[:infiltration_flow_per_m2] = [ 0.00025,			 spaceinfo[:infiltration_flow_per_m2], 5 ]
    data.each do |key,value|
      #puts key
      necb_section_test( 
        qaqc,
        value[0],
        '==',
        value[1],
        necb_section_name,
        "[SPACE][#{spaceinfo[:name]}]-#{key}",
        value[2]
      )
    end
  end
  #Exterior Opaque
  necb_section_name = "NECB2011-Section 3.2.2.2"
  climate_index = BTAP::Compliance::NECB2011::get_climate_zone_index(qaqc[:geography][:hdd])
  result_value_index = 6
  round_precision = 3
  data = {}
  data[:ext_wall_conductances]        =  [0.315,0.278,0.247,0.210,0.210,0.183,qaqc[:envelope][:outdoor_walls_average_conductance_w_per_m2_k]] unless qaqc[:envelope][:outdoor_walls_average_conductance_w_per_m2_k].nil?
  data[:ext_roof_conductances]        =  [0.227,0.183,0.183,0.162,0.162,0.142,qaqc[:envelope][:outdoor_roofs_average_conductance_w_per_m2_k]] unless qaqc[:envelope][:outdoor_roofs_average_conductance_w_per_m2_k].nil?
  data[:ext_floor_conductances]       =  [0.227,0.183,0.183,0.162,0.162,0.142,qaqc[:envelope][:outdoor_floors_average_conductance_w_per_m2_k]] unless qaqc[:envelope][:outdoor_floors_average_conductance_w_per_m2_k].nil?
    
  data.each {|key,value| necb_section_test( 
      qaqc,
      value[result_value_index],
      '==',
      value[climate_index],
      necb_section_name,
      "[ENVELOPE]#{key}",
      round_precision
    )
  }
  #Exterior Fenestration
  necb_section_name = "NECB2011-Section 3.2.2.3"
  climate_index = BTAP::Compliance::NECB2011::get_climate_zone_index(qaqc[:geography][:hdd])
  result_value_index = 6
  round_precision = 3
  data = {}
  data[:ext_window_conductances]      =     [2.400,2.200,2.200,2.200,2.200,1.600,qaqc[:envelope][:windows_average_conductance_w_per_m2_k]] unless qaqc[:envelope][:windows_average_conductance_w_per_m2_k].nil?
  data[:ext_door_conductances]        =     [2.400,2.200,2.200,2.200,2.200,1.600,qaqc[:envelope][:doors_average_conductance_w_per_m2_k]]   unless qaqc[:envelope][:doors_average_conductance_w_per_m2_k].nil?
  data[:ext_overhead_door_conductances] =   [2.400,2.200,2.200,2.200,2.200,1.600,qaqc[:envelope][:overhead_doors_average_conductance_w_per_m2_k]] unless qaqc[:envelope][:overhead_doors_average_conductance_w_per_m2_k].nil?
  data[:ext_skylight_conductances]  =       [2.400,2.200,2.200,2.200,2.200,1.600,qaqc[:envelope][:skylights_average_conductance_w_per_m2_k]] unless qaqc[:envelope][:skylights_average_conductance_w_per_m2_k].nil?
  data.each do |key,value|
	
    #puts key
    necb_section_test( 
      qaqc,
      value[result_value_index].round(round_precision),
      '==',
      value[climate_index].round(round_precision),
      necb_section_name,
      "[ENVELOPE]#{key}",
      round_precision
    )
  end    
  #Exterior Ground surfaces
  necb_section_name = "NECB2011-Section 3.2.3.1"
  climate_index = BTAP::Compliance::NECB2011::get_climate_zone_index(qaqc[:geography][:hdd])
  result_value_index = 6
  round_precision = 3
  data = {}
  data[:ground_wall_conductances]  = [ 0.568,0.379,0.284,0.284,0.284,0.210, qaqc[:envelope][:ground_walls_average_conductance_w_per_m2_k] ]  unless qaqc[:envelope][:ground_walls_average_conductance_w_per_m2_k].nil?
  data[:ground_roof_conductances]  = [ 0.568,0.379,0.284,0.284,0.284,0.210, qaqc[:envelope][:ground_roofs_average_conductance_w_per_m2_k] ]  unless qaqc[:envelope][:ground_roofs_average_conductance_w_per_m2_k].nil?
  data[:ground_floor_conductances] = [ 0.757,0.757,0.757,0.757,0.757,0.379, qaqc[:envelope][:ground_floors_average_conductance_w_per_m2_k] ] unless qaqc[:envelope][:ground_floors_average_conductance_w_per_m2_k].nil?
  data.each {|key,value| necb_section_test( 
      qaqc,
      value[result_value_index],
      '==',
      value[climate_index],
      necb_section_name,
      "[ENVELOPE]#{key}",
      round_precision
    )
  }
  #Zone Sizing and design supply temp tests
  necb_section_name = "NECB2011-?"
  qaqc[:thermal_zones].each do |zoneinfo|
    #    skipping undefined schedules
    if zoneinfo[:name].to_s.include?"- undefined -"
      next
    end
    data = {}
    data[:heating_sizing_factor] = [1.3 , zoneinfo[:heating_sizing_factor]]
    data[:cooling_sizing_factor] = [1.1 ,zoneinfo[:cooling_sizing_factor]]
    data[:heating_design_supply_air_temp] =   [43.0, zoneinfo[:zone_heating_design_supply_air_temperature] ] #unless zoneinfo[:zone_heating_design_supply_air_temperature].nil?
    data[:cooling_design_supply_temp] 	=   [13.0, zoneinfo[:zone_cooling_design_supply_air_temperature] ]
    data.each do |key,value| 
      #puts key
      necb_section_test( 
        qaqc,
        value[0],
        '==',
        value[1],
        necb_section_name,
        "[ZONE][#{zoneinfo[:name]}] #{key}",
        round_precision
      )
    end
  end	
  #Air flow sizing check
  #determine correct economizer usage according to section 5.2.2.7 of NECB2011
  necb_section_name = "NECB2011-5.2.2.7"
  qaqc[:air_loops].each do |air_loop_info|
    #    air_loop_info[:name] 
    #    air_loop_info[:thermal_zones] 
    #    air_loop_info[:total_floor_area_served]
    #    air_loop_info[:cooling_coils][:dx_single_speed]
    #    air_loop_info[:cooling_coils][:dx_two_speed]
    #    air_loop_info[:supply_fan][:max_air_flow_rate]
    #    
    #    air_loop_info[:heating_coils][:coil_heating_gas][:nominal_capacity]
    #    air_loop_info[:heating_coils][:coil_heating_electric][:nominal_capacity]
    #    air_loop_info[:heating_coils][:coil_heating_water][:nominal_capacity]
    #    
    #    air_loop_info[:economizer][:control_type]
    
    capacity = -1.0
    
    if !air_loop_info[:cooling_coils][:dx_single_speed][0].nil?
      puts "air_loop_info[:heating_coils][:coil_heating_gas][0][:nominal_capacity]"
      capacity = air_loop_info[:cooling_coils][:dx_single_speed][0][:nominal_total_capacity_w]
    elsif !air_loop_info[:cooling_coils][:dx_two_speed][0].nil?
      puts "capacity = air_loop_info[:heating_coils][:coil_heating_electric]"
      capacity = air_loop_info[:cooling_coils][:dx_two_speed][0][:cop_high]
    end
    puts capacity
    if capacity == -1.0
      #This should not happen
      puts "air_loop_info[:heating_coils] does not have a capacity or the type is not gas/electric/water for #{air_loop_info[:name]}"
    else
      #check for correct economizer usage
      puts "air_loop_info[:supply_fan][:max_air_flow_rate]: #{air_loop_info[:supply_fan][:max_air_flow_rate]}"
      unless air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s] == -1.0
        #capacity should be in kW
        if capacity > 20000 or air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s]*1000 >1500
          #diff enth
          #puts "diff"
          necb_section_test( 
            qaqc,
            "DifferentialEnthalpy",
            '==',
            air_loop_info[:economizer][:control_type],
            necb_section_name,
            "[AIR LOOP][#{air_loop_info[:name]}][:economizer][:control_type]"
          )
        else
          #no economizer
          #puts "no econ"
          necb_section_test( 
            qaqc,
            'NoEconomizer',
            '==',
            air_loop_info[:economizer][:control_type],
            necb_section_name,
            "[AIR LOOP][#{air_loop_info[:name]}][:economizer][:control_type]"
          )
        end
      end
    end
  end
  
  #*TODO*
  necb_section_name = "NECB2011-5.2.10.1"
  qaqc[:air_loops].each do |air_loop_info|
    unless air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s] == -1.0
      hrv_calc = 0.00123*air_loop_info[:outdoor_air_L_per_s]*(21-BTAP::Environment::WeatherFile.new( model.getWeatherFile.path.get.to_s ).db990) #=AP46*(21-O$1)
      hrv_reqd = hrv_calc > 150 ? true : false
      #qaqc[:information] << "[Info][TEST-PASS][#{necb_section_name}]:#{test_text} result value:#{result_value} #{bool_operator} expected value:#{expected_value}"
      hrv_present = false
      unless air_loop_info[:heat_exchanger].empty?
        hrv_present = true
      end
      necb_section_test( 
        qaqc,
        hrv_reqd,
        '==',
        hrv_present,
        necb_section_name,
        "[AIR LOOP][:heat_exchanger] for [#{air_loop_info[:name]}] is present?"
      )
      
    end
  end
  
  necb_section_name = "NECB2011-5.2.3.3"
  qaqc[:air_loops].each do |air_loop_info|
    #necb_clg_cop = air_loop_info[:cooling_coils][:dx_single_speed][:cop] #*assuming that the cop is defined correctly*
    if air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s].nil?
      qaqc[:ruby_warnings] << "air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s] is nil"
      next
    end
    necb_supply_fan_w = (air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s]*1000*1.6).round(2)

    if air_loop_info[:name].include? "PSZ"
      necb_supply_fan_w = (air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s]*1000*1.6).round(2)
    elsif air_loop_info[:name].include? "VAV"
      necb_supply_fan_w = (air_loop_info[:supply_fan][:max_air_flow_rate_m3_per_s]*1000*2.65).round(2)
    end

    if air_loop_info[:supply_fan][:rated_electric_power_w].nil?
      qaqc[:ruby_warnings] << "air_loop_info[:supply_fan][:rated_electric_power_w] is nil"
      next
    end

    supply_fan_w = (air_loop_info[:supply_fan][:rated_electric_power_w]).round(3)
    absolute_diff = (necb_supply_fan_w - supply_fan_w).to_f.abs
    if absolute_diff < 10
      #This case should ALWAYS PASS
      necb_section_test(
        qaqc,
        10,
        '>=',
        absolute_diff,
        necb_section_name,
        "[AIR LOOP][#{air_loop_info[:name]}][:supply_fan][:rated_electric_power_w] [#{supply_fan_w}] Absolute Difference from NECB value [#{necb_supply_fan_w}]"
      )
      next
    else
      #The test should pass if and only if the percent difference is less than 10%
      percent_diff = ((necb_supply_fan_w - supply_fan_w).to_f.abs/necb_supply_fan_w * 100).round(3)
      necb_section_test( 
        qaqc,
        10,
        '>=',
        percent_diff,
        necb_section_name,
        "[AIR LOOP][#{air_loop_info[:name]}][:supply_fan][:rated_electric_power_w] [#{supply_fan_w}] Percent Diff from NECB value [#{necb_supply_fan_w}]"
      )
    end
  end
  
  necb_section_name = "SANITY-??"
  qaqc[:plant_loops].each do |plant_loop_info|  
    pump_head = plant_loop_info[:pumps][0][:head_pa]
    flow_rate = plant_loop_info[:pumps][0][:water_flow_m3_per_s]*1000
    hp_check = ((flow_rate*60*60)/1000*1000*9.81*pump_head*0.000101997)/3600000
    puts "\npump_head #{pump_head}"
    puts "name: #{qaqc[:building][:name]}"
    puts "name: #{plant_loop_info[:name]}"
    puts "flow_rate #{flow_rate}"
    puts "hp_check #{hp_check}\n"
    pump_power_hp = plant_loop_info[:pumps][0][:electric_power_w]/1000*0.746
    percent_diff = (hp_check - pump_power_hp).to_f.abs/hp_check * 100
    
    if percent_diff.nan?
      qaqc[:ruby_warnings] << "(hp_check - pump_power_hp).to_f.abs/hp_check * 100 for #{plant_loop_info[:name]} is NaN"
      next
    end
    
    necb_section_test( 
      qaqc,
      20, #diff of 20%
      '>=',
      percent_diff,
      necb_section_name,
      "[PLANT LOOP][#{plant_loop_info[:name]}][:pumps][0][:electric_power_hp] [#{pump_power_hp}] Percent Diff from NECB value [#{hp_check}]"
    )
    
  end
end

#necb_section_test(qaqc, result_value, bool_operator, expected_value, necb_section_name, test_text, tolerance = nil) ⇒ Object



695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/openstudio-standards/btap/btap_result.rb', line 695

def necb_section_test(qaqc,result_value,bool_operator,expected_value,necb_section_name,test_text,tolerance = nil)
  test = "eval_failed"
  command = ''
  if tolerance.is_a?(Integer)
    command = "#{result_value}.round(#{tolerance}) #{bool_operator} #{expected_value}.round(#{tolerance})"
  elsif expected_value.is_a?(String) and result_value.is_a?(String)
    command = "'#{result_value}' #{bool_operator} '#{expected_value}'"
  else
    command = "#{result_value} #{bool_operator} #{expected_value}"
  end
  test = eval(command)
  test == 'true' ? true :false
  raise ("Eval command failed #{test}") if !!test != test 
  if test
    qaqc[:information] << "[Info][TEST-PASS][#{necb_section_name}]:#{test_text} result value:#{result_value} #{bool_operator} expected value:#{expected_value}"
  else
    qaqc[:errors] << "[ERROR][TEST-FAIL][#{necb_section_name}]:#{test_text} expected value:#{expected_value} #{bool_operator} result value:#{result_value}"
    unless (expected_value == -1.0 or expected_value == 'N/A')
      qaqc[:unique_errors] << "[ERROR][TEST-FAIL][#{necb_section_name}]:#{test_text} expected value:#{expected_value} #{bool_operator} result value:#{result_value}"
    end
  end
end

#remove_meta_class_fileObject



614
615
616
617
# File 'lib/openstudio-standards/prototypes/common/prototype_metaprogramming.rb', line 614

def remove_meta_class_file
  filepath = "#{File.dirname(__FILE__)}/do_not_edit_metaclasses.rb"
  FileUtils.rm(filepath)
end

#reset_logObject



109
110
111
# File 'lib/openstudio-standards/utilities/logging.rb', line 109

def reset_log
  $OPENSTUDIO_LOG.resetStringStream # rubocop:disable Style/GlobalVars
end

#sanity_check(qaqc) ⇒ Object



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
# File 'lib/openstudio-standards/btap/btap_result.rb', line 743

def sanity_check(qaqc)
  qaqc[:sanity_check] = {}
  qaqc[:sanity_check][:fail] = []
  qaqc[:sanity_check][:pass] = []
  #Padmassun's code for isConditioned start
  qaqc[:thermal_zones].each do |zoneinfo|
    zoneinfo[:spaces].each do |space|
      #skip plenums and undefined spaces/zones
      if zoneinfo[:name].to_s.include?"- undefined -"
        next
      end
      if zoneinfo[:space_type_name].to_s.include?"Space Function - undefined -"
        if zoneinfo[:is_conditioned].to_s == "No"
          qaqc[:sanity_check][:pass] << "[TEST-PASS][SANITY_CHECK-PASS] for [SPACE][#{space[:name]}] and [THERMAL ZONE] [#{zoneinfo[:name]}] where isConditioned is supposed to be [""No""] and found as #{zoneinfo[:is_conditioned]}"
        else
          qaqc[:sanity_check][:fail] << "[ERROR][SANITY_CHECK-FAIL] for [SPACE][#{space[:name]}] and [THERMAL ZONE] [#{zoneinfo[:name]}] where isConditioned is supposed to be [""No""] but found as #{zoneinfo[:is_conditioned]}"
        end
      else
        if zoneinfo[:is_conditioned].to_s == "Yes"
          qaqc[:sanity_check][:pass] << "[TEST-PASS][SANITY_CHECK-PASS] for [SPACE][#{space[:name]}] and [THERMAL ZONE] [#{zoneinfo[:name]}] where isConditioned is supposed to be [""Yes""] and found as #{zoneinfo[:is_conditioned]}"
        elsif zoneinfo[:name]
          qaqc[:sanity_check][:fail] << "[ERROR][SANITY_CHECK-FAIL] for [SPACE][#{space[:name]}] and [THERMAL ZONE] [#{zoneinfo[:name]}] where isConditioned is supposed to be [""Yes""] but found as #{zoneinfo[:is_conditioned]}"
        end          
      end
    end
  end	
  qaqc[:sanity_check][:fail] = qaqc[:sanity_check][:fail].sort
  qaqc[:sanity_check][:pass] = qaqc[:sanity_check][:pass].sort
  #Padmassun's code for isConditioned end
end

#save_meta_classes_to_fileObject



609
610
611
612
# File 'lib/openstudio-standards/prototypes/common/prototype_metaprogramming.rb', line 609

def save_meta_classes_to_file
  filepath = "#{File.dirname(__FILE__)}/do_not_edit_metaclasses.rb"
  File.open(filepath, 'w') {|f| create_class_array.each {|item| f << item}}
end

#validate_optional(var, model, return_value = "N/A") ⇒ Object



654
655
656
657
658
659
660
# File 'lib/openstudio-standards/btap/btap_result.rb', line 654

def validate_optional (var, model, return_value = "N/A")
  if var.empty?
    return return_value
  else
    return var.get
  end
end