diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index cb169b7ec..e77127df0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -61,7 +61,7 @@ add_library( resdata/rd_rsthead.cpp resdata/rd_sum_tstep.cpp resdata/rd_rst_file.cpp - resdata/rd_init_file.cpp + resdata/ resdata/rd_grid_cache.cpp resdata/smspec_node.cpp resdata/rd_kw_grdecl.cpp @@ -269,7 +269,6 @@ foreach( rd_sum_data_intermediate_test rd_grid_cell_contains rd_unsmry_loader_test - rd_init_file rd_kw_space_pad rd_kw_cmp_string rd_kw_equal diff --git a/lib/include/resdata/rd_init_file.hpp b/lib/include/resdata/rd_init_file.hpp deleted file mode 100644 index 0ad81993c..000000000 --- a/lib/include/resdata/rd_init_file.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ERT_RD_INIT_FILE_H -#define ERT_RD_INIT_FILE_H - -#include - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void rd_init_file_fwrite_header(fortio_type *fortio, const rd_grid_type *grid, - const rd_kw_type *poro, - ert_rd_unit_enum unit_system, int phases, - time_t start_date); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/resdata/rd_init_file.cpp b/lib/resdata/rd_init_file.cpp deleted file mode 100644 index 48c249428..000000000 --- a/lib/resdata/rd_init_file.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - This file contains functionality to write an ECLIPSE INIT file. The - file does (currently) not contain any datastructures, only - functions. Essentially this file is only a codifying of the ECLIPSE - documentation of INIT files. - - The functionality is mainly targeted at saving grid properties like - PORO, PERMX and FIPNUM. The thermodynamic/relperm properties are - mainly hardcoded to FALSE (in particular in the - rd_init_file_alloc_LOGIHEAD() function); this implies that the INIT - files produced in this way are probably not 100% valid, and can - certainly not be used to query for e.g. relperm properties. -*/ - -#include - -#include -#include -#include -#include -#include -#include -#include - -static rd_kw_type *rd_init_file_alloc_INTEHEAD(const rd_grid_type *rd_grid, - ert_rd_unit_enum unit_system, - int phases, time_t start_date, - int simulator) { - rd_kw_type *intehead_kw = - rd_kw_alloc(INTEHEAD_KW, INTEHEAD_INIT_SIZE, RD_INT); - rd_kw_scalar_set_int(intehead_kw, 0); - - rd_kw_iset_int(intehead_kw, INTEHEAD_UNIT_INDEX, unit_system); - rd_kw_iset_int(intehead_kw, INTEHEAD_NX_INDEX, rd_grid_get_nx(rd_grid)); - rd_kw_iset_int(intehead_kw, INTEHEAD_NY_INDEX, rd_grid_get_ny(rd_grid)); - rd_kw_iset_int(intehead_kw, INTEHEAD_NZ_INDEX, rd_grid_get_nz(rd_grid)); - rd_kw_iset_int(intehead_kw, INTEHEAD_NACTIVE_INDEX, - rd_grid_get_active_size(rd_grid)); - rd_kw_iset_int(intehead_kw, INTEHEAD_PHASE_INDEX, phases); - { - int mday, month, year; - rd_set_date_values(start_date, &mday, &month, &year); - rd_kw_iset_int(intehead_kw, INTEHEAD_DAY_INDEX, mday); - rd_kw_iset_int(intehead_kw, INTEHEAD_MONTH_INDEX, month); - rd_kw_iset_int(intehead_kw, INTEHEAD_YEAR_INDEX, year); - } - rd_kw_iset_int(intehead_kw, INTEHEAD_IPROG_INDEX, simulator); - - return intehead_kw; -} - -static rd_kw_type *rd_init_file_alloc_LOGIHEAD(int simulator) { - /* - This function includes lots of hardcoded options; the main - intention of writing the INIT file is to store the grid properties - like e.g. PORO and SATNUM. The relperm/thermodynamics properties - are just all defaulted to False. - - The documentation - */ - bool with_RS = false; - bool with_RV = false; - bool with_directional_relperm = false; - bool with_reversible_relperm_ECLIPSE100 = false; - bool radial_grid_ECLIPSE100 = false; - bool radial_grid_ECLIPSE300 = false; - bool with_reversible_relperm_ECLIPSE300 = false; - bool with_hysterisis = false; - bool dual_porosity = false; - bool endpoint_scaling = false; - bool directional_endpoint_scaling = false; - bool reversible_endpoint_scaling = false; - bool alternative_endpoint_scaling = false; - bool miscible_displacement = false; - bool scale_water_PC_at_max_sat = false; - bool scale_gas_PC_at_max_sat = false; - - rd_kw_type *logihead_kw = - rd_kw_alloc(LOGIHEAD_KW, LOGIHEAD_INIT_SIZE, RD_BOOL); - - rd_kw_scalar_set_bool(logihead_kw, false); - - rd_kw_iset_bool(logihead_kw, LOGIHEAD_RS_INDEX, with_RS); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_RV_INDEX, with_RV); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_DIR_RELPERM_INDEX, - with_directional_relperm); - - if (simulator == INTEHEAD_ECLIPSE100_VALUE) { - rd_kw_iset_bool(logihead_kw, LOGIHEAD_REV_RELPERM100_INDEX, - with_reversible_relperm_ECLIPSE100); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL100_INDEX, - radial_grid_ECLIPSE100); - } else { - rd_kw_iset_bool(logihead_kw, LOGIHEAD_REV_RELPERM300_INDEX, - with_reversible_relperm_ECLIPSE300); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL300_INDEX, - radial_grid_ECLIPSE300); - } - - rd_kw_iset_bool(logihead_kw, LOGIHEAD_HYSTERISIS_INDEX, with_hysterisis); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_DUALP_INDEX, dual_porosity); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_ENDPOINT_SCALING_INDEX, - endpoint_scaling); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_DIR_ENDPOINT_SCALING_INDEX, - directional_endpoint_scaling); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_REV_ENDPOINT_SCALING_INDEX, - reversible_endpoint_scaling); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_ALT_ENDPOINT_SCALING_INDEX, - alternative_endpoint_scaling); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_MISC_DISPLACEMENT_INDEX, - miscible_displacement); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_SCALE_WATER_PC_AT_MAX_SAT_INDEX, - scale_water_PC_at_max_sat); - rd_kw_iset_bool(logihead_kw, LOGIHEAD_SCALE_GAS_PC_AT_MAX_SAT_INDEX, - scale_gas_PC_at_max_sat); - - return logihead_kw; -} - -static rd_kw_type *rd_init_file_alloc_DOUBHEAD() { - rd_kw_type *doubhead_kw = - rd_kw_alloc(DOUBHEAD_KW, DOUBHEAD_INIT_SIZE, RD_DOUBLE); - - rd_kw_scalar_set_double(doubhead_kw, 0); - - return doubhead_kw; -} - -/** - The writing of the PORO field is somewhat special cased; the INIT - file should contain the PORV keyword with nx*ny*nz elements. The - cells which are inactive have the PORV volume explicitly set to - zero; this way the active/inactive status can be inferred from PORV - field in the INIT file. - - In this code the PORO field is considered to be the fundamental - quantity, and the PORV field is calculated from PORO and the volume - of the grid cells. Apart from PORV all the remaining fields in the - INIT file should have nactive elements. - - If you do not wish this function to be used for the PORV special - casing you can just pass NULL as the poro_kw in the - rd_init_file_fwrite_header() function. - */ - -static void rd_init_file_fwrite_poro(fortio_type *fortio, - const rd_grid_type *rd_grid, - const rd_kw_type *poro) { - { - rd_kw_type *porv = - rd_kw_alloc(PORV_KW, rd_grid_get_global_size(rd_grid), RD_FLOAT); - int global_index; - bool global_poro = - (rd_kw_get_size(poro) == rd_grid_get_global_size(rd_grid)) ? true - : false; - for (global_index = 0; global_index < rd_grid_get_global_size(rd_grid); - global_index++) { - int active_index = rd_grid_get_active_index1(rd_grid, global_index); - if (active_index >= 0) { - int poro_index = global_poro ? global_index : active_index; - rd_kw_iset_float( - porv, global_index, - rd_kw_iget_float(poro, poro_index) * - rd_grid_get_cell_volume1(rd_grid, global_index)); - } else - rd_kw_iset_float(porv, global_index, 0); - } - rd_kw_fwrite(porv, fortio); - rd_kw_free(porv); - } - - rd_kw_fwrite(poro, fortio); -} - -/* - If the poro keyword is non NULL this function will write both the - PORO keyword itself and also calculate the PORV keyword and write - that. -*/ - -void rd_init_file_fwrite_header(fortio_type *fortio, - const rd_grid_type *rd_grid, - const rd_kw_type *poro, - ert_rd_unit_enum unit_system, int phases, - time_t start_date) { - int simulator = INTEHEAD_ECLIPSE100_VALUE; - { - rd_kw_type *intehead_kw = rd_init_file_alloc_INTEHEAD( - rd_grid, unit_system, phases, start_date, simulator); - rd_kw_fwrite(intehead_kw, fortio); - rd_kw_free(intehead_kw); - } - - { - rd_kw_type *logihead_kw = rd_init_file_alloc_LOGIHEAD(simulator); - rd_kw_fwrite(logihead_kw, fortio); - rd_kw_free(logihead_kw); - } - - { - rd_kw_type *doubhead_kw = rd_init_file_alloc_DOUBHEAD(); - rd_kw_fwrite(doubhead_kw, fortio); - rd_kw_free(doubhead_kw); - } - - if (poro) { - int poro_size = rd_kw_get_size(poro); - if ((poro_size == rd_grid_get_nactive(rd_grid)) || - (poro_size == rd_grid_get_global_size(rd_grid))) - rd_init_file_fwrite_poro(fortio, rd_grid, poro); - else - util_abort("%s: keyword PORO has wrong size:%d Grid: %d/%d \n", - __func__, rd_kw_get_size(poro), - rd_grid_get_nactive(rd_grid), - rd_grid_get_global_size(rd_grid)); - } -} diff --git a/lib/resdata/tests/rd_init_file.cpp b/lib/resdata/tests/rd_init_file.cpp deleted file mode 100644 index 947b64809..000000000 --- a/lib/resdata/tests/rd_init_file.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -void test_write_header() { - int nx = 10; - int ny = 10; - int nz = 5; - - rd::util::TestArea ta("WRITE_header"); - int_vector_type *actnum = int_vector_alloc(nx * ny * nz, 1); - time_t start_time = util_make_date_utc(15, 12, 2010); - rd_grid_type *rd_grid; - - int_vector_iset(actnum, 10, 0); - int_vector_iset(actnum, 100, 0); - - rd_grid = rd_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, - int_vector_get_ptr(actnum)); - - // Write poro with global size. - { - fortio_type *f = fortio_open_writer("FOO1.INIT", false, RD_ENDIAN_FLIP); - rd_kw_type *poro = - rd_kw_alloc("PORO", rd_grid_get_global_size(rd_grid), RD_FLOAT); - rd_kw_scalar_set_float(poro, 0.10); - rd_init_file_fwrite_header(f, rd_grid, poro, RD_FIELD_UNITS, 7, - start_time); - rd_kw_free(poro); - fortio_fclose(f); - } - - // Write poro with nactive size. - { - fortio_type *f = fortio_open_writer("FOO2.INIT", false, RD_ENDIAN_FLIP); - rd_kw_type *poro = - rd_kw_alloc("PORO", rd_grid_get_global_size(rd_grid), RD_FLOAT); - rd_kw_scalar_set_float(poro, 0.10); - rd_init_file_fwrite_header(f, rd_grid, poro, RD_FIELD_UNITS, 7, - start_time); - rd_kw_free(poro); - fortio_fclose(f); - } - { - rd_file_type *file1 = rd_file_open("FOO1.INIT", 0); - rd_file_type *file2 = rd_file_open("FOO2.INIT", 0); - - test_assert_true(rd_kw_equal(rd_file_iget_named_kw(file1, "PORV", 0), - rd_file_iget_named_kw(file2, "PORV", 0))); - - rd_file_close(file2); - rd_file_close(file1); - } - - // Poro == NULL - { - fortio_type *f = fortio_open_writer("FOO3.INIT", false, RD_ENDIAN_FLIP); - rd_init_file_fwrite_header(f, rd_grid, NULL, RD_METRIC_UNITS, 7, - start_time); - fortio_fclose(f); - } - rd_grid_free(rd_grid); - int_vector_free(actnum); -} - -int main(int argc, char **argv) { - test_write_header(); - exit(0); -}