Skip to content

Commit dc8402c

Browse files
authored
Merge pull request #1808 from NREL/constants_refactor
Refactor constants
2 parents 3cee5e6 + fb1ad77 commit dc8402c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1882
-2351
lines changed

BuildResidentialHPXML/measure.rb

Lines changed: 114 additions & 119 deletions
Large diffs are not rendered by default.

BuildResidentialHPXML/measure.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<schema_version>3.1</schema_version>
44
<name>build_residential_hpxml</name>
55
<uid>a13a8983-2b01-4930-8af2-42030b6e4233</uid>
6-
<version_id>c97d3318-e2a9-46bc-b476-17509ea82a22</version_id>
7-
<version_modified>2024-08-21T17:55:23Z</version_modified>
6+
<version_id>85f5790a-07a6-4ceb-829a-7738e682fa6f</version_id>
7+
<version_modified>2024-08-21T17:13:24Z</version_modified>
88
<xml_checksum>2C38F48B</xml_checksum>
99
<class_name>BuildResidentialHPXML</class_name>
1010
<display_name>HPXML Builder</display_name>
@@ -7406,19 +7406,25 @@
74067406
<filename>measure.rb</filename>
74077407
<filetype>rb</filetype>
74087408
<usage_type>script</usage_type>
7409-
<checksum>3E87E8F5</checksum>
7409+
<checksum>E52B375E</checksum>
7410+
</file>
7411+
<file>
7412+
<filename>constants.rb</filename>
7413+
<filetype>rb</filetype>
7414+
<usage_type>resource</usage_type>
7415+
<checksum>079FF429</checksum>
74107416
</file>
74117417
<file>
74127418
<filename>geometry.rb</filename>
74137419
<filetype>rb</filetype>
74147420
<usage_type>resource</usage_type>
7415-
<checksum>7FDF7979</checksum>
7421+
<checksum>C62D3E76</checksum>
74167422
</file>
74177423
<file>
74187424
<filename>test_build_residential_hpxml.rb</filename>
74197425
<filetype>rb</filetype>
74207426
<usage_type>test</usage_type>
7421-
<checksum>4924B90F</checksum>
7427+
<checksum>BC30D013</checksum>
74227428
</file>
74237429
</files>
74247430
</measure>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# Collection of constants.
4+
module Constants
5+
BuildingAmerica = 'BuildingAmerica'
6+
FacadeFront = 'front'
7+
FacadeBack = 'back'
8+
FacadeLeft = 'left'
9+
FacadeRight = 'right'
10+
FacadeNone = 'none'
11+
LocationInterior = 'interior'
12+
LocationExterior = 'exterior'
13+
None = 'none'
14+
PositionRight = 'Right'
15+
PositionLeft = 'Left'
16+
RoofTypeGable = 'gable'
17+
RoofTypeHip = 'hip'
18+
end

BuildResidentialHPXML/resources/geometry.rb

Lines changed: 173 additions & 173 deletions
Large diffs are not rendered by default.

