openstudio-workflow 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -72
  3. data/README.md +93 -48
  4. data/Rakefile +36 -36
  5. data/lib/openstudio-workflow.rb +49 -49
  6. data/lib/openstudio/workflow/adapters/input/local.rb +244 -240
  7. data/lib/openstudio/workflow/adapters/output/local.rb +95 -95
  8. data/lib/openstudio/workflow/adapters/output/socket.rb +91 -91
  9. data/lib/openstudio/workflow/adapters/output/web.rb +66 -66
  10. data/lib/openstudio/workflow/adapters/output_adapter.rb +147 -147
  11. data/lib/openstudio/workflow/job.rb +22 -22
  12. data/lib/openstudio/workflow/jobs/resources/monthly_report.idf +222 -222
  13. data/lib/openstudio/workflow/jobs/run_energyplus.rb +49 -49
  14. data/lib/openstudio/workflow/jobs/run_ep_measures.rb +55 -55
  15. data/lib/openstudio/workflow/jobs/run_initialization.rb +169 -167
  16. data/lib/openstudio/workflow/jobs/run_os_measures.rb +69 -69
  17. data/lib/openstudio/workflow/jobs/run_postprocess.rb +53 -53
  18. data/lib/openstudio/workflow/jobs/run_preprocess.rb +69 -69
  19. data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +98 -98
  20. data/lib/openstudio/workflow/jobs/run_translation.rb +61 -61
  21. data/lib/openstudio/workflow/multi_delegator.rb +46 -46
  22. data/lib/openstudio/workflow/registry.rb +137 -137
  23. data/lib/openstudio/workflow/run.rb +299 -299
  24. data/lib/openstudio/workflow/time_logger.rb +53 -53
  25. data/lib/openstudio/workflow/util.rb +14 -14
  26. data/lib/openstudio/workflow/util/energyplus.rb +566 -564
  27. data/lib/openstudio/workflow/util/io.rb +33 -33
  28. data/lib/openstudio/workflow/util/measure.rb +588 -588
  29. data/lib/openstudio/workflow/util/model.rb +100 -100
  30. data/lib/openstudio/workflow/util/post_process.rb +187 -187
  31. data/lib/openstudio/workflow/util/weather_file.rb +108 -108
  32. data/lib/openstudio/workflow/version.rb +24 -24
  33. data/lib/openstudio/workflow_json.rb +426 -426
  34. data/lib/openstudio/workflow_runner.rb +233 -215
  35. metadata +3 -3
