openstudio-workflow 1.0.0.pat1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +16 -68
  4. data/Rakefile +9 -9
  5. data/bin/openstudio_cli +786 -0
  6. data/lib/openstudio/workflow/adapters/input/local.rb +97 -0
  7. data/lib/openstudio/workflow/adapters/output/local.rb +90 -0
  8. data/lib/openstudio/workflow/adapters/output/socket.rb +70 -0
  9. data/lib/openstudio/workflow/{jobs/run_preflight/run_preflight.rb → adapters/output/web.rb} +37 -19
  10. data/lib/openstudio/workflow/{adapter.rb → adapters/output_adapter.rb} +53 -51
  11. data/lib/openstudio/workflow/job.rb +22 -0
  12. data/lib/openstudio/workflow/jobs/{run_energyplus → resources}/monthly_report.idf +0 -0
  13. data/lib/openstudio/workflow/jobs/run_energyplus.rb +49 -0
  14. data/lib/openstudio/workflow/jobs/run_ep_measures.rb +55 -0
  15. data/lib/openstudio/workflow/jobs/run_initialization.rb +136 -0
  16. data/lib/openstudio/workflow/jobs/run_os_measures.rb +59 -0
  17. data/lib/openstudio/workflow/jobs/run_postprocess.rb +53 -0
  18. data/lib/openstudio/workflow/jobs/run_preprocess.rb +81 -0
  19. data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +86 -0
  20. data/lib/openstudio/workflow/jobs/run_translation.rb +49 -0
  21. data/lib/openstudio/workflow/multi_delegator.rb +1 -3
  22. data/lib/openstudio/workflow/registry.rb +137 -0
  23. data/lib/openstudio/workflow/run.rb +182 -221
  24. data/lib/openstudio/workflow/time_logger.rb +1 -1
  25. data/lib/openstudio/workflow/util/energyplus.rb +564 -0
  26. data/lib/openstudio/workflow/util/io.rb +33 -0
  27. data/lib/openstudio/workflow/util/measure.rb +520 -0
  28. data/lib/openstudio/workflow/util/model.rb +100 -0
  29. data/lib/openstudio/workflow/util/post_process.rb +177 -0
  30. data/lib/openstudio/workflow/util/weather_file.rb +108 -0
  31. data/lib/openstudio/workflow/util.rb +14 -0
  32. data/lib/openstudio/workflow/version.rb +1 -1
  33. data/lib/openstudio/workflow_json.rb +399 -0
  34. data/lib/openstudio/workflow_runner.rb +213 -0
  35. data/lib/openstudio-workflow.rb +13 -118
  36. metadata +45 -85
  37. data/lib/openstudio/extended_runner.rb +0 -105
  38. data/lib/openstudio/workflow/adapters/local.rb +0 -101
  39. data/lib/openstudio/workflow/adapters/mongo.rb +0 -227
  40. data/lib/openstudio/workflow/jobs/lib/apply_measures.rb +0 -253
  41. data/lib/openstudio/workflow/jobs/run_energyplus/run_energyplus.rb +0 -314
  42. data/lib/openstudio/workflow/jobs/run_openstudio/run_openstudio.rb +0 -230
  43. data/lib/openstudio/workflow/jobs/run_postprocess/run_postprocess.rb +0 -110
  44. data/lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb +0 -471
  45. data/lib/openstudio/workflow/jobs/run_runmanager/run_runmanager.rb +0 -247
  46. data/lib/openstudio/workflow/jobs/run_xml/run_xml.rb +0 -279
