honeybee-openstudio 0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +32 -33
  4. data/.releaserc.json +7 -7
  5. data/.travis.yml +41 -0
  6. data/Gemfile +18 -14
  7. data/LICENSE.md +23 -23
  8. data/README.md +95 -95
  9. data/Rakefile +21 -16
  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 -38
  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/{honeybee/_defaults → from_honeybee/_openapi}/model.json +8126 -11310
  19. data/lib/{honeybee/_defaults → from_honeybee/_openapi}/simulation-parameter.json +842 -972
  20. data/lib/{to_openstudio → from_honeybee}/construction/air.rb +65 -56
  21. data/lib/{to_openstudio → from_honeybee}/construction/opaque.rb +77 -67
  22. data/lib/{to_openstudio → from_honeybee}/construction/shade.rb +108 -99
  23. data/lib/{to_openstudio → from_honeybee}/construction/window.rb +80 -70
  24. data/lib/{to_openstudio → from_honeybee}/construction_set.rb +278 -266
  25. data/lib/{honeybee → from_honeybee}/extension.rb +109 -129
  26. data/lib/{to_openstudio → from_honeybee}/geometry/aperture.rb +167 -157
  27. data/lib/{to_openstudio → from_honeybee}/geometry/door.rb +160 -150
  28. data/lib/{to_openstudio → from_honeybee}/geometry/face.rb +163 -178
  29. data/lib/{to_openstudio → from_honeybee}/geometry/room.rb +392 -442
  30. data/lib/{to_openstudio → from_honeybee}/geometry/shade.rb +89 -79
  31. data/lib/{to_openstudio → from_honeybee}/hvac/ideal_air.rb +150 -141
  32. data/lib/{to_openstudio → from_honeybee}/load/electric_equipment.rb +96 -87
  33. data/lib/{to_openstudio → from_honeybee}/load/gas_equipment.rb +97 -88
  34. data/lib/{to_openstudio → from_honeybee}/load/infiltration.rb +94 -85
  35. data/lib/{to_openstudio → from_honeybee}/load/lighting.rb +98 -89
  36. data/lib/{to_openstudio → from_honeybee}/load/people.rb +100 -91
  37. data/lib/{to_openstudio → from_honeybee}/load/setpoint_humidistat.rb +75 -66
  38. data/lib/{to_openstudio → from_honeybee}/load/setpoint_thermostat.rb +71 -62
  39. data/lib/{to_openstudio → from_honeybee}/load/ventilation.rb +96 -87
  40. data/lib/{to_openstudio → from_honeybee}/material/opaque.rb +94 -85
  41. data/lib/{to_openstudio → from_honeybee}/material/opaque_no_mass.rb +94 -85
  42. data/lib/{to_openstudio → from_honeybee}/material/window_blind.rb +238 -229
  43. data/lib/{to_openstudio → from_honeybee}/material/window_gas.rb +76 -67
  44. data/lib/{to_openstudio → from_honeybee}/material/window_gas_custom.rb +118 -108
  45. data/lib/{to_openstudio → from_honeybee}/material/window_gas_mixture.rb +79 -70
  46. data/lib/{to_openstudio → from_honeybee}/material/window_glazing.rb +166 -157
  47. data/lib/{to_openstudio → from_honeybee}/material/window_shade.rb +160 -151
  48. data/lib/{to_openstudio → from_honeybee}/material/window_simpleglazsys.rb +73 -64
  49. data/lib/from_honeybee/model.rb +434 -0
  50. data/lib/{honeybee → from_honeybee}/model_object.rb +110 -108
  51. data/lib/{to_openstudio → from_honeybee}/program_type.rb +124 -104
  52. data/lib/{to_openstudio → from_honeybee}/schedule/fixed_interval.rb +115 -105
  53. data/lib/{to_openstudio → from_honeybee}/schedule/ruleset.rb +164 -164
  54. data/lib/{to_openstudio → from_honeybee}/schedule/type_limit.rb +88 -76
  55. data/lib/{to_openstudio/simulation/design_day.rb → from_honeybee/simulation/designday.rb} +105 -96
  56. data/lib/{honeybee/load/lighting.rb → from_honeybee/simulation/extension.rb} +46 -43
  57. data/lib/{to_openstudio/simulation/parameter_model.rb → from_honeybee/simulation/parameter.rb} +277 -243
  58. data/lib/{honeybee/simulation/design_day.rb → from_honeybee/version.rb} +34 -42
  59. data/lib/{honeybee.rb → from_honeybee.rb} +86 -93
  60. data/lib/measures/from_honeybee_model/LICENSE.md +27 -23
  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 -80
  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 +27 -23
  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 -86
  69. data/lib/measures/from_honeybee_simulation_parameter/tests/from_honeybee_simulation_parameter_test.rb +109 -109
  70. metadata +89 -147
  71. data/.github/workflows/ci.yaml +0 -88
  72. data/doc_templates/README.md.erb +0 -42
  73. data/lib/from_openstudio/geometry/aperture.rb +0 -136
  74. data/lib/from_openstudio/geometry/door.rb +0 -136
  75. data/lib/from_openstudio/geometry/face.rb +0 -174
  76. data/lib/from_openstudio/geometry/room.rb +0 -121
  77. data/lib/from_openstudio/geometry/shade.rb +0 -87
  78. data/lib/from_openstudio/model.rb +0 -123
  79. data/lib/from_openstudio/model_object.rb +0 -43
  80. data/lib/from_openstudio/simulation/design_day.rb +0 -123
  81. data/lib/from_openstudio/simulation/parameter_model.rb +0 -93
  82. data/lib/from_openstudio/simulation/simulation_output.rb +0 -67
  83. data/lib/from_openstudio.rb +0 -49
  84. data/lib/honeybee/_defaults/energy_default.json +0 -1682
  85. data/lib/honeybee/construction/air.rb +0 -42
  86. data/lib/honeybee/construction/opaque.rb +0 -42
  87. data/lib/honeybee/construction/shade.rb +0 -42
  88. data/lib/honeybee/construction/window.rb +0 -51
  89. data/lib/honeybee/construction/windowshade.rb +0 -43
  90. data/lib/honeybee/construction_set.rb +0 -42
  91. data/lib/honeybee/geometry/aperture.rb +0 -42
  92. data/lib/honeybee/geometry/door.rb +0 -42
  93. data/lib/honeybee/geometry/face.rb +0 -48
  94. data/lib/honeybee/geometry/room.rb +0 -56
  95. data/lib/honeybee/geometry/shade.rb +0 -42
  96. data/lib/honeybee/hvac/ideal_air.rb +0 -42
  97. data/lib/honeybee/hvac/template.rb +0 -73
  98. data/lib/honeybee/load/electric_equipment.rb +0 -42
  99. data/lib/honeybee/load/gas_equipment.rb +0 -42
  100. data/lib/honeybee/load/infiltration.rb +0 -42
  101. data/lib/honeybee/load/people.rb +0 -42
  102. data/lib/honeybee/load/setpoint_humidistat.rb +0 -46
  103. data/lib/honeybee/load/setpoint_thermostat.rb +0 -46
  104. data/lib/honeybee/load/ventilation.rb +0 -42
  105. data/lib/honeybee/material/opaque.rb +0 -42
  106. data/lib/honeybee/material/opaque_no_mass.rb +0 -42
  107. data/lib/honeybee/material/window_blind.rb +0 -42
  108. data/lib/honeybee/material/window_gas.rb +0 -42
  109. data/lib/honeybee/material/window_gas_custom.rb +0 -42
  110. data/lib/honeybee/material/window_gas_mixture.rb +0 -42
  111. data/lib/honeybee/material/window_glazing.rb +0 -42
  112. data/lib/honeybee/material/window_shade.rb +0 -42
  113. data/lib/honeybee/material/window_simpleglazsys.rb +0 -42
  114. data/lib/honeybee/model.rb +0 -87
  115. data/lib/honeybee/program_type.rb +0 -56
  116. data/lib/honeybee/schedule/fixed_interval.rb +0 -42
  117. data/lib/honeybee/schedule/ruleset.rb +0 -42
  118. data/lib/honeybee/schedule/type_limit.rb +0 -42
  119. data/lib/honeybee/simulation/parameter_model.rb +0 -86
  120. data/lib/honeybee/simulation/simulation_output.rb +0 -42
  121. data/lib/honeybee/ventcool/control.rb +0 -42
  122. data/lib/honeybee/ventcool/opening.rb +0 -46
  123. data/lib/honeybee/ventcool/simulation.rb +0 -42
  124. data/lib/to_openstudio/construction/windowshade.rb +0 -196
  125. data/lib/to_openstudio/hvac/Model.hvac.rb +0 -641
  126. data/lib/to_openstudio/hvac/template.rb +0 -169
  127. data/lib/to_openstudio/model.rb +0 -497
  128. data/lib/to_openstudio/model_object.rb +0 -52
  129. data/lib/to_openstudio/ventcool/control.rb +0 -185
  130. data/lib/to_openstudio/ventcool/opening.rb +0 -189
  131. data/lib/to_openstudio/ventcool/simulation.rb +0 -101
  132. data/lib/to_openstudio.rb +0 -92
