Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source "https://rubygems.org"
gemspec

#gem 'openstudio-extension', path: '../OpenStudio-extension-gem'
gem 'buildingsync-measures', path: '../buildingsync-measures-gem'
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
PATH
remote: ../buildingsync-measures-gem
specs:
buildingsync-measures (0.0.1)
bundler (~> 2.4.10)
openstudio-extension (~> 0.9.4)
openstudio-standards (= 0.8.2)

PATH
remote: .
specs:
Expand Down Expand Up @@ -192,6 +200,7 @@ PLATFORMS

DEPENDENCIES
BOSS!
buildingsync-measures!
pry (~> 0.15.2)
rake (~> 13.0)
rspec (~> 3.13)
Expand Down
2 changes: 2 additions & 0 deletions lib/BOSS/boss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_
OSWArgPopulator::populate_set_electric_equipment_loads_by_epd_args(baseline_osw, bsync_reader)
OSWArgPopulator::populate_replace_baseline_windows_args(baseline_osw, bsync_reader)

OSWArgPopulator::populate_modify_envelope_insulation(baseline_osw, bsync_reader)

OSWArgPopulator::populate_openstudio_results_args(baseline_osw, bsync_reader)

# Gather extension-derived paths (typically gem-based measures/files) from ObjectSpace.
Expand Down
121 changes: 101 additions & 20 deletions lib/BOSS/buildingsync_reader/buildingsync_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
require 'openstudio-standards'
require_relative 'systems_map'
require_relative 'bcl_weather_file_downloader'
require_relative 'r_value_and_u_factor_calculator'
include Math
include RValueAndUFactorCalculator


module BOSS
class BuildingSyncReader
Expand Down Expand Up @@ -360,15 +363,11 @@ def get_aspect_ratio
# get principal hvac system type
# @return [String]
def get_principal_HVAC_system_type
BOSS.BOSS_logger.info("|\t|\t- finding first hvac system with principal hvac system type...")
# if no hvac systems, return nil
hvac_systems = @facility_xml.elements.each("#{@ns}Systems/#{@ns}HVACSystems/#{@ns}HVACSystem") {|s| s}
if hvac_systems.nil?
BOSS.BOSS_logger.info("|\t|\t no hvac systems found")
return nil
end
hvac_systems = _get_systems("HVAC", "#{@ns}HVACSystems/#{@ns}HVACSystem")
return nil if hvac_systems.nil? || hvac_systems.empty?

# find first none nil principal_HVAC_system_type
BOSS.BOSS_logger.info("|\t|\t- finding first hvac system with principal hvac system type...")
hvac_systems = hvac_systems.reject {|s| s.class == REXML::Comment}
principal_HVAC_system_type = hvac_systems.map {|s| s.elements["#{@ns}PrincipalHVACSystemType/"]&.text}
first_principal_HVAC_system_type = principal_HVAC_system_type.find {|x| !x.nil?}
Expand All @@ -392,14 +391,11 @@ def get_principal_HVAC_system_type
# @return [String]
def get_total_installed_power
# if no lighting systems, return nil
BOSS.BOSS_logger.info("|\t|\t|\t- finding all lighting system installed power...")
lighting_systems = @facility_xml.elements.each("#{@ns}Systems/#{@ns}LightingSystems/#{@ns}LightingSystem") {|s| s}
if lighting_systems.nil?
BOSS.BOSS_logger.info("|\t|\t|\t no lighting systems found")
return nil
end
lighting_systems = _get_systems("Lighting", "#{@ns}LightingSystems/#{@ns}LightingSystem")
return nil if lighting_systems.nil? || lighting_systems.empty?

# get all all_installed_powers
BOSS.BOSS_logger.info("|\t|\t|\t- finding all lighting system installed power...")
lighting_systems = lighting_systems.reject {|s| s.class == REXML::Comment}
all_installed_powers = lighting_systems.map {|s| s.elements["#{@ns}InstalledPower/"]&.first&.to_s&.to_f}
BOSS.BOSS_logger.info("|\t|\t|\t all lighting system installed power: #{all_installed_powers}")
Expand All @@ -414,13 +410,11 @@ def get_total_installed_power
# @return [String]
def get_total_weighted_average_load
# if no plug_loads, return nil
BOSS.BOSS_logger.info("|\t|\t|\t- finding all plug load systems weighted average load...")
plug_loads = @facility_xml.elements.each("#{@ns}Systems/#{@ns}PlugLoads/#{@ns}PlugLoad") {|s| s}
if plug_loads.nil?
BOSS.BOSS_logger.info("|\t|\t|\t no plug load systems found")
return nil
end
plug_loads = _get_systems("PlugLoad", "#{@ns}PlugLoads/#{@ns}PlugLoad")
return nil if plug_loads.nil? || plug_loads.empty?