@@ -0,0 +1,97 @@
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
20
+ require 'openstudio/workflow_json'
21
+
22
+ # Local file based workflow
23
+ module OpenStudio
24
+ module Workflow
25
+ module InputAdapter
26
+ class Local
27
+ def initialize(osw_path = './workflow.osw')
28
+ @osw_abs_path = File.absolute_path(osw_path, Dir.pwd)
29
+
30
+ @workflow = if File.exist? @osw_abs_path
31
+ ::JSON.parse(File.read(@osw_abs_path), symbolize_names: true)
32
+ end
33
+ end
34
+
35
+ # Get the OSW file from the local filesystem
36
+ #
37
+ def workflow
38
+ raise "Could not read workflow from #{@osw_abs_path}" if @workflow.nil?
39
+ @workflow
40
+ end
41
+
42
+ # Get the OSW path
43
+ #
44
+ def osw_path
45
+ @osw_abs_path
46
+ end
47
+
48
+ # Get the OSW dir
49
+ #
50
+ def osw_dir
51
+ File.dirname(@osw_abs_path)
52
+ end
53
+
54
+ # Get the run dir
55
+ #
56
+ def run_dir
57
+ result = File.join(osw_dir, 'run')
58
+ if workflow
59
+ begin
60
+ workflow_json = nil
61
+ begin
62
+ # Create a temporary WorkflowJSON to compute run directory
63
+ workflow_json = OpenStudio::WorkflowJSON.new(JSON.fast_generate(workflow))
64
+ workflow_json.setOswDir(osw_dir)
65
+ rescue Exception => e
66
+ workflow_json = WorkflowJSON_Shim.new(workflow, osw_dir)
67
+ end
68
+ result = workflow_json.absoluteRunDir.to_s
69
+ rescue
70
+ end
71
+ end
72
+ result
73
+ end
74
+
75
+ # Get the associated OSD (datapoint) file from the local filesystem
76
+ #
77
+ def datapoint
78
+ # DLM: should this come from the OSW? the osd id and checksum are specified there.
79
+ osd_abs_path = File.join(osw_dir, 'datapoint.osd')
80
+ if File.exist? osd_abs_path
81
+ ::JSON.parse(File.read(osd_abs_path), symbolize_names: true)
82
+ end
83
+ end
84
+
85
+ # Get the associated OSA (analysis) definition from the local filesystem
86
+ #
87
+ def analysis
88
+ # DLM: should this come from the OSW? the osd id and checksum are specified there.
89
+ osa_abs_path = File.join(osw_dir, 'analysis.osa')
90
+ if File.exist? osa_abs_path
91
+ ::JSON.parse(File.read(osa_abs_path), symbolize_names: true)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,90 @@
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
20
+ require 'openstudio/workflow/adapters/output_adapter'
21
+
22
+ # Local file based workflow
23
+ module OpenStudio
24
+ module Workflow
25
+ module OutputAdapter
26
+ class Local < OutputAdapters
27
+ def initialize(options = {})
28
+ raise 'The required :output_directory option was not passed to the local output adapter' unless options[:output_directory]
29
+ super
30
+ end
31
+
32
+ # Write to the filesystem that the process has started
33
+ #
34
+ def communicate_started
35
+ File.open("#{@options[:output_directory]}/started.job", 'w') { |f| f << "Started Workflow #{::Time.now}" }
36
+ end
37
+
38
+ # Write to the filesystem that the process has completed
39
+ #
40
+ def communicate_complete
41
+ File.open("#{@options[:output_directory]}/finished.job", 'w') { |f| f << "Finished Workflow #{::Time.now}" }
42
+ end
43
+
44
+ # Write to the filesystem that the process has failed
45
+ #
46
+ def communicate_failure
47
+ File.open("#{@options[:output_directory]}/failed.job", 'w') { |f| f << "Failed Workflow #{::Time.now}" }
48
+ end
49
+
50
+ # Do nothing on a state transition
51
+ #
52
+ def communicate_transition(_ = nil, _ = nil, _ = nil)
53
+ end
54
+
55
+ # Do nothing on EnergyPlus stdout
56
+ #
57
+ def communicate_energyplus_stdout(_ = nil, _ = nil)
58
+ end
59
+
60
+ # Write the measure attributes to the filesystem
61
+ #
62
+ def communicate_measure_attributes(measure_attributes, _ = nil)
63
+ File.open("#{@options[:output_directory]}/measure_attributes.json", 'w') do |f|
64
+ f << JSON.pretty_generate(measure_attributes)
65
+ end
66
+ end
67
+
68
+ # Write the objective function results to the filesystem
69
+ #
70
+ def communicate_objective_function(objectives, _ = nil)
71
+ obj_fun_file = "#{@options[:output_directory]}/objectives.json"
72
+ FileUtils.rm_f(obj_fun_file) if File.exist?(obj_fun_file)
73
+ File.open(obj_fun_file, 'w') { |f| f << JSON.pretty_generate(objectives) }
74
+ end
75
+
76
+ # Write the results of the workflow to the filesystem
77
+ #
78
+ def communicate_results(directory, results)
79
+ zip_results(directory)
80
+
81
+ if results.is_a? Hash
82
+ File.open("#{@options[:output_directory]}/data_point_out.json", 'w') { |f| f << JSON.pretty_generate(results) }
83
+ else
84
+ puts "Unknown datapoint result type. Please handle #{results.class}"
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,70 @@
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
20
+ require_relative 'local'
21
+ require 'socket'
22
+
23
+ # Local file based workflow
24
+ module OpenStudio
25
+ module Workflow
26
+ module OutputAdapter
27
+ class Socket < Local
28
+ def initialize(options = {})
29
+ super
30
+ raise 'The required :port option was not passed to the socket output adapter' unless options[:port]
31
+
32
+ @socket = TCPSocket.open 'localhost', options[:port]
33
+ end
34
+
35
+ def communicate_started
36
+ super
37
+ @socket.write("Started\n")
38
+ end
39
+
40
+ def communicate_results(directory, results)
41
+ super
42
+ end
43
+
44
+ def communicate_complete
45
+ super
46
+ @socket.write("Complete\n")
47
+ end
48
+
49
+ def communicate_failure
50
+ super
51
+ @socket.write("Failure\n")
52
+ end
53
+
54
+ def communicate_objective_function(objectives, options = {})
55
+ super
56
+ end
57
+
58
+ def communicate_transition(message, type, options = {})
59
+ super
60
+ @socket.write(message + "\n")
61
+ end
62
+
63
+ def communicate_energyplus_stdout(line, options = {})
64
+ super
65
+ @socket.write(line)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -17,28 +17,46 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
  ######################################################################
