Module: OpenStudio::Workflow::Util::EnergyPlus
- Includes:
- IO
- Included in:
- RunEnergyPlus, RunPreprocess
- Defined in:
- lib/openstudio/workflow/util/energyplus.rb
Overview
The methods needed to run simulations using EnergyPlus are stored here. See the run_simulation class for
implementation details.
Constant Summary collapse
- ENERGYPLUS_REGEX =
/^energyplus\D{0,4}$/i.freeze
- EXPAND_OBJECTS_REGEX =
/^expandobjects\D{0,4}$/i.freeze
Class Method Summary collapse
-
.add_energyplus_output_request(workspace, idf_object) ⇒ Object
examines object and determines whether or not to add it to the workspace.
-
.check_for_object(workspace, idf_object, idd_object_type) ⇒ Object
check to see if we have an exact match for this object already.
-
.merge_output_table_summary_reports(current_object, new_object) ⇒ Object
merge all summary reports that are not in the current workspace.
- .monthly_report_idf_text ⇒ Object
Instance Method Summary collapse
-
#call_energyplus(run_directory, energyplus_path = nil, output_adapter = nil, logger = nil, workflow_json = nil) ⇒ Void
Configures and executes the EnergyPlus simulation and checks to see if the simulation was successful.
-
#clean_directory(run_directory, energyplus_files, logger) ⇒ Void
Does something.
-
#energyplus_preprocess(idf, logger) ⇒ Void
Run this code before running EnergyPlus to make sure the reporting variables are setup correctly.
-
#find_energyplus ⇒ String
Find the installation directory of EnergyPlus linked to the OpenStudio version being used.
-
#prepare_energyplus_dir(run_directory, logger, energyplus_path = nil) ⇒ Array, file
Prepare the directory to run EnergyPlus.
Methods included from IO
Class Method Details
.add_energyplus_output_request(workspace, idf_object) ⇒ Object
examines object and determines whether or not to add it to the workspace
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 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 261 def self.add_energyplus_output_request(workspace, idf_object) num_added = 0 idd_object = idf_object.iddObject allowed_objects = [] allowed_objects << 'Output:Surfaces:List' allowed_objects << 'Output:Surfaces:Drawing' allowed_objects << 'Output:Schedules' allowed_objects << 'Output:Constructions' allowed_objects << 'Output:Table:TimeBins' allowed_objects << 'Output:Table:Monthly' allowed_objects << 'Output:Variable' allowed_objects << 'Output:Meter' allowed_objects << 'Output:Meter:MeterFileOnly' allowed_objects << 'Output:Meter:Cumulative' allowed_objects << 'Output:Meter:Cumulative:MeterFileOnly' allowed_objects << 'Meter:Custom' allowed_objects << 'Meter:CustomDecrement' allowed_objects << 'EnergyManagementSystem:OutputVariable' if allowed_objects.include?(idd_object.name) && !check_for_object(workspace, idf_object, idd_object.type) workspace.addObject(idf_object) num_added += 1 end allowed_unique_objects = [] # allowed_unique_objects << "Output:EnergyManagementSystem" # TODO: have to merge # allowed_unique_objects << "OutputControl:SurfaceColorScheme" # TODO: have to merge allowed_unique_objects << 'Output:Table:SummaryReports' # TODO: have to merge # OutputControl:Table:Style # not allowed # OutputControl:ReportingTolerances # not allowed # Output:SQLite # not allowed if allowed_unique_objects.include?(idf_object.iddObject.name) && (idf_object.iddObject.name == 'Output:Table:SummaryReports') summary_reports = workspace.getObjectsByType(idf_object.iddObject.type) if summary_reports.empty? workspace.addObject(idf_object) num_added += 1 else merge_output_table_summary_reports(summary_reports[0], idf_object) end end return num_added end |
.check_for_object(workspace, idf_object, idd_object_type) ⇒ Object
check to see if we have an exact match for this object already
308 309 310 311 312 313 314 315 316 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 308 def self.check_for_object(workspace, idf_object, idd_object_type) workspace.getObjectsByType(idd_object_type).each do |object| # all of these objects fields are data fields if idf_object.dataFieldsEqual(object) return true end end return false end |
.merge_output_table_summary_reports(current_object, new_object) ⇒ Object
merge all summary reports that are not in the current workspace
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 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 319 def self.merge_output_table_summary_reports(current_object, new_object) current_fields = [] current_object.extensibleGroups.each do |current_extensible_group| current_fields << current_extensible_group.getString(0).to_s end fields_to_add = [] new_object.extensibleGroups.each do |new_extensible_group| field = new_extensible_group.getString(0).to_s unless current_fields.include?(field) current_fields << field fields_to_add << field end end unless fields_to_add.empty? fields_to_add.each do |field| values = OpenStudio::StringVector.new values << field current_object.pushExtensibleGroup(values) end return true end return false end |
.monthly_report_idf_text ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 346 def self.monthly_report_idf_text " Output:Table:Monthly,\n Building Energy Performance - Electricity, !- Name\n 2, !- Digits After Decimal\n InteriorLights:Electricity, !- Variable or Meter 1 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 1\n ExteriorLights:Electricity, !- Variable or Meter 2 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 2\n InteriorEquipment:Electricity, !- Variable or Meter 3 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 3\n ExteriorEquipment:Electricity, !- Variable or Meter 4 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 4\n Fans:Electricity, !- Variable or Meter 5 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 5\n Pumps:Electricity, !- Variable or Meter 6 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 6\n Heating:Electricity, !- Variable or Meter 7 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 7\n Cooling:Electricity, !- Variable or Meter 8 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 8\n HeatRejection:Electricity, !- Variable or Meter 9 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 9\n Humidifier:Electricity, !- Variable or Meter 10 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 10\n HeatRecovery:Electricity,!- Variable or Meter 11 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 11\n WaterSystems:Electricity,!- Variable or Meter 12 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 12\n Cogeneration:Electricity,!- Variable or Meter 13 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 13\n Refrigeration:Electricity,!- Variable or Meter 14 Name\n SumOrAverage; !- Aggregation Type for Variable or Meter 14\n\n Output:Table:Monthly,\n Building Energy Performance - Natural Gas, !- Name\n 2, !- Digits After Decimal\n InteriorEquipment:NaturalGas, !- Variable or Meter 1 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 1\n ExteriorEquipment:NaturalGas, !- Variable or Meter 2 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 2\n Heating:NaturalGas, !- Variable or Meter 3 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 3\n Cooling:NaturalGas, !- Variable or Meter 4 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 4\n WaterSystems:NaturalGas, !- Variable or Meter 5 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 5\n Cogeneration:NaturalGas, !- Variable or Meter 6 Name\n SumOrAverage; !- Aggregation Type for Variable or Meter 6\n\n Output:Table:Monthly,\n Building Energy Performance - District Heating, !- Name\n 2, !- Digits After Decimal\n InteriorLights:DistrictHeating, !- Variable or Meter 1 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 1\n ExteriorLights:DistrictHeating, !- Variable or Meter 2 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 2\n InteriorEquipment:DistrictHeating, !- Variable or Meter 3 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 3\n ExteriorEquipment:DistrictHeating, !- Variable or Meter 4 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 4\n Fans:DistrictHeating, !- Variable or Meter 5 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 5\n Pumps:DistrictHeating, !- Variable or Meter 6 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 6\n Heating:DistrictHeating, !- Variable or Meter 7 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 7\n Cooling:DistrictHeating, !- Variable or Meter 8 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 8\n HeatRejection:DistrictHeating, !- Variable or Meter 9 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 9\n Humidifier:DistrictHeating, !- Variable or Meter 10 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 10\n HeatRecovery:DistrictHeating,!- Variable or Meter 11 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 11\n WaterSystems:DistrictHeating,!- Variable or Meter 12 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 12\n Cogeneration:DistrictHeating,!- Variable or Meter 13 Name\n SumOrAverage; !- Aggregation Type for Variable or Meter 13\n\n Output:Table:Monthly,\n Building Energy Performance - District Cooling, !- Name\n 2, !- Digits After Decimal\n InteriorLights:DistrictCooling, !- Variable or Meter 1 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 1\n ExteriorLights:DistrictCooling, !- Variable or Meter 2 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 2\n InteriorEquipment:DistrictCooling, !- Variable or Meter 3 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 3\n ExteriorEquipment:DistrictCooling, !- Variable or Meter 4 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 4\n Fans:DistrictCooling, !- Variable or Meter 5 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 5\n Pumps:DistrictCooling, !- Variable or Meter 6 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 6\n Heating:DistrictCooling, !- Variable or Meter 7 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 7\n Cooling:DistrictCooling, !- Variable or Meter 8 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 8\n HeatRejection:DistrictCooling, !- Variable or Meter 9 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 9\n Humidifier:DistrictCooling, !- Variable or Meter 10 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 10\n HeatRecovery:DistrictCooling,!- Variable or Meter 11 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 11\n WaterSystems:DistrictCooling,!- Variable or Meter 12 Name\n SumOrAverage, !- Aggregation Type for Variable or Meter 12\n Cogeneration:DistrictCooling,!- Variable or Meter 13 Name\n SumOrAverage; !- Aggregation Type for Variable or Meter 13\n\n Output:Table:Monthly,\n Building Energy Performance - Electricity Peak Demand, !- Name\n 2, !- Digits After Decimal\n Electricity:Facility, !- Variable or Meter 1 Name\n Maximum, !- Aggregation Type for Variable or Meter 1\n InteriorLights:Electricity, !- Variable or Meter 1 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 1\n ExteriorLights:Electricity, !- Variable or Meter 2 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 2\n InteriorEquipment:Electricity, !- Variable or Meter 3 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 3\n ExteriorEquipment:Electricity, !- Variable or Meter 4 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 4\n Fans:Electricity, !- Variable or Meter 5 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 5\n Pumps:Electricity, !- Variable or Meter 6 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 6\n Heating:Electricity, !- Variable or Meter 7 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 7\n Cooling:Electricity, !- Variable or Meter 8 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 8\n HeatRejection:Electricity, !- Variable or Meter 9 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 9\n Humidifier:Electricity, !- Variable or Meter 10 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 10\n HeatRecovery:Electricity,!- Variable or Meter 11 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 11\n WaterSystems:Electricity,!- Variable or Meter 12 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 12\n Cogeneration:Electricity,!- Variable or Meter 13 Name\n ValueWhenMaximumOrMinimum; !- Aggregation Type for Variable or Meter 13\n\n Output:Table:Monthly,\n Building Energy Performance - Natural Gas Peak Demand, !- Name\n 2, !- Digits After Decimal\n NaturalGas:Facility, !- Variable or Meter 1 Name\n Maximum, !- Aggregation Type for Variable or Meter 1\n InteriorEquipment:NaturalGas, !- Variable or Meter 1 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 1\n ExteriorEquipment:NaturalGas, !- Variable or Meter 2 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 2\n Heating:NaturalGas, !- Variable or Meter 3 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 3\n Cooling:NaturalGas, !- Variable or Meter 4 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 4\n WaterSystems:NaturalGas, !- Variable or Meter 5 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 5\n Cogeneration:NaturalGas, !- Variable or Meter 6 Name\n ValueWhenMaximumOrMinimum; !- Aggregation Type for Variable or Meter 6\n\n Output:Table:Monthly,\n Building Energy Performance - District Heating Peak Demand, !- Name\n 2, !- Digits After Decimal\n DistrictHeating:Facility, !- Variable or Meter 1 Name\n Maximum, !- Aggregation Type for Variable or Meter 1\n InteriorLights:DistrictHeating, !- Variable or Meter 1 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 1\n ExteriorLights:DistrictHeating, !- Variable or Meter 2 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 2\n InteriorEquipment:DistrictHeating, !- Variable or Meter 3 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 3\n ExteriorEquipment:DistrictHeating, !- Variable or Meter 4 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 4\n Fans:DistrictHeating, !- Variable or Meter 5 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 5\n Pumps:DistrictHeating, !- Variable or Meter 6 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 6\n Heating:DistrictHeating, !- Variable or Meter 7 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 7\n Cooling:DistrictHeating, !- Variable or Meter 8 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 8\n HeatRejection:DistrictHeating, !- Variable or Meter 9 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 9\n Humidifier:DistrictHeating, !- Variable or Meter 10 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 10\n HeatRecovery:DistrictHeating,!- Variable or Meter 11 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 11\n WaterSystems:DistrictHeating,!- Variable or Meter 12 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 12\n Cogeneration:DistrictHeating,!- Variable or Meter 13 Name\n ValueWhenMaximumOrMinimum; !- Aggregation Type for Variable or Meter 13\n\n Output:Table:Monthly,\n Building Energy Performance - District Cooling Peak Demand, !- Name\n 2, !- Digits After Decimal\n DistrictCooling:Facility, !- Variable or Meter 1 Name\n Maximum, !- Aggregation Type for Variable or Meter 1\n InteriorLights:DistrictCooling, !- Variable or Meter 1 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 1\n ExteriorLights:DistrictCooling, !- Variable or Meter 2 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 2\n InteriorEquipment:DistrictCooling, !- Variable or Meter 3 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 3\n ExteriorEquipment:DistrictCooling, !- Variable or Meter 4 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 4\n Fans:DistrictCooling, !- Variable or Meter 5 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 5\n Pumps:DistrictCooling, !- Variable or Meter 6 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 6\n Heating:DistrictCooling, !- Variable or Meter 7 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 7\n Cooling:DistrictCooling, !- Variable or Meter 8 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 8\n HeatRejection:DistrictCooling, !- Variable or Meter 9 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 9\n Humidifier:DistrictCooling, !- Variable or Meter 10 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 10\n HeatRecovery:DistrictCooling,!- Variable or Meter 11 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 11\n WaterSystems:DistrictCooling,!- Variable or Meter 12 Name\n ValueWhenMaximumOrMinimum, !- Aggregation Type for Variable or Meter 12\n Cogeneration:DistrictCooling,!- Variable or Meter 13 Name\n ValueWhenMaximumOrMinimum; !- Aggregation Type for Variable or Meter 13\n HEREDOC\nend\n" |
Instance Method Details
#call_energyplus(run_directory, energyplus_path = nil, output_adapter = nil, logger = nil, workflow_json = nil) ⇒ Void
Configures and executes the EnergyPlus simulation and checks to see if the simulation was successful
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 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 127 def call_energyplus(run_directory, energyplus_path = nil, output_adapter = nil, logger = nil, workflow_json = nil) logger ||= ::Logger.new($stdout) unless logger current_dir = Dir.pwd energyplus_path ||= find_energyplus logger.info "EnergyPlus path is #{energyplus_path}" energyplus_files, energyplus_exe, = prepare_energyplus_dir(run_directory, logger, energyplus_path) Dir.chdir(run_directory) logger.info "Starting simulation in run directory: #{Dir.pwd}" if ![:skip_expand_objects] command = popen_command("\"#{expand_objects_exe}\"") logger.info "Running command '#{command}'" File.open('stdout-expandobject', 'w') do |file| ::IO.popen(command) do |io| while (line = io.gets) file << line end end end # Check if expand objects did anything if File.exist? 'expanded.idf' FileUtils.mv('in.idf', 'pre-expand.idf', force: true) if File.exist?('in.idf') FileUtils.mv('expanded.idf', 'in.idf', force: true) end end # create stdout command = popen_command("\"#{energyplus_exe}\" 2>&1") logger.info "Running command '#{command}'" File.open('stdout-energyplus', 'w') do |file| ::IO.popen(command) do |io| while (line = io.gets) file << line output_adapter&.communicate_energyplus_stdout(line) end end end r = $? logger.info "EnergyPlus returned '#{r}'" unless r.to_i.zero? logger.warn 'EnergyPlus returned a non-zero exit code. Check the stdout-energyplus log.' end if File.exist? 'eplusout.err' eplus_err = File.read('eplusout.err').force_encoding('ISO-8859-1').encode('utf-8', replace: nil) if workflow_json begin if ![:fast] workflow_json.setEplusoutErr(eplus_err) end rescue StandardError => e # older versions of OpenStudio did not have the setEplusoutErr method end end if eplus_err =~ /EnergyPlus Terminated--Fatal Error Detected/ raise 'EnergyPlus Terminated with a Fatal Error. Check eplusout.err log.' end end if File.exist? 'eplusout.end' f = File.read('eplusout.end').force_encoding('ISO-8859-1').encode('utf-8', replace: nil) warnings_count = f[/(\d*).Warning/, 1] error_count = f[/(\d*).Severe.Errors/, 1] logger.info "EnergyPlus finished with #{warnings_count} warnings and #{error_count} severe errors" if f =~ /EnergyPlus Terminated--Fatal Error Detected/ raise 'EnergyPlus Terminated with a Fatal Error. Check eplusout.err log.' end else raise 'EnergyPlus failed and did not create an eplusout.end file. Check the stdout-energyplus log.' end rescue StandardError => e = "#{__FILE__} failed with #{e.message}, #{e.backtrace.join("\n")}" logger.error raise ensure logger.info "Ensuring 'clean' directory" clean_directory(run_directory, energyplus_files, logger) Dir.chdir(current_dir) logger.info 'EnergyPlus Completed' end |
#clean_directory(run_directory, energyplus_files, logger) ⇒ Void
Does something
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 66 def clean_directory(run_directory, energyplus_files, logger) logger.info 'Removing any copied EnergyPlus files' energyplus_files.each do |file| if File.exist? file FileUtils.rm_f file end end paths_to_rm = [] paths_to_rm << "#{run_directory}/packaged_measures" paths_to_rm << "#{run_directory}/Energy+.ini" paths_to_rm.each { |p| FileUtils.rm_rf(p) if File.exist?(p) } end |
#energyplus_preprocess(idf, logger) ⇒ Void
Run this code before running EnergyPlus to make sure the reporting variables are setup correctly
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 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 219 def energyplus_preprocess(idf, logger) logger.info 'Running EnergyPlus Preprocess' new_objects = [] needs_sqlobj = idf.getObjectsByType('Output:SQLite'.to_IddObjectType).empty? if needs_sqlobj # just add this, we don't allow this type in add_energyplus_output_request logger.info 'Adding SQL Output to IDF' object = OpenStudio::IdfObject.load('Output:SQLite,SimpleAndTabular;').get idf.addObject(object) end # merge in monthly reports EnergyPlus.monthly_report_idf_text.split(/^\s*$/).each do |object| object = object.strip next if object.empty? new_objects << object end # These are needed for the calibration report new_objects << 'Output:Meter:MeterFileOnly,NaturalGas:Facility,Daily;' new_objects << 'Output:Meter:MeterFileOnly,Electricity:Facility,Timestep;' new_objects << 'Output:Meter:MeterFileOnly,Electricity:Facility,Daily;' # Always add in the timestep facility meters new_objects << 'Output:Meter,Electricity:Facility,Timestep;' new_objects << 'Output:Meter,NaturalGas:Facility,Timestep;' new_objects << 'Output:Meter,DistrictCooling:Facility,Timestep;' new_objects << 'Output:Meter,DistrictHeating:Facility,Timestep;' new_objects.each do |obj| object = OpenStudio::IdfObject.load(obj).get OpenStudio::Workflow::Util::EnergyPlus.add_energyplus_output_request(idf, object) end logger.info 'Finished EnergyPlus Preprocess' end |
#find_energyplus ⇒ String
Find the installation directory of EnergyPlus linked to the OpenStudio version being used
53 54 55 56 57 58 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 53 def find_energyplus path = OpenStudio.getEnergyPlusDirectory.to_s raise 'Unable to find the EnergyPlus executable' unless File.exist? path path end |
#prepare_energyplus_dir(run_directory, logger, energyplus_path = nil) ⇒ Array, file
Prepare the directory to run EnergyPlus
ExpandObjects EXE file, and EnergyPlus EXE file
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 |
# File 'lib/openstudio/workflow/util/energyplus.rb', line 88 def prepare_energyplus_dir(run_directory, logger, energyplus_path = nil) logger.info "Copying EnergyPlus files to run directory: #{run_directory}" energyplus_path ||= find_energyplus logger.info "EnergyPlus path is #{energyplus_path}" energyplus_files = [] energyplus_exe, = nil Dir["#{energyplus_path}/*"].each do |file| next if File.directory? file # copy idd and ini files if File.extname(file).downcase =~ /.idd|.ini/ dest_file = "#{run_directory}/#{File.basename(file)}" energyplus_files << dest_file FileUtils.copy file, dest_file end energyplus_exe = file if File.basename(file) =~ ENERGYPLUS_REGEX = file if File.basename(file) =~ EXPAND_OBJECTS_REGEX end raise "Could not find EnergyPlus executable in #{energyplus_path}" unless energyplus_exe raise "Could not find ExpandObjects executable in #{energyplus_path}" unless logger.info "EnergyPlus executable path is #{energyplus_exe}" logger.info "ExpandObjects executable path is #{expand_objects_exe}" return energyplus_files, energyplus_exe, end |