Method: RunTranslation#perform

Defined in:
lib/openstudio/workflow/jobs/run_translation.rb

#performObject



17
18
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
# File 'lib/openstudio/workflow/jobs/run_translation.rb', line 17

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

  # skip if halted
  if @registry[:runner].halted
    @logger.info 'Workflow halted, skipping OSM to IDF translation'
    @registry.register(:model_idf) { OpenStudio::Workspace.new } # This allows model arguments to still be calculated
    return nil
  end

  # Ensure that the run directory is created
  FileUtils.mkdir_p(@registry[:run_dir])

  # Copy in the weather file defined in the registry, or alternately in the options
  if @registry[:wf]
    @logger.info "Weather file for EnergyPlus simulation is #{@registry[:wf]}"
    FileUtils.copy(@registry[:wf], "#{@registry[:run_dir]}/in.epw")
    @registry.register(:wf) { "#{@registry[:run_dir]}/in.epw" }
  else
    @logger.warn "EPW file not found or not sent to #{self.class}"
  end

  # Translate the OSM to an IDF
  @logger.info 'Beginning the translation to IDF'
  @registry[:time_logger]&.start('Translating to EnergyPlus')
  model_idf = translate_to_energyplus @registry[:model], @logger
  @registry[:time_logger]&.stop('Translating to EnergyPlus')
  @registry.register(:model_idf) { model_idf }
  @logger.info 'Successfully translated to IDF'

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

  @registry[:time_logger]&.start('Saving IDF')
  idf_name = save_idf(@registry[:model_idf], @registry[:root_dir])
  @registry[:time_logger]&.stop('Saving IDF')
  @logger.debug "Saved IDF as #{idf_name}"

  nil
end