19
19
 
20
- # Run Prelight job to prepare the directory for simulations.
21
- class RunPreflight
22
- def initialize(directory, logger, time_logger, adapter, workflow_arguments, past_results, options = {})
23
- defaults = {}
24
- @options = defaults.merge(options)
25
- @directory = directory
26
- @adapter = adapter
27
- @logger = logger
28
- @time_logger = time_logger
29
- @workflow_arguments = workflow_arguments
30
- @past_results = past_results
31
- @results = {}
32
- end
20
+ require_relative 'local'
21
+
22
+ # Local file based workflow
23
+ module OpenStudio
24
+ module Workflow
25
+ module OutputAdapter
26
+ class Web < Local
27
+ def initialize(options = {})
28
+ super
29
+ raise 'The required :url option was not passed to the web output adapter' unless options[:url]
30
+ end
31
+
32
+ def communicate_started
33
+ super
34
+ end
35
+
36
+ def communicate_results(directory, results)
37
+ super
38
+ end
39
+
40
+ def communicate_complete
41
+ super
42
+ end
33
43
 
34
- def perform
35
- @logger.info "Calling #{__method__} in the #{self.class} class"
44
+ def communicate_failure
45
+ super
46
+ end
36
47
 
37
- @adapter.communicate_started @directory, @options
48
+ def communicate_objective_function(objectives, options = {})
49
+ super
50
+ end
38
51
 
39
- # At the moment this does nothing.
52
+ def communicate_transition(message, type, options = {})
53
+ super
54
+ end
40
55
 
41
- # return the results back to the caller -- always
42
- @results
56
+ def communicate_energyplus_stdout(line, options = {})
57
+ super
58
+ end
59
+ end
60
+ end
43
61
  end
44
62
  end
@@ -17,51 +17,46 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
  ######################################################################
19
19
 
20
- # Adapter class to decide where to obtain instructions to run the simulation workflow
21
20
  module OpenStudio
22
21
  module Workflow
23
- class Adapter
22
+ # Base class for all output adapters. These methods define the expected return behavior of the adapter instance
23
+ class OutputAdapters
24
24
  attr_accessor :options
25
25
 
26
26
  def initialize(options = {})
27
27
  @options = options
28
- @log = nil
29
- @datapoint = nil
30
28
  end
31
29
 
32
- # class << self
33
- # attr_reader :problem
34
-
35
- def load(filename, options = {})
36
- instance.load(filename, options)
30
+ def communicate_started
31
+ instance.communicate_started
37
32
  end
38
33
 
39
- def communicate_started(id, _options = {})
40
- instance.communicate_started id
34
+ def communicate_transition(message, type, options = {})
35
+ instance.communicate_transition message, type, options
41
36
  end
42
37
 
43
- def get_datapoint(id, options = {})
44
- instance.get_datapoint id, options
38
+ def communicate_energyplus_stdout(line, options = {})
39
+ instance.communicate_energyplus_stdout line, options
45
40
  end
46
41
 
47
- def get_problem(id, options = {})
48
- instance.get_problem id, options
42
+ def communicate_measure_attributes(measure_attributes, options = {})
43
+ instance.communicate_measure_attributes measure_attributes, options
49
44
  end
50
45
 
