Class: AddPackagedIceStorageTest
- Inherits:
-
MiniTest::Test
- Object
- MiniTest::Test
- AddPackagedIceStorageTest
- Defined in:
- lib/measures/add_packaged_ice_storage/tests/add_packaged_ice_storage_test.rb
Instance Method Summary collapse
-
#model_run_simulation_and_log_errors(model, workspace, run_dir = "#{Dir.pwd}/Run") ⇒ Bool
Runs an annual simulation of IDF.
- #test_good_argument_values ⇒ Object
- #test_single_speed_dx ⇒ Object
Instance Method Details
#model_run_simulation_and_log_errors(model, workspace, run_dir = "#{Dir.pwd}/Run") ⇒ Bool
Runs an annual simulation of IDF
code based on model_run_simulation_and_log_errors from OpenStudio Standards Maybe update method above to optionally take IDF instead of OSM or add another method
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 |
# File 'lib/measures/add_packaged_ice_storage/tests/add_packaged_ice_storage_test.rb', line 27 def model_run_simulation_and_log_errors(model, workspace, run_dir = "#{Dir.pwd}/Run") # Make the directory if it doesn't exist unless Dir.exist?(run_dir) FileUtils.mkdir_p(run_dir) end # Save workspace IDF idf_name = 'in.idf' OpenStudio.logFree(OpenStudio::Debug, 'openstudio.model.Model', "Starting simulation here: #{run_dir}.") OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', "Running simulation #{run_dir}.") idf_path = OpenStudio::Path.new("#{run_dir}/#{idf_name}") workspace.save(idf_path, true) # Set up the simulation # Find the weather file epw_path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw") sql_path = nil OpenStudio.logFree(OpenStudio::Debug, 'openstudio.model.Model', 'Running with RunManager.') # Find EnergyPlus ep_path = OpenStudio.getEnergyPlusExecutable puts "EnergyPlus is: #{ep_path}" job = "energyplus -w #{epw_path.to_s} -d #{run_dir} #{idf_path.to_s}" puts job system(job) sql_path = OpenStudio::Path.new("#{run_dir}/eplusout.sql") OpenStudio.logFree(OpenStudio::Info, 'openstudio.model.Model', 'Finished run.') # @todo Delete the eplustbl.htm and other files created by the run for cleanliness. if OpenStudio.exists(sql_path) sql = OpenStudio::SqlFile.new(sql_path) # Check to make sure the sql file is readable, # which won't be true if EnergyPlus crashed during simulation. unless sql.connectionOpen OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "The run failed, cannot create model. Look at the eplusout.err file in #{File.dirname(sql_path.to_s)} to see the cause.") return false end else # If the sql file does not exist, it is likely that EnergyPlus crashed, # in which case the useful errors are inside the eplusout.err file. err_file_path_string = "#{run_dir}/eplusout.err" err_file_path = OpenStudio::Path.new(err_file_path_string) if OpenStudio.exists(err_file_path) if __dir__[0] == ':' # Running from OpenStudio CLI errs = EmbeddedScripting.getFileAsString(err_file_path_string) else errs = File.read(err_file_path_string) end OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "The run did not finish because of the following errors: #{errs}") return false else OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "Results for the run couldn't be found here: #{sql_path}.") return false end end # Report severe or fatal errors in the run error_query = "SELECT ErrorMessage FROM Errors WHERE ErrorType in(1,2)" model.setSqlFile(sql) errs = model.sqlFile.get.execAndReturnVectorOfString(error_query) if errs.is_initialized errs = errs.get end # Check that the run completed successfully end_file_stringpath = "#{run_dir}/eplusout.end" end_file_path = OpenStudio::Path.new(end_file_stringpath) if OpenStudio.exists(end_file_path) endstring = File.read(end_file_stringpath) end if !endstring.include?('EnergyPlus Completed Successfully') OpenStudio.logFree(OpenStudio::Error, 'openstudio.model.Model', "The run did not finish and had following errors: #{errs.join('\n')}") return false end # Log any severe errors that did not cause simulation to fail unless errs.empty? OpenStudio.logFree(OpenStudio::Warn, 'openstudio.model.Model', "The run completed but had the following severe errors: #{errs.join('\n')}") end return true end |
#test_good_argument_values ⇒ Object
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 |
# File 'lib/measures/add_packaged_ice_storage/tests/add_packaged_ice_storage_test.rb', line 119 def test_good_argument_values # create an instance of the measure measure = AddPackagedIceStorage.new # create runner with empty OSW osw = OpenStudio::WorkflowJSON.new runner = OpenStudio::Measure::OSRunner.new(osw) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/MeasureTest.osm") model = translator.loadModel(path) assert(!model.empty?) model = model.get # forward translate OSM file to IDF file ft = OpenStudio::EnergyPlus::ForwardTranslator.new workspace = ft.translateModel(model) # get arguments arguments = measure.arguments(workspace) argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # create hash of argument values args_hash = {} args_hash['ice_cap'] = '40,50' # populate argument with specified has value if set arguments.each do |arg| temp_arg_var = arg.clone assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name] argument_map[arg.name] = temp_arg_var end # run the measure measure.run(workspace, runner, argument_map) # run the annual simulation # commented out for now E+ run in test doesn't function on CI yet #output_file_path = "#{File.dirname(__FILE__)}/output/test_good_argument_values" #sim_results = self.model_run_simulation_and_log_errors(model, workspace, output_file_path) #assert(sim_results) result = runner.result assert_equal('Success', result.value.valueName) show_output(result) true end |
#test_single_speed_dx ⇒ Object
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 |
# File 'lib/measures/add_packaged_ice_storage/tests/add_packaged_ice_storage_test.rb', line 170 def test_single_speed_dx # create an instance of the measure measure = AddPackagedIceStorage.new # create runner with empty OSW osw = OpenStudio::WorkflowJSON.new runner = OpenStudio::Measure::OSRunner.new(osw) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new("#{File.dirname(__FILE__)}/single_speed_dx_350.osm") model = translator.loadModel(path) assert(!model.empty?) model = model.get # forward translate OSM file to IDF file ft = OpenStudio::EnergyPlus::ForwardTranslator.new workspace = ft.translateModel(model) # get arguments arguments = measure.arguments(workspace) argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # create hash of argument values args_hash = {} #args_hash['ice_cap'] = '40,50' # populate argument with specified has value if set arguments.each do |arg| temp_arg_var = arg.clone assert(temp_arg_var.setValue(args_hash[arg.name])) if args_hash[arg.name] argument_map[arg.name] = temp_arg_var end # run the measure measure.run(workspace, runner, argument_map) # run the annual simulation # commented out for now E+ run in test doesn't function on CI yet #output_file_path = "#{File.dirname(__FILE__)}/output/single_speed_dx" #sim_results = self.model_run_simulation_and_log_errors(model, workspace, output_file_path) #assert(sim_results) result = runner.result assert_equal('Success', result.value.valueName) show_output(result) true end |