def test_analysis_module(self): rng = RandomNumberGenerator() module = self.createAnalysisModule() ens_size = 12 obs_size = 1 state_size = 2 true_params = [1.25, 0.75] true_state = forward_model(true_params) obs = [(measure(true_state), 0.75)] A = Matrix(state_size, ens_size) ens = [] for iens in range(ens_size): param = [random.gauss(1.00, 1.00), random.gauss(1.00, 1.00)] ens.append(param) mask = BoolVector(default_value=True, initial_size=ens_size) mask[2] = False (A, S, E, D, R, dObs) = init_matrices(ens, mask, obs, rng) module.initUpdate(mask, S, R, dObs, E, D) module.updateA(A, S, R, dObs, E, D) mask[10] = False mask[5] = False (A, S, E, D, R, dObs) = init_matrices(ens, mask, obs, rng) self.assertEqual(S.dims(), (obs_size, mask.countEqual(True))) self.assertEqual(E.dims(), (obs_size, mask.countEqual(True))) self.assertEqual(D.dims(), (obs_size, mask.countEqual(True))) module.initUpdate(mask, S, R, dObs, E, D) module.updateA(A, S, R, dObs, E, D)
def setUp(self): self.libname = clib.ert_lib_path + "/rml_enkf.so" self.user = "******" self.config_file = self.createTestPath( "Statoil/config/obs_testing2/config") self.rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT)
def test_matrix_copy_column(self): m = Matrix(10,2) rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) m.randomInit( rng ) with self.assertRaises(ValueError): m.copyColumn(0,2) with self.assertRaises(ValueError): m.copyColumn(2,0) with self.assertRaises(ValueError): m.copyColumn(-2,0) m.copyColumn(1, 0) for i in range(m.rows()): self.assertEqual( m[i,0] , m[i,1] )
def test_sub_copy(self): m1 = Matrix(3,3) rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) m1.randomInit( rng ) with self.assertRaises(ValueError): m2 = m1.subCopy( 0,0,4,2 ) with self.assertRaises(ValueError): m2 = m1.subCopy( 0,0,2,4 ) with self.assertRaises(ValueError): m2 = m1.subCopy( 4,0,1,1 ) with self.assertRaises(ValueError): m2 = m1.subCopy( 0,2,1,2 ) m2 = m1.subCopy( 0,0,2,2 ) for i in range(2): for j in range(2): self.assertEqual( m1[i,j] , m2[i,j])
grid.save_EGRID("grid/CASE.EGRID") return grid def make_field(rng , grid , iens): permx = EclKW.create( "PERMX" , grid.getGlobalSize( ) , EclTypeEnum.ECL_FLOAT_TYPE) permx.assign( rng.getDouble( ) ) poro = EclKW.create( "PORO" , grid.getGlobalSize( ) , EclTypeEnum.ECL_FLOAT_TYPE) poro.assign( rng.getDouble( ) ) if not os.path.isdir("fields"): os.makedirs("fields") with open("fields/permx%d.grdecl" % iens,"w") as f: permx.write_grdecl( f ) with open("fields/poro%d.grdecl" % iens ,"w") as f: poro.write_grdecl( f ) rng = RandomNumberGenerator( ) rng.setState("ABCD6375ejascEFGHIJ") grid = make_grid( ) for iens in range(ens_size): make_field(rng , grid , iens)
def test_matrix_random_init(self): m = Matrix(10,10) rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) m.randomInit( rng )
def createAnalysisModule(self): rng = RandomNumberGenerator(RngAlgTypeEnum.MZRAN, RngInitModeEnum.INIT_DEFAULT) return AnalysisModule(rng, lib_name=self.libname)
grid.save_EGRID("grid/CASE.EGRID") return grid def make_field(rng, grid, iens): permx = EclKW.create("PERMX", grid.getGlobalSize(), EclTypeEnum.ECL_FLOAT_TYPE) permx.assign(rng.getDouble()) poro = EclKW.create("PORO", grid.getGlobalSize(), EclTypeEnum.ECL_FLOAT_TYPE) poro.assign(rng.getDouble()) if not os.path.isdir("fields"): os.makedirs("fields") with open("fields/permx%d.grdecl" % iens, "w") as f: permx.write_grdecl(f) with open("fields/poro%d.grdecl" % iens, "w") as f: poro.write_grdecl(f) rng = RandomNumberGenerator() rng.setState("ABCD6375ejascEFGHIJ") grid = make_grid() for iens in range(ens_size): make_field(rng, grid, iens)