def test_grid_cell_bounding_boxes() -> None: layers = () flowdata = FlowData( _locate_test_case(), layers, "multiple_based_on_workovers", ) # Test no argument and entire field being equal flowdata._layers = ((1, flowdata.grid.nz), ) assert_almost_equal(flowdata._grid_cell_bounding_boxes(), flowdata._grid_cell_bounding_boxes(0)) # Test zero'th layer id flowdata._layers = ((1, 2), (3, 4)) result = flowdata._grid_cell_bounding_boxes(0) active_cells = EclRegion(flowdata.grid, True) active_cells.select_kslice(*tuple( map(operator.sub, flowdata._layers[0], (1, 1))), intersect=True) active_cells.select_active(intersect=True) assert result.shape[0] == active_cells.active_size() assert result.shape[1] == 6 # Test last layer id flowdata._layers = ((1, 2), (3, 4)) result = flowdata._grid_cell_bounding_boxes(1) active_cells = EclRegion(flowdata.grid, True) active_cells.select_kslice(*tuple( map(operator.sub, flowdata._layers[-1], (1, 1))), intersect=True) active_cells.select_active(intersect=True) assert result.shape[0] == active_cells.active_size() assert result.shape[1] == 6
def test_grid_cell_bounding_boxes() -> None: layers = () flowdata = FlowData(_locate_test_case(), layers) # Test one layer for the whole field and no layers equal flowdata._layers = ((1, flowdata.grid.nz),) field_one_layer = flowdata.grid_cell_bounding_boxes(0) flowdata._layers = () field_no_layer = flowdata.grid_cell_bounding_boxes(0) assert_almost_equal(field_one_layer, field_no_layer) # Test zero'th layer id flowdata._layers = ((1, 2), (3, 4)) result = flowdata.grid_cell_bounding_boxes(0) active_cells = EclRegion(flowdata.grid, True) active_cells.select_kslice( *tuple(map(operator.sub, flowdata._layers[0], (1, 1))), intersect=True ) active_cells.select_active(intersect=True) assert result.shape[0] == active_cells.active_size() assert result.shape[1] == 6 # Test last layer id flowdata._layers = ((1, 2), (3, 4)) result = flowdata.grid_cell_bounding_boxes(1) active_cells = EclRegion(flowdata.grid, True) active_cells.select_kslice( *tuple(map(operator.sub, flowdata._layers[-1], (1, 1))), intersect=True ) active_cells.select_active(intersect=True) assert result.shape[0] == active_cells.active_size() assert result.shape[1] == 6
def setUp(self): self.grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) ) self.kw = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_INT ) self.kw.assign( 1 ) reg = EclRegion( self.grid , False ) for k in range(self.grid.getNZ()): reg.clear( ) reg.select_kslice( k , k ) self.kw.assign( k , mask = reg ) self.kw[ k * self.grid.getNX() * self.grid.getNY() + 7] = 177
def setUp(self): self.grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) ) self.kw = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_INT ) self.kw.assign( 1 ) reg = EclRegion( self.grid , False ) for k in range(self.grid.getNZ()): reg.clear( ) reg.select_kslice( k , k ) self.kw.assign( k , mask = reg ) self.kw[ k * self.grid.getNX() * self.grid.getNY() + 7] = 177
def test_slice(self): reg = EclRegion(self.grid, False) reg.select_islice(0, 5) OK = True global_list = reg.getGlobalList() self.assertEqual(global_list.parent(), reg) for gi in global_list: (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False self.assertTrue(OK) self.assertTrue(self.grid.getNY() * self.grid.getNZ() * 6 == len(reg.getGlobalList())) reg.select_jslice(7, 8, intersect=True) OK = True for gi in reg.getGlobalList(): (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False self.assertTrue(OK) self.assertTrue(2 * self.grid.getNZ() * 6 == len(reg.getGlobalList())) reg2 = EclRegion(self.grid, False) reg2.select_kslice(3, 5) reg &= reg2 OK = True for gi in reg.getGlobalList(): (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False if k < 3 or k > 5: OK = False self.assertTrue(OK) self.assertTrue(2 * 3 * 6 == len(reg.getGlobalList()))
def filter_region_ijk(grid, i, j, k, combine_operator="intersect"): # Filter out the selected grid cells region = EclRegion(grid, False) region1 = EclRegion(grid, False) region_i = EclRegion(grid, False) region_j = EclRegion(grid, False) region_k = EclRegion(grid, False) # Create selected regions for each filter type if i: for i_slice in unpack_filter(i): region_i.select_islice(i_slice - 1, i_slice - 1) # -1 because ert defines i=1 as i=0 else: region_i.select_all() if j: for j_slice in unpack_filter(j): region_j.select_jslice(j_slice - 1, j_slice - 1) # -1 because ert defines j=1 as j=0 else: region_j.select_all() if k: for k_slice in unpack_filter(k): region_k.select_kslice(k_slice - 1, k_slice - 1) # -1 because ert defines j=1 as j=0 else: region_k.select_all() # Combine regions by if (combine_operator == "intersect" or combine_operator == "" or combine_operator is None): # Intersection region.select_all() region = region & region_i & region_j & region_k return region elif combine_operator == "union": # Union region1.select_active() region2 = region_i | region_j | region_k region = region1 & region2 return region else: raise Exception( "ERROR: '%s' is not a valid operator to combine regions." % combine_operator)
def test_slice(self): reg = EclRegion(self.grid, False) reg.select_islice(0, 5) OK = True global_list = reg.getGlobalList() self.assertEqual(global_list.parent(), reg) for gi in global_list: (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False self.assertTrue(OK) self.assertTrue(self.grid.getNY() * self.grid.getNZ() * 6 == len(reg.getGlobalList())) reg.select_jslice(7, 8, intersect=True) OK = True for gi in reg.getGlobalList(): (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False self.assertTrue(OK) self.assertTrue(2 * self.grid.getNZ() * 6 == len(reg.getGlobalList())) reg2 = EclRegion(self.grid, False) reg2.select_kslice(3, 5) reg &= reg2 OK = True for gi in reg.getGlobalList(): (i, j, k) = self.grid.get_ijk(global_index=gi) if i > 5: OK = False if j < 7 or j > 8: OK = False if k < 3 or k > 5: OK = False self.assertTrue(OK) self.assertTrue(2 * 3 * 6 == len(reg.getGlobalList()))
def filter_region(grid, idx_i, idx_j, idx_k, fipnum, fipnum_kw, combine_operator="intersect"): # Filter out the selected grid cells region = EclRegion(grid, False) region1 = EclRegion(grid, False) region_i = EclRegion(grid, False) region_j = EclRegion(grid, False) region_k = EclRegion(grid, False) region_fip = EclRegion(grid, False) # Create selected regions for each filter type if idx_i: for i_slice in unpack_filter(idx_i): region_i.select_islice(i_slice - 1, i_slice - 1) # -1 because ert defines i=1 as i=0 else: region_i.select_all() if idx_j: for j_slice in unpack_filter(idx_j): region_j.select_jslice(j_slice - 1, j_slice - 1) # -1 because ert defines j=1 as j=0 else: region_j.select_all() if idx_k: for k_slice in unpack_filter(idx_k): region_k.select_kslice(k_slice - 1, k_slice - 1) # -1 because ert defines j=1 as j=0 else: region_k.select_all() if fipnum: for fip in unpack_filter(fipnum): region_fip.select_equal(fipnum_kw, fip) else: region_fip.select_all() # Combine regions by if (combine_operator == "intersect" or combine_operator == "" or combine_operator is None): # Intersection region.select_all() # region.select_active() region = region & region_i & region_j & region_k & region_fip return region if combine_operator == "union": # Union region1.select_active() region2 = region_i | region_j | region_k | region_fip region = region1 & region2 return region raise Exception( f"ERROR: '{combine_operator}' is not a valid operator to combine regions." )