Class: RunEnergyplus

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio/workflow/jobs/run_energyplus/run_energyplus.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory, logger, time_logger, adapter, options = {}) ⇒ RunEnergyplus

Initialize param directory: base directory where the simulation files are prepared param logger: logger object in which to write log messages



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/openstudio/workflow/jobs/run_energyplus/run_energyplus.rb', line 29

def initialize(directory, logger, time_logger, adapter, options = {})
  @logger = logger

  energyplus_path = find_energyplus
  defaults = {
    energyplus_path: energyplus_path
  }
  @options = defaults.merge(options)

  # TODO: use openstudio tool finder for this
  @directory = directory
  @run_directory = "#{@directory}/run"
  @adapter = adapter
  @time_logger = time_logger
  @results = {}

  # container for storing the energyplus files there were copied into the local directory. These will be
  # removed at the end of the simulation.
  @energyplus_files = []
  @energyplus_exe = nil
  @expand_objects_exe = nil

  @logger.info "#{self.class} passed the following options #{@options}"
end

Instance Method Details

#performObject



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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/openstudio/workflow/jobs/run_energyplus/run_energyplus.rb', line 54

def perform
  @logger.info "Calling #{__method__} in the #{self.class} class"
  @logger.info "Current directory is #{@directory}"

  # Ensure that the directory is created (but it should already be at this point)
  FileUtils.mkdir_p(@run_directory)

  # if the weather file is already in the directory, then just use that weather file
  weather_file_name = nil
  weather_files = Dir["#{@directory}/*.epw"]
  if weather_files.size > 1
    @logger.info 'Multiple weather files in the directory. Will rely on the weather file name in the openstudio model'
  elsif weather_files.size == 1
    weather_file_name = weather_files.first
  end

  # verify that the OSM, IDF, and the Weather files are in the run directory as the 'in.*' format
  if !weather_file_name &&
     @options[:run_openstudio] &&
     @options[:run_openstudio][:weather_filename] &&
     File.exist?(@options[:run_openstudio][:weather_filename])
    weather_file_name = @options[:run_openstudio][:weather_filename]
  end

  if weather_file_name
    # verify that it is named in.epw
    @logger.info "Weather file for EnergyPlus simulation is #{weather_file_name}"
    FileUtils.copy(weather_file_name, "#{@run_directory}/in.epw")
  else
    fail "EPW file not found or not sent to #{self.class}"
  end

  # check if the run folder has an IDF. If not then check if the parent folder does.
  idf_file_name = nil
  if File.exist?("#{@run_directory}/in.idf")
    @logger.info 'IDF (in.idf) already exists in the run directory'
  else
    # glob for idf at the directory level
    idfs = Dir["#{@directory}/*.idf"]
    if idfs.size > 1
      @logger.info 'Multiple IDF files in the directory. Cannot continue'
    elsif idfs.size == 1
      idf_file_name = idfs.first
    end
  end

  # Need to check the in.idf and in.osm
  # FileUtils.copy(options[:osm], "#{@run_directory}/in.osm")
  if idf_file_name
    FileUtils.copy(idf_file_name, "#{@run_directory}/in.idf")
  end

  # can't create symlinks because the /vagrant mount is actually a windows mount
  @time_logger.start('Copying EnergyPlus files')
  prepare_energyplus_dir
  @time_logger.stop('Copying EnergyPlus files')

  @time_logger.start('Running EnergyPlus')
  @results = call_energyplus
  @time_logger.stop('Running EnergyPlus')

  @results
end