honeybee-openstudio 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -1
  3. data/.gitignore +32 -32
  4. data/.releaserc.json +7 -7
  5. data/.travis.yml +42 -41
  6. data/Gemfile +18 -18
  7. data/LICENSE.md +23 -23
  8. data/README.md +95 -95
  9. data/Rakefile +20 -20
  10. data/doc_templates/LICENSE.md +23 -23
  11. data/doc_templates/copyright_erb.txt +31 -31
  12. data/doc_templates/copyright_js.txt +4 -4
  13. data/doc_templates/copyright_ruby.txt +29 -29
  14. data/honeybee-openstudio.gemspec +35 -35
  15. data/lib/files/Honeybee.rb +112 -112
  16. data/lib/files/honeybee_workflow.osw +47 -47
  17. data/lib/files/urbanopt_Gemfile +32 -32
  18. data/lib/from_honeybee.rb +86 -86
  19. data/lib/from_honeybee/_openapi/model.json +8126 -8126
  20. data/lib/from_honeybee/_openapi/simulation-parameter.json +842 -842
  21. data/lib/from_honeybee/construction/air.rb +64 -64
  22. data/lib/from_honeybee/construction/opaque.rb +76 -76
  23. data/lib/from_honeybee/construction/shade.rb +107 -107
  24. data/lib/from_honeybee/construction/window.rb +80 -80
  25. data/lib/from_honeybee/construction_set.rb +278 -278
  26. data/lib/from_honeybee/extension.rb +109 -109
  27. data/lib/from_honeybee/geometry/aperture.rb +167 -167
  28. data/lib/from_honeybee/geometry/door.rb +160 -160
  29. data/lib/from_honeybee/geometry/face.rb +163 -163
  30. data/lib/from_honeybee/geometry/room.rb +392 -392
  31. data/lib/from_honeybee/geometry/shade.rb +89 -89
  32. data/lib/from_honeybee/hvac/ideal_air.rb +150 -150
  33. data/lib/from_honeybee/load/electric_equipment.rb +95 -95
  34. data/lib/from_honeybee/load/gas_equipment.rb +97 -97
  35. data/lib/from_honeybee/load/infiltration.rb +94 -94
  36. data/lib/from_honeybee/load/lighting.rb +98 -98
  37. data/lib/from_honeybee/load/people.rb +99 -99
  38. data/lib/from_honeybee/load/setpoint_humidistat.rb +74 -74
  39. data/lib/from_honeybee/load/setpoint_thermostat.rb +71 -71
  40. data/lib/from_honeybee/load/ventilation.rb +95 -95
  41. data/lib/from_honeybee/material/opaque.rb +94 -94
  42. data/lib/from_honeybee/material/opaque_no_mass.rb +94 -94
  43. data/lib/from_honeybee/material/window_blind.rb +238 -238
  44. data/lib/from_honeybee/material/window_gas.rb +76 -76
  45. data/lib/from_honeybee/material/window_gas_custom.rb +118 -118
  46. data/lib/from_honeybee/material/window_gas_mixture.rb +79 -79
  47. data/lib/from_honeybee/material/window_glazing.rb +166 -166
  48. data/lib/from_honeybee/material/window_shade.rb +160 -160
  49. data/lib/from_honeybee/material/window_simpleglazsys.rb +73 -73
  50. data/lib/from_honeybee/model.rb +434 -434
  51. data/lib/from_honeybee/model_object.rb +110 -110
  52. data/lib/from_honeybee/program_type.rb +124 -124
  53. data/lib/from_honeybee/schedule/fixed_interval.rb +115 -115
  54. data/lib/from_honeybee/schedule/ruleset.rb +164 -164
  55. data/lib/from_honeybee/schedule/type_limit.rb +88 -88
  56. data/lib/from_honeybee/simulation/designday.rb +105 -105
  57. data/lib/from_honeybee/simulation/extension.rb +46 -46
  58. data/lib/from_honeybee/simulation/parameter.rb +277 -277
  59. data/lib/from_honeybee/version.rb +34 -34
  60. data/lib/measures/from_honeybee_model/LICENSE.md +26 -26
  61. data/lib/measures/from_honeybee_model/README.md +32 -32
  62. data/lib/measures/from_honeybee_model/measure.rb +91 -91
  63. data/lib/measures/from_honeybee_model/measure.xml +103 -103
  64. data/lib/measures/from_honeybee_model/tests/from_honeybee_model_test.rb +126 -126
  65. data/lib/measures/from_honeybee_simulation_parameter/LICENSE.md +26 -26
  66. data/lib/measures/from_honeybee_simulation_parameter/README.md +32 -32
  67. data/lib/measures/from_honeybee_simulation_parameter/measure.rb +95 -95
  68. data/lib/measures/from_honeybee_simulation_parameter/measure.xml +91 -91
  69. data/lib/measures/from_honeybee_simulation_parameter/tests/from_honeybee_simulation_parameter_test.rb +109 -109
  70. metadata +2 -2
