Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor constants #1808

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 114 additions & 119 deletions BuildResidentialHPXML/measure.rb

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions BuildResidentialHPXML/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>build_residential_hpxml</name>
<uid>a13a8983-2b01-4930-8af2-42030b6e4233</uid>
<version_id>c97d3318-e2a9-46bc-b476-17509ea82a22</version_id>
<version_modified>2024-08-21T17:55:23Z</version_modified>
<version_id>85f5790a-07a6-4ceb-829a-7738e682fa6f</version_id>
<version_modified>2024-08-21T17:13:24Z</version_modified>
<xml_checksum>2C38F48B</xml_checksum>
<class_name>BuildResidentialHPXML</class_name>
<display_name>HPXML Builder</display_name>
Expand Down Expand Up @@ -7406,19 +7406,25 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>3E87E8F5</checksum>
<checksum>E52B375E</checksum>
</file>
<file>
<filename>constants.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>079FF429</checksum>
</file>
<file>
<filename>geometry.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>7FDF7979</checksum>
<checksum>C62D3E76</checksum>
</file>
<file>
<filename>test_build_residential_hpxml.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>4924B90F</checksum>
<checksum>BC30D013</checksum>
</file>
</files>
</measure>
18 changes: 18 additions & 0 deletions BuildResidentialHPXML/resources/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# Collection of constants.
module Constants
BuildingAmerica = 'BuildingAmerica'
FacadeFront = 'front'
FacadeBack = 'back'
FacadeLeft = 'left'
FacadeRight = 'right'
FacadeNone = 'none'
LocationInterior = 'interior'
LocationExterior = 'exterior'
None = 'none'
PositionRight = 'Right'
PositionLeft = 'Left'
RoofTypeGable = 'gable'
RoofTypeHip = 'hip'
end
346 changes: 173 additions & 173 deletions BuildResidentialHPXML/resources/geometry.rb

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions BuildResidentialHPXML/tests/test_build_residential_hpxml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ def _set_measure_argument_values(hpxml_file, args)
args['geometry_garage_width'] = 0.0
args['geometry_garage_depth'] = 20.0
args['geometry_garage_protrusion'] = 0.0
args['geometry_garage_position'] = 'Right'
args['geometry_garage_position'] = Constants::PositionRight
args['geometry_foundation_type'] = HPXML::FoundationTypeBasementConditioned
args['geometry_foundation_height'] = 8.0
args['geometry_foundation_height_above_grade'] = 1.0
args['geometry_rim_joist_height'] = 9.25
args['geometry_roof_type'] = 'gable'
args['geometry_roof_type'] = Constants::RoofTypeGable
args['geometry_roof_pitch'] = '6:12'
args['geometry_attic_type'] = HPXML::AtticTypeUnvented
args['geometry_eaves_depth'] = 0
Expand All @@ -440,7 +440,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['roof_material_type'] = HPXML::RoofTypeAsphaltShingles
args['roof_color'] = HPXML::ColorMedium
args['roof_assembly_r'] = 2.3
args['radiant_barrier_attic_location'] = 'none'
args['radiant_barrier_attic_location'] = Constants::None
args['radiant_barrier_grade'] = 1
args['neighbor_front_distance'] = 0
args['neighbor_back_distance'] = 0
Expand Down Expand Up @@ -500,7 +500,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['cooling_system_cooling_capacity'] = 24000.0
args['cooling_system_fraction_cool_load_served'] = 1
args['cooling_system_is_ducted'] = false
args['heat_pump_type'] = 'none'
args['heat_pump_type'] = Constants::None
args['heat_pump_heating_efficiency_type'] = HPXML::UnitsHSPF
args['heat_pump_heating_efficiency'] = 7.7
args['heat_pump_cooling_efficiency_type'] = HPXML::UnitsSEER
Expand All @@ -515,7 +515,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['heat_pump_backup_fuel'] = HPXML::FuelTypeElectricity
args['heat_pump_backup_heating_efficiency'] = 1
args['heat_pump_backup_heating_capacity'] = 36000.0
args['geothermal_loop_configuration'] = 'none'
args['geothermal_loop_configuration'] = Constants::None
args['hvac_control_heating_weekday_setpoint'] = 68
args['hvac_control_heating_weekend_setpoint'] = 68
args['hvac_control_cooling_weekday_setpoint'] = 78
Expand All @@ -530,19 +530,19 @@ def _set_measure_argument_values(hpxml_file, args)
args['ducts_supply_surface_area'] = 150.0
args['ducts_return_surface_area'] = 50.0
args['ducts_number_of_return_registers'] = 2
args['heating_system_2_type'] = 'none'
args['heating_system_2_type'] = Constants::None
args['heating_system_2_fuel'] = HPXML::FuelTypeElectricity
args['heating_system_2_heating_efficiency'] = 1.0
args['heating_system_2_fraction_heat_load_served'] = 0.25
args['mech_vent_fan_type'] = 'none'
args['mech_vent_fan_type'] = Constants::None
args['mech_vent_flow_rate'] = 110
args['mech_vent_hours_in_operation'] = 24
args['mech_vent_recovery_efficiency_type'] = 'Unadjusted'
args['mech_vent_total_recovery_efficiency'] = 0.48
args['mech_vent_sensible_recovery_efficiency'] = 0.72
args['mech_vent_fan_power'] = 30
args['mech_vent_num_units_served'] = 1
args['mech_vent_2_fan_type'] = 'none'
args['mech_vent_2_fan_type'] = Constants::None
args['mech_vent_2_flow_rate'] = 110
args['mech_vent_2_hours_in_operation'] = 24
args['mech_vent_2_recovery_efficiency_type'] = 'Unadjusted'
Expand Down Expand Up @@ -571,12 +571,12 @@ def _set_measure_argument_values(hpxml_file, args)
args['hot_water_distribution_recirc_branch_piping_length'] = 50
args['hot_water_distribution_recirc_pump_power'] = 50
args['hot_water_distribution_pipe_r'] = 0.0
args['dwhr_facilities_connected'] = 'none'
args['dwhr_facilities_connected'] = Constants::None
args['dwhr_equal_flow'] = true
args['dwhr_efficiency'] = 0.55
args['water_fixtures_shower_low_flow'] = true
args['water_fixtures_sink_low_flow'] = false
args['solar_thermal_system_type'] = 'none'
args['solar_thermal_system_type'] = Constants::None
args['solar_thermal_collector_area'] = 40.0
args['solar_thermal_collector_loop_type'] = HPXML::SolarThermalLoopTypeDirect
args['solar_thermal_collector_type'] = HPXML::SolarThermalCollectorTypeEvacuatedTube
Expand Down Expand Up @@ -605,7 +605,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['lighting_garage_fraction_lfl'] = 0.1
args['lighting_garage_fraction_led'] = 0.25
args['holiday_lighting_present'] = false
args['dehumidifier_type'] = 'none'
args['dehumidifier_type'] = Constants::None
args['dehumidifier_efficiency_type'] = 'EnergyFactor'
args['dehumidifier_efficiency'] = 1.8
args['dehumidifier_capacity'] = 40
Expand Down Expand Up @@ -784,16 +784,16 @@ def _set_measure_argument_values(hpxml_file, args)
args['heating_system_heating_efficiency'] = 1.0
args['heating_system_heating_capacity'] = 48000.0
args['heating_system_fraction_heat_load_served'] = 0.75
args['cooling_system_type'] = 'none'
args['cooling_system_type'] = Constants::None
args['heating_system_2_type'] = HPXML::HVACTypeFireplace
args['heating_system_2_heating_capacity'] = 16000.0
elsif ['extra-second-heating-system-boiler-to-heating-system.xml'].include? hpxml_file
args['heating_system_type'] = HPXML::HVACTypeBoiler
args['heating_system_fraction_heat_load_served'] = 0.75
args['heating_system_2_type'] = HPXML::HVACTypeBoiler
elsif ['extra-second-heating-system-portable-heater-to-heat-pump.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['cooling_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['cooling_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
args['heat_pump_backup_type'] = HPXML::HeatPumpBackupTypeIntegrated
args['heat_pump_backup_fuel'] = HPXML::FuelTypeElectricity
Expand All @@ -806,8 +806,8 @@ def _set_measure_argument_values(hpxml_file, args)
args['heating_system_2_type'] = HPXML::HVACTypeSpaceHeater
args['heating_system_2_heating_capacity'] = 16000.0
elsif ['extra-second-heating-system-fireplace-to-heat-pump.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['cooling_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['cooling_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpMiniSplit
args.delete('heat_pump_cooling_compressor_type')
args['heat_pump_heating_efficiency'] = 10.0
Expand All @@ -818,8 +818,8 @@ def _set_measure_argument_values(hpxml_file, args)
args['heating_system_2_type'] = HPXML::HVACTypeFireplace
args['heating_system_2_heating_capacity'] = 16000.0
elsif ['extra-second-heating-system-boiler-to-heat-pump.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['cooling_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['cooling_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpGroundToAir
args['heat_pump_heating_efficiency_type'] = HPXML::UnitsCOP
args['heat_pump_heating_efficiency'] = 3.6
Expand Down Expand Up @@ -860,7 +860,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['ducts_supply_location'] = HPXML::LocationUnderSlab
args['ducts_return_location'] = HPXML::LocationUnderSlab
elsif ['extra-enclosure-atticroof-conditioned-eaves-hip.xml'].include? hpxml_file
args['geometry_roof_type'] = 'hip'
args['geometry_roof_type'] = Constants::RoofTypeHip
elsif ['extra-gas-pool-heater-with-zero-kwh.xml'].include? hpxml_file
args['pool_present'] = true
args['pool_heater_type'] = HPXML::HeaterTypeGas
Expand Down Expand Up @@ -902,8 +902,8 @@ def _set_measure_argument_values(hpxml_file, args)
args['utility_bill_wood_pellets_fixed_charges'] = '16, 17'
args['utility_bill_wood_pellets_marginal_rates'] = '18, 19'
elsif ['extra-seasons-building-america.xml'].include? hpxml_file
args['hvac_control_heating_season_period'] = HPXML::BuildingAmerica
args['hvac_control_cooling_season_period'] = HPXML::BuildingAmerica
args['hvac_control_heating_season_period'] = Constants::BuildingAmerica
args['hvac_control_cooling_season_period'] = Constants::BuildingAmerica
elsif ['extra-ducts-crawlspace.xml'].include? hpxml_file
args['geometry_foundation_type'] = HPXML::FoundationTypeCrawlspaceUnvented
args['geometry_foundation_height'] = 4
Expand Down Expand Up @@ -933,8 +933,8 @@ def _set_measure_argument_values(hpxml_file, args)
args['battery_present'] = true
args['battery_location'] = HPXML::LocationAttic
elsif ['extra-detailed-performance-autosize.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['cooling_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['cooling_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
args['heat_pump_heating_efficiency'] = 10.0
args['heat_pump_cooling_efficiency'] = 17.25
Expand Down Expand Up @@ -969,7 +969,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['ducts_supply_location'] = HPXML::LocationConditionedSpace
args['ducts_return_location'] = HPXML::LocationConditionedSpace
elsif ['extra-sfa-atticroof-conditioned-eaves-hip.xml'].include? hpxml_file
args['geometry_roof_type'] = 'hip'
args['geometry_roof_type'] = Constants::RoofTypeHip
elsif ['extra-mf-eaves.xml'].include? hpxml_file
args['geometry_eaves_depth'] = 2
elsif ['extra-sfa-slab.xml'].include? hpxml_file
Expand Down Expand Up @@ -1138,10 +1138,10 @@ def _set_measure_argument_values(hpxml_file, args)

# Error
if ['error-heating-system-and-heat-pump.xml'].include? hpxml_file
args['cooling_system_type'] = 'none'
args['cooling_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
elsif ['error-cooling-system-and-heat-pump.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpAirToAir
elsif ['error-sfd-conditioned-basement-zero-foundation-height.xml'].include? hpxml_file
args['geometry_foundation_height'] = 0.0
Expand All @@ -1158,11 +1158,11 @@ def _set_measure_argument_values(hpxml_file, args)
args['geometry_attic_type'] = HPXML::AtticTypeBelowApartment
args.delete('foundation_wall_insulation_distance_to_bottom')
elsif ['error-second-heating-system-but-no-primary-heating.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['heating_system_2_type'] = HPXML::HVACTypeFireplace
elsif ['error-second-heating-system-ducted-with-ducted-primary-heating.xml'].include? hpxml_file
args['heating_system_type'] = 'none'
args['cooling_system_type'] = 'none'
args['heating_system_type'] = Constants::None
args['cooling_system_type'] = Constants::None
args['heat_pump_type'] = HPXML::HVACTypeHeatPumpMiniSplit
args.delete('heat_pump_cooling_compressor_type')
args['heat_pump_is_ducted'] = true
Expand Down Expand Up @@ -1248,7 +1248,7 @@ def _set_measure_argument_values(hpxml_file, args)
args['geometry_unit_front_wall_is_adiabatic'] = true
args['geometry_unit_back_wall_is_adiabatic'] = true
elsif ['error-hip-roof-and-protruding-garage.xml'].include? hpxml_file
args['geometry_roof_type'] = 'hip'
args['geometry_roof_type'] = Constants::RoofTypeHip
args['geometry_garage_width'] = 12
args['geometry_garage_protrusion'] = 0.5
elsif ['error-protruding-garage-under-gable-roof.xml'].include? hpxml_file
Expand Down
4 changes: 2 additions & 2 deletions BuildResidentialScheduleFile/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_simulation_parameters(hpxml, weather, args)
calendar_year = Location.get_sim_calendar_year(hpxml.header.sim_calendar_year, weather)
args[:sim_year] = calendar_year
args[:sim_start_day] = DateTime.new(args[:sim_year], 1, 1)
args[:total_days_in_year] = Constants.NumDaysInYear(calendar_year)
args[:total_days_in_year] = Calendar.num_days_in_year(calendar_year)
end

# Get generator inputs that are required for the stochastic schedule generator.
Expand All @@ -260,7 +260,7 @@ def get_simulation_parameters(hpxml, weather, args)
# @param args [Hash] Map of :argument_name => value
def get_generator_inputs(hpxml_bldg, weather, args)
state_code = HPXMLDefaults.get_default_state_code(hpxml_bldg.state_code, weather)
if Constants.StateCodesMap.keys.include?(state_code)
if Constants::StateCodesMap.keys.include?(state_code)
args[:state] = state_code
else
# Unhandled state code, fallback to CO
Expand Down
8 changes: 4 additions & 4 deletions BuildResidentialScheduleFile/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>build_residential_schedule_file</name>
<uid>f770b2db-1a9f-4e99-99a7-7f3161a594b1</uid>
<version_id>c82306e3-de8f-4659-b356-4e9cd05205e1</version_id>
<version_modified>2024-08-16T19:20:19Z</version_modified>
<version_id>395a8098-d391-4a45-9c9a-8079468ec41b</version_id>
<version_modified>2024-08-21T16:00:10Z</version_modified>
<xml_checksum>03F02484</xml_checksum>
<class_name>BuildResidentialScheduleFile</class_name>
<display_name>Schedule File Builder</display_name>
Expand Down Expand Up @@ -133,7 +133,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>038D2D11</checksum>
<checksum>19F7FF66</checksum>
</file>
<file>
<filename>README.md</filename>
Expand Down Expand Up @@ -229,7 +229,7 @@
<filename>schedules.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>25A966F4</checksum>
<checksum>AA136495</checksum>
</file>
<file>
<filename>shower_cluster_size_probability.csv</filename>
Expand Down
6 changes: 3 additions & 3 deletions BuildResidentialScheduleFile/resources/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ def create_stochastic_schedules(args:,
plugload_tv_monthly_multiplier = Schedule.validate_values(schedules_csv_data[SchedulesFile::Columns[:PlugLoadsTV].name]['PlugLoadsTVMonthlyMultipliers'], 12, 'monthly') # American Time Use Survey
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
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
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
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

sch = get_building_america_lighting_schedule(args[:time_zone_utc_offset], args[:latitude], args[:longitude], schedules_csv_data)
interior_lighting_schedule = []
num_days_in_months = Constants.NumDaysInMonths(@sim_year)
num_days_in_months = Calendar.num_days_in_months(@sim_year)
for month in 0..11
interior_lighting_schedule << sch[month] * num_days_in_months[month]
end
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def get_building_america_lighting_schedule(time_zone_utc_offset, latitude, longi
stdDevCons2 = 2.36567663279954

monthly_kwh_per_day = []
days_m = Constants.NumDaysInMonths(1999) # Intentionally excluding leap year designation
days_m = Calendar.num_days_in_months(1999) # Intentionally excluding leap year designation
wtd_avg_monthly_kwh_per_day = 0
for monthNum in 1..12
month = monthNum - 1
Expand Down
Loading