def setUp(self): AUT2_FIELDMAP = { 'Pressure': 'Pressure', 'Temperature': 'Temperature', 'Vapour saturation': 'Vapour saturation', } WAIWERA_FIELDMAP = { 'Pressure': 'fluid_pressure', 'Temperature': 'fluid_temperature', 'Vapour saturation': 'fluid_vapour_saturation', } # these two sets all have 50 output times, made identical self.mres1 = WaiweraModelResult('waiwera', outputPath=THIS_DIR, h5_filename='deliv.h5', fieldname_map=WAIWERA_FIELDMAP) self.mres2 = T2ModelResult('aut2', lst_filename='deliv.listing', ordering_map=list(range(1, 11)), fieldname_map=AUT2_FIELDMAP) # these two have different length of output results self.mres3 = WaiweraModelResult('waiwera', outputPath=THIS_DIR, h5_filename='deliv_38.h5', fieldname_map=WAIWERA_FIELDMAP) self.mres4 = T2ModelResult('aut2', lst_filename='deliv_39.listing', ordering_map=list(range(1, 11)), fieldname_map=AUT2_FIELDMAP) print('waiwera n = ', len(self.mres3.getTimes())) print('aut2 n = ', len(self.mres4.getTimes()))
def setUp(self): # cc6 has eleme 1-80 as atmosphere blocks lstname = 'mres_aut2_cc6.listing' self.idxmap = list(range(80, 1680)) self.mres_map = T2ModelResult('test_aut2_map', lst_filename=lstname, ordering_map=self.idxmap) self.mres = T2ModelResult('test_aut2_map', lst_filename=lstname, ordering_map=None) self.lst = t2listing(lstname) ### mResult with data file datname = 'mdat_fivespot.dat' self.mres_w_dat = T2ModelResult('test_aut2_map', lst_filename=lstname, dat_filename=datname, ordering_map=None) self.dat = t2data(datname)
def test_simple(self): """ Tests basic custom variable usage. Incls values at all cells and history of a single cell. """ # example of ustom variable function, first argument is always # ModelResult object, the second is an integer index. def calc_p_in_bar(mResult, index): """ Implement this func to calculate customised variable. Within this function, users should try to use only the public methods of ModelResult, such as .getFieldAtOutputIndex() and .getFieldHistoryAtCell(). Also the names of fields should be the keys specified in field_map. This would allow the function to be used in (almost) all ModelResults. """ return old_div(mResult.getFieldAtOutputIndex('pressu', index), 1.0e5) def calc_p_hist_in_bar(mResult, index): t, phist = mResult.getFieldHistoryAtCell('pressu', index) return t, old_div(phist, 1.0e5) # then pass the function into the ModelResult (or ModelRun) as part of # the field name map field_map = { 'pressu': 'Pressure', 'p_in_bar': calc_p_in_bar, 'p_hist_in_bar': calc_p_hist_in_bar, } mres = T2ModelResult( 'test_aut2_map', lst_filename=self.lstname, fieldname_map=field_map, ) # test final result table self.lst.index = -1 p_f = self.lst.element['Pressure'] b_f = old_div(p_f, 1.0e5) self.assertEqual(mres.getFieldAtOutputIndex('pressu', -1)[30], p_f[30]) self.assertEqual( mres.getFieldAtOutputIndex('p_in_bar', -1)[30], b_f[30]) # test history ele = self.lst.element.row_name[30] ph_f = self.lst.history(('e', ele, 'Pressure'), short=False)[1] bh_f = old_div(ph_f, 1.0e5) t, phist = mres.getFieldHistoryAtCell('pressu', 30) self.assertEqual(phist[1], ph_f[1]) t, phist = mres.getFieldHistoryAtCell('p_hist_in_bar', 30) self.assertEqual(phist[1], bh_f[1]) mres.destroy()
model_run = WaiweraModelRun(run_name, run_filename, fieldname_map=WAIWERA_FIELDMAP, simulator='waiwera', basePath=os.path.realpath(model_dir)) model_run.jobParams['nproc'] = num_procs problem1_test.mSuite.addRun(model_run, run_name) problem1_test.setupEmptyTestCompsList() digitised_time_result = {} digitised_r_result = {} run_base_name = model_name run_filename = os.path.join(model_dir, run_base_name + ".listing") AUTOUGH2_result = T2ModelResult("AUTOUGH2", run_filename, geo_filename=t2geo_filename, ordering_map=map_out_atm) problem1_test.addTestComp( run_index, "AUTOUGH2 history at " + obspt, HistoryWithinTolTC(fieldsToTest=test_fields, defFieldTol=1.e-3, expected=AUTOUGH2_result, testCellIndex=obs_cell_index)) problem1_test.addTestComp( run_index, "AUTOUGH2 t = 1.e9 s", FieldWithinTolTC(fieldsToTest=["Temperature"], defFieldTol=1.0e-4, expected=AUTOUGH2_result, testOutputIndex=-1))
AUTOUGH2_result = {} for run_index, run_name in enumerate(run_names): run_base_name = model_name + '_' + run_name results_filename = os.path.join(model_dir, run_base_name + ".listing") run_filename = run_base_name + '.json' inp = json.load(open(os.path.join(base_path, run_filename))) if 'minc' in inp['mesh']: num_levels = len(inp['mesh']['minc']['geometry']['matrix']['volume']) else: num_levels = 0 lst = t2listing(results_filename) lst.last() num_minc_cells = lst.element.num_rows - geo.num_blocks AUTOUGH2_result[run_name] = T2ModelResult("AUTOUGH2", results_filename, geo_filename = t2geo_filename, fieldname_map = AUTOUGH2_FIELDMAP, ordering_map = minc_level_map(num_levels, num_minc_cells)) minc_column_test.addTestComp(run_index, "AUTOUGH2", FieldWithinTolTC(fieldsToTest = test_fields, defFieldTol = 0.025, expected = AUTOUGH2_result[run_name], testOutputIndex = -1)) minc_column_test.addTestComp(run_index, "AUTOUGH2 history", HistoryWithinTolTC(fieldsToTest = test_fields, defFieldTol = 0.02, expected = AUTOUGH2_result[run_name], testCellIndex = obs_cell_index)) minc_column_test.addTestComp(run_index, "AUTOUGH2 source",
run_filename = run_base_name + '.json' model_run = WaiweraModelRun(run_name, run_filename, fieldname_map = WAIWERA_FIELDMAP, simulator = simulator, basePath = os.path.realpath(model_dir)) model_run.jobParams['nproc'] = args.np problem2_test.mSuite.addRun(model_run, run_name) problem2_test.setupEmptyTestCompsList() AUTOUGH2_result = {} for run_index, run_name in enumerate(run_names): run_base_name = model_name + run_name results_filename = os.path.join(model_dir, run_base_name + ".listing") AUTOUGH2_result[run_name] = T2ModelResult("AUTOUGH2", results_filename, geo_filename = t2geo_filename) problem2_test.addTestComp(run_index, "AUTOUGH2", SimilaritySolutionWithinTolTC( fieldsToTest = test_fields[run_name], defFieldTol = AUTOUGH2_field_tol[run_name], expected = AUTOUGH2_result[run_name], testCellIndices = obs_cell_indices)) problem2_test.addTestComp(run_index, ref_result_name[run_name], SimilaritySolutionWithinTolTC( fieldsToTest = test_fields[run_name], defFieldTol = ref_field_tol[run_name], fieldTols = {"Liquid saturation": 6.e-2}, absoluteErrorTol = 0.01, expected = expected[run_name],
basePath = os.path.realpath(model_dir)) model_run.jobParams['nproc'] = args.np co2_column_test.mSuite.addRun(model_run, run_name) co2_column_test.setupEmptyTestCompsList() digitised_test_fields = ['CO2 partial pressure'] digitised_simulators = ['MULKOM'] digitised_result = {} AUTOUGH2_result = {} for run_index, run_name in enumerate(run_names): run_base_name = model_name + '_' + run_name results_filename = os.path.join(model_dir, run_base_name + ".listing") AUTOUGH2_result[run_name] = T2ModelResult("AUTOUGH2", results_filename, geo_filename = t2geo_filename, fieldname_map = AUTOUGH2_FIELDMAP, ordering_map = map_out_atm) co2_column_test.addTestComp(run_index, "AUTOUGH2", FieldWithinTolTC(fieldsToTest = test_fields, defFieldTol = 1.e-3, expected = AUTOUGH2_result[run_name], testOutputIndex = -1)) for run_index, run_name in enumerate(run_names): if run_name in digitised_run_names: for sim in digitised_simulators: for field_name in digitised_test_fields: data_filename = '_'.join((model_name, run_name, field_name, sim)) data_filename = data_filename.lower().replace(' ', '_') data_filename = os.path.join(data_dir, data_filename + '.dat') result = DigitisedOneDFieldResult(sim, data_filename, field_name, -1)
run_base_name = model_name run_filename = run_base_name + '.json' model_run = WaiweraModelRun(run_name, run_filename, fieldname_map = WAIWERA_FIELDMAP, simulator = 'waiwera', basePath = os.path.realpath(model_dir)) model_run.jobParams['nproc'] = num_procs heat_pipe_test.mSuite.addRun(model_run, run_name) heat_pipe_test.setupEmptyTestCompsList() digitised_result = {} run_base_name = model_name run_filename = os.path.join(model_dir, run_base_name + ".listing") AUTOUGH2_result = T2ModelResult("AUTOUGH2", run_filename, fieldname_map = AUTOUGH2_FIELDMAP, geo_filename = t2geo_filename, ordering_map = map_out_bdy) heat_pipe_test.addTestComp(run_index, "AUTOUGH2", FieldWithinTolTC(fieldsToTest = test_fields, defFieldTol = 5.e-3, expected = AUTOUGH2_result, testOutputIndex = -1)) t_final = AUTOUGH2_result.getTimes()[-1] for sim in digitised_simulators: for field_name in digitised_test_fields: data_filename = '_'.join((model_name, field_name, sim)) data_filename = data_filename.lower().replace(' ', '_') data_filename = os.path.join(data_dir, data_filename + '.dat') result = DigitisedOneDFieldResult(sim, data_filename, field_name, -1)
run_filename, fieldname_map=WAIWERA_FIELDMAP, simulator=simulator, basePath=os.path.realpath(model_dir)) model_run.jobParams['nproc'] = args.np deliverability_test.mSuite.addRun(model_run, run_name) deliverability_test.setupEmptyTestCompsList() reference_result = {} for run_index, run_name in enumerate(run_names): run_base_name = '_'.join((model_name, run_name)) run_filename = os.path.join(model_dir, run_base_name + ".listing") reference_result[run_name] = T2ModelResult("aut2", run_filename, geo_filename=t2geo_filename, ordering_map=map_out_atm) deliverability_test.addTestComp( run_index, "final errors", FieldWithinTolTC(fieldsToTest=test_fields, defFieldTol=5.e-3, expected=reference_result[run_name], testOutputIndex=-1)) deliverability_test.addTestComp( run_index, "time history", HistoryWithinTolTC(fieldsToTest=test_fields, defFieldTol=1.e-2, expected=reference_result[run_name], testCellIndex=4)) deliverability_test.addTestComp( run_index, "source",
run_base_name = model_name run_filename = run_base_name + '.json' model_run = WaiweraModelRun(run_name, run_filename, fieldname_map=WAIWERA_FIELDMAP, simulator=simulator, basePath=os.path.realpath(model_dir)) model_run.jobParams['nproc'] = num_procs co2_one_cell_test.mSuite.addRun(model_run, run_name) co2_one_cell_test.setupEmptyTestCompsList() run_base_name = model_name run_filename = os.path.join(model_dir, run_base_name + ".listing") AUTOUGH2_result = T2ModelResult("AUTOUGH2", run_filename, fieldname_map=AUTOUGH2_FIELDMAP, geo_filename=t2geo_filename) co2_one_cell_test.addTestComp( run_index, "AUTOUGH2 history", HistoryWithinTolTC(fieldsToTest=test_fields, defFieldTol=1.e-3, expected=AUTOUGH2_result, testCellIndex=obs_cell_index)) co2_one_cell_test.addTestComp( run_index, "AUTOUGH2 source history", HistoryWithinTolTC(fieldsToTest=test_source_fields, defFieldTol=1.e-3, expected=AUTOUGH2_result, testSourceIndex=source_index))