BuildResidentialHPXML/tests/test_build_residential_hpxml.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ def _set_measure_argument_values(hpxml_file, args)
409409
args['geometry_garage_width'] = 0.0
410410
args['geometry_garage_depth'] = 20.0
411411
args['geometry_garage_protrusion'] = 0.0
412-
args['geometry_garage_position'] = 'Right'
412+
args['geometry_garage_position'] = Constants::PositionRight
413413
args['geometry_foundation_type'] = HPXML::FoundationTypeBasementConditioned
414414
args['geometry_foundation_height'] = 8.0
415415
args['geometry_foundation_height_above_grade'] = 1.0
416416
args['geometry_rim_joist_height'] = 9.25
417-
args['geometry_roof_type'] = 'gable'
417+
args['geometry_roof_type'] = Constants::RoofTypeGable
418418
args['geometry_roof_pitch'] = '6:12'
419419
args['geometry_attic_type'] = HPXML::AtticTypeUnvented
420420
args['geometry_eaves_depth'] = 0
@@ -440,7 +440,7 @@ def _set_measure_argument_values(hpxml_file, args)
440440
args['roof_material_type'] = HPXML::RoofTypeAsphaltShingles
441441
args['roof_color'] = HPXML::ColorMedium
442442
args['roof_assembly_r'] = 2.3
443-
args['radiant_barrier_attic_location'] = 'none'
443+
args['radiant_barrier_attic_location'] = Constants::None
444444
args['radiant_barrier_grade'] = 1
445445
args['neighbor_front_distance'] = 0
446446
args['neighbor_back_distance'] = 0
@@ -500,7 +500,7 @@ def _set_measure_argument_values(hpxml_file, args)
500500
args['cooling_system_cooling_capacity'] = 24000.0
501501
args['cooling_system_fraction_cool_load_served'] = 1
502502
args['cooling_system_is_ducted'] = false
503-
args['heat_pump_type'] = 'none'
503+
args['heat_pump_type'] = Constants::None
504504
args['heat_pump_heating_efficiency_type'] = HPXML::UnitsHSPF
505505
args['heat_pump_heating_efficiency'] = 7.7
506506
args['heat_pump_cooling_efficiency_type'] = HPXML::UnitsSEER
@@ -515,7 +515,7 @@ def _set_measure_argument_values(hpxml_file, args)
515515
args['heat_pump_backup_fuel'] = HPXML::FuelTypeElectricity
516516
args['heat_pump_backup_heating_efficiency'] = 1
517517
args['heat_pump_backup_heating_capacity'] = 36000.0
518-
args['geothermal_loop_configuration'] = 'none'
518+
args['geothermal_loop_configuration'] = Constants::None
519519
args['hvac_control_heating_weekday_setpoint'] = 68
520520
args['hvac_control_heating_weekend_setpoint'] = 68
521521
args['hvac_control_cooling_weekday_setpoint'] = 78
@@ -530,19 +530,19 @@ def _set_measure_argument_values(hpxml_file, args)
530530
args['ducts_supply_surface_area'] = 150.0
531531
args['ducts_return_surface_area'] = 50.0
532532
args['ducts_number_of_return_registers'] = 2
533-
args['heating_system_2_type'] = 'none'
533+
args['heating_system_2_type'] = Constants::None
534534
args['heating_system_2_fuel'] = HPXML::FuelTypeElectricity
535535
args['heating_system_2_heating_efficiency'] = 1.0
536536
args['heating_system_2_fraction_heat_load_served'] = 0.25
537-
args['mech_vent_fan_type'] = 'none'
537+
args['mech_vent_fan_type'] = Constants::None
538538
args['mech_vent_flow_rate'] = 110
539539
args['mech_vent_hours_in_operation'] = 24
540540
args['mech_vent_recovery_efficiency_type'] = 'Unadjusted'
541541
args['mech_vent_total_recovery_efficiency'] = 0.48
542542
args['mech_vent_sensible_recovery_efficiency'] = 0.72
543543
args['mech_vent_fan_power'] = 30
544544
args['mech_vent_num_units_served'] = 1
545-
args['mech_vent_2_fan_type'] = 'none'
545+
args['mech_vent_2_fan_type'] = Constants::None
546546
args['mech_vent_2_flow_rate'] = 110
547547
args['mech_vent_2_hours_in_operation'] = 24
548548
args['mech_vent_2_recovery_efficiency_type'] = 'Unadjusted'
@@ -571,12 +571,12 @@ def _set_measure_argument_values(hpxml_file, args)
571571
args['hot_water_distribution_recirc_branch_piping_length'] = 50
572572
args['hot_water_distribution_recirc_pump_power'] = 50
573573
args['hot_water_distribution_pipe_r'] = 0.0
574-
args['dwhr_facilities_connected'] = 'none'
574+
args['dwhr_facilities_connected'] = Constants::None
575575
args['dwhr_equal_flow'] = true
576576
args['dwhr_efficiency'] = 0.55
577577
args['water_fixtures_shower_low_flow'] = true
578578
args['water_fixtures_sink_low_flow'] = false
579-
args['solar_thermal_system_type'] = 'none'
579+
args['solar_thermal_system_type'] = Constants::None
580580
args['solar_thermal_collector_area'] = 40.0
581581
args['solar_thermal_collector_loop_type'] = HPXML::SolarThermalLoopTypeDirect
582582
args['solar_thermal_collector_type'] = HPXML::SolarThermalCollectorTypeEvacuatedTube
@@ -605,7 +605,7 @@ def _set_measure_argument_values(hpxml_file, args)
605605
args['lighting_garage_fraction_lfl'] = 0.1
606606
args['lighting_garage_fraction_led'] = 0.25
607607
args['holiday_lighting_present'] = false
608-
args['dehumidifier_type'] = 'none'
608+
args['dehumidifier_type'] = Constants::None
609609
args['dehumidifier_efficiency_type'] = 'EnergyFactor'
610610
args['dehumidifier_efficiency'] = 1.8
611611
args['dehumidifier_capacity'] = 40
@@ -784,16 +784,16 @@ def _set_measure_argument_values(hpxml_file, args)
784784
args['heating_system_heating_efficiency'] = 1.0
785785
args['heating_system_heating_capacity'] = 48000.0
786786
args['heating_system_fraction_heat_load_served'] = 0.75
787-
args['cooling_system_type'] = 'none'
787+
args['cooling_system_type'] = Constants::None
788788
args['heating_system_2_type'] = HPXML::HVACTypeFireplace
789789
args['heating_system_2_heating_capacity'] = 16000.0
790790
elsif ['extra-second-heating-system-boiler-to-heating-system.xml'].include? hpxml_file
791791
args['heating_system_type'] = HPXML::HVACTypeBoiler
792792
args['heating_system_fraction_heat_load_served'] = 0.75
793793
args['heating_system_2_type'] = HPXML::HVACTypeBoiler
794794
elsif ['extra-second-heating-system-portable-heater-to-heat-pump.xml'].include? hpxml_file
795-
args['heating_system_type'] = 'none'
796-
args['cooling_system_type'] = 'none'
795+
args['heating_system_type'] = Constants::None
796+
args['cooling_system_type'] = Constants::None
797797
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
798798
args['heat_pump_backup_type'] = HPXML::HeatPumpBackupTypeIntegrated
799799
args['heat_pump_backup_fuel'] = HPXML::FuelTypeElectricity
@@ -806,8 +806,8 @@ def _set_measure_argument_values(hpxml_file, args)
806806
args['heating_system_2_type'] = HPXML::HVACTypeSpaceHeater
807807
args['heating_system_2_heating_capacity'] = 16000.0
808808
elsif ['extra-second-heating-system-fireplace-to-heat-pump.xml'].include? hpxml_file
809-
args['heating_system_type'] = 'none'
810-
args['cooling_system_type'] = 'none'
809+
args['heating_system_type'] = Constants::None
810+
args['cooling_system_type'] = Constants::None
811811
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpMiniSplit
812812
args.delete('heat_pump_cooling_compressor_type')
813813
args['heat_pump_heating_efficiency'] = 10.0
@@ -818,8 +818,8 @@ def _set_measure_argument_values(hpxml_file, args)
818818
args['heating_system_2_type'] = HPXML::HVACTypeFireplace
819819
args['heating_system_2_heating_capacity'] = 16000.0
820820
elsif ['extra-second-heating-system-boiler-to-heat-pump.xml'].include? hpxml_file
821-
args['heating_system_type'] = 'none'
822-
args['cooling_system_type'] = 'none'
821+
args['heating_system_type'] = Constants::None
822+
args['cooling_system_type'] = Constants::None
823823
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpGroundToAir
824824
args['heat_pump_heating_efficiency_type'] = HPXML::UnitsCOP
825825
args['heat_pump_heating_efficiency'] = 3.6
@@ -860,7 +860,7 @@ def _set_measure_argument_values(hpxml_file, args)
860860
args['ducts_supply_location'] = HPXML::LocationUnderSlab
861861
args['ducts_return_location'] = HPXML::LocationUnderSlab
862862
elsif ['extra-enclosure-atticroof-conditioned-eaves-hip.xml'].include? hpxml_file
863-
args['geometry_roof_type'] = 'hip'
863+
args['geometry_roof_type'] = Constants::RoofTypeHip
864864
elsif ['extra-gas-pool-heater-with-zero-kwh.xml'].include? hpxml_file
865865
args['pool_present'] = true
866866
args['pool_heater_type'] = HPXML::HeaterTypeGas
@@ -902,8 +902,8 @@ def _set_measure_argument_values(hpxml_file, args)
902902
args['utility_bill_wood_pellets_fixed_charges'] = '16, 17'
903903
args['utility_bill_wood_pellets_marginal_rates'] = '18, 19'
904904
elsif ['extra-seasons-building-america.xml'].include? hpxml_file
905-
args['hvac_control_heating_season_period'] = HPXML::BuildingAmerica
906-
args['hvac_control_cooling_season_period'] = HPXML::BuildingAmerica
905+
args['hvac_control_heating_season_period'] = Constants::BuildingAmerica
906+
args['hvac_control_cooling_season_period'] = Constants::BuildingAmerica
907907
elsif ['extra-ducts-crawlspace.xml'].include? hpxml_file
908908
args['geometry_foundation_type'] = HPXML::FoundationTypeCrawlspaceUnvented
909909
args['geometry_foundation_height'] = 4
@@ -933,8 +933,8 @@ def _set_measure_argument_values(hpxml_file, args)
933933
args['battery_present'] = true
934934
args['battery_location'] = HPXML::LocationAttic
935935
elsif ['extra-detailed-performance-autosize.xml'].include? hpxml_file
936-
args['heating_system_type'] = 'none'
937-
args['cooling_system_type'] = 'none'
936+
args['heating_system_type'] = Constants::None
937+
args['cooling_system_type'] = Constants::None
938938
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
939939
args['heat_pump_heating_efficiency'] = 10.0
940940
args['heat_pump_cooling_efficiency'] = 17.25
@@ -969,7 +969,7 @@ def _set_measure_argument_values(hpxml_file, args)
969969
args['ducts_supply_location'] = HPXML::LocationConditionedSpace
970970
args['ducts_return_location'] = HPXML::LocationConditionedSpace
971971
elsif ['extra-sfa-atticroof-conditioned-eaves-hip.xml'].include? hpxml_file
972-
args['geometry_roof_type'] = 'hip'
972+
args['geometry_roof_type'] = Constants::RoofTypeHip
973973
elsif ['extra-mf-eaves.xml'].include? hpxml_file
974974
args['geometry_eaves_depth'] = 2
975975
elsif ['extra-sfa-slab.xml'].include? hpxml_file
@@ -1138,10 +1138,10 @@ def _set_measure_argument_values(hpxml_file, args)
11381138

