openstudio-calibration 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +5 -0
  4. data/CHANGELOG.md +23 -8
  5. data/Gemfile +0 -3
  6. data/Jenkinsfile +6 -2
  7. data/README.md +2 -2
  8. data/Rakefile +5 -5
  9. data/lib/measures/TimeseriesObjectiveFunction/README.md +5 -171
  10. data/lib/measures/TimeseriesObjectiveFunction/measure.rb +2 -6
  11. data/lib/measures/TimeseriesObjectiveFunction/measure.xml +89 -13
  12. data/lib/measures/TimeseriesObjectiveFunction/resources/report.html.erb +2 -0
  13. data/lib/measures/TimeseriesPlot/README.md +5 -35
  14. data/lib/measures/TimeseriesPlot/measure.xml +27 -11
  15. data/lib/measures/TimeseriesPlot/resources/report.html.erb +2 -0
  16. data/lib/measures/zone_report/README.md +2 -2
  17. data/lib/measures/zone_report/measure.rb +1 -1
  18. data/lib/measures/zone_report/measure.xml +14 -12
  19. data/lib/{openstudio-calibration-measures.rb → openstudio-calibration.rb} +1 -1
  20. data/lib/openstudio/{calibration_measures.rb → calibration.rb} +2 -2
  21. data/lib/openstudio/{calibration_measures → calibration}/extension.rb +1 -1
  22. data/lib/openstudio/{calibration_measures → calibration}/version.rb +2 -2
  23. data/openstudio-calibration.gemspec +38 -0
  24. metadata +37 -54
  25. data/lib/measures/AddMonthlyUtilityData/tests/AddMonthlyUtilityData_Test.rb +0 -88
  26. data/lib/measures/AddMonthlyUtilityData/tests/electric_billed_usages.json +0 -198
  27. data/lib/measures/AddMonthlyUtilityData/tests/gas_billed_usages.json +0 -198
  28. data/lib/measures/CalibrationReports/tests/CalibrationReports_Test.rb +0 -523
  29. data/lib/measures/CalibrationReports/tests/ExampleModel.osm +0 -10497
  30. data/lib/measures/CalibrationReports/tests/ExampleModelNoDemandInput.osm +0 -10560
  31. data/lib/measures/CalibrationReports/tests/ExampleModelNoGasInput.osm +0 -10456
  32. data/lib/measures/CalibrationReports/tests/USA_CO_Golden-NREL.724666_TMY3.epw +0 -8768
  33. data/lib/measures/CalibrationReportsEnhanced/tests/CalibrationReportsEnhanced_Test.rb +0 -734
  34. data/lib/measures/CalibrationReportsEnhanced/tests/ExampleModel.osm +0 -10497
  35. data/lib/measures/CalibrationReportsEnhanced/tests/ExampleModel_FuelOil.osm +0 -12740
  36. data/lib/measures/CalibrationReportsEnhanced/tests/USA_CO_Golden-NREL.724666_TMY3.epw +0 -8768
  37. data/lib/measures/CalibrationReportsEnhanced21/LICENSE.md +0 -27
  38. data/lib/measures/CalibrationReportsEnhanced21/README.md +0 -109
  39. data/lib/measures/CalibrationReportsEnhanced21/README.md.erb +0 -42
  40. data/lib/measures/CalibrationReportsEnhanced21/measure.rb +0 -690
  41. data/lib/measures/CalibrationReportsEnhanced21/measure.xml +0 -269
  42. data/lib/measures/CalibrationReportsEnhanced21/resources/report.html.in +0 -380
  43. data/lib/measures/MaalkaMonthlyJSONUtilityData/LICENSE.md +0 -27
  44. data/lib/measures/MaalkaMonthlyJSONUtilityData/README.md +0 -104
  45. data/lib/measures/MaalkaMonthlyJSONUtilityData/README.md.erb +0 -42
  46. data/lib/measures/MaalkaMonthlyJSONUtilityData/measure.rb +0 -304
  47. data/lib/measures/MaalkaMonthlyJSONUtilityData/measure.xml +0 -216
  48. data/openstudio-calibration-measures.gemspec +0 -30
