Class: RunOpenStudioMeasures

Inherits:
OpenStudio::Workflow::Job show all
Includes:
OpenStudio::Workflow::Util::Measure, OpenStudio::Workflow::Util::Model
Defined in:
lib/openstudio/workflow/jobs/run_os_measures.rb

Overview

Run any OpenStudio measures contained in the OSW

Instance Method Summary collapse

Methods included from OpenStudio::Workflow::Util::Model

#load_idf, #load_osm, #save_epjson, #save_idf, #save_osm, #translate_idf_to_epjson, #translate_to_energyplus

Methods included from OpenStudio::Workflow::Util::Measure

#add_result_measure_info, #apply_arguments, #apply_arguments_2, #apply_measure, #apply_measures, #validate_measures

Constructor Details

#initialize(input_adapter, output_adapter, registry, options = {}) ⇒ RunOpenStudioMeasures

Returns a new instance of RunOpenStudioMeasures.



15
16
17
# File 'lib/openstudio/workflow/jobs/run_os_measures.rb', line 15

def initialize(input_adapter, output_adapter, registry, options = {})
  super
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/openstudio/workflow/jobs/run_os_measures.rb', line 19

def perform
  @logger.debug "Calling #{__method__} in the #{self.class} class"

  # halted workflow is handled in apply_measures

  # set weather file
  if @registry[:wf] && @registry[:model]
    epwFile = OpenStudio::EpwFile.load(@registry[:wf])
    if !epwFile.empty?
      OpenStudio::Model::WeatherFile.setWeatherFile(@registry[:model], epwFile.get)
    else
      @logger.warn "Could not load weather file from '#{@registry[:wf]}'"
    end
  end

  # Ensure output_attributes is initialized in the registry
  @registry.register(:output_attributes) { {} } unless @registry[:output_attributes]

  # Execute the OpenStudio measures
  @options[:output_adapter] = @output_adapter
  @logger.info 'Beginning to execute OpenStudio measures.'
  apply_measures('ModelMeasure'.to_MeasureType, @registry, @options)
  @logger.info('Finished applying OpenStudio measures.')

  # Send the measure output attributes to the output adapter
  @logger.debug 'Communicating measure output attributes to the output adapter'
  @output_adapter.communicate_measure_attributes @registry[:output_attributes]

  # save the final OSM
  if !@options[:fast]
    save_osm(@registry[:model], @registry[:run_dir])
  end

  # Save the OSM if the :debug option is true
  return nil unless @options[:debug]

  @registry[:time_logger]&.start('Saving OSM')
  osm_name = save_osm(@registry[:model], @registry[:root_dir])
  @registry[:time_logger]&.stop('Saving OSM')
  @logger.debug "Saved model as #{osm_name}"

  nil
end