11391139
# Error
11401140
if ['error-heating-system-and-heat-pump.xml'].include? hpxml_file
1141-
args['cooling_system_type'] = 'none'
1141+
args['cooling_system_type'] = Constants::None
11421142
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
11431143
elsif ['error-cooling-system-and-heat-pump.xml'].include? hpxml_file
1144-
args['heating_system_type'] = 'none'
1144+
args['heating_system_type'] = Constants::None
11451145
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
11461146
elsif ['error-sfd-conditioned-basement-zero-foundation-height.xml'].include? hpxml_file
11471147
args['geometry_foundation_height'] = 0.0
@@ -1158,11 +1158,11 @@ def _set_measure_argument_values(hpxml_file, args)
11581158
args['geometry_attic_type'] = HPXML::AtticTypeBelowApartment
11591159
args.delete('foundation_wall_insulation_distance_to_bottom')
11601160
elsif ['error-second-heating-system-but-no-primary-heating.xml'].include? hpxml_file
1161-
args['heating_system_type'] = 'none'
1161+
args['heating_system_type'] = Constants::None
11621162
args['heating_system_2_type'] = HPXML::HVACTypeFireplace
11631163
elsif ['error-second-heating-system-ducted-with-ducted-primary-heating.xml'].include? hpxml_file
1164-
args['heating_system_type'] = 'none'
1165-
args['cooling_system_type'] = 'none'
1164+
args['heating_system_type'] = Constants::None
1165+
args['cooling_system_type'] = Constants::None
11661166
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpMiniSplit
11671167
args.delete('heat_pump_cooling_compressor_type')
11681168
args['heat_pump_is_ducted'] = true
@@ -1248,7 +1248,7 @@ def _set_measure_argument_values(hpxml_file, args)
12481248
args['geometry_unit_front_wall_is_adiabatic'] = true
12491249
args['geometry_unit_back_wall_is_adiabatic'] = true
12501250
elsif ['error-hip-roof-and-protruding-garage.xml'].include? hpxml_file
1251-
args['geometry_roof_type'] = 'hip'
1251+
args['geometry_roof_type'] = Constants::RoofTypeHip
12521252
args['geometry_garage_width'] = 12
12531253
args['geometry_garage_protrusion'] = 0.5
12541254
elsif ['error-protruding-garage-under-gable-roof.xml'].include? hpxml_file