@@ -1,69 +1,69 @@
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
- # Run any OpenStudio measures contained in the OSW
21
- class RunOpenStudioMeasures < OpenStudio::Workflow::Job
22
- # Mixin the required util modules
23
- require 'openstudio/workflow/util'
24
- include OpenStudio::Workflow::Util::Measure
25
- include OpenStudio::Workflow::Util::Model
26
-
27
- def initialize(input_adapter, output_adapter, registry, options = {})
28
- super
29
- end
30
-
31
- def perform
32
- @logger.debug "Calling #{__method__} in the #{self.class} class"
33
-
34
- # set weather file
35
- if @registry[:wf] && @registry[:model]
36
- epwFile = OpenStudio::EpwFile.load(@registry[:wf])
37
- if !epwFile.empty?
38
- OpenStudio::Model::WeatherFile.setWeatherFile(@registry[:model], epwFile.get)
39
- else
40
- @logger.warn "Could not load weather file from '#{weather_full_path.to_s}'"
41
- end
42
- end
43
-
44
- # Ensure output_attributes is initialized in the registry
45
- @registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
46
-
47
- # Execute the OpenStudio measures
48
- @options[:output_adapter] = @output_adapter
49
- @logger.info 'Beginning to execute OpenStudio measures.'
50
- apply_measures('ModelMeasure'.to_MeasureType, @registry, @options)
51
- @logger.info('Finished applying OpenStudio measures.')
52
-
53
- # Send the measure output attributes to the output adapter
54
- @logger.debug 'Communicating measure output attributes to the output adapter'
55
- @output_adapter.communicate_measure_attributes @registry[:output_attributes]
56
-
57
- # save the final OSM
58
- save_osm(@registry[:model], @registry[:run_dir])
59
-
60
- # Save the OSM if the :debug option is true
61
- return nil unless @options[:debug]
62
- @registry[:time_logger].start('Saving OSM') if @registry[:time_logger]
63
- osm_name = save_osm(@registry[:model], @registry[:root_dir])
64
- @registry[:time_logger].stop('Saving OSM') if @registry[:time_logger]
65
- @logger.debug "Saved model as #{osm_name}"
66
-
67
- nil
68
- end
69
- end
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
+ # Run any OpenStudio measures contained in the OSW
21
+ class RunOpenStudioMeasures < OpenStudio::Workflow::Job
22
+ # Mixin the required util modules
23
+ require 'openstudio/workflow/util'
24
+ include OpenStudio::Workflow::Util::Measure
25
+ include OpenStudio::Workflow::Util::Model
26
+
27
+ def initialize(input_adapter, output_adapter, registry, options = {})
28
+ super
29
+ end
30
+
31
+ def perform
32
+ @logger.debug "Calling #{__method__} in the #{self.class} class"
33
+
34
+ # set weather file
35
+ if @registry[:wf] && @registry[:model]
36
+ epwFile = OpenStudio::EpwFile.load(@registry[:wf])
37
+ if !epwFile.empty?
38
+ OpenStudio::Model::WeatherFile.setWeatherFile(@registry[:model], epwFile.get)
39
+ else
40
+ @logger.warn "Could not load weather file from '#{weather_full_path.to_s}'"
41
+ end
42
+ end
43
+
44
+ # Ensure output_attributes is initialized in the registry
45
+ @registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
46
+
47
+ # Execute the OpenStudio measures
48
+ @options[:output_adapter] = @output_adapter
49
+ @logger.info 'Beginning to execute OpenStudio measures.'
50
+ apply_measures('ModelMeasure'.to_MeasureType, @registry, @options)
51
+ @logger.info('Finished applying OpenStudio measures.')
52
+
53
+ # Send the measure output attributes to the output adapter
54
+ @logger.debug 'Communicating measure output attributes to the output adapter'
55
+ @output_adapter.communicate_measure_attributes @registry[:output_attributes]
56
+
57
+ # save the final OSM
58
+ save_osm(@registry[:model], @registry[:run_dir])
59
+
60
+ # Save the OSM if the :debug option is true
61
+ return nil unless @options[:debug]
62
+ @registry[:time_logger].start('Saving OSM') if @registry[:time_logger]
63
+ osm_name = save_osm(@registry[:model], @registry[:root_dir])
64
+ @registry[:time_logger].stop('Saving OSM') if @registry[:time_logger]
65
+ @logger.debug "Saved model as #{osm_name}"
66
+
67
+ nil
68
+ end
69
+ end
@@ -1,53 +1,53 @@
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
- # Clean up the run directory. Currently this class does nothing else, although eventually cleanup should become driven
21
- # and responsive to options
22
- class RunPostprocess < OpenStudio::Workflow::Job
23
- require 'openstudio/workflow/util/post_process'
24
- include OpenStudio::Workflow::Util::PostProcess
25
-
26
- def initialize(input_adapter, output_adapter, registry, options = {})
27
- defaults = {
28
- cleanup: true
29
- }
30
- options = defaults.merge(options)
31
- super
32
- end
33
-
34
- def perform
35
- @logger.debug "Calling #{__method__} in the #{self.class} class"
36
-
37
- @logger.info 'Gathering reports'
38
- gather_reports(@registry[:run_dir], @registry[:root_dir], @registry[:workflow_json], @logger)
39
- @logger.info 'Finished gathering reports'
40
-
41
- if @options[:cleanup]
42
- @logger.info 'Beginning cleanup of the run directory'
43
- cleanup(@registry[:run_dir], @registry[:root_dir], @logger)
44
- @logger.info 'Finished cleanup of the run directory'
45
- else
46
- @logger.info 'Flag for cleanup in options set to false. Moving to next step.'
47
- end
48
-
49
- @logger.info 'Finished postprocess'
50
-
51
- nil
52
- end
53
- end
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
+ # Clean up the run directory. Currently this class does nothing else, although eventually cleanup should become driven
21
+ # and responsive to options
22
+ class RunPostprocess < OpenStudio::Workflow::Job
23
+ require 'openstudio/workflow/util/post_process'
24
+ include OpenStudio::Workflow::Util::PostProcess
25
+
26
+ def initialize(input_adapter, output_adapter, registry, options = {})
27
+ defaults = {
28
+ cleanup: true
29
+ }
30
+ options = defaults.merge(options)
31
+ super
32
+ end
33
+
34
+ def perform
35
+ @logger.debug "Calling #{__method__} in the #{self.class} class"
36
+
37
+ @logger.info 'Gathering reports'
38
+ gather_reports(@registry[:run_dir], @registry[:root_dir], @registry[:workflow_json], @logger)
39
+ @logger.info 'Finished gathering reports'
40
+
41
+ if @options[:cleanup]
42
+ @logger.info 'Beginning cleanup of the run directory'
43
+ cleanup(@registry[:run_dir], @registry[:root_dir], @logger)
44
+ @logger.info 'Finished cleanup of the run directory'
45
+ else
46
+ @logger.info 'Flag for cleanup in options set to false. Moving to next step.'
47
+ end
48
+
49
+ @logger.info 'Finished postprocess'
50
+
51
+ nil
52
+ end
53
+ end
@@ -1,69 +1,69 @@
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
- # Prepares the directory for the EnergyPlus simulation
21
- class RunPreprocess < OpenStudio::Workflow::Job
22
- require 'openstudio/workflow/util'
23
- include OpenStudio::Workflow::Util::EnergyPlus
24
- include OpenStudio::Workflow::Util::Model
25
- include OpenStudio::Workflow::Util::Measure
26
-
27
- def initialize(input_adapter, output_adapter, registry, options = {})
28
- super
29
- end
30
-
31
- def perform
32
- @logger.debug "Calling #{__method__} in the #{self.class} class"
33
-
34
- # Ensure that the directory is created (but it should already be at this point)
35
- FileUtils.mkdir_p(@registry[:run_dir])
36
-
37
- # save the pre-preprocess file
38
- File.open("#{@registry[:run_dir]}/pre-preprocess.idf", 'w') { |f| f << @registry[:model_idf].to_s }
39
-
40
- # Add any EnergyPlus Output Requests from Reporting Measures
41
- @logger.info 'Beginning to collect output requests from Reporting measures.'
42
- energyplus_output_requests = true
43
- apply_measures('ReportingMeasure'.to_MeasureType, @registry, @options, energyplus_output_requests)
44
- @logger.info('Finished collect output requests from Reporting measures.')
45
-
46
- # Perform pre-processing on in.idf to capture logic in RunManager
47
- @registry[:time_logger].start('Running EnergyPlus Preprocess') if @registry[:time_logger]
48
- energyplus_preprocess(@registry[:model_idf], @logger)
49
- @registry[:time_logger].start('Running EnergyPlus Preprocess') if @registry[:time_logger]
50
- @logger.info 'Finished preprocess job for EnergyPlus simulation'
51
-
52
- # Save the model objects in the registry to the run directory
53
- if File.exist?("#{@registry[:run_dir]}/in.idf")
54
- # DLM: why is this here?
55
- @logger.warn 'IDF (in.idf) already exists in the run directory. Will simulate using this file'
56
- else
57
- save_idf(@registry[:model_idf], @registry[:run_dir])
58
- end
59
-
60
- # Save the generated IDF file if the :debug option is true
61
- return nil unless @options[:debug]
62
- @registry[:time_logger].start('Saving IDF') if @registry[:time_logger]
63
- idf_name = save_idf(@registry[:model_idf], @registry[:root_dir])
64
- @registry[:time_logger].stop('Saving IDF') if @registry[:time_logger]
65
- @logger.debug "Saved IDF as #{idf_name}"
66
-
67
- nil
68
- end
69
- end
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
+ # Prepares the directory for the EnergyPlus simulation
21
+ class RunPreprocess < OpenStudio::Workflow::Job
22
+ require 'openstudio/workflow/util'
23
+ include OpenStudio::Workflow::Util::EnergyPlus
24
+ include OpenStudio::Workflow::Util::Model
25
+ include OpenStudio::Workflow::Util::Measure
26
+
27
+ def initialize(input_adapter, output_adapter, registry, options = {})
28
+ super
29
+ end
30
+
31
+ def perform
32
+ @logger.debug "Calling #{__method__} in the #{self.class} class"
33
+
34
+ # Ensure that the directory is created (but it should already be at this point)
35
+ FileUtils.mkdir_p(@registry[:run_dir])
36
+
37
+ # save the pre-preprocess file
38
+ File.open("#{@registry[:run_dir]}/pre-preprocess.idf", 'w') { |f| f << @registry[:model_idf].to_s }
39
+
40
+ # Add any EnergyPlus Output Requests from Reporting Measures
41
+ @logger.info 'Beginning to collect output requests from Reporting measures.'
42
+ energyplus_output_requests = true
43
+ apply_measures('ReportingMeasure'.to_MeasureType, @registry, @options, energyplus_output_requests)
44
+ @logger.info('Finished collect output requests from Reporting measures.')
45
+
46
+ # Perform pre-processing on in.idf to capture logic in RunManager
47
+ @registry[:time_logger].start('Running EnergyPlus Preprocess') if @registry[:time_logger]
48
+ energyplus_preprocess(@registry[:model_idf], @logger)
49
+ @registry[:time_logger].start('Running EnergyPlus Preprocess') if @registry[:time_logger]
50
+ @logger.info 'Finished preprocess job for EnergyPlus simulation'
51
+
52
+ # Save the model objects in the registry to the run directory
53
+ if File.exist?("#{@registry[:run_dir]}/in.idf")
54
+ # DLM: why is this here?
55
+ @logger.warn 'IDF (in.idf) already exists in the run directory. Will simulate using this file'
56
+ else
57
+ save_idf(@registry[:model_idf], @registry[:run_dir])
58
+ end
59
+
60
+ # Save the generated IDF file if the :debug option is true
61
+ return nil unless @options[:debug]
62
+ @registry[:time_logger].start('Saving IDF') if @registry[:time_logger]
63
+ idf_name = save_idf(@registry[:model_idf], @registry[:root_dir])
64
+ @registry[:time_logger].stop('Saving IDF') if @registry[:time_logger]
65
+ @logger.debug "Saved IDF as #{idf_name}"
66
+
67
+ nil
68
+ end
69
+ end
@@ -1,98 +1,98 @@
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
- # Run reporting measures and execute scripts to post-process objective functions and results on the filesystem
21
- class RunReportingMeasures < OpenStudio::Workflow::Job
22
- require 'csv'
23
- require 'ostruct'
24
- require 'openstudio/workflow/util'
25
- include OpenStudio::Workflow::Util::Model
26
- include OpenStudio::Workflow::Util::Measure
27
- include OpenStudio::Workflow::Util::PostProcess
28
-
29
- def initialize(input_adapter, output_adapter, registry, options = {})
30
- defaults = {
31
- load_simulation_osm: false,
32
- load_simulation_idf: false,
33
- load_simulation_sql: false
34
- }
35
- options = defaults.merge(options)
36
- super
37
- end
38
-
39
- def perform
40
- @logger.debug "Calling #{__method__} in the #{self.class} class"
41
- @logger.debug 'RunPostProcess Retrieving datapoint and problem'
42
-
43
- # Ensure output_attributes is initialized in the registry
44
- @registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
45
-
46
- # Load simulation files as required
47
- if @registry[:model].nil?
48
- osm_path = File.absolute_path(File.join(@registry[:run_dir], 'in.osm'))
49
- @logger.debug "Attempting to load #{osm_path}"
50
- @registry.register(:model) { load_osm('.', osm_path) }
51
- raise "Unable to load #{osm_path}" unless @registry[:model]
52
- @logger.debug "Successfully loaded #{osm_path}"
53
- end
54
- if @registry[:model_idf].nil?
55
- idf_path = File.absolute_path(File.join(@registry[:run_dir], 'in.idf'))
56
- @logger.debug "Attempting to load #{idf_path}"
57
- @registry.register(:model_idf) { load_idf(idf_path, @logger) }
58
- raise "Unable to load #{idf_path}" unless @registry[:model_idf]
59
- @logger.debug "Successfully loaded #{idf_path}"
60
- end
61
- if @registry[:sql].nil?
62
- sql_path = File.absolute_path(File.join(@registry[:run_dir], 'eplusout.sql'))
63
- if File.exists?(sql_path)
64
- @registry.register(:sql) { sql_path }
65
- @logger.debug "Registered the sql filepath as #{@registry[:sql]}"
66
- end
67
- #raise "Unable to load #{sql_path}" unless @registry[:sql]
68
- end
69
- if @registry[:wf].nil?
70
- epw_path = File.absolute_path(File.join(@registry[:run_dir], 'in.epw'))
71
- if File.exists?(epw_path)
72
- @registry.register(:wf) { epw_path }
73
- @logger.debug "Registered the wf filepath as #{@registry[:wf]}"
74
- end
75
- #raise "Unable to load #{epw_path}" unless @registry[:wf]
76
- end
77
-
78
- # Apply reporting measures
79
- @options[:output_adapter] = @output_adapter
80
- @logger.info 'Beginning to execute Reporting measures.'
81
- apply_measures('ReportingMeasure'.to_MeasureType, @registry, @options)
82
- @logger.info('Finished applying Reporting measures.')
83
-
84
- # Send the updated measure_attributes to the output adapter
85
- @logger.debug 'Communicating measures output attributes to the output adapter'
86
- @output_adapter.communicate_measure_attributes @registry[:output_attributes]
87
-
88
- # Parse the files generated by the local output adapter
89
- results, objective_functions = run_extract_inputs_and_outputs @registry[:run_dir], @logger
90
- @registry.register(:results) { results }
91
-
92
- # Send the objective function results to the output adapter
93
- @logger.debug "Objective Function JSON is #{objective_functions}"
94
- @output_adapter.communicate_objective_function objective_functions
95
-
96
- nil
97
- end
98
- end
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
+ # Run reporting measures and execute scripts to post-process objective functions and results on the filesystem
21
+ class RunReportingMeasures < OpenStudio::Workflow::Job
22
+ require 'csv'
23
+ require 'ostruct'
24
+ require 'openstudio/workflow/util'
25
+ include OpenStudio::Workflow::Util::Model
26
+ include OpenStudio::Workflow::Util::Measure
27
+ include OpenStudio::Workflow::Util::PostProcess
28
+
29
+ def initialize(input_adapter, output_adapter, registry, options = {})
30
+ defaults = {
31
+ load_simulation_osm: false,
32
+ load_simulation_idf: false,
33
+ load_simulation_sql: false
34
+ }
35
+ options = defaults.merge(options)
36
+ super
37
+ end
38
+
39
+ def perform
40
+ @logger.debug "Calling #{__method__} in the #{self.class} class"
41
+ @logger.debug 'RunPostProcess Retrieving datapoint and problem'
42
+
43
+ # Ensure output_attributes is initialized in the registry
44
+ @registry.register(:output_attributes) { {} } unless @registry[:output_attributes]
45
+
46
+ # Load simulation files as required
47
+ if @registry[:model].nil?
48
+ osm_path = File.absolute_path(File.join(@registry[:run_dir], 'in.osm'))
49
+ @logger.debug "Attempting to load #{osm_path}"
50
+ @registry.register(:model) { load_osm('.', osm_path) }
51
+ raise "Unable to load #{osm_path}" unless @registry[:model]
52
+ @logger.debug "Successfully loaded #{osm_path}"
53
+ end
54
+ if @registry[:model_idf].nil?
55
+ idf_path = File.absolute_path(File.join(@registry[:run_dir], 'in.idf'))
56
+ @logger.debug "Attempting to load #{idf_path}"
57
+ @registry.register(:model_idf) { load_idf(idf_path, @logger) }
58
+ raise "Unable to load #{idf_path}" unless @registry[:model_idf]
59
+ @logger.debug "Successfully loaded #{idf_path}"
60
+ end
61
+ if @registry[:sql].nil?
62
+ sql_path = File.absolute_path(File.join(@registry[:run_dir], 'eplusout.sql'))
63
+ if File.exists?(sql_path)
64
+ @registry.register(:sql) { sql_path }
65
+ @logger.debug "Registered the sql filepath as #{@registry[:sql]}"
66
+ end
67
+ #raise "Unable to load #{sql_path}" unless @registry[:sql]
68
+ end
69
+ if @registry[:wf].nil?
70
+ epw_path = File.absolute_path(File.join(@registry[:run_dir], 'in.epw'))
71
+ if File.exists?(epw_path)
72
+ @registry.register(:wf) { epw_path }
73
+ @logger.debug "Registered the wf filepath as #{@registry[:wf]}"
74
+ end
75
+ #raise "Unable to load #{epw_path}" unless @registry[:wf]
76
+ end
77
+
78
+ # Apply reporting measures
79
+ @options[:output_adapter] = @output_adapter
80
+ @logger.info 'Beginning to execute Reporting measures.'
81
+ apply_measures('ReportingMeasure'.to_MeasureType, @registry, @options)
82
+ @logger.info('Finished applying Reporting measures.')
83
+
84
+ # Send the updated measure_attributes to the output adapter
85
+ @logger.debug 'Communicating measures output attributes to the output adapter'
86
+ @output_adapter.communicate_measure_attributes @registry[:output_attributes]
87
+
88
+ # Parse the files generated by the local output adapter
89
+ results, objective_functions = run_extract_inputs_and_outputs @registry[:run_dir], @logger
90
+ @registry.register(:results) { results }
91
+
92
+ # Send the objective function results to the output adapter
93
+ @logger.debug "Objective Function JSON is #{objective_functions}"
94
+ @output_adapter.communicate_objective_function objective_functions
95
+
96
+ nil
97
+ end
98
+ end