# get all weighted_average_loads
BOSS.BOSS_logger.info("|\t|\t|\t- finding all plug load systems weighted average load...")
plug_loads = plug_loads.reject {|s| s.class == REXML::Comment}
all_weighted_average_loads = plug_loads.map {|s| s.elements["#{@ns}WeightedAverageLoad/"]&.text}
BOSS.BOSS_logger.info("|\t|\t|\t all plug load system weighted average load: #{all_weighted_average_loads}")
Expand All @@ -431,6 +425,93 @@ def get_total_weighted_average_load
return all_weighted_average_loads.map {|s| s.to_f}.sum
end


def _get_systems(system_name, system_path)
BOSS.BOSS_logger.info("|\t|\t|\t- finding all #{system_name} systems...")
systems = @facility_xml.elements.each("#{@ns}Systems/#{system_path}") {|s| s}
if systems.nil? || systems.length == 0
BOSS.BOSS_logger.info("|\t|\t|\t no #{system_name} systems found")
end
BOSS.BOSS_logger.info("|\t|\t|\t #{systems.length} #{system_name} systems found")

return systems
end

def _get_section_ids(section_id_path, section_id_name="")
BOSS.BOSS_logger.info("|\t|\t|\t- finding all #{section_id_name} section ids...")
section_ids = @building_xml.elements.each("#{@ns}Sections/#{@ns}Section/#{section_id_path}") {|s| s}
if section_ids.nil? || section_ids.length == 0
BOSS.BOSS_logger.info("|\t|\t|\t no #{section_id_name} section_ids found")
end
BOSS.BOSS_logger.info("|\t|\t|\t #{section_ids.length} #{section_id_name} section_ids found")

return section_ids
end

def _get_target_r_value_and_u_factor(system_name, system_path, section_id_path, section_id_name, area_path, r_value_path, u_factor_path)
# get systems
systems = _get_systems(system_name, system_path)
return nil, nil if systems.nil? || systems.empty?

# get section_id
section_ids = _get_section_ids(section_id_path, section_id_name)
return nil, nil if section_ids.nil? || section_ids.empty?

# check all sections have area
section_ids_missing_area = section_ids.filter {|section_id| section_id.elements["#{@ns}#{area_path}/"].nil?}
if !section_ids_missing_area.empty?
BOSS.BOSS_logger.info("|\t|\t|\t Cannot calculate weighted r_value nor u_factor as these #{section_id_name} do not have an area: #{section_ids_missing_area.map {|s| s.attributes["IDref"]}}")
return nil, nil
end

# pair systems and sections, agg data
data_by_id = zip_envelope_data(section_ids, systems, area_path, r_value_path, u_factor_path, system_name)

# calculate r value
r_value = get_sum_weighted_by_area(data_by_id, "r_value", system_name)

# calculate u factor
u_factor = get_sum_weighted_by_area(data_by_id, "u_factor", system_name=system_name)

return r_value, u_factor
end

def get_wall_target_r_value_and_u_factor
return _get_target_r_value_and_u_factor(
system_name="Wall",
system_path="#{@ns}WallSystems/#{@ns}WallSystem",
section_id_path="#{@ns}Sides/#{@ns}Side/#{@ns}WallIDs/#{@ns}WallID",
section_id_name="Wall",
area_path="#{@ns}WallArea",
r_value_path="#{@ns}WallRValue",
u_factor_path="#{@ns}WallUFactor",
)
end

def get_roof_target_r_value_and_u_factor
return _get_target_r_value_and_u_factor(
system_name="Roof",
system_path="#{@ns}RoofSystems/#{@ns}RoofSystem",
section_id_path="#{@ns}Roofs/#{@ns}Roof/#{@ns}RoofID",
section_id_name="Roof",
area_path="#{@ns}RoofArea",
r_value_path="#{@ns}RoofRValue",
u_factor_path="#{@ns}RoofUFactor",
)
end

def get_floor_target_r_value_and_u_factor
return _get_target_r_value_and_u_factor(
system_name="Foundation",
system_path="#{@ns}FoundationSystems/#{@ns}FoundationSystem",
section_id_path="#{@ns}Foundations/#{@ns}Foundation/#{@ns}FoundationID",
section_id_name="Foundation",
area_path="#{@ns}FoundationArea",
r_value_path="#{@ns}SlabRValue",
u_factor_path="#{@ns}SlabUFactor",
)
end

# first valid window that has all mappable fields
def get_window_data
# if no windows, return nil
Expand All @@ -448,7 +529,7 @@ def get_window_data
glass_type = window.elements["#{@ns}GlassType"]&.text
fenestration_glass_layers = window.elements["#{@ns}FenestrationGlassLayers"]&.text
solar_heat_gain_coefficient = window.elements["#{@ns}SolarHeatGainCoefficient"]&.text
visible_transmittance = window.elements["#{@ns}VisibleTransmittance"]&.text
visible_transmittance = window.elements["#{@ns}VisibleTransmitance"]&.text

