Skip to content

Commit

Permalink
Merge pull request #1843 from NREL/mj_num_occ_double
Browse files Browse the repository at this point in the history
Bugfix for non-integer number of occupants
  • Loading branch information
shorowit authored Sep 25, 2024
2 parents 990df15 + 69f1aca commit c9f71f3
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 63 deletions.
16 changes: 8 additions & 8 deletions HPXMLtoOpenStudio/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>hpxm_lto_openstudio</name>
<uid>b1543b30-9465-45ff-ba04-1d1f85e763bc</uid>
<version_id>e5f1c576-9881-4a74-b9c0-d9a96ec4c6be</version_id>
<version_modified>2024-09-24T18:24:04Z</version_modified>
<version_id>453f8c5f-d922-42a5-8815-cd92b9b23fa0</version_id>
<version_modified>2024-09-25T21:40:48Z</version_modified>
<xml_checksum>D8922A73</xml_checksum>
<class_name>HPXMLtoOpenStudio</class_name>
<display_name>HPXML to OpenStudio Translator</display_name>
Expand Down Expand Up @@ -351,13 +351,13 @@
<filename>hpxml.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>C8198E51</checksum>
<checksum>278B0E8F</checksum>
</file>
<file>
<filename>hpxml_defaults.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>331D7C8E</checksum>
<checksum>ABD33AA9</checksum>
</file>
<file>
<filename>hpxml_schema/HPXML.xsd</filename>
Expand Down Expand Up @@ -663,7 +663,7 @@
<filename>test_defaults.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>FA4AF769</checksum>
<checksum>1821AF01</checksum>
</file>
<file>
<filename>test_enclosure.rb</filename>
Expand All @@ -681,7 +681,7 @@
<filename>test_hotwater_appliance.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>9FD5D93B</checksum>
<checksum>A1E1E023</checksum>
</file>
<file>
<filename>test_hvac.rb</filename>
Expand Down Expand Up @@ -711,7 +711,7 @@
<filename>test_miscloads.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>C3D97554</checksum>
<checksum>974B3838</checksum>
</file>
<file>
<filename>test_pv.rb</filename>
Expand All @@ -735,7 +735,7 @@
<filename>test_validation.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>57009C9A</checksum>
<checksum>9310E9E6</checksum>
</file>
<file>
<filename>test_water_heater.rb</filename>
Expand Down
6 changes: 3 additions & 3 deletions HPXMLtoOpenStudio/resources/hpxml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ class BuildingHeader < BaseElement
:manualj_humidity_difference, # [Double] HVACSizingControl/ManualJInputs/HumidityDifference (grains)
:manualj_internal_loads_sensible, # [Double] HVACSizingControl/ManualJInputs/InternalLoadsSensible (Btu/hr)
:manualj_internal_loads_latent, # [Double] HVACSizingControl/ManualJInputs/InternalLoadsLatent (Btu/hr)
:manualj_num_occupants, # [Integer] HVACSizingControl/ManualJInputs/NumberofOccupants
:manualj_num_occupants, # [Double] HVACSizingControl/ManualJInputs/NumberofOccupants
:manualj_infiltration_shielding_class, # [Integer] HVACSizingControl/ManualJInputs/InfiltrationShieldingClass (1-5)
:manualj_infiltration_method, # [String] HVACSizingControl/ManualJInputs/InfiltrationMethod (HPXML::ManualJInfiltrationMethodXXX)
:natvent_days_per_week, # [Integer] NaturalVentilationAvailabilityDaysperWeek
Expand Down Expand Up @@ -2595,7 +2595,7 @@ def to_doc(building)
XMLHelper.add_element(manualj_sizing_inputs, 'HumidityDifference', @manualj_humidity_difference, :float, @manualj_humidity_difference_isdefaulted) unless @manualj_humidity_difference.nil?
XMLHelper.add_element(manualj_sizing_inputs, 'InternalLoadsSensible', @manualj_internal_loads_sensible, :float, @manualj_internal_loads_sensible_isdefaulted) unless @manualj_internal_loads_sensible.nil?
XMLHelper.add_element(manualj_sizing_inputs, 'InternalLoadsLatent', @manualj_internal_loads_latent, :float, @manualj_internal_loads_latent_isdefaulted) unless @manualj_internal_loads_latent.nil?
XMLHelper.add_element(manualj_sizing_inputs, 'NumberofOccupants', @manualj_num_occupants, :integer, @manualj_num_occupants_isdefaulted) unless @manualj_num_occupants.nil?
XMLHelper.add_element(manualj_sizing_inputs, 'NumberofOccupants', @manualj_num_occupants, :float, @manualj_num_occupants_isdefaulted) unless @manualj_num_occupants.nil?
XMLHelper.add_element(manualj_sizing_inputs, 'InfiltrationShieldingClass', @manualj_infiltration_shielding_class, :integer, @manualj_infiltration_shielding_class_isdefaulted) unless @manualj_infiltration_shielding_class.nil?
XMLHelper.add_element(manualj_sizing_inputs, 'InfiltrationMethod', @manualj_infiltration_method, :string, @manualj_infiltration_method_isdefaulted) unless @manualj_infiltration_method.nil?
end
Expand Down Expand Up @@ -2648,7 +2648,7 @@ def from_doc(building)
@manualj_humidity_difference = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/HumidityDifference', :float)
@manualj_internal_loads_sensible = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/InternalLoadsSensible', :float)
@manualj_internal_loads_latent = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/InternalLoadsLatent', :float)
@manualj_num_occupants = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/NumberofOccupants', :integer)
@manualj_num_occupants = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/NumberofOccupants', :float)
@manualj_infiltration_shielding_class = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/InfiltrationShieldingClass', :integer)
@manualj_infiltration_method = XMLHelper.get_value(building_summary, 'extension/HVACSizingControl/ManualJInputs/InfiltrationMethod', :string)
@extension_properties = {}
Expand Down
4 changes: 2 additions & 2 deletions HPXMLtoOpenStudio/resources/hpxml_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def self.apply_building_header_sizing(runner, hpxml_bldg, weather)
runner.registerWarning("ManualJInputs/InternalLoadsLatent (#{hpxml_bldg.header.manualj_internal_loads_latent}) does not match sum of conditioned spaces (#{sum_space_manualj_internal_loads_latent}).")
end