@@ -1,243 +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 'honeybee/simulation/parameter_model'
33
-
34
- require 'openstudio'
35
-
36
- module Honeybee
37
- class SimulationParameter
38
-
39
- # convert to openstudio model, clears errors and warnings
40
- def to_openstudio_model(openstudio_model=nil, log_report=false)
41
- @errors = []
42
- @warnings = []
43
-
44
- if log_report
45
- puts 'Starting SimulationParameter translation from Honeybee to OpenStudio'
46
- end
47
- @openstudio_model = if openstudio_model
48
- openstudio_model
49
- else
50
- OpenStudio::Model::Model.new
51
- end
52
-
53
- create_openstudio_objects
54
-
55
- if log_report
56
- puts 'Done with SimulationParameter translation!'
57
- end
58
-
59
- @openstudio_model
60
- end
61
-
62
- def create_openstudio_objects
63
- # get the defaults for each sub-object
64
- simct_defaults = defaults[:SimulationControl][:properties]
65
- shdw_defaults = defaults[:ShadowCalculation][:properties]
66
- siz_defaults = defaults[:SizingParameter][:properties]
67
- out_defaults = defaults[:SimulationOutput][:properties]
68
- runper_defaults = defaults[:RunPeriod][:properties]
69
- simpar_defaults = defaults[:SimulationParameter][:properties]
70
-
71
- # set defaults for the Model's SimulationControl object
72
- os_sim_control = @openstudio_model.getSimulationControl
73
- os_sim_control.setDoZoneSizingCalculation(simct_defaults[:do_zone_sizing][:default])
74
- os_sim_control.setDoSystemSizingCalculation(simct_defaults[:do_system_sizing][:default])
75
- os_sim_control.setDoPlantSizingCalculation(simct_defaults[:do_plant_sizing][:default])
76
- os_sim_control.setRunSimulationforWeatherFileRunPeriods(simct_defaults[:run_for_run_periods][:default])
77
- os_sim_control.setRunSimulationforSizingPeriods(simct_defaults[:run_for_sizing_periods][:default])
78
- os_sim_control.setSolarDistribution(shdw_defaults[:solar_distribution][:default])
79
-
80
- # override any SimulationControl defaults with lodaded JSON
81
- if @hash[:simulation_control]
82
- unless @hash[:simulation_control][:do_zone_sizing].nil?
83
- os_sim_control.setDoZoneSizingCalculation(@hash[:simulation_control][:do_zone_sizing])
84
- end
85
- unless @hash[:simulation_control][:do_system_sizing].nil?
86
- os_sim_control.setDoSystemSizingCalculation(@hash[:simulation_control][:do_system_sizing])
87
- end
88
- unless @hash[:simulation_control][:do_plant_sizing].nil?
89
- os_sim_control.setDoPlantSizingCalculation(@hash[:simulation_control][:do_plant_sizing])
90
- end
91
- unless @hash[:simulation_control][:run_for_run_periods].nil?
92
- os_sim_control.setRunSimulationforWeatherFileRunPeriods(@hash[:simulation_control][:run_for_run_periods])
93
- end
94
- unless @hash[:simulation_control][:run_for_sizing_periods].nil?
95
- os_sim_control.setRunSimulationforSizingPeriods(@hash[:simulation_control][:run_for_sizing_periods])
96
- end
97
- end
98
-
99
- # set defaults for the Model's ShadowCalculation object
100
- os_shadow_calc = @openstudio_model.getShadowCalculation
101
- os_shadow_calc.setShadingCalculationMethod(
102
- shdw_defaults[:calculation_method][:default])
103
- os_shadow_calc.setShadingCalculationUpdateFrequencyMethod(
104
- shdw_defaults[:calculation_update_method][:default])
105
- os_shadow_calc.setShadingCalculationUpdateFrequency(
106
- shdw_defaults[:calculation_frequency][:default])
107
- os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations(
108
- shdw_defaults[:maximum_figures][:default])
109
-
110
- # override any ShadowCalculation defaults with lodaded JSON
111
- if @hash[:shadow_calculation]
112
- if @hash[:shadow_calculation][:calculation_method]
113
- os_shadow_calc.setShadingCalculationMethod(
114
- @hash[:shadow_calculation][:calculation_method])
115
- end
116
- if @hash[:shadow_calculation][:calculation_update_method]
117
- os_shadow_calc.setShadingCalculationUpdateFrequencyMethod(
118
- @hash[:shadow_calculation][:calculation_update_method])
119
- end
120
- if @hash[:shadow_calculation][:calculation_frequency]
121
- os_shadow_calc.setShadingCalculationUpdateFrequency(
122
- @hash[:shadow_calculation][:calculation_frequency])
123
- end
124
- if @hash[:shadow_calculation][:maximum_figures]
125
- os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations(
126
- @hash[:shadow_calculation][:maximum_figures])
127
- end
128
- if @hash[:shadow_calculation][:solar_distribution]
129
- os_sim_control.setSolarDistribution(
130
- @hash[:shadow_calculation][:solar_distribution])
131
- end
132
- end
133
-
134
- # set defaults for the Model's SizingParameter object
135
- os_sizing_par = @openstudio_model.getSizingParameters
136
- os_sizing_par.setHeatingSizingFactor(siz_defaults[:heating_factor][:default])
137
- os_sizing_par.setCoolingSizingFactor(siz_defaults[:cooling_factor][:default])
138
-
139
- # override any SizingParameter defaults with lodaded JSON
140
- if @hash[:sizing_parameter]
141
- if @hash[:sizing_parameter][:heating_factor]
142
- os_sizing_par.setHeatingSizingFactor(@hash[:sizing_parameter][:heating_factor])
143
- end
144
- if @hash[:sizing_parameter][:cooling_factor]
145
- os_sizing_par.setCoolingSizingFactor(@hash[:sizing_parameter][:cooling_factor])
146
- end
147
- # set any design days
148
- if @hash[:sizing_parameter][:design_days]
149
- @hash[:sizing_parameter][:design_days].each do |des_day|
150
- des_day_object = DesignDay.new(des_day)
151
- os_des_day = des_day_object.to_openstudio(@openstudio_model)
152
- end
153
- end
154
- end
155
-
156
- # set Outputs for the simulation
157
- if @hash[:output]
158
- if @hash[:output][:outputs]
159
- @hash[:output][:outputs].each do |output|
160
- os_output = OpenStudio::Model::OutputVariable.new(output, @openstudio_model)
161
- if @hash[:output][:reporting_frequency]
162
- os_output.setReportingFrequency(@hash[:output][:reporting_frequency])
163
- else
164
- os_output.setReportingFrequency(out_defaults[:reporting_frequency][:default])
165
- end
166
- end
167
- end
168
- if @hash[:output][:summary_reports]
169
- os_report = @openstudio_model.getOutputTableSummaryReports
170
- @hash[:output][:summary_reports].each do |report|
171
- os_report.addSummaryReport(report)
172
- end
173
- end
174
- end
175
-
176
- # set defaults for the year description
177
- year_description = @openstudio_model.getYearDescription
178
- year_description.setDayofWeekforStartDay(runper_defaults[:start_day_of_week][:default])
179
-
180
- # set up the simulation RunPeriod
181
- if @hash[:run_period]
182
- # set the leap year
183
- if @hash[:run_period][:leap_year]
184
- year_description.setIsLeapYear(@hash[:run_period][:leap_year])
185
- end
186
-
187
- # set the start day of the week
188
- if @hash[:run_period][:start_day_of_week]
189
- year_description.setDayofWeekforStartDay(@hash[:run_period][:start_day_of_week])
190
- end
191
-
192
- # set the run preiod start and end dates
193
- openstudio_runperiod = @openstudio_model.getRunPeriod
194
- openstudio_runperiod.setBeginMonth(@hash[:run_period][:start_date][0])
195
- openstudio_runperiod.setBeginDayOfMonth(@hash[:run_period][:start_date][1])
196
- openstudio_runperiod.setEndMonth(@hash[:run_period][:end_date][0])
197
- openstudio_runperiod.setEndDayOfMonth(@hash[:run_period][:end_date][1])
198
-
199
- # set the daylight savings time
200
- if @hash[:run_period][:daylight_saving_time]
201
- os_dl_saving = @openstudio_model.getRunPeriodControlDaylightSavingTime
202
- os_dl_saving.setStartDate(
203
- OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:start_date][0]),
204
- @hash[:run_period][:daylight_saving_time][:start_date][1])
205
- os_dl_saving.setEndDate(
206
- OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:end_date][0]),
207
- @hash[:run_period][:daylight_saving_time][:end_date][1])
208
- end
209
-
210
- # Set the holidays
211
- if @hash[:run_period][:holidays]
212
- @hash[:run_period][:holidays].each do |hol|
213
- os_hol = OpenStudio::Model::RunPeriodControlSpecialDays.new(
214
- OpenStudio::MonthOfYear.new(hol[0]), hol[1], @openstudio_model)
215
- os_hol.setDuration(1)
216
- os_hol.setSpecialDayType('Holiday')
217
- end
218
- end
219
- end
220
-
221
- # set the simulation timestep
222
- os_timestep = @openstudio_model.getTimestep
223
- if @hash[:timestep]
224
- os_timestep.setNumberOfTimestepsPerHour(@hash[:timestep])
225
- else
226
- os_timestep.setNumberOfTimestepsPerHour(simpar_defaults[:timestep][:default])
227
- end
228
-
229
- # assign the north
230
- if @hash[:north_angle]
231
- @openstudio_model.getBuilding.setNorthAxis(-@hash[:north_angle])
232
- end
233
-
234
- # assign the terrain
235
- os_site = @openstudio_model.getSite
236
- os_site.setTerrain(simpar_defaults[:terrain_type][:default])
237
- if @hash[:terrain_type]
238
- os_site.setTerrain(@hash[:terrain_type])
239
- end
240
- end
241
-
242
- end #SimulationParameter
243
- end #Honeybee
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,42 +1,34 @@
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 'honeybee/model_object'
33
-
34
- module Honeybee
35
- class DesignDay < ModelObject
36
-
37
- def defaults
38
- @@schema[:components][:schemas][:DesignDay][:properties]
39
- end
40
-
41
- end # DesignDay
42
- end # Honeybee
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
+ module FromHoneybee
33
+ VERSION = '0.1.0'.freeze
34
+ end