BuildResidentialScheduleFile/measure.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def get_simulation_parameters(hpxml, weather, args)
250250
calendar_year = Location.get_sim_calendar_year(hpxml.header.sim_calendar_year, weather)
251251
args[:sim_year] = calendar_year
252252
args[:sim_start_day] = DateTime.new(args[:sim_year], 1, 1)
253-
args[:total_days_in_year] = Constants.NumDaysInYear(calendar_year)
253+
args[:total_days_in_year] = Calendar.num_days_in_year(calendar_year)
254254
end
255255

256256
# Get generator inputs that are required for the stochastic schedule generator.
@@ -260,7 +260,7 @@ def get_simulation_parameters(hpxml, weather, args)
260260
# @param args [Hash] Map of :argument_name => value
261261
def get_generator_inputs(hpxml_bldg, weather, args)
262262
state_code = HPXMLDefaults.get_default_state_code(hpxml_bldg.state_code, weather)
263-
if Constants.StateCodesMap.keys.include?(state_code)
263+
if Constants::StateCodesMap.keys.include?(state_code)
264264
args[:state] = state_code
265265
else
266266
# Unhandled state code, fallback to CO

BuildResidentialScheduleFile/measure.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<schema_version>3.1</schema_version>
44
<name>build_residential_schedule_file</name>
55
<uid>f770b2db-1a9f-4e99-99a7-7f3161a594b1</uid>
6-
<version_id>9033e5e4-4876-4392-8a4a-77401a93c4ae</version_id>
7-
<version_modified>2024-08-21T18:55:44Z</version_modified>
6+
<version_id>27a369c7-3136-4a71-9ecd-af6392b6c251</version_id>
7+
<version_modified>2024-08-21T20:28:58Z</version_modified>
88
<xml_checksum>03F02484</xml_checksum>
99
<class_name>BuildResidentialScheduleFile</class_name>
1010
<display_name>Schedule File Builder</display_name>
@@ -133,7 +133,7 @@
133133
<filename>measure.rb</filename>
134134
<filetype>rb</filetype>
135135
<usage_type>script</usage_type>
136-
<checksum>038D2D11</checksum>
136+
<checksum>19F7FF66</checksum>
137137
</file>
138138
<file>
139139
<filename>README.md</filename>
@@ -229,7 +229,7 @@
229229
<filename>schedules.rb</filename>
230230
<filetype>rb</filetype>
231231
<usage_type>resource</usage_type>
232-
<checksum>08F7AF68</checksum>
232+
<checksum>23F6E830</checksum>
233233
</file>
234234
<file>
235235
<filename>shower_cluster_size_probability.csv</filename>

