diff --git a/applications/resdata/grid_info.c b/applications/resdata/grid_info.c index 21c3f62a9..6094803d6 100644 --- a/applications/resdata/grid_info.c +++ b/applications/resdata/grid_info.c @@ -47,15 +47,6 @@ int main(int argc, char **argv) { } rd_grid_free(grid2); } - /* - printf("----\n"); - { - double * ri_points = util_calloc( rd_grid_get_global_size( rd_grid ) * 24 , sizeof * ri_points ); - rd_grid_ri_export( rd_grid , ri_points ); - free( ri_points ); - } - printf("----\n"); - */ rd_grid_free(rd_grid); } } diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a1e30ee97..557f2ec10 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -257,16 +257,13 @@ foreach( rd_path_access rd_grid_add_nnc rd_grid_copy - rd_grid_create rd_grid_unit_system rd_grid_export rd_grid_init_fwrite rd_grid_reset_actnum - rd_grid_ext_actnum rd_nnc_export_intersect rd_sum_restart rd_sum_data_intermediate_test - rd_grid_cell_contains rd_unsmry_loader_test rd_kw_space_pad rd_kw_cmp_string diff --git a/lib/include/resdata/rd_grid.hpp b/lib/include/resdata/rd_grid.hpp index 0d857b351..82dbbfb7f 100644 --- a/lib/include/resdata/rd_grid.hpp +++ b/lib/include/resdata/rd_grid.hpp @@ -27,34 +27,12 @@ typedef struct rd_grid_struct rd_grid_type; bool rd_grid_have_coarse_cells(const rd_grid_type *main_grid); bool rd_grid_cell_in_coarse_group1(const rd_grid_type *main_grid, int global_index); -bool rd_grid_cell_in_coarse_group3(const rd_grid_type *main_grid, int i, int j, - int k); int rd_grid_get_num_coarse_groups(const rd_grid_type *main_grid); rd_coarse_cell_type *rd_grid_iget_coarse_group(const rd_grid_type *rd_grid, int coarse_nr); -rd_coarse_cell_type *rd_grid_get_cell_coarse_group1(const rd_grid_type *rd_grid, - int global_index); -rd_coarse_cell_type *rd_grid_get_cell_coarse_group3(const rd_grid_type *rd_grid, - int i, int j, int k); - -int rd_grid_get_cell_twist1(const rd_grid_type *rd_grid, int global_index); -int rd_grid_get_cell_twist3(const rd_grid_type *rd_grid, int i, int j, int k); - void rd_grid_get_column_property(const rd_grid_type *rd_grid, const rd_kw_type *rd_kw, int i, int j, double_vector_type *column); -int rd_grid_get_global_index_from_xy_top(const rd_grid_type *rd_grid, double x, - double y); -int rd_grid_get_global_index_from_xy_bottom(const rd_grid_type *rd_grid, - double x, double y); -rd_grid_type *rd_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, - const double *dx, const double *dy, - const double *dz, const double *tops, - const int *actnum); - -void rd_grid_get_cell_corner_xyz3(const rd_grid_type *grid, int i, int j, int k, - int corner_nr, double *xpos, double *ypos, - double *zpos); void rd_grid_get_cell_corner_xyz1(const rd_grid_type *grid, int global_index, int corner_nr, double *xpos, double *ypos, double *zpos); @@ -64,50 +42,32 @@ void rd_grid_get_corner_xyz(const rd_grid_type *grid, int i, int j, int k, double rd_grid_get_cell_dx1A(const rd_grid_type *grid, int active_index); double rd_grid_get_cell_dy1A(const rd_grid_type *grid, int active_index); double rd_grid_get_cell_dz1A(const rd_grid_type *grid, int active_index); -double rd_grid_get_cell_thickness1A(const rd_grid_type *grid, int active_index); double rd_grid_get_cell_dx1(const rd_grid_type *grid, int global_index); double rd_grid_get_cell_dy1(const rd_grid_type *grid, int global_index); double rd_grid_get_cell_dz1(const rd_grid_type *grid, int global_index); double rd_grid_get_cell_thickness1(const rd_grid_type *grid, int global_index); -double rd_grid_get_cell_dx3(const rd_grid_type *grid, int i, int j, int k); -double rd_grid_get_cell_dy3(const rd_grid_type *grid, int i, int j, int k); -double rd_grid_get_cell_dz3(const rd_grid_type *grid, int i, int j, int k); -double rd_grid_get_cell_thickness3(const rd_grid_type *grid, int i, int j, - int k); - void rd_grid_get_distance(const rd_grid_type *grid, int global_index1, int global_index2, double *dx, double *dy, double *dz); double rd_grid_get_cdepth1A(const rd_grid_type *grid, int active_index); double rd_grid_get_cdepth1(const rd_grid_type *grid, int global_index); -double rd_grid_get_cdepth3(const rd_grid_type *grid, int i, int j, int k); int rd_grid_get_global_index_from_xy(const rd_grid_type *rd_grid, int k, bool lower_layer, double x, double y); bool rd_grid_cell_contains_xyz1(const rd_grid_type *rd_grid, int global_index, double x, double y, double z); -bool rd_grid_cell_contains_xyz3(const rd_grid_type *rd_grid, int i, int j, - int k, double x, double y, double z); double rd_grid_get_cell_volume1(const rd_grid_type *rd_grid, int global_index); -double rd_grid_get_cell_volume3(const rd_grid_type *rd_grid, int i, int j, - int k); double rd_grid_get_cell_volume1A(const rd_grid_type *rd_grid, int active_index); bool rd_grid_cell_contains1(const rd_grid_type *grid, int global_index, double x, double y, double z); -bool rd_grid_cell_contains3(const rd_grid_type *grid, int i, int j, int k, - double x, double y, double z); int rd_grid_get_global_index_from_xyz(rd_grid_type *grid, double x, double y, double z, int start_index); -bool rd_grid_get_ijk_from_xyz(rd_grid_type *grid, double x, double y, double z, - int start_index, int *i, int *j, int *k); bool rd_grid_get_ij_from_xy(const rd_grid_type *grid, double x, double y, int k, int *i, int *j); const char *rd_grid_get_name(const rd_grid_type *); int rd_grid_get_active_index3(const rd_grid_type *rd_grid, int i, int j, int k); int rd_grid_get_active_index1(const rd_grid_type *rd_grid, int global_index); -int rd_grid_get_active_fracture_index3(const rd_grid_type *rd_grid, int i, - int j, int k); int rd_grid_get_active_fracture_index1(const rd_grid_type *rd_grid, int global_index); bool rd_grid_cell_active3(const rd_grid_type *, int, int, int); @@ -118,50 +78,25 @@ int rd_grid_get_global_index1A(const rd_grid_type *rd_grid, int active_index); int rd_grid_get_global_index1F(const rd_grid_type *rd_grid, int active_fracture_index); -const nnc_info_type *rd_grid_get_cell_nnc_info3(const rd_grid_type *grid, int i, - int j, int k); const nnc_info_type *rd_grid_get_cell_nnc_info1(const rd_grid_type *grid, int global_index); void rd_grid_add_self_nnc(rd_grid_type *grid1, int g1, int g2, int nnc_index); -void rd_grid_add_self_nnc_list(rd_grid_type *grid, const int *g1_list, - const int *g2_list, int num_nnc); - rd_grid_type *rd_grid_alloc_GRDECL_kw(int nx, int ny, int nz, const rd_kw_type *zcorn_kw, const rd_kw_type *coord_kw, const rd_kw_type *actnum_kw, const rd_kw_type *mapaxes_kw); -rd_grid_type *rd_grid_alloc_GRDECL_data(int, int, int, const float *, - const float *, const int *, - bool apply_mapaxes, - const float *mapaxes); -rd_grid_type *rd_grid_alloc_GRID_data(int num_coords, int nx, int ny, int nz, - int coords_size, int **coords, - float **corners, bool apply_mapaxes, - const float *mapaxes); rd_grid_type *rd_grid_alloc(const char *); -rd_grid_type *rd_grid_alloc_ext_actnum(const char *, const int *ext_actnum); rd_grid_type *rd_grid_load_case(const char *case_input); rd_grid_type *rd_grid_load_case__(const char *case_input, bool apply_mapaxes); rd_grid_type *rd_grid_alloc_rectangular(int nx, int ny, int nz, double dx, double dy, double dz, const int *actnum); -rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, const double *ivec, - const double *jvec, const double *kvec, - const int *actnum); -rd_grid_type *rd_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, - const double *dxv, const double *dyv, - const double *dzv, const int *actnum); -rd_grid_type * -rd_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, - const double *dyv, const double *dzv, - const double *depthz, const int *actnum); rd_kw_type *rd_grid_alloc_volume_kw(const rd_grid_type *grid, bool active_size); rd_kw_type *rd_grid_alloc_mapaxes_kw(const rd_grid_type *grid); rd_kw_type *rd_grid_alloc_coord_kw(const rd_grid_type *grid); bool rd_grid_exists(const char *case_input); -char *rd_grid_alloc_case_filename(const char *case_input); void rd_grid_free(rd_grid_type *); void rd_grid_free__(void *arg); @@ -177,9 +112,6 @@ void rd_grid_get_ijk1(const rd_grid_type *, int global_index, int *, int *, int *); void rd_grid_get_ijk1A(const rd_grid_type *, int active_index, int *, int *, int *); -void rd_grid_get_ijk_from_active_index(const rd_grid_type *, int, int *, int *, - int *); - void rd_grid_get_xyz3(const rd_grid_type *, int, int, int, double *, double *, double *); void rd_grid_get_xyz1(const rd_grid_type *grid, int global_index, double *xpos, @@ -187,11 +119,6 @@ void rd_grid_get_xyz1(const rd_grid_type *grid, int global_index, double *xpos, void rd_grid_get_xyz1A(const rd_grid_type *grid, int active_index, double *xpos, double *ypos, double *zpos); -bool rd_grid_get_xyz_inside1(const rd_grid_type *grid, int global_index, - double *xpos, double *ypos, double *zpos); -bool rd_grid_get_xyz_inside3(const rd_grid_type *grid, int i, int j, int k, - double *xpos, double *ypos, double *zpos); - int rd_grid_get_global_size(const rd_grid_type *rd_grid); bool rd_grid_compare(const rd_grid_type *g1, const rd_grid_type *g2, bool include_lgr, bool include_nnc, bool verbose); @@ -199,7 +126,6 @@ int rd_grid_get_active_size(const rd_grid_type *rd_grid); double rd_grid_get_bottom1(const rd_grid_type *grid, int global_index); double rd_grid_get_bottom3(const rd_grid_type *grid, int i, int j, int k); -double rd_grid_get_bottom1A(const rd_grid_type *grid, int active_index); double rd_grid_get_top1(const rd_grid_type *grid, int global_index); double rd_grid_get_top3(const rd_grid_type *grid, int i, int j, int k); double rd_grid_get_top1A(const rd_grid_type *grid, int active_index); @@ -207,33 +133,13 @@ double rd_grid_get_top2(const rd_grid_type *grid, int i, int j); double rd_grid_get_bottom2(const rd_grid_type *grid, int i, int j); int rd_grid_locate_depth(const rd_grid_type *grid, double depth, int i, int j); -void rd_grid_alloc_blocking_variables(rd_grid_type *, int); -void rd_grid_init_blocking(rd_grid_type *); -double rd_grid_block_eval3d(rd_grid_type *grid, int i, int j, int k, - block_function_ftype *blockf); -int rd_grid_get_block_count3d(const rd_grid_type *rd_grid, int i, int j, int k); -bool rd_grid_block_value_3d(rd_grid_type *, double, double, double, double); - bool rd_grid_cell_invalid1(const rd_grid_type *rd_grid, int global_index); -bool rd_grid_cell_invalid3(const rd_grid_type *rd_grid, int i, int j, int k); -double rd_grid_cell_invalid1A(const rd_grid_type *grid, int active_index); bool rd_grid_cell_valid1(const rd_grid_type *rd_grid, int global_index); -bool rd_grid_cell_valid3(const rd_grid_type *rd_grid, int i, int j, int k); -double rd_grid_cell_valid1A(const rd_grid_type *grid, int active_index); void rd_grid_dump(const rd_grid_type *grid, FILE *stream); void rd_grid_dump_ascii(rd_grid_type *grid, bool active_only, FILE *stream); -void rd_grid_dump_ascii_cell1(rd_grid_type *grid, int global_index, - FILE *stream, const double *offset); -void rd_grid_dump_ascii_cell3(rd_grid_type *grid, int i, int j, int k, - FILE *stream, const double *offset); - /* lgr related functions */ -const rd_grid_type *rd_grid_get_cell_lgr3(const rd_grid_type *grid, int i, - int j, int k); -const rd_grid_type *rd_grid_get_cell_lgr1A(const rd_grid_type *grid, - int active_index); const rd_grid_type *rd_grid_get_cell_lgr1(const rd_grid_type *grid, int global_index); int rd_grid_get_num_lgr(const rd_grid_type *main_grid); @@ -248,33 +154,16 @@ bool rd_grid_has_lgr(const rd_grid_type *main_grid, const char *__lgr_name); bool rd_grid_has_lgr_nr(const rd_grid_type *main_grid, int lgr_nr); const char *rd_grid_iget_lgr_name(const rd_grid_type *rd_grid, int lgr_index); const char *rd_grid_get_lgr_name(const rd_grid_type *rd_grid, int lgr_nr); -stringlist_type *rd_grid_alloc_lgr_name_list(const rd_grid_type *rd_grid); -int rd_grid_get_parent_cell1(const rd_grid_type *grid, int global_index); -int rd_grid_get_parent_cell3(const rd_grid_type *grid, int i, int j, int k); const rd_grid_type *rd_grid_get_global_grid(const rd_grid_type *grid); -bool rd_grid_is_lgr(const rd_grid_type *rd_grid); double rd_grid_get_property(const rd_grid_type *rd_grid, const rd_kw_type *rd_kw, int i, int j, int k); -float rd_grid_get_float_property(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, int k); -double rd_grid_get_double_property(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, - int k); -int rd_grid_get_int_property(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, int k); - void rd_grid_grdecl_fprintf_kw(const rd_grid_type *rd_grid, const rd_kw_type *rd_kw, const char *special_header, FILE *stream, double double_default); bool rd_grid_test_lgr_consistency(const rd_grid_type *rd_grid); -void rd_grid_fwrite_dims(const rd_grid_type *grid, fortio_type *init_file, - ert_rd_unit_enum output_unit); -void rd_grid_fwrite_depth(const rd_grid_type *grid, fortio_type *init_file, - ert_rd_unit_enum ouput_unit); - void rd_grid_fwrite_EGRID(rd_grid_type *grid, const char *filename, bool metric_output); void rd_grid_fwrite_EGRID2(rd_grid_type *grid, const char *filename, @@ -290,30 +179,13 @@ void rd_grid_fprintf_grdecl2(rd_grid_type *grid, FILE *stream, int rd_grid_zcorn_index__(int nx, int ny, int i, int j, int k, int c); int rd_grid_zcorn_index(const rd_grid_type *grid, int i, int j, int k, int c); -rd_grid_type *rd_grid_alloc_EGRID(const char *grid_file, bool apply_mapaxes); -rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes); -float *rd_grid_alloc_zcorn_data(const rd_grid_type *grid); rd_kw_type *rd_grid_alloc_zcorn_kw(const rd_grid_type *grid); -int *rd_grid_alloc_actnum_data(const rd_grid_type *grid); rd_kw_type *rd_grid_alloc_actnum_kw(const rd_grid_type *grid); -rd_kw_type *rd_grid_alloc_hostnum_kw(const rd_grid_type *grid); -rd_kw_type *rd_grid_alloc_gridhead_kw(int nx, int ny, int nz, int grid_nr); rd_grid_type *rd_grid_alloc_copy(const rd_grid_type *src_grid); -rd_grid_type *rd_grid_alloc_processed_copy(const rd_grid_type *src_grid, - const double *zcorn, - const int *actnum); - -void rd_grid_ri_export(const rd_grid_type *rd_grid, double *ri_points); -void rd_grid_cell_ri_export(const rd_grid_type *rd_grid, int global_index, - double *ri_points); - bool rd_grid_dual_grid(const rd_grid_type *rd_grid); int rd_grid_get_num_nnc(const rd_grid_type *grid); -bool rd_grid_cell_regular3(const rd_grid_type *rd_grid, int i, int j, int k); -bool rd_grid_cell_regular1(const rd_grid_type *rd_grid, int global_index); - void rd_grid_init_zcorn_data(const rd_grid_type *grid, float *zcorn); void rd_grid_init_zcorn_data_double(const rd_grid_type *grid, double *zcorn); int rd_grid_get_zcorn_size(const rd_grid_type *grid); @@ -353,18 +225,5 @@ UTIL_SAFE_CAST_HEADER(rd_grid); #ifdef __cplusplus } -namespace rd { - -rd_grid_type *rd_grid_alloc_GRDECL_data(int nx, int ny, int nz, - const double *zcorn, - const double *coord, const int *actnum, - bool apply_mapaxes, - const float *mapaxes); - -} - -#ifdef __cplusplus -#endif - #endif #endif diff --git a/lib/resdata/rd_grid.cpp b/lib/resdata/rd_grid.cpp index 326c766d8..93f238f6f 100644 --- a/lib/resdata/rd_grid.cpp +++ b/lib/resdata/rd_grid.cpp @@ -268,7 +268,6 @@ - int rd_grid_get_num_coarse_groups( const rd_grid_type * main_grid ) - bool rd_grid_have_coarse_cells( const rd_grid_type * main_grid ) - rd_coarse_cell_type * rd_grid_iget_coarse_group( const rd_grid_type * rd_grid , int coarse_nr ); - - rd_coarse_cell_type * rd_grid_get_cell_coarse_group1( const rd_grid_type * rd_grid , int global_index); In addition to the API presented by the rd_coarse_cell.c implementation. */ @@ -1942,21 +1941,6 @@ rd_coarse_cell_type *rd_grid_iget_coarse_group(const rd_grid_type *rd_grid, return (rd_coarse_cell_type *)vector_iget(rd_grid->coarse_cells, coarse_nr); } -rd_coarse_cell_type *rd_grid_get_cell_coarse_group1(const rd_grid_type *rd_grid, - int global_index) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); - if (cell->coarse_group == COARSE_GROUP_NONE) - return NULL; - else - return rd_grid_iget_coarse_group(rd_grid, cell->coarse_group); -} - -rd_coarse_cell_type *rd_grid_get_cell_coarse_group3(const rd_grid_type *rd_grid, - int i, int j, int k) { - int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - return rd_grid_get_cell_coarse_group1(rd_grid, global_index); -} - bool rd_grid_cell_in_coarse_group1(const rd_grid_type *main_grid, int global_index) { rd_cell_type *cell = rd_grid_get_cell(main_grid, global_index); @@ -1966,12 +1950,6 @@ bool rd_grid_cell_in_coarse_group1(const rd_grid_type *main_grid, return true; } -bool rd_grid_cell_in_coarse_group3(const rd_grid_type *main_grid, int i, int j, - int k) { - return rd_grid_cell_in_coarse_group1( - main_grid, rd_grid_get_global_index3(main_grid, i, j, k)); -} - static void rd_grid_pillar_cross_planes(const point_type *p0, double e_x, double e_y, double e_z, const double *z, double *x, double *y) { @@ -2543,79 +2521,8 @@ rd_grid_type *rd_grid_alloc_copy(const rd_grid_type *src_grid) { return copy_grid; } -/* - Does not handle LGR -*/ -rd_grid_type *rd_grid_alloc_processed_copy(const rd_grid_type *src_grid, - const double *zcorn, - const int *actnum) { - rd_grid_type *grid; - - if (zcorn == NULL) { - grid = rd_grid_alloc_copy__(src_grid, NULL); - if (actnum) - rd_grid_reset_actnum(grid, actnum); - } else { - int nx, ny, nz, na; - int zcorn_size = rd_grid_get_zcorn_size(src_grid); - float *zcorn_float = - (float *)util_malloc(zcorn_size * sizeof *zcorn_float); - float *coord = rd_grid_alloc_coord_data(src_grid); - float *mapaxes = NULL; - - if (rd_grid_get_mapaxes(src_grid)) { - mapaxes = (float *)util_malloc(6 * sizeof *mapaxes); - rd_grid_init_mapaxes_data_float(src_grid, mapaxes); - } - rd_grid_get_dims(src_grid, &nx, &ny, &nz, &na); - for (int i = 0; i < zcorn_size; i++) - zcorn_float[i] = zcorn[i]; - - grid = rd_grid_alloc_GRDECL_data(nx, ny, nz, zcorn_float, coord, actnum, - src_grid->use_mapaxes, mapaxes); - - free(mapaxes); - free(coord); - free(zcorn_float); - } - - return grid; -} - -/* - If you create/load data for the various fields, this function can be - used to create a GRID instance, without going through a GRID/EGRID - file - currently the implementation does not support the creation of - a lgr hierarchy - or cell coarsening. -*/ - -rd_grid_type *rd_grid_alloc_GRDECL_data(int nx, int ny, int nz, - const float *zcorn, const float *coord, - const int *actnum, bool apply_mapaxes, - const float *mapaxes) { - - ert_rd_unit_enum unit_system = RD_METRIC_UNITS; - return rd_grid_alloc_GRDECL_data__( - NULL, unit_system, FILEHEAD_SINGLE_POROSITY, apply_mapaxes, nx, ny, nz, - zcorn, coord, actnum, mapaxes, NULL, 0); -} - -namespace rd { - -rd_grid_type *rd_grid_alloc_GRDECL_data(int nx, int ny, int nz, - const double *zcorn, - const double *coord, const int *actnum, - bool apply_mapaxes, - const float *mapaxes) { - ert_rd_unit_enum unit_system = RD_METRIC_UNITS; - return rd_grid_alloc_GRDECL_data__( - NULL, unit_system, FILEHEAD_SINGLE_POROSITY, apply_mapaxes, nx, ny, nz, - zcorn, coord, actnum, mapaxes, NULL, 0); -} - -} // namespace rd - -const float *rd_grid_get_mapaxes_from_kw__(const rd_kw_type *mapaxes_kw) { +static const float * +rd_grid_get_mapaxes_from_kw__(const rd_kw_type *mapaxes_kw) { const float *mapaxes_data = rd_kw_get_float_ptr(mapaxes_kw); float x1 = mapaxes_data[2]; @@ -2681,6 +2588,20 @@ static rd_grid_type *rd_grid_alloc_GRDECL_kw__( } } +static rd_kw_type *rd_grid_alloc_gridhead_kw(int nx, int ny, int nz, + int grid_nr) { + rd_kw_type *gridhead_kw = rd_kw_alloc(GRIDHEAD_KW, GRIDHEAD_SIZE, RD_INT); + rd_kw_scalar_set_int(gridhead_kw, 0); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_TYPE_INDEX, + GRIDHEAD_GRIDTYPE_CORNERPOINT); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NX_INDEX, nx); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NY_INDEX, ny); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NZ_INDEX, nz); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NUMRES_INDEX, 1); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_LGR_INDEX, grid_nr); + return gridhead_kw; +} + /** If you create/load rd_kw instances for the various fields, this function can be used to create a GRID instance, without going @@ -2766,19 +2687,6 @@ void rd_grid_add_self_nnc(rd_grid_type *grid, int cell_index1, int cell_index2, nnc_info_add_nnc(grid_cell->nnc_info, grid->lgr_nr, cell_index2, nnc_index); } -/* - This function will add all the nnc connections given by the g1_list - and g2_list arrays. The ncc connections will be added with - consecutively running nnc_index = [0,num_nnc). -*/ - -void rd_grid_add_self_nnc_list(rd_grid_type *grid, const int *g1_list, - const int *g2_list, int num_nnc) { - int i; - for (i = 0; i < num_nnc; i++) - rd_grid_add_self_nnc(grid, g1_list[i], g2_list[i], i); -} - /* This function populates nnc_info for cells with non neighbour connections. For cells C1 and C2 the function will only add the directed link: @@ -2996,11 +2904,6 @@ static rd_grid_type *rd_grid_alloc_EGRID__(rd_grid_type *main_grid, } } -static rd_grid_type *rd_grid_alloc_GRID_all_grids(const char *filename) { - util_abort("%s .GRID files - %s - not supported \n", __func__, filename); - return NULL; -} - static rd_grid_type *rd_grid_alloc_EGRID_all_grids(const char *grid_file, bool apply_mapaxes, const int *ext_actnum) { @@ -3049,7 +2952,8 @@ static rd_grid_type *rd_grid_alloc_EGRID_all_grids(const char *grid_file, } } -rd_grid_type *rd_grid_alloc_EGRID(const char *grid_file, bool apply_mapaxes) { +static rd_grid_type *rd_grid_alloc_EGRID(const char *grid_file, + bool apply_mapaxes) { return rd_grid_alloc_EGRID_all_grids(grid_file, apply_mapaxes, NULL); } @@ -3081,22 +2985,6 @@ static rd_grid_type *rd_grid_alloc_GRID_data__( } } -/* - coords[num_coords][coords_size] - corners[num_coords][24] -*/ - -rd_grid_type *rd_grid_alloc_GRID_data(int num_coords, int nx, int ny, int nz, - int coords_size, int **coords, - float **corners, bool apply_mapaxes, - const float *mapaxes) { - ert_rd_unit_enum unit_system = RD_METRIC_UNITS; - return rd_grid_alloc_GRID_data__( - NULL, num_coords, unit_system, - FILEHEAD_SINGLE_POROSITY, /* Does currently not support to determine dualp_flag from inspection. */ - apply_mapaxes, nx, ny, nz, 0, coords_size, coords, corners, mapaxes); -} - static int rd_grid_dual_porosity_GRID_check(rd_file_type *rd_file) { rd_kw_type *dimens_kw = rd_file_iget_named_kw(rd_file, DIMENS_KW, 0); int nx = rd_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); @@ -3257,7 +3145,8 @@ static rd_grid_type *rd_grid_alloc_GRID__(rd_grid_type *global_grid, return grid; } -rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes) { +static rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, + bool apply_mapaxes) { rd_file_enum file_type; file_type = rd_get_file_type(grid_file, NULL, NULL); @@ -3311,9 +3200,11 @@ rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes) { cells and 0 for inactive cells. The actnum array can be NULL, in which case all cells will be active. */ -rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, const double *ivec, - const double *jvec, const double *kvec, - const int *actnum) { +static rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, + const double *ivec, + const double *jvec, + const double *kvec, + const int *actnum) { ert_rd_unit_enum unit_system = RD_METRIC_UNITS; rd_grid_type *grid = rd_grid_alloc_empty( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, 0, true); @@ -3365,213 +3256,6 @@ rd_grid_type *rd_grid_alloc_rectangular(int nx, int ny, int nz, double dx, return rd_grid_alloc_regular(nx, ny, nz, ivec, jvec, kvec, actnum); } -/** - This function will allocate a new grid with logical dimensions nx x - ny x nz. The cells in the grid are spanned by the dxv, dyv and dzv - vectors which are of size nx, ny and nz and specify the thickness - of a cell in x, y, and in z direction. - - The actnum argument is a pointer to an integer array of length - nx*ny*nz where actnum[i + j*nx + k*nx*ny] == 1 for active cells and - 0 for inactive cells. The actnum array can be NULL, in which case - all cells will be active. */ -rd_grid_type *rd_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, - const double *dxv, const double *dyv, - const double *dzv, const int *actnum) { - ert_rd_unit_enum unit_system = RD_METRIC_UNITS; - rd_grid_type *grid = rd_grid_alloc_empty( - NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, - /*lgr_nr=*/0, /*init_valid=*/true); - if (grid) { - double ivec[3] = {0, 0, 0}; - double jvec[3] = {0, 0, 0}; - double kvec[3] = {0, 0, 0}; - - const double grid_offset[3] = {0, 0, 0}; - double offset[3]; - int i, j, k; - offset[2] = grid_offset[2]; - for (k = 0; k < nz; k++) { - kvec[2] = dzv[k]; - offset[1] = grid_offset[1]; - for (j = 0; j < ny; j++) { - jvec[1] = dyv[j]; - offset[0] = grid_offset[0]; - for (i = 0; i < nx; i++) { - int global_index = i + j * nx + k * nx * ny; - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); - ivec[0] = dxv[i]; - - rd_cell_init_regular(cell, offset, i, j, k, global_index, - ivec, jvec, kvec, actnum); - offset[0] += dxv[i]; - } - offset[1] += dyv[j]; - } - offset[2] += dzv[k]; - } - rd_grid_update_index(grid); - } - - return grid; -} - -rd_grid_type * -rd_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, - const double *dyv, const double *dzv, - const double *depthz, const int *actnum) { - ert_rd_unit_enum unit_system = RD_METRIC_UNITS; - rd_grid_type *grid = rd_grid_alloc_empty( - NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, - /*lgr_nr=*/0, /*init_valid=*/true); - - /* First layer - where the DEPTHZ keyword applies. */ - if (grid) { - int i, j; - int k = 0; - double y0 = 0; - for (j = 0; j < ny; j++) { - double x0 = 0; - for (i = 0; i < nx; i++) { - int global_index = i + j * nx + k * nx * ny; - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); - double z0 = depthz[i + j * (nx + 1)]; - double z1 = depthz[i + 1 + j * (nx + 1)]; - double z2 = depthz[i + (j + 1) * (nx + 1)]; - double z3 = depthz[i + 1 + (j + 1) * (nx + 1)]; - - point_set(&cell->corner_list[0], x0, y0, z0); - point_set(&cell->corner_list[1], x0 + dxv[i], y0, z1); - point_set(&cell->corner_list[2], x0, y0 + dyv[j], z2); - point_set(&cell->corner_list[3], x0 + dxv[i], y0 + dyv[j], z3); - { - int c; - for (c = 0; c < 4; c++) { - cell->corner_list[c + 4] = cell->corner_list[c]; - point_shift(&cell->corner_list[c + 4], 0, 0, dzv[0]); - } - } - x0 += dxv[i]; - } - y0 += dyv[j]; - } - } - - /* Remaining layers */ - if (grid) { - int i, j, k; - for (k = 1; k < nz; k++) { - for (j = 0; j < ny; j++) { - for (i = 0; i < nx; i++) { - int g2 = i + j * nx + k * nx * ny; - int g1 = i + j * nx + (k - 1) * nx * ny; - rd_cell_type *cell2 = rd_grid_get_cell(grid, g2); - rd_cell_type *cell1 = rd_grid_get_cell(grid, g1); - int c; - - for (c = 0; c < 4; c++) { - cell2->corner_list[c] = cell1->corner_list[c + 4]; - cell2->corner_list[c + 4] = cell1->corner_list[c + 4]; - point_shift(&cell2->corner_list[c + 4], 0, 0, dzv[k]); - } - } - } - } - } - - if (grid) { - int i, j, k; - for (k = 0; k < nz; k++) { - for (j = 0; j < ny; j++) { - for (i = 0; i < nx; i++) { - int global_index = i + j * nx + k * nx * ny; - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); - - if (actnum) - cell->active = actnum[global_index]; - else - cell->active = CELL_ACTIVE; - } - } - } - } - - if (grid) - rd_grid_update_index(grid); - - return grid; -} - -/** - This is a really broken function which is here only to support - creating rectangualar grids from OPM. The vectors dx,dy,dz and tops - are all of length nx*ny*nz. In principle all values of these four - arrays are independent - but taking that all out will create some - really weird looking grids. For physical correctness there should - be many constraints among the different values. - - The x and y position of a cell is found by adding the increments - from dx and dy, whereas the vertical position is read dircetly out - of the tops array. - - The ECLIPSE input format only requires size(dz) >= nx*ny and the - same for tops. The remaining layers will then be extrapolated; such - trickery must be performed before calling this function. -*/ - -rd_grid_type *rd_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, - const double *dx, const double *dy, - const double *dz, const double *tops, - const int *actnum) { - ert_rd_unit_enum unit_system = RD_METRIC_UNITS; - rd_grid_type *grid = rd_grid_alloc_empty( - NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, 0, true); - if (grid) { - int i, j, k; - double *y0 = (double *)util_calloc(nx, sizeof *y0); - - for (k = 0; k < nz; k++) { - for (i = 0; i < nx; i++) { - y0[i] = 0; - } - for (j = 0; j < ny; j++) { - double x0 = 0; - for (i = 0; i < nx; i++) { - int g = i + j * nx + k * nx * ny; - rd_cell_type *cell = rd_grid_get_cell(grid, g); - double z0 = tops[g]; - - point_set(&cell->corner_list[0], x0, y0[i], z0); - point_set(&cell->corner_list[1], x0 + dx[g], y0[i], z0); - point_set(&cell->corner_list[2], x0, y0[i] + dy[g], z0); - point_set(&cell->corner_list[3], x0 + dx[g], y0[i] + dy[g], - z0); - - point_set(&cell->corner_list[4], x0, y0[i], z0 + dz[g]); - point_set(&cell->corner_list[5], x0 + dx[g], y0[i], - z0 + dz[g]); - point_set(&cell->corner_list[6], x0, y0[i] + dy[g], - z0 + dz[g]); - point_set(&cell->corner_list[7], x0 + dx[g], y0[i] + dy[g], - z0 + dz[g]); - - x0 += dx[g]; - y0[i] += dy[g]; - - if (actnum != NULL) - cell->active = actnum[g]; - else - cell->active = CELL_ACTIVE; - } - } - } - free(y0); - - rd_grid_update_index(grid); - } - return grid; -} - /** This function will allocate a rd_grid instance. As input it takes a filename, which can be both a GRID file and an EGRID file (both @@ -3583,7 +3267,8 @@ rd_grid_type *rd_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, with these keywords. */ -rd_grid_type *rd_grid_alloc__(const char *grid_file, bool apply_mapaxes) { +static rd_grid_type *rd_grid_alloc__(const char *grid_file, + bool apply_mapaxes) { rd_file_enum file_type; rd_grid_type *rd_grid = NULL; @@ -3604,129 +3289,6 @@ rd_grid_type *rd_grid_alloc(const char *grid_file) { return rd_grid_alloc__(grid_file, apply_mapaxes); } -// This function is used to override use of the keyword ACTNUM from the EGRID file. -// ext_actnum must have size equal to the number of cells in the main grid -// if ext_actnum = NULL, actnum is taken from file, otherwise ext_actnums -// determines which cells are active. -rd_grid_type *rd_grid_alloc_ext_actnum(const char *grid_file, - const int *ext_actnum) { - rd_file_enum file_type = rd_get_file_type(grid_file, NULL, NULL); - if (file_type == RD_EGRID_FILE) - return rd_grid_alloc_EGRID_all_grids(grid_file, true, ext_actnum); - else if (file_type == RD_GRID_FILE) - rd_grid_alloc_GRID_all_grids(grid_file); - else - util_abort("%s must have .EGRID file - %s not recognized \n", __func__, - grid_file); - - return NULL; -} - -static void rd_grid_file_nactive_dims(fortio_type *data_fortio, int *dims) { - if (data_fortio) { - if (rd_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { - rd_kw_type *intehead_kw = rd_kw_fread_alloc(data_fortio); - dims[3] = rd_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); - rd_kw_free(intehead_kw); - } - } -} - -static bool rd_grid_file_EGRID_dims(fortio_type *grid_fortio, - fortio_type *data_fortio, int *dims) { - - if (rd_kw_fseek_kw(GRIDHEAD_KW, false, false, grid_fortio)) { - { - rd_kw_type *gridhead_kw = rd_kw_fread_alloc(grid_fortio); - dims[0] = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); - dims[1] = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); - dims[2] = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); - - rd_kw_free(gridhead_kw); - } - rd_grid_file_nactive_dims(data_fortio, dims); - return true; - } else - return false; -} - -static bool rd_grid_file_GRID_dims(fortio_type *grid_fortio, - fortio_type *data_fortio, int *dims) { - - if (rd_kw_fseek_kw(DIMENS_KW, false, false, grid_fortio)) { - { - rd_kw_type *dimens_kw = rd_kw_fread_alloc(grid_fortio); - dims[0] = rd_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); - dims[1] = rd_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); - dims[2] = rd_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); - - rd_kw_free(dimens_kw); - } - - rd_grid_file_nactive_dims(data_fortio, dims); - return true; - } else - return false; -} - -/** - Will check the grid dimensions from the input grid file - @grid_filename; the input file must be a GRID/EGRID file. On exit - the dims array will be filled as: - - dims[0] = nx; - dims[1] = ny; - dims[2] = nz; - - Optionally you can in addition supply the name of a restart or INIT - file in the second file argument - if-and-only-if, that filename - points to an existing file the fourth element in the dims array - will be set as: - - dims[3] = nactive; - - The function as a whole will return true if the grid dimensions - (nx,ny,nz) are successfully set. If the dimensions are not set the - dims vector is not touched. -*/ - -bool rd_grid_file_dims(const char *grid_filename, - const char *init_restart_filename, int *dims) { - bool input_file_OK = false; - bool grid_fmt_file; - rd_file_enum grid_file_type = - rd_get_file_type(grid_filename, &grid_fmt_file, NULL); - - if ((grid_file_type == RD_GRID_FILE) || (grid_file_type == RD_EGRID_FILE)) { - fortio_type *grid_fortio = - fortio_open_reader(grid_filename, grid_fmt_file, RD_ENDIAN_FLIP); - if (grid_fortio) { - fortio_type *data_fortio = NULL; - bool data_fmt_file; - - if (init_restart_filename) { - rd_get_file_type(init_restart_filename, &data_fmt_file, NULL); - data_fortio = fortio_open_reader(init_restart_filename, - data_fmt_file, RD_ENDIAN_FLIP); - } - - if (grid_file_type == RD_GRID_FILE) - input_file_OK = - rd_grid_file_GRID_dims(grid_fortio, data_fortio, dims); - else - input_file_OK = - rd_grid_file_EGRID_dims(grid_fortio, data_fortio, dims); - - if (data_fortio) - fortio_fclose(data_fortio); - - fortio_fclose(grid_fortio); - } - } - - return input_file_OK; -} - /** Will load the grid corresponding to the input @input_case; depending on the value of @input_case many different paths will be @@ -3751,7 +3313,7 @@ bool rd_grid_file_dims(const char *grid_filename, files can be found. */ -char *rd_grid_alloc_case_filename(const char *case_input) { +static char *rd_grid_alloc_case_filename(const char *case_input) { rd_file_enum file_type; bool fmt_file; file_type = rd_get_file_type(case_input, &fmt_file, NULL); @@ -4246,8 +3808,9 @@ static bool concave_cell_contains(const rd_cell_type *cell, int method, - See the documentation of rd_grid_on_cell_face for caveats regarding containtment of points of cell faces. */ -bool rd_grid_cell_contains_xyz3(const rd_grid_type *rd_grid, int i, int j, - int k, double x, double y, double z) { +static bool rd_grid_cell_contains_xyz3(const rd_grid_type *rd_grid, int i, + int j, int k, double x, double y, + double z) { point_type p; rd_cell_type *cell = rd_grid_get_cell(rd_grid, rd_grid_get_global_index3(rd_grid, i, j, k)); @@ -4314,17 +3877,6 @@ int rd_grid_get_global_index_from_xy(const rd_grid_type *rd_grid, int k, return -1; /* Did not find x,y */ } -int rd_grid_get_global_index_from_xy_top(const rd_grid_type *rd_grid, double x, - double y) { - return rd_grid_get_global_index_from_xy(rd_grid, rd_grid->nz - 1, false, x, - y); -} - -int rd_grid_get_global_index_from_xy_bottom(const rd_grid_type *rd_grid, - double x, double y) { - return rd_grid_get_global_index_from_xy(rd_grid, 0, true, x, y); -} - static void rd_grid_clear_visited(rd_grid_type *grid) { if (grid->visited == NULL) grid->visited = (bool *)util_calloc(grid->size, sizeof *grid->visited); @@ -4447,16 +3999,6 @@ int rd_grid_get_global_index_from_xyz(rd_grid_type *grid, double x, double y, return -1; } -bool rd_grid_get_ijk_from_xyz(rd_grid_type *grid, double x, double y, double z, - int start_index, int *i, int *j, int *k) { - int g = rd_grid_get_global_index_from_xyz(grid, x, y, z, start_index); - if (g < 0) - return false; - - rd_grid_get_ijk1(grid, g, i, j, k); - return true; -} - static bool rd_grid_sublayer_contanins_xy__(const rd_grid_type *grid, double x, double y, int k, int i1, int i2, int j1, int j2, @@ -4554,57 +4096,6 @@ bool rd_grid_get_ij_from_xy(const rd_grid_type *grid, double x, double y, int k, return inside; } -void rd_grid_alloc_blocking_variables(rd_grid_type *grid, int block_dim) { - int index; - grid->block_dim = block_dim; - if (block_dim == 2) - grid->block_size = grid->nx * grid->ny; // Not supported - else if (block_dim == 3) - grid->block_size = grid->size; - else - util_abort("%: valid values are two and three. Value:%d invaid \n", - __func__, block_dim); - - grid->values = (double_vector_type **)util_calloc(grid->block_size, - sizeof *grid->values); - for (index = 0; index < grid->block_size; index++) - grid->values[index] = double_vector_alloc(0, 0.0); -} - -void rd_grid_init_blocking(rd_grid_type *grid) { - int index; - for (index = 0; index < grid->block_size; index++) - double_vector_reset(grid->values[index]); - grid->last_block_index = 0; -} - -bool rd_grid_block_value_3d(rd_grid_type *grid, double x, double y, double z, - double value) { - if (grid->block_dim != 3) - util_abort("%s: Wrong blocking dimension \n", __func__); - { - int global_index = rd_grid_get_global_index_from_xyz( - grid, x, y, z, grid->last_block_index); - if (global_index >= 0) { - double_vector_append(grid->values[global_index], value); - grid->last_block_index = global_index; - return true; - } else - return false; - } -} - -double rd_grid_block_eval3d(rd_grid_type *grid, int i, int j, int k, - block_function_ftype *blockf) { - int global_index = rd_grid_get_global_index3(grid, i, j, k); - return blockf(grid->values[global_index]); -} - -int rd_grid_get_block_count3d(const rd_grid_type *grid, int i, int j, int k) { - int global_index = rd_grid_get_global_index3(grid, i, j, k); - return double_vector_size(grid->values[global_index]); -} - void rd_grid_free(rd_grid_type *grid) { rd_grid_free_cells(grid); free(grid->index_map); @@ -4698,16 +4189,12 @@ int rd_grid_get_nactive_fracture(const rd_grid_type *grid) { return grid->total_active_fracture; } -int rd_grid_get_parent_cell1(const rd_grid_type *grid, int global_index) { +static int rd_grid_get_parent_cell1(const rd_grid_type *grid, + int global_index) { const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); return cell->host_cell; } -int rd_grid_get_parent_cell3(const rd_grid_type *grid, int i, int j, int k) { - int global_index = rd_grid_get_global_index__(grid, i, j, k); - return rd_grid_get_parent_cell1(grid, global_index); -} - /** Converts: (i,j,k) -> global_index. i,j,k are zero offset. */ @@ -4764,13 +4251,6 @@ int rd_grid_get_active_index1(const rd_grid_type *rd_grid, int global_index) { return rd_grid->index_map[global_index]; } -int rd_grid_get_active_fracture_index3(const rd_grid_type *rd_grid, int i, - int j, int k) { - int global_index = rd_grid_get_global_index3( - rd_grid, i, j, k); /* In range: [0,nx*ny*nz) */ - return rd_grid_get_active_fracture_index1(rd_grid, global_index); -} - /** Converts: global_index -> active_index. @@ -4871,9 +4351,9 @@ void rd_grid_export_cell_corners1(const rd_grid_type *grid, int global_index, } } -void rd_grid_get_cell_corner_xyz3(const rd_grid_type *grid, int i, int j, int k, - int corner_nr, double *xpos, double *ypos, - double *zpos) { +static void rd_grid_get_cell_corner_xyz3(const rd_grid_type *grid, int i, int j, + int k, int corner_nr, double *xpos, + double *ypos, double *zpos) { const int global_index = rd_grid_get_global_index__(grid, i, j, k); rd_grid_get_cell_corner_xyz1(grid, global_index, corner_nr, xpos, ypos, zpos); @@ -4927,11 +4407,6 @@ double rd_grid_get_cdepth1(const rd_grid_type *grid, int global_index) { return cell->center.z; } -double rd_grid_get_cdepth3(const rd_grid_type *grid, int i, int j, int k) { - const int global_index = rd_grid_get_global_index__(grid, i, j, k); - return rd_grid_get_cdepth1(grid, global_index); -} - double rd_grid_get_cdepth1A(const rd_grid_type *grid, int active_index) { const int global_index = rd_grid_get_global_index1A(grid, active_index); return rd_grid_get_cdepth1(grid, global_index); @@ -5017,11 +4492,6 @@ double rd_grid_get_bottom3(const rd_grid_type *grid, int i, int j, int k) { return rd_grid_get_bottom1(grid, global_index); } -double rd_grid_get_bottom1A(const rd_grid_type *grid, int active_index) { - const int global_index = rd_grid_get_global_index1A(grid, active_index); - return rd_grid_get_bottom1(grid, global_index); -} - double rd_grid_get_cell_dz1(const rd_grid_type *grid, int global_index) { const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); double dz = 0; @@ -5033,11 +4503,6 @@ double rd_grid_get_cell_dz1(const rd_grid_type *grid, int global_index) { return dz * 0.25; } -double rd_grid_get_cell_dz3(const rd_grid_type *grid, int i, int j, int k) { - const int global_index = rd_grid_get_global_index3(grid, i, j, k); - return rd_grid_get_cell_dz1(grid, global_index); -} - double rd_grid_get_cell_dz1A(const rd_grid_type *grid, int active_index) { const int global_index = rd_grid_get_global_index1A(grid, active_index); return rd_grid_get_cell_dz1(grid, global_index); @@ -5047,16 +4512,6 @@ double rd_grid_get_cell_thickness1(const rd_grid_type *grid, int global_index) { return rd_grid_get_cell_dz1(grid, global_index); } -double rd_grid_get_cell_thickness3(const rd_grid_type *grid, int i, int j, - int k) { - return rd_grid_get_cell_dz3(grid, i, j, k); -} - -double rd_grid_get_cell_thickness1A(const rd_grid_type *grid, - int active_index) { - return rd_grid_get_cell_dz1A(grid, active_index); -} - double rd_grid_get_cell_dx1(const rd_grid_type *grid, int global_index) { const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); double dx = 0; @@ -5073,11 +4528,6 @@ double rd_grid_get_cell_dx1(const rd_grid_type *grid, int global_index) { return sqrt(dx * dx + dy * dy); } -double rd_grid_get_cell_dx3(const rd_grid_type *grid, int i, int j, int k) { - const int global_index = rd_grid_get_global_index3(grid, i, j, k); - return rd_grid_get_cell_dx1(grid, global_index); -} - double rd_grid_get_cell_dx1A(const rd_grid_type *grid, int active_index) { const int global_index = rd_grid_get_global_index1A(grid, active_index); return rd_grid_get_cell_dx1(grid, global_index); @@ -5115,11 +4565,6 @@ double rd_grid_get_cell_dy1(const rd_grid_type *grid, int global_index) { return sqrt(dx * dx + dy * dy); } -double rd_grid_get_cell_dy3(const rd_grid_type *grid, int i, int j, int k) { - const int global_index = rd_grid_get_global_index3(grid, i, j, k); - return rd_grid_get_cell_dy1(grid, global_index); -} - double rd_grid_get_cell_dy1A(const rd_grid_type *grid, int active_index) { const int global_index = rd_grid_get_global_index1A(grid, active_index); return rd_grid_get_cell_dy1(grid, global_index); @@ -5131,12 +4576,6 @@ const nnc_info_type *rd_grid_get_cell_nnc_info1(const rd_grid_type *grid, return cell->nnc_info; } -const nnc_info_type *rd_grid_get_cell_nnc_info3(const rd_grid_type *grid, int i, - int j, int k) { - const int global_index = rd_grid_get_global_index3(grid, i, j, k); - return rd_grid_get_cell_nnc_info1(grid, global_index); -} - /* Global index in [0,...,nx*ny*nz) */ @@ -5158,16 +4597,6 @@ bool rd_grid_cell_invalid1(const rd_grid_type *rd_grid, int global_index) { return GET_CELL_FLAG(cell, CELL_FLAG_TAINTED); } -bool rd_grid_cell_invalid3(const rd_grid_type *rd_grid, int i, int j, int k) { - int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - return rd_grid_cell_invalid1(rd_grid, global_index); -} - -double rd_grid_cell_invalid1A(const rd_grid_type *grid, int active_index) { - const int global_index = rd_grid_get_global_index1A(grid, active_index); - return rd_grid_cell_invalid1(grid, global_index); -} - bool rd_grid_cell_valid1(const rd_grid_type *rd_grid, int global_index) { rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); if (GET_CELL_FLAG(cell, CELL_FLAG_TAINTED)) @@ -5176,16 +4605,6 @@ bool rd_grid_cell_valid1(const rd_grid_type *rd_grid, int global_index) { return (GET_CELL_FLAG(cell, CELL_FLAG_VALID)); } -bool rd_grid_cell_valid3(const rd_grid_type *rd_grid, int i, int j, int k) { - int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - return rd_grid_cell_valid1(rd_grid, global_index); -} - -double rd_grid_cell_valid1A(const rd_grid_type *grid, int active_index) { - const int global_index = rd_grid_get_global_index1A(grid, active_index); - return rd_grid_cell_valid1(grid, global_index); -} - static void __assert_main_grid(const rd_grid_type *rd_grid) { if (rd_grid->lgr_nr != RD_GRID_MAINGRID_LGR_NR) util_abort("%s: tried to get LGR grid from another LGR_grid - only " @@ -5312,18 +4731,6 @@ const rd_grid_type *rd_grid_get_cell_lgr1(const rd_grid_type *grid, return cell->lgr; } -const rd_grid_type *rd_grid_get_cell_lgr3(const rd_grid_type *grid, int i, - int j, int k) { - const int global_index = rd_grid_get_global_index__(grid, i, j, k); - return rd_grid_get_cell_lgr1(grid, global_index); -} - -const rd_grid_type *rd_grid_get_cell_lgr1A(const rd_grid_type *grid, - int active_index) { - const int global_index = rd_grid_get_global_index1A(grid, active_index); - return rd_grid_get_cell_lgr1(grid, global_index); -} - /** Will return the global grid for a lgr. If the input grid is indeed a global grid itself the function will return NULL. @@ -5332,20 +4739,6 @@ const rd_grid_type *rd_grid_get_global_grid(const rd_grid_type *grid) { return grid->global_grid; } -/** - Allocates a stringlist instance with the lookup names of the lgr names in this grid. -*/ - -stringlist_type *rd_grid_alloc_lgr_name_list(const rd_grid_type *rd_grid) { - __assert_main_grid(rd_grid); - { - stringlist_type *s = stringlist_alloc_new(); - for (const auto &lgr_pair : rd_grid->LGR_hash) - stringlist_append_copy(s, lgr_pair.first.c_str()); - return s; - } -} - const char *rd_grid_iget_lgr_name(const rd_grid_type *rd_grid, int lgr_index) { __assert_main_grid(rd_grid); if (lgr_index < (vector_get_size(rd_grid->LGR_list))) { @@ -5398,42 +4791,6 @@ int rd_grid_get_active_size(const rd_grid_type *rd_grid) { return rd_grid_get_nactive(rd_grid); } -bool rd_grid_cell_regular1(const rd_grid_type *rd_grid, int global_index) { - double x, y, z; - rd_grid_get_xyz1(rd_grid, global_index, &x, &y, &z); - return rd_grid_cell_contains_xyz1(rd_grid, global_index, x, y, z); -} - -bool rd_grid_cell_regular3(const rd_grid_type *rd_grid, int i, int j, int k) { - int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - return rd_grid_cell_regular1(rd_grid, global_index); -} - -/* - The function rd_grid_get_cell_twist() is an attempt to measure how - twisted or deformed a cell is. For a 'normal' cell the corners - [0..3] will z value <= the corners [4..7]. This function will count - the number of times the z value from the [4..7] is lower than the - corresponding z value from the [0..3] layer. - - The purpose of the function is to detect twisted cells before - embarking on cell contains calculation. The current - rd_cell_contains_xyz( ) implementation will fail badly for twisted - cells. - - If the function return 4 you probably have an inverted z-axis! -*/ - -int rd_grid_get_cell_twist1(const rd_grid_type *rd_grid, int global_index) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); - return rd_cell_get_twist(cell); -} - -int rd_grid_get_cell_twist3(const rd_grid_type *rd_grid, int i, int j, int k) { - int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - return rd_grid_get_cell_twist1(rd_grid, global_index); -} - double rd_grid_get_cell_volume1(const rd_grid_type *rd_grid, int global_index) { rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); int i, j, k; @@ -5447,12 +4804,6 @@ double rd_grid_get_cell_volume1A(const rd_grid_type *rd_grid, return rd_grid_get_cell_volume1(rd_grid, global_index); } -double rd_grid_get_cell_volume3(const rd_grid_type *rd_grid, int i, int j, - int k) { - int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - return rd_grid_get_cell_volume1(rd_grid, global_index); -} - void rd_grid_summarize(const rd_grid_type *rd_grid) { int active_cells, nx, ny, nz; rd_grid_get_dims(rd_grid, &nx, &ny, &nz, &active_cells); @@ -5529,77 +4880,6 @@ static int rd_grid_get_property_index__(const rd_grid_type *rd_grid, return lookup_index; } -static bool rd_grid_get_property__(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, int k, - void *value) { - rd_data_type data_type = rd_kw_get_data_type(rd_kw); - if (rd_type_is_numeric(data_type)) { - int lookup_index = - rd_grid_get_property_index__(rd_grid, rd_kw, i, j, k); - - if (lookup_index >= 0) { - rd_kw_iget(rd_kw, lookup_index, value); - return true; - } else - return false; - - } else { - util_abort("%s: sorry - can not lookup type:%s with %s.\n", __func__, - rd_type_alloc_name(data_type), __func__); - return false; - } -} - -double rd_grid_get_double_property(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, - int k) { - rd_data_type data_type = rd_kw_get_data_type(rd_kw); - if (rd_type_is_double(data_type)) { - double value; - if (rd_grid_get_property__(rd_grid, rd_kw, i, j, k, &value)) - return value; - else - return -1; // (i,j,k) Points to an inactive cell. - } else { - util_abort("%s: Wrong type \n", __func__); - return -1; - } -} - -int rd_grid_get_int_property(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, int k) { - rd_data_type data_type = rd_kw_get_data_type(rd_kw); - if (rd_type_is_int(data_type)) { - int value; - - if (rd_grid_get_property__(rd_grid, rd_kw, i, j, k, &value)) - return value; - else - return -1; // (i,j,k) Points to an inactive cell. - - } else { - util_abort("%s: Wrong type \n", __func__); - return -1; - } -} - -float rd_grid_get_float_property(const rd_grid_type *rd_grid, - const rd_kw_type *rd_kw, int i, int j, int k) { - rd_data_type data_type = rd_kw_get_data_type(rd_kw); - if (rd_type_is_float(data_type)) { - float value; - - if (rd_grid_get_property__(rd_grid, rd_kw, i, j, k, &value)) - return value; - else - return -1; // (i,j,k) Points to an inactive cell. - - } else { - util_abort("%s: Wrong type \n", __func__); - return -1; - } -} - double rd_grid_get_property(const rd_grid_type *rd_grid, const rd_kw_type *rd_kw, int i, int j, int k) { rd_data_type data_type = rd_kw_get_data_type(rd_kw); @@ -5673,77 +4953,6 @@ void rd_grid_get_column_property(const rd_grid_type *rd_grid, rd_type_alloc_name(data_type), __func__); } -/** - This function will look up all the indices in the grid where the - region_kw has a certain value (region_value). The rd_kw instance - must be loaded beforehand, typically with the functions - rd_kw_grdecl_fseek_kw / rd_kw_fscanf_alloc_grdecl_data. - - The two boolean flags active_only and export_active_index determine - how active/inactive indieces should be handled: - - active_only: Means that only cells which match the required - region_value AND are also active are stored. If active_only is - set to false, ALL cells matching region value are stored in - index_list. - - export_active_index: if this value is true the the index of the - cell is in the space of active cells, otherwise it is in terms - of the global indexing. - - Observe the following about the rd_kw instance wth region data: - - * It must be of type integer - otherwise we blow up hard. The - * size must be the total number of cells (should handle boxes and - so on ...) - - Observe that there is no way to get ijk from this function, then - you must call rd_grid_get_ijk() afterwards. the return value is - the number of cells found. -*/ - -int rd_grid_get_region_cells(const rd_grid_type *rd_grid, - const rd_kw_type *region_kw, int region_value, - bool active_only, bool export_active_index, - int_vector_type *index_list) { - int cells_found = 0; - if (rd_kw_get_size(region_kw) == rd_grid->size) { - if (rd_type_is_int(rd_kw_get_data_type(region_kw))) { - const int *region_ptr = (const int *)rd_kw_iget_ptr(region_kw, 0); - int_vector_reset(index_list); - - { - int global_index; - for (global_index = 0; global_index < rd_grid->size; - global_index++) { - if (region_ptr[global_index] == region_value) { - if (!active_only || - (rd_grid->index_map[global_index] >= 0)) { - /* Okay - this index should be included */ - if (export_active_index) - int_vector_iset( - index_list, cells_found, - rd_grid->index_map[global_index]); - else - int_vector_iset(index_list, cells_found, - global_index); - cells_found++; - } - } - } - } - } else - util_abort( - "%s: type mismatch - regions_kw must be of type integer \n", - __func__); - - } else - util_abort( - "%s: size mismatch grid has %d cells - region specifier:%d \n", - __func__, rd_grid->size, rd_kw_get_size(region_kw)); - return cells_found; -} - void rd_grid_grdecl_fprintf_kw(const rd_grid_type *rd_grid, const rd_kw_type *rd_kw, const char *special_header, FILE *stream, @@ -5901,21 +5110,6 @@ void rd_grid_dump_ascii(rd_grid_type *grid, bool active_only, FILE *stream) { } } -void rd_grid_dump_ascii_cell1(rd_grid_type *grid, int global_index, - FILE *stream, const double *offset) { - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); - int i, j, k; - rd_grid_get_ijk1(grid, global_index, &i, &j, &k); - rd_cell_dump_ascii(cell, i, j, k, stream, offset); -} - -void rd_grid_dump_ascii_cell3(rd_grid_type *grid, int i, int j, int k, - FILE *stream, const double *offset) { - int global_index = rd_grid_get_global_index3(grid, i, j, k); - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); - rd_cell_dump_ascii(cell, i, j, k, stream, offset); -} - /* 'MAPUNITS' 1 'CHAR' 'METRES ' @@ -6388,7 +5582,7 @@ float *rd_grid_alloc_coord_data(const rd_grid_type *grid) { return coord; } -void rd_grid_assert_coord_kw(rd_grid_type *grid) { +static void rd_grid_assert_coord_kw(rd_grid_type *grid) { if (grid->coord_kw == NULL) { grid->coord_kw = rd_kw_alloc(COORD_KW, rd_grid_get_coord_size(grid), RD_FLOAT); @@ -6453,12 +5647,6 @@ void rd_grid_init_zcorn_data_double(const rd_grid_type *grid, double *zcorn) { rd_grid_init_zcorn_data__(grid, NULL, zcorn); } -float *rd_grid_alloc_zcorn_data(const rd_grid_type *grid) { - float *zcorn = (float *)util_calloc(8 * grid->size, sizeof *zcorn); - rd_grid_init_zcorn_data(grid, zcorn); - return zcorn; -} - rd_kw_type *rd_grid_alloc_zcorn_kw(const rd_grid_type *grid) { rd_kw_type *zcorn_kw = rd_kw_alloc(ZCORN_KW, rd_grid_get_zcorn_size(grid), RD_FLOAT); @@ -6526,12 +5714,6 @@ void rd_grid_init_actnum_data(const rd_grid_type *grid, int *actnum) { } } -int *rd_grid_alloc_actnum_data(const rd_grid_type *grid) { - int *actnum = (int *)util_calloc(grid->size, sizeof *actnum); - rd_grid_init_actnum_data(grid, actnum); - return actnum; -} - rd_kw_type *rd_grid_alloc_actnum_kw(const rd_grid_type *grid) { rd_kw_type *actnum_kw = rd_kw_alloc(ACTNUM_KW, grid->size, RD_INT); rd_grid_init_actnum_data(grid, (int *)rd_kw_get_void_ptr(actnum_kw)); @@ -6586,13 +5768,7 @@ static void rd_grid_init_hostnum_data(const rd_grid_type *grid, int *hostnum) { } } -int *rd_grid_alloc_hostnum_data(const rd_grid_type *grid) { - int *hostnum = (int *)util_calloc(grid->size, sizeof *hostnum); - rd_grid_init_hostnum_data(grid, hostnum); - return hostnum; -} - -rd_kw_type *rd_grid_alloc_hostnum_kw(const rd_grid_type *grid) { +static rd_kw_type *rd_grid_alloc_hostnum_kw(const rd_grid_type *grid) { rd_kw_type *hostnum_kw = rd_kw_alloc(HOSTNUM_KW, grid->size, RD_INT); rd_grid_init_hostnum_data(grid, (int *)rd_kw_get_void_ptr(hostnum_kw)); return hostnum_kw; @@ -6606,31 +5782,12 @@ static void rd_grid_init_corsnum_data(const rd_grid_type *grid, int *corsnum) { } } -int *rd_grid_alloc_corsnum_data(const rd_grid_type *grid) { - int *corsnum = (int *)util_calloc(grid->size, sizeof *corsnum); - rd_grid_init_corsnum_data(grid, corsnum); - return corsnum; -} - -rd_kw_type *rd_grid_alloc_corsnum_kw(const rd_grid_type *grid) { +static rd_kw_type *rd_grid_alloc_corsnum_kw(const rd_grid_type *grid) { rd_kw_type *corsnum_kw = rd_kw_alloc(CORSNUM_KW, grid->size, RD_INT); rd_grid_init_corsnum_data(grid, (int *)rd_kw_get_void_ptr(corsnum_kw)); return corsnum_kw; } -rd_kw_type *rd_grid_alloc_gridhead_kw(int nx, int ny, int nz, int grid_nr) { - rd_kw_type *gridhead_kw = rd_kw_alloc(GRIDHEAD_KW, GRIDHEAD_SIZE, RD_INT); - rd_kw_scalar_set_int(gridhead_kw, 0); - rd_kw_iset_int(gridhead_kw, GRIDHEAD_TYPE_INDEX, - GRIDHEAD_GRIDTYPE_CORNERPOINT); - rd_kw_iset_int(gridhead_kw, GRIDHEAD_NX_INDEX, nx); - rd_kw_iset_int(gridhead_kw, GRIDHEAD_NY_INDEX, ny); - rd_kw_iset_int(gridhead_kw, GRIDHEAD_NZ_INDEX, nz); - rd_kw_iset_int(gridhead_kw, GRIDHEAD_NUMRES_INDEX, 1); - rd_kw_iset_int(gridhead_kw, GRIDHEAD_LGR_INDEX, grid_nr); - return gridhead_kw; -} - void rd_grid_reset_actnum(rd_grid_type *grid, const int *actnum) { const int global_size = rd_grid_get_global_size(grid); int g; @@ -6811,53 +5968,6 @@ void rd_grid_fwrite_EGRID(rd_grid_type *grid, const char *filename, rd_grid_fwrite_EGRID2(grid, filename, output_unit); } -void rd_grid_fwrite_depth(const rd_grid_type *grid, fortio_type *init_file, - ert_rd_unit_enum output_unit) { - rd_kw_type *depth_kw = - rd_kw_alloc("DEPTH", rd_grid_get_nactive(grid), RD_FLOAT); - { - float *depth_ptr = (float *)rd_kw_get_ptr(depth_kw); - for (int i = 0; i < rd_grid_get_nactive(grid); i++) - depth_ptr[i] = rd_grid_get_cdepth1A(grid, i); - } - rd_kw_scale_float(depth_kw, rd_grid_output_scaling(grid, output_unit)); - rd_kw_fwrite(depth_kw, init_file); - rd_kw_free(depth_kw); -} - -void rd_grid_fwrite_dims(const rd_grid_type *grid, fortio_type *init_file, - ert_rd_unit_enum output_unit) { - rd_kw_type *dx = rd_kw_alloc("DX", rd_grid_get_nactive(grid), RD_FLOAT); - rd_kw_type *dy = rd_kw_alloc("DY", rd_grid_get_nactive(grid), RD_FLOAT); - rd_kw_type *dz = rd_kw_alloc("DZ", rd_grid_get_nactive(grid), RD_FLOAT); - { - { - float *dx_ptr = (float *)rd_kw_get_ptr(dx); - float *dy_ptr = (float *)rd_kw_get_ptr(dy); - float *dz_ptr = (float *)rd_kw_get_ptr(dz); - - for (int i = 0; i < rd_grid_get_nactive(grid); i++) { - dx_ptr[i] = rd_grid_get_cell_dx1A(grid, i); - dy_ptr[i] = rd_grid_get_cell_dy1A(grid, i); - dz_ptr[i] = rd_grid_get_cell_dz1A(grid, i); - } - } - - { - float scale_factor = rd_grid_output_scaling(grid, output_unit); - rd_kw_scale_float(dx, scale_factor); - rd_kw_scale_float(dy, scale_factor); - rd_kw_scale_float(dz, scale_factor); - } - } - rd_kw_fwrite(dx, init_file); - rd_kw_fwrite(dy, init_file); - rd_kw_fwrite(dz, init_file); - rd_kw_free(dx); - rd_kw_free(dy); - rd_kw_free(dz); -} - /** Writes the current grid as grdecl keywords. This function will only write the main grid and not possible LGRs which are attached. @@ -6922,25 +6032,6 @@ void rd_grid_fprintf_grdecl(rd_grid_type *grid, FILE *stream) { rd_grid_fprintf_grdecl2(grid, stream, RD_METRIC_UNITS); } -/** - The ri_points pointer should point to the base address of the - points data; this function will calculate the correct offset based on - global_index. -*/ - -void rd_grid_cell_ri_export(const rd_grid_type *rd_grid, int global_index, - double *ri_points) { - const rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); - int offset = global_index * 8 * 3; - rd_cell_ri_export(cell, &ri_points[offset]); -} - -void rd_grid_ri_export(const rd_grid_type *rd_grid, double *ri_points) { - int global_index; - for (global_index = 0; global_index < rd_grid->size; global_index++) - rd_grid_cell_ri_export(rd_grid, global_index, ri_points); -} - bool rd_grid_dual_grid(const rd_grid_type *rd_grid) { if (rd_grid->dualp_flag == FILEHEAD_SINGLE_POROSITY) return false; diff --git a/lib/resdata/tests/rd_grid_add_nnc.cpp b/lib/resdata/tests/rd_grid_add_nnc.cpp index 2121b6e2e..6b3372a9a 100644 --- a/lib/resdata/tests/rd_grid_add_nnc.cpp +++ b/lib/resdata/tests/rd_grid_add_nnc.cpp @@ -93,8 +93,9 @@ void list_test() { int_vector_append(g1, 8); int_vector_append(g2, 9); - rd_grid_add_self_nnc_list(grid0, int_vector_get_ptr(g1), - int_vector_get_ptr(g2), int_vector_size(g1)); + for (int i = 0; i < int_vector_size(g1); i++) + rd_grid_add_self_nnc(grid0, int_vector_get_ptr(g1), + int_vector_get_ptr(g2), i); verify_simple_nnc(grid0); { diff --git a/lib/resdata/tests/rd_grid_cell_contains.cpp b/lib/resdata/tests/rd_grid_cell_contains.cpp deleted file mode 100644 index 0cd154cec..000000000 --- a/lib/resdata/tests/rd_grid_cell_contains.cpp +++ /dev/null @@ -1,279 +0,0 @@ -#include -#include -#include - -#include -#include - -bool get_test_point1(const rd_grid_type *grid, int global_index, double *_xpos, - double *_ypos, double *_zpos) { - const int corners[4] = {1, 2, 5, 6}; - double xpos = 0; - double ypos = 0; - double zpos = 0; - const double min_volume = 1e-8; - - if (fabs(rd_grid_get_cell_volume1(grid, global_index)) <= min_volume) - return false; - - if (rd_grid_get_cell_twist1(grid, global_index) > 0) - return false; - - if (!rd_grid_cell_regular1(grid, global_index)) - return false; - - for (int ci = 0; ci < 4; ci++) { - int corner = corners[ci]; - double x, y, z; - rd_grid_get_cell_corner_xyz1(grid, global_index, corner, &x, &y, &z); - xpos += x; - ypos += y; - zpos += z; - } - - *_xpos = xpos * 0.25; - *_ypos = ypos * 0.25; - *_zpos = zpos * 0.25; - - return rd_grid_cell_contains_xyz1(grid, global_index, *_xpos, *_ypos, - *_zpos); -} - -bool get_test_point3(const rd_grid_type *grid, int i, int j, int k, - double *_xpos, double *_ypos, double *_zpos) { - const int global_index = rd_grid_get_global_index3(grid, i, j, k); - return get_test_point1(grid, global_index, _xpos, _ypos, _zpos); -} - -void test_grid_covering(const rd_grid_type *grid) { - const int nx = rd_grid_get_nx(grid); - const int ny = rd_grid_get_ny(grid); - const int nz = rd_grid_get_nz(grid); - - for (int k = 0; k < nz - 1; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - int g1 = rd_grid_get_global_index3(grid, i, j, k); - int g2 = rd_grid_get_global_index3(grid, i, j, k + 1); - double p1[3]; - double p2[3]; - - for (int l = 0; l < 4; l++) { - rd_grid_get_cell_corner_xyz1(grid, g1, l + 4, &p1[0], - &p1[1], &p1[2]); - rd_grid_get_cell_corner_xyz1(grid, g2, l, &p2[0], &p2[1], - &p2[2]); - test_assert_true(p1[0] == p2[0]); - test_assert_true(p1[1] == p2[1]); - test_assert_true(p1[2] == p2[2]); - } - - for (int l = 0; l < 4; l++) { - rd_grid_get_cell_corner_xyz1(grid, g1, l, &p1[0], &p1[1], - &p1[2]); - rd_grid_get_cell_corner_xyz1(grid, g1, l + 4, &p2[0], - &p2[1], &p2[2]); - - test_assert_true(p2[2] >= p1[2]); - } - } - } - } -} - -void assert_contains(const rd_grid_type *grid, int i, int j, int k, double x, - double y, double z) { - if (!rd_grid_cell_contains_xyz3(grid, i, j, k, x, y, z)) - fprintf(stderr, " Point: (%g,%g,%g) not found in cell: (%d,%d,%d) \n", - x, y, z, i, j, k); - - test_assert_true(rd_grid_cell_contains_xyz3(grid, i, j, k, x, y, z)); -} - -void test_contains(const rd_grid_type *grid) { - const int nx = rd_grid_get_nx(grid); - const int ny = rd_grid_get_ny(grid); - const int nz = rd_grid_get_nz(grid); - - for (int k = 0; k < nz; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - if (rd_grid_get_cell_twist3(grid, i, j, k) != 0) { - double x, y, z; - if (get_test_point3(grid, i, j, k, &x, &y, &z)) { - assert_contains(grid, i, j, k, x, y, z); - { - int i2, j2, k2; - int kmin = util_int_max(0, k - 1); - int kmax = util_int_min(nz, k + 1); - - int jmin = util_int_max(0, j - 1); - int jmax = util_int_min(ny, j + 1); - - int imin = util_int_max(0, i - 1); - int imax = util_int_min(nx, i + 1); - - for (k2 = kmin; k2 < kmax; k2++) { - for (j2 = jmin; j2 < jmax; j2++) { - for (i2 = imin; i2 < imax; i2++) { - if ((i != i2) && (j != j2) && - (k != k2)) { - if (rd_grid_get_cell_twist3( - grid, i2, j2, k2) == 0) - test_assert_false( - rd_grid_cell_contains_xyz3( - grid, i2, j2, k2, x, y, - z)); - } - } - } - } - } - } - } - } - } - } -} - -void test_find(rd_grid_type *grid) { - int init_index; - int find_count = 100; - int delta = util_int_max(1, rd_grid_get_global_size(grid) / find_count); - for (init_index = 0; init_index < rd_grid_get_global_size(grid); - init_index += delta) { - if (rd_grid_get_cell_twist1(grid, init_index) == 0) { - double x, y, z; - int find_index; - int start_index = 0; - - if (get_test_point1(grid, init_index, &x, &y, &z)) { - find_index = rd_grid_get_global_index_from_xyz(grid, x, y, z, - start_index); - if (init_index != find_index) { - int i1, j1, k1, i2, j2, k2; - - rd_grid_get_ijk1(grid, init_index, &i1, &j1, &k1); - rd_grid_get_ijk1(grid, find_index, &i2, &j2, &k2); - printf(" point: %14.7f %14.7f %14.7f \n", x, y, z); - printf(" Regular: %d / %d \n", - rd_grid_cell_regular3(grid, i1, j1, k1), - rd_grid_cell_regular3(grid, i2, j2, k2)); - printf( - " init: contains(%7d) : %d (%d,%d,%d) V:%g \n", - init_index, - rd_grid_cell_contains_xyz1(grid, init_index, x, y, z), - i1 + 1, j1 + 1, k1 + 1, - rd_grid_get_cell_volume1(grid, init_index)); - printf( - "ERROR: find: contains(%7d) : %d (%d,%d,%d) V:%g " - "\n\n", - find_index, - rd_grid_cell_contains_xyz1(grid, find_index, x, y, z), - i2 + 1, j2 + 1, k2 + 1, - rd_grid_get_cell_volume1(grid, find_index)); - test_assert_int_equal(init_index, find_index); - } - } - } - } -} - -void test_corners() { - rd_grid_type *grid = rd_grid_alloc_rectangular(3, 3, 3, 1, 1, 1, NULL); - - test_assert_int_equal( - -1, rd_grid_get_global_index_from_xyz(grid, -1, -1, -1, 0)); - test_assert_int_equal(-1, - rd_grid_get_global_index_from_xyz(grid, -1, 1, 1, 0)); - test_assert_int_equal(-1, - rd_grid_get_global_index_from_xyz(grid, 1, -1, 1, 0)); - test_assert_int_equal(-1, - rd_grid_get_global_index_from_xyz(grid, 1, 1, -1, 0)); - - test_assert_int_equal( - -1, rd_grid_get_global_index_from_xyz(grid, 3.5, 3.5, 3.5, 0)); - test_assert_int_equal( - -1, rd_grid_get_global_index_from_xyz(grid, 3.5, 1, 1, 0)); - test_assert_int_equal( - -1, rd_grid_get_global_index_from_xyz(grid, 1, 3.5, 1, 0)); - test_assert_int_equal( - -1, rd_grid_get_global_index_from_xyz(grid, 1, 1, 3.5, 0)); - - { - double x, y, z; - int i; - rd_grid_get_cell_corner_xyz3(grid, 0, 0, 0, 0, &x, &y, &z); - test_assert_int_equal( - 0, rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - for (i = 1; i < 8; i++) { - rd_grid_get_cell_corner_xyz3(grid, 0, 0, 0, i, &x, &y, &z); - test_assert_int_not_equal( - 0, rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - } - - // Corner 1 - rd_grid_get_cell_corner_xyz3(grid, 2, 0, 0, 1, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 2, 0, 0), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 2 - rd_grid_get_cell_corner_xyz3(grid, 0, 2, 0, 2, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 0, 2, 0), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 3 - rd_grid_get_cell_corner_xyz3(grid, 2, 2, 0, 3, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 2, 2, 0), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 4 - rd_grid_get_cell_corner_xyz3(grid, 0, 0, 2, 4, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 0, 0, 2), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 5 - rd_grid_get_cell_corner_xyz3(grid, 2, 0, 2, 5, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 2, 0, 2), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 6 - rd_grid_get_cell_corner_xyz3(grid, 0, 2, 2, 6, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 0, 2, 2), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 7 - rd_grid_get_cell_corner_xyz3(grid, 2, 2, 2, 7, &x, &y, &z); - test_assert_int_equal( - rd_grid_get_global_index3(grid, 2, 2, 2), - rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - } - - rd_grid_free(grid); -} - -int main(int argc, char **argv) { - rd_grid_type *grid; - - util_install_signals(); - - if (argc == 1) { - grid = rd_grid_alloc_rectangular(6, 6, 6, 1, 2, 3, NULL); - } else - grid = rd_grid_alloc(argv[1]); - - test_grid_covering(grid); - test_contains(grid); - - test_find(grid); - test_corners(); - rd_grid_free(grid); - exit(0); -} diff --git a/lib/resdata/tests/rd_grid_create.cpp b/lib/resdata/tests/rd_grid_create.cpp deleted file mode 100644 index 14614c2d2..000000000 --- a/lib/resdata/tests/rd_grid_create.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include -#include - -#include -#include - -#include - -void test_create2() { - int nx = 10; - int ny = 8; - int nz = 5; - double *dx = (double *)util_calloc(nx * ny * nz, sizeof *dx); - double *dy = (double *)util_calloc(nx * ny * nz, sizeof *dy); - double *dz = (double *)util_calloc(nx * ny * nz, sizeof *dz); - double *tops = (double *)util_calloc(nx * ny * nz, sizeof *dz); - for (int k = 0; k < nz; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - int g = k * nx * ny + j * nx + i; - - dx[g] = (i + 1); - dy[g] = (j + 1); - dz[g] = (k + 1); - if (k == 0) - tops[g] = 77; - else - tops[g] = tops[g - nx * ny] + dz[g]; - } - } - } - - { - rd_grid_type *grid = - rd_grid_alloc_dx_dy_dz_tops(nx, ny, nz, dx, dy, dz, tops, NULL); - - test_assert_int_equal(nx * ny * nz, rd_grid_get_global_size(grid)); - test_assert_int_equal(nx * ny * nz, rd_grid_get_active_size(grid)); - - for (int k = 0; k < nz; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - int g = k * nx * ny + j * nx + i; - - test_assert_double_equal(rd_grid_get_cell_volume1(grid, g), - dx[g] * dy[g] * dz[g]); - } - } - } - { - double x, y, z; - - rd_grid_get_xyz1(grid, 0, &x, &y, &z); - test_assert_double_equal(x, dx[0] * 0.5); - test_assert_double_equal(y, dy[0] * 0.5); - test_assert_double_equal(z, dz[0] * 0.5 + tops[0]); - } - rd_grid_free(grid); - } - free(tops); - free(dx); - free(dy); - free(dz); -} - -void test_create1() { - int nx = 10; - int ny = 10; - int nz = 10; - double *dx = (double *)util_calloc(nx * ny * nz, sizeof *dx); - double *dy = (double *)util_calloc(nx * ny * nz, sizeof *dy); - double *dz = (double *)util_calloc(nx * ny * nz, sizeof *dz); - double *tops = (double *)util_calloc(nx * ny * nz, sizeof *tops); - for (int k = 0; k < nz; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - int g = k * nx * ny + j * nx + i; - - dx[g] = 1; - dy[g] = 1; - dz[g] = 1; - if (k == 0) - tops[g] = 0; - else - tops[g] = tops[g - nx * ny] + dz[g]; - } - } - } - - { - rd_grid_type *grid = - rd_grid_alloc_dx_dy_dz_tops(nx, ny, nz, dx, dy, dz, tops, NULL); - - test_assert_int_equal(nx * ny * nz, rd_grid_get_global_size(grid)); - test_assert_int_equal(nx * ny * nz, rd_grid_get_active_size(grid)); - - for (int k = 0; k < nz; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - int g = k * nx * ny + j * nx + i; - - test_assert_double_equal(rd_grid_get_cell_volume1(grid, g), - dx[g] * dy[g] * dz[g]); - - { - double x, y, z; - rd_grid_get_xyz1(grid, g, &x, &y, &z); - test_assert_double_equal(x, i + 0.5); - test_assert_double_equal(y, j + 0.5); - test_assert_double_equal(z, k + 0.5); - } - } - } - } - rd_grid_free(grid); - } - free(tops); - free(dx); - free(dy); - free(dz); -} - -int main(int argc, char **argv) { - test_create1(); - test_create2(); -} diff --git a/lib/resdata/tests/rd_grid_export.cpp b/lib/resdata/tests/rd_grid_export.cpp index 2a9418cb6..097564e59 100644 --- a/lib/resdata/tests/rd_grid_export.cpp +++ b/lib/resdata/tests/rd_grid_export.cpp @@ -65,70 +65,6 @@ void export_zcorn(const rd_grid_type *grid, rd_file_type *rd_file) { } } -void copy_processed(const rd_grid_type *src) { - { - rd_grid_type *copy = rd_grid_alloc_processed_copy(src, NULL, NULL); - test_assert_true(rd_grid_compare(src, copy, true, true, false)); - rd_grid_free(copy); - } - - { - int *actnum = - (int *)util_malloc(rd_grid_get_global_size(src) * sizeof *actnum); - int index = 0; - rd_grid_init_actnum_data(src, actnum); - - while (true) { - if (actnum[index] == 1) { - actnum[index] = 0; - break; - } - index++; - } - - { - rd_grid_type *copy = - rd_grid_alloc_processed_copy(src, NULL, actnum); - test_assert_int_equal(1, rd_grid_get_active_size(src) - - rd_grid_get_active_size(copy)); - rd_grid_free(copy); - } - free(actnum); - } - - { - double *zcorn_double = (double *)util_malloc( - rd_grid_get_zcorn_size(src) * sizeof *zcorn_double); - int i = 0; - int j = 0; - int k = 0; - - rd_grid_init_zcorn_data_double(src, zcorn_double); - { - rd_grid_type *copy = - rd_grid_alloc_processed_copy(src, zcorn_double, NULL); - test_assert_double_equal(rd_grid_get_cell_volume3(src, i, j, k), - rd_grid_get_cell_volume3(copy, i, j, k)); - rd_grid_free(copy); - } - - for (int c = 0; c < 4; c++) { - double dz = zcorn_double[rd_grid_zcorn_index(src, i, j, k, c + 4)] - - zcorn_double[rd_grid_zcorn_index(src, i, j, k, c)]; - zcorn_double[rd_grid_zcorn_index(src, i, j, k, c + 4)] += dz; - } - { - rd_grid_type *copy = - rd_grid_alloc_processed_copy(src, zcorn_double, NULL); - test_assert_double_equal(rd_grid_get_cell_volume3(src, i, j, k) * 2, - rd_grid_get_cell_volume3(copy, i, j, k)); - rd_grid_free(copy); - } - - free(zcorn_double); - } -} - void export_mapaxes(const rd_grid_type *grid, rd_file_type *rd_file) { if (rd_file_has_kw(rd_file, "MAPAXES")) { rd_kw_type *mapaxes_kw = rd_file_iget_named_kw(rd_file, "MAPAXES", 0); @@ -168,7 +104,6 @@ int main(int argc, char **argv) { export_coord(rd_grid, rd_file); export_zcorn(rd_grid, rd_file); export_mapaxes(rd_grid, rd_file); - copy_processed(rd_grid); rd_file_close(rd_file); rd_grid_free(rd_grid); } diff --git a/lib/resdata/tests/rd_grid_ext_actnum.cpp b/lib/resdata/tests/rd_grid_ext_actnum.cpp deleted file mode 100644 index 15613367e..000000000 --- a/lib/resdata/tests/rd_grid_ext_actnum.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include -#include - -#include -#include -#include -#include -#include - -void test_1() { - - rd::util::TestArea ta("test1"); - { - const char *filename = "FILE.EGRID"; - - rd_grid_type *grid_write = - rd_grid_alloc_rectangular(2, 3, 1, 1, 1, 1, NULL); - rd_grid_fwrite_EGRID(grid_write, filename, true); - rd_grid_free(grid_write); - - rd_file_type *rd_file = rd_file_open(filename, 0); - rd_kw_type *filehead_kw = - rd_file_iget_named_kw(rd_file, FILEHEAD_KW, 0); - int *filehead_data = rd_kw_get_int_ptr(filehead_kw); - filehead_data[FILEHEAD_DUALP_INDEX] = FILEHEAD_DUAL_POROSITY; - - rd_kw_type *actnum_kw = rd_file_iget_named_kw(rd_file, ACTNUM_KW, 0); - int *actnum_data = rd_kw_get_int_ptr(actnum_kw); - actnum_data[0] = 1; - actnum_data[1] = 2; - actnum_data[2] = 2; - actnum_data[3] = 0; - actnum_data[4] = 1; - actnum_data[5] = 1; - const char *filename1 = "FILE1.EGRID"; - fortio_type *f = fortio_open_writer(filename1, false, RD_ENDIAN_FLIP); - rd_file_fwrite_fortio(rd_file, f, 0); - fortio_fclose(f); - rd_file_close(rd_file); - - std::vector ext_actnum = {0, 1, 0, 1, 1, 1}; - rd_grid_type *grid = - rd_grid_alloc_ext_actnum(filename1, ext_actnum.data()); - test_assert_int_equal(4, rd_grid_get_nactive(grid)); - test_assert_int_equal(0, rd_grid_get_nactive_fracture(grid)); - test_assert_true(!rd_grid_cell_active1(grid, 0)); - - test_assert_true(!rd_grid_cell_active1(grid, 2)); - test_assert_true(rd_grid_cell_active1(grid, 3)); - test_assert_true(rd_grid_cell_active1(grid, 4)); - test_assert_true(rd_grid_cell_active1(grid, 5)); - - rd_grid_free(grid); - } -} - -int main() { test_1(); } diff --git a/lib/resdata/tests/rd_grid_init_fwrite.cpp b/lib/resdata/tests/rd_grid_init_fwrite.cpp index f97b3da7c..375bb43f4 100644 --- a/lib/resdata/tests/rd_grid_init_fwrite.cpp +++ b/lib/resdata/tests/rd_grid_init_fwrite.cpp @@ -32,6 +32,55 @@ void test_write_depth(const rd_grid_type *grid) { } } +static void rd_grid_fwrite_dims(const rd_grid_type *grid, + fortio_type *init_file, + ert_rd_unit_enum output_unit) { + rd_kw_type *dx = rd_kw_alloc("DX", rd_grid_get_nactive(grid), RD_FLOAT); + rd_kw_type *dy = rd_kw_alloc("DY", rd_grid_get_nactive(grid), RD_FLOAT); + rd_kw_type *dz = rd_kw_alloc("DZ", rd_grid_get_nactive(grid), RD_FLOAT); + { + { + float *dx_ptr = (float *)rd_kw_get_ptr(dx); + float *dy_ptr = (float *)rd_kw_get_ptr(dy); + float *dz_ptr = (float *)rd_kw_get_ptr(dz); + + for (int i = 0; i < rd_grid_get_nactive(grid); i++) { + dx_ptr[i] = rd_grid_get_cell_dx1A(grid, i); + dy_ptr[i] = rd_grid_get_cell_dy1A(grid, i); + dz_ptr[i] = rd_grid_get_cell_dz1A(grid, i); + } + } + + { + float scale_factor = rd_grid_output_scaling(grid, output_unit); + rd_kw_scale_float(dx, scale_factor); + rd_kw_scale_float(dy, scale_factor); + rd_kw_scale_float(dz, scale_factor); + } + } + rd_kw_fwrite(dx, init_file); + rd_kw_fwrite(dy, init_file); + rd_kw_fwrite(dz, init_file); + rd_kw_free(dx); + rd_kw_free(dy); + rd_kw_free(dz); +} + +static void rd_grid_fwrite_depth(const rd_grid_type *grid, + fortio_type *init_file, + ert_rd_unit_enum output_unit) { + rd_kw_type *depth_kw = + rd_kw_alloc("DEPTH", rd_grid_get_nactive(grid), RD_FLOAT); + { + float *depth_ptr = (float *)rd_kw_get_ptr(depth_kw); + for (int i = 0; i < rd_grid_get_nactive(grid); i++) + depth_ptr[i] = rd_grid_get_cdepth1A(grid, i); + } + rd_kw_scale_float(depth_kw, rd_grid_output_scaling(grid, output_unit)); + rd_kw_fwrite(depth_kw, init_file); + rd_kw_free(depth_kw); +} + void test_write_dims(const rd_grid_type *grid) { rd::util::TestArea ta("write_dims"); { diff --git a/lib/tests/test_rd_grid.cpp b/lib/tests/test_rd_grid.cpp index d3c9c7edf..c87981cfd 100644 --- a/lib/tests/test_rd_grid.cpp +++ b/lib/tests/test_rd_grid.cpp @@ -25,118 +25,6 @@ TEST_CASE("Test unfractured grids", "[unittest]") { } } -/** - * Arbitrarily chosen depth function. - */ -double depth_function(double x, double y) { - return cos(3 * x) * sin(2 * y) * sqrt(x * y); -} - -/** - * Given a number of cell with the given width, what - * is the coordinate of the cell centered at index i? - */ -double center_of_cell(double cell_width, int index) { - return cell_width * index + cell_width * 0.5; -} - -/** - * Generates a grid with the given number of x, y and z cells - * all width the given x, y, and z dimensions. depth is set by - * the depth function applied to the center of the cell. - */ -rd_grid_type *generate_dxv_dyv_dzv_depthz_grid(int num_x, int num_y, int num_z, - double x_width, double y_width, - double z_width) { - auto x_widths = std::vector(num_x + 1, x_width); - auto y_widths = std::vector(num_y + 1, y_width); - auto z_widths = std::vector(num_z, z_width); - auto z_depths = std::vector((num_x + 1) * (num_y + 1), 0); - - for (int j = 0; j <= num_y; j++) { - double y = center_of_cell(y_width, j); - for (int i = 0; i <= num_x; i++) { - double x = center_of_cell(x_width, i); - z_depths[i + j * (num_x + 1)] = depth_function(x, y); - } - } - - auto grid = rd_grid_alloc_dxv_dyv_dzv_depthz( - num_x, num_y, num_z, x_widths.data(), y_widths.data(), z_widths.data(), - z_depths.data(), NULL); - return grid; -} - -TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { - GIVEN("A grid constructed with dxv_dyv_dzv_depthz") { - int nx = GENERATE(take(3, random(5, 25))); - int ny = GENERATE(take(3, random(5, 25))); - int nz = GENERATE(take(3, random(5, 25))); - - double x_width = 1.0 / nx; - double y_width = 1.0 / ny; - double z_width = 3.0 / nz; - - rd_grid_type *grid = generate_dxv_dyv_dzv_depthz_grid( - nx, ny, nz, x_width, y_width, z_width); - - AND_GIVEN("Any cell in that grid") { - int i = GENERATE_COPY(0, nx - 1, take(3, random(1, nx - 2))); - int j = GENERATE_COPY(0, ny - 1, take(3, random(1, ny - 2))); - int k = GENERATE_COPY(0, nz - 1, take(3, random(1, nz - 2))); - - THEN("get_xyz3 should return cell center in x, y plane") { - double xc, yc, zc; - rd_grid_get_xyz3(grid, i, j, k, &xc, &yc, &zc); - - REQUIRE_THAT(xc, - WithinAbs(center_of_cell(x_width, i), 0.000001)); - REQUIRE_THAT(yc, WithinAbs(center_of_cell(y_width, j), 1e-4)); - } - THEN("The top cell corner has z offset by depth function") { - double xc, yc, zc; - - rd_grid_get_cell_corner_xyz3(grid, i, j, k, 0, &xc, &yc, &zc); - - double x_center = center_of_cell(x_width, i); - double y_center = center_of_cell(y_width, j); - REQUIRE_THAT( - zc, - WithinAbs(z_width * k + depth_function(x_center, y_center), - 1e-4)); - } - - THEN("The bottom cell corner has z offset by depth function") { - double xc, yc, zc; - - rd_grid_get_cell_corner_xyz3(grid, i, j, k, 4, &xc, &yc, &zc); - - double x_center = center_of_cell(x_width, i); - double y_center = center_of_cell(y_width, j); - REQUIRE_THAT(zc, - WithinAbs(z_width * (k + 1) + - depth_function(x_center, y_center), - 1e-4)); - } - - THEN("The volume should be simple multiplication") { - double volume = rd_grid_get_cell_volume3(grid, i, j, k); - REQUIRE_THAT(volume, - WithinAbs(z_width * x_width * y_width, 1e-4)); - } - } - AND_GIVEN("A grid constructed in the same way") { - rd_grid_type *grid2 = generate_dxv_dyv_dzv_depthz_grid( - nx, ny, nz, x_width, y_width, z_width); - THEN("Those grids are equal") { - REQUIRE(rd_grid_compare(grid, grid2, false, false, true)); - } - rd_grid_free(grid2); - } - rd_grid_free(grid); - } -} - /** * Generates a grid, using the rd_grid_alloc_GRDECL_kw constructor, * with the x,y,z coordinates of the 0th corner of the ijkth cel is @@ -194,58 +82,6 @@ rd_grid_type *generate_coordkw_grid( return grid; } -TEST_CASE("Test no twistedness", "[unittest]") { - GIVEN("A grid with untwisted cells") { - rd_grid_type *grid = generate_coordkw_grid(10, 7, 8, {}); - - AND_GIVEN("Any cell in that grid") { - auto i = GENERATE(take(3, random(0, 9))); - auto j = GENERATE(take(3, random(0, 6))); - auto k = GENERATE(take(3, random(0, 7))); - - THEN("That cell should have a twist score of 0") { - REQUIRE(rd_grid_get_cell_twist3(grid, i, j, k) == 0); - } - } - - rd_grid_free(grid); - } -} - -TEST_CASE("Test simple twistedness", "[unittest]") { - GIVEN("A grid with the first cell twisted") { - auto z_vector = std::vector>{ - {0, 0, 0, 0, 0.0}, - {0, 0, 0, 4, -0.25}, - }; - rd_grid_type *grid = generate_coordkw_grid(10, 7, 8, z_vector); - - THEN("That cell should have a twist score of 1") { - REQUIRE(rd_grid_get_cell_twist3(grid, 0, 0, 0) == 1); - } - - rd_grid_free(grid); - } -} - -TEST_CASE("Test double twistedness", "[unittest]") { - GIVEN("A grid with the first cell doubly twisted") { - auto z_vector = std::vector>{ - {0, 0, 0, 0, 0.0}, - {0, 0, 0, 4, -0.25}, - {0, 0, 0, 3, 0.0}, - {0, 0, 0, 7, -0.25}, - }; - rd_grid_type *grid = generate_coordkw_grid(10, 7, 8, z_vector); - - THEN("That cell should have a twist score of 2") { - REQUIRE(rd_grid_get_cell_twist3(grid, 0, 0, 0) == 2); - } - - rd_grid_free(grid); - } -} - TEST_CASE_METHOD(Tmpdir, "Test case loading", "[unittest]") { GIVEN("A grid on disc") { auto filename = dirname / "GRID.EGRID";