diff --git a/lib/resdata/rd_grid.cpp b/lib/resdata/rd_grid.cpp index 4ceb2b3a8..5d192387f 100644 --- a/lib/resdata/rd_grid.cpp +++ b/lib/resdata/rd_grid.cpp @@ -676,8 +676,6 @@ struct rd_cell_struct { static ert_rd_unit_enum rd_grid_check_unit_system(const rd_kw_type *gridunit_kw); -static void rd_grid_init_mapaxes_data_float(const rd_grid_type *grid, - float *mapaxes); float *rd_grid_alloc_coord_data(const rd_grid_type *grid); static const float *rd_grid_get_mapaxes(const rd_grid_type *grid); @@ -760,8 +758,6 @@ ert_rd_unit_enum rd_grid_get_unit_system(const rd_grid_type *grid) { static void rd_cell_compare(const rd_cell_type *c1, const rd_cell_type *c2, bool include_nnc, bool *equal) { - int i; - if (c1->active != c2->active) *equal = false; @@ -778,7 +774,7 @@ static void rd_cell_compare(const rd_cell_type *c1, const rd_cell_type *c2, *equal = false; if (*equal) { - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) point_compare(&c1->corner_list[i], &c2->corner_list[i], equal); } @@ -788,12 +784,6 @@ static void rd_cell_compare(const rd_cell_type *c1, const rd_cell_type *c2, } } -static void rd_cell_dump(const rd_cell_type *cell, FILE *stream) { - int i; - for (i = 0; i < 8; i++) - point_dump(&cell->corner_list[i], stream); -} - static void rd_cell_assert_center(rd_cell_type *cell); static void rd_cell_dump_ascii(rd_cell_type *cell, int i, int j, int k, @@ -809,13 +799,10 @@ static void rd_cell_dump_ascii(rd_cell_type *cell, int i, int j, int k, point_dump_ascii(&cell->center, stream, offset); fprintf(stream, "\n"); - { - int l; - for (l = 0; l < 8; l++) { - fprintf(stream, "Corner %d : ", l); - point_dump_ascii(&cell->corner_list[l], stream, offset); - fprintf(stream, "\n"); - } + for (int l = 0; l < 8; l++) { + fprintf(stream, "Corner %d : ", l); + point_dump_ascii(&cell->corner_list[l], stream, offset); + fprintf(stream, "\n"); } fprintf(stream, "\n"); } @@ -848,9 +835,7 @@ static void rd_cell_fwrite_GRID(const rd_grid_type *grid, { float *corners = (float *)rd_kw_get_void_ptr(corners_kw); point_type point; - int c; - - for (c = 0; c < 8; c++) { + for (int c = 0; c < 8; c++) { point_copy_values(&point, &cell->corner_list[c]); if (grid->use_mapaxes) point_mapaxes_invtransform(&point, grid->origo, grid->unit_x, @@ -868,46 +853,39 @@ static void rd_cell_fwrite_GRID(const rd_grid_type *grid, static void rd_cell_ri_export(const rd_cell_type *cell, double *ri_points) { int rd_offset = 4; int ri_offset = rd_offset * 3; - { - int point_nr; - // Handling the points 0,1 & 4,5 which map directly between ECLIPSE and RI - for (point_nr = 0; point_nr < 2; point_nr++) { - // Points 0 & 1 - ri_points[point_nr * 3] = cell->corner_list[point_nr].x; - ri_points[point_nr * 3 + 1] = cell->corner_list[point_nr].y; - ri_points[point_nr * 3 + 2] = -cell->corner_list[point_nr].z; - - // Points 4 & 5 - ri_points[ri_offset + point_nr * 3] = - cell->corner_list[rd_offset + point_nr].x; - ri_points[ri_offset + point_nr * 3 + 1] = - cell->corner_list[rd_offset + point_nr].y; - ri_points[ri_offset + point_nr * 3 + 2] = - -cell->corner_list[rd_offset + point_nr].z; - } - } - - { - int rd_point; - /* - Handling the points 2,3 & 6,7 which are flipped when (2,3) -> - (3,2) and (6,7) -> (7,6) when going between ECLIPSE and ResInsight. - */ - for (rd_point = 2; rd_point < 4; rd_point++) { - int ri_point = 5 - rd_point; - // Points 2 & 3 - ri_points[ri_point * 3] = cell->corner_list[rd_point].x; - ri_points[ri_point * 3 + 1] = cell->corner_list[rd_point].y; - ri_points[ri_point * 3 + 2] = -cell->corner_list[rd_point].z; - - // Points 6 & 7 - ri_points[ri_offset + ri_point * 3] = - cell->corner_list[rd_offset + rd_point].x; - ri_points[ri_offset + ri_point * 3 + 1] = - cell->corner_list[rd_offset + rd_point].y; - ri_points[ri_offset + ri_point * 3 + 2] = - -cell->corner_list[rd_offset + rd_point].z; - } + // + // Handling the points 0,1 & 4,5 which map directly between ECLIPSE and RI + for (int point_nr = 0; point_nr < 2; point_nr++) { + // Points 0 & 1 + ri_points[point_nr * 3] = cell->corner_list[point_nr].x; + ri_points[point_nr * 3 + 1] = cell->corner_list[point_nr].y; + ri_points[point_nr * 3 + 2] = -cell->corner_list[point_nr].z; + + // Points 4 & 5 + ri_points[ri_offset + point_nr * 3] = + cell->corner_list[rd_offset + point_nr].x; + ri_points[ri_offset + point_nr * 3 + 1] = + cell->corner_list[rd_offset + point_nr].y; + ri_points[ri_offset + point_nr * 3 + 2] = + -cell->corner_list[rd_offset + point_nr].z; + } + + // Handling the points 2,3 & 6,7 which are flipped when (2,3) -> + // (3,2) and (6,7) -> (7,6) when going between ECLIPSE and ResInsight. + for (int rd_point = 2; rd_point < 4; rd_point++) { + int ri_point = 5 - rd_point; + // Points 2 & 3 + ri_points[ri_point * 3] = cell->corner_list[rd_point].x; + ri_points[ri_point * 3 + 1] = cell->corner_list[rd_point].y; + ri_points[ri_point * 3 + 2] = -cell->corner_list[rd_point].z; + + // Points 6 & 7 + ri_points[ri_offset + ri_point * 3] = + cell->corner_list[rd_offset + rd_point].x; + ri_points[ri_offset + ri_point * 3 + 1] = + cell->corner_list[rd_offset + rd_point].y; + ri_points[ri_offset + ri_point * 3 + 2] = + -cell->corner_list[rd_offset + rd_point].z; } } @@ -1010,8 +988,7 @@ static double rd_cell_max_y(const rd_cell_type *cell) { */ static void rd_cell_taint_cell(rd_cell_type *cell) { - int c; - for (c = 0; c < 8; c++) { + for (int c = 0; c < 8; c++) { const point_type p = cell->corner_list[c]; if ((p.x == 0) && (p.y == 0)) { SET_CELL_FLAG(cell, CELL_FLAG_TAINTED); @@ -1077,21 +1054,10 @@ static void rd_cell_init(rd_cell_type *cell, bool init_valid) { cell->nnc_info = NULL; } -/* -#define mod(x,n) ((x) % (n)) -static int rd_cell_get_tetrahedron_method( int i , int j , int k) { - return (1 + (1 - 2*mod(i,2)) * (1 - 2 * mod(j,2)) * (1 - 2*mod(k,2))) / 2; -} -#undef mod -*/ - static void rd_cell_set_center(rd_cell_type *cell) { point_set(&cell->center, 0, 0, 0); - { - int c; - for (c = 0; c < 8; c++) - point_inplace_add(&cell->center, &cell->corner_list[c]); - } + for (int c = 0; c < 8; c++) + point_inplace_add(&cell->center, &cell->corner_list[c]); point_inplace_scale(&cell->center, 1.0 / 8.0); SET_CELL_FLAG(cell, CELL_FLAG_CENTER); @@ -1102,16 +1068,6 @@ static void rd_cell_assert_center(rd_cell_type *cell) { rd_cell_set_center(cell); } -static void rd_cell_memcpy(rd_cell_type *target_cell, - const rd_cell_type *src_cell) { - memcpy(target_cell, src_cell, sizeof *target_cell); -} - -static void rd_cell_install_lgr(rd_cell_type *cell, - const rd_grid_type *lgr_grid) { - cell->lgr = lgr_grid; -} - static double C(double *r, int f1, int f2, int f3) { if (f1 == 0) { if (f2 == 0) { @@ -1143,25 +1099,22 @@ static double C(double *r, int f1, int f2, int f3) { static double rd_cell_get_volume(rd_cell_type *cell) { double volume = 0; - int pb, pg, qa, qg, ra, rb; double X[8]; double Y[8]; double Z[8]; - { - int c; - for (c = 0; c < 8; c++) { - X[c] = cell->corner_list[c].x; - Y[c] = cell->corner_list[c].y; - Z[c] = cell->corner_list[c].z; - } + + for (int c = 0; c < 8; c++) { + X[c] = cell->corner_list[c].x; + Y[c] = cell->corner_list[c].y; + Z[c] = cell->corner_list[c].z; } - for (pb = 0; pb <= 1; pb++) - for (pg = 0; pg <= 1; pg++) - for (qa = 0; qa <= 1; qa++) - for (qg = 0; qg <= 1; qg++) - for (ra = 0; ra <= 1; ra++) - for (rb = 0; rb <= 1; rb++) { + for (int pb = 0; pb <= 1; pb++) + for (int pg = 0; pg <= 1; pg++) + for (int qa = 0; qa <= 1; qa++) + for (int qg = 0; qg <= 1; qg++) + for (int ra = 0; ra <= 1; ra++) + for (int rb = 0; rb <= 1; rb++) { int divisor = (qa + ra + 1) * (pb + rb + 1) * (pg + qg + 1); double dV = C(X, 1, pb, pg) * C(Y, qa, 1, qg) * @@ -1385,12 +1338,9 @@ static void rd_cell_init_regular(rd_cell_type *cell, const double *offset, cell->corner_list[3] = cell->corner_list[1]; // Point 3 point_shift(&cell->corner_list[3], jvec[0], jvec[1], jvec[2]); - { - int i; - for (i = 0; i < 4; i++) { - cell->corner_list[i + 4] = cell->corner_list[i]; // Point 4-7 - point_shift(&cell->corner_list[i + 4], kvec[0], kvec[1], kvec[2]); - } + for (int i = 0; i < 4; i++) { + cell->corner_list[i + 4] = cell->corner_list[i]; // Point 4-7 + point_shift(&cell->corner_list[i + 4], kvec[0], kvec[1], kvec[2]); } if (actnum != NULL) @@ -1402,15 +1352,6 @@ static void rd_cell_init_regular(rd_cell_type *cell, const double *offset, UTIL_SAFE_CAST_FUNCTION(rd_grid, RD_GRID_ID); UTIL_IS_INSTANCE_FUNCTION(rd_grid, RD_GRID_ID); -/** - this function allocates the internal index_map and inv_index_map fields. -*/ - -static rd_cell_type *rd_grid_get_cell(const rd_grid_type *grid, - int global_index) { - return &grid->cells[global_index]; -} - /** this function uses heuristics in an attempt to mark cells with wrong geometry - see further comments in the function @@ -1418,9 +1359,8 @@ static rd_cell_type *rd_grid_get_cell(const rd_grid_type *grid, */ static void rd_grid_taint_cells(rd_grid_type *rd_grid) { - int index; - for (index = 0; index < rd_grid->size; index++) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, index); + for (int index = 0; index < rd_grid->size; index++) { + rd_cell_type *cell = &rd_grid->cells[index]; rd_cell_taint_cell(cell); } } @@ -1430,7 +1370,7 @@ static void rd_grid_free_cells(rd_grid_type *grid) { return; for (int i = 0; i < grid->size; i++) { - rd_cell_type *cell = rd_grid_get_cell(grid, i); + rd_cell_type *cell = &grid->cells[i]; if (cell->nnc_info) nnc_info_free(cell->nnc_info); } @@ -1442,18 +1382,13 @@ static bool rd_grid_alloc_cells(rd_grid_type *grid, bool init_valid) { if (!grid->cells) return false; - { - rd_cell_type *cell0 = rd_grid_get_cell(grid, 0); - rd_cell_init(cell0, init_valid); - { - int i; - for (i = 1; i < grid->size; i++) { - rd_cell_type *target_cell = rd_grid_get_cell(grid, i); - rd_cell_memcpy(target_cell, cell0); - } - } - return true; + rd_cell_type *cell0 = &grid->cells[0]; + rd_cell_init(cell0, init_valid); + for (int i = 1; i < grid->size; i++) { + rd_cell_type *target_cell = &grid->cells[i]; + memcpy(target_cell, cell0, sizeof *target_cell); } + return true; } /** @@ -1555,7 +1490,7 @@ static void rd_grid_set_cell_EGRID(rd_grid_type *rd_grid, int i, int j, int k, const int *corsnum) { const int global_index = rd_grid_get_global_index__(rd_grid, i, j, k); - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *cell = &rd_grid->cells[global_index]; int ip, iz; for (iz = 0; iz < 2; iz++) { @@ -1610,7 +1545,7 @@ static void rd_grid_set_cell_GRID(rd_grid_type *rd_grid, int coords_size, } global_index = rd_grid_get_global_index__(rd_grid, i, j, k); - cell = rd_grid_get_cell(rd_grid, global_index); + cell = &rd_grid->cells[global_index]; /* the coords keyword can optionally contain 4,5 or 7 elements: @@ -1630,49 +1565,42 @@ static void rd_grid_set_cell_GRID(rd_grid_type *rd_grid, int coords_size, current code. */ - { - int c; + // The RD_GRID_MAINGRID_LGR_NR != rd_grid->lgr_nr test checks if + // this is a LGR; if this test applies we either have bug - or a + // GRID file with LGRs and only 4/5 elements in the coords keywords. + // In the latter case we must start using the LGRILG keyword. + if ((RD_GRID_MAINGRID_LGR_NR != rd_grid->lgr_nr) && (coords_size != 7)) + util_abort("%s: Need 7 element coords keywords for LGR - or " + "reimplement to use LGRILG keyword.\n", + __func__); - /* - The RD_GRID_MAINGRID_LGR_NR != rd_grid->lgr_nr test checks if - this is a LGR; if this test applies we either have bug - or a - GRID file with LGRs and only 4/5 elements in the coords keywords. - In the latter case we must start using the LGRILG keyword. - */ - if ((RD_GRID_MAINGRID_LGR_NR != rd_grid->lgr_nr) && (coords_size != 7)) - util_abort("%s: Need 7 element coords keywords for LGR - or " - "reimplement to use LGRILG keyword.\n", - __func__); - - switch (coords_size) { - case 4: /* all cells active */ - cell->active += active_value; - break; - case 5: /* only spesific cells active - no lgr */ - cell->active += coords[4] * active_value; - break; - case 7: - cell->active += coords[4] * active_value; - cell->host_cell = coords[5] - 1; - cell->coarse_group = coords[6] - 1; - if (cell->coarse_group >= 0) - rd_grid->coarsening_active = true; - break; - default: - util_abort("%s: coord size:%d unrecognized - should 4,5 or 7.\n", - __func__, coords_size); - } + switch (coords_size) { + case 4: /* all cells active */ + cell->active += active_value; + break; + case 5: /* only spesific cells active - no lgr */ + cell->active += coords[4] * active_value; + break; + case 7: + cell->active += coords[4] * active_value; + cell->host_cell = coords[5] - 1; + cell->coarse_group = coords[6] - 1; + if (cell->coarse_group >= 0) + rd_grid->coarsening_active = true; + break; + default: + util_abort("%s: coord size:%d unrecognized - should 4,5 or 7.\n", + __func__, coords_size); + } - if (matrix_cell) { - for (c = 0; c < 8; c++) { - point_set(&cell->corner_list[c], corners[3 * c], - corners[3 * c + 1], corners[3 * c + 2]); + if (matrix_cell) { + for (int c = 0; c < 8; c++) { + point_set(&cell->corner_list[c], corners[3 * c], corners[3 * c + 1], + corners[3 * c + 2]); - if (rd_grid->use_mapaxes) - point_mapaxes_transform(&cell->corner_list[c], - rd_grid->origo, rd_grid->unit_x, - rd_grid->unit_y); - } + if (rd_grid->use_mapaxes) + point_mapaxes_transform(&cell->corner_list[c], rd_grid->origo, + rd_grid->unit_x, rd_grid->unit_y); } } SET_CELL_FLAG(cell, CELL_FLAG_VALID); @@ -1688,7 +1616,7 @@ static void rd_grid_init_index_map__(rd_grid_type *rd_grid, int *index_map, int *inv_index_map, int active_mask, int type_index) { for (int global_index = 0; global_index < rd_grid->size; global_index++) { - const rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + const rd_cell_type *cell = &rd_grid->cells[global_index]; if (cell->active & active_mask) { index_map[global_index] = cell->active_index[type_index]; @@ -1788,7 +1716,7 @@ static void rd_grid_set_active_index(rd_grid_type *rd_grid) { /* Keeping a fast path for the 99% most common case of no coarse groups and single porosity. */ for (global_index = 0; global_index < rd_grid->size; global_index++) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *cell = &rd_grid->cells[global_index]; if (cell->active & CELL_ACTIVE_MATRIX) { cell->active_index[MATRIX_INDEX] = active_index; @@ -1799,7 +1727,7 @@ static void rd_grid_set_active_index(rd_grid_type *rd_grid) { if (rd_grid->dualp_flag != FILEHEAD_SINGLE_POROSITY) { for (global_index = 0; global_index < rd_grid->size; global_index++) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *cell = &rd_grid->cells[global_index]; if (cell->active & CELL_ACTIVE_FRACTURE) { cell->active_index[FRACTURE_INDEX] = active_fracture_index; active_fracture_index++; @@ -1830,7 +1758,7 @@ static void rd_grid_set_active_index(rd_grid_type *rd_grid) { the entire coarse cell. */ for (global_index = 0; global_index < rd_grid->size; global_index++) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *cell = &rd_grid->cells[global_index]; if (cell->active != CELL_NOT_ACTIVE) { if (cell->coarse_group == COARSE_GROUP_NONE) { @@ -1883,8 +1811,7 @@ static void rd_grid_set_active_index(rd_grid_type *rd_grid) { for (int i = 0; i < group_size; i++) { global_index = coarse_cell_list[i]; - rd_cell_type *cell = - rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *cell = &rd_grid->cells[global_index]; if (cell_active_value & CELL_ACTIVE_MATRIX) cell->active_index[MATRIX_INDEX] = cell_active_index; @@ -1921,9 +1848,9 @@ rd_grid_get_or_create_coarse_cell(rd_grid_type *rd_grid, int coarse_nr) { static void rd_grid_init_coarse_cells(rd_grid_type *rd_grid) { if (rd_grid->coarsening_active) { - int global_index; - for (global_index = 0; global_index < rd_grid->size; global_index++) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + for (int global_index = 0; global_index < rd_grid->size; + global_index++) { + rd_cell_type *cell = &rd_grid->cells[global_index]; if (cell->coarse_group != COARSE_GROUP_NONE) { rd_coarse_cell_type *coarse_cell = rd_grid_get_or_create_coarse_cell(rd_grid, @@ -1943,7 +1870,7 @@ rd_coarse_cell_type *rd_grid_iget_coarse_group(const rd_grid_type *rd_grid, 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); + rd_cell_type *cell = &main_grid->cells[global_index]; if (cell->coarse_group == COARSE_GROUP_NONE) return false; else @@ -2066,15 +1993,12 @@ static void rd_grid_install_lgr_common(rd_grid_type *host_grid, static void rd_grid_install_lgr_EGRID(rd_grid_type *host_grid, rd_grid_type *lgr_grid, const int *hostnum) { - int global_lgr_index; + for (int i = 0; i < lgr_grid->size; i++) { + int host_index = hostnum[i] - 1; + rd_cell_type *lgr_cell = &lgr_grid->cells[i]; + rd_cell_type *host_cell = &host_grid->cells[host_index]; - for (global_lgr_index = 0; global_lgr_index < lgr_grid->size; - global_lgr_index++) { - int host_index = hostnum[global_lgr_index] - 1; - rd_cell_type *lgr_cell = rd_grid_get_cell(lgr_grid, global_lgr_index); - rd_cell_type *host_cell = rd_grid_get_cell(host_grid, host_index); - - rd_cell_install_lgr(host_cell, lgr_grid); + host_cell->lgr = lgr_grid; lgr_cell->host_cell = host_index; } rd_grid_install_lgr_common(host_grid, lgr_grid); @@ -2085,14 +2009,10 @@ static void rd_grid_install_lgr_EGRID(rd_grid_type *host_grid, */ static void rd_grid_install_lgr_GRID(rd_grid_type *host_grid, rd_grid_type *lgr_grid) { - int global_lgr_index; - - for (global_lgr_index = 0; global_lgr_index < lgr_grid->size; - global_lgr_index++) { - rd_cell_type *lgr_cell = rd_grid_get_cell(lgr_grid, global_lgr_index); - rd_cell_type *host_cell = - rd_grid_get_cell(host_grid, lgr_cell->host_cell); - rd_cell_install_lgr(host_cell, lgr_grid); + for (int i = 0; i < lgr_grid->size; i++) { + rd_cell_type *lgr_cell = &lgr_grid->cells[i]; + rd_cell_type *host_cell = &host_grid->cells[lgr_cell->host_cell]; + host_cell->lgr = lgr_grid; } rd_grid_install_lgr_common(host_grid, lgr_grid); } @@ -2190,9 +2110,7 @@ static void rd_grid_init_GRDECL_data_jslice(rd_grid_type *rd_grid, const int nx = rd_grid->nx; const int ny = rd_grid->ny; const int nz = rd_grid->nz; - int i; - - for (i = 0; i < nx; i++) { + for (int i = 0; i < nx; i++) { point_type pillars[4][2]; int pillar_index[4]; pillar_index[0] = 6 * (j * (nx + 1) + i); @@ -2200,60 +2118,46 @@ static void rd_grid_init_GRDECL_data_jslice(rd_grid_type *rd_grid, pillar_index[2] = 6 * ((j + 1) * (nx + 1) + i); pillar_index[3] = 6 * ((j + 1) * (nx + 1) + i + 1); - { - int ip; - for (ip = 0; ip < 4; ip++) { - int index = pillar_index[ip]; - point_set(&pillars[ip][0], coord[index], coord[index + 1], - coord[index + 2]); - - index += 3; - point_set(&pillars[ip][1], coord[index], coord[index + 1], - coord[index + 2]); - } + for (int ip = 0; ip < 4; ip++) { + int index = pillar_index[ip]; + point_set(&pillars[ip][0], coord[index], coord[index + 1], + coord[index + 2]); + + index += 3; + point_set(&pillars[ip][1], coord[index], coord[index + 1], + coord[index + 2]); } { double ex[4]; double ey[4]; double ez[4]; - int k; - { - int ip; - for (ip = 0; ip < 4; ip++) { - ex[ip] = pillars[ip][1].x - pillars[ip][0].x; - ey[ip] = pillars[ip][1].y - pillars[ip][0].y; - ez[ip] = pillars[ip][1].z - pillars[ip][0].z; - } + for (int ip = 0; ip < 4; ip++) { + ex[ip] = pillars[ip][1].x - pillars[ip][0].x; + ey[ip] = pillars[ip][1].y - pillars[ip][0].y; + ez[ip] = pillars[ip][1].z - pillars[ip][0].z; } - for (k = 0; k < nz; k++) { + for (int k = 0; k < nz; k++) { double x[4][2]; double y[4][2]; double z[4][2]; - { - int c; - for (c = 0; c < 2; c++) { - z[0][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + - c * 4 * nx * ny]; - z[1][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + - 1 + c * 4 * nx * ny]; - z[2][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + - 2 * i + c * 4 * nx * ny]; - z[3][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + - 2 * i + 1 + c * 4 * nx * ny]; - } + for (int c = 0; c < 2; c++) { + z[0][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + + c * 4 * nx * ny]; + z[1][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + 1 + + c * 4 * nx * ny]; + z[2][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + + 2 * i + c * 4 * nx * ny]; + z[3][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + + 2 * i + 1 + c * 4 * nx * ny]; } - { - int ip; - for (ip = 0; ip < 4; ip++) - rd_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], - ey[ip], ez[ip], z[ip], - x[ip], y[ip]); - } + for (int ip = 0; ip < 4; ip++) + rd_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], ey[ip], + ez[ip], z[ip], x[ip], y[ip]); rd_grid_set_cell_EGRID(rd_grid, i, j, k, x, y, z, actnum, corsnum); @@ -2270,9 +2174,7 @@ static void rd_grid_init_GRDECL_data_jslice(rd_grid_type *rd_grid, const int nx = rd_grid->nx; const int ny = rd_grid->ny; const int nz = rd_grid->nz; - int i; - - for (i = 0; i < nx; i++) { + for (int i = 0; i < nx; i++) { point_type pillars[4][2]; int pillar_index[4]; pillar_index[0] = 6 * (j * (nx + 1) + i); @@ -2280,60 +2182,46 @@ static void rd_grid_init_GRDECL_data_jslice(rd_grid_type *rd_grid, pillar_index[2] = 6 * ((j + 1) * (nx + 1) + i); pillar_index[3] = 6 * ((j + 1) * (nx + 1) + i + 1); - { - int ip; - for (ip = 0; ip < 4; ip++) { - int index = pillar_index[ip]; - point_set(&pillars[ip][0], coord[index], coord[index + 1], - coord[index + 2]); - - index += 3; - point_set(&pillars[ip][1], coord[index], coord[index + 1], - coord[index + 2]); - } + for (int ip = 0; ip < 4; ip++) { + int index = pillar_index[ip]; + point_set(&pillars[ip][0], coord[index], coord[index + 1], + coord[index + 2]); + + index += 3; + point_set(&pillars[ip][1], coord[index], coord[index + 1], + coord[index + 2]); } { double ex[4]; double ey[4]; double ez[4]; - int k; - { - int ip; - for (ip = 0; ip < 4; ip++) { - ex[ip] = pillars[ip][1].x - pillars[ip][0].x; - ey[ip] = pillars[ip][1].y - pillars[ip][0].y; - ez[ip] = pillars[ip][1].z - pillars[ip][0].z; - } + for (int ip = 0; ip < 4; ip++) { + ex[ip] = pillars[ip][1].x - pillars[ip][0].x; + ey[ip] = pillars[ip][1].y - pillars[ip][0].y; + ez[ip] = pillars[ip][1].z - pillars[ip][0].z; } - for (k = 0; k < nz; k++) { + for (int k = 0; k < nz; k++) { double x[4][2]; double y[4][2]; double z[4][2]; - { - int c; - for (c = 0; c < 2; c++) { - z[0][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + - c * 4 * nx * ny]; - z[1][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + - 1 + c * 4 * nx * ny]; - z[2][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + - 2 * i + c * 4 * nx * ny]; - z[3][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + - 2 * i + 1 + c * 4 * nx * ny]; - } + for (int c = 0; c < 2; c++) { + z[0][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + + c * 4 * nx * ny]; + z[1][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * i + 1 + + c * 4 * nx * ny]; + z[2][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + + 2 * i + c * 4 * nx * ny]; + z[3][c] = zcorn[k * 8 * nx * ny + j * 4 * nx + 2 * nx + + 2 * i + 1 + c * 4 * nx * ny]; } - { - int ip; - for (ip = 0; ip < 4; ip++) - rd_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], - ey[ip], ez[ip], z[ip], - x[ip], y[ip]); - } + for (int ip = 0; ip < 4; ip++) + rd_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], ey[ip], + ez[ip], z[ip], x[ip], y[ip]); rd_grid_set_cell_EGRID(rd_grid, i, j, k, x, y, z, actnum, corsnum); @@ -2447,12 +2335,11 @@ static void rd_grid_copy_mapaxes(rd_grid_type *target_grid, static void rd_grid_copy_content(rd_grid_type *target_grid, const rd_grid_type *src_grid) { - int global_index; - for (global_index = 0; global_index < src_grid->size; global_index++) { - rd_cell_type *target_cell = rd_grid_get_cell(target_grid, global_index); - const rd_cell_type *src_cell = rd_grid_get_cell(src_grid, global_index); + for (int i = 0; i < src_grid->size; i++) { + rd_cell_type *target_cell = &target_grid->cells[i]; + const rd_cell_type *src_cell = &src_grid->cells[i]; - rd_cell_memcpy(target_cell, src_cell); + memcpy(target_cell, src_cell, sizeof *target_cell); if (src_cell->nnc_info) target_cell->nnc_info = nnc_info_alloc_copy(src_cell->nnc_info); } @@ -2483,39 +2370,29 @@ static rd_grid_type *rd_grid_alloc_copy__(const rd_grid_type *src_grid, rd_grid_type *rd_grid_alloc_copy(const rd_grid_type *src_grid) { rd_grid_type *copy_grid = rd_grid_alloc_copy__(src_grid, NULL); - { - int grid_nr; - for (grid_nr = 0; grid_nr < vector_get_size(src_grid->LGR_list); - grid_nr++) { - const rd_grid_type *src_lgr = - (const rd_grid_type *)vector_iget_const(src_grid->LGR_list, - grid_nr); - rd_grid_type *copy_lgr = rd_grid_alloc_copy__(src_lgr, copy_grid); - rd_grid_type *host_grid; - - rd_grid_add_lgr( - copy_grid, - copy_lgr); // This handles the storage ownership of the LGR. - if (copy_lgr->parent_name == NULL) - host_grid = copy_grid; - else - host_grid = rd_grid_get_lgr(copy_grid, copy_lgr->parent_name); + for (int grid_nr = 0; grid_nr < vector_get_size(src_grid->LGR_list); + grid_nr++) { + const rd_grid_type *src_lgr = (const rd_grid_type *)vector_iget_const( + src_grid->LGR_list, grid_nr); + rd_grid_type *copy_lgr = rd_grid_alloc_copy__(src_lgr, copy_grid); + rd_grid_type *host_grid; - { - int global_lgr_index; + rd_grid_add_lgr( + copy_grid, + copy_lgr); // This handles the storage ownership of the LGR. + if (copy_lgr->parent_name == NULL) + host_grid = copy_grid; + else + host_grid = rd_grid_get_lgr(copy_grid, copy_lgr->parent_name); - for (global_lgr_index = 0; global_lgr_index < copy_lgr->size; - global_lgr_index++) { - rd_cell_type *lgr_cell = - rd_grid_get_cell(copy_lgr, global_lgr_index); - rd_cell_type *host_cell = - rd_grid_get_cell(host_grid, lgr_cell->host_cell); + for (int i = 0; i < copy_lgr->size; i++) { + rd_cell_type *lgr_cell = ©_lgr->cells[i]; + rd_cell_type *host_cell = &host_grid->cells[lgr_cell->host_cell]; - rd_cell_install_lgr(host_cell, copy_lgr); - } - rd_grid_install_lgr_common(host_grid, copy_lgr); - } + host_cell->lgr = copy_lgr; + host_cell->lgr = copy_grid; } + rd_grid_install_lgr_common(host_grid, copy_lgr); } return copy_grid; @@ -2631,7 +2508,7 @@ rd_grid_alloc_GRDECL_kw(int nx, int ny, int nz, const rd_kw_type *zcorn_kw, static void rd_grid_init_cell_nnc_info(rd_grid_type *rd_grid, int global_index) { - rd_cell_type *grid_cell = rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *grid_cell = &rd_grid->cells[global_index]; if (!grid_cell->nnc_info) grid_cell->nnc_info = nnc_info_alloc(rd_grid->lgr_nr); @@ -2682,7 +2559,7 @@ static void rd_grid_init_cell_nnc_info(rd_grid_type *rd_grid, void rd_grid_add_self_nnc(rd_grid_type *grid, int cell_index1, int cell_index2, int nnc_index) { - rd_cell_type *grid_cell = rd_grid_get_cell(grid, cell_index1); + rd_cell_type *grid_cell = &grid->cells[cell_index1]; rd_grid_init_cell_nnc_info(grid, cell_index1); nnc_info_add_nnc(grid_cell->nnc_info, grid->lgr_nr, cell_index2, nnc_index); } @@ -2709,8 +2586,7 @@ static void rd_grid_init_nnc_cells(rd_grid_type *grid1, rd_grid_type *grid2, int *grid2_nnc_cells = rd_kw_get_int_ptr(keyword2); int nnc_count = rd_kw_get_size(keyword2); - int nnc_index; - for (nnc_index = 0; nnc_index < nnc_count; nnc_index++) { + for (int nnc_index = 0; nnc_index < nnc_count; nnc_index++) { int grid1_cell_index = grid1_nnc_cells[nnc_index] - 1; int grid2_cell_index = grid2_nnc_cells[nnc_index] - 1; @@ -2733,8 +2609,7 @@ static void rd_grid_init_nnc_cells(rd_grid_type *grid1, rd_grid_type *grid2, break; { - rd_cell_type *grid1_cell = - rd_grid_get_cell(grid1, grid1_cell_index); + rd_cell_type *grid1_cell = &grid1->cells[grid1_cell_index]; rd_grid_init_cell_nnc_info(grid1, grid1_cell_index); nnc_info_add_nnc(grid1_cell->nnc_info, grid2->lgr_nr, grid2_cell_index, nnc_index); @@ -2747,7 +2622,6 @@ static void rd_grid_init_nnc_cells(rd_grid_type *grid1, rd_grid_type *grid2, */ static void rd_grid_init_nnc(rd_grid_type *main_grid, rd_file_type *rd_file) { int num_nnchead_kw = rd_file_get_num_named_kw(rd_file, NNCHEAD_KW); - int i; /* NB: There is a bug in Eclipse version 2015.1, for MPI runs with @@ -2760,7 +2634,7 @@ static void rd_grid_init_nnc(rd_grid_type *main_grid, rd_file_type *rd_file) { return; */ - for (i = 0; i < num_nnchead_kw; i++) { + for (int i = 0; i < num_nnchead_kw; i++) { rd_file_view_type *lgr_view = rd_file_alloc_global_blockview(rd_file, NNCHEAD_KW, i); rd_kw_type *nnchead_kw = @@ -2809,8 +2683,7 @@ static void rd_grid_init_nnc_amalgamated(rd_grid_type *main_grid, rd_file_type *rd_file) { int num_nncheada_kw = rd_file_get_num_named_kw(rd_file, NNCHEADA_KW); - int i; - for (i = 0; i < num_nncheada_kw; i++) { + for (int i = 0; i < num_nncheada_kw; i++) { rd_kw_type *nncheada_kw = rd_file_iget_named_kw(rd_file, NNCHEADA_KW, i); int lgr_nr1 = rd_kw_iget_int(nncheada_kw, NNCHEADA_ILOC1_INDEX); @@ -2919,9 +2792,8 @@ static rd_grid_type *rd_grid_alloc_EGRID_all_grids(const char *grid_file, int num_grid = rd_file_get_num_named_kw(rd_file, GRIDHEAD_KW); rd_grid_type *main_grid = rd_grid_alloc_EGRID__( NULL, rd_file, 0, apply_mapaxes, ext_actnum); - int grid_nr; - for (grid_nr = 1; grid_nr < num_grid; grid_nr++) { + for (int grid_nr = 1; grid_nr < num_grid; grid_nr++) { // The apply_mapaxes argument is ignored for LGR - // it inherits from parent anyway. rd_grid_type *lgr_grid = rd_grid_alloc_EGRID__( @@ -2970,12 +2842,9 @@ static rd_grid_type *rd_grid_alloc_GRID_data__( if (mapaxes != NULL) rd_grid_init_mapaxes(grid, apply_mapaxes, mapaxes); - { - int index; - for (index = 0; index < num_coords; index++) - rd_grid_set_cell_GRID(grid, coords_size, coords[index], - corners[index]); - } + for (int index = 0; index < num_coords; index++) + rd_grid_set_cell_GRID(grid, coords_size, coords[index], + corners[index]); rd_grid_init_coarse_cells(grid); rd_grid_update_index(grid); @@ -3113,13 +2982,12 @@ static rd_grid_type *rd_grid_alloc_GRID__(rd_grid_type *global_grid, // CORNERS keywords. { int coords_size = -1; - int index; int **coords = (int **)util_calloc(num_coords, sizeof *coords); float **corners = (float **)util_calloc(num_coords, sizeof *corners); - for (index = 0; index < num_coords; index++) { + for (int index = 0; index < num_coords; index++) { const rd_kw_type *coords_kw = rd_file_iget_named_kw( rd_file, COORDS_KW, index + cell_offset); const rd_kw_type *corners_kw = rd_file_iget_named_kw( @@ -3159,7 +3027,6 @@ static rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, rd_file_type *rd_file = rd_file_open(grid_file, 0); int num_grid = rd_file_get_num_named_kw(rd_file, DIMENS_KW); rd_grid_type *main_grid; - int grid_nr; int dualp_flag; dualp_flag = rd_grid_dual_porosity_GRID_check(rd_file); @@ -3167,7 +3034,7 @@ static rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, dualp_flag, apply_mapaxes); cell_offset += rd_grid_get_global_size(main_grid); - for (grid_nr = 1; grid_nr < num_grid; grid_nr++) { + for (int grid_nr = 1; grid_nr < num_grid; grid_nr++) { rd_grid_type *lgr_grid = rd_grid_alloc_GRID__( main_grid, rd_file, cell_offset, grid_nr, dualp_flag, false); cell_offset += rd_grid_get_global_size(lgr_grid); @@ -3211,10 +3078,9 @@ static rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, if (grid) { const double grid_offset[3] = {0, 0, 0}; - int k, j, i; - for (k = 0; k < nz; k++) { - for (j = 0; j < ny; j++) { - for (i = 0; i < nx; i++) { + for (int k = 0; k < nz; k++) { + for (int j = 0; j < ny; j++) { + for (int i = 0; i < nx; i++) { int global_index = i + j * nx + k * nx * ny; double offset[3] = {grid_offset[0] + i * ivec[0] + j * jvec[0] + k * kvec[0], @@ -3223,7 +3089,7 @@ static rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, grid_offset[2] + i * ivec[2] + j * jvec[2] + k * kvec[2]}; - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + rd_cell_type *cell = &grid->cells[global_index]; rd_cell_init_regular(cell, offset, i, j, k, global_index, ivec, jvec, kvec, actnum); } @@ -3406,9 +3272,8 @@ static bool rd_grid_compare_coarse_cells(const rd_grid_type *g1, if (vector_get_size(g1->coarse_cells) == vector_get_size(g2->coarse_cells)) { bool equal = true; - int c; - for (c = 0; c < vector_get_size(g1->coarse_cells); c++) { + for (int c = 0; c < vector_get_size(g1->coarse_cells); c++) { const rd_coarse_cell_type *coarse_cell1 = (const rd_coarse_cell_type *)vector_iget_const(g1->coarse_cells, c); @@ -3429,12 +3294,11 @@ static bool rd_grid_compare_coarse_cells(const rd_grid_type *g1, static bool rd_grid_compare_cells(const rd_grid_type *g1, const rd_grid_type *g2, bool include_nnc, bool verbose) { - int g; bool equal = true; - for (g = 0; g < g1->size; g++) { + for (int g = 0; g < g1->size; g++) { bool this_equal = true; - rd_cell_type *c1 = rd_grid_get_cell(g1, g); - rd_cell_type *c2 = rd_grid_get_cell(g2, g); + rd_cell_type *c1 = &g1->cells[g]; + rd_cell_type *c2 = &g2->cells[g]; rd_cell_compare(c1, c2, include_nnc, &this_equal); if (!this_equal) { @@ -3591,8 +3455,7 @@ bool rd_grid_compare(const rd_grid_type *g1, const rd_grid_type *g2, if (equal && include_lgr) { if (vector_get_size(g1->LGR_list) == vector_get_size(g2->LGR_list)) { - int grid_nr; - for (grid_nr = 0; grid_nr < vector_get_size(g1->LGR_list); + for (int grid_nr = 0; grid_nr < vector_get_size(g1->LGR_list); grid_nr++) { const rd_grid_type *lgr1 = (const rd_grid_type *)vector_iget_const(g1->LGR_list, @@ -3813,7 +3676,7 @@ static bool rd_grid_cell_contains_xyz3(const rd_grid_type *rd_grid, int i, 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)); + &rd_grid->cells[rd_grid_get_global_index3(rd_grid, i, j, k)]; point_set(&p, x, y, z); int method = (i + j + k) % @@ -3866,12 +3729,11 @@ bool rd_grid_cell_contains_xyz1(const rd_grid_type *rd_grid, int global_index, int rd_grid_get_global_index_from_xy(const rd_grid_type *rd_grid, int k, bool lower_layer, double x, double y) { - int i, j; - for (j = 0; j < rd_grid->ny; j++) - for (i = 0; i < rd_grid->nx; i++) { + for (int j = 0; j < rd_grid->ny; j++) + for (int i = 0; i < rd_grid->nx; i++) { int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); - if (rd_cell_layer_contains_xy( - rd_grid_get_cell(rd_grid, global_index), lower_layer, x, y)) + if (rd_cell_layer_contains_xy(&rd_grid->cells[global_index], + lower_layer, x, y)) return global_index; } return -1; /* Did not find x,y */ @@ -3881,11 +3743,8 @@ static void rd_grid_clear_visited(rd_grid_type *grid) { if (grid->visited == NULL) grid->visited = (bool *)util_calloc(grid->size, sizeof *grid->visited); - { - int i; - for (i = 0; i < grid->size; i++) - grid->visited[i] = false; - } + for (int i = 0; i < grid->size; i++) + grid->visited[i] = false; } /* @@ -3895,11 +3754,10 @@ static int rd_grid_box_contains_xyz(const rd_grid_type *grid, int i1, int i2, int j1, int j2, int k1, int k2, const point_type *p) { - int i, j, k; int global_index = -1; - for (k = k1; k < k2; k++) - for (j = j1; j < j2; j++) - for (i = i1; i < i2; i++) { + for (int k = k1; k < k2; k++) + for (int j = j1; j < j2; j++) + for (int i = i1; i < i2; i++) { global_index = rd_grid_get_global_index3(grid, i, j, k); if (!grid->visited[global_index]) { grid->visited[global_index] = true; @@ -4106,8 +3964,7 @@ void rd_grid_free(rd_grid_type *grid) { free(grid->mapaxes); if (grid->values != NULL) { - int i; - for (i = 0; i < grid->block_size; i++) + for (int i = 0; i < grid->block_size; i++) double_vector_free(grid->values[i]); free(grid->values); } @@ -4133,8 +3990,8 @@ void rd_grid_free__(void *arg) { void rd_grid_get_distance(const rd_grid_type *grid, int global_index1, int global_index2, double *dx, double *dy, double *dz) { - rd_cell_type *cell1 = rd_grid_get_cell(grid, global_index1); - rd_cell_type *cell2 = rd_grid_get_cell(grid, global_index2); + rd_cell_type *cell1 = &grid->cells[global_index1]; + rd_cell_type *cell2 = &grid->cells[global_index2]; rd_cell_assert_center(cell1); rd_cell_assert_center(cell2); @@ -4191,7 +4048,7 @@ int rd_grid_get_nactive_fracture(const rd_grid_type *grid) { 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); + const rd_cell_type *cell = &grid->cells[global_index]; return cell->host_cell; } @@ -4307,7 +4164,7 @@ void rd_grid_get_ijk1A(const rd_grid_type *rd_grid, int active_index, int *i, void rd_grid_get_xyz1(const rd_grid_type *grid, int global_index, double *xpos, double *ypos, double *zpos) { - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + rd_cell_type *cell = &grid->cells[global_index]; rd_cell_assert_center(cell); { *xpos = cell->center.x; @@ -4332,7 +4189,7 @@ void rd_grid_get_cell_corner_xyz1(const rd_grid_type *grid, int global_index, int corner_nr, double *xpos, double *ypos, double *zpos) { if ((corner_nr >= 0) && (corner_nr <= 7)) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; const point_type point = cell->corner_list[corner_nr]; *xpos = point.x; *ypos = point.y; @@ -4342,7 +4199,7 @@ void rd_grid_get_cell_corner_xyz1(const rd_grid_type *grid, int global_index, void rd_grid_export_cell_corners1(const rd_grid_type *grid, int global_index, double *x, double *y, double *z) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; for (int i = 0; i < 8; i++) { const point_type point = cell->corner_list[i]; x[i] = point.x; @@ -4402,7 +4259,7 @@ void rd_grid_get_xyz1A(const rd_grid_type *grid, int active_index, double *xpos, } double rd_grid_get_cdepth1(const rd_grid_type *grid, int global_index) { - rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + rd_cell_type *cell = &grid->cells[global_index]; rd_cell_assert_center(cell); return cell->center.z; } @@ -4441,11 +4298,10 @@ int rd_grid_locate_depth(const rd_grid_type *grid, double depth, int i, int j) { */ double rd_grid_get_top1(const rd_grid_type *grid, int global_index) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; double depth = 0; - int ij; - for (ij = 0; ij < 4; ij++) + for (int ij = 0; ij < 4; ij++) depth += cell->corner_list[ij].z; return depth * 0.25; @@ -4477,11 +4333,10 @@ double rd_grid_get_top1A(const rd_grid_type *grid, int active_index) { */ double rd_grid_get_bottom1(const rd_grid_type *grid, int global_index) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; double depth = 0; - int ij; - for (ij = 0; ij < 4; ij++) + for (int ij = 0; ij < 4; ij++) depth += cell->corner_list[ij + 4].z; return depth * 0.25; @@ -4493,11 +4348,10 @@ double rd_grid_get_bottom3(const rd_grid_type *grid, int i, int j, int k) { } 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); + const rd_cell_type *cell = &grid->cells[global_index]; double dz = 0; - int ij; - for (ij = 0; ij < 4; ij++) + for (int ij = 0; ij < 4; ij++) dz += (cell->corner_list[ij + 4].z - cell->corner_list[ij].z); return dz * 0.25; @@ -4513,12 +4367,11 @@ double rd_grid_get_cell_thickness1(const rd_grid_type *grid, int global_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); + const rd_cell_type *cell = &grid->cells[global_index]; double dx = 0; double dy = 0; - int c; - for (c = 1; c < 8; c += 2) { + for (int c = 1; c < 8; c += 2) { dx += cell->corner_list[c].x - cell->corner_list[c - 1].x; dy += cell->corner_list[c].y - cell->corner_list[c - 1].y; } @@ -4547,7 +4400,7 @@ double rd_grid_get_cell_dx1A(const rd_grid_type *grid, int active_index) { */ double rd_grid_get_cell_dy1(const rd_grid_type *grid, int global_index) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; double dx = 0; double dy = 0; @@ -4572,7 +4425,7 @@ double rd_grid_get_cell_dy1A(const rd_grid_type *grid, int active_index) { const nnc_info_type *rd_grid_get_cell_nnc_info1(const rd_grid_type *grid, int global_index) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; return cell->nnc_info; } @@ -4593,12 +4446,12 @@ bool rd_grid_cell_active3(const rd_grid_type *rd_grid, int i, int j, int k) { } bool rd_grid_cell_invalid1(const rd_grid_type *rd_grid, int global_index) { - rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + rd_cell_type *cell = &rd_grid->cells[global_index]; return GET_CELL_FLAG(cell, CELL_FLAG_TAINTED); } 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); + rd_cell_type *cell = &rd_grid->cells[global_index]; if (GET_CELL_FLAG(cell, CELL_FLAG_TAINTED)) return false; else @@ -4727,7 +4580,7 @@ rd_grid_type *rd_grid_get_lgr_from_lgr_nr(const rd_grid_type *main_grid, const rd_grid_type *rd_grid_get_cell_lgr1(const rd_grid_type *grid, int global_index) { - const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; return cell->lgr; } @@ -4798,7 +4651,7 @@ bool rd_grid_cell_regular1(const rd_grid_type *rd_grid, int 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); + rd_cell_type *cell = &rd_grid->cells[global_index]; int i, j, k; rd_grid_get_ijk1(rd_grid, global_index, &i, &j, &k); return rd_cell_get_volume(cell); @@ -4826,8 +4679,7 @@ void rd_grid_summarize(const rd_grid_type *rd_grid) { printf(" Origo Y................: %10.2f \n", rd_grid->origo[1]); if (RD_GRID_MAINGRID_LGR_NR == rd_grid->lgr_nr) { - int grid_nr; - for (grid_nr = 1; grid_nr < vector_get_size(rd_grid->LGR_list); + for (int grid_nr = 1; grid_nr < vector_get_size(rd_grid->LGR_list); grid_nr++) { printf("\n"); rd_grid_summarize((const rd_grid_type *)vector_iget_const( @@ -4936,22 +4788,16 @@ void rd_grid_get_column_property(const rd_grid_type *rd_grid, rd_kw_get_size(rd_kw)); double_vector_reset(column); - { - int k; - for (k = 0; k < rd_grid->nz; k++) { - if (use_global_index) { - int global_index = - rd_grid_get_global_index3(rd_grid, i, j, k); + for (int k = 0; k < rd_grid->nz; k++) { + if (use_global_index) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + double_vector_iset(column, k, + rd_kw_iget_as_double(rd_kw, global_index)); + } else { + int active_index = rd_grid_get_active_index3(rd_grid, i, j, k); + if (active_index >= 0) double_vector_iset( - column, k, rd_kw_iget_as_double(rd_kw, global_index)); - } else { - int active_index = - rd_grid_get_active_index3(rd_grid, i, j, k); - if (active_index >= 0) - double_vector_iset( - column, k, - rd_kw_iget_as_double(rd_kw, active_index)); - } + column, k, rd_kw_iget_as_double(rd_kw, active_index)); } } } else @@ -5013,8 +4859,7 @@ static bool rd_grid_test_lgr_consistency2(const rd_grid_type *parent, const rd_grid_type *child) { bool consistent = true; int child_size = rd_grid_get_global_size(child); - int child_index; - for (child_index = 0; child_index < child_size; child_index++) { + for (int child_index = 0; child_index < child_size; child_index++) { int parent_cell = rd_grid_get_parent_cell1(child, child_index); if (parent_cell >= 0) { const rd_grid_type *child_test = @@ -5055,12 +4900,10 @@ static void rd_grid_dump__(const rd_grid_type *grid, FILE *stream) { util_fwrite_int_vector(grid->inv_index_map, grid->total_active, stream, __func__); - { - int i; - for (i = 0; i < grid->size; i++) { - const rd_cell_type *cell = rd_grid_get_cell(grid, i); - rd_cell_dump(cell, stream); - } + for (int i = 0; i < grid->size; i++) { + const rd_cell_type *cell = &grid->cells[i]; + for (int j = 0; j < 8; j++) + point_dump(&cell->corner_list[i], stream); } } @@ -5074,15 +4917,12 @@ static void rd_grid_dump_ascii__(rd_grid_type *grid, bool active_only, fprintf(stream, "nactive : %6d\n", grid->total_active); fprintf(stream, "nactive fracture : %6d\n", grid->total_active_fracture); - { - int l; - for (l = 0; l < grid->size; l++) { - rd_cell_type *cell = rd_grid_get_cell(grid, l); - if (cell->active_index[MATRIX_INDEX] >= 0 || !active_only) { - int i, j, k; - rd_grid_get_ijk1(grid, l, &i, &j, &k); - rd_cell_dump_ascii(cell, i, j, k, stream, NULL); - } + for (int l = 0; l < grid->size; l++) { + rd_cell_type *cell = &grid->cells[l]; + if (cell->active_index[MATRIX_INDEX] >= 0 || !active_only) { + int i, j, k; + rd_grid_get_ijk1(grid, l, &i, &j, &k); + rd_cell_dump_ascii(cell, i, j, k, stream, NULL); } } } @@ -5097,23 +4937,16 @@ static void rd_grid_dump_ascii__(rd_grid_type *grid, bool active_only, void rd_grid_dump(const rd_grid_type *grid, FILE *stream) { rd_grid_dump__(grid, stream); - { - int i; - for (i = 0; i < vector_get_size(grid->LGR_list); i++) - rd_grid_dump__( - (const rd_grid_type *)vector_iget_const(grid->LGR_list, i), - stream); - } + for (int i = 0; i < vector_get_size(grid->LGR_list); i++) + rd_grid_dump__( + (const rd_grid_type *)vector_iget_const(grid->LGR_list, i), stream); } void rd_grid_dump_ascii(rd_grid_type *grid, bool active_only, FILE *stream) { rd_grid_dump_ascii__(grid, active_only, stream); - { - int i; - for (i = 0; i < vector_get_size(grid->LGR_list); i++) - rd_grid_dump_ascii__((rd_grid_type *)vector_iget(grid->LGR_list, i), - active_only, stream); - } + for (int i = 0; i < vector_get_size(grid->LGR_list); i++) + rd_grid_dump_ascii__((rd_grid_type *)vector_iget(grid->LGR_list, i), + active_only, stream); } /* @@ -5149,15 +4982,7 @@ bool rd_grid_use_mapaxes(const rd_grid_type *grid) { return grid->use_mapaxes; } void rd_grid_init_mapaxes_data_double(const rd_grid_type *grid, double *mapaxes) { - int i; - for (i = 0; i < 6; i++) - mapaxes[i] = grid->mapaxes[i]; -} - -static void rd_grid_init_mapaxes_data_float(const rd_grid_type *grid, - float *mapaxes) { - int i; - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) mapaxes[i] = grid->mapaxes[i]; } @@ -5310,8 +5135,7 @@ static void rd_grid_fwrite_GRID__(const rd_grid_type *grid, int coords_size, for (i = 0; i < grid->nx; i++) { int global_index = rd_grid_get_global_index__(grid, i, j, k); - const rd_cell_type *cell = - rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; rd_cell_fwrite_GRID(grid, cell, false, coords_size, i, j, k, global_index, coords_kw, corners_kw, @@ -5326,8 +5150,7 @@ static void rd_grid_fwrite_GRID__(const rd_grid_type *grid, int coords_size, for (i = 0; i < grid->nx; i++) { int global_index = rd_grid_get_global_index__( grid, i, j, k - grid->nz); - const rd_cell_type *cell = - rd_grid_get_cell(grid, global_index); + const rd_cell_type *cell = &grid->cells[global_index]; rd_cell_fwrite_GRID(grid, cell, true, coords_size, i, j, k, global_index, coords_kw, @@ -5356,14 +5179,11 @@ void rd_grid_fwrite_GRID2(const rd_grid_type *grid, const char *filename, rd_grid_fwrite_GRID__(grid, coords_size, fortio, output_unit); - { - int grid_nr; - for (grid_nr = 0; grid_nr < vector_get_size(grid->LGR_list); - grid_nr++) { - const rd_grid_type *igrid = (const rd_grid_type *)vector_iget_const( - grid->LGR_list, grid_nr); - rd_grid_fwrite_GRID__(igrid, coords_size, fortio, output_unit); - } + for (int grid_nr = 0; grid_nr < vector_get_size(grid->LGR_list); + grid_nr++) { + const rd_grid_type *igrid = + (const rd_grid_type *)vector_iget_const(grid->LGR_list, grid_nr); + rd_grid_fwrite_GRID__(igrid, coords_size, fortio, output_unit); } fortio_fclose(fortio); } @@ -5441,10 +5261,9 @@ static int rd_grid_get_valid_index(const rd_grid_type *grid, int i, int j, int delta = (k1 < k2) ? 1 : -1; while (true) { - rd_cell_type *cell; global_index = rd_grid_get_global_index3(grid, i, j, k); - cell = rd_grid_get_cell(grid, global_index); + rd_cell_type *cell = &grid->cells[global_index]; if (GET_CELL_FLAG(cell, CELL_FLAG_VALID)) return global_index; else { @@ -5481,8 +5300,8 @@ static bool rd_grid_init_coord_section__(const rd_grid_type *grid, int i, int j, point_type top_point; point_type bottom_point; - const rd_cell_type *bottom_cell = rd_grid_get_cell(grid, bottom_index); - const rd_cell_type *top_cell = rd_grid_get_cell(grid, top_index); + const rd_cell_type *bottom_cell = &grid->cells[bottom_index]; + const rd_cell_type *top_cell = &grid->cells[top_index]; /* 2---3 @@ -5560,9 +5379,8 @@ void rd_grid_init_coord_data(const rd_grid_type *grid, float *coord) { chunks of data, where each chunk contains the coordinates (x,y,z) of the top and the bottom of the pillar. */ - int i, j; - for (j = 0; j <= grid->ny; j++) { - for (i = 0; i <= grid->nx; i++) + for (int j = 0; j <= grid->ny; j++) { + for (int i = 0; i <= grid->nx; i++) rd_grid_init_coord_section(grid, i, j, coord, NULL); } } @@ -5574,9 +5392,8 @@ void rd_grid_init_coord_data_double(const rd_grid_type *grid, double *coord) { chunks of data, where each chunk contains the coordinates (x,y,z) f the top and the bottom of the pillar. */ - int i, j; - for (j = 0; j <= grid->ny; j++) { - for (i = 0; i <= grid->nx; i++) + for (int j = 0; j <= grid->ny; j++) { + for (int i = 0; i <= grid->nx; i++) rd_grid_init_coord_section(grid, i, j, NULL, coord); } } @@ -5603,15 +5420,12 @@ static void rd_grid_init_zcorn_data__(const rd_grid_type *grid, int nx = grid->nx; int ny = grid->ny; int nz = grid->nz; - int i, j, k; - for (j = 0; j < ny; j++) { - for (i = 0; i < nx; i++) { - for (k = 0; k < nz; k++) { + for (int j = 0; j < ny; j++) { + for (int i = 0; i < nx; i++) { + for (int k = 0; k < nz; k++) { const int cell_index = rd_grid_get_global_index3(grid, i, j, k); - const rd_cell_type *cell = rd_grid_get_cell(grid, cell_index); - int l; - - for (l = 0; l < 2; l++) { + const rd_cell_type *cell = &grid->cells[cell_index]; + for (int l = 0; l < 2; l++) { point_type p0 = cell->corner_list[4 * l]; point_type p1 = cell->corner_list[4 * l + 1]; point_type p2 = cell->corner_list[4 * l + 2]; @@ -5680,9 +5494,8 @@ int rd_grid_get_zcorn_size(const rd_grid_type *grid) { } void rd_grid_init_actnum_data(const rd_grid_type *grid, int *actnum) { - int i; - for (i = 0; i < grid->size; i++) { - const rd_cell_type *cell = rd_grid_get_cell(grid, i); + for (int i = 0; i < grid->size; i++) { + const rd_cell_type *cell = &grid->cells[i]; if (cell->coarse_group == COARSE_GROUP_NONE) actnum[i] = cell->active; else { @@ -5696,8 +5509,7 @@ void rd_grid_init_actnum_data(const rd_grid_type *grid, int *actnum) { int group_size = rd_coarse_cell_get_size(coarse_cell); const int *index_ptr = rd_coarse_cell_get_index_ptr(coarse_cell); - int j; - for (j = 0; j < group_size; j++) + for (int j = 0; j < group_size; j++) actnum[index_ptr[j]] = CELL_NOT_ACTIVE; } @@ -5705,9 +5517,8 @@ void rd_grid_init_actnum_data(const rd_grid_type *grid, int *actnum) { and mark them correctly. */ { int num_active = rd_coarse_cell_get_num_active(coarse_cell); - int j; - for (j = 0; j < num_active; j++) { + for (int j = 0; j < num_active; j++) { int global_index = rd_coarse_cell_iget_active_cell_index(coarse_cell, j); int active_value = @@ -5731,8 +5542,7 @@ void rd_grid_compressed_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, if ((rd_kw_get_size(target_kw) == rd_grid_get_nactive(grid)) && (rd_kw_get_size(src_kw) == rd_grid_get_global_size(grid))) { int active_index = 0; - int global_index; - for (global_index = 0; global_index < rd_grid_get_global_size(grid); + for (int global_index = 0; global_index < rd_grid_get_global_size(grid); global_index++) { if (rd_grid_cell_active1(grid, global_index)) { rd_kw_iset(target_kw, active_index, @@ -5751,8 +5561,7 @@ void rd_grid_global_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, if ((rd_kw_get_size(src_kw) == rd_grid_get_nactive(grid)) && (rd_kw_get_size(target_kw) == rd_grid_get_global_size(grid))) { int active_index = 0; - int global_index; - for (global_index = 0; global_index < rd_grid_get_global_size(grid); + for (int global_index = 0; global_index < rd_grid_get_global_size(grid); global_index++) { if (rd_grid_cell_active1(grid, global_index)) { rd_kw_iset(target_kw, global_index, @@ -5767,9 +5576,8 @@ void rd_grid_global_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, } static void rd_grid_init_hostnum_data(const rd_grid_type *grid, int *hostnum) { - int i; - for (i = 0; i < grid->size; i++) { - const rd_cell_type *cell = rd_grid_get_cell(grid, i); + for (int i = 0; i < grid->size; i++) { + const rd_cell_type *cell = &grid->cells[i]; hostnum[i] = cell->host_cell; } } @@ -5781,9 +5589,8 @@ static rd_kw_type *rd_grid_alloc_hostnum_kw(const rd_grid_type *grid) { } static void rd_grid_init_corsnum_data(const rd_grid_type *grid, int *corsnum) { - int i; - for (i = 0; i < grid->size; i++) { - const rd_cell_type *cell = rd_grid_get_cell(grid, i); + for (int i = 0; i < grid->size; i++) { + const rd_cell_type *cell = &grid->cells[i]; corsnum[i] = cell->coarse_group + 1; } } @@ -5796,9 +5603,8 @@ static rd_kw_type *rd_grid_alloc_corsnum_kw(const rd_grid_type *grid) { void rd_grid_reset_actnum(rd_grid_type *grid, const int *actnum) { const int global_size = rd_grid_get_global_size(grid); - int g; - for (g = 0; g < global_size; g++) { - rd_cell_type *cell = rd_grid_get_cell(grid, g); + for (int g = 0; g < global_size; g++) { + rd_cell_type *cell = &grid->cells[g]; if (actnum) cell->active = actnum[g]; else @@ -5812,16 +5618,13 @@ static void rd_grid_fwrite_self_nnc(const rd_grid_type *grid, const int default_index = 1; int_vector_type *g1 = int_vector_alloc(0, default_index); int_vector_type *g2 = int_vector_alloc(0, default_index); - int g; - - for (g = 0; g < rd_grid_get_global_size(grid); g++) { - rd_cell_type *cell = rd_grid_get_cell(grid, g); + for (int g = 0; g < rd_grid_get_global_size(grid); g++) { + rd_cell_type *cell = &grid->cells[g]; const nnc_info_type *nnc_info = cell->nnc_info; if (nnc_info) { const nnc_vector_type *nnc_vector = nnc_info_get_self_vector(nnc_info); - int i; - for (i = 0; i < nnc_vector_get_size(nnc_vector); i++) { + for (int i = 0; i < nnc_vector_get_size(nnc_vector); i++) { int nnc_index = nnc_vector_iget_nnc_index(nnc_vector, i); int_vector_iset(g1, nnc_index, 1 + g); int_vector_iset(g2, nnc_index, @@ -5946,14 +5749,11 @@ void rd_grid_fwrite_EGRID2(rd_grid_type *grid, const char *filename, fortio_open_writer(filename, fmt_file, RD_ENDIAN_FLIP); rd_grid_fwrite_EGRID__(grid, fortio, output_unit); - { - int grid_nr; - for (grid_nr = 0; grid_nr < vector_get_size(grid->LGR_list); - grid_nr++) { - rd_grid_type *igrid = - (rd_grid_type *)vector_iget(grid->LGR_list, grid_nr); - rd_grid_fwrite_EGRID__(igrid, fortio, output_unit); - } + for (int grid_nr = 0; grid_nr < vector_get_size(grid->LGR_list); + grid_nr++) { + rd_grid_type *igrid = + (rd_grid_type *)vector_iget(grid->LGR_list, grid_nr); + rd_grid_fwrite_EGRID__(igrid, fortio, output_unit); } fortio_fclose(fortio); } @@ -6046,9 +5846,8 @@ bool rd_grid_dual_grid(const rd_grid_type *rd_grid) { } static int rd_grid_get_num_nnc__(const rd_grid_type *grid) { - int g; int num_nnc = 0; - for (g = 0; g < grid->size; g++) { + for (int g = 0; g < grid->size; g++) { const nnc_info_type *nnc_info = rd_grid_get_cell_nnc_info1(grid, g); if (nnc_info) num_nnc += nnc_info_get_total_size(nnc_info); @@ -6058,14 +5857,11 @@ static int rd_grid_get_num_nnc__(const rd_grid_type *grid) { int rd_grid_get_num_nnc(const rd_grid_type *grid) { int num_nnc = rd_grid_get_num_nnc__(grid); - { - int grid_nr; - for (grid_nr = 0; grid_nr < vector_get_size(grid->LGR_list); - grid_nr++) { - rd_grid_type *igrid = - (rd_grid_type *)vector_iget(grid->LGR_list, grid_nr); - num_nnc += rd_grid_get_num_nnc__(igrid); - } + for (int grid_nr = 0; grid_nr < vector_get_size(grid->LGR_list); + grid_nr++) { + rd_grid_type *igrid = + (rd_grid_type *)vector_iget(grid->LGR_list, grid_nr); + num_nnc += rd_grid_get_num_nnc__(igrid); } return num_nnc; } @@ -6075,8 +5871,7 @@ static rd_kw_type *rd_grid_alloc_volume_kw_active(const rd_grid_type *grid) { rd_kw_alloc("VOLUME", rd_grid_get_active_size(grid), RD_DOUBLE); { double *volume_data = (double *)rd_kw_get_ptr(volume_kw); - int active_index; - for (active_index = 0; active_index < rd_grid_get_active_size(grid); + for (int active_index = 0; active_index < rd_grid_get_active_size(grid); active_index++) { double cell_volume = rd_grid_get_cell_volume1A(grid, active_index); volume_data[active_index] = cell_volume; @@ -6090,8 +5885,7 @@ static rd_kw_type *rd_grid_alloc_volume_kw_global(const rd_grid_type *grid) { rd_kw_alloc("VOLUME", rd_grid_get_global_size(grid), RD_DOUBLE); { double *volume_data = (double *)rd_kw_get_ptr(volume_kw); - int global_index; - for (global_index = 0; global_index < rd_grid_get_global_size(grid); + for (int global_index = 0; global_index < rd_grid_get_global_size(grid); global_index++) { double cell_volume = rd_grid_get_cell_volume1(grid, global_index); volume_data[global_index] = cell_volume;