51
- def communicate_results(id, results)
52
- instance.communicate_results id, results
46
+ def communicate_objective_function(objectives, options = {})
47
+ instance.communicate_objective_function objectives, options
53
48
  end
54
49
 
55
- def communicate_complete(id)
56
- instance.communicate_complete id
50
+ def communicate_results(directory, results)
51
+ instance.communicate_results directory, results
57
52
  end
58
53
 
59
- def communicate_failure(id)
60
- instance.communicate_failure id
54
+ def communicate_complete
55
+ instance.communicate_complete
61
56
  end
62
57
 
63
- def get_logger(file, options = {})
64
- instance.get_logger file, options
58
+ def communicate_failure
59
+ instance.communicate_failure
65
60
  end
66
61
 
67
62
  protected
@@ -70,11 +65,15 @@ module OpenStudio
70
65
  def zip_directory(directory, zip_filename, pattern = '*')
71
66
  # Submethod for adding the directory to the zip folder.
72
67
  def add_directory_to_zip(zip_file, local_directory, root_directory)
73
- Dir[File.join("#{local_directory}", '**', '**')].each do |file|
68
+ Dir[File.join(local_directory.to_s, '**', '**')].each do |file|
74
69
  # remove the base directory from the zip file
75
70
  rel_dir = local_directory.sub("#{root_directory}/", '')
76
- zip_file_to_add = file.gsub("#{local_directory}", "#{rel_dir}")
77
- zip_file.add(zip_file_to_add, file)
71
+ zip_file_to_add = file.gsub(local_directory.to_s, rel_dir.to_s)
72
+ if File.directory?(file)
73
+ zip_file.addDirectory(file, zip_file_to_add)
74
+ else
75
+ zip_file.addFile(file, zip_file_to_add)
76
+ end
78
77
  end
79
78
 
80
79
  zip_file
@@ -82,36 +81,38 @@ module OpenStudio
82
81
 
83
82
  FileUtils.rm_f(zip_filename) if File.exist?(zip_filename)
84
83
 
85
- Zip.default_compression = Zlib::BEST_COMPRESSION
86
- Zip::File.open(zip_filename, Zip::File::CREATE) do |zf|
87
- Dir[File.join(directory, pattern)].each do |file|
88
- if File.directory?(file)
89
- # skip a few directory that should not be zipped as they are inputs
90
- if File.basename(file) =~ /seed|measures|weather/
91
- next
92
- end
93
- # skip x-large directory
94
- if File.size?(file)
95
- next if File.size?(file) >= 15000000
96
- end
97
- add_directory_to_zip(zf, file, directory)
98
- else
99
- next if File.extname(file) =~ /\.rb.*/
100
- next if File.extname(file) =~ /\.zip.*/
101
- # skip large non-osm/idf files
102
- if File.size(file)
103
- if File.size(file) >= 15000000
104
- next unless File.extname(file) == '.osm' || File.extname(file) == '.idf'
105
- end
106
- end
84
+ zf = OpenStudio::ZipFile.new(zip_filename, false)
107
85
 
108
- zip_file_to_add = file.gsub("#{directory}/", '')
109
- zf.add(zip_file_to_add, file)
86
+ Dir[File.join(directory, pattern)].each do |file|
87
+ if File.directory?(file)
88
+ # skip a few directory that should not be zipped as they are inputs
89
+ if File.basename(file) =~ /seed|measures|weather/
90
+ next
110
91
  end
92
+ # skip x-large directory
93
+ if File.size?(file)
94
+ next if File.size?(file) >= 15000000
95
+ end
96
+ add_directory_to_zip(zf, file, directory)
97
+ else
98
+ next if File.extname(file) =~ /\.rb.*/
99
+ next if File.extname(file) =~ /\.zip.*/
100
+ # skip large non-osm/idf files
101
+ if File.size(file)
102
+ if File.size(file) >= 15000000
103
+ next unless File.extname(file) == '.osm' || File.extname(file) == '.idf'
104
+ end
105
+ end
106
+
107
+ zip_file_to_add = file.gsub("#{directory}/", '')
108
+ zf.addFile(file, zip_file_to_add)
111
109
  end
112
110
  end
113
111
 
114
- File.chmod(0664, zip_filename)
112
+ zf = nil
113
+ GC.start
114
+
115
+ File.chmod(0o664, zip_filename)
115
116
  end
116
117
 
117
118
  # Main method to zip up the results of the simulation results. This will append the UUID of the data point
@@ -120,6 +121,7 @@ module OpenStudio
120
121
  #
