-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathoutput.rb
More file actions
1965 lines (1742 loc) · 102 KB
/
output.rb
File metadata and controls
1965 lines (1742 loc) · 102 KB
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
# frozen_string_literal: true
# Collection of methods related to output reporting or writing output files.
module Outputs
MeterCustomElectricityTotal = 'Electricity:Total'
MeterCustomElectricityNet = 'Electricity:Net'
MeterCustomElectricityPV = 'Electricity:PV'
MeterCustomElectricityCritical = 'Electricity:Critical'
MeterCustomElectricityNetCritical = 'Electricity:NetCritical'
FT_to_HPXML_fuel_map = {
FT::Elec => HPXML::FuelTypeElectricity,
FT::Gas => HPXML::FuelTypeNaturalGas,
FT::Oil => HPXML::FuelTypeOil,
FT::Propane => HPXML::FuelTypePropane,
FT::WoodCord => HPXML::FuelTypeWoodCord,
FT::WoodPellets => HPXML::FuelTypeWoodPellets,
FT::Coal => HPXML::FuelTypeCoal
}
FT_to_EPlus_fuel_map = {
FT::Elec => EPlus::FuelTypeElectricity,
FT::Gas => EPlus::FuelTypeNaturalGas,
FT::Oil => EPlus::FuelTypeOil,
FT::Propane => EPlus::FuelTypePropane,
FT::WoodCord => EPlus::FuelTypeWoodCord,
FT::WoodPellets => EPlus::FuelTypeWoodPellets,
FT::Coal => EPlus::FuelTypeCoal
}
# Add EMS programs for output reporting. In the case where a whole SFA/MF building is
# being simulated, these programs are added to the whole building (merged) model, not
# the individual dwelling unit models.
#
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param hpxml_osm_map [Hash] Map of HPXML::Building objects => OpenStudio Model objects for each dwelling unit
# @param hpxml_header [HPXML::Header] HPXML Header object (one per HPXML file)
# @param add_component_loads [Boolean] Whether to calculate component loads (since it incurs a runtime speed penalty)
# @return [nil]
def self.apply_ems_programs(model, hpxml_osm_map, hpxml_header, add_component_loads)
season_day_nums = apply_unmet_hours_ems_program(model, hpxml_osm_map, hpxml_header)
apply_unmet_driving_hours_ems_program(model, hpxml_osm_map)
loads_data = apply_total_loads_ems_program(model, hpxml_osm_map, hpxml_header)
if add_component_loads
apply_component_loads_ems_program(model, hpxml_osm_map, loads_data, season_day_nums)
end
apply_total_airflows_ems_program(model, hpxml_osm_map)
end
# Creates an EMS program that calculates heating and cooling unmet hours (number
# of hours where the heating or cooling setpoint is not maintained).
#
# Note: We do our own unmet hours calculation via EMS so that we can incorporate,
# e.g., heating/cooling seasons into the logic. The calculation layers on top
# of the built-in EnergyPlus unmet hours output.
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param hpxml_osm_map [Hash] Map of HPXML::Building objects => OpenStudio Model objects for each dwelling unit
# @param hpxml_header [HPXML::Header] HPXML Header object (one per HPXML file)
# @return [Hash] Mapping of unit index => heating/cooling season begin and end dates for use by subsequent programs
def self.apply_unmet_hours_ems_program(model, hpxml_osm_map, hpxml_header)
# Create sensors and gather data
htg_sensors, clg_sensors = {}, {}
zone_air_temp_sensors, htg_spt_sensors, clg_spt_sensors = {}, {}, {}
total_heat_load_serveds, total_cool_load_serveds = {}, {}
season_day_nums = {}
onoff_deadbands = hpxml_header.hvac_onoff_thermostat_deadband.to_f
hpxml_osm_map.each_with_index do |(hpxml_bldg, unit_model), unit|
conditioned_zone = unit_model.getThermalZones.find { |z| z.additionalProperties.getFeatureAsString('ObjectType').to_s == HPXML::LocationConditionedSpace }
conditioned_zone_name = conditioned_zone.name.to_s
# EMS sensors
htg_sensors[unit] = Model.add_ems_sensor(
model,
name: "#{conditioned_zone_name} htg unmet s",
output_var_or_meter_name: 'Zone Heating Setpoint Not Met Time',
key_name: conditioned_zone_name
)
clg_sensors[unit] = Model.add_ems_sensor(
model,
name: "#{conditioned_zone_name} clg unmet s",
output_var_or_meter_name: 'Zone Cooling Setpoint Not Met Time',
key_name: conditioned_zone_name
)
total_heat_load_serveds[unit] = hpxml_bldg.total_fraction_heat_load_served
total_cool_load_serveds[unit] = hpxml_bldg.total_fraction_cool_load_served
hvac_control = hpxml_bldg.hvac_controls[0]
next if hvac_control.nil?
if (onoff_deadbands > 0)
zone_air_temp_sensors[unit] = Model.add_ems_sensor(
model,
name: "#{conditioned_zone_name} space temp",
output_var_or_meter_name: 'Zone Air Temperature',
key_name: conditioned_zone_name
)
htg_sch = conditioned_zone.thermostatSetpointDualSetpoint.get.heatingSetpointTemperatureSchedule.get
htg_spt_sensors[unit] = Model.add_ems_sensor(
model,
name: "#{htg_sch.name} sch value",
output_var_or_meter_name: 'Schedule Value',
key_name: htg_sch.name
)
clg_sch = conditioned_zone.thermostatSetpointDualSetpoint.get.coolingSetpointTemperatureSchedule.get
clg_spt_sensors[unit] = Model.add_ems_sensor(
model,
name: "#{clg_sch.name} sch value",
output_var_or_meter_name: 'Schedule Value',
key_name: clg_sch.name
)
end
sim_year = hpxml_header.sim_calendar_year
season_day_nums[unit] = {
htg_start: Calendar.get_day_num_from_month_day(sim_year, hvac_control.seasons_heating_begin_month, hvac_control.seasons_heating_begin_day),
htg_end: Calendar.get_day_num_from_month_day(sim_year, hvac_control.seasons_heating_end_month, hvac_control.seasons_heating_end_day),
clg_start: Calendar.get_day_num_from_month_day(sim_year, hvac_control.seasons_cooling_begin_month, hvac_control.seasons_cooling_begin_day),
clg_end: Calendar.get_day_num_from_month_day(sim_year, hvac_control.seasons_cooling_end_month, hvac_control.seasons_cooling_end_day)
}
end
htg_avail_sensor = model.getEnergyManagementSystemSensors.find { |s| s.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeHeatingAvailabilitySensor }
clg_avail_sensor = model.getEnergyManagementSystemSensors.find { |s| s.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeCoolingAvailabilitySensor }
htg_tol = model.getOutputControlReportingTolerances.toleranceforTimeHeatingSetpointNotMet
clg_tol = model.getOutputControlReportingTolerances.toleranceforTimeCoolingSetpointNotMet
# EMS program
clg_hrs = 'clg_unmet_hours'
htg_hrs = 'htg_unmet_hours'
unit_clg_hrs = 'unit_clg_unmet_hours'
unit_htg_hrs = 'unit_htg_unmet_hours'
program = Model.add_ems_program(
model,
name: 'unmet hours program'
)
program.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeUnmetHoursProgram)
program.addLine("Set #{htg_hrs} = 0")
program.addLine("Set #{clg_hrs} = 0")
for unit in 0..hpxml_osm_map.size - 1
if total_heat_load_serveds[unit] > 0
program.addLine("Set #{unit_htg_hrs} = 0")
if season_day_nums[unit][:htg_end] >= season_day_nums[unit][:htg_start]
line = "If ((DayOfYear >= #{season_day_nums[unit][:htg_start]}) && (DayOfYear <= #{season_day_nums[unit][:htg_end]}))"
else
line = "If ((DayOfYear >= #{season_day_nums[unit][:htg_start]}) || (DayOfYear <= #{season_day_nums[unit][:htg_end]}))"
end
line += " && (#{htg_avail_sensor.name} == 1)" if not htg_avail_sensor.nil?
program.addLine(line)
if zone_air_temp_sensors.keys.include? unit # on off deadband
program.addLine(" If #{zone_air_temp_sensors[unit].name} < (#{htg_spt_sensors[unit].name} - #{htg_tol})")
program.addLine(" Set #{unit_htg_hrs} = #{unit_htg_hrs} + #{htg_sensors[unit].name}")
program.addLine(' EndIf')
else
program.addLine(" Set #{unit_htg_hrs} = #{unit_htg_hrs} + #{htg_sensors[unit].name}")
end
program.addLine(" If #{unit_htg_hrs} > #{htg_hrs}") # Use max hourly value across all units
program.addLine(" Set #{htg_hrs} = #{unit_htg_hrs}")
program.addLine(' EndIf')
program.addLine('EndIf')
end
next unless total_cool_load_serveds[unit] > 0
program.addLine("Set #{unit_clg_hrs} = 0")
if season_day_nums[unit][:clg_end] >= season_day_nums[unit][:clg_start]
line = "If ((DayOfYear >= #{season_day_nums[unit][:clg_start]}) && (DayOfYear <= #{season_day_nums[unit][:clg_end]}))"
else
line = "If ((DayOfYear >= #{season_day_nums[unit][:clg_start]}) || (DayOfYear <= #{season_day_nums[unit][:clg_end]}))"
end
line += " && (#{clg_avail_sensor.name} == 1)" if not clg_avail_sensor.nil?
program.addLine(line)
if zone_air_temp_sensors.keys.include? unit # on off deadband
program.addLine(" If #{zone_air_temp_sensors[unit].name} > (#{clg_spt_sensors[unit].name} + #{clg_tol})")
program.addLine(" Set #{unit_clg_hrs} = #{unit_clg_hrs} + #{clg_sensors[unit].name}")
program.addLine(' EndIf')
else
program.addLine(" Set #{unit_clg_hrs} = #{unit_clg_hrs} + #{clg_sensors[unit].name}")
end
program.addLine(" If #{unit_clg_hrs} > #{clg_hrs}") # Use max hourly value across all units
program.addLine(" Set #{clg_hrs} = #{unit_clg_hrs}")
program.addLine(' EndIf')
program.addLine('EndIf')
end
# EMS calling manager
Model.add_ems_program_calling_manager(
model,
name: "#{program.name} calling manager",
calling_point: 'EndOfZoneTimestepBeforeZoneReporting',
ems_programs: [program]
)
return season_day_nums
end
# Creates an EMS program that calculates driving unmet hours (number
# of hours where the EV driving demand is not met).
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param hpxml_osm_map [Hash] Map of HPXML::Building objects => OpenStudio Model objects for each dwelling unit
# @return [nil]
def self.apply_unmet_driving_hours_ems_program(model, hpxml_osm_map)
return if hpxml_osm_map.keys.map { |hpxml_bldg| hpxml_bldg.vehicles.map { |vehicle| vehicle.vehicle_type == HPXML::VehicleTypeBEV && !vehicle.ev_charger_idref.nil? }.size }.sum == 0
# EMS program
driving_hrs = 'unmet_driving_hours'
unit_driving_hrs = 'unit_driving_unmet_hours'
program = Model.add_ems_program(
model,
name: 'unmet driving hours program'
)
program.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeVehicleUnmetHoursProgram)
program.addLine("Set #{driving_hrs} = 0")
hpxml_osm_map.each do |hpxml_bldg, unit_model|
vehicle = hpxml_bldg.vehicles.find { |vehicle| vehicle.vehicle_type == HPXML::VehicleTypeBEV && !vehicle.ev_charger_idref.nil? }
next if vehicle.nil?
ev_elcd = unit_model.getElectricLoadCenterDistributions.find { |elcd| elcd.name.to_s.include?(vehicle.id) }
discharge_sch_sensor = unit_model.getEnergyManagementSystemSensors.find { |s| s.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeVehicleDischargeScheduleSensor }
unit_model.getElectricLoadCenterStorageLiIonNMCBatterys.each do |elcs|
next unless elcs.name.to_s.include? vehicle.id
min_soc = ev_elcd.minimumStorageStateofChargeFraction
soc_sensor = Model.add_ems_sensor(
model,
name: "#{elcs.name} soc_sensor",
output_var_or_meter_name: 'Electric Storage Charge Fraction',
key_name: elcs.name.to_s
)
program.addLine(" If #{discharge_sch_sensor.name} > 0.0")
program.addLine(" If #{soc_sensor.name} <= #{min_soc}")
program.addLine(" Set #{unit_driving_hrs} = #{discharge_sch_sensor.name}")
program.addLine(' Else')
program.addLine(" Set #{unit_driving_hrs} = 0")
program.addLine(' EndIf')
program.addLine(' Else')
program.addLine(" Set #{unit_driving_hrs} = 0")
program.addLine(' EndIf')
program.addLine(" If #{unit_driving_hrs} > #{driving_hrs}") # Use max hourly value across all units
program.addLine(" Set #{driving_hrs} = #{unit_driving_hrs}")
program.addLine(' EndIf')
end
end
Model.add_ems_program_calling_manager(
model,
name: "#{program.name} calling manager",
calling_point: 'BeginTimestepBeforePredictor',
ems_programs: [program]
)
end
# Creates an EMS program that calculates total heating and cooling loads delivered
# by the HVAC system(s).
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param hpxml_osm_map [Hash] Map of HPXML::Building objects => OpenStudio Model objects for each dwelling unit
# @param hpxml_header [HPXML::Header] HPXML Header object (one per HPXML file)
# @return [Array] Misc collection of things for use in the component loads EMS program
def self.apply_total_loads_ems_program(model, hpxml_osm_map, hpxml_header)
# Create sensors and gather data
htg_cond_load_sensors, clg_cond_load_sensors = {}, {}
htg_duct_load_sensors, clg_duct_load_sensors = {}, {}
total_heat_load_serveds, total_cool_load_serveds = {}, {}
dehumidifier_global_vars, dehumidifier_sensors, defrost_load_oe_sensors = {}, {}, {}
unit_multipliers = {}
hpxml_osm_map.each_with_index do |(hpxml_bldg, unit_model), unit|
# Retrieve objects
conditioned_zone_name = unit_model.getThermalZones.find { |z| z.additionalProperties.getFeatureAsString('ObjectType').to_s == HPXML::LocationConditionedSpace }.name.to_s
duct_zone_names = unit_model.getThermalZones.select { |z| z.isPlenum }.map { |z| z.name.to_s }
dehumidifier = unit_model.getZoneHVACDehumidifierDXs
dehumidifier_name = dehumidifier[0].name.to_s unless dehumidifier.empty?
defrost_load_oes = unit_model.getOtherEquipments.select { |o| o.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeHPDefrostHeatLoad }
# Fraction heat/cool load served
if hpxml_header.apply_ashrae140_assumptions
total_heat_load_serveds[unit] = 1.0
total_cool_load_serveds[unit] = 1.0
else
total_heat_load_serveds[unit] = hpxml_bldg.total_fraction_heat_load_served
total_cool_load_serveds[unit] = hpxml_bldg.total_fraction_cool_load_served
end
# Energy transferred in conditioned zone, used for determining heating (winter) vs cooling (summer)
htg_cond_load_sensors[unit] = Model.add_ems_sensor(
model,
name: 'htg_load_cond',
output_var_or_meter_name: "Heating:EnergyTransfer:Zone:#{conditioned_zone_name.upcase}",
key_name: nil
)
clg_cond_load_sensors[unit] = Model.add_ems_sensor(
model,
name: 'clg_load_cond',
output_var_or_meter_name: "Cooling:EnergyTransfer:Zone:#{conditioned_zone_name.upcase}",
key_name: nil
)
# Energy transferred in duct zone(s)
htg_duct_load_sensors[unit] = []
clg_duct_load_sensors[unit] = []
duct_zone_names.each do |duct_zone_name|
htg_duct_load_sensors[unit] << Model.add_ems_sensor(
model,
name: 'htg_load_duct',
output_var_or_meter_name: "Heating:EnergyTransfer:Zone:#{duct_zone_name.upcase}",
key_name: nil
)
clg_duct_load_sensors[unit] << Model.add_ems_sensor(
model,
name: 'clg_load_duct',
output_var_or_meter_name: "Cooling:EnergyTransfer:Zone:#{duct_zone_name.upcase}",
key_name: nil
)
end
defrost_load_oe_sensors[unit] = []
defrost_load_oes.sort.each_with_index do |o, i|
defrost_load_oe_sensors[unit] << Model.add_ems_sensor(
model,
name: "ig_defrost_#{i}",
output_var_or_meter_name: 'Other Equipment Total Heating Energy',
key_name: o.name.to_s
)
end
unit_multipliers[unit] = hpxml_bldg.building_construction.number_of_units
next if dehumidifier_name.nil?
# Need to adjust E+ EnergyTransfer meters for dehumidifier internal gains.
# We also offset the dehumidifier load by one timestep so that it aligns with the EnergyTransfer meters.
# Global Variable
dehumidifier_global_vars[unit] = Model.add_ems_global_var(
model,
var_name: "prev #{dehumidifier_name}"
)
# Initialization Program
timestep_offset_program = Model.add_ems_program(
model,
name: "#{dehumidifier_name} timestep offset init program"
)
timestep_offset_program.addLine("Set #{dehumidifier_global_vars[unit].name} = 0")
# calling managers
Model.add_ems_program_calling_manager(
model,
name: "#{timestep_offset_program.name} calling manager",
calling_point: 'BeginNewEnvironment',
ems_programs: [timestep_offset_program]
)
Model.add_ems_program_calling_manager(
model,
name: "#{timestep_offset_program.name} calling manager2",
calling_point: 'AfterNewEnvironmentWarmUpIsComplete',
ems_programs: [timestep_offset_program]
)
dehumidifier_sensors[unit] = Model.add_ems_sensor(
model,
name: 'ig_dehumidifier',
output_var_or_meter_name: 'Zone Dehumidifier Sensible Heating Energy',
key_name: dehumidifier_name
)
end
# EMS program
program = Model.add_ems_program(
model,
name: 'total loads program'
)
program.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeTotalLoadsProgram)
program.addLine('Set loads_htg_tot = 0')
program.addLine('Set loads_clg_tot = 0')
for unit in 0..hpxml_osm_map.size - 1
program.addLine("If #{htg_cond_load_sensors[unit].name} > 0")
program.addLine(" Set loads_htg_tot = loads_htg_tot + (#{htg_cond_load_sensors[unit].name} - #{clg_cond_load_sensors[unit].name}) * #{total_heat_load_serveds[unit]}")
for i in 0..htg_duct_load_sensors[unit].size - 1
program.addLine(" Set loads_htg_tot = loads_htg_tot + (#{htg_duct_load_sensors[unit][i].name} - #{clg_duct_load_sensors[unit][i].name}) * #{total_heat_load_serveds[unit]}")
end
if not dehumidifier_global_vars[unit].nil?
program.addLine(" Set loads_htg_tot = loads_htg_tot - #{dehumidifier_global_vars[unit].name}")
end
defrost_load_oe_sensors[unit].each do |defrost_ss|
program.addLine(" Set loads_htg_tot = loads_htg_tot + #{defrost_ss.name} * #{unit_multipliers[unit]}")
end
program.addLine('EndIf')
end
program.addLine('Set loads_htg_tot = (@Max loads_htg_tot 0)')
for unit in 0..hpxml_osm_map.size - 1
program.addLine("If #{clg_cond_load_sensors[unit].name} > 0")
program.addLine(" Set loads_clg_tot = loads_clg_tot + (#{clg_cond_load_sensors[unit].name} - #{htg_cond_load_sensors[unit].name}) * #{total_cool_load_serveds[unit]}")
for i in 0..clg_duct_load_sensors[unit].size - 1
program.addLine(" Set loads_clg_tot = loads_clg_tot + (#{clg_duct_load_sensors[unit][i].name} - #{htg_duct_load_sensors[unit][i].name}) * #{total_cool_load_serveds[unit]}")
end
if not dehumidifier_global_vars[unit].nil?
program.addLine(" Set loads_clg_tot = loads_clg_tot + #{dehumidifier_global_vars[unit].name}")
end
program.addLine('EndIf')
end
program.addLine('Set loads_clg_tot = (@Max loads_clg_tot 0)')
for unit in 0..hpxml_osm_map.size - 1
if not dehumidifier_global_vars[unit].nil?
# Store dehumidifier internal gain, will be used in EMS program next timestep
program.addLine("Set #{dehumidifier_global_vars[unit].name} = #{dehumidifier_sensors[unit].name}")
end
end
# EMS calling manager
Model.add_ems_program_calling_manager(
model,
name: "#{program.name} calling manager",
calling_point: 'EndOfZoneTimestepAfterZoneReporting',
ems_programs: [program]
)
loads_data = [htg_cond_load_sensors, clg_cond_load_sensors, total_heat_load_serveds, total_cool_load_serveds, dehumidifier_sensors]
return loads_data
end
# Creates an EMS program that calculates component heating and cooling loads (e.g., loads
# attributes to walls, windows, infiltration, ducts, internal gains, etc.).
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param hpxml_osm_map [Hash] Map of HPXML::Building objects => OpenStudio Model objects for each dwelling unit
# @param loads_data [Array] Misc collection of things from the total loads EMS program
# @param season_day_nums [Hash] Mapping of unit index => heating/cooling season begin and end dates
# @return [nil]
def self.apply_component_loads_ems_program(model, hpxml_osm_map, loads_data, season_day_nums)
htg_cond_load_sensors, clg_cond_load_sensors, total_heat_load_serveds, total_cool_load_serveds, dehumidifier_sensors = loads_data
# Output diagnostics needed for some output variables used below
output_diagnostics = model.getOutputDiagnostics
output_diagnostics.addKey('DisplayAdvancedReportVariables')
area_tolerance = UnitConversions.convert(1.0, 'ft^2', 'm^2')
nonsurf_names = ['intgains', 'lighting', 'infil', 'mechvent', 'natvent', 'whf', 'ducts']
surf_names = ['walls', 'rim_joists', 'foundation_walls', 'floors', 'slabs', 'ceilings',
'roofs', 'windows_conduction', 'windows_solar', 'doors', 'skylights_conduction',
'skylights_solar', 'internal_mass']
# EMS program
program = Model.add_ems_program(
model,
name: 'component loads program'
)
program.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeComponentLoadsProgram)
# Initialize
[:htg, :clg].each do |mode|
surf_names.each do |surf_name|
program.addLine("Set loads_#{mode}_#{surf_name} = 0")
end
nonsurf_names.each do |nonsurf_name|
program.addLine("Set loads_#{mode}_#{nonsurf_name} = 0")
end
end
hpxml_osm_map.each_with_index do |(hpxml_bldg, unit_model), unit|
conditioned_zone = unit_model.getThermalZones.find { |z| z.additionalProperties.getFeatureAsString('ObjectType').to_s == HPXML::LocationConditionedSpace }
# Prevent certain objects (e.g., OtherEquipment) from being counted towards both, e.g., ducts and internal gains
objects_already_processed = []
# EMS Sensors: Surfaces, SubSurfaces, InternalMass
surfaces_sensors = {}
surf_names.each do |surf_name|
surfaces_sensors[surf_name.to_sym] = []
end
unit_model.getSurfaces.sort.each do |s|
next unless s.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
surface_type = s.additionalProperties.getFeatureAsString('SurfaceType')
if not surface_type.is_initialized
fail "Could not identify surface type for surface: '#{s.name}'."
end
surface_type = surface_type.get
s.subSurfaces.each do |ss|
# Conduction (windows, skylights, doors)
key = { 'Window' => :windows_conduction,
'Door' => :doors,
'Skylight' => :skylights_conduction }[surface_type]
fail "Unexpected subsurface for component loads: '#{ss.name}'." if key.nil?
if (surface_type == 'Window') || (surface_type == 'Skylight')
vars = { 'Surface Inside Face Convection Heat Gain Energy' => 'ss_conv',
'Surface Inside Face Internal Gains Radiation Heat Gain Energy' => 'ss_ig',
'Surface Inside Face Net Surface Thermal Radiation Heat Gain Energy' => 'ss_surf' }
else
vars = { 'Surface Inside Face Solar Radiation Heat Gain Energy' => 'ss_sol',
'Surface Inside Face Lights Radiation Heat Gain Energy' => 'ss_lgt',
'Surface Inside Face Convection Heat Gain Energy' => 'ss_conv',
'Surface Inside Face Internal Gains Radiation Heat Gain Energy' => 'ss_ig',
'Surface Inside Face Net Surface Thermal Radiation Heat Gain Energy' => 'ss_surf' }
end
vars.each do |var, name|
surfaces_sensors[key] << []
surfaces_sensors[key][-1] << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: ss.name
)
end
# Solar (windows, skylights)
next unless (surface_type == 'Window') || (surface_type == 'Skylight')
key = { 'Window' => :windows_solar,
'Skylight' => :skylights_solar }[surface_type]
vars = { 'Surface Window Transmitted Solar Radiation Rate' => 'ss_trans_in',
'Surface Window Shortwave from Zone Back Out Window Heat Transfer Rate' => 'ss_back_out',
'Surface Inside Face Initial Transmitted Diffuse Transmitted Out Window Solar Radiation Rate' => 'ss_trans_out' }
surfaces_sensors[key] << []
vars.each do |var, name|
surfaces_sensors[key][-1] << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: ss.name
)
end
end
next if s.netArea < area_tolerance # Skip parent surfaces (of subsurfaces) that have near zero net area
key = { 'FoundationWall' => :foundation_walls,
'RimJoist' => :rim_joists,
'Wall' => :walls,
'Slab' => :slabs,
'Floor' => :floors,
'Ceiling' => :ceilings,
'Roof' => :roofs,
'Skylight' => :skylights_conduction, # Skylight curb/shaft
'InferredCeiling' => :internal_mass,
'InferredFloor' => :internal_mass }[surface_type]
fail "Unexpected surface for component loads: '#{s.name}'." if key.nil?
surfaces_sensors[key] << []
{ 'Surface Inside Face Convection Heat Gain Energy' => 's_conv',
'Surface Inside Face Internal Gains Radiation Heat Gain Energy' => 's_ig',
'Surface Inside Face Solar Radiation Heat Gain Energy' => 's_sol',
'Surface Inside Face Lights Radiation Heat Gain Energy' => 's_lgt',
'Surface Inside Face Net Surface Thermal Radiation Heat Gain Energy' => 's_surf' }.each do |var, name|
surfaces_sensors[key][-1] << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: s.name
)
end
end
unit_model.getInternalMasss.sort.each do |m|
next unless m.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
surfaces_sensors[:internal_mass] << []
{ 'Surface Inside Face Convection Heat Gain Energy' => 'im_conv',
'Surface Inside Face Internal Gains Radiation Heat Gain Energy' => 'im_ig',
'Surface Inside Face Solar Radiation Heat Gain Energy' => 'im_sol',
'Surface Inside Face Lights Radiation Heat Gain Energy' => 'im_lgt',
'Surface Inside Face Net Surface Thermal Radiation Heat Gain Energy' => 'im_surf' }.each do |var, name|
surfaces_sensors[:internal_mass][-1] << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: m.name
)
end
end
# EMS Sensors: Infiltration, Natural Ventilation, Whole House Fan
infil_sensors, natvent_sensors, whf_sensors = [], [], []
unit_model.getSpaceInfiltrationDesignFlowRates.sort.each do |i|
next unless i.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
object_type = i.additionalProperties.getFeatureAsString('ObjectType').get
{ 'Infiltration Sensible Heat Gain Energy' => 'airflow_gain',
'Infiltration Sensible Heat Loss Energy' => 'airflow_loss' }.each do |var, name|
airflow_sensor = Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: i.name
)
if object_type == Constants::ObjectTypeInfiltration
infil_sensors << airflow_sensor
elsif object_type == Constants::ObjectTypeNaturalVentilation
natvent_sensors << airflow_sensor
elsif object_type == Constants::ObjectTypeWholeHouseFan
whf_sensors << airflow_sensor
end
end
end
# EMS Sensors: Mechanical Ventilation
mechvents_sensors = []
unit_model.getElectricEquipments.sort.each do |o|
next unless o.endUseSubcategory == Constants::ObjectTypeMechanicalVentilation
objects_already_processed << o
{ 'Electric Equipment Convective Heating Energy' => 'mv_conv',
'Electric Equipment Radiant Heating Energy' => 'mv_rad' }.each do |var, name|
mechvents_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: o.name
)
end
end
unit_model.getOtherEquipments.sort.each do |o|
next unless o.endUseSubcategory == Constants::ObjectTypeMechanicalVentilationHouseFan
objects_already_processed << o
{ 'Other Equipment Convective Heating Energy' => 'mv_conv',
'Other Equipment Radiant Heating Energy' => 'mv_rad' }.each do |var, name|
mechvents_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: o.name
)
end
end
# EMS Sensors: Ducts
ducts_sensors = []
ducts_mix_gain_sensor = nil
ducts_mix_loss_sensor = nil
conditioned_zone.zoneMixing.each do |zone_mix|
object_type = zone_mix.additionalProperties.getFeatureAsString('ObjectType').to_s
next unless object_type == Constants::ObjectTypeDuctLoad
ducts_mix_gain_sensor = Model.add_ems_sensor(
model,
name: 'duct_mix_gain',
output_var_or_meter_name: 'Zone Mixing Sensible Heat Gain Energy',
key_name: conditioned_zone.name
)
ducts_mix_loss_sensor = Model.add_ems_sensor(
model,
name: 'duct_mix_loss',
output_var_or_meter_name: 'Zone Mixing Sensible Heat Loss Energy',
key_name: conditioned_zone.name
)
end
unit_model.getOtherEquipments.sort.each do |o|
next if objects_already_processed.include? o
next unless o.endUseSubcategory == Constants::ObjectTypeDuctLoad
objects_already_processed << o
{ 'Other Equipment Convective Heating Energy' => 'ducts_conv',
'Other Equipment Radiant Heating Energy' => 'ducts_rad' }.each do |var, name|
ducts_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: o.name
)
end
end
# EMS Sensors: Lighting
lightings_sensors = []
unit_model.getLightss.sort.each do |e|
next unless e.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
{ 'Lights Convective Heating Energy' => 'ig_lgt_conv',
'Lights Radiant Heating Energy' => 'ig_lgt_rad',
'Lights Visible Radiation Heating Energy' => 'ig_lgt_vis' }.each do |var, name|
lightings_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: e.name
)
end
end
# EMS Sensors: Internal Gains
intgains_sensors = []
unit_model.getElectricEquipments.sort.each do |o|
next if objects_already_processed.include? o
next unless o.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
{ 'Electric Equipment Convective Heating Energy' => 'ig_ee_conv',
'Electric Equipment Radiant Heating Energy' => 'ig_ee_rad' }.each do |var, name|
intgains_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: o.name
)
end
end
unit_model.getOtherEquipments.sort.each do |o|
next if objects_already_processed.include? o
next unless o.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
{ 'Other Equipment Convective Heating Energy' => 'ig_oe_conv',
'Other Equipment Radiant Heating Energy' => 'ig_oe_rad' }.each do |var, name|
intgains_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: o.name
)
end
end
unit_model.getPeoples.sort.each do |e|
next unless e.space.get.thermalZone.get.name.to_s == conditioned_zone.name.to_s
{ 'People Convective Heating Energy' => 'ig_ppl_conv',
'People Radiant Heating Energy' => 'ig_ppl_rad' }.each do |var, name|
intgains_sensors << Model.add_ems_sensor(
model,
name: name,
output_var_or_meter_name: var,
key_name: e.name
)
end
end
if not dehumidifier_sensors[unit].nil?
intgains_sensors << dehumidifier_sensors[unit]
end
intgains_dhw_sensors = {}
(unit_model.getWaterHeaterMixeds + unit_model.getWaterHeaterStratifieds).sort.each do |wh|
next unless wh.ambientTemperatureThermalZone.is_initialized
next unless wh.ambientTemperatureThermalZone.get.name.to_s == conditioned_zone.name.to_s
dhw_sensor = Model.add_ems_sensor(
model,
name: 'dhw_loss',
output_var_or_meter_name: 'Water Heater Heat Loss Energy',
key_name: wh.name
)
if wh.is_a? OpenStudio::Model::WaterHeaterMixed
oncycle_loss = wh.onCycleLossFractiontoThermalZone
offcycle_loss = wh.offCycleLossFractiontoThermalZone
else
oncycle_loss = wh.skinLossFractiontoZone
offcycle_loss = wh.offCycleFlueLossFractiontoZone
end
dhw_rtf_sensor = Model.add_ems_sensor(
model,
name: 'dhw_rtf',
output_var_or_meter_name: 'Water Heater Runtime Fraction',
key_name: wh.name
)
intgains_dhw_sensors[dhw_sensor] = [offcycle_loss, oncycle_loss, dhw_rtf_sensor]
end
# EMS program: Surfaces
surfaces_sensors.each do |k, surface_sensors|
program.addLine("Set hr_#{k} = 0")
surface_sensors.each do |sensors|
s = "Set hr_#{k} = hr_#{k}"
sensors.each do |sensor|
if sensor.name.to_s.start_with?('ss_trans_in', 'ss_infra', 'ss_glaz')
s += " - #{sensor.name} * ZoneTimestep * 3600"
elsif sensor.name.to_s.start_with?('ss_trans_out', 'ss_back_out')
s += " + #{sensor.name} * ZoneTimestep * 3600"
else
s += " + #{sensor.name}"
end
end
program.addLine(s) if sensors.size > 0
end
end
# EMS program: Internal Gains, Lighting, Infiltration, Natural Ventilation, Mechanical Ventilation, Ducts
{ 'intgains' => intgains_sensors,
'lighting' => lightings_sensors,
'infil' => infil_sensors,
'natvent' => natvent_sensors,
'whf' => whf_sensors,
'mechvent' => mechvents_sensors,
'ducts' => ducts_sensors }.each do |loadtype, sensors|
program.addLine("Set hr_#{loadtype} = 0")
next if sensors.empty?
s = "Set hr_#{loadtype} = hr_#{loadtype}"
sensors.each do |sensor|
if ['intgains', 'lighting', 'mechvent', 'ducts'].include? loadtype
s += " - #{sensor.name}"
elsif sensor.name.to_s.include? 'gain'
s += " - #{sensor.name}"
elsif sensor.name.to_s.include? 'loss'
s += " + #{sensor.name}"
end
end
program.addLine(s)
end
intgains_dhw_sensors.each do |sensor, vals|
off_loss, on_loss, rtf_sensor = vals
program.addLine("Set hr_intgains = hr_intgains + #{sensor.name} * (#{off_loss}*(1-#{rtf_sensor.name}) + #{on_loss}*#{rtf_sensor.name})") # Water heater tank losses to zone
end
if (not ducts_mix_loss_sensor.nil?) && (not ducts_mix_gain_sensor.nil?)
program.addLine("Set hr_ducts = hr_ducts + (#{ducts_mix_loss_sensor.name} - #{ducts_mix_gain_sensor.name})")
end
# EMS Sensors: Indoor temperature, setpoints
tin_sensor = Model.add_ems_sensor(
model,
name: 'tin s',
output_var_or_meter_name: 'Zone Mean Air Temperature',
key_name: conditioned_zone.name
)
thermostat = nil
if conditioned_zone.thermostatSetpointDualSetpoint.is_initialized
thermostat = conditioned_zone.thermostatSetpointDualSetpoint.get
htg_sp_sensor = Model.add_ems_sensor(
model,
name: 'htg sp s',
output_var_or_meter_name: 'Schedule Value',
key_name: thermostat.heatingSetpointTemperatureSchedule.get.name
)
clg_sp_sensor = Model.add_ems_sensor(
model,
name: 'clg sp s',
output_var_or_meter_name: 'Schedule Value',
key_name: thermostat.coolingSetpointTemperatureSchedule.get.name
)
end
# EMS program: Heating vs Cooling logic
program.addLine('Set htg_mode = 0')
program.addLine('Set clg_mode = 0')
program.addLine("If (#{htg_cond_load_sensors[unit].name} > 0)") # Assign hour to heating if heating load
program.addLine(" Set htg_mode = #{total_heat_load_serveds[unit]}")
program.addLine("ElseIf (#{clg_cond_load_sensors[unit].name} > 0)") # Assign hour to cooling if cooling load
program.addLine(" Set clg_mode = #{total_cool_load_serveds[unit]}")
program.addLine('Else')
program.addLine(' Set htg_season = 0')
program.addLine(' Set clg_season = 0')
if not season_day_nums[unit].nil?
# Determine whether we're in the heating and/or cooling season
if season_day_nums[unit][:clg_end] >= season_day_nums[unit][:clg_start]
program.addLine(" If ((DayOfYear >= #{season_day_nums[unit][:clg_start]}) && (DayOfYear <= #{season_day_nums[unit][:clg_end]}))")
else
program.addLine(" If ((DayOfYear >= #{season_day_nums[unit][:clg_start]}) || (DayOfYear <= #{season_day_nums[unit][:clg_end]}))")
end
program.addLine(' Set clg_season = 1')
program.addLine(' EndIf')
if season_day_nums[unit][:htg_end] >= season_day_nums[unit][:htg_start]
program.addLine(" If ((DayOfYear >= #{season_day_nums[unit][:htg_start]}) && (DayOfYear <= #{season_day_nums[unit][:htg_end]}))")
else
program.addLine(" If ((DayOfYear >= #{season_day_nums[unit][:htg_start]}) || (DayOfYear <= #{season_day_nums[unit][:htg_end]}))")
end
program.addLine(' Set htg_season = 1')
program.addLine(' EndIf')
end
program.addLine(" If ((#{natvent_sensors[0].name} <> 0) || (#{natvent_sensors[1].name} <> 0)) && (clg_season == 1)") # Assign hour to cooling if natural ventilation is operating
program.addLine(" Set clg_mode = #{total_cool_load_serveds[unit]}")
program.addLine(" ElseIf ((#{whf_sensors[0].name} <> 0) || (#{whf_sensors[1].name} <> 0)) && (clg_season == 1)") # Assign hour to cooling if whole house fan is operating
program.addLine(" Set clg_mode = #{total_cool_load_serveds[unit]}")
if not thermostat.nil?
program.addLine(' Else') # Indoor temperature floating between setpoints; determine assignment by comparing to average of heating/cooling setpoints
program.addLine(" Set Tmid_setpoint = (#{htg_sp_sensor.name} + #{clg_sp_sensor.name}) / 2")
program.addLine(" If (#{tin_sensor.name} > Tmid_setpoint) && (clg_season == 1)")
program.addLine(" Set clg_mode = #{total_cool_load_serveds[unit]}")
program.addLine(" ElseIf (#{tin_sensor.name} < Tmid_setpoint) && (htg_season == 1)")
program.addLine(" Set htg_mode = #{total_heat_load_serveds[unit]}")
program.addLine(' EndIf')
end
program.addLine(' EndIf')
program.addLine('EndIf')
unit_multiplier = hpxml_bldg.building_construction.number_of_units
[:htg, :clg].each do |mode|
if mode == :htg
sign = ''
else
sign = '-'
end
surf_names.each do |surf_name|
program.addLine("Set loads_#{mode}_#{surf_name} = loads_#{mode}_#{surf_name} + (#{sign}hr_#{surf_name} * #{mode}_mode * #{unit_multiplier})")
end
nonsurf_names.each do |nonsurf_name|
program.addLine("Set loads_#{mode}_#{nonsurf_name} = loads_#{mode}_#{nonsurf_name} + (#{sign}hr_#{nonsurf_name} * #{mode}_mode * #{unit_multiplier})")
end
end
end
# EMS calling manager
Model.add_ems_program_calling_manager(
model,
name: "#{program.name} calling manager",
calling_point: 'EndOfZoneTimestepAfterZoneReporting',
ems_programs: [program]
)
end
# Creates airflow outputs (for infiltration, ventilation, etc.) that sum across all individual dwelling
# units for output reporting.
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param hpxml_osm_map [Hash] Map of HPXML::Building objects => OpenStudio Model objects for each dwelling unit
# @return [nil]
def self.apply_total_airflows_ems_program(model, hpxml_osm_map)
# Retrieve objects
infil_vars = []
mechvent_vars = []
natvent_vars = []
whf_vars = []
unit_multipliers = []
hpxml_osm_map.each do |hpxml_bldg, unit_model|
infil_vars << unit_model.getEnergyManagementSystemGlobalVariables.find { |v| v.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeInfiltration }
mechvent_vars << unit_model.getEnergyManagementSystemGlobalVariables.find { |v| v.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeMechanicalVentilation }
natvent_vars << unit_model.getEnergyManagementSystemGlobalVariables.find { |v| v.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeNaturalVentilation }
whf_vars << unit_model.getEnergyManagementSystemGlobalVariables.find { |v| v.additionalProperties.getFeatureAsString('ObjectType').to_s == Constants::ObjectTypeWholeHouseFan }
unit_multipliers << hpxml_bldg.building_construction.number_of_units
end
# EMS program
program = Model.add_ems_program(
model,
name: 'total airflows program'
)
program.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeTotalAirflowsProgram)
program.addLine('Set total_infil_flow_rate = 0')
program.addLine('Set total_mechvent_flow_rate = 0')
program.addLine('Set total_natvent_flow_rate = 0')
program.addLine('Set total_whf_flow_rate = 0')
infil_vars.each_with_index do |infil_var, i|
program.addLine("Set total_infil_flow_rate = total_infil_flow_rate + (#{infil_var.name} * #{unit_multipliers[i]})")
end
mechvent_vars.each_with_index do |mechvent_var, i|
program.addLine("Set total_mechvent_flow_rate = total_mechvent_flow_rate + (#{mechvent_var.name} * #{unit_multipliers[i]})")
end
natvent_vars.each_with_index do |natvent_var, i|
program.addLine("Set total_natvent_flow_rate = total_natvent_flow_rate + (#{natvent_var.name} * #{unit_multipliers[i]})")
end
whf_vars.each_with_index do |whf_var, i|
program.addLine("Set total_whf_flow_rate = total_whf_flow_rate + (#{whf_var.name} * #{unit_multipliers[i]})")
end
# EMS calling manager
Model.add_ems_program_calling_manager(
model,
name: "#{program.name} calling manager",
calling_point: 'EndOfZoneTimestepAfterZoneReporting',
ems_programs: [program]
)
end
# Populate fields of both unique OpenStudio objects OutputJSON and OutputControlFiles based on the debug argument.
# Always request MessagePack output.
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param debug [Boolean] If true, writes in.osm, generates additional log output, and creates all E+ output files
# @return [nil]
def self.apply_output_file_controls(model, debug)
oj = model.getOutputJSON
oj.setOptionType('TimeSeriesAndTabular')
oj.setOutputJSON(debug)
oj.setOutputMessagePack(true) # Used by ReportSimulationOutput reporting measure
ocf = model.getOutputControlFiles
ocf.setOutputAUDIT(debug)
ocf.setOutputCSV(debug)
ocf.setOutputBND(debug)
ocf.setOutputEIO(debug)
ocf.setOutputESO(debug)
ocf.setOutputMDD(debug)
ocf.setOutputMTD(debug)