sum_space_manualj_num_occupants = hpxml_bldg.conditioned_spaces.map { |space| space.manualj_num_occupants.to_f }.sum.round
sum_space_manualj_num_occupants = hpxml_bldg.conditioned_spaces.map { |space| space.manualj_num_occupants.to_f }.sum
if hpxml_bldg.header.manualj_num_occupants.nil?
if sum_space_manualj_num_occupants > 0
hpxml_bldg.header.manualj_num_occupants = sum_space_manualj_num_occupants
Expand All @@ -348,7 +348,7 @@ def self.apply_building_header_sizing(runner, hpxml_bldg, weather)
space.manualj_num_occupants = (hpxml_bldg.header.manualj_num_occupants * space.floor_area / total_floor_area).round(2)
space.manualj_num_occupants_isdefaulted = true
end
elsif (hpxml_bldg.header.manualj_num_occupants - sum_space_manualj_num_occupants).abs >= 1 # Tolerance for rounding
elsif (hpxml_bldg.header.manualj_num_occupants - sum_space_manualj_num_occupants).abs >= 0.1
runner.registerWarning("ManualJInputs/NumberofOccupants (#{hpxml_bldg.header.manualj_num_occupants}) does not match sum of conditioned spaces (#{sum_space_manualj_num_occupants}).")
end

Expand Down
4 changes: 2 additions & 2 deletions HPXMLtoOpenStudio/tests/test_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ def test_building
assert_equal(4, default_hpxml_bldg.header.manualj_num_occupants)

# Test defaults w/ NumberOfResidents provided and greater than Nbr+1
hpxml_bldg.building_occupancy.number_of_residents = 6
hpxml_bldg.building_occupancy.number_of_residents = 5.5
XMLHelper.write_file(hpxml.to_doc, @tmp_hpxml_path)
_default_hpxml, default_hpxml_bldg = _test_measure()
assert_equal(6, default_hpxml_bldg.header.manualj_num_occupants)
assert_equal(5.5, default_hpxml_bldg.header.manualj_num_occupants)