121
122
  # @param directory [String] The data point directory to zip up.
122
123
  # @return nil
124
+ #
123
125
  def zip_results(directory)
124
126
  # create zip file using a system call
125
127
  if Dir.exist?(directory) && File.directory?(directory)
@@ -0,0 +1,22 @@
1
+ module OpenStudio
2
+ module Workflow
3
+ class Job
4
+ def initialize(input_adapter, output_adapter, registry, options = {})
5
+ @options = options
6
+ @input_adapter = input_adapter
7
+ @output_adapter = output_adapter
8
+ @registry = registry
9
+ @logger = @registry[:logger]
10
+ @results = {}
11
+
12
+ @logger.debug "#{self.class} passed the following options #{@options}"
13
+ @logger.debug "#{self.class} passed the following registry #{@registry.to_hash}" if @options[:debug]
14
+ end
15
+ end
16
+
17
+ def self.new_class(current_job, input_adapter, output_adapter, registry, options = {})
18
+ new_job = Object.const_get(current_job).new(input_adapter, output_adapter, registry, options)
19
+ return new_job
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
20
+ # This class runs the EnergyPlus simulation
21
+ class RunEnergyPlus < OpenStudio::Workflow::Job
22
+ require 'openstudio/workflow/util/energyplus'
23
+ include OpenStudio::Workflow::Util::EnergyPlus
24
+
25
+ def initialize(input_adapter, output_adapter, registry, options = {})
26
+ super
27
+ end
28
+
29
+ def perform
30
+ @logger.debug "Calling #{__method__} in the #{self.class} class"
31
+
32
+ # Checks and configuration
33
+ raise 'No run_dir specified in the registry' unless @registry[:run_dir]
34
+ ep_path = @options[:energyplus_path] ? @options[:energyplus_path] : nil
35
+ @logger.warn "Using EnergyPlus path specified in options #{ep_path}" if ep_path
36
+
37
+ @logger.info 'Starting the EnergyPlus simulation'
38
+ @registry[:time_logger].start('Running EnergyPlus') if @registry[:time_logger]
39
+ call_energyplus(@registry[:run_dir], ep_path, @output_adapter, @logger, @registry[:workflow_json])
40
+ @registry[:time_logger].stop('Running EnergyPlus') if @registry[:time_logger]
41
+ @logger.info 'Completed the EnergyPlus simulation'
42
+
43
+ sql_path = File.join(@registry[:run_dir], 'eplusout.sql')
44
+ @registry.register(:sql) { sql_path } if File.exist? sql_path
45
+ @logger.warn "Unable to find sql file at #{sql_path}" unless @registry[:sql]
46
+
47
+ nil
48
+ end
49
+ end
@@ -0,0 +1,55 @@
1
+ ######################################################################
2
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # All rights reserved.
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ ######################################################################
19
+
20
+ # This class runs all EnergyPlus measures defined in the OSW
21
+ class RunEnergyPlusMeasures < OpenStudio::Workflow::Job
22
+ require 'openstudio/workflow/util'
23
+ include OpenStudio::Workflow::Util::Measure
24
+ include OpenStudio::Workflow::Util::Model
25
+
26
+ def initialize(input_adapter, output_adapter, registry, options = {})
27
+ super
28
+ end
29
+
30
+ def perform
31
+ @logger.debug "Calling #{__method__} in the #{self.class} class"
32
+
33
+ # Ensure output_attributes is initialized in the registry
34
+ @registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
35
+
36
+ # Apply the EnergyPlus measures
37
+ @options[:output_adapter] = @output_adapter
38
+ @logger.info 'Beginning to execute EnergyPlus measures.'
39
+ apply_measures('EnergyPlusMeasure'.to_MeasureType, @registry, @options)
40
+ @logger.info('Finished applying EnergyPlus measures.')
41
+
42
+ # Send the measure output attributes to the output adapter
43
+ @logger.debug 'Communicating measure output attributes to the output adapter'
44
+ @output_adapter.communicate_measure_attributes @registry[:output_attributes]
45
+
46
+ # Save both the OSM and IDF if the :debug option is true
47
+ return nil unless @options[:debug]
48
+ @registry[:time_logger].start('Saving IDF') if @registry[:time_logger]
49
+ idf_name = save_idf(@registry[:model_idf], @registry[:root_dir])
50
+ @registry[:time_logger].stop('Saving IDF') if @registry[:time_logger]
51
+ @logger.debug "Saved IDF as #{idf_name}"
52
+
53
+ nil
54
+ end
55
+ end