BuildResidentialScheduleFile/resources/schedules.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ def create_stochastic_schedules(args:,
176176
plugload_tv_monthly_multiplier = Schedule.validate_values(schedules_csv_data[SchedulesFile::Columns[:PlugLoadsTV].name]['PlugLoadsTVMonthlyMultipliers'], 12, 'monthly') # American Time Use Survey
177177
ceiling_fan_weekday_sch = Schedule.validate_values(default_schedules_csv_data[SchedulesFile::Columns[:CeilingFan].name]['WeekdayScheduleFractions'], 24, 'weekday') # Table C.3(5) of ANSI/RESNET/ICC 301-2022 Addendum C
178178
ceiling_fan_weekend_sch = Schedule.validate_values(default_schedules_csv_data[SchedulesFile::Columns[:CeilingFan].name]['WeekendScheduleFractions'], 24, 'weekend') # Table C.3(5) of ANSI/RESNET/ICC 301-2022 Addendum C
179-
ceiling_fan_monthly_multiplier = Schedule.validate_values(Schedule.CeilingFanMonthlyMultipliers(weather: weather), 12, 'monthly') # based on monthly average outdoor temperatures per ANSI/RESNET/ICC 301-2019
179+
ceiling_fan_monthly_multiplier = Schedule.validate_values(HVAC.get_default_ceiling_fan_months(weather).join(', '), 12, 'monthly') # based on monthly average outdoor temperatures per ANSI/RESNET/ICC 301-2019
180180

181181
sch = get_building_america_lighting_schedule(args[:time_zone_utc_offset], args[:latitude], args[:longitude], schedules_csv_data)
182182
interior_lighting_schedule = []
183-
num_days_in_months = Constants.NumDaysInMonths(@sim_year)
183+
num_days_in_months = Calendar.num_days_in_months(@sim_year)
184184
for month in 0..11
185185
interior_lighting_schedule << sch[month] * num_days_in_months[month]
186186
end
@@ -1000,7 +1000,7 @@ def get_building_america_lighting_schedule(time_zone_utc_offset, latitude, longi
10001000
stdDevCons2 = 2.36567663279954
10011001

10021002
monthly_kwh_per_day = []
1003-
days_m = Constants.NumDaysInMonths(1999) # Intentionally excluding leap year designation
1003+
days_m = Calendar.num_days_in_months(1999) # Intentionally excluding leap year designation
10041004
wtd_avg_monthly_kwh_per_day = 0
10051005
for monthNum in 1..12
10061006
month = monthNum - 1

0 commit comments

Comments
 (0)