@@ -1,734 +0,0 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
- # All rights reserved.
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are met:
6
- #
7
- # (1) Redistributions of source code must retain the above copyright notice,
8
- # this list of conditions and the following disclaimer.
9
- #
10
- # (2) Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- #
14
- # (3) Neither the name of the copyright holder nor the names of any contributors
15
- # may be used to endorse or promote products derived from this software without
16
- # specific prior written permission from the respective party.
17
- #
18
- # (4) Other than as required in clauses (1) and (2), distributions in any form
19
- # of modifications or other derivative works may not use the "OpenStudio"
20
- # trademark, "OS", "os", or any other confusingly similar designation without
21
- # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
- #
23
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
24
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
27
- # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
28
- # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30
- # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32
- # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
- # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- # *******************************************************************************
35
-
36
- require 'openstudio'
37
-
38
- require 'openstudio/ruleset/ShowRunnerOutput'
39
-
40
- require "#{File.dirname(__FILE__)}/../measure.rb"
41
-
42
- require 'fileutils'
43
-
44
- require 'minitest/autorun'
45
-
46
- class CalibrationReportsEnhanced_Test < Minitest::Test
47
- def is_openstudio_2?
48
- begin
49
- workflow = OpenStudio::WorkflowJSON.new
50
- rescue StandardError
51
- return false
52
- end
53
- true
54
- end
55
-
56
- def model_in_path_default
57
- "#{File.dirname(__FILE__)}/ExampleModel.osm"
58
- end
59
-
60
- def epw_path_default
61
- # make sure we have a weather data location
62
- epw = nil
63
- epw = OpenStudio::Path.new("#{File.dirname(__FILE__)}/USA_CO_Golden-NREL.724666_TMY3.epw")
64
- assert(File.exist?(epw.to_s))
65
- epw.to_s
66
- end
67
-
68
- def run_dir(test_name)
69
- # always generate test output in specially named 'output' directory so result files are not made part of the measure
70
- "#{File.dirname(__FILE__)}/output/#{test_name}"
71
- end
72
-
73
- def model_out_path(test_name)
74
- "#{run_dir(test_name)}/TestOutput.osm"
75
- end
76
-
77
- def workspace_path(test_name)
78
- if is_openstudio_2?
79
- "#{run_dir(test_name)}/run/in.idf"
80
- else
81
- "#{run_dir(test_name)}/ModelToIdf/in.idf"
82
- end
83
- end
84
-
85
- def sql_path(test_name)
86
- if is_openstudio_2?
87
- "#{run_dir(test_name)}/run/eplusout.sql"
88
- else
89
- "#{run_dir(test_name)}/ModelToIdf/EnergyPlusPreProcess-0/EnergyPlus-0/eplusout.sql"
90
- end
91
- end
92
-
93
- def report_path(test_name)
94
- "#{run_dir(test_name)}/report.html"
95
- end
96
-
97
- # method for running the test simulation using OpenStudio 1.x API
98
- def setup_test_1(test_name, epw_path)
99
- co = OpenStudio::Runmanager::ConfigOptions.new(true)
100
- co.findTools(false, true, false, true)
101
-
102
- unless File.exist?(sql_path(test_name))
103
- puts 'Running EnergyPlus'
104
-
105
- wf = OpenStudio::Runmanager::Workflow.new('modeltoidf->energypluspreprocess->energyplus')
106
- wf.add(co.getTools)
107
- job = wf.create(OpenStudio::Path.new(run_dir(test_name)), OpenStudio::Path.new(model_out_path(test_name)), OpenStudio::Path.new(epw_path))
108
-
109
- rm = OpenStudio::Runmanager::RunManager.new
110
- rm.enqueue(job, true)
111
- rm.waitForFinished
112
- end
113
- end
114
-
115
- # method for running the test simulation using OpenStudio 2.x API
116
- def setup_test_2(test_name, epw_path)
117
- osw_path = File.join(run_dir(test_name), 'in.osw')
118
- osw_path = File.absolute_path(osw_path)
119
-
120
- workflow = OpenStudio::WorkflowJSON.new
121
- workflow.setSeedFile(File.absolute_path(model_out_path(test_name)))
122
- workflow.setWeatherFile(File.absolute_path(epw_path))
123
- workflow.saveAs(osw_path)
124
-
125
- cli_path = OpenStudio.getOpenStudioCLI
126
- cmd = "\"#{cli_path}\" run -w \"#{osw_path}\""
127
- puts cmd
128
- system(cmd)
129
- end
130
-
131
- # create test files if they do not exist when the test first runs
132
- def setup_test(test_name, idf_output_requests, model_in_path = model_in_path_default, epw_path = epw_path_default)
133
- FileUtils.mkdir_p(run_dir(test_name)) unless File.exist?(run_dir(test_name))
134
- assert(File.exist?(run_dir(test_name)))
135
-
136
- FileUtils.rm(report_path(test_name)) if File.exist?(report_path(test_name))
137
-
138
- assert(File.exist?(model_in_path))
139
-
140
- if File.exist?(model_out_path(test_name))
141
- FileUtils.rm(model_out_path(test_name))
142
- end
143
-
144
- # convert output requests to OSM for testing, OS App and PAT will add these to the E+ Idf
145
- workspace = OpenStudio::Workspace.new('Draft'.to_StrictnessLevel, 'EnergyPlus'.to_IddFileType)
146
- workspace.addObjects(idf_output_requests)
147
- rt = OpenStudio::EnergyPlus::ReverseTranslator.new
148
- request_model = rt.translateWorkspace(workspace)
149
-
150
- translator = OpenStudio::OSVersion::VersionTranslator.new
151
- model = translator.loadModel(model_in_path)
152
- assert(!model.empty?)
153
- model = model.get
154
- model.addObjects(request_model.objects)
155
- model.save(model_out_path(test_name), true)
156
-
157
- if is_openstudio_2?
158
- setup_test_2(test_name, epw_path)
159
- else
160
- setup_test_1(test_name, epw_path)
161
- end
162
- end
163
-
164
- # calibration_reports
165
- def test_CalibrationReportsEnhanced
166
- test_name = 'calibration_reports'
167
-
168
- # create an instance of the measure
169
- measure = CalibrationReportsEnhanced.new
170
-
171
- # create an instance of a runner
172
- runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
173
-
174
- # get arguments
175
- arguments = measure.arguments
176
- argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
177
-
178
- # create hash of argument values
179
- args_hash = {}
180
-
181
- # populate argument with specified hash value if specified
182
- arguments.each do |arg|
183
- temp_arg_var = arg.clone
184
- assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name]
185
- argument_map[arg.name] = temp_arg_var
186
- end
187
-
188
- # get the energyplus output requests, this will be done automatically by OS App and PAT
189
- idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map)
190
- assert_equal(0, idf_output_requests.size)
191
-
192
- # mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path.
193
- epw_path = epw_path_default
194
- setup_test(test_name, idf_output_requests)
195
-
196
- assert(File.exist?(model_out_path(test_name)))
197
- assert(File.exist?(sql_path(test_name)))
198
- assert(File.exist?(epw_path))
199
-
200
- # set up runner, this will happen automatically when measure is run in PAT or OpenStudio
201
- runner.setLastOpenStudioModelPath(OpenStudio::Path.new(model_out_path(test_name)))
202
- runner.setLastEnergyPlusWorkspacePath(OpenStudio::Path.new(workspace_path(test_name)))
203
- runner.setLastEpwFilePath(epw_path)
204
- runner.setLastEnergyPlusSqlFilePath(OpenStudio::Path.new(sql_path(test_name)))
205
-
206
- # delete the output if it exists
207
- FileUtils.rm(report_path(test_name)) if File.exist?(report_path(test_name))
208
- assert(!File.exist?(report_path(test_name)))
209
-
210
- # temporarily change directory to the run directory and run the measure
211
- start_dir = Dir.pwd
212
- begin
213
- Dir.chdir(run_dir(test_name))
214
-
215
- # run the measure
216
- measure.run(runner, argument_map)
217
- result = runner.result
218
- show_output(result)
219
- assert_equal('Success', result.value.valueName)
220
- assert(result.warnings.empty?)
221
- ensure
222
- Dir.chdir(start_dir)
223
- end
224
-
225
- model = runner.lastOpenStudioModel
226
- assert(!model.empty?)
227
- model = model.get
228
-
229
- sqlFile = runner.lastEnergyPlusSqlFile
230
- assert(!sqlFile.empty?)
231
- sqlFile = sqlFile.get
232
-
233
- model.setSqlFile(sqlFile)
234
-
235
- # must have a runPeriod
236
- runPeriod = model.runPeriod
237
- assert(!runPeriod.empty?)
238
-
239
- # must have a calendarYear
240
- yearDescription = model.yearDescription
241
- assert(!yearDescription.empty?)
242
- calendarYear = yearDescription.get.calendarYear
243
- assert(!calendarYear.empty?)
244
-
245
- # check for varying demand
246
- model.getUtilityBills.each do |utilityBill|
247
- next if utilityBill.peakDemandUnitConversionFactor.empty?
248
- hasVaryingDemand = false
249
- modelPeakDemand = 0.0
250
- count = 0
251
- utilityBill.billingPeriods.each do |billingPeriod|
252
- peakDemand = billingPeriod.modelPeakDemand
253
- next if peakDemand.empty?
254
- temp = peakDemand.get
255
- if count == 0
256
- modelPeakDemand = temp
257
- else
258
- if modelPeakDemand != temp
259
- hasVaryingDemand = true
260
- break
261
- end
262
- end
263
- count += 1
264
- end
265
- assert(hasVaryingDemand) if count > 1
266
- end
267
-
268
- # make sure the report file exists
269
- assert(File.exist?(report_path(test_name)))
270
- end
271
-
272
- # calibration_reports_no_gas
273
- def test_CalibrationReportsEnhanced_NoGas
274
- test_name = 'calibration_reports_no_gas'
275
-
276
- # load model, remove gas bills, save to new file
277
- raw_model_path = "#{File.dirname(__FILE__)}/ExampleModel.osm"
278
- vt = OpenStudio::OSVersion::VersionTranslator.new
279
- model = vt.loadModel(raw_model_path)
280
- assert(!model.empty?)
281
- model = model.get
282
- utilityBills = model.getUtilityBills
283
- assert_equal(2, utilityBills.size)
284
- utilityBills.each do |utilityBill|
285
- utilityBill.remove if utilityBill.fuelType == 'Gas'.to_FuelType
286
- end
287
- utilityBills = model.getUtilityBills
288
- assert_equal(1, utilityBills.size)
289
- altered_model_path = OpenStudio::Path.new("#{run_dir(test_name)}/ExampleModelNoGasInput.osm")
290
- FileUtils.mkdir_p run_dir(test_name)
291
- model.save(altered_model_path, true)
292
-
293
- # set model_in_path to new altered copy of model
294
- model_in_path = altered_model_path
295
-
296
- # create an instance of the measure
297
- measure = CalibrationReportsEnhanced.new
298
-
299
- # create an instance of a runner
300
- runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
301
-
302
- # get arguments
303
- arguments = measure.arguments
304
- argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
305
-
306
- # create hash of argument values
307
- args_hash = {}
308
-
309
- # populate argument with specified hash value if specified
310
- arguments.each do |arg|
311
- temp_arg_var = arg.clone
312
- assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name]
313
- argument_map[arg.name] = temp_arg_var
314
- end
315
-
316
- # get the energyplus output requests, this will be done automatically by OS App and PAT
317
- idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map)
318
- assert_equal(0, idf_output_requests.size)
319
-
320
- # mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path.
321
- epw_path = epw_path_default
322
- setup_test(test_name, idf_output_requests, model_in_path.to_s)
323
-
324
- assert(File.exist?(model_out_path(test_name)))
325
- assert(File.exist?(sql_path(test_name)))
326
- assert(File.exist?(epw_path))
327
-
328
- # set up runner, this will happen automatically when measure is run in PAT or OpenStudio
329
- runner.setLastOpenStudioModelPath(OpenStudio::Path.new(model_out_path(test_name)))
330
- runner.setLastEnergyPlusWorkspacePath(OpenStudio::Path.new(workspace_path(test_name)))
331
- runner.setLastEpwFilePath(epw_path)
332
- runner.setLastEnergyPlusSqlFilePath(OpenStudio::Path.new(sql_path(test_name)))
333
-
334
- # delete the output if it exists
335
- FileUtils.rm(report_path(test_name)) if File.exist?(report_path(test_name))
336
- assert(!File.exist?(report_path(test_name)))
337
-
338
- # temporarily change directory to the run directory and run the measure
339
- start_dir = Dir.pwd
340
- begin
341
- Dir.chdir(run_dir(test_name))
342
-
343
- # run the measure
344
- measure.run(runner, argument_map)
345
- result = runner.result
346
- show_output(result)
347
- assert_equal('Success', result.value.valueName)
348
- assert(result.warnings.empty?)
349
- ensure
350
- Dir.chdir(start_dir)
351
- end
352
-
353
- model = runner.lastOpenStudioModel
354
- assert(!model.empty?)
355
- model = model.get
356
-
357
- sqlFile = runner.lastEnergyPlusSqlFile
358
- assert(!sqlFile.empty?)
359
- sqlFile = sqlFile.get
360
-
361
- model.setSqlFile(sqlFile)
362
-
363
- # must have a runPeriod
364
- runPeriod = model.runPeriod
365
- assert(!runPeriod.empty?)
366
-
367
- # must have a calendarYear
368
- yearDescription = model.yearDescription
369
- assert(!yearDescription.empty?)
370
- calendarYear = yearDescription.get.calendarYear
371
- assert(!calendarYear.empty?)
372
-
373
- # check for varying demand
374
- model.getUtilityBills.each do |utilityBill|
375
- next if utilityBill.peakDemandUnitConversionFactor.empty?
376
- hasVaryingDemand = false
377
- modelPeakDemand = 0.0
378
- count = 0
379
- utilityBill.billingPeriods.each do |billingPeriod|
380
- peakDemand = billingPeriod.modelPeakDemand
381
- next if peakDemand.empty?
382
- temp = peakDemand.get
383
- if count == 0
384
- modelPeakDemand = temp
385
- else
386
- if modelPeakDemand != temp
387
- hasVaryingDemand = true
388
- break
389
- end
390
- end
391
- count += 1
392
- end
393
- assert(hasVaryingDemand) if count > 1
394
- end
395
-
396
- # make sure the report file exists
397
- assert(File.exist?(report_path(test_name)))
398
- end
399
-
400
- # calibration_reports_no_demand
401
- def test_CalibrationReportsEnhanced_NoDemand
402
- test_name = 'calibration_reports_no_demand'
403
-
404
- # load model, remove gas bills, save to new file
405
- raw_model_path = "#{File.dirname(__FILE__)}/ExampleModel.osm"
406
- vt = OpenStudio::OSVersion::VersionTranslator.new
407
- model = vt.loadModel(raw_model_path)
408
- assert(!model.empty?)
409
- model = model.get
410
- utilityBills = model.getUtilityBills
411
- assert_equal(2, utilityBills.size)
412
- utilityBills.each do |utilityBill|
413
- next unless utilityBill.fuelType == 'Electricity'.to_FuelType
414
- utilityBill.billingPeriods.each(&:resetPeakDemand)
415
- end
416
- utilityBills = model.getUtilityBills
417
- assert_equal(2, utilityBills.size)
418
- altered_model_path = OpenStudio::Path.new("#{run_dir(test_name)}/ExampleModelNoDemandInput.osm")
419
- FileUtils.mkdir_p run_dir(test_name)
420
- model.save(altered_model_path, true)
421
-
422
- # set model_in_path to new altered copy of model
423
- model_in_path = altered_model_path
424
-
425
- # create an instance of the measure
426
- measure = CalibrationReportsEnhanced.new
427
-
428
- # create an instance of a runner
429
- runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
430
-
431
- # get arguments
432
- arguments = measure.arguments
433
- argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
434
-
435
- # create hash of argument values
436
- args_hash = {}
437
-
438
- # populate argument with specified hash value if specified
439
- arguments.each do |arg|
440
- temp_arg_var = arg.clone
441
- assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name]
442
- argument_map[arg.name] = temp_arg_var
443
- end
444
-
445
- # get the energyplus output requests, this will be done automatically by OS App and PAT
446
- idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map)
447
- assert_equal(0, idf_output_requests.size)
448
-
449
- # mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path.
450
- epw_path = epw_path_default
451
- setup_test(test_name, idf_output_requests, model_in_path.to_s)
452
-
453
- assert(File.exist?(model_out_path(test_name)))
454
- assert(File.exist?(sql_path(test_name)))
455
- assert(File.exist?(epw_path))
456
-
457
- # set up runner, this will happen automatically when measure is run in PAT or OpenStudio
458
- runner.setLastOpenStudioModelPath(OpenStudio::Path.new(model_out_path(test_name)))
459
- runner.setLastEnergyPlusWorkspacePath(OpenStudio::Path.new(workspace_path(test_name)))
460
- runner.setLastEpwFilePath(epw_path)
461
- runner.setLastEnergyPlusSqlFilePath(OpenStudio::Path.new(sql_path(test_name)))
462
-
463
- # delete the output if it exists
464
- FileUtils.rm(report_path(test_name)) if File.exist?(report_path(test_name))
465
- assert(!File.exist?(report_path(test_name)))
466
-
467
- # temporarily change directory to the run directory and run the measure
468
- start_dir = Dir.pwd
469
- begin
470
- Dir.chdir(run_dir(test_name))
471
-
472
- # run the measure
473
- measure.run(runner, argument_map)
474
- result = runner.result
475
- show_output(result)
476
- assert_equal('Success', result.value.valueName)
477
- assert(result.warnings.empty?)
478
- ensure
479
- Dir.chdir(start_dir)
480
- end
481
-
482
- model = runner.lastOpenStudioModel
483
- assert(!model.empty?)
484
- model = model.get
485
-
486
- sqlFile = runner.lastEnergyPlusSqlFile
487
- assert(!sqlFile.empty?)
488
- sqlFile = sqlFile.get
489
-
490
- model.setSqlFile(sqlFile)
491
-
492
- # must have a runPeriod
493
- runPeriod = model.runPeriod
494
- assert(!runPeriod.empty?)
495
-
496
- # must have a calendarYear
497
- yearDescription = model.yearDescription
498
- assert(!yearDescription.empty?)
499
- calendarYear = yearDescription.get.calendarYear
500
- assert(!calendarYear.empty?)
501
-
502
- # check for no demand
503
- model.getUtilityBills.each do |utilityBill|
504
- utilityBill.billingPeriods.each do |billingPeriod|
505
- assert(billingPeriod.peakDemand.empty?)
506
- end
507
- end
508
-
509
- # make sure the report file exists
510
- assert(File.exist?(report_path(test_name)))
511
- end
512
-
513
- # calibration_reports_with_two_gas_bills
514
- def test_CalibrationReportsEnhanced_TwoGas
515
- test_name = 'calibration_reports_two_gas'
516
-
517
- # load model, remove gas bills, save to new file
518
- raw_model_path = "#{File.dirname(__FILE__)}/ExampleModel.osm"
519
- vt = OpenStudio::OSVersion::VersionTranslator.new
520
- model = vt.loadModel(raw_model_path)
521
- assert(!model.empty?)
522
- model = model.get
523
- utilityBills = model.getUtilityBills
524
- assert_equal(2, utilityBills.size)
525
- utilityBills.each do |utilityBill|
526
- utilityBill.clone(model) if utilityBill.fuelType == 'Gas'.to_FuelType
527
- end
528
- utilityBills = model.getUtilityBills
529
- assert_equal(3, utilityBills.size)
530
- altered_model_path = OpenStudio::Path.new("#{run_dir(test_name)}/ExampleModelTwoGasInput.osm")
531
- FileUtils.mkdir_p run_dir(test_name)
532
- model.save(altered_model_path, true)
533
-
534
- # set model_in_path to new altered copy of model
535
- model_in_path = altered_model_path
536
-
537
- # create an instance of the measure
538
- measure = CalibrationReportsEnhanced.new
539
-
540
- # create an instance of a runner
541
- runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
542
-
543
- # get arguments
544
- arguments = measure.arguments
545
- argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
546
-
547
- # create hash of argument values
548
- args_hash = {}
549
-
550
- # populate argument with specified hash value if specified
551
- arguments.each do |arg|
552
- temp_arg_var = arg.clone
553
- assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name]
554
- argument_map[arg.name] = temp_arg_var
555
- end
556
-
557
- # get the energyplus output requests, this will be done automatically by OS App and PAT
558
- idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map)
559
- assert_equal(0, idf_output_requests.size)
560
-
561
- # mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path.
562
- epw_path = epw_path_default
563
- setup_test(test_name, idf_output_requests, model_in_path.to_s)
564
-
565
- assert(File.exist?(model_out_path(test_name)))
566
- assert(File.exist?(sql_path(test_name)))
567
- assert(File.exist?(epw_path))
568
-
569
- # set up runner, this will happen automatically when measure is run in PAT or OpenStudio
570
- runner.setLastOpenStudioModelPath(OpenStudio::Path.new(model_out_path(test_name)))
571
- runner.setLastEnergyPlusWorkspacePath(OpenStudio::Path.new(workspace_path(test_name)))
572
- runner.setLastEpwFilePath(epw_path)
573
- runner.setLastEnergyPlusSqlFilePath(OpenStudio::Path.new(sql_path(test_name)))
574
-
575
- # delete the output if it exists
576
- FileUtils.rm(report_path(test_name)) if File.exist?(report_path(test_name))
577
- assert(!File.exist?(report_path(test_name)))
578
-
579
- # temporarily change directory to the run directory and run the measure
580
- start_dir = Dir.pwd
581
- begin
582
- Dir.chdir(run_dir(test_name))
583
-
584
- # run the measure
585
- measure.run(runner, argument_map)
586
- result = runner.result
587
- show_output(result)
588
- assert_equal('Success', result.value.valueName)
589
- assert(result.warnings.size == 1)
590
- ensure
591
- Dir.chdir(start_dir)
592
- end
593
-
594
- model = runner.lastOpenStudioModel
595
- assert(!model.empty?)
596
- model = model.get
597
-
598
- sqlFile = runner.lastEnergyPlusSqlFile
599
- assert(!sqlFile.empty?)
600
- sqlFile = sqlFile.get
601
-
602
- model.setSqlFile(sqlFile)
603
-
604
- # must have a runPeriod
605
- runPeriod = model.runPeriod
606
- assert(!runPeriod.empty?)
607
-
608
- # must have a calendarYear
609
- yearDescription = model.yearDescription
610
- assert(!yearDescription.empty?)
611
- calendarYear = yearDescription.get.calendarYear
612
- assert(!calendarYear.empty?)
613
-
614
- # make sure the report file exists
615
- assert(File.exist?(report_path(test_name)))
616
- end
617
-
618
- # calibration_reports
619
- def test_CalibrationFuelOil2
620
- skip 'Remove once CI is using 2.7.0 or later'
621
-
622
- test_name = 'calibration_fuel_oil2'
623
- model_in_path = "#{File.dirname(__FILE__)}/ExampleModel_FuelOil.osm"
624
-
625
- # create an instance of the measure
626
- measure = CalibrationReportsEnhanced.new
627
-
628
- # create an instance of a runner
629
- runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
630
-
631
- # get arguments
632
- arguments = measure.arguments
633
- argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
634
-
635
- # create hash of argument values
636
- args_hash = {}
637
-
638
- # populate argument with specified hash value if specified
639
- arguments.each do |arg|
640
- temp_arg_var = arg.clone
641
- assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name]
642
- argument_map[arg.name] = temp_arg_var
643
- end
644
-
645
- # get the energyplus output requests, this will be done automatically by OS App and PAT
646
- idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map)
647
- assert_equal(0, idf_output_requests.size)
648
-
649
- # mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path.
650
- epw_path = epw_path_default
651
- setup_test(test_name, idf_output_requests, model_in_path)
652
-
653
- assert(File.exist?(model_out_path(test_name)))
654
- assert(File.exist?(sql_path(test_name)))
655
- assert(File.exist?(epw_path))
656
-
657
- # set up runner, this will happen automatically when measure is run in PAT or OpenStudio
658
- runner.setLastOpenStudioModelPath(OpenStudio::Path.new(model_out_path(test_name)))
659
- runner.setLastEnergyPlusWorkspacePath(OpenStudio::Path.new(workspace_path(test_name)))
660
- runner.setLastEpwFilePath(epw_path)
661
- runner.setLastEnergyPlusSqlFilePath(OpenStudio::Path.new(sql_path(test_name)))
662
-
663
- # delete the output if it exists
664
- FileUtils.rm(report_path(test_name)) if File.exist?(report_path(test_name))
665
- assert(!File.exist?(report_path(test_name)))
666
-
667
- # temporarily change directory to the run directory and run the measure
668
- start_dir = Dir.pwd
669
- begin
670
- Dir.chdir(run_dir(test_name))
671
-
672
- # run the measure
673
- measure.run(runner, argument_map)
674
- result = runner.result
675
- show_output(result)
676
- assert_equal('Success', result.value.valueName)
677
- # assert(result.warnings.size == 0)
678
- ensure
679
- Dir.chdir(start_dir)
680
- end
681
-
682
- model = runner.lastOpenStudioModel
683
- assert(!model.empty?)
684
- model = model.get
685
-
686
- sqlFile = runner.lastEnergyPlusSqlFile
687
- assert(!sqlFile.empty?)
688
- sqlFile = sqlFile.get
689
-
690
- model.setSqlFile(sqlFile)
691
-
692
- # must have a runPeriod
693
- runPeriod = model.runPeriod
694
- assert(!runPeriod.empty?)
695
-
696
- # must have a calendarYear
697
- yearDescription = model.yearDescription
698
- assert(!yearDescription.empty?)
699
- calendarYear = yearDescription.get.calendarYear
700
- assert(!calendarYear.empty?)
701
-
702
- # check for varying demand
703
- assert_equal(3, model.getUtilityBills.size)
704
- model.getUtilityBills.each do |utilityBill|
705
- assert(!utilityBill.billingPeriods.empty?)
706
- utilityBill.billingPeriods.each do |billingPeriod|
707
- assert(!billingPeriod.modelConsumption.empty?)
708
- end
709
-
710
- next if utilityBill.peakDemandUnitConversionFactor.empty?
711
- hasVaryingDemand = false
712
- modelPeakDemand = 0.0
713
- count = 0
714
- utilityBill.billingPeriods.each do |billingPeriod|
715
- peakDemand = billingPeriod.modelPeakDemand
716
- next if peakDemand.empty?
717
- temp = peakDemand.get
718
- if count == 0
719
- modelPeakDemand = temp
720
- else
721
- if modelPeakDemand != temp
722
- hasVaryingDemand = true
723
- break
724
- end
725
- end
726
- count += 1
727
- end
728
- assert(hasVaryingDemand) if count > 1
729
- end
730
-
731
- # make sure the report file exists
732
- assert(File.exist?(report_path(test_name)))
733
- end
734
- end