From 33b954b3f47cea96e4837ed0076e2bc68b0632c0 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Thu, 22 Aug 2024 07:50:42 +0200 Subject: [PATCH] Remove unused rd_nnc_export c code --- lib/CMakeLists.txt | 37 -- lib/include/resdata/rd_nnc_data.hpp | 40 -- lib/include/resdata/rd_nnc_export.hpp | 50 --- lib/include/resdata/rd_nnc_geometry.hpp | 36 -- lib/resdata/rd_nnc_data.cpp | 271 ------------- lib/resdata/rd_nnc_export.cpp | 289 -------------- lib/resdata/rd_nnc_geometry.cpp | 119 ------ .../tests/rd_nnc_data_equinor_root.cpp | 113 ------ lib/resdata/tests/rd_nnc_export.cpp | 359 ------------------ lib/resdata/tests/rd_nnc_export_get_tran.cpp | 149 -------- lib/resdata/tests/rd_nnc_export_intersect.cpp | 95 ----- lib/resdata/tests/rd_nnc_geometry.cpp | 62 --- lib/resdata/tests/rd_nnc_pair.cpp | 22 -- lib/resdata/tests/test_rd_nnc_data.cpp | 81 ---- 14 files changed, 1723 deletions(-) delete mode 100644 lib/include/resdata/rd_nnc_data.hpp delete mode 100644 lib/include/resdata/rd_nnc_export.hpp delete mode 100644 lib/include/resdata/rd_nnc_geometry.hpp delete mode 100644 lib/resdata/rd_nnc_data.cpp delete mode 100644 lib/resdata/rd_nnc_export.cpp delete mode 100644 lib/resdata/rd_nnc_geometry.cpp delete mode 100644 lib/resdata/tests/rd_nnc_data_equinor_root.cpp delete mode 100644 lib/resdata/tests/rd_nnc_export.cpp delete mode 100644 lib/resdata/tests/rd_nnc_export_get_tran.cpp delete mode 100644 lib/resdata/tests/rd_nnc_export_intersect.cpp delete mode 100644 lib/resdata/tests/rd_nnc_geometry.cpp delete mode 100644 lib/resdata/tests/rd_nnc_pair.cpp delete mode 100644 lib/resdata/tests/test_rd_nnc_data.cpp diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2fee2b385..5c8c64f3e 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -87,9 +87,6 @@ add_library( resdata/nnc_info.cpp resdata/rd_grav_common.cpp resdata/nnc_vector.cpp - resdata/rd_nnc_export.cpp - resdata/rd_nnc_data.cpp - resdata/rd_nnc_geometry.cpp resdata/layer.cpp resdata/fault_block.cpp resdata/fault_block_layer.cpp @@ -259,7 +256,6 @@ foreach( rd_grid_export rd_grid_init_fwrite rd_grid_reset_actnum - rd_nnc_export_intersect rd_sum_restart rd_sum_data_intermediate_test rd_unsmry_loader_test @@ -269,7 +265,6 @@ foreach( rd_kw_fread rd_kw_grdecl rd_kw_init - rd_nnc_geometry rd_nnc_info_test rd_nnc_vector rd_rft_cell @@ -281,8 +276,6 @@ foreach( rd_filenames rd_make_date_no_shift rd_make_date_shift - test_rd_nnc_data - rd_nnc_pair well_conn_collection well_branch_collection well_conn @@ -355,9 +348,6 @@ foreach( rd_coarse_test rd_grid_layer_contains rd_restart_test - rd_nnc_export - rd_nnc_export_get_tran - rd_nnc_data_equinor_root rd_grid_lgr_name rd_region rd_grid_cell_contains_wellpath @@ -415,33 +405,6 @@ add_test(NAME rd_coarse_test COMMAND rd_coarse_test add_test(NAME rd_restart_test COMMAND rd_restart_test ${_resdatapath}/Gurbat/ECLIPSE.UNRST) -add_test(NAME rd_nnc_export_gurbat COMMAND rd_nnc_export - ${_resdatapath}/Gurbat/ECLIPSE TRUE) -add_test(NAME rd_nnc_export_10kcase - COMMAND rd_nnc_export ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC TRUE) -add_test(NAME rd_nnc_export_dual_poro_diff - COMMAND rd_nnc_export ${_resdatapath}/DualPoro/DUAL_DIFF TRUE) -add_test(NAME rd_nnc_export_dual_poro - COMMAND rd_nnc_export ${_resdatapath}/DualPoro/DUALPORO TRUE) -add_test(NAME rd_nnc_export_nested_lgr_case - COMMAND rd_nnc_export ${_resdatapath}/nestedLGRcase/TESTCASE_NESTEDLGR - TRUE) -add_test(NAME rd_nnc_export_tyrihans - COMMAND rd_nnc_export ${_resdatapath}/TYRIHANS/BASE20150218_MULTFLT - FALSE) - -add_test( - NAME rd_nnc_export_get_tran - COMMAND rd_nnc_export_get_tran - ${_resdatapath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3) - -add_test( - NAME rd_nnc_data_equinor_root - COMMAND - rd_nnc_data_equinor_root - ${_resdatapath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3 - ${_resdatapath}/flow-nnc/Simple4/SIMPLE_SUMMARY4) - add_test( NAME rd_grid_lgr_name COMMAND diff --git a/lib/include/resdata/rd_nnc_data.hpp b/lib/include/resdata/rd_nnc_data.hpp deleted file mode 100644 index 4d14a0de5..000000000 --- a/lib/include/resdata/rd_nnc_data.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef RD_NNC_DATA_H -#define RD_NNC_DATA_H - -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct rd_nnc_data_struct rd_nnc_data_type; - -rd_nnc_data_type *rd_nnc_data_alloc_tran(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file); -rd_nnc_data_type * -rd_nnc_data_alloc_wat_flux(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file); -rd_nnc_data_type * -rd_nnc_data_alloc_oil_flux(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file); -rd_nnc_data_type * -rd_nnc_data_alloc_gas_flux(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file); -void rd_nnc_data_free(rd_nnc_data_type *data); - -int rd_nnc_data_get_size(rd_nnc_data_type *data); -const double *rd_nnc_data_get_values(const rd_nnc_data_type *data); - -double rd_nnc_data_iget_value(const rd_nnc_data_type *data, int index); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/resdata/rd_nnc_export.hpp b/lib/include/resdata/rd_nnc_export.hpp deleted file mode 100644 index 2bc1771a6..000000000 --- a/lib/include/resdata/rd_nnc_export.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef ERT_RD_NNC_EXPORT -#define ERT_RD_NNC_EXPORT - -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define ERT_RD_DEFAULT_NNC_TRANS HUGE_VAL - -typedef struct { - int grid_nr1; - int global_index1; - int grid_nr2; - int global_index2; - - int input_index; /* corresponds to the input ordering of this nnc */ - - double trans; -} rd_nnc_type; - -bool rd_nnc_intersect_format(const rd_grid_type *grid, - const rd_file_type *init_file); -int rd_nnc_export_get_size(const rd_grid_type *grid, - const rd_file_type *init_file); -int rd_nnc_export(const rd_grid_type *grid, const rd_file_type *init_file, - rd_nnc_type *nnc_data); - -rd_kw_type *rd_nnc_export_get_tranx_kw(const rd_grid_type *grid, - const rd_file_type *init_file, - int lgr_nr1, int lgr_nr2); -rd_kw_type *rd_nnc_export_get_tranll_kw(const rd_grid_type *grid, - const rd_file_type *init_file, - int lgr_nr1, int lgr_nr2); -rd_kw_type *rd_nnc_export_get_tran_kw(const rd_file_type *init_file, - const char *kw, int lgr_nr); - -bool rd_nnc_equal(const rd_nnc_type *nnc1, const rd_nnc_type *nnc2); -int rd_nnc_sort_cmp(const rd_nnc_type *nnc1, const rd_nnc_type *nnc2); -void rd_nnc_sort(rd_nnc_type *nnc_list, int size); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/resdata/rd_nnc_geometry.hpp b/lib/include/resdata/rd_nnc_geometry.hpp deleted file mode 100644 index b3a3fd001..000000000 --- a/lib/include/resdata/rd_nnc_geometry.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef ERT_NNC_GEOMETRY_H -#define ERT_NNC_GEOMETRY_H - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct rd_nnc_geometry_struct rd_nnc_geometry_type; -typedef struct rd_nnc_pair_struct rd_nnc_pair_type; - -struct rd_nnc_pair_struct { - int grid_nr1; - int global_index1; - int grid_nr2; - int global_index2; - - int input_index; /* corresponds to the input ordering of this nnc */ -}; - -UTIL_IS_INSTANCE_HEADER(rd_nnc_geometry); -void rd_nnc_geometry_free(rd_nnc_geometry_type *nnc_geo); -rd_nnc_geometry_type *rd_nnc_geometry_alloc(const rd_grid_type *grid); -int rd_nnc_geometry_size(const rd_nnc_geometry_type *nnc_geo); -const rd_nnc_pair_type * -rd_nnc_geometry_iget(const rd_nnc_geometry_type *nnc_geo, int index); -bool rd_nnc_geometry_same_kw(const rd_nnc_pair_type *nnc1, - const rd_nnc_pair_type *nnc2); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/resdata/rd_nnc_data.cpp b/lib/resdata/rd_nnc_data.cpp deleted file mode 100644 index b9b3b9d82..000000000 --- a/lib/resdata/rd_nnc_data.cpp +++ /dev/null @@ -1,271 +0,0 @@ -#define RD_NNC_DATA_TYPE_ID 83756236 -#include - -#include -#include -#include -#include -#include -#include - -enum kw_data_type { - TRANS_DATA = 1, - WTR_FLUX_DATA = 2, - OIL_FLUX_DATA = 3, - GAS_FLUX_DATA = 4 -}; - -struct rd_nnc_data_struct { - UTIL_TYPE_ID_DECLARATION; - int size; - double *values; -}; - -static const char *rd_nnc_data_get_str_kw(int kw_type, int grid1, int grid2) { - const char *kw = NULL; - switch (kw_type) { - - case TRANS_DATA: - if (grid1 == grid2) - kw = TRANNNC_KW; - else if (grid1 == 0) - kw = TRANGL_KW; - else - kw = TRANLL_KW; - break; - - case WTR_FLUX_DATA: - if (grid1 == grid2) - kw = FLRWATNNC_KW; - else if (grid1 == 0) - kw = FLRWATLG_KW; - else - kw = FLRWATLL_KW; - break; - - case OIL_FLUX_DATA: - if (grid1 == grid2) - kw = FLROILNNC_KW; - else if (grid1 == 0) - kw = FLROILLG_KW; - else - kw = FLROILLL_KW; - break; - - case GAS_FLUX_DATA: - if (grid1 == grid2) - kw = FLRGASNNC_KW; - else if (grid1 == 0) - kw = FLRGASLG_KW; - else - kw = FLRGASLL_KW; - break; - - default: - kw = NULL; - } - return kw; -} - -static rd_kw_type * -rd_nnc_data_get_gl_kw(const rd_file_view_type *init_file_view, const char *kw, - int kw_type, int lgr_nr) { - if (!kw) - return NULL; - - if (lgr_nr == 0) { - if (rd_file_view_has_kw(init_file_view, kw)) - return rd_file_view_iget_named_kw(init_file_view, kw, 0); - else - return NULL; - } - - bool correct_lgrheadi = false; - const int file_num_kw = rd_file_view_get_size(init_file_view); - for (int kw_index = 0, head_index = 0; kw_index < file_num_kw; ++kw_index) { - rd_kw_type *rd_kw = rd_file_view_iget_kw(init_file_view, kw_index); - const char *current_kw = rd_kw_get_header(rd_kw); - - if (strcmp(LGRHEADI_KW, current_kw) == 0) { - if (rd_kw_iget_int(rd_kw, LGRHEADI_LGR_NR_INDEX) == lgr_nr) { - correct_lgrheadi = true; - head_index = kw_index; - } else { - correct_lgrheadi = false; - } - } - - if (correct_lgrheadi && strcmp(kw, current_kw) == 0) { - /* This is to calculate who fare from lgrheadi we found the TRANGL/TRANNNC key word */ - int steps = kw_index - head_index; - /* We only support a file format where TRANNNC is 3 steps and TRANGL is 4 or 6 steps from LGRHEADI */ - if (kw_type != TRANS_DATA || steps == 3 || steps == 4 || - steps == 6) { - return rd_kw; - } - } - } - - return NULL; -} - -static rd_kw_type * -rd_nnc_data_get_tranll_kw(const rd_grid_type *grid, - const rd_file_view_type *init_file_view, int lgr_nr1, - int lgr_nr2) { - const char *lgr_name1 = rd_grid_get_lgr_name(grid, lgr_nr1); - const char *lgr_name2 = rd_grid_get_lgr_name(grid, lgr_nr2); - - rd_kw_type *tran_kw = NULL; - const int file_num_kw = rd_file_view_get_size(init_file_view); - int global_kw_index = 0; - - while (true) { - if (global_kw_index >= file_num_kw) - break; - { - rd_kw_type *rd_kw = - rd_file_view_iget_kw(init_file_view, global_kw_index); - if (strcmp(LGRJOIN_KW, rd_kw_get_header(rd_kw)) == 0) { - - if (rd_kw_icmp_string(rd_kw, 0, lgr_name1) && - rd_kw_icmp_string(rd_kw, 1, lgr_name2)) { - tran_kw = rd_file_view_iget_kw(init_file_view, - global_kw_index + 1); - break; - } - } - global_kw_index++; - } - } - - return tran_kw; -} - -static rd_kw_type *rd_nnc_data_get_kw(const rd_grid_type *grid, - const rd_file_view_type *init_file_view, - int lgr_nr1, int lgr_nr2, int kw_type) { - - const char *kw = rd_nnc_data_get_str_kw(kw_type, lgr_nr1, lgr_nr2); - if (lgr_nr1 == 0 || lgr_nr1 == lgr_nr2) - return rd_nnc_data_get_gl_kw(init_file_view, kw, kw_type, lgr_nr2); - else if (kw_type == TRANS_DATA) - return rd_nnc_data_get_tranll_kw(grid, init_file_view, lgr_nr1, - lgr_nr2); - else - return NULL; -} - -static void assert_correct_kw_count(rd_kw_type *kw, const char *function_name, - int correct_kw_count, int kw_count) { - if (correct_kw_count != kw_count) - util_abort("In function %s, reading kw: %s. %d != %d", function_name, - rd_kw_get_header(kw), correct_kw_count, kw_count); -} - -static bool rd_nnc_data_set_values(rd_nnc_data_type *data, - const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file, - int kw_type) { - - int current_grid1 = -1; - int current_grid2 = -1; - rd_kw_type *current_kw = NULL; - int correct_kw_count = 0; - int kw_count = 0; - int nnc_size = rd_nnc_geometry_size(nnc_geo); - - for (int nnc_index = 0; nnc_index < nnc_size; nnc_index++) { - const rd_nnc_pair_type *pair = rd_nnc_geometry_iget(nnc_geo, nnc_index); - int grid1 = pair->grid_nr1; - int grid2 = pair->grid_nr2; - - if (grid1 != current_grid1 || grid2 != current_grid2) { - current_grid1 = grid1; - current_grid2 = grid2; - assert_correct_kw_count(current_kw, __func__, correct_kw_count, - kw_count); - current_kw = - rd_nnc_data_get_kw(grid, init_file, grid1, grid2, kw_type); - kw_count = 0; - if (current_kw) { - correct_kw_count = rd_kw_get_size(current_kw); - } else { - return false; - } - } - if (current_kw) { - data->values[nnc_index] = - rd_kw_iget_as_double(current_kw, pair->input_index); - kw_count++; - } - } - assert_correct_kw_count(current_kw, __func__, correct_kw_count, kw_count); - return true; -} - -static rd_nnc_data_type * -rd_nnc_data_alloc__(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file, int kw_type) { - rd_nnc_data_type *data = (rd_nnc_data_type *)util_malloc(sizeof *data); - - int nnc_size = rd_nnc_geometry_size(nnc_geo); - data->size = nnc_size; - - data->values = (double *)util_malloc(nnc_size * sizeof(double)); - - if (rd_nnc_data_set_values(data, grid, nnc_geo, init_file, kw_type)) - return data; - else { - rd_nnc_data_free(data); - return NULL; - } -} - -rd_nnc_data_type *rd_nnc_data_alloc_tran(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file) { - return rd_nnc_data_alloc__(grid, nnc_geo, init_file, TRANS_DATA); -} - -rd_nnc_data_type * -rd_nnc_data_alloc_wat_flux(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file) { - return rd_nnc_data_alloc__(grid, nnc_geo, init_file, WTR_FLUX_DATA); -} - -rd_nnc_data_type * -rd_nnc_data_alloc_oil_flux(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file) { - return rd_nnc_data_alloc__(grid, nnc_geo, init_file, OIL_FLUX_DATA); -} - -rd_nnc_data_type * -rd_nnc_data_alloc_gas_flux(const rd_grid_type *grid, - const rd_nnc_geometry_type *nnc_geo, - const rd_file_view_type *init_file) { - return rd_nnc_data_alloc__(grid, nnc_geo, init_file, GAS_FLUX_DATA); -} - -void rd_nnc_data_free(rd_nnc_data_type *data) { - free(data->values); - free(data); -} - -int rd_nnc_data_get_size(rd_nnc_data_type *data) { return data->size; } - -const double *rd_nnc_data_get_values(const rd_nnc_data_type *data) { - return data->values; -} - -double rd_nnc_data_iget_value(const rd_nnc_data_type *data, int index) { - if (index >= data->size) - util_abort("%s: index value:%d out range: [0,%d) \n", __func__, index, - data->size); - - return data->values[index]; -} diff --git a/lib/resdata/rd_nnc_export.cpp b/lib/resdata/rd_nnc_export.cpp deleted file mode 100644 index fd976894f..000000000 --- a/lib/resdata/rd_nnc_export.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#include - -#include -#include - -#include -#include -#include -#include -#include - -/** - * Return true if the NNC information is stored in the Intersect format, false otherwise. - * In the Intersect format, the NNC information stored in the grid is unrealiable. - * The correct NNC data is stored in the init file instead - */ -bool rd_nnc_intersect_format(const rd_grid_type *grid, - const rd_file_type *init_file) { - if (!rd_file_has_kw(init_file, NNC1_KW) || - !rd_file_has_kw(init_file, NNC2_KW) || - !rd_file_has_kw(init_file, TRANNNC_KW)) - return false; - // In the specific case we are treating, there should be just 1 occurrence of the kw - const auto nnc1_num = - rd_kw_get_size(rd_file_iget_named_kw(init_file, NNC1_KW, 0)); - const auto nnc2_num = - rd_kw_get_size(rd_file_iget_named_kw(init_file, NNC2_KW, 0)); - const auto tran_num = - rd_kw_get_size(rd_file_iget_named_kw(init_file, TRANNNC_KW, 0)); - return nnc1_num == tran_num && nnc2_num == tran_num; -} - -int rd_nnc_export_get_size(const rd_grid_type *grid, - const rd_file_type *init_file) { - return rd_nnc_intersect_format(grid, init_file) - ? rd_kw_get_size(rd_file_iget_named_kw(init_file, TRANNNC_KW, 0)) - : // Intersect format - rd_grid_get_num_nnc(grid); // Eclipse format -} - -static int rd_nnc_export_intersect__(const rd_file_type *init_file, - rd_nnc_type *nnc_data, int *nnc_offset) { - const auto nnc1_kw = rd_file_iget_named_kw(init_file, NNC1_KW, 0); - const auto nnc2_kw = rd_file_iget_named_kw(init_file, NNC2_KW, 0); - const auto tran_kw = rd_file_iget_named_kw(init_file, TRANNNC_KW, 0); - - auto nnc_index = *nnc_offset; - for (int i = 0; i < rd_kw_get_size(tran_kw); ++i) { - auto const nnc1 = rd_kw_iget_int(nnc1_kw, i); - auto const nnc2 = rd_kw_iget_int(nnc2_kw, i); - auto const tran = rd_kw_iget_as_double(tran_kw, i); - nnc_data[nnc_index] = rd_nnc_type{0, nnc1, 0, nnc2, i, tran}; - ++nnc_index; - } - *nnc_offset = nnc_index; - return rd_kw_get_size(tran_kw); // Assume all valid -} - -static int rd_nnc_export__(const rd_grid_type *grid, int lgr_index1, - const rd_file_type *init_file, rd_nnc_type *nnc_data, - int *nnc_offset) { - int nnc_index = *nnc_offset; - int lgr_nr1 = rd_grid_get_lgr_nr(grid); - int global_index1; - int valid_trans = 0; - const rd_grid_type *global_grid = rd_grid_get_global_grid(grid); - - if (!global_grid) - global_grid = grid; - - for (global_index1 = 0; global_index1 < rd_grid_get_global_size(grid); - global_index1++) { - const nnc_info_type *nnc_info = - rd_grid_get_cell_nnc_info1(grid, global_index1); - if (nnc_info) { - int lgr_index2; - for (lgr_index2 = 0; lgr_index2 < nnc_info_get_size(nnc_info); - lgr_index2++) { - const nnc_vector_type *nnc_vector = - nnc_info_iget_vector(nnc_info, lgr_index2); - const std::vector &grid2_index_list = - nnc_vector_get_grid_index_list(nnc_vector); - const std::vector &nnc_index_list = - nnc_vector_get_nnc_index_list(nnc_vector); - int lgr_nr2 = nnc_vector_get_lgr_nr(nnc_vector); - const rd_kw_type *tran_kw = rd_nnc_export_get_tranx_kw( - global_grid, init_file, lgr_nr1, lgr_nr2); - - int index2; - rd_nnc_type nnc; - - nnc.grid_nr1 = lgr_nr1; - nnc.grid_nr2 = lgr_nr2; - nnc.global_index1 = global_index1; - - for (index2 = 0; index2 < nnc_vector_get_size(nnc_vector); - index2++) { - nnc.global_index2 = grid2_index_list[index2]; - nnc.input_index = nnc_index_list[index2]; - if (tran_kw) { - nnc.trans = - rd_kw_iget_as_double(tran_kw, nnc.input_index); - valid_trans++; - } else { - nnc.trans = ERT_RD_DEFAULT_NNC_TRANS; - } - - nnc_data[nnc_index] = nnc; - nnc_index++; - } - } - } - } - *nnc_offset = nnc_index; - return valid_trans; -} - -int rd_nnc_export(const rd_grid_type *grid, const rd_file_type *init_file, - rd_nnc_type *nnc_data) { - int nnc_index = 0; - int total_valid_trans = 0; - if (rd_nnc_intersect_format(grid, init_file)) { - // Intersect format - total_valid_trans = - rd_nnc_export_intersect__(init_file, nnc_data, &nnc_index); - } else { - // Eclipse format - total_valid_trans = - rd_nnc_export__(grid, 0, init_file, nnc_data, &nnc_index); - { - for (int lgr_index = 0; lgr_index < rd_grid_get_num_lgr(grid); - lgr_index++) { - rd_grid_type *igrid = rd_grid_iget_lgr(grid, lgr_index); - total_valid_trans += rd_nnc_export__( - igrid, lgr_index, init_file, nnc_data, &nnc_index); - } - } - nnc_index = rd_grid_get_num_nnc(grid); - } - rd_nnc_sort(nnc_data, nnc_index); - return total_valid_trans; -} - -int rd_nnc_sort_cmp(const rd_nnc_type *nnc1, const rd_nnc_type *nnc2) { - - if (nnc1->grid_nr1 != nnc2->grid_nr1) { - if (nnc1->grid_nr1 < nnc2->grid_nr1) - return -1; - else - return 1; - } - - if (nnc1->grid_nr2 != nnc2->grid_nr2) { - if (nnc1->grid_nr2 < nnc2->grid_nr2) - return -1; - else - return 1; - } - - if (nnc1->global_index1 != nnc2->global_index1) { - if (nnc1->global_index1 < nnc2->global_index1) - return -1; - else - return 1; - } - - if (nnc1->global_index2 != nnc2->global_index2) { - if (nnc1->global_index2 < nnc2->global_index2) - return -1; - else - return 1; - } - - return 0; -} - -bool rd_nnc_equal(const rd_nnc_type *nnc1, const rd_nnc_type *nnc2) { - - if (rd_nnc_sort_cmp(nnc1, nnc2) == 0) - return ((nnc1->trans == nnc2->trans) && - (nnc1->input_index == nnc2->input_index)); - else - return false; -} - -static int rd_nnc_sort_cmp__(const void *nnc1, const void *nnc2) { - return rd_nnc_sort_cmp((const rd_nnc_type *)nnc1, - (const rd_nnc_type *)nnc2); -} - -void rd_nnc_sort(rd_nnc_type *nnc_list, int size) { - qsort(nnc_list, size, sizeof *nnc_list, rd_nnc_sort_cmp__); -} - -rd_kw_type *rd_nnc_export_get_tranll_kw(const rd_grid_type *grid, - const rd_file_type *init_file, - int lgr_nr1, int lgr_nr2) { - const char *lgr_name1 = rd_grid_get_lgr_name(grid, lgr_nr1); - const char *lgr_name2 = rd_grid_get_lgr_name(grid, lgr_nr2); - - rd_kw_type *tran_kw = NULL; - const int file_num_kw = rd_file_get_size(init_file); - int global_kw_index = 0; - - while (true) { - if (global_kw_index >= file_num_kw) - break; - { - rd_kw_type *rd_kw = rd_file_iget_kw(init_file, global_kw_index); - if (strcmp(LGRJOIN_KW, rd_kw_get_header(rd_kw)) == 0) { - - if (rd_kw_icmp_string(rd_kw, 0, lgr_name1) && - rd_kw_icmp_string(rd_kw, 1, lgr_name2)) { - tran_kw = rd_file_iget_kw(init_file, global_kw_index + 1); - break; - } - } - global_kw_index++; - } - } - - return tran_kw; -} - -rd_kw_type *rd_nnc_export_get_tran_kw(const rd_file_type *init_file, - const char *kw, int lgr_nr) { - rd_kw_type *tran_kw = NULL; - if (lgr_nr == 0) { - if (strcmp(kw, TRANNNC_KW) == 0) - if (rd_file_has_kw(init_file, kw)) { - tran_kw = rd_file_iget_named_kw(init_file, TRANNNC_KW, 0); - } - } else { - if ((strcmp(kw, TRANNNC_KW) == 0) || (strcmp(kw, TRANGL_KW) == 0)) { - const int file_num_kw = rd_file_get_size(init_file); - int global_kw_index = 0; - bool finished = false; - bool correct_lgrheadi = false; - int head_index = 0; - int steps = 0; - - while (!finished) { - rd_kw_type *rd_kw = rd_file_iget_kw(init_file, global_kw_index); - const char *current_kw = rd_kw_get_header(rd_kw); - if (strcmp(LGRHEADI_KW, current_kw) == 0) { - if (rd_kw_iget_int(rd_kw, LGRHEADI_LGR_NR_INDEX) == - lgr_nr) { - correct_lgrheadi = true; - head_index = global_kw_index; - } else { - correct_lgrheadi = false; - } - } - if (correct_lgrheadi) { - if (strcmp(kw, current_kw) == 0) { - steps = - global_kw_index - - head_index; /* This is to calculate who fare from lgrheadi we found the TRANGL/TRANNNC key word */ - if (steps == 3 || steps == 4 || - steps == - 6) { /* We only support a file format where TRANNNC is 3 steps and TRANGL is 4 or 6 steps from LGRHEADI */ - tran_kw = rd_kw; - finished = true; - break; - } - } - } - global_kw_index++; - if (global_kw_index == file_num_kw) - finished = true; - } - } - } - return tran_kw; -} - -rd_kw_type *rd_nnc_export_get_tranx_kw(const rd_grid_type *grid, - const rd_file_type *init_file, - int lgr_nr1, int lgr_nr2) { - if (lgr_nr1 == lgr_nr2) - return rd_nnc_export_get_tran_kw(init_file, TRANNNC_KW, lgr_nr2); - else { - if (lgr_nr1 == 0) - return rd_nnc_export_get_tran_kw(init_file, TRANGL_KW, lgr_nr2); - else - return rd_nnc_export_get_tranll_kw(grid, init_file, lgr_nr1, - lgr_nr2); - } -} diff --git a/lib/resdata/rd_nnc_geometry.cpp b/lib/resdata/rd_nnc_geometry.cpp deleted file mode 100644 index 0a0ff2ad2..000000000 --- a/lib/resdata/rd_nnc_geometry.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include -#include - -#include - -#define RD_NNC_GEOMETRY_TYPE_ID 6124343 - -struct rd_nnc_geometry_struct { - UTIL_TYPE_ID_DECLARATION; - std::vector *data; -}; - -UTIL_IS_INSTANCE_FUNCTION(rd_nnc_geometry, RD_NNC_GEOMETRY_TYPE_ID) - -int rd_nnc_geometry_size(const rd_nnc_geometry_type *nnc_geo) { - return nnc_geo->data->size(); -} - -/* - Will go through the grid and add links for all NNC connections in - the grid. The endpoints of an NNC are defined by the tuple: - - (grid_nr, global_index), - - and a NNC link is defined by a pair of such connections, linking - cells (grid_nr1, global_index1) and (grid_nr2, global_index2). -*/ - -static void rd_nnc_geometry_add_pairs(const rd_nnc_geometry_type *nnc_geo, - const rd_grid_type *grid) { - int lgr_nr1 = rd_grid_get_lgr_nr(grid); - const rd_grid_type *global_grid = rd_grid_get_global_grid(grid); - - if (!global_grid) - global_grid = grid; - - for (int global_index1 = 0; global_index1 < rd_grid_get_global_size(grid); - global_index1++) { - const nnc_info_type *nnc_info = - rd_grid_get_cell_nnc_info1(grid, global_index1); - if (!nnc_info) - continue; - - for (int lgr_index2 = 0; lgr_index2 < nnc_info_get_size(nnc_info); - lgr_index2++) { - const nnc_vector_type *nnc_vector = - nnc_info_iget_vector(nnc_info, lgr_index2); - const std::vector &grid2_index_list = - nnc_vector_get_grid_index_list(nnc_vector); - const std::vector &nnc_index_list = - nnc_vector_get_nnc_index_list(nnc_vector); - int lgr_nr2 = nnc_vector_get_lgr_nr(nnc_vector); - - for (int index2 = 0; index2 < nnc_vector_get_size(nnc_vector); - index2++) { - rd_nnc_pair_type pair; - pair.grid_nr1 = lgr_nr1; - pair.global_index1 = global_index1; - pair.grid_nr2 = lgr_nr2; - pair.global_index2 = grid2_index_list[index2]; - pair.input_index = nnc_index_list[index2]; - nnc_geo->data->push_back(pair); - } - } - } -} - -static bool rd_nnc_cmp(const rd_nnc_pair_type &nnc1, - const rd_nnc_pair_type &nnc2) { - if (nnc1.grid_nr1 != nnc2.grid_nr1) - return nnc1.grid_nr1 < nnc2.grid_nr1; - - if (nnc1.grid_nr2 != nnc2.grid_nr2) - return nnc1.grid_nr2 < nnc2.grid_nr2; - - if (nnc1.global_index1 != nnc2.global_index1) - return nnc1.global_index1 < nnc2.global_index1; - - if (nnc1.global_index2 != nnc2.global_index2) - return nnc1.global_index2 < nnc2.global_index2; - - return false; -} - -rd_nnc_geometry_type *rd_nnc_geometry_alloc(const rd_grid_type *grid) { - rd_nnc_geometry_type *nnc_geo = - (rd_nnc_geometry_type *)util_malloc(sizeof *nnc_geo); - UTIL_TYPE_ID_INIT(nnc_geo, RD_NNC_GEOMETRY_TYPE_ID); - nnc_geo->data = new std::vector(); - - rd_nnc_geometry_add_pairs(nnc_geo, grid); - for (int lgr_index = 0; lgr_index < rd_grid_get_num_lgr(grid); - lgr_index++) { - rd_grid_type *igrid = rd_grid_iget_lgr(grid, lgr_index); - rd_nnc_geometry_add_pairs(nnc_geo, igrid); - } - std::sort(nnc_geo->data->begin(), nnc_geo->data->end(), rd_nnc_cmp); - return nnc_geo; -} - -void rd_nnc_geometry_free(rd_nnc_geometry_type *nnc_geo) { - delete nnc_geo->data; - free(nnc_geo); -} - -const rd_nnc_pair_type * -rd_nnc_geometry_iget(const rd_nnc_geometry_type *nnc_geo, int index) { - const std::vector &nnc_data = *nnc_geo->data; - return &nnc_data[index]; -} - -bool rd_nnc_geometry_same_kw(const rd_nnc_pair_type *nnc1, - const rd_nnc_pair_type *nnc2) { - if ((nnc1->grid_nr1 == nnc2->grid_nr1) && - (nnc1->grid_nr2 == nnc2->grid_nr2)) - return true; - else - return false; -} diff --git a/lib/resdata/tests/rd_nnc_data_equinor_root.cpp b/lib/resdata/tests/rd_nnc_data_equinor_root.cpp deleted file mode 100644 index 25c504b01..000000000 --- a/lib/resdata/tests/rd_nnc_data_equinor_root.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -int find_index(rd_nnc_geometry_type *nnc_geo, int grid1, int grid2, int indx1, - int indx2) { - int index = -1; - int nnc_size = rd_nnc_geometry_size(nnc_geo); - for (int n = 0; n < nnc_size; n++) { - const rd_nnc_pair_type *pair = rd_nnc_geometry_iget(nnc_geo, n); - if (pair->grid_nr1 == grid1 && pair->grid_nr2 == grid2) - if (pair->global_index1 == indx1 && pair->global_index2 == indx2) { - index = n; - break; - } - } - return index; -} - -void test_alloc_file_tran(char *filename) { - char *grid_file_name = - rd_alloc_filename(NULL, filename, RD_EGRID_FILE, false, -1); - char *init_file_name = - rd_alloc_filename(NULL, filename, RD_INIT_FILE, false, -1); - rd_file_type *init_file = rd_file_open(init_file_name, 0); - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_nnc_geometry_type *nnc_geo = rd_nnc_geometry_alloc(grid); - rd_file_view_type *view_file = rd_file_get_global_view(init_file); - - rd_nnc_data_type *nnc_geo_data = - rd_nnc_data_alloc_tran(grid, nnc_geo, view_file); - test_assert_true(rd_nnc_geometry_size(nnc_geo) == - rd_nnc_data_get_size(nnc_geo_data)); - - //These numerical values are hand-tuned the specific input file at: - //${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3 - int index; - - index = find_index(nnc_geo, 0, 0, 541, 14507); - test_assert_double_equal(13.784438, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 0, 0, 48365, 118191); - test_assert_double_equal(0.580284, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 0, 19, 42830, 211); - test_assert_double_equal(0.571021, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 0, 79, 132406, 76); - test_assert_double_equal(37.547710, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 18, 12, 303, 115); - test_assert_double_equal(0.677443, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 72, 71, 255, 179); - test_assert_double_equal(0.045813, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 110, 109, 271, 275); - test_assert_double_equal(16.372242, - rd_nnc_data_iget_value(nnc_geo_data, index)); - - rd_nnc_data_free(nnc_geo_data); - rd_nnc_geometry_free(nnc_geo); - rd_grid_free(grid); - rd_file_close(init_file); - free(grid_file_name); - free(init_file_name); -} - -void test_alloc_file_flux(char *filename, int file_num) { - char *grid_file_name = - rd_alloc_filename(NULL, filename, RD_EGRID_FILE, false, -1); - char *restart_file_name = - rd_alloc_filename(NULL, filename, RD_RESTART_FILE, false, file_num); - - rd_file_type *restart_file = rd_file_open(restart_file_name, 0); - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_nnc_geometry_type *nnc_geo = rd_nnc_geometry_alloc(grid); - { - rd_file_view_type *view_file = rd_file_get_global_view(restart_file); - - rd_nnc_data_type *nnc_flux_data = - rd_nnc_data_alloc_wat_flux(grid, nnc_geo, view_file); - test_assert_not_NULL(nnc_flux_data); - rd_nnc_data_free(nnc_flux_data); - } - rd_nnc_geometry_free(nnc_geo); - rd_grid_free(grid); - rd_file_close(restart_file); - free(grid_file_name); - free(restart_file_name); -} - -int main(int argc, char **argv) { - test_alloc_file_tran(argv[1]); - test_alloc_file_flux(argv[2], 0); - test_alloc_file_flux(argv[2], 6); - return 0; -} diff --git a/lib/resdata/tests/rd_nnc_export.cpp b/lib/resdata/tests/rd_nnc_export.cpp deleted file mode 100644 index e821910b6..000000000 --- a/lib/resdata/tests/rd_nnc_export.cpp +++ /dev/null @@ -1,359 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -int count_kw_data(const rd_file_type *file, rd_grid_type *grid, const char *kw1, - const char *kw2) { - int i, j; - int count = 0; - - for (i = 0; i < rd_file_get_num_named_kw(file, kw1); i++) { - rd_kw_type *rd_kw1 = rd_file_iget_named_kw(file, kw1, i); - rd_kw_type *rd_kw2 = NULL; - - if (kw2) - rd_kw2 = rd_file_iget_named_kw(file, kw2, i); - - { - if (rd_kw2) { - int global_size; - rd_grid_type *igrid; - if (i == 0) - igrid = grid; - else - igrid = rd_grid_iget_lgr(grid, i - 1); - - global_size = rd_grid_get_global_size(igrid); - - for (j = 0; j < rd_kw_get_size(rd_kw1); j++) { - int g1 = rd_kw_iget_int(rd_kw1, j); - int g2 = rd_kw_iget_int(rd_kw2, j); - - if (g1 <= global_size && g2 <= global_size) - count += 1; - } - } else - count += rd_kw_get_size(rd_kw1); - } - } - return count; -} - -void test_count(const char *name) { - char *grid_file_name = - rd_alloc_filename(NULL, name, RD_EGRID_FILE, false, -1); - char *init_file_name = - rd_alloc_filename(NULL, name, RD_INIT_FILE, false, -1); - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_file_type *grid_file = rd_file_open(grid_file_name, 0); - rd_file_type *init_file = rd_file_open(init_file_name, 0); - - int num_nnc = 0; - - num_nnc = count_kw_data(grid_file, grid, "NNC1", "NNC2"); - num_nnc += count_kw_data(grid_file, grid, "NNCG", NULL); - num_nnc += count_kw_data(grid_file, grid, "NNA1", NULL); - - test_assert_int_equal(num_nnc, rd_nnc_export_get_size(grid, init_file)); - - free(grid_file_name); - rd_grid_free(grid); - rd_file_close(grid_file); -} - -void test_nnc_export_missing_TRANX(const char *name) { - char *grid_file_name = - rd_alloc_filename(NULL, name, RD_EGRID_FILE, false, -1); - char *init_file_name = - rd_alloc_filename(NULL, name, RD_INIT_FILE, false, -1); - if (util_entry_exists(init_file_name)) { - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_file_type *init_file = rd_file_open(init_file_name, 0); - rd_nnc_type *nnc_data1 = (rd_nnc_type *)util_calloc( - rd_nnc_export_get_size(grid, init_file), sizeof *nnc_data1); - int count = rd_nnc_export(grid, init_file, nnc_data1); - int i; - test_assert_int_equal(count, 0); - for (i = 0; i < count; i++) - test_assert_double_equal(nnc_data1[i].trans, - ERT_RD_DEFAULT_NNC_TRANS); - } -} - -void test_export(const char *name, bool have_tran_data) { - char *grid_file_name = - rd_alloc_filename(NULL, name, RD_EGRID_FILE, false, -1); - char *init_file_name = - rd_alloc_filename(NULL, name, RD_INIT_FILE, false, -1); - if (util_entry_exists(init_file_name)) { - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_file_type *grid_file = rd_file_open(grid_file_name, 0); - rd_file_type *init_file = rd_file_open(init_file_name, 0); - rd_nnc_type *nnc_data1 = (rd_nnc_type *)util_calloc( - rd_nnc_export_get_size(grid, init_file), sizeof *nnc_data1); - rd_nnc_type *nnc_data2 = (rd_nnc_type *)util_calloc( - rd_nnc_export_get_size(grid, init_file), sizeof *nnc_data2); - - { - int nnc_offset = 0; - int block_nr = 0; - for (block_nr = 0; - block_nr < rd_file_get_num_named_kw(grid_file, NNCHEAD_KW); - block_nr++) { - rd_file_view_type *nnc_view = rd_file_alloc_global_blockview( - grid_file, NNCHEAD_KW, block_nr); - - if (rd_file_view_has_kw(nnc_view, NNC1_KW)) { - rd_kw_type *nnc1_kw = - rd_file_view_iget_named_kw(nnc_view, NNC1_KW, 0); - rd_kw_type *nnc2_kw = - rd_file_view_iget_named_kw(nnc_view, NNC2_KW, 0); - rd_kw_type *nnchead = - rd_file_view_iget_named_kw(nnc_view, NNCHEAD_KW, 0); - int lgr_nr1 = rd_kw_iget_int(nnchead, NNCHEAD_LGR_INDEX); - int lgr_nr2 = rd_kw_iget_int(nnchead, NNCHEAD_LGR_INDEX); - rd_kw_type *nnc_tran = rd_nnc_export_get_tranx_kw( - grid, init_file, lgr_nr1, lgr_nr2); - if (!have_tran_data) { - test_assert_NULL(nnc_tran); - return; - } - - test_assert_not_NULL(nnc_tran); - test_assert_int_equal(rd_kw_get_size(nnc1_kw), - rd_kw_get_size(nnc_tran)); - { - rd_grid_type *lgr = grid; - int num_nnc = 0; - int i = 0; - if (lgr_nr1 > 0) - lgr = rd_grid_get_lgr_from_lgr_nr(grid, lgr_nr1); - - while (i < rd_kw_get_size(nnc1_kw)) { - int g1 = rd_kw_iget_int(nnc1_kw, i) - 1; - int g2 = rd_kw_iget_int(nnc2_kw, i) - 1; - - if (g1 < rd_grid_get_global_size(lgr) && - g2 < rd_grid_get_global_size(lgr)) { - nnc_data1[i + nnc_offset].grid_nr1 = lgr_nr1; - nnc_data1[i + nnc_offset].grid_nr2 = lgr_nr2; - nnc_data1[i + nnc_offset].global_index1 = g1; - nnc_data1[i + nnc_offset].global_index2 = g2; - nnc_data1[i + nnc_offset].trans = - rd_kw_iget_as_double(nnc_tran, i); - nnc_data1[i + nnc_offset].input_index = i; - num_nnc++; - } - i++; - } - nnc_offset += num_nnc; - } - } - - if (rd_file_view_has_kw(nnc_view, NNCL_KW)) { - rd_kw_type *nncl_kw = - rd_file_view_iget_named_kw(nnc_view, NNCL_KW, 0); - rd_kw_type *nncg_kw = - rd_file_view_iget_named_kw(nnc_view, NNCG_KW, 0); - rd_kw_type *nnchead = - rd_file_view_iget_named_kw(nnc_view, NNCHEAD_KW, 0); - int lgr_nr1 = 0; - int lgr_nr2 = rd_kw_iget_int(nnchead, NNCHEAD_LGR_INDEX); - rd_kw_type *nnc_tran = - rd_nnc_export_get_tranx_kw(grid, init_file, 0, lgr_nr2); - int i; - - test_assert_int_equal(rd_kw_get_size(nncl_kw), - rd_kw_get_size(nnc_tran)); - for (i = 0; i < rd_kw_get_size(nncl_kw); i++) { - nnc_data1[i + nnc_offset].grid_nr1 = lgr_nr1; - nnc_data1[i + nnc_offset].grid_nr2 = lgr_nr2; - nnc_data1[i + nnc_offset].global_index1 = - rd_kw_iget_int(nncg_kw, i) - 1; - nnc_data1[i + nnc_offset].global_index2 = - rd_kw_iget_int(nncl_kw, i) - 1; - nnc_data1[i + nnc_offset].trans = - rd_kw_iget_as_double(nnc_tran, i); - nnc_data1[i + nnc_offset].input_index = i; - } - nnc_offset += rd_kw_get_size(nncl_kw); - } - - rd_file_view_free(nnc_view); - } - - { - for (block_nr = 0; block_nr < rd_file_get_num_named_kw( - grid_file, NNCHEADA_KW); - block_nr++) { - rd_kw_type *nnc1_kw = - rd_file_iget_named_kw(grid_file, NNA1_KW, block_nr); - rd_kw_type *nnc2_kw = - rd_file_iget_named_kw(grid_file, NNA2_KW, block_nr); - rd_kw_type *nnchead = - rd_file_iget_named_kw(grid_file, NNCHEADA_KW, block_nr); - int lgr_nr1 = rd_kw_iget_int(nnchead, NNCHEADA_ILOC1_INDEX); - int lgr_nr2 = rd_kw_iget_int(nnchead, NNCHEADA_ILOC2_INDEX); - rd_kw_type *nnc_tran; - int i; - - nnc_tran = rd_nnc_export_get_tranx_kw(grid, init_file, - lgr_nr1, lgr_nr2); - test_assert_not_NULL(nnc_tran); - test_assert_int_equal(rd_kw_get_size(nnc1_kw), - rd_kw_get_size(nnc_tran)); - for (i = 0; i < rd_kw_get_size(nnc1_kw); i++) { - nnc_data1[i + nnc_offset].grid_nr1 = lgr_nr1; - nnc_data1[i + nnc_offset].grid_nr2 = lgr_nr2; - nnc_data1[i + nnc_offset].global_index1 = - rd_kw_iget_int(nnc1_kw, i) - 1; - nnc_data1[i + nnc_offset].global_index2 = - rd_kw_iget_int(nnc2_kw, i) - 1; - nnc_data1[i + nnc_offset].trans = - rd_kw_iget_as_double(nnc_tran, i); - nnc_data1[i + nnc_offset].input_index = i; - } - nnc_offset += rd_kw_get_size(nnc1_kw); - } - } - - test_assert_int_equal(nnc_offset, - rd_nnc_export_get_size(grid, init_file)); - rd_nnc_sort(nnc_data1, nnc_offset); - } - - { - int export_size = rd_nnc_export(grid, init_file, nnc_data2); - test_assert_int_equal(export_size, - rd_nnc_export_get_size(grid, init_file)); - } - - { - int i; - int size = rd_nnc_export_get_size(grid, init_file); - for (i = 0; i < size; i++) - test_assert_int_equal( - 0, rd_nnc_sort_cmp(&nnc_data1[i], &nnc_data2[i])); - } - - for (int i = 0; i < rd_nnc_export_get_size(grid, init_file); i++) - test_assert_true(rd_nnc_equal(&nnc_data1[i], &nnc_data2[i])); - - { - rd_nnc_geometry_type *nnc_geo = rd_nnc_geometry_alloc(grid); - rd_file_view_type *view_file = rd_file_get_global_view(init_file); - rd_nnc_data_type *nnc_geo_data = - rd_nnc_data_alloc_tran(grid, nnc_geo, view_file); - - test_assert_int_equal(rd_nnc_export_get_size(grid, init_file), - rd_nnc_geometry_size(nnc_geo)); - for (int i = 0; i < rd_nnc_geometry_size(nnc_geo); i++) { - const rd_nnc_pair_type *nnc_pair = - rd_nnc_geometry_iget(nnc_geo, i); - rd_nnc_type *nnc1 = &nnc_data1[i]; - - test_assert_int_equal(nnc_pair->grid_nr1, nnc1->grid_nr1); - test_assert_int_equal(nnc_pair->grid_nr2, nnc1->grid_nr2); - test_assert_int_equal(nnc_pair->global_index1, - nnc1->global_index1); - test_assert_int_equal(nnc_pair->global_index2, - nnc1->global_index2); - test_assert_double_equal( - rd_nnc_data_iget_value(nnc_geo_data, i), nnc1->trans); - } - rd_nnc_data_free(nnc_geo_data); - rd_nnc_geometry_free(nnc_geo); - } - - free(nnc_data2); - free(nnc_data1); - rd_grid_free(grid); - rd_file_close(grid_file); - rd_file_close(init_file); - } else - fprintf(stderr, " Could not find init file:%s - export test skipped \n", - init_file_name); - - free(grid_file_name); - free(init_file_name); -} - -void test_cmp() { - - rd_nnc_type nnc1 = {1, 1, 1, 1}; - rd_nnc_type nnc2 = {1, 1, 1, 1}; - rd_nnc_type nnc3 = {4, 1, 1, 1}; - rd_nnc_type nnc4 = {4, 2, 1, 1}; - rd_nnc_type nnc5 = {4, 2, 3, 1}; - rd_nnc_type nnc6 = {4, 2, 3, 5}; - - test_assert_int_equal(0, rd_nnc_sort_cmp(&nnc1, &nnc2)); - test_assert_int_equal(1, rd_nnc_sort_cmp(&nnc3, &nnc1)); - test_assert_int_equal(1, rd_nnc_sort_cmp(&nnc4, &nnc1)); - test_assert_int_equal(1, rd_nnc_sort_cmp(&nnc5, &nnc4)); - test_assert_int_equal(-1, rd_nnc_sort_cmp(&nnc4, &nnc5)); - test_assert_int_equal(-1, rd_nnc_sort_cmp(&nnc5, &nnc6)); -} - -void test_sort() { - const int N = 1000; - rd_nnc_type *nnc_list = (rd_nnc_type *)util_calloc(N, sizeof *nnc_list); - int i; - for (i = 0; i < N; i++) { - rd_nnc_type nnc; - - nnc.grid_nr1 = (i % 19); - nnc.grid_nr2 = (i % 3); - nnc.global_index1 = (i % 7); - nnc.global_index2 = (i % 13); - - nnc_list[i] = nnc; - } - rd_nnc_sort(nnc_list, N); - for (i = 0; i < (N - 1); i++) - test_assert_int_equal(-1, - rd_nnc_sort_cmp(&nnc_list[i], &nnc_list[i + 1])); - - free(nnc_list); -} - -void install_SIGNALS(void) { - signal( - SIGSEGV, - util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */ - signal(SIGINT, util_abort_signal); /* Control C */ - signal( - SIGTERM, - util_abort_signal); /* If killing the program with SIGTERM (the default kill signal) you will get a backtrace. - Killing with SIGKILL (-9) will not give a backtrace.*/ -} - -int main(int argc, char **argv) { - - const char *base = argv[1]; - bool have_tran_data; - install_SIGNALS(); - - if (util_sscanf_bool(argv[2], &have_tran_data)) { - test_cmp(); - test_sort(); - test_count(base); - test_export(base, have_tran_data); - if (!have_tran_data) - test_nnc_export_missing_TRANX(base); - - exit(0); - } else - test_error_exit("Failed to parse input:%s as bool", argv[2]); -} diff --git a/lib/resdata/tests/rd_nnc_export_get_tran.cpp b/lib/resdata/tests/rd_nnc_export_get_tran.cpp deleted file mode 100644 index 315db70ef..000000000 --- a/lib/resdata/tests/rd_nnc_export_get_tran.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include - -void test_get_tran(const char *name) { - char *grid_file_name = - rd_alloc_filename(NULL, name, RD_EGRID_FILE, false, -1); - char *init_file_name = - rd_alloc_filename(NULL, name, RD_INIT_FILE, false, -1); - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_file_type *grid_file = rd_file_open(grid_file_name, 0); - rd_file_type *init_file = rd_file_open(init_file_name, 0); - - /* Get global */ - { - rd_kw_type *tran_kw = - rd_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 0); - test_assert_true(rd_kw_is_instance(tran_kw)); - test_assert_double_equal(0.85582769, rd_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(0.24635284, - rd_kw_iget_as_double(tran_kw, 7184)); - } - test_assert_NULL(rd_nnc_export_get_tran_kw(init_file, TRANGL_KW, 0)); - test_assert_NULL(rd_nnc_export_get_tran_kw(init_file, TRANLL_KW, 0)); - test_assert_NULL(rd_nnc_export_get_tran_kw(init_file, "INVALID", 1)); - - /* Get lgr_nr: 48 */ - { - rd_kw_type *tran_kw = - rd_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 48); - test_assert_true(rd_kw_is_instance(tran_kw)); - test_assert_int_equal(0, rd_kw_get_size(tran_kw)); - - tran_kw = rd_nnc_export_get_tran_kw(init_file, TRANGL_KW, 48); - test_assert_int_equal(282, rd_kw_get_size(tran_kw)); - test_assert_double_equal(22.922695, rd_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(16.720325, rd_kw_iget_as_double(tran_kw, 281)); - } - - /* Get lgr_nr: 99 */ - { - rd_kw_type *tran_kw = - rd_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 99); - test_assert_true(rd_kw_is_instance(tran_kw)); - test_assert_int_equal(0, rd_kw_get_size(tran_kw)); - - tran_kw = rd_nnc_export_get_tran_kw(init_file, TRANGL_KW, 99); - test_assert_int_equal(693, rd_kw_get_size(tran_kw)); - test_assert_double_equal(0.25534782, rd_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(0.12677453, - rd_kw_iget_as_double(tran_kw, 692)); - } - - /* Get lgr_nr: 10 */ - { - rd_kw_type *tran_kw = - rd_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 10); - test_assert_true(rd_kw_is_instance(tran_kw)); - test_assert_int_equal(0, rd_kw_get_size(tran_kw)); - - tran_kw = rd_nnc_export_get_tran_kw(init_file, TRANGL_KW, 10); - test_assert_int_equal(260, rd_kw_get_size(tran_kw)); - test_assert_double_equal(0.87355447, rd_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(26.921568, rd_kw_iget_as_double(tran_kw, 259)); - } - - /* Get lgr_nr: 110 */ - { - rd_kw_type *tran_kw = - rd_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 110); - test_assert_true(rd_kw_is_instance(tran_kw)); - test_assert_int_equal(0, rd_kw_get_size(tran_kw)); - - tran_kw = rd_nnc_export_get_tran_kw(init_file, TRANGL_KW, 110); - test_assert_int_equal(208, rd_kw_get_size(tran_kw)); - test_assert_double_equal(17.287283, rd_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(569.26312, rd_kw_iget_as_double(tran_kw, 207)); - } - - free(init_file_name); - free(grid_file_name); - rd_grid_free(grid); - rd_file_close(grid_file); - rd_file_close(init_file); -} - -void test_tranLL(const rd_grid_type *grid, const rd_file_type *init_file, - int lgr_nr1, int lgr_nr2, int size, double first, - double last) { - - rd_kw_type *rd_kw = - rd_nnc_export_get_tranll_kw(grid, init_file, lgr_nr1, lgr_nr2); - - printf("lgr: %d -> %d \n", lgr_nr1, lgr_nr2); - test_assert_not_NULL(rd_kw); - test_assert_true(rd_kw_is_instance(rd_kw)); - test_assert_int_equal(size, rd_kw_get_size(rd_kw)); - test_assert_double_equal(first, rd_kw_iget_as_double(rd_kw, 0)); - test_assert_double_equal(last, rd_kw_iget_as_double(rd_kw, size - 1)); -} - -void test_get_tranLL(const char *name) { - char *grid_file_name = - rd_alloc_filename(NULL, name, RD_EGRID_FILE, false, -1); - char *init_file_name = - rd_alloc_filename(NULL, name, RD_INIT_FILE, false, -1); - rd_grid_type *grid = rd_grid_alloc(grid_file_name); - rd_file_type *grid_file = rd_file_open(grid_file_name, 0); - rd_file_type *init_file = rd_file_open(init_file_name, 0); - - test_tranLL(grid, init_file, rd_grid_get_lgr_nr_from_name(grid, "LG003017"), - rd_grid_get_lgr_nr_from_name(grid, "LG003018"), 172, 5.3957253, - 1.0099934); - - test_tranLL(grid, init_file, rd_grid_get_lgr_nr_from_name(grid, "LG002016"), - rd_grid_get_lgr_nr_from_name(grid, "LG002017"), 93, 1.4638059, - 0.36407200); - - test_tranLL(grid, init_file, rd_grid_get_lgr_nr_from_name(grid, "LG002016"), - rd_grid_get_lgr_nr_from_name(grid, "LG003016"), 56, 2.7360380, - 10.053267); - - test_tranLL(grid, init_file, rd_grid_get_lgr_nr_from_name(grid, "LG009027"), - rd_grid_get_lgr_nr_from_name(grid, "LG009026"), 152, 155.47754, - 219.23553); - - test_tranLL(grid, init_file, rd_grid_get_lgr_nr_from_name(grid, "LG009027"), - rd_grid_get_lgr_nr_from_name(grid, "LG008027"), 317, - 0.040260997, 0.0066288318); - - free(init_file_name); - free(grid_file_name); - rd_grid_free(grid); - rd_file_close(grid_file); - rd_file_close(init_file); -} - -int main(int argc, char **argv) { - test_get_tran(argv[1]); - test_get_tranLL(argv[1]); - exit(0); -} diff --git a/lib/resdata/tests/rd_nnc_export_intersect.cpp b/lib/resdata/tests/rd_nnc_export_intersect.cpp deleted file mode 100644 index 72c8cdf3a..000000000 --- a/lib/resdata/tests/rd_nnc_export_intersect.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// #include -// #include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace { - -const auto GRIDX = 10, GRIDY = 10, GRIDZ = 10; -const auto GRID_NNC_NUM = 342; -const auto INIT_NNC_NUM = 298; - -ERT::ert_unique_ptr make_intersect_grid() { - auto out = ERT::ert_unique_ptr( - rd_grid_alloc_rectangular(GRIDX, GRIDY, GRIDZ, 1., 1., 1., nullptr)); - for (auto i = 0; i < GRID_NNC_NUM; ++i) - rd_grid_add_self_nnc(out.get(), 2 * i + 1, 2 * i, i); - return out; -} - -ERT::ert_unique_ptr make_intersect_init_file() { - // Create keywords with useless data - auto nnc1_kw = rd_kw_alloc(NNC1_KW, INIT_NNC_NUM, RD_INT); - auto nnc2_kw = rd_kw_alloc(NNC2_KW, INIT_NNC_NUM, RD_INT); - auto tran_kw = rd_kw_alloc(TRANNNC_KW, INIT_NNC_NUM, RD_DOUBLE); - for (auto i = 0; i < INIT_NNC_NUM; ++i) { - rd_kw_iset_int(nnc1_kw, i, 2 * i); - rd_kw_iset_int(nnc2_kw, i, 2 * i + 1); - rd_kw_iset_double(tran_kw, i, 2.5 * i); - } - - // write to file directly using fortio - auto init_filename = - util_alloc_tmp_file("/tmp", "rd_nnc_export_intersect_init_file", false); - auto fortio = fortio_open_writer(init_filename, false, RD_ENDIAN_FLIP); - rd_kw_fwrite(nnc1_kw, fortio); - rd_kw_fwrite(nnc2_kw, fortio); - rd_kw_fwrite(tran_kw, fortio); - fortio_fclose(fortio); - - // reopen the file as an ecl file - auto out = ERT::ert_unique_ptr( - rd_file_open(init_filename, 0)); - - rd_kw_free(nnc1_kw); - rd_kw_free(nnc2_kw); - rd_kw_free(tran_kw); - free(init_filename); - return out; -} -} /* unnamed namespace */ - -int main(int argc, char **argv) { - util_install_signals(); - - const auto grid = make_intersect_grid(); - const auto init_file = make_intersect_init_file(); - - test_assert_true(rd_nnc_intersect_format(grid.get(), init_file.get())); - test_assert_int_equal(rd_nnc_export_get_size(grid.get(), init_file.get()), - INIT_NNC_NUM); - - auto nnc_data = std::vector( - rd_nnc_export_get_size(grid.get(), init_file.get())); - auto const total_valid_trans = - rd_nnc_export(grid.get(), init_file.get(), nnc_data.data()); - test_assert_int_equal(total_valid_trans, INIT_NNC_NUM); - test_assert_int_equal(int(nnc_data.size()), INIT_NNC_NUM); - - for (auto i = 0; i < int(nnc_data.size()); ++i) { - auto const &nnc = nnc_data[i]; - test_assert_int_equal(nnc.grid_nr1, 0); - test_assert_int_equal(nnc.grid_nr2, 0); - test_assert_int_equal(nnc.global_index1, - 2 * i); // as set in make_intersect_init_file() - test_assert_int_equal(nnc.global_index2, - 2 * i + - 1); // as set in make_intersect_init_file() - test_assert_double_equal( - nnc.trans, 2.5 * i); // as set in make_intersect_init_file() - test_assert_int_equal(nnc.input_index, i); - } - - return 0; -} diff --git a/lib/resdata/tests/rd_nnc_geometry.cpp b/lib/resdata/tests/rd_nnc_geometry.cpp deleted file mode 100644 index fa4a1cdc4..000000000 --- a/lib/resdata/tests/rd_nnc_geometry.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - -void test_create_empty() { - rd_grid_type *grid = rd_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); - rd_nnc_geometry_type *nnc_geo = rd_nnc_geometry_alloc(grid); - test_assert_true(rd_nnc_geometry_is_instance(nnc_geo)); - test_assert_int_equal(rd_nnc_geometry_size(nnc_geo), 0); - rd_nnc_geometry_free(nnc_geo); - rd_grid_free(grid); -} - -void test_create_simple() { - rd::util::TestArea ta("nnc_geometry"); - { - int nx = 10; - int ny = 10; - int nz = 10; - rd_grid_type *grid0 = - rd_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); - - rd_grid_add_self_nnc(grid0, 0, nx * ny + 0, 0); - rd_grid_add_self_nnc(grid0, 1, nx * ny + 1, 1); - rd_grid_add_self_nnc(grid0, 2, nx * ny + 2, 2); - { - rd_nnc_geometry_type *nnc_geo = rd_nnc_geometry_alloc(grid0); - test_assert_int_equal(rd_nnc_geometry_size(nnc_geo), 3); - - /* - Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size. - */ - { - rd_kw_type *trann_nnc = rd_kw_alloc( - TRANNNC_KW, rd_nnc_geometry_size(nnc_geo), RD_FLOAT); - fortio_type *f = - fortio_open_writer("TEST.INIT", false, RD_ENDIAN_FLIP); - - for (int i = 0; i < rd_kw_get_size(trann_nnc); i++) - rd_kw_iset_float(trann_nnc, i, i * 1.0); - - rd_kw_fwrite(trann_nnc, f); - fortio_fclose(f); - rd_kw_free(trann_nnc); - } - rd_nnc_geometry_free(nnc_geo); - } - rd_grid_free(grid0); - } -} - -int main(int argc, char **argv) { - util_install_signals(); - test_create_empty(); - test_create_simple(); -} diff --git a/lib/resdata/tests/rd_nnc_pair.cpp b/lib/resdata/tests/rd_nnc_pair.cpp deleted file mode 100644 index 263574e64..000000000 --- a/lib/resdata/tests/rd_nnc_pair.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#include -#include - -#include - -void test_pair(int grid1_1, int grid1_2, int grid2_1, int grid2_2, - bool expected) { - rd_nnc_pair_type pair1 = {grid1_1, grid1_2, 0, 0}; - rd_nnc_pair_type pair2 = {grid2_1, grid2_2, 0, 0}; - - test_assert_bool_equal(rd_nnc_geometry_same_kw(&pair1, &pair2), expected); -} - -int main(int argc, char **argv) { - test_pair(1, 1, 1, 1, true); - test_pair(1, 3, 1, 3, true); - test_pair(1, 1, 3, 3, false); - test_pair(1, 3, 3, 1, false); -} diff --git a/lib/resdata/tests/test_rd_nnc_data.cpp b/lib/resdata/tests/test_rd_nnc_data.cpp deleted file mode 100644 index 6be117886..000000000 --- a/lib/resdata/tests/test_rd_nnc_data.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -void test_alloc_global_only(bool data_in_file) { - rd::util::TestArea ta("nnc-INIT"); - { - int nx = 10; - int ny = 10; - int nz = 10; - rd_grid_type *grid0 = - rd_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); - - rd_grid_add_self_nnc(grid0, 0, nx * ny + 0, 0); - rd_grid_add_self_nnc(grid0, 1, nx * ny + 1, 1); - rd_grid_add_self_nnc(grid0, 2, nx * ny + 2, 2); - { - rd_nnc_geometry_type *nnc_geo = rd_nnc_geometry_alloc(grid0); - test_assert_int_equal(rd_nnc_geometry_size(nnc_geo), 3); - /* - Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size. - */ - { - rd_kw_type *trann_nnc = rd_kw_alloc( - TRANNNC_KW, rd_nnc_geometry_size(nnc_geo), RD_FLOAT); - fortio_type *f = - fortio_open_writer("TEST.INIT", false, RD_ENDIAN_FLIP); - - if (data_in_file) { - for (int i = 0; i < rd_kw_get_size(trann_nnc); i++) - rd_kw_iset_float(trann_nnc, i, i * 1.5); - - rd_kw_fwrite(trann_nnc, f); - } - fortio_fclose(f); - rd_kw_free(trann_nnc); - } - - rd_file_type *init_file = rd_file_open("TEST.INIT", 0); - rd_file_view_type *view_file = rd_file_get_global_view(init_file); - - rd_nnc_data_type *nnc_geo_data = - rd_nnc_data_alloc_tran(grid0, nnc_geo, view_file); - - if (data_in_file) { - - int nnc_data_size = rd_nnc_data_get_size(nnc_geo_data); - test_assert_true(rd_file_view_has_kw(view_file, TRANNNC_KW)); - test_assert_true(nnc_data_size == 3); - const double *values = rd_nnc_data_get_values(nnc_geo_data); - test_assert_double_equal(values[0], 0); - test_assert_double_equal(values[1], 1.5); - test_assert_double_equal(values[2], 3.0); - } else - test_assert_NULL(nnc_geo_data); - - if (data_in_file) - rd_nnc_data_free(nnc_geo_data); - rd_nnc_geometry_free(nnc_geo); - rd_file_close(init_file); - } - rd_grid_free(grid0); - } -} - -int main(int argc, char **argv) { - - test_alloc_global_only(true); - test_alloc_global_only(false); - - return 0; -}