Skip to content

Commit

Permalink
Refactor methods around g function jsons, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Sep 20, 2023
1 parent 1c822ef commit 7a57f41
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 39 deletions.
10 changes: 5 additions & 5 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>30bf1bd9-bd3a-4eec-a1aa-6f836ef69eef</version_id>
<version_modified>2023-09-20T22:49:23Z</version_modified>
<version_id>4c36dd4a-e14b-45f7-9020-a309164d58b5</version_id>
<version_modified>2023-09-20T23:55:50Z</version_modified>
<xml_checksum>D8922A73</xml_checksum>
<class_name>HPXMLtoOpenStudio</class_name>
<display_name>HPXML to OpenStudio Translator</display_name>
Expand Down Expand Up @@ -328,13 +328,13 @@
<filename>hvac.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>ED419146</checksum>
<checksum>CF8C283E</checksum>
</file>
<file>
<filename>hvac_sizing.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>A5E9F28C</checksum>
<checksum>46DA5A07</checksum>
</file>
<file>
<filename>lighting.rb</filename>
Expand Down Expand Up @@ -574,7 +574,7 @@
<filename>test_hvac.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>0D6E392F</checksum>
<checksum>88726BBF</checksum>
</file>
<file>
<filename>test_hvac_sizing.rb</filename>
Expand Down
39 changes: 32 additions & 7 deletions HPXMLtoOpenStudio/resources/hvac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3401,16 +3401,41 @@ def self.set_gshp_assumptions(heat_pump, weather)
end
end

def self.valid_borefield_configs
valid_configs = { HPXML::GeothermalLoopBorefieldConfigurationRectangle => { 'num_boreholes' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'filename' => 'rectangle_5m_v1.0.json' },
HPXML::GeothermalLoopBorefieldConfigurationOpenRectangle => { 'num_boreholes' => [8, 10], 'filename' => 'Open_configurations_5m_v1.0.json' },
HPXML::GeothermalLoopBorefieldConfigurationC => { 'num_boreholes' => [7, 9], 'filename' => 'C_configurations_5m_v1.0.json' },
HPXML::GeothermalLoopBorefieldConfigurationL => { 'num_boreholes' => [4, 5, 6, 7, 8, 9, 10], 'filename' => 'L_configurations_5m_v1.0.json' },
HPXML::GeothermalLoopBorefieldConfigurationU => { 'num_boreholes' => [7, 9, 10], 'filename' => 'U_configurations_5m_v1.0.json' },
HPXML::GeothermalLoopBorefieldConfigurationLopsidedU => { 'num_boreholes' => [6, 7, 8, 9, 10], 'filename' => 'LopU_configurations_5m_v1.0.json' } }
def self.valid_bore_configs
valid_configs = { HPXML::GeothermalLoopBorefieldConfigurationRectangle => 'rectangle_5m_v1.0.json',
HPXML::GeothermalLoopBorefieldConfigurationOpenRectangle => 'Open_configurations_5m_v1.0.json',
HPXML::GeothermalLoopBorefieldConfigurationC => 'C_configurations_5m_v1.0.json',
HPXML::GeothermalLoopBorefieldConfigurationL => 'L_configurations_5m_v1.0.json',
HPXML::GeothermalLoopBorefieldConfigurationU => 'U_configurations_5m_v1.0.json',
HPXML::GeothermalLoopBorefieldConfigurationLopsidedU => 'LopU_configurations_5m_v1.0.json' }
return valid_configs
end

def self.get_g_functions_json(g_functions_filename)
require 'json'

g_functions_filepath = File.join(File.dirname(__FILE__), 'g_functions', g_functions_filename)
g_functions_json = JSON.parse(File.read(g_functions_filepath), symbolize_names: true)
return g_functions_json
end

def self.get_valid_num_bores(g_functions_json)
valid_num_bores = []
g_functions_json.each do |_key_1, values_1|
if values_1.keys.include?(:bore_locations)
valid_num_bores << values_1[:bore_locations].size
else
values_1.each do |_key_2, values_2|
if values_2.keys.include?(:bore_locations)
valid_num_bores << values_2[:bore_locations]
end
end
end
end

return valid_num_bores
end

