Class: Honeybee::SimulationParameter
- Inherits:
-
Object
- Object
- Honeybee::SimulationParameter
- Defined in:
- lib/honeybee/simulation/parameter_model.rb,
lib/to_openstudio/simulation/parameter_model.rb,
lib/from_openstudio/simulation/parameter_model.rb
Constant Summary collapse
- @@schema =
nil
- @@standard_mapper =
{ DOE_Ref_Pre_1980: 'DOE Ref Pre-1980', DOE_Ref_1980_2004: 'DOE Ref 1980-2004', ASHRAE_2004: '90.1-2004', ASHRAE_2007: '90.1-2007', ASHRAE_2010: '90.1-2010', ASHRAE_2013: '90.1-2013', ASHRAE_2016: '90.1-2016', ASHRAE_2019: '90.1-2019' }
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
-
.read_from_disk(file) ⇒ Object
Read Simulation Parameter JSON from disk.
- .sizing_parameter_from_model(openstudio_model) ⇒ Object
-
.translate_from_gbxml_file(file) ⇒ Object
Create Ladybug Energy Model JSON from gbXML file.
-
.translate_from_idf_file(file) ⇒ Object
Create Ladybug Energy Model JSON from IDF file.
-
.translate_from_openstudio(openstudio_model) ⇒ Object
Create Ladybug SimulationParameter JSON from OpenStudio Model.
-
.translate_from_osm_file(file) ⇒ Object
Create Ladybug Energy Model JSON from OSM file.
Instance Method Summary collapse
- #create_openstudio_objects ⇒ Object
- #defaults ⇒ Object
- #gaussian(mean, stddev, seed) ⇒ Object
-
#initialize(hash) ⇒ SimulationParameter
constructor
Load ModelObject from symbolized hash.
-
#to_openstudio_model(openstudio_model = nil, log_report = false) ⇒ Object
convert to openstudio model, clears errors and warnings.
Constructor Details
#initialize(hash) ⇒ SimulationParameter
Load ModelObject from symbolized hash
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/honeybee/simulation/parameter_model.rb', line 51 def initialize(hash) if @@schema.nil? schema_path = File.join(File.dirname(__FILE__), '..', '_defaults', 'simulation-parameter.json') File.open(schema_path) do |f| @@schema = JSON.parse(f.read, symbolize_names: true) end end @hash = hash @type = @hash[:type] raise 'Unknown model type' if @type.nil? raise "Incorrect model type for SimulationParameter '#{@type}'" unless @type == 'SimulationParameter' end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
35 36 37 |
# File 'lib/honeybee/simulation/parameter_model.rb', line 35 def errors @errors end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
35 36 37 |
# File 'lib/honeybee/simulation/parameter_model.rb', line 35 def hash @hash end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
35 36 37 |
# File 'lib/honeybee/simulation/parameter_model.rb', line 35 def warnings @warnings end |
Class Method Details
.read_from_disk(file) ⇒ Object
Read Simulation Parameter JSON from disk
40 41 42 43 44 45 46 47 48 |
# File 'lib/honeybee/simulation/parameter_model.rb', line 40 def self.read_from_disk(file) hash = nil File.open(File.join(file), 'r') do |f| hash = JSON.parse(File.read(f, :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8'), symbolize_names: true, encoding: 'UTF-8') end SimulationParameter.new(hash) end |
.sizing_parameter_from_model(openstudio_model) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/from_openstudio/simulation/parameter_model.rb', line 75 def self.sizing_parameter_from_model(openstudio_model) hash = {} hash[:type] = 'SizingParameter' hash[:design_days] = [] openstudio_model.getDesignDays.each do |design_day| begin hash[:design_days] << DesignDay.from_design_day(design_day) rescue end end sizing_parameters = openstudio_model.getSizingParameters hash[:heating_factor] = sizing_parameters.heatingSizingFactor hash[:cooling_factor] = sizing_parameters.coolingSizingFactor hash end |
.translate_from_gbxml_file(file) ⇒ Object
Create Ladybug Energy Model JSON from gbXML file
60 61 62 63 64 65 |
# File 'lib/from_openstudio/simulation/parameter_model.rb', line 60 def self.translate_from_gbxml_file(file) translator = OpenStudio::GbXML::GbXMLReverseTranslator.new openstudio_model = translator.loadModel(file) raise "Cannot load gbXML file at '#{}'" if openstudio_model.empty? self.translate_from_openstudio(openstudio_model.get) end |
.translate_from_idf_file(file) ⇒ Object
Create Ladybug Energy Model JSON from IDF file
68 69 70 71 72 73 |
# File 'lib/from_openstudio/simulation/parameter_model.rb', line 68 def self.translate_from_idf_file(file) translator = OpenStudio::EnergyPlus::ReverseTranslator.new openstudio_model = translator.loadModel(file) raise "Cannot load IDF file at '#{}'" if openstudio_model.empty? self.translate_from_openstudio(openstudio_model.get) end |
.translate_from_openstudio(openstudio_model) ⇒ Object
Create Ladybug SimulationParameter JSON from OpenStudio Model
41 42 43 44 45 46 47 48 49 |
# File 'lib/from_openstudio/simulation/parameter_model.rb', line 41 def self.translate_from_openstudio(openstudio_model) hash = {} hash[:type] = 'SimulationParameter' hash[:output] = SimulationOutput.from_model(openstudio_model) hash[:sizing_parameter] = sizing_parameter_from_model(openstudio_model) SimulationParameter.new(hash) end |
.translate_from_osm_file(file) ⇒ Object
Create Ladybug Energy Model JSON from OSM file
52 53 54 55 56 57 |
# File 'lib/from_openstudio/simulation/parameter_model.rb', line 52 def self.translate_from_osm_file(file) vt = OpenStudio::OSVersion::VersionTranslator.new openstudio_model = vt.loadModel(file) raise "Cannot load OSM file at '#{}'" if openstudio_model.empty? self.translate_from_openstudio(openstudio_model.get) end |
Instance Method Details
#create_openstudio_objects ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/to_openstudio/simulation/parameter_model.rb', line 73 def create_openstudio_objects # get the defaults for each sub-object simct_defaults = defaults[:SimulationControl][:properties] shdw_defaults = defaults[:ShadowCalculation][:properties] siz_defaults = defaults[:SizingParameter][:properties] out_defaults = defaults[:SimulationOutput][:properties] runper_defaults = defaults[:RunPeriod][:properties] simpar_defaults = defaults[:SimulationParameter][:properties] # set defaults for the Model's SimulationControl object os_sim_control = @openstudio_model.getSimulationControl os_sim_control.setDoZoneSizingCalculation(simct_defaults[:do_zone_sizing][:default]) os_sim_control.setDoSystemSizingCalculation(simct_defaults[:do_system_sizing][:default]) os_sim_control.setDoPlantSizingCalculation(simct_defaults[:do_plant_sizing][:default]) os_sim_control.setRunSimulationforWeatherFileRunPeriods(simct_defaults[:run_for_run_periods][:default]) os_sim_control.setRunSimulationforSizingPeriods(simct_defaults[:run_for_sizing_periods][:default]) os_sim_control.setSolarDistribution(shdw_defaults[:solar_distribution][:default]) # override any SimulationControl defaults with lodaded JSON if @hash[:simulation_control] unless @hash[:simulation_control][:do_zone_sizing].nil? os_sim_control.setDoZoneSizingCalculation(@hash[:simulation_control][:do_zone_sizing]) end unless @hash[:simulation_control][:do_system_sizing].nil? os_sim_control.setDoSystemSizingCalculation(@hash[:simulation_control][:do_system_sizing]) end unless @hash[:simulation_control][:do_plant_sizing].nil? os_sim_control.setDoPlantSizingCalculation(@hash[:simulation_control][:do_plant_sizing]) end unless @hash[:simulation_control][:run_for_run_periods].nil? os_sim_control.setRunSimulationforWeatherFileRunPeriods(@hash[:simulation_control][:run_for_run_periods]) end unless @hash[:simulation_control][:run_for_sizing_periods].nil? os_sim_control.setRunSimulationforSizingPeriods(@hash[:simulation_control][:run_for_sizing_periods]) end end # set defaults for the Model's ShadowCalculation object os_shadow_calc = @openstudio_model.getShadowCalculation os_shadow_calc.setShadingCalculationMethod( shdw_defaults[:calculation_method][:default]) os_shadow_calc.setShadingCalculationUpdateFrequencyMethod( shdw_defaults[:calculation_update_method][:default]) os_shadow_calc.setShadingCalculationUpdateFrequency( shdw_defaults[:calculation_frequency][:default]) os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations( shdw_defaults[:maximum_figures][:default]) # override any ShadowCalculation defaults with lodaded JSON if @hash[:shadow_calculation] if @hash[:shadow_calculation][:calculation_method] os_shadow_calc.setShadingCalculationMethod( @hash[:shadow_calculation][:calculation_method]) end if @hash[:shadow_calculation][:calculation_update_method] os_shadow_calc.setShadingCalculationUpdateFrequencyMethod( @hash[:shadow_calculation][:calculation_update_method]) end if @hash[:shadow_calculation][:calculation_frequency] os_shadow_calc.setShadingCalculationUpdateFrequency( @hash[:shadow_calculation][:calculation_frequency]) end if @hash[:shadow_calculation][:maximum_figures] os_shadow_calc.setMaximumFiguresInShadowOverlapCalculations( @hash[:shadow_calculation][:maximum_figures]) end if @hash[:shadow_calculation][:solar_distribution] os_sim_control.setSolarDistribution( @hash[:shadow_calculation][:solar_distribution]) end end # set defaults for the Model's SizingParameter object os_sizing_par = @openstudio_model.getSizingParameters os_sizing_par.setHeatingSizingFactor(siz_defaults[:heating_factor][:default]) os_sizing_par.setCoolingSizingFactor(siz_defaults[:cooling_factor][:default]) # override any SizingParameter defaults with lodaded JSON db_temps = [] if @hash[:sizing_parameter] if @hash[:sizing_parameter][:heating_factor] os_sizing_par.setHeatingSizingFactor(@hash[:sizing_parameter][:heating_factor]) end if @hash[:sizing_parameter][:cooling_factor] os_sizing_par.setCoolingSizingFactor(@hash[:sizing_parameter][:cooling_factor]) end # set any design days if @hash[:sizing_parameter][:design_days] if @hash[:simulation_control][:do_zone_sizing].nil? || @hash[:simulation_control][:do_zone_sizing] == true @hash[:sizing_parameter][:design_days].each do |des_day| des_day_object = DesignDay.new(des_day) os_des_day = des_day_object.to_openstudio(@openstudio_model) db_temps << des_day[:dry_bulb_condition][:dry_bulb_max] end end end end # use the average of design day temperatures to set the water mains temperature os_water_mains = @openstudio_model.getSiteWaterMainsTemperature os_version_water_fix = OpenStudio::VersionString.new(3, 4) if @openstudio_model.version() >= os_version_water_fix os_water_mains.setCalculationMethod('CorrelationFromWeatherFile') else os_water_mains.setCalculationMethod('Correlation') if db_temps.length > 0 os_water_mains.setAnnualAverageOutdoorAirTemperature((db_temps.max + db_temps.min) / 2) else # just use some dummy values so that the simulation does not fail os_water_mains.setAnnualAverageOutdoorAirTemperature(12) end os_water_mains.setMaximumDifferenceInMonthlyAverageOutdoorAirTemperatures(4) end # set the climate zone from design days assuming 0.4% extremes and normal distribution climate_zone_objs = @openstudio_model.getClimateZones ashrae_zones = climate_zone_objs.getClimateZones('ASHRAE') if ashrae_zones.empty? && db_temps.length > 0 # generate temperatures according to a normal distribution mean_temp = (db_temps.max + db_temps.min) / 2 dist_to_mean = db_temps.max - mean_temp st_dev = dist_to_mean / 2.65 vals = [] for i in 0..4379 step_seed = i.to_f / 4380 add_val1, add_val2 = gaussian(mean_temp, st_dev, step_seed) vals << add_val1 vals << add_val2 end # compute the number of heating and cooling degree days cooling_deg_days, heating_deg_days = 0, 0 vals.each do |temp| if temp > 10 cdd = (temp - 10) / 24 cooling_deg_days += cdd end if temp < 18 hdd = (18 - temp) / 24 heating_deg_days += hdd end end # determine the climate zone from the degree-day distribution if cooling_deg_days > 5000 cz = '1' elsif cooling_deg_days > 3500 cz = '2A' elsif cooling_deg_days > 2500 cz = '3A' elsif cooling_deg_days <= 2500 and heating_deg_days <= 2000 cz = '3C' elsif cooling_deg_days <= 2500 and heating_deg_days <= 3000 cz = '4A' elsif heating_deg_days <= 3000 cz = '4C' elsif heating_deg_days <= 4000 cz = '5A' elsif heating_deg_days <= 5000 cz = '6A' elsif heating_deg_days <= 7000 cz = '7' else cz = '8' end # set the climate zone climate_zone_objs.setClimateZone('ASHRAE', cz) end # note any efficency standards that have been assigned to the if @hash[:sizing_parameter] if @hash[:sizing_parameter][:efficiency_standard] && @hash[:sizing_parameter][:efficiency_standard] != 0 std_gem_standard = @@standard_mapper[@hash[:sizing_parameter][:efficiency_standard].to_sym] building = @openstudio_model.getBuilding building.setStandardsTemplate(std_gem_standard) end if @hash[:sizing_parameter][:climate_zone] && @hash[:sizing_parameter][:climate_zone] != 0 climate_zone_objs.setClimateZone('ASHRAE', @hash[:sizing_parameter][:climate_zone]) end if @hash[:sizing_parameter][:building_type] && @hash[:sizing_parameter][:building_type] != 0 building = @openstudio_model.getBuilding building.setStandardsBuildingType(@hash[:sizing_parameter][:building_type]) end unless @hash[:sizing_parameter][:bypass_efficiency_sizing].nil? $bypass_eff_sizing = @hash[:sizing_parameter][:bypass_efficiency_sizing] end end # set defaults for the simulation output os_unmet_tol = @openstudio_model.getOutputControlReportingTolerances default_unmet_tol = out_defaults[:unmet_setpoint_tolerance][:default] os_unmet_tol.setToleranceforTimeHeatingSetpointNotMet(default_unmet_tol) os_unmet_tol.setToleranceforTimeCoolingSetpointNotMet(default_unmet_tol) # set Outputs for the simulation if @hash[:output] if @hash[:output][:outputs] @hash[:output][:outputs].each do |output| os_output = OpenStudio::Model::OutputVariable.new(output, @openstudio_model) if @hash[:output][:reporting_frequency] os_output.setReportingFrequency(@hash[:output][:reporting_frequency]) else os_output.setReportingFrequency(out_defaults[:reporting_frequency][:default]) end end end if @hash[:output][:summary_reports] os_report = @openstudio_model.getOutputTableSummaryReports @hash[:output][:summary_reports].each do |report| os_report.addSummaryReport(report) end end if @hash[:output][:unmet_setpoint_tolerance] unmet_tol = @hash[:output][:unmet_setpoint_tolerance] os_unmet_tol.setToleranceforTimeHeatingSetpointNotMet(unmet_tol) os_unmet_tol.setToleranceforTimeCoolingSetpointNotMet(unmet_tol) end end # set defaults for the year description year_description = @openstudio_model.getYearDescription year_description.setDayofWeekforStartDay(runper_defaults[:start_day_of_week][:default]) # set up the simulation RunPeriod if @hash[:run_period] # set the leap year if @hash[:run_period][:leap_year] year_description.setIsLeapYear(@hash[:run_period][:leap_year]) end # set the start day of the week if @hash[:run_period][:start_day_of_week] year_description.setDayofWeekforStartDay(@hash[:run_period][:start_day_of_week]) end # set the run preiod start and end dates openstudio_runperiod = @openstudio_model.getRunPeriod openstudio_runperiod.setBeginMonth(@hash[:run_period][:start_date][0]) openstudio_runperiod.setBeginDayOfMonth(@hash[:run_period][:start_date][1]) openstudio_runperiod.setEndMonth(@hash[:run_period][:end_date][0]) openstudio_runperiod.setEndDayOfMonth(@hash[:run_period][:end_date][1]) # set the daylight savings time if @hash[:run_period][:daylight_saving_time] os_dl_saving = @openstudio_model.getRunPeriodControlDaylightSavingTime os_dl_saving.setStartDate( OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:start_date][0]), @hash[:run_period][:daylight_saving_time][:start_date][1]) os_dl_saving.setEndDate( OpenStudio::MonthOfYear.new(@hash[:run_period][:daylight_saving_time][:end_date][0]), @hash[:run_period][:daylight_saving_time][:end_date][1]) end # Set the holidays if @hash[:run_period][:holidays] @hash[:run_period][:holidays].each do |hol| os_hol = OpenStudio::Model::RunPeriodControlSpecialDays.new( OpenStudio::MonthOfYear.new(hol[0]), hol[1], @openstudio_model) os_hol.setDuration(1) os_hol.setSpecialDayType('Holiday') end end end # set the simulation timestep os_timestep = @openstudio_model.getTimestep if @hash[:timestep] os_timestep.setNumberOfTimestepsPerHour(@hash[:timestep]) else os_timestep.setNumberOfTimestepsPerHour(simpar_defaults[:timestep][:default]) end # assign the north if @hash[:north_angle] @openstudio_model.getBuilding.setNorthAxis(@hash[:north_angle]) end # assign the terrain os_site = @openstudio_model.getSite os_site.setTerrain(simpar_defaults[:terrain_type][:default]) if @hash[:terrain_type] os_site.setTerrain(@hash[:terrain_type]) end end |
#defaults ⇒ Object
65 66 67 |
# File 'lib/honeybee/simulation/parameter_model.rb', line 65 def defaults @@schema[:components][:schemas] end |
#gaussian(mean, stddev, seed) ⇒ Object
359 360 361 362 363 364 365 366 367 |
# File 'lib/to_openstudio/simulation/parameter_model.rb', line 359 def gaussian(mean, stddev, seed) # generate a gaussian distribution of values theta = 2 * Math::PI * seed rho = Math.sqrt(-2 * Math.log(1 - seed)) scale = stddev * rho x = mean + scale * Math.cos(theta) y = mean + scale * Math.sin(theta) return x, y end |
#to_openstudio_model(openstudio_model = nil, log_report = false) ⇒ Object
convert to openstudio model, clears errors and warnings
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/to_openstudio/simulation/parameter_model.rb', line 50 def to_openstudio_model(openstudio_model=nil, log_report=false) @errors = [] @warnings = [] $bypass_eff_sizing = false # default value to bypass efficiency standard if log_report puts 'Starting SimulationParameter translation from Honeybee to OpenStudio' end @openstudio_model = if openstudio_model openstudio_model else OpenStudio::Model::Model.new end create_openstudio_objects if log_report puts 'Done with SimulationParameter translation!' end @openstudio_model end |