diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac19f54..bbf00d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,10 @@ concurrency: group: ci-${{ github.ref }} cancel-in-progress: true +env: + # Pinned commit of the sibling checkout that config/external_measure_repos.yml loads via local_path. + BSYNC_MEASURES_REF: 789bd50ec0ba42559f85e5cac23fcbbf8f9bdfbe + jobs: unit: name: unit @@ -25,17 +29,29 @@ jobs: env: LANG: C.UTF-8 LC_ALL: C.UTF-8 + defaults: + run: + working-directory: BOSS steps: - name: Checkout Code uses: actions/checkout@v4 + with: + path: BOSS + # Not released as a gem; config/external_measure_repos.yml loads it from ../buildingsync-measures-gem. + - name: Checkout buildingsync-measures-gem + uses: actions/checkout@v4 + with: + repository: BuildingSync/buildingsync-measures-gem + ref: ${{ env.BSYNC_MEASURES_REF }} + path: buildingsync-measures-gem - name: Cache gems uses: actions/cache@v4 with: path: .bundle/install - key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('Gemfile.lock', '*.gemspec') }} + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('BOSS/Gemfile.lock', 'BOSS/*.gemspec') }} - name: Setup run: | - git config --global --add safe.directory "$GITHUB_WORKSPACE" + git config --global --add safe.directory '*' gem install bundler -v 2.4.10 bundle config set --local path "$GITHUB_WORKSPACE/.bundle/install" bundle install @@ -90,19 +106,30 @@ jobs: LC_ALL: C.UTF-8 BOSS_SHARD: ${{ matrix.shard }} BOSS_SHARDS: '4' + defaults: + run: + working-directory: BOSS steps: - name: Checkout Code uses: actions/checkout@v4 + with: + path: BOSS + - name: Checkout buildingsync-measures-gem + uses: actions/checkout@v4 + with: + repository: BuildingSync/buildingsync-measures-gem + ref: ${{ env.BSYNC_MEASURES_REF }} + path: buildingsync-measures-gem - name: Cache gems uses: actions/cache@v4 with: path: .bundle/install - key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('Gemfile.lock', '*.gemspec') }} + key: gems-${{ runner.os }}-os3.10.0-${{ hashFiles('BOSS/Gemfile.lock', 'BOSS/*.gemspec') }} - name: Cache external measures uses: actions/cache@v4 with: - path: vendor/external_measures - key: ext-measures-${{ hashFiles('config/external_measure_repos.yml') }} + path: BOSS/vendor/external_measures + key: ext-measures-${{ hashFiles('BOSS/config/external_measure_repos.yml') }} - name: Setup run: | git config --global --add safe.directory '*' @@ -117,4 +144,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: integration-output-shard-${{ matrix.shard }} - path: spec/output + path: BOSS/spec/output diff --git a/README.md b/README.md index b598c6f..540c0cb 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ The shipped manifest lives at [config/external_measure_repos.yml](config/externa - local measure roots: `lib/measures` (first in precedence) - external repository: comstock (`measures` and `resources/measures`) +- local checkout: `buildingsync-measures-gem` (`lib/measures`), expected as a sibling of this repository (`../buildingsync-measures-gem`). It is marked `scenario_only` and is added to `measure_paths` only for baselines that use an HVAC topology. CI pins its commit via `BSYNC_MEASURES_REF` in [.github/workflows/ci.yml](.github/workflows/ci.yml). Measure path precedence is: @@ -46,6 +47,40 @@ Measure path precedence is: The generated `in.osw` will include these paths in order under `measure_paths`. +### Baseline HVAC + +When the facility's detailed (L200) `HVACSystems` exactly match a supported topology, the baseline sets `create_typical_building_from_model`'s `add_hvac` to `false` and adds `apply_hvac_topology_to_zone_scope` (operation `create`) and `apply_standard_hvac_sizing_and_efficiency` from buildingsync-measures-gem. Supported templates are DOE Ref Pre-1980, DOE Ref 1980-2004, and 90.1-2004 through 90.1-2019. HVAC systems referenced by measures as proposed (`AlternativeSystemReplacement` or `ModifiedSystem`) are excluded from the baseline. + +Configurations that can produce a topology baseline: + +| Configuration | Topology measure | +|---|---| +| Packaged Terminal Air Conditioner | `hvac_ptac` | +| Packaged Terminal Heat Pump | `hvac_pthp` | +| Four Pipe Fan Coil Unit | `hvac_four_pipe_fan_coil` | +| Packaged Rooftop Air Conditioner | `hvac_packaged_rooftop_ac` | +| Packaged Rooftop Heat Pump | `hvac_packaged_rooftop_heat_pump` | +| Packaged Rooftop VAV with Hot Water Reheat | `hvac_packaged_rooftop_vav_hw_reheat` | +| VAV with Hot Water Reheat | `hvac_vav_hw_reheat` | +| Warm Air Furnace | `hvac_warm_air_furnace` | +| VRF Terminal Unit | `hvac_vrf` | + +A Ventilation Only (`hvac_ventilation_only`) or Dedicated Outdoor Air System (`hvac_doas`) configuration can be added on top, but only alongside PTAC, PTHP, four-pipe fan coil, or VRF. + +Recognized but not yet mapped (always fall back): Packaged Rooftop VAV with Electric Reheat, VAV with Electric Reheat, Water Loop Heat Pump, Ground Source Heat Pump, Chilled Beam, and hydronic radiant systems. + +BOSS also falls back when: + +- any selected `HVACSystem` does not match a supported configuration; +- there is not exactly one conditioning configuration, or there is more than one ventilation configuration; +- ventilation is paired with a conditioning type that does not allow it; +- the template is not supported; +- a system's premises are scoped to specific zones rather than the whole building (the baseline binds topologies to all model zones only). + +On fallback, BOSS uses the `system_type` mapping below with `add_hvac` set to `true`, and logs a warning explaining why. + +Integration simulations currently cover the packaged rooftop heat pump; the other configurations are covered by unit specs. + ## OpenStudio Compatibility Version | OpenStudio Version | BuildingSync Version | BOSS Version | @@ -96,7 +131,7 @@ The table below maps in detail the BuildingSync XML data to measure inputs. Note | | template | get_standard_template | either `.../Building/YearOfLastMajorRemodel` or `.../Building/YearOfConstruction` | | | system_type | get_principal_HVAC_system_type | at least one mappable entry of `.../Systems/HVACSystems/HVACSystem/PrincipalHVACSystemType` | | | add_swh | | Hard Coded to to true | -| | add_hvac | | Hard Coded to to true | +| | add_hvac | | `true` for fallback baselines; `false` when an HVAC topology is applied (see [Baseline HVAC](#baseline-hvac)) | | [SetLightingLoadsByLPD] | | | | | | lpd | get_total_installed_power | `/InstalledPower` in ALL instances of `.../Systems/LightingSystems/LightingSystem` | | [set_electric_equipment_loads_by_epd] | | | | diff --git a/config/external_measure_repos.yml b/config/external_measure_repos.yml index 212bbcd..1ce9655 100644 --- a/config/external_measure_repos.yml +++ b/config/external_measure_repos.yml @@ -14,7 +14,12 @@ local_measure_roots: # - name: local checkout folder name under vendor/external_measures # - url: git repository URL # - ref: pinned tag/branch/commit to checkout +# - local_path (instead of url/ref): existing local checkout, relative to this file. +# BOSS uses it in place and never runs Git against it; a missing path is an error. # - measure_roots: one or more paths inside the repo that contain measure directories +# - scenario_only (optional, default false): when true, measure roots are added only to +# workflows that opt in (baseline/in.osw with a detailed HVAC topology); fallback +# baselines omit them, so they do not require this checkout # # The below measures are needed for the BOSS L200 workflow. @@ -25,3 +30,11 @@ repos: measure_roots: - measures - resources/measures + + # BuildingSync HVAC topology measures. Not released as a gem, so BOSS + # loads the sibling checkout ../buildingsync-measures-gem (CI pins its commit). + - name: buildingsync-measures-gem + local_path: ../../buildingsync-measures-gem + measure_roots: + - lib/measures + scenario_only: true diff --git a/lib/BOSS/baseline_hvac_planner.rb b/lib/BOSS/baseline_hvac_planner.rb new file mode 100644 index 0000000..a1e9666 --- /dev/null +++ b/lib/BOSS/baseline_hvac_planner.rb @@ -0,0 +1,148 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/hvac_topology_selector' +require 'BOSS/hvac_target_binder' + +module BOSS + # Decides whether the baseline builds HVAC from split topology measures or keeps + # create_typical_building_from_model HVAC. + # + # Every binder step resolves to all model zones, so a topology plan allows one + # conditioning configuration plus, for zone-equipment configurations only, one + # ventilation configuration (DOAS create rejects zones already on an air loop). + # Results with the same measure and measure arguments are one configuration. Its + # Section links count as whole-building when they cover the building's sections. + class BaselineHvacPlanner + SIZING_MEASURE = 'apply_standard_hvac_sizing_and_efficiency' + VENTILATION_MEASURES = HvacTopologySelector::VENTILATION_MEASURES.values.map(&:last).freeze + ZONE_EQUIPMENT_MEASURES = ['hvac_ptac', 'hvac_pthp', 'hvac_four_pipe_fan_coil', 'hvac_vrf'].freeze + + Plan = Struct.new(:status, :steps, :messages, keyword_init: true) do + def topology? = status == :topology + end + + def initialize(selector: HvacTopologySelector.new, binder: HvacTargetBinder.new) + @selector = selector + @binder = binder + end + + # @param hvac_systems [REXML::Element, nil] the facility HVACSystems element + # @param standards_template [String] baseline create_typical template + # @param operation [String] binder operation for the conditioning step; ventilation is always created + # @param include_system_ids [Array, nil] when given, only these HVACSystems are planned + # @param exclude_system_ids [Array] HVACSystems left out, such as proposed scenario systems + # @return [Plan] :topology with ordered OSW steps, or :fallback with the reasons + def plan(hvac_systems, standards_template, operation: 'create', include_system_ids: nil, exclude_system_ids: []) + return fallback(['No HVACSystems in the facility.']) if hvac_systems.nil? + + if !HvacTargetBinder::STANDARDS_TEMPLATES.include?(standards_template) + return fallback(["Template '#{standards_template}' is not supported by the split HVAC measures " \ + "(#{HvacTargetBinder::STANDARDS_TEMPLATES.join(', ')})."]) + end + + results = @selector.select(hvac_systems).select do |result| + (include_system_ids.nil? || include_system_ids.include?(result.hvac_system_id)) && + !exclude_system_ids.include?(result.hvac_system_id) + end + return fallback(['No HVACSystem records.']) if results.empty? + + unmatched = results.reject { |result| result.status == :match } + return fallback(unmatched.map { |result| describe(result, result.status, result.messages) }) if !unmatched.empty? + + groups = results.group_by { |result| [result.measure, result.measure_arguments || {}] }.values + .map { |members| merge(members, hvac_systems) } + ventilation, conditioning = groups.partition { |result| VENTILATION_MEASURES.include?(result.measure) } + problems = [] + if conditioning.length != 1 + problems << "Expected one conditioning configuration, found #{conditioning.length}; " \ + 'zone-level binding is not supported.' + end + problems << "Expected at most one ventilation configuration, found #{ventilation.length}." if ventilation.length > 1 + if !ventilation.empty? && conditioning.length == 1 && !ZONE_EQUIPMENT_MEASURES.include?(conditioning.first.measure) + problems << "#{ventilation.first.configuration} cannot be added to zones served by " \ + "#{conditioning.first.configuration} air loops." + end + return fallback(problems) if !problems.empty? + + bindings = conditioning.map { |result| [result, @binder.bind(result, operation:, standards_template:)] } + + ventilation.map { |result| [result, @binder.bind(result, operation: 'create', standards_template:)] } + unbound = bindings.reject { |_, binding| binding.status == :bound } + return fallback(unbound.map { |result, binding| describe(result, binding.status, binding.messages) }) if !unbound.empty? + + sizing_step = { measure_dir_name: SIZING_MEASURE, arguments: { standards_template: } } + Plan.new(status: :topology, steps: bindings.map { |_, binding| binding.step } + [sizing_step], messages: []) + end + + # @return [Array] HVACSystem IDs that measures name as alternatives or modified systems + def self.proposed_system_ids(hvac_systems) + return [] if hvac_systems.nil? + + system_ids = _system_ids(hvac_systems) + refs = REXML::XPath.match( + hvac_systems.document, + "//*[local-name()='Measure']/*[local-name()='TypeOfMeasure']//" \ + "*[local-name()='AlternativeSystemReplacement' or local-name()='ModifiedSystem']/@IDref" + ).map(&:value) + refs.uniq & system_ids + end + + def self._system_ids(hvac_systems) + REXML::XPath.match(hvac_systems, "*[local-name()='HVACSystem']/@ID").map(&:value) + end + + # @return [Array] premises, or one Building premise when Section links cover the building + def self.normalize_premises(premises, document) + building_id = covered_building_id(premises, document) + building_id ? [{ type: 'Building', id: building_id }] : premises + end + + # @return [String, nil] the building ID when every premise is a Section of the one + # building and they include its 'Whole building' section or all of its other + # non-empty sections + def self.covered_building_id(premises, document) + return nil if premises.empty? || !premises.all? { |premise| premise[:type] == 'Section' } + + buildings = REXML::XPath.match(document, "//*[local-name()='Building'][@ID]") + return nil if buildings.length != 1 + + sections = REXML::XPath.match(buildings.first, "*[local-name()='Sections']/*[local-name()='Section'][@ID]") + section_ids = sections.map { |section| section.attributes['ID'] } + linked = premises.map { |premise| premise[:id] } + return nil if !(linked - section_ids).empty? + + whole, parts = sections.partition do |section| + REXML::XPath.first(section, "*[local-name()='SectionType']")&.text == 'Whole building' + end + whole_linked = whole.any? { |section| linked.include?(section.attributes['ID']) } + parts_linked = !parts.empty? && parts.all? do |section| + section.elements.empty? || linked.include?(section.attributes['ID']) + end + whole_linked || parts_linked ? buildings.first.attributes['ID'] : nil + end + + private + + def merge(members, hvac_systems) + merged = members.first.dup + merged.premises = self.class.normalize_premises(members.flat_map { |member| member.premises || [] }.uniq, + hvac_systems.document) + merged + end + + def fallback(messages) + Plan.new(status: :fallback, steps: [], messages:) + end + + def describe(result, status, messages) + label = result.configuration || result.hvac_system_id || 'HVACSystem' + "#{label} (#{status}): #{messages.join(' ')}" + end + end +end diff --git a/lib/BOSS/boss.rb b/lib/BOSS/boss.rb index f998e7f..69a1085 100644 --- a/lib/BOSS/boss.rb +++ b/lib/BOSS/boss.rb @@ -10,6 +10,7 @@ require 'BOSS/buildingsync_reader/buildingsync_reader' require 'BOSS/osw_arg_populator' require 'BOSS/external_measure_repo_manager' +require 'BOSS/baseline_hvac_planner' require 'openstudio/common_measures' require 'openstudio/model_articulation' @@ -35,6 +36,43 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_ bsync_doc = REXML::Document.new(xml_data, ignore_whitespace_nodes: :all) bsync_reader = BOSS::BuildingSyncReader.new(bsync_doc, epw_file_path, standard_to_be_used) + baseline_osw = build_baseline_osw(bsync_reader) + + # write to file + workflow_dir = File.join(output_dir, 'baseline') + FileUtils.mkdir_p(workflow_dir) + osw_path = File.join(workflow_dir, 'in.osw') + File.open(osw_path, 'w') do |file| + file << JSON.pretty_generate(baseline_osw) + end + osw_path + end + + # @param osw_dir [String] path to osws + def run_baseline_osw(osw_dir) + # assert we have a baseline osm + baseline_osw_path = File.join(osw_dir, 'baseline', 'in.osw') + + # assert baseline exist + if !File.file?(baseline_osw_path) + error_message = ( + "this function requires #{baseline_osw_path}, which does not exist. "\ + "Create #{baseline_osw_path} with `write_baseline_osw` and try again." + ) + OpenStudio.logFree(OpenStudio::Error, 'BOSS.Boss.run_baseline_osw', error_message) + raise StandardError, "BOSS.Boss.run_baseline_osw: #{error_message}" + end + + runner = OpenStudio::Extension::Runner.new(dirname = Dir.pwd, bundle_without = [], options = { run_simulations: true, verbose: false, num_parallel: 7, max_to_run: Float::INFINITY }) + + # run the baseline osm + return runner.run_osws([baseline_osw_path]) + end + + private + + # Returns a new, unsaved baseline OSW hash for the given reader. + def build_baseline_osw(bsync_reader) # start with an empty baseline workflow file = File.read(EMPTY_BASELINE_OSW_PATH) baseline_osw = JSON.parse(file, symbolize_names: true) @@ -44,7 +82,18 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_ OSWArgPopulator::populate_change_building_location_args(baseline_osw, bsync_reader) OSWArgPopulator::populate_create_bar_from_building_type_ratios_args(baseline_osw, bsync_reader) - OSWArgPopulator::populate_create_typical_building_from_model_args(baseline_osw, bsync_reader) + hvac_systems = bsync_reader.get_hvac_systems_xml + hvac_plan = BaselineHvacPlanner.new.plan(hvac_systems, bsync_reader.get_standard_template, + exclude_system_ids: BaselineHvacPlanner.proposed_system_ids(hvac_systems)) + OSWArgPopulator::populate_create_typical_building_from_model_args(baseline_osw, bsync_reader, + add_hvac: !hvac_plan.topology?) + if hvac_plan.topology? + hvac_plan.steps.each { |step| OSWArgPopulator.append_step(baseline_osw, step) } + else + hvac_plan.messages.each do |message| + BOSS.BOSS_logger.warn("BOSS.Boss: Keeping create_typical_building_from_model HVAC: #{message}") + end + end OSWArgPopulator::populate_set_lighting_loads_by_LPD_args(baseline_osw, bsync_reader) OSWArgPopulator::populate_set_electric_equipment_loads_by_epd_args(baseline_osw, bsync_reader) @@ -58,7 +107,8 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_ # Force ordering: local BOSS measures, extension-discovered (gems), then external repos. manager = ExternalMeasureRepoManager.new local_measure_dirs = manager.local_measure_directories - external_measure_dirs = manager.resolved_measure_directories + # Topology HVAC steps need buildingsync-measures-gem, which fallback baselines omit. + external_measure_dirs = manager.resolved_measure_directories(include_scenario_only: hvac_plan.topology?) discovered_measure_dirs = baseline_osw[:measure_paths] || [] discovered_nonlocal_nonexternal = discovered_measure_dirs.reject do |path| @@ -77,39 +127,9 @@ def write_baseline_osw(xml_file_path, output_dir, epw_file_path, standard_to_be_ baseline_osw[:file_paths] = ordered_unique(local_file_paths + discovered_file_nonlocal_nonexternal + external_file_paths) - # write to file - workflow_dir = File.join(output_dir, 'baseline') - FileUtils.mkdir_p(workflow_dir) - osw_path = File.join(workflow_dir, 'in.osw') - File.open(osw_path, 'w') do |file| - file << JSON.pretty_generate(baseline_osw) - end - osw_path + baseline_osw end - # @param osw_dir [String] path to osws - def run_baseline_osw(osw_dir) - # assert we have a baseline osm - baseline_osw_path = File.join(osw_dir, 'baseline', 'in.osw') - - # assert baseline exist - if !File.file?(baseline_osw_path) - error_message = ( - "this function requires #{baseline_osw_path}, which does not exist. "\ - "Create #{baseline_osw_path} with `write_baseline_osw` and try again." - ) - OpenStudio.logFree(OpenStudio::Error, 'BOSS.Boss.run_baseline_osw', error_message) - raise StandardError, "BOSS.Boss.run_baseline_osw: #{error_message}" - end - - runner = OpenStudio::Extension::Runner.new(dirname = Dir.pwd, bundle_without = [], options = { run_simulations: true, verbose: false, num_parallel: 7, max_to_run: Float::INFINITY }) - - # run the baseline osm - return runner.run_osws([baseline_osw_path]) - end - - private - def measure_path_to_files_path(measure_path) path = measure_path.to_s replaced = path.sub(%r{/measures/?$}, '/files') diff --git a/lib/BOSS/buildingsync_reader/buildingsync_reader.rb b/lib/BOSS/buildingsync_reader/buildingsync_reader.rb index 0b9f29b..91ce430 100644 --- a/lib/BOSS/buildingsync_reader/buildingsync_reader.rb +++ b/lib/BOSS/buildingsync_reader/buildingsync_reader.rb @@ -360,6 +360,11 @@ def get_aspect_ratio return aspect_ratio.to_f end + # @return [REXML::Element, nil] the facility HVACSystems element + def get_hvac_systems_xml + @facility_xml.elements["#{@ns}Systems/#{@ns}HVACSystems"] + end + # get principal hvac system type # @return [String] def get_principal_HVAC_system_type diff --git a/lib/BOSS/external_measure_repo_manager.rb b/lib/BOSS/external_measure_repo_manager.rb index c4aa967..62ada89 100644 --- a/lib/BOSS/external_measure_repo_manager.rb +++ b/lib/BOSS/external_measure_repo_manager.rb @@ -47,15 +47,24 @@ def install_all install_repo(repo_entry) end - resolved_measure_directories + resolved_measure_directories(include_scenario_only: true) end - def resolved_measure_directories + # Repos marked scenario_only: true are omitted by default (fallback baselines) and are + # only returned when include_scenario_only is true (e.g. HVAC topology baselines). + def resolved_measure_directories(include_scenario_only: false) return [] if !manifest_exists? directories = [] repo_entries.each do |repo_entry| + next if repo_entry['scenario_only'] && !include_scenario_only + repo_root = repo_checkout_dir(repo_entry) + if local_repo?(repo_entry) && !Dir.exist?(repo_root) + raise StandardError, "Local measure repository '#{repo_entry['name']}' not found at #{repo_root}. " \ + "Check out the repository there or update local_path in #{@manifest_path}." + end + if !Dir.exist?(repo_root) message = "Repository '#{repo_entry['name']}' is not installed at #{repo_root}. Run rake measures:install_external." if defined?(OpenStudio) && OpenStudio.respond_to?(:logFree) @@ -110,7 +119,7 @@ def validate_repo_entry(repo) raise StandardError, "Each repo entry in #{@manifest_path} must be a map" end - required = %w[name url ref measure_roots] + required = repo.key?('local_path') ? %w[name local_path measure_roots] : %w[name url ref measure_roots] missing = required.select { |key| repo[key].nil? || repo[key].to_s.empty? } if !missing.empty? raise StandardError, "Repo entry is missing required keys #{missing.join(', ')} in #{@manifest_path}" @@ -124,10 +133,29 @@ def validate_repo_entry(repo) if !repo['measure_roots'].is_a?(Array) || repo['measure_roots'].empty? raise StandardError, "Repo '#{repo['name']}' must define a non-empty measure_roots array" end + + if repo.key?('local_path') && (repo.key?('url') || repo.key?('ref')) + raise StandardError, "Repo '#{repo['name']}' must use either local_path or url/ref, not both" + end + + if repo.key?('scenario_only') && ![true, false].include?(repo['scenario_only']) + raise StandardError, "Repo '#{repo['name']}' scenario_only must be true or false" + end + repo end + # Local checkouts are used in place; BOSS never runs Git against them. def install_repo(repo_entry) + if local_repo?(repo_entry) + repo_dir = repo_checkout_dir(repo_entry) + if !Dir.exist?(repo_dir) + raise StandardError, "Local measure repository '#{repo_entry['name']}' not found at #{repo_dir}. " \ + "Check out the repository there or update local_path in #{@manifest_path}." + end + return + end + repo_dir = repo_checkout_dir(repo_entry) measure_roots = repo_entry['measure_roots'] @@ -144,7 +172,13 @@ def install_repo(repo_entry) run_git(%W[-C #{repo_dir} checkout --force FETCH_HEAD]) end + def local_repo?(repo_entry) + repo_entry.key?('local_path') + end + def repo_checkout_dir(repo_entry) + return File.expand_path(repo_entry['local_path'], File.dirname(File.expand_path(@manifest_path))) if local_repo?(repo_entry) + File.join(@install_dir, repo_entry['name']) end diff --git a/lib/BOSS/hvac_target_binder.rb b/lib/BOSS/hvac_target_binder.rb new file mode 100644 index 0000000..a5270d2 --- /dev/null +++ b/lib/BOSS/hvac_target_binder.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'json' + +module BOSS + # Binds a matched HvacTopologySelector result to model zones. + # + # BOSS baseline geometry is generated (create_bar_from_building_type_ratios), so model zones + # have no BuildingSync IDs. Whole-building premises resolve to every model zone at run time + # through buildingsync-measures-gem apply_hvac_topology_to_zone_scope. Other premises bind only + # when the caller passes the exact model zone names; otherwise they return :missing_input. + class HvacTargetBinder + BINDING_MEASURE = 'apply_hvac_topology_to_zone_scope' + WHOLE_BUILDING_PREMISES = ['Building', 'Site', 'Facility'].freeze + STANDARDS_TEMPLATES = ['DOE Ref Pre-1980', 'DOE Ref 1980-2004', '90.1-2004', '90.1-2007', '90.1-2010', + '90.1-2013', '90.1-2016', '90.1-2019'].freeze + OPERATIONS = ['create', 'replace'].freeze + + Binding = Struct.new(:status, :step, :messages, keyword_init: true) + + # @param result [HvacTopologySelector::Result] + # @param operation [String] 'create' or 'replace' + # @param standards_template [String] one of STANDARDS_TEMPLATES + # @param zone_names [Array, nil] exact model zone names for the result's premises; + # when given, the step uses zone_scope explicit_zone_names instead of all_model_zones + # @return [Binding] status :bound with an OSW step spec, or the reason it cannot bind + def bind(result, operation:, standards_template:, zone_names: nil) + raise ArgumentError, "Unsupported operation '#{operation}'" if !OPERATIONS.include?(operation) + if !STANDARDS_TEMPLATES.include?(standards_template) + raise ArgumentError, "Unsupported standards_template '#{standards_template}'" + end + if !zone_names.nil? && (zone_names.empty? || !zone_names.all? { |name| name.is_a?(String) && !name.strip.empty? }) + raise ArgumentError, 'zone_names must be a non-empty array of non-empty strings' + end + return Binding.new(status: result.status, step: nil, messages: result.messages) if result.status != :match + return Binding.new(status: :bound, step: step(result, operation, standards_template, zone_names), messages: []) if zone_names + + unbound = result.premises.reject { |premise| WHOLE_BUILDING_PREMISES.include?(premise[:type]) } + if result.premises.empty? || !unbound.empty? + refs = unbound.map { |premise| "#{premise[:type]} #{premise[:id]}" } + return Binding.new( + status: :missing_input, step: nil, + messages: ["#{result.configuration} links #{refs.empty? ? 'no premises' : refs.join(', ')}; " \ + 'only whole-building premises can be bound to generated baseline zones.'] + ) + end + + Binding.new(status: :bound, step: step(result, operation, standards_template, nil), messages: []) + end + + private + + def step(result, operation, standards_template, zone_names) + scope = zone_names ? { zone_scope: 'explicit_zone_names', zone_names_json: JSON.generate(zone_names.uniq) } : { zone_scope: 'all_model_zones' } + arguments = { topology_measure: result.measure, operation: operation, **scope, standards_template: standards_template } + extra = result.measure_arguments || {} + arguments[:topology_arguments_json] = JSON.generate(extra) if !extra.empty? + { measure_dir_name: BINDING_MEASURE, arguments: arguments } + end + end +end diff --git a/lib/BOSS/hvac_topology_selector.rb b/lib/BOSS/hvac_topology_selector.rb new file mode 100644 index 0000000..a3dc8f1 --- /dev/null +++ b/lib/BOSS/hvac_topology_selector.rb @@ -0,0 +1,765 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' + +module BOSS + # Selects split HVAC topology measures from detailed BuildingSync HVACSystem data using + # the predicates in buildingsync-measures-gem docs/HVAC_MAPPING_AND_MIGRATION.md. + # + # Every conditioning Delivery and every OtherHVACSystem yields exactly one Result, so no + # constituent is dropped. Model zone resolution, call grouping, and quantity-vs-zone-count + # guards need the model crosswalk and are left to later steps; results carry the + # LinkedPremises references and a group_key for that work. + class HvacTopologySelector + STATUSES = [:match, :mapping_gap, :not_mappable, :missing_input, :conflicting_input, :no_hvac, :integrated].freeze + + # measure_arguments holds topology-measure arguments derived from the data (beyond operation, + # zones, and template), e.g. { 'supplemental_heating_fuel' => 'NaturalGas' }. + Result = Struct.new(:status, :configuration, :measure, :hvac_system_id, :record_ids, :premises, + :group_key, :messages, :measure_arguments, keyword_init: true) + + # Element accessors and predicates for one Delivery. Paths are '/'-separated local names, + # so namespace prefixes do not matter. + class Context + attr_reader :sys, :d, :hs, :cs, :conflicts + + def initialize(sys, delivery, index) + @sys = sys + @d = delivery + @index = index + @conflicts = [] + @hs = resolve_one(delivery, 'HeatingSourceID', :heating_source) + @cs = resolve_one(delivery, 'CoolingSourceID', :cooling_source) + end + + def self.nodes(el, path) + return [] if el.nil? + + path.split('/').reduce([el]) do |current, name| + current.flat_map { |node| node.elements.to_a.select { |child| child.name == name } } + end + end + + def self.texts(el, path) + nodes(el, path).map { |node| node.text.to_s.strip } + end + + def nodes(el, path) = self.class.nodes(el, path) + def node(el, path) = nodes(el, path).first + def exists(el, path) = !nodes(el, path).empty? + def absent(el, path) = nodes(el, path).empty? + + def eq(el, path, value) + values = self.class.texts(el, path) + !values.empty? && values.all? { |v| v == value } + end + + def one_of(el, path, allowed) + values = self.class.texts(el, path) + !values.empty? && values.all? { |v| allowed.include?(v) } + end + + # Guards are optional: they pass when the element is absent. + def guard(el, path, allowed) + values = self.class.texts(el, path) + values.empty? || values.all? { |v| Array(allowed).include?(v) } + end + + def quantity_guard(el, path) + values = self.class.texts(el, path) + values.empty? || values.all? { |v| Integer(v, exception: false) == 1 } + end + + def ref_ids(el, path) + nodes(el, path).map { |n| n.attributes['IDref'] } + end + + # Exactly one reference resolving to a record of the given kind, else nil plus a conflict. + def resolve_one(el, path, kind) + ids = ref_ids(el, path) + return nil if ids.empty? + + if ids.length > 1 + @conflicts << "#{el.attributes['ID'] || el.name}/#{path} has #{ids.length} references; expected one" + return nil + end + record = @index.dig(kind, ids.first) + @conflicts << "#{el.attributes['ID'] || el.name}/#{path} '#{ids.first}' does not resolve to a #{kind}" if record.nil? + record + end + + def hc = node(@sys, 'HeatingAndCoolingSystems') + def z = node(@d, 'DeliveryType/ZoneEquipment') + def a = node(@d, 'DeliveryType/CentralAirDistribution') + def h = node(@hs, 'HeatingSourceType') + def c = node(@cs, 'CoolingSourceType') + def dx = node(c, 'DX') + def fc = node(z, 'FanBased/FanBasedDistributionType/FanCoil') + def mv(other) = node(other, 'OtherHVACType/MechanicalVentilation') + + def hp = memo(:hp) { h && resolve_one(h, 'SourceHeatingPlantID', :heating_plant) } + def cp = memo(:cp) { c && resolve_one(c, 'CoolingPlantID', :cooling_plant) } + def cn_dx = memo(:cn_dx) { dx && resolve_one(dx, 'CondenserPlantIDs/CondenserPlantID', :condenser_plant) } + + def cn_chiller + memo(:cn_chiller) do + chiller = node(cp, 'Chiller') + chiller && resolve_one(chiller, 'CondenserPlantIDs/CondenserPlantID', :condenser_plant) + end + end + + # Resolves each reference once so a broken reference is reported once. + def memo(key) + @memo ||= {} + @memo[key] = yield unless @memo.key?(key) + @memo[key] + end + + def cs_id = @cs&.attributes&.[]('ID') + + def heat_pump_shares_cs + ids = ref_ids(h, 'HeatPump/CoolingSourceID') + ids.length == 1 && !cs_id.nil? && ids.first == cs_id + end + + def air_cooled_dx + cn = cn_dx + !cn.nil? && exists(cn, 'AirCooled') && absent(cn, 'AirCooled/EvaporativelyCooledCondenser') + end + + # Packaged and terminal DX units are self-contained air-cooled units, so an omitted + # condenser reference reads as air-cooled. VRF keeps the strict air_cooled_dx check. + def packaged_air_cooled_dx + absent(dx, 'CondenserPlantIDs') || air_cooled_dx + end + + def gas_hot_water_plant + eq(hs, 'HeatingMedium', 'Hot water') && !hp.nil? && + eq(hp, 'Boiler/BoilerType', 'Hot water') && eq(hp, 'PrimaryFuel', 'Natural gas') + end + + def tower_chiller_plant + eq(cs, 'CoolingMedium', 'Chilled water') && !cp.nil? && + eq(cp, 'Chiller/ChillerType', 'Vapor compression') && + eq(cp, 'Chiller/ChillerCompressorDriver', 'Electric Motor') && !cn_chiller.nil? && + eq(cn_chiller, 'WaterCooled/WaterCooledCondenserType', 'Cooling tower') && + absent(cn_chiller, 'WaterCooled/WaterSideEconomizer') + end + + def single_zone_cav + exists(@d, 'DeliveryType/CentralAirDistribution') && eq(a, 'AirDeliveryType', 'Central fan') && + eq(a, 'TerminalUnit', 'CAV terminal box no reheat') && eq(a, 'ReheatSource', 'None') && + eq(hc, 'ZoningSystemType', 'Single zone') + end + + def multizone_vav(terminal, reheat) + exists(@d, 'DeliveryType/CentralAirDistribution') && eq(a, 'AirDeliveryType', 'Central fan') && + eq(a, 'TerminalUnit', terminal) && eq(hc, 'ZoningSystemType', 'Multi zone') && + eq(a, 'ReheatSource', reheat) + end + + # An empty FanBasedDistributionType (no child elements) counts as absent. + def fan_based_distribution(el) + nodes(el, 'FanBased/FanBasedDistributionType').any? { |n| !n.elements.to_a.empty? } + end + + def gas_air_furnace + exists(h, 'Furnace') && eq(hs, 'PrimaryFuel', 'Natural gas') && eq(hs, 'HeatingMedium', 'Air') + end + + def zone_equipment_only + !z.nil? && ['Convection', 'Radiant', 'Other'].all? { |n| absent(z, n) } + end + + def plant_quantities_one(*plants) + plants.compact.all? do |plant| + quantity_guard(plant, 'Quantity') && ['Boiler', 'Chiller'].all? { |eq_name| quantity_guard(plant, "#{eq_name}/Quantity") } + end + end + + def conditioned + ['ElectricResistance', 'Furnace', 'HeatPump', 'SourceHeatingPlantID'].any? { |n| exists(h, n) } || + ['DX', 'CoolingPlantID', 'EvaporativeCooler'].any? { |n| exists(c, n) } + end + end + + ELECTRIC = 'Electricity' + AIR_REFRIGERANT = ['Air', 'Refrigerant'].freeze + FURNACE_TYPES = ['Warm air', 'Other'].freeze + # HeatPumpBackupSystemFuel => hvac_packaged_rooftop_heat_pump supplemental_heating_fuel + BACKUP_FUELS = { 'Electricity' => 'Electricity', 'Natural gas' => 'NaturalGas' }.freeze + + # Exact rows and mapping-gap rows. :required, :absent, and :guards take a Context. + # :absent and :guards return descriptions of failed checks. + DELIVERY_RULES = [ + { + configuration: 'Packaged Terminal Air Conditioner', measure: 'hvac_ptac', status: :match, group: :delivery, + required: lambda { |x| + x.zone_equipment_only && x.exists(x.h, 'ElectricResistance') && + x.eq(x.dx, 'DXSystemType', 'Packaged terminal air conditioner (PTAC)') && x.packaged_air_cooled_dx + }, + absent: ->(x) { x.fan_based_distribution(x.z) ? ['Z/FanBased/FanBasedDistributionType'] : [] }, + guards: lambda { |x| + [ + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', ELECTRIC)], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['HS/HeatingMedium', x.guard(x.hs, 'HeatingMedium', 'Air')], + ['CS/CoolingMedium', x.guard(x.cs, 'CoolingMedium', AIR_REFRIGERANT)] + ] + } + }, + { + configuration: 'Four Pipe Fan Coil Unit', measure: 'hvac_four_pipe_fan_coil', status: :match, group: :plants, + required: lambda { |x| + x.zone_equipment_only && x.eq(x.fc, 'FanCoilType', 'Fan coil 4 pipe') && + x.gas_hot_water_plant && x.tower_chiller_plant + }, + absent: ->(_x) { [] }, + guards: lambda { |x| + [ + ['FC/HVACPipeConfiguration', x.guard(x.fc, 'HVACPipeConfiguration', '4 pipe')], + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', 'Natural gas')], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['CP/PrimaryFuel', x.guard(x.cp, 'PrimaryFuel', ELECTRIC)], + ['CP/CondenserType', x.guard(x.cp, 'CondenserType', 'Water Cooled')], + ['plant quantities', x.plant_quantities_one(x.hp, x.cp, x.cn_chiller)] + ] + } + }, + { + configuration: 'Packaged Terminal Heat Pump', measure: 'hvac_pthp', status: :match, group: :delivery, + required: lambda { |x| + x.zone_equipment_only && x.eq(x.h, 'HeatPump/HeatPumpType', 'Packaged Terminal') && x.heat_pump_shares_cs && + x.eq(x.h, 'HeatPump/HeatPumpBackupSystemFuel', ELECTRIC) && x.absent(x.h, 'HeatPump/LinkedHeatingPlantID') && + x.eq(x.dx, 'DXSystemType', 'Packaged terminal heat pump (PTHP)') && x.packaged_air_cooled_dx + }, + absent: ->(x) { x.fan_based_distribution(x.z) ? ['Z/FanBased/FanBasedDistributionType'] : [] }, + guards: lambda { |x| + [ + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', ELECTRIC)], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['HS/HeatingMedium', x.guard(x.hs, 'HeatingMedium', AIR_REFRIGERANT)], + ['CS/CoolingMedium', x.guard(x.cs, 'CoolingMedium', AIR_REFRIGERANT)] + ] + } + }, + { + configuration: 'Packaged Rooftop Air Conditioner', measure: 'hvac_packaged_rooftop_ac', status: :match, group: :delivery, + required: lambda { |x| + x.single_zone_cav && x.gas_air_furnace && + x.eq(x.dx, 'DXSystemType', 'Packaged/unitary direct expansion/RTU') && x.packaged_air_cooled_dx + }, + absent: ->(x) { central_air_absent(x) }, + guards: lambda { |x| + [ + ['H/Furnace/FurnaceType', x.guard(x.h, 'Furnace/FurnaceType', FURNACE_TYPES)], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['CS/CoolingMedium', x.guard(x.cs, 'CoolingMedium', AIR_REFRIGERANT)] + ] + } + }, + { + configuration: 'Packaged Rooftop Heat Pump', measure: 'hvac_packaged_rooftop_heat_pump', status: :match, group: :delivery, + required: lambda { |x| + x.single_zone_cav && x.eq(x.h, 'HeatPump/HeatPumpType', 'Packaged Unitary') && x.heat_pump_shares_cs && + x.one_of(x.h, 'HeatPump/HeatPumpBackupSystemFuel', BACKUP_FUELS.keys) && + x.absent(x.h, 'HeatPump/LinkedHeatingPlantID') && + x.eq(x.dx, 'DXSystemType', 'Packaged/unitary heat pump') && x.packaged_air_cooled_dx + }, + arguments: lambda { |x| + { 'supplemental_heating_fuel' => BACKUP_FUELS[x.class.texts(x.h, 'HeatPump/HeatPumpBackupSystemFuel').first] } + }, + absent: ->(x) { central_air_absent(x) }, + guards: lambda { |x| + [ + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', ELECTRIC)], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['HS/HeatingMedium', x.guard(x.hs, 'HeatingMedium', AIR_REFRIGERANT)], + ['CS/CoolingMedium', x.guard(x.cs, 'CoolingMedium', AIR_REFRIGERANT)] + ] + } + }, + { + configuration: 'Packaged Rooftop VAV with Hot Water Reheat', measure: 'hvac_packaged_rooftop_vav_hw_reheat', + status: :match, group: :cooling_source, + required: lambda { |x| + x.multizone_vav('VAV terminal box not fan powered with reheat', 'Heating plant') && x.gas_hot_water_plant && + x.ref_ids(x.a, 'ReheatPlantID') == [x.hp.attributes['ID']] && + x.eq(x.dx, 'DXSystemType', 'Packaged/unitary direct expansion/RTU') && x.packaged_air_cooled_dx + }, + absent: ->(x) { x.fan_based_distribution(x.a) ? ['A/FanBased/FanBasedDistributionType'] : [] }, + guards: lambda { |x| + [ + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', 'Natural gas')], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['CS/CoolingMedium', x.guard(x.cs, 'CoolingMedium', AIR_REFRIGERANT)], + ['CS/Quantity', x.quantity_guard(x.cs, 'Quantity')], + ['plant quantities', x.plant_quantities_one(x.hp)] + ] + } + }, + { + configuration: 'Packaged Rooftop VAV with Electric Reheat', measure: 'hvac_packaged_rooftop_vav_electric_reheat', + status: :mapping_gap, group: :cooling_source, + gap: 'The terminal enum combines parallel and series fan-powered boxes; the measure builds only parallel boxes.', + required: lambda { |x| + x.multizone_vav('VAV terminal box fan powered with reheat', 'Local electric resistance') && + x.exists(x.h, 'ElectricResistance') && + x.eq(x.dx, 'DXSystemType', 'Packaged/unitary direct expansion/RTU') && x.packaged_air_cooled_dx + } + }, + { + configuration: 'VAV with Hot Water Reheat', measure: 'hvac_vav_hw_reheat', status: :match, group: :cooling_source, + required: lambda { |x| + x.multizone_vav('VAV terminal box not fan powered with reheat', 'Heating plant') && x.gas_hot_water_plant && + x.ref_ids(x.a, 'ReheatPlantID') == [x.hp.attributes['ID']] && x.tower_chiller_plant + }, + absent: ->(x) { x.fan_based_distribution(x.a) ? ['A/FanBased/FanBasedDistributionType'] : [] }, + guards: lambda { |x| + [ + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', 'Natural gas')], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['CS/Quantity', x.quantity_guard(x.cs, 'Quantity')], + ['CP/PrimaryFuel', x.guard(x.cp, 'PrimaryFuel', ELECTRIC)], + ['CP/CondenserType', x.guard(x.cp, 'CondenserType', 'Water Cooled')], + ['plant quantities', x.plant_quantities_one(x.hp, x.cp, x.cn_chiller)] + ] + } + }, + { + configuration: 'VAV with Electric Reheat', measure: 'hvac_vav_electric_reheat', status: :mapping_gap, group: :cooling_source, + gap: 'The terminal enum combines parallel and series fan-powered boxes; the measure builds only parallel boxes.', + required: lambda { |x| + x.multizone_vav('VAV terminal box fan powered with reheat', 'Local electric resistance') && + x.exists(x.h, 'ElectricResistance') && x.tower_chiller_plant + } + }, + { + configuration: 'Warm Air Furnace', measure: 'hvac_warm_air_furnace', status: :match, group: :delivery, + required: lambda { |x| + x.single_zone_cav && x.gas_air_furnace && x.exists(x.c, 'NoCooling') + }, + absent: ->(x) { central_air_absent(x) }, + guards: ->(x) { [['H/Furnace/FurnaceType', x.guard(x.h, 'Furnace/FurnaceType', FURNACE_TYPES)]] } + }, + { + configuration: 'Water Loop Heat Pump', measure: 'hvac_water_loop_heat_pump', status: :mapping_gap, group: :delivery, + gap: 'BuildingSync does not uniquely encode the generated terminal, shared loop, and fluid-cooler arrangement.', + required: lambda { |x| + !x.z.nil? && x.exists(x.h, 'HeatPump') && x.heat_pump_shares_cs && !x.dx.nil? && + !x.cn_dx.nil? && x.exists(x.cn_dx, 'WaterCooled') + } + }, + { + configuration: 'Ground Source Heat Pump', measure: 'hvac_ground_source_heat_pump', status: :mapping_gap, group: :delivery, + gap: 'The measure approximates the ground loop and creates no well or borefield geometry.', + required: lambda { |x| + !x.z.nil? && x.exists(x.h, 'HeatPump') && x.heat_pump_shares_cs && !x.cn_dx.nil? && + x.exists(x.cn_dx, 'GroundSource') + } + }, + { + configuration: 'VRF Terminal Unit', measure: 'hvac_vrf', status: :match, group: :cooling_source, + required: lambda { |x| + x.zone_equipment_only && x.eq(x.fc, 'FanCoilType', 'VRF terminal units') && x.exists(x.h, 'HeatPump') && + x.heat_pump_shares_cs && x.absent(x.h, 'HeatPump/LinkedHeatingPlantID') && + x.absent(x.h, 'HeatPump/HeatPumpBackupSystemFuel') && + x.eq(x.dx, 'DXSystemType', 'Variable refrigerant flow') && x.air_cooled_dx + }, + absent: ->(x) { x.exists(x.fc, 'HVACPipeConfiguration') ? ['FC/HVACPipeConfiguration'] : [] }, + guards: lambda { |x| + [ + ['HS/PrimaryFuel', x.guard(x.hs, 'PrimaryFuel', ELECTRIC)], + ['CS/PrimaryFuel', x.guard(x.cs, 'PrimaryFuel', ELECTRIC)], + ['HS/HeatingMedium', x.guard(x.hs, 'HeatingMedium', AIR_REFRIGERANT)], + ['CS/CoolingMedium', x.guard(x.cs, 'CoolingMedium', AIR_REFRIGERANT)], + ['CS/Quantity', x.quantity_guard(x.cs, 'Quantity')] + ] + } + }, + { + configuration: 'Chilled Beam', measure: 'hvac_chilled_beam', status: :mapping_gap, group: :plants, + gap: 'BuildingSync has no active/passive or beam pipe-arrangement selector; the measure builds active four-pipe beams.', + required: lambda { |x| + x.eq(x.z, 'Convection/ConvectionType', 'Chilled beam') && x.gas_hot_water_plant && x.tower_chiller_plant + } + }, + { + configuration: 'Hydronic radiant floor / ceiling', measure: 'hvac_radiant', status: :mapping_gap, group: :plants, + gap: 'BuildingSync combines floor and ceiling radiant; the measure builds floors only.', + required: lambda { |x| + x.eq(x.z, 'Radiant/RadiantType', 'Radiant floor or ceiling') && x.gas_hot_water_plant && x.tower_chiller_plant + } + } + ].freeze + + # Configurations the gem cannot generate. Each takes a Context and returns true on a hit. + NOT_MAPPABLE_DELIVERY = [ + ['Split DX air conditioner', ->(x) { x.eq(x.dx, 'DXSystemType', 'Split DX air conditioner') }], + ['Split / mini-split / multi-split heat pump', lambda { |x| + x.eq(x.dx, 'DXSystemType', 'Split heat pump') || x.one_of(x.fc, 'FanCoilType', ['Mini-split', 'Multi-split']) + }], + ['Single-package vertical AC / heat pump', lambda { |x| + x.one_of(x.dx, 'DXSystemType', ['Single package vertical air conditioner', 'Single package vertical heat pump']) + }], + ['Field-assembled DX system', ->(x) { x.eq(x.dx, 'DXSystemType', 'Field-assembled DX system') }], + ['Two-pipe / changeover fan coil', lambda { |x| + x.eq(x.fc, 'FanCoilType', 'Fan coil 2 pipe') || + (x.eq(x.fc, 'HVACPipeConfiguration', '2 pipe') && + (x.eq(x.hs, 'HeatingMedium', 'Hot water') || x.eq(x.cs, 'CoolingMedium', 'Chilled water'))) + }], + ['Baseboard / radiator', lambda { |x| + x.eq(x.z, 'Convection/ConvectionType', 'Perimeter baseboard') || x.eq(x.z, 'Radiant/RadiantType', 'Radiator') + }], + ['Heating-only or cooling-only paired system', lambda { |x| + paired = x.eq(x.dx, 'DXSystemType', 'Packaged terminal air conditioner (PTAC)') || + x.one_of(x.fc, 'FanCoilType', ['Fan coil 4 pipe', 'VRF terminal units']) || + x.eq(x.z, 'Radiant/RadiantType', 'Radiant floor or ceiling') + hydronic = x.eq(x.fc, 'FanCoilType', 'Fan coil 4 pipe') || x.eq(x.z, 'Radiant/RadiantType', 'Radiant floor or ceiling') + (x.exists(x.h, 'NoHeating') && paired) || (x.exists(x.c, 'NoCooling') && hydronic) + }], + ['Multizone CAV / CAV with terminal reheat', lambda { |x| + x.eq(x.a, 'TerminalUnit', 'CAV terminal box with reheat') || + (x.eq(x.hc, 'ZoningSystemType', 'Multi zone') && x.eq(x.a, 'TerminalUnit', 'CAV terminal box no reheat') && x.conditioned) + }], + ['VAV without terminal reheat', lambda { |x| + x.one_of(x.a, 'TerminalUnit', ['VAV terminal box fan powered no reheat', 'VAV terminal box not fan powered no reheat']) + }], + ['Unsupported VAV terminal / reheat pairing', lambda { |x| + (x.eq(x.a, 'TerminalUnit', 'VAV terminal box not fan powered with reheat') && + x.one_of(x.a, 'ReheatSource', ['Local electric resistance', 'Local gas'])) || + (x.eq(x.a, 'TerminalUnit', 'VAV terminal box fan powered with reheat') && + x.one_of(x.a, 'ReheatSource', ['Heating plant', 'Local gas'])) + }], + ['Underfloor air distribution', ->(x) { x.eq(x.a, 'AirDeliveryType', 'Low pressure under floor') }], + ['Evaporative cooling', lambda { |x| + x.one_of(x.c, 'EvaporativeCooler/EvaporativeCoolingType', ['Direct', 'Direct indirect', 'Indirect', 'Other']) + }], + ['Steam / district / solar-thermal heating', lambda { |x| + !x.hp.nil? && (x.eq(x.hp, 'Boiler/BoilerType', 'Steam') || x.exists(x.hp, 'DistrictHeating') || x.exists(x.hp, 'SolarThermal')) + }], + ['Absorption / non-electric chiller or district cooling', lambda { |x| + !x.cp.nil? && (x.eq(x.cp, 'Chiller/ChillerType', 'Absorption') || + x.one_of(x.cp, 'Chiller/ChillerCompressorDriver', ['Steam', 'Gas Turbine', 'Gas Engine']) || + x.exists(x.cp, 'DistrictChilledWater')) + }], + ['Air-cooled chiller', ->(x) { !x.cn_chiller.nil? && x.exists(x.cn_chiller, 'AirCooled') }] + ].freeze + + NOT_MAPPABLE_OTHER = { + 'Heat recovery ventilator' => 'Heat-recovery / energy-recovery ventilation', + 'Energy recovery ventilator' => 'Heat-recovery / energy-recovery ventilation', + 'Exhaust only' => 'Exhaust-only / spot exhaust' + }.freeze + + OTHER_EQUIPMENT_NOT_MAPPABLE = { + 'SpotExhaust' => 'Exhaust-only / spot exhaust', + 'Humidifier' => 'Humidification / dehumidification / air cleaning', + 'Dehumidifier' => 'Humidification / dehumidification / air cleaning', + 'AirCleaner' => 'Humidification / dehumidification / air cleaning', + 'NaturalVentilation' => 'Natural ventilation' + }.freeze + + VENTILATION_MEASURES = { + 'Supply only' => ['Ventilation Only', 'hvac_ventilation_only'], + 'Dedicated outdoor air system' => ['Dedicated Outdoor Air System', 'hvac_doas'] + }.freeze + + INTEGRATED = ['Integrated with central air distribution', 'Integrated with local air distribution'].freeze + + def self.central_air_absent(x) + failed = x.exists(x.a, 'ReheatPlantID') ? ['A/ReheatPlantID'] : [] + failed << 'A/FanBased/FanBasedDistributionType' if x.fan_based_distribution(x.a) + failed + end + + # @param hvac_systems [REXML::Element] an HVACSystems element (or any parent of HVACSystem elements) + # @return [Array] + def select(hvac_systems) + Context.nodes(hvac_systems, 'HVACSystem').flat_map { |sys| _select_system(sys) } + end + + private + + def _select_system(sys) + index, duplicates = _index(sys) + sys_id = sys.attributes['ID'] + deliveries = Context.nodes(sys, 'HeatingAndCoolingSystems/Deliveries/Delivery') + others = Context.nodes(sys, 'OtherHVACSystems/OtherHVACSystem') + + if deliveries.empty? && others.empty? + principal = Context.texts(sys, 'PrimaryHVACSystemType') + Context.texts(sys, 'PrincipalHVACSystemType') + message = if principal.empty? + 'HVACSystem has no Delivery or OtherHVACSystem records.' + else + "Only family-level data (#{principal.join(', ')}); detailed records are required to select a topology." + end + return [_result(:missing_input, sys_id, [sys_id], [], nil, [message])] + end + + unless duplicates.empty? + return [_result(:conflicting_input, sys_id, [sys_id], [], nil, ["Duplicate IDs: #{duplicates.join(', ')}"])] + end + + ventilation_links = Hash.new { |h, k| h[k] = [] } + others.each do |other| + next unless _consumes_deliveries?(sys, other, index) + + Context.nodes(other, 'LinkedDeliveryIDs/LinkedDeliveryID').each do |link| + ventilation_links[link.attributes['IDref']] << other.attributes['ID'] + end + end + + results = deliveries.reject { |d| ventilation_links.key?(d.attributes['ID']) }.map do |delivery| + _select_delivery(sys, delivery, index) + end + results + others.map { |other| _select_other(sys, other, index, ventilation_links) } + end + + # A record whose only content is MechanicalVentilation with VentilationType None or no type + # (optionally DemandControlVentilation) names no ventilation equipment. + def _ventilation_annotation?(other) + type_node = Context.nodes(other, 'OtherHVACType').first + return false if type_node.nil? || type_node.elements.to_a.map(&:name) != ['MechanicalVentilation'] + + mv = type_node.elements.to_a.first + (mv.elements.to_a.map(&:name) - ['VentilationType', 'DemandControlVentilation']).empty? && + [[], ['None']].include?(Context.texts(mv, 'VentilationType')) + end + + # Outdoor air delivered through the linked deliveries' own air system, not separate equipment. + def _integrated?(other) + texts = Context.texts(other, 'Integration') + !texts.empty? && texts.all? { |t| INTEGRATED.include?(t) } + end + + def _explicit_no_hvac?(x) + !x.d.nil? && x.exists(x.h, 'NoHeating') && x.exists(x.c, 'NoCooling') && x.absent(x.d, 'DeliveryType') + end + + # Ventilation annotations own their linked deliveries only when every one is explicitly + # unconditioned; otherwise those deliveries are still evaluated as conditioning deliveries. + def _consumes_deliveries?(sys, other, index) + return false if _integrated?(other) + return true unless _ventilation_annotation?(other) + + ids = Context.nodes(other, 'LinkedDeliveryIDs/LinkedDeliveryID').map { |l| l.attributes['IDref'] } + !ids.empty? && ids.all? { |id| _explicit_no_hvac?(Context.new(sys, index[:delivery][id], index)) } + end + + def _index(sys) + kinds = { + delivery: 'HeatingAndCoolingSystems/Deliveries/Delivery', + heating_source: 'HeatingAndCoolingSystems/HeatingSources/HeatingSource', + cooling_source: 'HeatingAndCoolingSystems/CoolingSources/CoolingSource', + heating_plant: 'Plants/HeatingPlants/HeatingPlant', + cooling_plant: 'Plants/CoolingPlants/CoolingPlant', + condenser_plant: 'Plants/CondenserPlants/CondenserPlant', + other: 'OtherHVACSystems/OtherHVACSystem' + } + seen = Hash.new(0) + index = kinds.transform_values do |path| + Context.nodes(sys, path).each_with_object({}) do |el, by_id| + id = el.attributes['ID'] + next if id.nil? + + seen[id] += 1 + by_id[id] = el + end + end + [index, seen.select { |_, count| count > 1 }.keys] + end + + def _select_delivery(sys, delivery, index) + x = Context.new(sys, delivery, index) + ids = [delivery, x.hs, x.cs].compact.map { |el| el.attributes['ID'] } + premises = _premises(delivery, sys) + + missing = [] + missing << 'Delivery/HeatingSourceID' if x.ref_ids(delivery, 'HeatingSourceID').empty? + missing << 'Delivery/CoolingSourceID' if x.ref_ids(delivery, 'CoolingSourceID').empty? + missing << 'LinkedPremises on Delivery or HVACSystem' if premises.empty? + return _result(:conflicting_input, sys.attributes['ID'], ids, premises, nil, x.conflicts) unless x.conflicts.empty? + return _result(:missing_input, sys.attributes['ID'], ids, premises, nil, missing.map { |m| "Missing #{m}" }) unless missing.empty? + + hits = DELIVERY_RULES.select { |rule| rule[:required].call(x) } + not_mappable = NOT_MAPPABLE_DELIVERY.select { |_, test| test.call(x) }.map(&:first) + return _result(:conflicting_input, sys.attributes['ID'], ids, premises, nil, x.conflicts) unless x.conflicts.empty? + + if hits.length + not_mappable.length > 1 + names = hits.map { |r| r[:configuration] } + not_mappable + return _result(:conflicting_input, sys.attributes['ID'], ids, premises, nil, + ["Delivery matches more than one configuration: #{names.join(', ')}"]) + end + + if not_mappable.length == 1 + return _result(:not_mappable, sys.attributes['ID'], ids, premises, nil, + ["#{not_mappable.first}: no buildingsync-measures-gem measure for this configuration."], + configuration: not_mappable.first) + end + + rule = hits.first + if rule.nil? + return _result(:missing_input, sys.attributes['ID'], ids, premises, nil, + ['Detailed HVAC data does not identify a supported or known configuration.']) + end + + group_key = _group_key(rule[:group], x) + if rule[:status] == :mapping_gap + return _result(:mapping_gap, sys.attributes['ID'], ids, premises, group_key, [rule[:gap]], + configuration: rule[:configuration], measure: rule[:measure]) + end + + failures = rule[:absent].call(x).map { |p| "#{p} must be absent" } + + rule[:guards].call(x).reject { |_, ok| ok }.map { |name, _| "Guard failed: #{name}" } + unless failures.empty? + return _result(:conflicting_input, sys.attributes['ID'], ids, premises, group_key, failures, + configuration: rule[:configuration]) + end + + _result(:match, sys.attributes['ID'], ids, premises, group_key, [], + configuration: rule[:configuration], measure: rule[:measure], + measure_arguments: rule[:arguments] ? rule[:arguments].call(x) : {}) + end + + def _select_other(sys, other, index, ventilation_links) + sys_id = sys.attributes['ID'] + other_id = other.attributes['ID'] + linked_ids = Context.nodes(other, 'LinkedDeliveryIDs/LinkedDeliveryID').map { |l| l.attributes['IDref'] } + ids = [other_id] + linked_ids + premises = _premises(other, sys) + type_node = Context.nodes(other, 'OtherHVACType').first + equipment = type_node.nil? ? [] : type_node.elements.to_a.map(&:name) + + unsupported = equipment.filter_map { |name| OTHER_EQUIPMENT_NOT_MAPPABLE[name] }.uniq + unless unsupported.empty? + return _result(:not_mappable, sys_id, ids, premises, nil, + unsupported.map { |c| "#{c}: no buildingsync-measures-gem measure for this configuration." }, + configuration: unsupported.join(', ')) + end + + x_probe = Context.new(sys, other, index) + ventilation_type = Context.texts(x_probe.mv(other), 'VentilationType') + if ventilation_type.empty? + return _result(:missing_input, sys_id, ids, premises, nil, + ['OtherHVACSystem does not identify a supported ventilation configuration.']) + end + if ventilation_type.length > 1 + return _result(:conflicting_input, sys_id, ids, premises, nil, ['Multiple VentilationType values.']) + end + + ventilation_type = ventilation_type.first + if NOT_MAPPABLE_OTHER.key?(ventilation_type) + configuration = NOT_MAPPABLE_OTHER[ventilation_type] + return _result(:not_mappable, sys_id, ids, premises, nil, + ["#{configuration}: no buildingsync-measures-gem measure creates this equipment."], + configuration: configuration) + end + + if _integrated?(other) + return _result(:integrated, sys_id, ids, premises, nil, + ['Outdoor air is integrated with the linked deliveries; they are selected as conditioning deliveries.'], + configuration: 'Integrated outdoor air') + end + + return _result(:missing_input, sys_id, ids, premises, nil, ['Missing LinkedDeliveryIDs.']) if linked_ids.empty? + + shared = linked_ids.select { |id| ventilation_links[id].length > 1 } + broken = linked_ids.reject { |id| index[:delivery].key?(id) } + conflicts = broken.map { |id| "LinkedDeliveryID '#{id}' does not resolve to a Delivery" } + + shared.map { |id| "Delivery '#{id}' is linked by more than one OtherHVACSystem" } + return _result(:conflicting_input, sys_id, ids, premises, nil, conflicts) unless conflicts.empty? + + contexts = linked_ids.map { |id| Context.new(sys, index[:delivery][id], index) } + linked_conflicts = contexts.flat_map(&:conflicts) + return _result(:conflicting_input, sys_id, ids, premises, nil, linked_conflicts) unless linked_conflicts.empty? + + if ventilation_type == 'None' + explicit = contexts.all? do |x| + x.exists(x.h, 'NoHeating') && x.exists(x.c, 'NoCooling') && x.absent(x.d, 'DeliveryType') + end + return _result(:no_hvac, sys_id, ids, premises, nil, [], configuration: 'Explicitly no HVAC') if explicit + + if _ventilation_annotation?(other) && contexts.none? { |x| _explicit_no_hvac?(x) } + return _result(:no_hvac, sys_id, ids, premises, nil, + ['VentilationType None names no ventilation equipment; linked deliveries are selected as conditioning deliveries.'], + configuration: 'No separate ventilation equipment') + end + + return _result(:missing_input, sys_id, ids, premises, nil, + ['VentilationType None requires linked deliveries with NoHeating, NoCooling, and no DeliveryType.']) + end + + configuration, measure = VENTILATION_MEASURES[ventilation_type] + if configuration.nil? + return _result(:missing_input, sys_id, ids, premises, nil, + ["VentilationType '#{ventilation_type}' does not identify a supported configuration."]) + end + + if contexts.any?(&:conditioned) + return _result(:not_mappable, sys_id, ids, premises, nil, + ['Conditioned DOAS / makeup-air unit: neither ventilation measure creates conditioning coils.'], + configuration: 'Conditioned DOAS / heated or cooled makeup-air unit') + end + + required = contexts.all? do |x| + x.exists(x.d, 'DeliveryType/CentralAirDistribution') && x.eq(x.a, 'AirDeliveryType', 'Central fan') && + x.eq(x.a, 'TerminalUnit', 'CAV terminal box no reheat') && x.eq(x.a, 'ReheatSource', 'None') && + x.exists(x.h, 'NoHeating') && x.exists(x.c, 'NoCooling') + end && Context.texts(other, 'Integration') == ['Stand-alone'] + unless required + return _result(:missing_input, sys_id, ids, premises, nil, + ["#{configuration} requires Stand-alone integration and unconditioned single-duct CAV deliveries."]) + end + + mv = x_probe.mv(other) + failures = contexts.flat_map { |x| self.class.central_air_absent(x) }.uniq.map { |p| "#{p} must be absent" } + failures += ['MakeupAirSourceID', 'VentilationControlMethods', 'VentilationZoneControl'] + .select { |p| x_probe.exists(mv, p) }.map { |p| "MV/#{p} must be absent" } + failures << 'Guard failed: MV/DemandControlVentilation' unless x_probe.guard(mv, 'DemandControlVentilation', ['false', '0']) + failures << 'Guard failed: O/PrimaryFuel' unless x_probe.guard(other, 'PrimaryFuel', ELECTRIC) + failures << 'Guard failed: O/Quantity' unless x_probe.quantity_guard(other, 'Quantity') + return _result(:conflicting_input, sys_id, ids, premises, nil, failures, configuration: configuration) unless failures.empty? + + _result(:match, sys_id, ids, premises, [:other, other_id], [], configuration: configuration, measure: measure) + end + + def _group_key(group, x) + case group + when :delivery then [:delivery, x.d.attributes['ID']] + when :cooling_source then [:cooling_source, x.cs_id] + when :plants then [:plants, x.hp&.attributes&.[]('ID'), x.cp&.attributes&.[]('ID'), x.cn_chiller&.attributes&.[]('ID')] + end + end + + # LinkedPremises references as [{ type: 'ThermalZone', id: 'ThermalZone-1' }, ...]. A record + # without its own links inherits the parent HVACSystem's links. + def _premises(record, sys) + own = _linked_premises(record) + own.empty? ? _linked_premises(sys) : own + end + + def _linked_premises(record) + Context.nodes(record, 'LinkedPremises').flat_map do |linked| + linked.elements.to_a.flat_map do |premise_type| + premise_type.elements.to_a.filter_map do |link| + id = link.attributes['IDref'] + { type: premise_type.name, id: id } if id + end + end + end + end + + def _result(status, sys_id, ids, premises, group_key, messages, configuration: nil, measure: nil, measure_arguments: {}) + Result.new(status: status, configuration: configuration, measure: measure, hvac_system_id: sys_id, + record_ids: ids.compact.uniq, premises: premises, group_key: group_key, messages: messages, + measure_arguments: measure_arguments) + end + end +end diff --git a/lib/BOSS/osw_arg_populator.rb b/lib/BOSS/osw_arg_populator.rb index 46ac09b..b6acea3 100644 --- a/lib/BOSS/osw_arg_populator.rb +++ b/lib/BOSS/osw_arg_populator.rb @@ -8,10 +8,32 @@ require 'BOSS/boss_logger' class OSWArgPopulator + # Inserts a deep copy of step before the first before_measure step, or appends it. + # Returns the inserted step. + def self.append_step(osw, step, before_measure: nil) + new_step = Marshal.load(Marshal.dump(step)) + new_step[:arguments] ||= {} + steps = osw[:steps] + index = before_measure && steps.index { |existing| existing[:measure_dir_name] == before_measure } + steps.insert(index || steps.length, new_step) + new_step + end + + # Sets one argument on this step only. set_measure_argument updates every step with the + # same measure_dir_name, so it is given a one-step workflow. + def self.set_step_argument(step, name, value) + OpenStudio::Extension.set_measure_argument({ steps: [step] }, step[:measure_dir_name], name, value) + step + end + + def self.step_argument_setter(osw, measure_dir_name) + step = append_step(osw, { measure_dir_name:, arguments: {} }) + ->(key, value) { set_step_argument(step, key, value) } + end + def self.populate_set_run_period_args(osw, bsync_reader) BOSS.BOSS_logger.info("+++++++++++++++++++++++++++ populating measure set_run_period +++++++++++++++++++++++") - osw[:steps].append({"measure_dir_name": "set_run_period", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "set_run_period", key, value) } + set_measure_argument = step_argument_setter(osw, "set_run_period") # Add args # - __SKIP__ @@ -35,8 +57,7 @@ def self.populate_set_run_period_args(osw, bsync_reader) def self.populate_change_building_location_args(osw, bsync_reader) BOSS.BOSS_logger.info("+++++++++++++++++++++ populating measure ChangeBuildingLocation +++++++++++++++++++++") - osw[:steps].append({"measure_dir_name": "ChangeBuildingLocation", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "ChangeBuildingLocation", key, value) } + set_measure_argument = step_argument_setter(osw, "ChangeBuildingLocation") # - __SKIP__ set_measure_argument.call("__SKIP__", false) @@ -57,8 +78,7 @@ def self.populate_change_building_location_args(osw, bsync_reader) def self.populate_create_bar_from_building_type_ratios_args(osw, bsync_reader) BOSS.BOSS_logger.info("++++ populating measure create_bar_from_building_type_ratios ++++++++++++++") - osw[:steps].append({"measure_dir_name": "create_bar_from_building_type_ratios", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "create_bar_from_building_type_ratios", key, value) } + set_measure_argument = step_argument_setter(osw, "create_bar_from_building_type_ratios") @@ -125,10 +145,9 @@ def self.populate_create_bar_from_building_type_ratios_args(osw, bsync_reader) BOSS.BOSS_logger.info("") end - def self.populate_create_typical_building_from_model_args(osw, bsync_reader) + def self.populate_create_typical_building_from_model_args(osw, bsync_reader, add_hvac: true) BOSS.BOSS_logger.info("+++++ populating measure create_typical_building_from_model +++++++++++++++") - osw[:steps].append({"measure_dir_name": "create_typical_building_from_model", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "create_typical_building_from_model", key, value) } + set_measure_argument = step_argument_setter(osw, "create_typical_building_from_model") # Add args # - __SKIP__ @@ -164,8 +183,8 @@ def self.populate_create_typical_building_from_model_args(osw, bsync_reader) # add_thermostat # add_hvac BOSS.BOSS_logger.info("|\t- setting arg 'add_hvac'...") - BOSS.BOSS_logger.info("|\t defaults to 'true'") - set_measure_argument.call("add_hvac", true) + BOSS.BOSS_logger.info("|\t set to '#{add_hvac}'") + set_measure_argument.call("add_hvac", add_hvac) # add_refrigeration # modify_wkdy_op_hrs # wkdy_op_hrs_start_time @@ -187,8 +206,7 @@ def self.populate_create_typical_building_from_model_args(osw, bsync_reader) def self.populate_set_lighting_loads_by_LPD_args(osw, bsync_reader) BOSS.BOSS_logger.info("++++++++++++++++++++++ populating measure SetLightingLoadsByLPD ++++++++++++++++++++") - osw[:steps].append({"measure_dir_name": "SetLightingLoadsByLPD", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "SetLightingLoadsByLPD", key, value) } + set_measure_argument = step_argument_setter(osw, "SetLightingLoadsByLPD") # skip if no total_installed_power or no usable floor area BOSS.BOSS_logger.info("|\t- gathering measure requirements...") @@ -229,8 +247,7 @@ def self.populate_set_lighting_loads_by_LPD_args(osw, bsync_reader) def self.populate_set_electric_equipment_loads_by_epd_args(osw, bsync_reader) BOSS.BOSS_logger.info("+++++ populating measure set_electric_equipment_loads_by_epd ++++++++++++++") - osw[:steps].append({"measure_dir_name": "set_electric_equipment_loads_by_epd", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "set_electric_equipment_loads_by_epd", key, value) } + set_measure_argument = step_argument_setter(osw, "set_electric_equipment_loads_by_epd") # skip if no total_weighted_average_load or no usable floor area BOSS.BOSS_logger.info("|\t- gathering measure requirements...") @@ -269,8 +286,7 @@ def self.populate_set_electric_equipment_loads_by_epd_args(osw, bsync_reader) end def self.populate_replace_baseline_windows_args(osw, bsync_reader) - osw[:steps].append({"measure_dir_name": "replace_baseline_windows", "arguments": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "replace_baseline_windows", key, value) } + set_measure_argument = step_argument_setter(osw, "replace_baseline_windows") # skip if no window_data window_data = bsync_reader.get_window_data @@ -292,8 +308,7 @@ def self.populate_replace_baseline_windows_args(osw, bsync_reader) 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": {}}) - set_measure_argument = lambda {| key, value | OpenStudio::Extension.set_measure_argument(osw, "openstudio_results", key, value) } + set_measure_argument = step_argument_setter(osw, "openstudio_results") # Add args # - __SKIP__ diff --git a/spec/files/v2.7.0/example-smalloffice-level2-built-2012.xml b/spec/files/v2.7.0/example-smalloffice-level2-built-2012.xml new file mode 100644 index 0000000..5af7ad4 --- /dev/null +++ b/spec/files/v2.7.0/example-smalloffice-level2-built-2012.xml @@ -0,0 +1,2733 @@ + + + + + + + + + Prototype Small Office in Denver + Here we record general problems / issues identified in a walkthrough survey. + + + City Custom Building ID + some ID + + + Custom ID 1 + some other ID + + +
+ + + Some address + + + Denver + CO + 80014 +
+ -104.830000 + 39.660000 + Commercial + Office + + 1 + 0 + 1 + 0 + true + false + + + Gross + 5500.000000 + + + + + + Conditioned + 5500.000000 + + + + + + 6500.000000 + 0.000000 + 0.213300 + 0.050000 + 2012 + 2000 + 2010 + 2020-03-01 + 2012 + +
+ Space function + Office + Office + + + Peak total occupants + 31.000000 + + + + + 40.000000 + Hours per week + + + 50.000000 + Weeks per year + + + + + Gross + 5500.000000 + + + Conditioned + 5500.000000 + + + Single zone +
+
+ Whole building + Rectangular + + + A1 + + + 909.012230 + + + + + 180.187860 + + + + + 42.086890 + + + + + B1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + C1 + + + 909.012230 + + + + + 180.187860 + + + + + 0.000000 + + + + + D1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + + + + 6444.999000 + Good + + + + + + + 3891.153600 + + + +
+
+ + + + + + + + + + Single zone + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 10311.100000 + 10311.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9801.300000 + 9801.300000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 7858.100000 + 7858.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9067.800000 + 9067.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9855.400000 + 9855.400000 + W + Good + + + + + + + + + + 2000 + + + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 10198.900000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 7737.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9143.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + + Digital + + +
+ + + + + +
+
+
+
+ + + + + T8 + + + Standard Electronic + + 0.200000 + + 100.000000 + 5.500000 + 32.000000 + 4 + 1.000000 + 43 + false + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + T12 + + + Standard Electronic + 100.000000 + 1.582575 + 316.516000 + 1 + 1.000000 + 5 + true + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + LED + + + Standard Electronic + + 0.100000 + + 100.000000 + 2.752000 + 16.000000 + 4 + 1.000000 + 43 + false + + + + + + + Photocell + Continuous + + + + false + +
+ + + + + +
+
+
+
+ + + + + + + + 40.000000 + 123.000000 + + + Notes + + 1 + 3.600000 + Continuous + 123.000000 + 1.870180 + + Looped + Thermal Efficiency + 1.000000 + 40.000000 + 140.000000 + 1950.520000 + 11722.840000 + W + + + + + + + + + + 2000 + Electricity + Good + + + + +
+ +
+
+ 1 +
+
+ + + 0.536000 + 880.000000 + 880.000000 + Constant Volume + + + + + + 0.536000 + 872.000000 + 872.000000 + Variable Volume + + + + + + 0.536000 + 836.000000 + 836.000000 + Constant Volume + + + + + + 0.536000 + 830.000000 + 830.000000 + Variable Volume + + + + + + 0.536000 + 671.000000 + 671.000000 + Constant Volume + + + + + + 0.536000 + 664.000000 + 664.000000 + Variable Volume + + + + + + 0.536000 + 774.000000 + 774.000000 + Constant Volume + + + + + + 0.536000 + 766.000000 + 766.000000 + Variable Volume + + + + + + 0.536000 + 841.000000 + 841.000000 + Constant Volume + + + + + + 0.536000 + 833.000000 + 833.000000 + Variable Volume + + + + + + + + Wood frame + 0.547000 + + + + + Wood frame + 4.706000 + + + + + + + + Vinyl + Clear uncoated + Single pane + 3.241000 + 0.391000 + 0.391000 + + + + + + Vinyl + Low e + Triple pane + 0.300000 + 0.391000 + 0.391000 + + + + + Insulated metal + 0.500000 + + + Steel + 2.839000 + + + + + + + + 0.345000 + + + + Concrete poured + + + + + Miscellaneous Electric Load + 0.630000 + +
+ + + + + +
+
+
+
+ + + Notes on test + Tight + 0.151000 + ACHnatural + Blower door + +
+ +
+
+
+
+ + + Notes on test + +
+ +
+
+
+
+
+ + + + + Weekday + Occupied + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + Occupied + 06:00:00 + 07:00:00 + 11.000000 + + + Weekday + Occupied + 07:00:00 + 08:00:00 + 21.000000 + + + Weekday + Occupied + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Occupied + 12:00:00 + 13:00:00 + 53.000000 + + + Weekday + Occupied + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Occupied + 17:00:00 + 18:00:00 + 32.000000 + + + Weekday + Occupied + 18:00:00 + 22:00:00 + 11.000000 + + + Weekday + Occupied + 22:00:00 + 23:00:00 + 5.000000 + + + Weekday + Occupied + 23:00:00 + 23:59:59 + 0.000000 + + + Weekend + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + + + + +
+ +
+
+
+ + + + Weekday + Lighting + 00:00:00 + 05:00:00 + 18.000000 + + + Weekday + Lighting + 05:00:00 + 07:00:00 + 23.000000 + + + Weekday + Lighting + 07:00:00 + 08:00:00 + 42.000000 + + + Weekday + Lighting + 08:00:00 + 12:00:00 + 90.000000 + + + Weekday + Lighting + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + Lighting + 13:00:00 + 17:00:00 + 90.000000 + + + Weekday + Lighting + 17:00:00 + 18:00:00 + 61.000000 + + + Weekday + Lighting + 18:00:00 + 20:00:00 + 42.000000 + + + Weekday + Lighting + 20:00:00 + 22:00:00 + 32.000000 + + + Weekday + Lighting + 22:00:00 + 23:00:00 + 23.000000 + + + Weekday + Lighting + 23:00:00 + 23:59:59 + 18.000000 + + + Weekend + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + Holiday + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + + + + + + + + + + Weekday + Miscellaneous equipment + 00:00:00 + 08:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 12:00:00 + 13:00:00 + 94.000000 + + + Weekday + Miscellaneous equipment + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 17:00:00 + 18:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 18:00:00 + 23:59:59 + 20.000000 + + + Weekend + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + Holiday + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 19:00:00 + 100.000000 + + + Weekday + HVAC equipment + 19:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 07:00:00 + 60.000000 + + + Weekday + HVAC equipment + 07:00:00 + 12:00:00 + 100.000000 + + + Weekday + HVAC equipment + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + HVAC equipment + 13:00:00 + 18:00:00 + 100.000000 + + + Weekday + HVAC equipment + 18:00:00 + 20:00:00 + 60.000000 + + + Weekday + HVAC equipment + 20:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + +
+ + + + + + + + + + + Lighting + + + + Retrofit with light emitting diode technologies + + + + Individual system + This measure is designed to replace all fluorescent bulbs with LEDs + 1 + 50.000000 + 774.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + Fan + + + + Add VSD motor controller + + + + Individual system + This measure is designed to retrofit all RTU fans with a VSD + 1 + 750.000000 + 1250.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + + + + + + Electricity + This is required to document irregularities in monthly energy patterns (Std 211 6.1.2.1.j). No irregularities found. + kWh + All end uses + 67334.150000 + 229.753657 + + + + + + + + + + + + + + + kW + 26.040000 + 26.040000 + 4613.820000 + + + + + + Natural gas + No irregularities in monthly energy consumption found. + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + + + + + + 540.830000 + + + + + + Electricity + kWh + Interior lighting + 28.705000 + 20062.690000 + 68.453898 + + + + Electricity + kWh + Heating + 6.722000 + 4698.230000 + 16.030361 + + + + Electricity + kWh + Cooling + 8.769000 + 6128.870000 + 20.911704 + + + + Electricity + kWh + Domestic hot water + 10.281000 + 7185.370000 + 24.516482 + + + + Electricity + kWh + Plug load + 21.379000 + 14942.150000 + 50.982616 + + + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 5933.100000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 5446.100000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 5736.490000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 4980.500000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 5187.210000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 5842.950000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 5801.730000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 6220.160000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 5682.870000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 5571.930000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 5525.150000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 5405.940000 + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 1.720000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 1.250000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.430000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.010000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.200000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.400000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 4.300000 + + + + Peak + On-peak + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 23.580000 + + + + Peak + On-peak + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 25.380000 + + + + Peak + On-peak + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 26.040000 + + + + Peak + On-peak + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 24.450000 + + + + Peak + On-peak + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 17.030000 + + + + Peak + On-peak + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 22.710000 + + + + Peak + On-peak + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 22.010000 + + + + Peak + On-peak + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 21.810000 + + + + Peak + On-peak + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 20.630000 + + + + Peak + On-peak + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 21.870000 + + + + Peak + On-peak + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 21.630000 + + + + Peak + On-peak + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 21.780000 + + + + Load factor + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 0.320000 + + + + Load factor + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.300000 + + + + Load factor + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.280000 + + + + Load factor + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Load factor + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.360000 + + + + Load factor + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 0.330000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 332.160000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 306.290000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 321.720000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 281.540000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 292.530000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 534.100000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 530.450000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 567.490000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 519.930000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 312.970000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 310.490000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 304.150000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 46.690000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 45.930000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 44.550000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 44.580000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 43.900000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 44.210000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 44.530000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 50.920000 + + + + + + 238473.656550 + 43.358800 + 737088.900000 + 134.000000 + 238473.656550 + 43.358800 + 238.473657 + 0.000000 + 0.000000 + 0.000000 + 4952.480000 + 0.900000 + + + + + + + + + + + + + + 2022-06-01 + + + Portfolio Manager + 2019 + 80.000000 + + + + + 238473.656550 + 43.358800 + 4952.480000 + + + + + + + + + + + + + 39070.530000 + 995 + 89.000000 + + + + + 190348.600000 + 34.600000 + 4846.040000 + 0.881000 + + + + + + + + + + + + + + TMY3 + Finished + + + + + + + Electricity + kWh + All end uses + 67334.150000 + 229.753657 + kW + 26.040000 + 26.040000 + + + Natural gas + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + POM-LEDs + + + + + + + Capital + 35.713000 + 772 + + + Electricity + kWh + 11524.540000 + + + Natural gas + MMBtu + 0.000000 + + + 3.220000 + 0 + 0.000000 + 0.000000 + 1 + 824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 1.070000 + 0.000000 + + + + + + + + + + POM-VSDs + + + + + + + Capital + 5.175000 + 9 + + + Electricity + kWh + 207.240000 + + + Natural gas + MMBtu + 4.460000 + + + 0.420000 + 0 + 0.000000 + 0.000000 + 1 + 2000.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 230.150000 + 0.000000 + + + + + + + + + + POM-LEDs-VSDs + + + + + + + + Capital + 41.827000 + 781 + + + Electricity + kWh + 11701.620000 + + + Natural gas + MMBtu + 1.890000 + + + 4.700000 + 0 + 0.000000 + 0.000000 + 1 + 2824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 3.620000 + 0.000000 + + + + + + + + + + Level 2: Energy Survey and Analysis + + + + + + + + + --06-01 + --09-30 + --06-01 + --09-30 + 0.088520 + 0.000000 + + + --01-01 + --05-31 + --01-01 + --05-31 + 0.053140 + 0.000000 + + + --10-01 + --12-31 + --10-01 + --12-31 + 0.053140 + 0.000000 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 16.880000 + + + 12345 + Xcel Energy + + Some-meter-ID + + some-account-number + Building Owner + + + + + + + + + --01-01 + --12-31 + 0.163600 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 43.880000 + + + Xcel Energy + + Some-meter-ID + + some-other-account-number + Building Owner + + + + + + + + + + + + + + Owner + + The dude + Some big company + + + 123-456-7890 + + + + + the.dude@somebigco.net + + + + + + Energy Auditor + + The lady + Auditeers + + + 123-456-7890 + + + + + the.lady@the-three-auditeers.com + + + + + + + diff --git a/spec/files/v2.7.0/example-smalloffice-level2.xml b/spec/files/v2.7.0/example-smalloffice-level2.xml new file mode 100644 index 0000000..c7ef53c --- /dev/null +++ b/spec/files/v2.7.0/example-smalloffice-level2.xml @@ -0,0 +1,2733 @@ + + + + + + + + + Prototype Small Office in Denver + Here we record general problems / issues identified in a walkthrough survey. + + + City Custom Building ID + some ID + + + Custom ID 1 + some other ID + + +
+ + + Some address + + + Denver + CO + 80014 +
+ -104.830000 + 39.660000 + Commercial + Office + + 1 + 0 + 1 + 0 + true + false + + + Gross + 5500.000000 + + + + + + Conditioned + 5500.000000 + + + + + + 6500.000000 + 0.000000 + 0.213300 + 0.050000 + 2000 + 2000 + 2010 + 2020-03-01 + 2000 + +
+ Space function + Office + Office + + + Peak total occupants + 31.000000 + + + + + 40.000000 + Hours per week + + + 50.000000 + Weeks per year + + + + + Gross + 5500.000000 + + + Conditioned + 5500.000000 + + + Single zone +
+
+ Whole building + Rectangular + + + A1 + + + 909.012230 + + + + + 180.187860 + + + + + 42.086890 + + + + + B1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + C1 + + + 909.012230 + + + + + 180.187860 + + + + + 0.000000 + + + + + D1 + + + 606.008200 + + + + + 120.125240 + + + + + 0.000000 + + + + + + + + 6444.999000 + Good + + + + + + + 3891.153600 + + + +
+
+ + + + + + + + + + Single zone + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 10311.100000 + 10311.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9801.300000 + 9801.300000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 7858.100000 + 7858.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9067.800000 + 9067.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged Unitary + Natural gas + 0.000000 + + + + 3.010000 + COP + 9855.400000 + 9855.400000 + W + Good + + + + + + + + + + 2000 + + + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 10198.900000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 7737.100000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9143.800000 + W + Good + + + + + + + + + + 2000 + + + + + Packaged/unitary heat pump + Reciprocating + Single stage + + + 2.610000 + COP + 9847.200000 + W + Good + + + + + + + + + + 2000 + + + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + Central fan + CAV terminal box no reheat + None + + + None + Fixed + + + + + + + + + + + + + + + + 2000 + 1 + Good + + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + Single + Good + + + + + + Digital + + +
+ + + + + +
+
+
+
+ + + + + T8 + + + Standard Electronic + + 0.200000 + + 100.000000 + 5.500000 + 32.000000 + 4 + 1.000000 + 43 + false + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + T12 + + + Standard Electronic + 100.000000 + 1.582575 + 316.516000 + 1 + 1.000000 + 5 + true + + + + + + + Programmable + + + + false + +
+ + + + + +
+
+
+ + + + LED + + + Standard Electronic + + 0.100000 + + 100.000000 + 2.752000 + 16.000000 + 4 + 1.000000 + 43 + false + + + + + + + Photocell + Continuous + + + + false + +
+ + + + + +
+
+
+
+ + + + + + + + 40.000000 + 123.000000 + + + Notes + + 1 + 3.600000 + Continuous + 123.000000 + 1.870180 + + Looped + Thermal Efficiency + 1.000000 + 40.000000 + 140.000000 + 1950.520000 + 11722.840000 + W + + + + + + + + + + 2000 + Electricity + Good + + + + +
+ +
+
+ 1 +
+
+ + + 0.536000 + 880.000000 + 880.000000 + Constant Volume + + + + + + 0.536000 + 872.000000 + 872.000000 + Variable Volume + + + + + + 0.536000 + 836.000000 + 836.000000 + Constant Volume + + + + + + 0.536000 + 830.000000 + 830.000000 + Variable Volume + + + + + + 0.536000 + 671.000000 + 671.000000 + Constant Volume + + + + + + 0.536000 + 664.000000 + 664.000000 + Variable Volume + + + + + + 0.536000 + 774.000000 + 774.000000 + Constant Volume + + + + + + 0.536000 + 766.000000 + 766.000000 + Variable Volume + + + + + + 0.536000 + 841.000000 + 841.000000 + Constant Volume + + + + + + 0.536000 + 833.000000 + 833.000000 + Variable Volume + + + + + + + + Wood frame + 0.547000 + + + + + Wood frame + 4.706000 + + + + + + + + Vinyl + Clear uncoated + Single pane + 3.241000 + 0.391000 + 0.391000 + + + + + + Vinyl + Low e + Triple pane + 0.300000 + 0.391000 + 0.391000 + + + + + Insulated metal + 0.500000 + + + Steel + 2.839000 + + + + + + + + 0.345000 + + + + Concrete poured + + + + + Miscellaneous Electric Load + 0.630000 + +
+ + + + + +
+
+
+
+ + + Notes on test + Tight + 0.151000 + ACHnatural + Blower door + +
+ +
+
+
+
+ + + Notes on test + +
+ +
+
+
+
+
+ + + + + Weekday + Occupied + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + Occupied + 06:00:00 + 07:00:00 + 11.000000 + + + Weekday + Occupied + 07:00:00 + 08:00:00 + 21.000000 + + + Weekday + Occupied + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Occupied + 12:00:00 + 13:00:00 + 53.000000 + + + Weekday + Occupied + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Occupied + 17:00:00 + 18:00:00 + 32.000000 + + + Weekday + Occupied + 18:00:00 + 22:00:00 + 11.000000 + + + Weekday + Occupied + 22:00:00 + 23:00:00 + 5.000000 + + + Weekday + Occupied + 23:00:00 + 23:59:59 + 0.000000 + + + Weekend + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + Occupied + 00:00:00 + 23:59:59 + 0.000000 + + + + + + +
+ +
+
+
+ + + + Weekday + Lighting + 00:00:00 + 05:00:00 + 18.000000 + + + Weekday + Lighting + 05:00:00 + 07:00:00 + 23.000000 + + + Weekday + Lighting + 07:00:00 + 08:00:00 + 42.000000 + + + Weekday + Lighting + 08:00:00 + 12:00:00 + 90.000000 + + + Weekday + Lighting + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + Lighting + 13:00:00 + 17:00:00 + 90.000000 + + + Weekday + Lighting + 17:00:00 + 18:00:00 + 61.000000 + + + Weekday + Lighting + 18:00:00 + 20:00:00 + 42.000000 + + + Weekday + Lighting + 20:00:00 + 22:00:00 + 32.000000 + + + Weekday + Lighting + 22:00:00 + 23:00:00 + 23.000000 + + + Weekday + Lighting + 23:00:00 + 23:59:59 + 18.000000 + + + Weekend + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + Holiday + Lighting + 00:00:00 + 23:59:59 + 18.000000 + + + + + + + + + + + + Weekday + Miscellaneous equipment + 00:00:00 + 08:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 08:00:00 + 12:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 12:00:00 + 13:00:00 + 94.000000 + + + Weekday + Miscellaneous equipment + 13:00:00 + 17:00:00 + 100.000000 + + + Weekday + Miscellaneous equipment + 17:00:00 + 18:00:00 + 50.000000 + + + Weekday + Miscellaneous equipment + 18:00:00 + 23:59:59 + 20.000000 + + + Weekend + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + Holiday + Miscellaneous equipment + 00:00:00 + 23:59:59 + 20.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 19:00:00 + 100.000000 + + + Weekday + HVAC equipment + 19:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + + + + + Weekday + HVAC equipment + 00:00:00 + 06:00:00 + 0.000000 + + + Weekday + HVAC equipment + 06:00:00 + 07:00:00 + 60.000000 + + + Weekday + HVAC equipment + 07:00:00 + 12:00:00 + 100.000000 + + + Weekday + HVAC equipment + 12:00:00 + 13:00:00 + 80.000000 + + + Weekday + HVAC equipment + 13:00:00 + 18:00:00 + 100.000000 + + + Weekday + HVAC equipment + 18:00:00 + 20:00:00 + 60.000000 + + + Weekday + HVAC equipment + 20:00:00 + 23:59:59 + 0.000000 + + + Weekend + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + Holiday + HVAC equipment + 00:00:00 + 23:59:59 + 0.000000 + + + + + + + + +
+ + + + + + + + + + + Lighting + + + + Retrofit with light emitting diode technologies + + + + Individual system + This measure is designed to replace all fluorescent bulbs with LEDs + 1 + 50.000000 + 774.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + Fan + + + + Add VSD motor controller + + + + Individual system + This measure is designed to retrofit all RTU fans with a VSD + 1 + 750.000000 + 1250.000000 + true + 2021-01-01 + 2021-12-30 + + + + + + + + + + + + + + + + Electricity + This is required to document irregularities in monthly energy patterns (Std 211 6.1.2.1.j). No irregularities found. + kWh + All end uses + 67334.150000 + 229.753657 + + + + + + + + + + + + + + + kW + 26.040000 + 26.040000 + 4613.820000 + + + + + + Natural gas + No irregularities in monthly energy consumption found. + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + + + + + + 540.830000 + + + + + + Electricity + kWh + Interior lighting + 28.705000 + 20062.690000 + 68.453898 + + + + Electricity + kWh + Heating + 6.722000 + 4698.230000 + 16.030361 + + + + Electricity + kWh + Cooling + 8.769000 + 6128.870000 + 20.911704 + + + + Electricity + kWh + Domestic hot water + 10.281000 + 7185.370000 + 24.516482 + + + + Electricity + kWh + Plug load + 21.379000 + 14942.150000 + 50.982616 + + + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 5933.100000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 5446.100000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 5736.490000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 4980.500000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 5187.210000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 5842.950000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 5801.730000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 6220.160000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 5682.870000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 5571.930000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 5525.150000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 5405.940000 + + + + Total + Energy + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 1.720000 + + + + Total + Energy + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 1.250000 + + + + Total + Energy + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Total + Energy + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.430000 + + + + Total + Energy + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.010000 + + + + Total + Energy + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.000000 + + + + Total + Energy + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.000000 + + + + Total + Energy + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.200000 + + + + Total + Energy + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.400000 + + + + Total + Energy + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 4.300000 + + + + Peak + On-peak + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 23.580000 + + + + Peak + On-peak + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 25.380000 + + + + Peak + On-peak + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 26.040000 + + + + Peak + On-peak + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 24.450000 + + + + Peak + On-peak + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 17.030000 + + + + Peak + On-peak + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 22.710000 + + + + Peak + On-peak + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 22.010000 + + + + Peak + On-peak + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 21.810000 + + + + Peak + On-peak + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 20.630000 + + + + Peak + On-peak + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 21.870000 + + + + Peak + On-peak + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 21.630000 + + + + Peak + On-peak + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 21.780000 + + + + Load factor + Power + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 0.320000 + + + + Load factor + Power + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 0.300000 + + + + Load factor + Power + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 0.280000 + + + + Load factor + Power + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 0.410000 + + + + Load factor + Power + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 0.360000 + + + + Load factor + Power + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 0.380000 + + + + Load factor + Power + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 0.340000 + + + + Load factor + Power + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 0.350000 + + + + Load factor + Power + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 0.330000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 332.160000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 306.290000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 321.720000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 281.540000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 292.530000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 534.100000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 530.450000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 567.490000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 519.930000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 312.970000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 310.490000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 304.150000 + + + + Cost + Cost + 2019-01-01T00:00:00 + 2019-02-01T00:00:00 + 31 + Day + Month + 46.690000 + + + + Cost + Cost + 2019-02-01T00:00:00 + 2019-03-01T00:00:00 + 28 + Day + Month + 45.930000 + + + + Cost + Cost + 2019-03-01T00:00:00 + 2019-04-01T00:00:00 + 31 + Day + Month + 44.550000 + + + + Cost + Cost + 2019-04-01T00:00:00 + 2019-05-01T00:00:00 + 30 + Day + Month + 44.580000 + + + + Cost + Cost + 2019-05-01T00:00:00 + 2019-06-01T00:00:00 + 31 + Day + Month + 43.900000 + + + + Cost + Cost + 2019-06-01T00:00:00 + 2019-07-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-07-01T00:00:00 + 2019-08-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-08-01T00:00:00 + 2019-09-01T00:00:00 + 31 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-09-01T00:00:00 + 2019-10-01T00:00:00 + 30 + Day + Month + 43.880000 + + + + Cost + Cost + 2019-10-01T00:00:00 + 2019-11-01T00:00:00 + 31 + Day + Month + 44.210000 + + + + Cost + Cost + 2019-11-01T00:00:00 + 2019-12-01T00:00:00 + 30 + Day + Month + 44.530000 + + + + Cost + Cost + 2019-12-01T00:00:00 + 2020-01-01T00:00:00 + 31 + Day + Month + 50.920000 + + + + + + 238473.656550 + 43.358800 + 737088.900000 + 134.000000 + 238473.656550 + 43.358800 + 238.473657 + 0.000000 + 0.000000 + 0.000000 + 4952.480000 + 0.900000 + + + + + + + + + + + + + + 2022-06-01 + + + Portfolio Manager + 2019 + 80.000000 + + + + + 238473.656550 + 43.358800 + 4952.480000 + + + + + + + + + + + + + 39070.530000 + 995 + 89.000000 + + + + + 190348.600000 + 34.600000 + 4846.040000 + 0.881000 + + + + + + + + + + + + + + TMY3 + Finished + + + + + + + Electricity + kWh + All end uses + 67334.150000 + 229.753657 + kW + 26.040000 + 26.040000 + + + Natural gas + MMBtu + All end uses + 8.720000 + 8.720000 + + + + + + + + + + POM-LEDs + + + + + + + Capital + 35.713000 + 772 + + + Electricity + kWh + 11524.540000 + + + Natural gas + MMBtu + 0.000000 + + + 3.220000 + 0 + 0.000000 + 0.000000 + 1 + 824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 1.070000 + 0.000000 + + + + + + + + + + POM-VSDs + + + + + + + Capital + 5.175000 + 9 + + + Electricity + kWh + 207.240000 + + + Natural gas + MMBtu + 4.460000 + + + 0.420000 + 0 + 0.000000 + 0.000000 + 1 + 2000.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 230.150000 + 0.000000 + + + + + + + + + + POM-LEDs-VSDs + + + + + + + + Capital + 41.827000 + 781 + + + Electricity + kWh + 11701.620000 + + + Natural gas + MMBtu + 1.890000 + + + 4.700000 + 0 + 0.000000 + 0.000000 + 1 + 2824.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0.000000 + 0 + 0 + 3.620000 + 0.000000 + + + + + + + + + + Level 2: Energy Survey and Analysis + + + + + + + + + --06-01 + --09-30 + --06-01 + --09-30 + 0.088520 + 0.000000 + + + --01-01 + --05-31 + --01-01 + --05-31 + 0.053140 + 0.000000 + + + --10-01 + --12-31 + --10-01 + --12-31 + 0.053140 + 0.000000 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 16.880000 + + + 12345 + Xcel Energy + + Some-meter-ID + + some-account-number + Building Owner + + + + + + + + + --01-01 + --12-31 + 0.163600 + + + + + https://www.xcelenergy.com/company/rates_and_regulations/rates/rate_books + 43.880000 + + + Xcel Energy + + Some-meter-ID + + some-other-account-number + Building Owner + + + + + + + + + + + + + + Owner + + The dude + Some big company + + + 123-456-7890 + + + + + the.dude@somebigco.net + + + + + + Energy Auditor + + The lady + Auditeers + + + 123-456-7890 + + + + + the.lady@the-three-auditeers.com + + + + + + + diff --git a/spec/tests/integration/write_and_run_osws_spec.rb b/spec/tests/integration/write_and_run_osws_spec.rb index 8b0a4f1..4012703 100644 --- a/spec/tests/integration/write_and_run_osws_spec.rb +++ b/spec/tests/integration/write_and_run_osws_spec.rb @@ -39,12 +39,15 @@ test_configs = test_configs.select { |config| SMOKE_FILES.include?(config[0]) } if ENV['BOSS_SMOKE'] == '1' # BOSS_SHARD / BOSS_SHARDS split the fixtures across parallel CI jobs. +run_extra_examples = ENV['BOSS_SMOKE'] != '1' if ENV['BOSS_SHARDS'] shards = Integer(ENV['BOSS_SHARDS']) shard = Integer(ENV.fetch('BOSS_SHARD', '0')) raise ArgumentError, "BOSS_SHARD must be in 0...#{shards}" if shards < 1 || shard.negative? || shard >= shards test_configs = test_configs.select.with_index { |_config, index| index % shards == shard } + # Examples outside test_configs run once, in shard 0. + run_extra_examples &&= shard.zero? end RSpec.describe 'BOSS' do @@ -76,5 +79,30 @@ end end + + next unless run_extra_examples + + { + 'example-smalloffice-level2.xml' => ['smalloffice_l2_topology_doe_ref', 'DOE Ref 1980-2004'], + 'example-smalloffice-level2-built-2012.xml' => ['smalloffice_l2_topology', '90.1-2013'] + }.each do |file_name, (output_name, template)| + it "write and run a topology HVAC baseline. File: #{file_name}, Template: #{template}" do + xml_path = File.join(SPEC_FILES_DIR, 'v2.7.0', file_name) + output_path = File.join(SPEC_OUTPUT_DIR, 'v2.7.0', 'write_and_run_baseline_osw', output_name) + + BOSS::Boss.write_baseline_osw(xml_path, output_path, nil, ASHRAE90_1) + BOSS::Boss.run_baseline_osw(output_path) + + out_osw = JSON.parse(File.read(File.join(output_path, 'baseline', 'out.osw')), symbolize_names: true) + expect(out_osw[:completed_status]).to eq 'Success' + steps = out_osw[:steps].to_h { |step| [step[:measure_dir_name], step] } + expect(steps['create_typical_building_from_model'][:arguments][:add_hvac]).to be false + topology = steps['apply_hvac_topology_to_zone_scope'] + expect(topology[:result][:step_result]).to eq 'Success' + expect(topology[:result][:step_final_condition]) + .to match(/Created \d+ PSZ-HP loops \(NaturalGas supplemental heat\).*#{Regexp.escape(template)}/) + expect(steps['apply_standard_hvac_sizing_and_efficiency'][:result][:step_result]).to eq 'Success' + end + end end end diff --git a/spec/tests/unit/baseline_hvac_planner_spec.rb b/spec/tests/unit/baseline_hvac_planner_spec.rb new file mode 100644 index 0000000..70f0e77 --- /dev/null +++ b/spec/tests/unit/baseline_hvac_planner_spec.rb @@ -0,0 +1,189 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/baseline_hvac_planner' +require 'BOSS/boss_logger' +require 'BOSS/buildingsync_reader/buildingsync_reader' + +RSpec.describe BOSS::BaselineHvacPlanner do + building = [{ type: 'Building', id: 'B-1' }] + result = lambda do |status: :match, measure: 'hvac_ptac', configuration: 'PTAC', group_key: [:delivery, 'D-1'], premises: building, messages: []| + BOSS::HvacTopologySelector::Result.new(status:, configuration:, measure:, hvac_system_id: 'HVAC-1', + record_ids: [], premises:, group_key:, messages:) + end + hvac_systems = REXML::Document.new('').root + + def plan_for(results, systems, template = '90.1-2019') + selector = instance_double(BOSS::HvacTopologySelector, select: results) + described_class.new(selector:).plan(systems, template) + end + + it 'plans whole-building create steps, ventilation last, then sizing' do + doas = result.call(measure: 'hvac_doas', configuration: 'DOAS', group_key: [:other, 'O-1']) + plan = plan_for([doas, result.call, result.call(group_key: [:delivery, 'D-1'])], hvac_systems, '90.1-2016') + + expect(plan.status).to eq(:topology) + expect(plan.steps.map { |step| step[:measure_dir_name] }).to eq( + ['apply_hvac_topology_to_zone_scope', 'apply_hvac_topology_to_zone_scope', 'apply_standard_hvac_sizing_and_efficiency'] + ) + expect(plan.steps.map { |step| step[:arguments][:topology_measure] }.compact).to eq(['hvac_ptac', 'hvac_doas']) + expect(plan.steps.map { |step| step[:arguments][:operation] }.compact).to eq(['create', 'create']) + expect(plan.steps.map { |step| step[:arguments][:standards_template] }.uniq).to eq(['90.1-2016']) + end + + { + 'no HVACSystems' => [[], nil, '90.1-2019', /No HVACSystems/], + 'an unsupported template' => [[], :systems, 'DEER 2017', /Template 'DEER 2017'/], + 'family-only data' => [[{ status: :missing_input, messages: ['Only family-level data'] }], :systems, '90.1-2019', + /missing_input.*family-level/], + 'two conditioning configurations' => [[{}, { measure: 'hvac_pthp', group_key: [:delivery, 'D-2'] }], :systems, '90.1-2019', + /one conditioning configuration, found 2/], + 'ventilation on air-loop HVAC' => [[{ measure: 'hvac_warm_air_furnace', configuration: 'Furnace' }, + { measure: 'hvac_doas', configuration: 'DOAS', group_key: [:other, 'O-1'] }], + :systems, '90.1-2019', /DOAS cannot be added.*Furnace/], + 'zone-linked premises' => [[{ premises: [{ type: 'ThermalZone', id: 'TZ-1' }] }], :systems, '90.1-2019', + /only whole-building premises/] + }.each do |label, (specs, systems, template, message)| + it "falls back for #{label}" do + plan = plan_for(specs.map { |spec| result.call(**spec) }, systems && hvac_systems, template) + + expect(plan.status).to eq(:fallback) + expect(plan.steps).to be_empty + expect(plan.messages.join("\n")).to match(message) + end + end + + it 'plans a building-linked PTAC from BuildingSync XML' do + xml = '' \ + '' \ + 'Packaged terminal air conditioner (PTAC)' \ + '' \ + '' \ + '' \ + '' \ + '' + plan = described_class.new.plan(REXML::Document.new(xml).root, '90.1-2019') + + expect(plan.status).to eq(:topology), plan.messages.join("\n") + expect(plan.steps.first[:arguments][:topology_measure]).to eq('hvac_ptac') + end + + sectioned = REXML::Document.new( + '' \ + '
Space function
' \ + '
Space function
' \ + '
' + ) + sectioned_systems = REXML::XPath.first(sectioned, '//HVACSystems') + section = ->(id) { [{ type: 'Section', id: }] } + + it 'merges same-configuration deliveries whose Section links cover the building' do + results = [result.call(premises: section.call('S-1')), + result.call(premises: section.call('S-2'), group_key: [:delivery, 'D-2'])] + plan = plan_for(results, sectioned_systems) + + expect(plan.status).to eq(:topology), plan.messages.join("\n") + expect(plan.steps.map { |step| step[:arguments][:topology_measure] }.compact).to eq(['hvac_ptac']) + expect(plan.steps.first[:arguments][:zone_scope]).to eq('all_model_zones') + end + + it 'falls back when Section links leave part of the building unserved' do + plan = plan_for([result.call(premises: section.call('S-1'))], sectioned_systems) + + expect(plan.status).to eq(:fallback) + expect(plan.messages.join("\n")).to match(/Section S-1.*only whole-building premises/) + end + + it 'keeps different measure arguments as separate configurations' do + results = [['D-1', 'NaturalGas'], ['D-2', 'Electricity']].map do |id, fuel| + result.call(measure: 'hvac_packaged_rooftop_heat_pump', group_key: [:delivery, id]) + .tap { |r| r.measure_arguments = { 'supplemental_heating_fuel' => fuel } } + end + plan = plan_for(results, hvac_systems) + + expect(plan.messages.join("\n")).to match(/one conditioning configuration, found 2/) + end + + { + 'example-smalloffice-level2.xml' => 'DOE Ref 1980-2004', + 'example-smalloffice-level2-built-2012.xml' => '90.1-2013' + }.each do |file_name, template| + it "plans topology HVAC for #{file_name} with #{template}" do + path = File.expand_path("../../files/v2.7.0/#{file_name}", __dir__) + doc = REXML::Document.new(File.read(path), ignore_whitespace_nodes: :all) + reader = BOSS::BuildingSyncReader.new(doc, nil, ASHRAE90_1) + plan = described_class.new.plan(reader.get_hvac_systems_xml, reader.get_standard_template) + + expect(plan.status).to eq(:topology), plan.messages.join("\n") + step = plan.steps.first[:arguments] + expect(step).to include(topology_measure: 'hvac_packaged_rooftop_heat_pump', zone_scope: 'all_model_zones', + standards_template: template, + topology_arguments_json: '{"supplemental_heating_fuel":"NaturalGas"}') + expect(plan.steps.last).to eq(measure_dir_name: 'apply_standard_hvac_sizing_and_efficiency', + arguments: { standards_template: template }) + end + end + + describe '.proposed_system_ids' do + def systems_with_measures(measure_xml) + xml = <<~XML + + + + + + #{measure_xml} + + + XML + REXML::XPath.first(REXML::Document.new(xml), "//*[local-name()='HVACSystems']") + end + + it 'returns no IDs without HVACSystems or measure references' do + expect(described_class.proposed_system_ids(nil)).to eq([]) + expect(described_class.proposed_system_ids(systems_with_measures(''))).to eq([]) + end + + it 'returns unique HVACSystem IDs named as alternatives or modified systems, without changing the XML' do + systems = systems_with_measures(<<~XML) + + + + + + + + + + XML + before = systems.document.to_s + + expect(described_class.proposed_system_ids(systems)).to eq(['Alt', 'Mod']) + expect(systems.document.to_s).to eq(before) + end + end + + it 'plans the existing system when an unmappable proposed HVACSystem is excluded' do + path = File.expand_path('../../files/v2.7.0/example-smalloffice-level2.xml', __dir__) + doc = REXML::Document.new(File.read(path), ignore_whitespace_nodes: :all) + hvac_systems = REXML::XPath.first(doc, "//*[local-name()='HVACSystems']") + prefix = hvac_systems.prefix.empty? ? '' : "#{hvac_systems.prefix}:" + hvac_systems.add_element("#{prefix}HVACSystem", 'ID' => 'Proposed-HVAC') + measure = hvac_systems.parent.parent.add_element("#{prefix}Measures").add_element("#{prefix}Measure", 'ID' => 'M-1') + ["#{prefix}TypeOfMeasure", "#{prefix}Replacements", "#{prefix}Replacement"] + .reduce(measure) { |parent, name| parent.add_element(name) } + .add_element("#{prefix}AlternativeSystemReplacement", 'IDref' => 'Proposed-HVAC') + + expect(described_class.new.plan(hvac_systems, 'DOE Ref 1980-2004').status).to eq(:fallback) + plan = described_class.new.plan(hvac_systems, 'DOE Ref 1980-2004', + exclude_system_ids: described_class.proposed_system_ids(hvac_systems)) + expect(plan.status).to eq(:topology), plan.messages.join("\n") + expect(plan.steps.first[:arguments]).to include(topology_measure: 'hvac_packaged_rooftop_heat_pump', operation: 'create') + end +end diff --git a/spec/tests/unit/boss_spec.rb b/spec/tests/unit/boss_spec.rb index a7f9baa..0a55741 100644 --- a/spec/tests/unit/boss_spec.rb +++ b/spec/tests/unit/boss_spec.rb @@ -24,21 +24,283 @@ allow(BOSS::BCLWeatherFileDownloader) .to receive(:download_weather_file_from_city_name) .and_return(openstudio_weather_file_path) + end + + def stub_measure_dirs(local:, external:, discovered:, scenario_only: []) + allow(OpenStudio::Extension).to receive(:configure_osw) do |osw| + osw[:measure_paths] = discovered + end + + fake_manager = instance_double(BOSS::ExternalMeasureRepoManager) + allow(BOSS::ExternalMeasureRepoManager).to receive(:new).and_return(fake_manager) + allow(fake_manager).to receive(:local_measure_directories).and_return(local) + allow(fake_manager).to receive(:resolved_measure_directories).and_return(external) + allow(fake_manager).to receive(:resolved_measure_directories) + .with(include_scenario_only: true).and_return(external + scenario_only) + end + + def build_reader(xml_file_name) + xml = File.read(File.join(BOSS_SPEC_FILES_DIR, 'v2.7.0', xml_file_name)) + doc = REXML::Document.new(xml, ignore_whitespace_nodes: :all) + BOSS::BuildingSyncReader.new(doc, openstudio_weather_file_path, ASHRAE90_1) + end + + def common_steps(climate_zone) + { + run_period: { + measure_dir_name: 'set_run_period', + arguments: { __SKIP__: false, timesteps_per_hour: '4', begin_date: '2019-01-01', end_date: '2019-12-31' } + }, + location: { + measure_dir_name: 'ChangeBuildingLocation', + arguments: { __SKIP__: false, weather_file_name: File.expand_path(openstudio_weather_file_path), climate_zone: } + }, + results: { measure_dir_name: 'openstudio_results', arguments: { __SKIP__: false, reg_monthly_details: true } } + } + end + + let(:building_151_steps) do + common = common_steps('ASHRAE 169-2013-3C') + [ + common[:run_period], + common[:location], + { + measure_dir_name: 'create_bar_from_building_type_ratios', + arguments: { + __SKIP__: false, bldg_type_a: 'RetailStandalone', total_bldg_floor_area: 69452.0, floor_height: 0.0, + num_stories_above_grade: 1.0, num_stories_below_grade: 0.0, template: 'DOE Ref 1980-2004', + ns_to_ew_ratio: 3.6732677131179763, story_multiplier_method: 'None' + } + }, + { + measure_dir_name: 'create_typical_building_from_model', + arguments: { __SKIP__: false, template: 'DOE Ref 1980-2004', system_type: 'Inferred', add_swh: true, add_hvac: true, use_upstream_args: false } + }, + { measure_dir_name: 'SetLightingLoadsByLPD', arguments: { __SKIP__: true } }, + { measure_dir_name: 'set_electric_equipment_loads_by_epd', arguments: { __SKIP__: true } }, + { measure_dir_name: 'replace_baseline_windows', arguments: { __SKIP__: true } }, + common[:results] + ] + end - # Stub all OSWArgPopulator class methods so they are no-ops; we only care - # about measure_paths ordering, not the steps payload. + let(:all_measures_steps) do + common = common_steps('ASHRAE 169-2013-5B') [ - :populate_set_run_period_args, - :populate_change_building_location_args, - :populate_create_bar_from_building_type_ratios_args, - :populate_create_typical_building_from_model_args, - :populate_set_lighting_loads_by_LPD_args, - :populate_set_electric_equipment_loads_by_epd_args, - :populate_openstudio_results_args - ].each { |m| allow(OSWArgPopulator).to receive(m) } + common[:run_period], + common[:location], + { + measure_dir_name: 'create_bar_from_building_type_ratios', + arguments: { + __SKIP__: false, bldg_type_a: 'SmallOffice', total_bldg_floor_area: 15000.0, floor_height: 10.0, + num_stories_above_grade: 2.0, num_stories_below_grade: 0.0, template: 'DOE Ref 1980-2004', + ns_to_ew_ratio: 1.5, story_multiplier_method: 'None' + } + }, + { + measure_dir_name: 'create_typical_building_from_model', + arguments: { + __SKIP__: false, template: 'DOE Ref 1980-2004', system_type: 'PSZ-AC with gas unit heaters', + add_swh: true, add_hvac: true, use_upstream_args: false + } + }, + { measure_dir_name: 'SetLightingLoadsByLPD', arguments: { __SKIP__: false, lpd: 1.0 } }, + { measure_dir_name: 'set_electric_equipment_loads_by_epd', arguments: { __SKIP__: false, epd: 1.0 } }, + { + measure_dir_name: 'replace_baseline_windows', + arguments: { __SKIP__: false, window_pane_type: 'Double - No LowE - Clear - Aluminum', u_value_ip: '0.50', shgc: '0.39', vlt: '0.39' } + }, + common[:results] + ] + end + + describe '.write_baseline_osw generated baseline' do + before do + stub_measure_dirs(local: [LOCAL_MEASURES_DIR], external: [external_measure_dir], discovered: [gem_measure_dir]) + end + + { + 'building_151.xml' => :building_151_steps, + 'all_measures_applied_example.xml' => :all_measures_steps + }.each do |xml_file_name, expected_steps| + it "keeps every baseline step and argument for #{xml_file_name}" do + Dir.mktmpdir do |output_dir| + xml = File.join(BOSS_SPEC_FILES_DIR, 'v2.7.0', xml_file_name) + osw_path = described_class.write_baseline_osw(xml, output_dir, openstudio_weather_file_path, ASHRAE90_1) + + expect(osw_path).to eq File.join(output_dir, 'baseline', 'in.osw') + expect(Dir.children(output_dir)).to eq ['baseline'] + expect(Dir.children(File.join(output_dir, 'baseline'))).to eq ['in.osw'] + + osw = JSON.parse(File.read(osw_path), symbolize_names: true) + expect(osw[:steps]).to eq send(expected_steps) + expect(osw.keys).to eq [:seed_file, :weather_file, :measure_paths, :file_paths, :run_directory, :steps, :name, :description] + expect(osw.values_at(:seed_file, :weather_file, :run_directory, :name, :description)).to all(be_nil) + end + end + end + + it 'raises the existing error for a missing XML file without writing output' do + Dir.mktmpdir do |output_dir| + missing = File.join(output_dir, 'missing.xml') + expect { described_class.write_baseline_osw(missing, output_dir, nil, ASHRAE90_1) } + .to raise_error(RuntimeError, "File '#{missing}' does not exist") + expect(Dir.children(output_dir)).to be_empty + end + end + + it 'writes into nested output paths with spaces' do + Dir.mktmpdir do |tmp| + output_dir = File.join(tmp, 'nested dir', 'out') + osw_path = described_class.write_baseline_osw( + File.join(BOSS_SPEC_FILES_DIR, 'v2.7.0', 'building_151.xml'), output_dir, nil, ASHRAE90_1 + ) + expect(osw_path).to eq File.join(output_dir, 'baseline', 'in.osw') + expect(File.file?(osw_path)).to be true + end + end + + it 'does not run workflows while writing' do + expect(OpenStudio::Extension::Runner).not_to receive(:new) + Dir.mktmpdir do |output_dir| + described_class.write_baseline_osw(File.join(BOSS_SPEC_FILES_DIR, 'v2.7.0', 'building_151.xml'), output_dir, nil, ASHRAE90_1) + end + end + end + + describe '.build_baseline_osw' do + before do + stub_measure_dirs(local: [LOCAL_MEASURES_DIR], external: [external_measure_dir], discovered: [gem_measure_dir]) + end + + it 'is private while the public API stays public' do + expect(described_class.private_methods).to include(:build_baseline_osw) + expect(described_class.public_methods).to include(:write_baseline_osw, :run_baseline_osw) + expect(described_class.method(:write_baseline_osw).arity).to eq 4 + expect(described_class.method(:run_baseline_osw).arity).to eq 1 + end + + it 'returns the same steps as the writer without writing files' do + Dir.mktmpdir do |output_dir| + Dir.chdir(output_dir) do + osw = described_class.send(:build_baseline_osw, build_reader('all_measures_applied_example.xml')) + expect(osw[:steps]).to eq all_measures_steps + expect(Dir.children(output_dir)).to be_empty + end + end + end + + it 'returns a fresh workflow on every call' do + reader = build_reader('all_measures_applied_example.xml') + first = described_class.send(:build_baseline_osw, reader) + first[:steps].first[:arguments][:timesteps_per_hour] = '1' + first[:steps] << { measure_dir_name: 'extra', arguments: {} } + first[:measure_paths] << '/mutated' + first[:file_paths] << '/mutated' + + second = described_class.send(:build_baseline_osw, reader) + expect(second[:steps]).to eq all_measures_steps + expect(second[:measure_paths]).not_to include('/mutated') + expect(second[:file_paths]).not_to include('/mutated') + end + + it 'replaces create_typical HVAC with planned topology steps and adds gated topology measure paths' do + stub_measure_dirs(local: [LOCAL_MEASURES_DIR], external: [external_measure_dir], discovered: [gem_measure_dir], + scenario_only: ['/bsync/measures']) + steps = [{ measure_dir_name: 'apply_hvac_topology_to_zone_scope', arguments: { topology_measure: 'hvac_ptac' } }, + { measure_dir_name: 'apply_standard_hvac_sizing_and_efficiency', arguments: {} }] + plan = BOSS::BaselineHvacPlanner::Plan.new(status: :topology, steps: steps, messages: []) + allow_any_instance_of(BOSS::BaselineHvacPlanner).to receive(:plan).and_return(plan) + + osw = described_class.send(:build_baseline_osw, build_reader('all_measures_applied_example.xml')) + names = osw[:steps].map { |step| step[:measure_dir_name] } + typical = names.index('create_typical_building_from_model') + + expect(osw[:steps][typical][:arguments][:add_hvac]).to be false + expect(names[typical + 1, 2]).to eq(steps.map { |step| step[:measure_dir_name] }) + expect(names - steps.map { |step| step[:measure_dir_name] }).to eq(all_measures_steps.map { |step| step[:measure_dir_name] }) + expect(osw[:measure_paths]).to include('/bsync/measures') + end + + it 'keeps fallback measure paths free of gated topology repos' do + stub_measure_dirs(local: [LOCAL_MEASURES_DIR], external: [external_measure_dir], discovered: [gem_measure_dir], + scenario_only: ['/bsync/measures']) + + osw = described_class.send(:build_baseline_osw, build_reader('all_measures_applied_example.xml')) + expect(osw[:steps]).to eq all_measures_steps + expect(osw[:measure_paths]).not_to include('/bsync/measures') + end + + it 'builds a PSZ-HP topology baseline for the small office level 2 example' do + stub_measure_dirs(local: [LOCAL_MEASURES_DIR], external: [external_measure_dir], discovered: [gem_measure_dir]) + + osw = described_class.send(:build_baseline_osw, build_reader('example-smalloffice-level2.xml')) + names = osw[:steps].map { |step| step[:measure_dir_name] } + typical = names.index('create_typical_building_from_model') + + expect(osw[:steps][typical][:arguments][:add_hvac]).to be false + expect(names[typical + 1, 2]).to eq %w[apply_hvac_topology_to_zone_scope apply_standard_hvac_sizing_and_efficiency] + expect(osw[:steps][typical + 1][:arguments]).to include(zone_scope: 'all_model_zones', operation: 'create') + end + + it 'plans baseline HVAC without systems that measures propose' do + stub_measure_dirs(local: [LOCAL_MEASURES_DIR], external: [external_measure_dir], discovered: [gem_measure_dir]) + planner = instance_double(BOSS::BaselineHvacPlanner) + allow(BOSS::BaselineHvacPlanner).to receive(:new).and_return(planner) + allow(BOSS::BaselineHvacPlanner).to receive(:proposed_system_ids).and_return(['Proposed']) + allow(planner).to receive(:plan) + .and_return(BOSS::BaselineHvacPlanner::Plan.new(status: :fallback, steps: [], messages: [])) + + described_class.send(:build_baseline_osw, build_reader('all_measures_applied_example.xml')) + expect(planner).to have_received(:plan).with(anything, 'DOE Ref 1980-2004', exclude_system_ids: ['Proposed']) + end + + it 'does not load scenario planning code' do + expect(defined?(BOSS::ScenarioHvacPlanner)).to be_nil + expect(defined?(BOSS::ScenarioMeasureMapper)).to be_nil + end end describe '.write_baseline_osw measure_paths ordering' do + before do + # Steps are covered above; these examples only check path ordering. + [ + :populate_set_run_period_args, + :populate_change_building_location_args, + :populate_create_bar_from_building_type_ratios_args, + :populate_create_typical_building_from_model_args, + :populate_set_lighting_loads_by_LPD_args, + :populate_set_electric_equipment_loads_by_epd_args, + :populate_replace_baseline_windows_args, + :populate_openstudio_results_args + ].each { |m| allow(OSWArgPopulator).to receive(m) } + end + + it 'orders measure_paths and file_paths exactly as local, gem, then external' do + Dir.mktmpdir do |output_dir| + stub_measure_dirs(local: ['/fake/local/measures'], external: [external_measure_dir], discovered: [gem_measure_dir]) + + osw_path = described_class.write_baseline_osw(xml_path, output_dir, nil, ASHRAE90_1) + osw = JSON.parse(File.read(osw_path), symbolize_names: true) + + expect(osw[:measure_paths]).to eq ['/fake/local/measures', gem_measure_dir, external_measure_dir] + expect(osw[:file_paths]).to eq ['/fake/local/files', '/fake/external/files'] + end + end + + it 'drops nil, empty, and cross-tier duplicate paths without reordering' do + Dir.mktmpdir do |output_dir| + stub_measure_dirs( + local: ['/fake/local/measures'], + external: [external_measure_dir], + discovered: [external_measure_dir, nil, '', '/fake/local/measures', gem_measure_dir, gem_measure_dir] + ) + + osw_path = described_class.write_baseline_osw(xml_path, output_dir, nil, ASHRAE90_1) + osw = JSON.parse(File.read(osw_path), symbolize_names: true) + + expect(osw[:measure_paths]).to eq ['/fake/local/measures', gem_measure_dir, external_measure_dir] + end + end it 'places local measures first, then gem-provided measures, then external repo measures' do Dir.mktmpdir do |output_dir| @@ -112,4 +374,44 @@ end end end + + describe 'running OSWs' do + let(:runner) { instance_double(OpenStudio::Extension::Runner, run_osws: []) } + let(:runner_options) { { run_simulations: true, verbose: false, num_parallel: 7, max_to_run: Float::INFINITY } } + + before do + allow(OpenStudio::Extension::Runner).to receive(:new).and_return(runner) + allow(BOSS.BOSS_logger).to receive(:warn) + allow(OpenStudio).to receive(:logFree) + end + + def touch_osw(*parts) + path = File.join(*parts, 'in.osw') + FileUtils.mkdir_p(File.dirname(path)) + File.write(path, '{}') + path + end + + describe '.run_baseline_osw' do + it 'runs only baseline/in.osw with the existing runner options and returns failures' do + Dir.mktmpdir do |dir| + baseline = touch_osw(dir, 'baseline') + touch_osw(dir, 'scenarios', 'Scenario1') + allow(runner).to receive(:run_osws).and_return(['failed']) + + expect(described_class.run_baseline_osw(dir)).to eq ['failed'] + expect(OpenStudio::Extension::Runner).to have_received(:new).with(Dir.pwd, [], runner_options) + expect(runner).to have_received(:run_osws).with([baseline]) + end + end + + it 'raises the existing error without building a runner when the baseline is missing' do + Dir.mktmpdir do |dir| + expect { described_class.run_baseline_osw(dir) } + .to raise_error(StandardError, /BOSS\.Boss\.run_baseline_osw: .*write_baseline_osw/) + expect(OpenStudio::Extension::Runner).not_to have_received(:new) + end + end + end + end end diff --git a/spec/tests/unit/buildingsync_reader_spec.rb b/spec/tests/unit/buildingsync_reader_spec.rb index edc2e9b..4cdb132 100644 --- a/spec/tests/unit/buildingsync_reader_spec.rb +++ b/spec/tests/unit/buildingsync_reader_spec.rb @@ -330,6 +330,25 @@ def site_with_building(site_xml, building_xml) describe 'get_principal_HVAC_system_type should' do end + describe 'get_hvac_systems_xml should' do + def reader_for(file_name) + path = File.expand_path("../../files/v2.7.0/#{file_name}", __dir__) + doc = REXML::Document.new(File.read(path), ignore_whitespace_nodes: :all) + BOSS::BuildingSyncReader.new(doc, nil, ASHRAE90_1) + end + + it 'return the facility HVACSystems element' do + hvac_systems = reader_for('example-smalloffice-level2.xml').get_hvac_systems_xml + expect(hvac_systems.name).to eq 'HVACSystems' + expect(hvac_systems.elements.to_a.map(&:name).uniq).to eq ['HVACSystem'] + end + + it 'return nil when the facility has no HVACSystems' do + reader = BOSS::BuildingSyncReader.new(REXML::Document.new(wrap_in_site('')), nil, ASHRAE90_1) + expect(reader.get_hvac_systems_xml).to be_nil + end + end + describe 'get_total_installed_power should' do def wrap_in_systems(xml) <<~XML diff --git a/spec/tests/unit/external_measure_repo_manager_spec.rb b/spec/tests/unit/external_measure_repo_manager_spec.rb index 035248f..1df4e57 100644 --- a/spec/tests/unit/external_measure_repo_manager_spec.rb +++ b/spec/tests/unit/external_measure_repo_manager_spec.rb @@ -166,6 +166,53 @@ def manager_for(manifest_path, install_dir) end end + it 'leaves scenario_only repos out unless include_scenario_only is true' do + Dir.mktmpdir do |dir| + install_dir = File.join(dir, 'vendor') + shared_root = File.join(install_dir, 'shared_repo', 'measures') + scenario_root = File.join(install_dir, 'scenario_repo', 'lib', 'measures') + FileUtils.mkdir_p(shared_root) + FileUtils.mkdir_p(scenario_root) + + yaml = <<~YAML + repos: + - name: scenario_repo + url: https://example.com/scenario.git + ref: abc123 + measure_roots: + - lib/measures + scenario_only: true + - name: shared_repo + url: https://example.com/shared.git + ref: main + measure_roots: + - measures + scenario_only: false + YAML + mgr = manager_for(write_manifest(dir, yaml), install_dir) + + expect(mgr.resolved_measure_directories).to eq [shared_root] + expect(mgr.resolved_measure_directories(include_scenario_only: true)).to eq [scenario_root, shared_root] + end + end + + it 'rejects a non-boolean scenario_only value' do + Dir.mktmpdir do |dir| + yaml = <<~YAML + repos: + - name: my_repo + url: https://example.com/repo.git + ref: main + measure_roots: + - measures + scenario_only: "yes" + YAML + mgr = manager_for(write_manifest(dir, yaml), dir) + + expect { mgr.resolved_measure_directories }.to raise_error(StandardError, /scenario_only must be true or false/) + end + end + it 'skips repo if checkout directory does not exist' do Dir.mktmpdir do |dir| install_dir = File.join(dir, 'vendor') @@ -308,5 +355,64 @@ def manager_for(manifest_path, install_dir) expect { manager_for(path, dir).configured? }.to raise_error(StandardError, /must be a map/) end end + + it 'raises when a repo entry sets both local_path and url' do + Dir.mktmpdir do |dir| + yaml = <<~YAML + repos: + - name: my_repo + local_path: ../my_repo + url: https://example.com/repo.git + measure_roots: [lib/measures] + YAML + path = write_manifest(dir, yaml) + expect { manager_for(path, dir).configured? }.to raise_error(StandardError, /either local_path or url/) + end + end + end + + # --------------------------------------------------------------------------- + describe 'local_path repos' do + def local_manifest(dir, scenario_only: false) + config_dir = File.join(dir, 'config') + FileUtils.mkdir_p(config_dir) + yaml = <<~YAML + repos: + - name: sibling + local_path: ../sibling + scenario_only: #{scenario_only} + measure_roots: [lib/measures] + YAML + write_manifest(config_dir, yaml) + end + + it 'resolves measure roots relative to the manifest without running git' do + Dir.mktmpdir do |dir| + mroot = File.join(dir, 'sibling', 'lib', 'measures') + FileUtils.mkdir_p(mroot) + mgr = manager_for(local_manifest(dir), File.join(dir, 'vendor')) + expect(mgr).not_to receive(:run_git) + + mgr.install_all + expect(mgr.resolved_measure_directories).to eq([File.expand_path(mroot)]) + end + end + + it 'raises an actionable error when the local checkout is missing' do + Dir.mktmpdir do |dir| + mgr = manager_for(local_manifest(dir), File.join(dir, 'vendor')) + expect(mgr).not_to receive(:run_git) + + expect { mgr.install_all }.to raise_error(StandardError, /Local measure repository 'sibling' not found/) + expect { mgr.resolved_measure_directories }.to raise_error(StandardError, /local_path/) + end + end + + it 'skips a missing scenario-only local checkout for baseline resolution' do + Dir.mktmpdir do |dir| + mgr = manager_for(local_manifest(dir, scenario_only: true), File.join(dir, 'vendor')) + expect(mgr.resolved_measure_directories).to eq([]) + end + end end end diff --git a/spec/tests/unit/hvac_target_binder_spec.rb b/spec/tests/unit/hvac_target_binder_spec.rb new file mode 100644 index 0000000..e853bd2 --- /dev/null +++ b/spec/tests/unit/hvac_target_binder_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'json' +require 'BOSS/constants' +require 'BOSS/external_measure_repo_manager' +require 'BOSS/hvac_topology_selector' +require 'BOSS/hvac_target_binder' + +RSpec.describe BOSS::HvacTargetBinder do + def match_result(premises, measure: 'hvac_ptac') + BOSS::HvacTopologySelector::Result.new( + status: :match, configuration: 'Packaged Terminal Air Conditioner', measure: measure, + hvac_system_id: 'HVAC-1', record_ids: ['D-1'], premises: premises, group_key: [:delivery, 'D-1'], messages: [] + ) + end + + let(:binder) { described_class.new } + + ['Building', 'Site', 'Facility'].each do |type| + it "binds #{type} premises to all model zones through the runtime binding measure" do + binding = binder.bind(match_result([{ type: type, id: "#{type}-1" }]), + operation: 'replace', standards_template: '90.1-2016') + expect(binding.status).to eq(:bound) + expect(binding.step).to eq( + measure_dir_name: 'apply_hvac_topology_to_zone_scope', + arguments: { topology_measure: 'hvac_ptac', operation: 'replace', zone_scope: 'all_model_zones', + standards_template: '90.1-2016' } + ) + end + end + + it 'returns missing input for zone or space premises instead of guessing names' do + premises = [{ type: 'Building', id: 'B-1' }, { type: 'ThermalZone', id: 'TZ-1' }] + binding = binder.bind(match_result(premises), operation: 'create', standards_template: '90.1-2019') + expect(binding.status).to eq(:missing_input) + expect(binding.step).to be_nil + expect(binding.messages.first).to include('ThermalZone TZ-1') + end + + it 'binds any premises to explicit zone names as a JSON array' do + premises = [{ type: 'ThermalZone', id: 'TZ-1' }] + binding = binder.bind(match_result(premises), operation: 'replace', standards_template: '90.1-2019', + zone_names: ['Office, East', 'Core', 'Core']) + expect(binding.status).to eq(:bound) + expect(binding.step[:arguments]).to eq( + topology_measure: 'hvac_ptac', operation: 'replace', zone_scope: 'explicit_zone_names', + zone_names_json: '["Office, East","Core"]', standards_template: '90.1-2019' + ) + end + + it 'rejects empty or blank explicit zone names' do + result = match_result([{ type: 'Building', id: 'B-1' }]) + [[], [''], [nil]].each do |names| + expect { binder.bind(result, operation: 'create', standards_template: '90.1-2019', zone_names: names) } + .to raise_error(ArgumentError, /zone_names/) + end + end + + it 'forwards selector measure arguments as topology_arguments_json' do + result = match_result([{ type: 'Building', id: 'B-1' }], measure: 'hvac_packaged_rooftop_heat_pump') + result.measure_arguments = { 'supplemental_heating_fuel' => 'NaturalGas' } + binding = binder.bind(result, operation: 'create', standards_template: '90.1-2019') + expect(binding.step[:arguments][:topology_arguments_json]).to eq('{"supplemental_heating_fuel":"NaturalGas"}') + end + + it 'returns missing input when no premises are linked' do + binding = binder.bind(match_result([]), operation: 'create', standards_template: '90.1-2019') + expect(binding.status).to eq(:missing_input) + end + + it 'passes non-match selector results through unchanged' do + result = match_result([{ type: 'Building', id: 'B-1' }]).dup + result.status = :mapping_gap + result.messages = ['gap'] + binding = binder.bind(result, operation: 'create', standards_template: '90.1-2019') + expect(binding).to have_attributes(status: :mapping_gap, step: nil, messages: ['gap']) + end + + it 'rejects templates and operations the topology measures do not support' do + result = match_result([{ type: 'Building', id: 'B-1' }]) + expect { binder.bind(result, operation: 'create', standards_template: 'DEER 2017') } + .to raise_error(ArgumentError, /standards_template/) + expect { binder.bind(result, operation: 'delete', standards_template: '90.1-2019') } + .to raise_error(ArgumentError, /operation/) + end + + it 'matches the binding measure arguments in the configured measure source' do + dirs = BOSS::ExternalMeasureRepoManager.new.resolved_measure_directories(include_scenario_only: true) + xml_path = dirs.map { |dir| File.join(dir, described_class::BINDING_MEASURE, 'measure.xml') }.find { |p| File.file?(p) } + skip 'apply_hvac_topology_to_zone_scope is not in the configured measure source' if xml_path.nil? + + doc = REXML::Document.new(File.read(xml_path)) + names = doc.get_elements('measure/arguments/argument/name').map(&:text) + expect(names).to eq(['topology_measure', 'operation', 'zone_scope', 'zone_names_json', 'standards_template', + 'topology_arguments_json']) + scopes = doc.get_elements("measure/arguments/argument[name='zone_scope']/choices/choice/value").map(&:text) + expect(scopes).to eq(['all_model_zones', 'explicit_zone_names']) + topologies = doc.get_elements("measure/arguments/argument[name='topology_measure']/choices/choice/value").map(&:text) + expect(topologies).to include('hvac_ptac', 'hvac_doas', 'hvac_vav_hw_reheat') + end +end diff --git a/spec/tests/unit/hvac_topology_selector_spec.rb b/spec/tests/unit/hvac_topology_selector_spec.rb new file mode 100644 index 0000000..cad4f29 --- /dev/null +++ b/spec/tests/unit/hvac_topology_selector_spec.rb @@ -0,0 +1,335 @@ +# frozen_string_literal: true + +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'rexml/document' +require 'BOSS/hvac_topology_selector' + +RSpec.describe BOSS::HvacTopologySelector do + dx = lambda do |type, condenser = 'CN-AIR'| + "#{type}" \ + "" + end + heat_pump = lambda do |type, backup = 'Electricity'| + backup_xml = backup ? "#{backup}" : '' + "#{type ? "#{type}" : ''}" \ + "#{backup_xml}" + end + central_air = lambda do |terminal, reheat, extra = ''| + "Central fan#{terminal}" \ + "#{reheat}#{extra}" + end + + electric_resistance = '' + gas_furnace = 'Natural gasAirWarm air' + hot_water = 'Hot water' + chilled_water = 'Chilled water' + no_cooling = '' + no_heating = '' + single_zone_cav = central_air.call('CAV terminal box no reheat', 'None') + vav_hw = central_air.call('VAV terminal box not fan powered with reheat', 'Heating plant', '') + fan_coil = ->(type) { "#{type}" } + + air_condenser = '' + hydronic_plants = 'Hot water' \ + 'Natural gas' \ + 'Vapor compression' \ + 'Electric Motor' \ + '' \ + '' \ + 'Cooling tower' + all_plants = hydronic_plants + air_condenser + premises = '' + + # One HVACSystem with a single HS/CS/Delivery triple plus optional plants and other systems. + system_xml = lambda do |delivery:, heating:, cooling:, zoning: nil, plants: all_plants, others: '', delivery_refs: nil, + delivery_premises: premises, cooling_extra: ''| + refs = delivery_refs || '' + zoning_xml = zoning ? "#{zoning}" : '' + '' \ + "#{zoning_xml}#{heating}" \ + "#{cooling}#{cooling_extra}" \ + "#{delivery_premises}#{delivery}#{refs}" \ + "#{plants}#{others}" + end + + def select_from(body, prefix: nil) + ns = prefix ? "xmlns:#{prefix}=\"http://buildingsync.net/schemas/bedes-auc/2019\"" : '' + xml = "#{body}" + xml = xml.gsub(%r{<(/?)([A-Za-z])}, "<\\1#{prefix}:\\2") if prefix + doc = REXML::Document.new(xml) + described_class.new.select(doc.root.elements.to_a.first) + end + + exact_cases = { + 'Packaged Terminal Air Conditioner' => ['hvac_ptac', { delivery: '', heating: electric_resistance, + cooling: dx.call('Packaged terminal air conditioner (PTAC)') }], + 'Packaged Terminal Heat Pump' => ['hvac_pthp', { delivery: '', heating: heat_pump.call('Packaged Terminal'), + cooling: dx.call('Packaged terminal heat pump (PTHP)') }], + 'Packaged Rooftop Air Conditioner' => ['hvac_packaged_rooftop_ac', { delivery: single_zone_cav, heating: gas_furnace, + cooling: dx.call('Packaged/unitary direct expansion/RTU'), + zoning: 'Single zone' }], + 'Packaged Rooftop Heat Pump' => ['hvac_packaged_rooftop_heat_pump', { delivery: single_zone_cav, + heating: heat_pump.call('Packaged Unitary'), + cooling: dx.call('Packaged/unitary heat pump'), + zoning: 'Single zone' }], + 'Warm Air Furnace' => ['hvac_warm_air_furnace', { delivery: single_zone_cav, heating: gas_furnace, cooling: no_cooling, + zoning: 'Single zone' }], + 'Four Pipe Fan Coil Unit' => ['hvac_four_pipe_fan_coil', { delivery: fan_coil.call('Fan coil 4 pipe'), heating: hot_water, + cooling: chilled_water }], + 'VAV with Hot Water Reheat' => ['hvac_vav_hw_reheat', { delivery: vav_hw, heating: hot_water, cooling: chilled_water, + zoning: 'Multi zone', cooling_extra: '1' }], + 'Packaged Rooftop VAV with Hot Water Reheat' => ['hvac_packaged_rooftop_vav_hw_reheat', { + delivery: vav_hw, heating: hot_water, cooling: dx.call('Packaged/unitary direct expansion/RTU'), zoning: 'Multi zone', + cooling_extra: '1' + }], + 'VRF Terminal Unit' => ['hvac_vrf', { delivery: fan_coil.call('VRF terminal units'), heating: heat_pump.call(nil, nil), + cooling: dx.call('Variable refrigerant flow'), cooling_extra: '1' }] + } + + describe 'exact matches' do + exact_cases.each do |configuration, (measure, args)| + it "selects #{measure} for #{configuration}" do + results = select_from(system_xml.call(**args)) + expect(results.length).to eq(1) + result = results.first + expect(result.messages).to eq([]) + expect(result).to have_attributes(status: :match, configuration: configuration, measure: measure, + hvac_system_id: 'HVAC-1', premises: [{ type: 'ThermalZone', id: 'TZ-1' }]) + end + end + + it 'groups VAV by cooling source and fan coils by plant tuple' do + vav = select_from(system_xml.call(**exact_cases['VAV with Hot Water Reheat'][1])).first + fcu = select_from(system_xml.call(**exact_cases['Four Pipe Fan Coil Unit'][1])).first + expect(vav.group_key).to eq([:cooling_source, 'CS-1']) + expect(fcu.group_key).to eq([:plants, 'HP-1', 'CP-1', 'CN-TOWER']) + end + + it 'treats an empty FanBasedDistributionType as absent' do + args = exact_cases['Packaged Terminal Air Conditioner'][1] + delivery = '' + expect(select_from(system_xml.call(**args, delivery:)).first.status).to eq(:match) + end + + it 'accepts FurnaceType Other or absent and rejects other furnace types' do + args = exact_cases['Warm Air Furnace'][1] + other = select_from(system_xml.call(**args, heating: gas_furnace.sub('Warm air', 'Other'))).first + absent = select_from(system_xml.call(**args, heating: gas_furnace.sub('Warm air', ''))).first + steam = select_from(system_xml.call(**args, heating: gas_furnace.sub('Warm air', 'Steam'))).first + expect([other.status, absent.status, steam.status]).to eq([:match, :match, :conflicting_input]) + end + + it 'passes the heat pump backup fuel as a measure argument' do + args = exact_cases['Packaged Rooftop Heat Pump'][1] + electric = select_from(system_xml.call(**args)).first + gas = select_from(system_xml.call(**args, heating: heat_pump.call('Packaged Unitary', 'Natural gas'))).first + expect(electric.measure_arguments).to eq('supplemental_heating_fuel' => 'Electricity') + expect(gas).to have_attributes(status: :match, measure_arguments: { 'supplemental_heating_fuel' => 'NaturalGas' }) + end + + it 'treats CS/Quantity as a guard on VAV and VRF rows' do + ['VAV with Hot Water Reheat', 'VRF Terminal Unit'].each do |configuration| + args = exact_cases[configuration][1] + expect(select_from(system_xml.call(**args, cooling_extra: '')).first.status).to eq(:match) + expect(select_from(system_xml.call(**args, cooling_extra: '2')).first.status).to eq(:conflicting_input) + end + end + + it 'reads an omitted condenser reference as air-cooled for packaged DX but not VRF' do + strip = ->(xml) { xml.sub(%r{.*?}, '') } + ['Packaged Terminal Air Conditioner', 'Packaged Rooftop Heat Pump', 'Packaged Rooftop VAV with Hot Water Reheat'].each do |configuration| + args = exact_cases[configuration][1] + expect(select_from(system_xml.call(**args, cooling: strip.call(args[:cooling]))).first.status).to eq(:match) + end + vrf = exact_cases['VRF Terminal Unit'][1] + expect(select_from(system_xml.call(**vrf, cooling: strip.call(vrf[:cooling]))).first.status).not_to eq(:match) + end + + it 'ignores namespace prefixes' do + result = select_from(system_xml.call(**exact_cases['Packaged Terminal Air Conditioner'][1]), prefix: 'auc').first + expect(result).to have_attributes(status: :match, measure: 'hvac_ptac') + end + end + + describe 'non-match results' do + { + 'mapping gap for fan-powered VAV with electric reheat' => [ + :mapping_gap, 'hvac_packaged_rooftop_vav_electric_reheat', + { delivery: central_air.call('VAV terminal box fan powered with reheat', 'Local electric resistance'), + heating: electric_resistance, cooling: dx.call('Packaged/unitary direct expansion/RTU'), zoning: 'Multi zone' } + ], + 'mapping gap for ground source heat pump' => [ + :mapping_gap, 'hvac_ground_source_heat_pump', + { delivery: '', heating: heat_pump.call(nil, nil), cooling: dx.call('Other', 'CN-G'), + plants: '' } + ], + 'not mappable for split DX' => [ + :not_mappable, nil, + { delivery: single_zone_cav, heating: gas_furnace, cooling: dx.call('Split DX air conditioner'), zoning: 'Single zone' } + ], + 'not mappable for two-pipe fan coil' => [ + :not_mappable, nil, { delivery: fan_coil.call('Fan coil 2 pipe'), heating: hot_water, cooling: chilled_water } + ], + 'not mappable for air-cooled chiller' => [ + :not_mappable, nil, + { delivery: fan_coil.call('Fan coil 4 pipe'), heating: hot_water, cooling: chilled_water, + plants: all_plants.sub('Cooling tower', + '') } + ], + 'missing input when the cooling source reference is absent' => [ + :missing_input, nil, + { delivery: '', heating: electric_resistance, cooling: dx.call('Packaged terminal air conditioner (PTAC)'), + delivery_refs: '' } + ], + 'missing input when the delivery has no linked premises' => [ + :missing_input, nil, + { delivery: '', heating: electric_resistance, cooling: dx.call('Packaged terminal air conditioner (PTAC)'), + delivery_premises: '' } + ], + 'missing input when detailed data identifies no configuration' => [ + :missing_input, nil, { delivery: '', heating: electric_resistance, cooling: no_cooling } + ], + 'conflicting input for a broken condenser reference' => [ + :conflicting_input, nil, + { delivery: '', heating: electric_resistance, + cooling: dx.call('Packaged terminal air conditioner (PTAC)', 'CN-MISSING') } + ], + 'conflicting input for a failed fuel guard' => [ + :conflicting_input, nil, + { delivery: '', heating: "Natural gas#{electric_resistance}", + cooling: dx.call('Packaged terminal air conditioner (PTAC)') } + ], + 'conflicting input for a required-absent element' => [ + :conflicting_input, nil, + { delivery: fan_coil.call('Fan coil 4 pipe'), + heating: electric_resistance, cooling: dx.call('Packaged terminal air conditioner (PTAC)') } + ], + 'conflicting input for four-pipe fan coil with 2 pipe configuration' => [ + :conflicting_input, nil, + { delivery: fan_coil.call('Fan coil 4 pipe').sub('', '2 pipe'), + heating: hot_water, cooling: chilled_water } + ] + }.each do |description, (status, measure, args)| + it "reports #{description}" do + results = select_from(system_xml.call(**args)) + expect(results.length).to eq(1) + expect(results.first.status).to eq(status) + expect(results.first.measure).to eq(measure) + expect(results.first.messages).not_to be_empty + end + end + + it 'reports family-only data as missing input' do + result = select_from('Packaged Rooftop Air Conditioner').first + expect(result.status).to eq(:missing_input) + expect(result.messages.first).to include('family-level data') + end + + it 'reports duplicate IDs as conflicting input' do + body = system_xml.call(**exact_cases['Packaged Terminal Air Conditioner'][1]).sub('CN-AIR">', 'HS-1">') + expect(select_from(body).first.status).to eq(:conflicting_input) + end + + it 'inherits HVACSystem linked premises when the delivery has none' do + system_premises = '' + body = system_xml.call(**exact_cases['Packaged Terminal Air Conditioner'][1], delivery_premises: '') + system_premises + expect(select_from(body).first).to have_attributes(status: :match, premises: [{ type: 'Building', id: 'B-1' }]) + end + + it 'keeps delivery linked premises over HVACSystem linked premises' do + system_premises = '' + body = system_xml.call(**exact_cases['Packaged Terminal Air Conditioner'][1]) + system_premises + expect(select_from(body).first.premises).to eq([{ type: 'ThermalZone', id: 'TZ-1' }]) + end + end + + describe 'ventilation and other HVAC systems' do + ventilation_delivery = "#{premises}#{single_zone_cav}" \ + '' + other = lambda do |type_xml, links: '', + integration: 'Stand-alone'| + "#{type_xml}" \ + "#{integration}#{links}" + end + mechanical = ->(type) { "#{type}" } + + with_ventilation = lambda do |others, ventilation_heating: no_heating| + system_xml.call(**exact_cases['Packaged Terminal Air Conditioner'][1], others: others) + .sub('', "#{ventilation_heating}") + .sub('', "#{no_cooling}") + .sub('', "#{ventilation_delivery}") + end + + it 'selects PTAC plus DOAS as separate results' do + results = select_from(with_ventilation.call(other.call(mechanical.call('Dedicated outdoor air system')))) + expect(results.map { |r| [r.status, r.measure] }).to eq([[:match, 'hvac_ptac'], [:match, 'hvac_doas']]) + expect(results.last.group_key).to eq([:other, 'O-1']) + expect(results.last.record_ids).to eq(['O-1', 'D-V']) + end + + it 'selects ventilation only for supply-only ventilation' do + results = select_from(with_ventilation.call(other.call(mechanical.call('Supply only')))) + expect(results.last).to have_attributes(status: :match, measure: 'hvac_ventilation_only') + end + + it 'reports conditioned DOAS as not mappable' do + results = select_from(with_ventilation.call(other.call(mechanical.call('Dedicated outdoor air system')), + ventilation_heating: electric_resistance)) + expect(results.last.status).to eq(:not_mappable) + end + + it 'reports energy recovery ventilation as not mappable without dropping it' do + results = select_from(with_ventilation.call(other.call(mechanical.call('Energy recovery ventilator')))) + expect(results.map(&:status)).to eq([:match, :not_mappable]) + end + + it 'reports humidifiers as not mappable' do + results = select_from(with_ventilation.call(other.call('', links: ''))) + expect(results.last).to have_attributes(status: :not_mappable, + configuration: 'Humidification / dehumidification / air cleaning') + end + + it 'reports a broken linked delivery as conflicting input' do + links = '' + results = select_from(with_ventilation.call(other.call(mechanical.call('Supply only'), links: links))) + expect(results.last.status).to eq(:conflicting_input) + end + + conditioning_link = '' + + it 'still selects conditioning deliveries linked by VentilationType None' do + results = select_from(with_ventilation.call(other.call(mechanical.call('None'), links: conditioning_link))) + expect(results.map(&:status)).to eq([:match, :missing_input, :no_hvac]) + expect(results.first.measure).to eq('hvac_ptac') + expect(results.last.configuration).to eq('No separate ventilation equipment') + end + + it 'still selects conditioning deliveries linked by an untyped ventilation record' do + untyped = 'false' + results = select_from(with_ventilation.call(other.call(untyped, links: conditioning_link))) + expect(results.first).to have_attributes(status: :match, measure: 'hvac_ptac') + expect(results.last.status).to eq(:missing_input) + end + + it 'still selects conditioning deliveries linked by integrated outdoor air records' do + integrated = other.call(mechanical.call('Supply only'), links: conditioning_link, + integration: 'Integrated with central air distribution') + second = integrated[%r{}].sub('O-1', 'O-2') + results = select_from(with_ventilation.call(integrated.sub('', "#{second}"))) + expect(results.map(&:status)).to eq([:match, :missing_input, :integrated, :integrated]) + expect(results.first.measure).to eq('hvac_ptac') + end + + it 'lets VentilationType None own explicitly unconditioned deliveries' do + body = with_ventilation.call(other.call(mechanical.call('None'))).sub("#{single_zone_cav}", '') + results = select_from(body) + expect(results.map(&:status)).to eq([:match, :no_hvac]) + expect(results.last.configuration).to eq('Explicitly no HVAC') + end + end +end diff --git a/spec/tests/unit/osw_arg_populator_spec.rb b/spec/tests/unit/osw_arg_populator_spec.rb new file mode 100644 index 0000000..2205bc5 --- /dev/null +++ b/spec/tests/unit/osw_arg_populator_spec.rb @@ -0,0 +1,93 @@ +# ******************************************************************************* +# OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. +# BuildingSync(R), Copyright (c) Alliance for Energy Innovation, LLC. +# See also https://github.com/BuildingSync/BOSS/blob/develop/LICENSE.md +# ******************************************************************************* + +require 'json' +require 'BOSS/osw_arg_populator' + +RSpec.describe OSWArgPopulator do + def round_trip(osw) + JSON.parse(JSON.pretty_generate(osw), symbolize_names: true) + end + + def results_step + { measure_dir_name: 'openstudio_results', arguments: { __SKIP__: false } } + end + + describe '.set_step_argument' do + it 'serializes boolean, numeric, and string arguments without coercion' do + osw = { steps: [] } + step = described_class.append_step(osw, { measure_dir_name: 'm', arguments: {} }) + { + 'on' => true, 'off' => false, 'zero' => 0, 'count' => 4, 'ratio' => 0.6, + 'text' => 'Inferred', 'empty' => '', 'numeric_text' => '4', 'boolean_text' => 'false' + }.each { |name, value| described_class.set_step_argument(step, name, value) } + + arguments = round_trip(osw)[:steps].first[:arguments] + expect(arguments).to eq( + on: true, off: false, zero: 0, count: 4, ratio: 0.6, + text: 'Inferred', empty: '', numeric_text: '4', boolean_text: 'false' + ) + expect(arguments[:count]).to be_an Integer + expect(arguments[:ratio]).to be_a Float + end + + it 'updates only the given step when other steps share its measure_dir_name' do + osw = { steps: [] } + baseline = described_class.append_step(osw, { measure_dir_name: 'SetLightingLoadsByLPD', arguments: { lpd: 1.0 } }) + first = described_class.append_step(osw, { measure_dir_name: 'SetLightingLoadsByLPD', arguments: { lpd: 0.6 } }) + described_class.append_step(osw, { measure_dir_name: 'SetLightingLoadsByLPD', arguments: { lpd: 0.5 } }) + + described_class.set_step_argument(first, 'lpd', 0.4) + described_class.set_step_argument(baseline, '__SKIP__', false) + + expect(osw[:steps].map { |step| step[:arguments] }).to eq [ + { lpd: 1.0, __SKIP__: false }, { lpd: 0.4 }, { lpd: 0.5 } + ] + expect(osw[:steps].map { |step| step.key?(:name) }).to all(be false) + end + end + + describe '.append_step' do + it 'appends at the end by default and keeps prepopulated argument types' do + osw = { steps: [results_step] } + described_class.append_step(osw, { measure_dir_name: 'm', arguments: { flag: true, n: 2, x: 1.5, s: '0.50' } }) + + steps = round_trip(osw)[:steps] + expect(steps.map { |step| step[:measure_dir_name] }).to eq ['openstudio_results', 'm'] + expect(steps.last[:arguments]).to eq(flag: true, n: 2, x: 1.5, s: '0.50') + end + + it 'inserts before the named measure in call order, or appends when it is absent' do + osw = { steps: [{ measure_dir_name: 'a', arguments: {} }, results_step] } + described_class.append_step(osw, { measure_dir_name: 'b', arguments: {} }, before_measure: 'openstudio_results') + described_class.append_step(osw, { measure_dir_name: 'c', arguments: {} }, before_measure: 'openstudio_results') + described_class.append_step(osw, { measure_dir_name: 'd', arguments: {} }, before_measure: 'missing') + + expect(osw[:steps].map { |step| step[:measure_dir_name] }).to eq ['a', 'b', 'c', 'openstudio_results', 'd'] + end + + it 'adds an arguments hash when the step has none' do + osw = { steps: [] } + expect(described_class.append_step(osw, { measure_dir_name: 'm' })).to eq(measure_dir_name: 'm', arguments: {}) + end + + it 'stores independent copies of the source step' do + source = { measure_dir_name: 'm', arguments: { s: 'value' } } + osw = { steps: [] } + first = described_class.append_step(osw, source) + second = described_class.append_step(osw, source) + + first[:arguments][:s] << '-changed' + described_class.set_step_argument(second, 'n', 1) + + expect(source).to eq(measure_dir_name: 'm', arguments: { s: 'value' }) + expect(osw[:steps]).to eq [ + { measure_dir_name: 'm', arguments: { s: 'value-changed' } }, + { measure_dir_name: 'm', arguments: { s: 'value', n: 1 } } + ] + end + end +end