def self.calc_mshp_hspf(cop_47, c_d, capacity_ratio, cfm_tons, fan_power_rated, heat_eir_ft_spec, heat_cap_ft_spec)
n_max = (cop_47.length - 1.0) #-3 # Don't use max speed; FIXME: this is different than calc_mshp_seer?
n_min = 0
Expand Down
23 changes: 7 additions & 16 deletions HPXMLtoOpenStudio/resources/hvac_sizing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1938,14 +1938,16 @@ def self.apply_hvac_ground_loop(hvac_sizing_values, weather, hvac_cooling, clima
bore_config = HPXML::GeothermalLoopBorefieldConfigurationRectangle
end

valid_configs = HVAC.valid_borefield_configs
valid_num_bores = valid_configs[bore_config]['num_boreholes']
valid_configs = HVAC.valid_bore_configs
g_functions_filename = valid_configs[bore_config]
g_functions_json = HVAC.get_g_functions_json(g_functions_filename)
valid_num_bores = HVAC.get_valid_num_bores(g_functions_json)

unless valid_num_bores.include? num_bore_holes
fail "Number of bore holes (#{num_bore_holes}) with borefield configuration '#{bore_config}' not supported."
end

g_functions_filename = valid_configs[bore_config]['filename']
lntts, gfnc_coeff = gshp_gfnc_coeff(bore_config, g_functions_filename, num_bore_holes, bore_spacing, bore_depth, bore_diameter)
lntts, gfnc_coeff = gshp_gfnc_coeff(bore_config, g_functions_json, num_bore_holes, bore_spacing, bore_depth, bore_diameter)

hvac_sizing_values.GSHP_Loop_flow = loop_flow
hvac_sizing_values.GSHP_Bore_Depth = bore_depth
Expand Down Expand Up @@ -2672,12 +2674,7 @@ def self.gshp_hxbore_ft_per_ton(weather, hvac_cooling_ap, bore_spacing, bore_dia
return nom_length_heat, nom_length_cool
end

def self.gshp_gfnc_coeff(bore_config, g_functions_filename, num_bore_holes, bore_spacing, bore_depth, bore_diameter)
require 'json'

g_functions_filepath = File.join(File.dirname(__FILE__), 'g_functions', g_functions_filename)
g_functions_json = JSON.parse(File.read(g_functions_filepath), symbolize_names: true)

def self.gshp_gfnc_coeff(bore_config, g_functions_json, num_bore_holes, bore_spacing, bore_depth, bore_diameter)
actuals = { 'b' => UnitConversions.convert(bore_spacing, 'ft', 'm'),
'h' => UnitConversions.convert(bore_depth, 'ft', 'm'),
'rb' => UnitConversions.convert(bore_diameter / 2.0, 'in', 'm') }
Expand Down Expand Up @@ -2729,12 +2726,8 @@ def self.gshp_gfnc_coeff(bore_config, g_functions_filename, num_bore_holes, bore
correction_factor = Math.log(rb_actual_over_rb)
g_functions = g_functions.map { |v| v - correction_factor }

fail "Found different logtimes for '#{bore_config}' with H=#{h1} and H=#{h2}." if logtimes[0] != logtimes[1]

return logtimes[0], g_functions
end

fail "Could not find gfnc_coeff from '#{g_functions_filename}'."
end

def self.get_g_functions(g_functions_json, bore_config, num_bore_holes, b_h_rb)
Expand Down Expand Up @@ -2763,8 +2756,6 @@ def self.get_g_functions(g_functions_json, bore_config, num_bore_holes, b_h_rb)
end
end
end

fail "Could not find g-values for '#{bore_config}' with '#{num_bore_holes}' boreholes."
end

def self.calculate_average_r_value(surfaces)
Expand Down
26 changes: 15 additions & 11 deletions HPXMLtoOpenStudio/tests/test_hvac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,11 @@ def test_g_function_library_linear_interpolation_example
bore_spacing = UnitConversions.convert(7.0, 'm', 'ft')
bore_depth = UnitConversions.convert(150.0, 'm', 'ft')
bore_diameter = UnitConversions.convert(UnitConversions.convert(80.0, 'mm', 'm'), 'm', 'in') * 2
valid_configs = HVAC.valid_borefield_configs
g_functions_filename = valid_configs[bore_config]['filename']
actual_lntts, actual_gfnc_coeff = HVACSizing.gshp_gfnc_coeff(bore_config, g_functions_filename, num_bore_holes, bore_spacing, bore_depth, bore_diameter)
valid_bore_configs = HVAC.valid_bore_configs
g_functions_filename = valid_bore_configs[bore_config]
g_functions_json = HVAC.get_g_functions_json(g_functions_filename)

actual_lntts, actual_gfnc_coeff = HVACSizing.gshp_gfnc_coeff(bore_config, g_functions_json, num_bore_holes, bore_spacing, bore_depth, bore_diameter)

expected_lntts = [-8.5, -7.8, -7.2, -6.5, -5.9, -5.2, -4.5, -3.963, -3.27, -2.864, -2.577, -2.171, -1.884, -1.191, -0.497, -0.274, -0.051, 0.196, 0.419, 0.642, 0.873, 1.112, 1.335, 1.679, 2.028, 2.275, 3.003]
expected_gfnc_coeff = [2.619, 2.967, 3.279, 3.700, 4.190, 5.107, 6.680, 8.537, 11.991, 14.633, 16.767, 20.083, 22.593, 28.734, 34.345, 35.927, 37.342, 38.715, 39.768, 40.664, 41.426, 42.056, 42.524, 43.054, 43.416, 43.594, 43.885]
Expand All @@ -762,14 +764,16 @@ def test_g_function_library_linear_interpolation_example
end

def test_all_g_function_configs_exist
require 'json'

valid_configs = HVAC.valid_borefield_configs
valid_configs.each do |bore_config, num_boreholes_and_filename|
valid_num_bores = num_boreholes_and_filename['num_boreholes']
g_functions_filename = num_boreholes_and_filename['filename']
g_functions_filepath = File.join(File.dirname(__FILE__), '../resources/g_functions', g_functions_filename)
g_functions_json = JSON.parse(File.read(g_functions_filepath), symbolize_names: true)
valid_configs = { HPXML::GeothermalLoopBorefieldConfigurationRectangle => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
HPXML::GeothermalLoopBorefieldConfigurationOpenRectangle => [8, 10],
HPXML::GeothermalLoopBorefieldConfigurationC => [7, 9],
HPXML::GeothermalLoopBorefieldConfigurationL => [4, 5, 6, 7, 8, 9, 10],
HPXML::GeothermalLoopBorefieldConfigurationU => [7, 9, 10],
HPXML::GeothermalLoopBorefieldConfigurationLopsidedU => [6, 7, 8, 9, 10] }

valid_configs.each do |bore_config, valid_num_bores|
g_functions_filename = HVAC.valid_bore_configs[bore_config]
g_functions_json = HVAC.get_g_functions_json(g_functions_filename)
valid_num_bores.each do |num_bore_holes|
HVACSizing.get_g_functions(g_functions_json, bore_config, num_bore_holes, '5._192._0.08') # b_h_rb is arbitrary
end
Expand Down

0 comments on commit 7a57f41

Please sign in to comment.