# Test defaults - DST in weather file
hpxml, hpxml_bldg = _create_hpxml('base-location-AMY-2012.xml')
Expand Down
56 changes: 28 additions & 28 deletions HPXMLtoOpenStudio/tests/test_hotwater_appliance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_base
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 43.71
dist_gpd = 10.030
cw_gpd = 3.7116
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_dhw_multiple
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-dhw-multiple.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 15.30
dist_gpd = 3.510
cw_gpd = 1.2991
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_dhw_shared_water_heater_recirc
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-bldgtype-mf-unit-shared-water-heater-recirc.xml'))
model, _hpxml, hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 43.71
dist_gpd = 12.103
cw_gpd = 3.7116
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_dhw_shared_laundry
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-bldgtype-mf-unit-shared-laundry-room.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 43.71
dist_gpd = 12.103
cw_gpd = 3.7116
Expand Down Expand Up @@ -374,7 +374,7 @@ def test_dhw_low_flow_fixtures
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-dhw-low-flow-fixtures.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 42.39
dist_gpd = 9.7261
assert_in_epsilon(fixture_gpd, get_wu_gpd(model, Constants::ObjectTypeFixtures), 0.001)
Expand All @@ -386,7 +386,7 @@ def test_dhw_dwhr
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-dhw-dwhr.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 43.71
dist_gpd = 10.030
assert_in_epsilon(fixture_gpd, get_wu_gpd(model, Constants::ObjectTypeFixtures), 0.001)
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_appliances_none
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-none.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
assert_nil(get_wu_gpd(model, Constants::ObjectTypeClothesWasher))
assert_nil(get_wu_gpd(model, Constants::ObjectTypeDishwasher))

Expand Down Expand Up @@ -494,7 +494,7 @@ def test_appliances_modified
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-modified.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
cw_gpd = 3.7116
dw_gpd = 5.475
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_appliances_oil
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-oil.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
cw_gpd = 3.7116
dw_gpd = 2.7342
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
Expand Down Expand Up @@ -620,7 +620,7 @@ def test_appliances_gas
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-gas.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
cw_gpd = 3.7116
dw_gpd = 2.7342
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
Expand Down Expand Up @@ -689,7 +689,7 @@ def test_appliances_propane
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-propane.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
cw_gpd = 3.7116
dw_gpd = 2.7342
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
Expand Down Expand Up @@ -758,7 +758,7 @@ def test_appliances_wood
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-wood.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
cw_gpd = 3.7116
dw_gpd = 2.7342
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
Expand Down Expand Up @@ -827,7 +827,7 @@ def test_appliances_coal
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-appliances-coal.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
cw_gpd = 3.7116
dw_gpd = 2.7342
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
Expand Down Expand Up @@ -896,7 +896,7 @@ def test_usage_multiplier
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-misc-usage-multiplier.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 43.71 * 0.9
dist_gpd = 10.030 * 0.9
cw_gpd = 3.7116 * 0.9
Expand Down Expand Up @@ -957,7 +957,7 @@ def test_operational_1_occupant
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-residents-1.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
# water use equipment hot water gal/day
fixture_gpd = 13.485
dist_gpd = 4.569
cw_gpd = 2.25
Expand Down Expand Up @@ -1013,37 +1013,37 @@ def test_operational_1_occupant
assert_in_epsilon(1.0, get_oe_fractions(model, Constants::ObjectTypeGeneralWaterUseLatent)[1], 0.001)
end

def test_operational_5_occupants
def test_operational_5_5_occupants
args_hash = {}
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-residents-5.xml'))
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-residents-5-5.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# water use equipment peak flows
fixture_gpd = 86.397
dist_gpd = 21.648
cw_gpd = 6.224
dw_gpd = 5.387
# water use equipment hot water gal/day
fixture_gpd = 95.511
dist_gpd = 23.142
cw_gpd = 6.667
dw_gpd = 5.722
assert_in_epsilon(cw_gpd, get_wu_gpd(model, Constants::ObjectTypeClothesWasher), 0.001)
assert_in_epsilon(dw_gpd, get_wu_gpd(model, Constants::ObjectTypeDishwasher), 0.001)
assert_in_epsilon(fixture_gpd, get_wu_gpd(model, Constants::ObjectTypeFixtures), 0.001)
assert_in_epsilon(dist_gpd, get_wu_gpd(model, Constants::ObjectTypeDistributionWaste), 0.001)

