int main(int argc , char ** argv) { util_install_signals(); { ecl_grid_type * grid = ecl_grid_alloc( argv[1] ); vector_type * expected = load_expected( grid, argv[2] ); for (int c=0; c < vector_get_size( expected ); c++) { const point_type * p = vector_iget_const( expected , c ); int g = ecl_grid_get_global_index_from_xyz(grid , p->x, p->y , p->z , 0 ); if (g != ecl_grid_get_global_index3(grid, p->i,p->j, p->k)) { int i,j,k; ecl_grid_get_ijk1(grid, g, &i, &j, &k); fprintf(stderr,"point:%d (%g,%g,%g), Simulated: %d:(%d,%d,%d) Expected: %d:(%d,%d,%d) contains:%d\n", c , p->x, p->y, p->z, g, i,j,k, p->g, p->i, p->j, p->k, ecl_grid_cell_contains_xyz1( grid, p->g , p->x , p->y, p->z)); } if (!p->skip) test_assert_int_equal( g , ecl_grid_get_global_index3(grid, p->i,p->j, p->k)); else { if ( g != ecl_grid_get_global_index3(grid, p->i,p->j, p->k)) fprintf(stderr," ** Skipping failed test for point:%d \n",c); } } ecl_grid_free( grid ); vector_free( expected ); } exit(0); }
void test_create( const ecl_grid_type * grid , ecl_kw_type * fault_block_kw) { int k = 0; int i,j; for (j=0; j < ecl_grid_get_ny( grid ); j++) { for (i = 0; i < ecl_grid_get_nx( grid ); i++) { int g = ecl_grid_get_global_index3( grid , i,j,k); ecl_kw_iset_int( fault_block_kw , g , 9 ); } } { fault_block_layer_type * layer = fault_block_layer_alloc( grid , k ); test_assert_int_equal( 1 , fault_block_layer_get_next_id( layer )); fault_block_layer_scan_kw( layer , fault_block_kw); { fault_block_type * block = fault_block_layer_iget_block( layer , 0 ); double x,y,z; ecl_grid_get_xyz3( grid , 4,4,k , &x, &y , &z ); test_assert_double_equal( x , fault_block_get_xc( block )); test_assert_double_equal( y , fault_block_get_yc( block )); } fault_block_layer_free( layer ); } }
bool fault_block_layer_load_kw( fault_block_layer_type * layer , const ecl_kw_type * fault_block_kw) { if (ecl_kw_get_size( fault_block_kw) != ecl_grid_get_global_size(layer->grid)) return false; else if (!ecl_type_is_int(ecl_kw_get_data_type( fault_block_kw ))) return false; else { int i,j; for (j=0; j < ecl_grid_get_ny( layer->grid ); j++) { for (i=0; i < ecl_grid_get_nx( layer->grid ); i++) { int g = ecl_grid_get_global_index3( layer->grid , i , j , layer->k ); int block_id = ecl_kw_iget_int( fault_block_kw , g ); if (block_id > 0) { fault_block_layer_add_block( layer , block_id ); { fault_block_type * fault_block = fault_block_layer_get_block( layer , block_id ); fault_block_add_cell( fault_block , i,j ); } } } } return true; } }
bool fault_block_layer_scan_kw( fault_block_layer_type * layer , const ecl_kw_type * fault_block_kw) { bool assign_zero = true; if (ecl_kw_get_size( fault_block_kw) != ecl_grid_get_global_size(layer->grid)) return false; else if (!ecl_type_is_int(ecl_kw_get_data_type( fault_block_kw ))) return false; else { int i,j; int max_block_id = 0; layer_type * work_layer = layer_alloc( ecl_grid_get_nx( layer->grid ) , ecl_grid_get_ny( layer->grid )); for (j=0; j < ecl_grid_get_ny( layer->grid ); j++) { for (i=0; i < ecl_grid_get_nx( layer->grid ); i++) { int g = ecl_grid_get_global_index3( layer->grid , i , j , layer->k ); int block_id = ecl_kw_iget_int( fault_block_kw , g ); if (block_id > 0) { layer_iset_cell_value( work_layer , i , j , block_id ); max_block_id = util_int_max( block_id , max_block_id ); } } } if (assign_zero) layer_replace_cell_values( work_layer , 0 , max_block_id + 1); fault_block_layer_scan_layer( layer , work_layer ); layer_free( work_layer ); return true; } }
vector_type * load_expected( const ecl_grid_type * grid, const char * filename ) { FILE * stream = util_fopen( filename , "r"); vector_type * expected = vector_alloc_new(); while (true) { double x,y,z; int i,j,k,skip; if (fscanf( stream , "%lg %lg %lg %d %d %d %d" , &x,&y,&z,&i,&j,&k,&skip) == 7) { point_type * p = util_malloc( sizeof * p ); p->x = x; p->y = y; p->z = z; p->i = i-1; p->j = j-1; p->k = k-1; p->skip = skip; p->g = ecl_grid_get_global_index3(grid, p->i, p->j, p->k); vector_append_owned_ref( expected, p , free ); } else break; } fclose( stream ); test_assert_int_equal( 10 , vector_get_size( expected )); return expected; }
void test_neighbours( const ecl_grid_type * grid) { const int k = 0; fault_block_layer_type * layer = fault_block_layer_alloc( grid , k ); geo_polygon_collection_type * polylines = geo_polygon_collection_alloc(); ecl_kw_type * ecl_kw = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid ) , ECL_INT_TYPE ); ecl_kw_iset_int( ecl_kw , 0 , 1); ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 3,3,k) , 2); ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 4,3,k) , 3); ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 5,3,k) , 4); ecl_kw_iset_int( ecl_kw , ecl_grid_get_global_index3( grid , 4,2,k) , 5); fault_block_layer_load_kw( layer , ecl_kw); { int_vector_type * neighbours = int_vector_alloc( 0,0); { fault_block_type * block = fault_block_layer_get_block( layer , 1 ); test_assert_int_equal( 0 , int_vector_size( neighbours )); fault_block_list_neighbours( block , false , polylines , neighbours ); test_assert_int_equal( 0 , int_vector_size( neighbours )); } { fault_block_type * block = fault_block_layer_get_block( layer , 2 ); fault_block_list_neighbours( block , false , polylines , neighbours ); test_assert_int_equal( 1 , int_vector_size( neighbours )); test_assert_true( int_vector_contains( neighbours , 3 )); } int_vector_free( neighbours ); } geo_polygon_collection_free( polylines ); fault_block_layer_free( layer ); ecl_kw_free( ecl_kw ); }
bool fault_block_layer_export( const fault_block_layer_type * layer , ecl_kw_type * faultblock_kw) { if (ecl_type_is_int(ecl_kw_get_data_type( faultblock_kw )) && (ecl_kw_get_size( faultblock_kw ) == ecl_grid_get_global_size( layer->grid ))) { int i,j; for (j=0; j < ecl_grid_get_ny( layer->grid ); j++) { for (i=0; i < ecl_grid_get_nx( layer->grid ); i++) { int g = ecl_grid_get_global_index3( layer->grid , i, j , layer->k ); int cell_value = layer_iget_cell_value( layer->layer , i , j ); ecl_kw_iset_int( faultblock_kw , g , cell_value); } } return true; } else return false; }
ecl_box::ecl_box(const ecl_grid_type * grid, int i1, int i2, int j1, int j2, int k1, int k2) : grid(grid), i1(std::min(i1,i2)), i2(std::max(i1,i2)), j1(std::min(j1,j2)), j2(std::max(j1,j2)), k1(std::min(k1,k2)), k2(std::max(k1,k2)) { for (int k=this->k1; k <= this->k2; k++) for (int j=this->j1; j <= this->j2; j++) for (int i=this->i1; i <= this->i2; i++) { int active_index = ecl_grid_get_active_index3(this->grid, i, j , k); if (active_index >= 0) this->active_index_list.push_back(active_index); this->global_index_list.push_back(ecl_grid_get_global_index3(this->grid, i, j, k)); } }
inline int field_config_global_index(const field_config_type * config, int i, int j, int k) { return ecl_grid_get_global_index3( config->grid , i,j,k); }
void test_create() { ecl_grid_type * ecl_grid; int nx = 100; int ny = 100; int nz = 10; double * DXV = util_malloc( nx * sizeof * DXV ); double * DYV = util_malloc( ny * sizeof * DYV ); double * DZV = util_malloc( nz * sizeof * DZV ); double * DEPTHZ = util_malloc( (nx + 1) * (ny + 1) * sizeof * DEPTHZ); for (int i=0; i < nx; i++) DXV[i] = 1.0 / nx; for (int j=0; j < ny; j++) DYV[j] = 1.0 / ny; for (int k=0; k < nz; k++) DZV[k] = 3.0 / nz; for (int j=0; j <= ny; j++) { double y = center_sum(DYV , j); for (int i=0; i <= nx; i++) { double x = center_sum(DXV , i); DEPTHZ[i + j*(nx + 1)] = zfunc( x,y ); } } ecl_grid = ecl_grid_alloc_dxv_dyv_dzv_depthz( nx,ny,nz,DXV , DYV , DZV , DEPTHZ , NULL); for (int k=0; k < nz; k++) { double z0 = center_sum(DZV , k ) - 0.5*DZV[0]; for (int j=0; j < ny; j++) { double y0 = center_sum(DYV , j ); for (int i=0; i < nx; i++) { double x0 = center_sum(DXV , i ); double xc,yc,zc; int g = ecl_grid_get_global_index3( ecl_grid , i , j , k ); ecl_grid_get_xyz1( ecl_grid , g , &xc , &yc , &zc); test_assert_double_equal( x0 , xc ); test_assert_double_equal( y0 , yc ); ecl_grid_get_cell_corner_xyz1( ecl_grid , g , 0 , &xc , &yc , &zc); test_assert_double_equal( z0 + zfunc(x0 , y0) , zc ); ecl_grid_get_cell_corner_xyz1( ecl_grid , g , 4, &xc , &yc , &zc); test_assert_double_equal( z0 + zfunc(x0 , y0) + DZV[k] , zc ); } } } free( DXV ); free( DYV ); free( DZV ); free( DEPTHZ ); ecl_grid_free( ecl_grid ); }