openstudio-workflow 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +89 -77
- data/README.md +67 -93
- data/Rakefile +36 -36
- data/lib/openstudio-workflow.rb +65 -65
- data/lib/openstudio/workflow/adapters/input/local.rb +311 -324
- data/lib/openstudio/workflow/adapters/output/local.rb +158 -161
- data/lib/openstudio/workflow/adapters/output/socket.rb +106 -107
- data/lib/openstudio/workflow/adapters/output/web.rb +82 -82
- data/lib/openstudio/workflow/adapters/output_adapter.rb +163 -163
- data/lib/openstudio/workflow/job.rb +57 -57
- data/lib/openstudio/workflow/jobs/resources/monthly_report.idf +222 -222
- data/lib/openstudio/workflow/jobs/run_energyplus.rb +70 -70
- data/lib/openstudio/workflow/jobs/run_ep_measures.rb +73 -73
- data/lib/openstudio/workflow/jobs/run_initialization.rb +203 -203
- data/lib/openstudio/workflow/jobs/run_os_measures.rb +89 -89
- data/lib/openstudio/workflow/jobs/run_postprocess.rb +73 -73
- data/lib/openstudio/workflow/jobs/run_preprocess.rb +104 -104
- data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +118 -118
- data/lib/openstudio/workflow/jobs/run_translation.rb +84 -84
- data/lib/openstudio/workflow/multi_delegator.rb +62 -62
- data/lib/openstudio/workflow/registry.rb +172 -172
- data/lib/openstudio/workflow/run.rb +342 -328
- data/lib/openstudio/workflow/time_logger.rb +96 -96
- data/lib/openstudio/workflow/util.rb +49 -49
- data/lib/openstudio/workflow/util/energyplus.rb +575 -605
- data/lib/openstudio/workflow/util/io.rb +68 -68
- data/lib/openstudio/workflow/util/measure.rb +658 -650
- data/lib/openstudio/workflow/util/model.rb +151 -151
- data/lib/openstudio/workflow/util/post_process.rb +235 -238
- data/lib/openstudio/workflow/util/weather_file.rb +143 -143
- data/lib/openstudio/workflow/version.rb +40 -40
- data/lib/openstudio/workflow_json.rb +475 -476
- data/lib/openstudio/workflow_runner.rb +263 -268
- metadata +24 -24
@@ -1,161 +1,158 @@
|
|
1
|
-
# *******************************************************************************
|
2
|
-
# OpenStudio(R), Copyright (c) 2008-
|
3
|
-
# All rights reserved.
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
-
#
|
7
|
-
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
-
# this list of conditions and the following disclaimer.
|
9
|
-
#
|
10
|
-
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
# this list of conditions and the following disclaimer in the documentation
|
12
|
-
# and/or other materials provided with the distribution.
|
13
|
-
#
|
14
|
-
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
-
# may be used to endorse or promote products derived from this software without
|
16
|
-
# specific prior written permission from the respective party.
|
17
|
-
#
|
18
|
-
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
-
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
-
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
-
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
-
#
|
23
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
|
27
|
-
# GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
28
|
-
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
29
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
30
|
-
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
31
|
-
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
32
|
-
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
33
|
-
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
-
# *******************************************************************************
|
35
|
-
|
36
|
-
require 'openstudio/workflow/adapters/output_adapter'
|
37
|
-
|
38
|
-
# Local file based workflow
|
39
|
-
module OpenStudio
|
40
|
-
module Workflow
|
41
|
-
module OutputAdapter
|
42
|
-
class Local < OutputAdapters
|
43
|
-
def initialize(options = {})
|
44
|
-
raise 'The required :output_directory option was not passed to the local output adapter' unless options[:output_directory]
|
45
|
-
super
|
46
|
-
end
|
47
|
-
|
48
|
-
# Write to the filesystem that the process has started
|
49
|
-
#
|
50
|
-
def communicate_started
|
51
|
-
File.open("#{@options[:output_directory]}/started.job", 'w') do |f|
|
52
|
-
f << "Started Workflow #{::Time.now}"
|
53
|
-
# make sure data is written to the disk one way or the other
|
54
|
-
begin
|
55
|
-
f.fsync
|
56
|
-
rescue
|
57
|
-
f.flush
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Write to the filesystem that the process has completed
|
63
|
-
#
|
64
|
-
def communicate_complete
|
65
|
-
File.open("#{@options[:output_directory]}/finished.job", 'w') do |f|
|
66
|
-
f << "Finished Workflow #{::Time.now}"
|
67
|
-
# make sure data is written to the disk one way or the other
|
68
|
-
begin
|
69
|
-
f.fsync
|
70
|
-
rescue
|
71
|
-
f.flush
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Write to the filesystem that the process has failed
|
77
|
-
#
|
78
|
-
def communicate_failure
|
79
|
-
File.open("#{@options[:output_directory]}/failed.job", 'w') do |f|
|
80
|
-
f << "Failed Workflow #{::Time.now}"
|
81
|
-
# make sure data is written to the disk one way or the other
|
82
|
-
begin
|
83
|
-
f.fsync
|
84
|
-
rescue
|
85
|
-
f.flush
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Do nothing on a state transition
|
91
|
-
#
|
92
|
-
def communicate_transition(_ = nil, _ = nil, _ = nil)
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
|
27
|
+
# GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
28
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
29
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
30
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
31
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
32
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
33
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
|
36
|
+
require 'openstudio/workflow/adapters/output_adapter'
|
37
|
+
|
38
|
+
# Local file based workflow
|
39
|
+
module OpenStudio
|
40
|
+
module Workflow
|
41
|
+
module OutputAdapter
|
42
|
+
class Local < OutputAdapters
|
43
|
+
def initialize(options = {})
|
44
|
+
raise 'The required :output_directory option was not passed to the local output adapter' unless options[:output_directory]
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
# Write to the filesystem that the process has started
|
49
|
+
#
|
50
|
+
def communicate_started
|
51
|
+
File.open("#{@options[:output_directory]}/started.job", 'w') do |f|
|
52
|
+
f << "Started Workflow #{::Time.now}"
|
53
|
+
# make sure data is written to the disk one way or the other
|
54
|
+
begin
|
55
|
+
f.fsync
|
56
|
+
rescue StandardError
|
57
|
+
f.flush
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Write to the filesystem that the process has completed
|
63
|
+
#
|
64
|
+
def communicate_complete
|
65
|
+
File.open("#{@options[:output_directory]}/finished.job", 'w') do |f|
|
66
|
+
f << "Finished Workflow #{::Time.now}"
|
67
|
+
# make sure data is written to the disk one way or the other
|
68
|
+
begin
|
69
|
+
f.fsync
|
70
|
+
rescue StandardError
|
71
|
+
f.flush
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Write to the filesystem that the process has failed
|
77
|
+
#
|
78
|
+
def communicate_failure
|
79
|
+
File.open("#{@options[:output_directory]}/failed.job", 'w') do |f|
|
80
|
+
f << "Failed Workflow #{::Time.now}"
|
81
|
+
# make sure data is written to the disk one way or the other
|
82
|
+
begin
|
83
|
+
f.fsync
|
84
|
+
rescue StandardError
|
85
|
+
f.flush
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Do nothing on a state transition
|
91
|
+
#
|
92
|
+
def communicate_transition(_ = nil, _ = nil, _ = nil); end
|
93
|
+
|
94
|
+
# Do nothing on EnergyPlus stdout
|
95
|
+
#
|
96
|
+
def communicate_energyplus_stdout(_ = nil, _ = nil); end
|
97
|
+
|
98
|
+
# Do nothing on Measure result
|
99
|
+
#
|
100
|
+
def communicate_measure_result(_ = nil, _ = nil); end
|
101
|
+
|
102
|
+
# Write the measure attributes to the filesystem
|
103
|
+
#
|
104
|
+
def communicate_measure_attributes(measure_attributes, _ = nil)
|
105
|
+
attributes_file = "#{@options[:output_directory]}/measure_attributes.json"
|
106
|
+
FileUtils.rm_f(attributes_file) if File.exist?(attributes_file)
|
107
|
+
File.open(attributes_file, 'w') do |f|
|
108
|
+
f << JSON.pretty_generate(measure_attributes)
|
109
|
+
# make sure data is written to the disk one way or the other
|
110
|
+
begin
|
111
|
+
f.fsync
|
112
|
+
rescue StandardError
|
113
|
+
f.flush
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Write the objective function results to the filesystem
|
119
|
+
#
|
120
|
+
def communicate_objective_function(objectives, _ = nil)
|
121
|
+
obj_fun_file = "#{@options[:output_directory]}/objectives.json"
|
122
|
+
FileUtils.rm_f(obj_fun_file) if File.exist?(obj_fun_file)
|
123
|
+
File.open(obj_fun_file, 'w') do |f|
|
124
|
+
f << JSON.pretty_generate(objectives)
|
125
|
+
# make sure data is written to the disk one way or the other
|
126
|
+
begin
|
127
|
+
f.fsync
|
128
|
+
rescue StandardError
|
129
|
+
f.flush
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Write the results of the workflow to the filesystem
|
135
|
+
#
|
136
|
+
def communicate_results(directory, results)
|
137
|
+
zip_results(directory)
|
138
|
+
|
139
|
+
if results.is_a? Hash
|
140
|
+
# DLM: don't we want this in the results zip?
|
141
|
+
# DLM: deprecate in favor of out.osw
|
142
|
+
File.open("#{@options[:output_directory]}/data_point_out.json", 'w') do |f|
|
143
|
+
f << JSON.pretty_generate(results)
|
144
|
+
# make sure data is written to the disk one way or the other
|
145
|
+
begin
|
146
|
+
f.fsync
|
147
|
+
rescue StandardError
|
148
|
+
f.flush
|
149
|
+
end
|
150
|
+
end
|
151
|
+
else
|
152
|
+
# puts "Unknown datapoint result type. Please handle #{results.class}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -1,107 +1,106 @@
|
|
1
|
-
# *******************************************************************************
|
2
|
-
# OpenStudio(R), Copyright (c) 2008-
|
3
|
-
# All rights reserved.
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
-
#
|
7
|
-
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
-
# this list of conditions and the following disclaimer.
|
9
|
-
#
|
10
|
-
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
# this list of conditions and the following disclaimer in the documentation
|
12
|
-
# and/or other materials provided with the distribution.
|
13
|
-
#
|
14
|
-
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
-
# may be used to endorse or promote products derived from this software without
|
16
|
-
# specific prior written permission from the respective party.
|
17
|
-
#
|
18
|
-
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
-
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
-
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
-
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
-
#
|
23
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
|
27
|
-
# GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
28
|
-
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
29
|
-
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
30
|
-
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
31
|
-
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
32
|
-
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
33
|
-
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
-
# *******************************************************************************
|
35
|
-
|
36
|
-
require_relative 'local'
|
37
|
-
require 'socket'
|
38
|
-
|
39
|
-
# Local file based workflow
|
40
|
-
module OpenStudio
|
41
|
-
module Workflow
|
42
|
-
module OutputAdapter
|
43
|
-
class Socket < Local
|
44
|
-
def initialize(options = {})
|
45
|
-
super
|
46
|
-
raise 'The required :port option was not passed to the socket output adapter' unless options[:port]
|
47
|
-
|
48
|
-
@socket = TCPSocket.open 'localhost', options[:port]
|
49
|
-
end
|
50
|
-
|
51
|
-
def communicate_started
|
52
|
-
super
|
53
|
-
@socket.write("Started\n")
|
54
|
-
end
|
55
|
-
|
56
|
-
def communicate_results(directory, results)
|
57
|
-
super
|
58
|
-
end
|
59
|
-
|
60
|
-
def communicate_complete
|
61
|
-
super
|
62
|
-
@socket.write("Complete\n")
|
63
|
-
end
|
64
|
-
|
65
|
-
def communicate_failure
|
66
|
-
super
|
67
|
-
@socket.write("Failure\n")
|
68
|
-
end
|
69
|
-
|
70
|
-
def communicate_objective_function(objectives, options = {})
|
71
|
-
super
|
72
|
-
end
|
73
|
-
|
74
|
-
def communicate_transition(message, type, options = {})
|
75
|
-
super
|
76
|
-
@socket.write(message + "\n")
|
77
|
-
end
|
78
|
-
|
79
|
-
def communicate_energyplus_stdout(line, options = {})
|
80
|
-
super
|
81
|
-
@socket.write(line)
|
82
|
-
end
|
83
|
-
|
84
|
-
def communicate_measure_result(result, options = {})
|
85
|
-
super
|
86
|
-
|
87
|
-
step_result = result.stepResult
|
88
|
-
initial_condition = result.stepInitialCondition
|
89
|
-
final_condition = result.stepFinalCondition
|
90
|
-
errors = result.stepErrors
|
91
|
-
warnings = result.stepWarnings
|
92
|
-
infos = result.stepInfo
|
93
|
-
|
94
|
-
# Mirrors WorkflowStepResult::string
|
95
|
-
tab = ' '
|
96
|
-
@socket.write("#{tab}Result: #{step_result.get.valueName}\n") if !step_result.empty?
|
97
|
-
@socket.write("#{tab}Initial Condition: #{initial_condition.get}\n") if !initial_condition.empty?
|
98
|
-
@socket.write("#{tab}Final Condition: #{final_condition.get}\n") if !final_condition.empty?
|
99
|
-
errors.each {|error| @socket.write("#{tab}Error: #{error}\n") }
|
100
|
-
warnings.each {|warning| @socket.write("#{tab}Warn: #{warning}\n") }
|
101
|
-
infos.each {|info| @socket.write("#{tab}Info: #{info}\n") }
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
|
27
|
+
# GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
28
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
29
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
30
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
31
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
32
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
33
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
|
36
|
+
require_relative 'local'
|
37
|
+
require 'socket'
|
38
|
+
|
39
|
+
# Local file based workflow
|
40
|
+
module OpenStudio
|
41
|
+
module Workflow
|
42
|
+
module OutputAdapter
|
43
|
+
class Socket < Local
|
44
|
+
def initialize(options = {})
|
45
|
+
super
|
46
|
+
raise 'The required :port option was not passed to the socket output adapter' unless options[:port]
|
47
|
+
|
48
|
+
@socket = TCPSocket.open 'localhost', options[:port]
|
49
|
+
end
|
50
|
+
|
51
|
+
def communicate_started
|
52
|
+
super
|
53
|
+
@socket.write("Started\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def communicate_results(directory, results)
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
def communicate_complete
|
61
|
+
super
|
62
|
+
@socket.write("Complete\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
def communicate_failure
|
66
|
+
super
|
67
|
+
@socket.write("Failure\n")
|
68
|
+
end
|
69
|
+
|
70
|
+
def communicate_objective_function(objectives, options = {})
|
71
|
+
super
|
72
|
+
end
|
73
|
+
|
74
|
+
def communicate_transition(message, type, options = {})
|
75
|
+
super
|
76
|
+
@socket.write(message + "\n")
|
77
|
+
end
|
78
|
+
|
79
|
+
def communicate_energyplus_stdout(line, options = {})
|
80
|
+
super
|
81
|
+
@socket.write(line)
|
82
|
+
end
|
83
|
+
|
84
|
+
def communicate_measure_result(result, options = {})
|
85
|
+
super
|
86
|
+
|
87
|
+
step_result = result.stepResult
|
88
|
+
initial_condition = result.stepInitialCondition
|
89
|
+
final_condition = result.stepFinalCondition
|
90
|
+
errors = result.stepErrors
|
91
|
+
warnings = result.stepWarnings
|
92
|
+
infos = result.stepInfo
|
93
|
+
|
94
|
+
# Mirrors WorkflowStepResult::string
|
95
|
+
tab = ' '
|
96
|
+
@socket.write("#{tab}Result: #{step_result.get.valueName}\n") if !step_result.empty?
|
97
|
+
@socket.write("#{tab}Initial Condition: #{initial_condition.get}\n") if !initial_condition.empty?
|
98
|
+
@socket.write("#{tab}Final Condition: #{final_condition.get}\n") if !final_condition.empty?
|
99
|
+
errors.each { |error| @socket.write("#{tab}Error: #{error}\n") }
|
100
|
+
warnings.each { |warning| @socket.write("#{tab}Warn: #{warning}\n") }
|
101
|
+
infos.each { |info| @socket.write("#{tab}Info: #{info}\n") }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|