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.



45
46
47
# File 'lib/openstudio/workflow/jobs/run_os_measures.rb', line 45

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

Instance Method Details

#performObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/openstudio/workflow/jobs/run_os_measures.rb', line 49

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