# We only need one of fenestration_u_factor/fenestration_r_value
fenestration_u_factor = window.elements["#{@ns}FenestrationUFactor"]&.text
Expand Down
36 changes: 36 additions & 0 deletions lib/BOSS/buildingsync_reader/r_value_and_u_factor_calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module RValueAndUFactorCalculator
def zip_envelope_data(section_ids, systems, area_path, r_value_path, u_factor_path, system_name)
# pair systems and sections, agg data
data_by_id = Hash.new { |h, k| h[k] = {area: 0, r_value: nil, u_factor: nil} }
section_ids.each do |section_id|
id = section_id.attributes["IDref"]
data_by_id[id][:area] += section_id.elements[area_path]&.first&.to_s&.to_f
end
systems.each do |system|
id = system.attributes["ID"]
data_by_id[id][:r_value] = system.elements[r_value_path]&.first&.to_s&.to_f
data_by_id[id][:u_factor] = system.elements[u_factor_path]&.first&.to_s&.to_f
end

BOSS.BOSS_logger.info("|\t|\t|\t- #{system_name} information found: #{data_by_id}")
return data_by_id
end

def get_sum_weighted_by_area(data_by_id, field_to_sum, system_name)
# check all pairs complete
missing_data = data_by_id.filter {|key, value| value[field_to_sum.to_sym].nil?}
# require 'pry'; binding.pry;
if !missing_data.empty?
BOSS.BOSS_logger.info("|\t|\t|\t Cannot calculate weighted #{field_to_sum} as these #{system_name} do not have an #{field_to_sum}: #{missing_data.keys}")

return nil
# calculate weighted average
else
total_area = (data_by_id.map {|k, v| v[:area]}).sum
sum = (data_by_id.map{|k, v| v[field_to_sum.to_sym] * (v[:area] / total_area)}).sum
BOSS.BOSS_logger.info("|\t|\t|\t weighted average of #{field_to_sum} calculated to be #{sum}")

return sum
end
end
end
51 changes: 51 additions & 0 deletions lib/BOSS/osw_arg_populator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,57 @@ def self.populate_replace_baseline_windows_args(osw, bsync_reader)

end

def self.populate_modify_envelope_insulation(osw, bsync_reader)
BOSS.BOSS_logger.info("+++++++++++++++++++++++++++ populating measure modify_envelope_insulation +++++++++++++++++++++++")
osw[:steps].append({"measure_dir_name": "modify_envelope_insulation", "arguments": {}})
set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "modify_envelope_insulation", key, value) }

# Add args
# - __SKIP__
set_measure_argument.call("__SKIP__", false)

BOSS.BOSS_logger.info("|\t- gathering measure requirements...")
BOSS.BOSS_logger.info("|\t|\t- calculating wall r value and u factor...")
wall_target_rvalue, wall_target_uvalue = bsync_reader.get_wall_target_r_value_and_u_factor
BOSS.BOSS_logger.info("|\t|\t- calculating roof r value and u factor...")
roof_target_rvalue, roof_target_uvalue = bsync_reader.get_roof_target_r_value_and_u_factor
BOSS.BOSS_logger.info("|\t|\t- calculating floor r value and u factor...")
floor_target_rvalue, floor_target_uvalue = bsync_reader.get_floor_target_r_value_and_u_factor

# - wall_target_rvalue
BOSS.BOSS_logger.info("|\t- setting arg 'wall_target_rvalue'...")
BOSS.BOSS_logger.info("|\t set to #{wall_target_rvalue}")
set_measure_argument.call("wall_target_rvalue", wall_target_rvalue)

# - wall_target_uvalue
BOSS.BOSS_logger.info("|\t- setting arg 'wall_target_uvalue'...")
BOSS.BOSS_logger.info("|\t set to #{wall_target_uvalue}")
set_measure_argument.call("wall_target_uvalue", wall_target_uvalue)

# - roof_target_rvalue
BOSS.BOSS_logger.info("|\t- setting arg 'roof_target_rvalue'...")
BOSS.BOSS_logger.info("|\t set to #{roof_target_rvalue}")
set_measure_argument.call("roof_target_rvalue", roof_target_rvalue)

# - roof_target_uvalue
BOSS.BOSS_logger.info("|\t- setting arg 'roof_target_uvalue'...")
BOSS.BOSS_logger.info("|\t set to #{roof_target_uvalue}")
set_measure_argument.call("roof_target_uvalue", roof_target_uvalue)

# - floor_target_rvalue
BOSS.BOSS_logger.info("|\t- setting arg 'floor_target_rvalue'...")
BOSS.BOSS_logger.info("|\t set to #{floor_target_rvalue}")
set_measure_argument.call("floor_target_rvalue", floor_target_rvalue)

# - floor_target_uvalue
BOSS.BOSS_logger.info("|\t- setting arg 'floor_target_uvalue'...")
BOSS.BOSS_logger.info("|\t set to #{floor_target_uvalue}")
set_measure_argument.call("floor_target_uvalue", floor_target_uvalue)

BOSS.BOSS_logger.info("++++++++++++++++++++++++++++++++++ populated. +++++++++++++++++++++++++++++++++++++++")
BOSS.BOSS_logger.info("")
end

def self.populate_openstudio_results_args(osw, bsync_reader)
BOSS.BOSS_logger.info("+++++++++++++++++++++++++ populating measure openstudio_results +++++++++++++++++++++")
osw[:steps].append({"measure_dir_name": "openstudio_results", "arguments": {}})
Expand Down
Loading
Loading