@@ -1,277 +1,277 @@
1
- # *******************************************************************************
2
- # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
- # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
- #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are met:
7
- #
8
- # (1) Redistributions of source code must retain the above copyright notice,
9
- # this list of conditions and the following disclaimer.
10
- #
11
- # (2) Redistributions in binary form must reproduce the above copyright notice,
12
- # this list of conditions and the following disclaimer in the documentation
13
- # and/or other materials provided with the distribution.
14
- #
15
- # (3) Neither the name of the copyright holder nor the names of any contributors
16
- # may be used to endorse or promote products derived from this software without
17
- # specific prior written permission from the respective party.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
- # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
- # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
- # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
- # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
- # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
- # *******************************************************************************
31
-
32
- require 'from_honeybee/model_object'
33
- require 'from_honeybee/simulation/extension'
34
- require 'from_honeybee/simulation/designday'
35
-
36
- require 'openstudio'
37
-
38
- module FromHoneybee
39
- class SimulationParameter
40
- attr_reader :errors, :warnings
41
-
42
- # Read Simulation Parameter JSON from disk
43
- def self.read_from_disk(file)
44
- hash = nil
45
- File.open(File.join(file), 'r') do |f|
46
- hash = JSON.parse(f.read, symbolize_names: true)
47
- end
48
-
49
- SimulationParameter.new(hash)
50
- end
51
-
52
- # Load ModelObject from symbolized hash
53
- def initialize(hash)
54
- # initialize class variable @@extension only once
55
- @@extension = ExtensionSimulationParameter.new
56
- @@schema = nil
57
- File.open(@@extension.schema_file) do |f|
58
- @@schema = JSON.parse(f.read, symbolize_names: true)
59
- end
60
-
61
- @hash = hash
62
- @type = @hash[:type]
63
- raise 'Unknown model type' if @type.nil?
64
- raise "Incorrect model type for SimulationParameter '#{@type}'" unless @type == 'SimulationParameter'
65
- end
66
-
67
- # check if the model is valid
68
- def valid?
69
- if Gem.loaded_specs.has_key?("json-schema")
70
- return validation_errors.empty?
71
- else
72
- return true
73
- end
74
- end
75
-
76
- # return detailed model validation errors
77
- def validation_errors
78
- if Gem.loaded_specs.has_key?("json-schema")
79
- require 'json-schema'
80
- JSON::Validator.fully_validate(@@schema, @hash)
81
- end
82
- end
83
-
84
- def defaults
85
- @@schema[:components][:schemas]
86
- end
87
-
88
- # convert to openstudio model, clears errors and warnings
89
- def to_openstudio_model(openstudio_model=nil, log_report=false)
90
- @errors = []
91
- @warnings = []
92
-
93
- if log_report
94
- puts 'Starting SimulationParameter translation from Honeybee to OpenStudio'
95
- end
96
- @openstudio_model = if openstudio_model
97
- openstudio_model
98
- else
99
- OpenStudio::Model::Model.new
100
- end
101
-
102
- create_openstudio_objects
103
-
104
- if log_report
105
- puts 'Done with SimulationParameter translation!'
106
- end
107
-
108
- @openstudio_model
109
- end
110
-
111
- def create_openstudio_objects
112
- # get the defaults for each sub-object
113
- simct_defaults = defaults[:SimulationControl][:properties]
114
- shdw_defaults = defaults[:ShadowCalculation][:properties]
115
- siz_defaults = defaults[:SizingParameter][:properties]
116
- out_defaults = defaults[:SimulationOutput][:properties]
117
- runper_defaults = defaults[:RunPeriod][:properties]
118
- simpar_defaults = defaults[:SimulationParameter][:properties]
119
-
120
- # set defaults for the Model's SimulationControl object
121
- os_sim_control = @openstudio_model.getSimulationControl
122
- os_sim_control.setDoZoneSizingCalculation(simct_defaults[:do_zone_sizing][:default])
123
- os_sim_control.setDoSystemSizingCalculation(simct_defaults[:do_system_sizing][:default])
124
- os_sim_control.setDoPlantSizingCalculation(simct_defaults[:do_plant_sizing][:default])
125
- os_sim_control.setRunSimulationforWeatherFileRunPeriods(simct_defaults[:run_for_run_periods][:default])
126
- os_sim_control.setRunSimulationforSizingPeriods(simct_defaults[:run_for_sizing_periods][:default])
127
- os_sim_control.setSolarDistribution(shdw_defaults[:solar_distribution][:default])
128
-
129
- # override any SimulationControl defaults with lodaded JSON
130
- if @hash[:simulation_control]
131
- unless @hash[:simulation_control][:do_zone_sizing].nil?
132
- os_sim_control.setDoZoneSizingCalculation(@hash[:simulation_control][:do_zone_sizing])
133
- end
134
- unless @hash[:simulation_control][:do_system_sizing].nil?
135
- os_sim_control.setDoSystemSizingCalculation(@hash[:simulation_control][:do_system_sizing])
136
- end
137
- unless @hash[:simulation_control][:do_plant_sizing].nil?
138
- os_sim_control.setDoPlantSizingCalculation(@hash[:simulation_control][:do_plant_sizing])
139
- end
140
- unless @hash[:simulation_control][:run_for_run_periods].nil?
141
- os_sim_control.setRunSimulationforWeatherFileRunPeriods(@hash[:simulation_control][:run_for_run_periods])
142
- end
143
- unless @hash[:simulation_control][:run_for_sizing_periods].nil?
144
- os_sim_control.setRunSimulationforSizingPeriods(@hash[:simulation_control][:run_for_sizing_periods])
145
- end
146
- end
147
-
148
- # set defaults for the Model's ShadowCalculation object
149
- os_shadow_calc = @openstudio_model.getShadowCalculation
150
- os_shadow_calc.setCalculationFrequency(shdw_defaults[:calculation_frequency][:default])
151
- os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations(shdw_defaults[:maximum_figures][:default])
152
- os_shadow_calc.setCalculationMethod(shdw_defaults[:calculation_method][:default])
153
-
154
- # override any ShadowCalculation defaults with lodaded JSON
155
- if @hash[:shadow_calculation]
156
- if @hash[:shadow_calculation][:calculation_frequency]
157
- os_shadow_calc.setCalculationFrequency(@hash[:shadow_calculation][:calculation_frequency])
158
- end
159
- if @hash[:shadow_calculation][:maximum_figures]
160
- os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations(@hash[:shadow_calculation][:maximum_figures])
161
- end
162
- if @hash[:shadow_calculation][:calculation_method]
163
- os_shadow_calc.setCalculationMethod(@hash[:shadow_calculation][:calculation_method])
164
- end
165
- if @hash[:shadow_calculation][:solar_distribution]
166
- os_sim_control.setSolarDistribution(@hash[:shadow_calculation][:solar_distribution])
167
- end
168
- end
169
-
170
- # set defaults for the Model's SizingParameter object
171
- os_sizing_par = @openstudio_model.getSizingParameters
172
- os_sizing_par.setHeatingSizingFactor(siz_defaults[:heating_factor][:default])
173
- os_sizing_par.setCoolingSizingFactor(siz_defaults[:cooling_factor][:default])
174
-
175
- # override any SizingParameter defaults with lodaded JSON
176
- if @hash[:sizing_parameter]
177
- if @hash[:sizing_parameter][:heating_factor]
178
- os_sizing_par.setHeatingSizingFactor(@hash[:sizing_parameter][:heating_factor])
179
- end
180
- if @hash[:sizing_parameter][:cooling_factor]
181
- os_sizing_par.setCoolingSizingFactor(@hash[:sizing_parameter][:cooling_factor])
182
- end
183
- # set any design days
184
- if @hash[:sizing_parameter][:design_days]
185
- @hash[:sizing_parameter][:design_days].each do |des_day|
186
- des_day_object = DesignDay.new(des_day)
187
- os_des_day = des_day_object.to_openstudio(@openstudio_model)
188
- end
189
- end
190
- end
191
-
192
- # set Outputs for the simulation
193
- if @hash[:output]
194
- if @hash[:output][:outputs]
195
- @hash[:output][:outputs].each do |output|
196
- os_output = OpenStudio::Model::OutputVariable.new(output, @openstudio_model)
197
- if @hash[:output][:reporting_frequency]
198
- os_output.setReportingFrequency(@hash[:output][:reporting_frequency])
199
- else
200
- os_output.setReportingFrequency(out_defaults[:reporting_frequency][:default])
201
- end
202
- end
203
- end
204
- if @hash[:output][:summary_reports]
205
- begin
206
- os_report = OpenStudio::Model::OutputTableSummaryReports.new(@openstudio_model)
207
- rescue NameError
208
- end
209
- @hash[:output][:summary_reports].each do |report|
210
- begin
211
- os_report.addSummaryReport(report)
212
- rescue NoMethodError
213
- end
214
- end
215
- end
216
- end
217
-
218
- # set defaults for the year description
219
- year_description = @openstudio_model.getYearDescription
220
- year_description.setDayofWeekforStartDay(runper_defaults[:start_day_of_week][:default])
221
-
222
- # set up the simulation RunPeriod
223
- if @hash[:run_period]
224
- # set the leap year
225
- if @hash[:run_period][:leap_year]
226
- year_description.setIsLeapYear(@hash[:run_period][:leap_year])
227
- end
228
-
229
- # set the start day of the week
230
- if @hash[:run_period][:start_day_of_week]
231
- year_description.setDayofWeekforStartDay(@hash[:run_period][:start_day_of_week])
232
- end
233
-
234
- # set the run preiod start and end dates
235
- openstudio_runperiod = @openstudio_model.getRunPeriod
236
- openstudio_runperiod.setBeginMonth(@hash[:run_period][:start_date][0])
237
- openstudio_runperiod.setBeginDayOfMonth(@hash[:run_period][:start_date][1])
238
- openstudio_runperiod.setEndMonth(@hash[:run_period][:end_date][0])
239
- openstudio_runperiod.setEndDayOfMonth(@hash[:run_period][:end_date][1])
240
-
241
- # set the daylight savings time
242
- if @hash[:run_period][:daylight_saving_time]
243
- os_dl_saving = @openstudio_model.getRunPeriodControlDaylightSavingTime
244
- os_dl_saving.setStartDate(
245
- OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:start_date][0]),
246
- @hash[:run_period][:daylight_saving_time][:start_date][1])
247
- os_dl_saving.setEndDate(
248
- OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:end_date][0]),
249
- @hash[:run_period][:daylight_saving_time][:end_date][1])
250
- end
251
-
252
- # TODO: set the holidays once they are available in OpenStudio SDK
253
- end
254
-
255
- # set the simulation timestep
256
- os_timestep = @openstudio_model.getTimestep
257
- if @hash[:timestep]
258
- os_timestep.setNumberOfTimestepsPerHour(@hash[:timestep])
259
- else
260
- os_timestep.setNumberOfTimestepsPerHour(simpar_defaults[:timestep][:default])
261
- end
262
-
263
- # assign the north
264
- if @hash[:north_angle]
265
- @openstudio_model.getBuilding.setNorthAxis(-@hash[:north_angle])
266
- end
267
-
268
- # assign the terrain
269
- os_site = @openstudio_model.getSite
270
- os_site.setTerrain(simpar_defaults[:terrain_type][:default])
271
- if @hash[:terrain_type]
272
- os_site.setTerrain(@hash[:terrain_type])
273
- end
274
- end
275
-
276
- end #SimulationParameter
277
- end #FromHoneybee
1
+ # *******************************************************************************
2
+ # Honeybee OpenStudio Gem, Copyright (c) 2020, Alliance for Sustainable
3
+ # Energy, LLC, Ladybug Tools LLC and other contributors. All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # (1) Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # (3) Neither the name of the copyright holder nor the names of any contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission from the respective party.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
23
+ # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
24
+ # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26
+ # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # *******************************************************************************
31
+
32
+ require 'from_honeybee/model_object'
33
+ require 'from_honeybee/simulation/extension'
34
+ require 'from_honeybee/simulation/designday'
35
+
36
+ require 'openstudio'
37
+
38
+ module FromHoneybee
39
+ class SimulationParameter
40
+ attr_reader :errors, :warnings
41
+
42
+ # Read Simulation Parameter JSON from disk
43
+ def self.read_from_disk(file)
44
+ hash = nil
45
+ File.open(File.join(file), 'r') do |f|
46
+ hash = JSON.parse(f.read, symbolize_names: true)
47
+ end
48
+
49
+ SimulationParameter.new(hash)
50
+ end
51
+
52
+ # Load ModelObject from symbolized hash
53
+ def initialize(hash)
54
+ # initialize class variable @@extension only once
55
+ @@extension = ExtensionSimulationParameter.new
56
+ @@schema = nil
57
+ File.open(@@extension.schema_file) do |f|
58
+ @@schema = JSON.parse(f.read, symbolize_names: true)
59
+ end
60
+
61
+ @hash = hash
62
+ @type = @hash[:type]
63
+ raise 'Unknown model type' if @type.nil?
64
+ raise "Incorrect model type for SimulationParameter '#{@type}'" unless @type == 'SimulationParameter'
65
+ end
66
+
67
+ # check if the model is valid
68
+ def valid?
69
+ if Gem.loaded_specs.has_key?("json-schema")
70
+ return validation_errors.empty?
71
+ else
72
+ return true
73
+ end
74
+ end
75
+
76
+ # return detailed model validation errors
77
+ def validation_errors
78
+ if Gem.loaded_specs.has_key?("json-schema")
79
+ require 'json-schema'
80
+ JSON::Validator.fully_validate(@@schema, @hash)
81
+ end
82
+ end
83
+
84
+ def defaults
85
+ @@schema[:components][:schemas]
86
+ end
87
+
88
+ # convert to openstudio model, clears errors and warnings
89
+ def to_openstudio_model(openstudio_model=nil, log_report=false)
90
+ @errors = []
91
+ @warnings = []
92
+
93
+ if log_report
94
+ puts 'Starting SimulationParameter translation from Honeybee to OpenStudio'
95
+ end
96
+ @openstudio_model = if openstudio_model
97
+ openstudio_model
98
+ else
99
+ OpenStudio::Model::Model.new
100
+ end
101
+
102
+ create_openstudio_objects
103
+
104
+ if log_report
105
+ puts 'Done with SimulationParameter translation!'
106
+ end
107
+
108
+ @openstudio_model
109
+ end
110
+
111
+ def create_openstudio_objects
112
+ # get the defaults for each sub-object
113
+ simct_defaults = defaults[:SimulationControl][:properties]
114
+ shdw_defaults = defaults[:ShadowCalculation][:properties]
115
+ siz_defaults = defaults[:SizingParameter][:properties]
116
+ out_defaults = defaults[:SimulationOutput][:properties]
117
+ runper_defaults = defaults[:RunPeriod][:properties]
118
+ simpar_defaults = defaults[:SimulationParameter][:properties]
119
+
120
+ # set defaults for the Model's SimulationControl object
121
+ os_sim_control = @openstudio_model.getSimulationControl
122
+ os_sim_control.setDoZoneSizingCalculation(simct_defaults[:do_zone_sizing][:default])
123
+ os_sim_control.setDoSystemSizingCalculation(simct_defaults[:do_system_sizing][:default])
124
+ os_sim_control.setDoPlantSizingCalculation(simct_defaults[:do_plant_sizing][:default])
125
+ os_sim_control.setRunSimulationforWeatherFileRunPeriods(simct_defaults[:run_for_run_periods][:default])
126
+ os_sim_control.setRunSimulationforSizingPeriods(simct_defaults[:run_for_sizing_periods][:default])
127
+ os_sim_control.setSolarDistribution(shdw_defaults[:solar_distribution][:default])
128
+
129
+ # override any SimulationControl defaults with lodaded JSON
130
+ if @hash[:simulation_control]
131
+ unless @hash[:simulation_control][:do_zone_sizing].nil?
132
+ os_sim_control.setDoZoneSizingCalculation(@hash[:simulation_control][:do_zone_sizing])
133
+ end
134
+ unless @hash[:simulation_control][:do_system_sizing].nil?
135
+ os_sim_control.setDoSystemSizingCalculation(@hash[:simulation_control][:do_system_sizing])
136
+ end
137
+ unless @hash[:simulation_control][:do_plant_sizing].nil?
138
+ os_sim_control.setDoPlantSizingCalculation(@hash[:simulation_control][:do_plant_sizing])
139
+ end
140
+ unless @hash[:simulation_control][:run_for_run_periods].nil?
141
+ os_sim_control.setRunSimulationforWeatherFileRunPeriods(@hash[:simulation_control][:run_for_run_periods])
142
+ end
143
+ unless @hash[:simulation_control][:run_for_sizing_periods].nil?
144
+ os_sim_control.setRunSimulationforSizingPeriods(@hash[:simulation_control][:run_for_sizing_periods])
145
+ end
146
+ end
147
+
148
+ # set defaults for the Model's ShadowCalculation object
149
+ os_shadow_calc = @openstudio_model.getShadowCalculation
150
+ os_shadow_calc.setCalculationFrequency(shdw_defaults[:calculation_frequency][:default])
151
+ os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations(shdw_defaults[:maximum_figures][:default])
152
+ os_shadow_calc.setCalculationMethod(shdw_defaults[:calculation_method][:default])
153
+
154
+ # override any ShadowCalculation defaults with lodaded JSON
155
+ if @hash[:shadow_calculation]
156
+ if @hash[:shadow_calculation][:calculation_frequency]
157
+ os_shadow_calc.setCalculationFrequency(@hash[:shadow_calculation][:calculation_frequency])
158
+ end
159
+ if @hash[:shadow_calculation][:maximum_figures]
160
+ os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations(@hash[:shadow_calculation][:maximum_figures])
161
+ end
162
+ if @hash[:shadow_calculation][:calculation_method]
163
+ os_shadow_calc.setCalculationMethod(@hash[:shadow_calculation][:calculation_method])
164
+ end
165
+ if @hash[:shadow_calculation][:solar_distribution]
166
+ os_sim_control.setSolarDistribution(@hash[:shadow_calculation][:solar_distribution])
167
+ end
168
+ end
169
+
170
+ # set defaults for the Model's SizingParameter object
171
+ os_sizing_par = @openstudio_model.getSizingParameters
172
+ os_sizing_par.setHeatingSizingFactor(siz_defaults[:heating_factor][:default])
173
+ os_sizing_par.setCoolingSizingFactor(siz_defaults[:cooling_factor][:default])
174
+
175
+ # override any SizingParameter defaults with lodaded JSON
176
+ if @hash[:sizing_parameter]
177
+ if @hash[:sizing_parameter][:heating_factor]
178
+ os_sizing_par.setHeatingSizingFactor(@hash[:sizing_parameter][:heating_factor])
179
+ end
180
+ if @hash[:sizing_parameter][:cooling_factor]
181
+ os_sizing_par.setCoolingSizingFactor(@hash[:sizing_parameter][:cooling_factor])
182
+ end
183
+ # set any design days
184
+ if @hash[:sizing_parameter][:design_days]
185
+ @hash[:sizing_parameter][:design_days].each do |des_day|
186
+ des_day_object = DesignDay.new(des_day)
187
+ os_des_day = des_day_object.to_openstudio(@openstudio_model)
188
+ end
189
+ end
190
+ end
191
+
192
+ # set Outputs for the simulation
193
+ if @hash[:output]
194
+ if @hash[:output][:outputs]
195
+ @hash[:output][:outputs].each do |output|
196
+ os_output = OpenStudio::Model::OutputVariable.new(output, @openstudio_model)
197
+ if @hash[:output][:reporting_frequency]
198
+ os_output.setReportingFrequency(@hash[:output][:reporting_frequency])
199
+ else
200
+ os_output.setReportingFrequency(out_defaults[:reporting_frequency][:default])
201
+ end
202
+ end
203
+ end
204
+ if @hash[:output][:summary_reports]
205
+ begin
206
+ os_report = OpenStudio::Model::OutputTableSummaryReports.new(@openstudio_model)
207
+ rescue NameError
208
+ end
209
+ @hash[:output][:summary_reports].each do |report|
210
+ begin
211
+ os_report.addSummaryReport(report)
212
+ rescue NoMethodError
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ # set defaults for the year description
219
+ year_description = @openstudio_model.getYearDescription
220
+ year_description.setDayofWeekforStartDay(runper_defaults[:start_day_of_week][:default])
221
+
222
+ # set up the simulation RunPeriod
223
+ if @hash[:run_period]
224
+ # set the leap year
225
+ if @hash[:run_period][:leap_year]
226
+ year_description.setIsLeapYear(@hash[:run_period][:leap_year])
227
+ end
228
+
229
+ # set the start day of the week
230
+ if @hash[:run_period][:start_day_of_week]
231
+ year_description.setDayofWeekforStartDay(@hash[:run_period][:start_day_of_week])
232
+ end
233
+
234
+ # set the run preiod start and end dates
235
+ openstudio_runperiod = @openstudio_model.getRunPeriod
236
+ openstudio_runperiod.setBeginMonth(@hash[:run_period][:start_date][0])
237
+ openstudio_runperiod.setBeginDayOfMonth(@hash[:run_period][:start_date][1])
238
+ openstudio_runperiod.setEndMonth(@hash[:run_period][:end_date][0])
239
+ openstudio_runperiod.setEndDayOfMonth(@hash[:run_period][:end_date][1])
240
+
241
+ # set the daylight savings time
242
+ if @hash[:run_period][:daylight_saving_time]
243
+ os_dl_saving = @openstudio_model.getRunPeriodControlDaylightSavingTime
244
+ os_dl_saving.setStartDate(
245
+ OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:start_date][0]),
246
+ @hash[:run_period][:daylight_saving_time][:start_date][1])
247
+ os_dl_saving.setEndDate(
248
+ OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:end_date][0]),
249
+ @hash[:run_period][:daylight_saving_time][:end_date][1])
250
+ end
251
+
252
+ # TODO: set the holidays once they are available in OpenStudio SDK
253
+ end
254
+
255
+ # set the simulation timestep
256
+ os_timestep = @openstudio_model.getTimestep
257
+ if @hash[:timestep]
258
+ os_timestep.setNumberOfTimestepsPerHour(@hash[:timestep])
259
+ else
260
+ os_timestep.setNumberOfTimestepsPerHour(simpar_defaults[:timestep][:default])
261
+ end
262
+
263
+ # assign the north
264
+ if @hash[:north_angle]
265
+ @openstudio_model.getBuilding.setNorthAxis(-@hash[:north_angle])
266
+ end
267
+
268
+ # assign the terrain
269
+ os_site = @openstudio_model.getSite
270
+ os_site.setTerrain(simpar_defaults[:terrain_type][:default])
271
+ if @hash[:terrain_type]
272
+ os_site.setTerrain(@hash[:terrain_type])
273
+ end
274
+ end
275
+
276
+ end #SimulationParameter
277
+ end #FromHoneybee