# electric equipment
cw_ee_kwh_yr = 139.688
cw_ee_kwh_yr = 149.642
cw_sens_frac = 0.27
cw_lat_frac = 0.03
assert_in_epsilon(cw_ee_kwh_yr, get_ee_kwh_per_year(model, Constants::ObjectTypeClothesWasher), 0.001)
assert_in_epsilon(cw_sens_frac, get_ee_fractions(model, Constants::ObjectTypeClothesWasher)[0], 0.001)
assert_in_epsilon(cw_lat_frac, get_ee_fractions(model, Constants::ObjectTypeClothesWasher)[1], 0.001)

dw_ee_kwh_yr = 163.593
dw_ee_kwh_yr = 173.775
dw_sens_frac = 0.3
dw_lat_frac = 0.300
assert_in_epsilon(dw_ee_kwh_yr, get_ee_kwh_per_year(model, Constants::ObjectTypeDishwasher), 0.001)
assert_in_epsilon(dw_sens_frac, get_ee_fractions(model, Constants::ObjectTypeDishwasher)[0], 0.001)
assert_in_epsilon(dw_lat_frac, get_ee_fractions(model, Constants::ObjectTypeDishwasher)[1], 0.001)

cd_ee_kwh_yr = 1038.961
cd_ee_kwh_yr = 1113.0
cd_sens_frac = 0.135
cd_lat_frac = 0.015
assert_in_epsilon(cd_ee_kwh_yr, get_ee_kwh_per_year(model, Constants::ObjectTypeClothesDryer), 0.001)
Expand All @@ -1055,16 +1055,16 @@ def test_operational_5_occupants
assert_in_epsilon(rf_sens_frac, get_ee_fractions(model, Constants::ObjectTypeRefrigerator)[0], 0.001)
assert_in_epsilon(rf_lat_frac, get_ee_fractions(model, Constants::ObjectTypeRefrigerator)[1], 0.001)

cook_ee_kwh_yr = 651.2
cook_ee_kwh_yr = 691.75
cook_sens_frac = 0.72
cook_lat_frac = 0.080
assert_in_epsilon(cook_ee_kwh_yr, get_ee_kwh_per_year(model, Constants::ObjectTypeCookingRange), 0.001)
assert_in_epsilon(cook_sens_frac, get_ee_fractions(model, Constants::ObjectTypeCookingRange)[0], 0.001)
assert_in_epsilon(cook_lat_frac, get_ee_fractions(model, Constants::ObjectTypeCookingRange)[1], 0.001)

# other equipment
water_sens = -490.4
water_lat = 497.6
water_sens = -536.0
water_lat = 543.8
assert_in_epsilon(water_sens, get_oe_kwh(model, Constants::ObjectTypeGeneralWaterUseSensible), 0.001)
assert_in_epsilon(1.0, get_oe_fractions(model, Constants::ObjectTypeGeneralWaterUseSensible)[0], 0.001)
assert_in_epsilon(0.0, get_oe_fractions(model, Constants::ObjectTypeGeneralWaterUseSensible)[1], 0.001)
Expand Down
6 changes: 3 additions & 3 deletions HPXMLtoOpenStudio/tests/test_miscloads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ def test_large_uncommon_loads2

def test_operational_defaults
args_hash = {}
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-residents-5.xml'))
args_hash['hpxml_path'] = File.absolute_path(File.join(sample_files_dir, 'base-residents-5-5.xml'))
model, _hpxml, _hpxml_bldg = _test_measure(args_hash)

# Check misc plug loads
kwh_yr, therm_yr = get_kwh_therm_per_year(model, Constants::ObjectTypeMiscPlugLoads)
assert_in_delta(2887, kwh_yr, 1.0)
assert_in_delta(3008, kwh_yr, 1.0)
assert_equal(0, therm_yr)

# Check television
kwh_yr, therm_yr = get_kwh_therm_per_year(model, Constants::ObjectTypeMiscTelevision)
assert_in_delta(957, kwh_yr, 1.0)
assert_in_delta(1003, kwh_yr, 1.0)
assert_equal(0, therm_yr)

# Check vehicle
Expand Down
Loading

0 comments on commit c9f71f3

Please sign in to comment.