From 7d91bac8dafddd1d7506f8399f6a0d2a378d58db Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Wed, 25 Oct 2023 11:31:43 +0200 Subject: [PATCH] rename libecl to resdata * Rename namespace ecl to resdata/rd * Rename ResdataFileEnum to FileType * Rename ResdataPhaseEnum to Phase * Rename ResdataUnitTypeEnum to UnitSytem * Rename ResdataFileFlagEnum to FileMode * Rename WellConnectionDirectionEnum to WellConnectionDirection * Rename WellTypeEnum to WellType * Rename resdata.util.geometry to resdata.geometry * Rename ErtTestRunner to ResdataTestRunner --- .github/workflows/testing.yml | 20 +- .gitignore | 2 +- CMakeLists.txt | 47 +- CONTRIBUTING.md | 2 +- README.md | 48 +- WINDOWS.md | 14 +- applications/CMakeLists.txt | 54 +- .../man/man1/{ecl_summary.1 => rd_summary.1} | 56 +- applications/{ecl => resdata}/convert.c | 43 +- applications/{ecl => resdata}/grdecl_grid.c | 40 +- applications/{ecl => resdata}/grdecl_test.c | 10 +- applications/{ecl => resdata}/grid_dump.c | 10 +- .../{ecl => resdata}/grid_dump_ascii.c | 10 +- applications/{ecl => resdata}/grid_info.c | 22 +- applications/{ecl => resdata}/kw_extract.cpp | 32 +- applications/{ecl => resdata}/kw_list.c | 20 +- applications/{ecl => resdata}/load_test.c | 34 +- applications/{ecl => resdata}/make_grid.c | 12 +- .../{ecl/ecl_pack.c => resdata/rd_pack.c} | 66 +- .../{ecl/ecl_unpack.c => resdata/rd_unpack.c} | 69 +- applications/{ecl => resdata}/select_test.c | 4 +- applications/{ecl => resdata}/sum_write.cpp | 92 +- .../{ecl => resdata}/view_summary.cpp | 51 +- applications/well/ri_well_test.c | 10 +- applications/well/segment_info.c | 46 +- applications/well/well_CF_dump.c | 10 +- bin/summary_resample | 8 +- ci/github/setup.py | 4 +- ci/testkomodo.sh | 2 +- ...ake.in => resdata-config-version.cmake.in} | 6 +- ...onfig.cmake.in => resdata-config.cmake.in} | 6 +- lib/CMakeLists.txt | 773 ++-- lib/ecl/EclFilename.cpp | 68 - lib/ecl/ecl_file.cpp | 1014 ----- lib/ecl/ecl_file_kw.cpp | 426 -- lib/ecl/ecl_file_view.cpp | 856 ---- lib/ecl/ecl_grav.cpp | 697 --- lib/ecl/ecl_grid_cache.cpp | 46 - lib/ecl/ecl_grid_dims.cpp | 131 - lib/ecl/ecl_init_file.cpp | 220 - lib/ecl/ecl_kw.cpp | 2875 ------------- lib/ecl/ecl_nnc_data.cpp | 273 -- lib/ecl/ecl_nnc_export.cpp | 290 -- lib/ecl/ecl_region.cpp | 1554 ------- lib/ecl/ecl_rft_node.cpp | 615 --- lib/ecl/ecl_rst_file.cpp | 278 -- lib/ecl/ecl_smspec.cpp | 1804 -------- lib/ecl/ecl_subsidence.cpp | 340 -- lib/ecl/ecl_sum.cpp | 1560 ------- lib/ecl/ecl_sum_tstep.cpp | 333 -- lib/ecl/ecl_sum_vector.cpp | 146 - lib/ecl/ecl_type.cpp | 187 - lib/ecl/ecl_type_python.cpp | 121 - lib/ecl/readme.overview | 55 - lib/ecl/tests/ecl_coarse_test.cpp | 88 - lib/ecl/tests/ecl_dualp.cpp | 70 - lib/ecl/tests/ecl_file.cpp | 108 - lib/ecl/tests/ecl_file_equinor.cpp | 125 - lib/ecl/tests/ecl_file_view.cpp | 103 - lib/ecl/tests/ecl_get_num_cpu_test.cpp | 20 - lib/ecl/tests/ecl_grid_add_nnc.cpp | 122 - lib/ecl/tests/ecl_grid_cell_contains.cpp | 279 -- lib/ecl/tests/ecl_grid_copy.cpp | 34 - lib/ecl/tests/ecl_grid_dx_dy_dz.cpp | 56 - lib/ecl/tests/ecl_grid_export.cpp | 179 - lib/ecl/tests/ecl_grid_ext_actnum.cpp | 59 - lib/ecl/tests/ecl_grid_init_fwrite.cpp | 86 - lib/ecl/tests/ecl_grid_layer_contains.cpp | 31 - lib/ecl/tests/ecl_grid_reset_actnum.cpp | 45 - lib/ecl/tests/ecl_grid_unit_system.cpp | 38 - lib/ecl/tests/ecl_grid_volume.cpp | 75 - lib/ecl/tests/ecl_init_file.cpp | 83 - lib/ecl/tests/ecl_kw_cmp_string.cpp | 30 - lib/ecl/tests/ecl_kw_equal.cpp | 50 - lib/ecl/tests/ecl_kw_fread.cpp | 111 - lib/ecl/tests/ecl_kw_grdecl.cpp | 58 - lib/ecl/tests/ecl_lgr_name.cpp | 28 - lib/ecl/tests/ecl_lgr_test.cpp | 25 - lib/ecl/tests/ecl_nnc_data_equinor_root.cpp | 113 - lib/ecl/tests/ecl_nnc_export.cpp | 361 -- lib/ecl/tests/ecl_nnc_export_get_tran.cpp | 157 - lib/ecl/tests/ecl_nnc_export_intersect.cpp | 95 - lib/ecl/tests/ecl_nnc_geometry.cpp | 62 - lib/ecl/tests/ecl_nnc_index_list_grid.cpp | 45 - lib/ecl/tests/ecl_nnc_test.cpp | 135 - lib/ecl/tests/ecl_region.cpp | 49 - lib/ecl/tests/ecl_region2region.cpp | 53 - lib/ecl/tests/ecl_rft.cpp | 164 - lib/ecl/tests/ecl_rft_cell.cpp | 138 - lib/ecl/tests/ecl_rst_file.cpp | 146 - lib/ecl/tests/ecl_smspec.cpp | 35 - .../tests/ecl_sum_alloc_resampled_test.cpp | 141 - .../tests/ecl_sum_report_step_compatible.cpp | 31 - lib/ecl/tests/ecl_sum_report_step_equal.cpp | 31 - lib/ecl/tests/ecl_sum_test.cpp | 51 - lib/ecl/tests/ecl_sum_writer.cpp | 246 -- lib/ecl/tests/ecl_unsmry_loader_test.cpp | 63 - lib/ecl/tests/ecl_util_path_access.cpp | 31 - lib/ecl/tests/ecl_valid_basename.cpp | 17 - lib/ecl/tests/eclxx_filename.cpp | 50 - lib/ecl/tests/eclxx_types.cpp | 37 - lib/ecl/tests/test_ecl_file_index.cpp | 91 - lib/ecl/tests/test_ecl_nnc_data.cpp | 81 - lib/ecl/tests/test_transactions.cpp | 97 - lib/include/ert/ecl/EclFilename.hpp | 21 - lib/include/ert/ecl/EclKW.hpp | 241 -- lib/include/ert/ecl/ecl_box.hpp | 24 - lib/include/ert/ecl/ecl_coarse_cell.hpp | 51 - lib/include/ert/ecl/ecl_endian_flip.hpp | 41 - lib/include/ert/ecl/ecl_file.hpp | 135 - lib/include/ert/ecl/ecl_file_kw.hpp | 59 - lib/include/ert/ecl/ecl_file_view.hpp | 150 - lib/include/ert/ecl/ecl_grav.hpp | 41 - lib/include/ert/ecl/ecl_grav_common.h | 7 - lib/include/ert/ecl/ecl_grav_common.hpp | 32 - lib/include/ert/ecl/ecl_grid.hpp | 390 -- lib/include/ert/ecl/ecl_grid_dims.h | 7 - lib/include/ert/ecl/ecl_grid_dims.hpp | 21 - lib/include/ert/ecl/ecl_init_file.h | 7 - lib/include/ert/ecl/ecl_init_file.hpp | 23 - lib/include/ert/ecl/ecl_io_config.h | 7 - lib/include/ert/ecl/ecl_io_config.hpp | 26 - lib/include/ert/ecl/ecl_kw.hpp | 294 -- lib/include/ert/ecl/ecl_kw_grdecl.h | 7 - lib/include/ert/ecl/ecl_kw_grdecl.hpp | 47 - lib/include/ert/ecl/ecl_kw_magic.h | 7 - lib/include/ert/ecl/ecl_nnc_data.h | 7 - lib/include/ert/ecl/ecl_nnc_data.hpp | 40 - lib/include/ert/ecl/ecl_nnc_export.h | 7 - lib/include/ert/ecl/ecl_nnc_export.hpp | 50 - lib/include/ert/ecl/ecl_nnc_geometry.h | 7 - lib/include/ert/ecl/ecl_nnc_geometry.hpp | 36 - lib/include/ert/ecl/ecl_region.h | 7 - lib/include/ert/ecl/ecl_region.hpp | 261 -- lib/include/ert/ecl/ecl_rft_cell.h | 7 - lib/include/ert/ecl/ecl_rft_cell.hpp | 60 - lib/include/ert/ecl/ecl_rft_file.h | 7 - lib/include/ert/ecl/ecl_rft_file.hpp | 53 - lib/include/ert/ecl/ecl_rft_node.h | 7 - lib/include/ert/ecl/ecl_rft_node.hpp | 70 - lib/include/ert/ecl/ecl_rst_file.h | 7 - lib/include/ert/ecl/ecl_rst_file.hpp | 31 - lib/include/ert/ecl/ecl_rsthead.h | 7 - lib/include/ert/ecl/ecl_smspec.h | 7 - lib/include/ert/ecl/ecl_smspec.hpp | 225 - lib/include/ert/ecl/ecl_subsidence.h | 7 - lib/include/ert/ecl/ecl_subsidence.hpp | 48 - lib/include/ert/ecl/ecl_sum.hpp | 322 -- lib/include/ert/ecl/ecl_sum_data.h | 7 - lib/include/ert/ecl/ecl_sum_data.hpp | 134 - lib/include/ert/ecl/ecl_sum_index.h | 7 - lib/include/ert/ecl/ecl_sum_index.hpp | 13 - lib/include/ert/ecl/ecl_sum_tstep.h | 7 - lib/include/ert/ecl/ecl_sum_tstep.hpp | 72 - lib/include/ert/ecl/ecl_sum_vector.h | 7 - lib/include/ert/ecl/ecl_sum_vector.hpp | 40 - lib/include/ert/ecl/ecl_type.h | 7 - lib/include/ert/ecl/ecl_type.hpp | 134 - lib/include/ert/ecl/ecl_units.h | 7 - lib/include/ert/ecl/ecl_units.hpp | 28 - lib/include/ert/ecl/ecl_util.h | 7 - lib/include/ert/ecl/ecl_util.hpp | 158 - lib/include/ert/geometry/geo_pointset.h | 2 +- lib/include/ert/geometry/geo_polygon.h | 2 +- .../ert/geometry/geo_polygon_collection.h | 2 +- lib/include/ert/geometry/geo_region.h | 2 +- lib/include/ert/geometry/geo_surface.h | 2 +- lib/include/ert/geometry/geo_util.h | 2 +- lib/include/ert/util/buffer.h | 2 +- lib/include/ert/util/ecl_version.h | 7 - lib/include/ert/util/ecl_version.hpp | 22 - lib/include/ert/util/hash.h | 2 +- lib/include/ert/util/hash_node.h | 2 +- lib/include/ert/util/hash_sll.h | 2 +- lib/include/ert/util/lookup_table.h | 2 +- lib/include/ert/util/mzran.h | 2 +- lib/include/ert/util/node_ctype.h | 2 +- lib/include/ert/util/node_data.h | 2 +- lib/include/ert/util/parser.h | 2 +- lib/include/ert/util/path_stack.h | 2 +- lib/include/ert/util/perm_vector.h | 2 +- lib/include/ert/util/rd_version.h | 7 + lib/include/ert/util/rd_version.hpp | 22 + lib/include/ert/util/rng.h | 2 +- lib/include/ert/util/ssize_t.h | 2 +- lib/include/ert/util/statistics.h | 2 +- lib/include/ert/util/string_util.h | 2 +- lib/include/ert/util/stringlist.h | 2 +- lib/include/ert/util/test_util.h | 2 +- lib/include/ert/util/test_work_area.h | 2 +- lib/include/ert/util/test_work_area.hpp | 6 +- lib/include/ert/util/type_macros.h | 2 +- lib/include/ert/util/type_vector_functions.h | 2 +- lib/include/ert/util/vector.h | 2 +- lib/include/{ert/ecl => resdata}/FortIO.hpp | 8 +- lib/include/resdata/RDFilename.hpp | 21 + lib/include/resdata/ResdataKW.hpp | 244 ++ .../{ert/ecl => resdata}/fault_block.h | 4 +- .../{ert/ecl => resdata}/fault_block.hpp | 4 +- .../{ert/ecl => resdata}/fault_block_layer.h | 4 +- .../ecl => resdata}/fault_block_layer.hpp | 18 +- lib/include/{ert/ecl => resdata}/fortio.h | 0 lib/include/{ert/ecl => resdata}/grid_dims.h | 4 +- .../{ert/ecl => resdata}/grid_dims.hpp | 0 lib/include/{ert/ecl => resdata}/layer.h | 4 +- lib/include/{ert/ecl => resdata}/layer.hpp | 4 +- lib/include/{ert/ecl => resdata}/nnc_info.h | 4 +- lib/include/{ert/ecl => resdata}/nnc_info.hpp | 2 +- lib/include/{ert/ecl => resdata}/nnc_vector.h | 4 +- .../{ert/ecl => resdata}/nnc_vector.hpp | 0 lib/include/resdata/rd_box.hpp | 24 + .../rd_coarse_cell.h} | 4 +- lib/include/resdata/rd_coarse_cell.hpp | 51 + .../rd_endian_flip.h} | 4 +- lib/include/resdata/rd_endian_flip.hpp | 41 + .../{ert/ecl/ecl_file.h => resdata/rd_file.h} | 4 +- lib/include/resdata/rd_file.hpp | 128 + .../ecl_file_kw.h => resdata/rd_file_kw.h} | 4 +- lib/include/resdata/rd_file_kw.hpp | 54 + .../rd_file_view.h} | 4 +- lib/include/resdata/rd_file_view.hpp | 145 + .../{ert/ecl/ecl_grid.h => resdata/rd_grav.h} | 4 +- lib/include/resdata/rd_grav.hpp | 41 + lib/include/resdata/rd_grav_common.h | 7 + lib/include/resdata/rd_grav_common.hpp | 32 + .../{ert/ecl/ecl_grav.h => resdata/rd_grid.h} | 4 +- lib/include/resdata/rd_grid.hpp | 372 ++ lib/include/resdata/rd_grid_dims.h | 7 + lib/include/resdata/rd_grid_dims.hpp | 21 + lib/include/resdata/rd_init_file.h | 7 + lib/include/resdata/rd_init_file.hpp | 23 + lib/include/resdata/rd_io_config.h | 7 + lib/include/resdata/rd_io_config.hpp | 26 + .../{ert/ecl/ecl_kw.h => resdata/rd_kw.h} | 4 +- lib/include/resdata/rd_kw.hpp | 286 ++ lib/include/resdata/rd_kw_grdecl.h | 7 + lib/include/resdata/rd_kw_grdecl.hpp | 46 + lib/include/resdata/rd_kw_magic.h | 7 + .../rd_kw_magic.hpp} | 12 +- lib/include/resdata/rd_nnc_data.h | 7 + lib/include/resdata/rd_nnc_data.hpp | 40 + lib/include/resdata/rd_nnc_export.h | 7 + lib/include/resdata/rd_nnc_export.hpp | 50 + lib/include/resdata/rd_nnc_geometry.h | 7 + lib/include/resdata/rd_nnc_geometry.hpp | 36 + lib/include/resdata/rd_region.h | 7 + lib/include/resdata/rd_region.hpp | 243 ++ lib/include/resdata/rd_rft_cell.h | 7 + lib/include/resdata/rd_rft_cell.hpp | 59 + lib/include/resdata/rd_rft_file.h | 7 + lib/include/resdata/rd_rft_file.hpp | 50 + lib/include/resdata/rd_rft_node.h | 7 + lib/include/resdata/rd_rft_node.hpp | 70 + lib/include/resdata/rd_rst_file.h | 7 + lib/include/resdata/rd_rst_file.hpp | 30 + lib/include/resdata/rd_rsthead.h | 7 + .../rd_rsthead.hpp} | 50 +- lib/include/resdata/rd_smspec.h | 7 + lib/include/resdata/rd_smspec.hpp | 222 + lib/include/resdata/rd_subsidence.h | 7 + lib/include/resdata/rd_subsidence.hpp | 48 + .../{ert/ecl/ecl_sum.h => resdata/rd_sum.h} | 4 +- lib/include/resdata/rd_sum.hpp | 313 ++ lib/include/resdata/rd_sum_data.h | 7 + lib/include/resdata/rd_sum_data.hpp | 129 + lib/include/resdata/rd_sum_index.h | 7 + lib/include/resdata/rd_sum_index.hpp | 13 + lib/include/resdata/rd_sum_tstep.h | 7 + lib/include/resdata/rd_sum_tstep.hpp | 73 + lib/include/resdata/rd_sum_vector.h | 7 + lib/include/resdata/rd_sum_vector.hpp | 40 + lib/include/resdata/rd_type.h | 7 + lib/include/resdata/rd_type.hpp | 134 + lib/include/resdata/rd_units.h | 7 + lib/include/resdata/rd_units.hpp | 28 + lib/include/resdata/rd_util.h | 7 + lib/include/resdata/rd_util.hpp | 154 + .../{ert/ecl => resdata}/smspec_node.h | 42 +- .../{ert/ecl => resdata}/smspec_node.hpp | 18 +- .../well}/well_branch_collection.h | 4 +- .../well}/well_branch_collection.hpp | 2 +- .../ecl_well => resdata/well}/well_conn.h | 4 +- .../ecl_well => resdata/well}/well_conn.hpp | 14 +- .../well}/well_conn_collection.h | 4 +- .../well}/well_conn_collection.hpp | 14 +- .../ecl_well => resdata/well}/well_const.h | 4 +- .../ecl_well => resdata/well}/well_const.hpp | 10 +- .../ecl_well => resdata/well}/well_info.h | 4 +- .../ecl_well => resdata/well}/well_info.hpp | 20 +- .../well}/well_rseg_loader.h | 4 +- .../well}/well_rseg_loader.hpp | 4 +- .../ecl_well => resdata/well}/well_segment.h | 4 +- .../well}/well_segment.hpp | 18 +- .../well}/well_segment_collection.h | 4 +- .../well}/well_segment_collection.hpp | 14 +- .../ecl_well => resdata/well}/well_state.h | 4 +- .../ecl_well => resdata/well}/well_state.hpp | 36 +- .../{ert/ecl_well => resdata/well}/well_ts.h | 4 +- .../ecl_well => resdata/well}/well_ts.hpp | 2 +- .../detail/{ecl => resdata}/layer_cxx.hpp | 2 +- .../rd_grid_cache.hpp} | 16 +- .../rd_sum_file_data.hpp} | 36 +- .../rd_unsmry_loader.hpp} | 14 +- lib/private-include/detail/util/path.hpp | 4 +- .../detail/util/string_util.hpp | 8 +- lib/{ecl => resdata}/FortIO.cpp | 2 +- lib/resdata/RDFilename.cpp | 67 + lib/{ecl => resdata}/fault_block.cpp | 38 +- lib/{ecl => resdata}/fault_block_layer.cpp | 73 +- lib/{ecl => resdata}/fortio.c | 2 +- lib/{ecl => resdata}/grid_dims.cpp | 2 +- lib/{ecl => resdata}/layer.cpp | 10 +- lib/{ecl => resdata}/nnc_info.cpp | 6 +- lib/{ecl => resdata}/nnc_vector.cpp | 2 +- lib/{ecl/ecl_box.cpp => resdata/rd_box.cpp} | 18 +- .../rd_coarse_cell.cpp} | 108 +- lib/resdata/rd_file.cpp | 999 +++++ lib/resdata/rd_file_kw.cpp | 422 ++ lib/resdata/rd_file_view.cpp | 840 ++++ lib/resdata/rd_grav.cpp | 690 +++ .../rd_grav_common.cpp} | 66 +- lib/{ecl/ecl_grid.cpp => resdata/rd_grid.cpp} | 3734 ++++++++--------- lib/resdata/rd_grid_cache.cpp | 45 + lib/resdata/rd_grid_dims.cpp | 129 + lib/resdata/rd_init_file.cpp | 217 + .../rd_io_config.cpp} | 53 +- lib/resdata/rd_kw.cpp | 2842 +++++++++++++ .../rd_kw_functions.cpp} | 46 +- .../rd_kw_grdecl.cpp} | 150 +- lib/resdata/rd_nnc_data.cpp | 270 ++ lib/resdata/rd_nnc_export.cpp | 288 ++ .../rd_nnc_geometry.cpp} | 62 +- lib/resdata/rd_region.cpp | 1528 +++++++ .../rd_rft_cell.cpp} | 150 +- .../rd_rft_file.cpp} | 213 +- lib/resdata/rd_rft_node.cpp | 608 +++ lib/resdata/rd_rst_file.cpp | 276 ++ .../rd_rsthead.cpp} | 96 +- lib/resdata/rd_smspec.cpp | 1794 ++++++++ lib/resdata/rd_subsidence.cpp | 339 ++ lib/resdata/rd_sum.cpp | 1526 +++++++ .../rd_sum_data.cpp} | 644 ++- .../rd_sum_file_data.cpp} | 281 +- .../rd_sum_index.cpp} | 12 +- lib/resdata/rd_sum_tstep.cpp | 333 ++ lib/resdata/rd_sum_vector.cpp | 145 + lib/resdata/rd_type.cpp | 184 + lib/resdata/rd_type_python.cpp | 118 + .../rd_unsmry_loader.cpp} | 79 +- lib/{ecl/ecl_util.cpp => resdata/rd_util.cpp} | 565 ++- lib/{ecl => resdata}/smspec_node.cpp | 458 +- lib/{ecl => resdata}/tests/data/num_cpu1 | 0 lib/{ecl => resdata}/tests/data/num_cpu2 | 0 lib/{ecl => resdata}/tests/data/num_cpu3 | 0 lib/{ecl => resdata}/tests/data/num_cpu4 | 0 lib/{ecl => resdata}/tests/data/num_cpu5 | 0 lib/resdata/tests/rd_coarse_test.cpp | 88 + lib/resdata/tests/rd_dualp.cpp | 69 + .../rd_fault_block_collection_equinor.cpp} | 35 +- .../tests/rd_fault_block_layer.cpp} | 113 +- .../tests/rd_fault_block_layer_equinor.cpp} | 26 +- lib/resdata/tests/rd_file.cpp | 107 + lib/resdata/tests/rd_file_equinor.cpp | 123 + lib/resdata/tests/rd_file_view.cpp | 102 + .../tests/rd_filenames.cpp} | 60 +- .../ecl_fmt.cpp => resdata/tests/rd_fmt.cpp} | 20 +- .../tests/rd_fortio.cpp} | 32 +- lib/resdata/tests/rd_get_num_cpu_test.cpp | 20 + lib/resdata/tests/rd_grid_add_nnc.cpp | 119 + lib/resdata/tests/rd_grid_cell_contains.cpp | 279 ++ .../tests/rd_grid_cell_contains_wellpath.cpp} | 36 +- lib/resdata/tests/rd_grid_copy.cpp | 34 + .../tests/rd_grid_corner.cpp} | 26 +- .../tests/rd_grid_create.cpp} | 30 +- .../tests/rd_grid_dims.cpp} | 22 +- lib/resdata/tests/rd_grid_dx_dy_dz.cpp | 56 + lib/resdata/tests/rd_grid_export.cpp | 176 + lib/resdata/tests/rd_grid_ext_actnum.cpp | 59 + lib/resdata/tests/rd_grid_init_fwrite.cpp | 85 + lib/resdata/tests/rd_grid_layer_contains.cpp | 31 + .../tests/rd_grid_lgr_name.cpp} | 12 +- lib/resdata/tests/rd_grid_reset_actnum.cpp | 45 + lib/resdata/tests/rd_grid_unit_system.cpp | 38 + lib/resdata/tests/rd_grid_volume.cpp | 75 + lib/resdata/tests/rd_init_file.cpp | 79 + lib/resdata/tests/rd_kw_cmp_string.cpp | 29 + lib/resdata/tests/rd_kw_equal.cpp | 49 + lib/resdata/tests/rd_kw_fread.cpp | 110 + lib/resdata/tests/rd_kw_grdecl.cpp | 57 + .../tests/rd_kw_init.cpp} | 30 +- .../tests/rd_kw_space_pad.cpp} | 12 +- .../tests/rd_layer.cpp} | 4 +- .../tests/rd_layer_equinor.cpp} | 38 +- .../ecl_lfs.cpp => resdata/tests/rd_lfs.cpp} | 38 +- lib/resdata/tests/rd_lgr_name.cpp | 28 + lib/resdata/tests/rd_lgr_test.cpp | 25 + .../tests/rd_make_date_no_shift.cpp} | 6 +- .../tests/rd_make_date_shift.cpp} | 6 +- .../tests/rd_month_range.cpp} | 6 +- .../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 + .../tests/rd_nnc_index_list.cpp} | 2 +- lib/resdata/tests/rd_nnc_index_list_grid.cpp | 45 + .../tests/rd_nnc_info_test.cpp} | 8 +- .../tests/rd_nnc_pair.cpp} | 8 +- lib/resdata/tests/rd_nnc_test.cpp | 133 + .../tests/rd_nnc_vector.cpp} | 2 +- lib/resdata/tests/rd_path_access.cpp | 31 + lib/resdata/tests/rd_region.cpp | 49 + lib/resdata/tests/rd_region2region.cpp | 53 + .../tests/rd_restart_test.cpp} | 10 +- lib/resdata/tests/rd_rft.cpp | 162 + lib/resdata/tests/rd_rft_cell.cpp | 138 + lib/resdata/tests/rd_rst_file.cpp | 145 + .../tests/rd_rsthead.cpp} | 46 +- lib/resdata/tests/rd_smspec.cpp | 35 + .../tests/rd_smspec_node.cpp} | 161 +- .../tests/rd_sum_alloc_resampled_test.cpp | 138 + .../tests/rd_sum_case_exists.cpp} | 12 +- .../tests/rd_sum_data_intermediate_test.cpp} | 223 +- .../tests/rd_sum_report_step_compatible.cpp | 31 + .../tests/rd_sum_report_step_equal.cpp | 30 + .../tests/rd_sum_restart.cpp} | 89 +- lib/resdata/tests/rd_sum_test.cpp | 51 + lib/resdata/tests/rd_sum_writer.cpp | 246 ++ lib/resdata/tests/rd_unsmry_loader_test.cpp | 63 + lib/resdata/tests/rd_valid_basename.cpp | 17 + lib/resdata/tests/rdxx_filename.cpp | 49 + .../tests/rdxx_fortio.cpp} | 14 +- .../tests/rdxx_kw.cpp} | 70 +- lib/resdata/tests/rdxx_types.cpp | 37 + lib/{ecl => resdata}/tests/rft_test.cpp | 37 +- lib/resdata/tests/test_rd_file_index.cpp | 91 + lib/resdata/tests/test_rd_nnc_data.cpp | 81 + lib/resdata/tests/test_transactions.cpp | 97 + .../tests/well_branch_collection.cpp | 8 +- lib/{ecl => resdata}/tests/well_conn.cpp | 6 +- lib/{ecl => resdata}/tests/well_conn_CF.cpp | 42 +- .../tests/well_conn_collection.cpp | 6 +- lib/{ecl => resdata}/tests/well_conn_load.cpp | 32 +- lib/{ecl => resdata}/tests/well_dualp.cpp | 23 +- lib/{ecl => resdata}/tests/well_info.cpp | 10 +- lib/{ecl => resdata}/tests/well_lgr_load.cpp | 18 +- lib/{ecl => resdata}/tests/well_segment.cpp | 6 +- .../tests/well_segment_branch_conn_load.cpp | 44 +- .../tests/well_segment_collection.cpp | 6 +- .../tests/well_segment_conn.cpp | 20 +- .../tests/well_segment_conn_load.cpp | 36 +- .../tests/well_segment_load.cpp | 36 +- lib/{ecl => resdata}/tests/well_state.cpp | 26 +- .../tests/well_state_load.cpp | 28 +- .../tests/well_state_load_missing_RSEG.cpp | 24 +- lib/{ecl => resdata}/tests/well_ts.cpp | 13 +- .../well_branch_collection.cpp | 6 +- lib/{ecl => resdata}/well_conn.cpp | 51 +- lib/{ecl => resdata}/well_conn_collection.cpp | 22 +- lib/{ecl => resdata}/well_info.cpp | 113 +- lib/{ecl => resdata}/well_rseg_loader.cpp | 24 +- lib/{ecl => resdata}/well_segment.cpp | 33 +- .../well_segment_collection.cpp | 23 +- lib/{ecl => resdata}/well_state.cpp | 265 +- lib/{ecl => resdata}/well_ts.cpp | 6 +- .../{test_ecl_grid.cpp => test_rd_grid.cpp} | 157 +- .../{test_ecl_util.cpp => test_rd_util.cpp} | 12 +- lib/tests/tmpdir.hpp | 2 +- lib/util/cxx_string_util.cpp | 4 +- lib/util/ecl_version.cpp | 39 - lib/util/path.cpp | 4 +- lib/util/rd_version.cpp | 39 + lib/util/test_work_area.cpp | 10 +- lib/util/tests/ert_util_chdir.cpp | 2 +- lib/util/tests/ert_util_copy_file.cpp | 2 +- lib/util/tests/ert_util_mkdir_p.cpp | 2 +- lib/util/tests/ert_util_normal_path.cpp | 4 +- lib/util/tests/ert_util_spawn.cpp | 6 +- lib/util/tests/ert_util_split_path.cpp | 2 +- lib/util/tests/ert_util_stringlist_test.cpp | 2 +- lib/util/tests/test_area.cpp | 2 +- lib/util/util.cpp | 2 +- lib/util/util_endian.cpp | 2 +- python/docs/CMakeLists.txt | 10 +- python/docs/code/python/index.rst | 464 +- python/docs/conf.py.in | 14 +- python/docs/examples/avg_pressure.py | 17 +- python/docs/examples/cmp_nnc.py | 10 +- python/docs/examples/grid_info.py | 6 +- python/ecl/ecl_lib_info_build.py.in | 9 - python/ecl/ecl_lib_info_install.py.in | 9 - python/ecl/ecl_type.py | 184 - python/ecl/ecl_util.py | 164 - python/ecl/eclfile/__init__.py | 29 - python/ecl/eclfile/ecl_init_file.py | 15 - python/ecl/gravimetry/__init__.py | 11 - python/ecl/grid/__init__.py | 19 - python/ecl/rft/__init__.py | 8 - python/ecl/summary/__init__.py | 18 - python/ecl/summary/ecl_sum_keyword_vector.py | 61 - python/ecl/summary/ecl_sum_var_type.py | 37 - python/ecl/util/geometry/geo_pointset.py | 66 - python/ecl/util/test/ecl_mock/__init__.py | 1 - python/ecl/util/util/double_vector.py | 95 - python/ecl/util/util/install_abort_signals.py | 18 - python/ecl/util/util/int_vector.py | 120 - .../well/well_connection_direction_enum.py | 17 - python/ecl/well/well_type_enum.py | 17 - python/{ecl => resdata}/__init__.py | 113 +- python/{ecl => resdata}/bin.py | 0 .../util => resdata}/geometry/__init__.py | 2 +- .../util => resdata}/geometry/cpolyline.py | 30 +- .../geometry/cpolyline_collection.py | 20 +- python/resdata/geometry/geo_pointset.py | 66 + .../util => resdata}/geometry/geo_region.py | 28 +- .../geometry/geometry_tools.py | 0 .../util => resdata}/geometry/polyline.py | 0 .../{ecl/util => resdata}/geometry/surface.py | 48 +- .../{ecl/util => resdata}/geometry/xyz_io.py | 0 python/resdata/gravimetry/__init__.py | 11 + .../gravimetry/rd_grav.py} | 106 +- .../gravimetry/rd_subsidence.py} | 72 +- python/resdata/grid/__init__.py | 19 + python/{ecl => resdata}/grid/cell.py | 0 .../{ecl => resdata}/grid/faults/__init__.py | 0 python/{ecl => resdata}/grid/faults/fault.py | 4 +- .../grid/faults/fault_block.py | 32 +- .../grid/faults/fault_block_collection.py | 18 +- .../grid/faults/fault_block_layer.py | 52 +- .../grid/faults/fault_collection.py | 6 +- .../grid/faults/fault_line.py | 6 +- .../grid/faults/fault_segments.py | 2 +- python/{ecl => resdata}/grid/faults/layer.py | 54 +- .../ecl_grid.py => resdata/grid/rd_grid.py} | 470 ++- .../grid/rd_grid_generator.py} | 48 +- .../grid/rd_region.py} | 574 +-- python/resdata/rd_type.py | 184 + python/resdata/rd_util.py | 165 + python/resdata/resdata_info_build.py.in | 9 + python/resdata/resdata_info_install.py.in | 9 + python/resdata/resfile/__init__.py | 29 + .../eclfile => resdata/resfile}/fortio.py | 34 +- .../resfile/rd_3d_file.py} | 12 +- .../resfile/rd_3dkw.py} | 94 +- .../resfile/rd_file.py} | 292 +- .../resfile/rd_file_view.py} | 68 +- python/resdata/resfile/rd_init_file.py | 13 + .../ecl_kw.py => resdata/resfile/rd_kw.py} | 406 +- .../resfile/rd_restart_file.py} | 77 +- python/resdata/rft/__init__.py | 8 + .../rft/ecl_rft.py => resdata/rft/rd_rft.py} | 130 +- .../rft/rd_rft_cell.py} | 70 +- .../{ecl => resdata}/rft/well_trajectory.py | 0 python/resdata/summary/__init__.py | 18 + .../ecl_cmp.py => resdata/summary/rd_cmp.py} | 36 +- .../ecl_npv.py => resdata/summary/rd_npv.py} | 22 +- .../summary/rd_smspec_node.py} | 60 +- .../ecl_sum.py => resdata/summary/rd_sum.py} | 388 +- .../resdata/summary/rd_sum_keyword_vector.py | 63 + .../summary/rd_sum_node.py} | 14 +- .../summary/rd_sum_tstep.py} | 44 +- python/resdata/summary/rd_sum_var_type.py | 37 + .../summary/rd_sum_vector.py} | 38 +- python/{ecl => resdata}/util/__init__.py | 0 .../{ecl => resdata}/util/enums/__init__.py | 0 .../util/enums/rng_alg_type_enum.py | 0 .../util/enums/rng_init_mode_enum.py | 0 python/{ecl => resdata}/util/test/__init__.py | 2 +- .../{ecl => resdata}/util/test/debug_msg.py | 0 .../util/test/ert_test_context.py | 0 .../util/test/extended_testcase.py | 4 +- .../util/test/import_test_case.py | 0 .../util/test/lint_test_case.py | 0 python/resdata/util/test/mock/__init__.py | 1 + .../util/test/mock/rd_sum_mock.py} | 16 +- .../util/test/path_context.py | 0 .../util/test/resdata_test_runner.py} | 12 +- .../util/test/source_enumerator.py | 0 .../{ecl => resdata}/util/test/test_area.py | 22 +- python/{ecl => resdata}/util/test/test_run.py | 0 python/{ecl => resdata}/util/util/__init__.py | 22 +- python/{ecl => resdata}/util/util/arg_pack.py | 14 +- .../{ecl => resdata}/util/util/bool_vector.py | 110 +- .../util/util/cthread_pool.py | 10 +- python/{ecl => resdata}/util/util/ctime.py | 6 +- .../{ecl => resdata}/util/util/cwd_context.py | 0 python/resdata/util/util/double_vector.py | 105 + python/{ecl => resdata}/util/util/hash.py | 30 +- .../util/util/install_abort_signals.py | 18 + python/resdata/util/util/int_vector.py | 130 + .../util/util/lookup_table.py | 32 +- .../util/util/permutation_vector.py | 8 +- python/{ecl => resdata}/util/util/rng.py | 24 +- .../{ecl => resdata}/util/util/stringlist.py | 32 +- .../{ecl => resdata}/util/util/thread_pool.py | 0 .../{ecl => resdata}/util/util/time_vector.py | 112 +- .../{ecl => resdata}/util/util/util_func.py | 6 +- .../util/util/vector_template.py | 2 +- python/{ecl => resdata}/util/util/version.py | 24 +- python/{ecl => resdata}/well/__init__.py | 10 +- .../{ecl => resdata}/well/well_connection.py | 52 +- .../well/well_connection_direction_enum.py | 17 + python/{ecl => resdata}/well/well_info.py | 40 +- python/{ecl => resdata}/well/well_segment.py | 28 +- python/{ecl => resdata}/well/well_state.py | 66 +- .../{ecl => resdata}/well/well_time_line.py | 10 +- python/resdata/well/well_type_enum.py | 17 + python/tests/__init__.py | 14 +- .../tests/bin_tests/test_summary_resample.py | 18 +- python/tests/ecl_tests/test_deprecation.py | 38 - python/tests/ecl_tests/test_ecl_cmp.py | 49 - python/tests/ecl_tests/test_ecl_init_file.py | 29 - python/tests/ecl_tests/test_ecl_type.py | 139 - python/tests/ecl_tests/test_ecl_util.py | 27 - python/tests/ecl_tests/test_grav.py | 24 - python/tests/ecl_tests/test_grdecl_equinor.py | 107 - python/tests/ecl_tests/test_rft.py | 19 - .../tests/geometry_tests/test_convex_hull.py | 6 +- python/tests/geometry_tests/test_cpolyline.py | 10 +- .../test_cpolyline_collection.py | 12 +- .../tests/geometry_tests/test_geo_pointset.py | 8 +- .../tests/geometry_tests/test_geo_region.py | 8 +- .../geometry_tests/test_geometry_tools.py | 10 +- .../tests/geometry_tests/test_intersection.py | 6 +- .../geometry_tests/test_point_in_polygon.py | 8 +- .../geometry_tests/test_polygon_slicing.py | 6 +- python/tests/geometry_tests/test_polyline.py | 10 +- python/tests/geometry_tests/test_surface.py | 8 +- python/tests/global_tests/test_pylint.py | 12 +- .../tests/{ecl_tests => rd_tests}/__init__.py | 0 .../{ecl_tests => rd_tests}/test_cell.py | 8 +- .../{ecl_tests => rd_tests}/test_debug.py | 6 +- python/tests/rd_tests/test_deprecation.py | 38 + .../test_equinor_faults.py | 24 +- .../test_fault_blocks.py | 60 +- .../test_fault_blocks_equinor.py | 18 +- .../{ecl_tests => rd_tests}/test_faults.py | 48 +- .../test_fk_user_data.py | 10 +- .../{ecl_tests => rd_tests}/test_fortio.py | 30 +- .../{ecl_tests => rd_tests}/test_geertsma.py | 66 +- python/tests/rd_tests/test_grav.py | 24 + .../{ecl_tests => rd_tests}/test_grdecl.py | 4 +- python/tests/rd_tests/test_grdrd_equinor.py | 107 + .../{ecl_tests => rd_tests}/test_grid.py | 60 +- .../test_grid_equinor.py | 83 +- .../test_grid_equinor_coarse.py | 18 +- .../test_grid_equinor_dual.py | 20 +- .../test_grid_generator.py | 32 +- .../test_grid_large_case.py | 4 +- .../test_grid_pandas.py | 26 +- .../test_indexed_read.py | 71 +- .../test_kw_function.py | 22 +- .../{ecl_tests => rd_tests}/test_layer.py | 28 +- .../tests/{ecl_tests => rd_tests}/test_npv.py | 26 +- .../test_rd_3dkw.py} | 68 +- python/tests/rd_tests/test_rd_cmp.py | 49 + .../test_rd_file.py} | 146 +- .../test_rd_file_equinor.py} | 66 +- python/tests/rd_tests/test_rd_init_file.py | 29 + .../test_ecl_kw.py => rd_tests/test_rd_kw.py} | 218 +- .../test_rd_kw_equinor.py} | 24 +- .../test_rd_restart_file.py} | 40 +- .../test_rd_sum.py} | 70 +- .../test_rd_sum_vector.py} | 24 +- python/tests/rd_tests/test_rd_type.py | 141 + python/tests/rd_tests/test_rd_util.py | 20 + .../{ecl_tests => rd_tests}/test_region.py | 42 +- .../test_region_equinor.py | 42 +- .../{ecl_tests => rd_tests}/test_removed.py | 18 +- .../{ecl_tests => rd_tests}/test_restart.py | 42 +- .../test_restart_head.py | 20 +- python/tests/rd_tests/test_rft.py | 25 + .../{ecl_tests => rd_tests}/test_rft_cell.py | 15 +- .../test_rft_equinor.py | 20 +- .../tests/{ecl_tests => rd_tests}/test_sum.py | 184 +- .../test_sum_equinor.py | 150 +- python/tests/test_bin.py | 4 +- python/tests/util_tests/test_ctime.py | 2 +- python/tests/util_tests/test_hash.py | 6 +- python/tests/util_tests/test_lookup_table.py | 2 +- python/tests/util_tests/test_path_context.py | 6 +- python/tests/util_tests/test_rng.py | 10 +- python/tests/util_tests/test_spawn.py | 12 +- python/tests/util_tests/test_string_list.py | 2 +- python/tests/util_tests/test_thread_pool.py | 8 +- python/tests/util_tests/test_vectors.py | 2 +- python/tests/util_tests/test_version.py | 16 +- python/tests/util_tests/test_work_area.py | 6 +- .../{test_ecl_well.py => test_rd_well.py} | 105 +- .../{test_ecl_well2.py => test_rd_well2.py} | 24 +- .../{test_ecl_well3.py => test_rd_well3.py} | 22 +- .../well_tests/test_well_missing_ICON.py | 14 +- release-notes.txt | 2 +- setup.py | 28 +- 694 files changed, 32068 insertions(+), 32445 deletions(-) rename applications/man/man1/{ecl_summary.1 => rd_summary.1} (72%) rename applications/{ecl => resdata}/convert.c (72%) rename applications/{ecl => resdata}/grdecl_grid.c (50%) rename applications/{ecl => resdata}/grdecl_test.c (81%) rename applications/{ecl => resdata}/grid_dump.c (86%) rename applications/{ecl => resdata}/grid_dump_ascii.c (85%) rename applications/{ecl => resdata}/grid_info.c (69%) rename applications/{ecl => resdata}/kw_extract.cpp (64%) rename applications/{ecl => resdata}/kw_list.c (76%) rename applications/{ecl => resdata}/load_test.c (68%) rename applications/{ecl => resdata}/make_grid.c (85%) rename applications/{ecl/ecl_pack.c => resdata/rd_pack.c} (58%) rename applications/{ecl/ecl_unpack.c => resdata/rd_unpack.c} (50%) rename applications/{ecl => resdata}/select_test.c (91%) rename applications/{ecl => resdata}/sum_write.cpp (78%) rename applications/{ecl => resdata}/view_summary.cpp (84%) rename cmake/{libecl-config-version.cmake.in => resdata-config-version.cmake.in} (70%) rename cmake/{libecl-config.cmake.in => resdata-config.cmake.in} (54%) delete mode 100644 lib/ecl/EclFilename.cpp delete mode 100644 lib/ecl/ecl_file.cpp delete mode 100644 lib/ecl/ecl_file_kw.cpp delete mode 100644 lib/ecl/ecl_file_view.cpp delete mode 100644 lib/ecl/ecl_grav.cpp delete mode 100644 lib/ecl/ecl_grid_cache.cpp delete mode 100644 lib/ecl/ecl_grid_dims.cpp delete mode 100644 lib/ecl/ecl_init_file.cpp delete mode 100644 lib/ecl/ecl_kw.cpp delete mode 100644 lib/ecl/ecl_nnc_data.cpp delete mode 100644 lib/ecl/ecl_nnc_export.cpp delete mode 100644 lib/ecl/ecl_region.cpp delete mode 100644 lib/ecl/ecl_rft_node.cpp delete mode 100644 lib/ecl/ecl_rst_file.cpp delete mode 100644 lib/ecl/ecl_smspec.cpp delete mode 100644 lib/ecl/ecl_subsidence.cpp delete mode 100644 lib/ecl/ecl_sum.cpp delete mode 100644 lib/ecl/ecl_sum_tstep.cpp delete mode 100644 lib/ecl/ecl_sum_vector.cpp delete mode 100644 lib/ecl/ecl_type.cpp delete mode 100644 lib/ecl/ecl_type_python.cpp delete mode 100644 lib/ecl/readme.overview delete mode 100644 lib/ecl/tests/ecl_coarse_test.cpp delete mode 100644 lib/ecl/tests/ecl_dualp.cpp delete mode 100644 lib/ecl/tests/ecl_file.cpp delete mode 100644 lib/ecl/tests/ecl_file_equinor.cpp delete mode 100644 lib/ecl/tests/ecl_file_view.cpp delete mode 100644 lib/ecl/tests/ecl_get_num_cpu_test.cpp delete mode 100644 lib/ecl/tests/ecl_grid_add_nnc.cpp delete mode 100644 lib/ecl/tests/ecl_grid_cell_contains.cpp delete mode 100644 lib/ecl/tests/ecl_grid_copy.cpp delete mode 100644 lib/ecl/tests/ecl_grid_dx_dy_dz.cpp delete mode 100644 lib/ecl/tests/ecl_grid_export.cpp delete mode 100644 lib/ecl/tests/ecl_grid_ext_actnum.cpp delete mode 100644 lib/ecl/tests/ecl_grid_init_fwrite.cpp delete mode 100644 lib/ecl/tests/ecl_grid_layer_contains.cpp delete mode 100644 lib/ecl/tests/ecl_grid_reset_actnum.cpp delete mode 100644 lib/ecl/tests/ecl_grid_unit_system.cpp delete mode 100644 lib/ecl/tests/ecl_grid_volume.cpp delete mode 100644 lib/ecl/tests/ecl_init_file.cpp delete mode 100644 lib/ecl/tests/ecl_kw_cmp_string.cpp delete mode 100644 lib/ecl/tests/ecl_kw_equal.cpp delete mode 100644 lib/ecl/tests/ecl_kw_fread.cpp delete mode 100644 lib/ecl/tests/ecl_kw_grdecl.cpp delete mode 100644 lib/ecl/tests/ecl_lgr_name.cpp delete mode 100644 lib/ecl/tests/ecl_lgr_test.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_data_equinor_root.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_export.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_export_get_tran.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_export_intersect.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_geometry.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_index_list_grid.cpp delete mode 100644 lib/ecl/tests/ecl_nnc_test.cpp delete mode 100644 lib/ecl/tests/ecl_region.cpp delete mode 100644 lib/ecl/tests/ecl_region2region.cpp delete mode 100644 lib/ecl/tests/ecl_rft.cpp delete mode 100644 lib/ecl/tests/ecl_rft_cell.cpp delete mode 100644 lib/ecl/tests/ecl_rst_file.cpp delete mode 100644 lib/ecl/tests/ecl_smspec.cpp delete mode 100644 lib/ecl/tests/ecl_sum_alloc_resampled_test.cpp delete mode 100644 lib/ecl/tests/ecl_sum_report_step_compatible.cpp delete mode 100644 lib/ecl/tests/ecl_sum_report_step_equal.cpp delete mode 100644 lib/ecl/tests/ecl_sum_test.cpp delete mode 100644 lib/ecl/tests/ecl_sum_writer.cpp delete mode 100644 lib/ecl/tests/ecl_unsmry_loader_test.cpp delete mode 100644 lib/ecl/tests/ecl_util_path_access.cpp delete mode 100644 lib/ecl/tests/ecl_valid_basename.cpp delete mode 100644 lib/ecl/tests/eclxx_filename.cpp delete mode 100644 lib/ecl/tests/eclxx_types.cpp delete mode 100644 lib/ecl/tests/test_ecl_file_index.cpp delete mode 100644 lib/ecl/tests/test_ecl_nnc_data.cpp delete mode 100644 lib/ecl/tests/test_transactions.cpp delete mode 100644 lib/include/ert/ecl/EclFilename.hpp delete mode 100644 lib/include/ert/ecl/EclKW.hpp delete mode 100644 lib/include/ert/ecl/ecl_box.hpp delete mode 100644 lib/include/ert/ecl/ecl_coarse_cell.hpp delete mode 100644 lib/include/ert/ecl/ecl_endian_flip.hpp delete mode 100644 lib/include/ert/ecl/ecl_file.hpp delete mode 100644 lib/include/ert/ecl/ecl_file_kw.hpp delete mode 100644 lib/include/ert/ecl/ecl_file_view.hpp delete mode 100644 lib/include/ert/ecl/ecl_grav.hpp delete mode 100644 lib/include/ert/ecl/ecl_grav_common.h delete mode 100644 lib/include/ert/ecl/ecl_grav_common.hpp delete mode 100644 lib/include/ert/ecl/ecl_grid.hpp delete mode 100644 lib/include/ert/ecl/ecl_grid_dims.h delete mode 100644 lib/include/ert/ecl/ecl_grid_dims.hpp delete mode 100644 lib/include/ert/ecl/ecl_init_file.h delete mode 100644 lib/include/ert/ecl/ecl_init_file.hpp delete mode 100644 lib/include/ert/ecl/ecl_io_config.h delete mode 100644 lib/include/ert/ecl/ecl_io_config.hpp delete mode 100644 lib/include/ert/ecl/ecl_kw.hpp delete mode 100644 lib/include/ert/ecl/ecl_kw_grdecl.h delete mode 100644 lib/include/ert/ecl/ecl_kw_grdecl.hpp delete mode 100644 lib/include/ert/ecl/ecl_kw_magic.h delete mode 100644 lib/include/ert/ecl/ecl_nnc_data.h delete mode 100644 lib/include/ert/ecl/ecl_nnc_data.hpp delete mode 100644 lib/include/ert/ecl/ecl_nnc_export.h delete mode 100644 lib/include/ert/ecl/ecl_nnc_export.hpp delete mode 100644 lib/include/ert/ecl/ecl_nnc_geometry.h delete mode 100644 lib/include/ert/ecl/ecl_nnc_geometry.hpp delete mode 100644 lib/include/ert/ecl/ecl_region.h delete mode 100644 lib/include/ert/ecl/ecl_region.hpp delete mode 100644 lib/include/ert/ecl/ecl_rft_cell.h delete mode 100644 lib/include/ert/ecl/ecl_rft_cell.hpp delete mode 100644 lib/include/ert/ecl/ecl_rft_file.h delete mode 100644 lib/include/ert/ecl/ecl_rft_file.hpp delete mode 100644 lib/include/ert/ecl/ecl_rft_node.h delete mode 100644 lib/include/ert/ecl/ecl_rft_node.hpp delete mode 100644 lib/include/ert/ecl/ecl_rst_file.h delete mode 100644 lib/include/ert/ecl/ecl_rst_file.hpp delete mode 100644 lib/include/ert/ecl/ecl_rsthead.h delete mode 100644 lib/include/ert/ecl/ecl_smspec.h delete mode 100644 lib/include/ert/ecl/ecl_smspec.hpp delete mode 100644 lib/include/ert/ecl/ecl_subsidence.h delete mode 100644 lib/include/ert/ecl/ecl_subsidence.hpp delete mode 100644 lib/include/ert/ecl/ecl_sum.hpp delete mode 100644 lib/include/ert/ecl/ecl_sum_data.h delete mode 100644 lib/include/ert/ecl/ecl_sum_data.hpp delete mode 100644 lib/include/ert/ecl/ecl_sum_index.h delete mode 100644 lib/include/ert/ecl/ecl_sum_index.hpp delete mode 100644 lib/include/ert/ecl/ecl_sum_tstep.h delete mode 100644 lib/include/ert/ecl/ecl_sum_tstep.hpp delete mode 100644 lib/include/ert/ecl/ecl_sum_vector.h delete mode 100644 lib/include/ert/ecl/ecl_sum_vector.hpp delete mode 100644 lib/include/ert/ecl/ecl_type.h delete mode 100644 lib/include/ert/ecl/ecl_type.hpp delete mode 100644 lib/include/ert/ecl/ecl_units.h delete mode 100644 lib/include/ert/ecl/ecl_units.hpp delete mode 100644 lib/include/ert/ecl/ecl_util.h delete mode 100644 lib/include/ert/ecl/ecl_util.hpp delete mode 100644 lib/include/ert/util/ecl_version.h delete mode 100644 lib/include/ert/util/ecl_version.hpp create mode 100644 lib/include/ert/util/rd_version.h create mode 100644 lib/include/ert/util/rd_version.hpp rename lib/include/{ert/ecl => resdata}/FortIO.hpp (71%) create mode 100644 lib/include/resdata/RDFilename.hpp create mode 100644 lib/include/resdata/ResdataKW.hpp rename lib/include/{ert/ecl => resdata}/fault_block.h (57%) rename lib/include/{ert/ecl => resdata}/fault_block.hpp (97%) rename lib/include/{ert/ecl => resdata}/fault_block_layer.h (56%) rename lib/include/{ert/ecl => resdata}/fault_block_layer.hpp (82%) rename lib/include/{ert/ecl => resdata}/fortio.h (100%) rename lib/include/{ert/ecl => resdata}/grid_dims.h (57%) rename lib/include/{ert/ecl => resdata}/grid_dims.hpp (100%) rename lib/include/{ert/ecl => resdata}/layer.h (58%) rename lib/include/{ert/ecl => resdata}/layer.hpp (96%) rename lib/include/{ert/ecl => resdata}/nnc_info.h (58%) rename lib/include/{ert/ecl => resdata}/nnc_info.hpp (97%) rename lib/include/{ert/ecl => resdata}/nnc_vector.h (57%) rename lib/include/{ert/ecl => resdata}/nnc_vector.hpp (100%) create mode 100644 lib/include/resdata/rd_box.hpp rename lib/include/{ert/ecl/ecl_coarse_cell.h => resdata/rd_coarse_cell.h} (56%) create mode 100644 lib/include/resdata/rd_coarse_cell.hpp rename lib/include/{ert/ecl/ecl_endian_flip.h => resdata/rd_endian_flip.h} (56%) create mode 100644 lib/include/resdata/rd_endian_flip.hpp rename lib/include/{ert/ecl/ecl_file.h => resdata/rd_file.h} (58%) create mode 100644 lib/include/resdata/rd_file.hpp rename lib/include/{ert/ecl/ecl_file_kw.h => resdata/rd_file_kw.h} (57%) create mode 100644 lib/include/resdata/rd_file_kw.hpp rename lib/include/{ert/ecl/ecl_file_view.h => resdata/rd_file_view.h} (57%) create mode 100644 lib/include/resdata/rd_file_view.hpp rename lib/include/{ert/ecl/ecl_grid.h => resdata/rd_grav.h} (58%) create mode 100644 lib/include/resdata/rd_grav.hpp create mode 100644 lib/include/resdata/rd_grav_common.h create mode 100644 lib/include/resdata/rd_grav_common.hpp rename lib/include/{ert/ecl/ecl_grav.h => resdata/rd_grid.h} (58%) create mode 100644 lib/include/resdata/rd_grid.hpp create mode 100644 lib/include/resdata/rd_grid_dims.h create mode 100644 lib/include/resdata/rd_grid_dims.hpp create mode 100644 lib/include/resdata/rd_init_file.h create mode 100644 lib/include/resdata/rd_init_file.hpp create mode 100644 lib/include/resdata/rd_io_config.h create mode 100644 lib/include/resdata/rd_io_config.hpp rename lib/include/{ert/ecl/ecl_kw.h => resdata/rd_kw.h} (58%) create mode 100644 lib/include/resdata/rd_kw.hpp create mode 100644 lib/include/resdata/rd_kw_grdecl.h create mode 100644 lib/include/resdata/rd_kw_grdecl.hpp create mode 100644 lib/include/resdata/rd_kw_magic.h rename lib/include/{ert/ecl/ecl_kw_magic.hpp => resdata/rd_kw_magic.hpp} (99%) create mode 100644 lib/include/resdata/rd_nnc_data.h create mode 100644 lib/include/resdata/rd_nnc_data.hpp create mode 100644 lib/include/resdata/rd_nnc_export.h create mode 100644 lib/include/resdata/rd_nnc_export.hpp create mode 100644 lib/include/resdata/rd_nnc_geometry.h create mode 100644 lib/include/resdata/rd_nnc_geometry.hpp create mode 100644 lib/include/resdata/rd_region.h create mode 100644 lib/include/resdata/rd_region.hpp create mode 100644 lib/include/resdata/rd_rft_cell.h create mode 100644 lib/include/resdata/rd_rft_cell.hpp create mode 100644 lib/include/resdata/rd_rft_file.h create mode 100644 lib/include/resdata/rd_rft_file.hpp create mode 100644 lib/include/resdata/rd_rft_node.h create mode 100644 lib/include/resdata/rd_rft_node.hpp create mode 100644 lib/include/resdata/rd_rst_file.h create mode 100644 lib/include/resdata/rd_rst_file.hpp create mode 100644 lib/include/resdata/rd_rsthead.h rename lib/include/{ert/ecl/ecl_rsthead.hpp => resdata/rd_rsthead.hpp} (57%) create mode 100644 lib/include/resdata/rd_smspec.h create mode 100644 lib/include/resdata/rd_smspec.hpp create mode 100644 lib/include/resdata/rd_subsidence.h create mode 100644 lib/include/resdata/rd_subsidence.hpp rename lib/include/{ert/ecl/ecl_sum.h => resdata/rd_sum.h} (58%) create mode 100644 lib/include/resdata/rd_sum.hpp create mode 100644 lib/include/resdata/rd_sum_data.h create mode 100644 lib/include/resdata/rd_sum_data.hpp create mode 100644 lib/include/resdata/rd_sum_index.h create mode 100644 lib/include/resdata/rd_sum_index.hpp create mode 100644 lib/include/resdata/rd_sum_tstep.h create mode 100644 lib/include/resdata/rd_sum_tstep.hpp create mode 100644 lib/include/resdata/rd_sum_vector.h create mode 100644 lib/include/resdata/rd_sum_vector.hpp create mode 100644 lib/include/resdata/rd_type.h create mode 100644 lib/include/resdata/rd_type.hpp create mode 100644 lib/include/resdata/rd_units.h create mode 100644 lib/include/resdata/rd_units.hpp create mode 100644 lib/include/resdata/rd_util.h create mode 100644 lib/include/resdata/rd_util.hpp rename lib/include/{ert/ecl => resdata}/smspec_node.h (83%) rename lib/include/{ert/ecl => resdata}/smspec_node.hpp (90%) rename lib/include/{ert/ecl_well => resdata/well}/well_branch_collection.h (54%) rename lib/include/{ert/ecl_well => resdata/well}/well_branch_collection.hpp (96%) rename lib/include/{ert/ecl_well => resdata/well}/well_conn.h (56%) rename lib/include/{ert/ecl_well => resdata/well}/well_conn.hpp (85%) rename lib/include/{ert/ecl_well => resdata/well}/well_conn_collection.h (54%) rename lib/include/{ert/ecl_well => resdata/well}/well_conn_collection.hpp (72%) rename lib/include/{ert/ecl_well => resdata/well}/well_const.h (56%) rename lib/include/{ert/ecl_well => resdata/well}/well_const.hpp (96%) rename lib/include/{ert/ecl_well => resdata/well}/well_info.h (56%) rename lib/include/{ert/ecl_well => resdata/well}/well_info.hpp (77%) rename lib/include/{ert/ecl_well => resdata/well}/well_rseg_loader.h (55%) rename lib/include/{ert/ecl_well => resdata/well}/well_rseg_loader.hpp (81%) rename lib/include/{ert/ecl_well => resdata/well}/well_segment.h (56%) rename lib/include/{ert/ecl_well => resdata/well}/well_segment.hpp (83%) rename lib/include/{ert/ecl_well => resdata/well}/well_segment_collection.h (54%) rename lib/include/{ert/ecl_well => resdata/well}/well_segment_collection.hpp (81%) rename lib/include/{ert/ecl_well => resdata/well}/well_state.h (56%) rename lib/include/{ert/ecl_well => resdata/well}/well_state.hpp (76%) rename lib/include/{ert/ecl_well => resdata/well}/well_ts.h (57%) rename lib/include/{ert/ecl_well => resdata/well}/well_ts.hpp (96%) rename lib/private-include/detail/{ecl => resdata}/layer_cxx.hpp (90%) rename lib/private-include/detail/{ecl/ecl_grid_cache.hpp => resdata/rd_grid_cache.hpp} (71%) rename lib/private-include/detail/{ecl/ecl_sum_file_data.hpp => resdata/rd_sum_file_data.hpp} (80%) rename lib/private-include/detail/{ecl/ecl_unsmry_loader.hpp => resdata/rd_unsmry_loader.hpp} (76%) rename lib/{ecl => resdata}/FortIO.cpp (97%) create mode 100644 lib/resdata/RDFilename.cpp rename lib/{ecl => resdata}/fault_block.cpp (90%) rename lib/{ecl => resdata}/fault_block_layer.cpp (80%) rename lib/{ecl => resdata}/fortio.c (99%) rename lib/{ecl => resdata}/grid_dims.cpp (94%) rename lib/{ecl => resdata}/layer.cpp (98%) rename lib/{ecl => resdata}/nnc_info.cpp (98%) rename lib/{ecl => resdata}/nnc_vector.cpp (98%) rename lib/{ecl/ecl_box.cpp => resdata/rd_box.cpp} (61%) rename lib/{ecl/ecl_coarse_cell.cpp => resdata/rd_coarse_cell.cpp} (73%) create mode 100644 lib/resdata/rd_file.cpp create mode 100644 lib/resdata/rd_file_kw.cpp create mode 100644 lib/resdata/rd_file_view.cpp create mode 100644 lib/resdata/rd_grav.cpp rename lib/{ecl/ecl_grav_common.cpp => resdata/rd_grav_common.cpp} (66%) rename lib/{ecl/ecl_grid.cpp => resdata/rd_grid.cpp} (57%) create mode 100644 lib/resdata/rd_grid_cache.cpp create mode 100644 lib/resdata/rd_grid_dims.cpp create mode 100644 lib/resdata/rd_init_file.cpp rename lib/{ecl/ecl_io_config.cpp => resdata/rd_io_config.cpp} (58%) create mode 100644 lib/resdata/rd_kw.cpp rename lib/{ecl/ecl_kw_functions.cpp => resdata/rd_kw_functions.cpp} (76%) rename lib/{ecl/ecl_kw_grdecl.cpp => resdata/rd_kw_grdecl.cpp} (78%) create mode 100644 lib/resdata/rd_nnc_data.cpp create mode 100644 lib/resdata/rd_nnc_export.cpp rename lib/{ecl/ecl_nnc_geometry.cpp => resdata/rd_nnc_geometry.cpp} (55%) create mode 100644 lib/resdata/rd_region.cpp rename lib/{ecl/ecl_rft_cell.cpp => resdata/rd_rft_cell.cpp} (55%) rename lib/{ecl/ecl_rft_file.cpp => resdata/rd_rft_file.cpp} (51%) create mode 100644 lib/resdata/rd_rft_node.cpp create mode 100644 lib/resdata/rd_rst_file.cpp rename lib/{ecl/ecl_rsthead.cpp => resdata/rd_rsthead.cpp} (65%) create mode 100644 lib/resdata/rd_smspec.cpp create mode 100644 lib/resdata/rd_subsidence.cpp create mode 100644 lib/resdata/rd_sum.cpp rename lib/{ecl/ecl_sum_data.cpp => resdata/rd_sum_data.cpp} (59%) rename lib/{ecl/ecl_sum_file_data.cpp => resdata/rd_sum_file_data.cpp} (65%) rename lib/{ecl/ecl_sum_index.cpp => resdata/rd_sum_index.cpp} (72%) create mode 100644 lib/resdata/rd_sum_tstep.cpp create mode 100644 lib/resdata/rd_sum_vector.cpp create mode 100644 lib/resdata/rd_type.cpp create mode 100644 lib/resdata/rd_type_python.cpp rename lib/{ecl/ecl_unsmry_loader.cpp => resdata/rd_unsmry_loader.cpp} (61%) rename lib/{ecl/ecl_util.cpp => resdata/rd_util.cpp} (70%) rename lib/{ecl => resdata}/smspec_node.cpp (75%) rename lib/{ecl => resdata}/tests/data/num_cpu1 (100%) rename lib/{ecl => resdata}/tests/data/num_cpu2 (100%) rename lib/{ecl => resdata}/tests/data/num_cpu3 (100%) rename lib/{ecl => resdata}/tests/data/num_cpu4 (100%) rename lib/{ecl => resdata}/tests/data/num_cpu5 (100%) create mode 100644 lib/resdata/tests/rd_coarse_test.cpp create mode 100644 lib/resdata/tests/rd_dualp.cpp rename lib/{ecl/tests/ecl_fault_block_collection_equinor.cpp => resdata/tests/rd_fault_block_collection_equinor.cpp} (55%) rename lib/{ecl/tests/ecl_fault_block_layer.cpp => resdata/tests/rd_fault_block_layer.cpp} (57%) rename lib/{ecl/tests/ecl_fault_block_layer_equinor.cpp => resdata/tests/rd_fault_block_layer_equinor.cpp} (71%) create mode 100644 lib/resdata/tests/rd_file.cpp create mode 100644 lib/resdata/tests/rd_file_equinor.cpp create mode 100644 lib/resdata/tests/rd_file_view.cpp rename lib/{ecl/tests/ecl_util_filenames.cpp => resdata/tests/rd_filenames.cpp} (58%) rename lib/{ecl/tests/ecl_fmt.cpp => resdata/tests/rd_fmt.cpp} (66%) rename lib/{ecl/tests/ecl_fortio.cpp => resdata/tests/rd_fortio.cpp} (89%) create mode 100644 lib/resdata/tests/rd_get_num_cpu_test.cpp create mode 100644 lib/resdata/tests/rd_grid_add_nnc.cpp create mode 100644 lib/resdata/tests/rd_grid_cell_contains.cpp rename lib/{ecl/tests/ecl_grid_cell_contains_wellpath.cpp => resdata/tests/rd_grid_cell_contains_wellpath.cpp} (62%) create mode 100644 lib/resdata/tests/rd_grid_copy.cpp rename lib/{ecl/tests/ecl_grid_corner.cpp => resdata/tests/rd_grid_corner.cpp} (53%) rename lib/{ecl/tests/ecl_grid_create.cpp => resdata/tests/rd_grid_create.cpp} (76%) rename lib/{ecl/tests/ecl_grid_dims.cpp => resdata/tests/rd_grid_dims.cpp} (67%) create mode 100644 lib/resdata/tests/rd_grid_dx_dy_dz.cpp create mode 100644 lib/resdata/tests/rd_grid_export.cpp create mode 100644 lib/resdata/tests/rd_grid_ext_actnum.cpp create mode 100644 lib/resdata/tests/rd_grid_init_fwrite.cpp create mode 100644 lib/resdata/tests/rd_grid_layer_contains.cpp rename lib/{ecl/tests/ecl_grid_lgr_name.cpp => resdata/tests/rd_grid_lgr_name.cpp} (72%) create mode 100644 lib/resdata/tests/rd_grid_reset_actnum.cpp create mode 100644 lib/resdata/tests/rd_grid_unit_system.cpp create mode 100644 lib/resdata/tests/rd_grid_volume.cpp create mode 100644 lib/resdata/tests/rd_init_file.cpp create mode 100644 lib/resdata/tests/rd_kw_cmp_string.cpp create mode 100644 lib/resdata/tests/rd_kw_equal.cpp create mode 100644 lib/resdata/tests/rd_kw_fread.cpp create mode 100644 lib/resdata/tests/rd_kw_grdecl.cpp rename lib/{ecl/tests/ecl_kw_init.cpp => resdata/tests/rd_kw_init.cpp} (54%) rename lib/{ecl/tests/ecl_kw_space_pad.cpp => resdata/tests/rd_kw_space_pad.cpp} (70%) rename lib/{ecl/tests/ecl_layer.cpp => resdata/tests/rd_layer.cpp} (99%) rename lib/{ecl/tests/ecl_layer_equinor.cpp => resdata/tests/rd_layer_equinor.cpp} (60%) rename lib/{ecl/tests/ecl_lfs.cpp => resdata/tests/rd_lfs.cpp} (61%) create mode 100644 lib/resdata/tests/rd_lgr_name.cpp create mode 100644 lib/resdata/tests/rd_lgr_test.cpp rename lib/{ecl/tests/ecl_util_make_date_no_shift.cpp => resdata/tests/rd_make_date_no_shift.cpp} (79%) rename lib/{ecl/tests/ecl_util_make_date_shift.cpp => resdata/tests/rd_make_date_shift.cpp} (80%) rename lib/{ecl/tests/ecl_util_month_range.cpp => resdata/tests/rd_month_range.cpp} (95%) create mode 100644 lib/resdata/tests/rd_nnc_data_equinor_root.cpp create mode 100644 lib/resdata/tests/rd_nnc_export.cpp create mode 100644 lib/resdata/tests/rd_nnc_export_get_tran.cpp create mode 100644 lib/resdata/tests/rd_nnc_export_intersect.cpp create mode 100644 lib/resdata/tests/rd_nnc_geometry.cpp rename lib/{ecl/tests/ecl_nnc_index_list.cpp => resdata/tests/rd_nnc_index_list.cpp} (98%) create mode 100644 lib/resdata/tests/rd_nnc_index_list_grid.cpp rename lib/{ecl/tests/ecl_nnc_info_test.cpp => resdata/tests/rd_nnc_info_test.cpp} (96%) rename lib/{ecl/tests/ecl_nnc_pair.cpp => resdata/tests/rd_nnc_pair.cpp} (61%) create mode 100644 lib/resdata/tests/rd_nnc_test.cpp rename lib/{ecl/tests/ecl_nnc_vector.cpp => resdata/tests/rd_nnc_vector.cpp} (98%) create mode 100644 lib/resdata/tests/rd_path_access.cpp create mode 100644 lib/resdata/tests/rd_region.cpp create mode 100644 lib/resdata/tests/rd_region2region.cpp rename lib/{ecl/tests/ecl_restart_test.cpp => resdata/tests/rd_restart_test.cpp} (74%) create mode 100644 lib/resdata/tests/rd_rft.cpp create mode 100644 lib/resdata/tests/rd_rft_cell.cpp create mode 100644 lib/resdata/tests/rd_rst_file.cpp rename lib/{ecl/tests/ecl_rsthead.cpp => resdata/tests/rd_rsthead.cpp} (60%) create mode 100644 lib/resdata/tests/rd_smspec.cpp rename lib/{ecl/tests/ecl_smspec_node.cpp => resdata/tests/rd_smspec_node.cpp} (60%) create mode 100644 lib/resdata/tests/rd_sum_alloc_resampled_test.cpp rename lib/{ecl/tests/ecl_sum_case_exists.cpp => resdata/tests/rd_sum_case_exists.cpp} (77%) rename lib/{ecl/tests/ecl_sum_data_intermediate_test.cpp => resdata/tests/rd_sum_data_intermediate_test.cpp} (50%) create mode 100644 lib/resdata/tests/rd_sum_report_step_compatible.cpp create mode 100644 lib/resdata/tests/rd_sum_report_step_equal.cpp rename lib/{ecl/tests/ecl_sum_restart.cpp => resdata/tests/rd_sum_restart.cpp} (59%) create mode 100644 lib/resdata/tests/rd_sum_test.cpp create mode 100644 lib/resdata/tests/rd_sum_writer.cpp create mode 100644 lib/resdata/tests/rd_unsmry_loader_test.cpp create mode 100644 lib/resdata/tests/rd_valid_basename.cpp create mode 100644 lib/resdata/tests/rdxx_filename.cpp rename lib/{ecl/tests/eclxx_fortio.cpp => resdata/tests/rdxx_fortio.cpp} (90%) rename lib/{ecl/tests/eclxx_kw.cpp => resdata/tests/rdxx_kw.cpp} (71%) create mode 100644 lib/resdata/tests/rdxx_types.cpp rename lib/{ecl => resdata}/tests/rft_test.cpp (58%) create mode 100644 lib/resdata/tests/test_rd_file_index.cpp create mode 100644 lib/resdata/tests/test_rd_nnc_data.cpp create mode 100644 lib/resdata/tests/test_transactions.cpp rename lib/{ecl => resdata}/tests/well_branch_collection.cpp (92%) rename lib/{ecl => resdata}/tests/well_conn.cpp (97%) rename lib/{ecl => resdata}/tests/well_conn_CF.cpp (58%) rename lib/{ecl => resdata}/tests/well_conn_collection.cpp (86%) rename lib/{ecl => resdata}/tests/well_conn_load.cpp (79%) rename lib/{ecl => resdata}/tests/well_dualp.cpp (63%) rename lib/{ecl => resdata}/tests/well_info.cpp (74%) rename lib/{ecl => resdata}/tests/well_lgr_load.cpp (79%) rename lib/{ecl => resdata}/tests/well_segment.cpp (97%) rename lib/{ecl => resdata}/tests/well_segment_branch_conn_load.cpp (78%) rename lib/{ecl => resdata}/tests/well_segment_collection.cpp (95%) rename lib/{ecl => resdata}/tests/well_segment_conn.cpp (74%) rename lib/{ecl => resdata}/tests/well_segment_conn_load.cpp (80%) rename lib/{ecl => resdata}/tests/well_segment_load.cpp (76%) rename lib/{ecl => resdata}/tests/well_state.cpp (71%) rename lib/{ecl => resdata}/tests/well_state_load.cpp (75%) rename lib/{ecl => resdata}/tests/well_state_load_missing_RSEG.cpp (68%) rename lib/{ecl => resdata}/tests/well_ts.cpp (85%) rename lib/{ecl => resdata}/well_branch_collection.cpp (96%) rename lib/{ecl => resdata}/well_conn.cpp (84%) rename lib/{ecl => resdata}/well_conn_collection.cpp (82%) rename lib/{ecl => resdata}/well_info.cpp (79%) rename lib/{ecl => resdata}/well_rseg_loader.cpp (76%) rename lib/{ecl => resdata}/well_segment.cpp (89%) rename lib/{ecl => resdata}/well_segment_collection.cpp (91%) rename lib/{ecl => resdata}/well_state.cpp (71%) rename lib/{ecl => resdata}/well_ts.cpp (98%) rename lib/tests/{test_ecl_grid.cpp => test_rd_grid.cpp} (62%) rename lib/tests/{test_ecl_util.cpp => test_rd_util.cpp} (63%) delete mode 100644 lib/util/ecl_version.cpp create mode 100644 lib/util/rd_version.cpp delete mode 100644 python/ecl/ecl_lib_info_build.py.in delete mode 100644 python/ecl/ecl_lib_info_install.py.in delete mode 100644 python/ecl/ecl_type.py delete mode 100644 python/ecl/ecl_util.py delete mode 100644 python/ecl/eclfile/__init__.py delete mode 100644 python/ecl/eclfile/ecl_init_file.py delete mode 100644 python/ecl/gravimetry/__init__.py delete mode 100644 python/ecl/grid/__init__.py delete mode 100644 python/ecl/rft/__init__.py delete mode 100644 python/ecl/summary/__init__.py delete mode 100644 python/ecl/summary/ecl_sum_keyword_vector.py delete mode 100644 python/ecl/summary/ecl_sum_var_type.py delete mode 100644 python/ecl/util/geometry/geo_pointset.py delete mode 100644 python/ecl/util/test/ecl_mock/__init__.py delete mode 100644 python/ecl/util/util/double_vector.py delete mode 100644 python/ecl/util/util/install_abort_signals.py delete mode 100644 python/ecl/util/util/int_vector.py delete mode 100644 python/ecl/well/well_connection_direction_enum.py delete mode 100644 python/ecl/well/well_type_enum.py rename python/{ecl => resdata}/__init__.py (62%) rename python/{ecl => resdata}/bin.py (100%) rename python/{ecl/util => resdata}/geometry/__init__.py (96%) rename python/{ecl/util => resdata}/geometry/cpolyline.py (85%) rename python/{ecl/util => resdata}/geometry/cpolyline_collection.py (90%) create mode 100644 python/resdata/geometry/geo_pointset.py rename python/{ecl/util => resdata}/geometry/geo_region.py (83%) rename python/{ecl/util => resdata}/geometry/geometry_tools.py (100%) rename python/{ecl/util => resdata}/geometry/polyline.py (100%) rename python/{ecl/util => resdata}/geometry/surface.py (83%) rename python/{ecl/util => resdata}/geometry/xyz_io.py (100%) create mode 100644 python/resdata/gravimetry/__init__.py rename python/{ecl/gravimetry/ecl_grav.py => resdata/gravimetry/rd_grav.py} (68%) rename python/{ecl/gravimetry/ecl_subsidence.py => resdata/gravimetry/rd_subsidence.py} (67%) create mode 100644 python/resdata/grid/__init__.py rename python/{ecl => resdata}/grid/cell.py (100%) rename python/{ecl => resdata}/grid/faults/__init__.py (100%) rename python/{ecl => resdata}/grid/faults/fault.py (99%) rename python/{ecl => resdata}/grid/faults/fault_block.py (85%) rename python/{ecl => resdata}/grid/faults/fault_block_collection.py (82%) rename python/{ecl => resdata}/grid/faults/fault_block_layer.py (89%) rename python/{ecl => resdata}/grid/faults/fault_collection.py (96%) rename python/{ecl => resdata}/grid/faults/fault_line.py (98%) rename python/{ecl => resdata}/grid/faults/fault_segments.py (98%) rename python/{ecl => resdata}/grid/faults/layer.py (82%) rename python/{ecl/grid/ecl_grid.py => resdata/grid/rd_grid.py} (75%) rename python/{ecl/grid/ecl_grid_generator.py => resdata/grid/rd_grid_generator.py} (95%) rename python/{ecl/grid/ecl_region.py => resdata/grid/rd_region.py} (60%) create mode 100644 python/resdata/rd_type.py create mode 100644 python/resdata/rd_util.py create mode 100644 python/resdata/resdata_info_build.py.in create mode 100644 python/resdata/resdata_info_install.py.in create mode 100644 python/resdata/resfile/__init__.py rename python/{ecl/eclfile => resdata/resfile}/fortio.py (87%) rename python/{ecl/eclfile/ecl_3d_file.py => resdata/resfile/rd_3d_file.py} (59%) rename python/{ecl/eclfile/ecl_3dkw.py => resdata/resfile/rd_3dkw.py} (63%) rename python/{ecl/eclfile/ecl_file.py => resdata/resfile/rd_file.py} (67%) rename python/{ecl/eclfile/ecl_file_view.py => resdata/resfile/rd_file_view.py} (69%) create mode 100644 python/resdata/resfile/rd_init_file.py rename python/{ecl/eclfile/ecl_kw.py => resdata/resfile/rd_kw.py} (73%) rename python/{ecl/eclfile/ecl_restart_file.py => resdata/resfile/rd_restart_file.py} (59%) create mode 100644 python/resdata/rft/__init__.py rename python/{ecl/rft/ecl_rft.py => resdata/rft/rd_rft.py} (59%) rename python/{ecl/rft/ecl_rft_cell.py => resdata/rft/rd_rft_cell.py} (63%) rename python/{ecl => resdata}/rft/well_trajectory.py (100%) create mode 100644 python/resdata/summary/__init__.py rename python/{ecl/summary/ecl_cmp.py => resdata/summary/rd_cmp.py} (79%) rename python/{ecl/summary/ecl_npv.py => resdata/summary/rd_npv.py} (90%) rename python/{ecl/summary/ecl_smspec_node.py => resdata/summary/rd_smspec_node.py} (69%) rename python/{ecl/summary/ecl_sum.py => resdata/summary/rd_sum.py} (80%) create mode 100644 python/resdata/summary/rd_sum_keyword_vector.py rename python/{ecl/summary/ecl_sum_node.py => resdata/summary/rd_sum_node.py} (54%) rename python/{ecl/summary/ecl_sum_tstep.py => resdata/summary/rd_sum_tstep.py} (50%) create mode 100644 python/resdata/summary/rd_sum_var_type.py rename python/{ecl/summary/ecl_sum_vector.py => resdata/summary/rd_sum_vector.py} (88%) rename python/{ecl => resdata}/util/__init__.py (100%) rename python/{ecl => resdata}/util/enums/__init__.py (100%) rename python/{ecl => resdata}/util/enums/rng_alg_type_enum.py (100%) rename python/{ecl => resdata}/util/enums/rng_init_mode_enum.py (100%) rename python/{ecl => resdata}/util/test/__init__.py (87%) rename python/{ecl => resdata}/util/test/debug_msg.py (100%) rename python/{ecl => resdata}/util/test/ert_test_context.py (100%) rename python/{ecl => resdata}/util/test/extended_testcase.py (98%) rename python/{ecl => resdata}/util/test/import_test_case.py (100%) rename python/{ecl => resdata}/util/test/lint_test_case.py (100%) create mode 100644 python/resdata/util/test/mock/__init__.py rename python/{ecl/util/test/ecl_mock/ecl_sum_mock.py => resdata/util/test/mock/rd_sum_mock.py} (78%) rename python/{ecl => resdata}/util/test/path_context.py (100%) rename python/{ecl/util/test/ert_test_runner.py => resdata/util/test/resdata_test_runner.py} (82%) rename python/{ecl => resdata}/util/test/source_enumerator.py (100%) rename python/{ecl => resdata}/util/test/test_area.py (86%) rename python/{ecl => resdata}/util/test/test_run.py (100%) rename python/{ecl => resdata}/util/util/__init__.py (83%) rename python/{ecl => resdata}/util/util/arg_pack.py (61%) rename python/{ecl => resdata}/util/util/bool_vector.py (52%) rename python/{ecl => resdata}/util/util/cthread_pool.py (82%) rename python/{ecl => resdata}/util/util/ctime.py (96%) rename python/{ecl => resdata}/util/util/cwd_context.py (100%) create mode 100644 python/resdata/util/util/double_vector.py rename python/{ecl => resdata}/util/util/hash.py (72%) create mode 100644 python/resdata/util/util/install_abort_signals.py create mode 100644 python/resdata/util/util/int_vector.py rename python/{ecl => resdata}/util/util/lookup_table.py (69%) rename python/{ecl => resdata}/util/util/permutation_vector.py (71%) rename python/{ecl => resdata}/util/util/rng.py (69%) rename python/{ecl => resdata}/util/util/stringlist.py (87%) rename python/{ecl => resdata}/util/util/thread_pool.py (100%) rename python/{ecl => resdata}/util/util/time_vector.py (63%) rename python/{ecl => resdata}/util/util/util_func.py (84%) rename python/{ecl => resdata}/util/util/vector_template.py (99%) rename python/{ecl => resdata}/util/util/version.py (77%) rename python/{ecl => resdata}/well/__init__.py (72%) rename python/{ecl => resdata}/well/well_connection.py (63%) create mode 100644 python/resdata/well/well_connection_direction_enum.py rename python/{ecl => resdata}/well/well_info.py (67%) rename python/{ecl => resdata}/well/well_segment.py (61%) rename python/{ecl => resdata}/well/well_state.py (68%) rename python/{ecl => resdata}/well/well_time_line.py (74%) create mode 100644 python/resdata/well/well_type_enum.py delete mode 100644 python/tests/ecl_tests/test_deprecation.py delete mode 100644 python/tests/ecl_tests/test_ecl_cmp.py delete mode 100644 python/tests/ecl_tests/test_ecl_init_file.py delete mode 100644 python/tests/ecl_tests/test_ecl_type.py delete mode 100644 python/tests/ecl_tests/test_ecl_util.py delete mode 100644 python/tests/ecl_tests/test_grav.py delete mode 100755 python/tests/ecl_tests/test_grdecl_equinor.py delete mode 100644 python/tests/ecl_tests/test_rft.py rename python/tests/{ecl_tests => rd_tests}/__init__.py (100%) rename python/tests/{ecl_tests => rd_tests}/test_cell.py (95%) rename python/tests/{ecl_tests => rd_tests}/test_debug.py (58%) create mode 100644 python/tests/rd_tests/test_deprecation.py rename python/tests/{ecl_tests => rd_tests}/test_equinor_faults.py (86%) rename python/tests/{ecl_tests => rd_tests}/test_fault_blocks.py (86%) rename python/tests/{ecl_tests => rd_tests}/test_fault_blocks_equinor.py (56%) rename python/tests/{ecl_tests => rd_tests}/test_faults.py (94%) rename python/tests/{ecl_tests => rd_tests}/test_fk_user_data.py (85%) rename python/tests/{ecl_tests => rd_tests}/test_fortio.py (80%) rename python/tests/{ecl_tests => rd_tests}/test_geertsma.py (77%) create mode 100644 python/tests/rd_tests/test_grav.py rename python/tests/{ecl_tests => rd_tests}/test_grdecl.py (85%) create mode 100755 python/tests/rd_tests/test_grdrd_equinor.py rename python/tests/{ecl_tests => rd_tests}/test_grid.py (93%) rename python/tests/{ecl_tests => rd_tests}/test_grid_equinor.py (81%) rename python/tests/{ecl_tests => rd_tests}/test_grid_equinor_coarse.py (81%) rename python/tests/{ecl_tests => rd_tests}/test_grid_equinor_dual.py (85%) rename python/tests/{ecl_tests => rd_tests}/test_grid_generator.py (92%) rename python/tests/{ecl_tests => rd_tests}/test_grid_large_case.py (95%) rename python/tests/{ecl_tests => rd_tests}/test_grid_pandas.py (90%) rename python/tests/{ecl_tests => rd_tests}/test_indexed_read.py (61%) rename python/tests/{ecl_tests => rd_tests}/test_kw_function.py (69%) rename python/tests/{ecl_tests => rd_tests}/test_layer.py (91%) rename python/tests/{ecl_tests => rd_tests}/test_npv.py (90%) rename python/tests/{ecl_tests/test_ecl_3dkw.py => rd_tests/test_rd_3dkw.py} (61%) create mode 100644 python/tests/rd_tests/test_rd_cmp.py rename python/tests/{ecl_tests/test_ecl_file.py => rd_tests/test_rd_file.py} (53%) rename python/tests/{ecl_tests/test_ecl_file_equinor.py => rd_tests/test_rd_file_equinor.py} (90%) create mode 100644 python/tests/rd_tests/test_rd_init_file.py rename python/tests/{ecl_tests/test_ecl_kw.py => rd_tests/test_rd_kw.py} (67%) rename python/tests/{ecl_tests/test_ecl_kw_equinor.py => rd_tests/test_rd_kw_equinor.py} (79%) rename python/tests/{ecl_tests/test_ecl_restart_file.py => rd_tests/test_rd_restart_file.py} (58%) rename python/tests/{ecl_tests/test_ecl_sum.py => rd_tests/test_rd_sum.py} (66%) rename python/tests/{ecl_tests/test_ecl_sum_vector.py => rd_tests/test_rd_sum_vector.py} (54%) create mode 100644 python/tests/rd_tests/test_rd_type.py create mode 100644 python/tests/rd_tests/test_rd_util.py rename python/tests/{ecl_tests => rd_tests}/test_region.py (57%) rename python/tests/{ecl_tests => rd_tests}/test_region_equinor.py (83%) rename python/tests/{ecl_tests => rd_tests}/test_removed.py (62%) rename python/tests/{ecl_tests => rd_tests}/test_restart.py (69%) rename python/tests/{ecl_tests => rd_tests}/test_restart_head.py (65%) create mode 100644 python/tests/rd_tests/test_rft.py rename python/tests/{ecl_tests => rd_tests}/test_rft_cell.py (88%) rename python/tests/{ecl_tests => rd_tests}/test_rft_equinor.py (87%) rename python/tests/{ecl_tests => rd_tests}/test_sum.py (81%) rename python/tests/{ecl_tests => rd_tests}/test_sum_equinor.py (82%) rename python/tests/well_tests/{test_ecl_well.py => test_rd_well.py} (91%) rename python/tests/well_tests/{test_ecl_well2.py => test_rd_well2.py} (76%) rename python/tests/well_tests/{test_ecl_well3.py => test_rd_well3.py} (87%) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 7a1beb805c..21e9c7055a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,4 +1,4 @@ -name: ecl testing +name: testing on: [push, pull_request] @@ -19,12 +19,18 @@ jobs: # required for `git describe --tags` to work fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + - name: Install dependencies run: | python3 -m pip install "conan<2" - - name: Build ecl + - name: Build run: | pip install -r requirements.txt mkdir cmake-build @@ -37,7 +43,7 @@ jobs: export DYLD_LIBRARY_PATH=$PWD/lib ctest --output-on-failure env: - ECL_SKIP_SIGNAL: absolutely + RD_SKIP_SIGNAL: absolutely ERT_SHOW_BACKTRACE: yes please! @@ -80,7 +86,7 @@ jobs: name: ${{ matrix.os }} Python ${{ matrix.python }} wheel path: dist/* - - name: Install ecl + - name: Install run: pip install dist/* - name: Run Python tests @@ -89,8 +95,8 @@ jobs: python -m pip install pytest # pytest adds every directory up-to and including python/ into sys.path, - # meaning that "import ecl" will import python/ecl and not the installed - # one. This doesn't work because the libecl.so library only exists in + # meaning that "import resdata" will import python/resdata and not the installed + # one. This doesn't work because the resdata.so library only exists in # site-packages, so we copy directories required by the tests out into its # own temporary directory. mkdir test-run; cd test-run @@ -101,7 +107,7 @@ jobs: cp -R {..,$PWD}/python/tests # Env vars - export ECL_SKIP_SIGNAL=1 + export RD_SKIP_SIGNAL=1 export ERT_SHOW_BACKTRACE=1 # Run tests diff --git a/.gitignore b/.gitignore index 96dfd491b8..596585bf10 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ scratch.sparsebundle /venv/ /_skbuild/ -/python/ecl/version.py +/python/resdata/version.py .* *.egg-info/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 58e441d259..1bab380272 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(ecl C CXX) +project(resdata C CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -79,25 +79,24 @@ conan_cmake_run( # ----------------------------------------------------------------- -set(ECL_VERSION_MAJOR 0) -set(ECL_VERSION_MINOR 0) -set(ECL_VERSION_MICRO "not-available") +set(RD_VERSION_MAJOR 0) +set(RD_VERSION_MINOR 0) +set(RD_VERSION_MICRO "not-available") # If the micro version is not integer, that should be interpreted as a # development version leading towards version MAJOR.MINOR.0 -execute_process(COMMAND date "+%Y-%m-%d %H:%M:%S" - OUTPUT_VARIABLE ECL_BUILD_TIME) -string(STRIP "${ECL_BUILD_TIME}" ECL_BUILD_TIME) +execute_process(COMMAND date "+%Y-%m-%d %H:%M:%S" OUTPUT_VARIABLE RD_BUILD_TIME) +string(STRIP "${RD_BUILD_TIME}" RD_BUILD_TIME) -if(ECL_VERSION) +if(RD_VERSION) # Have we been provided with an explicitly-set version? - string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\1" ECL_VERSION_MAJOR - "${ECL_VERSION}") - string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\2" ECL_VERSION_MINOR - "${ECL_VERSION}") - string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\3" ECL_VERSION_MICRO - "${ECL_VERSION}") + string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\1" RD_VERSION_MAJOR + "${RD_VERSION}") + string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\2" RD_VERSION_MINOR + "${RD_VERSION}") + string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\3" RD_VERSION_MICRO + "${RD_VERSION}") else() # Otherwise try to discover it via git find_package(Git) @@ -132,11 +131,11 @@ else() OUTPUT_VARIABLE GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\1" ECL_VERSION_MAJOR + string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\1" RD_VERSION_MAJOR "${GIT_TAG}") - string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\2" ECL_VERSION_MINOR + string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\2" RD_VERSION_MINOR "${GIT_TAG}") - string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\3" ECL_VERSION_MICRO + string(REGEX REPLACE "^([^.]+)\\.([^.]+)\\.(.+)$" "\\3" RD_VERSION_MICRO "${GIT_TAG}") else() set(GIT_COMMIT "unknown (git not found!)") @@ -148,14 +147,14 @@ endif() message( STATUS - "libecl version: ${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" + "resdata version: ${RD_VERSION_MAJOR}.${RD_VERSION_MINOR}.${RD_VERSION_MICRO}" ) # ----------------------------------------------------------------- option(BUILD_TESTS "Should the tests be built" OFF) option(BUILD_APPLICATIONS "Should we build small utility applications" OFF) -option(BUILD_ECL_SUMMARY "Build the commandline application ecl_summary" OFF) +option(BUILD_RD_SUMMARY "Build the commandline application rd_summary" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(ERT_USE_OPENMP "Use OpenMP" OFF) option(RST_DOC "Build RST documentation" OFF) @@ -175,11 +174,11 @@ if(EXISTS ${EQUINOR_TESTDATA_ROOT}) message(STATUS "Linking testdata: ${LINK} -> ${EQUINOR_TESTDATA_ROOT}") set(_equinor_test_data ${CMAKE_SOURCE_DIR}/test-data/Equinor) - set(_eclpath ${_equinor_test_data}/ECLIPSE) + set(_resdatapath ${_equinor_test_data}/ECLIPSE) set(_geopath ${_equinor_test_data}/Geometry) endif() set(_local_test_data "${CMAKE_CURRENT_SOURCE_DIR}/test-data/local") -set(_local_eclpath ${_local_test_data}/ECLIPSE) +set(_local_resdatapath ${_local_test_data}/ECLIPSE) # output libs to some lib/ path for testing set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) @@ -449,7 +448,7 @@ endif() if(NOT SKBUILD) # Avoid installing when calling from python setup.py - install(EXPORT ecl-config DESTINATION share/cmake/ecl) - export(TARGETS ecl FILE eclConfig.cmake) - export(PACKAGE ecl) + install(EXPORT resdata-config DESTINATION share/cmake/resdata) + export(TARGETS resdata FILE resdataConfig.cmake) + export(PACKAGE resdata) endif() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9e4c7be29c..164e1f174a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -The following is a set of guidelines for contributing to ecl. +The following is a set of guidelines for contributing to resdata. ## Ground Rules diff --git a/README.md b/README.md index dbc293324d..81e7112563 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -# ecl [![Build Status](https://github.com/equinor/libecl/workflows/ecl%20testing/badge.svg)](https://github.com/equinor/libecl/actions) +# resdata [![Build Status](https://github.com/equinor/resdata/workflows/resdata%20testing/badge.svg)](https://github.com/equinor/resdata/actions) -*ecl* is a package for reading and writing the result files from -the Eclipse reservoir simulator. The file types covered are the +*resdata* is a package for reading and writing the result files from +the reservoir simulators. The file types covered are the restart, init, rft, summary and grid files. Both unified and non-unified and formatted and unformatted files are supported. -*ecl* is mainly developed on *Linux* and *macOS*, in addition there +*resdata* is mainly developed on *Linux* and *macOS*, in addition there is a portability layer which ensures that most of the functionality is available on *Windows*. The main functionality is written in C/C++, and -should typically be linked in in other compiled programs. *ecl* was +should typically be linked in in other compiled programs. *resdata* was initially developed as part of the [Ensemble Reservoir Tool](http://github.com/Equinor/ert), other applications using -*ecl* are the reservoir simulator flow and Resinsight from the [OPM +*resdata* are the reservoir simulator flow and Resinsight from the [OPM project](http://github.com/OPM/). ### Dependencies -Regardless of how you build *ecl*, it will depend on the following system-level +Regardless of how you build *resdata*, it will depend on the following system-level components. | Software | Debian / Ubuntu | RHEL / Fedora | macOS | @@ -33,52 +33,52 @@ not. ### Alternative 1: Python only ### For small interactive scripts, such as forward models, the recommended way to -use *ecl* is by installing it from PyPI. This method doesn't require setting +use *resdata* is by installing it from PyPI. This method doesn't require setting `PYTHONPATH` or `LD_LIBRARY_PATH` environment variables: ``` -$ pip install ecl +$ pip install resdata ``` ### Alternative 2: C library only ### -This is for when you need to link directly with the *ecl* C library, but -don't need the Python bindings. *ecl* requires a conforming C++11 or later +This is for when you need to link directly with the *resdata* C library, but +don't need the Python bindings. *resdata* requires a conforming C++11 or later compiler such as GNU GCC, the CMake build system and, optionally, zlib. ```bash -$ git clone https://github.com/Equinor/ecl -$ mkdir ecl/build -$ cd ecl/build +$ git clone https://github.com/Equinor/resdata +$ mkdir resdata/build +$ cd resdata/build $ cmake .. $ make $ make install ``` -To install *ecl* in a non-standard location, add +To install *resdata* in a non-standard location, add `-DCMAKE_INSTALL_PREFIX=/path/to/install` to the first `cmake` command. Remember to set `LD_LIBRARY_PATH=/path/to/install/lib64:$LD_LIBRARY_PATH` if you do use a -non-standard location for your program to find `libecl.so`. +non-standard location for your program to find `resdata.so`. -If you intend to develop and change *ecl* you should build the tests by +If you intend to develop and change *resdata* you should build the tests by passing `-DBUILD_TESTS=ON` and run the tests with `ctest`. ### Alternative 3: C library with Python bindings ### It is also possible to install both the C library and Python bindings using -CMake. Note that this alternative is incompatible with *ecl* installed from +CMake. Note that this alternative is incompatible with *resdata* installed from PyPI (_Alternative 1_). As before, we require a conforming C++11 or later compiler, CMake and, optionally, zlib. ```bash -$ git clone https://github.com/Equinor/ecl -$ mkdir ecl/build -$ cd ecl/build +$ git clone https://github.com/Equinor/resdata +$ mkdir resdata/build +$ cd resdata/build $ pip install -r ../requirements.txt $ cmake .. -DENABLE_PYTHON=ON $ make $ make install ``` -You will most likely want to install *ecl* into a Python virtual environment. +You will most likely want to install *resdata* into a Python virtual environment. First activate the virtualenv, then add the argument `-DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)")` to the `cmake` command when building. @@ -92,10 +92,10 @@ $ export LD_LIBRARY_PATH=/path/to/install/lib64:$LD_LIBRARY_PATH Then you can fire up your Python interpreter and try it out: ```python ->>> from ecl.summary import EclSum +>>> from resdata.summary import Summary >>> import sys ->>> summary = EclSum(sys.argv[1]) +>>> summary = Summary(sys.argv[1]) >>> fopt = summary.numpy_vector("FOPT") ``` diff --git a/WINDOWS.md b/WINDOWS.md index 419958b2b1..d8c1a84f90 100644 --- a/WINDOWS.md +++ b/WINDOWS.md @@ -1,19 +1,19 @@ -# Compiling and Installing **_libecl_** on Windows +# Compiling and Installing **_resdata_** on Windows ## Prerequisits: * Python 2.7 or 3.x https://www.python.org/ or https://anaconda.org/ * Microsoft Visual Studio https://visualstudio.microsoft.com/downloads/ -* Local copy of **_libecl_** +* Local copy of **_resdata_** ## Instructions: -1. Download or clone the **_libecl_** Github repository to your local disk. +1. Download or clone the **_resdata_** Github repository to your local disk. 2. Python 2.7 or 3.x installation - Download a python instalation or a python environment solution such as Anaconda. -3. Download and install Microsoft Visual Studio . At a minimum **_libecl_** requires the VS Studio packages for cmake, msbuild, c and c++ compilers (CL.exe). +3. Download and install Microsoft Visual Studio . At a minimum **_resdata_** requires the VS Studio packages for cmake, msbuild, c and c++ compilers (CL.exe). -4. Open a MSVC command prompt such as _x64 Native Tools Command Prompt for VS 2017_ from your start menu. In the open prompt, navigate to the **_libecl_** source directory you created in step 1. Use the Python package manager **pip** to install **_libecl_** requirements via `pip install -r requirements.txt`. If Python is not accessible from the prompt it may be necessary to add the Python environment location to your system path variable `PATH`. +4. Open a MSVC command prompt such as _x64 Native Tools Command Prompt for VS 2017_ from your start menu. In the open prompt, navigate to the **_resdata_** source directory you created in step 1. Use the Python package manager **pip** to install **_resdata_** requirements via `pip install -r requirements.txt`. If Python is not accessible from the prompt it may be necessary to add the Python environment location to your system path variable `PATH`. 5. Execute the build commands with the desired CMAKE parameters from `README.md`. The cmake generator can be _`NMake Makefiles`_ , _`Ninja`_ or an appropriate version of _`MSVC`_. For the availble options type `cmake -G` in the MSVC command prompt. @@ -22,6 +22,6 @@ cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALLPATH% -DBUILD_SHARED_LIBS="ON" -DENABLE_PYTHON="ON" -DCMAKE_BUILD_TYPE="Release" %SOURCEPATH% cmake --build %BUILDPATH% --config Release --target install ~~~~ -6. For **_libecl_** to be accessible in Python the `%INSTALLPATH%\lib\pythonX.Y\site-package` and Python subdirectories must be added to the `PATH` and `PYTHONPATH` variables. Where `pythonx.y` is the current Python version _e.g._ (`python3.9`, `python3.10` _etc._) . +6. For **_resdata_** to be accessible in Python the `%INSTALLPATH%\lib\pythonX.Y\site-package` and Python subdirectories must be added to the `PATH` and `PYTHONPATH` variables. Where `pythonx.y` is the current Python version _e.g._ (`python3.9`, `python3.10` _etc._) . -8. Open a Python interactive session and run `import ecl` to check that the install and paths are now set. \ No newline at end of file +8. Open a Python interactive session and run `import resdata` to check that the install and paths are now set. diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index 1b8c9935c1..637e1cc037 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -1,37 +1,37 @@ -project(libecl-applications) +project(resdata-applications) -function(target_link_libecl target) - target_link_libraries(${target} ecl) +function(target_link_resdata target) + target_link_libraries(${target} resdata) if(SKBUILD) set_target_properties(${target} PROPERTIES INSTALL_RPATH "$ORIGIN/../.libs") endif() endfunction() if(BUILD_APPLICATIONS) - add_executable(sum_write ecl/sum_write.cpp) - add_executable(make_grid ecl/make_grid.c) - add_executable(grdecl_grid ecl/grdecl_grid.c) - add_executable(summary ecl/view_summary.cpp) - add_executable(kw_extract ecl/kw_extract.cpp) - target_link_libecl(sum_write) - target_link_libecl(make_grid) - target_link_libecl(grdecl_grid) - target_link_libecl(summary) - target_link_libecl(kw_extract) + add_executable(sum_write resdata/sum_write.cpp) + add_executable(make_grid resdata/make_grid.c) + add_executable(grdecl_grid resdata/grdecl_grid.c) + add_executable(summary resdata/view_summary.cpp) + add_executable(kw_extract resdata/kw_extract.cpp) + target_link_resdata(sum_write) + target_link_resdata(make_grid) + target_link_resdata(grdecl_grid) + target_link_resdata(summary) + target_link_resdata(kw_extract) list(APPEND apps make_grid grdecl_grid summary kw_extract) foreach( app - ecl_pack - ecl_unpack + rd_pack + rd_unpack grid_info grid_dump grid_dump_ascii select_test load_test) - add_executable(${app} ecl/${app}.c) - target_link_libecl(${app}) + add_executable(${app} resdata/${app}.c) + target_link_resdata(${app}) list(APPEND apps ${app}) if(ERT_LINUX) # The .x extension creates problems on windows @@ -41,8 +41,8 @@ if(BUILD_APPLICATIONS) if(ERT_LINUX) foreach(app convert grdecl_test kw_list) - add_executable(${app} ecl/${app}.c) - target_link_libecl(${app}) + add_executable(${app} resdata/${app}.c) + target_link_resdata(${app}) # The .x extension creates problems on windows set_target_properties(${app} PROPERTIES SUFFIX ".x") list(APPEND apps ${app}) @@ -55,19 +55,19 @@ if(BUILD_APPLICATIONS) add_executable(CF_dump well/well_CF_dump.c) add_executable(ri_well_test well/ri_well_test.c) - target_link_libecl(segment_info) - target_link_libecl(CF_dump) - target_link_libecl(ri_well_test) + target_link_resdata(segment_info) + target_link_resdata(CF_dump) + target_link_resdata(ri_well_test) list(APPEND apps segment_info CF_dump ri_well_test) endif() -if(BUILD_ECL_SUMMARY) - add_executable(ecl_summary ecl/view_summary.cpp) - target_link_libecl(ecl_summary) - list(APPEND apps ecl_summary) +if(BUILD_RD_SUMMARY) + add_executable(rd_summary resdata/view_summary.cpp) + target_link_resdata(rd_summary) + list(APPEND apps rd_summary) - install(FILES ${PROJECT_SOURCE_DIR}/man/man1/ecl_summary.1 + install(FILES ${PROJECT_SOURCE_DIR}/man/man1/rd_summary.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) endif() diff --git a/applications/man/man1/ecl_summary.1 b/applications/man/man1/rd_summary.1 similarity index 72% rename from applications/man/man1/ecl_summary.1 rename to applications/man/man1/rd_summary.1 index f881dc0efc..566b2a5d38 100644 --- a/applications/man/man1/ecl_summary.1 +++ b/applications/man/man1/rd_summary.1 @@ -1,7 +1,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH ecl_summary "1" "November 8 2016" +.TH rd_summary "1" "October 25 2023" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -15,17 +15,17 @@ .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME -ecl_summary \- Program to extract summary vectors from ECLIPSE files +rd_summary \- Program to extract summary vectors from summary files .SH DESCRIPTION -The ecl_summary program is used to quickly extract summary vectors -from ECLIPSE summary files. The program is invoked as: +The rd_summary program is used to quickly extract summary vectors +from summary files. The program is invoked as: .PP -computer> ecl_summary \fI\,/Path/to/ECLIPSE\/\fP key1 key2 key3 .... +computer> rd_summary \fI\,/Path/to/CASE\/\fP key1 key2 key3 .... .PP -Here ECLIPSE is the name of an existing case, you can give it with +Here CASE is the name of an existing case, you can give it with extension, or without; the case need not be in the current directory. .PP -The keys are formed by combining ECLIPSE variable names and +The keys are formed by combining variable names and qualifiers from the WGNAMES and NUMS arrays. Examples of keys are: .TP WWCT:F\-36 @@ -55,11 +55,11 @@ The option \fB\-\-list\fR can be used to list all available keys. .HP \fB\-\-no\-restart\fR: If the simulation in question is a restart, i.e a prediction .IP -which starts at the end of the historical period, the ecl_summary +which starts at the end of the historical period, the rd_summary program will by default also load historical data. If the \fB\-\-no\-restart\fR option is used the program will not look for old results. .HP -\fB\-\-no\-header\fR: By default ecl_summary will print a header line at the top, with the +\fB\-\-no\-header\fR: By default rd_summary will print a header line at the top, with the .IP option \fB\-\-no\-header\fR this will be suppressed. .HP @@ -67,11 +67,11 @@ option \fB\-\-no\-header\fR this will be suppressed. .HP \fB\-\-help\fR: Print this message and exit. .PP -The options should come before the ECLIPSE basename. +The options should come before the basename. .PP Example1: .TP -computer> ecl_summary +computer> rd_summary CASE1_XXX WWCT:F\-36 FOPT FWPT .IP This example will load results from case 'CASE1_XXX' and print the @@ -79,35 +79,35 @@ results for keys 'WWCT:F\-36', 'FOPT' and 'FWPT' on standard out. .PP Example2: .TP -computer> ecl_summary +computer> rd_summary \fB\-\-list\fR CASE2_XXX "*:F\-36" "BPR:*" .IP This example will list all the available keys which end with \&':F\-36' and those which start with 'BPR:'. Observe the use of quoting characters "" when using shell wildcards. .PP -The ecl_summary program will look for and load both unified and +The rd_summary program will look for and load both unified and non\-unified and formatted and non\-formatted files. The default search order is: UNSMRY, Snnnn, FUNSMRY, Annnn, however you can manipulate this with the extension to the basename: .PP -* If the extension corresponds to an unformatted file, ecl_summary +* If the extension corresponds to an unformatted file, rd_summary .IP will only look for unformatted files. .PP -* If the extension corresponds to a unified file, ecl_summary will +* If the extension corresponds to a unified file, rd_summary will .IP only look for unified files. .PP -The ecl_summary program is used to quickly extract summary vectors -from ECLIPSE summary files. The program is invoked as: +The rd_summary program is used to quickly extract summary vectors +from summary files. The program is invoked as: .PP -computer> ecl_summary \fI\,/Path/to/ECLIPSE\/\fP key1 key2 key3 .... +computer> rd_summary \fI\,/Path/to/CASE\/\fP key1 key2 key3 .... .PP -Here ECLIPSE is the name of an existing case, you can give it with +Here CASE is the name of an existing case, you can give it with extension, or without; the case need not be in the current directory. .PP -The keys are formed by combining ECLIPSE variable names and +The keys are formed by combining variable names and qualifiers from the WGNAMES and NUMS arrays. Examples of keys are: .TP WWCT:F\-36 @@ -136,11 +136,11 @@ The option \fB\-\-list\fR can be used to list all available keys. .HP \fB\-\-no\-restart\fR: If the simulation in question is a restart, i.e a prediction .IP -which starts at the end of the historical period, the ecl_summary +which starts at the end of the historical period, the rd_summary program will by default also load historical data. If the \fB\-\-no\-restart\fR option is used the program will not look for old results. .HP -\fB\-\-no\-header\fR: By default ecl_summary will print a header line at the top, with the +\fB\-\-no\-header\fR: By default rd_summary will print a header line at the top, with the .IP option \fB\-\-no\-header\fR this will be suppressed. .HP @@ -148,11 +148,11 @@ option \fB\-\-no\-header\fR this will be suppressed. .HP \fB\-\-help\fR: Print this message and exit. .PP -The options should come before the ECLIPSE basename. +The options should come before the basename. .PP Example1: .TP -computer> ecl_summary +computer> rd_summary CASE1_XXX WWCT:F\-36 FOPT FWPT .IP This example will load results from case 'CASE1_XXX' and print the @@ -160,23 +160,23 @@ results for keys 'WWCT:F\-36', 'FOPT' and 'FWPT' on standard out. .PP Example2: .TP -computer> ecl_summary +computer> rd_summary \fB\-\-list\fR CASE2_XXX "*:F\-36" "BPR:*" .IP This example will list all the available keys which end with \&':F\-36' and those which start with 'BPR:'. Observe the use of quoting characters "" when using shell wildcards. .PP -The ecl_summary program will look for and load both unified and +The rd_summary program will look for and load both unified and non\-unified and formatted and non\-formatted files. The default search order is: UNSMRY, Snnnn, FUNSMRY, Annnn, however you can manipulate this with the extension to the basename: .PP -* If the extension corresponds to an unformatted file, ecl_summary +* If the extension corresponds to an unformatted file, rd_summary .IP will only look for unformatted files. .PP -* If the extension corresponds to a unified file, ecl_summary will +* If the extension corresponds to a unified file, rd_summary will .IP only look for unified files. .PP diff --git a/applications/ecl/convert.c b/applications/resdata/convert.c similarity index 72% rename from applications/ecl/convert.c rename to applications/resdata/convert.c index 7d0fc9b4f2..9d3946bfef 100644 --- a/applications/ecl/convert.c +++ b/applications/resdata/convert.c @@ -23,18 +23,18 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include void file_convert(const char *src_file, const char *target_file, - ecl_file_enum file_type, bool fmt_src) { + rd_file_enum file_type, bool fmt_src) { fortio_type *src, *target; bool formatted_src; printf("Converting %s -> %s \n", src_file, target_file); - if (file_type != ECL_OTHER_FILE) + if (file_type != RD_OTHER_FILE) formatted_src = fmt_src; else { if (util_fmt_bit8(src_file)) @@ -43,18 +43,18 @@ void file_convert(const char *src_file, const char *target_file, formatted_src = false; } - target = fortio_open_writer(target_file, !formatted_src, ECL_ENDIAN_FLIP); - src = fortio_open_reader(src_file, formatted_src, ECL_ENDIAN_FLIP); + target = fortio_open_writer(target_file, !formatted_src, RD_ENDIAN_FLIP); + src = fortio_open_reader(src_file, formatted_src, RD_ENDIAN_FLIP); while (true) { if (fortio_read_at_eof(src)) break; { - ecl_kw_type *ecl_kw = ecl_kw_fread_alloc(src); - if (ecl_kw) { - ecl_kw_fwrite(ecl_kw, target); - ecl_kw_free(ecl_kw); + rd_kw_type *rd_kw = rd_kw_fread_alloc(src); + if (rd_kw) { + rd_kw_fwrite(rd_kw, target); + rd_kw_free(rd_kw); } else { fprintf(stderr, "Reading keyword failed \n"); break; @@ -77,15 +77,15 @@ int main(int argc, char **argv) { char *target_file; int report_nr; - ecl_file_enum file_type; + rd_file_enum file_type; bool fmt_file; - file_type = ecl_util_get_file_type(src_file, &fmt_file, &report_nr); + file_type = rd_get_file_type(src_file, &fmt_file, &report_nr); - if (file_type == ECL_OTHER_FILE) { + if (file_type == RD_OTHER_FILE) { if (argc != 3) { fprintf(stderr, - "When the file can not be recognized on the name as an " - "ECLIPSE file you must give output_file as second (and " + "When the file can not be recognized on the name" + "you must give output_file as second (and " "final) argument \n"); exit(0); } @@ -98,9 +98,8 @@ int main(int argc, char **argv) { char *basename; char *extension; src_file = argv[file_nr]; - file_type = - ecl_util_get_file_type(src_file, &fmt_file, &report_nr); - if (file_type == ECL_OTHER_FILE) { + file_type = rd_get_file_type(src_file, &fmt_file, &report_nr); + if (file_type == RD_OTHER_FILE) { fprintf(stderr, "File: %s - problem \n", src_file); fprintf(stderr, "In a list of many files ALL must be " "recognizable by their name. \n"); @@ -109,8 +108,8 @@ int main(int argc, char **argv) { util_alloc_file_components(src_file, &path, &basename, &extension); - target_file = ecl_util_alloc_filename(path, basename, file_type, - !fmt_file, report_nr); + target_file = rd_alloc_filename(path, basename, file_type, + !fmt_file, report_nr); file_convert(src_file, target_file, file_type, fmt_file); free(path); diff --git a/applications/ecl/grdecl_grid.c b/applications/resdata/grdecl_grid.c similarity index 50% rename from applications/ecl/grdecl_grid.c rename to applications/resdata/grdecl_grid.c index b174230a3b..2cf16da338 100644 --- a/applications/ecl/grdecl_grid.c +++ b/applications/resdata/grdecl_grid.c @@ -21,33 +21,33 @@ #include -#include -#include -#include +#include +#include +#include int main(int argc, char **argv) { FILE *stream = util_fopen(argv[1], "r"); - ecl_kw_type *gridhead_kw = ecl_kw_fscanf_alloc_grdecl_dynamic__( - stream, SPECGRID_KW, false, ECL_INT); - ecl_kw_type *zcorn_kw = - ecl_kw_fscanf_alloc_grdecl_dynamic(stream, ZCORN_KW, ECL_FLOAT); - ecl_kw_type *coord_kw = - ecl_kw_fscanf_alloc_grdecl_dynamic(stream, COORD_KW, ECL_FLOAT); - ecl_kw_type *actnum_kw = - ecl_kw_fscanf_alloc_grdecl_dynamic(stream, ACTNUM_KW, ECL_INT); + rd_kw_type *gridhead_kw = + rd_kw_fscanf_alloc_grdecl_dynamic__(stream, SPECGRID_KW, false, RD_INT); + rd_kw_type *zcorn_kw = + rd_kw_fscanf_alloc_grdecl_dynamic(stream, ZCORN_KW, RD_FLOAT); + rd_kw_type *coord_kw = + rd_kw_fscanf_alloc_grdecl_dynamic(stream, COORD_KW, RD_FLOAT); + rd_kw_type *actnum_kw = + rd_kw_fscanf_alloc_grdecl_dynamic(stream, ACTNUM_KW, RD_INT); { - int nx = ecl_kw_iget_int(gridhead_kw, SPECGRID_NX_INDEX); - int ny = ecl_kw_iget_int(gridhead_kw, SPECGRID_NY_INDEX); - int nz = ecl_kw_iget_int(gridhead_kw, SPECGRID_NZ_INDEX); - ecl_grid_type *ecl_grid = ecl_grid_alloc_GRDECL_kw( + int nx = rd_kw_iget_int(gridhead_kw, SPECGRID_NX_INDEX); + int ny = rd_kw_iget_int(gridhead_kw, SPECGRID_NY_INDEX); + int nz = rd_kw_iget_int(gridhead_kw, SPECGRID_NZ_INDEX); + rd_grid_type *rd_grid = rd_grid_alloc_GRDECL_kw( nx, ny, nz, zcorn_kw, coord_kw, actnum_kw, NULL); /* .... */ - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } - ecl_kw_free(gridhead_kw); - ecl_kw_free(zcorn_kw); - ecl_kw_free(actnum_kw); - ecl_kw_free(coord_kw); + rd_kw_free(gridhead_kw); + rd_kw_free(zcorn_kw); + rd_kw_free(actnum_kw); + rd_kw_free(coord_kw); fclose(stream); } diff --git a/applications/ecl/grdecl_test.c b/applications/resdata/grdecl_test.c similarity index 81% rename from applications/ecl/grdecl_test.c rename to applications/resdata/grdecl_test.c index c8f42f4f53..dfe639b50c 100644 --- a/applications/ecl/grdecl_test.c +++ b/applications/resdata/grdecl_test.c @@ -20,23 +20,23 @@ #include #include -#include +#include int main(int argc, char **argv) { FILE *stream = util_fopen(argv[1], "r"); { while (true) { - ecl_kw_type *grdecl_kw; + rd_kw_type *grdecl_kw; clock_t begin = clock(); - grdecl_kw = ecl_kw_fscanf_alloc_current_grdecl(stream, ECL_FLOAT); + grdecl_kw = rd_kw_fscanf_alloc_current_grdecl(stream, RD_FLOAT); clock_t end = clock(); double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; if (grdecl_kw != NULL) { printf("Loaded %s - %d elements : %g \n", - ecl_kw_get_header(grdecl_kw), ecl_kw_get_size(grdecl_kw), + rd_kw_get_header(grdecl_kw), rd_kw_get_size(grdecl_kw), time_spent); - ecl_kw_free(grdecl_kw); + rd_kw_free(grdecl_kw); } else break; } diff --git a/applications/ecl/grid_dump.c b/applications/resdata/grid_dump.c similarity index 86% rename from applications/ecl/grid_dump.c rename to applications/resdata/grid_dump.c index a68bcc5880..afd460f5d1 100644 --- a/applications/ecl/grid_dump.c +++ b/applications/resdata/grid_dump.c @@ -21,7 +21,7 @@ #include -#include +#include int main(int argc, char **argv) { if (argc < 2) { @@ -32,7 +32,7 @@ int main(int argc, char **argv) { { const char *grid_file = argv[1]; char *output_file = NULL; - ecl_grid_type *ecl_grid; + rd_grid_type *rd_grid; FILE *stream; if (argc == 3) { @@ -41,11 +41,11 @@ int main(int argc, char **argv) { } else stream = stdout; - ecl_grid = ecl_grid_alloc(grid_file); - ecl_grid_dump(ecl_grid, stream); + rd_grid = rd_grid_alloc(grid_file); + rd_grid_dump(rd_grid, stream); if (output_file != NULL) fclose(stream); - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } } diff --git a/applications/ecl/grid_dump_ascii.c b/applications/resdata/grid_dump_ascii.c similarity index 85% rename from applications/ecl/grid_dump_ascii.c rename to applications/resdata/grid_dump_ascii.c index cbbdfb5360..597b272d7c 100644 --- a/applications/ecl/grid_dump_ascii.c +++ b/applications/resdata/grid_dump_ascii.c @@ -21,7 +21,7 @@ #include -#include +#include int main(int argc, char **argv) { if (argc < 2) { @@ -32,7 +32,7 @@ int main(int argc, char **argv) { { const char *grid_file = argv[1]; char *output_file = NULL; - ecl_grid_type *ecl_grid; + rd_grid_type *rd_grid; FILE *stream; if (argc == 3) { @@ -41,11 +41,11 @@ int main(int argc, char **argv) { } else stream = stdout; - ecl_grid = ecl_grid_alloc(grid_file); - ecl_grid_dump_ascii(ecl_grid, false, stream); + rd_grid = rd_grid_alloc(grid_file); + rd_grid_dump_ascii(rd_grid, false, stream); if (output_file != NULL) fclose(stream); - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } } diff --git a/applications/ecl/grid_info.c b/applications/resdata/grid_info.c similarity index 69% rename from applications/ecl/grid_info.c rename to applications/resdata/grid_info.c index ded31b7cc7..b3126aa329 100644 --- a/applications/ecl/grid_info.c +++ b/applications/resdata/grid_info.c @@ -21,7 +21,7 @@ #include -#include +#include int main(int argc, char **argv) { if (argc < 2) { @@ -30,32 +30,32 @@ int main(int argc, char **argv) { } { - ecl_grid_type *ecl_grid; + rd_grid_type *rd_grid; const char *grid_file = argv[1]; - ecl_grid = ecl_grid_alloc(grid_file); - ecl_grid_summarize(ecl_grid); + rd_grid = rd_grid_alloc(grid_file); + rd_grid_summarize(rd_grid); if (argc >= 3) { - ecl_grid_type *grid2 = ecl_grid_alloc(argv[2]); + rd_grid_type *grid2 = rd_grid_alloc(argv[2]); - if (ecl_grid_compare(ecl_grid, grid2, true, false, false)) + if (rd_grid_compare(rd_grid, grid2, true, false, false)) printf("\nThe grids %s %s are IDENTICAL.\n", argv[1], argv[2]); else { printf("\n"); - ecl_grid_summarize(grid2); + rd_grid_summarize(grid2); printf("\nThe grids %s %s are DIFFERENT.\n", argv[1], argv[2]); } - ecl_grid_free(grid2); + rd_grid_free(grid2); } /* printf("----\n"); { - double * ri_points = util_calloc( ecl_grid_get_global_size( ecl_grid ) * 24 , sizeof * ri_points ); - ecl_grid_ri_export( ecl_grid , ri_points ); + double * ri_points = util_calloc( rd_grid_get_global_size( rd_grid ) * 24 , sizeof * ri_points ); + rd_grid_ri_export( rd_grid , ri_points ); free( ri_points ); } printf("----\n"); */ - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } } diff --git a/applications/ecl/kw_extract.cpp b/applications/resdata/kw_extract.cpp similarity index 64% rename from applications/ecl/kw_extract.cpp rename to applications/resdata/kw_extract.cpp index f6903c66d5..04460586b2 100644 --- a/applications/ecl/kw_extract.cpp +++ b/applications/resdata/kw_extract.cpp @@ -6,12 +6,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /** This file will extract all occurences of kw1,kw2,...,kwn from the @@ -36,30 +36,30 @@ int main(int argc, char **argv) { for (int iarg = 3; iarg < argc; iarg++) stringlist_append_copy(kw_set, argv[iarg]); - if (!ecl_util_fmt_file(src_file, &fmt_src)) + if (!rd_fmt_file(src_file, &fmt_src)) util_exit("Hmm - could not determine formatted/unformatted status " "for:%s \n", src_file); fmt_target = fmt_src; /* Can in principle be different */ - fortio_src = fortio_open_reader(src_file, fmt_src, ECL_ENDIAN_FLIP); + fortio_src = fortio_open_reader(src_file, fmt_src, RD_ENDIAN_FLIP); fortio_target = - fortio_open_writer(target_file, fmt_target, ECL_ENDIAN_FLIP); + fortio_open_writer(target_file, fmt_target, RD_ENDIAN_FLIP); { - ecl_kw_type *ecl_kw = ecl_kw_alloc_empty(); + rd_kw_type *rd_kw = rd_kw_alloc_empty(); while (true) { - if (ecl_kw_fread_header(ecl_kw, fortio_src) == ECL_KW_READ_OK) { - const char *header = ecl_kw_get_header(ecl_kw); + if (rd_kw_fread_header(rd_kw, fortio_src) == RD_KW_READ_OK) { + const char *header = rd_kw_get_header(rd_kw); if (stringlist_contains(kw_set, header)) { - ecl_kw_fread_realloc_data(ecl_kw, fortio_src); - ecl_kw_fwrite(ecl_kw, fortio_target); + rd_kw_fread_realloc_data(rd_kw, fortio_src); + rd_kw_fwrite(rd_kw, fortio_target); } else - ecl_kw_fskip_data(ecl_kw, fortio_src); + rd_kw_fskip_data(rd_kw, fortio_src); } else break; /* We have reached EOF */ } - ecl_kw_free(ecl_kw); + rd_kw_free(rd_kw); } fortio_fclose(fortio_src); diff --git a/applications/ecl/kw_list.c b/applications/resdata/kw_list.c similarity index 76% rename from applications/ecl/kw_list.c rename to applications/resdata/kw_list.c index 3d2055dd2f..ec6757a5b8 100644 --- a/applications/ecl/kw_list.c +++ b/applications/resdata/kw_list.c @@ -21,27 +21,27 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include void kw_list(const char *filename) { fortio_type *fortio; - ecl_kw_type *ecl_kw = ecl_kw_alloc_empty(); + rd_kw_type *rd_kw = rd_kw_alloc_empty(); bool fmt_file; - if (ecl_util_fmt_file(filename, &fmt_file)) { + if (rd_fmt_file(filename, &fmt_file)) { printf("---------------------------------------------------------------" "--\n"); printf("%s: \n", filename); - fortio = fortio_open_reader(filename, fmt_file, ECL_ENDIAN_FLIP); - while (ecl_kw_fread_realloc(ecl_kw, fortio)) - ecl_kw_summarize(ecl_kw); + fortio = fortio_open_reader(filename, fmt_file, RD_ENDIAN_FLIP); + while (rd_kw_fread_realloc(rd_kw, fortio)) + rd_kw_summarize(rd_kw); printf("---------------------------------------------------------------" "--\n"); - ecl_kw_free(ecl_kw); + rd_kw_free(rd_kw); fortio_fclose(fortio); } else fprintf(stderr, diff --git a/applications/ecl/load_test.c b/applications/resdata/load_test.c similarity index 68% rename from applications/ecl/load_test.c rename to applications/resdata/load_test.c index ec278ce06b..fd1643825e 100644 --- a/applications/ecl/load_test.c +++ b/applications/resdata/load_test.c @@ -20,47 +20,45 @@ #include #include -#include -#include +#include +#include void test_case(const char *base, bool load_all) { - char *grid_file = - ecl_util_alloc_filename(NULL, base, ECL_EGRID_FILE, false, 0); - char *init_file = - ecl_util_alloc_filename(NULL, base, ECL_INIT_FILE, false, 0); + char *grid_file = rd_alloc_filename(NULL, base, RD_EGRID_FILE, false, 0); + char *init_file = rd_alloc_filename(NULL, base, RD_INIT_FILE, false, 0); char *restart_file = - ecl_util_alloc_filename(NULL, base, ECL_UNIFIED_RESTART_FILE, false, 0); + rd_alloc_filename(NULL, base, RD_UNIFIED_RESTART_FILE, false, 0); - ecl_grid_type *grid; - ecl_file_type *restart; - ecl_file_type *init; + rd_grid_type *grid; + rd_file_type *restart; + rd_file_type *init; clock_t begin = clock(); - grid = ecl_grid_alloc(grid_file); + grid = rd_grid_alloc(grid_file); clock_t end = clock(); double grid_time = (double)(end - begin) / CLOCKS_PER_SEC; begin = clock(); - init = ecl_file_open(init_file, 0); + init = rd_file_open(init_file, 0); if (load_all) - ecl_file_load_all(init); + rd_file_load_all(init); end = clock(); double init_time = (double)(end - begin) / CLOCKS_PER_SEC; begin = clock(); - restart = ecl_file_open(restart_file, 0); + restart = rd_file_open(restart_file, 0); if (load_all) - ecl_file_load_all(restart); + rd_file_load_all(restart); end = clock(); double restarts_time = (double)(end - begin) / CLOCKS_PER_SEC; printf("%-64s Restart:%8.4f Grid:%8.4f Init:%8.4f \n", base, restarts_time, grid_time, init_time); - ecl_file_close(init); - ecl_file_close(restart); - ecl_grid_free(grid); + rd_file_close(init); + rd_file_close(restart); + rd_grid_free(grid); free(grid_file); free(init_file); free(restart_file); diff --git a/applications/ecl/make_grid.c b/applications/resdata/make_grid.c similarity index 85% rename from applications/ecl/make_grid.c rename to applications/resdata/make_grid.c index 6745cdc4f9..83adce4b99 100644 --- a/applications/ecl/make_grid.c +++ b/applications/resdata/make_grid.c @@ -21,7 +21,7 @@ #include -#include +#include int main(int argc, char **argv) { if (argc != 5) { @@ -36,17 +36,17 @@ int main(int argc, char **argv) { int nz = atoi(argv[4]); char *path, *basename; - ecl_grid_type *ecl_grid; + rd_grid_type *rd_grid; util_alloc_file_components(base_input, &path, &basename, NULL); - ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); + rd_grid = rd_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); { char *EGRID_file = util_alloc_filename(path, basename, "EGRID"); printf("Writing file: %s ...", EGRID_file); fflush(stdout); - ecl_grid_fwrite_EGRID2(ecl_grid, EGRID_file, ECL_METRIC_UNITS); + rd_grid_fwrite_EGRID2(rd_grid, EGRID_file, RD_METRIC_UNITS); free(EGRID_file); } @@ -55,7 +55,7 @@ int main(int argc, char **argv) { FILE *stream = util_fopen(grdecl_file, "w"); printf("\nWriting file: %s ...", grdecl_file); fflush(stdout); - ecl_grid_fprintf_grdecl(ecl_grid, stream); + rd_grid_fprintf_grdecl(rd_grid, stream); fclose(stream); free(grdecl_file); printf("\n"); @@ -63,6 +63,6 @@ int main(int argc, char **argv) { free(basename); free(path); - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } } diff --git a/applications/ecl/ecl_pack.c b/applications/resdata/rd_pack.c similarity index 58% rename from applications/ecl/ecl_pack.c rename to applications/resdata/rd_pack.c index 7fccb9472b..20ecdab317 100644 --- a/applications/ecl/ecl_pack.c +++ b/applications/resdata/rd_pack.c @@ -1,7 +1,7 @@ /* Copyright (C) 2011 Equinor ASA, Norway. - The file 'ecl_pack.c' is part of ERT - Ensemble based Reservoir Tool. + The file 'rd_pack.c' is part of ERT - Ensemble based Reservoir Tool. ERT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,32 +21,32 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { int num_files = argc - 1; if (num_files >= 1) { /* File type and formatted / unformatted is determined from the first argument on the command line. */ - char *ecl_base; + char *rd_base; char *path; - ecl_file_enum file_type, target_type; + rd_file_enum file_type, target_type; bool fmt_file; /** Look at the first command line argument to determine type and formatted/unformatted status. */ - file_type = ecl_util_get_file_type(argv[1], &fmt_file, NULL); - if (file_type == ECL_SUMMARY_FILE) - target_type = ECL_UNIFIED_SUMMARY_FILE; - else if (file_type == ECL_RESTART_FILE) - target_type = ECL_UNIFIED_RESTART_FILE; + file_type = rd_get_file_type(argv[1], &fmt_file, NULL); + if (file_type == RD_SUMMARY_FILE) + target_type = RD_UNIFIED_SUMMARY_FILE; + else if (file_type == RD_RESTART_FILE) + target_type = RD_UNIFIED_RESTART_FILE; else { - util_exit("The ecl_pack program can only be used with ECLIPSE " + util_exit("The rd_pack program can only be used with " "restart files or summary files.\n"); target_type = -1; } - util_alloc_file_components(argv[1], &path, &ecl_base, NULL); + util_alloc_file_components(argv[1], &path, &rd_base, NULL); /** Will pack to cwd, even though the source files might be @@ -57,25 +57,25 @@ int main(int argc, char **argv) { { int i, report_step, prev_report_step; - char *target_file_name = ecl_util_alloc_filename( - NULL, ecl_base, target_type, fmt_file, -1); + char *target_file_name = + rd_alloc_filename(NULL, rd_base, target_type, fmt_file, -1); stringlist_type *filelist = stringlist_alloc_argv_copy((const char **)&argv[1], num_files); - ecl_kw_type *seqnum_kw = NULL; + rd_kw_type *seqnum_kw = NULL; fortio_type *target = - fortio_open_writer(target_file_name, fmt_file, ECL_ENDIAN_FLIP); + fortio_open_writer(target_file_name, fmt_file, RD_ENDIAN_FLIP); - if (target_type == ECL_UNIFIED_RESTART_FILE) { + if (target_type == RD_UNIFIED_RESTART_FILE) { int dummy; - seqnum_kw = ecl_kw_alloc_new("SEQNUM", 1, ECL_INT, &dummy); + seqnum_kw = rd_kw_alloc_new("SEQNUM", 1, RD_INT, &dummy); } - stringlist_sort(filelist, ecl_util_fname_report_cmp); + stringlist_sort(filelist, rd_fname_report_cmp); prev_report_step = -1; for (i = 0; i < num_files; i++) { - ecl_file_enum this_file_type; - this_file_type = ecl_util_get_file_type( - stringlist_iget(filelist, i), NULL, &report_step); + rd_file_enum this_file_type; + this_file_type = rd_get_file_type(stringlist_iget(filelist, i), + NULL, &report_step); if (this_file_type == file_type) { if (report_step == prev_report_step) util_exit( @@ -85,15 +85,15 @@ int main(int argc, char **argv) { prev_report_step = report_step; { - ecl_file_type *src_file = - ecl_file_open(stringlist_iget(filelist, i), 0); - if (target_type == ECL_UNIFIED_RESTART_FILE) { + rd_file_type *src_file = + rd_file_open(stringlist_iget(filelist, i), 0); + if (target_type == RD_UNIFIED_RESTART_FILE) { /* Must insert the SEQNUM keyword first. */ - ecl_kw_iset_int(seqnum_kw, 0, report_step); - ecl_kw_fwrite(seqnum_kw, target); + rd_kw_iset_int(seqnum_kw, 0, report_step); + rd_kw_fwrite(seqnum_kw, target); } - ecl_file_fwrite_fortio(src_file, target, 0); - ecl_file_close(src_file); + rd_file_fwrite_fortio(src_file, target, 0); + rd_file_close(src_file); } } /* Else skipping file of incorrect type. */ } @@ -101,9 +101,9 @@ int main(int argc, char **argv) { free(target_file_name); stringlist_free(filelist); if (seqnum_kw != NULL) - ecl_kw_free(seqnum_kw); + rd_kw_free(seqnum_kw); } - free(ecl_base); + free(rd_base); free(path); } } diff --git a/applications/ecl/ecl_unpack.c b/applications/resdata/rd_unpack.c similarity index 50% rename from applications/ecl/ecl_unpack.c rename to applications/resdata/rd_unpack.c index 18a260d0a4..b09c8adb58 100644 --- a/applications/ecl/ecl_unpack.c +++ b/applications/resdata/rd_unpack.c @@ -1,7 +1,7 @@ /* Copyright (C) 2011 Equinor ASA, Norway. - The file 'ecl_unpack.c' is part of ERT - Ensemble based Reservoir Tool. + The file 'rd_unpack.c' is part of ERT - Ensemble based Reservoir Tool. ERT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,31 +20,30 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include void unpack_file(const char *filename) { - ecl_file_enum target_type = ECL_OTHER_FILE; - ecl_file_enum file_type; + rd_file_enum target_type = RD_OTHER_FILE; + rd_file_enum file_type; bool fmt_file; - file_type = ecl_util_get_file_type(filename, &fmt_file, NULL); - if (file_type == ECL_UNIFIED_SUMMARY_FILE) - target_type = ECL_SUMMARY_FILE; - else if (file_type == ECL_UNIFIED_RESTART_FILE) - target_type = ECL_RESTART_FILE; + file_type = rd_get_file_type(filename, &fmt_file, NULL); + if (file_type == RD_UNIFIED_SUMMARY_FILE) + target_type = RD_SUMMARY_FILE; + else if (file_type == RD_UNIFIED_RESTART_FILE) + target_type = RD_RESTART_FILE; else - util_exit( - "Can only unpack unified ECLIPSE summary and restart files\n"); + util_exit("Can only unpack unified summary and restart files\n"); - if (target_type == ECL_SUMMARY_FILE) { + if (target_type == RD_SUMMARY_FILE) { printf("** Warning: when unpacking unified summary files it as " "ambigous - starting with 0001 -> \n"); } { - ecl_file_type *src_file = ecl_file_open(filename, 0); + rd_file_type *src_file = rd_file_open(filename, 0); int size; int offset; int report_step = 0; @@ -53,29 +52,29 @@ void unpack_file(const char *filename) { char *base; util_alloc_file_components(filename, &path, &base, NULL); - if (target_type == ECL_SUMMARY_FILE) - size = ecl_file_get_num_named_kw(src_file, "SEQHDR"); + if (target_type == RD_SUMMARY_FILE) + size = rd_file_get_num_named_kw(src_file, "SEQHDR"); else - size = ecl_file_get_num_named_kw(src_file, "SEQNUM"); + size = rd_file_get_num_named_kw(src_file, "SEQNUM"); while (true) { - ecl_file_view_type *active_view; + rd_file_view_type *active_view; if (block_index == size) break; - if (target_type == ECL_SUMMARY_FILE) { - active_view = ecl_file_get_global_blockview(src_file, SEQHDR_KW, - block_index); + if (target_type == RD_SUMMARY_FILE) { + active_view = rd_file_get_global_blockview(src_file, SEQHDR_KW, + block_index); report_step += 1; offset = 0; } else { - ecl_kw_type *seqnum_kw; - active_view = ecl_file_get_global_blockview(src_file, SEQNUM_KW, - block_index); + rd_kw_type *seqnum_kw; + active_view = rd_file_get_global_blockview(src_file, SEQNUM_KW, + block_index); seqnum_kw = - ecl_file_view_iget_named_kw(active_view, SEQNUM_KW, 0); - report_step = ecl_kw_iget_int(seqnum_kw, 0); + rd_file_view_iget_named_kw(active_view, SEQNUM_KW, 0); + report_step = rd_kw_iget_int(seqnum_kw, 0); offset = 1; } @@ -87,18 +86,18 @@ void unpack_file(const char *filename) { */ { - char *target_file = ecl_util_alloc_filename( - NULL, base, target_type, fmt_file, report_step); + char *target_file = rd_alloc_filename(NULL, base, target_type, + fmt_file, report_step); fortio_type *fortio_target = - fortio_open_writer(target_file, fmt_file, ECL_ENDIAN_FLIP); - ecl_file_view_fwrite(active_view, fortio_target, offset); + fortio_open_writer(target_file, fmt_file, RD_ENDIAN_FLIP); + rd_file_view_fwrite(active_view, fortio_target, offset); fortio_fclose(fortio_target); free(target_file); } block_index++; } - ecl_file_close(src_file); + rd_file_close(src_file); free(path); free(base); } @@ -106,7 +105,7 @@ void unpack_file(const char *filename) { int main(int argc, char **argv) { if (argc == 1) - util_exit("ecl_unpack UNIFIED_FILE1 UNIFIED_FILE2 ...\n"); + util_exit("rd_unpack UNIFIED_FILE1 UNIFIED_FILE2 ...\n"); { int iarg; for (iarg = 1; iarg < argc; iarg++) diff --git a/applications/ecl/select_test.c b/applications/resdata/select_test.c similarity index 91% rename from applications/ecl/select_test.c rename to applications/resdata/select_test.c index 6c31ebe3ff..f34427003d 100644 --- a/applications/ecl/select_test.c +++ b/applications/resdata/select_test.c @@ -22,14 +22,14 @@ #include #include -#include +#include int main(int argc, char **argv) { const char *path = argv[1]; const char *base = argv[2]; stringlist_type *names = stringlist_alloc_new(); - ecl_util_select_filelist(path, base, ECL_OTHER_FILE, false, names); + rd_select_filelist(path, base, RD_OTHER_FILE, false, names); { int i; for (i = 0; i < stringlist_get_size(names); i++) diff --git a/applications/ecl/sum_write.cpp b/applications/resdata/sum_write.cpp similarity index 78% rename from applications/ecl/sum_write.cpp rename to applications/resdata/sum_write.cpp index 827d45eac9..019b0cc69c 100644 --- a/applications/ecl/sum_write.cpp +++ b/applications/resdata/sum_write.cpp @@ -4,19 +4,19 @@ #include #include -#include -#include -#include +#include +#include +#include /* - The ECLIPSE summary data is stored in two different files: + The summary data is stored in two different files: - A header file which contains metadata of the stored data; this header file has extension SMSPEC. - The actual data is stored as blocks of data where each block - contains all the variables for one timestep (called MINISTEP in - ECLIPSE lingo). The data can be stored in a unified summary file + contains all the variables for one timestep (MINISTEP). The data + can be stored in a unified summary file with all the data in one file, or alternatively several separate files - one for each report step. @@ -25,7 +25,7 @@ The format is quite primitive, and very much influenced by Fortran77 arrays which are fixed-size-large-enough thank you. The header file - is (mainly) based on three different ecl_kw vectors which together + is (mainly) based on three different rd_kw vectors which together completely specify the variables. The example below consists of the following: @@ -58,7 +58,7 @@ ECLIPSE will determine the type of variable by looking at the first letter of the keyword: "W" for well variables, "F" for field variables and so on. This is further documented in the - ecl_smspec_identify_var_type() function. + rd_smspec_identify_var_type() function. 2. The KEYWORD vector in the SMSPEC file is relevant for all the entries, whereas the WGNAMES and NUMS entries should be @@ -81,7 +81,7 @@ - All timesteps are equally large. Due to this fixed size nature an important element in the - ecl_sum implementation is "the index of a variable" - i.e. the + rd_sum implementation is "the index of a variable" - i.e. the "FOPT" variable in the example above will be found at index 1 of every datablock. @@ -91,7 +91,7 @@ data block is the current time (in days) for that datablock; if labunits is used the stored value is the elapsed time in hours. - 6. In the ecl_sum library the concept of a 'gen_key' is used quite + 6. In the rd_sum library the concept of a 'gen_key' is used quite extensively. The gen_key is a string combination of the KEYWORD, WGNAMES and NUMS values from the smspec header file. Only the relevant elements are combined when forming a gen_key; i.e. for @@ -126,11 +126,11 @@ point 4 above, the library is somewhat cumbersome and unflexible to use. Very briefly the usage pattern will be like: - 1. Create a ecl_sum instance and add variables to it with the - ecl_sum_add_var() function. + 1. Create a rd_sum instance and add variables to it with the + rd_sum_add_var() function. 2. Use your simulator to step forward in time, and add timesteps - with ecl_sum_add_tstep(). + with rd_sum_add_tstep(). Now - the important thing is that steps 1 and 2 two can not be interchanged, that will lead to crash and burn. @@ -146,11 +146,11 @@ int main(int argc, char **argv) { We create a new summary case which will be used for writing. The arguments are: - 1: The case - this an ECLIPSE basename, with an optional leading - path component. Can later be modified with ecl_sum_set_case(). + 1: The case - this the basename, with an optional leading + path component. Can later be modified with rd_sum_set_case(). 2: Should formatted files be used? Can be modified with - ecl_sum_set_fmt_output(). + rd_sum_set_fmt_output(). 3: Character(s) to separate the items from the smspec header generate a gen_key value. The value ":" is close to a @@ -158,7 +158,7 @@ int main(int argc, char **argv) { 4: Should the data be output as a unified file, or as a collection of files - one for each report step. Can be - modified with ecl_sum_set_unified_output(). + modified with rd_sum_set_unified_output(). 5: The real-world start time of this simulation, as a unix time_t value. @@ -166,7 +166,7 @@ int main(int argc, char **argv) { 6-8: Grid dimensions. */ bool time_in_days = true; - ecl_sum_type *ecl_sum = ecl_sum_alloc_writer( + rd_sum_type *rd_sum = rd_sum_alloc_writer( "/tmp/CASE", false, true, ":", start_time, time_in_days, nx, ny, nz); /* @@ -179,7 +179,7 @@ int main(int argc, char **argv) { 1. self / this 2. The KEYWORD value for the variable we are considering; the - function ecl_smspec_identify_var_type() will be called with + function rd_smspec_identify_var_type() will be called with this string - i.e. you must follow the ECLIPSE rules (see table 3.4 in the ECLIPSE file format reference manual). @@ -194,17 +194,17 @@ int main(int argc, char **argv) { 6. A defualt value for this variable. */ - ecl_sum_add_var(ecl_sum, "FOPT", NULL, 0, "Barrels", 99.0); - ecl_sum_add_var(ecl_sum, "BPR", NULL, 567, "BARS", 0.0); - ecl_sum_add_var(ecl_sum, "WWCT", "OP-1", 0, "(1)", 0.0); - ecl_sum_add_var(ecl_sum, "WOPR", "OP-1", 0, "Barrels", 0.0); + rd_sum_add_var(rd_sum, "FOPT", NULL, 0, "Barrels", 99.0); + rd_sum_add_var(rd_sum, "BPR", NULL, 567, "BARS", 0.0); + rd_sum_add_var(rd_sum, "WWCT", "OP-1", 0, "(1)", 0.0); + rd_sum_add_var(rd_sum, "WOPR", "OP-1", 0, "Barrels", 0.0); /* - The return value from the ecl_sum_add_var() function is an - ecl::smspec_node instance (implemented in file smspec_node.c); + The return value from the rd_sum_add_var() function is an + rd::smspec_node instance (implemented in file smspec_node.c); which is essentially a struct holding header information about this varible. There are several options on how to handle the - return value from the ecl_sum_add_var() function; which affect how + return value from the rd_sum_add_var() function; which affect how you can add data at a later stage: 1. You can just ignore it - that is not very clean; in this @@ -221,10 +221,10 @@ int main(int argc, char **argv) { */ - const ecl::smspec_node *wwct_wellx = - ecl_sum_add_var(ecl_sum, "WWCT", NULL, 0, "(1)", 0.0); - const ecl::smspec_node *wopr_wellx = - ecl_sum_add_var(ecl_sum, "WOPR", NULL, 0, "Barrels", 0.0); + const rd::smspec_node *wwct_wellx = + rd_sum_add_var(rd_sum, "WWCT", NULL, 0, "(1)", 0.0); + const rd::smspec_node *wopr_wellx = + rd_sum_add_var(rd_sum, "WOPR", NULL, 0, "Barrels", 0.0); { int num_dates = 10; @@ -240,7 +240,7 @@ int main(int argc, char **argv) { { /* Here we add a new timestep. The report steps are not - added explicitly; the ecl_sum layer will just see if this + added explicitly; the rd_sum layer will just see if this is a new report step. Observe that report_step == 1 is the first permissible report step. @@ -248,45 +248,45 @@ int main(int argc, char **argv) { element for each variable, and now we must set the various elements in the block. There are different ways to do this - depending on which metadata information we - are holding on to from the ecl_sum_add_var() calls. + are holding on to from the rd_sum_add_var() calls. Observe that one element for the number of simulation days has already been inserted in the timestep. The elements which are not set explicitly will have the - default value given in the ecl_sum_add_var() call. + default value given in the rd_sum_add_var() call. */ - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_days); + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_days); /* We can just set a value by it's index using the - ecl_sum_tstep_iset() function. The index value should come + rd_sum_tstep_iset() function. The index value should come from the smspec_get_params_index() function. */ - ecl_sum_tstep_iset(tstep, 3, 0.98); + rd_sum_tstep_iset(tstep, 3, 0.98); /* We can use the gen_key value to set the numerical values. The gen_key value should could from the smpec_get_gen_key1() function: */ - ecl_sum_tstep_set_from_key(tstep, "WWCT:OP-1", - sim_days / 10); + rd_sum_tstep_set_from_key(tstep, "WWCT:OP-1", + sim_days / 10); if (report_step >= 5) { /* We can use the smspec_node value from the - ecl_sum_add_var() function directly: + rd_sum_add_var() function directly: */ - ecl_sum_tstep_set_from_node(tstep, *wwct_wellx, - sim_days); - ecl_sum_tstep_set_from_node(tstep, *wopr_wellx, - sim_days * 100); + rd_sum_tstep_set_from_node(tstep, *wwct_wellx, + sim_days); + rd_sum_tstep_set_from_node(tstep, *wopr_wellx, + sim_days * 100); } } } } } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); } diff --git a/applications/ecl/view_summary.cpp b/applications/resdata/view_summary.cpp similarity index 84% rename from applications/ecl/view_summary.cpp rename to applications/resdata/view_summary.cpp index c132987931..35967113e7 100644 --- a/applications/ecl/view_summary.cpp +++ b/applications/resdata/view_summary.cpp @@ -11,8 +11,8 @@ #include #include -#include -#include +#include +#include void install_SIGNALS(void) { signal( @@ -28,16 +28,15 @@ void install_SIGNALS(void) { void print_help_and_exit() { printf( "\nThe summary.x program is used to quickly extract summary vectors\n"); - printf("from ECLIPSE summary files. The program is invoked as:\n"); + printf("from summary files. The program is invoked as:\n"); printf("\n"); - printf("computer> summary.x /Path/to/ECLIPSE key1 key2 key3 ....\n"); + printf("computer> summary.x /Path/to/CASE key1 key2 key3 ....\n"); printf("\n"); - printf( - "Here ECLIPSE is the name of an existing case, you can give it with\n"); + printf("Here CASE is the name of an existing case, you can give it with\n"); printf("extension, or without; the case need not be in the current " "directory. \n"); printf("\n"); - printf("The keys are formed by combining ECLIPSE variable names and\n"); + printf("The keys are formed by combining variable names and\n"); printf( "qualifiers from the WGNAMES and NUMS arrays. Examples of keys are:\n"); printf("\n"); @@ -76,7 +75,7 @@ void print_help_and_exit() { printf("\n"); printf(" --help: Print this message and exit.\n"); printf("\n"); - printf("The options should come before the ECLIPSE basename.\n"); + printf("The options should come before the basename.\n"); printf("\n"); printf("Example1:\n"); printf("\n"); @@ -114,21 +113,20 @@ void print_help_and_exit() { exit(1); } -static void build_key_list(const ecl_sum_type *ecl_sum, - stringlist_type *key_list, int argc, - const char **argv) { +static void build_key_list(const rd_sum_type *rd_sum, stringlist_type *key_list, + int argc, const char **argv) { int iarg; for (iarg = 0; iarg < argc; iarg++) { /** If the string does not contain wildcards we add it unconditionally; and then subsequently let the - ecl_sum_fprintf() function print a message on stderr about + rd_sum_fprintf() function print a message on stderr about missing keys. */ if (util_string_has_wildcard(argv[iarg])) - ecl_sum_select_matching_general_var_list(ecl_sum, argv[iarg], - key_list); + rd_sum_select_matching_general_var_list(rd_sum, argv[iarg], + key_list); else stringlist_append_copy(key_list, argv[iarg]); } @@ -193,17 +191,17 @@ int main(int argc, char **argv) { { char *data_file = argv[arg_offset]; - ecl_sum_type *ecl_sum; + rd_sum_type *rd_sum; int num_keys = argc - arg_offset - 1; const char **arg_list = (const char **)&argv[arg_offset + 1]; - ecl_sum = ecl_sum_fread_alloc_case2__(data_file, ":", - include_restart, true, 0); + rd_sum = rd_sum_fread_alloc_case2__(data_file, ":", include_restart, + true, 0); /** If no keys have been presented the function will list available keys. */ if (num_keys == 0) list_mode = true; - if (ecl_sum != NULL) { + if (rd_sum != NULL) { if (list_mode) { /* The program is called in list mode, we only print the @@ -214,11 +212,11 @@ int main(int argc, char **argv) { stringlist_type *keys = stringlist_alloc_new(); if (num_keys == 0) { - ecl_sum_select_matching_general_var_list(ecl_sum, "*", - keys); + rd_sum_select_matching_general_var_list(rd_sum, "*", + keys); stringlist_sort(keys, NULL); } else - build_key_list(ecl_sum, keys, num_keys, arg_list); + build_key_list(rd_sum, keys, num_keys, arg_list); { int columns = 5; @@ -233,21 +231,20 @@ int main(int argc, char **argv) { stringlist_free(keys); } else { /* Normal operation print results for the various keys on stdout. */ - ecl_sum_fmt_type fmt; + rd_sum_fmt_type fmt; stringlist_type *key_list = stringlist_alloc_new(); - build_key_list(ecl_sum, key_list, num_keys, arg_list); + build_key_list(rd_sum, key_list, num_keys, arg_list); if (print_header) - ecl_sum_fmt_init_summary_x(ecl_sum, &fmt); + rd_sum_fmt_init_summary_x(rd_sum, &fmt); else fmt.print_header = false; - ecl_sum_fprintf(ecl_sum, stdout, key_list, report_only, - &fmt); + rd_sum_fprintf(rd_sum, stdout, key_list, report_only, &fmt); stringlist_free(key_list); } - ecl_sum_free(ecl_sum); + rd_sum_free(rd_sum); } else fprintf(stderr, "summary.x: No summary data found for case:%s\n", diff --git a/applications/well/ri_well_test.c b/applications/well/ri_well_test.c index 7c8322e66c..705429b895 100644 --- a/applications/well/ri_well_test.c +++ b/applications/well/ri_well_test.c @@ -16,9 +16,9 @@ for more details. */ -#include -#include -#include +#include +#include +#include /* This is a small test program which will load the well information in @@ -36,7 +36,7 @@ int main(int argc, char **argv) { usage(); else { char *grid_file = argv[1]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); + rd_grid_type *grid = rd_grid_alloc(grid_file); well_info_type *well_info = well_info_alloc(grid); int ifile; for (ifile = 2; ifile < argc; ifile++) { @@ -45,7 +45,7 @@ int main(int argc, char **argv) { well_info_load_rstfile(well_info, rst_file, true); } - ecl_grid_free(grid); + rd_grid_free(grid); well_info_free(well_info); } } diff --git a/applications/well/segment_info.c b/applications/well/segment_info.c index 5eb1e77792..b5fec6fd8f 100644 --- a/applications/well/segment_info.c +++ b/applications/well/segment_info.c @@ -22,37 +22,37 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { const char *Xfile = argv[1]; - ecl_file_type *rst_file = ecl_file_open(Xfile, 0); - ecl_rsthead_type *rst_head = ecl_rsthead_alloc( - ecl_file_get_global_view(rst_file), ecl_util_filename_report_nr(Xfile)); - const ecl_kw_type *iwel_kw = ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - const ecl_kw_type *iseg_kw = ecl_file_iget_named_kw(rst_file, ISEG_KW, 0); + rd_file_type *rst_file = rd_file_open(Xfile, 0); + rd_rsthead_type *rst_head = rd_rsthead_alloc( + rd_file_get_global_view(rst_file), rd_filename_report_nr(Xfile)); + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + const rd_kw_type *iseg_kw = rd_file_iget_named_kw(rst_file, ISEG_KW, 0); well_rseg_loader_type *rseg_loader = - well_rseg_loader_alloc(ecl_file_get_global_view(rst_file)); - const ecl_kw_type *icon_kw = ecl_file_iget_named_kw(rst_file, ICON_KW, 0); - const ecl_kw_type *scon_kw = ecl_file_iget_named_kw(rst_file, SCON_KW, 0); - const ecl_kw_type *xcon_kw = ecl_file_iget_named_kw(rst_file, XCON_KW, 0); - const ecl_kw_type *zwel_kw = ecl_file_iget_named_kw(rst_file, ZWEL_KW, 0); + well_rseg_loader_alloc(rd_file_get_global_view(rst_file)); + const rd_kw_type *icon_kw = rd_file_iget_named_kw(rst_file, ICON_KW, 0); + const rd_kw_type *scon_kw = rd_file_iget_named_kw(rst_file, SCON_KW, 0); + const rd_kw_type *xcon_kw = rd_file_iget_named_kw(rst_file, XCON_KW, 0); + const rd_kw_type *zwel_kw = rd_file_iget_named_kw(rst_file, ZWEL_KW, 0); { int well_nr; for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { const int zwel_offset = rst_head->nzwelz * well_nr; char *well_name = - util_alloc_strip_copy(ecl_kw_iget_ptr(zwel_kw, zwel_offset)); + util_alloc_strip_copy(rd_kw_iget_ptr(zwel_kw, zwel_offset)); printf("===========================================================" "======\n"); @@ -77,7 +77,7 @@ int main(int argc, char **argv) { well_segment_collection_link(segments); well_segment_collection_add_branches(segments, branches); well_segment_collection_add_connections( - segments, ECL_GRID_GLOBAL_GRID, connections); + segments, RD_GRID_GLOBAL_GRID, connections); printf("\n"); printf("Segments:\n"); @@ -131,6 +131,6 @@ int main(int argc, char **argv) { } } - ecl_file_close(rst_file); - ecl_rsthead_free(rst_head); + rd_file_close(rst_file); + rd_rsthead_free(rst_head); } diff --git a/applications/well/well_CF_dump.c b/applications/well/well_CF_dump.c index 4daa7f5541..5f5bece82a 100644 --- a/applications/well/well_CF_dump.c +++ b/applications/well/well_CF_dump.c @@ -16,14 +16,14 @@ for more details. */ -#include -#include -#include +#include +#include +#include int main(int argc, char **argv) { char *grid_file = argv[1]; char *rst_file = argv[2]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); + rd_grid_type *grid = rd_grid_alloc(grid_file); well_info_type *well_info = well_info_alloc(grid); well_info_load_rstfile(well_info, rst_file, true); @@ -51,5 +51,5 @@ int main(int argc, char **argv) { } well_info_free(well_info); - ecl_grid_free(grid); + rd_grid_free(grid); } diff --git a/bin/summary_resample b/bin/summary_resample index 1a08006d2f..eccfb54131 100755 --- a/bin/summary_resample +++ b/bin/summary_resample @@ -1,8 +1,8 @@ #!/usr/bin/env python import sys import argparse -from ecl.summary import EclSum -from ecl.util.util import TimeVector, CTime +from resdata.summary import Summary +from resdata.util.util import TimeVector, CTime @@ -14,9 +14,9 @@ parser.add_argument("--refcase", metavar="refcase", type=str) parser.add_argument("--extrapolation", action="store_true") args = parser.parse_args() -input_case = EclSum(args.input_case) +input_case = Summary(args.input_case) if args.refcase: - refcase = EclSum(args.refcase) + refcase = Summary(args.refcase) report_only = False time_points = refcase.alloc_time_vector( report_only ) else: diff --git a/ci/github/setup.py b/ci/github/setup.py index acf9ee7e22..298b40b6bd 100644 --- a/ci/github/setup.py +++ b/ci/github/setup.py @@ -6,9 +6,9 @@ setup( - name="libecl", + name="resdata", author="Equinor ASA", author_email="fg_sib-scout@equinor.com", version=version, - install_requires=["ecl==" + version], + install_requires=["resdata==" + version], ) diff --git a/ci/testkomodo.sh b/ci/testkomodo.sh index 67345f7225..5a7c9a25a4 100755 --- a/ci/testkomodo.sh +++ b/ci/testkomodo.sh @@ -24,7 +24,7 @@ build_and_run_ctest () { pushd $CI_TEST_ROOT cmake $CI_SOURCE_ROOT \ -DBUILD_TESTS=ON \ - -DEQUINOR_TESTDATA_ROOT=$EQUINOR_TESTDATA_ROOT/ecl + -DEQUINOR_TESTDATA_ROOT=$EQUINOR_TESTDATA_ROOT/resdata cmake --build . ctest --output-on-failure popd diff --git a/cmake/libecl-config-version.cmake.in b/cmake/resdata-config-version.cmake.in similarity index 70% rename from cmake/libecl-config-version.cmake.in rename to cmake/resdata-config-version.cmake.in index 2f8df5a4e8..8bcb05bef1 100644 --- a/cmake/libecl-config-version.cmake.in +++ b/cmake/resdata-config-version.cmake.in @@ -3,12 +3,12 @@ set(PACKAGE_VERSION_MAJOR @ERT_VERSION_MAJOR@) set(PACKAGE_VERSION_MINOR @ERT_VERSION_MINOR@) set(PACKAGE_VERSION_PATCH @ERT_VERSION_MICRO@) -set(libecl_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include) -set(libecl_LIBRARIES -lecl_well -lecl -lert_geometry -lert_util) +set(resdata_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include) +set(resdata_LIBRARIES -lrd_well -lresdata -lert_geometry -lert_util) link_directories( @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ ) include_directories( @CMAKE_INSTALL_PREFIX@/include ) set( CMAKE_MODULE_PATH @CMAKE_INSTALL_PREFIX@/share/cmake/Modules ${CMAKE_MODULE_PATH}) if (@ENABLE_PYTHON@) - set(libecl_PYTHONPATH @CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_PREFIX@ ) + set(resdata_PYTHONPATH @CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_PREFIX@ ) endif() diff --git a/cmake/libecl-config.cmake.in b/cmake/resdata-config.cmake.in similarity index 54% rename from cmake/libecl-config.cmake.in rename to cmake/resdata-config.cmake.in index bf718e2e23..89606c3255 100644 --- a/cmake/libecl-config.cmake.in +++ b/cmake/resdata-config.cmake.in @@ -1,10 +1,10 @@ -set(libecl_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include) -set(libecl_LIBRARIES -lecl_well -lecl -lert_geometry -lert_util) +set(resdata_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/include) +set(resdata_LIBRARIES -lrd_well -lresdata -lert_geometry -lert_util) set( CMAKE_MODULE_PATH @CMAKE_INSTALL_PREFIX@/share/cmake/Modules ${CMAKE_MODULE_PATH}) link_directories( @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ ) include_directories( @CMAKE_INSTALL_PREFIX@/include ) if (@ENABLE_PYTHON@) - set(libecl_PYTHONPATH @CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_PREFIX@ ) + set(resdata_PYTHONPATH @CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_PREFIX@ ) endif() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index beee855372..9ad87bc5c1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -50,7 +50,7 @@ configure_file(build_config.hpp.in include/ert/util/build_config.hpp) configure_file(ert_api_config.hpp.in include/ert/util/ert_api_config.hpp) add_library( - ecl + resdata util/rng.cpp util/lookup_table.cpp util/statistics.cpp @@ -72,64 +72,64 @@ add_library( util/buffer.cpp util/string_util.cpp util/type_vector_functions.cpp - util/ecl_version.cpp + util/rd_version.cpp util/perm_vector.cpp util/test_util.cpp util/cxx_string_util.cpp ${opt_srcs} - ecl/ecl_rsthead.cpp - ecl/ecl_sum_tstep.cpp - ecl/ecl_rst_file.cpp - ecl/ecl_init_file.cpp - ecl/ecl_grid_cache.cpp - ecl/smspec_node.cpp - ecl/ecl_kw_grdecl.cpp - ecl/ecl_file_kw.cpp - ecl/ecl_file_view.cpp - ecl/ecl_grav.cpp - ecl/ecl_smspec.cpp - ecl/ecl_unsmry_loader.cpp - ecl/ecl_sum_data.cpp - ecl/ecl_sum_file_data.cpp - ecl/ecl_util.cpp - ecl/ecl_kw.cpp - ecl/ecl_sum.cpp - ecl/ecl_sum_vector.cpp - ecl/fortio.c - ecl/ecl_rft_file.cpp - ecl/ecl_rft_node.cpp - ecl/ecl_rft_cell.cpp - ecl/ecl_grid.cpp - ecl/ecl_coarse_cell.cpp - ecl/ecl_box.cpp - ecl/ecl_io_config.cpp - ecl/ecl_file.cpp - ecl/ecl_region.cpp - ecl/ecl_subsidence.cpp - ecl/ecl_grid_dims.cpp - ecl/grid_dims.cpp - ecl/nnc_info.cpp - ecl/ecl_grav_common.cpp - ecl/nnc_vector.cpp - ecl/ecl_nnc_export.cpp - ecl/ecl_nnc_data.cpp - ecl/ecl_nnc_geometry.cpp - ecl/layer.cpp - ecl/fault_block.cpp - ecl/fault_block_layer.cpp - ecl/ecl_type.cpp - ecl/ecl_type_python.cpp - ecl/well_state.cpp - ecl/well_conn.cpp - ecl/well_info.cpp - ecl/well_ts.cpp - ecl/well_conn_collection.cpp - ecl/well_segment.cpp - ecl/well_segment_collection.cpp - ecl/well_branch_collection.cpp - ecl/well_rseg_loader.cpp - ecl/FortIO.cpp - ecl/EclFilename.cpp + resdata/rd_rsthead.cpp + resdata/rd_sum_tstep.cpp + resdata/rd_rst_file.cpp + resdata/rd_init_file.cpp + resdata/rd_grid_cache.cpp + resdata/smspec_node.cpp + resdata/rd_kw_grdecl.cpp + resdata/rd_file_kw.cpp + resdata/rd_file_view.cpp + resdata/rd_grav.cpp + resdata/rd_smspec.cpp + resdata/rd_unsmry_loader.cpp + resdata/rd_sum_data.cpp + resdata/rd_sum_file_data.cpp + resdata/rd_util.cpp + resdata/rd_kw.cpp + resdata/rd_sum.cpp + resdata/rd_sum_vector.cpp + resdata/fortio.c + resdata/rd_rft_file.cpp + resdata/rd_rft_node.cpp + resdata/rd_rft_cell.cpp + resdata/rd_grid.cpp + resdata/rd_coarse_cell.cpp + resdata/rd_box.cpp + resdata/rd_io_config.cpp + resdata/rd_file.cpp + resdata/rd_region.cpp + resdata/rd_subsidence.cpp + resdata/rd_grid_dims.cpp + resdata/grid_dims.cpp + 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 + resdata/rd_type.cpp + resdata/rd_type_python.cpp + resdata/well_state.cpp + resdata/well_conn.cpp + resdata/well_info.cpp + resdata/well_ts.cpp + resdata/well_conn_collection.cpp + resdata/well_segment.cpp + resdata/well_segment_collection.cpp + resdata/well_branch_collection.cpp + resdata/well_rseg_loader.cpp + resdata/FortIO.cpp + resdata/RDFilename.cpp geometry/geo_surface.cpp geometry/geo_util.cpp geometry/geo_pointset.cpp @@ -138,19 +138,19 @@ add_library( geometry/geo_polygon_collection.cpp) if(ERT_WINDOWS) - set_target_properties(ecl PROPERTIES PREFIX "lib") + set_target_properties(resdata PROPERTIES PREFIX "lib") if(MSVC) - set_target_properties(ecl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) + set_target_properties(resdata PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() endif() target_link_libraries( - ecl + resdata PUBLIC ${m} ${dl} ${pthread} ${blas} ${zlib} ${shlwapi} PRIVATE Backward::Backward fmt::fmt) target_include_directories( - ecl + resdata PUBLIC $ $ $ @@ -159,32 +159,32 @@ target_include_directories( ${CMAKE_CURRENT_BINARY_DIR}/include) target_compile_definitions( - ecl + resdata PRIVATE -DGIT_COMMIT=${GIT_COMMIT} -DGIT_COMMIT_SHORT=${GIT_COMMIT_SHORT} - -DECL_VERSION_MAJOR=${ECL_VERSION_MAJOR} - -DECL_VERSION_MINOR=${ECL_VERSION_MINOR} - -DECL_VERSION_MICRO=${ECL_VERSION_MICRO} + -DRD_VERSION_MAJOR=${RD_VERSION_MAJOR} + -DRD_VERSION_MINOR=${RD_VERSION_MINOR} + -DRD_VERSION_MICRO=${RD_VERSION_MICRO} $<$:HOST_BIG_ENDIAN>) -target_compile_options(ecl PUBLIC ${pthreadarg}) +target_compile_options(resdata PUBLIC ${pthreadarg}) if(ERT_USE_OPENMP) - target_compile_options(ecl PUBLIC ${OpenMP_CXX_FLAGS}) + target_compile_options(resdata PUBLIC ${OpenMP_CXX_FLAGS}) set_property( - TARGET ecl + TARGET resdata APPEND PROPERTY LINK_FLAGS ${OpenMP_CXX_FLAGS}) - target_link_libraries(ecl PUBLIC ${OpenMP_EXE_LINKER_FLAGS}) + target_link_libraries(resdata PUBLIC ${OpenMP_EXE_LINKER_FLAGS}) endif() set_target_properties( - ecl PROPERTIES VERSION ${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR} - SOVERSION ${ECL_VERSION_MAJOR}) + resdata PROPERTIES VERSION ${RD_VERSION_MAJOR}.${RD_VERSION_MINOR} + SOVERSION ${RD_VERSION_MAJOR}) install( - TARGETS ecl - EXPORT ecl-config + TARGETS resdata + EXPORT resdata-config ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -196,20 +196,20 @@ if(NOT BUILD_TESTS) return() endif() -add_executable(ecl_test_suite tests/test_ecl_grid.cpp tests/test_ecl_util.cpp - tests/testsuite.cpp tests/test_util.cpp) +add_executable(rd_test_suite tests/test_rd_grid.cpp tests/test_rd_util.cpp + tests/testsuite.cpp tests/test_util.cpp) if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) - target_compile_options(ecl_test_suite PRIVATE -DFS_EXPERIMENTAL) + target_compile_options(rd_test_suite PRIVATE -DFS_EXPERIMENTAL) else() - target_compile_options(ecl_test_suite PRIVATE "--std=c++17") + target_compile_options(rd_test_suite PRIVATE "--std=c++17") endif() - target_link_libraries(ecl_test_suite ecl Catch2::Catch2WithMain stdc++fs) + target_link_libraries(rd_test_suite resdata Catch2::Catch2WithMain stdc++fs) else() - target_compile_options(ecl_test_suite PRIVATE "--std=c++17") - target_link_libraries(ecl_test_suite ecl Catch2::Catch2WithMain) + target_compile_options(rd_test_suite PRIVATE "--std=c++17") + target_link_libraries(rd_test_suite resdata Catch2::Catch2WithMain) endif() -add_test(NAME ecl_test_suite COMMAND ecl_test_suite) +add_test(NAME rd_test_suite COMMAND rd_test_suite) foreach( name @@ -243,16 +243,16 @@ foreach( add_executable(${name} util/tests/${name}.cpp) target_include_directories( ${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include) - target_link_libraries(${name} ecl) + target_link_libraries(${name} resdata) add_test(NAME ${name} COMMAND ${name}) endforeach() -add_executable(ecl_smspec_node ecl/tests/ecl_smspec_node.cpp) -target_link_libraries(ecl_smspec_node ecl) -add_test(NAME ecl_smspec_node COMMAND ecl_smspec_node) +add_executable(rd_smspec_node resdata/tests/rd_smspec_node.cpp) +target_link_libraries(rd_smspec_node resdata) +add_test(NAME rd_smspec_node COMMAND rd_smspec_node) add_executable(ert_util_work_area util/tests/ert_util_work_area.cpp) -target_link_libraries(ert_util_work_area ecl) +target_link_libraries(ert_util_work_area resdata) add_test( NAME ert_util_work_area COMMAND ert_util_work_area data2/file1 @@ -260,85 +260,81 @@ add_test( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/util/tests) add_executable(ert_util_cwd_test util/tests/ert_util_cwd_test.cpp) -target_link_libraries(ert_util_cwd_test ecl) +target_link_libraries(ert_util_cwd_test resdata) add_test(NAME ert_util_cwd_test COMMAND ert_util_cwd_test ${CMAKE_CURRENT_BINARY_DIR}) add_executable(ert_util_copy_file util/tests/ert_util_copy_file.cpp) -target_link_libraries(ert_util_copy_file ecl) +target_link_libraries(ert_util_copy_file resdata) add_test(NAME ert_util_copy_file COMMAND ert_util_copy_file $) add_executable(ert_util_file_readable util/tests/ert_util_file_readable.cpp) -target_link_libraries(ert_util_file_readable ecl) +target_link_libraries(ert_util_file_readable resdata) add_test(NAME ert_util_file_readable COMMAND ert_util_file_readable) add_executable(ert_util_path_stack_test util/tests/ert_util_path_stack_test.cpp) -target_link_libraries(ert_util_path_stack_test ecl) +target_link_libraries(ert_util_path_stack_test resdata) add_test(NAME ert_util_path_stack_test COMMAND ert_util_path_stack_test ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_executable(ert_util_abort_gnu_tests util/tests/ert_util_abort_gnu_tests.cpp) -target_link_libraries(ert_util_abort_gnu_tests ecl) +target_link_libraries(ert_util_abort_gnu_tests resdata) add_test(NAME ert_util_abort_gnu_tests COMMAND ert_util_abort_gnu_tests) add_executable(ert_util_type_vector_test util/tests/ert_util_type_vector_test.cpp) -target_link_libraries(ert_util_type_vector_test ecl) +target_link_libraries(ert_util_type_vector_test resdata) add_test(NAME ert_util_type_vector_test COMMAND ert_util_type_vector_test) if(ERT_HAVE_SPAWN) add_executable(ert_util_spawn util/tests/ert_util_spawn.cpp) - target_link_libraries(ert_util_spawn ecl) + target_link_libraries(ert_util_spawn resdata) add_test(NAME ert_util_spawn COMMAND ert_util_spawn) endif() -# -# ecl -# - foreach( name - ecl_fault_block_layer - ecl_util_path_access - ecl_grid_add_nnc - ecl_grid_copy - ecl_grid_create - ecl_grid_unit_system - ecl_grid_export - ecl_grid_init_fwrite - ecl_grid_reset_actnum - ecl_grid_ext_actnum - ecl_nnc_export_intersect - ecl_sum_restart - ecl_sum_data_intermediate_test - ecl_grid_cell_contains - ecl_unsmry_loader_test - ecl_init_file - ecl_kw_space_pad - ecl_kw_cmp_string - ecl_kw_equal - ecl_kw_fread - ecl_kw_grdecl - ecl_kw_init - ecl_nnc_geometry - ecl_nnc_info_test - ecl_nnc_vector - ecl_rft_cell - ecl_sum_alloc_resampled_test - ecl_file_view - test_ecl_file_index + rd_fault_block_layer + rd_path_access + rd_grid_add_nnc + rd_grid_copy + rd_grid_create + rd_grid_unit_system + rd_grid_export + rd_grid_init_fwrite + rd_grid_reset_actnum + rd_grid_ext_actnum + rd_nnc_export_intersect + rd_sum_restart + rd_sum_data_intermediate_test + rd_grid_cell_contains + rd_unsmry_loader_test + rd_init_file + rd_kw_space_pad + rd_kw_cmp_string + rd_kw_equal + rd_kw_fread + rd_kw_grdecl + rd_kw_init + rd_nnc_geometry + rd_nnc_info_test + rd_nnc_vector + rd_rft_cell + rd_sum_alloc_resampled_test + rd_file_view + test_rd_file_index test_transactions - ecl_rst_file - ecl_sum_writer - ecl_util_filenames - ecl_util_make_date_no_shift - ecl_util_make_date_shift - ecl_util_month_range - ecl_valid_basename - test_ecl_nnc_data - ecl_nnc_pair + rd_rst_file + rd_sum_writer + rd_filenames + rd_make_date_no_shift + rd_make_date_shift + rd_month_range + rd_valid_basename + test_rd_nnc_data + rd_nnc_pair well_conn_collection well_branch_collection well_conn @@ -346,42 +342,42 @@ foreach( well_segment well_segment_conn well_segment_collection - ecl_file) - add_executable(${name} ecl/tests/${name}.cpp) - target_link_libraries(${name} ecl) + rd_file) + add_executable(${name} resdata/tests/${name}.cpp) + target_link_libraries(${name} resdata) target_include_directories( ${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include) add_test(NAME ${name} COMMAND ${name}) endforeach() if(HAVE_UTIL_ABORT_INTERCEPT) - add_executable(ecl_grid_corner ecl/tests/ecl_grid_corner.cpp) - target_link_libraries(ecl_grid_corner ecl) - add_test(NAME ecl_grid_corner COMMAND ecl_grid_corner) + add_executable(rd_grid_corner resdata/tests/rd_grid_corner.cpp) + target_link_libraries(rd_grid_corner resdata) + add_test(NAME rd_grid_corner COMMAND rd_grid_corner) - add_executable(ecl_layer ecl/tests/ecl_layer.cpp) - target_link_libraries(ecl_layer ecl) + add_executable(rd_layer resdata/tests/rd_layer.cpp) + target_link_libraries(rd_layer resdata) target_include_directories( - ecl_layer PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include) - add_test(NAME ecl_layer COMMAND ecl_layer) + rd_layer PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include) + add_test(NAME rd_layer COMMAND rd_layer) endif() -add_executable(ecl_get_num_cpu ecl/tests/ecl_get_num_cpu_test.cpp) -target_link_libraries(ecl_get_num_cpu ecl) +add_executable(rd_get_num_cpu resdata/tests/rd_get_num_cpu_test.cpp) +target_link_libraries(rd_get_num_cpu resdata) add_test( - NAME ecl_get_num_cpu + NAME rd_get_num_cpu COMMAND - ecl_get_num_cpu ${CMAKE_CURRENT_SOURCE_DIR}/ecl/tests/data/num_cpu1 - ${CMAKE_CURRENT_SOURCE_DIR}/ecl/tests/data/num_cpu2 - ${CMAKE_CURRENT_SOURCE_DIR}/ecl/tests/data/num_cpu3 - ${CMAKE_CURRENT_SOURCE_DIR}/ecl/tests/data/num_cpu4 - ${CMAKE_CURRENT_SOURCE_DIR}/ecl/tests/data/num_cpu5) + rd_get_num_cpu ${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu1 + ${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu2 + ${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu3 + ${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu4 + ${CMAKE_CURRENT_SOURCE_DIR}/resdata/tests/data/num_cpu5) -# The ecl_win64 application is not built as a proper test integrated into the +# The rd_win64 application is not built as a proper test integrated into the # CTEST system. Should be invoked manually on Windows. if(ERT_WINDOWS) - add_executable(ecl_lfs ecl/tests/ecl_lfs.cpp) - target_link_libraries(ecl_lfs ecl) + add_executable(rd_lfs resdata/tests/rd_lfs.cpp) + target_link_libraries(rd_lfs resdata) endif() # @@ -390,51 +386,51 @@ endif() foreach(name geo_util_xlines geo_polygon geo_polygon_collection) add_executable(${name} geometry/tests/${name}.cpp) - target_link_libraries(${name} ecl) + target_link_libraries(${name} resdata) add_test(NAME ${name} COMMAND ${name}) endforeach() foreach(test ert_util_unique_ptr) add_executable(${test} util/tests/${test}.cpp) - target_link_libraries(${test} ecl) + target_link_libraries(${test} resdata) add_test(NAME ${test} COMMAND ${test}) endforeach() -foreach(test eclxx_kw eclxx_fortio eclxx_filename eclxx_types) - add_executable(${test} ecl/tests/${test}.cpp) - target_link_libraries(${test} ecl) +foreach(test rdxx_kw rdxx_fortio rdxx_filename rdxx_types) + add_executable(${test} resdata/tests/${test}.cpp) + target_link_libraries(${test} resdata) add_test(NAME ${test} COMMAND ${test}) endforeach() foreach( name - ecl_coarse_test - ecl_grid_layer_contains - ecl_restart_test - ecl_nnc_export - ecl_nnc_export_get_tran - ecl_nnc_data_equinor_root - ecl_sum_case_exists - ecl_grid_lgr_name - ecl_region - ecl_grid_cell_contains_wellpath - ecl_region2region - ecl_grid_volume - ecl_grid_dims - ecl_nnc_test - ecl_lgr_test - ecl_layer_equinor - ecl_dualp - ecl_grid_dx_dy_dz - ecl_sum_test - ecl_sum_report_step_equal - ecl_sum_report_step_compatible - ecl_file_equinor - ecl_fmt - ecl_rsthead - ecl_smspec - ecl_rft - ecl_fault_block_layer_equinor + rd_coarse_test + rd_grid_layer_contains + rd_restart_test + rd_nnc_export + rd_nnc_export_get_tran + rd_nnc_data_equinor_root + rd_sum_case_exists + rd_grid_lgr_name + rd_region + rd_grid_cell_contains_wellpath + rd_region2region + rd_grid_volume + rd_grid_dims + rd_nnc_test + rd_lgr_test + rd_layer_equinor + rd_dualp + rd_grid_dx_dy_dz + rd_sum_test + rd_sum_report_step_equal + rd_sum_report_step_compatible + rd_file_equinor + rd_fmt + rd_rsthead + rd_smspec + rd_rft + rd_fault_block_layer_equinor well_state_load well_state_load_missing_RSEG well_segment_load @@ -446,16 +442,17 @@ foreach( well_dualp well_lgr_load) - add_executable(${name} ecl/tests/${name}.cpp) - target_link_libraries(${name} ecl) + add_executable(${name} resdata/tests/${name}.cpp) + target_link_libraries(${name} resdata) target_include_directories( ${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/private-include) endforeach() -foreach(name ecl_grid_layer_contains ecl_region ecl_grid_copy) +foreach(name rd_grid_layer_contains rd_region rd_grid_copy) foreach(i RANGE 1 7) add_test(NAME ${name}_faarikaal${i} - COMMAND ${name} ${_local_eclpath}/faarikaal/faarikaal${i}.EGRID) + COMMAND ${name} + ${_local_resdatapath}/faarikaal/faarikaal${i}.EGRID) endforeach() endforeach() @@ -463,275 +460,285 @@ if(NOT EQUINOR_TESTDATA_ROOT) return() endif() -add_test(NAME ecl_grid_dx_dy_dz_gurbat COMMAND ecl_grid_dx_dy_dz - ${_eclpath}/Gurbat/ECLIPSE) -add_test(NAME ecl_grid_dx_dy_dz_troll - COMMAND ecl_grid_dx_dy_dz ${_eclpath}/Troll/Ref2014/T07-4A-W2014-06) - -add_test(NAME ecl_coarse_test COMMAND ecl_coarse_test - ${_eclpath}/LGCcase/LGC_TESTCASE2) - -add_test(NAME ecl_restart_test COMMAND ecl_restart_test - ${_eclpath}/Gurbat/ECLIPSE.UNRST) - -add_test(NAME ecl_nnc_export_gurbat COMMAND ecl_nnc_export - ${_eclpath}/Gurbat/ECLIPSE TRUE) -add_test(NAME ecl_nnc_export_10kcase - COMMAND ecl_nnc_export ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC TRUE) -add_test(NAME ecl_nnc_export_dual_poro_diff - COMMAND ecl_nnc_export ${_eclpath}/DualPoro/DUAL_DIFF TRUE) -add_test(NAME ecl_nnc_export_dual_poro - COMMAND ecl_nnc_export ${_eclpath}/DualPoro/DUALPORO TRUE) -add_test(NAME ecl_nnc_export_nested_lgr_case - COMMAND ecl_nnc_export ${_eclpath}/nestedLGRcase/TESTCASE_NESTEDLGR +add_test(NAME rd_grid_dx_dy_dz_gurbat COMMAND rd_grid_dx_dy_dz + ${_resdatapath}/Gurbat/ECLIPSE) +add_test(NAME rd_grid_dx_dy_dz_troll + COMMAND rd_grid_dx_dy_dz ${_resdatapath}/Troll/Ref2014/T07-4A-W2014-06) + +add_test(NAME rd_coarse_test COMMAND rd_coarse_test + ${_resdatapath}/LGCcase/LGC_TESTCASE2) + +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 ecl_nnc_export_tyrihans - COMMAND ecl_nnc_export ${_eclpath}/TYRIHANS/BASE20150218_MULTFLT FALSE) +add_test(NAME rd_nnc_export_tyrihans + COMMAND rd_nnc_export ${_resdatapath}/TYRIHANS/BASE20150218_MULTFLT + FALSE) add_test( - NAME ecl_nnc_export_get_tran - COMMAND ecl_nnc_export_get_tran - ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3) + 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 ecl_nnc_data_equinor_root + NAME rd_nnc_data_equinor_root COMMAND - ecl_nnc_data_equinor_root - ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3 - ${_eclpath}/flow-nnc/Simple4/SIMPLE_SUMMARY4) + rd_nnc_data_equinor_root + ${_resdatapath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3 + ${_resdatapath}/flow-nnc/Simple4/SIMPLE_SUMMARY4) add_test( - NAME ecl_sum_case_exists + NAME rd_sum_case_exists COMMAND - ecl_sum_case_exists ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/GurbatSummary/missingHeader/ECLIPSE - ${_eclpath}/GurbatSummary/missingData/ECLIPSE) + rd_sum_case_exists ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/GurbatSummary/missingHeader/ECLIPSE + ${_resdatapath}/GurbatSummary/missingData/ECLIPSE) add_test( - NAME ecl_grid_lgr_name + NAME rd_grid_lgr_name COMMAND - ecl_grid_lgr_name - ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID) + rd_grid_lgr_name + ${_resdatapath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID) add_test( - NAME ecl_grid_cell_contains_wellpath1 + NAME rd_grid_cell_contains_wellpath1 COMMAND - ecl_grid_cell_contains_wellpath ${_eclpath}/CellContains/model/SMS-0.EGRID - ${_eclpath}/CellContains/R_PB-4H.jira) + rd_grid_cell_contains_wellpath + ${_resdatapath}/CellContains/model/SMS-0.EGRID + ${_resdatapath}/CellContains/R_PB-4H.jira) -add_test(NAME ecl_region2region COMMAND ecl_region2region - ${_eclpath}/R2R/R2R.SMSPEC) +add_test(NAME rd_region2region COMMAND rd_region2region + ${_resdatapath}/R2R/R2R.SMSPEC) -add_test(NAME ecl_lgr_test1 - COMMAND ecl_lgr_test ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID) -add_test(NAME ecl_lgr_test2 - COMMAND ecl_lgr_test ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.GRID) +add_test(NAME rd_lgr_test1 + COMMAND rd_lgr_test ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID) +add_test(NAME rd_lgr_test2 + COMMAND rd_lgr_test ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.GRID) add_test( - NAME ecl_lgr_test3 + NAME rd_lgr_test3 COMMAND - ecl_lgr_test - ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID) - -add_test(NAME ecl_grid_volume1 COMMAND ecl_grid_volume - ${_eclpath}/Gurbat/ECLIPSE) -add_test(NAME ecl_grid_volume2 COMMAND ecl_grid_volume - ${_eclpath}/VolumeTest/TEST1) -add_test(NAME ecl_grid_volume3 COMMAND ecl_grid_volume - ${_eclpath}/OsebergSyd/Omega/OMEGA-0) -add_test(NAME ecl_grid_volume4 - COMMAND ecl_grid_volume - ${_eclpath}/Norne/reservoir_models/Norne_ATW2013/NORNE_ATW2013) + rd_lgr_test + ${_resdatapath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID) + +add_test(NAME rd_grid_volume1 COMMAND rd_grid_volume + ${_resdatapath}/Gurbat/ECLIPSE) +add_test(NAME rd_grid_volume2 COMMAND rd_grid_volume + ${_resdatapath}/VolumeTest/TEST1) +add_test(NAME rd_grid_volume3 COMMAND rd_grid_volume + ${_resdatapath}/OsebergSyd/Omega/OMEGA-0) +add_test( + NAME rd_grid_volume4 + COMMAND rd_grid_volume + ${_resdatapath}/Norne/reservoir_models/Norne_ATW2013/NORNE_ATW2013) # The grid volume test fails miserably on the test case given as example five; # looking at the failures one could actually suspect that the ECLIPSE algorithm # for PORV calculations has been different in this file - i.e. that the absolute # value of the individual tetrahedron parts have been taken during the sum, and # not at the end. At least the ert algorithm gets volumes ~ 0 whereas ECLIPSE -# reports ~10^9 for the same cell. add_test( ecl_grid_volume5 -# ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_volume -# ${_eclpath}/Heidrun/Summary/FF12_2013B3_CLEAN_RS) - -add_test(NAME ecl_grid_dims0 COMMAND ecl_grid_dims) -add_test(NAME ecl_grid_dims1 - COMMAND ecl_grid_dims ${_eclpath}/Gurbat/ECLIPSE.EGRID - ${_eclpath}/Gurbat/ECLIPSE.INIT) -add_test(NAME ecl_grid_dims2 - COMMAND ecl_grid_dims ${_eclpath}/Gurbat/ECLIPSE.GRID - ${_eclpath}/Gurbat/ECLIPSE.INIT) -add_test(NAME ecl_grid_dims3 COMMAND ecl_grid_dims - ${_eclpath}/Gurbat/ECLIPSE.EGRID) -add_test(NAME ecl_grid_dims4 COMMAND ecl_grid_dims - ${_eclpath}/Gurbat/ECLIPSE.GRID) -add_test(NAME ecl_grid_dims5 - COMMAND ecl_grid_dims - ${_eclpath}/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID) - -add_test(NAME ecl_nnc_test1 COMMAND ecl_nnc_test - ${_eclpath}/Gurbat/ECLIPSE.EGRID) -add_test(NAME ecl_nnc_test2 - COMMAND ecl_nnc_test ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID) +# reports ~10^9 for the same cell. add_test( rd_grid_volume5 +# ${EXECUTABLE_OUTPUT_PATH}/rd_grid_volume +# ${_resdatapath}/Heidrun/Summary/FF12_2013B3_CLEAN_RS) + +add_test(NAME rd_grid_dims0 COMMAND rd_grid_dims) +add_test(NAME rd_grid_dims1 + COMMAND rd_grid_dims ${_resdatapath}/Gurbat/ECLIPSE.EGRID + ${_resdatapath}/Gurbat/ECLIPSE.INIT) +add_test(NAME rd_grid_dims2 + COMMAND rd_grid_dims ${_resdatapath}/Gurbat/ECLIPSE.GRID + ${_resdatapath}/Gurbat/ECLIPSE.INIT) +add_test(NAME rd_grid_dims3 COMMAND rd_grid_dims + ${_resdatapath}/Gurbat/ECLIPSE.EGRID) +add_test(NAME rd_grid_dims4 COMMAND rd_grid_dims + ${_resdatapath}/Gurbat/ECLIPSE.GRID) +add_test(NAME rd_grid_dims5 + COMMAND rd_grid_dims + ${_resdatapath}/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID) + +add_test(NAME rd_nnc_test1 COMMAND rd_nnc_test + ${_resdatapath}/Gurbat/ECLIPSE.EGRID) +add_test(NAME rd_nnc_test2 + COMMAND rd_nnc_test ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID) add_test( - NAME ecl_nnc_test3 + NAME rd_nnc_test3 COMMAND - ecl_nnc_test - ${_eclpath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID) -add_test(NAME ecl_nnc_test4 COMMAND ecl_nnc_test - ${_eclpath}/DualPoro/DUAL_DIFF.EGRID) -add_test(NAME ecl_nnc_test5 - COMMAND ecl_nnc_test - ${_eclpath}/nestedLGRcase/TESTCASE_NESTEDLGR.EGRID) - -add_test(NAME ecl_layer_equinor - COMMAND ecl_layer_equinor ${_eclpath}/Mariner/MARINER.EGRID - ${_eclpath}/Mariner/faultblock.grdecl) - -add_test(NAME ecl_dualp COMMAND ecl_dualp ${_eclpath}/LGCcase/LGC_TESTCASE2) - -add_test(NAME ecl_sum_test COMMAND ecl_sum_test ${_eclpath}/Gurbat/ECLIPSE) - -add_test(NAME ecl_sum_report_step_equal1 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/Snorre/SNORRE FALSE) -add_test(NAME ecl_sum_report_step_equal2 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/Gurbat/ECLIPSE TRUE) -add_test(NAME ecl_sum_report_step_equal3 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/modGurbat/extraMinistep/ECLIPSE TRUE) -add_test(NAME ecl_sum_report_step_equal4 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/modGurbat/short/ECLIPSE FALSE) -add_test(NAME ecl_sum_report_step_equal5 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/modGurbat/enkf/ECLIPSE FALSE) -add_test(NAME ecl_sum_report_step_equal6 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Snorre/SNORRE - ${_eclpath}/Snorre2/SNORRE2 FALSE) - -add_test(NAME ecl_sum_report_step_compatible1 - COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/Snorre/SNORRE FALSE) -add_test(NAME ecl_sum_report_step_compatible2 - COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/Gurbat/ECLIPSE TRUE) -add_test(NAME ecl_sum_report_step_compatible3 - COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/modGurbat/extraMinistep/ECLIPSE TRUE) -add_test(NAME ecl_sum_report_step_compatible4 - COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/modGurbat/short/ECLIPSE TRUE) -add_test(NAME ecl_sum_report_step_compatible5 - COMMAND ecl_sum_report_step_compatible ${_eclpath}/Gurbat/ECLIPSE - ${_eclpath}/modGurbat/enkf/ECLIPSE TRUE) -add_test(NAME ecl_sum_report_step_compatible6 - COMMAND ecl_sum_report_step_equal ${_eclpath}/Snorre/SNORRE - ${_eclpath}/Snorre2/SNORRE2 FALSE) - -add_test(NAME ecl_file_equinor - COMMAND ecl_file_equinor ${_eclpath}/Gurbat/ECLIPSE.UNRST + rd_nnc_test + ${_resdatapath}/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID) +add_test(NAME rd_nnc_test4 COMMAND rd_nnc_test + ${_resdatapath}/DualPoro/DUAL_DIFF.EGRID) +add_test(NAME rd_nnc_test5 + COMMAND rd_nnc_test + ${_resdatapath}/nestedLGRcase/TESTCASE_NESTEDLGR.EGRID) + +add_test(NAME rd_layer_equinor + COMMAND rd_layer_equinor ${_resdatapath}/Mariner/MARINER.EGRID + ${_resdatapath}/Mariner/faultblock.grdecl) + +add_test(NAME rd_dualp COMMAND rd_dualp ${_resdatapath}/LGCcase/LGC_TESTCASE2) + +add_test(NAME rd_sum_test COMMAND rd_sum_test ${_resdatapath}/Gurbat/ECLIPSE) + +add_test(NAME rd_sum_report_step_equal1 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/Snorre/SNORRE FALSE) +add_test(NAME rd_sum_report_step_equal2 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/Gurbat/ECLIPSE TRUE) +add_test(NAME rd_sum_report_step_equal3 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/modGurbat/extraMinistep/ECLIPSE TRUE) +add_test(NAME rd_sum_report_step_equal4 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/modGurbat/short/ECLIPSE FALSE) +add_test(NAME rd_sum_report_step_equal5 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/modGurbat/enkf/ECLIPSE FALSE) +add_test(NAME rd_sum_report_step_equal6 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Snorre/SNORRE + ${_resdatapath}/Snorre2/SNORRE2 FALSE) + +add_test(NAME rd_sum_report_step_compatible1 + COMMAND rd_sum_report_step_compatible ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/Snorre/SNORRE FALSE) +add_test(NAME rd_sum_report_step_compatible2 + COMMAND rd_sum_report_step_compatible ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/Gurbat/ECLIPSE TRUE) +add_test(NAME rd_sum_report_step_compatible3 + COMMAND rd_sum_report_step_compatible ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/modGurbat/extraMinistep/ECLIPSE TRUE) +add_test(NAME rd_sum_report_step_compatible4 + COMMAND rd_sum_report_step_compatible ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/modGurbat/short/ECLIPSE TRUE) +add_test(NAME rd_sum_report_step_compatible5 + COMMAND rd_sum_report_step_compatible ${_resdatapath}/Gurbat/ECLIPSE + ${_resdatapath}/modGurbat/enkf/ECLIPSE TRUE) +add_test(NAME rd_sum_report_step_compatible6 + COMMAND rd_sum_report_step_equal ${_resdatapath}/Snorre/SNORRE + ${_resdatapath}/Snorre2/SNORRE2 FALSE) + +add_test(NAME rd_file_equinor + COMMAND rd_file_equinor ${_resdatapath}/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST) -add_test(NAME ecl_rsthead COMMAND ecl_rsthead ${_eclpath}/Gurbat/ECLIPSE.UNRST - ${_eclpath}/DualPoro/DUALPORO.X0005) +add_test(NAME rd_rsthead + COMMAND rd_rsthead ${_resdatapath}/Gurbat/ECLIPSE.UNRST + ${_resdatapath}/DualPoro/DUALPORO.X0005) -add_test(NAME ecl_smspec - COMMAND ecl_smspec ${_eclpath}/Gurbat/ECLIPSE.SMSPEC - ${_eclpath}/Heidrun/Summary/FF12_2013B3_CLEAN_RS.SMSPEC) +add_test(NAME rd_smspec + COMMAND rd_smspec ${_resdatapath}/Gurbat/ECLIPSE.SMSPEC + ${_resdatapath}/Heidrun/Summary/FF12_2013B3_CLEAN_RS.SMSPEC) -add_test(NAME ecl_rft_rft COMMAND ecl_rft ${_eclpath}/Gurbat/ECLIPSE.RFT RFT) -add_test(NAME ecl_rft_rft_rw COMMAND ecl_rft ${_eclpath}/Gurbat/ECLIPSE.RFT - RFT_RW) -add_test(NAME ecl_rft_plt COMMAND ecl_rft ${_eclpath}/RFT/TEST1_1A.RFT PLT) -add_test(NAME ecl_rft_mswplt COMMAND ecl_rft ${_eclpath}/RFT/RFT2.RFT MSW-PLT) -add_test(NAME ecl_rft_alloc - COMMAND ecl_rft ${_eclpath}/RFT/NORNE_ATW2013_RFTPLT_V2.RFT SIMPLE) +add_test(NAME rd_rft_rft COMMAND rd_rft ${_resdatapath}/Gurbat/ECLIPSE.RFT RFT) +add_test(NAME rd_rft_rft_rw COMMAND rd_rft ${_resdatapath}/Gurbat/ECLIPSE.RFT + RFT_RW) +add_test(NAME rd_rft_plt COMMAND rd_rft ${_resdatapath}/RFT/TEST1_1A.RFT PLT) +add_test(NAME rd_rft_mswplt COMMAND rd_rft ${_resdatapath}/RFT/RFT2.RFT MSW-PLT) +add_test(NAME rd_rft_alloc + COMMAND rd_rft ${_resdatapath}/RFT/NORNE_ATW2013_RFTPLT_V2.RFT SIMPLE) add_test( - NAME ecl_fault_block_layer_equinor - COMMAND ecl_fault_block_layer_equinor ${_eclpath}/Mariner/MARINER.EGRID - ${_eclpath}/Mariner/faultblock.grdecl) + NAME rd_fault_block_layer_equinor + COMMAND rd_fault_block_layer_equinor ${_resdatapath}/Mariner/MARINER.EGRID + ${_resdatapath}/Mariner/faultblock.grdecl) if(HAVE_UTIL_ABORT_INTERCEPT) - add_executable(ecl_fortio ecl/tests/ecl_fortio.cpp) - target_link_libraries(ecl_fortio ecl) - add_test(NAME ecl_fortio COMMAND ecl_fortio ${_eclpath}/Gurbat/ECLIPSE.UNRST) + add_executable(rd_fortio resdata/tests/rd_fortio.cpp) + target_link_libraries(rd_fortio resdata) + add_test(NAME rd_fortio COMMAND rd_fortio + ${_resdatapath}/Gurbat/ECLIPSE.UNRST) endif() add_test(NAME well_state_load1 - COMMAND well_state_load ${_eclpath}/Gurbat/ECLIPSE.EGRID - ${_eclpath}/Gurbat/ECLIPSE.X0030) + COMMAND well_state_load ${_resdatapath}/Gurbat/ECLIPSE.EGRID + ${_resdatapath}/Gurbat/ECLIPSE.X0030) add_test(NAME well_state_load2 - COMMAND well_state_load ${_eclpath}/MSWcase/MSW_CASE.EGRID - ${_eclpath}/MSWcase/MSW_CASE.X0021) + COMMAND well_state_load ${_resdatapath}/MSWcase/MSW_CASE.EGRID + ${_resdatapath}/MSWcase/MSW_CASE.X0021) add_test(NAME well_state_load3 - COMMAND well_state_load ${_eclpath}/Troll/MSW/MSW.EGRID - ${_eclpath}/Troll/MSW/MSW.X0123) + COMMAND well_state_load ${_resdatapath}/Troll/MSW/MSW.EGRID + ${_resdatapath}/Troll/MSW/MSW.X0123) add_test(NAME well_state_load4 - COMMAND well_state_load ${_eclpath}/Troll/MSW_LGR/LGR.EGRID - ${_eclpath}/Troll/MSW_LGR/LGR.X0095) -add_test(NAME well_state_load5 - COMMAND well_state_load ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID - ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.X0061) + COMMAND well_state_load ${_resdatapath}/Troll/MSW_LGR/LGR.EGRID + ${_resdatapath}/Troll/MSW_LGR/LGR.X0095) +add_test( + NAME well_state_load5 + COMMAND well_state_load ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID + ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.X0061) add_test( NAME well_state_load_missing_RSEG1 COMMAND - well_state_load_missing_RSEG ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID - ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.X0061) -add_test(NAME well_state_load_missing_RSEG2 - COMMAND well_state_load_missing_RSEG ${_eclpath}/Troll/MSW/MSW.EGRID - ${_eclpath}/Troll/MSW/MSW.X0123) + well_state_load_missing_RSEG + ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.EGRID + ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.X0061) +add_test( + NAME well_state_load_missing_RSEG2 + COMMAND well_state_load_missing_RSEG ${_resdatapath}/Troll/MSW/MSW.EGRID + ${_resdatapath}/Troll/MSW/MSW.X0123) add_test(NAME well_segment_load COMMAND well_segment_load - ${_eclpath}/MSWcase/MSW_CASE.X0021) + ${_resdatapath}/MSWcase/MSW_CASE.X0021) add_test(NAME well_segment_branch_conn_load COMMAND well_segment_branch_conn_load - ${_eclpath}/MSWcase/MSW_CASE.X0021) + ${_resdatapath}/MSWcase/MSW_CASE.X0021) -add_test(NAME well_info1 COMMAND well_info ${_eclpath}/Gurbat/ECLIPSE.EGRID) +add_test(NAME well_info1 COMMAND well_info ${_resdatapath}/Gurbat/ECLIPSE.EGRID) add_test( NAME well_info2 COMMAND well_info - ${_eclpath}/well_info_rio/BMS8_TMPL_1-BMS8_105DST_EMBED_T0_1.EGRID - ${_eclpath}/well_info_rio/BMS8_TMPL_1-BMS8_105DST_EMBED_T0_1.UNRST) + ${_resdatapath}/well_info_rio/BMS8_TMPL_1-BMS8_105DST_EMBED_T0_1.EGRID + ${_resdatapath}/well_info_rio/BMS8_TMPL_1-BMS8_105DST_EMBED_T0_1.UNRST) add_test(NAME well_conn_CF COMMAND well_conn_CF - ${_eclpath}/Gurbat/ECLIPSE.X0060) + ${_resdatapath}/Gurbat/ECLIPSE.X0060) add_test(NAME well_conn_load1 COMMAND well_conn_load - ${_eclpath}/Gurbat/ECLIPSE.X0030 F) + ${_resdatapath}/Gurbat/ECLIPSE.X0030 F) add_test(NAME well_conn_load2 - COMMAND well_conn_load ${_eclpath}/10kcase/TEST10K_FLT_LGR_NNC.X0021 F) + COMMAND well_conn_load + ${_resdatapath}/10kcase/TEST10K_FLT_LGR_NNC.X0021 F) add_test(NAME well_conn_load3 COMMAND well_conn_load - ${_eclpath}/MSWcase/MSW_CASE.X0021 T) + ${_resdatapath}/MSWcase/MSW_CASE.X0021 T) add_test(NAME well_conn_load4 COMMAND well_conn_load - ${_eclpath}/AmalgLGRcase/TESTCASE_AMALG_LGR.X0021 F) + ${_resdatapath}/AmalgLGRcase/TESTCASE_AMALG_LGR.X0021 F) add_test(NAME well_conn_load5 COMMAND well_conn_load - ${_eclpath}/DualPoro/DUALPORO.X0009 F) + ${_resdatapath}/DualPoro/DUALPORO.X0009 F) add_test(NAME well_conn_load6 COMMAND well_conn_load - ${_eclpath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003 F) + ${_resdatapath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003 F) -add_test(NAME well_ts COMMAND well_ts ${_eclpath}/CO2case/BASE_CASE) +add_test(NAME well_ts COMMAND well_ts ${_resdatapath}/CO2case/BASE_CASE) -add_test(NAME well_dualp COMMAND well_dualp ${_eclpath}/Gurbat/ECLIPSE.UNRST - ${_eclpath}/DualPoro/DUALPORO.X0005) +add_test(NAME well_dualp + COMMAND well_dualp ${_resdatapath}/Gurbat/ECLIPSE.UNRST + ${_resdatapath}/DualPoro/DUALPORO.X0005) add_test( NAME well_lgr_load1 - COMMAND well_lgr_load ${_eclpath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.EGRID - ${_eclpath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003) + COMMAND well_lgr_load ${_resdatapath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.EGRID + ${_resdatapath}/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003) add_test( NAME well_lgr_load2 - COMMAND well_lgr_load ${_eclpath}/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID - ${_eclpath}/AmalgLGRcase/TESTCASE_AMALG_LGR.X0016) + COMMAND well_lgr_load ${_resdatapath}/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID + ${_resdatapath}/AmalgLGRcase/TESTCASE_AMALG_LGR.X0016) # # geometry # add_executable(geo_surface geometry/tests/geo_surface.cpp) -target_link_libraries(geo_surface ecl) +target_link_libraries(geo_surface resdata) add_test(NAME geo_surface COMMAND geo_surface ${_geopath}/Surface.irap ${_geopath}/Surface_incompatible.irap) diff --git a/lib/ecl/EclFilename.cpp b/lib/ecl/EclFilename.cpp deleted file mode 100644 index 4811a2f9c9..0000000000 --- a/lib/ecl/EclFilename.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include - -namespace ERT { - -std::string EclFilename(const std::string &path, const std::string &base, - ecl_file_enum file_type, int report_step, - bool fmt_file) { - char *tmp = ecl_util_alloc_filename(path.c_str(), base.c_str(), file_type, - fmt_file, report_step); - std::string retval = tmp; - free(tmp); - return retval; -} - -std::string EclFilename(const std::string &base, ecl_file_enum file_type, - int report_step, bool fmt_file) { - char *tmp = ecl_util_alloc_filename(nullptr, base.c_str(), file_type, - fmt_file, report_step); - std::string retval = tmp; - free(tmp); - return retval; -} - -namespace { -bool require_report_step(ecl_file_enum file_type) { - if ((file_type == ECL_RESTART_FILE) || (file_type == ECL_SUMMARY_FILE)) - return true; - else - return false; -} -} // namespace - -std::string EclFilename(const std::string &path, const std::string &base, - ecl_file_enum file_type, bool fmt_file) { - if (require_report_step(file_type)) - throw std::runtime_error( - "Must use overload with report step for this file type"); - else { - char *tmp = ecl_util_alloc_filename(path.c_str(), base.c_str(), - file_type, fmt_file, -1); - std::string retval = tmp; - free(tmp); - return retval; - } -} - -std::string EclFilename(const std::string &base, ecl_file_enum file_type, - bool fmt_file) { - if (require_report_step(file_type)) - throw std::runtime_error( - "Must use overload with report step for this file type"); - else { - char *tmp = ecl_util_alloc_filename(nullptr, base.c_str(), file_type, - fmt_file, -1); - std::string retval = tmp; - free(tmp); - return retval; - } -} - -ecl_file_enum EclFiletype(const std::string &filename) { - return ecl_util_get_file_type(filename.c_str(), nullptr, nullptr); -} - -} // namespace ERT diff --git a/lib/ecl/ecl_file.cpp b/lib/ecl/ecl_file.cpp deleted file mode 100644 index 06e3000073..0000000000 --- a/lib/ecl/ecl_file.cpp +++ /dev/null @@ -1,1014 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - This file implements functionality to load an ECLIPSE file in - ecl_kw format. The implementation works by first searching through - the complete file to create an index over all the keywords present - in the file. The actual keyword data is not loaded before they are - explicitly requested. - - The ecl_file_type is the middle layer of abstraction in the libecl - hierarchy (see the file overview.txt in this directory); it works - with a collection of ecl_kw instances and has various query - functions, however it does not utilize knowledge of the - structure/content of the files in the way e.g. ecl_grid.c does[1]. - - The main datatype here is the ecl_file type, but in addition each - ecl_kw instance is wrapped in an ecl_file_kw (implemented in - ecl_file_kw.c) structure and all the indexing is implemented with - the ecl_file_view type. The ecl_file_view type is not used outside this file. - - When the file is opened an index of all the keywords is created and - stored in the field global_map, and the field active_view is set to - point to global_map, i.e. all query/get operations on the ecl_file - will be based on the complete index: - - In many cases (in particular for unified restart files) it is quite - painful to work with this large and unvieldy index, and it is - convenient to create a sub index based on a subset of the - keywords. The creation of these sub indices is based on identifying - a keyword from name and occurence number, and then including all - keywords up to the next occurence of the same keyword: - - SEQHDR ---\ - MINISTEP 0 | - PARAMS ..... | - MINISTEP 1 | Block 0 - PARAMS ..... | - MINISTEP 2 | - PARAMS ..... | - SEQHDR ---+ - MINISTEP 3 | - PARAMS ..... | - MINISTEP 4 | Block 1 - PARAMS ..... | - MINISTEP 5 | - SEQHDR ---+ - MINISTEP 6 | Block 2 - PARAMS .... | - SEQHDR ---+ - MINISTEP 7 | - PARAMS .... | Block 3 - MINISTEP 8 | - PARAMS .... | - - For the unified summary file depicted here e.g. the call - - ecl_file_get_blockmap( ecl_file , "SEQHDR" , 2 ) - - Will create a sub-index consisting of the (three) keywords in what - is called 'Block 2' in the figure above. In particular for restart - files this abstraction is very convenient, because an extra layer - of functionality is required to get from natural time coordinates - (i.e. simulation time or report step) to the occurence number (see - ecl_rstfile for more details). - - To select a subindex as the active index you use the - ecl_file_select_block() function, or alternatively you can use - ecl_file_open_block() to directly select the relevant block - immediately after the open() statement. Observe that when using a - sub index thorugh ecl_file_select_block() function the global_map - will still be present in the ecl_file instance, and subsequent - calls to create a new sub index will also use the global_map index - - i.e. the indexing is not recursive, a sub index is always created - based on the global_map, and not on the currently active map. - - - [1]: This is not entirely true - in the file ecl_rstfile.c; which - is included from this file are several specialized function - for working with restart files. However the restart files are - still treated as collections of ecl_kw instances, and not - internalized as in e.g. ecl_sum. -*/ - -#define ECL_FILE_ID 776107 - -struct ecl_file_struct { - UTIL_TYPE_ID_DECLARATION; - fortio_type *fortio; /* The source of all the keywords - must be retained - open for reading for the entire lifetime of the - ecl_file object. */ - ecl_file_view_type - *global_view; /* The index of all the ecl_kw instances in the file. */ - ecl_file_view_type *active_view; /* The currently active index. */ - bool read_only; - int flags; - vector_type *map_stack; - inv_map_type *inv_view; -}; - -/* - This illustrates the indexing. The ecl_file instance contains in - total 7 ecl_kw instances, the global index [0...6] is the internal - way to access the various keywords. The kw_index is a hash table - with entries 'SEQHDR', 'MINISTEP' and 'PARAMS'. Each entry in the - hash table is an integer vector which again contains the internal - index of the various occurences: - - ------------------ - SEQHDR \ - MINISTEP 0 | - PARAMS ..... | - MINISTEP 1 | - PARAMS ..... | - MINISTEP 2 | - PARAMS ..... / - ------------------ - - kw_index = {"SEQHDR": [0], "MINISTEP": [1,3,5], "PARAMS": [2,4,6]} <== This is hash table. - kw_list = [SEQHDR , MINISTEP , PARAMS , MINISTEP , PARAMS , MINISTEP , PARAMS] - distinct_kw = [SEQHDR , MINISTEP , PARAMS] - -*/ - -UTIL_SAFE_CAST_FUNCTION(ecl_file, ECL_FILE_ID) -UTIL_IS_INSTANCE_FUNCTION(ecl_file, ECL_FILE_ID) - -ecl_file_type *ecl_file_alloc_empty(int flags) { - ecl_file_type *ecl_file = (ecl_file_type *)util_malloc(sizeof *ecl_file); - UTIL_TYPE_ID_INIT(ecl_file, ECL_FILE_ID); - ecl_file->map_stack = vector_alloc_new(); - ecl_file->inv_view = inv_map_alloc(); - ecl_file->flags = flags; - return ecl_file; -} - -void ecl_file_fwrite_fortio(const ecl_file_type *ecl_file, fortio_type *target, - int offset) { - ecl_file_view_fwrite(ecl_file->active_view, target, offset); -} - -/* - Observe : if the filename is a standard filename which can be used - to infer formatted/unformatted automagically the fmt_file variable - is NOT consulted. -*/ - -void ecl_file_fwrite(const ecl_file_type *ecl_file, const char *filename, - bool fmt_file) { - bool __fmt_file; - ecl_file_enum file_type; - - file_type = ecl_util_get_file_type(filename, &__fmt_file, NULL); - if (file_type == ECL_OTHER_FILE) - __fmt_file = fmt_file; - - { - fortio_type *target = - fortio_open_writer(filename, __fmt_file, ECL_ENDIAN_FLIP); - ecl_file_fwrite_fortio(ecl_file, target, 0); - fortio_fclose(target); - } -} - -/** - Here comes several functions for querying the ecl_file instance, and - getting pointers to the ecl_kw content of the ecl_file. For getting - ecl_kw instances there are two principally different access methods: - - * ecl_file_iget_named_kw(): This function will take a keyword - (char *) and an integer as input. The integer corresponds to the - ith occurence of the keyword in the file. - - * ecl_file_iget_kw(): This function just takes an integer index as - input, and returns the corresponding ecl_kw instance - without - considering which keyword it is. - - ------- - - In addition the functions ecl_file_get_num_distinct_kw() and - ecl_file_iget_distinct_kw() will return the number of distinct - keywords, and distinct keyword keyword nr i (as a const char *). - - - Possible usage pattern: - - .... - for (ikw = 0; ikw < ecl_file_get_num_distinct_kw(ecl_file); ikw++) { - const char * kw = ecl_file_iget_distinct_kw(ecl_file , ikw); - - printf("The file contains: %d occurences of \'%s\' \n",ecl_file_get_num_named_kw( ecl_file , kw) , kw); - } - .... - - For the summary file showed in the top this code will produce: - - The file contains 1 occurences of 'SEQHDR' - The file contains 3 occurences of 'MINISTEP' - The file contains 3 occurences of 'PARAMS' - -*/ - -/** - This function will iterate through the ecl_file instance and search - for the ecl_kw instance @old_kw - the search is based on pointer - equality, i.e. the actual ecl_kw instance, and not on content - equality. - - When @old_kw is found that keyword instance will be discarded with - ecl_kw_free() and the new keyword @new_kw will be inserted. If - @old_kw can not be found the function will fail hard - to verify - that @new_kw is indeed in the ecl_file instance you should use - ecl_file_has_kw_ptr() first. - - The ecl_file function typically gives out references to the - internal ecl_kw instances via the ecl_file_iget_kw() function. Use - of ecl_file_replace_kw() might lead to invalidating ecl_kw - instances held by the calling scope: - - - .... - ecl_file_type * restart_file = ecl_file_fread_alloc( "ECLIPSE.UNRST" ); - ecl_kw_type * initial_pressure = ecl_file_iget_named_kw( ecl_file , "PRESSURE" , 0); - ecl_kw_type * faked_pressure = ecl_kw_alloc_copy( initial_pressure ); - - ecl_kw_scale( faked_pressure , 1.25 ); - ecl_file_replace_kw( restart_file , initial_pressure , faked_pressure , false ); <--- This call will invalidate the inital_pressure reference - .... - .... - // This will fail horribly: - printf("The initial pressure in cell(0) was:%g \n",ecl_kw_iget_double( initial_pressure , 0 )); - /|\ - | - +---------> Using initial_pressure => Crash and burn! - - The ecl_file structure takes ownership of all the keywords, and - will also take ownership of the newly instered @new_kw instance; if - the boolean @insert_copy is set to true the function will insert a - copy of @new_kw, leaving the original reference untouched. -*/ - -void ecl_file_replace_kw(ecl_file_type *ecl_file, ecl_kw_type *old_kw, - ecl_kw_type *new_kw, bool insert_copy) { - ecl_file_view_replace_kw(ecl_file->active_view, old_kw, new_kw, - insert_copy); -} - -ecl_kw_type *ecl_file_icopy_named_kw(const ecl_file_type *ecl_file, - const char *kw, int ith) { - return ecl_kw_alloc_copy(ecl_file_iget_named_kw(ecl_file, kw, ith)); -} - -/* - Will return the number of times a particular keyword occurs in a - ecl_file instance. Will return 0 if the keyword can not be found. -*/ - -int ecl_file_get_num_named_kw(const ecl_file_type *ecl_file, const char *kw) { - return ecl_file_view_get_num_named_kw(ecl_file->active_view, kw); -} - -/** - This function does the following: - - 1. Takes an input index which goes in to the global kw_list vector. - 2. Looks up the corresponding keyword. - 3. Return the number of this particular keyword instance, among - the other instance with the same header. - - With the example above we get: - - ecl_file_iget_occurence(ecl_file , 2) -> 0; Global index 2 will - look up the first occurence of PARAMS. - - ecl_file_iget_occurence(ecl_file , 5) -> 2; Global index 5 will - look up th third occurence of MINISTEP. - - The enkf layer uses this funny functionality. -*/ - -int ecl_file_iget_occurence(const ecl_file_type *ecl_file, int index) { - return ecl_file_view_iget_occurence(ecl_file->active_view, index); -} - -/** - Returns the total number of ecl_kw instances in the ecl_file - instance. -*/ -int ecl_file_get_size(const ecl_file_type *ecl_file) { - return ecl_file_view_get_size(ecl_file->active_view); -} - -/** - Returns true if the ecl_file instance has at-least one occurence of - ecl_kw 'kw'. -*/ -bool ecl_file_has_kw(const ecl_file_type *ecl_file, const char *kw) { - return ecl_file_view_has_kw(ecl_file->active_view, kw); -} - -int ecl_file_get_num_distinct_kw(const ecl_file_type *ecl_file) { - return ecl_file_view_get_num_distinct_kw(ecl_file->active_view); -} - -const char *ecl_file_iget_distinct_kw(const ecl_file_type *ecl_file, - int index) { - return ecl_file_view_iget_distinct_kw(ecl_file->active_view, index); -} - -const char *ecl_file_get_src_file(const ecl_file_type *ecl_file) { - return fortio_filename_ref(ecl_file->fortio); -} - -void ecl_file_fprintf_kw_list(const ecl_file_type *ecl_file, FILE *stream) { - ecl_file_view_fprintf_kw_list(ecl_file->active_view, stream); -} - -ecl_file_kw_type *ecl_file_iget_file_kw(const ecl_file_type *file, - int global_index) { - return ecl_file_view_iget_file_kw(file->active_view, global_index); -} - -ecl_file_kw_type *ecl_file_iget_named_file_kw(const ecl_file_type *file, - const char *kw, int ith) { - return ecl_file_view_iget_named_file_kw(file->active_view, kw, ith); -} - -ecl_kw_type *ecl_file_iget_kw(const ecl_file_type *file, int global_index) { - return ecl_file_view_iget_kw(file->active_view, global_index); -} - -ecl_data_type ecl_file_iget_data_type(const ecl_file_type *file, - int global_index) { - return ecl_file_view_iget_data_type(file->active_view, global_index); -} - -int ecl_file_iget_size(const ecl_file_type *file, int global_index) { - return ecl_file_view_iget_size(file->active_view, global_index); -} - -const char *ecl_file_iget_header(const ecl_file_type *file, int global_index) { - return ecl_file_view_iget_header(file->active_view, global_index); -} - -/* - This function will return the ith occurence of 'kw' in - ecl_file. Will abort hard if the request can not be satisifed - use - query functions if you can not take that. -*/ - -ecl_kw_type *ecl_file_iget_named_kw(const ecl_file_type *file, const char *kw, - int ith) { - return ecl_file_view_iget_named_kw(file->active_view, kw, ith); -} - -void ecl_file_indexed_read(const ecl_file_type *file, const char *kw, int index, - const int_vector_type *index_map, char *buffer) { - ecl_file_view_index_fload_kw(file->active_view, kw, index, index_map, - buffer); -} - -ecl_data_type ecl_file_iget_named_data_type(const ecl_file_type *file, - const char *kw, int ith) { - return ecl_file_view_iget_named_data_type(file->active_view, kw, ith); -} - -int ecl_file_iget_named_size(const ecl_file_type *file, const char *kw, - int ith) { - return ecl_file_view_iget_named_size(file->active_view, kw, ith); -} - -ecl_file_view_type *ecl_file_get_global_view(ecl_file_type *ecl_file) { - return ecl_file->global_view; -} - -// Very deprecated ... -ecl_file_view_type *ecl_file_get_active_view(ecl_file_type *ecl_file) { - return ecl_file->active_view; -} - -ecl_file_view_type *ecl_file_get_global_blockview(ecl_file_type *ecl_file, - const char *kw, - int occurence) { - ecl_file_view_type *view = - ecl_file_view_add_blockview(ecl_file->global_view, kw, occurence); - return view; -} - -ecl_file_view_type *ecl_file_alloc_global_blockview2(ecl_file_type *ecl_file, - const char *start_kw, - const char *end_kw, - int occurence) { - ecl_file_view_type *view = ecl_file_view_alloc_blockview2( - ecl_file->global_view, start_kw, end_kw, occurence); - return view; -} - -ecl_file_view_type *ecl_file_alloc_global_blockview(ecl_file_type *ecl_file, - const char *kw, - int occurence) { - return ecl_file_alloc_global_blockview2(ecl_file, kw, kw, occurence); -} - -ecl_file_view_type *ecl_file_get_restart_view(ecl_file_type *ecl_file, - int input_index, int report_step, - time_t sim_time, - double sim_days) { - ecl_file_view_type *view = ecl_file_view_add_restart_view( - ecl_file->global_view, input_index, report_step, sim_time, sim_days); - return view; -} - -ecl_file_view_type *ecl_file_get_summary_view(ecl_file_type *ecl_file, - int report_step) { - ecl_file_view_type *view = - ecl_file_view_add_summary_view(ecl_file->global_view, report_step); - return view; -} - -/* - Different functions to open and close a file. -*/ - -/** - The ecl_file_scan() function will scan through the whole file and build up an - index of all the kewyords. The map created from this scan will be stored - under the 'global_view' field; and all subsequent lookup operations will - ultimately be based on the global map. - - The ecl_file_scan function will scan through the file as long as it finds - valid ecl_kw instances on the disk; it will return when EOF is encountered or - an invalid ecl_kw instance is detected. This implies that for a partly broken - file the ecl_file_scan function will index the valid keywords which are in - the file, possible garbage at the end will be ignored. -*/ - -static void ecl_file_scan(ecl_file_type *ecl_file) { - fortio_fseek(ecl_file->fortio, 0, SEEK_SET); - { - ecl_kw_type *work_kw = ecl_kw_alloc_new("WORK-KW", 0, ECL_INT, NULL); - - while (true) { - if (fortio_read_at_eof(ecl_file->fortio)) - break; - - { - offset_type current_offset = fortio_ftell(ecl_file->fortio); - ecl_read_status_enum read_status = - ecl_kw_fread_header(work_kw, ecl_file->fortio); - if (read_status == ECL_KW_READ_FAIL) - break; - - if (read_status == ECL_KW_READ_OK) { - ecl_file_kw_type *file_kw = - ecl_file_kw_alloc(work_kw, current_offset); - - if (ecl_file_kw_fskip_data(file_kw, ecl_file->fortio)) - ecl_file_view_add_kw(ecl_file->global_view, file_kw); - else { - ecl_file_kw_free(file_kw); - break; - } - } - } - } - - ecl_kw_free(work_kw); - } - ecl_file_view_make_index(ecl_file->global_view); -} - -void ecl_file_select_global(ecl_file_type *ecl_file) { - ecl_file->active_view = ecl_file->global_view; -} - -/** - The fundamental open file function; all alternative open() - functions start by calling this one. This function will read - through the complete file, extract all the keyword headers and - create the map/index stored in the global_view field of the ecl_file - structure. No keyword data will be loaded from the file. - - The ecl_file instance will retain an open fortio reference to the - file until ecl_file_close() is called. -*/ - -static fortio_type *ecl_file_alloc_fortio(const char *filename, int flags) { - fortio_type *fortio = NULL; - bool fmt_file; - - ecl_util_fmt_file(filename, &fmt_file); - - if (ecl_file_view_check_flags(flags, ECL_FILE_WRITABLE)) - fortio = fortio_open_readwrite(filename, fmt_file, ECL_ENDIAN_FLIP); - else - fortio = fortio_open_reader(filename, fmt_file, ECL_ENDIAN_FLIP); - - return fortio; -} - -ecl_file_type *ecl_file_open(const char *filename, int flags) { - fortio_type *fortio = ecl_file_alloc_fortio(filename, flags); - - if (fortio) { - ecl_file_type *ecl_file = ecl_file_alloc_empty(flags); - ecl_file->fortio = fortio; - ecl_file->global_view = ecl_file_view_alloc( - ecl_file->fortio, &ecl_file->flags, ecl_file->inv_view, true); - - ecl_file_scan(ecl_file); - ecl_file_select_global(ecl_file); - - if (ecl_file_view_check_flags(ecl_file->flags, ECL_FILE_CLOSE_STREAM)) - fortio_fclose_stream(ecl_file->fortio); - - return ecl_file; - } else - return NULL; -} - -int ecl_file_get_flags(const ecl_file_type *ecl_file) { - return ecl_file->flags; -} - -void ecl_file_set_flags(ecl_file_type *ecl_file, int flags) { - ecl_file->flags = flags; -} - -bool ecl_file_flags_set(const ecl_file_type *ecl_file, int flags) { - return ecl_file_view_check_flags(ecl_file->flags, flags); -} - -bool ecl_file_writable(const ecl_file_type *ecl_file) { - return ecl_file_view_check_flags(ecl_file->flags, ECL_FILE_WRITABLE); -} - -/** - The ecl_file_close() function will close the fortio instance and - free all the data created by the ecl_file instance; this includes - the ecl_kw instances which have been loaded on demand. -*/ - -void ecl_file_close(ecl_file_type *ecl_file) { - if (ecl_file->fortio != NULL) - fortio_fclose(ecl_file->fortio); - - if (ecl_file->global_view) - ecl_file_view_free(ecl_file->global_view); - - inv_map_free(ecl_file->inv_view); - vector_free(ecl_file->map_stack); - free(ecl_file); -} - -void ecl_file_close_fortio_stream(ecl_file_type *ecl_file) { - if (ecl_file->fortio != NULL) { - fortio_fclose_stream(ecl_file->fortio); - } -} - -/** - This function will detach the current ecl_file instance from the - underlying fortio instance. The ecl_file instance can be used - further to access the ecl_kw instances which have been loaded - already, but if you try on-demand loading of a keyword you will get - crash-and-burn. To ensure that all keywords are in memory you can - call ecl_file_load_all() prior to the detach call. -*/ - -void ecl_file_fortio_detach(ecl_file_type *ecl_file) { - fortio_fclose(ecl_file->fortio); - ecl_file->fortio = NULL; -} - -bool ecl_file_load_all(ecl_file_type *ecl_file) { - return ecl_file_view_load_all(ecl_file->active_view); -} - -void ecl_file_free__(void *arg) { ecl_file_close(ecl_file_safe_cast(arg)); } - -/* Functions specialized to work with restart files. */ - -/* Query functions. */ -/** - Will look through all the INTEHEAD kw instances of the current - ecl_file and look for @sim_time. If the value is found true is - returned, otherwise false. -*/ - -bool ecl_file_has_sim_time(const ecl_file_type *ecl_file, time_t sim_time) { - return ecl_file_view_has_sim_time(ecl_file->active_view, sim_time); -} - -/* - This function will determine the restart block corresponding to the - world time @sim_time; if @sim_time can not be found the function - will return 0. - - The returned index is the 'occurence number' in the restart file, - i.e. in the (quite typical case) that not all report steps are - present the return value will not agree with report step. - - The return value from this function can then be used to get a - corresponding solution field directly, or the file map can - restricted to this block. - - Direct access: - - int index = ecl_file_get_restart_index( ecl_file , sim_time ); - if (index >= 0) { - ecl_kw_type * pressure_kw = ecl_file_iget_named_kw( ecl_file , "PRESSURE" , index ); - .... - } - - - Using block restriction: - - int index = ecl_file_get_restart_index( ecl_file , sim_time ); - if (index >= 0) { - ecl_file_iselect_rstblock( ecl_file , index ); - { - ecl_kw_type * pressure_kw = ecl_file_iget_named_kw( ecl_file , "PRESSURE" , 0 ); - .... - } - } - - Specially in the case of LGRs the block restriction should be used. - */ - -int ecl_file_get_restart_index(const ecl_file_type *ecl_file, time_t sim_time) { - int active_index = - ecl_file_view_find_sim_time(ecl_file->active_view, sim_time); - return active_index; -} - -/** - Will look through all the SEQNUM kw instances of the current - ecl_file and look for @report_step. If the value is found true is - returned, otherwise false. -*/ - -bool ecl_file_has_report_step(const ecl_file_type *ecl_file, int report_step) { - return ecl_file_view_has_report_step(ecl_file->active_view, report_step); -} - -/** - This function will look up the INTEHEAD keyword in a ecl_file_type - instance, and calculate simulation date from this instance. - - Will return -1 if the requested INTEHEAD keyword can not be found. -*/ - -time_t ecl_file_iget_restart_sim_date(const ecl_file_type *restart_file, - int index) { - return ecl_file_view_iget_restart_sim_date(restart_file->active_view, - index); -} - -double ecl_file_iget_restart_sim_days(const ecl_file_type *restart_file, - int index) { - return ecl_file_view_iget_restart_sim_days(restart_file->active_view, - index); -} - -/* - The input @file must be either an INIT file or a restart file. Will - fail hard if an INTEHEAD kw can not be found - or if the INTEHEAD - keyword is not sufficiently large. - - The eclipse files can distinguish between ECLIPSE300 ( value == 300) - and ECLIPSE300-Thermal option (value == 500). This function will - return ECLIPSE300 in both those cases. -*/ - -ecl_version_enum ecl_file_get_ecl_version(const ecl_file_type *file) { - ecl_kw_type *intehead_kw = ecl_file_iget_named_kw(file, INTEHEAD_KW, 0); - int int_value = ecl_kw_iget_int(intehead_kw, INTEHEAD_IPROG_INDEX); - - if (int_value == INTEHEAD_ECLIPSE100_VALUE) - return ECLIPSE100; - - if (int_value == INTEHEAD_ECLIPSE300_VALUE) - return ECLIPSE300; - - if (int_value == INTEHEAD_ECLIPSE300THERMAL_VALUE) - return ECLIPSE300_THERMAL; - - if (int_value == INTEHEAD_INTERSECT_VALUE) - return INTERSECT; - - if (int_value == INTEHEAD_FRONTSIM_VALUE) - return FRONTSIM; - - util_abort("%s: Simulator version value:%d not recognized \n", __func__, - int_value); - return (ecl_version_enum)0; -} - -/* - 1: Oil - 2: Water - 3: Oil + water - 4: Gas - 5: Gas + Oil - 6: Gas + water - 7: Gas + Water + Oil -*/ - -int ecl_file_get_phases(const ecl_file_type *init_file) { - ecl_kw_type *intehead_kw = - ecl_file_iget_named_kw(init_file, INTEHEAD_KW, 0); - int phases = ecl_kw_iget_int(intehead_kw, INTEHEAD_PHASE_INDEX); - return phases; -} - -/* -bool ecl_file_writable( const ecl_file_type * ecl_file ) { - return fortio_writable( ecl_file->fortio ); -} -*/ - -/** - Checks if the ecl_file contains ecl_kw; this check is based on - pointer equality - i.e. we check if the ecl_file contains exactly - this keyword - not an arbitrary equivalent keyword. - - This function can be called as a safeguard before calling - ecl_file_save_kw(). -*/ - -bool ecl_file_has_kw_ptr(const ecl_file_type *ecl_file, - const ecl_kw_type *ecl_kw) { - ecl_file_kw_type *file_kw = inv_map_get_file_kw(ecl_file->inv_view, ecl_kw); - if (file_kw == NULL) - return false; - else - return true; -} - -/* - Will save the content of @ecl_kw to the on-disk file wrapped by the - ecl_file instance. This function is quite strict: - - 1. The actual keyword which should be updated is identified using - pointer comparison; i.e. the ecl_kw argument must be the actual - return value from an earlier ecl_file_get_kw() operation. To - check this you can call ecl_file_has_kw_ptr(). - - 2. The header data of the ecl_kw must be unmodified; this is checked - by the ecl_file_kw_inplace_fwrite() function and crash-and-burn - will ensue if this is not satisfied. - - 3. The ecl_file must have been opened with one of the _writable() - open functions. -*/ - -bool ecl_file_save_kw(const ecl_file_type *ecl_file, - const ecl_kw_type *ecl_kw) { - ecl_file_kw_type *file_kw = inv_map_get_file_kw( - ecl_file->inv_view, - ecl_kw); // We just verify that the input ecl_kw points to an ecl_kw - if (file_kw != - NULL) { // we manage; from then on we use the reference contained in - if (fortio_assert_stream_open( - ecl_file->fortio)) { // the corresponding ecl_file_kw instance. - - ecl_file_kw_inplace_fwrite(file_kw, ecl_file->fortio); - - if (ecl_file_view_check_flags(ecl_file->flags, - ECL_FILE_CLOSE_STREAM)) - fortio_fclose_stream(ecl_file->fortio); - - return true; - } else - return false; - } else { - util_abort("%s: keyword pointer:%p not found in ecl_file instance. \n", - __func__, ecl_kw); - return false; - } -} - -/* DEPRECATED */ -void ecl_file_push_block(ecl_file_type *ecl_file) { - vector_append_ref(ecl_file->map_stack, ecl_file->active_view); -} - -void ecl_file_pop_block(ecl_file_type *ecl_file) { - ecl_file->active_view = - (ecl_file_view_type *)vector_pop_back(ecl_file->map_stack); -} - -static ecl_file_view_type * -ecl_file_get_relative_blockview(ecl_file_type *ecl_file, const char *kw, - int occurence) { - ecl_file_view_type *view = - ecl_file_view_add_blockview(ecl_file->active_view, kw, occurence); - return view; -} - -bool ecl_file_subselect_block(ecl_file_type *ecl_file, const char *kw, - int occurence) { - ecl_file_view_type *blockmap = - ecl_file_get_relative_blockview(ecl_file, kw, occurence); - if (blockmap != NULL) { - ecl_file->active_view = blockmap; - return true; - } else - return false; -} - -bool ecl_file_select_block(ecl_file_type *ecl_file, const char *kw, - int occurence) { - ecl_file_view_type *blockmap = - ecl_file_get_global_blockview(ecl_file, kw, occurence); - if (blockmap != NULL) { - ecl_file->active_view = blockmap; - return true; - } else - return false; -} - -/* - Will select restart block nr @seqnum_index - without considering - report_steps or simulation time. -*/ -bool ecl_file_iselect_rstblock(ecl_file_type *ecl_file, int seqnum_index) { - return ecl_file_select_block(ecl_file, SEQNUM_KW, seqnum_index); -} - -bool ecl_file_select_rstblock_sim_time(ecl_file_type *ecl_file, - time_t sim_time) { - int seqnum_index = ecl_file_view_seqnum_index_from_sim_time( - ecl_file->global_view, sim_time); - - if (seqnum_index >= 0) - return ecl_file_iselect_rstblock(ecl_file, seqnum_index); - else - return false; -} - -bool ecl_file_select_rstblock_report_step(ecl_file_type *ecl_file, - int report_step) { - int global_index = ecl_file_view_find_kw_value(ecl_file->global_view, - SEQNUM_KW, &report_step); - if (global_index >= 0) { - int seqnum_index = - ecl_file_view_iget_occurence(ecl_file->global_view, global_index); - return ecl_file_iselect_rstblock(ecl_file, seqnum_index); - } else - return false; -} - -static ecl_file_type *ecl_file_open_rstblock_report_step__(const char *filename, - int report_step, - int flags) { - ecl_file_type *ecl_file = ecl_file_open(filename, flags); - if (ecl_file) { - if (!ecl_file_select_rstblock_report_step(ecl_file, report_step)) { - ecl_file_close(ecl_file); - ecl_file = NULL; - } - } - return ecl_file; -} - -ecl_file_type *ecl_file_open_rstblock_report_step(const char *filename, - int report_step, int flags) { - return ecl_file_open_rstblock_report_step__(filename, report_step, flags); -} - -static ecl_file_type *ecl_file_open_rstblock_sim_time__(const char *filename, - time_t sim_time, - int flags) { - ecl_file_type *ecl_file = ecl_file_open(filename, flags); - if (ecl_file) { - if (!ecl_file_select_rstblock_sim_time(ecl_file, sim_time)) { - ecl_file_close(ecl_file); - ecl_file = NULL; - } - } - return ecl_file; -} - -ecl_file_type *ecl_file_open_rstblock_sim_time(const char *filename, - time_t sim_time, int flags) { - return ecl_file_open_rstblock_sim_time__(filename, sim_time, flags); -} - -static ecl_file_type *ecl_file_iopen_rstblock__(const char *filename, - int seqnum_index, int flags) { - ecl_file_type *ecl_file = ecl_file_open(filename, flags); - if (ecl_file) { - if (!ecl_file_iselect_rstblock(ecl_file, seqnum_index)) { - ecl_file_close(ecl_file); - ecl_file = NULL; - } - } - return ecl_file; -} - -ecl_file_type *ecl_file_iopen_rstblock(const char *filename, int seqnum_index, - int flags) { - return ecl_file_iopen_rstblock__(filename, seqnum_index, flags); -} - -static bool ecl_file_index_valid0(const char *file_name, - const char *index_file_name) { - if (!util_file_exists(file_name)) - return false; - - if (!util_file_exists(index_file_name)) - return false; - - if (util_file_difftime(file_name, index_file_name) > 0) - return false; - - return true; -} - -static bool ecl_file_index_valid1(const char *file_name, FILE *stream) { - bool name_equal; - char *source_file = util_fread_alloc_string(stream); - char *input_name = util_split_alloc_filename(file_name); - - name_equal = util_string_equal(source_file, input_name); - - free(source_file); - free(input_name); - return name_equal; -} - -bool ecl_file_index_valid(const char *file_name, const char *index_file_name) { - if (!ecl_file_index_valid0(file_name, index_file_name)) - return false; - - bool valid = false; - FILE *stream = fopen(index_file_name, "rb"); - if (stream) { - valid = ecl_file_index_valid1(file_name, stream); - fclose(stream); - } - - return valid; -} - -bool ecl_file_write_index(const ecl_file_type *ecl_file, - const char *index_filename) { - FILE *ostream = fopen(index_filename, "wb"); - if (!ostream) - return false; - { - char *filename = - util_split_alloc_filename(fortio_filename_ref(ecl_file->fortio)); - util_fwrite_string(filename, ostream); - free(filename); - } - ecl_file_view_write_index(ecl_file->global_view, ostream); - fclose(ostream); - return true; -} - -ecl_file_type *ecl_file_fast_open(const char *file_name, - const char *index_file_name, int flags) { - if (!ecl_file_index_valid0(file_name, index_file_name)) - return NULL; - - FILE *istream = fopen(index_file_name, "rb"); - if (!istream) - return NULL; - - ecl_file_type *ecl_file = NULL; - - if (ecl_file_index_valid1(file_name, istream)) { - fortio_type *fortio = ecl_file_alloc_fortio(file_name, flags); - if (fortio) { - ecl_file = ecl_file_alloc_empty(flags); - ecl_file->fortio = fortio; - ecl_file->global_view = - ecl_file_view_fread_alloc(ecl_file->fortio, &ecl_file->flags, - ecl_file->inv_view, istream); - if (ecl_file->global_view) { - ecl_file_select_global(ecl_file); - if (ecl_file_view_check_flags(ecl_file->flags, - ECL_FILE_CLOSE_STREAM)) - fortio_fclose_stream(ecl_file->fortio); - } else { - ecl_file_close(ecl_file); - ecl_file = NULL; - } - } - } - fclose(istream); - return ecl_file; -} diff --git a/lib/ecl/ecl_file_kw.cpp b/lib/ecl/ecl_file_kw.cpp deleted file mode 100644 index 4ea43e3f16..0000000000 --- a/lib/ecl/ecl_file_kw.cpp +++ /dev/null @@ -1,426 +0,0 @@ -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -/* - This file implements the datatype ecl_file_kw which is used to hold - header-information about an ecl_kw instance on file. When a - ecl_file_kw instance is created it is initialized with the header - information (name, size, type) for an ecl_kw instance and the offset - in a file actually containing the keyword. - - If and when the keyword is actually queried for at a later stage the - ecl_file_kw_get_kw() method will seek to the keyword position in an - open fortio instance and call ecl_kw_fread_alloc() to instantiate - the keyword itself. - - The ecl_file_kw datatype is mainly used by the ecl_file datatype; - whose index tables consists of ecl_file_kw instances. -*/ - -#define ECL_FILE_KW_TYPE_ID 646107 - -struct inv_map_struct { - size_t_vector_type *file_kw_ptr; - size_t_vector_type *ecl_kw_ptr; - bool sorted; -}; - -struct ecl_file_kw_struct { - UTIL_TYPE_ID_DECLARATION; - offset_type file_offset; - ecl_data_type data_type; - int kw_size; - int ref_count; - char *header; - ecl_kw_type *kw; -}; - -inv_map_type *inv_map_alloc() { - inv_map_type *map = (inv_map_type *)util_malloc(sizeof *map); - map->file_kw_ptr = size_t_vector_alloc(0, 0); - map->ecl_kw_ptr = size_t_vector_alloc(0, 0); - map->sorted = false; - return map; -} - -void inv_map_free(inv_map_type *map) { - size_t_vector_free(map->file_kw_ptr); - size_t_vector_free(map->ecl_kw_ptr); - free(map); -} - -static void inv_map_assert_sort(inv_map_type *map) { - if (!map->sorted) { - perm_vector_type *perm = size_t_vector_alloc_sort_perm(map->ecl_kw_ptr); - - size_t_vector_permute(map->ecl_kw_ptr, perm); - size_t_vector_permute(map->file_kw_ptr, perm); - map->sorted = true; - - perm_vector_free(perm); - } -} - -static void inv_map_drop_kw(inv_map_type *map, const ecl_kw_type *ecl_kw) { - inv_map_assert_sort(map); - { - int index = size_t_vector_index_sorted(map->ecl_kw_ptr, (size_t)ecl_kw); - if (index == -1) - util_abort("%s: trying to drop non-existent kw \n", __func__); - - size_t_vector_idel(map->ecl_kw_ptr, index); - size_t_vector_idel(map->file_kw_ptr, index); - map->sorted = false; - } -} - -static void inv_map_add_kw(inv_map_type *map, const ecl_file_kw_type *file_kw, - const ecl_kw_type *ecl_kw) { - size_t_vector_append(map->file_kw_ptr, (size_t)file_kw); - size_t_vector_append(map->ecl_kw_ptr, (size_t)ecl_kw); - map->sorted = false; -} - -ecl_file_kw_type *inv_map_get_file_kw(inv_map_type *inv_map, - const ecl_kw_type *ecl_kw) { - inv_map_assert_sort(inv_map); - { - int index = - size_t_vector_index_sorted(inv_map->ecl_kw_ptr, (size_t)ecl_kw); - if (index == -1) - /* ecl_kw ptr not found. */ - return NULL; - else - return (ecl_file_kw_type *)size_t_vector_iget(inv_map->file_kw_ptr, - index); - } -} - -static UTIL_SAFE_CAST_FUNCTION(ecl_file_kw, ECL_FILE_KW_TYPE_ID) - UTIL_IS_INSTANCE_FUNCTION(ecl_file_kw, ECL_FILE_KW_TYPE_ID) - - ecl_file_kw_type *ecl_file_kw_alloc0(const char *header, - ecl_data_type data_type, int size, - offset_type offset) { - ecl_file_kw_type *file_kw = - (ecl_file_kw_type *)util_malloc(sizeof *file_kw); - UTIL_TYPE_ID_INIT(file_kw, ECL_FILE_KW_TYPE_ID); - - file_kw->header = util_alloc_string_copy(header); - memcpy(&file_kw->data_type, &data_type, sizeof data_type); - file_kw->kw_size = size; - file_kw->file_offset = offset; - file_kw->ref_count = 0; - file_kw->kw = NULL; - - return file_kw; -} - -/** - Create a new ecl_file_kw instance based on header information from - the input keyword. Typically only the header has been loaded from - the keyword. - - Observe that it is the users responsability that the @offset - argument in ecl_file_kw_alloc() comes from the same fortio instance - as used when calling ecl_file_kw_get_kw() to actually instatiate - the ecl_kw. This is automatically assured when using ecl_file to - access the ecl_file_kw instances. -*/ - -ecl_file_kw_type *ecl_file_kw_alloc(const ecl_kw_type *ecl_kw, - offset_type offset) { - return ecl_file_kw_alloc0(ecl_kw_get_header(ecl_kw), - ecl_kw_get_data_type(ecl_kw), - ecl_kw_get_size(ecl_kw), offset); -} - -/** - Does NOT copy the kw pointer which must be reloaded. -*/ -ecl_file_kw_type *ecl_file_kw_alloc_copy(const ecl_file_kw_type *src) { - return ecl_file_kw_alloc0(src->header, ecl_file_kw_get_data_type(src), - src->kw_size, src->file_offset); -} - -void ecl_file_kw_free(ecl_file_kw_type *file_kw) { - if (file_kw->kw != NULL) { - ecl_kw_free(file_kw->kw); - file_kw->kw = NULL; - } - free(file_kw->header); - free(file_kw); -} - -void ecl_file_kw_free__(void *arg) { - ecl_file_kw_type *file_kw = ecl_file_kw_safe_cast(arg); - ecl_file_kw_free(file_kw); -} - -bool ecl_file_kw_equal(const ecl_file_kw_type *kw1, - const ecl_file_kw_type *kw2) { - if (kw1->file_offset != kw2->file_offset) - return false; - - if (kw1->kw_size != kw2->kw_size) - return false; - - if (!ecl_type_is_equal(kw1->data_type, kw2->data_type)) - return false; - - return util_string_equal(kw1->header, kw2->header); -} - -static void ecl_file_kw_assert_kw(const ecl_file_kw_type *file_kw) { - if (!ecl_type_is_equal(ecl_file_kw_get_data_type(file_kw), - ecl_kw_get_data_type(file_kw->kw))) - util_abort("%s: type mismatch between header and file.\n", __func__); - - if (file_kw->kw_size != ecl_kw_get_size(file_kw->kw)) - util_abort("%s: size mismatch between header and file.\n", __func__); - - if (strcmp(file_kw->header, ecl_kw_get_header(file_kw->kw)) != 0) - util_abort("%s: name mismatch between header and file.\n", __func__); -} - -static void ecl_file_kw_drop_kw(ecl_file_kw_type *file_kw, - inv_map_type *inv_map) { - if (file_kw->kw != NULL) { - inv_map_drop_kw(inv_map, file_kw->kw); - ecl_kw_free(file_kw->kw); - file_kw->kw = NULL; - } -} - -static void ecl_file_kw_load_kw(ecl_file_kw_type *file_kw, fortio_type *fortio, - inv_map_type *inv_map) { - if (fortio == NULL) - util_abort("%s: trying to load a keyword after the backing file has " - "been detached.\n", - __func__); - - if (file_kw->kw != NULL) - ecl_file_kw_drop_kw(file_kw, inv_map); - - { - fortio_fseek(fortio, file_kw->file_offset, SEEK_SET); - file_kw->kw = ecl_kw_fread_alloc(fortio); - ecl_file_kw_assert_kw(file_kw); - inv_map_add_kw(inv_map, file_kw, file_kw->kw); - } -} - -/* - Calling scope will handle the NULL return value, and (optionally) - reopen the fortio stream and then call the ecl_file_kw_get_kw() - function. -*/ - -ecl_kw_type *ecl_file_kw_get_kw_ptr(ecl_file_kw_type *file_kw) { - if (file_kw->ref_count == 0) - return NULL; - - file_kw->ref_count++; - return file_kw->kw; -} - -/* - Will return the ecl_kw instance of this file_kw; if it is not - currently loaded the method will instantiate the ecl_kw instance - from the @fortio input handle. - - After loading the keyword it will be kept in memory, so a possible - subsequent lookup will be served from memory. - - The ecl_file layer maintains a pointer mapping between the - ecl_kw_type pointers and their ecl_file_kw_type containers; this - mapping needs the new_load return value from the - ecl_file_kw_get_kw() function. -*/ - -ecl_kw_type *ecl_file_kw_get_kw(ecl_file_kw_type *file_kw, fortio_type *fortio, - inv_map_type *inv_map) { - if (file_kw->ref_count == 0) - ecl_file_kw_load_kw(file_kw, fortio, inv_map); - - if (file_kw->kw) - file_kw->ref_count++; - - return file_kw->kw; -} - -bool ecl_file_kw_ptr_eq(const ecl_file_kw_type *file_kw, - const ecl_kw_type *ecl_kw) { - if (file_kw->kw == ecl_kw) - return true; - else - return false; -} - -void ecl_file_kw_replace_kw(ecl_file_kw_type *file_kw, fortio_type *target, - ecl_kw_type *new_kw) { - if (!ecl_type_is_equal(ecl_file_kw_get_data_type(file_kw), - ecl_kw_get_data_type(new_kw))) - util_abort("%s: sorry type mismatch between in-file keyword and new " - "keyword \n", - __func__); - if (file_kw->kw_size != ecl_kw_get_size(new_kw)) - util_abort("%s: sorry size mismatch between in-file keyword and new " - "keyword \n", - __func__); - - if (file_kw->kw != NULL) - ecl_kw_free(file_kw->kw); - - file_kw->kw = new_kw; - fortio_fseek(target, file_kw->file_offset, SEEK_SET); - ecl_kw_fwrite(file_kw->kw, target); -} - -const char *ecl_file_kw_get_header(const ecl_file_kw_type *file_kw) { - return file_kw->header; -} - -int ecl_file_kw_get_size(const ecl_file_kw_type *file_kw) { - return file_kw->kw_size; -} - -ecl_data_type ecl_file_kw_get_data_type(const ecl_file_kw_type *file_kw) { - return file_kw->data_type; -} - -offset_type ecl_file_kw_get_offset(const ecl_file_kw_type *file_kw) { - return file_kw->file_offset; -} - -bool ecl_file_kw_fskip_data(const ecl_file_kw_type *file_kw, - fortio_type *fortio) { - return ecl_kw_fskip_data__(ecl_file_kw_get_data_type(file_kw), - file_kw->kw_size, fortio); -} - -/** - This function will replace the file content of the keyword pointed - to by @file_kw, with the new content given by @ecl_kw. The new - @ecl_kw keyword must have identical header to the one already - present in the file. -*/ - -void ecl_file_kw_inplace_fwrite(ecl_file_kw_type *file_kw, - fortio_type *fortio) { - ecl_file_kw_assert_kw(file_kw); - fortio_fseek(fortio, file_kw->file_offset, SEEK_SET); - ecl_kw_fskip_header(fortio); - fortio_fclean(fortio); - ecl_kw_fwrite_data(file_kw->kw, fortio); -} - -void ecl_file_kw_fwrite(const ecl_file_kw_type *file_kw, FILE *stream) { - int header_length = strlen(file_kw->header); - for (int i = 0; i < ECL_STRING8_LENGTH; i++) { - if (i < header_length) - fputc(file_kw->header[i], stream); - else - fputc(' ', stream); - } - - util_fwrite_int(file_kw->kw_size, stream); - util_fwrite_offset(file_kw->file_offset, stream); - util_fwrite_int(ecl_type_get_type(file_kw->data_type), stream); - util_fwrite_size_t(ecl_type_get_sizeof_iotype(file_kw->data_type), stream); -} - -ecl_file_kw_type **ecl_file_kw_fread_alloc_multiple(FILE *stream, int num) { - - size_t file_kw_size = ECL_STRING8_LENGTH + 2 * sizeof(int) + - sizeof(offset_type) + sizeof(size_t); - size_t buffer_size = num * file_kw_size; - char *buffer = (char *)util_malloc(buffer_size * sizeof *buffer); - size_t num_read = fread(buffer, 1, buffer_size, stream); - - if (num_read != buffer_size) { - free(buffer); - return NULL; - } - - { - ecl_file_kw_type **kw_list = - (ecl_file_kw_type **)util_malloc(num * sizeof *kw_list); - for (int ikw = 0; ikw < num; ikw++) { - int buffer_offset = ikw * file_kw_size; - char header[ECL_STRING8_LENGTH + 1]; - int kw_size; - offset_type file_offset; - ecl_type_enum ecl_type; - size_t type_size; - { - int index = 0; - while (true) { - if (buffer[index + buffer_offset] != ' ') - header[index] = buffer[index + buffer_offset]; - else - break; - - index++; - if (index == ECL_STRING8_LENGTH) - break; - } - header[index] = '\0'; - buffer_offset += ECL_STRING8_LENGTH; - } - - memcpy(&kw_size, &buffer[buffer_offset], sizeof kw_size); - buffer_offset += sizeof kw_size; - - memcpy(&file_offset, &buffer[buffer_offset], sizeof file_offset); - buffer_offset += sizeof file_offset; - - memcpy(&ecl_type, &buffer[buffer_offset], sizeof ecl_type); - buffer_offset += sizeof ecl_type; - - memcpy(&type_size, &buffer[buffer_offset], sizeof type_size); - buffer_offset += sizeof type_size; - - kw_list[ikw] = - ecl_file_kw_alloc0(header, ecl_type_create(ecl_type, type_size), - kw_size, file_offset); - } - - free(buffer); - return kw_list; - } -} - -ecl_file_kw_type *ecl_file_kw_fread_alloc(FILE *stream) { - ecl_file_kw_type *file_kw = NULL; - ecl_file_kw_type **multiple = ecl_file_kw_fread_alloc_multiple(stream, 1); - - if (multiple) { - file_kw = multiple[0]; - free(multiple); - } - - return file_kw; -} - -void ecl_file_kw_start_transaction(const ecl_file_kw_type *file_kw, - int *ref_count) { - *ref_count = file_kw->ref_count; -} - -void ecl_file_kw_end_transaction(ecl_file_kw_type *file_kw, int ref_count) { - if (ref_count == 0 && file_kw->ref_count > 0) { - ecl_kw_free(file_kw->kw); - file_kw->kw = NULL; - } - file_kw->ref_count = ref_count; -} diff --git a/lib/ecl/ecl_file_view.cpp b/lib/ecl/ecl_file_view.cpp deleted file mode 100644 index 9b3c1db270..0000000000 --- a/lib/ecl/ecl_file_view.cpp +++ /dev/null @@ -1,856 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -struct ecl_file_view_struct { - std::vector kw_list; - std::map> kw_index; - std::vector - distinct_kw; /* A list of the keywords occuring in the file - each string occurs ONLY ONCE. */ - fortio_type * - fortio; /* The same fortio instance pointer as in the ecl_file styructure. */ - bool - owner; /* Is this map the owner of the ecl_file_kw instances; only true for the global_map. */ - inv_map_type - *inv_map; /* Shared reference owned by the ecl_file structure. */ - std::vector child_list; - int *flags; -}; - -struct ecl_file_transaction_struct { - const ecl_file_view_type *file_view; - int *ref_count; -}; - -bool ecl_file_view_check_flags(int state_flags, int query_flags) { - if ((state_flags & query_flags) == query_flags) - return true; - else - return false; -} - -bool ecl_file_view_flags_set(const ecl_file_view_type *file_view, - int query_flags) { - return ecl_file_view_check_flags(*file_view->flags, query_flags); -} - -const char *ecl_file_view_get_src_file(const ecl_file_view_type *file_view) { - return fortio_filename_ref(file_view->fortio); -} - -ecl_file_view_type *ecl_file_view_alloc(fortio_type *fortio, int *flags, - inv_map_type *inv_map, bool owner) { - ecl_file_view_type *ecl_file_view = new ecl_file_view_type(); - - ecl_file_view->owner = owner; - ecl_file_view->fortio = fortio; - ecl_file_view->inv_map = inv_map; - ecl_file_view->flags = flags; - - return ecl_file_view; -} - -int ecl_file_view_get_global_index(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith) { - const auto &index_vector = ecl_file_view->kw_index.at(kw); - return index_vector[ith]; -} - -/** - This function iterates over the kw_list vector and builds the - internal index fields 'kw_index' and 'distinct_kw'. This function - must be called every time the content of the kw_list vector is - modified (otherwise the ecl_file instance will be in an - inconsistent state). -*/ - -void ecl_file_view_make_index(ecl_file_view_type *ecl_file_view) { - ecl_file_view->distinct_kw.clear(); - ecl_file_view->kw_index.clear(); - { - int global_index = 0; - for (const auto &file_kw : ecl_file_view->kw_list) { - const std::string &header = ecl_file_kw_get_header(file_kw); - if (ecl_file_view->kw_index.find(header) == - ecl_file_view->kw_index.end()) - ecl_file_view->distinct_kw.push_back(header); - - auto &index_vector = ecl_file_view->kw_index[header]; - index_vector.push_back(global_index); - global_index++; - } - } -} - -bool ecl_file_view_has_kw(const ecl_file_view_type *ecl_file_view, - const char *kw) { - return (ecl_file_view->kw_index.find(kw) != ecl_file_view->kw_index.end()); -} - -ecl_file_kw_type * -ecl_file_view_iget_file_kw(const ecl_file_view_type *ecl_file_view, - int global_index) { - return ecl_file_view->kw_list[global_index]; -} - -ecl_file_kw_type * -ecl_file_view_iget_named_file_kw(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith) { - int global_index = ecl_file_view_get_global_index(ecl_file_view, kw, ith); - ecl_file_kw_type *file_kw = - ecl_file_view_iget_file_kw(ecl_file_view, global_index); - return file_kw; -} - -bool ecl_file_view_drop_flag(ecl_file_view_type *file_view, int flag) { - bool flag_set = ecl_file_view_flags_set(file_view, flag); - if (flag_set) - *file_view->flags -= flag; - - return flag_set; -} - -void ecl_file_view_add_flag(ecl_file_view_type *file_view, int flag) { - *file_view->flags |= flag; -} - -static ecl_kw_type * -ecl_file_view_get_kw(const ecl_file_view_type *ecl_file_view, - ecl_file_kw_type *file_kw) { - ecl_kw_type *ecl_kw = ecl_file_kw_get_kw_ptr(file_kw); - if (!ecl_kw) { - if (fortio_assert_stream_open(ecl_file_view->fortio)) { - - ecl_kw = ecl_file_kw_get_kw(file_kw, ecl_file_view->fortio, - ecl_file_view->inv_map); - - if (ecl_file_view_flags_set(ecl_file_view, ECL_FILE_CLOSE_STREAM)) - fortio_fclose_stream(ecl_file_view->fortio); - } - } - return ecl_kw; -} - -ecl_kw_type *ecl_file_view_iget_kw(const ecl_file_view_type *ecl_file_view, - int index) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_file_kw(ecl_file_view, index); - return ecl_file_view_get_kw(ecl_file_view, file_kw); -} - -void ecl_file_view_index_fload_kw(const ecl_file_view_type *ecl_file_view, - const char *kw, int index, - const int_vector_type *index_map, - char *io_buffer) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_named_file_kw(ecl_file_view, kw, index); - - if (fortio_assert_stream_open(ecl_file_view->fortio)) { - offset_type offset = ecl_file_kw_get_offset(file_kw); - ecl_data_type data_type = ecl_file_kw_get_data_type(file_kw); - int element_count = ecl_file_kw_get_size(file_kw); - - ecl_kw_fread_indexed_data(ecl_file_view->fortio, - offset + ECL_KW_HEADER_FORTIO_SIZE, data_type, - element_count, index_map, io_buffer); - } -} - -int ecl_file_view_find_kw_value(const ecl_file_view_type *ecl_file_view, - const char *kw, const void *value) { - int global_index = -1; - if (ecl_file_view_has_kw(ecl_file_view, kw)) { - const auto &index_list = ecl_file_view->kw_index.at(kw); - size_t index = 0; - while (index < index_list.size()) { - const ecl_kw_type *ecl_kw = - ecl_file_view_iget_kw(ecl_file_view, index_list[index]); - if (ecl_kw_data_equal(ecl_kw, value)) { - global_index = index_list[index]; - break; - } - index++; - } - } - return global_index; -} - -const char * -ecl_file_view_iget_distinct_kw(const ecl_file_view_type *ecl_file_view, - int index) { - const std::string &string = ecl_file_view->distinct_kw[index]; - return string.c_str(); -} - -int ecl_file_view_get_num_distinct_kw(const ecl_file_view_type *ecl_file_view) { - return ecl_file_view->distinct_kw.size(); -} - -int ecl_file_view_get_size(const ecl_file_view_type *ecl_file_view) { - return ecl_file_view->kw_list.size(); -} - -ecl_data_type -ecl_file_view_iget_data_type(const ecl_file_view_type *ecl_file_view, - int index) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_file_kw(ecl_file_view, index); - return ecl_file_kw_get_data_type(file_kw); -} - -int ecl_file_view_iget_size(const ecl_file_view_type *ecl_file_view, - int index) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_file_kw(ecl_file_view, index); - return ecl_file_kw_get_size(file_kw); -} - -const char *ecl_file_view_iget_header(const ecl_file_view_type *ecl_file_view, - int index) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_file_kw(ecl_file_view, index); - return ecl_file_kw_get_header(file_kw); -} - -ecl_kw_type * -ecl_file_view_iget_named_kw(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_named_file_kw(ecl_file_view, kw, ith); - return ecl_file_view_get_kw(ecl_file_view, file_kw); -} - -ecl_data_type -ecl_file_view_iget_named_data_type(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_named_file_kw(ecl_file_view, kw, ith); - return ecl_file_kw_get_data_type(file_kw); -} - -int ecl_file_view_iget_named_size(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith) { - ecl_file_kw_type *file_kw = - ecl_file_view_iget_named_file_kw(ecl_file_view, kw, ith); - return ecl_file_kw_get_size(file_kw); -} - -void ecl_file_view_replace_kw(ecl_file_view_type *ecl_file_view, - ecl_kw_type *old_kw, ecl_kw_type *new_kw, - bool insert_copy) { - size_t index = 0; - while (index < ecl_file_view->kw_list.size()) { - auto *ikw = ecl_file_view->kw_list[index]; - if (ecl_file_kw_ptr_eq(ikw, old_kw)) { - /* - Found it; observe that the vector_iset() function will - automatically invoke the destructor on the old_kw. - */ - ecl_kw_type *insert_kw = new_kw; - - if (insert_copy) - insert_kw = ecl_kw_alloc_copy(new_kw); - ecl_file_kw_replace_kw(ikw, ecl_file_view->fortio, insert_kw); - - ecl_file_view_make_index(ecl_file_view); - return; - } - index++; - } - util_abort("%s: could not find ecl_kw ptr: %p \n", __func__, old_kw); -} - -bool ecl_file_view_load_all(ecl_file_view_type *ecl_file_view) { - bool loadOK = false; - - if (fortio_assert_stream_open(ecl_file_view->fortio)) { - for (ecl_file_kw_type *file_kw : ecl_file_view->kw_list) - ecl_file_kw_get_kw(file_kw, ecl_file_view->fortio, - ecl_file_view->inv_map); - loadOK = true; - } - - if (ecl_file_view_flags_set(ecl_file_view, ECL_FILE_CLOSE_STREAM)) - fortio_fclose_stream(ecl_file_view->fortio); - - return loadOK; -} - -void ecl_file_view_add_kw(ecl_file_view_type *ecl_file_view, - ecl_file_kw_type *file_kw) { - ecl_file_view->kw_list.push_back(file_kw); -} - -void ecl_file_view_free(ecl_file_view_type *ecl_file_view) { - - for (auto &child_ptr : ecl_file_view->child_list) - ecl_file_view_free(child_ptr); - - if (ecl_file_view->owner) { - for (auto &kw_ptr : ecl_file_view->kw_list) - ecl_file_kw_free(kw_ptr); - } - - delete ecl_file_view; -} - -void ecl_file_view_free__(void *arg) { - ecl_file_view_type *ecl_file_view = (ecl_file_view_type *)arg; - ecl_file_view_free(ecl_file_view); -} - -int ecl_file_view_get_num_named_kw(const ecl_file_view_type *ecl_file_view, - const char *kw) { - if (ecl_file_view_has_kw(ecl_file_view, kw)) { - const auto &index_vector = ecl_file_view->kw_index.at(kw); - return index_vector.size(); - } else - return 0; -} - -void ecl_file_view_fwrite(const ecl_file_view_type *ecl_file_view, - fortio_type *target, int offset) { - for (size_t index = offset; index < ecl_file_view->kw_list.size(); - index++) { - ecl_kw_type *ecl_kw = ecl_file_view_iget_kw(ecl_file_view, index); - ecl_kw_fwrite(ecl_kw, target); - } -} - -int ecl_file_view_iget_occurence(const ecl_file_view_type *ecl_file_view, - int global_index) { - const ecl_file_kw_type *file_kw = ecl_file_view->kw_list[global_index]; - const char *header = ecl_file_kw_get_header(file_kw); - const auto &index_vector = ecl_file_view->kw_index.at(header); - - int occurence = -1; - { - /* Manual reverse lookup. */ - for (size_t i = 0; i < index_vector.size(); i++) { - if (index_vector[i] == global_index) - occurence = i; - } - } - if (occurence < 0) - util_abort("%s: internal error ... \n", __func__); - - return occurence; -} - -void ecl_file_view_fprintf_kw_list(const ecl_file_view_type *ecl_file_view, - FILE *stream) { - for (auto &file_kw : ecl_file_view->kw_list) { - char *type_name = - ecl_type_alloc_name(ecl_file_kw_get_data_type(file_kw)); - fprintf(stream, "%-8s %7d:%s\n", ecl_file_kw_get_header(file_kw), - ecl_file_kw_get_size(file_kw), type_name); - free(type_name); - } -} - -ecl_file_view_type * -ecl_file_view_alloc_blockview2(const ecl_file_view_type *ecl_file_view, - const char *start_kw, const char *end_kw, - int occurence) { - if ((start_kw != NULL) && - ecl_file_view_get_num_named_kw(ecl_file_view, start_kw) <= occurence) - return NULL; - - ecl_file_view_type *block_map = - ecl_file_view_alloc(ecl_file_view->fortio, ecl_file_view->flags, - ecl_file_view->inv_map, false); - size_t kw_index = 0; - if (start_kw) - kw_index = - ecl_file_view_get_global_index(ecl_file_view, start_kw, occurence); - - { - ecl_file_kw_type *file_kw = ecl_file_view->kw_list[kw_index]; - while (true) { - ecl_file_view_add_kw(block_map, file_kw); - - kw_index++; - if (kw_index == ecl_file_view->kw_list.size()) - break; - else { - if (end_kw) { - file_kw = ecl_file_view->kw_list[kw_index]; - if (strcmp(end_kw, ecl_file_kw_get_header(file_kw)) == 0) - break; - } - } - } - } - ecl_file_view_make_index(block_map); - return block_map; -} - -/** - Will return NULL if the block which is asked for is not present. -*/ -ecl_file_view_type * -ecl_file_view_alloc_blockview(const ecl_file_view_type *ecl_file_view, - const char *header, int occurence) { - return ecl_file_view_alloc_blockview2(ecl_file_view, header, header, - occurence); -} - -ecl_file_view_type *ecl_file_view_add_blockview(ecl_file_view_type *file_view, - const char *header, - int occurence) { - ecl_file_view_type *child = - ecl_file_view_alloc_blockview2(file_view, header, header, occurence); - - if (child) - file_view->child_list.push_back(child); - - return child; -} - -ecl_file_view_type * -ecl_file_view_add_blockview2(ecl_file_view_type *ecl_file_view, - const char *start_kw, const char *end_kw, - int occurence) { - ecl_file_view_type *child = ecl_file_view_alloc_blockview2( - ecl_file_view, start_kw, end_kw, occurence); - - if (child) - ecl_file_view->child_list.push_back(child); - - return child; -} - -/* - There is no special datastructure for working with restart files, - they are 100% stock ecl_file instances with the following limited - structure: - - * They are organized in blocks; where each block starts with a - SEQNUM keyword, which contains the report step. - - * Each block contains an INTEHEAD keyword, immediately after the - SEQNUM keyword, which contains the true simulation date of of the - block, and also some other data. Observe that also INIT files and - GRID files contain an INTEHEAD keyword; and that for files with - LGRs there is one INTEHEAD keyword for each LGR. This creates an - extra level of mess. - - The natural time ordering when working with the file data is just - the running index in the file; however from a user perspective the - natural way to indicate time coordinate is through the report step - or the true simulation time (i.e. 22.th of October 2009). This file - is all about converting the natural input unit time and report_step - to the internal indexing. This is achieved by consulting the value - of the INTEHEAD and SEQNUM keywords respectively. -*/ - -/* -About the time-direction -======================== - -For the following discussion we will focus on the following simplified -unified restart file. The leading number is the global index of the -keyword, the value in [] corresponds to the relevant part of the -content of the keyword on the line, the labels A,B,C,D,E are used for -references in the text below. - - 0 | SEQNUM [0] \ A - 1 | INTEHEAD [01.01.2005] | - 2 | PRESSURE [... ] | - 3 | SWAT [...] | - | -----------------------+ - 4 | SEQNUM [5] | B - 5 | INTEHEAD [01.06.2005] | - 6 | PRESSURE [... ] | - 7 | SWAT [...] | - |------------------------+ - 8 | SEQNUM [10] | C - 9 | INTEHEAD [01.12.2006] | -10 | PRESSURE [...] | -11 | SWAT [...] | - |------------------------+ -12 | SEQNUM [20] | D -13 | INTEHEAD [01.12.2007] | -14 | PRESSURE [...] | -15 | SWAT [...] | -16 | OIL_DEN [...] | - |------------------------+ -17 | SEQNUM [40] | E -18 | INTEHEAD [01.12.2009] | -19 | PRESSURE [...] | -20 | SWAT [...] / - - -This restart file has the following features: - - o It contains in total 16 keywords. - - o It contains 5 blocks of collected keywords corresponding to one - time instant, each of these blocks is called a report_step, - typcially coming from one DATES keyword in the ECLIPSE - datafile. Observe that the file does not have the block structure - visualized on this figure, the only thing separating the blocks in - the file is the occurence of a SEQNUM keyword. - - o Only a few of the report steps are present, namely 0, 5, 10, 20 and - 40. - - o The different blocks are not equally long, the fourth block has an - extra keyword OIL_DEN. - -To adress these keywords and blocks using different time coordinates -we have introduced the following concepts: - - report_step: This corresponds to the value of the SEQNUM keword, - i.e. to do queries based on the report_step we must load the - seqnum kewyord and read the value. - - ecl_file_get_unrstmap_report_step( ecl_file , 0 ) => A - ecl_file_get_unrstmap_report_step( ecl_file , 1 ) => NULL - - ecl_file_has_report_step( ecl_file , 5 ) => True - ecl_file_has_report_step( ecl_file , 2 ) => False - - sim_time: This correpsonds to the true simulation time of the report - step, the simulation time is stored as integers DAY, MONTH, YEAR - in the INTEHEAD keyword; the function INTEHEAD_date() will extract - the DAY, MONTH and YEAR values from an INTEHEAD keyword instance - and convert to a time_t instance. The functions: - - ecl_file_get_unrstmap_sim_time() and ecl_file_has_has_sim_time() - - can be used to query for simulation times and get the - corresponding block maps. - - index/global_index : This is typically the global running index of - the keyword in the file; this is the unique address of the keyword - which is used for the final lookup. - - occurence: The nth' time a particular keyword has occured in the - file, i.e. the SEQNUM keyword in block C is the third occurence of - SEQNUM. Instead of occurence xxxx_index is also used to indicate - the occurence of keyword xxxx. The occurence number is the integer - argument to the xxx_iget_named_kw() function, and also the final - call to create blockmaps. - -*/ - -bool ecl_file_view_has_report_step(const ecl_file_view_type *ecl_file_view, - int report_step) { - int global_index = - ecl_file_view_find_kw_value(ecl_file_view, SEQNUM_KW, &report_step); - if (global_index >= 0) - return true; - else - return false; -} - -time_t -ecl_file_view_iget_restart_sim_date(const ecl_file_view_type *ecl_file_view, - int seqnum_index) { - time_t sim_time = -1; - ecl_file_view_type *seqnum_map = - ecl_file_view_alloc_blockview(ecl_file_view, SEQNUM_KW, seqnum_index); - - if (seqnum_map != NULL) { - ecl_kw_type *intehead_kw = - ecl_file_view_iget_named_kw(seqnum_map, INTEHEAD_KW, 0); - sim_time = ecl_rsthead_date(intehead_kw); - ecl_file_view_free(seqnum_map); - } - - return sim_time; -} - -double -ecl_file_view_iget_restart_sim_days(const ecl_file_view_type *ecl_file_view, - int seqnum_index) { - double sim_days = 0; - ecl_file_view_type *seqnum_map = - ecl_file_view_alloc_blockview(ecl_file_view, SEQNUM_KW, seqnum_index); - - if (seqnum_map != NULL) { - ecl_kw_type *doubhead_kw = - ecl_file_view_iget_named_kw(seqnum_map, DOUBHEAD_KW, 0); - sim_days = ecl_kw_iget_double(doubhead_kw, DOUBHEAD_DAYS_INDEX); - ecl_file_view_free(seqnum_map); - } - - return sim_days; -} - -int ecl_file_view_find_sim_time(const ecl_file_view_type *ecl_file_view, - time_t sim_time) { - int seqnum_index = -1; - if (ecl_file_view_has_kw(ecl_file_view, INTEHEAD_KW)) { - const auto &intehead_index_list = - ecl_file_view->kw_index.at(INTEHEAD_KW); - size_t index = 0; - while (index < intehead_index_list.size()) { - const ecl_kw_type *intehead_kw = ecl_file_view_iget_kw( - ecl_file_view, intehead_index_list[index]); - if (ecl_rsthead_date(intehead_kw) == sim_time) { - seqnum_index = index; - break; - } - index++; - } - } - return seqnum_index; -} - -/** - This function will scan through the ecl_file looking for INTEHEAD - headers corresponding to sim_time. If sim_time is found the - function will return the INTEHEAD occurence number, i.e. for a - unified restart file like: - - INTEHEAD / 01.01.2000 - ... - PRESSURE - SWAT - ... - INTEHEAD / 01.03.2000 - ... - PRESSURE - SWAT - ... - INTEHEAD / 01.05.2000 - ... - PRESSURE - SWAT - .... - - The function call: - - ecl_file_get_restart_index( restart_file , (time_t) "01.03.2000") - - will return 1. Observe that this will in general NOT agree with the - DATES step number. - - If the sim_time can not be found the function will return -1, that - includes the case when the file in question is not a restart file - at all, and no INTEHEAD headers can be found. - - Observe that the function requires on-the-second-equality; which is - of course quite strict. - - Each report step only has one occurence of SEQNUM, but one INTEHEAD - for each LGR; i.e. one should call iselect_rstblock() prior to - calling this function. -*/ - -bool ecl_file_view_has_sim_time(const ecl_file_view_type *ecl_file_view, - time_t sim_time) { - int num_INTEHEAD = - ecl_file_view_get_num_named_kw(ecl_file_view, INTEHEAD_KW); - if (num_INTEHEAD == 0) - return false; /* We have no INTEHEAD headers - probably not a restart file at all. */ - else { - int intehead_index = 0; - while (true) { - time_t itime = ecl_file_view_iget_restart_sim_date(ecl_file_view, - intehead_index); - - if (itime == sim_time) /* Perfect hit. */ - return true; - - if (itime > - sim_time) /* We have gone past the target_time - i.e. we do not have it. */ - return false; - - intehead_index++; - if (intehead_index == - num_INTEHEAD) /* We have iterated through the whole thing without finding sim_time. */ - return false; - } - } -} - -bool ecl_file_view_has_sim_days(const ecl_file_view_type *ecl_file_view, - double sim_days) { - int num_DOUBHEAD = - ecl_file_view_get_num_named_kw(ecl_file_view, DOUBHEAD_KW); - if (num_DOUBHEAD == 0) - return false; /* We have no DOUBHEAD headers - probably not a restart file at all. */ - else { - int doubhead_index = 0; - while (true) { - double file_sim_days = ecl_file_view_iget_restart_sim_days( - ecl_file_view, doubhead_index); - - if (util_double_approx_equal(sim_days, - file_sim_days)) /* Perfect hit. */ - return true; - - if (file_sim_days > - sim_days) /* We have gone past the target_time - i.e. we do not have it. */ - return false; - - doubhead_index++; - if (doubhead_index == - num_DOUBHEAD) /* We have iterated through the whole thing without finding sim_time. */ - return false; - } - } -} - -int ecl_file_view_seqnum_index_from_sim_time(ecl_file_view_type *parent_map, - time_t sim_time) { - int num_seqnum = ecl_file_view_get_num_named_kw(parent_map, SEQNUM_KW); - ecl_file_view_type *seqnum_map; - - for (int s_idx = 0; s_idx < num_seqnum; s_idx++) { - seqnum_map = - ecl_file_view_alloc_blockview(parent_map, SEQNUM_KW, s_idx); - - if (!seqnum_map) - continue; - - bool sim = ecl_file_view_has_sim_time(seqnum_map, sim_time); - ecl_file_view_free(seqnum_map); - if (sim) - return s_idx; - } - return -1; -} - -int ecl_file_view_seqnum_index_from_sim_days(ecl_file_view_type *file_view, - double sim_days) { - int num_seqnum = ecl_file_view_get_num_named_kw(file_view, SEQNUM_KW); - int seqnum_index = 0; - ecl_file_view_type *seqnum_map; - - while (true) { - seqnum_map = - ecl_file_view_alloc_blockview(file_view, SEQNUM_KW, seqnum_index); - - if (seqnum_map != NULL) { - if (ecl_file_view_has_sim_days(seqnum_map, sim_days)) { - ecl_file_view_free(seqnum_map); - return seqnum_index; - } else { - ecl_file_view_free(seqnum_map); - seqnum_index++; - } - } - - if (num_seqnum == seqnum_index) - return -1; - } -} - -/* - Will mulitplex on the four input arguments. -*/ -ecl_file_view_type * -ecl_file_view_add_restart_view(ecl_file_view_type *file_view, int input_index, - int report_step, time_t sim_time, - double sim_days) { - ecl_file_view_type *child = NULL; - int seqnum_index = -1; - - if (input_index >= 0) - seqnum_index = input_index; - else if (report_step >= 0) { - int global_index = - ecl_file_view_find_kw_value(file_view, SEQNUM_KW, &report_step); - if (global_index >= 0) - seqnum_index = - ecl_file_view_iget_occurence(file_view, global_index); - } else if (sim_time != -1) - seqnum_index = - ecl_file_view_seqnum_index_from_sim_time(file_view, sim_time); - else if (sim_days >= 0) - seqnum_index = - ecl_file_view_seqnum_index_from_sim_days(file_view, sim_days); - - if (seqnum_index >= 0) - child = ecl_file_view_add_blockview(file_view, SEQNUM_KW, seqnum_index); - - return child; -} - -ecl_file_view_type * -ecl_file_view_add_summary_view(ecl_file_view_type *file_view, int report_step) { - ecl_file_view_type *child = - ecl_file_view_add_blockview(file_view, SEQHDR_KW, report_step); - return child; -} - -void ecl_file_view_fclose_stream(ecl_file_view_type *file_view) { - fortio_fclose_stream(file_view->fortio); -} - -void ecl_file_view_write_index(const ecl_file_view_type *file_view, - FILE *ostream) { - int size = ecl_file_view_get_size(file_view); - util_fwrite_int(size, ostream); - - ecl_file_kw_type *file_kw; - for (int i = 0; i < size; i++) { - file_kw = ecl_file_view_iget_file_kw(file_view, i); - ecl_file_kw_fwrite(file_kw, ostream); - } -} - -ecl_file_view_type *ecl_file_view_fread_alloc(fortio_type *fortio, int *flags, - inv_map_type *inv_map, - FILE *istream) { - - int index_size = util_fread_int(istream); - ecl_file_kw_type **file_kw_list = - ecl_file_kw_fread_alloc_multiple(istream, index_size); - if (file_kw_list) { - ecl_file_view_type *file_view = - ecl_file_view_alloc(fortio, flags, inv_map, true); - for (int i = 0; i < index_size; i++) - ecl_file_view_add_kw(file_view, file_kw_list[i]); - - free(file_kw_list); - ecl_file_view_make_index(file_view); - return file_view; - } else { - fprintf(stderr, "%s: error reading ecl_file_type index file.\n", - __func__); - return NULL; - } -} - -ecl_file_transaction_type * -ecl_file_view_start_transaction(ecl_file_view_type *file_view) { - ecl_file_transaction_type *t = - (ecl_file_transaction_type *)util_malloc(sizeof *t); - int size = ecl_file_view_get_size(file_view); - t->file_view = file_view; - t->ref_count = (int *)util_malloc(size * sizeof *t->ref_count); - for (int i = 0; i < size; i++) { - ecl_file_kw_type *file_kw = ecl_file_view_iget_file_kw(file_view, i); - ecl_file_kw_start_transaction(file_kw, &t->ref_count[i]); - } - - return t; -} - -void ecl_file_view_end_transaction(ecl_file_view_type *file_view, - ecl_file_transaction_type *transaction) { - if (transaction->file_view != file_view) - util_abort("%s: internal error - file_view / transaction mismatch\n", - __func__); - - const int *ref_count = transaction->ref_count; - for (int i = 0; i < ecl_file_view_get_size(file_view); i++) { - ecl_file_kw_type *file_kw = ecl_file_view_iget_file_kw(file_view, i); - ecl_file_kw_end_transaction(file_kw, ref_count[i]); - } - free(transaction->ref_count); - free(transaction); -} diff --git a/lib/ecl/ecl_grav.cpp b/lib/ecl/ecl_grav.cpp deleted file mode 100644 index 180719abd4..0000000000 --- a/lib/ecl/ecl_grav.cpp +++ /dev/null @@ -1,697 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "detail/ecl/ecl_grid_cache.hpp" - -/** - This file contains datastructures for calculating changes in - gravitational response in reservoirs. The main datastructure is the - ecl_grav_type structure (which is the only structure which is - exported). -*/ - -#define GRAV_CALC_USE_PORV 128 -#define GRAV_CALC_USE_RHO \ - 256 // The GRAV_CALC_USE_RHO value is currently not used. - -typedef enum { - GRAV_CALC_RPORV = 1 + GRAV_CALC_USE_PORV + GRAV_CALC_USE_RHO, - GRAV_CALC_PORMOD = 2 + GRAV_CALC_USE_PORV + GRAV_CALC_USE_RHO, - GRAV_CALC_FIP = 3, - GRAV_CALC_RFIP = 4 + GRAV_CALC_USE_RHO -} grav_calc_type; - -typedef struct ecl_grav_phase_struct ecl_grav_phase_type; - -/** - The ecl_grav_struct datastructure is the main structure for - calculating the gravimetric response from time lapse ECLIPSE - simulations. -*/ - -struct ecl_grav_struct { - const ecl_file_type * - init_file; /* The init file - a shared reference owned by calling scope. */ - ecl::ecl_grid_cache * - grid_cache; /* An internal specialized structure to facilitate fast grid lookup. */ - bool *aquifer_cell; /* Numerical aquifer cells should be ignored. */ - - std::unordered_map surveys; - std::unordered_map default_density; - std::unordered_map> std_density; -}; - -/** - Data structure representing one gravimetric survey. -*/ - -#define ECL_GRAV_SURVEY_ID 88517 -struct ecl_grav_survey_struct { - UTIL_TYPE_ID_DECLARATION; - const ecl::ecl_grid_cache *grid_cache; - const bool *aquifer_cell; - char *name; /* Name of the survey - arbitrary string. */ - double * - porv; /* Reference shared by the ecl_grav_phase structures - i.e. it must not be updated. */ - std::vector - phase_list; /* ecl_grav_phase_type objects - one for each phase present in the model. */ - std::unordered_map - phase_map; /* The same objects as in the phase_list vector - accessible by the "SWAT", "SGAS" and "SOIL" keys. */ -}; - -/** - Data structure representing the results from one phase at one survey. -*/ - -#define ECL_GRAV_PHASE_TYPE_ID 1066652 -struct ecl_grav_phase_struct { - UTIL_TYPE_ID_DECLARATION; - const ecl::ecl_grid_cache *grid_cache; - const bool *aquifer_cell; - double * - fluid_mass; /* The total fluid in place (mass) of this phase - for each active cell.*/ - double *work; /* Temporary used in the summation over all cells. */ - ecl_phase_enum phase; -}; - -static const char *get_den_kw(ecl_phase_enum phase, - ecl_version_enum ecl_version) { - if (ecl_version == ECLIPSE100) { - switch (phase) { - case (ECL_OIL_PHASE): - return ECLIPSE100_OIL_DEN_KW; - break; - case (ECL_GAS_PHASE): - return ECLIPSE100_GAS_DEN_KW; - break; - case (ECL_WATER_PHASE): - return ECLIPSE100_WATER_DEN_KW; - break; - default: - util_abort("%s: unrecognized phase id:%d \n", __func__, phase); - return NULL; - } - } else if ((ecl_version == ECLIPSE300) || - (ecl_version == ECLIPSE300_THERMAL)) { - switch (phase) { - case (ECL_OIL_PHASE): - return ECLIPSE300_OIL_DEN_KW; - break; - case (ECL_GAS_PHASE): - return ECLIPSE300_GAS_DEN_KW; - break; - case (ECL_WATER_PHASE): - return ECLIPSE300_WATER_DEN_KW; - break; - default: - util_abort("%s: unrecognized phase id:%d \n", __func__, phase); - return NULL; - } - } else { - util_abort("%s: unrecognized simulator id:%d \n", __func__, - ecl_version); - return NULL; - } -} - -static void ecl_grav_phase_ensure_work(ecl_grav_phase_type *grav_phase) { - if (grav_phase->work == NULL) - grav_phase->work = (double *)util_calloc(grav_phase->grid_cache->size(), - sizeof *grav_phase->work); -} - -static double ecl_grav_phase_eval(ecl_grav_phase_type *base_phase, - const ecl_grav_phase_type *monitor_phase, - ecl_region_type *region, double utm_x, - double utm_y, double depth) { - - ecl_grav_phase_ensure_work(base_phase); - if ((monitor_phase == NULL) || - (base_phase->phase == monitor_phase->phase)) { - const ecl::ecl_grid_cache &grid_cache = *(base_phase->grid_cache); - const bool *aquifer = base_phase->aquifer_cell; - double *mass_diff = base_phase->work; - double deltag; - /* - Initialize a work array to contain the difference in mass for - every cell. - */ - { - int index; - if (monitor_phase == NULL) { - for (index = 0; index < grid_cache.size(); index++) - mass_diff[index] = -base_phase->fluid_mass[index]; - } else { - for (index = 0; index < grid_cache.size(); index++) - mass_diff[index] = monitor_phase->fluid_mass[index] - - base_phase->fluid_mass[index]; - } - } - - /** - The Gravitational constant is 6.67E-11 N (m/kg)^2, we - return the result in microGal, i.e. we scale with 10^2 * - 10^6 => 6.67E-3. - */ - deltag = 6.67428E-3 * ecl_grav_common_eval_biot_savart( - grid_cache, region, aquifer, mass_diff, utm_x, - utm_y, depth); - - return deltag; - } else { - util_abort("%s comparing different phases ... \n", __func__); - return -1; - } -} - -static ecl_grav_phase_type *ecl_grav_phase_alloc( - ecl_grav_type *ecl_grav, ecl_grav_survey_type *survey, ecl_phase_enum phase, - const ecl_file_view_type *restart_file, grav_calc_type calc_type) { - - const ecl_file_type *init_file = ecl_grav->init_file; - const ecl::ecl_grid_cache *grid_cache = ecl_grav->grid_cache; - const char *sat_kw_name = ecl_util_get_phase_name(phase); - { - ecl_grav_phase_type *grav_phase = new ecl_grav_phase_type(); - const int size = grid_cache->size(); - - UTIL_TYPE_ID_INIT(grav_phase, ECL_GRAV_PHASE_TYPE_ID); - grav_phase->grid_cache = grid_cache; - grav_phase->aquifer_cell = ecl_grav->aquifer_cell; - grav_phase->fluid_mass = - (double *)util_calloc(size, sizeof *grav_phase->fluid_mass); - grav_phase->phase = phase; - grav_phase->work = NULL; - - if (calc_type == GRAV_CALC_FIP) { - ecl_kw_type *pvtnum_kw = - ecl_file_iget_named_kw(init_file, PVTNUM_KW, 0); - const std::vector std_density = - ecl_grav - ->std_density[std::string(ecl_util_get_phase_name(phase))]; - ecl_kw_type *fip_kw; - - if (phase == ECL_OIL_PHASE) - fip_kw = - ecl_file_view_iget_named_kw(restart_file, FIPOIL_KW, 0); - else if (phase == ECL_GAS_PHASE) - fip_kw = - ecl_file_view_iget_named_kw(restart_file, FIPGAS_KW, 0); - else - fip_kw = - ecl_file_view_iget_named_kw(restart_file, FIPWAT_KW, 0); - - { - int iactive; - for (iactive = 0; iactive < size; iactive++) { - double fip = ecl_kw_iget_as_double(fip_kw, iactive); - int pvtnum = ecl_kw_iget_int(pvtnum_kw, iactive); - grav_phase->fluid_mass[iactive] = fip * std_density[pvtnum]; - } - } - } else { - ecl_version_enum ecl_version = ecl_file_get_ecl_version(init_file); - const char *den_kw_name = get_den_kw(phase, ecl_version); - const ecl_kw_type *den_kw = - ecl_file_view_iget_named_kw(restart_file, den_kw_name, 0); - - if (calc_type == GRAV_CALC_RFIP) { - ecl_kw_type *rfip_kw; - if (phase == ECL_OIL_PHASE) - rfip_kw = ecl_file_view_iget_named_kw(restart_file, - RFIPOIL_KW, 0); - else if (phase == ECL_GAS_PHASE) - rfip_kw = ecl_file_view_iget_named_kw(restart_file, - RFIPGAS_KW, 0); - else - rfip_kw = ecl_file_view_iget_named_kw(restart_file, - RFIPWAT_KW, 0); - - { - int iactive; - for (iactive = 0; iactive < size; iactive++) { - double rho = ecl_kw_iget_as_double(den_kw, iactive); - double rfip = ecl_kw_iget_as_double(rfip_kw, iactive); - grav_phase->fluid_mass[iactive] = rho * rfip; - } - } - } else { - /* (calc_type == GRAV_CALC_RPORV) || (calc_type == GRAV_CALC_PORMOD) */ - ecl_kw_type *sat_kw; - bool private_sat_kw = false; - if (ecl_file_view_has_kw(restart_file, sat_kw_name)) - sat_kw = ecl_file_view_iget_named_kw(restart_file, - sat_kw_name, 0); - else { - /* We are targeting the residual phase, e.g. the OIL phase in a three phase system. */ - const ecl_kw_type *swat_kw = - ecl_file_view_iget_named_kw(restart_file, "SWAT", 0); - sat_kw = ecl_kw_alloc_copy(swat_kw); - ecl_kw_scalar_set_float(sat_kw, 1.0); - ecl_kw_inplace_sub(sat_kw, swat_kw); /* sat = 1 - SWAT */ - - if (ecl_file_view_has_kw(restart_file, "SGAS")) { - const ecl_kw_type *sgas_kw = - ecl_file_view_iget_named_kw(restart_file, "SGAS", - 0); - ecl_kw_inplace_sub(sat_kw, sgas_kw); /* sat -= SGAS */ - } - private_sat_kw = true; - } - - { - int iactive; - for (iactive = 0; iactive < size; iactive++) { - double rho = ecl_kw_iget_as_double(den_kw, iactive); - double sat = ecl_kw_iget_as_double(sat_kw, iactive); - grav_phase->fluid_mass[iactive] = - rho * sat * survey->porv[iactive]; - } - } - - if (private_sat_kw) - ecl_kw_free(sat_kw); - } - } - - return grav_phase; - } -} - -static void ecl_grav_phase_free(ecl_grav_phase_type *grav_phase) { - free(grav_phase->work); - free(grav_phase->fluid_mass); - delete grav_phase; -} - -static void ecl_grav_survey_add_phase(ecl_grav_survey_type *survey, - ecl_phase_enum phase, - ecl_grav_phase_type *grav_phase) { - survey->phase_list.push_back(grav_phase); - survey->phase_map[std::string(ecl_util_get_phase_name(phase))] = grav_phase; -} - -static void ecl_grav_survey_add_phases(ecl_grav_type *ecl_grav, - ecl_grav_survey_type *survey, - const ecl_file_view_type *restart_file, - grav_calc_type calc_type) { - int phases = ecl_file_get_phases(ecl_grav->init_file); - if (phases & ECL_OIL_PHASE) { - ecl_grav_phase_type *oil_phase = ecl_grav_phase_alloc( - ecl_grav, survey, ECL_OIL_PHASE, restart_file, calc_type); - ecl_grav_survey_add_phase(survey, ECL_OIL_PHASE, oil_phase); - } - - if (phases & ECL_GAS_PHASE) { - ecl_grav_phase_type *gas_phase = ecl_grav_phase_alloc( - ecl_grav, survey, ECL_GAS_PHASE, restart_file, calc_type); - ecl_grav_survey_add_phase(survey, ECL_GAS_PHASE, gas_phase); - } - - if (phases & ECL_WATER_PHASE) { - ecl_grav_phase_type *water_phase = ecl_grav_phase_alloc( - ecl_grav, survey, ECL_WATER_PHASE, restart_file, calc_type); - ecl_grav_survey_add_phase(survey, ECL_WATER_PHASE, water_phase); - } -} - -static ecl_grav_survey_type * -ecl_grav_survey_alloc_empty(const ecl_grav_type *ecl_grav, const char *name, - grav_calc_type calc_type) { - ecl_grav_survey_type *survey = new ecl_grav_survey_type(); - UTIL_TYPE_ID_INIT(survey, ECL_GRAV_SURVEY_ID); - survey->grid_cache = ecl_grav->grid_cache; - survey->aquifer_cell = ecl_grav->aquifer_cell; - survey->name = util_alloc_string_copy(name); - - if (calc_type & GRAV_CALC_USE_PORV) - survey->porv = (double *)util_calloc(ecl_grav->grid_cache->size(), - sizeof *survey->porv); - else - survey->porv = NULL; - - return survey; -} - -/** - Check that the rporv values are in the right ballpark. For ECLIPSE - version 2008.2 they are way off. Check PORV versus RPORV - for some random locations in the grid. -*/ - -static void ecl_grav_survey_assert_RPORV(const ecl_grav_survey_type *survey, - const ecl_file_type *init_file) { - const ecl::ecl_grid_cache &grid_cache = *(survey->grid_cache); - int active_size = grid_cache.size(); - const ecl_kw_type *init_porv_kw = - ecl_file_iget_named_kw(init_file, PORV_KW, 0); - int check_points = 100; - int check_nr = 0; - const std::vector &global_index = grid_cache.global_index(); - - while (check_nr < check_points) { - int active_index = rand() % active_size; - - double init_porv = ecl_kw_iget_as_double( - init_porv_kw, - global_index[active_index]); /* NB - this uses global indexing. */ - if (init_porv > 0) { - double rporv = survey->porv[active_index]; - double log_pormod = log10(rporv / init_porv); - - if (fabs(log_pormod) > 1) { - /* Detected as error if the effective pore volume multiplier - is greater than 10 or less than 0.10. */ - fprintf(stderr, "----------------------------------------------" - "-------------------\n"); - fprintf(stderr, "INIT PORV : %g \n", init_porv); - fprintf(stderr, "RPORV : %g \n", rporv); - fprintf(stderr, "Hmmm - the RPORV values extracted from the " - "restart file seem to be \n"); - fprintf(stderr, "veeery different from the initial porv value. " - "This might indicate \n"); - fprintf(stderr, "an ECLIPSE bug in the RPORV handling. Try " - "using another ECLIPSE version,\n"); - fprintf(stderr, - "or alternatively the PORMOD approach instead\n"); - fprintf(stderr, "----------------------------------------------" - "-------------------\n"); - exit(1); - } - check_nr++; - } - } -} - -/** - There are currently two main methods to add a survey; differentiated by - how the mass of various phases in each cell is calculated: - - 1. We can calculate the mass of each phase from the relation: - - mass = saturation * pore_volume * mass_density. - - This method requires access to the instantaneous pore volume. This - can be accessed in two different ways, based either on the RPORV - keyword or the PORV_MOD keyword. This functionality is available - through the ecl_grav_survey_alloc_RPORV() and - ecl_grav_survey_alloc_PORMOD() functions. - - - 2. The mass of each phase can be calculated based on the fluid in place - values (volume of phase when the matter is brought to standard - conditions), i.e. the FIPGAS, FIPWAT and FIPOIL keywords, and the - corresponding densities at surface conditions. This functionality is - implemented with the ecl_grav_survey_alloc_FIP() function. - - Observe that use of the FIP based method requires densities entered - with ecl_grav_new_std_density()/ecl_grav_add_std_density() prior to - adding the actual survey. -*/ - -/** - Allocate one survey based on using the RPORV keyword from the - restart file to calculate the instantaneous pore volume in each - cell. - - Unfortunately different versions of ECLIPSE have showed a wide - range of bugs related to the RPORV keyword, including: - - - Using the pressure values instead of pore volumes - this will be - cached by the ecl_grav_survey_assert_RPORV() function. - - - Ignoring the dynamic pore volume changes, and just using - RPORV == INIT PORV. -*/ - -static ecl_grav_survey_type * -ecl_grav_survey_alloc_RPORV(ecl_grav_type *ecl_grav, - const ecl_file_view_type *restart_file, - const char *name) { - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_empty(ecl_grav, name, GRAV_CALC_RPORV); - if (ecl_file_view_has_kw(restart_file, RPORV_KW)) { - ecl_kw_type *rporv_kw = - ecl_file_view_iget_named_kw(restart_file, RPORV_KW, 0); - int iactive; - for (iactive = 0; iactive < ecl_kw_get_size(rporv_kw); iactive++) - survey->porv[iactive] = ecl_kw_iget_as_double(rporv_kw, iactive); - } else - util_abort("%s: restart file did not contain %s keyword??\n", __func__, - RPORV_KW); - - { - const ecl_file_type *init_file = ecl_grav->init_file; - ecl_grav_survey_assert_RPORV(survey, init_file); - ecl_grav_survey_add_phases(ecl_grav, survey, restart_file, - GRAV_CALC_RPORV); - } - return survey; -} - -static ecl_grav_survey_type * -ecl_grav_survey_alloc_PORMOD(ecl_grav_type *ecl_grav, - const ecl_file_view_type *restart_file, - const char *name) { - ecl::ecl_grid_cache &grid_cache = *(ecl_grav->grid_cache); - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_empty(ecl_grav, name, GRAV_CALC_PORMOD); - ecl_kw_type *init_porv_kw = ecl_file_iget_named_kw( - ecl_grav->init_file, PORV_KW, 0); /* Global indexing */ - ecl_kw_type *pormod_kw = ecl_file_view_iget_named_kw( - restart_file, PORMOD_KW, 0); /* Active indexing */ - const int size = grid_cache.size(); - const auto &global_index = grid_cache.global_index(); - int active_index; - - for (active_index = 0; active_index < size; active_index++) - survey->porv[active_index] = - ecl_kw_iget_float(pormod_kw, active_index) * - ecl_kw_iget_float(init_porv_kw, global_index[active_index]); - - ecl_grav_survey_add_phases(ecl_grav, survey, restart_file, - GRAV_CALC_PORMOD); - - return survey; -} - -/** - Use of the ecl_grav_survey_alloc_FIP() function requires that the densities - have been added for all phases with the ecl_grav_new_std_density() and - possibly also the ecl_grav_add_std_density() functions. -*/ - -static ecl_grav_survey_type * -ecl_grav_survey_alloc_FIP(ecl_grav_type *ecl_grav, - const ecl_file_view_type *restart_file, - const char *name) { - - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_empty(ecl_grav, name, GRAV_CALC_FIP); - ecl_grav_survey_add_phases(ecl_grav, survey, restart_file, GRAV_CALC_FIP); - - return survey; -} - -static ecl_grav_survey_type * -ecl_grav_survey_alloc_RFIP(ecl_grav_type *ecl_grav, - const ecl_file_view_type *restart_file, - const char *name) { - - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_empty(ecl_grav, name, GRAV_CALC_RFIP); - ecl_grav_survey_add_phases(ecl_grav, survey, restart_file, GRAV_CALC_RFIP); - - return survey; -} - -static void ecl_grav_survey_free(ecl_grav_survey_type *grav_survey) { - free(grav_survey->name); - free(grav_survey->porv); - for (auto *phase : grav_survey->phase_list) - ecl_grav_phase_free(phase); - - delete grav_survey; -} - -static double ecl_grav_survey_eval(const ecl_grav_survey_type *base_survey, - const ecl_grav_survey_type *monitor_survey, - ecl_region_type *region, double utm_x, - double utm_y, double depth, int phase_mask) { - double deltag = 0; - for (std::size_t phase_nr = 0; phase_nr < base_survey->phase_list.size(); - phase_nr++) { - ecl_grav_phase_type *base_phase = base_survey->phase_list[phase_nr]; - if (base_phase->phase & phase_mask) { - if (monitor_survey != NULL) { - const ecl_grav_phase_type *monitor_phase = - monitor_survey->phase_list[phase_nr]; - deltag += ecl_grav_phase_eval(base_phase, monitor_phase, region, - utm_x, utm_y, depth); - } else - deltag += ecl_grav_phase_eval(base_phase, NULL, region, utm_x, - utm_y, depth); - } - } - return deltag; -} - -/** - The grid instance is only used during the construction phase. The - @init_file object is used by the ecl_grav_add_survey_XXX() - functions; and calling scope must NOT destroy this object before - all surveys have been added. -*/ - -ecl_grav_type *ecl_grav_alloc(const ecl_grid_type *ecl_grid, - const ecl_file_type *init_file) { - ecl_grav_type *ecl_grav = new ecl_grav_type(); - - ecl_grav->init_file = init_file; - ecl_grav->grid_cache = new ecl::ecl_grid_cache(ecl_grid); - ecl_grav->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( - *(ecl_grav->grid_cache), ecl_grav->init_file); - - return ecl_grav; -} - -static void ecl_grav_add_survey__(ecl_grav_type *grav, const char *name, - ecl_grav_survey_type *survey) { - grav->surveys[name] = survey; -} - -ecl_grav_survey_type * -ecl_grav_add_survey_RPORV(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file) { - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_RPORV(grav, restart_file, name); - ecl_grav_add_survey__(grav, name, survey); - return survey; -} - -ecl_grav_survey_type * -ecl_grav_add_survey_FIP(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file) { - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_FIP(grav, restart_file, name); - ecl_grav_add_survey__(grav, name, survey); - return survey; -} - -ecl_grav_survey_type * -ecl_grav_add_survey_RFIP(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file) { - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_RFIP(grav, restart_file, name); - ecl_grav_add_survey__(grav, name, survey); - return survey; -} - -ecl_grav_survey_type * -ecl_grav_add_survey_PORMOD(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file) { - ecl_grav_survey_type *survey = - ecl_grav_survey_alloc_PORMOD(grav, restart_file, name); - ecl_grav_add_survey__(grav, name, survey); - return survey; -} - -static ecl_grav_survey_type *ecl_grav_get_survey(const ecl_grav_type *grav, - const char *name) { - if (name == NULL) - return NULL; // Calling scope must determine if this is OK? - else { - if (grav->surveys.count(name) > 0) - return grav->surveys.at(name); - else { - fprintf(stderr, - "Survey name:%s not registered. Available surveys are: " - "\n\n ", - name); - - for (const auto &survey_pair : grav->surveys) - fprintf(stderr, "%s ", survey_pair.first.c_str()); - - fprintf(stderr, "\n\n"); - exit(1); - } - } -} - -double ecl_grav_eval(const ecl_grav_type *grav, const char *base, - const char *monitor, ecl_region_type *region, double utm_x, - double utm_y, double depth, int phase_mask) { - ecl_grav_survey_type *base_survey = ecl_grav_get_survey(grav, base); - ecl_grav_survey_type *monitor_survey = ecl_grav_get_survey(grav, monitor); - - return ecl_grav_survey_eval(base_survey, monitor_survey, region, utm_x, - utm_y, depth, phase_mask); -} - -/* The functions ecl_grav_new_std_density() and ecl_grav_add_std_density() are - used to "install" standard conditions densities for the various phases - involved. These functions must be called prior to calling - ecl_grav_add_survey_FIP() - failure to do so will lead to hard failure. -*/ - -/** - The function ecl_grav_new_std_density() is used to add a default density for - a new phase. -*/ - -void ecl_grav_new_std_density(ecl_grav_type *grav, ecl_phase_enum phase, - double default_density) { - const char *phase_key = ecl_util_get_phase_name(phase); - grav->default_density[std::string(phase_key)] = default_density; -} - -/** - In cases with many PVT regions it is possible to install per PVT - region densities. The ecl_grav_new_std_density() must be called - first to install a default density for the phase, and then this - function can be called afterwards to install density for a - particular PVT region. In the example below we set the default gas - density to 0.75, but in PVT regions 2 and 7 the density is - different: - - ecl_grav_new_std_density( grav , ECL_GAS_PHASE , 0.75 ); - ecl_grav_add_std_density( grav , ECL_GAS_PHASE , 2 , 0.70 ); - ecl_grav_add_std_density( grav , ECL_GAS_PHASE , 7 , 0.80 ); -*/ - -void ecl_grav_add_std_density(ecl_grav_type *grav, ecl_phase_enum phase, - int pvtnum, double density) { - std::vector &std_density = - grav->std_density[std::string(ecl_util_get_phase_name(phase))]; - if (std_density.size() <= static_cast(pvtnum)) - std_density.resize( - pvtnum + 1, - grav->default_density[std::string(ecl_util_get_phase_name(phase))]); - std_density[pvtnum] = density; -} - -void ecl_grav_free(ecl_grav_type *ecl_grav) { - delete ecl_grav->grid_cache; - free(ecl_grav->aquifer_cell); - - for (const auto &survey_pair : ecl_grav->surveys) - ecl_grav_survey_free(survey_pair.second); - - delete ecl_grav; -} diff --git a/lib/ecl/ecl_grid_cache.cpp b/lib/ecl/ecl_grid_cache.cpp deleted file mode 100644 index c5105e61a2..0000000000 --- a/lib/ecl/ecl_grid_cache.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include "detail/ecl/ecl_grid_cache.hpp" - -/** - The ecl_grid_cache_struct data structure internalizes the world - position of all the active cells. This is just a minor - simplification to speed up repeated calls to get the true world - coordinates of a cell. -*/ - -namespace ecl { -ecl_grid_cache::ecl_grid_cache(const ecl_grid_type *grid) : grid(grid) { - for (int active_index = 0; - active_index < ecl_grid_get_active_size(this->grid); active_index++) { - double x, y, z; - int global_index = - ecl_grid_get_global_index1A(this->grid, active_index); - ecl_grid_get_xyz1(this->grid, global_index, &x, &y, &z); - - this->gi.push_back(global_index); - this->xp.push_back(x); - this->yp.push_back(y); - this->zp.push_back(z); - } -} - -const std::vector &ecl_grid_cache::volume() const { - if (this->v.empty()) { - for (int active_index = 0; active_index < this->size(); active_index++) - this->v.push_back( - ecl_grid_get_cell_volume1A(this->grid, active_index)); - } - return this->v; -} - -} // namespace ecl diff --git a/lib/ecl/ecl_grid_dims.cpp b/lib/ecl/ecl_grid_dims.cpp deleted file mode 100644 index 22ab4f1731..0000000000 --- a/lib/ecl/ecl_grid_dims.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -struct ecl_grid_dims_struct { - vector_type *dims_list; -}; - -static void ecl_grid_dims_read_EGRID(ecl_grid_dims_type *grid_dims, - fortio_type *grid_fortio, - fortio_type *data_fortio) { - while (ecl_kw_fseek_kw(GRIDHEAD_KW, false, false, grid_fortio)) { - grid_dims_type *dims; - { - ecl_kw_type *gridhead_kw = ecl_kw_fread_alloc(grid_fortio); - - int nx = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); - int ny = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); - int nz = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); - - dims = grid_dims_alloc(nx, ny, nz, 0); - ecl_kw_free(gridhead_kw); - } - - if (data_fortio) { - if (ecl_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { - ecl_kw_type *intehead_kw = ecl_kw_fread_alloc(data_fortio); - dims->nactive = - ecl_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); - ecl_kw_free(intehead_kw); - } - } - - vector_append_owned_ref(grid_dims->dims_list, dims, grid_dims_free__); - } -} - -static void ecl_grid_dims_read_GRID(ecl_grid_dims_type *grid_dims, - fortio_type *grid_fortio, - fortio_type *data_fortio) { - while (ecl_kw_fseek_kw(DIMENS_KW, false, false, grid_fortio)) { - grid_dims_type *dims; - { - ecl_kw_type *dimens_kw = ecl_kw_fread_alloc(grid_fortio); - - int nx = ecl_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); - int ny = ecl_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); - int nz = ecl_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); - - dims = grid_dims_alloc(nx, ny, nz, 0); - ecl_kw_free(dimens_kw); - } - - if (data_fortio) { - if (ecl_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { - ecl_kw_type *intehead_kw = ecl_kw_fread_alloc(data_fortio); - dims->nactive = - ecl_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); - ecl_kw_free(intehead_kw); - } - } - - vector_append_owned_ref(grid_dims->dims_list, dims, grid_dims_free__); - } -} - -ecl_grid_dims_type *ecl_grid_dims_alloc(const char *grid_file, - const char *data_file) { - ecl_grid_dims_type *grid_dims = NULL; - bool grid_fmt_file; - ecl_file_enum grid_file_type = - ecl_util_get_file_type(grid_file, &grid_fmt_file, NULL); - - if ((grid_file_type == ECL_GRID_FILE) || - (grid_file_type == ECL_EGRID_FILE)) { - fortio_type *grid_fortio = - fortio_open_reader(grid_file, grid_fmt_file, ECL_ENDIAN_FLIP); - if (grid_fortio) { - grid_dims = (ecl_grid_dims_type *)util_malloc(sizeof *grid_dims); - grid_dims->dims_list = vector_alloc_new(); - - { - fortio_type *data_fortio = NULL; - bool data_fmt_file; - - if (data_file) { - ecl_util_get_file_type(data_file, &data_fmt_file, NULL); - data_fortio = fortio_open_reader(data_file, data_fmt_file, - ECL_ENDIAN_FLIP); - } - - if (grid_file_type == ECL_EGRID_FILE) - ecl_grid_dims_read_EGRID(grid_dims, grid_fortio, - data_fortio); - else - ecl_grid_dims_read_GRID(grid_dims, grid_fortio, - data_fortio); - - if (data_fortio) - fortio_fclose(data_fortio); - } - fortio_fclose(grid_fortio); - } - } - - return grid_dims; -} - -void ecl_grid_dims_free(ecl_grid_dims_type *grid_dims) { - vector_free(grid_dims->dims_list); - free(grid_dims); -} - -int ecl_grid_dims_get_num_grids(const ecl_grid_dims_type *grid_dims) { - return vector_get_size(grid_dims->dims_list); -} - -const grid_dims_type * -ecl_grid_dims_iget_dims(const ecl_grid_dims_type *grid_dims, int grid_nr) { - return (const grid_dims_type *)vector_iget_const(grid_dims->dims_list, - grid_nr); -} diff --git a/lib/ecl/ecl_init_file.cpp b/lib/ecl/ecl_init_file.cpp deleted file mode 100644 index 0b22a2965a..0000000000 --- a/lib/ecl/ecl_init_file.cpp +++ /dev/null @@ -1,220 +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 - ecl_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 ecl_kw_type *ecl_init_file_alloc_INTEHEAD(const ecl_grid_type *ecl_grid, - ert_ecl_unit_enum unit_system, - int phases, time_t start_date, - int simulator) { - ecl_kw_type *intehead_kw = - ecl_kw_alloc(INTEHEAD_KW, INTEHEAD_INIT_SIZE, ECL_INT); - ecl_kw_scalar_set_int(intehead_kw, 0); - - ecl_kw_iset_int(intehead_kw, INTEHEAD_UNIT_INDEX, unit_system); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NX_INDEX, ecl_grid_get_nx(ecl_grid)); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NY_INDEX, ecl_grid_get_ny(ecl_grid)); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NZ_INDEX, ecl_grid_get_nz(ecl_grid)); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NACTIVE_INDEX, - ecl_grid_get_active_size(ecl_grid)); - ecl_kw_iset_int(intehead_kw, INTEHEAD_PHASE_INDEX, phases); - { - int mday, month, year; - ecl_util_set_date_values(start_date, &mday, &month, &year); - ecl_kw_iset_int(intehead_kw, INTEHEAD_DAY_INDEX, mday); - ecl_kw_iset_int(intehead_kw, INTEHEAD_MONTH_INDEX, month); - ecl_kw_iset_int(intehead_kw, INTEHEAD_YEAR_INDEX, year); - } - ecl_kw_iset_int(intehead_kw, INTEHEAD_IPROG_INDEX, simulator); - - return intehead_kw; -} - -static ecl_kw_type *ecl_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; - - ecl_kw_type *logihead_kw = - ecl_kw_alloc(LOGIHEAD_KW, LOGIHEAD_INIT_SIZE, ECL_BOOL); - - ecl_kw_scalar_set_bool(logihead_kw, false); - - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_RS_INDEX, with_RS); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_RV_INDEX, with_RV); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_DIR_RELPERM_INDEX, - with_directional_relperm); - - if (simulator == INTEHEAD_ECLIPSE100_VALUE) { - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_REV_RELPERM100_INDEX, - with_reversible_relperm_ECLIPSE100); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL100_INDEX, - radial_grid_ECLIPSE100); - } else { - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_REV_RELPERM300_INDEX, - with_reversible_relperm_ECLIPSE300); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL300_INDEX, - radial_grid_ECLIPSE300); - } - - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_HYSTERISIS_INDEX, with_hysterisis); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_DUALP_INDEX, dual_porosity); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_ENDPOINT_SCALING_INDEX, - endpoint_scaling); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_DIR_ENDPOINT_SCALING_INDEX, - directional_endpoint_scaling); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_REV_ENDPOINT_SCALING_INDEX, - reversible_endpoint_scaling); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_ALT_ENDPOINT_SCALING_INDEX, - alternative_endpoint_scaling); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_MISC_DISPLACEMENT_INDEX, - miscible_displacement); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_SCALE_WATER_PC_AT_MAX_SAT_INDEX, - scale_water_PC_at_max_sat); - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_SCALE_GAS_PC_AT_MAX_SAT_INDEX, - scale_gas_PC_at_max_sat); - - return logihead_kw; -} - -static ecl_kw_type *ecl_init_file_alloc_DOUBHEAD() { - ecl_kw_type *doubhead_kw = - ecl_kw_alloc(DOUBHEAD_KW, DOUBHEAD_INIT_SIZE, ECL_DOUBLE); - - ecl_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 - ecl_init_file_fwrite_header() function. - */ - -static void ecl_init_file_fwrite_poro(fortio_type *fortio, - const ecl_grid_type *ecl_grid, - const ecl_kw_type *poro) { - { - ecl_kw_type *porv = ecl_kw_alloc( - PORV_KW, ecl_grid_get_global_size(ecl_grid), ECL_FLOAT); - int global_index; - bool global_poro = - (ecl_kw_get_size(poro) == ecl_grid_get_global_size(ecl_grid)) - ? true - : false; - for (global_index = 0; - global_index < ecl_grid_get_global_size(ecl_grid); - global_index++) { - int active_index = - ecl_grid_get_active_index1(ecl_grid, global_index); - if (active_index >= 0) { - int poro_index = global_poro ? global_index : active_index; - ecl_kw_iset_float( - porv, global_index, - ecl_kw_iget_float(poro, poro_index) * - ecl_grid_get_cell_volume1(ecl_grid, global_index)); - } else - ecl_kw_iset_float(porv, global_index, 0); - } - ecl_kw_fwrite(porv, fortio); - ecl_kw_free(porv); - } - - ecl_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 ecl_init_file_fwrite_header(fortio_type *fortio, - const ecl_grid_type *ecl_grid, - const ecl_kw_type *poro, - ert_ecl_unit_enum unit_system, int phases, - time_t start_date) { - int simulator = INTEHEAD_ECLIPSE100_VALUE; - { - ecl_kw_type *intehead_kw = ecl_init_file_alloc_INTEHEAD( - ecl_grid, unit_system, phases, start_date, simulator); - ecl_kw_fwrite(intehead_kw, fortio); - ecl_kw_free(intehead_kw); - } - - { - ecl_kw_type *logihead_kw = ecl_init_file_alloc_LOGIHEAD(simulator); - ecl_kw_fwrite(logihead_kw, fortio); - ecl_kw_free(logihead_kw); - } - - { - ecl_kw_type *doubhead_kw = ecl_init_file_alloc_DOUBHEAD(); - ecl_kw_fwrite(doubhead_kw, fortio); - ecl_kw_free(doubhead_kw); - } - - if (poro) { - int poro_size = ecl_kw_get_size(poro); - if ((poro_size == ecl_grid_get_nactive(ecl_grid)) || - (poro_size == ecl_grid_get_global_size(ecl_grid))) - ecl_init_file_fwrite_poro(fortio, ecl_grid, poro); - else - util_abort("%s: keyword PORO has wrong size:%d Grid: %d/%d \n", - __func__, ecl_kw_get_size(poro), - ecl_grid_get_nactive(ecl_grid), - ecl_grid_get_global_size(ecl_grid)); - } -} diff --git a/lib/ecl/ecl_kw.cpp b/lib/ecl/ecl_kw.cpp deleted file mode 100644 index a078e1f1e6..0000000000 --- a/lib/ecl/ecl_kw.cpp +++ /dev/null @@ -1,2875 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#define ECL_KW_TYPE_ID 6111098 - -struct ecl_kw_struct { - UTIL_TYPE_ID_DECLARATION; - int size; - ecl_data_type data_type; - char * - header8; /* Header which is right padded with ' ' to become exactly 8 characters long. Should only be used internally.*/ - char *header; /* Header which is trimmed to no-space. */ - char *data; /* The actual data vector. */ - bool shared_data; /* Whether this keyword has shared data or not. */ -}; - -UTIL_IS_INSTANCE_FUNCTION(ecl_kw, ECL_KW_TYPE_ID) - -/* For some peculiar reason the keyword data is written in blocks, all - numeric data is in blocks of 1000 elements, and character data is - in blocks of 105 elements. -*/ - -#define BLOCKSIZE_NUMERIC 1000 -#define BLOCKSIZE_CHAR 105 - -/* When writing formatted data, the data comes in columns, with a - certain number of elements in each row, i.e. four columns for float - data: - - 0.000 0.000 0.000 0.000 - 0.000 0.000 0.000 0.000 - 0.000 0.000 0.000 0.000 - .... - - These #define symbols define the number of columns for the - different datatypes. -*/ -#define COLUMNS_CHAR 7 -#define COLUMNS_FLOAT 4 -#define COLUMNS_DOUBLE 3 -#define COLUMNS_INT 6 -#define COLUMNS_MESSAGE 1 -#define COLUMNS_BOOL 25 - -/* Format string used when writing a formatted header. */ -#define WRITE_HEADER_FMT " '%-8s' %11d '%-4s'\n" - -/* Format string used when reading and writing formatted - files. Observe the following about these format strings: - - 1. The format string for reading double contains two '%' - identifiers, that is because doubles are read by parsing a - prefix and power separately. - - 2. For both double and float the write format contains two '%' - characters - that is because the values are split in a prefix - and a power prior to writing - see the function - __fprintf_scientific(). - - 3. The logical type involves converting back and forth between 'T' - and 'F' and internal logical representation. The format strings - are therefore for reading/writing a character. - -*/ - -#define READ_FMT_CHAR "%8c" -#define READ_FMT_FLOAT "%gE" -#define READ_FMT_INT "%d" -#define READ_FMT_MESS "%8c" -#define READ_FMT_BOOL " %c" -#define READ_FMT_DOUBLE "%lgD%d" - -#define WRITE_FMT_CHAR " '%-8s'" -#define WRITE_FMT_INT " %11d" -#define WRITE_FMT_FLOAT " %11.8fE%+03d" -#define WRITE_FMT_DOUBLE " %17.14fD%+03d" -#define WRITE_FMT_MESS "%s" -#define WRITE_FMT_BOOL " %c" - -/* The boolean type is not a native type which can be uniquely - identified between Fortran (ECLIPSE), C, formatted and unformatted - files: - - o In the formatted ECLIPSE files the characters BOOL_TRUE_CHAR and - BOOL_FALSE_CHAR are used to represent true and false values - repsectively. - - o In the unformatted ECLIPSE files the boolean values are - represented as integers with the values ECL_BOOL_TRUE_INT and - ECL_BOOL_FALSE_INT respectively. - - Internally in an ecl_kw instance boolean values are represented as - integers (NOT bool), with the representation given by ECL_BOOL_TRUE_INT - and ECL_BOOL_FALSE_INT. This implies that read/write of unformatted - data can go transparently without between ECLIPSE and the ecl_kw - implementation, but exported set()/get() functions with bool must - intercept the bool values and convert to the appropriate integer - value. -*/ - -// For formatted files: -#define BOOL_TRUE_CHAR 'T' -#define BOOL_FALSE_CHAR 'F' - -ecl_type_enum ecl_kw_get_type(const ecl_kw_type *); -void ecl_kw_set_data_type(ecl_kw_type *ecl_kw, ecl_data_type data_type); - -static char *alloc_read_fmt_string(const ecl_data_type ecl_type) { - return util_alloc_sprintf("%%%dc", ecl_type_get_sizeof_iotype(ecl_type)); -} - -static char *alloc_read_fmt(const ecl_data_type data_type) { - switch (ecl_type_get_type(data_type)) { - case (ECL_CHAR_TYPE): - return util_alloc_string_copy(READ_FMT_CHAR); - case (ECL_INT_TYPE): - return util_alloc_string_copy(READ_FMT_INT); - case (ECL_FLOAT_TYPE): - return util_alloc_string_copy(READ_FMT_FLOAT); - case (ECL_DOUBLE_TYPE): - return util_alloc_string_copy(READ_FMT_DOUBLE); - case (ECL_BOOL_TYPE): - return util_alloc_string_copy(READ_FMT_BOOL); - case (ECL_MESS_TYPE): - return util_alloc_string_copy(READ_FMT_MESS); - case (ECL_STRING_TYPE): - return alloc_read_fmt_string(data_type); - default: - util_abort("%s: invalid ecl_type:%s \n", __func__, - ecl_type_alloc_name(data_type)); - return NULL; - } -} - -static char *alloc_write_fmt_string(const ecl_data_type ecl_type) { - return util_alloc_sprintf(" '%%-%ds'", - ecl_type_get_sizeof_iotype(ecl_type)); -} - -static char *alloc_write_fmt(const ecl_data_type data_type) { - switch (ecl_type_get_type(data_type)) { - case (ECL_CHAR_TYPE): - return util_alloc_string_copy(WRITE_FMT_CHAR); - case (ECL_INT_TYPE): - return util_alloc_string_copy(WRITE_FMT_INT); - case (ECL_FLOAT_TYPE): - return util_alloc_string_copy(WRITE_FMT_FLOAT); - case (ECL_DOUBLE_TYPE): - return util_alloc_string_copy(WRITE_FMT_DOUBLE); - case (ECL_BOOL_TYPE): - return util_alloc_string_copy(WRITE_FMT_BOOL); - case (ECL_MESS_TYPE): - return util_alloc_string_copy(WRITE_FMT_MESS); - case (ECL_STRING_TYPE): - return alloc_write_fmt_string(data_type); - default: - util_abort("%s: invalid ecl_type: %s\n", __func__, - ecl_type_alloc_name(data_type)); - return NULL; - } -} - -static int get_blocksize(ecl_data_type data_type) { - if (ecl_type_is_alpha(data_type)) - return BLOCKSIZE_CHAR; - - return BLOCKSIZE_NUMERIC; -} - -static int get_columns(const ecl_data_type data_type) { - switch (ecl_type_get_type(data_type)) { - case (ECL_CHAR_TYPE): - return COLUMNS_CHAR; - case (ECL_INT_TYPE): - return COLUMNS_INT; - case (ECL_FLOAT_TYPE): - return COLUMNS_FLOAT; - case (ECL_DOUBLE_TYPE): - return COLUMNS_DOUBLE; - case (ECL_BOOL_TYPE): - return COLUMNS_BOOL; - case (ECL_MESS_TYPE): - return COLUMNS_MESSAGE; - case (ECL_STRING_TYPE): - return COLUMNS_CHAR; // TODO: Is this correct? - default: - util_abort("%s: invalid ecl_type: %s\n", __func__, - ecl_type_alloc_name(data_type)); - return -1; - } -} - -static void ecl_kw_assert_index(const ecl_kw_type *ecl_kw, int index, - const char *caller) { - if (index < 0 || index >= ecl_kw->size) - util_abort( - "%s: Invalid index lookup. kw:%s input_index:%d size:%d \n", - caller, ecl_kw->header, index, ecl_kw->size); -} - -static char *ecl_kw_alloc_output_buffer(const ecl_kw_type *ecl_kw) { - size_t sizeof_iotype = ecl_type_get_sizeof_iotype(ecl_kw->data_type); - size_t buffer_size = ecl_kw->size * sizeof_iotype; - char *buffer = (char *)util_malloc(buffer_size); - - if (ecl_type_is_bool(ecl_kw->data_type)) { - int *int_data = (int *)buffer; - bool *bool_data = (bool *)ecl_kw->data; - - for (int i = 0; i < ecl_kw->size; i++) - if (bool_data[i]) - int_data[i] = ECL_BOOL_TRUE_INT; - else - int_data[i] = ECL_BOOL_FALSE_INT; - - util_endian_flip_vector(buffer, sizeof_iotype, ecl_kw->size); - return buffer; - } - - if (ecl_type_is_char(ecl_kw->data_type) || - ecl_type_is_string(ecl_kw->data_type)) { - size_t sizeof_ctype = ecl_type_get_sizeof_ctype(ecl_kw->data_type); - for (int i = 0; i < ecl_kw->size; i++) { - size_t buffer_offset = i * sizeof_iotype; - size_t data_offset = i * sizeof_ctype; - size_t string_length = strlen(&ecl_kw->data[data_offset]); - - for (size_t i = 0; i < string_length; i++) - buffer[buffer_offset + i] = ecl_kw->data[data_offset + i]; - - // Pad with spaces - for (size_t i = string_length; i < sizeof_iotype; i++) - buffer[buffer_offset + i] = ' '; - } - - return buffer; - } - - if (ecl_type_is_mess(ecl_kw->data_type)) - return buffer; - - if (ecl_kw->data) { - memcpy(buffer, ecl_kw->data, buffer_size); - util_endian_flip_vector(buffer, sizeof_iotype, ecl_kw->size); - } - - return buffer; -} - -static char *ecl_kw_alloc_input_buffer(const ecl_kw_type *ecl_kw) { - size_t buffer_size = - ecl_kw->size * ecl_type_get_sizeof_iotype(ecl_kw->data_type); - char *buffer = (char *)util_malloc(buffer_size); - - return buffer; -} - -static void ecl_kw_load_from_input_buffer(ecl_kw_type *ecl_kw, char *buffer) { - size_t sizeof_iotype = ecl_type_get_sizeof_iotype(ecl_kw->data_type); - size_t sizeof_ctype = ecl_type_get_sizeof_ctype(ecl_kw->data_type); - size_t buffer_size = ecl_kw->size * sizeof_iotype; - if (ECL_ENDIAN_FLIP) { - if (ecl_type_is_numeric(ecl_kw->data_type) || - ecl_type_is_bool(ecl_kw->data_type)) - util_endian_flip_vector(buffer, sizeof_iotype, ecl_kw->size); - } - - /* - Special case bool: Return Eclipse integer representation of bool to native bool. - */ - if (ecl_type_is_bool(ecl_kw->data_type)) { - int *int_data = (int *)buffer; - bool *bool_data = (bool *)ecl_kw->data; - - for (int i = 0; i < ecl_kw->size; i++) { - if (int_data[i] == ECL_BOOL_TRUE_INT) - bool_data[i] = true; - else - bool_data[i] = false; - } - return; - } - - /* - Special case: insert '\0' termination at end of strings loaded from file; - when writing out again strlen() will be called on data - i.e. it is - paramount to add this '\0'. - */ - if (ecl_type_is_char(ecl_kw->data_type) || - ecl_type_is_string(ecl_kw->data_type)) { - const char null_char = '\0'; - for (int i = 0; i < ecl_kw->size; i++) { - size_t buffer_offset = i * sizeof_iotype; - size_t data_offset = i * sizeof_ctype; - memcpy(&ecl_kw->data[data_offset], &buffer[buffer_offset], - sizeof_iotype); - ecl_kw->data[data_offset + sizeof_iotype] = null_char; - } - return; - } - - if (ecl_type_is_mess(ecl_kw->data_type)) - return; - - /* - Plain int, double, float data - that can be copied straight over to the ->data field. - */ - memcpy(ecl_kw->data, buffer, buffer_size); -} - -const char *ecl_kw_get_header8(const ecl_kw_type *ecl_kw) { - return ecl_kw->header8; -} - -/* - Return the header without the trailing spaces -*/ -const char *ecl_kw_get_header(const ecl_kw_type *ecl_kw) { - return ecl_kw->header; -} - -bool ecl_kw_name_equal(const ecl_kw_type *ecl_kw, const char *name) { - return (strcmp(ecl_kw->header, name) == 0); -} - -void ecl_kw_get_memcpy_data(const ecl_kw_type *ecl_kw, void *target) { - memcpy(target, ecl_kw->data, - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); -} - -void ecl_kw_get_memcpy_int_data(const ecl_kw_type *ecl_kw, int *target) { - if (ecl_type_is_int(ecl_kw->data_type)) - ecl_kw_get_memcpy_data(ecl_kw, target); -} - -void ecl_kw_get_memcpy_float_data(const ecl_kw_type *ecl_kw, float *target) { - if (ecl_type_is_float(ecl_kw->data_type)) - ecl_kw_get_memcpy_data(ecl_kw, target); -} - -void ecl_kw_get_memcpy_double_data(const ecl_kw_type *ecl_kw, double *target) { - if (ecl_type_is_double(ecl_kw->data_type)) - ecl_kw_get_memcpy_data(ecl_kw, target); -} - -/** Allocates a untyped buffer with exactly the same content as the ecl_kw instances data. */ -void *ecl_kw_alloc_data_copy(const ecl_kw_type *ecl_kw) { - void *buffer = util_alloc_copy( - ecl_kw->data, - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); - return buffer; -} - -void ecl_kw_set_memcpy_data(ecl_kw_type *ecl_kw, const void *src) { - if (src != NULL) - memcpy(ecl_kw->data, src, - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); -} - -static bool ecl_kw_string_eq(const char *s1, const char *s2) { - const char space_char = ' '; - const char *long_kw = (strlen(s1) >= strlen(s2)) ? s1 : s2; - const char *short_kw = (strlen(s1) < strlen(s2)) ? s1 : s2; - const int len1 = strlen(long_kw); - const int len2 = strlen(short_kw); - int index; - bool eq = true; - if (len1 > ECL_STRING8_LENGTH) - util_abort("%s : eclipse keyword:%s is too long - aborting \n", - __func__, long_kw); - - for (index = 0; index < len2; index++) - eq = eq & (long_kw[index] == short_kw[index]); - - if (eq) { - for (index = len2; index < len1; index++) - eq = eq & (long_kw[index] == space_char); - } - - return eq; -} - -bool ecl_kw_ichar_eq(const ecl_kw_type *ecl_kw, int i, const char *value) { - char s1[ECL_STRING8_LENGTH + 1]; - ecl_kw_iget(ecl_kw, i, s1); - return ecl_kw_string_eq(s1, value); -} - -bool ecl_kw_size_and_type_equal(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2) { - return (ecl_kw1->size == ecl_kw2->size && - ecl_type_is_equal(ecl_kw1->data_type, ecl_kw2->data_type)); -} - -bool ecl_kw_header_eq(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2) { - bool equal = true; - - if (strcmp(ecl_kw1->header8, ecl_kw2->header8) != 0) - equal = false; - else - equal = ecl_kw_size_and_type_equal(ecl_kw1, ecl_kw2); - - return equal; -} - -static bool ecl_kw_data_equal__(const ecl_kw_type *ecl_kw, const void *data, - int cmp_elements) { - int cmp = - memcmp(ecl_kw->data, data, - cmp_elements * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); - if (cmp == 0) - return true; - else - return false; -} - -/** - Observe that the comparison is done with memcmp() - - i.e. "reasonably good" numerical agreement is *not* enough. -*/ - -bool ecl_kw_data_equal(const ecl_kw_type *ecl_kw, const void *data) { - return ecl_kw_data_equal__(ecl_kw, data, ecl_kw->size); -} - -bool ecl_kw_content_equal(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2) { - if (ecl_kw_size_and_type_equal(ecl_kw1, ecl_kw2)) - return ecl_kw_data_equal__(ecl_kw1, ecl_kw2->data, ecl_kw1->size); - else - return false; -} - -/** - This function compares two ecl_kw instances, and returns true if they are equal. -*/ - -bool ecl_kw_equal(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2) { - bool equal = ecl_kw_header_eq(ecl_kw1, ecl_kw2); - if (equal) - equal = ecl_kw_data_equal(ecl_kw1, ecl_kw2->data); - - return equal; -} - -#define ECL_KW_NUMERIC_CMP(ctype) \ - static bool ecl_kw_numeric_equal_##ctype(const ecl_kw_type *ecl_kw1, \ - const ecl_kw_type *ecl_kw2, \ - ctype abs_diff, ctype rel_diff) { \ - int index; \ - bool equal = true; \ - { \ - const ctype *data1 = (const ctype *)ecl_kw1->data; \ - const ctype *data2 = (const ctype *)ecl_kw2->data; \ - for (index = 0; index < ecl_kw1->size; index++) { \ - equal = util_##ctype##_approx_equal__( \ - data1[index], data2[index], rel_diff, abs_diff); \ - if (!equal) \ - break; \ - } \ - } \ - return equal; \ - } - -ECL_KW_NUMERIC_CMP(float) -ECL_KW_NUMERIC_CMP(double) -#undef ECL_KW_NUMERIC_CMP - -/** - This function compares the data of two ecl_kw instances, and - returns true if the relative numerical difference is less than - @rel_diff. Does not consider consider the kw header. -*/ - -bool ecl_kw_numeric_equal(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2, double abs_diff, - double rel_diff) { - if (!ecl_kw_size_and_type_equal(ecl_kw1, ecl_kw2)) - return false; - - if (ecl_type_is_float(ecl_kw1->data_type)) - return ecl_kw_numeric_equal_float(ecl_kw1, ecl_kw2, abs_diff, rel_diff); - else if (ecl_type_is_double(ecl_kw1->data_type)) - return ecl_kw_numeric_equal_double(ecl_kw1, ecl_kw2, abs_diff, - rel_diff); - else - return ecl_kw_data_equal(ecl_kw1, ecl_kw2->data); -} - -bool ecl_kw_block_equal(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2, - int cmp_elements) { - if (ecl_kw_header_eq(ecl_kw1, ecl_kw2)) { - if (cmp_elements == 0) - cmp_elements = ecl_kw1->size; - - return ecl_kw_data_equal__(ecl_kw1, ecl_kw2->data, cmp_elements); - } else - return false; -} - -static void ecl_kw_set_shared_ref(ecl_kw_type *ecl_kw, void *data_ptr) { - if (!ecl_kw->shared_data) { - if (ecl_kw->data != NULL) - util_abort("%s: can not change to shared for keyword with " - "allocated storage - aborting \n", - __func__); - } - ecl_kw->shared_data = true; - ecl_kw->data = (char *)data_ptr; -} - -static void ecl_kw_initialize(ecl_kw_type *ecl_kw, const char *header, int size, - ecl_data_type data_type) { - ecl_kw_set_data_type(ecl_kw, data_type); - ecl_kw_set_header_name(ecl_kw, header); - ecl_kw->size = size; -} - -static size_t ecl_kw_fortio_data_size(const ecl_kw_type *ecl_kw) { - const int blocksize = get_blocksize(ecl_kw->data_type); - const int num_blocks = - ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1); - - return num_blocks * (4 + 4) + // Fortran fluff for each block - ecl_kw->size * - ecl_type_get_sizeof_iotype(ecl_kw->data_type); // Actual data -} - -/** - Returns the number of bytes this ecl_kw instance would occupy in - BINARY file; we add 2*4 to the header size to include the size of - the fortran header and trailer combo. -*/ - -size_t ecl_kw_fortio_size(const ecl_kw_type *ecl_kw) { - size_t size = ECL_KW_HEADER_FORTIO_SIZE; - size += ecl_kw_fortio_data_size(ecl_kw); - return size; -} - -/** - The data is copied from the input argument to the ecl_kw; data can be NULL. -*/ -ecl_kw_type *ecl_kw_alloc_new(const char *header, int size, - ecl_data_type data_type, const void *data) { - ecl_kw_type *ecl_kw; - ecl_kw = ecl_kw_alloc_empty(); - ecl_kw_initialize(ecl_kw, header, size, data_type); - if (data != NULL) { - ecl_kw_alloc_data(ecl_kw); - ecl_kw_set_memcpy_data(ecl_kw, data); - } - return ecl_kw; -} - -ecl_kw_type *ecl_kw_alloc(const char *header, int size, - ecl_data_type data_type) { - ecl_kw_type *ecl_kw; - - ecl_kw = ecl_kw_alloc_empty(); - ecl_kw_initialize(ecl_kw, header, size, data_type); - ecl_kw_alloc_data(ecl_kw); - - return ecl_kw; -} - -ecl_kw_type *ecl_kw_alloc_new_shared(const char *header, int size, - ecl_data_type data_type, void *data) { - ecl_kw_type *ecl_kw; - ecl_kw = ecl_kw_alloc_empty(); - ecl_kw_initialize(ecl_kw, header, size, data_type); - ecl_kw_set_shared_ref(ecl_kw, data); - return ecl_kw; -} - -ecl_kw_type *ecl_kw_alloc_empty() { - ecl_kw_type *ecl_kw; - - ecl_kw = (ecl_kw_type *)util_malloc(sizeof *ecl_kw); - ecl_kw->header = NULL; - ecl_kw->header8 = NULL; - ecl_kw->data = NULL; - ecl_kw->shared_data = false; - ecl_kw->size = 0; - - UTIL_TYPE_ID_INIT(ecl_kw, ECL_KW_TYPE_ID); - - return ecl_kw; -} - -void ecl_kw_free(ecl_kw_type *ecl_kw) { - free(ecl_kw->header); - free(ecl_kw->header8); - ecl_kw_free_data(ecl_kw); - free(ecl_kw); -} - -void ecl_kw_free__(void *void_ecl_kw) { - ecl_kw_free((ecl_kw_type *)void_ecl_kw); -} - -void ecl_kw_memcpy_data(ecl_kw_type *target, const ecl_kw_type *src) { - if (!ecl_kw_size_and_type_equal(target, src)) - util_abort("%s: type/size mismatch \n", __func__); - - memcpy(target->data, src->data, - target->size * ecl_type_get_sizeof_ctype(target->data_type)); -} - -void ecl_kw_memcpy(ecl_kw_type *target, const ecl_kw_type *src) { - target->size = src->size; - ecl_kw_set_data_type(target, src->data_type); - - ecl_kw_set_header_name(target, src->header); - ecl_kw_alloc_data(target); - ecl_kw_memcpy_data(target, src); -} - -ecl_kw_type *ecl_kw_alloc_copy(const ecl_kw_type *src) { - ecl_kw_type *new_; - new_ = ecl_kw_alloc_empty(); - ecl_kw_memcpy(new_, src); - return new_; -} - -/** - This function will allocate a new copy of @src, where only the - elements corresponding to the slice [index1:index2) is included. - - The input parameters @index1 and @index2 can to some extent be - out-of-range: - - index1 = max( index1 , 0 ); - index2 = min( index2 , size ); - - If index1 > index2 it will fail hard; the same applies if stride is - <= 0. -*/ - -ecl_kw_type *ecl_kw_alloc_slice_copy(const ecl_kw_type *src, int index1, - int index2, int stride) { - if (index1 < 0) - index1 = 0; - if (index2 > src->size) - index2 = src->size; - if (index1 >= src->size) - util_abort("%s: index1=%d > size:%d \n", __func__, index1, src->size); - if (stride <= 0) - util_abort("%s: stride:%d completely broken ...\n", __func__, stride); - { - ecl_kw_type *new_kw = NULL; - int src_index = index1; - /* 1: Determine size of the sliced copy. */ - { - int new_size = 0; - while (src_index < index2) { - new_size++; - src_index += stride; - } - if (new_size > 0) { - new_kw = ecl_kw_alloc_empty(); - ecl_kw_initialize(new_kw, src->header, new_size, - src->data_type); - ecl_kw_alloc_data(new_kw); - - /* 2: Copy over the elements. */ - src_index = index1; - { - int target_index = 0; - const char *src_ptr = src->data; - char *new_ptr = new_kw->data; - int sizeof_ctype = - ecl_type_get_sizeof_ctype(new_kw->data_type); - - while (src_index < index2) { - memcpy(&new_ptr[target_index * sizeof_ctype], - &src_ptr[src_index * sizeof_ctype], - sizeof_ctype); - src_index += stride; - target_index += 1; - } - } - } - } - return new_kw; - } -} - -void ecl_kw_resize(ecl_kw_type *ecl_kw, int new_size) { - if (ecl_kw->shared_data) - util_abort("%s: trying to allocate data for ecl_kw object which has " - "been declared with shared storage - aborting \n", - __func__); - - if (new_size != ecl_kw->size) { - size_t old_byte_size = - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type); - size_t new_byte_size = - new_size * ecl_type_get_sizeof_ctype(ecl_kw->data_type); - - ecl_kw->data = (char *)util_realloc(ecl_kw->data, new_byte_size); - if (new_byte_size > old_byte_size) { - size_t offset = old_byte_size; - memset(&ecl_kw->data[offset], 0, new_byte_size - old_byte_size); - } - ecl_kw->size = new_size; - } -} - -/** - Will allocate a copy of the src_kw. Will copy @count elements - starting at @offset. If @count < 0 all remaining elements from - @offset will be copied. If new_kw == NULL the new keyword will have - the same header as the @src, otherwise the value @new_kw will be - used. -*/ - -ecl_kw_type *ecl_kw_alloc_sub_copy(const ecl_kw_type *src, const char *new_kw, - int offset, int count) { - if (new_kw == NULL) - new_kw = src->header; - - if (count < 0) - count = src->size - offset; - - if ((offset < 0) || (offset >= src->size)) - util_abort("%s: invalid offset - limits: [%d,%d) \n", __func__, 0, - src->size); - if ((count + offset) > src->size) - util_abort("%s: invalid count value: %d \n", __func__, count); - - { - void *src_data = ecl_kw_iget_ptr(src, offset); - return ecl_kw_alloc_new(new_kw, count, src->data_type, src_data); - } -} - -const void *ecl_kw_copyc__(const void *void_kw) { - return ecl_kw_alloc_copy((const ecl_kw_type *)void_kw); -} - -static void *ecl_kw_iget_ptr_static(const ecl_kw_type *ecl_kw, int i) { - ecl_kw_assert_index(ecl_kw, i, __func__); - return &ecl_kw->data[i * ecl_type_get_sizeof_ctype(ecl_kw->data_type)]; -} - -static void ecl_kw_iget_static(const ecl_kw_type *ecl_kw, int i, void *iptr) { - memcpy(iptr, ecl_kw_iget_ptr_static(ecl_kw, i), - ecl_type_get_sizeof_ctype(ecl_kw->data_type)); -} - -static void ecl_kw_iset_static(ecl_kw_type *ecl_kw, int i, const void *iptr) { - size_t sizeof_ctype = ecl_type_get_sizeof_ctype(ecl_kw->data_type); - ecl_kw_assert_index(ecl_kw, i, __func__); - memcpy(&ecl_kw->data[i * sizeof_ctype], iptr, sizeof_ctype); -} - -void ecl_kw_iget(const ecl_kw_type *ecl_kw, int i, void *iptr) { - ecl_kw_iget_static(ecl_kw, i, iptr); -} - -/** - Will return a double value for underlying data types of double, - float and int. -*/ -double ecl_kw_iget_as_double(const ecl_kw_type *ecl_kw, int index) { - if (ecl_type_is_float(ecl_kw->data_type)) - return ecl_kw_iget_float( - ecl_kw, - index); /* Here the compiler will silently insert a float -> double conversion. */ - else if (ecl_type_is_double(ecl_kw->data_type)) - return ecl_kw_iget_double(ecl_kw, index); - else if (ecl_type_is_int(ecl_kw->data_type)) - return ecl_kw_iget_int(ecl_kw, index); /* */ - else { - util_abort("%s: can not be converted to double - no data for you! \n", - __func__); - return -1; - } -} - -/** - Will return a float value for underlying data types of double and float. -*/ - -float ecl_kw_iget_as_float(const ecl_kw_type *ecl_kw, int i) { - if (ecl_type_is_float(ecl_kw->data_type)) - return ecl_kw_iget_float(ecl_kw, i); - else if (ecl_type_is_double(ecl_kw->data_type)) - return (float)ecl_kw_iget_double(ecl_kw, i); - else { - util_abort("%s: can not be converted to float - no data for you! \n", - __func__); - return -1; - } -} - -#define ECL_KW_IGET_TYPED(ctype, ECL_TYPE) \ - ctype ecl_kw_iget_##ctype(const ecl_kw_type *ecl_kw, int i) { \ - ctype value; \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - ecl_kw_iget_static(ecl_kw, i, &value); \ - return value; \ - } - -ECL_KW_IGET_TYPED(double, ECL_DOUBLE_TYPE); -ECL_KW_IGET_TYPED(float, ECL_FLOAT_TYPE); -ECL_KW_IGET_TYPED(int, ECL_INT_TYPE); -ECL_KW_IGET_TYPED(bool, ECL_BOOL_TYPE); -#undef ECL_KW_IGET_TYPED - -const char *ecl_kw_iget_char_ptr(const ecl_kw_type *ecl_kw, int i) { - if (ecl_kw_get_type(ecl_kw) != ECL_CHAR_TYPE) - util_abort("%s: Keyword: %s is wrong type - aborting \n", __func__, - ecl_kw_get_header8(ecl_kw)); - return (const char *)ecl_kw_iget_ptr(ecl_kw, i); -} - -const char *ecl_kw_iget_string_ptr(const ecl_kw_type *ecl_kw, int i) { - if (ecl_kw_get_type(ecl_kw) != ECL_STRING_TYPE) - util_abort("%s: Keyword: %s is wrong type - aborting \n", __func__, - ecl_kw_get_header8(ecl_kw)); - return (const char *)ecl_kw_iget_ptr(ecl_kw, i); -} - -/** - This will set the elemnts of the ecl_kw data storage in index to - the value of s8; if s8 is shorter than 8 characters the result will - be padded, if s8 is longer than 8 characters the characters from 9 - and out will be ignored. -*/ -void ecl_kw_iset_string8(ecl_kw_type *ecl_kw, int index, const char *s8) { - char *ecl_string = (char *)ecl_kw_iget_ptr(ecl_kw, index); - if (strlen(s8) >= ECL_STRING8_LENGTH) { - /* The whole string goes in - possibly loosing content at the end. */ - int i; - for (i = 0; i < ECL_STRING8_LENGTH; i++) - ecl_string[i] = s8[i]; - } else { - /* The string is padded with trailing spaces. */ - int string_length = strlen(s8); - int i; - - for (i = 0; i < string_length; i++) - ecl_string[i] = s8[i]; - - for (i = string_length; i < ECL_STRING8_LENGTH; i++) - ecl_string[i] = ' '; - } - - ecl_string[ECL_STRING8_LENGTH] = '\0'; -} - -/** - This function will set the string @index in the ecl_kw string array - to @s. IFF @s is longer than 8 characters, the first part will go - in element @index, and then we will continue writing into the next - elements. If the resulting index goes beyond the length of the - keyword - WhamBang! - - You should know what you are doing when sending in a string of - length greater than 8 - maybe the overwriting of consecutive - elements is not what you want? -*/ -void ecl_kw_iset_char_ptr(ecl_kw_type *ecl_kw, int index, const char *s) { - int strings = strlen(s) / ECL_STRING8_LENGTH; - if ((strlen(s) % ECL_STRING8_LENGTH) != 0) - strings++; - { - int sub_index; - for (sub_index = 0; sub_index < strings; sub_index++) - ecl_kw_iset_string8(ecl_kw, index + sub_index, - &s[sub_index * ECL_STRING8_LENGTH]); - } -} - -/** - This function will verify that the given string is of approperiate - length (0 <= lenght <= data_type.element_size). If so, the elements - of @s will be written to the @ecl_kw string array starting at - @index. If the input string is shorter than the type length the - string will be padded with trailing spaces. - */ -void ecl_kw_iset_string_ptr(ecl_kw_type *ecl_kw, int index, const char *s) { - if (!ecl_type_is_alpha(ecl_kw_get_data_type(ecl_kw))) { - char *type_name = ecl_type_alloc_name(ecl_kw_get_data_type(ecl_kw)); - util_abort( - "%s: Expected alphabetic data type (CHAR, CXXX or MESS), was %s\n", - __func__, type_name); - } - - size_t input_len = strlen(s); - size_t type_len = ecl_type_get_sizeof_iotype(ecl_kw->data_type); - - if (input_len > type_len) - util_abort( - "%s: String of length %d cannot hold input string of length %d\n", - __func__, type_len, input_len); - - { - char *ecl_string = (char *)ecl_kw_iget_ptr(ecl_kw, index); - size_t i; - - for (i = 0; i < input_len; ++i) - ecl_string[i] = s[i]; - - for (i = input_len; i < type_len; ++i) - ecl_string[i] = ' '; - - ecl_string[type_len] = '\0'; - } -} - -/** - This function will compare the string at position @index with the - input @other string. The comparison will be done in a - 'space-tolerant', i.e. trailing spaces are ignored in the - comparison. If the strings are considered equal true is returned. -*/ - -bool ecl_kw_icmp_string(const ecl_kw_type *ecl_kw, int index, - const char *other_string) { - const char *kw_string = (const char *)ecl_kw_iget_char_ptr(ecl_kw, index); - if (strlen(other_string)) { - const char *match = strstr(kw_string, other_string); - if (match == kw_string) - return true; - } - - return false; -} - -#define ECL_KW_ISET_TYPED(ctype, ECL_TYPE) \ - void ecl_kw_iset_##ctype(ecl_kw_type *ecl_kw, int i, ctype value) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - ecl_kw_iset_static(ecl_kw, i, &value); \ - } - -ECL_KW_ISET_TYPED(double, ECL_DOUBLE_TYPE); -ECL_KW_ISET_TYPED(float, ECL_FLOAT_TYPE); -ECL_KW_ISET_TYPED(int, ECL_INT_TYPE); -ECL_KW_ISET_TYPED(bool, ECL_BOOL_TYPE); -#undef ECL_KW_ISET_TYPED - -#define ECL_KW_SET_INDEXED(ctype, ECL_TYPE) \ - void ecl_kw_set_indexed_##ctype( \ - ecl_kw_type *ecl_kw, const int_vector_type *index_list, ctype value) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - { \ - ctype *data = (ctype *)ecl_kw->data; \ - int size = int_vector_size(index_list); \ - const int *index_ptr = int_vector_get_const_ptr(index_list); \ - int i; \ - for (i = 0; i < size; i++) \ - data[index_ptr[i]] = value; \ - } \ - } - -ECL_KW_SET_INDEXED(double, ECL_DOUBLE_TYPE); -ECL_KW_SET_INDEXED(float, ECL_FLOAT_TYPE); -ECL_KW_SET_INDEXED(int, ECL_INT_TYPE); -#undef ECL_KW_SET_INDEXED - -#define ECL_KW_SHIFT_INDEXED(ctype, ECL_TYPE) \ - void ecl_kw_shift_indexed_##ctype( \ - ecl_kw_type *ecl_kw, const int_vector_type *index_list, ctype shift) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - { \ - ctype *data = (ctype *)ecl_kw->data; \ - int size = int_vector_size(index_list); \ - const int *index_ptr = int_vector_get_const_ptr(index_list); \ - int i; \ - for (i = 0; i < size; i++) \ - data[index_ptr[i]] += shift; \ - } \ - } - -ECL_KW_SHIFT_INDEXED(double, ECL_DOUBLE_TYPE); -ECL_KW_SHIFT_INDEXED(float, ECL_FLOAT_TYPE); -ECL_KW_SHIFT_INDEXED(int, ECL_INT_TYPE); -#undef ECL_KW_SHIFT_INDEXED - -#define ECL_KW_SCALE_INDEXED(ctype, ECL_TYPE) \ - void ecl_kw_scale_indexed_##ctype( \ - ecl_kw_type *ecl_kw, const int_vector_type *index_list, ctype scale) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - { \ - ctype *data = (ctype *)ecl_kw->data; \ - int size = int_vector_size(index_list); \ - const int *index_ptr = int_vector_get_const_ptr(index_list); \ - int i; \ - for (i = 0; i < size; i++) \ - data[index_ptr[i]] *= scale; \ - } \ - } - -ECL_KW_SCALE_INDEXED(double, ECL_DOUBLE_TYPE); -ECL_KW_SCALE_INDEXED(float, ECL_FLOAT_TYPE); -ECL_KW_SCALE_INDEXED(int, ECL_INT_TYPE); -#undef ECL_KW_SCALE_INDEXED - -#define ECL_KW_GET_TYPED_PTR(ctype, ECL_TYPE) \ - ctype *ecl_kw_get_##ctype##_ptr(const ecl_kw_type *ecl_kw) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - return (ctype *)ecl_kw->data; \ - } - -ECL_KW_GET_TYPED_PTR(double, ECL_DOUBLE_TYPE); -ECL_KW_GET_TYPED_PTR(float, ECL_FLOAT_TYPE); -ECL_KW_GET_TYPED_PTR(int, ECL_INT_TYPE); -ECL_KW_GET_TYPED_PTR(bool, ECL_BOOL_TYPE); -#undef ECL_KW_GET_TYPED_PTR - -void *ecl_kw_get_void_ptr(const ecl_kw_type *ecl_kw) { return ecl_kw->data; } - -void *ecl_kw_iget_ptr(const ecl_kw_type *ecl_kw, int i) { - return ecl_kw_iget_ptr_static(ecl_kw, i); -} - -void ecl_kw_iset(ecl_kw_type *ecl_kw, int i, const void *iptr) { - ecl_kw_iset_static(ecl_kw, i, iptr); -} - -static bool ecl_kw_qskip(FILE *stream) { - const char sep = '\''; - const char space = ' '; - const char newline = '\n'; - const char tab = '\t'; - bool OK = true; - char c; - bool cont = true; - while (cont) { - c = fgetc(stream); - if (c == EOF) { - cont = false; - OK = false; - } else { - if (c == space || c == newline || c == tab) - cont = true; - else if (c == sep) - cont = false; - } - } - return OK; -} - -static bool ecl_kw_fscanf_qstring(char *s, const char *fmt, int len, - FILE *stream) { - const char null_char = '\0'; - char last_sep; - bool OK; - OK = ecl_kw_qskip(stream); - if (OK) { - int read_count = 0; - read_count += fscanf(stream, fmt, s); - s[len] = null_char; - read_count += fscanf(stream, "%c", &last_sep); - - if (read_count != 2) - util_abort("%s: reading \'xxxxxxxx\' formatted string failed \n", - __func__); - } - return OK; -} - -/* - This rather painful parsing is because formatted eclipse double - format : 0.ddddD+01 - difficult to parse the 'D'; -*/ -/** Should be: NESTED */ - -static double __fscanf_ECL_double(FILE *stream, const char *fmt) { - int read_count, power; - double value, arg; - read_count = fscanf(stream, fmt, &arg, &power); - if (read_count == 2) - value = arg * pow(10, power); - else { - util_abort("%s: read failed \n", __func__); - value = -1; - } - return value; -} - -bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { - bool fmt_file = fortio_fmt_file(fortio); - if (ecl_kw->size > 0) { - const int blocksize = get_blocksize(ecl_kw->data_type); - if (fmt_file) { - const int blocks = ecl_kw->size / blocksize + - (ecl_kw->size % blocksize == 0 ? 0 : 1); - char *read_fmt = alloc_read_fmt(ecl_kw->data_type); - FILE *stream = fortio_get_FILE(fortio); - int offset = 0; - int index = 0; - int ib, ir; - for (ib = 0; ib < blocks; ib++) { - int read_elm = - util_int_min((ib + 1) * blocksize, ecl_kw->size) - - ib * blocksize; - for (ir = 0; ir < read_elm; ir++) { - switch (ecl_kw_get_type(ecl_kw)) { - case (ECL_CHAR_TYPE): - ecl_kw_fscanf_qstring(&ecl_kw->data[offset], read_fmt, - 8, stream); - break; - case (ECL_STRING_TYPE): - ecl_kw_fscanf_qstring(&ecl_kw->data[offset], read_fmt, - ecl_type_get_sizeof_iotype( - ecl_kw_get_data_type(ecl_kw)), - stream); - break; - case (ECL_INT_TYPE): { - int iread = fscanf(stream, read_fmt, - (int *)&ecl_kw->data[offset]); - if (iread != 1) - util_abort( - "%s: after reading %d values reading of " - "keyword:%s from:%s failed - aborting \n", - __func__, - offset / ecl_type_get_sizeof_ctype( - ecl_kw->data_type), - ecl_kw->header8, fortio_filename_ref(fortio)); - } break; - case (ECL_FLOAT_TYPE): { - int iread = fscanf(stream, read_fmt, - (float *)&ecl_kw->data[offset]); - if (iread != 1) { - util_abort( - "%s: after reading %d values reading of " - "keyword:%s from:%s failed - aborting \n", - __func__, - offset / ecl_type_get_sizeof_ctype( - ecl_kw->data_type), - ecl_kw->header8, fortio_filename_ref(fortio)); - } - } break; - case (ECL_DOUBLE_TYPE): { - double value = __fscanf_ECL_double(stream, read_fmt); - ecl_kw_iset(ecl_kw, index, &value); - } break; - case (ECL_BOOL_TYPE): { - char bool_char; - if (fscanf(stream, read_fmt, &bool_char) == 1) { - if (bool_char == BOOL_TRUE_CHAR) - ecl_kw_iset_bool(ecl_kw, index, true); - else if (bool_char == BOOL_FALSE_CHAR) - ecl_kw_iset_bool(ecl_kw, index, false); - else - util_abort("%s: Logical value: [%c] not " - "recogniced - aborting \n", - __func__, bool_char); - } else - util_abort( - "%s: read failed - premature file end? \n", - __func__); - } break; - case (ECL_MESS_TYPE): - ecl_kw_fscanf_qstring(&ecl_kw->data[offset], read_fmt, - 8, stream); - break; - default: - util_abort("%s: Internal error: internal eclipse_type: " - "%d not recognized - aborting \n", - __func__, ecl_kw_get_type(ecl_kw)); - } - offset += ecl_type_get_sizeof_ctype(ecl_kw->data_type); - index++; - } - } - - /* Skip the trailing newline */ - fortio_fseek(fortio, 1, SEEK_CUR); - free(read_fmt); - return true; - } else { - char *buffer = ecl_kw_alloc_input_buffer(ecl_kw); - const int sizeof_iotype = - ecl_type_get_sizeof_iotype(ecl_kw->data_type); - bool read_ok = fortio_fread_buffer(fortio, buffer, - ecl_kw->size * sizeof_iotype); - - if (read_ok) - ecl_kw_load_from_input_buffer(ecl_kw, buffer); - - free(buffer); - return read_ok; - } - } else - /* The keyword has zero size - and reading data is trivially OK. */ - return true; -} - -void ecl_kw_fread_indexed_data(fortio_type *fortio, offset_type data_offset, - ecl_data_type data_type, int element_count, - const int_vector_type *index_map, - char *io_buffer) { - const int block_size = get_blocksize(data_type); - FILE *stream = fortio_get_FILE(fortio); - int index; - int sizeof_iotype = ecl_type_get_sizeof_iotype(data_type); - - for (index = 0; index < int_vector_size(index_map); index++) { - int element_index = int_vector_iget(index_map, index); - - if (element_index < 0 || element_index >= element_count) - util_abort("%s: Element index is out of range 0 <= %d < %d\n", - __func__, element_index, element_count); - - fortio_data_fseek(fortio, data_offset, element_index, sizeof_iotype, - element_count, block_size); - util_fread(&io_buffer[index * sizeof_iotype], sizeof_iotype, 1, stream, - __func__); - } - - if (ECL_ENDIAN_FLIP) - util_endian_flip_vector(io_buffer, sizeof_iotype, - int_vector_size(index_map)); -} - -/** - Allocates storage and reads data. -*/ -bool ecl_kw_fread_realloc_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { - ecl_kw_alloc_data(ecl_kw); - return ecl_kw_fread_data(ecl_kw, fortio); -} - -/** - Static method without a class instance. -*/ - -bool ecl_kw_fskip_data__(ecl_data_type data_type, const int element_count, - fortio_type *fortio) { - if (element_count <= 0) - return true; - - bool fmt_file = fortio_fmt_file(fortio); - if (fmt_file) { - /* Formatted skipping actually involves reading the data - nice ??? */ - ecl_kw_type *tmp_kw = ecl_kw_alloc_empty(); - ecl_kw_initialize(tmp_kw, "WORK", element_count, data_type); - ecl_kw_alloc_data(tmp_kw); - ecl_kw_fread_data(tmp_kw, fortio); - ecl_kw_free(tmp_kw); - } else { - const int blocksize = get_blocksize(data_type); - const int block_count = - element_count / blocksize + (element_count % blocksize != 0); - int element_size = ecl_type_get_sizeof_iotype(data_type); - - if (!fortio_data_fskip(fortio, element_size, element_count, - block_count)) - return false; - } - - return true; -} - -bool ecl_kw_fskip_data(ecl_kw_type *ecl_kw, fortio_type *fortio) { - return ecl_kw_fskip_data__(ecl_kw_get_data_type(ecl_kw), ecl_kw->size, - fortio); -} - -/** - This function will skip the header part of an ecl_kw instance. The - function will read the file content at the current position, it is - therefore essential that the file pointer is positioned at the - beginning of a keyword when this function is called; otherwise it - will be complete crash and burn. -*/ - -void ecl_kw_fskip_header(fortio_type *fortio) { - bool fmt_file = fortio_fmt_file(fortio); - if (fmt_file) { - ecl_kw_type *ecl_kw = ecl_kw_alloc_empty(); - ecl_kw_fread_header(ecl_kw, fortio); - ecl_kw_free(ecl_kw); - } else - fortio_fskip_record(fortio); -} - -ecl_read_status_enum ecl_kw_fread_header(ecl_kw_type *ecl_kw, - fortio_type *fortio) { - const char null_char = '\0'; - FILE *stream = fortio_get_FILE(fortio); - bool fmt_file = fortio_fmt_file(fortio); - char header[ECL_STRING8_LENGTH + 1]; - char ecl_type_str[ECL_TYPE_LENGTH + 1]; - int record_size; - int size; - - if (fmt_file) { - if (!ecl_kw_fscanf_qstring(header, "%8c", 8, stream)) - return ECL_KW_READ_FAIL; - - int read_count = fscanf(stream, "%d", &size); - if (read_count != 1) - return ECL_KW_READ_FAIL; - - if (!ecl_kw_fscanf_qstring(ecl_type_str, "%4c", 4, stream)) - return ECL_KW_READ_FAIL; - - fgetc(stream); /* Reading the trailing newline ... */ - } else { - header[ECL_STRING8_LENGTH] = null_char; - ecl_type_str[ECL_TYPE_LENGTH] = null_char; - record_size = fortio_init_read(fortio); - - if (record_size <= 0) - return ECL_KW_READ_FAIL; - - char buffer[ECL_KW_HEADER_DATA_SIZE]; - size_t read_bytes = fread(buffer, 1, ECL_KW_HEADER_DATA_SIZE, stream); - - if (read_bytes != ECL_KW_HEADER_DATA_SIZE) - return ECL_KW_READ_FAIL; - - memcpy(header, &buffer[0], ECL_STRING8_LENGTH); - void *ptr = &buffer[ECL_STRING8_LENGTH]; - size = *((int *)ptr); - - memcpy(ecl_type_str, &buffer[ECL_STRING8_LENGTH + sizeof(size)], - ECL_TYPE_LENGTH); - - if (!fortio_complete_read(fortio, record_size)) - return ECL_KW_READ_FAIL; - - if (ECL_ENDIAN_FLIP) - util_endian_flip_vector(&size, sizeof size, 1); - } - - ecl_data_type data_type = ecl_type_create_from_name(ecl_type_str); - ecl_kw_initialize(ecl_kw, header, size, data_type); - - return ECL_KW_READ_OK; -} - -/** - Will seek through the open fortio file and search for a keyword with - header 'kw'. It will always start the search from the present - position in the file, but if rewind is true it will rewind the - fortio file if not finding 'kw' between current offset and EOF. - - If the kw is found the fortio pointer is positioned at the - beginning of the keyword, and the function returns true. If the the - 'kw' is NOT found the file will be repositioned to the initial - position, and the function will return false; unless abort_on_error - == true in which case the function will abort if the 'kw' is not - found. -*/ - -bool ecl_kw_fseek_kw(const char *kw, bool rewind, bool abort_on_error, - fortio_type *fortio) { - ecl_kw_type *tmp_kw = ecl_kw_alloc_empty(); - long int init_pos = fortio_ftell(fortio); - bool cont, kw_found; - - cont = true; - kw_found = false; - while (cont) { - long current_pos = fortio_ftell(fortio); - if (ecl_kw_fread_header(tmp_kw, fortio) == ECL_KW_READ_OK) { - if (ecl_kw_string_eq(ecl_kw_get_header8(tmp_kw), kw)) { - fortio_fseek(fortio, current_pos, SEEK_SET); - kw_found = true; - cont = false; - } else - ecl_kw_fskip_data(tmp_kw, fortio); - } else { - if (rewind) { - fortio_rewind(fortio); - rewind = false; - } else - cont = false; - } - } - if (!kw_found) { - if (abort_on_error) - util_abort( - "%s: failed to locate keyword:%s in file:%s - aborting \n", - __func__, kw, fortio_filename_ref(fortio)); - - fortio_fseek(fortio, init_pos, SEEK_SET); - } - - ecl_kw_free(tmp_kw); - return kw_found; -} - -bool ecl_kw_ifseek_kw(const char *kw, fortio_type *fortio, int index) { - int i = 0; - do { - ecl_kw_fseek_kw(kw, false, true, fortio); - i++; - } while (i <= index); - return true; -} - -bool ecl_kw_fseek_last_kw(const char *kw, bool abort_on_error, - fortio_type *fortio) { - long int init_pos = fortio_ftell(fortio); - bool kw_found = false; - - fortio_fseek(fortio, 0L, SEEK_SET); - kw_found = ecl_kw_fseek_kw(kw, false, false, fortio); - if (kw_found) { - bool cont = true; - do { - long int current_pos = fortio_ftell(fortio); - ecl_kw_fskip(fortio); - cont = ecl_kw_fseek_kw(kw, false, false, fortio); - if (!cont) - fortio_fseek(fortio, current_pos, SEEK_SET); - } while (cont); - } else { - if (abort_on_error) - util_abort("%s: could not locate keyword:%s - aborting \n", - __func__, kw); - else - fortio_fseek(fortio, init_pos, SEEK_SET); - } - return kw_found; -} - -void ecl_kw_set_data_ptr(ecl_kw_type *ecl_kw, void *data) { - if (!ecl_kw->shared_data) - free(ecl_kw->data); - ecl_kw->data = (char *)data; -} - -/** - This is where the storage buffer of the ecl_kw is allocated. -*/ -void ecl_kw_alloc_data(ecl_kw_type *ecl_kw) { - if (ecl_kw->shared_data) - util_abort("%s: trying to allocate data for ecl_kw object which has " - "been declared with shared storage - aborting \n", - __func__); - - { - size_t byte_size = - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type); - ecl_kw->data = (char *)util_realloc(ecl_kw->data, byte_size); - if (ecl_kw->data) { - memset(ecl_kw->data, 0, byte_size); - } - } -} - -void ecl_kw_free_data(ecl_kw_type *ecl_kw) { - if (!ecl_kw->shared_data) - free(ecl_kw->data); - - ecl_kw->data = NULL; -} - -void ecl_kw_set_header_name(ecl_kw_type *ecl_kw, const char *header) { - ecl_kw->header8 = (char *)realloc(ecl_kw->header8, ECL_STRING8_LENGTH + 1); - if (strlen(header) <= 8) { - sprintf(ecl_kw->header8, "%-8s", header); - - /* Internalizing a header without the trailing spaces as well. */ - free(ecl_kw->header); - ecl_kw->header = util_alloc_strip_copy(ecl_kw->header8); - } else { - ecl_kw->header = (char *)util_alloc_copy(header, strlen(header) + 1); - } -} - -void ecl_kw_set_data_type(ecl_kw_type *ecl_kw, ecl_data_type data_type) { - memcpy(&ecl_kw->data_type, &data_type, sizeof data_type); -} - -bool ecl_kw_fread_realloc(ecl_kw_type *ecl_kw, fortio_type *fortio) { - if (ecl_kw_fread_header(ecl_kw, fortio) == ECL_KW_READ_OK) - return ecl_kw_fread_realloc_data(ecl_kw, fortio); - else - return false; -} - -void ecl_kw_fread(ecl_kw_type *ecl_kw, fortio_type *fortio) { - int current_size = ecl_kw->size; - if (ecl_kw_fread_header(ecl_kw, fortio) != ECL_KW_READ_OK) - util_abort("%s: failed to read header for ecl_kw - aborting \n", - __func__); - - if (ecl_kw->size == current_size) - ecl_kw_fread_data(ecl_kw, fortio); - else - util_abort("%s: size mismatch - aborting \n", __func__); -} - -ecl_kw_type *ecl_kw_fread_alloc(fortio_type *fortio) { - bool OK; - ecl_kw_type *ecl_kw = ecl_kw_alloc_empty(); - OK = ecl_kw_fread_realloc(ecl_kw, fortio); - if (!OK) { - ecl_kw_free(ecl_kw); - ecl_kw = NULL; - } - - return ecl_kw; -} - -void ecl_kw_fskip(fortio_type *fortio) { - ecl_kw_type *tmp_kw; - tmp_kw = ecl_kw_fread_alloc(fortio); - ecl_kw_free(tmp_kw); -} - -static void ecl_kw_fwrite_data_unformatted(const ecl_kw_type *ecl_kw, - fortio_type *fortio) { - char *iobuffer = ecl_kw_alloc_output_buffer(ecl_kw); - int sizeof_iotype = ecl_type_get_sizeof_iotype(ecl_kw->data_type); - { - const int blocksize = get_blocksize(ecl_kw->data_type); - const int num_blocks = - ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1); - int block_nr; - - for (block_nr = 0; block_nr < num_blocks; block_nr++) { - int this_blocksize = - util_int_min((block_nr + 1) * blocksize, ecl_kw->size) - - block_nr * blocksize; - int record_size = - this_blocksize * - sizeof_iotype; /* The total size in bytes of the record written by the fortio layer. */ - fortio_fwrite_record( - fortio, &iobuffer[block_nr * blocksize * sizeof_iotype], - record_size); - } - } - free(iobuffer); -} - -/** - The point of this awkward function is that I have not managed to - use C fprintf() syntax to reproduce the ECLIPSE - formatting. ECLIPSE expects the following formatting for float - and double values: - - 0.ddddddddE+03 (float) - 0.ddddddddddddddD+03 (double) - - The problem with printf have been: - - 1. To force the radix part to start with 0. - 2. To use 'D' as the exponent start for double values. - - If you are more proficient with C fprintf() format strings than I - am, the __fprintf_scientific() function should be removed, and - the WRITE_FMT_DOUBLE and WRITE_FMT_FLOAT format specifiers - updated accordingly. - */ - -static void __fprintf_scientific(FILE *stream, const char *fmt, double x) { - double pow_x = ceil(log10(fabs(x))); - double arg_x = x / pow(10.0, pow_x); - if (x != 0.0) { - if (fabs(arg_x) == 1.0) { - arg_x *= 0.10; - pow_x += 1; - } - } else { - arg_x = 0.0; - pow_x = 0.0; - } - fprintf(stream, fmt, arg_x, (int)pow_x); -} - -static void ecl_kw_fwrite_data_formatted(ecl_kw_type *ecl_kw, - fortio_type *fortio) { - - { - - FILE *stream = fortio_get_FILE(fortio); - const int blocksize = get_blocksize(ecl_kw->data_type); - const int columns = get_columns(ecl_kw->data_type); - char *write_fmt = alloc_write_fmt(ecl_kw->data_type); - const int num_blocks = - ecl_kw->size / blocksize + (ecl_kw->size % blocksize == 0 ? 0 : 1); - int block_nr; - - for (block_nr = 0; block_nr < num_blocks; block_nr++) { - int this_blocksize = - util_int_min((block_nr + 1) * blocksize, ecl_kw->size) - - block_nr * blocksize; - int num_lines = this_blocksize / columns + - (this_blocksize % columns == 0 ? 0 : 1); - int line_nr; - for (line_nr = 0; line_nr < num_lines; line_nr++) { - int num_columns = - util_int_min((line_nr + 1) * columns, this_blocksize) - - columns * line_nr; - int col_nr; - for (col_nr = 0; col_nr < num_columns; col_nr++) { - int data_index = - block_nr * blocksize + line_nr * columns + col_nr; - void *data_ptr = ecl_kw_iget_ptr_static(ecl_kw, data_index); - switch (ecl_kw_get_type(ecl_kw)) { - case (ECL_CHAR_TYPE): - fprintf(stream, write_fmt, data_ptr); - break; - case (ECL_STRING_TYPE): - fprintf(stream, write_fmt, data_ptr); - break; - case (ECL_INT_TYPE): { - int int_value = ((int *)data_ptr)[0]; - fprintf(stream, write_fmt, int_value); - } break; - case (ECL_BOOL_TYPE): { - bool bool_value = ((bool *)data_ptr)[0]; - if (bool_value) - fprintf(stream, write_fmt, BOOL_TRUE_CHAR); - else - fprintf(stream, write_fmt, BOOL_FALSE_CHAR); - } break; - case (ECL_FLOAT_TYPE): { - float float_value = ((float *)data_ptr)[0]; - __fprintf_scientific(stream, write_fmt, float_value); - } break; - case (ECL_DOUBLE_TYPE): { - double double_value = ((double *)data_ptr)[0]; - __fprintf_scientific(stream, write_fmt, double_value); - } break; - case (ECL_MESS_TYPE): - util_abort("%s: Internal inconsistency : message type " - "keywords should not have data\n", - __func__); - break; - } - } - fprintf(stream, "\n"); - } - } - - free(write_fmt); - } -} - -void ecl_kw_fwrite_data(const ecl_kw_type *_ecl_kw, fortio_type *fortio) { - ecl_kw_type *ecl_kw = (ecl_kw_type *)_ecl_kw; - bool fmt_file = fortio_fmt_file(fortio); - - if (fmt_file) - ecl_kw_fwrite_data_formatted(ecl_kw, fortio); - else - ecl_kw_fwrite_data_unformatted(ecl_kw, fortio); -} - -void ecl_kw_fwrite_header(const ecl_kw_type *ecl_kw, fortio_type *fortio) { - FILE *stream = fortio_get_FILE(fortio); - bool fmt_file = fortio_fmt_file(fortio); - char *type_name = ecl_type_alloc_name(ecl_kw->data_type); - - if (fmt_file) - fprintf(stream, WRITE_HEADER_FMT, ecl_kw->header8, ecl_kw->size, - type_name); - else { - int size = ecl_kw->size; - if (ECL_ENDIAN_FLIP) - util_endian_flip_vector(&size, sizeof size, 1); - - fortio_init_write(fortio, ECL_KW_HEADER_DATA_SIZE); - - fwrite(ecl_kw->header8, sizeof(char), ECL_STRING8_LENGTH, stream); - fwrite(&size, sizeof(int), 1, stream); - fwrite(type_name, sizeof(char), ECL_TYPE_LENGTH, stream); - - fortio_complete_write(fortio, ECL_KW_HEADER_DATA_SIZE); - } - - free(type_name); -} - -bool ecl_kw_fwrite(const ecl_kw_type *ecl_kw, fortio_type *fortio) { - if (strlen(ecl_kw_get_header(ecl_kw)) > ECL_STRING8_LENGTH) { - fortio_fwrite_error(fortio); - return false; - } - ecl_kw_fwrite_header(ecl_kw, fortio); - ecl_kw_fwrite_data(ecl_kw, fortio); - return true; -} - -static void *ecl_kw_get_data_ref(const ecl_kw_type *ecl_kw) { - return ecl_kw->data; -} - -void *ecl_kw_get_ptr(const ecl_kw_type *ecl_kw) { - return ecl_kw_get_data_ref(ecl_kw); -} - -int ecl_kw_get_size(const ecl_kw_type *ecl_kw) { return ecl_kw->size; } - -ecl_type_enum ecl_kw_get_type(const ecl_kw_type *ecl_kw) { - return ecl_type_get_type(ecl_kw->data_type); -} - -ecl_data_type ecl_kw_get_data_type(const ecl_kw_type *ecl_kw) { - return ecl_kw->data_type; -} - -ecl_kw_type *ecl_kw_buffer_alloc(buffer_type *buffer) { - const char *header = buffer_fread_string(buffer); - int size = buffer_fread_int(buffer); - ecl_type_enum ecl_type = (ecl_type_enum)buffer_fread_int(buffer); - size_t element_size = buffer_fread_int(buffer); - - ecl_data_type data_type = ecl_type_create(ecl_type, element_size); - ecl_kw_type *ecl_kw = ecl_kw_alloc_empty(); - ecl_kw_initialize(ecl_kw, header, size, data_type); - ecl_kw_alloc_data(ecl_kw); - buffer_fread(buffer, ecl_kw->data, - ecl_type_get_sizeof_ctype(ecl_kw->data_type), ecl_kw->size); - return ecl_kw; -} - -void ecl_kw_buffer_store(const ecl_kw_type *ecl_kw, buffer_type *buffer) { - buffer_fwrite_string(buffer, ecl_kw->header8); - buffer_fwrite_int(buffer, ecl_kw->size); - buffer_fwrite_int(buffer, ecl_type_get_type(ecl_kw->data_type)); - buffer_fwrite_int(buffer, ecl_type_get_sizeof_ctype(ecl_kw->data_type)); - buffer_fwrite(buffer, ecl_kw->data, - ecl_type_get_sizeof_ctype(ecl_kw->data_type), ecl_kw->size); -} - -void ecl_kw_fwrite_param_fortio(fortio_type *fortio, const char *header, - ecl_data_type data_type, int size, void *data) { - ecl_kw_type *ecl_kw = - ecl_kw_alloc_new_shared(header, size, data_type, data); - ecl_kw_fwrite(ecl_kw, fortio); - ecl_kw_free(ecl_kw); -} - -void ecl_kw_fwrite_param(const char *filename, bool fmt_file, - const char *header, ecl_data_type data_type, int size, - void *data) { - fortio_type *fortio = - fortio_open_writer(filename, fmt_file, ECL_ENDIAN_FLIP); - ecl_kw_fwrite_param_fortio(fortio, header, data_type, size, data); - fortio_fclose(fortio); -} - -void ecl_kw_get_data_as_double(const ecl_kw_type *ecl_kw, double *double_data) { - - if (ecl_type_is_double(ecl_kw->data_type)) - // Direct memcpy - no conversion - ecl_kw_get_memcpy_data(ecl_kw, double_data); - else { - if (ecl_type_is_float(ecl_kw->data_type)) { - const float *float_data = (const float *)ecl_kw->data; - util_float_to_double(double_data, float_data, ecl_kw->size); - } else if (ecl_type_is_int(ecl_kw->data_type)) { - const int *int_data = (const int *)ecl_kw->data; - int i; - for (i = 0; i < ecl_kw->size; i++) - double_data[i] = int_data[i]; - } else { - fprintf(stderr, - "%s: type can not be converted to double - aborting \n", - __func__); - ecl_kw_summarize(ecl_kw); - util_abort("%s: Aborting \n", __func__); - } - } -} - -void ecl_kw_get_data_as_float(const ecl_kw_type *ecl_kw, float *float_data) { - - if (ecl_type_is_float(ecl_kw->data_type)) - // Direct memcpy - no conversion - ecl_kw_get_memcpy_data(ecl_kw, float_data); - else { - if (ecl_type_is_double(ecl_kw->data_type)) { - const double *double_data = (const double *)ecl_kw->data; - util_double_to_float(float_data, double_data, ecl_kw->size); - } else if (ecl_type_is_int(ecl_kw->data_type)) { - const int *int_data = (const int *)ecl_kw->data; - int i; - for (i = 0; i < ecl_kw->size; i++) - float_data[i] = (float)int_data[i]; - } else { - fprintf(stderr, - "%s: type can not be converted to float - aborting \n", - __func__); - ecl_kw_summarize(ecl_kw); - util_abort("%s: Aborting \n", __func__); - } - } -} - -/** - Will create a new keyword of the same type as src_kw, and size - @target_size. The integer array mapping is a list sizeof(src_kw) - elements, where each element is the new index, i.e. - - new_kw[ mapping[i] ] = src_kw[i] - - For all inactive elements in new kw are set as follows: - - 0 - For float / int / double - False - For logical - "" - For char -*/ - -ecl_kw_type *ecl_kw_alloc_scatter_copy(const ecl_kw_type *src_kw, - int target_size, const int *mapping, - void *def_value) { - int default_int = 0; - double default_double = 0; - float default_float = 0; - bool default_bool = false; - const char *default_char = ""; - ecl_kw_type *new_kw = - ecl_kw_alloc(src_kw->header, target_size, src_kw->data_type); - - if (def_value != NULL) - ecl_kw_scalar_set__(new_kw, def_value); - else { - /** Initialize with defaults .*/ - switch (ecl_kw_get_type(src_kw)) { - case (ECL_INT_TYPE): - ecl_kw_scalar_set__(new_kw, &default_int); - break; - case (ECL_FLOAT_TYPE): - ecl_kw_scalar_set__(new_kw, &default_float); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_scalar_set__(new_kw, &default_double); - break; - case (ECL_BOOL_TYPE): - ecl_kw_scalar_set__(new_kw, &default_bool); - break; - case (ECL_CHAR_TYPE): - ecl_kw_scalar_set__(new_kw, default_char); - break; - default: - util_abort("%s: unsupported type:%d \n", __func__, - ecl_kw_get_type(src_kw)); - } - } - - { - int sizeof_ctype = ecl_type_get_sizeof_ctype(src_kw->data_type); - int i; - for (i = 0; i < src_kw->size; i++) { - int target_index = mapping[i]; - memcpy(&new_kw->data[target_index * sizeof_ctype], - &src_kw->data[i * sizeof_ctype], sizeof_ctype); - } - } - - return new_kw; -} - -ecl_kw_type *ecl_kw_alloc_global_copy(const ecl_kw_type *src, - const ecl_kw_type *actnum) { - if (ecl_kw_get_type(actnum) != ECL_INT_TYPE) - return NULL; - - const int global_size = ecl_kw_get_size(actnum); - ecl_kw_type *global_copy = - ecl_kw_alloc(ecl_kw_get_header(src), global_size, src->data_type); - const int *mapping = ecl_kw_get_int_ptr(actnum); - const int src_size = ecl_kw_get_size(src); - int src_index = 0; - for (int global_index = 0; global_index < global_size; global_index++) { - if (mapping[global_index]) { - /* We ran through and beyond the size of the src keyword. */ - if (src_index >= src_size) { - ecl_kw_free(global_copy); - global_copy = NULL; - break; - } - const void *value_ptr = ecl_kw_iget_ptr(src, src_index); - ecl_kw_iset_static(global_copy, global_index, value_ptr); - src_index++; - } - } - - /* Not all the src data was distributed. */ - if (src_index < src_size) { - ecl_kw_free(global_copy); - global_copy = NULL; - } - - return global_copy; -} - -void ecl_kw_fread_double_param(const char *filename, bool fmt_file, - double *double_data) { - fortio_type *fortio = - fortio_open_reader(filename, fmt_file, ECL_ENDIAN_FLIP); - ecl_kw_type *ecl_kw = ecl_kw_fread_alloc(fortio); - fortio_fclose(fortio); - - if (ecl_kw == NULL) - util_abort( - "%s: fatal error: loading parameter from: %s failed - aborting \n", - __func__, filename); - - ecl_kw_get_data_as_double(ecl_kw, double_data); - ecl_kw_free(ecl_kw); -} - -void ecl_kw_summarize(const ecl_kw_type *ecl_kw) { - char *type_name = ecl_type_alloc_name(ecl_kw->data_type); - printf("%8s %10d:%4s \n", ecl_kw_get_header8(ecl_kw), - ecl_kw_get_size(ecl_kw), type_name); - free(type_name); -} - -#define ECL_KW_SCALAR_SET_TYPED(ctype, ECL_TYPE) \ - void ecl_kw_scalar_set_##ctype(ecl_kw_type *ecl_kw, ctype value) { \ - if (ecl_kw_get_type(ecl_kw) == ECL_TYPE) { \ - ctype *data = (ctype *)ecl_kw_get_data_ref(ecl_kw); \ - int i; \ - for (i = 0; i < ecl_kw->size; i++) \ - data[i] = value; \ - } else \ - util_abort("%s: wrong type\n", __func__); \ - } - -ECL_KW_SCALAR_SET_TYPED(int, ECL_INT_TYPE) -ECL_KW_SCALAR_SET_TYPED(float, ECL_FLOAT_TYPE) -ECL_KW_SCALAR_SET_TYPED(double, ECL_DOUBLE_TYPE) -ECL_KW_SCALAR_SET_TYPED(bool, ECL_BOOL_TYPE) -#undef ECL_KW_SCALAR_SET_TYPED - -void ecl_kw_scalar_set_float_or_double(ecl_kw_type *ecl_kw, double value) { - ecl_type_enum ecl_type = ecl_kw_get_type(ecl_kw); - if (ecl_type == ECL_FLOAT_TYPE) - ecl_kw_scalar_set_float(ecl_kw, (float)value); - else if (ecl_type == ECL_DOUBLE_TYPE) - ecl_kw_scalar_set_double(ecl_kw, value); - else - util_abort("%s: wrong type \n", __func__); -} - -/* - Untyped - low level alternative. -*/ -void ecl_kw_scalar_set__(ecl_kw_type *ecl_kw, const void *value) { - int sizeof_ctype = ecl_type_get_sizeof_ctype(ecl_kw->data_type); - int i; - for (i = 0; i < ecl_kw->size; i++) - memcpy(&ecl_kw->data[i * sizeof_ctype], value, sizeof_ctype); -} - -void ecl_kw_alloc_double_data(ecl_kw_type *ecl_kw, double *values) { - ecl_kw_alloc_data(ecl_kw); - memcpy(ecl_kw->data, values, - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); -} - -void ecl_kw_alloc_float_data(ecl_kw_type *ecl_kw, float *values) { - ecl_kw_alloc_data(ecl_kw); - memcpy(ecl_kw->data, values, - ecl_kw->size * ecl_type_get_sizeof_ctype(ecl_kw->data_type)); -} - -#define ECL_KW_SCALE_TYPED(ctype, ECL_TYPE) \ - void ecl_kw_scale_##ctype(ecl_kw_type *ecl_kw, ctype scale_factor) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - { \ - ctype *data = (ctype *)ecl_kw_get_data_ref(ecl_kw); \ - int size = ecl_kw_get_size(ecl_kw); \ - int i; \ - for (i = 0; i < size; i++) \ - data[i] *= scale_factor; \ - } \ - } - -ECL_KW_SCALE_TYPED(int, ECL_INT_TYPE) -ECL_KW_SCALE_TYPED(float, ECL_FLOAT_TYPE) -ECL_KW_SCALE_TYPED(double, ECL_DOUBLE_TYPE) -#undef ECL_KW_SCALE_TYPED - -void ecl_kw_scale_float_or_double(ecl_kw_type *ecl_kw, double scale_factor) { - ecl_type_enum ecl_type = ecl_kw_get_type(ecl_kw); - if (ecl_type == ECL_FLOAT_TYPE) - ecl_kw_scale_float(ecl_kw, (float)scale_factor); - else if (ecl_type == ECL_DOUBLE_TYPE) - ecl_kw_scale_double(ecl_kw, scale_factor); - else - util_abort("%s: wrong type \n", __func__); -} - -#define ECL_KW_SHIFT_TYPED(ctype, ECL_TYPE) \ - void ecl_kw_shift_##ctype(ecl_kw_type *ecl_kw, ctype shift_value) { \ - if (ecl_kw_get_type(ecl_kw) != ECL_TYPE) \ - util_abort("%s: Keyword: %s is wrong type - aborting \n", \ - __func__, ecl_kw_get_header8(ecl_kw)); \ - { \ - ctype *data = (ctype *)ecl_kw_get_data_ref(ecl_kw); \ - int size = ecl_kw_get_size(ecl_kw); \ - int i; \ - for (i = 0; i < size; i++) \ - data[i] += shift_value; \ - } \ - } - -ECL_KW_SHIFT_TYPED(int, ECL_INT_TYPE) -ECL_KW_SHIFT_TYPED(float, ECL_FLOAT_TYPE) -ECL_KW_SHIFT_TYPED(double, ECL_DOUBLE_TYPE) -#undef ECL_KW_SHIFT_TYPED - -void ecl_kw_shift_float_or_double(ecl_kw_type *ecl_kw, double shift_value) { - ecl_type_enum ecl_type = ecl_kw_get_type(ecl_kw); - if (ecl_type == ECL_FLOAT_TYPE) - ecl_kw_shift_float(ecl_kw, (float)shift_value); - else if (ecl_type == ECL_DOUBLE_TYPE) - ecl_kw_shift_double(ecl_kw, shift_value); - else - util_abort("%s: wrong type \n", __func__); -} - -bool ecl_kw_size_and_numeric_type_equal(const ecl_kw_type *kw1, - const ecl_kw_type *kw2) { - return ecl_kw_size_and_type_equal(kw1, kw2) && - ecl_type_is_numeric(kw1->data_type); -} - -#define ECL_KW_ASSERT_TYPED_BINARY_OP(ctype, ECL_TYPE) \ - bool ecl_kw_assert_binary_##ctype(const ecl_kw_type *kw1, \ - const ecl_kw_type *kw2) { \ - if (!ecl_kw_size_and_numeric_type_equal(kw1, kw2)) \ - return false; \ - if (ecl_kw_get_type(kw1) != ECL_TYPE) \ - return false; /* Type mismatch */ \ - return true; \ - } - -ECL_KW_ASSERT_TYPED_BINARY_OP(int, ECL_INT_TYPE) -ECL_KW_ASSERT_TYPED_BINARY_OP(float, ECL_FLOAT_TYPE) -ECL_KW_ASSERT_TYPED_BINARY_OP(double, ECL_DOUBLE_TYPE) -#undef ECL_KW_ASSERT_TYPED_BINARY_OP - -void ecl_kw_copy_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *src_kw) { - if (!ecl_kw_size_and_type_equal(target_kw, src_kw)) - util_abort("%s: type/size mismatch\n", __func__); - { - char *target_data = (char *)ecl_kw_get_data_ref(target_kw); - const char *src_data = (const char *)ecl_kw_get_data_ref(src_kw); - int sizeof_ctype = ecl_type_get_sizeof_ctype(target_kw->data_type); - int set_size = int_vector_size(index_set); - const int *index_data = int_vector_get_const_ptr(index_set); - int i; - for (i = 0; i < set_size; i++) { - int index = index_data[i]; - memcpy(&target_data[index * sizeof_ctype], - &src_data[index * sizeof_ctype], sizeof_ctype); - } - } -} - -#define ECL_KW_TYPED_INPLACE_ADD_INDEXED(ctype) \ - static void ecl_kw_inplace_add_indexed_##ctype( \ - ecl_kw_type *target_kw, const int_vector_type *index_set, \ - const ecl_kw_type *add_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, add_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *add_data = \ - (const ctype *)ecl_kw_get_data_ref(add_kw); \ - int set_size = int_vector_size(index_set); \ - const int *index_data = int_vector_get_const_ptr(index_set); \ - int i; \ - for (i = 0; i < set_size; i++) { \ - int index = index_data[i]; \ - target_data[index] += add_data[index]; \ - } \ - } \ - } - -ECL_KW_TYPED_INPLACE_ADD_INDEXED(int) -ECL_KW_TYPED_INPLACE_ADD_INDEXED(double) -ECL_KW_TYPED_INPLACE_ADD_INDEXED(float) -#undef ECL_KW_TYPED_INPLACE_ADD - -void ecl_kw_inplace_add_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *add_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_add_indexed_float(target_kw, index_set, add_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_add_indexed_double(target_kw, index_set, add_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_add_indexed_int(target_kw, index_set, add_kw); - break; - default: - util_abort("%s: inplace add not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_ADD(ctype) \ - static void ecl_kw_inplace_add_##ctype(ecl_kw_type *target_kw, \ - const ecl_kw_type *add_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, add_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *add_data = \ - (const ctype *)ecl_kw_get_data_ref(add_kw); \ - int i; \ - for (i = 0; i < target_kw->size; i++) \ - target_data[i] += add_data[i]; \ - } \ - } -ECL_KW_TYPED_INPLACE_ADD(int) -ECL_KW_TYPED_INPLACE_ADD(double) -ECL_KW_TYPED_INPLACE_ADD(float) - -#undef ECL_KW_TYPED_INPLACE_ADD - -void ecl_kw_inplace_add(ecl_kw_type *target_kw, const ecl_kw_type *add_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_add_float(target_kw, add_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_add_double(target_kw, add_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_add_int(target_kw, add_kw); - break; - default: - util_abort("%s: inplace add not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_ADD_SQUARED(ctype) \ - static void ecl_kw_inplace_add_squared_##ctype( \ - ecl_kw_type *target_kw, const ecl_kw_type *add_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, add_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *add_data = \ - (const ctype *)ecl_kw_get_data_ref(add_kw); \ - int i; \ - for (i = 0; i < target_kw->size; i++) \ - target_data[i] += add_data[i] * add_data[i]; \ - } \ - } -ECL_KW_TYPED_INPLACE_ADD_SQUARED(int) -ECL_KW_TYPED_INPLACE_ADD_SQUARED(double) -ECL_KW_TYPED_INPLACE_ADD_SQUARED(float) - -#undef ECL_KW_TYPED_INPLACE_ADD - -void ecl_kw_inplace_add_squared(ecl_kw_type *target_kw, - const ecl_kw_type *add_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_add_squared_float(target_kw, add_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_add_squared_double(target_kw, add_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_add_squared_int(target_kw, add_kw); - break; - default: - util_abort("%s: inplace add not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_SUB(ctype) \ - void ecl_kw_inplace_sub_##ctype(ecl_kw_type *target_kw, \ - const ecl_kw_type *sub_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, sub_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *sub_data = \ - (const ctype *)ecl_kw_get_data_ref(sub_kw); \ - int i; \ - for (i = 0; i < target_kw->size; i++) \ - target_data[i] -= sub_data[i]; \ - } \ - } -ECL_KW_TYPED_INPLACE_SUB(int) -ECL_KW_TYPED_INPLACE_SUB(double) -ECL_KW_TYPED_INPLACE_SUB(float) -#undef ECL_KW_TYPED_INPLACE_SUB - -void ecl_kw_inplace_sub(ecl_kw_type *target_kw, const ecl_kw_type *sub_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_sub_float(target_kw, sub_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_sub_double(target_kw, sub_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_sub_int(target_kw, sub_kw); - break; - default: - util_abort("%s: inplace sub not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_SUB_INDEXED(ctype) \ - static void ecl_kw_inplace_sub_indexed_##ctype( \ - ecl_kw_type *target_kw, const int_vector_type *index_set, \ - const ecl_kw_type *sub_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, sub_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *sub_data = \ - (const ctype *)ecl_kw_get_data_ref(sub_kw); \ - int set_size = int_vector_size(index_set); \ - const int *index_data = int_vector_get_const_ptr(index_set); \ - int i; \ - for (i = 0; i < set_size; i++) { \ - int index = index_data[i]; \ - target_data[index] -= sub_data[index]; \ - } \ - } \ - } - -ECL_KW_TYPED_INPLACE_SUB_INDEXED(int) -ECL_KW_TYPED_INPLACE_SUB_INDEXED(double) -ECL_KW_TYPED_INPLACE_SUB_INDEXED(float) -#undef ECL_KW_TYPED_INPLACE_SUB - -void ecl_kw_inplace_sub_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *sub_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_sub_indexed_float(target_kw, index_set, sub_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_sub_indexed_double(target_kw, index_set, sub_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_sub_indexed_int(target_kw, index_set, sub_kw); - break; - default: - util_abort("%s: inplace sub not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_ABS(ctype, abs_func) \ - void ecl_kw_inplace_abs_##ctype(ecl_kw_type *kw) { \ - ctype *data = (ctype *)ecl_kw_get_data_ref(kw); \ - int i; \ - for (i = 0; i < kw->size; i++) \ - data[i] = abs_func(data[i]); \ - } - -ECL_KW_TYPED_INPLACE_ABS(int, abs) -ECL_KW_TYPED_INPLACE_ABS(double, fabs) -ECL_KW_TYPED_INPLACE_ABS(float, fabsf) -#undef ECL_KW_TYPED_INPLACE_ABS - -void ecl_kw_inplace_abs(ecl_kw_type *kw) { - ecl_type_enum type = ecl_kw_get_type(kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_abs_float(kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_abs_double(kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_abs_int(kw); - break; - default: - util_abort("%s: inplace abs not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(kw))); - } -} - -static int sqrti(int x) { return round(sqrt(x)); } - -#define ECL_KW_TYPED_INPLACE_SQRT(ctype, sqrt_func) \ - void ecl_kw_inplace_sqrt_##ctype(ecl_kw_type *kw) { \ - ctype *data = (ctype *)ecl_kw_get_data_ref(kw); \ - int i; \ - for (i = 0; i < kw->size; i++) \ - data[i] = sqrt_func(data[i]); \ - } - -ECL_KW_TYPED_INPLACE_SQRT(double, sqrt) -ECL_KW_TYPED_INPLACE_SQRT(float, sqrtf) -ECL_KW_TYPED_INPLACE_SQRT(int, sqrti) -#undef ECL_KW_TYPED_INPLACE_SQRT - -void ecl_kw_inplace_sqrt(ecl_kw_type *kw) { - ecl_type_enum type = ecl_kw_get_type(kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_sqrt_float(kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_sqrt_double(kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_sqrt_int(kw); - break; - default: - util_abort("%s: inplace sqrt not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_MUL(ctype) \ - void ecl_kw_inplace_mul_##ctype(ecl_kw_type *target_kw, \ - const ecl_kw_type *mul_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, mul_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *mul_data = \ - (const ctype *)ecl_kw_get_data_ref(mul_kw); \ - int i; \ - for (i = 0; i < target_kw->size; i++) \ - target_data[i] *= mul_data[i]; \ - } \ - } -ECL_KW_TYPED_INPLACE_MUL(int) -ECL_KW_TYPED_INPLACE_MUL(double) -ECL_KW_TYPED_INPLACE_MUL(float) -#undef ECL_KW_TYPED_INPLACE_MUL - -void ecl_kw_inplace_mul(ecl_kw_type *target_kw, const ecl_kw_type *mul_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_mul_float(target_kw, mul_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_mul_double(target_kw, mul_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_mul_int(target_kw, mul_kw); - break; - default: - util_abort("%s: inplace mul not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_MUL_INDEXED(ctype) \ - static void ecl_kw_inplace_mul_indexed_##ctype( \ - ecl_kw_type *target_kw, const int_vector_type *index_set, \ - const ecl_kw_type *mul_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, mul_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *mul_data = \ - (const ctype *)ecl_kw_get_data_ref(mul_kw); \ - int set_size = int_vector_size(index_set); \ - const int *index_data = int_vector_get_const_ptr(index_set); \ - int i; \ - for (i = 0; i < set_size; i++) { \ - int index = index_data[i]; \ - target_data[index] *= mul_data[index]; \ - } \ - } \ - } - -ECL_KW_TYPED_INPLACE_MUL_INDEXED(int) -ECL_KW_TYPED_INPLACE_MUL_INDEXED(double) -ECL_KW_TYPED_INPLACE_MUL_INDEXED(float) -#undef ECL_KW_TYPED_INPLACE_MUL - -void ecl_kw_inplace_mul_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *mul_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_mul_indexed_float(target_kw, index_set, mul_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_mul_indexed_double(target_kw, index_set, mul_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_mul_indexed_int(target_kw, index_set, mul_kw); - break; - default: - util_abort("%s: inplace mul not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_DIV(ctype) \ - void ecl_kw_inplace_div_##ctype(ecl_kw_type *target_kw, \ - const ecl_kw_type *div_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, div_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *div_data = \ - (const ctype *)ecl_kw_get_data_ref(div_kw); \ - int i; \ - for (i = 0; i < target_kw->size; i++) \ - target_data[i] /= div_data[i]; \ - } \ - } -ECL_KW_TYPED_INPLACE_DIV(int) -ECL_KW_TYPED_INPLACE_DIV(double) -ECL_KW_TYPED_INPLACE_DIV(float) -#undef ECL_KW_TYPED_INPLACE_DIV - -void ecl_kw_inplace_div(ecl_kw_type *target_kw, const ecl_kw_type *div_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_div_float(target_kw, div_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_div_double(target_kw, div_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_div_int(target_kw, div_kw); - break; - default: - util_abort("%s: inplace div not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -#define ECL_KW_TYPED_INPLACE_DIV_INDEXED(ctype) \ - static void ecl_kw_inplace_div_indexed_##ctype( \ - ecl_kw_type *target_kw, const int_vector_type *index_set, \ - const ecl_kw_type *div_kw) { \ - if (!ecl_kw_assert_binary_##ctype(target_kw, div_kw)) \ - util_abort("%s: type/size mismatch\n", __func__); \ - { \ - ctype *target_data = (ctype *)ecl_kw_get_data_ref(target_kw); \ - const ctype *div_data = \ - (const ctype *)ecl_kw_get_data_ref(div_kw); \ - int set_size = int_vector_size(index_set); \ - const int *index_data = int_vector_get_const_ptr(index_set); \ - int i; \ - for (i = 0; i < set_size; i++) { \ - int index = index_data[i]; \ - target_data[index] *= div_data[index]; \ - } \ - } \ - } - -ECL_KW_TYPED_INPLACE_DIV_INDEXED(int) -ECL_KW_TYPED_INPLACE_DIV_INDEXED(double) -ECL_KW_TYPED_INPLACE_DIV_INDEXED(float) -#undef ECL_KW_TYPED_INPLACE_DIV - -void ecl_kw_inplace_div_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *div_kw) { - ecl_type_enum type = ecl_kw_get_type(target_kw); - switch (type) { - case (ECL_FLOAT_TYPE): - ecl_kw_inplace_div_indexed_float(target_kw, index_set, div_kw); - break; - case (ECL_DOUBLE_TYPE): - ecl_kw_inplace_div_indexed_double(target_kw, index_set, div_kw); - break; - case (ECL_INT_TYPE): - ecl_kw_inplace_div_indexed_int(target_kw, index_set, div_kw); - break; - default: - util_abort("%s: inplace div not implemented for type:%s \n", __func__, - ecl_type_alloc_name(ecl_kw_get_data_type(target_kw))); - } -} - -bool ecl_kw_inplace_safe_div(ecl_kw_type *target_kw, - const ecl_kw_type *divisor) { - if (ecl_kw_get_type(target_kw) != ECL_FLOAT_TYPE) - return false; - - if (ecl_kw_get_type(divisor) != ECL_INT_TYPE) - return false; - - float *target_data = (float *)ecl_kw_get_data_ref(target_kw); - const int *div_data = (const int *)ecl_kw_get_data_ref(divisor); - for (int i = 0; i < target_kw->size; i++) { - if (div_data[i] != 0) - target_data[i] /= div_data[i]; - } - - return true; -} - -void ecl_kw_inplace_inv(ecl_kw_type *my_kw) { - int size = ecl_kw_get_size(my_kw); - ecl_type_enum type = ecl_kw_get_type(my_kw); - { - int i; - void *my_data = ecl_kw_get_data_ref(my_kw); - - switch (type) { - case (ECL_DOUBLE_TYPE): { - double *my_double = (double *)my_data; - for (i = 0; i < size; i++) - my_double[i] = 1.0 / my_double[i]; - break; - } - case (ECL_FLOAT_TYPE): { - float *my_float = (float *)my_data; - for (i = 0; i < size; i++) - my_float[i] = 1.0f / my_float[i]; - break; - } - default: - util_abort("%s: can only be called on ECL_FLOAT_TYPE and " - "ECL_DOUBLE_TYPE - aborting \n", - __func__); - } - } -} - -void ecl_kw_inplace_update_file(const ecl_kw_type *ecl_kw, const char *filename, - int index) { - if (util_file_exists(filename)) { - bool fmt_file = util_fmt_bit8(filename); - - { - fortio_type *fortio = - fortio_open_readwrite(filename, fmt_file, ECL_ENDIAN_FLIP); - ecl_kw_ifseek_kw(ecl_kw_get_header8(ecl_kw), fortio, index); - { - ecl_kw_type *file_kw = ecl_kw_alloc_empty(); - long int current_pos = fortio_ftell(fortio); - ecl_kw_fread_header(file_kw, fortio); - fortio_fseek(fortio, current_pos, SEEK_SET); - - if (!ecl_kw_size_and_type_equal(ecl_kw, file_kw)) - util_abort( - "%s: header mismatch when trying to update:%s in %s \n", - __func__, ecl_kw_get_header8(ecl_kw), filename); - ecl_kw_free(file_kw); - } - - fortio_fflush(fortio); - ecl_kw_fwrite(ecl_kw, fortio); - fortio_fclose(fortio); - } - } -} - -bool ecl_kw_is_kw_file(fortio_type *fortio) { - const long int init_pos = fortio_ftell(fortio); - bool kw_file; - - { - ecl_kw_type *ecl_kw = ecl_kw_alloc_empty(); - - if (fortio_fmt_file(fortio)) - kw_file = (ecl_kw_fread_header(ecl_kw, fortio) != ECL_KW_READ_FAIL); - else { - if (fortio_is_fortio_file(fortio)) - kw_file = - (ecl_kw_fread_header(ecl_kw, fortio) != ECL_KW_READ_FAIL); - else - kw_file = false; - } - - ecl_kw_free(ecl_kw); - } - - fortio_fseek(fortio, init_pos, SEEK_SET); - return kw_file; -} - -#define KW_MAX_MIN(type) \ - { \ - type *data = (type *)ecl_kw_get_data_ref(ecl_kw); \ - type max = data[0]; \ - type min = data[0]; \ - int i; \ - for (i = 1; i < ecl_kw_get_size(ecl_kw); i++) \ - util_update_##type##_max_min(data[i], &max, &min); \ - memcpy(_max, &max, ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ - memcpy(_min, &min, ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ - } - -void ecl_kw_max_min(const ecl_kw_type *ecl_kw, void *_max, void *_min) { - switch (ecl_kw_get_type(ecl_kw)) { - case (ECL_FLOAT_TYPE): - KW_MAX_MIN(float); - break; - case (ECL_DOUBLE_TYPE): - KW_MAX_MIN(double); - break; - case (ECL_INT_TYPE): - KW_MAX_MIN(int); - break; - default: - util_abort("%s: invalid type for element sum \n", __func__); - } -} - -#define ECL_KW_MAX_MIN(ctype) \ - void ecl_kw_max_min_##ctype(const ecl_kw_type *ecl_kw, ctype *_max, \ - ctype *_min) { \ - KW_MAX_MIN(ctype); \ - } - -#define ECL_KW_MAX(ctype) \ - ctype ecl_kw_##ctype##_max(const ecl_kw_type *ecl_kw) { \ - ctype max, min; \ - ecl_kw_max_min_##ctype(ecl_kw, &max, &min); \ - return max; \ - } - -#define ECL_KW_MIN(ctype) \ - ctype ecl_kw_##ctype##_min(const ecl_kw_type *ecl_kw) { \ - ctype max, min; \ - ecl_kw_max_min_##ctype(ecl_kw, &max, &min); \ - return min; \ - } - -ECL_KW_MAX_MIN(int) -ECL_KW_MAX_MIN(float) -ECL_KW_MAX_MIN(double) - -ECL_KW_MAX(int) -ECL_KW_MAX(float) -ECL_KW_MAX(double) - -ECL_KW_MIN(int) -ECL_KW_MIN(float) -ECL_KW_MIN(double) - -#undef ECL_KW_MAX -#undef ECL_KW_MIN -#undef KW_MAX_MIN -#undef ECL_KW_MAX_MIN - -#define KW_SUM_INDEXED(type) \ - { \ - const type *data = (const type *)ecl_kw_get_data_ref(ecl_kw); \ - type sum = 0; \ - int size = int_vector_size(index_list); \ - const int *index_ptr = int_vector_get_const_ptr(index_list); \ - for (int i = 0; i < size; i++) \ - sum += data[index_ptr[i]]; \ - memcpy(_sum, &sum, ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ - } - -void ecl_kw_element_sum_indexed(const ecl_kw_type *ecl_kw, - const int_vector_type *index_list, void *_sum) { - switch (ecl_kw_get_type(ecl_kw)) { - case (ECL_FLOAT_TYPE): - KW_SUM_INDEXED(float); - break; - case (ECL_DOUBLE_TYPE): - KW_SUM_INDEXED(double); - break; - case (ECL_INT_TYPE): - KW_SUM_INDEXED(int); - break; - case (ECL_BOOL_TYPE): { - const bool *data = (const bool *)ecl_kw_get_data_ref(ecl_kw); - const int *index_ptr = int_vector_get_const_ptr(index_list); - const int size = int_vector_size(index_list); - int sum = 0; - for (int i = 0; i < size; i++) - sum += (data[index_ptr[i]]); - - memcpy(_sum, &sum, sizeof sum); - } break; - default: - util_abort("%s: invalid type for element sum \n", __func__); - } -} -#undef KW_SUM - -#define KW_SUM(type) \ - { \ - const type *data = (const type *)ecl_kw_get_data_ref(ecl_kw); \ - type sum = 0; \ - for (int i = 0; i < ecl_kw_get_size(ecl_kw); i++) \ - sum += data[i]; \ - memcpy(_sum, &sum, ecl_type_get_sizeof_ctype(ecl_kw->data_type)); \ - } - -void ecl_kw_element_sum(const ecl_kw_type *ecl_kw, void *_sum) { - switch (ecl_kw_get_type(ecl_kw)) { - case (ECL_FLOAT_TYPE): - KW_SUM(float); - break; - case (ECL_DOUBLE_TYPE): - KW_SUM(double); - break; - case (ECL_INT_TYPE): - KW_SUM(int); - break; - default: - util_abort("%s: invalid type for element sum \n", __func__); - } -} -#undef KW_SUM - -double ecl_kw_element_sum_float(const ecl_kw_type *ecl_kw) { - float float_sum; - double double_sum; - void *sum_ptr = NULL; - - if (ecl_type_is_double(ecl_kw->data_type)) - sum_ptr = &double_sum; - else if (ecl_type_is_float(ecl_kw->data_type)) - sum_ptr = &float_sum; - else - util_abort("%s: invalid type: \n", __func__); - - ecl_kw_element_sum(ecl_kw, sum_ptr); - - if (ecl_type_is_double(ecl_kw->data_type)) - return double_sum; - else if (ecl_type_is_float(ecl_kw->data_type)) - return float_sum; - else - return 0; -} - -int ecl_kw_element_sum_int(const ecl_kw_type *ecl_kw) { - int int_sum; - ecl_kw_element_sum(ecl_kw, &int_sum); - - return int_sum; -} - -#define ECL_KW_FPRINTF_DATA(ctype) \ - static void ecl_kw_fprintf_data_##ctype(const ecl_kw_type *ecl_kw, \ - const char *fmt, FILE *stream) { \ - const ctype *data = (const ctype *)ecl_kw->data; \ - int i; \ - for (i = 0; i < ecl_kw->size; i++) \ - fprintf(stream, fmt, data[i]); \ - } - -ECL_KW_FPRINTF_DATA(int) -ECL_KW_FPRINTF_DATA(float) -ECL_KW_FPRINTF_DATA(double) -ECL_KW_FPRINTF_DATA(bool) -#undef ECL_KW_FPRINTF_DATA - -static void ecl_kw_fprintf_data_string(const ecl_kw_type *ecl_kw, - const char *fmt, FILE *stream) { - int i; - for (i = 0; i < ecl_kw->size; i++) - fprintf( - stream, fmt, - &ecl_kw->data[i * ecl_type_get_sizeof_ctype(ecl_kw->data_type)]); -} - -void ecl_kw_fprintf_data(const ecl_kw_type *ecl_kw, const char *fmt, - FILE *stream) { - if (ecl_type_is_double(ecl_kw->data_type)) - ecl_kw_fprintf_data_double(ecl_kw, fmt, stream); - else if (ecl_type_is_float(ecl_kw->data_type)) - ecl_kw_fprintf_data_float(ecl_kw, fmt, stream); - else if (ecl_type_is_int(ecl_kw->data_type)) - ecl_kw_fprintf_data_int(ecl_kw, fmt, stream); - else if (ecl_type_is_bool(ecl_kw->data_type)) - ecl_kw_fprintf_data_bool(ecl_kw, fmt, stream); - else if (ecl_type_is_char(ecl_kw->data_type) || - ecl_type_is_string(ecl_kw->data_type)) - ecl_kw_fprintf_data_string(ecl_kw, fmt, stream); -} - -static bool ecl_kw_elm_equal_numeric__(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2, int offset, - double abs_epsilon, double rel_epsilon) { - double v1 = ecl_kw_iget_as_double(ecl_kw1, offset); - double v2 = ecl_kw_iget_as_double(ecl_kw2, offset); - return util_double_approx_equal__(v1, v2, rel_epsilon, abs_epsilon); -} - -static bool ecl_kw_elm_equal__(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2, int offset) { - size_t data_offset = ecl_type_get_sizeof_ctype(ecl_kw1->data_type) * offset; - int cmp = memcmp(&ecl_kw1->data[data_offset], &ecl_kw2->data[data_offset], - ecl_type_get_sizeof_ctype(ecl_kw1->data_type)); - if (cmp == 0) - return true; - else - return false; -} - -int ecl_kw_first_different(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2, int offset, - double abs_epsilon, double rel_epsilon) { - if (!ecl_kw_size_and_type_equal(ecl_kw1, ecl_kw2)) - util_abort("%s: sorry invalid comparison\n", __func__); - - if (offset >= ecl_kw_get_size(ecl_kw1)) - util_abort("%s: sorry - invalid offset value\n", __func__); - - { - bool numeric_compare = false; - - if (((abs_epsilon > 0) || (rel_epsilon > 0)) && - ((ecl_kw_get_type(ecl_kw1) == ECL_FLOAT_TYPE) || - (ecl_kw_get_type(ecl_kw1) == ECL_DOUBLE_TYPE))) - numeric_compare = true; - { - int index = offset; - - while (true) { - bool equal = - (numeric_compare) - ? ecl_kw_elm_equal_numeric__(ecl_kw1, ecl_kw2, index, - abs_epsilon, rel_epsilon) - : ecl_kw_elm_equal__(ecl_kw1, ecl_kw2, index); - if (!equal) - break; - - index++; - if (index == ecl_kw_get_size(ecl_kw1)) - break; - } - - return index; - } - } -} - -#include "ecl_kw_functions.cpp" diff --git a/lib/ecl/ecl_nnc_data.cpp b/lib/ecl/ecl_nnc_data.cpp deleted file mode 100644 index 84565fd1e2..0000000000 --- a/lib/ecl/ecl_nnc_data.cpp +++ /dev/null @@ -1,273 +0,0 @@ -#define ECL_NNC_DATA_TYPE_ID 83756236 - -#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 ecl_nnc_data_struct { - UTIL_TYPE_ID_DECLARATION; - int size; - double *values; -}; - -static const char *ecl_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 ecl_kw_type * -ecl_nnc_data_get_gl_kw(const ecl_file_view_type *init_file_view, const char *kw, - int kw_type, int lgr_nr) { - if (!kw) - return NULL; - - if (lgr_nr == 0) { - if (ecl_file_view_has_kw(init_file_view, kw)) - return ecl_file_view_iget_named_kw(init_file_view, kw, 0); - else - return NULL; - } - - bool correct_lgrheadi = false; - const int file_num_kw = ecl_file_view_get_size(init_file_view); - for (int kw_index = 0, head_index = 0; kw_index < file_num_kw; ++kw_index) { - ecl_kw_type *ecl_kw = ecl_file_view_iget_kw(init_file_view, kw_index); - const char *current_kw = ecl_kw_get_header(ecl_kw); - - if (strcmp(LGRHEADI_KW, current_kw) == 0) { - if (ecl_kw_iget_int(ecl_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 ecl_kw; - } - } - } - - return NULL; -} - -static ecl_kw_type * -ecl_nnc_data_get_tranll_kw(const ecl_grid_type *grid, - const ecl_file_view_type *init_file_view, - int lgr_nr1, int lgr_nr2) { - const char *lgr_name1 = ecl_grid_get_lgr_name(grid, lgr_nr1); - const char *lgr_name2 = ecl_grid_get_lgr_name(grid, lgr_nr2); - - ecl_kw_type *tran_kw = NULL; - const int file_num_kw = ecl_file_view_get_size(init_file_view); - int global_kw_index = 0; - - while (true) { - if (global_kw_index >= file_num_kw) - break; - { - ecl_kw_type *ecl_kw = - ecl_file_view_iget_kw(init_file_view, global_kw_index); - if (strcmp(LGRJOIN_KW, ecl_kw_get_header(ecl_kw)) == 0) { - - if (ecl_kw_icmp_string(ecl_kw, 0, lgr_name1) && - ecl_kw_icmp_string(ecl_kw, 1, lgr_name2)) { - tran_kw = ecl_file_view_iget_kw(init_file_view, - global_kw_index + 1); - break; - } - } - global_kw_index++; - } - } - - return tran_kw; -} - -static ecl_kw_type * -ecl_nnc_data_get_kw(const ecl_grid_type *grid, - const ecl_file_view_type *init_file_view, int lgr_nr1, - int lgr_nr2, int kw_type) { - - const char *kw = ecl_nnc_data_get_str_kw(kw_type, lgr_nr1, lgr_nr2); - if (lgr_nr1 == 0 || lgr_nr1 == lgr_nr2) - return ecl_nnc_data_get_gl_kw(init_file_view, kw, kw_type, lgr_nr2); - else if (kw_type == TRANS_DATA) - return ecl_nnc_data_get_tranll_kw(grid, init_file_view, lgr_nr1, - lgr_nr2); - else - return NULL; -} - -static void assert_correct_kw_count(ecl_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, - ecl_kw_get_header(kw), correct_kw_count, kw_count); -} - -static bool ecl_nnc_data_set_values(ecl_nnc_data_type *data, - const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file, - int kw_type) { - - int current_grid1 = -1; - int current_grid2 = -1; - ecl_kw_type *current_kw = NULL; - int correct_kw_count = 0; - int kw_count = 0; - int nnc_size = ecl_nnc_geometry_size(nnc_geo); - - for (int nnc_index = 0; nnc_index < nnc_size; nnc_index++) { - const ecl_nnc_pair_type *pair = - ecl_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 = - ecl_nnc_data_get_kw(grid, init_file, grid1, grid2, kw_type); - kw_count = 0; - if (current_kw) { - correct_kw_count = ecl_kw_get_size(current_kw); - } else { - return false; - } - } - if (current_kw) { - data->values[nnc_index] = - ecl_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 ecl_nnc_data_type * -ecl_nnc_data_alloc__(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file, int kw_type) { - ecl_nnc_data_type *data = (ecl_nnc_data_type *)util_malloc(sizeof *data); - - int nnc_size = ecl_nnc_geometry_size(nnc_geo); - data->size = nnc_size; - - data->values = (double *)util_malloc(nnc_size * sizeof(double)); - - if (ecl_nnc_data_set_values(data, grid, nnc_geo, init_file, kw_type)) - return data; - else { - ecl_nnc_data_free(data); - return NULL; - } -} - -ecl_nnc_data_type * -ecl_nnc_data_alloc_tran(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file) { - return ecl_nnc_data_alloc__(grid, nnc_geo, init_file, TRANS_DATA); -} - -ecl_nnc_data_type * -ecl_nnc_data_alloc_wat_flux(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file) { - return ecl_nnc_data_alloc__(grid, nnc_geo, init_file, WTR_FLUX_DATA); -} - -ecl_nnc_data_type * -ecl_nnc_data_alloc_oil_flux(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file) { - return ecl_nnc_data_alloc__(grid, nnc_geo, init_file, OIL_FLUX_DATA); -} - -ecl_nnc_data_type * -ecl_nnc_data_alloc_gas_flux(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file) { - return ecl_nnc_data_alloc__(grid, nnc_geo, init_file, GAS_FLUX_DATA); -} - -void ecl_nnc_data_free(ecl_nnc_data_type *data) { - free(data->values); - free(data); -} - -int ecl_nnc_data_get_size(ecl_nnc_data_type *data) { return data->size; } - -const double *ecl_nnc_data_get_values(const ecl_nnc_data_type *data) { - return data->values; -} - -double ecl_nnc_data_iget_value(const ecl_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/ecl/ecl_nnc_export.cpp b/lib/ecl/ecl_nnc_export.cpp deleted file mode 100644 index f191e16fe1..0000000000 --- a/lib/ecl/ecl_nnc_export.cpp +++ /dev/null @@ -1,290 +0,0 @@ -#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 ecl_nnc_intersect_format(const ecl_grid_type *grid, - const ecl_file_type *init_file) { - if (!ecl_file_has_kw(init_file, NNC1_KW) || - !ecl_file_has_kw(init_file, NNC2_KW) || - !ecl_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 = - ecl_kw_get_size(ecl_file_iget_named_kw(init_file, NNC1_KW, 0)); - const auto nnc2_num = - ecl_kw_get_size(ecl_file_iget_named_kw(init_file, NNC2_KW, 0)); - const auto tran_num = - ecl_kw_get_size(ecl_file_iget_named_kw(init_file, TRANNNC_KW, 0)); - return nnc1_num == tran_num && nnc2_num == tran_num; -} - -int ecl_nnc_export_get_size(const ecl_grid_type *grid, - const ecl_file_type *init_file) { - return ecl_nnc_intersect_format(grid, init_file) - ? ecl_kw_get_size( - ecl_file_iget_named_kw(init_file, TRANNNC_KW, 0)) - : // Intersect format - ecl_grid_get_num_nnc(grid); // Eclipse format -} - -static int ecl_nnc_export_intersect__(const ecl_file_type *init_file, - ecl_nnc_type *nnc_data, int *nnc_offset) { - const auto nnc1_kw = ecl_file_iget_named_kw(init_file, NNC1_KW, 0); - const auto nnc2_kw = ecl_file_iget_named_kw(init_file, NNC2_KW, 0); - const auto tran_kw = ecl_file_iget_named_kw(init_file, TRANNNC_KW, 0); - - auto nnc_index = *nnc_offset; - for (int i = 0; i < ecl_kw_get_size(tran_kw); ++i) { - auto const nnc1 = ecl_kw_iget_int(nnc1_kw, i); - auto const nnc2 = ecl_kw_iget_int(nnc2_kw, i); - auto const tran = ecl_kw_iget_as_double(tran_kw, i); - nnc_data[nnc_index] = ecl_nnc_type{0, nnc1, 0, nnc2, i, tran}; - ++nnc_index; - } - *nnc_offset = nnc_index; - return ecl_kw_get_size(tran_kw); // Assume all valid -} - -static int ecl_nnc_export__(const ecl_grid_type *grid, int lgr_index1, - const ecl_file_type *init_file, - ecl_nnc_type *nnc_data, int *nnc_offset) { - int nnc_index = *nnc_offset; - int lgr_nr1 = ecl_grid_get_lgr_nr(grid); - int global_index1; - int valid_trans = 0; - const ecl_grid_type *global_grid = ecl_grid_get_global_grid(grid); - - if (!global_grid) - global_grid = grid; - - for (global_index1 = 0; global_index1 < ecl_grid_get_global_size(grid); - global_index1++) { - const nnc_info_type *nnc_info = - ecl_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 ecl_kw_type *tran_kw = ecl_nnc_export_get_tranx_kw( - global_grid, init_file, lgr_nr1, lgr_nr2); - - int index2; - ecl_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 = - ecl_kw_iget_as_double(tran_kw, nnc.input_index); - valid_trans++; - } else { - nnc.trans = ERT_ECL_DEFAULT_NNC_TRANS; - } - - nnc_data[nnc_index] = nnc; - nnc_index++; - } - } - } - } - *nnc_offset = nnc_index; - return valid_trans; -} - -int ecl_nnc_export(const ecl_grid_type *grid, const ecl_file_type *init_file, - ecl_nnc_type *nnc_data) { - int nnc_index = 0; - int total_valid_trans = 0; - if (ecl_nnc_intersect_format(grid, init_file)) { - // Intersect format - total_valid_trans = - ecl_nnc_export_intersect__(init_file, nnc_data, &nnc_index); - } else { - // Eclipse format - total_valid_trans = - ecl_nnc_export__(grid, 0, init_file, nnc_data, &nnc_index); - { - for (int lgr_index = 0; lgr_index < ecl_grid_get_num_lgr(grid); - lgr_index++) { - ecl_grid_type *igrid = ecl_grid_iget_lgr(grid, lgr_index); - total_valid_trans += ecl_nnc_export__( - igrid, lgr_index, init_file, nnc_data, &nnc_index); - } - } - nnc_index = ecl_grid_get_num_nnc(grid); - } - ecl_nnc_sort(nnc_data, nnc_index); - return total_valid_trans; -} - -int ecl_nnc_sort_cmp(const ecl_nnc_type *nnc1, const ecl_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 ecl_nnc_equal(const ecl_nnc_type *nnc1, const ecl_nnc_type *nnc2) { - - if (ecl_nnc_sort_cmp(nnc1, nnc2) == 0) - return ((nnc1->trans == nnc2->trans) && - (nnc1->input_index == nnc2->input_index)); - else - return false; -} - -static int ecl_nnc_sort_cmp__(const void *nnc1, const void *nnc2) { - return ecl_nnc_sort_cmp((const ecl_nnc_type *)nnc1, - (const ecl_nnc_type *)nnc2); -} - -void ecl_nnc_sort(ecl_nnc_type *nnc_list, int size) { - qsort(nnc_list, size, sizeof *nnc_list, ecl_nnc_sort_cmp__); -} - -ecl_kw_type *ecl_nnc_export_get_tranll_kw(const ecl_grid_type *grid, - const ecl_file_type *init_file, - int lgr_nr1, int lgr_nr2) { - const char *lgr_name1 = ecl_grid_get_lgr_name(grid, lgr_nr1); - const char *lgr_name2 = ecl_grid_get_lgr_name(grid, lgr_nr2); - - ecl_kw_type *tran_kw = NULL; - const int file_num_kw = ecl_file_get_size(init_file); - int global_kw_index = 0; - - while (true) { - if (global_kw_index >= file_num_kw) - break; - { - ecl_kw_type *ecl_kw = ecl_file_iget_kw(init_file, global_kw_index); - if (strcmp(LGRJOIN_KW, ecl_kw_get_header(ecl_kw)) == 0) { - - if (ecl_kw_icmp_string(ecl_kw, 0, lgr_name1) && - ecl_kw_icmp_string(ecl_kw, 1, lgr_name2)) { - tran_kw = ecl_file_iget_kw(init_file, global_kw_index + 1); - break; - } - } - global_kw_index++; - } - } - - return tran_kw; -} - -ecl_kw_type *ecl_nnc_export_get_tran_kw(const ecl_file_type *init_file, - const char *kw, int lgr_nr) { - ecl_kw_type *tran_kw = NULL; - if (lgr_nr == 0) { - if (strcmp(kw, TRANNNC_KW) == 0) - if (ecl_file_has_kw(init_file, kw)) { - tran_kw = ecl_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 = ecl_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) { - ecl_kw_type *ecl_kw = - ecl_file_iget_kw(init_file, global_kw_index); - const char *current_kw = ecl_kw_get_header(ecl_kw); - if (strcmp(LGRHEADI_KW, current_kw) == 0) { - if (ecl_kw_iget_int(ecl_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 = ecl_kw; - finished = true; - break; - } - } - } - global_kw_index++; - if (global_kw_index == file_num_kw) - finished = true; - } - } - } - return tran_kw; -} - -ecl_kw_type *ecl_nnc_export_get_tranx_kw(const ecl_grid_type *grid, - const ecl_file_type *init_file, - int lgr_nr1, int lgr_nr2) { - if (lgr_nr1 == lgr_nr2) - return ecl_nnc_export_get_tran_kw(init_file, TRANNNC_KW, lgr_nr2); - else { - if (lgr_nr1 == 0) - return ecl_nnc_export_get_tran_kw(init_file, TRANGL_KW, lgr_nr2); - else - return ecl_nnc_export_get_tranll_kw(grid, init_file, lgr_nr1, - lgr_nr2); - } -} diff --git a/lib/ecl/ecl_region.cpp b/lib/ecl/ecl_region.cpp deleted file mode 100644 index 9e713a1ec9..0000000000 --- a/lib/ecl/ecl_region.cpp +++ /dev/null @@ -1,1554 +0,0 @@ -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -/** - This file implements a type called ecl_region which is a way to - select and keep track of designated cells in an ECLIPSE reservoir - grid. An instance is allocated with a grid (a shared reference - which is NOT modified). Then we can select/deselect cells based on: - - 1. Integer equality - ecl_region_select_equal() - 2. Float interval - ecl_region_select_in_interval() - 3. A rectangualar box - ecl_region_select_from_box() - 4. Subsections of i/j/k - ecl_region_select_i1i2() / ecl_region_seleect_j1j2() / ... - 5. All cells - ecl_region_select_all() - - When allocating an instance you determine whether all cells should - be initially selected, or not-selected. The various select - functions can (of course ...) be chained together. All functions - exist in a xxx_select() and an opposite xxx_deselect() version. - - When you are finished with selecting you can query the ecl_region - instance for the number of active cells, and get a (const int *) to - the indices. You can also get the results in term of global - indices. (Refer to ecl_grid for the difference between active and - global indices). - - For the functions which take ecl_kw input, the ecl_kw instance must - have either nx*ny*nz elements, or nactive(from the grid) - elements. This is checked, and the program will fail hard if it is - not satisfied. - - Example: - -------- - - ecl_grid_type * ecl_grid; - ecl_kw_type * soil; - ecl_kw_type * regions; - ecl_region_type * ecl_region; - - // Load grid, soil and regions somehow. - - ecl_region = ecl_region_alloc( ecl_grid , false ); // Start with nothing selected - ecl_region_select_in_interval( ecl_region , soil , 0.50, 1.00); // Select all cells with soil > 0.50 - ecl_region_select_equal( ecl_region , regions , 3 ); // Only consider ECLIPSE region 3. - ecl_region_select_k1k2( ecl_region , 5 , 8); // Select layers 5,6,7,8 - { - int num_cells = ecl_region_get_global_size( ecl_region ); // How many cells are active - const int * cell_list = ecl_region_get_global_list( ecl_region ); // Get a list of indices - int i; - printf("%d cells satisfy your selection. The cells are: \n"); - - for (i=0; i < num_cells; i++) - printf("Cell: %d \n",cell_list[i]); - } - - ecl_region_free( ecl_region ); - -*/ - -#define ECL_REGION_TYPE_ID 1106377 - -struct ecl_region_struct { - UTIL_TYPE_ID_DECLARATION; - bool * - active_mask; /* This marks active|inactive in the region, which is unrelated to active in the grid. */ - int_vector_type * - global_index_list; /* This is a list of the cells in the region - irrespective of whether they are active in the grid or not. */ - int_vector_type * - active_index_list; /* This means cells in the region which are also active in the grid */ - int_vector_type * - global_active_list; /* This is a list of (maximum) nactive elements, where the values are in the [0,..nx*ny*nz) range. */ - bool global_index_list_valid; - bool active_index_list_valid; - - char *name; /* User name attached to region will typically be NULL. */ - bool preselect; - /* Grid properties */ - int grid_nx, grid_ny, grid_nz, grid_vol, grid_active; - const ecl_grid_type *parent_grid; -}; - -UTIL_IS_INSTANCE_FUNCTION(ecl_region, ECL_REGION_TYPE_ID) -UTIL_SAFE_CAST_FUNCTION(ecl_region, ECL_REGION_TYPE_ID) - -static void ecl_region_invalidate_index_list(ecl_region_type *region) { - region->global_index_list_valid = false; - region->active_index_list_valid = false; -} - -void ecl_region_lock(ecl_region_type *region) { - int_vector_set_read_only(region->global_index_list, true); - int_vector_set_read_only(region->active_index_list, true); - int_vector_set_read_only(region->global_active_list, true); -} - -void ecl_region_unlock(ecl_region_type *region) { - int_vector_set_read_only(region->global_index_list, false); - int_vector_set_read_only(region->active_index_list, false); - int_vector_set_read_only(region->global_active_list, false); -} - -ecl_region_type *ecl_region_alloc(const ecl_grid_type *ecl_grid, - bool preselect) { - ecl_region_type *region = (ecl_region_type *)util_malloc(sizeof *region); - UTIL_TYPE_ID_INIT(region, ECL_REGION_TYPE_ID); - region->parent_grid = ecl_grid; - ecl_grid_get_dims(ecl_grid, ®ion->grid_nx, ®ion->grid_ny, - ®ion->grid_nz, ®ion->grid_active); - region->grid_vol = region->grid_nx * region->grid_ny * region->grid_nz; - region->active_mask = - (bool *)util_calloc(region->grid_vol, sizeof *region->active_mask); - region->active_index_list = int_vector_alloc(0, 0); - region->global_index_list = int_vector_alloc(0, 0); - region->global_active_list = int_vector_alloc(0, 0); - region->preselect = preselect; - region->name = NULL; - ecl_region_reset( - region); /* This MUST be called to ensure that xxx_valid is correctly initialized. */ - return region; -} - -ecl_region_type *ecl_region_alloc_copy(const ecl_region_type *ecl_region) { - ecl_region_type *new_region = - ecl_region_alloc(ecl_region->parent_grid, ecl_region->preselect); - memcpy(new_region->active_mask, ecl_region->active_mask, - ecl_region->grid_vol * sizeof *ecl_region->active_mask); - ecl_region_invalidate_index_list(new_region); - return new_region; -} - -void ecl_region_free(ecl_region_type *region) { - free(region->active_mask); - int_vector_free(region->active_index_list); - int_vector_free(region->global_index_list); - int_vector_free(region->global_active_list); - free(region->name); - free(region); -} - -void ecl_region_free__(void *__region) { - ecl_region_type *region = ecl_region_safe_cast(__region); - ecl_region_free(region); -} - -static void ecl_region_assert_global_index_list(ecl_region_type *region) { - if (!region->global_index_list_valid) { - int global_index; - - int_vector_reset(region->global_index_list); - for (global_index = 0; global_index < region->grid_vol; global_index++) - if (region->active_mask[global_index]) - int_vector_append(region->global_index_list, global_index); - - region->global_index_list_valid = true; - } -} - -static void ecl_region_assert_active_index_list(ecl_region_type *region) { - if (!region->active_index_list_valid) { - int global_index; - - int_vector_reset(region->active_index_list); - int_vector_reset(region->global_active_list); - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (region->active_mask[global_index]) { - int active_index = ecl_grid_get_active_index1( - region->parent_grid, global_index); - if (active_index >= 0) { - int_vector_append(region->active_index_list, active_index); - int_vector_append(region->global_active_list, global_index); - } - } - } - region->active_index_list_valid = true; - } -} - -const int_vector_type *ecl_region_get_active_list(ecl_region_type *region) { - ecl_region_assert_active_index_list(region); - return region->active_index_list; -} - -const int_vector_type * -ecl_region_get_global_active_list(ecl_region_type *region) { - ecl_region_assert_active_index_list(region); - return region->global_active_list; -} - -const int_vector_type *ecl_region_get_global_list(ecl_region_type *region) { - ecl_region_assert_global_index_list(region); - return region->global_index_list; -} - -/* Cpp compat/legacy/cruft functions. */ -int ecl_region_get_active_size_cpp(ecl_region_type *region) { - return int_vector_size(ecl_region_get_active_list(region)); -} - -int ecl_region_get_global_size_cpp(ecl_region_type *region) { - return int_vector_size(ecl_region_get_global_list(region)); -} - -const int *ecl_region_get_active_list_cpp(ecl_region_type *region) { - return int_vector_get_const_ptr(ecl_region_get_active_list(region)); -} - -const int *ecl_region_get_global_list_cpp(ecl_region_type *region) { - return int_vector_get_const_ptr(ecl_region_get_global_list(region)); -} - -static void ecl_region_assert_kw(const ecl_region_type *region, - const ecl_kw_type *ecl_kw, bool *global_kw) { - int kw_size = ecl_kw_get_size(ecl_kw); - if (!(kw_size == region->grid_vol || kw_size == region->grid_active)) - util_abort( - "%s: size mismatch between ecl_kw instance and region->grid \n", - __func__); - if (kw_size == region->grid_vol) - *global_kw = true; - else - *global_kw = false; -} - -void ecl_region_reset(ecl_region_type *ecl_region) { - int i; - for (i = 0; i < ecl_region->grid_vol; i++) - ecl_region->active_mask[i] = ecl_region->preselect; - ecl_region_invalidate_index_list(ecl_region); -} - -static void ecl_region_select_cell__(ecl_region_type *region, int i, int j, - int k, bool select) { - int global_index = ecl_grid_get_global_index3(region->parent_grid, i, j, k); - region->active_mask[global_index] = select; - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_cell(ecl_region_type *region, int i, int j, int k) { - ecl_region_select_cell__(region, i, j, k, true); -} - -void ecl_region_deselect_cell(ecl_region_type *region, int i, int j, int k) { - ecl_region_select_cell__(region, i, j, k, false); -} - -static void ecl_region_select_equal__(ecl_region_type *region, - const ecl_kw_type *ecl_kw, int value, - bool select) { - bool global_kw; - ecl_region_assert_kw(region, ecl_kw, &global_kw); - if (!ecl_type_is_int(ecl_kw_get_data_type(ecl_kw))) - util_abort("%s: sorry - select by equality is only supported for " - "integer keywords \n", - __func__); - { - const int *kw_data = ecl_kw_get_int_ptr(ecl_kw); - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (kw_data[global_index] == value) - region->active_mask[global_index] = select; - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (kw_data[active_index] == value) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_equal(ecl_region_type *region, const ecl_kw_type *ecl_kw, - int value) { - ecl_region_select_equal__(region, ecl_kw, value, true); -} - -void ecl_region_deselect_equal(ecl_region_type *region, - const ecl_kw_type *ecl_kw, int value) { - ecl_region_select_equal__(region, ecl_kw, value, false); -} - -static void ecl_region_select_bool_equal__(ecl_region_type *region, - const ecl_kw_type *ecl_kw, - bool value, bool select) { - bool global_kw; - ecl_region_assert_kw(region, ecl_kw, &global_kw); - if (!ecl_type_is_bool(ecl_kw_get_data_type(ecl_kw))) - util_abort("%s: sorry - select by equality is only supported for " - "boolean keywords \n", - __func__); - { - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (ecl_kw_iget_bool(ecl_kw, global_index) == value) - region->active_mask[global_index] = select; - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (ecl_kw_iget_bool(ecl_kw, active_index) == value) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_true(ecl_region_type *region, - const ecl_kw_type *ecl_kw) { - ecl_region_select_bool_equal__(region, ecl_kw, true, true); -} - -void ecl_region_deselect_true(ecl_region_type *region, - const ecl_kw_type *ecl_kw) { - ecl_region_select_bool_equal__(region, ecl_kw, true, false); -} - -void ecl_region_select_false(ecl_region_type *region, - const ecl_kw_type *ecl_kw) { - ecl_region_select_bool_equal__(region, ecl_kw, false, true); -} - -void ecl_region_deselect_false(ecl_region_type *region, - const ecl_kw_type *ecl_kw) { - ecl_region_select_bool_equal__(region, ecl_kw, false, false); -} - -static void ecl_region_select_in_interval__(ecl_region_type *region, - const ecl_kw_type *ecl_kw, - float min_value, float max_value, - bool select) { - bool global_kw; - ecl_region_assert_kw(region, ecl_kw, &global_kw); - if (!ecl_type_is_float(ecl_kw_get_data_type(ecl_kw))) - util_abort("%s: sorry - select by in_interval is only supported for " - "float keywords \n", - __func__); - { - const float *kw_data = ecl_kw_get_float_ptr(ecl_kw); - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (kw_data[global_index] >= min_value && - kw_data[global_index] < max_value) - region->active_mask[global_index] = select; - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (kw_data[active_index] >= min_value && - kw_data[active_index] < max_value) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_in_interval(ecl_region_type *region, - const ecl_kw_type *ecl_kw, float min_value, - float max_value) { - ecl_region_select_in_interval__(region, ecl_kw, min_value, max_value, true); -} - -void ecl_region_deselect_in_interval(ecl_region_type *region, - const ecl_kw_type *ecl_kw, float min_value, - float max_value) { - ecl_region_select_in_interval__(region, ecl_kw, min_value, max_value, - false); -} - -/** - This is too large: - - Float / Int / double * Active / Global * More / Less ==> In total 12 code blocks written out ... -*/ - -/* - NBNBNBNB: Select >= on float values and select > on integer!!!!!! -*/ -static void ecl_region_select_with_limit__(ecl_region_type *region, - const ecl_kw_type *ecl_kw, - float limit, bool select_less, - bool select) { - bool global_kw; - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - ecl_region_assert_kw(region, ecl_kw, &global_kw); - if (!ecl_type_is_numeric(data_type)) - util_abort("%s: sorry - select by in_interval is only supported for " - "float and integer keywords \n", - __func__); - - { - if (ecl_type_is_float(data_type)) { - const float *kw_data = ecl_kw_get_float_ptr(ecl_kw); - float float_limit = limit; - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (select_less) { - if (kw_data[global_index] < float_limit) - region->active_mask[global_index] = select; - } else { - if (kw_data[global_index] >= float_limit) - region->active_mask[global_index] = select; - } - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (select_less) { - if (kw_data[active_index] < float_limit) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } else { - if (kw_data[active_index] >= float_limit) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - } else if (ecl_type_is_int(data_type)) { - const int *kw_data = ecl_kw_get_int_ptr(ecl_kw); - int int_limit = (int)limit; - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (select_less) { - if (kw_data[global_index] < int_limit) - region->active_mask[global_index] = select; - } else { - if (kw_data[global_index] > int_limit) - region->active_mask[global_index] = select; - } - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (select_less) { - if (kw_data[active_index] < int_limit) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } else { - if (kw_data[active_index] > int_limit) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - } else if (ecl_type_is_double(data_type)) { - const double *kw_data = ecl_kw_get_double_ptr(ecl_kw); - double double_limit = (double)limit; - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (select_less) { - if (kw_data[global_index] < double_limit) - region->active_mask[global_index] = select; - } else { - if (kw_data[global_index] >= double_limit) - region->active_mask[global_index] = select; - } - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (select_less) { - if (kw_data[active_index] < double_limit) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } else { - if (kw_data[active_index] >= double_limit) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_smaller(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit) { - ecl_region_select_with_limit__(ecl_region, ecl_kw, limit, true, true); -} - -void ecl_region_deselect_smaller(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit) { - ecl_region_select_with_limit__(ecl_region, ecl_kw, limit, true, false); -} - -void ecl_region_select_larger(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit) { - ecl_region_select_with_limit__(ecl_region, ecl_kw, limit, false, true); -} - -void ecl_region_deselect_larger(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit) { - ecl_region_select_with_limit__(ecl_region, ecl_kw, limit, false, false); -} - -/** - Selection based on comparing two keywords. -*/ - -static void ecl_region_cmp_select__(ecl_region_type *region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2, bool select_less, - bool select) { - bool global_kw; - ecl_region_assert_kw(region, kw1, &global_kw); - if (!ecl_type_is_float(ecl_kw_get_data_type(kw1))) - util_abort("%s: sorry - select by cmp() is only supported for float " - "keywords \n", - __func__); - { - if (ecl_kw_size_and_type_equal(kw1, kw2)) { - - const float *kw1_data = ecl_kw_get_float_ptr(kw1); - const float *kw2_data = ecl_kw_get_float_ptr(kw2); - - if (global_kw) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - if (select_less) { - if (kw1_data[global_index] < kw2_data[global_index]) - region->active_mask[global_index] = select; - } else { - if (kw1_data[global_index] >= kw2_data[global_index]) - region->active_mask[global_index] = select; - } - } - } else { - int active_index; - for (active_index = 0; active_index < region->grid_active; - active_index++) { - if (select_less) { - if (kw1_data[active_index] < kw2_data[active_index]) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } else { - if (kw1_data[active_index] >= kw2_data[active_index]) { - int global_index = ecl_grid_get_global_index1A( - region->parent_grid, active_index); - region->active_mask[global_index] = select; - } - } - } - } - } else - util_abort("%s: type/size mismatch between keywords. \n", __func__); - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_cmp_select_less(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2) { - ecl_region_cmp_select__(ecl_region, kw1, kw2, true, true); -} - -void ecl_region_cmp_deselect_less(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2) { - ecl_region_cmp_select__(ecl_region, kw1, kw2, true, false); -} - -void ecl_region_cmp_select_more(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2) { - ecl_region_cmp_select__(ecl_region, kw1, kw2, false, true); -} - -void ecl_region_cmp_deselect_more(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2) { - ecl_region_cmp_select__(ecl_region, kw1, kw2, false, false); -} - -/** - Will select all the cells in the box. Remember that the box is - defined as an inclusive geometry. Alternatively the functions - xxx_ijkbox() can be used, these functions take i1,i2,j1,j2,k1,k2 as - input and create a temporary box object. -*/ - -static void ecl_region_select_from_box__(ecl_region_type *region, - const ecl::ecl_box &ecl_box, - bool select) { - for (auto global_index : ecl_box.active_list()) - region->active_mask[global_index] = select; - - ecl_region_invalidate_index_list(region); -} - -/** - Observe that: - - 1. All the indices are inclusive. - 2. All the indices have zero offset. - - Only a thin wrapper around the ecl_region_select_from_box() function. -*/ - -static void ecl_region_select_from_ijkbox__(ecl_region_type *region, int i1, - int i2, int j1, int j2, int k1, - int k2, bool select) { - ecl::ecl_box tmp_box(region->parent_grid, i1, i2, j1, j2, k1, k2); - ecl_region_select_from_box__(region, tmp_box, select); -} - -void ecl_region_select_from_ijkbox(ecl_region_type *region, int i1, int i2, - int j1, int j2, int k1, int k2) { - ecl_region_select_from_ijkbox__(region, i1, i2, j1, j2, k1, k2, true); -} - -void ecl_region_deselect_from_ijkbox(ecl_region_type *region, int i1, int i2, - int j1, int j2, int k1, int k2) { - ecl_region_select_from_ijkbox__(region, i1, i2, j1, j2, k1, k2, false); -} - -/** - Observe that i1 and i2 are: - - * ZERO offset. - * An inclusive interval : [i1,i2] - - Input values below zero or above the upper limit are truncated. -*/ - -static void ecl_region_select_i1i2__(ecl_region_type *region, int i1, int i2, - bool select) { - if (i1 > i2) - util_abort("%s: i1 > i2 - this is illogical ... \n", __func__); - i1 = util_int_max(0, i1); - i2 = util_int_min(region->grid_nx - 1, i2); - { - int i, j, k; - for (k = 0; k < region->grid_nz; k++) - for (j = 0; j < region->grid_ny; j++) - for (i = i1; i <= i2; i++) { - int global_index = ecl_grid_get_global_index3( - region->parent_grid, i, j, k); - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_i1i2(ecl_region_type *region, int i1, int i2) { - ecl_region_select_i1i2__(region, i1, i2, true); -} - -void ecl_region_deselect_i1i2(ecl_region_type *region, int i1, int i2) { - ecl_region_select_i1i2__(region, i1, i2, false); -} - -/** - Observe that j1 and j2 are: - - * ZERO offset. - * An inclusive interval : [i1,i2] - - Input values below zero or above the upper limit are truncated. -*/ - -static void ecl_region_select_j1j2__(ecl_region_type *region, int j1, int j2, - bool select) { - if (j1 > j2) - util_abort("%s: i1 > i2 - this is illogical ... \n", __func__); - - j1 = util_int_max(0, j1); - j2 = util_int_min(region->grid_ny - 1, j2); - { - int i, j, k; - for (k = 0; k < region->grid_nz; k++) - for (j = j1; j <= j2; j++) - for (i = 0; i < region->grid_nx; i++) { - int global_index = ecl_grid_get_global_index3( - region->parent_grid, i, j, k); - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_j1j2(ecl_region_type *region, int j1, int j2) { - ecl_region_select_j1j2__(region, j1, j2, true); -} - -void ecl_region_deselect_j1j2(ecl_region_type *region, int j1, int j2) { - ecl_region_select_j1j2__(region, j1, j2, false); -} - -/** - Observe that k1 and k2 are: - - * ZERO offset. - * An inclusive interval : [i1,i2] - - Input values below zero or above the upper limit are truncated. -*/ - -static void ecl_region_select_k1k2__(ecl_region_type *region, int k1, int k2, - bool select) { - if (k1 > k2) - util_abort("%s: i1 > i2 - this is illogical ... \n", __func__); - k1 = util_int_max(0, k1); - k2 = util_int_min(region->grid_nz - 1, k2); - { - int i, j, k; - for (k = k1; k <= k2; k++) - for (j = 0; j < region->grid_ny; j++) - for (i = 0; i < region->grid_nx; i++) { - int global_index = ecl_grid_get_global_index3( - region->parent_grid, i, j, k); - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_k1k2(ecl_region_type *region, int k1, int k2) { - ecl_region_select_k1k2__(region, k1, k2, true); -} - -void ecl_region_deselect_k1k2(ecl_region_type *region, int k1, int k2) { - ecl_region_select_k1k2__(region, k1, k2, false); -} - -/** - This function will select all the cells with depth below the input - parameter @depth (if @select_below == true). The depth of a cell is - determined by the depth of the center of a cell. -*/ - -static void ecl_region_select_from_depth__(ecl_region_type *region, - double depth_limit, bool select_deep, - bool select) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) { - double cell_depth = - ecl_grid_get_cdepth1(region->parent_grid, global_index); - if (select_deep) { - // The select/deselect mechanism should be applied to deep cells. - if (cell_depth >= depth_limit) - region->active_mask[global_index] = select; - } else { - // The select/deselect mechanism should be applied to shallow cells. - if (cell_depth <= depth_limit) - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_shallow_cells(ecl_region_type *region, - double depth_limit) { - ecl_region_select_from_depth__(region, depth_limit, false, true); -} - -void ecl_region_deselect_shallow_cells(ecl_region_type *region, - double depth_limit) { - ecl_region_select_from_depth__(region, depth_limit, false, false); -} - -void ecl_region_select_deep_cells(ecl_region_type *region, double depth_limit) { - ecl_region_select_from_depth__(region, depth_limit, true, true); -} - -void ecl_region_deselect_deep_cells(ecl_region_type *region, - double depth_limit) { - ecl_region_select_from_depth__(region, depth_limit, true, false); -} - -static void ecl_region_select_from_volume__(ecl_region_type *region, - double volum_limit, - bool select_small, bool select) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) { - double cell_size = - ecl_grid_get_cell_volume1(region->parent_grid, global_index); - if (select_small) { - // The select/deselect mechanism should be applied to small cells. - if (cell_size <= volum_limit) - region->active_mask[global_index] = select; - } else { - // The select/deselect mechanism should be applied to large cells. - if (cell_size >= volum_limit) - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_small_cells(ecl_region_type *ecl_region, - double volum_limit) { - ecl_region_select_from_volume__(ecl_region, volum_limit, true, true); -} - -void ecl_region_deselect_small_cells(ecl_region_type *ecl_region, - double volum_limit) { - ecl_region_select_from_volume__(ecl_region, volum_limit, true, false); -} - -void ecl_region_select_large_cells(ecl_region_type *ecl_region, - double volum_limit) { - ecl_region_select_from_volume__(ecl_region, volum_limit, false, true); -} - -void ecl_region_deselect_large_cells(ecl_region_type *ecl_region, - double volum_limit) { - ecl_region_select_from_volume__(ecl_region, volum_limit, false, false); -} - -static void ecl_region_select_from_dz__(ecl_region_type *region, - double dz_limit, bool select_thin, - bool select) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) { - double cell_dz = - ecl_grid_get_cell_thickness1(region->parent_grid, global_index); - if (select_thin) { - // The select/deselect mechanism should be applied to thin cells. - if (cell_dz <= dz_limit) - region->active_mask[global_index] = select; - } else { - // The select/deselect mechanism should be applied to thick cells. - if (cell_dz >= dz_limit) - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_thin_cells(ecl_region_type *ecl_region, - double dz_limit) { - ecl_region_select_from_dz__(ecl_region, dz_limit, true, true); -} - -void ecl_region_deselect_thin_cells(ecl_region_type *ecl_region, - double dz_limit) { - ecl_region_select_from_dz__(ecl_region, dz_limit, true, false); -} - -void ecl_region_select_thick_cells(ecl_region_type *ecl_region, - double dz_limit) { - ecl_region_select_from_dz__(ecl_region, dz_limit, false, true); -} - -void ecl_region_deselect_thick_cells(ecl_region_type *ecl_region, - double dz_limit) { - ecl_region_select_from_dz__(ecl_region, dz_limit, false, false); -} - -static void ecl_region_select_active_cells__(ecl_region_type *ecl_region, - bool select_active, bool select) { - int global_index; - for (global_index = 0; global_index < ecl_region->grid_vol; - global_index++) { - if (select_active) { - if (ecl_grid_get_active_index1(ecl_region->parent_grid, - global_index) >= 0) - ecl_region->active_mask[global_index] = select; - } else { - if (ecl_grid_get_active_index1(ecl_region->parent_grid, - global_index) < 0) - ecl_region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(ecl_region); -} - -void ecl_region_select_active_cells(ecl_region_type *region) { - ecl_region_select_active_cells__(region, true, true); -} - -void ecl_region_deselect_active_cells(ecl_region_type *region) { - ecl_region_select_active_cells__(region, true, false); -} - -void ecl_region_select_inactive_cells(ecl_region_type *region) { - ecl_region_select_active_cells__(region, false, true); -} - -void ecl_region_deselect_inactive_cells(ecl_region_type *region) { - ecl_region_select_active_cells__(region, false, false); -} - -/** - This function will select a cell based on global_index. -*/ - -static void ecl_region_select_global_index__(ecl_region_type *region, - int global_index, bool select) { - if ((global_index >= 0) && (global_index < region->grid_vol)) - region->active_mask[global_index] = select; - else - util_abort("%s: global_index:%d invalid - legal interval: [0,%d) \n", - __func__, global_index, region->grid_vol); - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_global_index(ecl_region_type *region, int global_index) { - ecl_region_select_global_index__(region, global_index, true); -} - -void ecl_region_deselect_global_index(ecl_region_type *region, - int global_index) { - ecl_region_select_global_index__(region, global_index, false); -} - -/** - Here comes functions for selecting all the cells which are in the - vertical cylinder located at (x0,y0) with radius R. The functions - with name 'zcylinder' operate on a finite cylinder in the z - direction, specified with the additional arguments z1 and z2; the - functions without z1 and z2 arguments operate on an infinite - cylinder piercing the complete reservoir. - - Currently all user-exported functions call the - ecl_region_clyinder_select__() with select_inside == true. -*/ - -static void ecl_region_cylinder_select__(ecl_region_type *region, double x0, - double y0, double R, double z1, - double z2, bool select_inside, - bool select) { - double R2 = R * R; - - if (z1 < z2) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - double x, y, z; - ecl_grid_get_xyz1(region->parent_grid, global_index, &x, &y, &z); - if ((z >= z1) && (z <= z2)) { - double pointR2 = (x - x0) * (x - x0) + (y - y0) * (y - y0); - if ((pointR2 < R2) && (select_inside)) - region->active_mask[global_index] = select; - else if ((pointR2 > R2) && (!select_inside)) - region->active_mask[global_index] = select; - } - } - } else { - const int nx = region->grid_nx; - const int ny = region->grid_ny; - const int nz = region->grid_nz; - int i, j; - for (i = 0; i < nx; i++) { - for (j = 0; j < ny; j++) { - double x, y, z; - ecl_grid_get_xyz3(region->parent_grid, i, j, 0, &x, &y, &z); - { - double pointR2 = (x - x0) * (x - x0) + (y - y0) * (y - y0); - bool select_column = false; - - if ((pointR2 < R2) && (select_inside)) - select_column = true; - else if ((pointR2 > R2) && (!select_inside)) - select_column = true; - - if (select_column) { - int k; - for (k = 0; k < nz; k++) { - int global_index = ecl_grid_get_global_index3( - region->parent_grid, i, j, k); - region->active_mask[global_index] = select; - } - } - } - } - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_in_cylinder(ecl_region_type *region, double x0, - double y0, double R) { - ecl_region_cylinder_select__(region, x0, y0, R, 1, 0, true, true); -} - -void ecl_region_deselect_in_cylinder(ecl_region_type *region, double x0, - double y0, double R) { - ecl_region_cylinder_select__(region, x0, y0, R, 1, 0, true, false); -} - -void ecl_region_select_in_zcylinder(ecl_region_type *region, double x0, - double y0, double R, double z1, double z2) { - ecl_region_cylinder_select__(region, x0, y0, R, util_double_min(z1, z2), - util_double_max(z1, z2), true, true); -} - -void ecl_region_deselect_in_zcylinder(ecl_region_type *region, double x0, - double y0, double R, double z1, - double z2) { - ecl_region_cylinder_select__(region, x0, y0, R, util_double_min(z1, z2), - util_double_max(z1, z2), true, false); -} - -/** - Select or deselect points based on their distance to the plane - specified by normal vector @n and point @p. -*/ - -static void ecl_region_plane_select__(ecl_region_type *region, - const double n[3], const double p[3], - bool select_above, bool select) { - const double a = n[0]; - const double b = n[1]; - const double c = -n[2]; - const double d = -a * p[0] - b * p[1] - c * p[2]; - /** - Plane: ax + by + cz + d = 0 - */ - { - int global_index; - for (global_index = 0; global_index < region->grid_vol; - global_index++) { - double x, y, z; - double D; - ecl_grid_get_xyz1(region->parent_grid, global_index, &x, &y, &z); - D = a * x + b * y + c * z + d; - if ((D >= 0) && (select_above)) - region->active_mask[global_index] = select; - else if ((D < 0) && (!select_above)) - region->active_mask[global_index] = select; - } - } - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_above_plane(ecl_region_type *region, const double n[3], - const double p[3]) { - ecl_region_plane_select__(region, n, p, true, true); -} - -void ecl_region_select_below_plane(ecl_region_type *region, const double n[3], - const double p[3]) { - ecl_region_plane_select__(region, n, p, false, true); -} - -void ecl_region_deselect_above_plane(ecl_region_type *region, const double n[3], - const double p[3]) { - ecl_region_plane_select__(region, n, p, true, false); -} - -void ecl_region_deselect_below_plane(ecl_region_type *region, const double n[3], - const double p[3]) { - ecl_region_plane_select__(region, n, p, false, false); -} - -/** - When it comes to depth the polygon select function works as - follows: - - 1. The defining polygon is layed out at the top of the reservoir. - - 2. The set {(i,j,0)} of cells in the top layer inside the polygon - is selected by checking the polygon perimeter. - - 3. The set {(i,j,0)} is extended to all k vertically. This implies that: - - * If the pillars of the grid are not vertical the selection - polygon will effectively qbe translated as a function of - depth. - - * If the pillars are not parallell the selection polygon will - effectively change in size. -*/ - -static void ecl_region_polygon_select__(ecl_region_type *region, - const geo_polygon_type *polygon, - bool select_inside, bool select) { - - const int define_k = 0; // The k-level where the polygon is checked. - const int k1 = 0; // Selection range in k - const int k2 = region->grid_nz; - - { - int i, j; - for (i = 0; i < region->grid_nx; i++) { - for (j = 0; j < region->grid_ny; j++) { - double x, y, z; - bool inside; - int global_index = ecl_grid_get_global_index3( - region->parent_grid, i, j, define_k); - - ecl_grid_get_xyz1(region->parent_grid, global_index, &x, &y, - &z); - inside = geo_polygon_contains_point(polygon, x, y); - - if (select_inside == inside) { - int k; - for (k = k1; k < k2; k++) { - global_index = ecl_grid_get_global_index3( - region->parent_grid, i, j, k); - region->active_mask[global_index] = select; - } - } - } - } - } -} - -void ecl_region_select_inside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon) { - ecl_region_polygon_select__(region, polygon, true, true); -} - -void ecl_region_deselect_inside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon) { - ecl_region_polygon_select__(region, polygon, true, false); -} - -void ecl_region_select_outside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon) { - ecl_region_polygon_select__(region, polygon, false, true); -} - -void ecl_region_deselect_outside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon) { - ecl_region_polygon_select__(region, polygon, false, false); -} - -/** - This function will select a cell based on active_index. -*/ - -static void ecl_region_select_active_index__(ecl_region_type *region, - int active_index, bool select) { - if ((active_index >= 0) && (active_index < region->grid_active)) { - int global_index = - ecl_grid_get_global_index1A(region->parent_grid, active_index); - region->active_mask[global_index] = select; - } else - util_abort("%s: active_index:%d invalid - legal interval: [0,%d) \n", - __func__, active_index, region->grid_vol); - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_active_index(ecl_region_type *region, int active_index) { - ecl_region_select_active_index__(region, active_index, true); -} - -void ecl_region_deselect_active_index(ecl_region_type *region, - int active_index) { - ecl_region_select_active_index__(region, active_index, false); -} - -static void ecl_region_select_from_layer__(ecl_region_type *region, - const layer_type *layer, int k, - int layer_value, bool select) { - int_vector_type *i_list = int_vector_alloc(0, 0); - int_vector_type *j_list = int_vector_alloc(0, 0); - - layer_cells_equal(layer, layer_value, i_list, j_list); - { - const int *i = int_vector_get_ptr(i_list); - const int *j = int_vector_get_ptr(j_list); - - int index; - for (index = 0; index < int_vector_size(i_list); index++) { - int global_index = ecl_grid_get_global_index3( - region->parent_grid, i[index], j[index], k); - region->active_mask[global_index] = select; - } - } - if (int_vector_size(i_list) > 0) - ecl_region_invalidate_index_list(region); - - int_vector_free(i_list); - int_vector_free(j_list); -} - -void ecl_region_select_from_layer(ecl_region_type *region, - const layer_type *layer, int k, - int layer_value) { - ecl_region_select_from_layer__(region, layer, k, layer_value, true); -} - -void ecl_region_deselect_from_layer(ecl_region_type *region, - const layer_type *layer, int k, - int layer_value) { - ecl_region_select_from_layer__(region, layer, k, layer_value, false); -} - -static void ecl_region_select_all__(ecl_region_type *region, bool select) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) - region->active_mask[global_index] = select; - ecl_region_invalidate_index_list(region); -} - -void ecl_region_select_all(ecl_region_type *region) { - ecl_region_select_all__(region, true); -} - -void ecl_region_deselect_all(ecl_region_type *region) { - ecl_region_select_all__(region, false); -} - -void ecl_region_invert_selection(ecl_region_type *region) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) - region->active_mask[global_index] = !region->active_mask[global_index]; - ecl_region_invalidate_index_list(region); -} - -/** - - Returns true if the region has selected grid cell ijk. - - ijk have zero offset. -*/ - -bool ecl_region_contains_ijk(const ecl_region_type *ecl_region, int i, int j, - int k) { - int global_index = - ecl_grid_get_global_index3(ecl_region->parent_grid, i, j, k); - return ecl_region->active_mask[global_index]; -} - -bool ecl_region_contains_global(const ecl_region_type *ecl_region, - int global_index) { - return ecl_region->active_mask[global_index]; -} - -bool ecl_region_contains_active(const ecl_region_type *ecl_region, - int active_index) { - int global_index = - ecl_grid_get_global_index1A(ecl_region->parent_grid, active_index); - return ecl_region->active_mask[global_index]; -} - -/** - Will update the selection in @region to ONLY contain the elements - which are also present in @new_region. Will FAIL hard if the two - regions do not share the same grid instance (checked by pointer - equality). - - A &= B -*/ - -void ecl_region_intersection(ecl_region_type *region, - const ecl_region_type *new_region) { - if (region->parent_grid == new_region->parent_grid) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) - region->active_mask[global_index] = - (region->active_mask[global_index] && - new_region->active_mask[global_index]); - - ecl_region_invalidate_index_list(region); - } else - util_abort("%s: The two regions do not share grid - aborting \n", - __func__); -} - -/** - Will update the selection in @region to contain all the elements - which are selected in either @region or @new_region. - - A |= B -*/ -void ecl_region_union(ecl_region_type *region, - const ecl_region_type *new_region) { - if (region->parent_grid == new_region->parent_grid) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) - region->active_mask[global_index] = - (region->active_mask[global_index] || - new_region->active_mask[global_index]); - - ecl_region_invalidate_index_list(region); - } else - util_abort("%s: The two regions do not share grid - aborting \n", - __func__); -} - -/** - Will update the selection in @region to deselect the elements which - are also in new_region: - - A &= !B -*/ -void ecl_region_subtract(ecl_region_type *region, - const ecl_region_type *new_region) { - if (region->parent_grid == new_region->parent_grid) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) - region->active_mask[global_index] &= - !new_region->active_mask[global_index]; - - ecl_region_invalidate_index_list(region); - } else - util_abort("%s: The two regions do not share grid - aborting \n", - __func__); -} - -/** - Will update the selection in @region to seselect the elements which - are either in region or new_region: - - A ^= B -*/ -void ecl_region_xor(ecl_region_type *region, - const ecl_region_type *new_region) { - if (region->parent_grid == new_region->parent_grid) { - int global_index; - for (global_index = 0; global_index < region->grid_vol; global_index++) - region->active_mask[global_index] ^= - !new_region->active_mask[global_index]; - - ecl_region_invalidate_index_list(region); - } else - util_abort("%s: The two regions do not share grid - aborting \n", - __func__); -} - -const int_vector_type *ecl_region_get_kw_index_list(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, - bool force_active) { - const int_vector_type *index_set = NULL; - int kw_size = ecl_kw_get_size(ecl_kw); - int grid_active = ecl_grid_get_active_size(ecl_region->parent_grid); - int grid_global = ecl_grid_get_global_size(ecl_region->parent_grid); - - if (kw_size == grid_active) - index_set = ecl_region_get_active_list(ecl_region); - else if (kw_size == grid_global) { - if (force_active) - index_set = ecl_region_get_global_active_list(ecl_region); - else - index_set = ecl_region_get_global_list(ecl_region); - } else - util_abort( - "%s: size mismatch: grid_active:%d grid_global:%d kw_size:%d \n", - __func__, grid_active, grid_global, kw_size); - - return index_set; -} - -void ecl_region_set_kw_int(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - int value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_set_indexed_int(ecl_kw, index_set, value); -} - -void ecl_region_set_kw_float(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - float value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_set_indexed_float(ecl_kw, index_set, value); -} - -void ecl_region_set_kw_double(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - double value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_set_indexed_double(ecl_kw, index_set, value); -} - -void ecl_region_shift_kw_int(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - int value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_shift_indexed_int(ecl_kw, index_set, value); -} - -void ecl_region_shift_kw_float(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - float value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_shift_indexed_float(ecl_kw, index_set, value); -} - -void ecl_region_shift_kw_double(ecl_region_type *ecl_region, - ecl_kw_type *ecl_kw, double value, - bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_shift_indexed_double(ecl_kw, index_set, value); -} - -void ecl_region_scale_kw_int(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - int value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_scale_indexed_int(ecl_kw, index_set, value); -} - -void ecl_region_scale_kw_float(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - float value, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_scale_indexed_float(ecl_kw, index_set, value); -} - -void ecl_region_scale_kw_double(ecl_region_type *ecl_region, - ecl_kw_type *ecl_kw, double value, - bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_scale_indexed_double(ecl_kw, index_set, value); -} - -void ecl_region_kw_iadd(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *delta_kw, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_inplace_add_indexed(ecl_kw, index_set, delta_kw); -} - -void ecl_region_kw_idiv(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *div_kw, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_inplace_div_indexed(ecl_kw, index_set, div_kw); -} - -void ecl_region_kw_imul(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *mul_kw, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_inplace_mul_indexed(ecl_kw, index_set, mul_kw); -} - -void ecl_region_kw_isub(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *delta_kw, bool force_active) { - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_inplace_sub_indexed(ecl_kw, index_set, delta_kw); -} - -void ecl_region_kw_copy(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *src_kw, bool force_active) { - const int_vector_type *target_index = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_copy_indexed(ecl_kw, target_index, src_kw); -} - -void ecl_region_set_name(ecl_region_type *region, const char *name) { - region->name = util_realloc_string_copy(region->name, name); -} - -const char *ecl_region_get_name(const ecl_region_type *region) { - return region->name; -} - -bool ecl_region_equal(const ecl_region_type *region1, - const ecl_region_type *region2) { - if (region1->parent_grid == - region2 - ->parent_grid) { // Must be exactly the same grid instance to compare as equal. - if (memcmp(region1->active_mask, region2->active_mask, - region1->grid_vol * sizeof *region1->active_mask) == 0) - return true; - else - return false; - } else - return false; -} - -int ecl_region_sum_kw_int(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active) { - int sum; - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_element_sum_indexed(ecl_kw, index_set, &sum); - return sum; -} - -float ecl_region_sum_kw_float(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active) { - float sum; - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_element_sum_indexed(ecl_kw, index_set, &sum); - return sum; -} - -double ecl_region_sum_kw_double(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active) { - double sum; - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_element_sum_indexed(ecl_kw, index_set, &sum); - return sum; -} - -int ecl_region_sum_kw_bool(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active) { - int sum; - const int_vector_type *index_set = - ecl_region_get_kw_index_list(ecl_region, ecl_kw, force_active); - ecl_kw_element_sum_indexed(ecl_kw, index_set, &sum); - return sum; -} diff --git a/lib/ecl/ecl_rft_node.cpp b/lib/ecl/ecl_rft_node.cpp deleted file mode 100644 index 06b391bec6..0000000000 --- a/lib/ecl/ecl_rft_node.cpp +++ /dev/null @@ -1,615 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -/** - The RFT's from several wells, and possibly also several timesteps - are lumped togeheter in one .RFT file. The ecl_rft_node - implemented in this file contains the information for one - well/report step. -*/ - -/* - If the type is RFT, PLT or SEGMENT depends on the options used when - the .RFT file is created. RFT and PLT are quite similar, SEGMENT is - not really supported. -*/ - -#define ECL_RFT_NODE_ID 887195 -struct ecl_rft_node_struct { - UTIL_TYPE_ID_DECLARATION; - std::string well_name; - - ecl_rft_enum data_type; /* What type of data: RFT|PLT|SEGMENT */ - time_t recording_date; /* When was the RFT recorded - date.*/ - double days; /* When was the RFT recorded - days after simulaton start. */ - bool MSW; - - std::vector cells; -}; - -/* - The implementation of cell types based on _either_ RFT data or PLT - data is based on a misunderstanding and is currently WRONG. One - section in an RFT file can contain RFT data, PLT data and SEGMENT - data. The @data_type string should therefore not be interpreted as a - type string, but rather as a "bit mask": - - - "R" => Section contains only RFT data. - "P" => Section contains only PLT data. - "RP" => Section contains *BOTH* RFT data and PLT data. -*/ - -/** - Will return NULL if the data_type_string is equal to "SEGMENT" - - that is not (yet) supported. -*/ -static ecl_rft_enum -translate_from_sting_to_ecl_rft_enum(const char *data_type_string) { - ecl_rft_enum data_type = SEGMENT; - /* According to the ECLIPSE documentaton. */ - if (strchr(data_type_string, 'P') != NULL) - data_type = PLT; - else if (strchr(data_type_string, 'R') != NULL) - data_type = RFT; - else if (strchr(data_type_string, 'S') != NULL) - data_type = SEGMENT; - else - util_abort( - "%s: Could not determine type of RFT/PLT/SEGMENT data - aborting\n", - __func__); - - return data_type; -} - -ecl_rft_node_type *ecl_rft_node_alloc_new(const char *well_name, - const char *data_type_string, - const time_t recording_date, - const double days) { - ecl_rft_enum data_type = - translate_from_sting_to_ecl_rft_enum(data_type_string); - ecl_rft_node_type *rft_node = new ecl_rft_node_type(); - - UTIL_TYPE_ID_INIT(rft_node, ECL_RFT_NODE_ID); - rft_node->well_name = std::string(well_name); - rft_node->recording_date = recording_date; - rft_node->days = days; - rft_node->data_type = data_type; - - return rft_node; -} - -static ecl_rft_node_type * -ecl_rft_node_alloc_empty(const char *data_type_string) { - ecl_rft_enum data_type = - translate_from_sting_to_ecl_rft_enum(data_type_string); - - /* Can return NULL */ - if (data_type == SEGMENT) { - fprintf( - stderr, - "%s: sorry SEGMENT PLT/RFT is not supported - file a complaint. \n", - __func__); - return NULL; - } - - { - ecl_rft_node_type *rft_node = new ecl_rft_node_type(); - - UTIL_TYPE_ID_INIT(rft_node, ECL_RFT_NODE_ID); - rft_node->data_type = data_type; - - return rft_node; - } -} - -UTIL_SAFE_CAST_FUNCTION(ecl_rft_node, ECL_RFT_NODE_ID); -UTIL_IS_INSTANCE_FUNCTION(ecl_rft_node, ECL_RFT_NODE_ID); - -void ecl_rft_node_append_cell(ecl_rft_node_type *rft_node, - ecl_rft_cell_type *cell) { - if (rft_node->MSW) { - auto pos_iter = - std::upper_bound(rft_node->cells.begin(), rft_node->cells.end(), - cell, ecl_rft_cell_lt); - rft_node->cells.insert(pos_iter, cell); - } else - rft_node->cells.push_back(cell); -} - -static ecl_kw_type * -ecl_rft_node_get_pressure_kw(ecl_rft_node_type *rft_node, - const ecl_file_view_type *rft) { - if (rft_node->data_type == RFT) - return ecl_file_view_iget_named_kw(rft, PRESSURE_KW, 0); - else { - ecl_kw_type *conpres_kw = - ecl_file_view_iget_named_kw(rft, CONPRES_KW, 0); - if (ecl_kw_element_sum_float(conpres_kw) > 0.0) - return conpres_kw; - else if (ecl_file_view_has_kw(rft, PRESSURE_KW)) - return ecl_file_view_iget_named_kw(rft, PRESSURE_KW, 0); - else { - fprintf(stderr, - "WARNING: %s returned a CONPRES_KW with all values at " - "zero. PRESSURE_KW not found.\n", - __func__); - return conpres_kw; - } - } -} - -static void ecl_rft_node_init_RFT_cells(ecl_rft_node_type *rft_node, - const ecl_file_view_type *rft_view) { - const ecl_kw_type *conipos = - ecl_file_view_iget_named_kw(rft_view, CONIPOS_KW, 0); - const ecl_kw_type *conjpos = - ecl_file_view_iget_named_kw(rft_view, CONJPOS_KW, 0); - const ecl_kw_type *conkpos = - ecl_file_view_iget_named_kw(rft_view, CONKPOS_KW, 0); - const ecl_kw_type *depth_kw = - ecl_file_view_iget_named_kw(rft_view, DEPTH_KW, 0); - const ecl_kw_type *swat_kw = - ecl_file_view_iget_named_kw(rft_view, SWAT_KW, 0); - const ecl_kw_type *sgas_kw = - ecl_file_view_iget_named_kw(rft_view, SGAS_KW, 0); - const ecl_kw_type *pressure_kw = - ecl_rft_node_get_pressure_kw(rft_node, rft_view); - - const float *SW = ecl_kw_get_float_ptr(swat_kw); - const float *SG = ecl_kw_get_float_ptr(sgas_kw); - const float *P = ecl_kw_get_float_ptr(pressure_kw); - const float *depth = ecl_kw_get_float_ptr(depth_kw); - const int *i = ecl_kw_get_int_ptr(conipos); - const int *j = ecl_kw_get_int_ptr(conjpos); - const int *k = ecl_kw_get_int_ptr(conkpos); - - { - int c; - for (c = 0; c < ecl_kw_get_size(conipos); c++) { - /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ - ecl_rft_cell_type *cell = ecl_rft_cell_alloc_RFT( - i[c] - 1, j[c] - 1, k[c] - 1, depth[c], P[c], SW[c], SG[c]); - ecl_rft_node_append_cell(rft_node, cell); - } - } -} - -static void ecl_rft_node_init_PLT_cells(ecl_rft_node_type *rft_node, - const ecl_file_view_type *rft_view) { - /* For PLT there is quite a lot of extra information which is not yet internalized. */ - const ecl_kw_type *conipos = - ecl_file_view_iget_named_kw(rft_view, CONIPOS_KW, 0); - const ecl_kw_type *conjpos = - ecl_file_view_iget_named_kw(rft_view, CONJPOS_KW, 0); - const ecl_kw_type *conkpos = - ecl_file_view_iget_named_kw(rft_view, CONKPOS_KW, 0); - - const int *i = ecl_kw_get_int_ptr(conipos); - const int *j = ecl_kw_get_int_ptr(conjpos); - const int *k = ecl_kw_get_int_ptr(conkpos); - - const float *WR = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONWRAT_KW, 0)); - const float *GR = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONGRAT_KW, 0)); - const float *OR = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONORAT_KW, 0)); - const float *P = - ecl_kw_get_float_ptr(ecl_rft_node_get_pressure_kw(rft_node, rft_view)); - const float *depth = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONDEPTH_KW, 0)); - const float *flowrate = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONVTUB_KW, 0)); - const float *oil_flowrate = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONOTUB_KW, 0)); - const float *gas_flowrate = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONGTUB_KW, 0)); - const float *water_flowrate = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONWTUB_KW, 0)); - const float *connection_start = NULL; - const float *connection_end = NULL; - - /* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */ - if (ecl_file_view_has_kw(rft_view, CONLENST_KW)) - connection_start = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONLENST_KW, 0)); - - if (ecl_file_view_has_kw(rft_view, CONLENEN_KW)) - connection_end = ecl_kw_get_float_ptr( - ecl_file_view_iget_named_kw(rft_view, CONLENEN_KW, 0)); - - { - int c; - for (c = 0; c < ecl_kw_get_size(conipos); c++) { - ecl_rft_cell_type *cell; - double cs = 0; - double ce = 0; - - if (connection_start) - cs = connection_start[c]; - - if (connection_end) - ce = connection_end[c]; - - /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ - cell = ecl_rft_cell_alloc_PLT(i[c] - 1, j[c] - 1, k[c] - 1, - depth[c], P[c], OR[c], GR[c], WR[c], - cs, ce, flowrate[c], oil_flowrate[c], - gas_flowrate[c], water_flowrate[c]); - ecl_rft_node_append_cell(rft_node, cell); - } - } -} - -static void ecl_rft_node_init_cells(ecl_rft_node_type *rft_node, - const ecl_file_view_type *rft_view) { - - if (rft_node->data_type == RFT) - ecl_rft_node_init_RFT_cells(rft_node, rft_view); - else if (rft_node->data_type == PLT) - ecl_rft_node_init_PLT_cells(rft_node, rft_view); -} - -ecl_rft_node_type *ecl_rft_node_alloc(const ecl_file_view_type *rft_view) { - ecl_kw_type *welletc = ecl_file_view_iget_named_kw(rft_view, WELLETC_KW, 0); - ecl_rft_node_type *rft_node = ecl_rft_node_alloc_empty( - (const char *)ecl_kw_iget_ptr(welletc, WELLETC_TYPE_INDEX)); - - if (rft_node != NULL) { - ecl_kw_type *date_kw = - ecl_file_view_iget_named_kw(rft_view, DATE_KW, 0); - { - char *tmp = util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(welletc, WELLETC_NAME_INDEX)); - rft_node->well_name = std::string(tmp); - free(tmp); - } - /* Time information. */ - { - int *time = ecl_kw_get_int_ptr(date_kw); - rft_node->recording_date = - ecl_util_make_date(time[DATE_DAY_INDEX], time[DATE_MONTH_INDEX], - time[DATE_YEAR_INDEX]); - } - rft_node->days = ecl_kw_iget_float( - ecl_file_view_iget_named_kw(rft_view, TIME_KW, 0), 0); - if (ecl_file_view_has_kw(rft_view, CONLENST_KW)) - rft_node->MSW = true; - else - rft_node->MSW = false; - - ecl_rft_node_init_cells(rft_node, rft_view); - } - return rft_node; -} - -const char *ecl_rft_node_get_well_name(const ecl_rft_node_type *rft_node) { - return rft_node->well_name.c_str(); -} - -void ecl_rft_node_free(ecl_rft_node_type *rft_node) { - for (auto cell_ptr : rft_node->cells) - ecl_rft_cell_free(cell_ptr); - - delete rft_node; -} - -void ecl_rft_node_free__(void *void_node) { - ecl_rft_node_free(ecl_rft_node_safe_cast(void_node)); -} - -int ecl_rft_node_get_size(const ecl_rft_node_type *rft_node) { - return rft_node->cells.size(); -} -time_t ecl_rft_node_get_date(const ecl_rft_node_type *rft_node) { - return rft_node->recording_date; -} -ecl_rft_enum ecl_rft_node_get_type(const ecl_rft_node_type *rft_node) { - return rft_node->data_type; -} - -const ecl_rft_cell_type * -ecl_rft_node_iget_cell(const ecl_rft_node_type *rft_node, int index) { - return rft_node->cells[index]; -} - -const ecl_rft_cell_type * -ecl_rft_node_iget_cell_sorted(ecl_rft_node_type *rft_node, int index) { - return rft_node->cells[index]; -} - -double ecl_rft_node_iget_depth(const ecl_rft_node_type *rft_node, int index) { - const ecl_rft_cell_type *cell = ecl_rft_node_iget_cell(rft_node, index); - return ecl_rft_cell_get_depth(cell); -} - -double ecl_rft_node_iget_pressure(const ecl_rft_node_type *rft_node, - int index) { - const ecl_rft_cell_type *cell = ecl_rft_node_iget_cell(rft_node, index); - return ecl_rft_cell_get_pressure(cell); -} - -void ecl_rft_node_iget_ijk(const ecl_rft_node_type *rft_node, int index, int *i, - int *j, int *k) { - const ecl_rft_cell_type *cell = ecl_rft_node_iget_cell(rft_node, index); - - ecl_rft_cell_get_ijk(cell, i, j, k); -} - -const ecl_rft_cell_type * -ecl_rft_node_lookup_ijk(const ecl_rft_node_type *rft_node, int i, int j, - int k) { - int index = 0; - int size = ecl_rft_node_get_size(rft_node); - while (true) { - const ecl_rft_cell_type *cell = ecl_rft_node_iget_cell(rft_node, index); - - if (ecl_rft_cell_ijk_equal(cell, i, j, k)) - return cell; - - index++; - if (index == size) /* Could not find it. */ - return NULL; - } -} - -static void assert_type_and_index(const ecl_rft_node_type *rft_node, - ecl_rft_enum target_type, int index) { - if (rft_node->data_type != target_type) - util_abort("%s: wrong type \n", __func__); - - if ((index < 0) || (index >= static_cast(rft_node->cells.size()))) - util_abort("%s: invalid index:%d \n", __func__, index); -} - -double ecl_rft_node_iget_sgas(const ecl_rft_node_type *rft_node, int index) { - assert_type_and_index(rft_node, RFT, index); - { - const ecl_rft_cell_type *cell = ecl_rft_node_iget_cell(rft_node, index); - return ecl_rft_cell_get_sgas(cell); - } -} - -double ecl_rft_node_iget_swat(const ecl_rft_node_type *rft_node, int index) { - assert_type_and_index(rft_node, RFT, index); - { - const ecl_rft_cell_type *cell = rft_node->cells[index]; - return ecl_rft_cell_get_swat(cell); - } -} - -double ecl_rft_node_get_days(const ecl_rft_node_type *rft_node) { - return rft_node->days; -} - -double ecl_rft_node_iget_soil(const ecl_rft_node_type *rft_node, int index) { - assert_type_and_index(rft_node, RFT, index); - { - const ecl_rft_cell_type *cell = rft_node->cells[index]; - return ecl_rft_cell_get_soil(cell); - } -} - -double ecl_rft_node_iget_orat(const ecl_rft_node_type *rft_node, int index) { - assert_type_and_index(rft_node, PLT, index); - { - const ecl_rft_cell_type *cell = rft_node->cells[index]; - return ecl_rft_cell_get_orat(cell); - } -} - -double ecl_rft_node_iget_wrat(const ecl_rft_node_type *rft_node, int index) { - assert_type_and_index(rft_node, PLT, index); - { - const ecl_rft_cell_type *cell = rft_node->cells[index]; - return ecl_rft_cell_get_wrat(cell); - } -} - -double ecl_rft_node_iget_grat(const ecl_rft_node_type *rft_node, int index) { - assert_type_and_index(rft_node, PLT, index); - { - const ecl_rft_cell_type *cell = rft_node->cells[index]; - return ecl_rft_cell_get_grat(cell); - } -} - -bool ecl_rft_node_is_MSW(const ecl_rft_node_type *rft_node) { - return rft_node->MSW; -} - -bool ecl_rft_node_is_PLT(const ecl_rft_node_type *rft_node) { - if (rft_node->data_type == PLT) - return true; - else - return false; -} - -bool ecl_rft_node_is_SEGMENT(const ecl_rft_node_type *rft_node) { - if (rft_node->data_type == SEGMENT) - return true; - else - return false; -} - -bool ecl_rft_node_is_RFT(const ecl_rft_node_type *rft_node) { - if (rft_node->data_type == RFT) - return true; - else - return false; -} - -static void ecl_rft_node_fill_welletc(ecl_kw_type *welletc, - ert_ecl_unit_enum unit_set) { - if (unit_set == ECL_METRIC_UNITS) { - ecl_kw_iset_string8(welletc, 0, " DAYS"); - ecl_kw_iset_string8(welletc, 2, ""); - ecl_kw_iset_string8(welletc, 3, " METRES"); - ecl_kw_iset_string8(welletc, 4, " BARSA"); - ecl_kw_iset_string8(welletc, 6, "STANDARD"); - ecl_kw_iset_string8(welletc, 7, " SM3/DAY"); - ecl_kw_iset_string8(welletc, 8, " SM3/DAY"); - ecl_kw_iset_string8(welletc, 9, " RM3/DAY"); - ecl_kw_iset_string8(welletc, 10, " M/SEC"); - ecl_kw_iset_string8(welletc, 11, ""); - ecl_kw_iset_string8(welletc, 12, " CP"); - ecl_kw_iset_string8(welletc, 13, " KG/SM3"); - ecl_kw_iset_string8(welletc, 14, " KG/DAY"); - ecl_kw_iset_string8(welletc, 15, " KG/KG"); - } else if (unit_set == ECL_FIELD_UNITS) { - ecl_kw_iset_string8(welletc, 0, " DAYS"); - ecl_kw_iset_string8(welletc, 2, ""); - ecl_kw_iset_string8(welletc, 3, " FEET"); - ecl_kw_iset_string8(welletc, 4, " PISA"); - ecl_kw_iset_string8(welletc, 6, "STANDARD"); - ecl_kw_iset_string8(welletc, 7, " STB/DAY"); - ecl_kw_iset_string8(welletc, 8, " MSCF/DAY"); - ecl_kw_iset_string8(welletc, 9, " RB/DAY"); - ecl_kw_iset_string8(welletc, 10, " FT/SEC"); - ecl_kw_iset_string8(welletc, 11, ""); - ecl_kw_iset_string8(welletc, 12, " CP"); - ecl_kw_iset_string8(welletc, 13, " LB/STB"); - ecl_kw_iset_string8(welletc, 14, " LB/DAY"); - ecl_kw_iset_string8(welletc, 15, " LB/LB"); - - } else if (unit_set == ECL_LAB_UNITS) { - ecl_kw_iset_string8(welletc, 0, " HR"); - ecl_kw_iset_string8(welletc, 2, ""); - ecl_kw_iset_string8(welletc, 3, " CM"); - ecl_kw_iset_string8(welletc, 4, " ATMA"); - ecl_kw_iset_string8(welletc, 6, "STANDARD"); - ecl_kw_iset_string8(welletc, 7, " SCC/HR"); - ecl_kw_iset_string8(welletc, 8, " SCC/HR"); - ecl_kw_iset_string8(welletc, 9, " RCC/SCC"); - ecl_kw_iset_string8(welletc, 10, " CM/SEC"); - ecl_kw_iset_string8(welletc, 11, ""); - ecl_kw_iset_string8(welletc, 12, " CP"); - ecl_kw_iset_string8(welletc, 13, " GM/SCC"); - ecl_kw_iset_string8(welletc, 14, " GH/HR"); - ecl_kw_iset_string8(welletc, 15, " GM/GM"); - } -} - -void ecl_rft_node_fwrite(const ecl_rft_node_type *rft_node, fortio_type *fortio, - ert_ecl_unit_enum unit_set) { - ecl_rft_enum type = ecl_rft_node_get_type(rft_node); - if (type != RFT) - util_abort( - "%s: sorry - only writing of simple RFT is currently implemented", - __func__); - - { - ecl_kw_type *time = ecl_kw_alloc(TIME_KW, 1, ECL_FLOAT); - ecl_kw_iset_float(time, 0, ecl_rft_node_get_days(rft_node)); - ecl_kw_fwrite(time, fortio); - ecl_kw_free(time); - } - - { - ecl_kw_type *datevalue = ecl_kw_alloc(DATE_KW, 3, ECL_INT); - time_t date = ecl_rft_node_get_date(rft_node); - int day; - int month; - int year; - ecl_util_set_date_values(date, &day, &month, &year); - ecl_kw_iset_int(datevalue, 0, day); - ecl_kw_iset_int(datevalue, 1, month); - ecl_kw_iset_int(datevalue, 2, year); - ecl_kw_fwrite(datevalue, fortio); - ecl_kw_free(datevalue); - } - - { - ecl_kw_type *welletc = ecl_kw_alloc(WELLETC_KW, 16, ECL_CHAR); - ecl_rft_enum type = ecl_rft_node_get_type(rft_node); - - ecl_kw_iset_string8(welletc, 1, ecl_rft_node_get_well_name(rft_node)); - - if (type == PLT) { - ecl_kw_iset_string8(welletc, 5, "P"); - } else if (type == RFT) { - ecl_kw_iset_string8(welletc, 5, "R"); - } else if (type == SEGMENT) { - ecl_kw_iset_string8(welletc, 5, "S"); - } - ecl_rft_node_fill_welletc(welletc, unit_set); - ecl_kw_fwrite(welletc, fortio); - ecl_kw_free(welletc); - } - - { - int size_cells = ecl_rft_node_get_size(rft_node); - ecl_kw_type *conipos = ecl_kw_alloc(CONIPOS_KW, size_cells, ECL_INT); - ecl_kw_type *conjpos = ecl_kw_alloc(CONJPOS_KW, size_cells, ECL_INT); - ecl_kw_type *conkpos = ecl_kw_alloc(CONKPOS_KW, size_cells, ECL_INT); - ecl_kw_type *hostgrid = ecl_kw_alloc(HOSTGRID_KW, size_cells, ECL_CHAR); - ecl_kw_type *depth = ecl_kw_alloc(DEPTH_KW, size_cells, ECL_FLOAT); - ecl_kw_type *pressure = - ecl_kw_alloc(PRESSURE_KW, size_cells, ECL_FLOAT); - ecl_kw_type *swat = ecl_kw_alloc(SWAT_KW, size_cells, ECL_FLOAT); - ecl_kw_type *sgas = ecl_kw_alloc(SGAS_KW, size_cells, ECL_FLOAT); - - for (int i = 0; i < size_cells; i++) { - const ecl_rft_cell_type *cell = rft_node->cells[i]; - ecl_kw_iset_int(conipos, i, ecl_rft_cell_get_i(cell) + 1); - ecl_kw_iset_int(conjpos, i, ecl_rft_cell_get_j(cell) + 1); - ecl_kw_iset_int(conkpos, i, ecl_rft_cell_get_k(cell) + 1); - ecl_kw_iset_float(depth, i, ecl_rft_cell_get_depth(cell)); - ecl_kw_iset_float(pressure, i, ecl_rft_cell_get_pressure(cell)); - ecl_kw_iset_float(swat, i, ecl_rft_cell_get_swat(cell)); - ecl_kw_iset_float(sgas, i, ecl_rft_cell_get_sgas(cell)); - } - ecl_kw_fwrite(conipos, fortio); - ecl_kw_fwrite(conjpos, fortio); - ecl_kw_fwrite(conkpos, fortio); - ecl_kw_fwrite(hostgrid, fortio); - ecl_kw_fwrite(depth, fortio); - ecl_kw_fwrite(pressure, fortio); - ecl_kw_fwrite(swat, fortio); - ecl_kw_fwrite(sgas, fortio); - - ecl_kw_free(conipos); - ecl_kw_free(conjpos); - ecl_kw_free(conkpos); - ecl_kw_free(hostgrid); - ecl_kw_free(depth); - ecl_kw_free(pressure); - ecl_kw_free(swat); - ecl_kw_free(sgas); - } -} - -int ecl_rft_node_cmp(const ecl_rft_node_type *n1, const ecl_rft_node_type *n2) { - time_t val1 = ecl_rft_node_get_date(n1); - time_t val2 = ecl_rft_node_get_date(n2); - - if (val1 < val2) - return -1; - else if (val1 == val2) - return 0; - else - return 1; -} - -bool ecl_rft_node_lt(const ecl_rft_node_type *n1, const ecl_rft_node_type *n2) { - return (ecl_rft_node_cmp(n1, n2) < 0); -} diff --git a/lib/ecl/ecl_rst_file.cpp b/lib/ecl/ecl_rst_file.cpp deleted file mode 100644 index cdee3c9290..0000000000 --- a/lib/ecl/ecl_rst_file.cpp +++ /dev/null @@ -1,278 +0,0 @@ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct ecl_rst_file_struct { - fortio_type *fortio; - bool unified; - bool fmt_file; -}; - -static ecl_rst_file_type *ecl_rst_file_alloc(const char *filename) { - bool unified = ecl_util_unified_file(filename); - bool fmt_file; - ecl_rst_file_type *rst_file = - (ecl_rst_file_type *)util_malloc(sizeof *rst_file); - - if (ecl_util_fmt_file(filename, &fmt_file)) { - rst_file->unified = unified; - rst_file->fmt_file = fmt_file; - return rst_file; - } else { - util_abort("%s: invalid restart filename:%s - could not determine " - "formatted/unformatted status\n", - __func__, filename); - return NULL; - } -} - -/** - Observe that all the open() functions expect that filename conforms - to the standard ECLIPSE conventions, i.e. with extension .FUNRST / - .UNRST / .Xnnnn / .Fnnnn. -*/ - -ecl_rst_file_type *ecl_rst_file_open_read(const char *filename) { - ecl_rst_file_type *rst_file = ecl_rst_file_alloc(filename); - rst_file->fortio = - fortio_open_reader(filename, rst_file->fmt_file, ECL_ENDIAN_FLIP); - return rst_file; -} - -/* - This function will scan through the file and look for seqnum - headers, and position the file pointer in the right location to - start writing data for the report step given by @report_step. The - file is truncated, so that the filepointer will be at the (new) EOF - when returning. -*/ - -ecl_rst_file_type *ecl_rst_file_open_write_seek(const char *filename, - int report_step) { - ecl_rst_file_type *rst_file = ecl_rst_file_alloc(filename); - offset_type target_pos = 0; - bool seqnum_found = false; - rst_file->fortio = - fortio_open_readwrite(filename, rst_file->fmt_file, ECL_ENDIAN_FLIP); - /* - If the file does not exist at all the fortio_open_readwrite() - will fail, we just try again - opening a new file in normal write - mode, and then immediately returning. - */ - if (!rst_file->fortio) { - rst_file->fortio = - fortio_open_writer(filename, rst_file->fmt_file, ECL_ENDIAN_FLIP); - return rst_file; - } - - fortio_fseek(rst_file->fortio, 0, SEEK_SET); - { - ecl_kw_type *work_kw = ecl_kw_alloc_new("WORK-KW", 0, ECL_INT, NULL); - - while (true) { - offset_type current_offset = fortio_ftell(rst_file->fortio); - - if (fortio_read_at_eof(rst_file->fortio)) { - if (seqnum_found) - target_pos = current_offset; - break; - } - - if (ecl_kw_fread_header(work_kw, rst_file->fortio) == - ECL_KW_READ_FAIL) - break; - - if (ecl_kw_name_equal(work_kw, SEQNUM_KW)) { - ecl_kw_fread_realloc_data(work_kw, rst_file->fortio); - int file_step = ecl_kw_iget_int(work_kw, 0); - if (file_step >= report_step) { - target_pos = current_offset; - break; - } - seqnum_found = true; - } else - ecl_kw_fskip_data(work_kw, rst_file->fortio); - } - - ecl_kw_free(work_kw); - } - - fortio_fseek(rst_file->fortio, target_pos, SEEK_SET); - fortio_ftruncate_current(rst_file->fortio); - return rst_file; -} - -ecl_rst_file_type *ecl_rst_file_open_write(const char *filename) { - ecl_rst_file_type *rst_file = ecl_rst_file_alloc(filename); - rst_file->fortio = - fortio_open_writer(filename, rst_file->fmt_file, ECL_ENDIAN_FLIP); - return rst_file; -} - -ecl_rst_file_type *ecl_rst_file_open_append(const char *filename) { - ecl_rst_file_type *rst_file = ecl_rst_file_alloc(filename); - rst_file->fortio = - fortio_open_append(filename, rst_file->fmt_file, ECL_ENDIAN_FLIP); - return rst_file; -} - -void ecl_rst_file_close(ecl_rst_file_type *rst_file) { - fortio_fclose(rst_file->fortio); - free(rst_file); -} - -static void ecl_rst_file_fwrite_SEQNUM(ecl_rst_file_type *rst_file, - int seqnum) { - ecl_kw_type *seqnum_kw = ecl_kw_alloc(SEQNUM_KW, 1, ECL_INT); - ecl_kw_iset_int(seqnum_kw, 0, seqnum); - ecl_kw_fwrite(seqnum_kw, rst_file->fortio); - ecl_kw_free(seqnum_kw); -} - -void ecl_rst_file_start_solution(ecl_rst_file_type *rst_file) { - ecl_kw_type *startsol_kw = ecl_kw_alloc(STARTSOL_KW, 0, ECL_MESS); - ecl_kw_fwrite(startsol_kw, rst_file->fortio); - ecl_kw_free(startsol_kw); -} - -void ecl_rst_file_end_solution(ecl_rst_file_type *rst_file) { - ecl_kw_type *endsol_kw = ecl_kw_alloc(ENDSOL_KW, 0, ECL_MESS); - ecl_kw_fwrite(endsol_kw, rst_file->fortio); - ecl_kw_free(endsol_kw); -} - -static ecl_kw_type *ecl_rst_file_alloc_INTEHEAD(ecl_rst_file_type *rst_file, - ecl_rsthead_type *rsthead, - int simulator) { - ecl_kw_type *intehead_kw = - ecl_kw_alloc(INTEHEAD_KW, INTEHEAD_RESTART_SIZE, ECL_INT); - ecl_kw_scalar_set_int(intehead_kw, 0); - - ecl_kw_iset_int(intehead_kw, INTEHEAD_UNIT_INDEX, rsthead->unit_system); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NX_INDEX, rsthead->nx); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NY_INDEX, rsthead->ny); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NZ_INDEX, rsthead->nz); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NACTIVE_INDEX, rsthead->nactive); - ecl_kw_iset_int(intehead_kw, INTEHEAD_PHASE_INDEX, rsthead->phase_sum); - - /* All well properties are hardcoded to zero. */ - { - int NGMAXZ = 0; - int NWGMAX = 0; - int NIGRPZ = 0; - int NSWLMX = 0; - int NSEGMX = 0; - int NISEGZ = 0; - - ecl_kw_iset_int(intehead_kw, INTEHEAD_NWELLS_INDEX, rsthead->nwells); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NCWMAX_INDEX, rsthead->ncwmax); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NWGMAX_INDEX, NWGMAX); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NGMAXZ_INDEX, NGMAXZ); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NIWELZ_INDEX, rsthead->niwelz); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NZWELZ_INDEX, rsthead->nzwelz); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NICONZ_INDEX, rsthead->niconz); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NIGRPZ_INDEX, NIGRPZ); - - { - ecl_util_set_date_values(rsthead->sim_time, &rsthead->day, - &rsthead->month, &rsthead->year); - ecl_kw_iset_int(intehead_kw, INTEHEAD_DAY_INDEX, rsthead->day); - ecl_kw_iset_int(intehead_kw, INTEHEAD_MONTH_INDEX, rsthead->month); - ecl_kw_iset_int(intehead_kw, INTEHEAD_YEAR_INDEX, rsthead->year); - } - - ecl_kw_iset_int(intehead_kw, INTEHEAD_IPROG_INDEX, simulator); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NSWLMX_INDEX, NSWLMX); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NSEGMX_INDEX, NSEGMX); - ecl_kw_iset_int(intehead_kw, INTEHEAD_NISEGZ_INDEX, NISEGZ); - } - return intehead_kw; -} - -static ecl_kw_type *ecl_rst_file_alloc_LOGIHEAD(int simulator) { - bool dual_porosity = false; - bool radial_grid_ECLIPSE100 = false; - bool radial_grid_ECLIPSE300 = false; - - ecl_kw_type *logihead_kw = - ecl_kw_alloc(LOGIHEAD_KW, LOGIHEAD_RESTART_SIZE, ECL_BOOL); - - ecl_kw_scalar_set_bool(logihead_kw, false); - - if (simulator == INTEHEAD_ECLIPSE100_VALUE) - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL100_INDEX, - radial_grid_ECLIPSE100); - else - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL300_INDEX, - radial_grid_ECLIPSE300); - - ecl_kw_iset_bool(logihead_kw, LOGIHEAD_DUALP_INDEX, dual_porosity); - return logihead_kw; -} - -static ecl_kw_type *ecl_rst_file_alloc_DOUBHEAD(ecl_rst_file_type *rst_file, - double days) { - ecl_kw_type *doubhead_kw = - ecl_kw_alloc(DOUBHEAD_KW, DOUBHEAD_RESTART_SIZE, ECL_DOUBLE); - - ecl_kw_scalar_set_double(doubhead_kw, 0); - ecl_kw_iset_double(doubhead_kw, DOUBHEAD_DAYS_INDEX, days); - - return doubhead_kw; -} - -void ecl_rst_file_fwrite_header(ecl_rst_file_type *rst_file, int seqnum, - ecl_rsthead_type *rsthead_data) { - - if (rst_file->unified) - ecl_rst_file_fwrite_SEQNUM(rst_file, seqnum); - - { - ecl_kw_type *intehead_kw = ecl_rst_file_alloc_INTEHEAD( - rst_file, rsthead_data, INTEHEAD_ECLIPSE100_VALUE); - ecl_kw_fwrite(intehead_kw, rst_file->fortio); - ecl_kw_free(intehead_kw); - } - - { - ecl_kw_type *logihead_kw = - ecl_rst_file_alloc_LOGIHEAD(INTEHEAD_ECLIPSE100_VALUE); - ecl_kw_fwrite(logihead_kw, rst_file->fortio); - ecl_kw_free(logihead_kw); - } - - { - ecl_kw_type *doubhead_kw = - ecl_rst_file_alloc_DOUBHEAD(rst_file, rsthead_data->sim_days); - ecl_kw_fwrite(doubhead_kw, rst_file->fortio); - ecl_kw_free(doubhead_kw); - } -} - -void ecl_rst_file_add_kw(ecl_rst_file_type *rst_file, - const ecl_kw_type *ecl_kw) { - ecl_kw_fwrite(ecl_kw, rst_file->fortio); -} - -offset_type ecl_rst_file_ftell(const ecl_rst_file_type *rst_file) { - return fortio_ftell(rst_file->fortio); -} diff --git a/lib/ecl/ecl_smspec.cpp b/lib/ecl/ecl_smspec.cpp deleted file mode 100644 index c11dc2ba89..0000000000 --- a/lib/ecl/ecl_smspec.cpp +++ /dev/null @@ -1,1804 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include "detail/util/path.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_FNMATCH -#include -#endif - -/** - This file implements the indexing into the ECLIPSE summary files. -*/ - -/* - Supporting a new variable type: - ------------------------------- - - 1. The function smspec_node_alloc() must be updated to return a valid - ecl::smspec_node instance when called with the new var_type. - - 2. Update the function ecl_smpec_install_gen_key() to install smpec_index - instances of this particular type. The format of the general key is - implicitly defined in this function. - - 3. The ecl_smspec structure supports two different types of lookup: - - a) Lookup based on general key like e.g. WWCT:OP6 - b) Specific lookup based on the variable type, i.e. : - - ecl_smspec_get_well_var( xxx , well_name , var). - - Historically everything started with specific lookup as in case b); - however the general lookup proved to be very convenient, and the - specfic lookup method has seen less use[*]. The final step in - supporting a new variable is to update the function - ecl_smspec_fread_header(). - - If you want to support specific lookup of the new variable type you - must add the necessary datastructures to the ecl_smspec_struct - structure and then subsequently fill that structure in the big - switch() in ecl_smspec_fread_header() - if you do not care about - specific lookup you just have to add an empty case() slot to the - switch in ecl_smspec_fread_header(). The LGR variables, and also - ECL_SMSPEC_SEGMENT_VAR do not support specific lookup. - - [*]: The advantage of the specific lookup is that it is possible - to supply better error messages (The well 'XX' does not - exist, instead of just unknown key: 'WWCT:XX'), and it is - also possible to support queries like: give me all the - well names. - - 4. Mark the variable type as supported with a 'X' in the defintion of - ecl_smspec_var_type in ecl_smspec.h. - - */ - -#define ECL_SMSPEC_ID 806647 -#define PARAMS_GLOBAL_DEFAULT -99 - -typedef std::map node_map; - -struct ecl_smspec_struct { - UTIL_TYPE_ID_DECLARATION; - /* - All the hash tables listed below here are different ways to access - smspec_node instances. The actual smspec_node instances are - owned by the smspec_nodes vector; - */ - node_map field_var_index; - node_map misc_var_index; /* Variables like 'TCPU' and 'NEWTON'. */ - node_map - gen_var_index /* This is "everything" - things can either be found as gen_var("WWCT:OP_X") or as well_var("WWCT" , "OP_X") */ - ; - - std::map - well_var_index; /* Indexes for all well variables: - {well1: {var1: index1 , var2: index2} , well2: {var1: index1 , var2: index2}} */ - std::map - group_var_index; /* Indexes for group variables.*/ - std::map - region_var_index; /* The stored index is an offset. */ - std::map block_var_index; /* Block variables like BPR */ - std::map> - well_completion_var_index; /* Indexes for completion indexes .*/ - - std::vector> smspec_nodes; - bool write_mode; - bool need_nums; - std::vector index_map; - std::map inv_index_map; - int params_size; - - int time_seconds; - int grid_dims[3]; /* Grid dimensions - in DIMENS[1,2,3] */ - int num_regions; - int Nwells, param_offset; - std::string - key_join_string; /* The string used to join keys when building gen_key keys - typically ":" - - but arbitrary - NOT necessary to be able to invert the joining. */ - std::string - header_file; /* FULL path to the currenbtly loaded header_file. */ - - bool - formatted; /* Has this summary instance been loaded from a formatted (i.e. FSMSPEC file) or unformatted (i.e. SMSPEC) file. */ - time_t sim_start_time; /* When did the simulation start - worldtime. */ - - int time_index; /* The fields time_index, day_index, month_index and year_index */ - int day_index; /* are used by the ecl_sum_data object to locate per. timestep */ - int month_index; /* time information. */ - int year_index; - bool has_lgr; - std::vector params_default; - - std::string restart_case; - ert_ecl_unit_enum unit_system; - int restart_step; -}; - -/** -About indexing: ---------------- - -The ECLISPE summary files are organised (roughly) like this: - - 1. A header-file called xxx.SMPSEC is written, which is common to - every timestep. - - 2. For each timestep the summary vector is written in the form of a - vector 'PARAMS' of length N with floats. In the PARAMS vector all - types of data are stacked togeheter, and one must use the header - info in the SMSPEC file to disentangle the summary data. - -Here I will try to describe how the header in SMSPEC is organised, and -how that support is imlemented here. The SMSPEC header is organized -around three character vectors, of length N. To find the position in -the PARAMS vector of a certain quantity, you must consult one, two or -all three of these vectors. The most important vecor - which must -always be consulted is the KEYWORDS vector, then it is the WGNAMES and -NUMS (integer) vectors whcih must be consulted for some variable -types. - - -Let us a consider a system consisting of: - - * Two wells: P1 and P2 - for each well we have variables WOPR, WWCT - and WGOR. - - * Three regions: For each region we have variables RPR and RXX(??) - - * We have stored field properties FOPT and FWPT - - -KEYWORDS = ['TIME','FOPR','FPR','FWCT','WOPR','WOPR,'WWCT','WWCT] - .... - - - -general_var: ------------- -VAR_TYPE:(WELL_NAME|GROUP_NAME|NUMBER):NUMBER - -Field var: VAR_TYPE -Misc var: VAR_TYPE -Well var: VAR_TYPE:WELL_NAME -Group var: VAR_TYPE:GROUP_NAME -Block var: VAR_TYPE:i,j,k (where i,j,k is calculated form NUM) -Region var VAR_TYPE:index (where index is NOT from the nums vector, it it is just an offset). -Completion var: VAR_TYPE:WELL_NAME:NUM -.... - -*/ - -/* - The smspec_required_keywords variable contains a list of keywords - which are *absolutely* required in the SMSPEC file, but observe that - depending on the content of the "KEYWORDS" array other keywords - might bre requred as well - this typically includes the NUMS - keyword. Such 'second-order' dependencies are not accounted for with - this simple list. -*/ - -static const size_t num_req_keywords = 5; -static const char *smspec_required_keywords[] = { - WGNAMES_KW, KEYWORDS_KW, STARTDAT_KW, UNITS_KW, DIMENS_KW}; - -namespace { - -const ecl::smspec_node *ecl_smspec_get_var_node(const node_map &mp, - const char *var) { - const auto it = mp.find(var); - if (it == mp.end()) - return nullptr; - - return it->second; -} - -const ecl::smspec_node * -ecl_smspec_get_str_key_var_node(const std::map &mp, - const char *key, const char *var) { - const auto key_it = mp.find(key); - if (key_it == mp.end()) - return nullptr; - - const node_map &var_map = key_it->second; - return ecl_smspec_get_var_node(var_map, var); -} - -const ecl::smspec_node * -ecl_smspec_get_int_key_var_node(const std::map &mp, int key, - const char *var) { - const auto key_it = mp.find(key); - if (key_it == mp.end()) - return nullptr; - - const auto &var_map = key_it->second; - return ecl_smspec_get_var_node(var_map, var); -} - -} //end namespace - -int ecl_smspec_num_nodes(const ecl_smspec_type *smspec) { - return smspec->smspec_nodes.size(); -} - -/* - When loading a summary case from file many of the nodes can be ignored, in - that case the size of PARAMS vector in the data files is larger than the - number of internalized nodes. Therefor we need to maintain the - params_size member. -*/ - -int ecl_smspec_get_params_size(const ecl_smspec_type *smspec) { - return smspec->params_size; -} - -ecl_smspec_type *ecl_smspec_alloc_empty(bool write_mode, - const char *key_join_string) { - ecl_smspec_type *ecl_smspec = new ecl_smspec_type(); - UTIL_TYPE_ID_INIT(ecl_smspec, ECL_SMSPEC_ID); - - ecl_smspec->sim_start_time = -1; - ecl_smspec->key_join_string = key_join_string; - ecl_smspec->header_file = ""; - - ecl_smspec->time_index = -1; - ecl_smspec->day_index = -1; - ecl_smspec->year_index = -1; - ecl_smspec->month_index = -1; - ecl_smspec->time_seconds = -1; - ecl_smspec->params_size = -1; - - /* - The unit system is given as an integer in the INTEHEAD keyword. The INTEHEAD - keyword is optional, and we have for a long time been completely oblivious - to the possibility of extracting unit system information from the SMSPEC file. - */ - ecl_smspec->unit_system = ECL_METRIC_UNITS; - - ecl_smspec->restart_step = -1; - ecl_smspec->write_mode = write_mode; - ecl_smspec->need_nums = false; - - return ecl_smspec; -} - -int *ecl_smspec_alloc_mapping(const ecl_smspec_type *self, - const ecl_smspec_type *other) { - int params_size = ecl_smspec_get_params_size(self); - int *mapping = (int *)util_malloc(params_size * sizeof *mapping); - - for (int i = 0; i < params_size; i++) - mapping[i] = -1; - - for (int i = 0; i < ecl_smspec_num_nodes(self); i++) { - const ecl::smspec_node &self_node = - ecl_smspec_iget_node_w_node_index(self, i); - int self_index = self_node.get_params_index(); - const char *key = self_node.get_gen_key1(); - if (ecl_smspec_has_general_var(other, key)) { - const ecl::smspec_node &other_node = - ecl_smspec_get_general_var_node(other, key); - int other_index = other_node.get_params_index(); - mapping[self_index] = other_index; - } - } - - return mapping; -} - -/** - Observe that the index here is into the __INTERNAL__ indexing in - the smspec_nodes vector; and in general widely different from the - params_index of the returned smspec_node instance. -*/ - -const ecl::smspec_node & -ecl_smspec_iget_node_w_node_index(const ecl_smspec_type *smspec, - int node_index) { - const auto &node = smspec->smspec_nodes[node_index]; - return *node.get(); -} - -/* - The ecl_smspec_iget_node() function is only retained for compatibility; should be - replaced with calls to the more explicit: ecl_smspec_iget_node_w_node_index(). -*/ - -const ecl::smspec_node &ecl_smspec_iget_node(const ecl_smspec_type *smspec, - int index) { - return ecl_smspec_iget_node_w_node_index(smspec, index); -} - -const ecl::smspec_node & -ecl_smspec_iget_node_w_params_index(const ecl_smspec_type *smspec, - int params_index) { - int node_index = smspec->inv_index_map.at(params_index); - return ecl_smspec_iget_node_w_node_index(smspec, node_index); -} - -/** - * Returns an ecl data type for which all names will fit. If the maximum name - * length is at most 8, an ECL_CHAR is returned and otherwise a large enough - * ECL_STRING. - */ -static ecl_data_type get_wgnames_type(const ecl_smspec_type *smspec) { - size_t max_len = 0; - for (int i = 0; i < ecl_smspec_num_nodes(smspec); ++i) { - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(smspec, i); - const char *name = smspec_node_get_wgname(&node); - if (name) - max_len = util_size_t_max(max_len, strlen(name)); - } - - return max_len <= ECL_STRING8_LENGTH ? ECL_CHAR : ECL_STRING(max_len); -} - -static void ecl_smspec_fwrite_INTEHEAD(const ecl_smspec_type *smspec, - fortio_type *fortio) { - ecl_kw_type *intehead = - ecl_kw_alloc(INTEHEAD_KW, INTEHEAD_SMSPEC_SIZE, ECL_INT); - ecl_kw_iset_int(intehead, INTEHEAD_SMSPEC_UNIT_INDEX, smspec->unit_system); - /* - The simulator type is just hardcoded to ECLIPSE100. - */ - ecl_kw_iset_int(intehead, INTEHEAD_SMSPEC_IPROG_INDEX, - INTEHEAD_ECLIPSE100_VALUE); - ecl_kw_fwrite(intehead, fortio); - ecl_kw_free(intehead); -} - -static void ecl_smspec_fwrite_RESTART(const ecl_smspec_type *smspec, - fortio_type *fortio) { - ecl_kw_type *restart_kw = - ecl_kw_alloc(RESTART_KW, SUMMARY_RESTART_SIZE, ECL_CHAR); - for (int i = 0; i < SUMMARY_RESTART_SIZE; i++) - ecl_kw_iset_string8(restart_kw, i, ""); - - if (smspec->restart_case.size() > 0) { - size_t restart_case_len = smspec->restart_case.size(); - - size_t offset = 0; - for (size_t i = 0; i < SUMMARY_RESTART_SIZE; i++) { - if (offset < restart_case_len) - ecl_kw_iset_string8(restart_kw, i, - &smspec->restart_case[offset]); - offset += ECL_STRING8_LENGTH; - } - } - ecl_kw_fwrite(restart_kw, fortio); - ecl_kw_free(restart_kw); -} - -static void ecl_smspec_fwrite_DIMENS(const ecl_smspec_type *smspec, - fortio_type *fortio) { - ecl_kw_type *dimens_kw = ecl_kw_alloc(DIMENS_KW, DIMENS_SIZE, ECL_INT); - int num_nodes = ecl_smspec_num_nodes(smspec); - ecl_kw_iset_int(dimens_kw, DIMENS_SMSPEC_SIZE_INDEX, num_nodes); - ecl_kw_iset_int(dimens_kw, DIMENS_SMSPEC_NX_INDEX, smspec->grid_dims[0]); - ecl_kw_iset_int(dimens_kw, DIMENS_SMSPEC_NY_INDEX, smspec->grid_dims[1]); - ecl_kw_iset_int(dimens_kw, DIMENS_SMSPEC_NZ_INDEX, smspec->grid_dims[2]); - ecl_kw_iset_int(dimens_kw, 4, 0); // Do not know what this is for. - ecl_kw_iset_int(dimens_kw, DIMENS_SMSPEC_RESTART_STEP_INDEX, - smspec->restart_step); - - ecl_kw_fwrite(dimens_kw, fortio); - ecl_kw_free(dimens_kw); -} - -static void ecl_smspec_fwrite_STARTDAT(const ecl_smspec_type *smspec, - fortio_type *fortio) { - ecl_kw_type *startdat_kw = - ecl_kw_alloc(STARTDAT_KW, STARTDAT_SIZE, ECL_INT); - int second, minute, hour, mday, month, year; - ecl_util_set_datetime_values(smspec->sim_start_time, &second, &minute, - &hour, &mday, &month, &year); - - ecl_kw_iset_int(startdat_kw, STARTDAT_DAY_INDEX, mday); - ecl_kw_iset_int(startdat_kw, STARTDAT_MONTH_INDEX, month); - ecl_kw_iset_int(startdat_kw, STARTDAT_YEAR_INDEX, year); - ecl_kw_iset_int(startdat_kw, STARTDAT_HOUR_INDEX, hour); - ecl_kw_iset_int(startdat_kw, STARTDAT_MINUTE_INDEX, minute); - ecl_kw_iset_int(startdat_kw, STARTDAT_MICRO_SECOND_INDEX, second * 1000000); - - ecl_kw_fwrite(startdat_kw, fortio); - ecl_kw_free(startdat_kw); -} - -static void ecl_smspec_fortio_fwrite(const ecl_smspec_type *smspec, - fortio_type *fortio) { - ecl_smspec_fwrite_INTEHEAD(smspec, fortio); - ecl_smspec_fwrite_RESTART(smspec, fortio); - ecl_smspec_fwrite_DIMENS(smspec, fortio); - - int num_nodes = ecl_smspec_num_nodes(smspec); - ecl_kw_type *keywords_kw = ecl_kw_alloc(KEYWORDS_KW, num_nodes, ECL_CHAR); - ecl_kw_type *units_kw = ecl_kw_alloc(UNITS_KW, num_nodes, ECL_CHAR); - ecl_kw_type *nums_kw = NULL; - - // If the names_type is an ECL_STRING we expect this to be an INTERSECT - // summary, otherwise an ECLIPSE summary. - ecl_data_type names_type = get_wgnames_type(smspec); - ecl_kw_type *wgnames_kw = - ecl_kw_alloc(ecl_type_is_char(names_type) ? WGNAMES_KW : NAMES_KW, - num_nodes, names_type); - - if (smspec->need_nums) - nums_kw = ecl_kw_alloc(NUMS_KW, num_nodes, ECL_INT); - - for (int i = 0; i < ecl_smspec_num_nodes(smspec); i++) { - const ecl::smspec_node &smspec_node = - ecl_smspec_iget_node_w_node_index(smspec, i); - /* - It is possible to add variables with deferred initialisation - with the ecl_sum_add_blank_var() function. Before these - variables can be actually used for anything interesting they - must be initialized with the ecl_sum_init_var() function. - - If a call to save the smspec file comes before all the - variable have been initialized things will potentially go - belly up. This is solved with the following uber-hack: - - o One of the well related keywords is chosen; in - particular 'WWCT' in this case. - - o The wgname value is set to DUMMY_WELL - - The use of DUMMY_WELL ensures that this field will be - ignored when/if this smspec file is read in at a later - stage. - */ - if (smspec_node.get_var_type() == ECL_SMSPEC_INVALID_VAR) { - ecl_kw_iset_string8(keywords_kw, i, "WWCT"); - ecl_kw_iset_string8(units_kw, i, "????????"); - ecl_kw_iset_string_ptr(wgnames_kw, i, DUMMY_WELL); - } else { - ecl_kw_iset_string8(keywords_kw, i, - smspec_node_get_keyword(&smspec_node)); - ecl_kw_iset_string8(units_kw, i, - smspec_node_get_unit(&smspec_node)); - { - const char *wgname = DUMMY_WELL; - if (smspec_node_get_wgname(&smspec_node)) - wgname = smspec_node_get_wgname(&smspec_node); - ecl_kw_iset_string_ptr(wgnames_kw, i, wgname); - } - } - - if (nums_kw != NULL) - ecl_kw_iset_int(nums_kw, i, smspec_node.get_num()); - } - ecl_kw_fwrite(keywords_kw, fortio); - ecl_kw_fwrite(wgnames_kw, fortio); - if (nums_kw != NULL) - ecl_kw_fwrite(nums_kw, fortio); - ecl_kw_fwrite(units_kw, fortio); - - ecl_kw_free(keywords_kw); - ecl_kw_free(wgnames_kw); - ecl_kw_free(units_kw); - if (nums_kw != NULL) - ecl_kw_free(nums_kw); - - ecl_smspec_fwrite_STARTDAT(smspec, fortio); -} - -void ecl_smspec_fwrite(const ecl_smspec_type *smspec, const char *ecl_case, - bool fmt_file) { - char *filename = ecl_util_alloc_filename( - NULL, ecl_case, ECL_SUMMARY_HEADER_FILE, fmt_file, 0); - fortio_type *fortio = - fortio_open_writer(filename, fmt_file, ECL_ENDIAN_FLIP); - - if (!fortio) { - const char *error_fmt_msg = - "%s: Unable to open fortio file %s, error: %s .\n"; - util_abort(error_fmt_msg, __func__, filename, strerror(errno)); - } - - ecl_smspec_fortio_fwrite(smspec, fortio); - - fortio_fclose(fortio); - free(filename); -} - -static ecl_smspec_type * -ecl_smspec_alloc_writer__(const char *key_join_string, const char *restart_case, - int restart_step, time_t sim_start, bool time_in_days, - int nx, int ny, int nz) { - ecl_smspec_type *ecl_smspec = ecl_smspec_alloc_empty(true, key_join_string); - /* - Only a total of 9 * 8 characters is set aside for the restart keyword, if - the supplied restart case is longer than that we silently ignore it. - */ - if (restart_case) { - if (strlen(restart_case) <= - (SUMMARY_RESTART_SIZE * ECL_STRING8_LENGTH)) { - ecl_smspec->restart_case = restart_case; - ecl_smspec->restart_step = restart_step; - } - } - ecl_smspec->grid_dims[0] = nx; - ecl_smspec->grid_dims[1] = ny; - ecl_smspec->grid_dims[2] = nz; - ecl_smspec->sim_start_time = sim_start; - - { - const ecl::smspec_node *time_node; - - if (time_in_days) { - ecl_smspec->time_seconds = 3600 * 24; - time_node = ecl_smspec_add_node(ecl_smspec, "TIME", "DAYS", 0); - } else { - ecl_smspec->time_seconds = 3600; - time_node = ecl_smspec_add_node(ecl_smspec, "TIME", "HOURS", 0); - } - ecl_smspec->time_index = time_node->get_params_index(); - } - return ecl_smspec; -} - -ecl_smspec_type *ecl_smspec_alloc_restart_writer( - const char *key_join_string, const char *restart_case, int restart_step, - time_t sim_start, bool time_in_days, int nx, int ny, int nz) { - return ecl_smspec_alloc_writer__(key_join_string, restart_case, - restart_step, sim_start, time_in_days, nx, - ny, nz); -} - -ecl_smspec_type *ecl_smspec_alloc_writer(const char *key_join_string, - time_t sim_start, bool time_in_days, - int nx, int ny, int nz) { - return ecl_smspec_alloc_writer__(key_join_string, NULL, 0, sim_start, - time_in_days, nx, ny, nz); -} - -UTIL_SAFE_CAST_FUNCTION(ecl_smspec, ECL_SMSPEC_ID) - -ecl_smspec_var_type ecl_smspec_identify_var_type(const char *var) { - return ecl::smspec_node::identify_var_type(var); -} - -static bool ecl_smspec_lgr_var_type(ecl_smspec_var_type var_type) { - if ((var_type == ECL_SMSPEC_LOCAL_BLOCK_VAR) || - (var_type == ECL_SMSPEC_LOCAL_WELL_VAR) || - (var_type == ECL_SMSPEC_LOCAL_COMPLETION_VAR)) - - return true; - else - return false; -} - -/** - Takes a ecl_smspec_var_type variable as input, and return a string - representation of this var_type. Suitable for debug messages +++ -*/ - -const char *ecl_smspec_get_var_type_name(ecl_smspec_var_type var_type) { - switch (var_type) { - case (ECL_SMSPEC_INVALID_VAR): - return "INVALID_VAR"; - break; - case (ECL_SMSPEC_AQUIFER_VAR): - return "AQUIFER_VAR"; - break; - case (ECL_SMSPEC_WELL_VAR): - return "WELL_VAR"; - break; - case (ECL_SMSPEC_REGION_VAR): - return "REGION_VAR"; - break; - case (ECL_SMSPEC_FIELD_VAR): - return "FIELD_VAR"; - break; - case (ECL_SMSPEC_GROUP_VAR): - return "GROUP_VAR"; - break; - case (ECL_SMSPEC_BLOCK_VAR): - return "BLOCK_VAR"; - break; - case (ECL_SMSPEC_COMPLETION_VAR): - return "COMPLETION_VAR"; - break; - case (ECL_SMSPEC_LOCAL_BLOCK_VAR): - return "LOCAL_BLOCK_VAR"; - break; - case (ECL_SMSPEC_LOCAL_COMPLETION_VAR): - return "LOCAL_COMPLETION_VAR"; - break; - case (ECL_SMSPEC_LOCAL_WELL_VAR): - return "LOCAL_WELL_VAR"; - break; - case (ECL_SMSPEC_NETWORK_VAR): - return "NETWORK_VAR"; - break; - case (ECL_SMSPEC_REGION_2_REGION_VAR): - return "REGION_2_REGION_VAR"; - break; - case (ECL_SMSPEC_SEGMENT_VAR): - return "SEGMENT_VAR"; - break; - case (ECL_SMSPEC_MISC_VAR): - return "MISC_VAR"; - break; - default: - util_abort("%s: Unrecognized variable type:%d \n", __func__, var_type); - return NULL; - } -} - -/** - Input i,j,k are assumed to be in the interval [1..nx] , [1..ny], - [1..nz], return value is a global index which can be used in the - xxx_block_xxx routines. -*/ - -static int ecl_smspec_get_global_grid_index(const ecl_smspec_type *smspec, - int i, int j, int k) { - return i + (j - 1) * smspec->grid_dims[0] + - (k - 1) * smspec->grid_dims[0] * smspec->grid_dims[1]; -} - -/** - This function takes a fully initialized smspec_node instance, generates the - corresponding key and inserts smspec_node instance in the main hash table - smspec->gen_var_index. - - The format strings used, i.e. VAR:WELL for well based variables is implicitly - defined through the format strings used in this function. -*/ - -static void ecl_smspec_install_gen_keys(ecl_smspec_type *smspec, - const ecl::smspec_node &smspec_node) { - /* Insert the default general mapping. */ - { - const char *gen_key1 = smspec_node.get_gen_key1(); - if (gen_key1) - smspec->gen_var_index[gen_key1] = &smspec_node; - } - - /* Insert the (optional) extra mapping for block related variables and region_2_region variables: */ - { - const char *gen_key2 = smspec_node.get_gen_key2(); - if (gen_key2) - smspec->gen_var_index[gen_key2] = &smspec_node; - } -} - -static void -ecl_smspec_install_special_keys(ecl_smspec_type *ecl_smspec, - const ecl::smspec_node &smspec_node) { - /** - This large switch is for installing keys which have custom lookup - paths, in addition to the lookup based on general keys. Examples - of this is e.g. well variables which can be looked up through: - - ecl_smspec_get_well_var_index( smspec , well_name , var ); - */ - - const char *well = smspec_node_get_wgname(&smspec_node); - const char *group = well; - const int num = smspec_node_get_num(&smspec_node); - const char *keyword = smspec_node_get_keyword(&smspec_node); - ecl_smspec_var_type var_type = smspec_node_get_var_type(&smspec_node); - - switch (var_type) { - case (ECL_SMSPEC_COMPLETION_VAR): - ecl_smspec->well_completion_var_index[well][num][keyword] = - &smspec_node; - break; - case (ECL_SMSPEC_FIELD_VAR): - ecl_smspec->field_var_index[keyword] = &smspec_node; - break; - case (ECL_SMSPEC_GROUP_VAR): - ecl_smspec->group_var_index[group][keyword] = &smspec_node; - break; - case (ECL_SMSPEC_REGION_VAR): - ecl_smspec->region_var_index[num][keyword] = &smspec_node; - ecl_smspec->num_regions = util_int_max(ecl_smspec->num_regions, num); - break; - case (ECL_SMSPEC_WELL_VAR): - ecl_smspec->well_var_index[well][keyword] = &smspec_node; - break; - case (ECL_SMSPEC_MISC_VAR): - /* Misc variable - i.e. date or CPU time ... */ - ecl_smspec->misc_var_index[keyword] = &smspec_node; - break; - case (ECL_SMSPEC_BLOCK_VAR): - ecl_smspec->block_var_index[num][keyword] = &smspec_node; - break; - /** - The variables below are ONLY accesable through the gen_key - setup; but the must be mentioned in this switch statement, - otherwise they will induce a hard failure in the default: target - below. - */ - case (ECL_SMSPEC_LOCAL_BLOCK_VAR): - break; - case (ECL_SMSPEC_LOCAL_COMPLETION_VAR): - break; - case (ECL_SMSPEC_LOCAL_WELL_VAR): - break; - case (ECL_SMSPEC_SEGMENT_VAR): - break; - case (ECL_SMSPEC_REGION_2_REGION_VAR): - break; - case (ECL_SMSPEC_AQUIFER_VAR): - break; - default: - throw std::invalid_argument("Internal error - should not be here \n"); - } -} - -/** - The usage of this functon breaks down completely if LGR's are involved. -*/ - -bool ecl_smspec_needs_wgname(ecl_smspec_var_type var_type) { - switch (var_type) { - case (ECL_SMSPEC_COMPLETION_VAR): - return true; - break; - case (ECL_SMSPEC_FIELD_VAR): - return false; - break; - case (ECL_SMSPEC_GROUP_VAR): - return true; - break; - case (ECL_SMSPEC_WELL_VAR): - return true; - break; - case (ECL_SMSPEC_REGION_VAR): - return false; - break; - case (ECL_SMSPEC_REGION_2_REGION_VAR): - return false; - break; - case (ECL_SMSPEC_MISC_VAR): - return false; - break; - case (ECL_SMSPEC_BLOCK_VAR): - return false; - break; - case (ECL_SMSPEC_AQUIFER_VAR): - return false; - break; - case (ECL_SMSPEC_SEGMENT_VAR): - return true; - break; - default: - util_exit("Sorry: support for variables of type:%s is not implemented " - "in %s.\n", - ecl_smspec_get_var_type_name(var_type), __FILE__); - } - /* Really should not be here. */ - return false; -} - -/** - The usage of this functon breaks down completely if LGR's are involved. -*/ -bool ecl_smspec_needs_num(ecl_smspec_var_type var_type) { - switch (var_type) { - case (ECL_SMSPEC_COMPLETION_VAR): - return true; - break; - case (ECL_SMSPEC_AQUIFER_VAR): - return true; - break; - case (ECL_SMSPEC_FIELD_VAR): - return false; - break; - case (ECL_SMSPEC_GROUP_VAR): - return false; - break; - case (ECL_SMSPEC_WELL_VAR): - return false; - break; - case (ECL_SMSPEC_REGION_VAR): - return true; - break; - case (ECL_SMSPEC_REGION_2_REGION_VAR): - return true; - break; - case (ECL_SMSPEC_MISC_VAR): - return false; - break; - case (ECL_SMSPEC_BLOCK_VAR): - return true; - break; - default: - util_exit("Sorry: support for variables of type:%s is not implemented " - "in %s.\n", - ecl_smspec_get_var_type_name(var_type), __FILE__); - } - return false; -} - -bool ecl_smspec_equal(const ecl_smspec_type *self, - const ecl_smspec_type *other) { - if (self->smspec_nodes.size() != other->smspec_nodes.size()) - return false; - - for (size_t i = 0; i < self->smspec_nodes.size(); i++) { - const ecl::smspec_node *node1 = self->smspec_nodes[i].get(); - const ecl::smspec_node *node2 = other->smspec_nodes[i].get(); - - if (node1->cmp(*node2) != 0) - return false; - } - - return true; -} - -static void ecl_smspec_load_restart(ecl_smspec_type *ecl_smspec, - const ecl_file_type *header) { - if (ecl_file_has_kw(header, RESTART_KW)) { - const ecl_kw_type *restart_kw = - ecl_file_iget_named_kw(header, RESTART_KW, 0); - char tmp_base - [73]; /* To accomodate a maximum of 9 items which consist of 8 characters each. */ - char *restart_base; - int i; - tmp_base[0] = '\0'; - for (i = 0; i < ecl_kw_get_size(restart_kw); i++) - strcat(tmp_base, (const char *)ecl_kw_iget_ptr(restart_kw, i)); - - restart_base = util_alloc_strip_copy(tmp_base); - if (strlen(restart_base)) { /* We ignore the empty ones. */ - char *smspec_header; - - /* - The conditional block here is to support the following situation: - - 1. A simulation with a restart has been performed on Posix with path - separator '/'. - - 2. The simulation is loaded on windows, where the native path - separator is '\'. - - This code block will translate '/' -> '\' in the restart keyword which - is read from the summary file. - */ - -#ifdef ERT_WINDOWS - for (int i = 0; i < strlen(restart_base); i++) { - if (restart_base[i] == UTIL_POSIX_PATH_SEP_CHAR) - restart_base[i] = UTIL_PATH_SEP_CHAR; - } -#endif - - std::string path = - ecl::util::path::dirname(ecl_smspec->header_file); - smspec_header = ecl_util_alloc_exfilename( - path.c_str(), restart_base, ECL_SUMMARY_HEADER_FILE, - ecl_smspec->formatted, 0); - if (smspec_header) { - if (!util_same_file( - smspec_header, - ecl_smspec->header_file - .c_str())) /* Restart from the current case is ignored. */ - { - if (util_is_abs_path(restart_base)) - ecl_smspec->restart_case = restart_base; - else { - char *tmp_path = util_alloc_filename( - path.c_str(), restart_base, NULL); - char *abs_path = util_alloc_abs_path(tmp_path); - ecl_smspec->restart_case = abs_path; - free(abs_path); - free(tmp_path); - } - } - free(smspec_header); - } - } - free(restart_base); - } -} - -static const ecl::smspec_node * -ecl_smspec_insert_node(ecl_smspec_type *ecl_smspec, - std::unique_ptr smspec_node) { - int params_index = smspec_node->get_params_index(); - - /* This indexing must be used when writing. */ - ecl_smspec->index_map.push_back(params_index); - ecl_smspec->params_default.resize(params_index + 1, PARAMS_GLOBAL_DEFAULT); - ecl_smspec->params_default[params_index] = smspec_node->get_default(); - ecl_smspec->inv_index_map.insert( - std::make_pair(params_index, ecl_smspec->smspec_nodes.size())); - - ecl_smspec_install_gen_keys(ecl_smspec, *smspec_node.get()); - ecl_smspec_install_special_keys(ecl_smspec, *smspec_node.get()); - - if (smspec_node->need_nums()) - ecl_smspec->need_nums = true; - - ecl_smspec->smspec_nodes.push_back(std::move(smspec_node)); - - if (params_index > ecl_smspec->params_size) - ecl_smspec->params_size = params_index + 1; - - if (static_cast(ecl_smspec->smspec_nodes.size()) > - ecl_smspec->params_size) - ecl_smspec->params_size = ecl_smspec->smspec_nodes.size(); - - const auto &node = ecl_smspec->smspec_nodes.back(); - return node.get(); -} - -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, int num, - const char *unit, - float default_value) { - int params_index = ecl_smspec->smspec_nodes.size(); - return ecl_smspec_insert_node( - ecl_smspec, std::unique_ptr(new ecl::smspec_node( - params_index, keyword, num, unit, ecl_smspec->grid_dims, - default_value, ecl_smspec->key_join_string.c_str()))); -} - -//copy given node with a new index -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const ecl::smspec_node &node) { - int params_index = ecl_smspec->smspec_nodes.size(); - return ecl_smspec_insert_node( - ecl_smspec, std::unique_ptr( - new ecl::smspec_node(node, params_index))); -} - -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, - const char *unit, - float default_value) { - int params_index = ecl_smspec->smspec_nodes.size(); - return ecl_smspec_insert_node( - ecl_smspec, std::unique_ptr(new ecl::smspec_node( - params_index, keyword, unit, default_value))); -} - -const ecl::smspec_node * -ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, const char *keyword, - const char *wgname, const char *unit, float default_value) { - int params_index = ecl_smspec->smspec_nodes.size(); - return ecl_smspec_insert_node( - ecl_smspec, std::unique_ptr(new ecl::smspec_node( - params_index, keyword, wgname, unit, default_value, - ecl_smspec->key_join_string.c_str()))); -} - -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, - const char *wgname, int num, - const char *unit, - float default_value) { - int params_index = ecl_smspec->smspec_nodes.size(); - return ecl_smspec_insert_node( - ecl_smspec, - std::unique_ptr(new ecl::smspec_node( - params_index, keyword, wgname, num, unit, ecl_smspec->grid_dims, - default_value, ecl_smspec->key_join_string.c_str()))); -} - -const ecl::smspec_node * -ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, int params_index, - const char *keyword, const char *wgname, int num, - const char *unit, float default_value) { - return ecl_smspec_insert_node( - ecl_smspec, - std::unique_ptr(new ecl::smspec_node( - params_index, keyword, wgname, num, unit, ecl_smspec->grid_dims, - default_value, ecl_smspec->key_join_string.c_str()))); -} - -const ecl::smspec_node * -ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, int params_index, - const char *keyword, const char *wgname, int num, - const char *unit, const char *lgr, int lgr_i, int lgr_j, - int lgr_k, float default_value) { - return ecl_smspec_insert_node( - ecl_smspec, - std::unique_ptr(new ecl::smspec_node( - params_index, keyword, wgname, unit, lgr, lgr_i, lgr_j, lgr_k, - default_value, ecl_smspec->key_join_string.c_str()))); -} - -const int *ecl_smspec_get_index_map(const ecl_smspec_type *smspec) { - return smspec->index_map.data(); -} - -/** - * This function is to support the NAMES alias for WGNAMES. If similar - * situations occur in the future, this is a sane starting point for general - * support. - */ -static const char *get_active_keyword_alias(ecl_file_type *header, - const char *keyword) { - if (strcmp(keyword, WGNAMES_KW) == 0 || strcmp(keyword, NAMES_KW) == 0) - return ecl_file_has_kw(header, WGNAMES_KW) ? WGNAMES_KW : NAMES_KW; - - return keyword; -} - -static bool ecl_smspec_check_header(ecl_file_type *header) { - bool OK = true; - for (size_t i = 0; i < num_req_keywords && OK; i++) { - OK &= ecl_file_has_kw(header, get_active_keyword_alias( - header, smspec_required_keywords[i])); - } - - return OK; -} - -static bool ecl_smspec_fread_header(ecl_smspec_type *ecl_smspec, - const char *header_file, - bool include_restart) { - ecl_file_type *header = ecl_file_open(header_file, 0); - if (header && ecl_smspec_check_header(header)) { - const char *names_alias = get_active_keyword_alias(header, WGNAMES_KW); - ecl_kw_type *wells = ecl_file_iget_named_kw(header, names_alias, 0); - ecl_kw_type *keywords = ecl_file_iget_named_kw(header, KEYWORDS_KW, 0); - ecl_kw_type *startdat = ecl_file_iget_named_kw(header, STARTDAT_KW, 0); - ecl_kw_type *units = ecl_file_iget_named_kw(header, UNITS_KW, 0); - ecl_kw_type *dimens = ecl_file_iget_named_kw(header, DIMENS_KW, 0); - ecl_kw_type *nums = NULL; - ecl_kw_type *lgrs = NULL; - ecl_kw_type *numlx = NULL; - ecl_kw_type *numly = NULL; - ecl_kw_type *numlz = NULL; - - int params_index; - ecl_smspec->num_regions = 0; - ecl_smspec->params_size = ecl_kw_get_size(keywords); - if (startdat == NULL) - util_abort( - "%s: could not locate STARTDAT keyword in header - aborting \n", - __func__); - - if (ecl_file_has_kw(header, NUMS_KW)) - nums = ecl_file_iget_named_kw(header, NUMS_KW, 0); - - if (ecl_file_has_kw(header, INTEHEAD_KW)) { - const ecl_kw_type *intehead = - ecl_file_iget_named_kw(header, INTEHEAD_KW, 0); - ecl_smspec->unit_system = (ert_ecl_unit_enum)ecl_kw_iget_int( - intehead, INTEHEAD_SMSPEC_UNIT_INDEX); - /* - The second item in the INTEHEAD vector is an integer designating which - simulator has been used for the current simulation, that is currently - ignored. - */ - } - - if (ecl_file_has_kw(header, - LGRS_KW)) { /* The file has LGR information. */ - lgrs = ecl_file_iget_named_kw(header, LGRS_KW, 0); - numlx = ecl_file_iget_named_kw(header, NUMLX_KW, 0); - numly = ecl_file_iget_named_kw(header, NUMLY_KW, 0); - numlz = ecl_file_iget_named_kw(header, NUMLZ_KW, 0); - ecl_smspec->has_lgr = true; - } else - ecl_smspec->has_lgr = false; - - { - int *date = ecl_kw_get_int_ptr(startdat); - int year = date[STARTDAT_YEAR_INDEX]; - int month = date[STARTDAT_MONTH_INDEX]; - int day = date[STARTDAT_DAY_INDEX]; - int hour = 0; - int min = 0; - int sec = 0; - if (ecl_kw_get_size(startdat) == 6) { - hour = date[STARTDAT_HOUR_INDEX]; - min = date[STARTDAT_MINUTE_INDEX]; - sec = date[STARTDAT_MICRO_SECOND_INDEX] / 1000000; - } - - ecl_smspec->sim_start_time = - ecl_util_make_datetime(sec, min, hour, day, month, year); - } - - ecl_smspec->grid_dims[0] = - ecl_kw_iget_int(dimens, DIMENS_SMSPEC_NX_INDEX); - ecl_smspec->grid_dims[1] = - ecl_kw_iget_int(dimens, DIMENS_SMSPEC_NY_INDEX); - ecl_smspec->grid_dims[2] = - ecl_kw_iget_int(dimens, DIMENS_SMSPEC_NZ_INDEX); - ecl_smspec->restart_step = - ecl_kw_iget_int(dimens, DIMENS_SMSPEC_RESTART_STEP_INDEX); - - ecl_util_get_file_type(header_file, &ecl_smspec->formatted, NULL); - - { - for (params_index = 0; params_index < ecl_kw_get_size(wells); - params_index++) { - float default_value = PARAMS_GLOBAL_DEFAULT; - int num = SMSPEC_NUMS_INVALID; - char *well = (char *)util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(wells, params_index)); - char *kw = (char *)util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(keywords, params_index)); - char *unit = (char *)util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(units, params_index)); - - ecl_smspec_var_type var_type; - if (nums != NULL) - num = ecl_kw_iget_int(nums, params_index); - var_type = ecl::smspec_node::valid_type(kw, well, num); - if (var_type == ECL_SMSPEC_INVALID_VAR) { - free(kw); - free(well); - free(unit); - continue; - } - - if (ecl_smspec_lgr_var_type(var_type)) { - int lgr_i = ecl_kw_iget_int(numlx, params_index); - int lgr_j = ecl_kw_iget_int(numly, params_index); - int lgr_k = ecl_kw_iget_int(numlz, params_index); - char *lgr_name = (char *)util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(lgrs, params_index)); - - ecl_smspec_insert_node( - ecl_smspec, - std::unique_ptr(new ecl::smspec_node( - params_index, kw, well, unit, lgr_name, lgr_i, - lgr_j, lgr_k, default_value, - ecl_smspec->key_join_string.c_str()))); - free(lgr_name); - } else - ecl_smspec_insert_node( - ecl_smspec, - std::unique_ptr(new ecl::smspec_node( - params_index, kw, well, num, unit, - ecl_smspec->grid_dims, default_value, - ecl_smspec->key_join_string.c_str()))); - - free(kw); - free(well); - free(unit); - } - } - - char *header_str = util_alloc_realpath(header_file); - ecl_smspec->header_file = header_str; - free(header_str); - if (include_restart) - ecl_smspec_load_restart(ecl_smspec, header); - - ecl_file_close(header); - - return true; - } else - return false; -} - -ecl_smspec_type *ecl_smspec_fread_alloc(const char *header_file, - const char *key_join_string, - bool include_restart) { - ecl_smspec_type *ecl_smspec; - - { - char *path; - util_alloc_file_components(header_file, &path, NULL, NULL); - ecl_smspec = ecl_smspec_alloc_empty(false, key_join_string); - free(path); - } - - if (ecl_smspec_fread_header(ecl_smspec, header_file, include_restart)) { - - const ecl::smspec_node *time_node = - ecl_smspec_get_var_node(ecl_smspec->misc_var_index, "TIME"); - if (time_node) { - const char *time_unit = time_node->get_unit(); - ecl_smspec->time_index = time_node->get_params_index(); - - if (util_string_equal(time_unit, "DAYS")) - ecl_smspec->time_seconds = 3600 * 24; - else if (util_string_equal(time_unit, "HOURS")) - ecl_smspec->time_seconds = 3600; - else - util_abort("%s: time_unit:%s not recognized \n", __func__, - time_unit); - } - - const ecl::smspec_node *day_node = - ecl_smspec_get_var_node(ecl_smspec->misc_var_index, "DAY"); - if (day_node != NULL) { - ecl_smspec->day_index = smspec_node_get_params_index(day_node); - ecl_smspec->month_index = smspec_node_get_params_index( - &ecl_smspec->misc_var_index["MONTH"]); - ecl_smspec->year_index = smspec_node_get_params_index( - &ecl_smspec->misc_var_index["YEAR"]); - } - - if ((ecl_smspec->time_index == -1) && (ecl_smspec->day_index == -1)) { - /* Unusable configuration. - - Seems the ECLIPSE file can also have time specified with - 'YEARS' as basic time unit; that mode is not supported. - */ - - util_abort("%s: Sorry the SMSPEC file seems to lack all time " - "information, need either TIME, or DAY/MONTH/YEAR " - "information. Can not proceed.", - __func__); - return NULL; - } - return ecl_smspec; - } else { - /** Failed to load from disk. */ - ecl_smspec_free(ecl_smspec); - return NULL; - } -} - -int ecl_smspec_get_num_groups(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->group_var_index.size(); -} - -/*char ** ecl_smspec_alloc_group_names(const ecl_smspec_type * ecl_smspec) { - return hash_alloc_keylist(ecl_smspec->group_var_index); -}*/ - -int ecl_smspec_get_num_regions(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->num_regions; -} - -/* - For each type of summary data (according to the types in - ecl_smcspec_var_type there are a set accessor functions: - - xx_get_xx: This function will take the apropriate input, and - return a double value. The function will fail with util_abort() - if the ecl_smspec object can not recognize the input. THis - function is not here. - - xxx_has_xx: Ths will return true / false depending on whether the - ecl_smspec object the variable we ask for. - - xxx_get_xxx_index: This function will rerturn an (internal) - integer index of where the variable in question is stored, this - index can then be subsequently used for faster lookup. If the - variable can not be found, the function will return -1. - - In general the index function is the real function, the others are - only wrappers around this. In addition there are specialized - functions, like get_well_names() and so on. -*/ - -namespace { - -bool node_exists(const ecl::smspec_node *node_ptr) { - if (node_ptr) - return true; - - return false; -} - -int node_valid_index(const ecl::smspec_node *node_ptr) { - if (node_ptr) - return node_ptr->get_params_index(); - - throw std::out_of_range("Invalid lookup summary object"); -} - -} // namespace - -const ecl::smspec_node & -ecl_smspec_get_well_var_node(const ecl_smspec_type *smspec, const char *well, - const char *var) { - const auto node_ptr = - ecl_smspec_get_str_key_var_node(smspec->well_var_index, well, var); - if (!node_ptr) - throw std::out_of_range("The well: " + std::string(well) + - " variable: " + std::string(var) + - " combination does not exist."); - - return *node_ptr; -} - -int ecl_smspec_get_well_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var) { - const auto node_ptr = - ecl_smspec_get_str_key_var_node(ecl_smspec->well_var_index, well, var); - return node_valid_index(node_ptr); -} - -bool ecl_smspec_has_well_var(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var) { - const auto node_ptr = - ecl_smspec_get_str_key_var_node(ecl_smspec->well_var_index, well, var); - return node_exists(node_ptr); -} - -const ecl::smspec_node & -ecl_smspec_get_group_var_node(const ecl_smspec_type *smspec, const char *group, - const char *var) { - const auto node_ptr = - ecl_smspec_get_str_key_var_node(smspec->group_var_index, group, var); - if (!node_ptr) - throw std::out_of_range("The group: " + std::string(group) + - " variable: " + std::string(var) + - " combination does not exist."); - - return *node_ptr; -} - -int ecl_smspec_get_group_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *group, const char *var) { - const auto node_ptr = ecl_smspec_get_str_key_var_node( - ecl_smspec->group_var_index, group, var); - return node_valid_index(node_ptr); -} - -bool ecl_smspec_has_group_var(const ecl_smspec_type *ecl_smspec, - const char *group, const char *var) { - const auto node_ptr = ecl_smspec_get_str_key_var_node( - ecl_smspec->group_var_index, group, var); - return node_exists(node_ptr); -} - -const ecl::smspec_node & -ecl_smspec_get_field_var_node(const ecl_smspec_type *ecl_smspec, - const char *var) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->field_var_index, var); - if (!node_ptr) - throw std::out_of_range("The field variable: " + std::string(var) + - " does not exist."); - - return *node_ptr; -} - -int ecl_smspec_get_field_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *var) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->field_var_index, var); - return node_valid_index(node_ptr); -} - -bool ecl_smspec_has_field_var(const ecl_smspec_type *ecl_smspec, - const char *var) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->field_var_index, var); - return node_exists(node_ptr); -} - -/** - Observe that block_nr is represented as char literal, - i.e. "2345". This is because it will be used as a hash key. - - This is the final low level function which actually consults the - hash tables. -*/ - -const ecl::smspec_node & -ecl_smspec_get_block_var_node(const ecl_smspec_type *ecl_smspec, - const char *block_var, int block_nr) { - const auto node_ptr = ecl_smspec_get_int_key_var_node( - ecl_smspec->block_var_index, block_nr, block_var); - if (!node_ptr) - throw std::out_of_range("No such block variable"); - - return *node_ptr; -} - -const ecl::smspec_node & -ecl_smspec_get_block_var_node_ijk(const ecl_smspec_type *ecl_smspec, - const char *block_var, int i, int j, int k) { - return ecl_smspec_get_block_var_node( - ecl_smspec, block_var, - ecl_smspec_get_global_grid_index(ecl_smspec, i, j, k)); -} - -bool ecl_smspec_has_block_var(const ecl_smspec_type *ecl_smspec, - const char *block_var, int block_nr) { - const auto node_ptr = ecl_smspec_get_int_key_var_node( - ecl_smspec->block_var_index, block_nr, block_var); - return node_exists(node_ptr); -} - -bool ecl_smspec_has_block_var_ijk(const ecl_smspec_type *ecl_smspec, - const char *block_var, int i, int j, int k) { - return ecl_smspec_has_block_var( - ecl_smspec, block_var, - ecl_smspec_get_global_grid_index(ecl_smspec, i, j, k)); -} - -int ecl_smspec_get_block_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *block_var, int block_nr) { - const auto node_ptr = ecl_smspec_get_int_key_var_node( - ecl_smspec->block_var_index, block_nr, block_var); - return node_valid_index(node_ptr); -} - -int ecl_smspec_get_block_var_params_index_ijk(const ecl_smspec_type *ecl_smspec, - const char *block_var, int i, - int j, int k) { - return ecl_smspec_get_block_var_params_index( - ecl_smspec, block_var, - ecl_smspec_get_global_grid_index(ecl_smspec, i, j, k)); -} - -/** - region_nr: [1...num_regions] (NOT C-based indexing) -*/ - -const ecl::smspec_node & -ecl_smspec_get_region_var_node(const ecl_smspec_type *ecl_smspec, - const char *region_var, int region_nr) { - const auto node_ptr = ecl_smspec_get_int_key_var_node( - ecl_smspec->region_var_index, region_nr, region_var); - if (!node_ptr) - throw std::out_of_range("No such block variable"); - - return *node_ptr; -} - -bool ecl_smspec_has_region_var(const ecl_smspec_type *ecl_smspec, - const char *region_var, int region_nr) { - const auto node_ptr = ecl_smspec_get_int_key_var_node( - ecl_smspec->region_var_index, region_nr, region_var); - return node_exists(node_ptr); -} - -int ecl_smspec_get_region_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *region_var, - int region_nr) { - const auto node_ptr = ecl_smspec_get_int_key_var_node( - ecl_smspec->region_var_index, region_nr, region_var); - return node_valid_index(node_ptr); -} - -const ecl::smspec_node & -ecl_smspec_get_misc_var_node(const ecl_smspec_type *ecl_smspec, - const char *var) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->misc_var_index, var); - if (!node_ptr) - throw std::out_of_range("No such misc variable"); - - return *node_ptr; -} - -bool ecl_smspec_has_misc_var(const ecl_smspec_type *ecl_smspec, - const char *var) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->misc_var_index, var); - return node_exists(node_ptr); -} - -int ecl_smspec_get_misc_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *var) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->misc_var_index, var); - return node_valid_index(node_ptr); -} - -const ecl::smspec_node * -ecl_smspec_get_well_completion_var_node__(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var, - int cell_nr) { - const auto well_iter = ecl_smspec->well_completion_var_index.find(well); - if (well_iter == ecl_smspec->well_completion_var_index.end()) - return nullptr; - - const auto &num_map = well_iter->second; - return ecl_smspec_get_int_key_var_node(num_map, cell_nr, var); -} - -const ecl::smspec_node & -ecl_smspec_get_well_completion_var_node(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var, - int cell_nr) { - const auto node_ptr = ecl_smspec_get_well_completion_var_node__( - ecl_smspec, well, var, cell_nr); - if (!node_ptr) - throw std::out_of_range("No such well/var/completion"); - - return *node_ptr; -} - -bool ecl_smspec_has_well_completion_var(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var, - int cell_nr) { - const auto node_ptr = ecl_smspec_get_well_completion_var_node__( - ecl_smspec, well, var, cell_nr); - return node_exists(node_ptr); -} - -int ecl_smspec_get_well_completion_var_params_index( - const ecl_smspec_type *ecl_smspec, const char *well, const char *var, - int cell_nr) { - const auto node_ptr = ecl_smspec_get_well_completion_var_node__( - ecl_smspec, well, var, cell_nr); - return node_valid_index(node_ptr); -} - -/* There is a quite wide range of error which are just returned as - "Not found" (i.e. -1). */ -/* Completions not supported yet. */ - -const ecl::smspec_node & -ecl_smspec_get_general_var_node(const ecl_smspec_type *smspec, - const char *lookup_kw) { - const auto node_ptr = - ecl_smspec_get_var_node(smspec->gen_var_index, lookup_kw); - if (!node_ptr) - throw std::out_of_range("No such variable: " + std::string(lookup_kw)); - - return *node_ptr; -} - -int ecl_smspec_get_general_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *lookup_kw) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->gen_var_index, lookup_kw); - return node_valid_index(node_ptr); -} - -bool ecl_smspec_has_general_var(const ecl_smspec_type *ecl_smspec, - const char *lookup_kw) { - const auto node_ptr = - ecl_smspec_get_var_node(ecl_smspec->gen_var_index, lookup_kw); - return node_exists(node_ptr); -} - -/** DIES if the lookup_kw is not present. */ -const char *ecl_smspec_get_general_var_unit(const ecl_smspec_type *ecl_smspec, - const char *lookup_kw) { - const auto smspec_node = - ecl_smspec_get_general_var_node(ecl_smspec, lookup_kw); - return smspec_node_get_unit(&smspec_node); -} - -int ecl_smspec_get_time_seconds(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->time_seconds; -} - -int ecl_smspec_get_time_index(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->time_index; -} - -time_t ecl_smspec_get_start_time(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->sim_start_time; -} - -bool ecl_smspec_get_formatted(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->formatted; -} - -const char *ecl_smspec_get_header_file(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->header_file.c_str(); -} - -int ecl_smspec_get_restart_step(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->restart_step; -} - -int ecl_smspec_get_first_step(const ecl_smspec_type *ecl_smspec) { - if (ecl_smspec->restart_step > 0) - return ecl_smspec->restart_step + 1; - else - return 1; -} - -const char *ecl_smspec_get_restart_case(const ecl_smspec_type *ecl_smspec) { - if (ecl_smspec->restart_case.size() > 0) - return ecl_smspec->restart_case.c_str(); - else - return NULL; -} - -const std::vector & -ecl_smspec_get_params_default(const ecl_smspec_type *ecl_smspec) { - return ecl_smspec->params_default; -} - -void ecl_smspec_free(ecl_smspec_type *ecl_smspec) { delete ecl_smspec; } - -void ecl_smspec_free__(void *__ecl_smspec) { - ecl_smspec_type *ecl_smspec = ecl_smspec_safe_cast(__ecl_smspec); - ecl_smspec_free(ecl_smspec); -} - -int ecl_smspec_get_date_day_index(const ecl_smspec_type *smspec) { - return smspec->day_index; -} - -int ecl_smspec_get_date_month_index(const ecl_smspec_type *smspec) { - return smspec->month_index; -} - -int ecl_smspec_get_date_year_index(const ecl_smspec_type *smspec) { - return smspec->year_index; -} - -/** - This function checks whether an input general key (i.e. FWPR or - GGPT:NORTH) represents an accumulated total. If the variable is not - internalized the function will fail hard. -*/ - -bool ecl_smspec_general_is_total(const ecl_smspec_type *smspec, - const char *gen_key) { - const ecl::smspec_node &smspec_node = - ecl_smspec_get_general_var_node(smspec, gen_key); - return smspec_node_is_total(&smspec_node); -} - -/** - Fills a stringlist instance with all the gen_key string matching - the supplied pattern. I.e. - - ecl_smspec_alloc_matching_general_var_list( smspec , "WGOR:*"); - - will give a list of WGOR for ALL the wells. The function is - unfortunately not as useful as one might think because ECLIPSE - will for instance happily give you the WOPR for a - water injector or WWIR for an oil producer. - - The function can be called several times with different patterns, - the stringlist is not cleared on startup; the keys in the list are - unique - keys are not added multiple times. If pattern == NULL all - keys will match. -*/ - -void ecl_smspec_select_matching_general_var_list(const ecl_smspec_type *smspec, - const char *pattern, - stringlist_type *keys) { - std::set ex_keys; - for (int i = 0; i < stringlist_get_size(keys); i++) - ex_keys.insert(stringlist_iget(keys, i)); - - { - for (const auto &pair : smspec->gen_var_index) { - const char *key = pair.first.c_str(); - - /* - The TIME is typically special cased by output and will not - match the 'all keys' wildcard. - */ - if (util_string_equal(key, "TIME")) { - if ((pattern == NULL) || (util_string_equal(pattern, "*"))) - continue; - } - - if ((pattern == NULL) || (util_fnmatch(pattern, key) == 0)) { - if (ex_keys.find(key) == ex_keys.end()) - stringlist_append_copy(keys, key); - } - } - } - - stringlist_sort(keys, (string_cmp_ftype *)util_strcmp_int); -} - -/** - Allocates a new stringlist and initializes it with the - ecl_smspec_select_matching_general_var_list() function. -*/ - -stringlist_type * -ecl_smspec_alloc_matching_general_var_list(const ecl_smspec_type *smspec, - const char *pattern) { - stringlist_type *keys = stringlist_alloc_new(); - ecl_smspec_select_matching_general_var_list(smspec, pattern, keys); - return keys; -} - -const char *ecl_smspec_get_join_string(const ecl_smspec_type *smspec) { - return smspec->key_join_string.c_str(); -} - -/** - Returns a stringlist instance with all the (valid) well names. It - is the responsability of the calling scope to free the stringlist - with stringlist_free(); - - - If @pattern is different from NULL only wells which 'match' the - pattern is included; if @pattern == NULL all wells are - included. The match is done with function fnmatch() - - i.e. standard shell wildcards. -*/ - -static stringlist_type * -ecl_smspec_alloc_map_list(const std::map &mp, - const char *pattern) { - stringlist_type *map_list = stringlist_alloc_new(); - - for (const auto &pair : mp) { - const char *map_name = pair.first.c_str(); - - if (pattern == NULL) - stringlist_append_copy(map_list, map_name); - else if (util_fnmatch(pattern, map_name) == 0) - stringlist_append_copy(map_list, map_name); - } - stringlist_sort(map_list, (string_cmp_ftype *)util_strcmp_int); - return map_list; -} - -stringlist_type *ecl_smspec_alloc_well_list(const ecl_smspec_type *smspec, - const char *pattern) { - return ecl_smspec_alloc_map_list(smspec->well_var_index, pattern); -} - -/** - Returns a stringlist instance with all the (valid) group names. It - is the responsability of the calling scope to free the stringlist - with stringlist_free(); -*/ - -stringlist_type *ecl_smspec_alloc_group_list(const ecl_smspec_type *smspec, - const char *pattern) { - return ecl_smspec_alloc_map_list(smspec->group_var_index, pattern); -} - -/** - Returns a stringlist instance with all the well variables. It is - the responsability of the calling scope to free the stringlist - with stringlist_free(); -*/ - -stringlist_type *ecl_smspec_alloc_well_var_list(const ecl_smspec_type *smspec) { - stringlist_type *stringlist = stringlist_alloc_new(); - for (const auto &pair : smspec->well_var_index) - stringlist_append_copy(stringlist, pair.first.c_str()); - - return stringlist; -} - -const int *ecl_smspec_get_grid_dims(const ecl_smspec_type *smspec) { - return smspec->grid_dims; -} - -char *ecl_smspec_alloc_well_key(const ecl_smspec_type *smspec, - const char *keyword, const char *wgname) { - return smspec_alloc_well_key(smspec->key_join_string.c_str(), keyword, - wgname); -} - -/*void ecl_smspec_sort( ecl_smspec_type * smspec ) { - std::sort(smspec->smspec_nodes.begin(), smspec->smspec_nodes.end(), smspec_node_lt); - - for (int i=0; i < static_cast(smspec->smspec_nodes.size()); i++) { - ecl::smspec_node& node = *smspec->smspec_nodes[i].get(); - smspec_node_set_params_index( &node , i ); - } -} -*/ - -ert_ecl_unit_enum ecl_smspec_get_unit_system(const ecl_smspec_type *smspec) { - return smspec->unit_system; -} diff --git a/lib/ecl/ecl_subsidence.cpp b/lib/ecl/ecl_subsidence.cpp deleted file mode 100644 index c2d41a220b..0000000000 --- a/lib/ecl/ecl_subsidence.cpp +++ /dev/null @@ -1,340 +0,0 @@ -#include -#define _USE_MATH_DEFINES // for C WINDOWS -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "detail/ecl/ecl_grid_cache.hpp" - -/** - This file contains datastructures for calculating changes in - subsidence from compression of reservoirs. The main datastructure is the - ecl_subsidence_type structure (which is the only structure which is - exported). -*/ - -/** - The ecl_subsidence_struct datastructure is the main structure for - calculating the subsidence from time lapse ECLIPSE simulations. -*/ - -struct ecl_subsidence_struct { - const ecl_file_type * - init_file; /* The init file - a shared reference owned by calling scope. */ - ecl::ecl_grid_cache *grid_cache; - bool *aquifer_cell; - hash_type * - surveys; /* A hash table containg ecl_subsidence_survey_type instances; one instance - for each interesting time. */ - double *compressibility; /*total compressibility*/ - double *poisson_ratio; -}; - -/** - Data structure representing one subsidence survey. -*/ - -#define ECL_SUBSIDENCE_SURVEY_ID 88517 -struct ecl_subsidence_survey_struct { - UTIL_TYPE_ID_DECLARATION; - const ecl::ecl_grid_cache *grid_cache; - const bool * - aquifer_cell; /* Is this cell a numerical aquifer cell - must be disregarded. */ - char *name; /* Name of the survey - arbitrary string. */ - double *porv; /* Reference pore volume */ - double *pressure; /* Pressure in each grid cell at survey time */ - double - *dynamic_porevolume; /* Porevolume in each grid cell at survey time */ -}; - -static ecl_subsidence_survey_type * -ecl_subsidence_survey_alloc_empty(const ecl_subsidence_type *sub, - const char *name) { - ecl_subsidence_survey_type *survey = - (ecl_subsidence_survey_type *)util_malloc(sizeof *survey); - UTIL_TYPE_ID_INIT(survey, ECL_SUBSIDENCE_SURVEY_ID); - survey->grid_cache = sub->grid_cache; - survey->aquifer_cell = sub->aquifer_cell; - survey->name = util_alloc_string_copy(name); - - survey->porv = - (double *)util_calloc(sub->grid_cache->size(), sizeof *survey->porv); - survey->pressure = (double *)util_calloc(sub->grid_cache->size(), - sizeof *survey->pressure); - survey->dynamic_porevolume = NULL; - - return survey; -} - -static UTIL_SAFE_CAST_FUNCTION(ecl_subsidence_survey, ECL_SUBSIDENCE_SURVEY_ID) - - static ecl_subsidence_survey_type *ecl_subsidence_survey_alloc_PRESSURE( - ecl_subsidence_type *ecl_subsidence, - const ecl_file_view_type *restart_view, const char *name) { - - ecl_subsidence_survey_type *survey = - ecl_subsidence_survey_alloc_empty(ecl_subsidence, name); - const ecl::ecl_grid_cache &grid_cache = *(ecl_subsidence->grid_cache); - const auto &global_index = grid_cache.global_index(); - const int size = grid_cache.size(); - - int active_index; - ecl_kw_type *init_porv_kw = ecl_file_iget_named_kw( - ecl_subsidence->init_file, PORV_KW, 0); /*Global indexing*/ - ecl_kw_type *pressure_kw = ecl_file_view_iget_named_kw( - restart_view, PRESSURE_KW, 0); /*Active indexing*/ - - ecl_kw_type *rporv_kw = NULL; - if (ecl_file_view_has_kw(restart_view, RPORV_KW)) { - survey->dynamic_porevolume = - (double *)util_calloc(ecl_subsidence->grid_cache->size(), - sizeof *survey->dynamic_porevolume); - rporv_kw = ecl_file_view_iget_named_kw(restart_view, RPORV_KW, 0); - } - - for (active_index = 0; active_index < size; active_index++) { - survey->porv[active_index] = - ecl_kw_iget_float(init_porv_kw, global_index[active_index]); - survey->pressure[active_index] = - ecl_kw_iget_float(pressure_kw, active_index); - - if (rporv_kw) - survey->dynamic_porevolume[active_index] = - ecl_kw_iget_float(rporv_kw, active_index); - } - return survey; -} - -static void -ecl_subsidence_survey_free(ecl_subsidence_survey_type *subsidence_survey) { - free(subsidence_survey->name); - free(subsidence_survey->porv); - free(subsidence_survey->pressure); - free(subsidence_survey->dynamic_porevolume); - free(subsidence_survey); -} - -static void ecl_subsidence_survey_free__(void *__subsidence_survey) { - ecl_subsidence_survey_type *subsidence_survey = - ecl_subsidence_survey_safe_cast(__subsidence_survey); - ecl_subsidence_survey_free(subsidence_survey); -} - -static double -ecl_subsidence_survey_eval(const ecl_subsidence_survey_type *base_survey, - const ecl_subsidence_survey_type *monitor_survey, - ecl_region_type *region, double utm_x, double utm_y, - double depth, double compressibility, - double poisson_ratio) { - - const ecl::ecl_grid_cache &grid_cache = *(base_survey->grid_cache); - const int size = grid_cache.size(); - double *weight = (double *)util_calloc(size, sizeof *weight); - double deltaz; - int index; - - if (monitor_survey != NULL) { - for (index = 0; index < size; index++) - weight[index] = - base_survey->porv[index] * (base_survey->pressure[index] - - monitor_survey->pressure[index]); - } else { - for (index = 0; index < size; index++) - weight[index] = - base_survey->porv[index] * base_survey->pressure[index]; - } - - deltaz = compressibility * 31.83099 * (1 - poisson_ratio) * - ecl_grav_common_eval_biot_savart(grid_cache, region, - base_survey->aquifer_cell, weight, - utm_x, utm_y, depth); - - free(weight); - return deltaz; -} - -static double ecl_subsidence_survey_eval_geertsma( - const ecl_subsidence_survey_type *base_survey, - const ecl_subsidence_survey_type *monitor_survey, ecl_region_type *region, - double utm_x, double utm_y, double depth, double youngs_modulus, - double poisson_ratio, double seabed) { - - const ecl::ecl_grid_cache &grid_cache = *(base_survey->grid_cache); - const auto &cell_volume = grid_cache.volume(); - const int size = grid_cache.size(); - double scale_factor = 1e4 * (1 + poisson_ratio) * (1 - 2 * poisson_ratio) / - (4 * M_PI * (1 - poisson_ratio) * youngs_modulus); - double *weight = (double *)util_calloc(size, sizeof *weight); - double deltaz; - - for (int index = 0; index < size; index++) { - if (monitor_survey) { - weight[index] = scale_factor * cell_volume[index] * - (base_survey->pressure[index] - - monitor_survey->pressure[index]); - } else { - weight[index] = scale_factor * cell_volume[index] * - (base_survey->pressure[index]); - } - } - - deltaz = ecl_grav_common_eval_geertsma( - grid_cache, region, base_survey->aquifer_cell, weight, utm_x, utm_y, - depth, poisson_ratio, seabed); - - free(weight); - return deltaz; -} - -static double ecl_subsidence_survey_eval_geertsma_rporv( - const ecl_subsidence_survey_type *base_survey, - const ecl_subsidence_survey_type *monitor_survey, ecl_region_type *region, - double utm_x, double utm_y, double depth, double youngs_modulus, - double poisson_ratio, double seabed) { - - const ecl::ecl_grid_cache &grid_cache = *(base_survey->grid_cache); - std::vector weight(grid_cache.size()); - - if (!base_survey->dynamic_porevolume) { - util_abort( - "%s: Keyword RPORV not defined in .UNRST file for %s. Please add " - "RPORV keyword to output in RPTRST clause in .DATA file.\n", - __func__, base_survey->name); - } - - if (monitor_survey && !monitor_survey->dynamic_porevolume) { - util_abort( - "%s: Keyword RPORV not defined in .UNRST file for %s. Please add " - "RPORV keyword to output in RPTRST clause in .DATA file.\n", - __func__, monitor_survey->name); - } - - for (size_t index = 0; index < weight.size(); ++index) { - if (monitor_survey) - weight[index] = (base_survey->dynamic_porevolume[index] - - monitor_survey->dynamic_porevolume[index]) / - (4 * M_PI); - else - weight[index] = base_survey->dynamic_porevolume[index] / (4 * M_PI); - } - - return ecl_grav_common_eval_geertsma( - grid_cache, region, base_survey->aquifer_cell, weight.data(), utm_x, - utm_y, depth, poisson_ratio, seabed); -} - -/** - The grid instance is only used during the construction phase. The - @init_file object is used by the ecl_subsidence_add_survey_XXX() - functions; and calling scope must NOT destroy this object before - all surveys have been added. -*/ - -ecl_subsidence_type *ecl_subsidence_alloc(const ecl_grid_type *ecl_grid, - const ecl_file_type *init_file) { - ecl_subsidence_type *ecl_subsidence = - (ecl_subsidence_type *)util_malloc(sizeof *ecl_subsidence); - ecl_subsidence->init_file = init_file; - ecl_subsidence->grid_cache = new ecl::ecl_grid_cache(ecl_grid); - ecl_subsidence->aquifer_cell = ecl_grav_common_alloc_aquifer_cell( - *(ecl_subsidence->grid_cache), init_file); - - ecl_subsidence->surveys = hash_alloc(); - return ecl_subsidence; -} - -static void ecl_subsidence_add_survey__(ecl_subsidence_type *subsidence, - const char *name, - ecl_subsidence_survey_type *survey) { - hash_insert_hash_owned_ref(subsidence->surveys, name, survey, - ecl_subsidence_survey_free__); -} - -ecl_subsidence_survey_type * -ecl_subsidence_add_survey_PRESSURE(ecl_subsidence_type *subsidence, - const char *name, - const ecl_file_view_type *restart_view) { - ecl_subsidence_survey_type *survey = - ecl_subsidence_survey_alloc_PRESSURE(subsidence, restart_view, name); - ecl_subsidence_add_survey__(subsidence, name, survey); - return survey; -} - -bool ecl_subsidence_has_survey(const ecl_subsidence_type *subsidence, - const char *name) { - return hash_has_key(subsidence->surveys, name); -} - -static ecl_subsidence_survey_type * -ecl_subsidence_get_survey(const ecl_subsidence_type *subsidence, - const char *name) { - if (name == NULL) - return NULL; // Calling scope must determine if this is OK? - else - return (ecl_subsidence_survey_type *)hash_get(subsidence->surveys, - name); -} - -double ecl_subsidence_eval(const ecl_subsidence_type *subsidence, - const char *base, const char *monitor, - ecl_region_type *region, double utm_x, double utm_y, - double depth, double compressibility, - double poisson_ratio) { - ecl_subsidence_survey_type *base_survey = - ecl_subsidence_get_survey(subsidence, base); - ecl_subsidence_survey_type *monitor_survey = - ecl_subsidence_get_survey(subsidence, monitor); - return ecl_subsidence_survey_eval(base_survey, monitor_survey, region, - utm_x, utm_y, depth, compressibility, - poisson_ratio); -} - -double ecl_subsidence_eval_geertsma(const ecl_subsidence_type *subsidence, - const char *base, const char *monitor, - ecl_region_type *region, double utm_x, - double utm_y, double depth, - double youngs_modulus, double poisson_ratio, - double seabed) { - ecl_subsidence_survey_type *base_survey = - ecl_subsidence_get_survey(subsidence, base); - ecl_subsidence_survey_type *monitor_survey = - ecl_subsidence_get_survey(subsidence, monitor); - return ecl_subsidence_survey_eval_geertsma( - base_survey, monitor_survey, region, utm_x, utm_y, depth, - youngs_modulus, poisson_ratio, seabed); -} - -double ecl_subsidence_eval_geertsma_rporv(const ecl_subsidence_type *subsidence, - const char *base, const char *monitor, - ecl_region_type *region, double utm_x, - double utm_y, double depth, - double youngs_modulus, - double poisson_ratio, double seabed) { - ecl_subsidence_survey_type *base_survey = - ecl_subsidence_get_survey(subsidence, base); - ecl_subsidence_survey_type *monitor_survey = - ecl_subsidence_get_survey(subsidence, monitor); - return ecl_subsidence_survey_eval_geertsma_rporv( - base_survey, monitor_survey, region, utm_x, utm_y, depth, - youngs_modulus, poisson_ratio, seabed); -} - -void ecl_subsidence_free(ecl_subsidence_type *ecl_subsidence) { - delete ecl_subsidence->grid_cache; - - free(ecl_subsidence->aquifer_cell); - hash_free(ecl_subsidence->surveys); - free(ecl_subsidence); -} diff --git a/lib/ecl/ecl_sum.cpp b/lib/ecl/ecl_sum.cpp deleted file mode 100644 index fc74662398..0000000000 --- a/lib/ecl/ecl_sum.cpp +++ /dev/null @@ -1,1560 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include "detail/util/path.hpp" - -/** - The ECLIPSE summary data is organised in a header file (.SMSPEC) - and the actual summary data. This file implements a data structure - ecl_sum_type which holds ECLIPSE summary data. Most of the actual - implementation is in separate files ecl_smspec.c for the SMSPEC - header, and ecl_sum_data for the actual data. - - Observe that this datastructure is built up around internalizing - ECLIPSE summary data, the code has NO AMBITION of being able to - write summary data. - - - Header in ECLIPSE.SMSPEC file Actual data; many 'PARAMS' blocks in .Snnnn or .UNSMRY file - - ------------------------------......... ----------- ----------- ----------- ----------- ----------- - | WGNAMES KEYWORDS NUMS | INDEX : | PARAMS | | PARAMS | | PARAMS | | PARAMS | | PARAMS | - |----------------------------|........: |---------| |---------| |---------| |---------| |---------| - | OP-1 WOPR X | 0 : | 652 | | 752 | | 862 | | 852 | | 962 | - | OP-1 WWPR X | 1 : | 45 | | 47 | | 55 | | 59 | | 62 | - | GI-1 WGIR X | 2 : | 500 | | 500 | | 786 | | 786 | | 486 | - | :+:+:+:+ FOPT X | 3 : | 7666 | | 7666 | | 8811 | | 7688 | | 8649 | - | :+:+:+:+ RPR 5 | 4 : | 255 | | 255 | | 266 | | 257 | | 277 | - | :+:+:+:+ BPR 3457 | 5 : | 167 | | 167 | | 189 | | 201 | | 166 | - ------------------------------......... ----------- ----------- ----------- ----------- ----------- - - <------------------------ Time direction -------------------------> - - As illustrated in the figure above header information is stored in - the SMSPEC file; the header information is organised in several - keywords; at least the WGNAMES and KEYWORDS arrays, and often also - the NUMS array. Together these three arrays uniquely specify a - summary vector. - - The INDEX column in the header information is NOT part of the - SMSPEC file, but an important part of the ecl_smspec - implementation. The the values from WGNAMES/KEYWORDS/NUMS are - combined to create a unique key; and the corresponding index is - used to lookup a numerical value from the PARAMS vector with actual - data. - - These matters are documented further in the ecl_smspec.c and - ecl_sum_data.c files. -*/ - -#define ECL_SUM_ID 89067 - -struct ecl_sum_struct { - UTIL_TYPE_ID_DECLARATION; - ecl_smspec_type *smspec; /* Internalized version of the SMSPEC file. */ - ecl_sum_data_type *data; /* The data - can be NULL. */ - ecl_sum_type *restart_case; - - bool fmt_case; - bool unified; - char *key_join_string; - char * - path; /* The path - as given for the case input. Can be NULL for cwd. */ - char *abs_path; /* Absolute path. */ - char *base; /* Only the basename. */ - char * - ecl_case; /* This is the current case, with optional path component. == path + base*/ - char * - ext; /* Only to support selective loading of formatted|unformatted and unified|multiple. (can be NULL) */ -}; - -UTIL_SAFE_CAST_FUNCTION(ecl_sum, ECL_SUM_ID); -UTIL_IS_INSTANCE_FUNCTION(ecl_sum, ECL_SUM_ID); - -/** - Reads the data from ECLIPSE summary files, can either be a list of - files BASE.S0000, BASE.S0001, BASE.S0002,.. or one unified - file. Formatted/unformatted is detected automagically. - - The actual loading is implemented in the ecl_sum_data.c file. -*/ - -void ecl_sum_set_case(ecl_sum_type *ecl_sum, const char *input_arg) { - free(ecl_sum->ecl_case); - free(ecl_sum->path); - free(ecl_sum->abs_path); - free(ecl_sum->base); - free(ecl_sum->ext); - { - std::string path = ecl::util::path::dirname(input_arg); - std::string base = ecl::util::path::basename(input_arg); - std::string ext = ecl::util::path::extension(input_arg); - - ecl_sum->ecl_case = - util_alloc_filename(path.c_str(), base.c_str(), NULL); - if (path.size()) - ecl_sum->path = util_alloc_string_copy(path.c_str()); - else - ecl_sum->path = NULL; - - if (base.size()) - ecl_sum->base = util_alloc_string_copy(base.c_str()); - else - ecl_sum->base = NULL; - - if (ext.size()) - ecl_sum->ext = util_alloc_string_copy(ext.c_str()); - else - ecl_sum->ext = NULL; - - if (path.size() > 0) - ecl_sum->abs_path = util_alloc_abs_path(path.c_str()); - else - ecl_sum->abs_path = util_alloc_cwd(); - } -} - -static ecl_sum_type *ecl_sum_alloc__(const char *input_arg, - const char *key_join_string) { - if (!ecl_util_path_access(input_arg)) - return NULL; - - ecl_sum_type *ecl_sum = (ecl_sum_type *)util_malloc(sizeof *ecl_sum); - UTIL_TYPE_ID_INIT(ecl_sum, ECL_SUM_ID); - - ecl_sum->ecl_case = NULL; - ecl_sum->path = NULL; - ecl_sum->base = NULL; - ecl_sum->ext = NULL; - ecl_sum->abs_path = NULL; - ecl_sum_set_case(ecl_sum, input_arg); - ecl_sum->key_join_string = util_alloc_string_copy(key_join_string); - - ecl_sum->smspec = NULL; - ecl_sum->data = NULL; - ecl_sum->restart_case = NULL; - - return ecl_sum; -} - -static bool ecl_sum_fread_data(ecl_sum_type *ecl_sum, - const stringlist_type *data_files, - bool include_restart, bool lazy_load, - int file_options) { - if (ecl_sum->data != NULL) - ecl_sum_free_data(ecl_sum); - - ecl_sum->data = ecl_sum_data_alloc(ecl_sum->smspec); - return ecl_sum_data_fread(ecl_sum->data, data_files, lazy_load, - file_options); -} - -static void ecl_sum_fread_history(ecl_sum_type *ecl_sum, bool lazy_load, - int file_options) { - char *restart_header = ecl_util_alloc_filename( - NULL, ecl_smspec_get_restart_case(ecl_sum->smspec), - ECL_SUMMARY_HEADER_FILE, ecl_smspec_get_formatted(ecl_sum->smspec), -1); - ecl_sum_type *restart_case = ecl_sum_fread_alloc_case2__( - restart_header, ":", true, lazy_load, file_options); - if (restart_case) { - ecl_sum->restart_case = restart_case; - ecl_sum_data_add_case(ecl_sum->data, restart_case->data); - } - free(restart_header); -} - -static bool ecl_sum_fread(ecl_sum_type *ecl_sum, const char *header_file, - const stringlist_type *data_files, - bool include_restart, bool lazy_load, - int file_options) { - ecl_sum->smspec = ecl_smspec_fread_alloc( - header_file, ecl_sum->key_join_string, include_restart); - if (ecl_sum->smspec) { - bool fmt_file; - ecl_util_get_file_type(header_file, &fmt_file, NULL); - ecl_sum_set_fmt_case(ecl_sum, fmt_file); - } else - return false; - - if (ecl_sum_fread_data(ecl_sum, data_files, include_restart, lazy_load, - file_options)) { - ecl_file_enum file_type = - ecl_util_get_file_type(stringlist_iget(data_files, 0), NULL, NULL); - - if (file_type == ECL_SUMMARY_FILE) - ecl_sum_set_unified(ecl_sum, false); - else if (file_type == ECL_UNIFIED_SUMMARY_FILE) - ecl_sum_set_unified(ecl_sum, true); - else - util_abort("%s: FileTypeError, should be ECL_SUMMARY_FILE OR " - "ECL_UNIFIED_SUMMARY_FILE \n", - __func__); - } else - return false; - - if (include_restart && ecl_smspec_get_restart_case(ecl_sum->smspec)) - ecl_sum_fread_history(ecl_sum, lazy_load, file_options); - - return true; -} - -static bool ecl_sum_fread_case(ecl_sum_type *ecl_sum, bool include_restart, - bool lazy_load, int file_options) { - char *header_file; - stringlist_type *summary_file_list = stringlist_alloc_new(); - - bool caseOK = false; - - ecl_util_alloc_summary_files(ecl_sum->path, ecl_sum->base, ecl_sum->ext, - &header_file, summary_file_list); - if ((header_file != NULL) && (stringlist_get_size(summary_file_list) > 0)) { - caseOK = ecl_sum_fread(ecl_sum, header_file, summary_file_list, - include_restart, lazy_load, file_options); - } - free(header_file); - stringlist_free(summary_file_list); - - return caseOK; -} - -/** - This will explicitly load the summary specified by @header_file and - @data_files, i.e. if the case has been restarted from another case, - it will NOT look for old summary information - that functionality - is only invoked when using ecl_sum_fread_alloc_case() function; - however the list of data_files could in principle be achieved by - initializing the data_files list with files from the restarted - case. -*/ - -ecl_sum_type *ecl_sum_fread_alloc(const char *header_file, - const stringlist_type *data_files, - const char *key_join_string, - bool include_restart, bool lazy_load, - int file_options) { - ecl_sum_type *ecl_sum = ecl_sum_alloc__(header_file, key_join_string); - if (ecl_sum) { - if (!ecl_sum_fread(ecl_sum, header_file, data_files, include_restart, - lazy_load, file_options)) { - ecl_sum_free(ecl_sum); - ecl_sum = NULL; - } - } - return ecl_sum; -} - -void ecl_sum_set_unified(ecl_sum_type *ecl_sum, bool unified) { - ecl_sum->unified = unified; -} - -void ecl_sum_set_fmt_case(ecl_sum_type *ecl_sum, bool fmt_case) { - ecl_sum->fmt_case = fmt_case; -} - -const ecl::smspec_node *ecl_sum_add_var(ecl_sum_type *ecl_sum, - const char *keyword, const char *wgname, - int num, const char *unit, - float default_value) { - if (ecl_sum_data_get_length(ecl_sum->data) > 0) - throw std::invalid_argument( - "Can not interchange variable adding and timesteps.\n"); - - return ecl_smspec_add_node(ecl_sum->smspec, keyword, wgname, num, unit, - default_value); -} - -const ecl::smspec_node *ecl_sum_add_smspec_node(ecl_sum_type *ecl_sum, - const ecl::smspec_node *node) { - return ecl_smspec_add_node(ecl_sum->smspec, *node); -} - -/* - Observe the time argument in ecl_sum_add_tstep() and the bool flag - time_in_days in ecl_sum_alloc_writer() can be misleading: - - - The time argument 'sim_seconds' to ecl_sum_add_tstep() should - *ALWAYS* be in seconds. - - - The 'sim_in_days' argument to the ecl_sum_alloc_writer( ) is just - a very very basic unit support in the output. If sim_in_days == - true the output time unit will be days, otherwise it will be hours. -*/ - -ecl_sum_tstep_type *ecl_sum_add_tstep(ecl_sum_type *ecl_sum, int report_step, - double sim_seconds) { - ecl_sum_tstep_type *new_tstep = - ecl_sum_data_add_new_tstep(ecl_sum->data, report_step, sim_seconds); - return new_tstep; -} - -static ecl_sum_type * -ecl_sum_alloc_writer__(const char *ecl_case, const char *restart_case, - int restart_step, bool fmt_output, bool unified, - const char *key_join_string, time_t sim_start, - bool time_in_days, int nx, int ny, int nz) { - - ecl_sum_type *ecl_sum = ecl_sum_alloc__(ecl_case, key_join_string); - if (ecl_sum) { - ecl_sum_set_unified(ecl_sum, unified); - ecl_sum_set_fmt_case(ecl_sum, fmt_output); - - if (restart_case) - ecl_sum->smspec = ecl_smspec_alloc_restart_writer( - key_join_string, restart_case, restart_step, sim_start, - time_in_days, nx, ny, nz); - else - ecl_sum->smspec = ecl_smspec_alloc_writer( - key_join_string, sim_start, time_in_days, nx, ny, nz); - - ecl_sum->data = ecl_sum_data_alloc_writer(ecl_sum->smspec); - } - return ecl_sum; -} - -ecl_sum_type * -ecl_sum_alloc_restart_writer2(const char *ecl_case, const char *restart_case, - int restart_step, bool fmt_output, bool unified, - const char *key_join_string, time_t sim_start, - bool time_in_days, int nx, int ny, int nz) { - return ecl_sum_alloc_writer__(ecl_case, restart_case, restart_step, - fmt_output, unified, key_join_string, - sim_start, time_in_days, nx, ny, nz); -} - -/* - This does not take in the restart_step argument is depcrecated. You should use the - ecl_sum_alloc_restart_writer2() function. -*/ - -ecl_sum_type *ecl_sum_alloc_restart_writer(const char *ecl_case, - const char *restart_case, - bool fmt_output, bool unified, - const char *key_join_string, - time_t sim_start, bool time_in_days, - int nx, int ny, int nz) { - int restart_step = 0; - return ecl_sum_alloc_writer__(ecl_case, restart_case, restart_step, - fmt_output, unified, key_join_string, - sim_start, time_in_days, nx, ny, nz); -} - -ecl_sum_type *ecl_sum_alloc_writer(const char *ecl_case, bool fmt_output, - bool unified, const char *key_join_string, - time_t sim_start, bool time_in_days, int nx, - int ny, int nz) { - return ecl_sum_alloc_writer__(ecl_case, NULL, 0, fmt_output, unified, - key_join_string, sim_start, time_in_days, nx, - ny, nz); -} - -void ecl_sum_fwrite(const ecl_sum_type *ecl_sum) { - ecl_sum_fwrite_smspec(ecl_sum); - ecl_sum_data_fwrite(ecl_sum->data, ecl_sum->ecl_case, ecl_sum->fmt_case, - ecl_sum->unified); -} - -bool ecl_sum_can_write(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_can_write(ecl_sum->data); -} - -void ecl_sum_fwrite_smspec(const ecl_sum_type *ecl_sum) { - ecl_smspec_fwrite(ecl_sum->smspec, ecl_sum->ecl_case, ecl_sum->fmt_case); -} - -/** - This function frees the data from the ecl_sum instance and sets the - data pointer to NULL. The SMSPEC data is still valid, and can be - reused with calls to ecl_sum_fread_realloc_data(). -*/ - -void ecl_sum_free_data(ecl_sum_type *ecl_sum) { - ecl_sum_data_free(ecl_sum->data); - ecl_sum->data = NULL; -} - -void ecl_sum_free(ecl_sum_type *ecl_sum) { - if (ecl_sum->restart_case) - ecl_sum_free(ecl_sum->restart_case); - - if (ecl_sum->data) - ecl_sum_free_data(ecl_sum); - - if (ecl_sum->smspec) - ecl_smspec_free(ecl_sum->smspec); - - free(ecl_sum->path); - free(ecl_sum->ext); - free(ecl_sum->abs_path); - - free(ecl_sum->base); - free(ecl_sum->ecl_case); - - free(ecl_sum->key_join_string); - free(ecl_sum); -} - -void ecl_sum_free__(void *__ecl_sum) { - ecl_sum_type *ecl_sum = ecl_sum_safe_cast(__ecl_sum); - ecl_sum_free(ecl_sum); -} - -/** - This function takes an input file, and loads the corresponding - summary. The function extracts the path part, and the basename from - the input file. The extension is not considered (the input need not - even be a valid file). In principle a simulation directory with a - given basename can contain four different simulation cases: - - * Formatted and unformatted. - * Unified and not unified. - - The program will load the most recent dataset, by looking at the - modification time stamps of the files; if no simulation case is - found the function will return NULL. - - If the SMSPEC file contains the RESTART keyword the function will - iterate backwards to load summary information from previous runs - (this is goverened by the local variable include_restart). -*/ - -ecl_sum_type *ecl_sum_fread_alloc_case2__(const char *input_file, - const char *key_join_string, - bool include_restart, bool lazy_load, - int file_options) { - ecl_sum_type *ecl_sum = ecl_sum_alloc__(input_file, key_join_string); - if (!ecl_sum) - return NULL; - - if (ecl_sum_fread_case(ecl_sum, include_restart, lazy_load, file_options)) - return ecl_sum; - else { - /* - Loading a case failed - we discard the partly initialized - ecl_sum structure and jump ship. - */ - ecl_sum_free(ecl_sum); - return NULL; - } -} - -ecl_sum_type *ecl_sum_fread_alloc_case__(const char *input_file, - const char *key_join_string, - bool include_restart) { - bool lazy_load = true; - int file_options = 0; - return ecl_sum_fread_alloc_case2__( - input_file, key_join_string, include_restart, lazy_load, file_options); -} - -ecl_sum_type *ecl_sum_fread_alloc_case(const char *input_file, - const char *key_join_string) { - bool include_restart = true; - bool lazy_load = true; - int file_options = 0; - return ecl_sum_fread_alloc_case2__( - input_file, key_join_string, include_restart, lazy_load, file_options); -} - -bool ecl_sum_case_exists(const char *input_file) { - char *smspec_file = NULL; - stringlist_type *data_files = stringlist_alloc_new(); - char *path; - char *basename; - char *extension; - bool case_exists; - - util_alloc_file_components(input_file, &path, &basename, &extension); - case_exists = ecl_util_alloc_summary_files(path, basename, extension, - &smspec_file, data_files); - - free(path); - free(basename); - free(extension); - free(smspec_file); - stringlist_free(data_files); - - return case_exists; -} - -double ecl_sum_get_from_sim_time(const ecl_sum_type *ecl_sum, time_t sim_time, - const ecl::smspec_node *node) { - return ecl_sum_data_get_from_sim_time(ecl_sum->data, sim_time, *node); -} - -double ecl_sum_get_from_sim_days(const ecl_sum_type *ecl_sum, double sim_days, - const ecl::smspec_node *node) { - return ecl_sum_data_get_from_sim_days(ecl_sum->data, sim_days, *node); -} - -double ecl_sum_time2days(const ecl_sum_type *ecl_sum, time_t sim_time) { - return ecl_sum_data_time2days(ecl_sum->data, sim_time); -} - -bool ecl_sum_has_well_var(const ecl_sum_type *ecl_sum, const char *well, - const char *var) { - return ecl_smspec_has_well_var(ecl_sum->smspec, well, var); -} - -double ecl_sum_get_well_var(const ecl_sum_type *ecl_sum, int time_index, - const char *well, const char *var) { - int params_index = - ecl_smspec_get_well_var_params_index(ecl_sum->smspec, well, var); - return ecl_sum_data_iget(ecl_sum->data, time_index, params_index); -} - -double ecl_sum_get_well_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *well, - const char *var) { - const ecl::smspec_node &node = - ecl_smspec_get_well_var_node(ecl_sum->smspec, well, var); - return ecl_sum_get_from_sim_time(ecl_sum, sim_time, &node); -} - -double ecl_sum_get_well_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *well, - const char *var) { - const ecl::smspec_node &node = - ecl_smspec_get_well_var_node(ecl_sum->smspec, well, var); - return ecl_sum_get_from_sim_days(ecl_sum, sim_days, &node); -} - -bool ecl_sum_has_group_var(const ecl_sum_type *ecl_sum, const char *group, - const char *var) { - return ecl_smspec_has_group_var(ecl_sum->smspec, group, var); -} - -double ecl_sum_get_group_var(const ecl_sum_type *ecl_sum, int time_index, - const char *group, const char *var) { - int params_index = - ecl_smspec_get_group_var_params_index(ecl_sum->smspec, group, var); - return ecl_sum_data_iget(ecl_sum->data, time_index, params_index); -} - -double ecl_sum_get_group_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *group, - const char *var) { - const ecl::smspec_node &node = - ecl_smspec_get_group_var_node(ecl_sum->smspec, group, var); - return ecl_sum_get_from_sim_time(ecl_sum, sim_time, &node); -} - -double ecl_sum_get_group_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *group, - const char *var) { - const ecl::smspec_node &node = - ecl_smspec_get_group_var_node(ecl_sum->smspec, group, var); - return ecl_sum_get_from_sim_days(ecl_sum, sim_days, &node); -} - -bool ecl_sum_has_field_var(const ecl_sum_type *ecl_sum, const char *var) { - return ecl_smspec_has_field_var(ecl_sum->smspec, var); -} - -double ecl_sum_get_field_var(const ecl_sum_type *ecl_sum, int time_index, - const char *var) { - int params_index = - ecl_smspec_get_field_var_params_index(ecl_sum->smspec, var); - return ecl_sum_data_iget(ecl_sum->data, time_index, params_index); -} - -double ecl_sum_get_field_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *var) { - const ecl::smspec_node &node = - ecl_smspec_get_field_var_node(ecl_sum->smspec, var); - return ecl_sum_get_from_sim_time(ecl_sum, sim_time, &node); -} - -double ecl_sum_get_field_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *var) { - const ecl::smspec_node &node = - ecl_smspec_get_field_var_node(ecl_sum->smspec, var); - return ecl_sum_get_from_sim_days(ecl_sum, sim_days, &node); -} - -bool ecl_sum_has_block_var(const ecl_sum_type *ecl_sum, const char *block_var, - int block_nr) { - return ecl_smspec_has_block_var(ecl_sum->smspec, block_var, block_nr); -} - -double ecl_sum_get_block_var(const ecl_sum_type *ecl_sum, int time_index, - const char *block_var, int block_nr) { - int params_index = ecl_smspec_get_block_var_params_index( - ecl_sum->smspec, block_var, block_nr); - return ecl_sum_data_iget(ecl_sum->data, time_index, params_index); -} - -int ecl_sum_get_block_var_index_ijk(const ecl_sum_type *ecl_sum, - const char *block_var, int i, int j, - int k) { - return ecl_smspec_get_block_var_params_index_ijk(ecl_sum->smspec, block_var, - i, j, k); -} - -bool ecl_sum_has_block_var_ijk(const ecl_sum_type *ecl_sum, - const char *block_var, int i, int j, int k) { - return ecl_smspec_has_block_var_ijk(ecl_sum->smspec, block_var, i, j, k); -} - -double ecl_sum_get_block_var_ijk(const ecl_sum_type *ecl_sum, int time_index, - const char *block_var, int i, int j, int k) { - int index = ecl_sum_get_block_var_index_ijk(ecl_sum, block_var, i, j, k); - return ecl_sum_data_iget(ecl_sum->data, time_index, index); -} - -double ecl_sum_get_block_var_ijk_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, - const char *block_var, int i, - int j, int k) { - const ecl::smspec_node &node = - ecl_smspec_get_block_var_node_ijk(ecl_sum->smspec, block_var, i, j, k); - return ecl_sum_get_from_sim_time(ecl_sum, sim_time, &node); -} - -double ecl_sum_get_block_var_ijk_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, - const char *block_var, int i, - int j, int k) { - const ecl::smspec_node &node = - ecl_smspec_get_block_var_node_ijk(ecl_sum->smspec, block_var, i, j, k); - return ecl_sum_get_from_sim_days(ecl_sum, sim_days, &node); -} - -/** - region_nr: [1...num_regions] (NOT C-based indexing) -*/ - -bool ecl_sum_has_region_var(const ecl_sum_type *ecl_sum, const char *var, - int region_nr) { - return ecl_smspec_has_region_var(ecl_sum->smspec, var, region_nr); -} - -double ecl_sum_get_region_var(const ecl_sum_type *ecl_sum, int time_index, - const char *var, int region_nr) { - int params_index = - ecl_smspec_get_region_var_params_index(ecl_sum->smspec, var, region_nr); - return ecl_sum_data_iget(ecl_sum->data, time_index, params_index); -} - -double ecl_sum_get_region_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *var, - int region_nr) { - const ecl::smspec_node &node = - ecl_smspec_get_region_var_node(ecl_sum->smspec, var, region_nr); - return ecl_sum_get_from_sim_time(ecl_sum, sim_time, &node); -} - -double ecl_sum_get_region_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *var, - int region_nr) { - const ecl::smspec_node &node = - ecl_smspec_get_region_var_node(ecl_sum->smspec, var, region_nr); - return ecl_sum_get_from_sim_days(ecl_sum, sim_days, &node); -} - -int ecl_sum_get_misc_var_index(const ecl_sum_type *ecl_sum, const char *var) { - return ecl_smspec_get_misc_var_params_index(ecl_sum->smspec, var); -} - -bool ecl_sum_has_misc_var(const ecl_sum_type *ecl_sum, const char *var) { - return ecl_smspec_has_misc_var(ecl_sum->smspec, var); -} - -double ecl_sum_get_misc_var(const ecl_sum_type *ecl_sum, int time_index, - const char *var) { - int index = ecl_sum_get_misc_var_index(ecl_sum, var); - return ecl_sum_data_iget(ecl_sum->data, time_index, index); -} - -int ecl_sum_get_well_completion_var_index(const ecl_sum_type *ecl_sum, - const char *well, const char *var, - int cell_nr) { - return ecl_smspec_get_well_completion_var_params_index(ecl_sum->smspec, - well, var, cell_nr); -} - -bool ecl_sum_has_well_completion_var(const ecl_sum_type *ecl_sum, - const char *well, const char *var, - int cell_nr) { - return ecl_smspec_has_well_completion_var(ecl_sum->smspec, well, var, - cell_nr); -} - -double ecl_sum_get_well_completion_var(const ecl_sum_type *ecl_sum, - int time_index, const char *well, - const char *var, int cell_nr) { - int index = - ecl_sum_get_well_completion_var_index(ecl_sum, well, var, cell_nr); - return ecl_sum_data_iget(ecl_sum->data, time_index, index); -} - -const ecl::smspec_node * -ecl_sum_get_general_var_node(const ecl_sum_type *ecl_sum, - const char *lookup_kw) { - const ecl::smspec_node &node = - ecl_smspec_get_general_var_node(ecl_sum->smspec, lookup_kw); - return &node; -} - -int ecl_sum_get_general_var_params_index(const ecl_sum_type *ecl_sum, - const char *lookup_kw) { - return ecl_smspec_get_general_var_params_index(ecl_sum->smspec, lookup_kw); -} - -bool ecl_sum_has_general_var(const ecl_sum_type *ecl_sum, - const char *lookup_kw) { - return ecl_smspec_has_general_var(ecl_sum->smspec, lookup_kw); -} - -bool ecl_sum_has_key(const ecl_sum_type *ecl_sum, const char *lookup_kw) { - return ecl_sum_has_general_var(ecl_sum, lookup_kw); -} - -double ecl_sum_get_general_var(const ecl_sum_type *ecl_sum, int time_index, - const char *lookup_kw) { - int params_index = ecl_sum_get_general_var_params_index(ecl_sum, lookup_kw); - return ecl_sum_data_iget(ecl_sum->data, time_index, params_index); -} - -#ifdef __cplusplus -extern "C" { - -void ecl_sum_get_interp_vector(const ecl_sum_type *ecl_sum, time_t sim_time, - const ecl_sum_vector_type *key_words, - double_vector_type *data) { - ecl_sum_data_get_interp_vector(ecl_sum->data, sim_time, key_words, data); -} - -void ecl_sum_fwrite_interp_csv_line(const ecl_sum_type *ecl_sum, - time_t sim_time, - const ecl_sum_vector_type *key_words, - FILE *fp) { - ecl_sum_data_fwrite_interp_csv_line(ecl_sum->data, sim_time, key_words, fp); -} -} -#endif - -double ecl_sum_get_general_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *var) { - const ecl::smspec_node *node = ecl_sum_get_general_var_node(ecl_sum, var); - return ecl_sum_get_from_sim_time(ecl_sum, sim_time, node); -} - -double ecl_sum_get_general_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *var) { - const ecl::smspec_node *node = ecl_sum_get_general_var_node(ecl_sum, var); - return ecl_sum_data_get_from_sim_days(ecl_sum->data, sim_days, *node); -} - -const char *ecl_sum_get_general_var_unit(const ecl_sum_type *ecl_sum, - const char *var) { - const ecl::smspec_node *node = ecl_sum_get_general_var_node(ecl_sum, var); - return smspec_node_get_unit(node); -} - -ecl_sum_type *ecl_sum_alloc_resample(const ecl_sum_type *ecl_sum, - const char *ecl_case, - const time_t_vector_type *times, - bool lower_extrapolation, - bool upper_extrapolation) { - /* - If lower and / or upper extrapolation is set to true it makes sure that resampling returns the first / last value of the simulation - or in the case of derivate / rate then it gets zero. if these are set to false, we jus throw exception - */ - - time_t start_time = ecl_sum_get_data_start(ecl_sum); - time_t end_time = ecl_sum_get_end_time(ecl_sum); - time_t input_start = time_t_vector_get_first(times); - time_t input_end = time_t_vector_get_last(times); - - if (!lower_extrapolation && input_start < start_time) - return NULL; - if (!upper_extrapolation && input_end > end_time) - return NULL; - if (!time_t_vector_is_sorted(times, false)) - return NULL; - - const int *grid_dims = ecl_smspec_get_grid_dims(ecl_sum->smspec); - - bool time_in_days = false; - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(ecl_sum->smspec, 0); - if (util_string_equal(smspec_node_get_unit(&node), "DAYS")) - time_in_days = true; - - //create elc_sum_resampled with TIME node only - ecl_sum_type *ecl_sum_resampled = ecl_sum_alloc_writer( - ecl_case, ecl_sum->fmt_case, ecl_sum->unified, ecl_sum->key_join_string, - input_start, time_in_days, grid_dims[0], grid_dims[1], grid_dims[2]); - - //add remaining nodes - for (int i = 0; i < ecl_smspec_num_nodes(ecl_sum->smspec); i++) { - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(ecl_sum->smspec, i); - if (util_string_equal(smspec_node_get_gen_key1(&node), "TIME")) - continue; - - ecl_sum_add_smspec_node(ecl_sum_resampled, &node); - } - - /* - The SMSPEC header structure has been completely initialized, it is time to - start filling it up with data. - - */ - ecl_sum_vector_type *ecl_sum_vector = ecl_sum_vector_alloc(ecl_sum, true); - double_vector_type *data = - double_vector_alloc(ecl_sum_vector_get_size(ecl_sum_vector), 0); - - for (int report_step = 0; report_step < time_t_vector_size(times); - report_step++) { - time_t input_t = time_t_vector_iget(times, report_step); - if (input_t < start_time) { - //clamping to the first value for t < start_time or if it is a rate than derivative is 0 - for (int i = 1; i < ecl_smspec_num_nodes(ecl_sum->smspec); i++) { - double value = 0; - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(ecl_sum->smspec, i); - if (!node.is_rate()) - value = ecl_sum_iget_first_value(ecl_sum, - node.get_params_index()); - double_vector_iset(data, i - 1, value); - } - } else if (input_t > end_time) { - //clamping to the last value for t > end_time or if it is a rate than derivative is 0 - for (int i = 1; i < ecl_smspec_num_nodes(ecl_sum->smspec); i++) { - double value = 0; - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(ecl_sum->smspec, i); - if (!node.is_rate()) - value = ecl_sum_iget_last_value(ecl_sum, - node.get_params_index()); - double_vector_iset(data, i - 1, value); - } - } else { - /* Look up interpolated data in the original case. */ - ecl_sum_get_interp_vector(ecl_sum, input_t, ecl_sum_vector, data); - } - - /* Add timestep corresponding to the interpolated data in the resampled case. */ - ecl_sum_tstep_type *tstep = ecl_sum_add_tstep( - ecl_sum_resampled, report_step, input_t - input_start); - for (int data_index = 0; - data_index < ecl_sum_vector_get_size(ecl_sum_vector); - data_index++) { - double value = double_vector_iget(data, data_index); - int params_index = - data_index + - 1; // The +1 shift is because the first element in the tstep is time value. - ecl_sum_tstep_iset(tstep, params_index, value); - } - } - double_vector_free(data); - ecl_sum_vector_free(ecl_sum_vector); - return ecl_sum_resampled; -} - -double ecl_sum_iget(const ecl_sum_type *ecl_sum, int time_index, - int param_index) { - return ecl_sum_data_iget(ecl_sum->data, time_index, param_index); -} - -bool ecl_sum_var_is_rate(const ecl_sum_type *ecl_sum, const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_is_rate(node); -} - -bool ecl_sum_var_is_total(const ecl_sum_type *ecl_sum, const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_is_total(node); -} - -ecl_smspec_var_type ecl_sum_identify_var_type(const char *var) { - return ecl_smspec_identify_var_type(var); -} - -ecl_smspec_var_type ecl_sum_get_var_type(const ecl_sum_type *ecl_sum, - const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_get_var_type(node); -} - -const char *ecl_sum_get_unit(const ecl_sum_type *ecl_sum, const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_get_unit(node); -} - -int ecl_sum_get_num(const ecl_sum_type *ecl_sum, const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_get_num(node); -} - -const char *ecl_sum_get_wgname(const ecl_sum_type *ecl_sum, - const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_get_wgname(node); -} - -const char *ecl_sum_get_keyword(const ecl_sum_type *ecl_sum, - const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return smspec_node_get_keyword(node); -} - -bool ecl_sum_has_report_step(const ecl_sum_type *ecl_sum, int report_step) { - return ecl_sum_data_has_report_step(ecl_sum->data, report_step); -} - -int ecl_sum_get_last_report_step(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_get_last_report_step(ecl_sum->data); -} - -int ecl_sum_get_first_report_step(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_get_first_report_step(ecl_sum->data); -} - -int ecl_sum_iget_report_end(const ecl_sum_type *ecl_sum, int report_step) { - return ecl_sum_data_iget_report_end(ecl_sum->data, report_step); -} - -int ecl_sum_iget_report_step(const ecl_sum_type *ecl_sum, int internal_index) { - return ecl_sum_data_iget_report_step(ecl_sum->data, internal_index); -} - -time_t_vector_type *ecl_sum_alloc_time_vector(const ecl_sum_type *ecl_sum, - bool report_only) { - return ecl_sum_data_alloc_time_vector(ecl_sum->data, report_only); -} - -void ecl_sum_init_double_vector__(const ecl_sum_type *ecl_sum, int params_index, - double *data) { - ecl_sum_data_init_double_vector(ecl_sum->data, params_index, data); -} - -void ecl_sum_init_double_vector(const ecl_sum_type *ecl_sum, - const char *gen_key, double *data) { - int params_index = ecl_sum_get_general_var_params_index(ecl_sum, gen_key); - ecl_sum_init_double_vector__(ecl_sum, params_index, data); -} - -void ecl_sum_init_double_vector_interp(const ecl_sum_type *ecl_sum, - const char *gen_key, - const time_t_vector_type *time_points, - double *data) { - const ecl::smspec_node &node = - ecl_smspec_get_general_var_node(ecl_sum->smspec, gen_key); - ecl_sum_data_init_double_vector_interp(ecl_sum->data, node, time_points, - data); -} - -void ecl_sum_init_datetime64_vector(const ecl_sum_type *ecl_sum, int64_t *data, - int multiplier) { - ecl_sum_data_init_datetime64_vector(ecl_sum->data, data, multiplier); -} - -void ecl_sum_init_double_frame(const ecl_sum_type *ecl_sum, - const ecl_sum_vector_type *keywords, - double *data) { - ecl_sum_data_init_double_frame(ecl_sum->data, keywords, data); -} - -void ecl_sum_init_double_frame_interp(const ecl_sum_type *ecl_sum, - const ecl_sum_vector_type *keywords, - const time_t_vector_type *time_points, - double *data) { - ecl_sum_data_init_double_frame_interp(ecl_sum->data, keywords, time_points, - data); -} - -double_vector_type *ecl_sum_alloc_data_vector(const ecl_sum_type *ecl_sum, - int data_index, - bool report_only) { - return ecl_sum_data_alloc_data_vector(ecl_sum->data, data_index, - report_only); -} - -void ecl_sum_summarize(const ecl_sum_type *ecl_sum, FILE *stream) { - ecl_sum_data_summarize(ecl_sum->data, stream); -} - -/** - Returns the first internal index where a limiting value is - reached. If the limiting value is never reached, -1 is - returned. The smspec_index should be calculated first with one of - the - - ecl_sum_get_XXXX_index() - - functions. I.e. the following code will give the first index where - the water wut in well PX exceeds 0.25: - - { - int smspec_index = ecl_sum_get_well_var( ecl_sum , "PX" , "WWCT" ); - int first_index = ecl_sum_get_first_gt( ecl_sum , smspec_index , 0.25); - } - -*/ - -static int ecl_sum_get_limiting(const ecl_sum_type *ecl_sum, int smspec_index, - double limit, bool gt) { - const int length = ecl_sum_data_get_length(ecl_sum->data); - int internal_index = 0; - do { - double value = - ecl_sum_data_iget(ecl_sum->data, internal_index, smspec_index); - if (gt) { - if (value > limit) - break; - } else { - if (value < limit) - break; - } - internal_index++; - } while (internal_index < length); - - if (internal_index == length) /* Did not find it */ - internal_index = -1; - - return internal_index; -} - -int ecl_sum_get_first_gt(const ecl_sum_type *ecl_sum, int param_index, - double limit) { - return ecl_sum_get_limiting(ecl_sum, param_index, limit, true); -} - -int ecl_sum_get_first_lt(const ecl_sum_type *ecl_sum, int param_index, - double limit) { - return ecl_sum_get_limiting(ecl_sum, param_index, limit, false); -} - -time_t ecl_sum_get_report_time(const ecl_sum_type *ecl_sum, int report_step) { - return ecl_sum_data_get_report_time(ecl_sum->data, report_step); -} - -time_t ecl_sum_iget_sim_time(const ecl_sum_type *ecl_sum, int index) { - return ecl_sum_data_iget_sim_time(ecl_sum->data, index); -} - -time_t ecl_sum_get_data_start(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_get_data_start(ecl_sum->data); -} - -time_t ecl_sum_get_start_time(const ecl_sum_type *ecl_sum) { - return ecl_smspec_get_start_time(ecl_sum->smspec); -} - -time_t ecl_sum_get_end_time(const ecl_sum_type *ecl_sum) { - try { - return ecl_sum_data_get_sim_end(ecl_sum->data); - } catch (std::out_of_range) { - return ecl_smspec_get_start_time(ecl_sum->smspec); - } -} - -double ecl_sum_iget_sim_days(const ecl_sum_type *ecl_sum, int index) { - return ecl_sum_data_iget_sim_days(ecl_sum->data, index); -} - -void ecl_sum_fmt_init_summary_x(const ecl_sum_type *ecl_sum, - ecl_sum_fmt_type *fmt) { - fmt->locale = NULL; - fmt->sep = ""; - fmt->date_fmt = "%d/%m/%Y "; - fmt->value_fmt = " %15.6g "; - - if (util_string_equal(ecl_sum_get_unit(ecl_sum, "TIME"), "DAYS")) - fmt->days_fmt = "%7.2f "; - else - fmt->days_fmt = "%7.4f "; - - fmt->header_fmt = " %15s "; - - fmt->newline = "\n"; - fmt->print_header = true; - fmt->print_dash = true; - fmt->date_dash = "-----------------------"; - fmt->value_dash = "-----------------"; - fmt->date_header = "-- Days dd/mm/yyyy "; -} - -/*#define DAYS_DATE_FORMAT "%7.2f %02d/%02d/%04d " -#define FLOAT_FORMAT " %15.6g " -#define HEADER_FORMAT " %15s " -#define DATE_DASH "-----------------------" -#define FLOAT_DASH "-----------------" -*/ - -#define DATE_HEADER "-- Days dd/mm/yyyy " -#define DATE_STRING_LENGTH 128 - -static void __ecl_sum_fprintf_line(const ecl_sum_type *ecl_sum, FILE *stream, - int internal_index, - const bool_vector_type *has_var, - const int_vector_type *var_index, - char *date_string, - const ecl_sum_fmt_type *fmt) { - fprintf(stream, fmt->days_fmt, - ecl_sum_iget_sim_days(ecl_sum, internal_index)); - fprintf(stream, "%s", fmt->sep); - - { - struct tm ts; - time_t sim_time = ecl_sum_iget_sim_time(ecl_sum, internal_index); - util_time_utc(&sim_time, &ts); - strftime(date_string, DATE_STRING_LENGTH - 1, fmt->date_fmt, &ts); - fprintf(stream, "%s", date_string); - } - - { - int ivar; - for (ivar = 0; ivar < int_vector_size(var_index); ivar++) { - if (bool_vector_iget(has_var, ivar)) { - fprintf(stream, "%s", fmt->sep); - fprintf(stream, fmt->value_fmt, - ecl_sum_iget(ecl_sum, internal_index, - int_vector_iget(var_index, ivar))); - } - } - } - - fprintf(stream, "%s", fmt->newline); -} - -static void ecl_sum_fprintf_header(const ecl_sum_type *ecl_sum, - const stringlist_type *key_list, - const bool_vector_type *has_var, - FILE *stream, const ecl_sum_fmt_type *fmt) { - fprintf(stream, "%s", fmt->date_header); - { - int i; - for (i = 0; i < stringlist_get_size(key_list); i++) - if (bool_vector_iget(has_var, i)) { - fprintf(stream, "%s", fmt->sep); - fprintf(stream, fmt->header_fmt, stringlist_iget(key_list, i)); - } - } - - fprintf(stream, "%s", fmt->newline); - if (fmt->print_dash) { - fprintf(stream, "%s", fmt->date_dash); - - { - int i; - for (i = 0; i < stringlist_get_size(key_list); i++) - if (bool_vector_iget(has_var, i)) - fprintf(stream, "%s", fmt->value_dash); - } - fprintf(stream, "%s", fmt->newline); - } -} - -void ecl_sum_fprintf(const ecl_sum_type *ecl_sum, FILE *stream, - const stringlist_type *var_list, bool report_only, - const ecl_sum_fmt_type *fmt) { - bool_vector_type *has_var = - bool_vector_alloc(stringlist_get_size(var_list), false); - int_vector_type *var_index = - int_vector_alloc(stringlist_get_size(var_list), -1); - char *date_string = - (char *)util_malloc(DATE_STRING_LENGTH * sizeof *date_string); - - char *current_locale = NULL; - if (fmt->locale != NULL) - current_locale = setlocale(LC_NUMERIC, fmt->locale); - - { - int ivar; - for (ivar = 0; ivar < stringlist_get_size(var_list); ivar++) { - if (ecl_sum_has_general_var(ecl_sum, - stringlist_iget(var_list, ivar))) { - bool_vector_iset(has_var, ivar, true); - int_vector_iset(var_index, ivar, - ecl_sum_get_general_var_params_index( - ecl_sum, stringlist_iget(var_list, ivar))); - } else { - fprintf(stderr, - "** Warning: could not find variable: \'%s\' in " - "summary file \n", - stringlist_iget(var_list, ivar)); - bool_vector_iset(has_var, ivar, false); - } - } - } - - if (fmt->print_header) - ecl_sum_fprintf_header(ecl_sum, var_list, has_var, stream, fmt); - - if (report_only) { - int first_report = ecl_sum_get_first_report_step(ecl_sum); - int last_report = ecl_sum_get_last_report_step(ecl_sum); - int report; - - for (report = first_report; report <= last_report; report++) { - if (ecl_sum_data_has_report_step(ecl_sum->data, report)) { - int time_index; - time_index = - ecl_sum_data_iget_report_end(ecl_sum->data, report); - __ecl_sum_fprintf_line(ecl_sum, stream, time_index, has_var, - var_index, date_string, fmt); - } - } - } else { - int time_index; - for (time_index = 0; time_index < ecl_sum_get_data_length(ecl_sum); - time_index++) - __ecl_sum_fprintf_line(ecl_sum, stream, time_index, has_var, - var_index, date_string, fmt); - } - - int_vector_free(var_index); - bool_vector_free(has_var); - if (current_locale != NULL) - setlocale(LC_NUMERIC, current_locale); - free(date_string); -} -#undef DATE_STRING_LENGTH - -static void ecl_sum_fmt_init_csv(ecl_sum_fmt_type *fmt, const char *date_format, - const char *date_header, const char *sep) { - fmt->locale = NULL; //"Norwegian"; - fmt->sep = sep; - fmt->date_fmt = date_format; - fmt->value_fmt = "%g"; - fmt->days_fmt = "%7.2f"; - fmt->header_fmt = "%s"; - - fmt->newline = "\r\n"; - fmt->date_header = date_header; - fmt->print_header = true; - fmt->print_dash = false; -} - -void ecl_sum_export_csv(const ecl_sum_type *ecl_sum, const char *filename, - const stringlist_type *var_list, - const char *date_format, const char *sep) { - FILE *stream = util_mkdir_fopen(filename, "w"); - char *date_header = util_alloc_sprintf("DAYS%sDATE", sep); - bool report_only = false; - ecl_sum_fmt_type fmt; - ecl_sum_fmt_init_csv(&fmt, date_format, date_header, sep); - ecl_sum_fprintf(ecl_sum, stream, var_list, report_only, &fmt); - fclose(stream); - free(date_header); -} - -const ecl_sum_type *ecl_sum_get_restart_case(const ecl_sum_type *ecl_sum) { - return ecl_sum->restart_case; -} - -int ecl_sum_get_restart_step(const ecl_sum_type *ecl_sum) { - return ecl_smspec_get_restart_step(ecl_sum->smspec); -} - -const char *ecl_sum_get_case(const ecl_sum_type *ecl_sum) { - return ecl_sum->ecl_case; -} - -const char *ecl_sum_get_path(const ecl_sum_type *ecl_sum) { - return ecl_sum->path; -} - -const char *ecl_sum_get_abs_path(const ecl_sum_type *ecl_sum) { - return ecl_sum->abs_path; -} - -const char *ecl_sum_get_base(const ecl_sum_type *ecl_sum) { - return ecl_sum->base; -} - -/** - This function will check if the currently loaded case corresponds - to the case specified by @input_file. The extension of @input file - can be arbitrary (or nonexistent) and will be ignored (this can - lead to errors with formatted/unformatted mixup if the simulation - directory has been changed after the ecl_sum instance has been - loaded). -*/ - -bool ecl_sum_same_case(const ecl_sum_type *ecl_sum, const char *input_file) { - bool same_case = false; - { - char *path; - char *base; - - util_alloc_file_components(input_file, &path, &base, NULL); - { - bool fmt_file = ecl_smspec_get_formatted(ecl_sum->smspec); - char *header_file = ecl_util_alloc_exfilename( - path, base, ECL_SUMMARY_HEADER_FILE, fmt_file, -1); - if (header_file != NULL) { - same_case = util_same_file( - header_file, ecl_smspec_get_header_file(ecl_sum->smspec)); - free(header_file); - } - } - - free(path); - free(base); - } - return same_case; -} - -stringlist_type * -ecl_sum_alloc_matching_general_var_list(const ecl_sum_type *ecl_sum, - const char *pattern) { - return ecl_smspec_alloc_matching_general_var_list(ecl_sum->smspec, pattern); -} - -void ecl_sum_select_matching_general_var_list(const ecl_sum_type *ecl_sum, - const char *pattern, - stringlist_type *keys) { - ecl_smspec_select_matching_general_var_list(ecl_sum->smspec, pattern, keys); -} - -stringlist_type *ecl_sum_alloc_well_list(const ecl_sum_type *ecl_sum, - const char *pattern) { - return ecl_smspec_alloc_well_list(ecl_sum->smspec, pattern); -} - -stringlist_type *ecl_sum_alloc_group_list(const ecl_sum_type *ecl_sum, - const char *pattern) { - return ecl_smspec_alloc_group_list(ecl_sum->smspec, pattern); -} - -stringlist_type *ecl_sum_alloc_well_var_list(const ecl_sum_type *ecl_sum) { - return ecl_smspec_alloc_well_var_list(ecl_sum->smspec); -} - -void ecl_sum_resample_from_sim_time(const ecl_sum_type *ecl_sum, - const time_t_vector_type *sim_time, - double_vector_type *value, - const char *gen_key) { - const ecl::smspec_node &node = - ecl_smspec_get_general_var_node(ecl_sum->smspec, gen_key); - double_vector_reset(value); - { - int i; - for (i = 0; i < time_t_vector_size(sim_time); i++) - double_vector_iset( - value, i, - ecl_sum_data_get_from_sim_time( - ecl_sum->data, time_t_vector_iget(sim_time, i), node)); - } -} - -void ecl_sum_resample_from_sim_days(const ecl_sum_type *ecl_sum, - const double_vector_type *sim_days, - double_vector_type *value, - const char *gen_key) { - const ecl::smspec_node &node = - ecl_smspec_get_general_var_node(ecl_sum->smspec, gen_key); - double_vector_reset(value); - { - int i; - for (i = 0; i < double_vector_size(sim_days); i++) - double_vector_iset( - value, i, - ecl_sum_data_get_from_sim_days( - ecl_sum->data, double_vector_iget(sim_days, i), node)); - } -} - -time_t ecl_sum_time_from_days(const ecl_sum_type *ecl_sum, double sim_days) { - time_t t = ecl_smspec_get_start_time(ecl_sum->smspec); - util_inplace_forward_days_utc(&t, sim_days); - return t; -} - -double ecl_sum_days_from_time(const ecl_sum_type *ecl_sum, time_t sim_time) { - double seconds_diff = - util_difftime(ecl_smspec_get_start_time(ecl_sum->smspec), sim_time, - NULL, NULL, NULL, NULL); - return seconds_diff * 1.0 / (3600 * 24.0); -} - -double ecl_sum_get_first_day(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_get_first_day(ecl_sum->data); -} - -double ecl_sum_get_sim_length(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_get_sim_length(ecl_sum->data); -} - -/** - Will return the number of data blocks. -*/ -int ecl_sum_get_data_length(const ecl_sum_type *ecl_sum) { - return ecl_sum_data_get_length(ecl_sum->data); -} - -bool ecl_sum_check_sim_time(const ecl_sum_type *sum, time_t sim_time) { - return ecl_sum_data_check_sim_time(sum->data, sim_time); -} - -bool ecl_sum_check_sim_days(const ecl_sum_type *sum, double sim_days) { - return ecl_sum_data_check_sim_days(sum->data, sim_days); -} - -int ecl_sum_get_report_step_from_time(const ecl_sum_type *sum, - time_t sim_time) { - return ecl_sum_data_get_report_step_from_time(sum->data, sim_time); -} - -int ecl_sum_get_report_step_from_days(const ecl_sum_type *sum, - double sim_days) { - return ecl_sum_data_get_report_step_from_days(sum->data, sim_days); -} - -ecl_smspec_type *ecl_sum_get_smspec(const ecl_sum_type *ecl_sum) { - return ecl_sum->smspec; -} - -/* - The functions below are extremly simple functions which only serve - as an easy access to the smspec_alloc_xxx_key() functions which - know how to create the various composite keys. -*/ - -char *ecl_sum_alloc_well_key(const ecl_sum_type *ecl_sum, const char *keyword, - const char *wgname) { - return ecl_smspec_alloc_well_key(ecl_sum->smspec, keyword, wgname); -} - -bool ecl_sum_is_oil_producer(const ecl_sum_type *ecl_sum, const char *well) { - const char *WOPT_KEY = "WOPT"; - bool oil_producer = false; - - if (ecl_sum_has_well_var(ecl_sum, well, WOPT_KEY)) { - int last_step = ecl_sum_get_data_length(ecl_sum) - 1; - double wopt = ecl_sum_get_well_var(ecl_sum, last_step, well, WOPT_KEY); - - if (wopt > 0) - oil_producer = true; - } - - return oil_producer; -} - -bool ecl_sum_report_step_equal(const ecl_sum_type *ecl_sum1, - const ecl_sum_type *ecl_sum2) { - if (ecl_sum1 == ecl_sum2) - return true; - else - return ecl_sum_data_report_step_equal(ecl_sum1->data, ecl_sum2->data); -} - -bool ecl_sum_report_step_compatible(const ecl_sum_type *ecl_sum1, - const ecl_sum_type *ecl_sum2) { - if (ecl_sum1 == ecl_sum2) - return true; - else - return ecl_sum_data_report_step_compatible(ecl_sum1->data, - ecl_sum2->data); -} - -double_vector_type *ecl_sum_alloc_seconds_solution(const ecl_sum_type *ecl_sum, - const char *gen_key, - double cmp_value, - bool rates_clamp_lower) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return ecl_sum_data_alloc_seconds_solution(ecl_sum->data, *node, cmp_value, - rates_clamp_lower); -} - -double_vector_type *ecl_sum_alloc_days_solution(const ecl_sum_type *ecl_sum, - const char *gen_key, - double cmp_value, - bool rates_clamp_lower) { - double_vector_type *solution = ecl_sum_alloc_seconds_solution( - ecl_sum, gen_key, cmp_value, rates_clamp_lower); - double_vector_scale(solution, 1.0 / 86400); - return solution; -} - -time_t_vector_type *ecl_sum_alloc_time_solution(const ecl_sum_type *ecl_sum, - const char *gen_key, - double cmp_value, - bool rates_clamp_lower) { - time_t_vector_type *solution = time_t_vector_alloc(0, 0); - { - double_vector_type *seconds = ecl_sum_alloc_seconds_solution( - ecl_sum, gen_key, cmp_value, rates_clamp_lower); - time_t start_time = ecl_sum_get_start_time(ecl_sum); - for (int i = 0; i < double_vector_size(seconds); i++) { - time_t t = start_time; - util_inplace_forward_seconds_utc(&t, - double_vector_iget(seconds, i)); - time_t_vector_append(solution, t); - } - double_vector_free(seconds); - } - return solution; -} - -ert_ecl_unit_enum ecl_sum_get_unit_system(const ecl_sum_type *ecl_sum) { - return ecl_smspec_get_unit_system(ecl_sum->smspec); -} - -double ecl_sum_iget_last_value(const ecl_sum_type *ecl_sum, int param_index) { - return ecl_sum_data_iget_last_value(ecl_sum->data, param_index); -} - -double ecl_sum_get_last_value_gen_key(const ecl_sum_type *ecl_sum, - const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return ecl_sum_iget_last_value(ecl_sum, smspec_node_get_params_index(node)); -} - -double ecl_sum_get_last_value_node(const ecl_sum_type *ecl_sum, - const ecl::smspec_node *node) { - return ecl_sum_iget_last_value(ecl_sum, smspec_node_get_params_index(node)); -} - -double ecl_sum_iget_first_value(const ecl_sum_type *ecl_sum, int param_index) { - return ecl_sum_data_iget_first_value(ecl_sum->data, param_index); -} - -double ecl_sum_get_first_value_gen_key(const ecl_sum_type *ecl_sum, - const char *gen_key) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum, gen_key); - return ecl_sum_iget_first_value(ecl_sum, - smspec_node_get_params_index(node)); -} - -double ecl_sum_get_first_value_node(const ecl_sum_type *ecl_sum, - const ecl::smspec_node *node) { - return ecl_sum_iget_first_value(ecl_sum, - smspec_node_get_params_index(node)); -} diff --git a/lib/ecl/ecl_sum_tstep.cpp b/lib/ecl/ecl_sum_tstep.cpp deleted file mode 100644 index 3d2fc659bd..0000000000 --- a/lib/ecl/ecl_sum_tstep.cpp +++ /dev/null @@ -1,333 +0,0 @@ -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#define ECL_SUM_TSTEP_ID 88631 - -/* - This file implements the ecl_sum_tstep datatype which contains the - summary information for all summary vectors at one instant in - time. If we view the summary data as this: - - -Header direction: ecl_smspec DAYS WWCT:OP_3 FOPT BPR:15,10,25 - -------------------------------------------- - /|\ 0.00 0.00 0.00 256.00 <-- One timestep ecl_sum_tstep - | 10.00 0.56 10.00 255.00 - Time direction: ecl_sum_data 20.00 0.61 18.70 253.00 - | 30.00 0.63 21.20 251.00 - | ... - \|/ 90.00 0.80 39.70 244.00 - -------------------------------------------- - - The ecl_sum_tstep structure corresponds to one 'horizontal line' in - the summary data. - - These timesteps correspond exactly to the simulators timesteps, - i.e. when convergence is poor they are closely spaced. In the - ECLIPSE summary files these time steps are called "MINISTEPS" - and - that term is also used some places in the ecl_sum_xxx codebase. - */ - -struct ecl_sum_tstep_struct { - UTIL_TYPE_ID_DECLARATION; - std::vector - data; /* A memcpy copy of the PARAMS vector in ecl_kw instance - the raw data. */ - time_t - sim_time; /* The true time (i.e. 20.th of october 2010) of corresponding to this timestep. */ - int ministep; /* The ECLIPSE internal time-step number; one ministep per numerical timestep. */ - int report_step; /* The report step this time-step is part of - in general there can be many timestep for each report step. */ - double sim_seconds; /* Accumulated simulation time up to this ministep. */ - int internal_index; /* Used for lookups of the next / previous ministep based on an existing ministep. */ - const ecl_smspec_type * - smspec; /* The smespec header information for this tstep - must be compatible. */ -}; - -ecl_sum_tstep_type * -ecl_sum_tstep_alloc_remap_copy(const ecl_sum_tstep_type *src, - const ecl_smspec_type *new_smspec, - float default_value, const int *params_map) { - int params_size = ecl_smspec_get_params_size(new_smspec); - ecl_sum_tstep_type *target = new ecl_sum_tstep_type(); - UTIL_TYPE_ID_INIT(target, ECL_SUM_TSTEP_ID); - target->report_step = src->report_step; - target->ministep = src->ministep; - - target->smspec = new_smspec; - target->data.resize(params_size); - for (int i = 0; i < params_size; i++) { - - if (params_map[i] >= 0) - target->data[i] = src->data[params_map[i]]; - else - target->data[i] = default_value; - } - return target; -} - -ecl_sum_tstep_type *ecl_sum_tstep_alloc_copy(const ecl_sum_tstep_type *src) { - ecl_sum_tstep_type *target = new ecl_sum_tstep_type(); - UTIL_TYPE_ID_INIT(target, ECL_SUM_TSTEP_ID); - target->smspec = src->smspec; - target->report_step = src->report_step; - target->ministep = src->ministep; - target->data = src->data; - return target; -} - -static ecl_sum_tstep_type *ecl_sum_tstep_alloc(int report_step, int ministep_nr, - const ecl_smspec_type *smspec) { - ecl_sum_tstep_type *tstep = new ecl_sum_tstep_type(); - UTIL_TYPE_ID_INIT(tstep, ECL_SUM_TSTEP_ID); - tstep->smspec = smspec; - tstep->report_step = report_step; - tstep->ministep = ministep_nr; - tstep->data.resize(ecl_smspec_get_params_size(smspec)); - return tstep; -} - -UTIL_SAFE_CAST_FUNCTION(ecl_sum_tstep, ECL_SUM_TSTEP_ID) -UTIL_SAFE_CAST_FUNCTION_CONST(ecl_sum_tstep, ECL_SUM_TSTEP_ID) - -void ecl_sum_tstep_free(ecl_sum_tstep_type *ministep) { delete ministep; } - -void ecl_sum_tstep_free__(void *__ministep) { - ecl_sum_tstep_type *ministep = ecl_sum_tstep_safe_cast(__ministep); - ecl_sum_tstep_free(ministep); -} - -/** - This function sets the internal time representation in the - ecl_sum_tstep. The treatment of time is a bit weird; on the one - hand the time elements in the summary data are just like any other - element like e.g. the FOPT or GGPR:NAME - on the other hand the - time information is strictly required and the summary file will - fall to pieces if it is missing. - - The time can be provided in using (at least) two different - keywords: - - DAYS/HOURS: The data vector will contain the number of - days/hours since the simulation start (hours in the case - of lab units). - - DAY,MONTH,YEAR: The data vector will contain the true date of - the tstep. - - The ecl_sum_tstep class can utilize both types of information, but - will select the DAYS variety if both are present. -*/ - -static void ecl_sum_tstep_set_time_info_from_seconds(ecl_sum_tstep_type *tstep, - time_t sim_start, - double sim_seconds) { - tstep->sim_seconds = sim_seconds; - tstep->sim_time = sim_start; - util_inplace_forward_seconds_utc(&tstep->sim_time, tstep->sim_seconds); -} - -static void ecl_sum_tstep_set_time_info_from_date(ecl_sum_tstep_type *tstep, - time_t sim_start, - time_t sim_time) { - tstep->sim_time = sim_time; - tstep->sim_seconds = util_difftime_seconds(sim_start, tstep->sim_time); -} - -static void ecl_sum_tstep_set_time_info(ecl_sum_tstep_type *tstep, - const ecl_smspec_type *smspec) { - int date_day_index = ecl_smspec_get_date_day_index(smspec); - int date_month_index = ecl_smspec_get_date_month_index(smspec); - int date_year_index = ecl_smspec_get_date_year_index(smspec); - int sim_time_index = ecl_smspec_get_time_index(smspec); - time_t sim_start = ecl_smspec_get_start_time(smspec); - - if (sim_time_index >= 0) { - double sim_time = tstep->data[sim_time_index]; - double sim_seconds = sim_time * ecl_smspec_get_time_seconds(smspec); - ecl_sum_tstep_set_time_info_from_seconds(tstep, sim_start, sim_seconds); - } else if (date_day_index >= 0) { - int day = util_roundf(tstep->data[date_day_index]); - int month = util_roundf(tstep->data[date_month_index]); - int year = util_roundf(tstep->data[date_year_index]); - - time_t sim_time = ecl_util_make_date(day, month, year); - ecl_sum_tstep_set_time_info_from_date(tstep, sim_start, sim_time); - } else - util_abort("%s: Hmmm - could not extract date/time information from " - "SMSPEC header file? \n", - __func__); -} - -/** - If the ecl_kw instance is in some way invalid (i.e. wrong size); - the function will return NULL: -*/ - -ecl_sum_tstep_type *ecl_sum_tstep_alloc_from_file( - int report_step, int ministep_nr, const ecl_kw_type *params_kw, - const char *src_file, const ecl_smspec_type *smspec) { - - int data_size = ecl_kw_get_size(params_kw); - - if (data_size == ecl_smspec_get_params_size(smspec)) { - ecl_sum_tstep_type *ministep = - ecl_sum_tstep_alloc(report_step, ministep_nr, smspec); - ecl_kw_get_memcpy_data(params_kw, ministep->data.data()); - ecl_sum_tstep_set_time_info(ministep, smspec); - return ministep; - } else { - /* - This is actually a fatal error / bug; the difference in smspec - header structure should have been detected already in the - ecl_smspec_load_restart() function and the restart case - discarded. - */ - fprintf(stderr, - "** Warning size mismatch between timestep loaded from:%s(%d) " - "and header:%s(%d) - timestep discarded.\n", - src_file, data_size, ecl_smspec_get_header_file(smspec), - ecl_smspec_get_params_size(smspec)); - return NULL; - } -} - -/* - Should be called in write mode. -*/ - -ecl_sum_tstep_type *ecl_sum_tstep_alloc_new(int report_step, int ministep, - float sim_seconds, - const ecl_smspec_type *smspec) { - ecl_sum_tstep_type *tstep = - ecl_sum_tstep_alloc(report_step, ministep, smspec); - tstep->data = ecl_smspec_get_params_default(smspec); - - ecl_sum_tstep_set_time_info_from_seconds( - tstep, ecl_smspec_get_start_time(smspec), sim_seconds); - ecl_sum_tstep_iset(tstep, ecl_smspec_get_time_index(smspec), - sim_seconds / ecl_smspec_get_time_seconds(smspec)); - return tstep; -} - -double ecl_sum_tstep_iget(const ecl_sum_tstep_type *ministep, int index) { - if ((index >= 0) && (index < (int)ministep->data.size())) - return ministep->data[index]; - else { - util_abort("%s: param index:%d invalid: Valid range: [0,%d) \n", - __func__, index, ministep->data.size()); - return -1; - } -} - -time_t ecl_sum_tstep_get_sim_time(const ecl_sum_tstep_type *ministep) { - return ministep->sim_time; -} - -double ecl_sum_tstep_get_sim_days(const ecl_sum_tstep_type *ministep) { - return ministep->sim_seconds / (24 * 3600); -} - -double ecl_sum_tstep_get_sim_seconds(const ecl_sum_tstep_type *ministep) { - return ministep->sim_seconds; -} - -int ecl_sum_tstep_get_report(const ecl_sum_tstep_type *ministep) { - return ministep->report_step; -} - -int ecl_sum_tstep_get_ministep(const ecl_sum_tstep_type *ministep) { - return ministep->ministep; -} - -void ecl_sum_tstep_fwrite(const ecl_sum_tstep_type *ministep, - const int *index_map, int index_map_size, - fortio_type *fortio) { - { - ecl_kw_type *ministep_kw = ecl_kw_alloc(MINISTEP_KW, 1, ECL_INT); - ecl_kw_iset_int(ministep_kw, 0, ministep->ministep); - ecl_kw_fwrite(ministep_kw, fortio); - ecl_kw_free(ministep_kw); - } - - { - int compact_size = index_map_size; - ecl_kw_type *params_kw = - ecl_kw_alloc(PARAMS_KW, compact_size, ECL_FLOAT); - - float *data = (float *)ecl_kw_get_ptr(params_kw); - - { - int i; - for (i = 0; i < compact_size; i++) - data[i] = ministep->data[index_map[i]]; - } - ecl_kw_fwrite(params_kw, fortio); - ecl_kw_free(params_kw); - } -} - -void ecl_sum_tstep_iset(ecl_sum_tstep_type *tstep, int index, float value) { - if ((index < static_cast(tstep->data.size())) && (index >= 0)) - tstep->data[index] = value; - else - util_abort("%s: index:%d invalid. Valid range: [0,%d) \n", __func__, - index, tstep->data.size()); -} - -void ecl_sum_tstep_iscale(ecl_sum_tstep_type *tstep, int index, float scalar) { - ecl_sum_tstep_iset(tstep, index, ecl_sum_tstep_iget(tstep, index) * scalar); -} - -void ecl_sum_tstep_ishift(ecl_sum_tstep_type *tstep, int index, float addend) { - ecl_sum_tstep_iset(tstep, index, ecl_sum_tstep_iget(tstep, index) + addend); -} - -void ecl_sum_tstep_set_from_node(ecl_sum_tstep_type *tstep, - const ecl::smspec_node &smspec_node, - float value) { - int data_index = smspec_node_get_params_index(&smspec_node); - ecl_sum_tstep_iset(tstep, data_index, value); -} - -double ecl_sum_tstep_get_from_node(const ecl_sum_tstep_type *tstep, - const ecl::smspec_node &smspec_node) { - int data_index = smspec_node_get_params_index(&smspec_node); - return ecl_sum_tstep_iget(tstep, data_index); -} - -void ecl_sum_tstep_set_from_key(ecl_sum_tstep_type *tstep, const char *gen_key, - float value) { - const ecl::smspec_node &smspec_node = - ecl_smspec_get_general_var_node(tstep->smspec, gen_key); - ecl_sum_tstep_set_from_node(tstep, smspec_node, value); -} - -double ecl_sum_tstep_get_from_key(const ecl_sum_tstep_type *tstep, - const char *gen_key) { - const ecl::smspec_node &smspec_node = - ecl_smspec_get_general_var_node(tstep->smspec, gen_key); - return ecl_sum_tstep_get_from_node(tstep, smspec_node); -} - -bool ecl_sum_tstep_has_key(const ecl_sum_tstep_type *tstep, - const char *gen_key) { - return ecl_smspec_has_general_var(tstep->smspec, gen_key); -} - -bool ecl_sum_tstep_sim_time_equal(const ecl_sum_tstep_type *tstep1, - const ecl_sum_tstep_type *tstep2) { - if (tstep1->sim_time == tstep2->sim_time) - return true; - else - return false; -} diff --git a/lib/ecl/ecl_sum_vector.cpp b/lib/ecl/ecl_sum_vector.cpp deleted file mode 100644 index d74198eeb7..0000000000 --- a/lib/ecl/ecl_sum_vector.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include - -#define ECL_SUM_VECTOR_TYPE_ID 8768778 - -struct ecl_sum_vector_struct { - UTIL_TYPE_ID_DECLARATION; - std::vector node_index_list; - std::vector is_rate_list; - std::vector key_list; - const ecl_sum_type *ecl_sum; -}; - -void ecl_sum_vector_free(ecl_sum_vector_type *ecl_sum_vector) { - delete ecl_sum_vector; -} - -UTIL_IS_INSTANCE_FUNCTION(ecl_sum_vector, ECL_SUM_VECTOR_TYPE_ID) - -static void ecl_sum_vector_add_node(ecl_sum_vector_type *vector, - const ecl::smspec_node *node, - const char *key) { - int params_index = smspec_node_get_params_index(node); - bool is_rate_key = smspec_node_is_rate(node); - - vector->node_index_list.push_back(params_index); - vector->is_rate_list.push_back(is_rate_key); - vector->key_list.push_back(key); -} - -ecl_sum_vector_type *ecl_sum_vector_alloc(const ecl_sum_type *ecl_sum, - bool add_keywords) { - ecl_sum_vector_type *ecl_sum_vector = new ecl_sum_vector_type(); - UTIL_TYPE_ID_INIT(ecl_sum_vector, ECL_SUM_VECTOR_TYPE_ID); - ecl_sum_vector->ecl_sum = ecl_sum; - if (add_keywords) { - const ecl_smspec_type *smspec = ecl_sum_get_smspec(ecl_sum); - for (int i = 0; i < ecl_smspec_num_nodes(smspec); i++) { - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(smspec, i); - const char *key = smspec_node_get_gen_key1(&node); - /* - The TIME keyword is special case handled to not be included; that is - to match the same special casing in the key matching function. - */ - if (!util_string_equal(key, "TIME")) - ecl_sum_vector_add_node(ecl_sum_vector, &node, key); - } - } - return ecl_sum_vector; -} - -static void ecl_sum_vector_add_invalid_key(ecl_sum_vector_type *vector, - const char *key) { - vector->node_index_list.push_back(-1); - vector->is_rate_list.push_back(false); - vector->key_list.push_back(key); -} - -/* - This function will allocate a keyword vector for the keys in the @ecl_sum - argument passed in, it will contain all the same keys as in the input argument - @src_vector. If the @src_vector contains keys which are not present in - @ecl_sum an entry marked as *invalid* will be added. The whole point about - this function is to ensure that calls to: - - ecl_sum_fwrite_interp_csv_line( ) - - will result in nicely aligned output even if the different summary cases do - not have the exact same keys. -*/ - -ecl_sum_vector_type * -ecl_sum_vector_alloc_layout_copy(const ecl_sum_vector_type *src_vector, - const ecl_sum_type *ecl_sum) { - ecl_sum_vector_type *new_vector = ecl_sum_vector_alloc(ecl_sum, false); - for (size_t i = 0; i < src_vector->key_list.size(); i++) { - const char *key = src_vector->key_list[i].c_str(); - if (ecl_sum_has_general_var(ecl_sum, key)) - ecl_sum_vector_add_key(new_vector, key); - else - ecl_sum_vector_add_invalid_key(new_vector, key); - } - return new_vector; -} - -bool ecl_sum_vector_add_key(ecl_sum_vector_type *ecl_sum_vector, - const char *key) { - if (ecl_sum_has_general_var(ecl_sum_vector->ecl_sum, key)) { - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum_vector->ecl_sum, key); - ecl_sum_vector_add_node(ecl_sum_vector, node, key); - return true; - } else - return false; -} - -void ecl_sum_vector_add_keys(ecl_sum_vector_type *ecl_sum_vector, - const char *pattern) { - stringlist_type *keylist = ecl_sum_alloc_matching_general_var_list( - ecl_sum_vector->ecl_sum, pattern); - - int num_keywords = stringlist_get_size(keylist); - int i; - for (i = 0; i < num_keywords; i++) { - const char *key = stringlist_iget(keylist, i); - const ecl::smspec_node *node = - ecl_sum_get_general_var_node(ecl_sum_vector->ecl_sum, key); - ecl_sum_vector_add_node(ecl_sum_vector, node, key); - } - stringlist_free(keylist); -} - -int ecl_sum_vector_get_size(const ecl_sum_vector_type *ecl_sum_vector) { - return ecl_sum_vector->node_index_list.size(); -} - -bool ecl_sum_vector_iget_is_rate(const ecl_sum_vector_type *ecl_sum_vector, - int index) { - return ecl_sum_vector->is_rate_list[index]; -} - -bool ecl_sum_vector_iget_valid(const ecl_sum_vector_type *ecl_sum_vector, - int index) { - return (ecl_sum_vector->node_index_list[index] >= 0); -} - -int ecl_sum_vector_iget_param_index(const ecl_sum_vector_type *ecl_sum_vector, - int index) { - return ecl_sum_vector->node_index_list[index]; -} - -const char *ecl_sum_vector_iget_key(const ecl_sum_vector_type *ecl_sum_vector, - int index) { - return ecl_sum_vector->key_list[index].c_str(); -} diff --git a/lib/ecl/ecl_type.cpp b/lib/ecl/ecl_type.cpp deleted file mode 100644 index 9392585d4a..0000000000 --- a/lib/ecl/ecl_type.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include -#include -#include - -#include -#include - -/* The string names for the different ECLIPSE low-level - types. -*/ -#define ECL_TYPE_NAME_CHAR "CHAR" -#define ECL_TYPE_NAME_FLOAT "REAL" -#define ECL_TYPE_NAME_INT "INTE" -#define ECL_TYPE_NAME_DOUBLE "DOUB" -#define ECL_TYPE_NAME_BOOL "LOGI" -#define ECL_TYPE_NAME_MESSAGE "MESS" - -static char *alloc_string_name(const ecl_data_type ecl_type) { - return util_alloc_sprintf("C%03d", ecl_type_get_sizeof_iotype(ecl_type)); -} - -static bool is_ecl_string_name(const char *type_name) { - return (type_name[0] == 'C' && isdigit(type_name[1]) && - isdigit(type_name[2]) && isdigit(type_name[3])); -} - -static size_t get_ecl_string_length(const char *type_name) { - if (!is_ecl_string_name(type_name)) - util_abort("%s: Expected eclipse string (CXXX), received %s\n", - __func__, type_name); - - return atoi(type_name + 1); -} - -ecl_data_type ecl_type_create(const ecl_type_enum type, - const size_t element_size) { - ecl_data_type ecl_type = - (type == ECL_STRING_TYPE ? ECL_STRING(element_size) - : ecl_type_create_from_type(type)); - - if ((size_t)ecl_type_get_sizeof_iotype(ecl_type) != element_size) - util_abort( - "%s: element_size mismatch for type %d, was: %d, expected: %d\n", - __func__, type, element_size, ecl_type_get_sizeof_iotype(ecl_type)); - - return ecl_type; -} - -ecl_data_type ecl_type_create_from_type(const ecl_type_enum type) { - switch (type) { - case (ECL_CHAR_TYPE): - return ECL_CHAR; - case (ECL_INT_TYPE): - return ECL_INT; - case (ECL_FLOAT_TYPE): - return ECL_FLOAT; - case (ECL_DOUBLE_TYPE): - return ECL_DOUBLE; - case (ECL_BOOL_TYPE): - return ECL_BOOL; - case (ECL_MESS_TYPE): - return ECL_MESS; - case (ECL_STRING_TYPE): - util_abort("%s: Variable length string type cannot be created" - " from type alone!\n", - __func__); - return ECL_STRING(0); /* Dummy */ - default: - util_abort("%s: invalid ecl_type: %d\n", __func__, type); - return ECL_INT; /* Dummy */ - } -} - -ecl_type_enum ecl_type_get_type(const ecl_data_type ecl_type) { - return ecl_type.type; -} - -char *ecl_type_alloc_name(const ecl_data_type ecl_type) { - switch (ecl_type.type) { - case (ECL_CHAR_TYPE): - return util_alloc_string_copy(ECL_TYPE_NAME_CHAR); - case (ECL_STRING_TYPE): - return alloc_string_name(ecl_type); - case (ECL_FLOAT_TYPE): - return util_alloc_string_copy(ECL_TYPE_NAME_FLOAT); - case (ECL_DOUBLE_TYPE): - return util_alloc_string_copy(ECL_TYPE_NAME_DOUBLE); - case (ECL_INT_TYPE): - return util_alloc_string_copy(ECL_TYPE_NAME_INT); - case (ECL_BOOL_TYPE): - return util_alloc_string_copy(ECL_TYPE_NAME_BOOL); - case (ECL_MESS_TYPE): - return util_alloc_string_copy(ECL_TYPE_NAME_MESSAGE); - default: - util_abort("Internal error in %s - internal eclipse_type: %d not " - "recognized - aborting \n", - __func__, ecl_type.type); - return NULL; /* Dummy */ - } -} - -ecl_data_type ecl_type_create_from_name(const char *type_name) { - if (strncmp(type_name, ECL_TYPE_NAME_FLOAT, ECL_TYPE_LENGTH) == 0) - return ECL_FLOAT; - else if (strncmp(type_name, ECL_TYPE_NAME_INT, ECL_TYPE_LENGTH) == 0) - return ECL_INT; - else if (strncmp(type_name, ECL_TYPE_NAME_DOUBLE, ECL_TYPE_LENGTH) == 0) - return ECL_DOUBLE; - else if (strncmp(type_name, ECL_TYPE_NAME_CHAR, ECL_TYPE_LENGTH) == 0) - return ECL_CHAR; - else if (is_ecl_string_name(type_name)) - return ECL_STRING(get_ecl_string_length(type_name)); - else if (strncmp(type_name, ECL_TYPE_NAME_MESSAGE, ECL_TYPE_LENGTH) == 0) - return ECL_MESS; - else if (strncmp(type_name, ECL_TYPE_NAME_BOOL, ECL_TYPE_LENGTH) == 0) - return ECL_BOOL; - else { - util_abort("%s: unrecognized type name:%s \n", __func__, type_name); - return ECL_INT; /* Dummy */ - } -} - -int ecl_type_get_sizeof_ctype(const ecl_data_type ecl_type) { - return ecl_type.element_size; -} - -int ecl_type_get_sizeof_iotype(const ecl_data_type ecl_type) { - if (ecl_type_is_bool(ecl_type)) - return sizeof(int); - - if (ecl_type_is_char(ecl_type)) - return ecl_type.element_size - 1; - - if (ecl_type_is_string(ecl_type)) - return ecl_type.element_size - 1; - - return ecl_type.element_size; -} - -bool ecl_type_is_numeric(const ecl_data_type ecl_type) { - return (ecl_type_is_int(ecl_type) || ecl_type_is_float(ecl_type) || - ecl_type_is_double(ecl_type)); -} - -bool ecl_type_is_alpha(const ecl_data_type ecl_type) { - return (ecl_type_is_char(ecl_type) || ecl_type_is_mess(ecl_type) || - ecl_type_is_string(ecl_type)); -} - -bool ecl_type_is_equal(const ecl_data_type ecl_type1, - const ecl_data_type ecl_type2) { - return (ecl_type1.type == ecl_type2.type && - ecl_type1.element_size == ecl_type2.element_size); -} - -bool ecl_type_is_char(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_CHAR_TYPE); -} - -bool ecl_type_is_int(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_INT_TYPE); -} - -bool ecl_type_is_float(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_FLOAT_TYPE); -} - -bool ecl_type_is_double(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_DOUBLE_TYPE); -} - -bool ecl_type_is_mess(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_MESS_TYPE); -} - -bool ecl_type_is_bool(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_BOOL_TYPE); -} - -bool ecl_type_is_string(const ecl_data_type ecl_type) { - return (ecl_type.type == ECL_STRING_TYPE); -} - -// Temporary fixup for OPM. -char *ecl_type_get_name(const ecl_data_type ecl_type) { - return ecl_type_alloc_name(ecl_type); -} diff --git a/lib/ecl/ecl_type_python.cpp b/lib/ecl/ecl_type_python.cpp deleted file mode 100644 index 8e62ccb5db..0000000000 --- a/lib/ecl/ecl_type_python.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include - -/** - * - * Functions only to be used by the *PYTHON* prototype for EclDataType - * - */ - -#ifdef __cplusplus -extern "C" { - -ecl_data_type *ecl_type_alloc_copy_python(const ecl_data_type *src_type) { - ecl_data_type *data_type = (ecl_data_type *)util_malloc(sizeof *src_type); - memcpy(data_type, src_type, sizeof *data_type); - return data_type; -} - -ecl_data_type *ecl_type_alloc_python(const ecl_type_enum type, - const size_t element_size) { - ecl_data_type src_type = ecl_type_create(type, element_size); - return ecl_type_alloc_copy_python(&src_type); -} - -ecl_data_type *ecl_type_alloc_from_type_python(const ecl_type_enum type) { - ecl_data_type src_type = ecl_type_create_from_type(type); - return ecl_type_alloc_copy_python(&src_type); -} - -ecl_data_type *ecl_type_alloc_from_name_python(const char *name) { - ecl_data_type src_type = ecl_type_create_from_name(name); - return ecl_type_alloc_copy_python(&src_type); -} - -void ecl_type_free_python(ecl_data_type *data_type) { free(data_type); } - -ecl_type_enum ecl_type_get_type_python(const ecl_data_type *ecl_type) { - return ecl_type_get_type(*ecl_type); -} - -const char *ecl_type_alloc_name_python(const ecl_data_type *ecl_type) { - return ecl_type_alloc_name(*ecl_type); -} - -int ecl_type_get_sizeof_iotype_python(const ecl_data_type *ecl_type) { - return ecl_type_get_sizeof_iotype(*ecl_type); -} - -int ecl_type_get_sizeof_ctype_python(const ecl_data_type *ecl_type) { - return ecl_type_get_sizeof_ctype(*ecl_type); -} - -bool ecl_type_is_numeric_python(const ecl_data_type *ecl_type) { - return ecl_type_is_numeric(*ecl_type); -} - -bool ecl_type_is_equal_python(const ecl_data_type *ecl_type1, - const ecl_data_type *ecl_type2) { - return ecl_type_is_equal(*ecl_type1, *ecl_type2); -} - -bool ecl_type_is_char_python(const ecl_data_type *ecl_type) { - return ecl_type_is_char(*ecl_type); -} - -bool ecl_type_is_int_python(const ecl_data_type *ecl_type) { - return ecl_type_is_int(*ecl_type); -} - -bool ecl_type_is_float_python(const ecl_data_type *ecl_type) { - return ecl_type_is_float(*ecl_type); -} - -bool ecl_type_is_double_python(const ecl_data_type *ecl_type) { - return ecl_type_is_double(*ecl_type); -} - -bool ecl_type_is_mess_python(const ecl_data_type *ecl_type) { - return ecl_type_is_mess(*ecl_type); -} - -bool ecl_type_is_bool_python(const ecl_data_type *ecl_type) { - return ecl_type_is_bool(*ecl_type); -} - -bool ecl_type_is_string_python(const ecl_data_type *ecl_type) { - return ecl_type_is_string(*ecl_type); -} - -/** - * - * Functions for the EclKw prototype - * - */ -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_dynamic_python( - FILE *stream, const char *kw, bool strict, const ecl_data_type *data_type) { - return ecl_kw_fscanf_alloc_grdecl_dynamic__(stream, kw, strict, *data_type); -} - -ecl_kw_type *ecl_kw_alloc_python(const char *header, int size, - const ecl_data_type *data_type) { - return ecl_kw_alloc(header, size, *data_type); -} - -ecl_data_type *ecl_kw_get_data_type_python(const ecl_kw_type *ecl_kw) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - return ecl_type_alloc_copy_python(&data_type); -} - -void ecl_kw_fread_indexed_data_python(fortio_type *fortio, - offset_type data_offset, - const ecl_data_type *data_type, - int element_count, - const int_vector_type *index_map, - char *buffer) { - return ecl_kw_fread_indexed_data(fortio, data_offset, *data_type, - element_count, index_map, buffer); -} -} -#endif diff --git a/lib/ecl/readme.overview b/lib/ecl/readme.overview deleted file mode 100644 index 7e395aaa73..0000000000 --- a/lib/ecl/readme.overview +++ /dev/null @@ -1,55 +0,0 @@ -The EnKF functionality is organized in xxx libraries with different -functionalities. The different libraries depend on eachother, and the -libraries must be built in correct order. The dependencies is as -follows: - -libhash : -libutil : libhash -libecl : libhash libutil -librms : libecl libutil libhash -libsched : libecl linutil libhash -libenkf : libecl libsched librm linutil libhash - - -libhash: This library implements the classes hash_type, set_type and - list_type. - -libutil: This library is a collection utility routines. Observe that - this library only implements routines, and not statefull - objects. - -libecl: This library implements functions for reading/writing ECLIPSE - restart/summary/init/grid files. - -libsched: This library implements a basic SCHEDULE file parser. - -librms: This library implements (basic) reader and writer for binary - RMS ROFF files. - -libenkf: This library implements various high level objects for EnKF - functionality. - ------------------------------------------------------------------ - -All the makefiles start with the statement: - -include "path_config" - -The file path_config is *not* under version control, this is on -purpose because every user can/should have a private confiiguration of -paths. The file path_config should define make-variables for the -location of all the libraries, this is an example of a valid -path-config file: - - LIBHASH_HOME = /h/a152128/EnKF/EnKF/libhash - LIBUTIL_HOME = /h/a152128/EnKF/EnKF/libutil - LIBSCHED_HOME = /h/a152128/EnKF/EnKF/libsched - LIBRMS_HOME = /h/a152128/EnKF/EnKF/librms - LIBECL_HOME = /h/a152128/EnKF/EnKF/libecl - LIBENKF_HOME = /h/a152128/EnKF/EnKF/libenkf - -In this example all libraries have a common path prefix, that is not -a requirement. - - - diff --git a/lib/ecl/tests/ecl_coarse_test.cpp b/lib/ecl/tests/ecl_coarse_test.cpp deleted file mode 100644 index e1adf9adab..0000000000 --- a/lib/ecl/tests/ecl_coarse_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include - -void test_coarse_cell(const ecl_grid_type *grid, ecl_coarse_cell_type *cell) { - const int_vector_type *global_index_list = - ecl_coarse_cell_get_index_vector(cell); - const int *ijk = ecl_coarse_cell_get_box_ptr(cell); - int c; - int prev_active = 0; - - for (c = 0; c < ecl_coarse_cell_get_size(cell); c++) { - int gi = int_vector_iget(global_index_list, c); - int i, j, k; - - /* The coordinates are right */ - ecl_grid_get_ijk1(grid, gi, &i, &j, &k); - if ((i < ijk[0]) || (i > ijk[1])) - test_error_exit("i:%d not inside range [%d,%d] \n", i, ijk[0], - ijk[1]); - - if ((j < ijk[2]) || (j > ijk[3])) - test_error_exit("j:%d not inside range [%d,%d] \n", j, ijk[2], - ijk[3]); - - if ((k < ijk[4]) || (k > ijk[5])) - test_error_exit("k:%d not inside range [%d,%d] \n", k, ijk[4], - ijk[4]); - - if (c == 0) - prev_active = ecl_grid_get_active_index1(grid, gi); - else { - /* All the cells have the same active value */ - int this_active = ecl_grid_get_active_index1(grid, gi); - test_assert_int_equal(prev_active, this_active); - prev_active = this_active; - } - } -} - -int main(int argc, char **argv) { - const char *case_path = argv[1]; - char *egrid_file = - ecl_util_alloc_filename(NULL, case_path, ECL_EGRID_FILE, false, 0); - char *rst_file = - ecl_util_alloc_filename(NULL, case_path, ECL_RESTART_FILE, false, 0); - char *init_file = - ecl_util_alloc_filename(NULL, case_path, ECL_INIT_FILE, false, 0); - - ecl_grid_type *GRID = ecl_grid_alloc(egrid_file); - ecl_file_type *RST_file = ecl_file_open(rst_file, 0); - ecl_file_type *INIT_file = ecl_file_open(init_file, 0); - - { - test_assert_true(ecl_grid_have_coarse_cells(GRID)); - test_assert_int_equal(ecl_grid_get_num_coarse_groups(GRID), 3384); - } - - { - const ecl_kw_type *swat0 = ecl_file_iget_named_kw(RST_file, "SWAT", 0); - const ecl_kw_type *porv = ecl_file_iget_named_kw(INIT_file, "PORV", 0); - - test_assert_int_equal(ecl_kw_get_size(swat0), - ecl_grid_get_active_size(GRID)); - test_assert_int_equal(ecl_kw_get_size(porv), - ecl_grid_get_global_size(GRID)); - } - - { - int ic; - for (ic = 0; ic < ecl_grid_get_num_coarse_groups(GRID); ic++) { - ecl_coarse_cell_type *coarse_cell = - ecl_grid_iget_coarse_group(GRID, ic); - test_coarse_cell(GRID, coarse_cell); - } - } - - ecl_file_close(INIT_file); - ecl_file_close(RST_file); - ecl_grid_free(GRID); - exit(0); -} diff --git a/lib/ecl/tests/ecl_dualp.cpp b/lib/ecl/tests/ecl_dualp.cpp deleted file mode 100644 index 061744e015..0000000000 --- a/lib/ecl/tests/ecl_dualp.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include - -int main(int argc, char **argv) { - const char *case_path = argv[1]; - char *grid_file = - ecl_util_alloc_filename(NULL, case_path, ECL_EGRID_FILE, false, 0); - char *init_file = - ecl_util_alloc_filename(NULL, case_path, ECL_INIT_FILE, false, 0); - char *rst_file = - ecl_util_alloc_filename(NULL, case_path, ECL_RESTART_FILE, false, 0); - - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_file); - ecl_file_type *RST_file = ecl_file_open(rst_file, 0); - ecl_file_type *INIT_file = ecl_file_open(init_file, 0); - ecl_file_type *GRID_file = ecl_file_open(grid_file, 0); - - { - ecl_kw_type *actnum = ecl_file_iget_named_kw(GRID_file, "ACTNUM", 0); - ecl_kw_type *swat = ecl_file_iget_named_kw(RST_file, "SWAT", 0); - ecl_kw_type *permx = ecl_file_iget_named_kw(INIT_file, "PERMX", 0); - int fracture_size = ecl_grid_get_nactive_fracture(ecl_grid); - int matrix_size = ecl_grid_get_nactive(ecl_grid); - - test_assert_int_equal(fracture_size + matrix_size, - ecl_kw_get_size(swat)); - test_assert_int_equal(fracture_size + matrix_size, - ecl_kw_get_size(permx)); - - { - int gi; - int matrix_index = 0; - int fracture_index = 0; - - for (gi = 0; gi < ecl_grid_get_global_size(ecl_grid); gi++) { - if (ecl_kw_iget_int(actnum, gi) & CELL_ACTIVE_MATRIX) { - test_assert_int_equal( - ecl_grid_get_active_index1(ecl_grid, gi), matrix_index); - test_assert_int_equal( - ecl_grid_get_global_index1A(ecl_grid, matrix_index), - gi); - matrix_index++; - } - - if (ecl_kw_iget_int(actnum, gi) & CELL_ACTIVE_FRACTURE) { - test_assert_int_equal( - ecl_grid_get_active_fracture_index1(ecl_grid, gi), - fracture_index); - test_assert_int_equal( - ecl_grid_get_global_index1F(ecl_grid, fracture_index), - gi); - fracture_index++; - } - } - } - } - - ecl_file_close(RST_file); - ecl_file_close(INIT_file); - ecl_grid_free(ecl_grid); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_file.cpp b/lib/ecl/tests/ecl_file.cpp deleted file mode 100644 index 39f032cf3b..0000000000 --- a/lib/ecl/tests/ecl_file.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -void test_writable(size_t data_size) { - ecl::util::TestArea ta("file_writable"); - const char *data_file_name = "test_file"; - - ecl_kw_type *kw = ecl_kw_alloc("TEST_KW", data_size, ECL_INT); - for (size_t i = 0; i < data_size; ++i) - ecl_kw_iset_int(kw, i, ((i * 37) + 11) % data_size); - - fortio_type *fortio = fortio_open_writer(data_file_name, false, true); - ecl_kw_fwrite(kw, fortio); - fortio_fclose(fortio); - - for (int i = 0; i < 4; ++i) { - ecl_file_type *ecl_file = - ecl_file_open(data_file_name, ECL_FILE_WRITABLE); - ecl_kw_type *loaded_kw = - ecl_file_view_iget_kw(ecl_file_get_global_view(ecl_file), 0); - test_assert_true(ecl_kw_equal(kw, loaded_kw)); - - ecl_file_save_kw(ecl_file, loaded_kw); - ecl_file_close(ecl_file); - } - - ecl_kw_free(kw); -} - -void test_truncated() { - ecl::util::TestArea ta("truncate_file"); - int num_kw; - { - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(20, 20, 20, 1, 1, 1, NULL); - ecl_grid_fwrite_EGRID2(grid, "TEST.EGRID", ECL_METRIC_UNITS); - ecl_grid_free(grid); - } - { - ecl_file_type *ecl_file = ecl_file_open("TEST.EGRID", 0); - test_assert_true(ecl_file_is_instance(ecl_file)); - num_kw = ecl_file_get_size(ecl_file); - test_assert_int_equal(ecl_file_get_num_distinct_kw(ecl_file), 11); - ecl_file_close(ecl_file); - } - - { - offset_type file_size = util_file_size("TEST.EGRID"); - FILE *stream = util_fopen("TEST.EGRID", "r+"); - util_ftruncate(stream, file_size / 2); - fclose(stream); - } - { - ecl_file_type *ecl_file = ecl_file_open("TEST.EGRID", 0); - test_assert_true(ecl_file_get_size(ecl_file) < num_kw); - ecl_file_close(ecl_file); - } -} - -void test_mixed_case() { - ecl::util::TestArea ta("mixed_case_file"); - int num_kw; - { - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(20, 20, 20, 1, 1, 1, NULL); - ecl_grid_fwrite_EGRID2(grid, "TESTcase.EGRID", ECL_METRIC_UNITS); - ecl_grid_free(grid); - } - { - ecl_file_type *ecl_file = ecl_file_open("TESTcase.EGRID", 0); - test_assert_true(ecl_file_is_instance(ecl_file)); - num_kw = ecl_file_get_size(ecl_file); - test_assert_int_equal(ecl_file_get_num_distinct_kw(ecl_file), 11); - ecl_file_close(ecl_file); - } - - { - offset_type file_size = util_file_size("TESTcase.EGRID"); - FILE *stream = util_fopen("TESTcase.EGRID", "r+"); - util_ftruncate(stream, file_size / 2); - fclose(stream); - } - { - ecl_file_type *ecl_file = ecl_file_open("TESTcase.EGRID", 0); - test_assert_true(ecl_file_get_size(ecl_file) < num_kw); - ecl_file_close(ecl_file); - } -} - -int main(int argc, char **argv) { - test_writable(10); - test_writable(1337); - test_truncated(); - test_mixed_case(); - exit(0); -} diff --git a/lib/ecl/tests/ecl_file_equinor.cpp b/lib/ecl/tests/ecl_file_equinor.cpp deleted file mode 100644 index b9f281ee1a..0000000000 --- a/lib/ecl/tests/ecl_file_equinor.cpp +++ /dev/null @@ -1,125 +0,0 @@ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -void test_flags(const char *filename) { - int FLAG1 = 1; - int FLAG2 = 2; - int FLAG3 = 4; - int FLAG4 = 8; - - int FLAGS = FLAG1 + FLAG2 + FLAG3; - - ecl_file_type *ecl_file = ecl_file_open(filename, FLAGS); - - test_assert_int_equal(ecl_file_get_flags(ecl_file), FLAGS); - test_assert_true(ecl_file_flags_set(ecl_file, FLAG1)); - test_assert_true(ecl_file_flags_set(ecl_file, FLAG1 | FLAG2)); - test_assert_true(ecl_file_flags_set(ecl_file, FLAG1 | FLAG3)); - test_assert_true(ecl_file_flags_set(ecl_file, FLAG1 | FLAG3 | FLAG2)); - test_assert_false(ecl_file_flags_set(ecl_file, FLAG1 | FLAG3 | FLAG4)); - ecl_file_close(ecl_file); -} - -void test_close_stream2(const char *src_file, const char *target_file) { - util_copy_file(src_file, target_file); - ecl_file_type *ecl_file = ecl_file_open(target_file, ECL_FILE_CLOSE_STREAM); - - ecl_file_load_all(ecl_file); - unlink(target_file); - ecl_kw_type *kw2 = ecl_file_iget_kw(ecl_file, 2); - test_assert_not_NULL(kw2); - ecl_file_close(ecl_file); -} - -void test_loadall(const char *src_file, const char *target_file) { - util_copy_file(src_file, target_file); - { - ecl_file_type *ecl_file = - ecl_file_open(target_file, ECL_FILE_CLOSE_STREAM); - - test_assert_true(ecl_file_load_all(ecl_file)); - ecl_file_close(ecl_file); - } - - { - ecl_file_type *ecl_file = - ecl_file_open(target_file, ECL_FILE_CLOSE_STREAM); - unlink(target_file); - - test_assert_false(ecl_file_load_all(ecl_file)); - ecl_file_close(ecl_file); - } -} - -void test_close_stream1(const char *src_file, const char *target_file) { - util_copy_file(src_file, target_file); - - ecl_file_type *ecl_file = ecl_file_open(target_file, ECL_FILE_CLOSE_STREAM); - ecl_kw_type *kw0 = ecl_file_iget_kw(ecl_file, 0); - ecl_kw_type *kw1 = ecl_file_iget_kw(ecl_file, 1); - unlink(target_file); - ecl_kw_type *kw1b = ecl_file_iget_kw(ecl_file, 1); - - test_assert_not_NULL(kw0); - test_assert_not_NULL(kw1); - test_assert_ptr_equal(kw1, kw1b); - - ecl_kw_type *kw2 = ecl_file_iget_kw(ecl_file, 2); - test_assert_NULL(kw2); - - test_assert_false(ecl_file_writable(ecl_file)); - - ecl_file_close(ecl_file); -} - -void test_writable(const char *src_file) { - ecl::util::TestArea ta("file_writable"); - char *fname = util_split_alloc_filename(src_file); - - ta.copy_file(src_file); - { - test_flags(fname); - ecl_file_type *ecl_file = ecl_file_open(fname, ECL_FILE_WRITABLE); - ecl_kw_type *swat = ecl_file_iget_named_kw(ecl_file, "SWAT", 0); - ecl_kw_type *swat0 = ecl_kw_alloc_copy(swat); - test_assert_true(ecl_kw_equal(swat, swat0)); - ecl_kw_iset_float(swat, 0, 1000.0); - ecl_file_save_kw(ecl_file, swat); - test_assert_true(ecl_file_writable(ecl_file)); - ecl_file_close(ecl_file); - - ecl_file = ecl_file_open(fname, 0); - swat = ecl_file_iget_named_kw(ecl_file, "SWAT", 0); - test_assert_true( - util_double_approx_equal(ecl_kw_iget_float(swat, 0), 1000)); - } -} - -int main(int argc, char **argv) { - const char *src_file = argv[1]; - const char *target_file = argv[2]; - - { - ecl::util::TestArea ta("file_equinor"); - - ta.copy_file(src_file); - test_loadall(src_file, target_file); - - test_close_stream1(src_file, target_file); - test_close_stream2(src_file, target_file); - test_writable(src_file); - } - exit(0); -} diff --git a/lib/ecl/tests/ecl_file_view.cpp b/lib/ecl/tests/ecl_file_view.cpp deleted file mode 100644 index b84bce33df..0000000000 --- a/lib/ecl/tests/ecl_file_view.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -void test_file_kw_equal() { - ecl_file_kw_type *kw1 = ecl_file_kw_alloc0("PRESSURE", ECL_FLOAT, 1000, 66); - ecl_file_kw_type *kw2 = ecl_file_kw_alloc0("PRESSURE", ECL_FLOAT, 1000, 66); - ecl_file_kw_type *kw3 = ecl_file_kw_alloc0("SWAT", ECL_FLOAT, 1000, 66); - ecl_file_kw_type *kw4 = - ecl_file_kw_alloc0("PRESSURE", ECL_DOUBLE, 1000, 66); - ecl_file_kw_type *kw5 = ecl_file_kw_alloc0("PRESSURE", ECL_FLOAT, 10, 66); - ecl_file_kw_type *kw6 = ecl_file_kw_alloc0("PRESSURE", ECL_FLOAT, 1000, 67); - - test_assert_true(ecl_file_kw_equal(kw1, kw1)); - test_assert_true(ecl_file_kw_equal(kw1, kw2)); - test_assert_false(ecl_file_kw_equal(kw1, kw3)); - test_assert_false(ecl_file_kw_equal(kw1, kw4)); - test_assert_false(ecl_file_kw_equal(kw1, kw5)); - test_assert_false(ecl_file_kw_equal(kw1, kw6)); - - ecl_file_kw_free(kw6); - ecl_file_kw_free(kw5); - ecl_file_kw_free(kw4); - ecl_file_kw_free(kw3); - ecl_file_kw_free(kw2); - ecl_file_kw_free(kw1); -} - -void test_create_file_kw() { - ecl_file_kw_type *file_kw0 = - ecl_file_kw_alloc0("PRESSURE", ECL_FLOAT, 1000, 66); - ecl_file_kw_type *file_kw1 = - ecl_file_kw_alloc0("TEST1_KW", ECL_FLOAT, 2000, 1066); - ecl_file_kw_type *file_kw2 = - ecl_file_kw_alloc0("TEST2_KW", ECL_FLOAT, 3000, 2066); - test_assert_string_equal(ecl_file_kw_get_header(file_kw0), "PRESSURE"); - test_assert_int_equal(ecl_file_kw_get_size(file_kw0), 1000); - test_assert_true( - ecl_type_is_equal(ecl_file_kw_get_data_type(file_kw0), ECL_FLOAT)); - { - ecl::util::TestArea ta("file_kw"); - { - FILE *ostream = util_fopen("file_kw", "w"); - ecl_file_kw_fwrite(file_kw0, ostream); - fclose(ostream); - } - { - FILE *istream = util_fopen("file_kw", "r"); - ecl_file_kw_type *disk_kw = ecl_file_kw_fread_alloc(istream); - test_assert_true(ecl_file_kw_equal(file_kw0, disk_kw)); - - /* Beyond the end of stream - return NULL */ - test_assert_NULL(ecl_file_kw_fread_alloc(istream)); - ecl_file_kw_free(disk_kw); - fclose(istream); - } - - { - FILE *ostream = util_fopen("file_kw", "w"); - ecl_file_kw_fwrite(file_kw0, ostream); - ecl_file_kw_fwrite(file_kw1, ostream); - ecl_file_kw_fwrite(file_kw2, ostream); - fclose(ostream); - } - - { - FILE *istream = util_fopen("file_kw", "r"); - ecl_file_kw_type **disk_kw = - ecl_file_kw_fread_alloc_multiple(istream, 3); - test_assert_true(ecl_file_kw_equal(file_kw0, disk_kw[0])); - test_assert_true(ecl_file_kw_equal(file_kw1, disk_kw[1])); - test_assert_true(ecl_file_kw_equal(file_kw2, disk_kw[2])); - - for (int i = 0; i < 3; i++) - ecl_file_kw_free(disk_kw[i]); - free(disk_kw); - fclose(istream); - } - { - FILE *istream = util_fopen("file_kw", "r"); - test_assert_NULL(ecl_file_kw_fread_alloc_multiple(istream, 10)); - fclose(istream); - } - } - ecl_file_kw_free(file_kw0); - ecl_file_kw_free(file_kw1); - ecl_file_kw_free(file_kw2); -} - -int main(int argc, char **argv) { - util_install_signals(); - test_file_kw_equal(); - test_create_file_kw(); -} diff --git a/lib/ecl/tests/ecl_get_num_cpu_test.cpp b/lib/ecl/tests/ecl_get_num_cpu_test.cpp deleted file mode 100644 index 692acf01c6..0000000000 --- a/lib/ecl/tests/ecl_get_num_cpu_test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -#include -#include - -int main(int argc, char **argv) { - const char *filename1 = argv[1]; - const char *filename2 = argv[2]; - const char *filename3 = argv[3]; - const char *filename4 = argv[4]; - const char *filename5 = argv[5]; - - test_assert_int_equal(ecl_util_get_num_cpu(filename1), 4); - test_assert_int_equal(ecl_util_get_num_cpu(filename2), 4); - test_assert_int_equal(ecl_util_get_num_cpu(filename3), 15); - test_assert_int_equal(ecl_util_get_num_cpu(filename4), 4); - test_assert_int_equal(ecl_util_get_num_cpu(filename5), 4); - exit(0); -} diff --git a/lib/ecl/tests/ecl_grid_add_nnc.cpp b/lib/ecl/tests/ecl_grid_add_nnc.cpp deleted file mode 100644 index eb9222fab9..0000000000 --- a/lib/ecl/tests/ecl_grid_add_nnc.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -void verify_simple_nnc(const ecl_grid_type *grid) { - test_assert_not_NULL(ecl_grid_get_cell_nnc_info1(grid, 5)); - test_assert_not_NULL(ecl_grid_get_cell_nnc_info1(grid, 8)); - - // Cell 5: - { - const nnc_info_type *nnc_info = ecl_grid_get_cell_nnc_info1(grid, 5); - const nnc_vector_type *nnc_vector = nnc_info_iget_vector(nnc_info, 0); - test_assert_int_equal(2, nnc_vector_get_size(nnc_vector)); - test_assert_int_equal(6, nnc_vector_iget_grid_index(nnc_vector, 0)); - test_assert_int_equal(7, nnc_vector_iget_grid_index(nnc_vector, 1)); - - test_assert_int_equal(0, nnc_vector_iget_nnc_index(nnc_vector, 0)); - test_assert_int_equal(1, nnc_vector_iget_nnc_index(nnc_vector, 1)); - } - - // Cell 8: - { - const nnc_info_type *nnc_info = ecl_grid_get_cell_nnc_info1(grid, 8); - const nnc_vector_type *nnc_vector = nnc_info_iget_vector(nnc_info, 0); - test_assert_int_equal(1, nnc_vector_get_size(nnc_vector)); - test_assert_int_equal(9, nnc_vector_iget_grid_index(nnc_vector, 0)); - test_assert_int_equal(2, nnc_vector_iget_nnc_index(nnc_vector, 0)); - } -} - -void simple_test() { - ecl_grid_type *grid0 = - ecl_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); - ecl_grid_add_self_nnc(grid0, 5, 6, 0); - ecl_grid_add_self_nnc(grid0, 5, 7, 1); - ecl_grid_add_self_nnc(grid0, 8, 9, 2); - - verify_simple_nnc(grid0); - { - ecl::util::TestArea ta("simple_nnc"); - ecl_grid_type *grid1; - ecl_grid_fwrite_EGRID2(grid0, "TEST.EGRID", ECL_METRIC_UNITS); - grid1 = ecl_grid_alloc("TEST.EGRID"); - - verify_simple_nnc(grid1); - ecl_grid_free(grid1); - } - ecl_grid_free(grid0); -} - -void overwrite_test() { - ecl_grid_type *grid0 = - ecl_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); - - /* - This first list of nnc will be overwritten, and will not survive - the serialization to disk. - */ - - ecl_grid_add_self_nnc(grid0, 1, 2, 0); - ecl_grid_add_self_nnc(grid0, 1, 3, 1); - ecl_grid_add_self_nnc(grid0, 1, 4, 2); - - ecl_grid_add_self_nnc(grid0, 5, 6, 0); - ecl_grid_add_self_nnc(grid0, 5, 7, 1); - ecl_grid_add_self_nnc(grid0, 8, 9, 2); - - verify_simple_nnc(grid0); - { - ecl::util::TestArea ta("overwrite"); - ecl_grid_type *grid1; - ecl_grid_fwrite_EGRID2(grid0, "TEST.EGRID", ECL_METRIC_UNITS); - grid1 = ecl_grid_alloc("TEST.EGRID"); - - verify_simple_nnc(grid1); - ecl_grid_free(grid1); - } - ecl_grid_free(grid0); -} - -void list_test() { - ecl_grid_type *grid0 = - ecl_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); - int_vector_type *g1 = int_vector_alloc(0, 0); - int_vector_type *g2 = int_vector_alloc(0, 0); - - int_vector_append(g1, 5); - int_vector_append(g2, 6); - int_vector_append(g1, 5); - int_vector_append(g2, 7); - int_vector_append(g1, 8); - int_vector_append(g2, 9); - - ecl_grid_add_self_nnc_list(grid0, int_vector_get_ptr(g1), - int_vector_get_ptr(g2), int_vector_size(g1)); - - verify_simple_nnc(grid0); - { - ecl::util::TestArea ta("list_test"); - ecl_grid_type *grid1; - ecl_grid_fwrite_EGRID2(grid0, "TEST.EGRID", ECL_METRIC_UNITS); - grid1 = ecl_grid_alloc("TEST.EGRID"); - - verify_simple_nnc(grid1); - ecl_grid_free(grid1); - } - int_vector_free(g1); - int_vector_free(g2); - ecl_grid_free(grid0); -} - -int main(int argc, char **argv) { - simple_test(); - list_test(); - overwrite_test(); - exit(0); -} diff --git a/lib/ecl/tests/ecl_grid_cell_contains.cpp b/lib/ecl/tests/ecl_grid_cell_contains.cpp deleted file mode 100644 index 15325f88bb..0000000000 --- a/lib/ecl/tests/ecl_grid_cell_contains.cpp +++ /dev/null @@ -1,279 +0,0 @@ -#include -#include -#include - -#include -#include - -bool get_test_point1(const ecl_grid_type *grid, int global_index, double *_xpos, - double *_ypos, double *_zpos) { - const int corners[4] = {1, 2, 5, 6}; - double xpos = 0; - double ypos = 0; - double zpos = 0; - const double min_volume = 1e-8; - - if (fabs(ecl_grid_get_cell_volume1(grid, global_index)) <= min_volume) - return false; - - if (ecl_grid_get_cell_twist1(grid, global_index) > 0) - return false; - - if (!ecl_grid_cell_regular1(grid, global_index)) - return false; - - for (int ci = 0; ci < 4; ci++) { - int corner = corners[ci]; - double x, y, z; - ecl_grid_get_cell_corner_xyz1(grid, global_index, corner, &x, &y, &z); - xpos += x; - ypos += y; - zpos += z; - } - - *_xpos = xpos * 0.25; - *_ypos = ypos * 0.25; - *_zpos = zpos * 0.25; - - return ecl_grid_cell_contains_xyz1(grid, global_index, *_xpos, *_ypos, - *_zpos); -} - -bool get_test_point3(const ecl_grid_type *grid, int i, int j, int k, - double *_xpos, double *_ypos, double *_zpos) { - const int global_index = ecl_grid_get_global_index3(grid, i, j, k); - return get_test_point1(grid, global_index, _xpos, _ypos, _zpos); -} - -void test_grid_covering(const ecl_grid_type *grid) { - const int nx = ecl_grid_get_nx(grid); - const int ny = ecl_grid_get_ny(grid); - const int nz = ecl_grid_get_nz(grid); - - for (int k = 0; k < nz - 1; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - int g1 = ecl_grid_get_global_index3(grid, i, j, k); - int g2 = ecl_grid_get_global_index3(grid, i, j, k + 1); - double p1[3]; - double p2[3]; - - for (int l = 0; l < 4; l++) { - ecl_grid_get_cell_corner_xyz1(grid, g1, l + 4, &p1[0], - &p1[1], &p1[2]); - ecl_grid_get_cell_corner_xyz1(grid, g2, l, &p2[0], &p2[1], - &p2[2]); - test_assert_true(p1[0] == p2[0]); - test_assert_true(p1[1] == p2[1]); - test_assert_true(p1[2] == p2[2]); - } - - for (int l = 0; l < 4; l++) { - ecl_grid_get_cell_corner_xyz1(grid, g1, l, &p1[0], &p1[1], - &p1[2]); - ecl_grid_get_cell_corner_xyz1(grid, g1, l + 4, &p2[0], - &p2[1], &p2[2]); - - test_assert_true(p2[2] >= p1[2]); - } - } - } - } -} - -void assert_contains(const ecl_grid_type *grid, int i, int j, int k, double x, - double y, double z) { - if (!ecl_grid_cell_contains_xyz3(grid, i, j, k, x, y, z)) - fprintf(stderr, " Point: (%g,%g,%g) not found in cell: (%d,%d,%d) \n", - x, y, z, i, j, k); - - test_assert_true(ecl_grid_cell_contains_xyz3(grid, i, j, k, x, y, z)); -} - -void test_contains(const ecl_grid_type *grid) { - const int nx = ecl_grid_get_nx(grid); - const int ny = ecl_grid_get_ny(grid); - const int nz = ecl_grid_get_nz(grid); - - for (int k = 0; k < nz; k++) { - for (int j = 0; j < ny; j++) { - for (int i = 0; i < nx; i++) { - if (ecl_grid_get_cell_twist3(grid, i, j, k) != 0) { - double x, y, z; - if (get_test_point3(grid, i, j, k, &x, &y, &z)) { - assert_contains(grid, i, j, k, x, y, z); - { - int i2, j2, k2; - int kmin = util_int_max(0, k - 1); - int kmax = util_int_min(nz, k + 1); - - int jmin = util_int_max(0, j - 1); - int jmax = util_int_min(ny, j + 1); - - int imin = util_int_max(0, i - 1); - int imax = util_int_min(nx, i + 1); - - for (k2 = kmin; k2 < kmax; k2++) { - for (j2 = jmin; j2 < jmax; j2++) { - for (i2 = imin; i2 < imax; i2++) { - if ((i != i2) && (j != j2) && - (k != k2)) { - if (ecl_grid_get_cell_twist3( - grid, i2, j2, k2) == 0) - test_assert_false( - ecl_grid_cell_contains_xyz3( - grid, i2, j2, k2, x, y, - z)); - } - } - } - } - } - } - } - } - } - } -} - -void test_find(ecl_grid_type *grid) { - int init_index; - int find_count = 100; - int delta = util_int_max(1, ecl_grid_get_global_size(grid) / find_count); - for (init_index = 0; init_index < ecl_grid_get_global_size(grid); - init_index += delta) { - if (ecl_grid_get_cell_twist1(grid, init_index) == 0) { - double x, y, z; - int find_index; - int start_index = 0; - - if (get_test_point1(grid, init_index, &x, &y, &z)) { - find_index = ecl_grid_get_global_index_from_xyz(grid, x, y, z, - start_index); - if (init_index != find_index) { - int i1, j1, k1, i2, j2, k2; - - ecl_grid_get_ijk1(grid, init_index, &i1, &j1, &k1); - ecl_grid_get_ijk1(grid, find_index, &i2, &j2, &k2); - printf(" point: %14.7f %14.7f %14.7f \n", x, y, z); - printf(" Regular: %d / %d \n", - ecl_grid_cell_regular3(grid, i1, j1, k1), - ecl_grid_cell_regular3(grid, i2, j2, k2)); - printf( - " init: contains(%7d) : %d (%d,%d,%d) V:%g \n", - init_index, - ecl_grid_cell_contains_xyz1(grid, init_index, x, y, z), - i1 + 1, j1 + 1, k1 + 1, - ecl_grid_get_cell_volume1(grid, init_index)); - printf( - "ERROR: find: contains(%7d) : %d (%d,%d,%d) V:%g " - "\n\n", - find_index, - ecl_grid_cell_contains_xyz1(grid, find_index, x, y, z), - i2 + 1, j2 + 1, k2 + 1, - ecl_grid_get_cell_volume1(grid, find_index)); - test_assert_int_equal(init_index, find_index); - } - } - } - } -} - -void test_corners() { - ecl_grid_type *grid = ecl_grid_alloc_rectangular(3, 3, 3, 1, 1, 1, NULL); - - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, -1, -1, -1, 0)); - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, -1, 1, 1, 0)); - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, 1, -1, 1, 0)); - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, 1, 1, -1, 0)); - - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, 3.5, 3.5, 3.5, 0)); - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, 3.5, 1, 1, 0)); - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, 1, 3.5, 1, 0)); - test_assert_int_equal( - -1, ecl_grid_get_global_index_from_xyz(grid, 1, 1, 3.5, 0)); - - { - double x, y, z; - int i; - ecl_grid_get_cell_corner_xyz3(grid, 0, 0, 0, 0, &x, &y, &z); - test_assert_int_equal( - 0, ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - for (i = 1; i < 8; i++) { - ecl_grid_get_cell_corner_xyz3(grid, 0, 0, 0, i, &x, &y, &z); - test_assert_int_not_equal( - 0, ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - } - - // Corner 1 - ecl_grid_get_cell_corner_xyz3(grid, 2, 0, 0, 1, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 2, 0, 0), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 2 - ecl_grid_get_cell_corner_xyz3(grid, 0, 2, 0, 2, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 0, 2, 0), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 3 - ecl_grid_get_cell_corner_xyz3(grid, 2, 2, 0, 3, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 2, 2, 0), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 4 - ecl_grid_get_cell_corner_xyz3(grid, 0, 0, 2, 4, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 0, 0, 2), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 5 - ecl_grid_get_cell_corner_xyz3(grid, 2, 0, 2, 5, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 2, 0, 2), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 6 - ecl_grid_get_cell_corner_xyz3(grid, 0, 2, 2, 6, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 0, 2, 2), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - - // Corner 7 - ecl_grid_get_cell_corner_xyz3(grid, 2, 2, 2, 7, &x, &y, &z); - test_assert_int_equal( - ecl_grid_get_global_index3(grid, 2, 2, 2), - ecl_grid_get_global_index_from_xyz(grid, x, y, z, 0)); - } - - ecl_grid_free(grid); -} - -int main(int argc, char **argv) { - ecl_grid_type *grid; - - util_install_signals(); - - if (argc == 1) { - grid = ecl_grid_alloc_rectangular(6, 6, 6, 1, 2, 3, NULL); - } else - grid = ecl_grid_alloc(argv[1]); - - test_grid_covering(grid); - test_contains(grid); - - test_find(grid); - test_corners(); - ecl_grid_free(grid); - exit(0); -} diff --git a/lib/ecl/tests/ecl_grid_copy.cpp b/lib/ecl/tests/ecl_grid_copy.cpp deleted file mode 100644 index 869d56dbf6..0000000000 --- a/lib/ecl/tests/ecl_grid_copy.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -void test_copy_grid(const ecl_grid_type *grid) { - ecl_grid_type *grid_copy = ecl_grid_alloc_copy(grid); - test_assert_true(ecl_grid_compare(grid, grid_copy, true, true, true)); - ecl_grid_free(grid_copy); -} - -void test_copy_grid_file(const char *filename) { - ecl_grid_type *src_grid = ecl_grid_alloc(filename); - ecl_grid_type *copy_grid = ecl_grid_alloc_copy(src_grid); - test_assert_true(ecl_grid_compare(src_grid, copy_grid, true, true, true)); - ecl_grid_free(copy_grid); - ecl_grid_free(src_grid); -} - -int main(int argc, char **argv) { - if (argc < 2) { - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(10, 11, 12, 1, 2, 3, NULL); - test_copy_grid(grid); - ecl_grid_free(grid); - } else { - test_copy_grid_file(argv[1]); - } - exit(0); -} diff --git a/lib/ecl/tests/ecl_grid_dx_dy_dz.cpp b/lib/ecl/tests/ecl_grid_dx_dy_dz.cpp deleted file mode 100644 index ad73163b8a..0000000000 --- a/lib/ecl/tests/ecl_grid_dx_dy_dz.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -double err(double a, double b) { return (a - b) / a; } - -void test_dxdydz(const std::string &grid_fname, const std::string &init_fname) { - double eps_x = 1e-4; - double eps_y = 1e-4; - double eps_z = 1e-3; - ecl_grid_type *grid = ecl_grid_alloc(grid_fname.c_str()); - ecl_file_type *init_file = ecl_file_open(init_fname.c_str(), 0); - ecl_kw_type *dx = ecl_file_iget_named_kw(init_file, "DX", 0); - ecl_kw_type *dy = ecl_file_iget_named_kw(init_file, "DY", 0); - ecl_kw_type *dz = ecl_file_iget_named_kw(init_file, "DZ", 0); - for (int a = 0; a < ecl_grid_get_active_size(grid); a += 100) { - int g = ecl_grid_get_global_index1A(grid, a); - - double dxg = ecl_grid_get_cell_dx1(grid, g); - double dyg = ecl_grid_get_cell_dy1(grid, g); - double dzg = ecl_grid_get_cell_dz1(grid, g); - - double dxi = ecl_kw_iget_float(dx, a); - double dyi = ecl_kw_iget_float(dy, a); - double dzi = ecl_kw_iget_float(dz, a); - - double err_x = fabs(err(dxg, dxi)); - double err_y = fabs(err(dyg, dyi)); - double err_z = fabs(err(dzg, dzi)); - - test_assert_true(err_x < eps_x); - test_assert_true(err_y < eps_y); - test_assert_true(err_z < eps_z); - } - ecl_file_close(init_file); - ecl_grid_free(grid); -} - -int main(int argc, char **argv) { - const std::string ecl_case = argv[1]; - std::string grid_file = ecl_case + ".EGRID"; - std::string init_file = ecl_case + ".INIT"; - - test_dxdydz(grid_file, init_file); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_grid_export.cpp b/lib/ecl/tests/ecl_grid_export.cpp deleted file mode 100644 index 2f3b1a5a51..0000000000 --- a/lib/ecl/tests/ecl_grid_export.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include -#include - -#include -#include - -#include -#include -#include - -void export_actnum(const ecl_grid_type *ecl_grid, ecl_file_type *ecl_file) { - ecl_kw_type *actnum_kw = ecl_file_iget_named_kw(ecl_file, "ACTNUM", 0); - int *actnum = - (int *)util_malloc(ecl_kw_get_size(actnum_kw) * sizeof *actnum); - - ecl_grid_init_actnum_data(ecl_grid, actnum); - for (int i = 0; i < ecl_kw_get_size(actnum_kw); i++) - test_assert_int_equal(actnum[i], ecl_kw_iget_int(actnum_kw, i)); - - free(actnum); -} - -void export_coord(const ecl_grid_type *grid, ecl_file_type *ecl_file) { - ecl_kw_type *coord_kw = ecl_file_iget_named_kw(ecl_file, "COORD", 0); - test_assert_int_equal(ecl_kw_get_size(coord_kw), - ecl_grid_get_coord_size(grid)); - { - float *coord_float = (float *)util_malloc( - ecl_grid_get_coord_size(grid) * sizeof *coord_float); - double *coord_double = (double *)util_malloc( - ecl_grid_get_coord_size(grid) * sizeof *coord_double); - - ecl_grid_init_coord_data(grid, coord_float); - ecl_grid_init_coord_data_double(grid, coord_double); - - for (int i = 0; i < ecl_grid_get_coord_size(grid); i++) - test_assert_double_equal(coord_double[i], coord_float[i]); - - free(coord_float); - free(coord_double); - } -} - -void export_zcorn(const ecl_grid_type *grid, ecl_file_type *ecl_file) { - ecl_kw_type *zcorn_kw = ecl_file_iget_named_kw(ecl_file, "ZCORN", 0); - test_assert_int_equal(ecl_kw_get_size(zcorn_kw), - ecl_grid_get_zcorn_size(grid)); - { - float *zcorn_float = (float *)util_malloc( - ecl_grid_get_zcorn_size(grid) * sizeof *zcorn_float); - double *zcorn_double = (double *)util_malloc( - ecl_grid_get_zcorn_size(grid) * sizeof *zcorn_double); - - ecl_grid_init_zcorn_data(grid, zcorn_float); - ecl_grid_init_zcorn_data_double(grid, zcorn_double); - - for (int i = 0; i < ecl_grid_get_zcorn_size(grid); i++) { - test_assert_double_equal(zcorn_double[i], zcorn_float[i]); - test_assert_float_equal(zcorn_float[i], - ecl_kw_iget_float(zcorn_kw, i)); - } - - free(zcorn_float); - free(zcorn_double); - } -} - -void copy_processed(const ecl_grid_type *src) { - { - ecl_grid_type *copy = ecl_grid_alloc_processed_copy(src, NULL, NULL); - test_assert_true(ecl_grid_compare(src, copy, true, true, false)); - ecl_grid_free(copy); - } - - { - int *actnum = - (int *)util_malloc(ecl_grid_get_global_size(src) * sizeof *actnum); - int index = 0; - ecl_grid_init_actnum_data(src, actnum); - - while (true) { - if (actnum[index] == 1) { - actnum[index] = 0; - break; - } - index++; - } - - { - ecl_grid_type *copy = - ecl_grid_alloc_processed_copy(src, NULL, actnum); - test_assert_int_equal(1, ecl_grid_get_active_size(src) - - ecl_grid_get_active_size(copy)); - ecl_grid_free(copy); - } - free(actnum); - } - - { - double *zcorn_double = (double *)util_malloc( - ecl_grid_get_zcorn_size(src) * sizeof *zcorn_double); - int i = 0; - int j = 0; - int k = 0; - - ecl_grid_init_zcorn_data_double(src, zcorn_double); - { - ecl_grid_type *copy = - ecl_grid_alloc_processed_copy(src, zcorn_double, NULL); - test_assert_double_equal(ecl_grid_get_cell_volume3(src, i, j, k), - ecl_grid_get_cell_volume3(copy, i, j, k)); - ecl_grid_free(copy); - } - - for (int c = 0; c < 4; c++) { - double dz = - zcorn_double[ecl_grid_zcorn_index(src, i, j, k, c + 4)] - - zcorn_double[ecl_grid_zcorn_index(src, i, j, k, c)]; - zcorn_double[ecl_grid_zcorn_index(src, i, j, k, c + 4)] += dz; - } - { - ecl_grid_type *copy = - ecl_grid_alloc_processed_copy(src, zcorn_double, NULL); - test_assert_double_equal(ecl_grid_get_cell_volume3(src, i, j, k) * - 2, - ecl_grid_get_cell_volume3(copy, i, j, k)); - ecl_grid_free(copy); - } - - free(zcorn_double); - } -} - -void export_mapaxes(const ecl_grid_type *grid, ecl_file_type *ecl_file) { - if (ecl_file_has_kw(ecl_file, "MAPAXES")) { - ecl_kw_type *mapaxes_kw = - ecl_file_iget_named_kw(ecl_file, "MAPAXES", 0); - double mapaxes[6]; - int i; - - test_assert_true(ecl_grid_use_mapaxes(grid)); - ecl_grid_init_mapaxes_data_double(grid, mapaxes); - for (i = 0; i < 6; i++) - test_assert_double_equal(ecl_kw_iget_float(mapaxes_kw, i), - mapaxes[i]); - } -} - -int main(int argc, char **argv) { - ecl::util::TestArea ta("grid_export"); - { - const char *test_grid = "TEST.EGRID"; - const char *grid_file; - if (argc == 1) { - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(4, 4, 2, 1, 1, 1, NULL); - grid_file = test_grid; - ecl_grid_fwrite_EGRID(grid, grid_file, true); - ecl_grid_free(grid); - } else - grid_file = argv[1]; - - { - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_file); - if (argc == 1) - test_assert_true(ecl_grid_get_unit_system(ecl_grid) == - ECL_METRIC_UNITS); - ecl_file_type *ecl_file = ecl_file_open(grid_file, 0); - - export_actnum(ecl_grid, ecl_file); - export_coord(ecl_grid, ecl_file); - export_zcorn(ecl_grid, ecl_file); - export_mapaxes(ecl_grid, ecl_file); - copy_processed(ecl_grid); - ecl_file_close(ecl_file); - ecl_grid_free(ecl_grid); - } - } -} diff --git a/lib/ecl/tests/ecl_grid_ext_actnum.cpp b/lib/ecl/tests/ecl_grid_ext_actnum.cpp deleted file mode 100644 index 1cddf94c67..0000000000 --- a/lib/ecl/tests/ecl_grid_ext_actnum.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include -#include - -#include -#include -#include -#include -#include - -void test_1() { - - ecl::util::TestArea ta("test1"); - { - const char *filename = "FILE.EGRID"; - - ecl_grid_type *grid_write = - ecl_grid_alloc_rectangular(2, 3, 1, 1, 1, 1, NULL); - ecl_grid_fwrite_EGRID(grid_write, filename, true); - ecl_grid_free(grid_write); - - ecl_file_type *ecl_file = ecl_file_open(filename, 0); - ecl_kw_type *filehead_kw = - ecl_file_iget_named_kw(ecl_file, FILEHEAD_KW, 0); - int *filehead_data = ecl_kw_get_int_ptr(filehead_kw); - filehead_data[FILEHEAD_DUALP_INDEX] = FILEHEAD_DUAL_POROSITY; - - ecl_kw_type *actnum_kw = ecl_file_iget_named_kw(ecl_file, ACTNUM_KW, 0); - int *actnum_data = ecl_kw_get_int_ptr(actnum_kw); - actnum_data[0] = 1; - actnum_data[1] = 2; - actnum_data[2] = 2; - actnum_data[3] = 0; - actnum_data[4] = 1; - actnum_data[5] = 1; - const char *filename1 = "FILE1.EGRID"; - fortio_type *f = fortio_open_writer(filename1, false, ECL_ENDIAN_FLIP); - ecl_file_fwrite_fortio(ecl_file, f, 0); - fortio_fclose(f); - ecl_file_close(ecl_file); - - std::vector ext_actnum = {0, 1, 0, 1, 1, 1}; - ecl_grid_type *grid = - ecl_grid_alloc_ext_actnum(filename1, ext_actnum.data()); - test_assert_int_equal(4, ecl_grid_get_nactive(grid)); - test_assert_int_equal(0, ecl_grid_get_nactive_fracture(grid)); - test_assert_true(!ecl_grid_cell_active1(grid, 0)); - - test_assert_true(!ecl_grid_cell_active1(grid, 2)); - test_assert_true(ecl_grid_cell_active1(grid, 3)); - test_assert_true(ecl_grid_cell_active1(grid, 4)); - test_assert_true(ecl_grid_cell_active1(grid, 5)); - - ecl_grid_free(grid); - } -} - -int main() { test_1(); } diff --git a/lib/ecl/tests/ecl_grid_init_fwrite.cpp b/lib/ecl/tests/ecl_grid_init_fwrite.cpp deleted file mode 100644 index 06a828f29d..0000000000 --- a/lib/ecl/tests/ecl_grid_init_fwrite.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -void test_write_depth(const ecl_grid_type *grid) { - ecl::util::TestArea ta("write_depth"); - { - fortio_type *init_file = - fortio_open_writer("INIT", false, ECL_ENDIAN_FLIP); - ecl_grid_fwrite_depth(grid, init_file, ECL_METRIC_UNITS); - fortio_fclose(init_file); - } - { - ecl_file_type *init_file = ecl_file_open("INIT", 0); - ecl_kw_type *depth = ecl_file_iget_named_kw(init_file, "DEPTH", 0); - - test_assert_int_equal(ecl_kw_get_size(depth), - ecl_grid_get_nactive(grid)); - for (int i = 0; i < ecl_grid_get_nactive(grid); i++) - test_assert_double_equal(ecl_kw_iget_as_double(depth, i), - ecl_grid_get_cdepth1A(grid, i)); - - ecl_file_close(init_file); - } -} - -void test_write_dims(const ecl_grid_type *grid) { - ecl::util::TestArea ta("write_dims"); - { - fortio_type *init_file = - fortio_open_writer("INIT", false, ECL_ENDIAN_FLIP); - ecl_grid_fwrite_dims(grid, init_file, ECL_METRIC_UNITS); - fortio_fclose(init_file); - } - { - ecl_file_type *init_file = ecl_file_open("INIT", 0); - ecl_kw_type *DX = ecl_file_iget_named_kw(init_file, "DX", 0); - ecl_kw_type *DY = ecl_file_iget_named_kw(init_file, "DY", 0); - ecl_kw_type *DZ = ecl_file_iget_named_kw(init_file, "DZ", 0); - - test_assert_int_equal(ecl_kw_get_size(DX), ecl_grid_get_nactive(grid)); - test_assert_int_equal(ecl_kw_get_size(DY), ecl_grid_get_nactive(grid)); - test_assert_int_equal(ecl_kw_get_size(DZ), ecl_grid_get_nactive(grid)); - for (int i = 0; i < ecl_grid_get_nactive(grid); i++) { - test_assert_double_equal(ecl_kw_iget_as_double(DX, i), - ecl_grid_get_cell_dx1A(grid, i)); - test_assert_double_equal(ecl_kw_iget_as_double(DY, i), - ecl_grid_get_cell_dy1A(grid, i)); - test_assert_double_equal(ecl_kw_iget_as_double(DZ, i), - ecl_grid_get_cell_dz1A(grid, i)); - } - ecl_file_close(init_file); - } -} - -ecl_grid_type *create_grid() { - int nx = 10; - int ny = 10; - int nz = 8; - int_vector_type *actnum = int_vector_alloc(nx * ny * nz, 1); - - ecl_grid_type *ecl_grid = ecl_grid_alloc_rectangular( - nx, ny, nz, 1, 1, 1, int_vector_get_ptr(actnum)); - int_vector_free(actnum); - return ecl_grid; -} - -int main(int argc, char **argv) { - util_install_signals(); - { - ecl_grid_type *grid = create_grid(); - - test_write_depth(grid); - test_write_dims(grid); - ecl_grid_free(grid); - } -} diff --git a/lib/ecl/tests/ecl_grid_layer_contains.cpp b/lib/ecl/tests/ecl_grid_layer_contains.cpp deleted file mode 100644 index 8a8d7df7f4..0000000000 --- a/lib/ecl/tests/ecl_grid_layer_contains.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include - -#include - -void test_layer(const ecl_grid_type *grid) { - int g; - - for (g = 0; g < ecl_grid_get_global_size(grid); g += 25) { - double x, y, z; - int i, j, k; - - ecl_grid_get_xyz1(grid, g, &x, &y, &z); - ecl_grid_get_ijk1(grid, g, &i, &j, &k); - { - int find_i, find_j; - test_assert_true( - ecl_grid_get_ij_from_xy(grid, x, y, k, &find_i, &find_j)); - test_assert_int_equal(i, find_i); - test_assert_int_equal(j, find_j); - } - } -} - -int main(int argc, char **argv) { - ecl_grid_type *grid = ecl_grid_alloc(argv[1]); - test_layer(grid); - ecl_grid_free(grid); -} diff --git a/lib/ecl/tests/ecl_grid_reset_actnum.cpp b/lib/ecl/tests/ecl_grid_reset_actnum.cpp deleted file mode 100644 index 7477fdde70..0000000000 --- a/lib/ecl/tests/ecl_grid_reset_actnum.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -#include - -#include - -int main(int argc, char **argv) { - const int nx = 5; - const int ny = 4; - const int nz = 2; - const int g = nx * ny * nz; - const int nactive = g - 9; - const int actnum1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - const int actnum2[] = {0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0}; - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, actnum1); - - test_assert_int_equal(g, ecl_grid_get_nactive(grid)); - ecl_grid_reset_actnum(grid, actnum2); - test_assert_int_equal(nactive, ecl_grid_get_nactive(grid)); - - test_assert_int_equal(-1, ecl_grid_get_active_index1(grid, 0)); - test_assert_int_equal(0, ecl_grid_get_active_index1(grid, 1)); - test_assert_int_equal(-1, ecl_grid_get_active_index1(grid, 2)); - test_assert_int_equal(1, ecl_grid_get_global_index1A(grid, 0)); - test_assert_int_equal(3, ecl_grid_get_global_index1A(grid, 1)); - test_assert_int_equal(5, ecl_grid_get_global_index1A(grid, 2)); - - ecl_grid_reset_actnum(grid, NULL); - test_assert_int_equal(g, ecl_grid_get_nactive(grid)); - test_assert_int_equal(0, ecl_grid_get_active_index1(grid, 0)); - test_assert_int_equal(1, ecl_grid_get_active_index1(grid, 1)); - test_assert_int_equal(2, ecl_grid_get_active_index1(grid, 2)); - test_assert_int_equal(0, ecl_grid_get_global_index1A(grid, 0)); - test_assert_int_equal(1, ecl_grid_get_global_index1A(grid, 1)); - test_assert_int_equal(2, ecl_grid_get_global_index1A(grid, 2)); - - ecl_grid_free(grid); - exit(0); -} diff --git a/lib/ecl/tests/ecl_grid_unit_system.cpp b/lib/ecl/tests/ecl_grid_unit_system.cpp deleted file mode 100644 index 412a137ff2..0000000000 --- a/lib/ecl/tests/ecl_grid_unit_system.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -#include -#include - -#include -#include -#include - -void test_EGRID(const char *filename, ert_ecl_unit_enum unit_system) { - ecl_grid_type *grid = ecl_grid_alloc_rectangular(4, 4, 2, 1, 1, 1, NULL); - ecl_grid_fwrite_EGRID2(grid, filename, unit_system); - ecl_grid_free(grid); - - ecl_grid_type *grid2 = ecl_grid_alloc(filename); - test_assert_int_equal(ecl_grid_get_unit_system(grid2), unit_system); - ecl_grid_free(grid2); -} - -void test_GRID(const char *filename, ert_ecl_unit_enum unit_system) { - ecl_grid_type *grid = ecl_grid_alloc_rectangular(4, 4, 2, 1, 1, 1, NULL); - ecl_grid_fwrite_GRID2(grid, filename, unit_system); - ecl_grid_free(grid); - - ecl_grid_type *grid2 = ecl_grid_alloc(filename); - test_assert_int_equal(ecl_grid_get_unit_system(grid2), unit_system); - ecl_grid_free(grid2); -} - -int main(int argc, char **argv) { - ecl::util::TestArea ta("grid_unit_system"); - - test_EGRID("METRIC.EGRID", ECL_METRIC_UNITS); - test_EGRID("FIELD.EGRID", ECL_FIELD_UNITS); - test_GRID("METRIC.GRID", ECL_METRIC_UNITS); - test_GRID("FIELD.GRID", ECL_FIELD_UNITS); -} diff --git a/lib/ecl/tests/ecl_grid_volume.cpp b/lib/ecl/tests/ecl_grid_volume.cpp deleted file mode 100644 index 639600b214..0000000000 --- a/lib/ecl/tests/ecl_grid_volume.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -int main(int argc, char **argv) { - const char *path_case = argv[1]; - char *grid_file = - ecl_util_alloc_filename(NULL, path_case, ECL_EGRID_FILE, false, 0); - char *init_file = - ecl_util_alloc_filename(NULL, path_case, ECL_INIT_FILE, false, 0); - - ecl_file_type *init = ecl_file_open(init_file, 0); - ecl_grid_type *grid = ecl_grid_alloc(grid_file); - const ecl_kw_type *poro_kw = ecl_file_iget_named_kw(init, "PORO", 0); - const ecl_kw_type *porv_kw = ecl_file_iget_named_kw(init, "PORV", 0); - ecl_kw_type *multpv = NULL; - ecl_kw_type *NTG = NULL; - bool error_found = false; - - double total_volume = 0; - double total_diff = 0; - int error_count = 0; - int iactive; - - if (ecl_file_has_kw(init, "NTG")) - NTG = ecl_file_iget_named_kw(init, "NTG", 0); - - if (ecl_file_has_kw(init, "MULTPV")) - multpv = ecl_file_iget_named_kw(init, "MULTPV", 0); - - for (iactive = 0; iactive < ecl_grid_get_nactive(grid); ++iactive) { - int iglobal = ecl_grid_get_global_index1A(grid, iactive); - double grid_volume = ecl_grid_get_cell_volume1(grid, iglobal); - double eclipse_volume = ecl_kw_iget_float(porv_kw, iglobal) / - ecl_kw_iget_float(poro_kw, iactive); - - if (NTG) - eclipse_volume /= ecl_kw_iget_float(NTG, iactive); - - if (multpv) - eclipse_volume *= ecl_kw_iget_float(multpv, iactive); - - total_volume += grid_volume; - total_diff += fabs(eclipse_volume - grid_volume); - if (!util_double_approx_equal__(grid_volume, eclipse_volume, 2.5e-3, - 0.00)) { - double diff = 100 * (grid_volume - eclipse_volume) / eclipse_volume; - printf("Error in cell: %d V1: %g V2: %g diff:%g %% \n", - iglobal, grid_volume, eclipse_volume, diff); - error_count++; - error_found = true; - } - } - printf("Total volume difference: %g %% \n", - 100 * total_diff / total_volume); - - ecl_grid_free(grid); - ecl_file_close(init); - free(grid_file); - free(init_file); - if (error_found) { - printf("Error_count: %d / %d \n", error_count, - ecl_grid_get_nactive(grid)); - exit(1); - } else - exit(0); -} diff --git a/lib/ecl/tests/ecl_init_file.cpp b/lib/ecl/tests/ecl_init_file.cpp deleted file mode 100644 index f6ec317dc9..0000000000 --- a/lib/ecl/tests/ecl_init_file.cpp +++ /dev/null @@ -1,83 +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; - - ecl::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); - ecl_grid_type *ecl_grid; - - int_vector_iset(actnum, 10, 0); - int_vector_iset(actnum, 100, 0); - - ecl_grid = ecl_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, ECL_ENDIAN_FLIP); - ecl_kw_type *poro = - ecl_kw_alloc("PORO", ecl_grid_get_global_size(ecl_grid), ECL_FLOAT); - ecl_kw_scalar_set_float(poro, 0.10); - ecl_init_file_fwrite_header(f, ecl_grid, poro, ECL_FIELD_UNITS, 7, - start_time); - ecl_kw_free(poro); - fortio_fclose(f); - } - - // Write poro with nactive size. - { - fortio_type *f = - fortio_open_writer("FOO2.INIT", false, ECL_ENDIAN_FLIP); - ecl_kw_type *poro = - ecl_kw_alloc("PORO", ecl_grid_get_global_size(ecl_grid), ECL_FLOAT); - ecl_kw_scalar_set_float(poro, 0.10); - ecl_init_file_fwrite_header(f, ecl_grid, poro, ECL_FIELD_UNITS, 7, - start_time); - ecl_kw_free(poro); - fortio_fclose(f); - } - { - ecl_file_type *file1 = ecl_file_open("FOO1.INIT", 0); - ecl_file_type *file2 = ecl_file_open("FOO2.INIT", 0); - - test_assert_true( - ecl_kw_equal(ecl_file_iget_named_kw(file1, "PORV", 0), - ecl_file_iget_named_kw(file2, "PORV", 0))); - - ecl_file_close(file2); - ecl_file_close(file1); - } - - // Poro == NULL - { - fortio_type *f = - fortio_open_writer("FOO3.INIT", false, ECL_ENDIAN_FLIP); - ecl_init_file_fwrite_header(f, ecl_grid, NULL, ECL_METRIC_UNITS, 7, - start_time); - fortio_fclose(f); - } - ecl_grid_free(ecl_grid); - int_vector_free(actnum); -} - -int main(int argc, char **argv) { - test_write_header(); - exit(0); -} diff --git a/lib/ecl/tests/ecl_kw_cmp_string.cpp b/lib/ecl/tests/ecl_kw_cmp_string.cpp deleted file mode 100644 index dc37039cbc..0000000000 --- a/lib/ecl/tests/ecl_kw_cmp_string.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -#include -#include -#include - -void test_cmp_string() { - ecl_kw_type *ecl_kw = ecl_kw_alloc("HEADER", 1, ECL_CHAR); - - ecl_kw_iset_string8(ecl_kw, 0, "ABCD"); - - test_assert_int_equal(0, - strcmp(ecl_kw_iget_char_ptr(ecl_kw, 0), "ABCD ")); - test_assert_true(ecl_kw_icmp_string(ecl_kw, 0, "ABCD")); - test_assert_true(ecl_kw_icmp_string(ecl_kw, 0, "ABCD ")); - test_assert_true(ecl_kw_icmp_string(ecl_kw, 0, "ABCD ")); - - test_assert_false(ecl_kw_icmp_string(ecl_kw, 0, "Different")); - test_assert_false(ecl_kw_icmp_string(ecl_kw, 0, "")); - test_assert_false(ecl_kw_icmp_string(ecl_kw, 0, "")); - - ecl_kw_free(ecl_kw); -} - -int main(int argc, char **argv) { - test_cmp_string(); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_kw_equal.cpp b/lib/ecl/tests/ecl_kw_equal.cpp deleted file mode 100644 index 9cf3bfeb52..0000000000 --- a/lib/ecl/tests/ecl_kw_equal.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -int main(int argc, char **argv) { - ecl_kw_type *ecl_kw1 = ecl_kw_alloc("KW", 10, ECL_INT); - int data[10]; - int i; - for (i = 0; i < 10; i++) { - ecl_kw_iset_int(ecl_kw1, i, i); - data[i] = i; - } - - { - ecl_kw_type *ecl_kw2 = ecl_kw_alloc_copy(ecl_kw1); - - test_assert_true(ecl_kw_equal(ecl_kw1, ecl_kw2)); - - ecl_kw_iset_int(ecl_kw2, 1, 77); - test_assert_false(ecl_kw_equal(ecl_kw1, ecl_kw2)); - ecl_kw_iset_int(ecl_kw2, 1, 1); - test_assert_true(ecl_kw_equal(ecl_kw1, ecl_kw2)); - - ecl_kw_set_header_name(ecl_kw2, "TEST"); - test_assert_false(ecl_kw_equal(ecl_kw1, ecl_kw2)); - test_assert_true(ecl_kw_content_equal(ecl_kw1, ecl_kw2)); - ecl_kw_free(ecl_kw2); - } - - { - ecl_kw_type *ecl_ikw = ecl_kw_alloc_new_shared("KW", 10, ECL_INT, data); - ecl_kw_type *ecl_fkw = - ecl_kw_alloc_new_shared("KW", 10, ECL_FLOAT, data); - - test_assert_true(ecl_kw_content_equal(ecl_kw1, ecl_ikw)); - test_assert_false(ecl_kw_content_equal(ecl_kw1, ecl_fkw)); - - ecl_kw_free(ecl_ikw); - ecl_kw_free(ecl_fkw); - } - - test_assert_true(ecl_kw_data_equal(ecl_kw1, data)); - data[0] = 99; - test_assert_false(ecl_kw_data_equal(ecl_kw1, data)); - ecl_kw_free(ecl_kw1); -} diff --git a/lib/ecl/tests/ecl_kw_fread.cpp b/lib/ecl/tests/ecl_kw_fread.cpp deleted file mode 100644 index 276f708387..0000000000 --- a/lib/ecl/tests/ecl_kw_fread.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -void test_truncated(const char *filename, offset_type truncate_size) { - { - FILE *stream = util_fopen(filename, "r+"); - util_ftruncate(stream, truncate_size); - fclose(stream); - } - { - fortio_type *fortio = fortio_open_reader(filename, false, true); - ecl_kw_type *kw2 = ecl_kw_fread_alloc(fortio); - test_assert_NULL(kw2); - fortio_fclose(fortio); - } -} - -void test_fread_alloc() { - ecl::util::TestArea ta("fread_alloc"); - { - ecl_kw_type *kw1 = ecl_kw_alloc("INT", 100, ECL_INT); - int i; - for (i = 0; i < 100; i++) - ecl_kw_iset_int(kw1, i, i); - { - fortio_type *fortio = fortio_open_writer("INT", false, true); - ecl_kw_fwrite(kw1, fortio); - fortio_fclose(fortio); - } - { - fortio_type *fortio = fortio_open_reader("INT", false, true); - ecl_kw_type *kw2 = ecl_kw_fread_alloc(fortio); - test_assert_true(ecl_kw_is_instance(kw2)); - test_assert_true(ecl_kw_equal(kw1, kw2)); - ecl_kw_free(kw2); - fortio_fclose(fortio); - } - - { - offset_type file_size = util_file_size("INT"); - test_truncated("INT", file_size - 4); - test_truncated("INT", file_size - 25); - test_truncated("INT", 5); - test_truncated("INT", 0); - } - ecl_kw_free(kw1); - } -} - -void test_kw_io_charlength() { - ecl::util::TestArea ta("io_charlength"); - { - const char *KW0 = "QWERTYUI"; - const char *KW1 = "ABCDEFGHIJTTTTTTTTTTTTTTTTTTTTTTABCDEFGHIJKLMNOP"; - ecl_kw_type *ecl_kw_out0 = ecl_kw_alloc(KW0, 5, ECL_FLOAT); - ecl_kw_type *ecl_kw_out1 = ecl_kw_alloc(KW1, 5, ECL_FLOAT); - for (int i = 0; i < ecl_kw_get_size(ecl_kw_out1); i++) { - ecl_kw_iset_float(ecl_kw_out0, i, i * 1.5); - ecl_kw_iset_float(ecl_kw_out1, i, i * 1.5); - } - - { - fortio_type *f = - fortio_open_writer("TEST1", false, ECL_ENDIAN_FLIP); - test_assert_true(ecl_kw_fwrite(ecl_kw_out0, f)); - test_assert_false(ecl_kw_fwrite(ecl_kw_out1, f)); - fortio_fclose(f); - } - - { test_assert_false(util_file_exists("TEST1")); } - - { - FILE *file = util_fopen("TEST2", "w"); - ecl_kw_fprintf_grdecl(ecl_kw_out1, file); - fclose(file); - } - - { - FILE *file = util_fopen("TEST2", "r"); - ecl_kw_type *ecl_kw_in = - ecl_kw_fscanf_alloc_grdecl(file, KW1, -1, ECL_FLOAT); - test_assert_string_equal(KW1, ecl_kw_get_header(ecl_kw_in)); - test_assert_int_equal(5, ecl_kw_get_size(ecl_kw_in)); - - test_assert_double_equal(ecl_kw_iget_as_double(ecl_kw_in, 0), 0.0); - test_assert_double_equal(ecl_kw_iget_as_double(ecl_kw_in, 4), 6.0); - - ecl_kw_free(ecl_kw_in); - fclose(file); - } - - ecl_kw_free(ecl_kw_out0); - ecl_kw_free(ecl_kw_out1); - } -} - -int main(int argc, char **argv) { - test_fread_alloc(); - test_kw_io_charlength(); - exit(0); -} diff --git a/lib/ecl/tests/ecl_kw_grdecl.cpp b/lib/ecl/tests/ecl_kw_grdecl.cpp deleted file mode 100644 index be184c781a..0000000000 --- a/lib/ecl/tests/ecl_kw_grdecl.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -int main(int argc, char **argv) { - int i; - ecl_kw_type *ecl_kw = ecl_kw_alloc("HEAD", 10, ECL_INT); - - for (i = 0; i < 10; i++) - ecl_kw_iset_int(ecl_kw, i, i); - - { - ecl::util::TestArea ta("kw_grdecl"); - FILE *stream = util_fopen("FILE.grdecl", "w"); - - ecl_kw_fprintf_grdecl(ecl_kw, stream); - fclose(stream); - - stream = util_fopen("FILE.grdecl", "r"); - { - ecl_kw_type *ecl_kw2 = - ecl_kw_fscanf_alloc_grdecl(stream, "HEAD", 10, ECL_INT); - - test_assert_not_NULL(ecl_kw2); - test_assert_true(ecl_kw_equal(ecl_kw, ecl_kw2)); - ecl_kw_free(ecl_kw2); - } - fclose(stream); - - stream = util_fopen("FILE.grdecl", "w"); - ecl_kw_fprintf_grdecl__(ecl_kw, "HEAD1234", stream); - fclose(stream); - - stream = util_fopen("FILE.grdecl", "r"); - { - ecl_kw_type *ecl_kw2 = - ecl_kw_fscanf_alloc_grdecl(stream, "HEAD", 10, ECL_INT); - - test_assert_NULL(ecl_kw2); - ecl_kw2 = - ecl_kw_fscanf_alloc_grdecl(stream, "HEAD1234", 10, ECL_INT); - test_assert_not_NULL(ecl_kw2); - - test_assert_string_equal(ecl_kw_get_header(ecl_kw2), "HEAD1234"); - test_assert_true(ecl_kw_content_equal(ecl_kw, ecl_kw2)); - ecl_kw_free(ecl_kw2); - } - fclose(stream); - } - ecl_kw_free(ecl_kw); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_lgr_name.cpp b/lib/ecl/tests/ecl_lgr_name.cpp deleted file mode 100644 index e79f33a792..0000000000 --- a/lib/ecl/tests/ecl_lgr_name.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -#include - -#include - -int main(int argc, char **argv) { - ecl_grid_type *grid = ecl_grid_alloc(argv[1]); - - int num_lgr = ecl_grid_get_num_lgr(grid); - int lgr_index; - for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) { - ecl_grid_type *lgr_from_index = ecl_grid_iget_lgr(grid, lgr_index); - int lgr_nr = ecl_grid_get_lgr_nr(lgr_from_index); - ecl_grid_type *lgr_from_nr = ecl_grid_get_lgr_from_lgr_nr(grid, lgr_nr); - - test_assert_ptr_equal(lgr_from_index, lgr_from_nr); - - test_assert_string_equal(ecl_grid_get_lgr_name(grid, lgr_nr), - ecl_grid_iget_lgr_name(grid, lgr_index)); - printf("Grid[%d:%d] : %s \n", lgr_index, lgr_nr, - ecl_grid_iget_lgr_name(grid, lgr_index)); - } - ecl_grid_free(grid); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_lgr_test.cpp b/lib/ecl/tests/ecl_lgr_test.cpp deleted file mode 100644 index ba5c2a4c7e..0000000000 --- a/lib/ecl/tests/ecl_lgr_test.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -#include -#include - -#include -#include -#include - -int main(int argc, char **argv) { - const char *grid_file = argv[1]; - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_file); - ecl_file_type *ecl_file = ecl_file_open(grid_file, 0); - - ecl_grid_test_lgr_consistency(ecl_grid); - - if (ecl_file_get_num_named_kw(ecl_file, COORD_KW)) - test_assert_int_equal(ecl_file_get_num_named_kw(ecl_file, COORD_KW) - 1, - ecl_grid_get_num_lgr(ecl_grid)); - - ecl_grid_free(ecl_grid); - ecl_file_close(ecl_file); - exit(0); -} diff --git a/lib/ecl/tests/ecl_nnc_data_equinor_root.cpp b/lib/ecl/tests/ecl_nnc_data_equinor_root.cpp deleted file mode 100644 index f11f24d9ee..0000000000 --- a/lib/ecl/tests/ecl_nnc_data_equinor_root.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -int find_index(ecl_nnc_geometry_type *nnc_geo, int grid1, int grid2, int indx1, - int indx2) { - int index = -1; - int nnc_size = ecl_nnc_geometry_size(nnc_geo); - for (int n = 0; n < nnc_size; n++) { - const ecl_nnc_pair_type *pair = ecl_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 = - ecl_util_alloc_filename(NULL, filename, ECL_EGRID_FILE, false, -1); - char *init_file_name = - ecl_util_alloc_filename(NULL, filename, ECL_INIT_FILE, false, -1); - ecl_file_type *init_file = ecl_file_open(init_file_name, 0); - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_nnc_geometry_type *nnc_geo = ecl_nnc_geometry_alloc(grid); - ecl_file_view_type *view_file = ecl_file_get_global_view(init_file); - - ecl_nnc_data_type *nnc_geo_data = - ecl_nnc_data_alloc_tran(grid, nnc_geo, view_file); - test_assert_true(ecl_nnc_geometry_size(nnc_geo) == - ecl_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, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 0, 0, 48365, 118191); - test_assert_double_equal(0.580284, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 0, 19, 42830, 211); - test_assert_double_equal(0.571021, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 0, 79, 132406, 76); - test_assert_double_equal(37.547710, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 18, 12, 303, 115); - test_assert_double_equal(0.677443, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 72, 71, 255, 179); - test_assert_double_equal(0.045813, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - index = find_index(nnc_geo, 110, 109, 271, 275); - test_assert_double_equal(16.372242, - ecl_nnc_data_iget_value(nnc_geo_data, index)); - - ecl_nnc_data_free(nnc_geo_data); - ecl_nnc_geometry_free(nnc_geo); - ecl_grid_free(grid); - ecl_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 = - ecl_util_alloc_filename(NULL, filename, ECL_EGRID_FILE, false, -1); - char *restart_file_name = ecl_util_alloc_filename( - NULL, filename, ECL_RESTART_FILE, false, file_num); - - ecl_file_type *restart_file = ecl_file_open(restart_file_name, 0); - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_nnc_geometry_type *nnc_geo = ecl_nnc_geometry_alloc(grid); - { - ecl_file_view_type *view_file = ecl_file_get_global_view(restart_file); - - ecl_nnc_data_type *nnc_flux_data = - ecl_nnc_data_alloc_wat_flux(grid, nnc_geo, view_file); - test_assert_not_NULL(nnc_flux_data); - ecl_nnc_data_free(nnc_flux_data); - } - ecl_nnc_geometry_free(nnc_geo); - ecl_grid_free(grid); - ecl_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/ecl/tests/ecl_nnc_export.cpp b/lib/ecl/tests/ecl_nnc_export.cpp deleted file mode 100644 index 9ddcf7bece..0000000000 --- a/lib/ecl/tests/ecl_nnc_export.cpp +++ /dev/null @@ -1,361 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -int count_kw_data(const ecl_file_type *file, ecl_grid_type *grid, - const char *kw1, const char *kw2) { - int i, j; - int count = 0; - - for (i = 0; i < ecl_file_get_num_named_kw(file, kw1); i++) { - ecl_kw_type *ecl_kw1 = ecl_file_iget_named_kw(file, kw1, i); - ecl_kw_type *ecl_kw2 = NULL; - - if (kw2) - ecl_kw2 = ecl_file_iget_named_kw(file, kw2, i); - - { - if (ecl_kw2) { - int global_size; - ecl_grid_type *igrid; - if (i == 0) - igrid = grid; - else - igrid = ecl_grid_iget_lgr(grid, i - 1); - - global_size = ecl_grid_get_global_size(igrid); - - for (j = 0; j < ecl_kw_get_size(ecl_kw1); j++) { - int g1 = ecl_kw_iget_int(ecl_kw1, j); - int g2 = ecl_kw_iget_int(ecl_kw2, j); - - if (g1 <= global_size && g2 <= global_size) - count += 1; - } - } else - count += ecl_kw_get_size(ecl_kw1); - } - } - return count; -} - -void test_count(const char *name) { - char *grid_file_name = - ecl_util_alloc_filename(NULL, name, ECL_EGRID_FILE, false, -1); - char *init_file_name = - ecl_util_alloc_filename(NULL, name, ECL_INIT_FILE, false, -1); - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_file_type *grid_file = ecl_file_open(grid_file_name, 0); - ecl_file_type *init_file = ecl_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, ecl_nnc_export_get_size(grid, init_file)); - - free(grid_file_name); - ecl_grid_free(grid); - ecl_file_close(grid_file); -} - -void test_nnc_export_missing_TRANX(const char *name) { - char *grid_file_name = - ecl_util_alloc_filename(NULL, name, ECL_EGRID_FILE, false, -1); - char *init_file_name = - ecl_util_alloc_filename(NULL, name, ECL_INIT_FILE, false, -1); - if (util_entry_exists(init_file_name)) { - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_file_type *init_file = ecl_file_open(init_file_name, 0); - ecl_nnc_type *nnc_data1 = (ecl_nnc_type *)util_calloc( - ecl_nnc_export_get_size(grid, init_file), sizeof *nnc_data1); - int count = ecl_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_ECL_DEFAULT_NNC_TRANS); - } -} - -void test_export(const char *name, bool have_tran_data) { - char *grid_file_name = - ecl_util_alloc_filename(NULL, name, ECL_EGRID_FILE, false, -1); - char *init_file_name = - ecl_util_alloc_filename(NULL, name, ECL_INIT_FILE, false, -1); - if (util_entry_exists(init_file_name)) { - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_file_type *grid_file = ecl_file_open(grid_file_name, 0); - ecl_file_type *init_file = ecl_file_open(init_file_name, 0); - ecl_nnc_type *nnc_data1 = (ecl_nnc_type *)util_calloc( - ecl_nnc_export_get_size(grid, init_file), sizeof *nnc_data1); - ecl_nnc_type *nnc_data2 = (ecl_nnc_type *)util_calloc( - ecl_nnc_export_get_size(grid, init_file), sizeof *nnc_data2); - - { - int nnc_offset = 0; - int block_nr = 0; - for (block_nr = 0; - block_nr < ecl_file_get_num_named_kw(grid_file, NNCHEAD_KW); - block_nr++) { - ecl_file_view_type *nnc_view = ecl_file_alloc_global_blockview( - grid_file, NNCHEAD_KW, block_nr); - - if (ecl_file_view_has_kw(nnc_view, NNC1_KW)) { - ecl_kw_type *nnc1_kw = - ecl_file_view_iget_named_kw(nnc_view, NNC1_KW, 0); - ecl_kw_type *nnc2_kw = - ecl_file_view_iget_named_kw(nnc_view, NNC2_KW, 0); - ecl_kw_type *nnchead = - ecl_file_view_iget_named_kw(nnc_view, NNCHEAD_KW, 0); - int lgr_nr1 = ecl_kw_iget_int(nnchead, NNCHEAD_LGR_INDEX); - int lgr_nr2 = ecl_kw_iget_int(nnchead, NNCHEAD_LGR_INDEX); - ecl_kw_type *nnc_tran = ecl_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(ecl_kw_get_size(nnc1_kw), - ecl_kw_get_size(nnc_tran)); - { - ecl_grid_type *lgr = grid; - int num_nnc = 0; - int i = 0; - if (lgr_nr1 > 0) - lgr = ecl_grid_get_lgr_from_lgr_nr(grid, lgr_nr1); - - while (i < ecl_kw_get_size(nnc1_kw)) { - int g1 = ecl_kw_iget_int(nnc1_kw, i) - 1; - int g2 = ecl_kw_iget_int(nnc2_kw, i) - 1; - - if (g1 < ecl_grid_get_global_size(lgr) && - g2 < ecl_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 = - ecl_kw_iget_as_double(nnc_tran, i); - nnc_data1[i + nnc_offset].input_index = i; - num_nnc++; - } - i++; - } - nnc_offset += num_nnc; - } - } - - if (ecl_file_view_has_kw(nnc_view, NNCL_KW)) { - ecl_kw_type *nncl_kw = - ecl_file_view_iget_named_kw(nnc_view, NNCL_KW, 0); - ecl_kw_type *nncg_kw = - ecl_file_view_iget_named_kw(nnc_view, NNCG_KW, 0); - ecl_kw_type *nnchead = - ecl_file_view_iget_named_kw(nnc_view, NNCHEAD_KW, 0); - int lgr_nr1 = 0; - int lgr_nr2 = ecl_kw_iget_int(nnchead, NNCHEAD_LGR_INDEX); - ecl_kw_type *nnc_tran = ecl_nnc_export_get_tranx_kw( - grid, init_file, 0, lgr_nr2); - int i; - - test_assert_int_equal(ecl_kw_get_size(nncl_kw), - ecl_kw_get_size(nnc_tran)); - for (i = 0; i < ecl_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 = - ecl_kw_iget_int(nncg_kw, i) - 1; - nnc_data1[i + nnc_offset].global_index2 = - ecl_kw_iget_int(nncl_kw, i) - 1; - nnc_data1[i + nnc_offset].trans = - ecl_kw_iget_as_double(nnc_tran, i); - nnc_data1[i + nnc_offset].input_index = i; - } - nnc_offset += ecl_kw_get_size(nncl_kw); - } - - ecl_file_view_free(nnc_view); - } - - { - for (block_nr = 0; block_nr < ecl_file_get_num_named_kw( - grid_file, NNCHEADA_KW); - block_nr++) { - ecl_kw_type *nnc1_kw = - ecl_file_iget_named_kw(grid_file, NNA1_KW, block_nr); - ecl_kw_type *nnc2_kw = - ecl_file_iget_named_kw(grid_file, NNA2_KW, block_nr); - ecl_kw_type *nnchead = ecl_file_iget_named_kw( - grid_file, NNCHEADA_KW, block_nr); - int lgr_nr1 = - ecl_kw_iget_int(nnchead, NNCHEADA_ILOC1_INDEX); - int lgr_nr2 = - ecl_kw_iget_int(nnchead, NNCHEADA_ILOC2_INDEX); - ecl_kw_type *nnc_tran; - int i; - - nnc_tran = ecl_nnc_export_get_tranx_kw(grid, init_file, - lgr_nr1, lgr_nr2); - test_assert_not_NULL(nnc_tran); - test_assert_int_equal(ecl_kw_get_size(nnc1_kw), - ecl_kw_get_size(nnc_tran)); - for (i = 0; i < ecl_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 = - ecl_kw_iget_int(nnc1_kw, i) - 1; - nnc_data1[i + nnc_offset].global_index2 = - ecl_kw_iget_int(nnc2_kw, i) - 1; - nnc_data1[i + nnc_offset].trans = - ecl_kw_iget_as_double(nnc_tran, i); - nnc_data1[i + nnc_offset].input_index = i; - } - nnc_offset += ecl_kw_get_size(nnc1_kw); - } - } - - test_assert_int_equal(nnc_offset, - ecl_nnc_export_get_size(grid, init_file)); - ecl_nnc_sort(nnc_data1, nnc_offset); - } - - { - int export_size = ecl_nnc_export(grid, init_file, nnc_data2); - test_assert_int_equal(export_size, - ecl_nnc_export_get_size(grid, init_file)); - } - - { - int i; - int size = ecl_nnc_export_get_size(grid, init_file); - for (i = 0; i < size; i++) - test_assert_int_equal( - 0, ecl_nnc_sort_cmp(&nnc_data1[i], &nnc_data2[i])); - } - - for (int i = 0; i < ecl_nnc_export_get_size(grid, init_file); i++) - test_assert_true(ecl_nnc_equal(&nnc_data1[i], &nnc_data2[i])); - - { - ecl_nnc_geometry_type *nnc_geo = ecl_nnc_geometry_alloc(grid); - ecl_file_view_type *view_file = ecl_file_get_global_view(init_file); - ecl_nnc_data_type *nnc_geo_data = - ecl_nnc_data_alloc_tran(grid, nnc_geo, view_file); - - test_assert_int_equal(ecl_nnc_export_get_size(grid, init_file), - ecl_nnc_geometry_size(nnc_geo)); - for (int i = 0; i < ecl_nnc_geometry_size(nnc_geo); i++) { - const ecl_nnc_pair_type *nnc_pair = - ecl_nnc_geometry_iget(nnc_geo, i); - ecl_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( - ecl_nnc_data_iget_value(nnc_geo_data, i), nnc1->trans); - } - ecl_nnc_data_free(nnc_geo_data); - ecl_nnc_geometry_free(nnc_geo); - } - - free(nnc_data2); - free(nnc_data1); - ecl_grid_free(grid); - ecl_file_close(grid_file); - ecl_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() { - - ecl_nnc_type nnc1 = {1, 1, 1, 1}; - ecl_nnc_type nnc2 = {1, 1, 1, 1}; - ecl_nnc_type nnc3 = {4, 1, 1, 1}; - ecl_nnc_type nnc4 = {4, 2, 1, 1}; - ecl_nnc_type nnc5 = {4, 2, 3, 1}; - ecl_nnc_type nnc6 = {4, 2, 3, 5}; - - test_assert_int_equal(0, ecl_nnc_sort_cmp(&nnc1, &nnc2)); - test_assert_int_equal(1, ecl_nnc_sort_cmp(&nnc3, &nnc1)); - test_assert_int_equal(1, ecl_nnc_sort_cmp(&nnc4, &nnc1)); - test_assert_int_equal(1, ecl_nnc_sort_cmp(&nnc5, &nnc4)); - test_assert_int_equal(-1, ecl_nnc_sort_cmp(&nnc4, &nnc5)); - test_assert_int_equal(-1, ecl_nnc_sort_cmp(&nnc5, &nnc6)); -} - -void test_sort() { - const int N = 1000; - ecl_nnc_type *nnc_list = (ecl_nnc_type *)util_calloc(N, sizeof *nnc_list); - int i; - for (i = 0; i < N; i++) { - ecl_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; - } - ecl_nnc_sort(nnc_list, N); - for (i = 0; i < (N - 1); i++) - test_assert_int_equal(-1, - ecl_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/ecl/tests/ecl_nnc_export_get_tran.cpp b/lib/ecl/tests/ecl_nnc_export_get_tran.cpp deleted file mode 100644 index 538d1e6cb8..0000000000 --- a/lib/ecl/tests/ecl_nnc_export_get_tran.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include - -void test_get_tran(const char *name) { - char *grid_file_name = - ecl_util_alloc_filename(NULL, name, ECL_EGRID_FILE, false, -1); - char *init_file_name = - ecl_util_alloc_filename(NULL, name, ECL_INIT_FILE, false, -1); - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_file_type *grid_file = ecl_file_open(grid_file_name, 0); - ecl_file_type *init_file = ecl_file_open(init_file_name, 0); - - /* Get global */ - { - ecl_kw_type *tran_kw = - ecl_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 0); - test_assert_true(ecl_kw_is_instance(tran_kw)); - test_assert_double_equal(0.85582769, ecl_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(0.24635284, - ecl_kw_iget_as_double(tran_kw, 7184)); - } - test_assert_NULL(ecl_nnc_export_get_tran_kw(init_file, TRANGL_KW, 0)); - test_assert_NULL(ecl_nnc_export_get_tran_kw(init_file, TRANLL_KW, 0)); - test_assert_NULL(ecl_nnc_export_get_tran_kw(init_file, "INVALID", 1)); - - /* Get lgr_nr: 48 */ - { - ecl_kw_type *tran_kw = - ecl_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 48); - test_assert_true(ecl_kw_is_instance(tran_kw)); - test_assert_int_equal(0, ecl_kw_get_size(tran_kw)); - - tran_kw = ecl_nnc_export_get_tran_kw(init_file, TRANGL_KW, 48); - test_assert_int_equal(282, ecl_kw_get_size(tran_kw)); - test_assert_double_equal(22.922695, ecl_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(16.720325, - ecl_kw_iget_as_double(tran_kw, 281)); - } - - /* Get lgr_nr: 99 */ - { - ecl_kw_type *tran_kw = - ecl_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 99); - test_assert_true(ecl_kw_is_instance(tran_kw)); - test_assert_int_equal(0, ecl_kw_get_size(tran_kw)); - - tran_kw = ecl_nnc_export_get_tran_kw(init_file, TRANGL_KW, 99); - test_assert_int_equal(693, ecl_kw_get_size(tran_kw)); - test_assert_double_equal(0.25534782, ecl_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(0.12677453, - ecl_kw_iget_as_double(tran_kw, 692)); - } - - /* Get lgr_nr: 10 */ - { - ecl_kw_type *tran_kw = - ecl_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 10); - test_assert_true(ecl_kw_is_instance(tran_kw)); - test_assert_int_equal(0, ecl_kw_get_size(tran_kw)); - - tran_kw = ecl_nnc_export_get_tran_kw(init_file, TRANGL_KW, 10); - test_assert_int_equal(260, ecl_kw_get_size(tran_kw)); - test_assert_double_equal(0.87355447, ecl_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(26.921568, - ecl_kw_iget_as_double(tran_kw, 259)); - } - - /* Get lgr_nr: 110 */ - { - ecl_kw_type *tran_kw = - ecl_nnc_export_get_tran_kw(init_file, TRANNNC_KW, 110); - test_assert_true(ecl_kw_is_instance(tran_kw)); - test_assert_int_equal(0, ecl_kw_get_size(tran_kw)); - - tran_kw = ecl_nnc_export_get_tran_kw(init_file, TRANGL_KW, 110); - test_assert_int_equal(208, ecl_kw_get_size(tran_kw)); - test_assert_double_equal(17.287283, ecl_kw_iget_as_double(tran_kw, 0)); - test_assert_double_equal(569.26312, - ecl_kw_iget_as_double(tran_kw, 207)); - } - - free(init_file_name); - free(grid_file_name); - ecl_grid_free(grid); - ecl_file_close(grid_file); - ecl_file_close(init_file); -} - -void test_tranLL(const ecl_grid_type *grid, const ecl_file_type *init_file, - int lgr_nr1, int lgr_nr2, int size, double first, - double last) { - - ecl_kw_type *ecl_kw = - ecl_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(ecl_kw); - test_assert_true(ecl_kw_is_instance(ecl_kw)); - test_assert_int_equal(size, ecl_kw_get_size(ecl_kw)); - test_assert_double_equal(first, ecl_kw_iget_as_double(ecl_kw, 0)); - test_assert_double_equal(last, ecl_kw_iget_as_double(ecl_kw, size - 1)); -} - -void test_get_tranLL(const char *name) { - char *grid_file_name = - ecl_util_alloc_filename(NULL, name, ECL_EGRID_FILE, false, -1); - char *init_file_name = - ecl_util_alloc_filename(NULL, name, ECL_INIT_FILE, false, -1); - ecl_grid_type *grid = ecl_grid_alloc(grid_file_name); - ecl_file_type *grid_file = ecl_file_open(grid_file_name, 0); - ecl_file_type *init_file = ecl_file_open(init_file_name, 0); - - test_tranLL(grid, init_file, - ecl_grid_get_lgr_nr_from_name(grid, "LG003017"), - ecl_grid_get_lgr_nr_from_name(grid, "LG003018"), 172, 5.3957253, - 1.0099934); - - test_tranLL(grid, init_file, - ecl_grid_get_lgr_nr_from_name(grid, "LG002016"), - ecl_grid_get_lgr_nr_from_name(grid, "LG002017"), 93, 1.4638059, - 0.36407200); - - test_tranLL(grid, init_file, - ecl_grid_get_lgr_nr_from_name(grid, "LG002016"), - ecl_grid_get_lgr_nr_from_name(grid, "LG003016"), 56, 2.7360380, - 10.053267); - - test_tranLL(grid, init_file, - ecl_grid_get_lgr_nr_from_name(grid, "LG009027"), - ecl_grid_get_lgr_nr_from_name(grid, "LG009026"), 152, 155.47754, - 219.23553); - - test_tranLL(grid, init_file, - ecl_grid_get_lgr_nr_from_name(grid, "LG009027"), - ecl_grid_get_lgr_nr_from_name(grid, "LG008027"), 317, - 0.040260997, 0.0066288318); - - free(init_file_name); - free(grid_file_name); - ecl_grid_free(grid); - ecl_file_close(grid_file); - ecl_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/ecl/tests/ecl_nnc_export_intersect.cpp b/lib/ecl/tests/ecl_nnc_export_intersect.cpp deleted file mode 100644 index 2df6fd17e0..0000000000 --- a/lib/ecl/tests/ecl_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( - ecl_grid_alloc_rectangular(GRIDX, GRIDY, GRIDZ, 1., 1., 1., nullptr)); - for (auto i = 0; i < GRID_NNC_NUM; ++i) - ecl_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 = ecl_kw_alloc(NNC1_KW, INIT_NNC_NUM, ECL_INT); - auto nnc2_kw = ecl_kw_alloc(NNC2_KW, INIT_NNC_NUM, ECL_INT); - auto tran_kw = ecl_kw_alloc(TRANNNC_KW, INIT_NNC_NUM, ECL_DOUBLE); - for (auto i = 0; i < INIT_NNC_NUM; ++i) { - ecl_kw_iset_int(nnc1_kw, i, 2 * i); - ecl_kw_iset_int(nnc2_kw, i, 2 * i + 1); - ecl_kw_iset_double(tran_kw, i, 2.5 * i); - } - - // write to file directly using fortio - auto init_filename = util_alloc_tmp_file( - "/tmp", "ecl_nnc_export_intersect_init_file", false); - auto fortio = fortio_open_writer(init_filename, false, ECL_ENDIAN_FLIP); - ecl_kw_fwrite(nnc1_kw, fortio); - ecl_kw_fwrite(nnc2_kw, fortio); - ecl_kw_fwrite(tran_kw, fortio); - fortio_fclose(fortio); - - // reopen the file as an ecl file - auto out = ERT::ert_unique_ptr( - ecl_file_open(init_filename, 0)); - - ecl_kw_free(nnc1_kw); - ecl_kw_free(nnc2_kw); - ecl_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(ecl_nnc_intersect_format(grid.get(), init_file.get())); - test_assert_int_equal(ecl_nnc_export_get_size(grid.get(), init_file.get()), - INIT_NNC_NUM); - - auto nnc_data = std::vector( - ecl_nnc_export_get_size(grid.get(), init_file.get())); - auto const total_valid_trans = - ecl_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/ecl/tests/ecl_nnc_geometry.cpp b/lib/ecl/tests/ecl_nnc_geometry.cpp deleted file mode 100644 index 9f90b606f8..0000000000 --- a/lib/ecl/tests/ecl_nnc_geometry.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - -void test_create_empty() { - ecl_grid_type *grid = ecl_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); - ecl_nnc_geometry_type *nnc_geo = ecl_nnc_geometry_alloc(grid); - test_assert_true(ecl_nnc_geometry_is_instance(nnc_geo)); - test_assert_int_equal(ecl_nnc_geometry_size(nnc_geo), 0); - ecl_nnc_geometry_free(nnc_geo); - ecl_grid_free(grid); -} - -void test_create_simple() { - ecl::util::TestArea ta("nnc_geometry"); - { - int nx = 10; - int ny = 10; - int nz = 10; - ecl_grid_type *grid0 = - ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); - - ecl_grid_add_self_nnc(grid0, 0, nx * ny + 0, 0); - ecl_grid_add_self_nnc(grid0, 1, nx * ny + 1, 1); - ecl_grid_add_self_nnc(grid0, 2, nx * ny + 2, 2); - { - ecl_nnc_geometry_type *nnc_geo = ecl_nnc_geometry_alloc(grid0); - test_assert_int_equal(ecl_nnc_geometry_size(nnc_geo), 3); - - /* - Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size. - */ - { - ecl_kw_type *trann_nnc = ecl_kw_alloc( - TRANNNC_KW, ecl_nnc_geometry_size(nnc_geo), ECL_FLOAT); - fortio_type *f = - fortio_open_writer("TEST.INIT", false, ECL_ENDIAN_FLIP); - - for (int i = 0; i < ecl_kw_get_size(trann_nnc); i++) - ecl_kw_iset_float(trann_nnc, i, i * 1.0); - - ecl_kw_fwrite(trann_nnc, f); - fortio_fclose(f); - ecl_kw_free(trann_nnc); - } - ecl_nnc_geometry_free(nnc_geo); - } - ecl_grid_free(grid0); - } -} - -int main(int argc, char **argv) { - util_install_signals(); - test_create_empty(); - test_create_simple(); -} diff --git a/lib/ecl/tests/ecl_nnc_index_list_grid.cpp b/lib/ecl/tests/ecl_nnc_index_list_grid.cpp deleted file mode 100644 index ef1a4129d7..0000000000 --- a/lib/ecl/tests/ecl_nnc_index_list_grid.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include - -int main(int argc, char **argv) { - const char *egrid_file = argv[1]; - - ecl_grid_type *grid = ecl_grid_alloc(egrid_file); - ecl_file_type *gfile = ecl_file_open(egrid_file, 0); - const ecl_kw_type *nnc1_kw = ecl_file_iget_named_kw(gfile, "NNC1", 0); - const ecl_kw_type *nnc2_kw = ecl_file_iget_named_kw(gfile, "NNC2", 0); - const int_vector_type *index_list = ecl_grid_get_nnc_index_list(grid); - - { - int_vector_type *nnc = int_vector_alloc(0, 0); - - int_vector_set_many(nnc, 0, ecl_kw_get_ptr(nnc1_kw), - ecl_kw_get_size(nnc1_kw)); - int_vector_append_many(nnc, ecl_kw_get_ptr(nnc2_kw), - ecl_kw_get_size(nnc2_kw)); - int_vector_select_unique(nnc); - test_assert_int_equal(int_vector_size(index_list), - int_vector_size(nnc)); - - { - int i; - for (i = 0; i < int_vector_size(nnc); i++) - test_assert_int_equal(int_vector_iget(nnc, i) - 1, - int_vector_iget(index_list, i)); - } - int_vector_free(nnc); - } - - ecl_file_close(gfile); - ecl_grid_free(grid); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_nnc_test.cpp b/lib/ecl/tests/ecl_nnc_test.cpp deleted file mode 100644 index fc78698d4a..0000000000 --- a/lib/ecl/tests/ecl_nnc_test.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -void test_scan(const char *grid_filename) { - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_filename); - ecl_file_type *grid_file = ecl_file_open(grid_filename, 0); - int block_nr; - - for (block_nr = 0; - block_nr < ecl_file_get_num_named_kw(grid_file, NNCHEAD_KW); - block_nr++) { - ecl_grid_type *lgr = ecl_grid; - int lgr_nr; - ecl_file_view_type *nnc_view = - ecl_file_alloc_global_blockview(grid_file, NNCHEAD_KW, block_nr); - { - if (block_nr > 0) - lgr = ecl_grid_iget_lgr(ecl_grid, block_nr - 1); - lgr_nr = ecl_grid_get_lgr_nr(lgr); - - /* Internal nnc */ - { - if (ecl_file_view_has_kw(nnc_view, NNC1_KW)) { - ecl_kw_type *nnc1_kw = - ecl_file_view_iget_named_kw(nnc_view, NNC1_KW, 0); - ecl_kw_type *nnc2_kw = - ecl_file_view_iget_named_kw(nnc_view, NNC2_KW, 0); - int i; - for (i = 0; i < ecl_kw_get_size(nnc1_kw); i++) { - const int g1 = ecl_kw_iget_int(nnc1_kw, i) - 1; - const int g2 = ecl_kw_iget_int(nnc2_kw, i) - 1; - - if (g2 < - ecl_grid_get_global_size( - lgr)) { // Skipping matrix <-> fracture link in dual poro. - const nnc_info_type *nnc_info = - ecl_grid_get_cell_nnc_info1(lgr, g1); - const std::vector &index_list = - nnc_info_get_grid_index_list(nnc_info, lgr_nr); - test_assert_not_NULL(nnc_info); - test_assert_int_not_equal( - -1, vector_util_index(index_list, g2)); - } - } - } - } - } - - /* Global -> lgr */ - { - if (ecl_file_view_has_kw(nnc_view, NNCG_KW)) { - ecl_kw_type *nnchead_kw = - ecl_file_view_iget_named_kw(nnc_view, NNCHEAD_KW, 0); - ecl_kw_type *nncg_kw = - ecl_file_view_iget_named_kw(nnc_view, NNCG_KW, 0); - ecl_kw_type *nncl_kw = - ecl_file_view_iget_named_kw(nnc_view, NNCL_KW, 0); - int i; - int lgr_nr = ecl_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX); - for (i = 0; i < ecl_kw_get_size(nncg_kw); i++) { - const int g = ecl_kw_iget_int(nncg_kw, i) - 1; - const int l = ecl_kw_iget_int(nncl_kw, i) - 1; - - const nnc_info_type *nnc_info = - ecl_grid_get_cell_nnc_info1(ecl_grid, g); - test_assert_not_NULL(nnc_info); - { - const std::vector &index_list = - nnc_info_get_grid_index_list(nnc_info, lgr_nr); - test_assert_true( - nnc_info_has_grid_index_list(nnc_info, lgr_nr)); - test_assert_int_not_equal( - -1, vector_util_index(index_list, l)); - } - } - } - } - - /* Amalgamated: LGR -> LGR */ - { - if (ecl_file_view_has_kw(nnc_view, NNCHEADA_KW)) { - ecl_kw_type *nncheada_kw = - ecl_file_view_iget_named_kw(nnc_view, NNCHEADA_KW, 0); - ecl_kw_type *nnc1_kw = - ecl_file_view_iget_named_kw(nnc_view, NNA1_KW, 0); - ecl_kw_type *nnc2_kw = - ecl_file_view_iget_named_kw(nnc_view, NNA2_KW, 0); - int lgr_nr1 = - ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC1_INDEX); - int lgr_nr2 = - ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC2_INDEX); - - ecl_grid_type *lgr1 = - ecl_grid_get_lgr_from_lgr_nr(ecl_grid, lgr_nr1); - for (int i = 0; i < ecl_kw_get_size(nnc1_kw); i++) { - const int g1 = ecl_kw_iget_int(nnc1_kw, i) - 1; - const int g2 = ecl_kw_iget_int(nnc2_kw, i) - 1; - - const nnc_info_type *nnc_info = - ecl_grid_get_cell_nnc_info1(lgr1, g1); - const std::vector &index_list = - nnc_info_get_grid_index_list(nnc_info, lgr_nr2); - test_assert_not_NULL(nnc_info); - test_assert_int_not_equal( - -1, vector_util_index(index_list, g2)); - } - } - } - - ecl_file_view_free(nnc_view); - } -} - -int main(int argc, char **argv) { - int iarg; - for (iarg = 1; iarg < argc; iarg++) { - printf("Checking file: %s \n", argv[iarg]); - test_scan(argv[iarg]); - } - - exit(0); -} diff --git a/lib/ecl/tests/ecl_region.cpp b/lib/ecl/tests/ecl_region.cpp deleted file mode 100644 index 0b6cc32ae1..0000000000 --- a/lib/ecl/tests/ecl_region.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -#include - -#include -#include - -void test_list(int volume, int nactive, ecl_region_type *region) { - const int_vector_type *active_list; - const int_vector_type *global_list; - active_list = ecl_region_get_active_list(region); - global_list = ecl_region_get_global_list(region); - test_assert_int_equal(nactive, int_vector_size(active_list)); - test_assert_int_equal(volume, int_vector_size(global_list)); - - ecl_region_deselect_all(region); - active_list = ecl_region_get_active_list(region); - global_list = ecl_region_get_global_list(region); - test_assert_int_equal(0, int_vector_size(active_list)); - test_assert_int_equal(0, int_vector_size(global_list)); -} - -void test_slice(const ecl_grid_type *grid) { - int nx = ecl_grid_get_nx(grid); - int ny = ecl_grid_get_ny(grid); - int nz = ecl_grid_get_nz(grid); - int nactive = ecl_grid_get_nactive(grid); - ecl_region_type *region = ecl_region_alloc(grid, false); - - ecl_region_select_i1i2(region, 0, nx - 1); - test_list(nx * ny * nz, nactive, region); - ecl_region_select_j1j2(region, 0, ny - 1); - test_list(nx * ny * nz, nactive, region); - ecl_region_select_k1k2(region, 0, nz - 1); - test_list(nx * ny * nz, nactive, region); - - ecl_region_free(region); -} - -int main(int argc, char **argv) { - const char *grid_file = argv[1]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); - - test_slice(grid); - - ecl_grid_free(grid); - exit(0); -} diff --git a/lib/ecl/tests/ecl_region2region.cpp b/lib/ecl/tests/ecl_region2region.cpp deleted file mode 100644 index a710a7e0c0..0000000000 --- a/lib/ecl/tests/ecl_region2region.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include - -#include -#include - -void has_r2r_key(const ecl_sum_type *ecl_sum) { - test_assert_true(ecl_sum_has_key(ecl_sum, "RGF:393217")); - test_assert_true(ecl_sum_has_key(ecl_sum, "RGF:1-2")); - test_assert_true(ecl_sum_has_key(ecl_sum, "ROF:524291")); - test_assert_true(ecl_sum_has_key(ecl_sum, "RWF:393222")); - test_assert_true(ecl_sum_has_key(ecl_sum, "RWF:6-2")); - test_assert_true(ecl_sum_has_key(ecl_sum, "ROF:3-6")); - test_assert_true(ecl_sum_has_key(ecl_sum, "RNLF:458753")); - test_assert_true(ecl_sum_has_key(ecl_sum, "RNLF:1-4")); -} - -void get_unit(const ecl_sum_type *ecl_sum) { - test_assert_string_equal(ecl_sum_get_unit(ecl_sum, "RGF:1-2"), "GFLOW"); - test_assert_string_equal(ecl_sum_get_unit(ecl_sum, "ROF:3-6"), "OFLOW"); - test_assert_string_equal(ecl_sum_get_unit(ecl_sum, "RWF:6-2"), "WFLOW"); - test_assert_string_equal(ecl_sum_get_unit(ecl_sum, "RNLF:1-4"), "NLFLOW"); -} - -void get_var_params_index(const ecl_sum_type *ecl_sum) { - test_assert_int_equal( - ecl_sum_get_general_var_params_index(ecl_sum, "RGF:1-2"), 21917); - test_assert_int_equal( - ecl_sum_get_general_var_params_index(ecl_sum, "ROF:3-6"), 21918); - test_assert_int_equal( - ecl_sum_get_general_var_params_index(ecl_sum, "RWF:6-2"), 21919); - test_assert_int_equal( - ecl_sum_get_general_var_params_index(ecl_sum, "RNLF:1-4"), 21920); -} - -int main(int argc, char **argv) { - - const char *headerfile = argv[1]; - - ecl_sum_type *ecl_sum = ecl_sum_fread_alloc_case(headerfile, ":"); - - if (ecl_sum) { - has_r2r_key(ecl_sum); - get_unit(ecl_sum); - get_var_params_index(ecl_sum); - } else - test_error_exit("ecl_region2region_test: Test file not read correctly"); - - if (ecl_sum) - ecl_sum_free(ecl_sum); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_rft.cpp b/lib/ecl/tests/ecl_rft.cpp deleted file mode 100644 index 1394024852..0000000000 --- a/lib/ecl/tests/ecl_rft.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -void test_rft_read_write(const char *rft_file) { - ecl_rft_file_type *rft = ecl_rft_file_alloc(rft_file); - ecl_rft_node_type **nodes = - (ecl_rft_node_type **)malloc(sizeof(ecl_rft_node_type *) * 3); - int size = ecl_rft_file_get_size(rft); - for (int i = 0; i < size; i++) { - ecl_rft_node_type *rft_node = ecl_rft_file_iget_node(rft, i); - nodes[i] = rft_node; - } - ecl_rft_node_type *old_node = ecl_rft_file_iget_node(rft, 0); - ecl_rft_node_type *new_node = - ecl_rft_node_alloc_new("DUMMY", "R", ecl_rft_node_get_date(old_node), - ecl_rft_node_get_days(old_node)); - nodes[2] = new_node; - ecl::util::TestArea ta("rft"); - - ecl_rft_file_update("eclipse.rft", nodes, 3, ECL_METRIC_UNITS); - free(nodes); -} - -// Hardcoded GURBAT values -void test_rft(const char *rft_file) { - ecl_rft_file_type *rft = ecl_rft_file_alloc(rft_file); - ecl_rft_node_type *rft_node = ecl_rft_file_iget_node(rft, 0); - - test_assert_true(ecl_rft_node_is_RFT(rft_node)); - test_assert_int_equal(14, ecl_rft_node_get_size(rft_node)); - test_assert_false(ecl_rft_node_is_MSW(rft_node)); - - test_assert_double_equal(260.6111, ecl_rft_node_iget_pressure(rft_node, 0)); - test_assert_double_equal(0.0581993, ecl_rft_node_iget_soil(rft_node, 0)); - test_assert_double_equal(0.9405648, ecl_rft_node_iget_swat(rft_node, 0)); - test_assert_double_equal(0.00123579, ecl_rft_node_iget_sgas(rft_node, 0)); - - { - int i, j, k; - - ecl_rft_node_iget_ijk(rft_node, 0, &i, &j, &k); - test_assert_int_equal(32, i); - test_assert_int_equal(53, j); - test_assert_int_equal(0, k); - - ecl_rft_node_iget_ijk(rft_node, 13, &i, &j, &k); - test_assert_int_equal(32, i); - test_assert_int_equal(54, j); - test_assert_int_equal(12, k); - - for (i = 0; i < ecl_rft_node_get_size(rft_node); i++) { - const ecl_rft_cell_type *cell1 = - ecl_rft_node_iget_cell(rft_node, i); - const ecl_rft_cell_type *cell2 = - ecl_rft_node_iget_cell_sorted(rft_node, i); - - test_assert_ptr_equal(cell1, cell2); - } - } - ecl_rft_file_free(rft); -} - -void test_plt_msw(const char *plt_file) { - ecl_rft_file_type *plt = ecl_rft_file_alloc(plt_file); - ecl_rft_node_type *plt_node = ecl_rft_file_iget_node(plt, 11); - - test_assert_true(ecl_rft_node_is_PLT(plt_node)); - test_assert_true(ecl_rft_node_is_MSW(plt_node)); - test_assert_int_equal(22, ecl_rft_node_get_size(plt_node)); - { - int i; - for (i = 1; i < ecl_rft_node_get_size(plt_node); i++) { - const ecl_rft_cell_type *prev_cell = - ecl_rft_node_iget_cell(plt_node, i - 1); - const ecl_rft_cell_type *this_cell = - ecl_rft_node_iget_cell(plt_node, i); - - test_assert_true(ecl_rft_cell_get_connection_start(prev_cell) < - ecl_rft_cell_get_connection_start(this_cell)); - test_assert_true(ecl_rft_cell_get_connection_end(prev_cell) < - ecl_rft_cell_get_connection_end(this_cell)); - } - } - - ecl_rft_file_free(plt); -} - -// Hardcoded values from a test case with a PLT. -void test_plt(const char *plt_file) { - ecl_rft_file_type *plt = ecl_rft_file_alloc(plt_file); - ecl_rft_node_type *plt_node = ecl_rft_file_iget_node(plt, 11); - - test_assert_true(ecl_rft_node_is_PLT(plt_node)); - test_assert_false(ecl_rft_node_is_MSW(plt_node)); - test_assert_int_equal(22, ecl_rft_node_get_size(plt_node)); - - test_assert_double_equal(244.284, ecl_rft_node_iget_pressure(plt_node, 0)); - test_assert_double_equal(167.473, ecl_rft_node_iget_orat(plt_node, 0)); - test_assert_double_equal(41682.2, ecl_rft_node_iget_grat(plt_node, 0)); - test_assert_double_equal(0.958927, ecl_rft_node_iget_wrat(plt_node, 0)); - - { - int i, j, k; - - ecl_rft_node_iget_ijk(plt_node, 0, &i, &j, &k); - test_assert_int_equal(39, i); - test_assert_int_equal(33, j); - test_assert_int_equal(16, k); - - ecl_rft_node_iget_ijk(plt_node, 21, &i, &j, &k); - test_assert_int_equal(44, i); - test_assert_int_equal(34, j); - test_assert_int_equal(7, k); - - for (i = 0; i < ecl_rft_node_get_size(plt_node); i++) { - const ecl_rft_cell_type *cell1 = - ecl_rft_node_iget_cell(plt_node, i); - const ecl_rft_cell_type *cell2 = - ecl_rft_node_iget_cell_sorted(plt_node, i); - - test_assert_ptr_equal(cell1, cell2); - } - } - - ecl_rft_file_free(plt); -} - -void test_simple_load_rft(const char *filename) { - ecl_rft_file_type *rft_file = ecl_rft_file_alloc_case(filename); - ecl_rft_file_free(rft_file); -} - -int main(int argc, char **argv) { - const char *rft_file = argv[1]; - const char *mode_string = argv[2]; - util_install_signals(); - - if (strcmp(mode_string, "RFT") == 0) - test_rft(rft_file); - else if (strcmp(mode_string, "RFT_RW") == 0) - test_rft_read_write(rft_file); - else if (strcmp(mode_string, "PLT") == 0) - test_plt(rft_file); - else if (strcmp(mode_string, "MSW-PLT") == 0) - test_plt_msw(rft_file); - else if (strcmp(mode_string, "SIMPLE") == 0) - test_simple_load_rft(rft_file); - else - test_error_exit( - "Second argument:%s not recognized. Valid values are: RFT and PLT", - mode_string); - - exit(0); -} diff --git a/lib/ecl/tests/ecl_rft_cell.cpp b/lib/ecl/tests/ecl_rft_cell.cpp deleted file mode 100644 index 80f2f122b1..0000000000 --- a/lib/ecl/tests/ecl_rft_cell.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include - -void test_rft_cell() { - const int i = 10; - const int j = 11; - const int k = 12; - - const double depth = 100; - const double pressure = 200; - const double swat = 0.25; - const double sgas = 0.35; - - ecl_rft_cell_type *cell = - ecl_rft_cell_alloc_RFT(i, j, k, depth, pressure, swat, sgas); - - test_assert_int_equal(i, ecl_rft_cell_get_i(cell)); - test_assert_int_equal(j, ecl_rft_cell_get_j(cell)); - test_assert_int_equal(k, ecl_rft_cell_get_k(cell)); - - { - int ii, jj, kk; - ecl_rft_cell_get_ijk(cell, &ii, &jj, &kk); - test_assert_int_equal(i, ii); - test_assert_int_equal(j, jj); - test_assert_int_equal(k, kk); - } - - test_assert_double_equal(depth, ecl_rft_cell_get_depth(cell)); - test_assert_double_equal(pressure, ecl_rft_cell_get_pressure(cell)); - test_assert_double_equal(swat, ecl_rft_cell_get_swat(cell)); - test_assert_double_equal(sgas, ecl_rft_cell_get_sgas(cell)); - test_assert_double_equal(1 - (swat + sgas), ecl_rft_cell_get_soil(cell)); - - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_orat(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_grat(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_wrat(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_flowrate(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_connection_start(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_connection_end(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_oil_flowrate(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_gas_flowrate(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_water_flowrate(cell)); - - ecl_rft_cell_free(cell); - { - ecl_rft_cell_type *cell = - ecl_rft_cell_alloc_RFT(i, j, k, depth, pressure, swat, sgas); - - test_assert_true(ecl_rft_cell_ijk_equal(cell, i, j, k)); - test_assert_false(ecl_rft_cell_ijk_equal(cell, i, j, k + 1)); - - ecl_rft_cell_free__(cell); - } -} - -void test_plt_cell() { - const int i = 10; - const int j = 11; - const int k = 12; - - const double depth = 100; - const double pressure = 200; - const double orat = 0.25; - const double grat = 0.35; - const double wrat = 0.45; - const double flowrate = 100.0; - const double connection_start = 891; - const double connection_end = 979; - const double oil_flowrate = 0.891; - const double gas_flowrate = 7771; - const double water_flowrate = 77614; - - ecl_rft_cell_type *cell = ecl_rft_cell_alloc_PLT( - i, j, k, depth, pressure, orat, grat, wrat, connection_start, - connection_end, flowrate, oil_flowrate, gas_flowrate, water_flowrate); - - test_assert_int_equal(i, ecl_rft_cell_get_i(cell)); - test_assert_int_equal(j, ecl_rft_cell_get_j(cell)); - test_assert_int_equal(k, ecl_rft_cell_get_k(cell)); - - { - int ii, jj, kk; - ecl_rft_cell_get_ijk(cell, &ii, &jj, &kk); - test_assert_int_equal(i, ii); - test_assert_int_equal(j, jj); - test_assert_int_equal(k, kk); - } - - test_assert_double_equal(depth, ecl_rft_cell_get_depth(cell)); - test_assert_double_equal(pressure, ecl_rft_cell_get_pressure(cell)); - - test_assert_double_equal(orat, ecl_rft_cell_get_orat(cell)); - test_assert_double_equal(grat, ecl_rft_cell_get_grat(cell)); - test_assert_double_equal(wrat, ecl_rft_cell_get_wrat(cell)); - test_assert_double_equal(connection_start, - ecl_rft_cell_get_connection_start(cell)); - test_assert_double_equal(connection_end, - ecl_rft_cell_get_connection_end(cell)); - test_assert_double_equal(flowrate, ecl_rft_cell_get_flowrate(cell)); - - test_assert_double_equal(oil_flowrate, ecl_rft_cell_get_oil_flowrate(cell)); - test_assert_double_equal(gas_flowrate, ecl_rft_cell_get_gas_flowrate(cell)); - test_assert_double_equal(water_flowrate, - ecl_rft_cell_get_water_flowrate(cell)); - - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_swat(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_sgas(cell)); - test_assert_double_equal(ECL_RFT_CELL_INVALID_VALUE, - ecl_rft_cell_get_soil(cell)); - - ecl_rft_cell_free(cell); -} - -int main(int argc, char **argv) { - - test_rft_cell(); - test_plt_cell(); - exit(0); -} diff --git a/lib/ecl/tests/ecl_rst_file.cpp b/lib/ecl/tests/ecl_rst_file.cpp deleted file mode 100644 index 074f6f961a..0000000000 --- a/lib/ecl/tests/ecl_rst_file.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -void write_keyword(fortio_type *fortio, const char *kw, - ecl_data_type data_type) { - ecl_kw_type *ecl_kw = ecl_kw_alloc(kw, 1000, data_type); - ecl_kw_fwrite(ecl_kw, fortio); - ecl_kw_free(ecl_kw); -} - -void write_seqnum(fortio_type *fortio, int report_step) { - ecl_kw_type *ecl_kw = ecl_kw_alloc(SEQNUM_KW, 1, ECL_INT); - ecl_kw_iset_int(ecl_kw, 0, report_step); - ecl_kw_fwrite(ecl_kw, fortio); - ecl_kw_free(ecl_kw); -} - -void test_empty() { - ecl_rst_file_type *rst_file = - ecl_rst_file_open_write_seek("EMPTY.UNRST", 0); - test_assert_int_equal(ecl_rst_file_ftell(rst_file), 0); - ecl_rst_file_close(rst_file); -} - -void test_file(const char *src_file, const char *target_file, int report_step, - offset_type expected_offset) { - util_copy_file(src_file, target_file); - { - ecl_rst_file_type *rst_file = - ecl_rst_file_open_write_seek(target_file, report_step); - test_assert_true(ecl_rst_file_ftell(rst_file) == expected_offset); - ecl_rst_file_close(rst_file); - test_assert_true(util_file_size(target_file) == - (size_t)expected_offset); - } -} - -void test_Xfile() { - ecl::util::TestArea ta("xfile"); - { - fortio_type *f = - fortio_open_writer("TEST.X0010", false, ECL_ENDIAN_FLIP); - - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - fortio_fclose(f); - } - test_file("TEST.X0010", "FILE.X0010", 10, 0); -} - -void test_UNRST0() { - ecl::util::TestArea ta("rst-file"); - offset_type pos10; - offset_type pos20; - offset_type pos_end; - { - fortio_type *f = - fortio_open_writer("TEST.UNRST", false, ECL_ENDIAN_FLIP); - write_seqnum(f, 0); - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - pos10 = fortio_ftell(f); - write_seqnum(f, 10); - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - pos20 = fortio_ftell(f); - write_seqnum(f, 20); - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - pos_end = fortio_ftell(f); - fortio_fclose(f); - } - test_file("TEST.UNRST", "FILE.UNRST", 0, 0); - test_file("TEST.UNRST", "FILE.UNRST", 5, pos10); - test_file("TEST.UNRST", "FILE.UNRST", 10, pos10); - test_file("TEST.UNRST", "FILE.UNRST", 15, pos20); - test_file("TEST.UNRST", "FILE.UNRST", 20, pos20); - test_file("TEST.UNRST", "FILE.UNRST", 25, pos_end); -} - -void test_UNRST1() { - ecl::util::TestArea ta("rst-file"); - offset_type pos5; - offset_type pos10; - offset_type pos20; - offset_type pos_end; - { - fortio_type *f = - fortio_open_writer("TEST.UNRST", false, ECL_ENDIAN_FLIP); - pos5 = fortio_ftell(f); - write_seqnum(f, 5); - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - pos10 = fortio_ftell(f); - write_seqnum(f, 10); - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - pos20 = fortio_ftell(f); - write_seqnum(f, 20); - write_keyword(f, "INTEHEAD", ECL_INT); - write_keyword(f, "PRESSURE", ECL_FLOAT); - write_keyword(f, "SWAT", ECL_FLOAT); - - pos_end = fortio_ftell(f); - fortio_fclose(f); - } - test_file("TEST.UNRST", "FILE.UNRST", 0, 0); - test_file("TEST.UNRST", "FILE.UNRST", 1, 0); - test_file("TEST.UNRST", "FILE.UNRST", 5, pos5); - test_file("TEST.UNRST", "FILE.UNRST", 10, pos10); - test_file("TEST.UNRST", "FILE.UNRST", 15, pos20); - test_file("TEST.UNRST", "FILE.UNRST", 20, pos20); - test_file("TEST.UNRST", "FILE.UNRST", 25, pos_end); -} - -int main(int argc, char **argv) { - test_empty(); - test_Xfile(); - test_UNRST0(); - test_UNRST1(); -} diff --git a/lib/ecl/tests/ecl_smspec.cpp b/lib/ecl/tests/ecl_smspec.cpp deleted file mode 100644 index 8af380dfe0..0000000000 --- a/lib/ecl/tests/ecl_smspec.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -#include -#include -#include - -void test_copy(const ecl_smspec_type *smspec1) { - ecl_sum_type *ecl_sum2 = - ecl_sum_alloc_writer("CASE", false, true, ":", 0, true, 100, 100, 100); - const ecl_smspec_type *smspec2 = ecl_sum_get_smspec(ecl_sum2); - for (int i = 0; i < ecl_smspec_num_nodes(smspec1); i++) { - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_node_index(smspec1, i); - ecl_sum_add_smspec_node(ecl_sum2, &node); - } - test_assert_true(ecl_smspec_equal(smspec1, smspec2)); - ecl_sum_free(ecl_sum2); -} - -int main(int argc, char **argv) { - const char *case1 = argv[1]; - const char *case2 = argv[2]; - ecl_smspec_type *smspec1 = ecl_smspec_fread_alloc(case1, ":", false); - ecl_smspec_type *smspec2 = ecl_smspec_fread_alloc(case2, ":", false); - - test_assert_true(ecl_smspec_equal(smspec2, smspec2)); - test_assert_true(ecl_smspec_equal(smspec1, smspec1)); - - test_assert_false(ecl_smspec_equal(smspec1, smspec2)); - test_assert_false(ecl_smspec_equal(smspec2, smspec1)); - - ecl_smspec_free(smspec1); - ecl_smspec_free(smspec2); -} diff --git a/lib/ecl/tests/ecl_sum_alloc_resampled_test.cpp b/lib/ecl/tests/ecl_sum_alloc_resampled_test.cpp deleted file mode 100644 index 710b81f72a..0000000000 --- a/lib/ecl/tests/ecl_sum_alloc_resampled_test.cpp +++ /dev/null @@ -1,141 +0,0 @@ - -#include - -#include -#include -#include - -ecl_sum_type *test_alloc_ecl_sum() { - time_t start_time = util_make_date_utc(1, 1, 2010); - ecl_sum_type *ecl_sum = ecl_sum_alloc_writer("/tmp/CASE", false, true, ":", - start_time, true, 10, 10, 10); - double sim_seconds = 0; - - int num_dates = 4; - double ministep_length = 86400; // seconds in a day - - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "FOPT", NULL, 0, "Barrels", 99.0); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 567, "BARS", 0.0); - const ecl::smspec_node *node3 = - ecl_sum_add_var(ecl_sum, "WWCT", "OP-1", 0, "(1)", 0.0); - - for (int report_step = 0; report_step < num_dates; report_step++) { - { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, report_step * 2.0); - ecl_sum_tstep_set_from_node(tstep, *node2, report_step * 4.0 + 2.0); - ecl_sum_tstep_set_from_node(tstep, *node3, report_step * 6.0 + 4.0); - } - sim_seconds += ministep_length * 3; - } - return ecl_sum; -} - -void test_correct_time_vector() { - - ecl_sum_type *ecl_sum = test_alloc_ecl_sum(); - time_t_vector_type *t = time_t_vector_alloc(0, 0); - time_t_vector_append(t, util_make_date_utc(2, 1, 2010)); - time_t_vector_append(t, util_make_date_utc(4, 1, 2010)); - time_t_vector_append(t, util_make_date_utc(6, 1, 2010)); - time_t_vector_append(t, util_make_date_utc(8, 1, 2010)); - ecl_sum_type *ecl_sum_resampled = - ecl_sum_alloc_resample(ecl_sum, "kk", t, false, false); - test_assert_int_equal(ecl_sum_get_report_time(ecl_sum_resampled, 2), - util_make_date_utc(6, 1, 2010)); - - const ecl_smspec_type *smspec_resampled = - ecl_sum_get_smspec(ecl_sum_resampled); - const ecl::smspec_node &node1 = - ecl_smspec_iget_node_w_params_index(smspec_resampled, 1); - const ecl::smspec_node &node2 = - ecl_smspec_iget_node_w_params_index(smspec_resampled, 2); - const ecl::smspec_node &node3 = - ecl_smspec_iget_node_w_params_index(smspec_resampled, 3); - test_assert_string_equal("BPR", smspec_node_get_keyword(&node2)); - test_assert_string_equal("BARS", smspec_node_get_unit(&node2)); - - test_assert_double_equal( - 3.33333, - ecl_sum_get_from_sim_time(ecl_sum_resampled, - util_make_date_utc(6, 1, 2010), &node1)); - test_assert_double_equal( - 3.33333, - ecl_sum_get_from_sim_time(ecl_sum_resampled, - util_make_date_utc(2, 1, 2010), &node2)); - test_assert_double_equal( - 10.0000, - ecl_sum_get_from_sim_time(ecl_sum_resampled, - util_make_date_utc(4, 1, 2010), &node3)); - - ecl_sum_free(ecl_sum_resampled); - time_t_vector_free(t); - ecl_sum_free(ecl_sum); -} - -void test_resample_extrapolate_rate() { - - ecl_sum_type *ecl_sum = test_alloc_ecl_sum(); - - time_t_vector_type *t = time_t_vector_alloc(0, 0); - time_t_vector_append(t, util_make_date_utc(1, 1, 2009)); - time_t_vector_append(t, util_make_date_utc(4, 1, 2010)); - time_t_vector_append(t, util_make_date_utc(12, 1, 2010)); - - ecl_sum_type *ecl_sum_resampled = - ecl_sum_alloc_resample(ecl_sum, "kk", t, true, true); - - const ecl_smspec_type *smspec_resampled = - ecl_sum_get_smspec(ecl_sum_resampled); - const ecl::smspec_node &node1 = - ecl_smspec_iget_node_w_params_index(smspec_resampled, 1); - const ecl::smspec_node &node3 = - ecl_smspec_iget_node_w_params_index(smspec_resampled, 3); - - //testing extrapolation for rate wrt. 3 dates: lower, inside and upper - test_assert_double_equal( - 0, ecl_sum_get_from_sim_time(ecl_sum_resampled, - util_make_date_utc(1, 1, 2009), &node3)); - test_assert_double_equal( - 10.000, ecl_sum_get_from_sim_time( - ecl_sum_resampled, util_make_date_utc(4, 1, 2010), &node3)); - test_assert_double_equal( - 0, ecl_sum_get_from_sim_time(ecl_sum_resampled, - util_make_date_utc(12, 1, 2010), &node3)); - - //testing extrapolation for variable wrt. 3 dates: lower, inside and upper - test_assert_double_equal( - 0, ecl_sum_get_from_sim_time(ecl_sum_resampled, - util_make_date_utc(1, 1, 2009), &node1)); - test_assert_double_equal( - 2.000, ecl_sum_get_from_sim_time( - ecl_sum_resampled, util_make_date_utc(4, 1, 2010), &node1)); - test_assert_double_equal( - 6.000, ecl_sum_get_from_sim_time( - ecl_sum_resampled, util_make_date_utc(12, 1, 2010), &node1)); - - ecl_sum_free(ecl_sum_resampled); - time_t_vector_free(t); - ecl_sum_free(ecl_sum); -} - -void test_not_sorted() { - ecl_sum_type *ecl_sum = test_alloc_ecl_sum(); - time_t_vector_type *t = time_t_vector_alloc(0, 0); - time_t_vector_append(t, util_make_date_utc(1, 1, 2010)); - time_t_vector_append(t, util_make_date_utc(3, 1, 2010)); - time_t_vector_append(t, util_make_date_utc(2, 1, 2010)); - test_assert_NULL(ecl_sum_alloc_resample(ecl_sum, "kk", t, false, false)); - time_t_vector_free(t); - ecl_sum_free(ecl_sum); -} - -int main() { - test_correct_time_vector(); - test_resample_extrapolate_rate(); - test_not_sorted(); - return 0; -} diff --git a/lib/ecl/tests/ecl_sum_report_step_compatible.cpp b/lib/ecl/tests/ecl_sum_report_step_compatible.cpp deleted file mode 100644 index ae2257cb12..0000000000 --- a/lib/ecl/tests/ecl_sum_report_step_compatible.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -int main(int argc, char **argv) { - const char *case1 = argv[1]; - const char *case2 = argv[2]; - const char *compatible_string = argv[3]; - ecl_sum_type *ecl_sum1 = ecl_sum_fread_alloc_case(case1, ":"); - ecl_sum_type *ecl_sum2 = ecl_sum_fread_alloc_case(case2, ":"); - - test_assert_true(ecl_sum_is_instance(ecl_sum1)); - test_assert_true(ecl_sum_is_instance(ecl_sum2)); - test_assert_true(ecl_sum_report_step_compatible(ecl_sum1, ecl_sum1)); - test_assert_true(ecl_sum_report_step_compatible(ecl_sum2, ecl_sum2)); - - { - bool compatible; - test_assert_true(util_sscanf_bool(compatible_string, &compatible)); - test_assert_bool_equal( - compatible, ecl_sum_report_step_compatible(ecl_sum1, ecl_sum2)); - } - ecl_sum_free(ecl_sum1); - ecl_sum_free(ecl_sum2); - exit(0); -} diff --git a/lib/ecl/tests/ecl_sum_report_step_equal.cpp b/lib/ecl/tests/ecl_sum_report_step_equal.cpp deleted file mode 100644 index 1c0a788b38..0000000000 --- a/lib/ecl/tests/ecl_sum_report_step_equal.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -int main(int argc, char **argv) { - const char *case1 = argv[1]; - const char *case2 = argv[2]; - const char *equal_string = argv[3]; - bool equal; - ecl_sum_type *ecl_sum1 = ecl_sum_fread_alloc_case(case1, ":"); - ecl_sum_type *ecl_sum2 = ecl_sum_fread_alloc_case(case2, ":"); - - test_assert_true(ecl_sum_is_instance(ecl_sum1)); - test_assert_true(ecl_sum_is_instance(ecl_sum2)); - test_assert_true(ecl_sum_report_step_equal(ecl_sum1, ecl_sum1)); - test_assert_true(util_sscanf_bool(equal_string, &equal)); - - test_assert_true(ecl_sum_report_step_equal(ecl_sum1, ecl_sum1)); - test_assert_true(ecl_sum_report_step_equal(ecl_sum2, ecl_sum2)); - test_assert_bool_equal(equal, - ecl_sum_report_step_equal(ecl_sum1, ecl_sum2)); - - ecl_sum_free(ecl_sum1); - ecl_sum_free(ecl_sum2); - exit(0); -} diff --git a/lib/ecl/tests/ecl_sum_test.cpp b/lib/ecl/tests/ecl_sum_test.cpp deleted file mode 100644 index 824263b49f..0000000000 --- a/lib/ecl/tests/ecl_sum_test.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -void test_time_range(const ecl_sum_type *ecl_sum) { - // Hardcoded Gurbat case values - time_t start = ecl_util_make_date(1, 1, 2000); - time_t end = ecl_util_make_date(31, 12, 2004); - - test_assert_time_t_equal(ecl_sum_get_start_time(ecl_sum), start); - test_assert_time_t_equal(ecl_sum_get_end_time(ecl_sum), end); - test_assert_time_t_equal(ecl_sum_get_data_start(ecl_sum), start); -} - -void test_days(const ecl_sum_type *ecl_sum) { - time_t date1 = ecl_util_make_date(1, 1, 2000); - time_t date2 = ecl_util_make_date(31, 12, 2004); - time_t date3 = ecl_util_make_date(2, 1, 2000); - - double days1 = ecl_sum_time2days(ecl_sum, date1); - double days2 = ecl_sum_time2days(ecl_sum, date2); - double days3 = ecl_sum_time2days(ecl_sum, date3); - - test_assert_double_equal(days1, 0); - test_assert_double_equal(days2, 1826); - test_assert_double_equal(days3, 1); -} - -void test_is_oil_producer(const ecl_sum_type *ecl_sum) { - test_assert_true(ecl_sum_is_oil_producer(ecl_sum, "OP_1")); - test_assert_false(ecl_sum_is_oil_producer(ecl_sum, "WI_1")); - test_assert_false(ecl_sum_is_oil_producer(ecl_sum, "DoesNotExist")); -} - -int main(int argc, char **argv) { - const char *case1 = argv[1]; - - ecl_sum_type *ecl_sum1 = ecl_sum_fread_alloc_case(case1, ":"); - - test_assert_true(ecl_sum_is_instance(ecl_sum1)); - test_time_range(ecl_sum1); - test_days(ecl_sum1); - test_is_oil_producer(ecl_sum1); - ecl_sum_free(ecl_sum1); - exit(0); -} diff --git a/lib/ecl/tests/ecl_sum_writer.cpp b/lib/ecl/tests/ecl_sum_writer.cpp deleted file mode 100644 index fb4f1ccc10..0000000000 --- a/lib/ecl/tests/ecl_sum_writer.cpp +++ /dev/null @@ -1,246 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -double write_summary(const char *name, time_t start_time, int nx, int ny, - int nz, int num_dates, int num_ministep, - double ministep_length) { - ecl_sum_type *ecl_sum = ecl_sum_alloc_writer(name, false, true, ":", - start_time, true, nx, ny, nz); - double sim_seconds = 0; - ecl_smspec_type *smspec = ecl_sum_get_smspec(ecl_sum); - - test_assert_int_equal(ecl_smspec_get_params_size(smspec), 1); - const ecl::smspec_node *node1 = - ecl_smspec_add_node(smspec, "FOPT", "Barrels", 99.0); - const ecl::smspec_node *node2 = - ecl_smspec_add_node(smspec, "BPR", 567, "BARS", 0.0); - const ecl::smspec_node *node3 = - ecl_smspec_add_node(smspec, "WWCT", "OP-1", "(1)", 0.0); - test_assert_int_equal(ecl_smspec_get_params_size(smspec), 4); - - for (int report_step = 0; report_step < num_dates; report_step++) { - for (int step = 0; step < num_ministep; step++) { - /* Simulate .... */ - - { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node2, 10 * sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node3, 100 * sim_seconds); - - test_assert_double_equal( - ecl_sum_tstep_get_from_node(tstep, *node1), sim_seconds); - test_assert_double_equal( - ecl_sum_tstep_get_from_node(tstep, *node2), - sim_seconds * 10); - test_assert_double_equal( - ecl_sum_tstep_get_from_node(tstep, *node3), - sim_seconds * 100); - } - sim_seconds += ministep_length; - } - } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); - return sim_seconds; -} - -int write_restart_summary(const char *name, const char *restart_name, - int start_report_step, double sim_seconds, - time_t start_time, int nx, int ny, int nz, - int num_dates, int num_ministep, - double ministep_length) { - ecl_sum_type *ecl_sum = ecl_sum_alloc_restart_writer( - name, restart_name, false, true, ":", start_time, true, nx, ny, nz); - ecl_smspec_type *smspec = ecl_sum_get_smspec(ecl_sum); - - const ecl::smspec_node *node1 = - ecl_smspec_add_node(smspec, "FOPT", "Barrels", 99.0); - const ecl::smspec_node *node2 = - ecl_smspec_add_node(smspec, "BPR", 567, "BARS", 0.0); - const ecl::smspec_node *node3 = - ecl_smspec_add_node(smspec, "WWCT", "OP-1", "(1)", 0.0); - - int num_report_steps = start_report_step + num_dates; - for (int report_step = start_report_step; report_step < num_report_steps; - report_step++) { - for (int step = 0; step < num_ministep; step++) { - { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node2, 10 * sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node3, 100 * sim_seconds); - } - sim_seconds += ministep_length; - } - } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); - return sim_seconds; -} - -void test_write_read() { - const char *name = "CASE"; - time_t start_time = util_make_date_utc(1, 1, 2010); - time_t end_time = start_time; - int nx = 10; - int ny = 11; - int nz = 12; - int num_dates = 5; - int num_ministep = 10; - double ministep_length = - 86400; // Seconds - numerical value chosen to avoid rounding problems when converting between seconds and days. - { - ecl::util::TestArea ta("write_read"); - ecl_sum_type *ecl_sum; - - write_summary(name, start_time, nx, ny, nz, num_dates, num_ministep, - ministep_length); - ecl_sum = ecl_sum_fread_alloc_case(name, ":"); - test_assert_true(ecl_sum_is_instance(ecl_sum)); - test_assert_true(ecl_sum_get_start_time(ecl_sum) == start_time); - - /* Time direction */ - test_assert_time_t_equal(start_time, ecl_sum_get_start_time(ecl_sum)); - test_assert_time_t_equal(start_time, ecl_sum_get_data_start(ecl_sum)); - util_inplace_forward_seconds_utc( - &end_time, (num_dates * num_ministep - 1) * ministep_length); - test_assert_time_t_equal(end_time, ecl_sum_get_end_time(ecl_sum)); - - /* Keys */ - test_assert_true(ecl_sum_has_key(ecl_sum, "FOPT")); - test_assert_true(ecl_sum_has_key(ecl_sum, "WWCT:OP-1")); - test_assert_true(ecl_sum_has_key(ecl_sum, "BPR:567")); - { - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); - int i, j, k; - char *ijk_key; - ecl_grid_get_ijk1(grid, 567 - 1, &i, &j, &k); - ijk_key = util_alloc_sprintf("BPR:%d,%d,%d", i + 1, j + 1, k + 1); - - free(ijk_key); - ecl_grid_free(grid); - } - - test_assert_throw(ecl_sum_get_general_var(ecl_sum, 1, "NO_SUCH_KEY"), - std::out_of_range); - ecl_sum_free(ecl_sum); - } -} - -void test_ecl_sum_alloc_restart_writer() { - ecl::util::TestArea ta("sum_write_restart"); - { - const char *name1 = "CASE1"; - const char *name2 = "CASE2"; - time_t start_time = util_make_date_utc(1, 1, 2010); - int nx = 10; - int ny = 11; - int nz = 12; - int num_dates = 5; - int num_ministep = 10; - double ministep_length = 36000; // Seconds - - int sim_seconds = - write_summary(name1, start_time, nx, ny, nz, num_dates, - num_ministep, ministep_length); - sim_seconds = write_restart_summary( - name2, name1, num_dates, sim_seconds, start_time, nx, ny, nz, - num_dates, num_ministep, ministep_length); - - ecl_sum_type *case1 = ecl_sum_fread_alloc_case(name1, ":"); - ecl_sum_type *case2 = ecl_sum_fread_alloc_case(name2, ":"); - test_assert_true(ecl_sum_is_instance(case2)); - - test_assert_true(ecl_sum_has_key(case2, "FOPT")); - - ecl_file_type *restart_file = ecl_file_open("CASE2.SMSPEC", 0); - ecl_file_view_type *view_file = ecl_file_get_global_view(restart_file); - test_assert_true(ecl_file_view_has_kw(view_file, RESTART_KW)); - ecl_kw_type *restart_kw = - ecl_file_view_iget_named_kw(view_file, "RESTART", 0); - test_assert_int_equal(8, ecl_kw_get_size(restart_kw)); - test_assert_string_equal("CASE1 ", - (const char *)ecl_kw_iget_ptr(restart_kw, 0)); - test_assert_string_equal(" ", - (const char *)ecl_kw_iget_ptr(restart_kw, 1)); - - for (int time_index = 0; time_index < ecl_sum_get_data_length(case1); - time_index++) - test_assert_double_equal( - ecl_sum_get_general_var(case1, time_index, "FOPT"), - ecl_sum_get_general_var(case2, time_index, "FOPT")); - - ecl_sum_free(case2); - ecl_sum_free(case1); - ecl_file_close(restart_file); - } -} - -void test_long_restart_names() { - char restart_case[65] = {0}; - for (int n = 0; n < 8; n++) { - char s[9]; - sprintf(s, "WWWWGGG%d", n); - strcat(restart_case, s); - } - const char *name = "THE_CASE"; - ecl::util::TestArea ta("suM_write_restart_long_name"); - { - int restart_step = 77; - time_t start_time = util_make_date_utc(1, 1, 2010); - ecl_sum_type *ecl_sum = ecl_sum_alloc_restart_writer2( - name, restart_case, restart_step, false, true, ":", start_time, - true, 3, 3, 3); - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); - - ecl_file_type *smspec_file = ecl_file_open("THE_CASE.SMSPEC", 0); - ecl_file_view_type *view_file = ecl_file_get_global_view(smspec_file); - test_assert_true(ecl_file_view_has_kw(view_file, RESTART_KW)); - ecl_kw_type *restart_kw = - ecl_file_view_iget_named_kw(view_file, "RESTART", 0); - test_assert_int_equal(8, ecl_kw_get_size(restart_kw)); - - for (int n = 0; n < 8; n++) { - char s[9]; - sprintf(s, "WWWWGGG%d", n); - test_assert_string_equal(s, ecl_kw_iget_char_ptr(restart_kw, n)); - } - ecl_file_close(smspec_file); - { - ecl_smspec_type *smspec = ecl_smspec_alloc_restart_writer( - ":", - "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ" - "KLMNOPQRSTUVWXYZ", - 10, start_time, true, 3, 3, 3); - /* - Restart case is too long - it is ignored. - */ - test_assert_NULL(ecl_smspec_get_restart_case(smspec)); - ecl_smspec_free(smspec); - } - } -} - -int main(int argc, char **argv) { - util_install_signals(); - test_write_read(); - test_ecl_sum_alloc_restart_writer(); - test_long_restart_names(); - exit(0); -} diff --git a/lib/ecl/tests/ecl_unsmry_loader_test.cpp b/lib/ecl/tests/ecl_unsmry_loader_test.cpp deleted file mode 100644 index 88b7a75f2e..0000000000 --- a/lib/ecl/tests/ecl_unsmry_loader_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include - -#include -#include - -#include - -#include "detail/ecl/ecl_unsmry_loader.hpp" - -ecl_sum_type *write_ecl_sum() { - time_t start_time = util_make_date_utc(1, 1, 2010); - ecl_sum_type *ecl_sum = ecl_sum_alloc_writer("CASE", false, true, ":", - start_time, true, 10, 10, 10); - double sim_seconds = 0; - - int num_dates = 4; - double ministep_length = 86400; // seconds in a day - - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "FOPT", NULL, 0, "Barrels", 99.0); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 567, "BARS", 0.0); - const ecl::smspec_node *node3 = - ecl_sum_add_var(ecl_sum, "WWCT", "OP-1", 0, "(1)", 0.0); - - for (int report_step = 0; report_step < num_dates; report_step++) { - { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, report_step * 2.0); - ecl_sum_tstep_set_from_node(tstep, *node2, report_step * 4.0 + 2.0); - ecl_sum_tstep_set_from_node(tstep, *node3, report_step * 6.0 + 4.0); - } - sim_seconds += ministep_length * 3; - } - ecl_sum_fwrite(ecl_sum); - return ecl_sum; -} - -void test_load() { - ecl::util::TestArea ta("ecl_sum_loader"); - ecl_sum_type *ecl_sum = write_ecl_sum(); - test_assert_true(util_file_exists("CASE.SMSPEC")); - test_assert_true(util_file_exists("CASE.UNSMRY")); - ecl::unsmry_loader *loader = - new ecl::unsmry_loader(ecl_sum_get_smspec(ecl_sum), "CASE.UNSMRY", 0); - - const std::vector FOPT_value = loader->get_vector(1); - const std::vector BPR_value = loader->get_vector(2); - const std::vector WWCT_value = loader->get_vector(3); - test_assert_int_equal(FOPT_value.size(), 4); - test_assert_double_equal(FOPT_value[3], 6.0); - test_assert_double_equal(BPR_value[2], 10.0); - test_assert_double_equal(WWCT_value[1], 10.0); - - delete loader; - ecl_sum_free(ecl_sum); -} - -int main() { - test_load(); - return 0; -} diff --git a/lib/ecl/tests/ecl_util_path_access.cpp b/lib/ecl/tests/ecl_util_path_access.cpp deleted file mode 100644 index 1bb8882f5b..0000000000 --- a/lib/ecl/tests/ecl_util_path_access.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -#include - -void test_relative_access() { - ecl::util::TestArea ta("ecl_access"); - test_assert_false(ecl_util_path_access("No/directory/does/not/exist")); - - util_make_path("path"); - test_assert_true(ecl_util_path_access("path")); - test_assert_true(ecl_util_path_access("path/FILE_DOES_NOT_EXIST")); - - { - FILE *f = util_fopen("path/file", "w"); - fprintf(f, "Hello\n"); - fclose(f); - } - test_assert_true(ecl_util_path_access("path/file")); - chmod("path/file", 0); - test_assert_false(ecl_util_path_access("path/file")); - - test_assert_true(ecl_util_path_access("ECLIPSE_CASE")); -} - -int main(int argc, char **argv) { test_relative_access(); } diff --git a/lib/ecl/tests/ecl_valid_basename.cpp b/lib/ecl/tests/ecl_valid_basename.cpp deleted file mode 100644 index 7c8823a9b3..0000000000 --- a/lib/ecl/tests/ecl_valid_basename.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int main(int argc, char **argv) { - test_assert_true(ecl_util_valid_basename_fmt("ecl_%d.data")); - test_assert_true(ecl_util_valid_basename_fmt("ECL_%d.DATA")); - test_assert_true(ecl_util_valid_basename_fmt("ECL_%04d.DATA")); - test_assert_true(ecl_util_valid_basename_fmt("mypath/ECL_%04d.DATA")); - test_assert_true(ecl_util_valid_basename_fmt("MYPATH/ECL_%04d.DATA")); - test_assert_true(ecl_util_valid_basename_fmt("MYPATH/ECL_%04d.DATA")); - test_assert_true(ecl_util_valid_basename_fmt("ECL_%d.dATA")); - test_assert_false(ecl_util_valid_basename_fmt("ECL_%s.DATA")); - test_assert_false(ecl_util_valid_basename_fmt("ECL_%f.DATA")); - test_assert_true(ecl_util_valid_basename_fmt("mypath/ECL_%d.dATA")); - - exit(0); -} diff --git a/lib/ecl/tests/eclxx_filename.cpp b/lib/ecl/tests/eclxx_filename.cpp deleted file mode 100644 index 03d431c5f6..0000000000 --- a/lib/ecl/tests/eclxx_filename.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -void cmp(const char *expected, const std::string &value) { - test_assert_string_equal(expected, value.c_str()); -} - -int main(int argc, char **argv) { - cmp("BASE.X0067", ERT::EclFilename("BASE", ECL_RESTART_FILE, 67)); - cmp("BASE.F0067", ERT::EclFilename("BASE", ECL_RESTART_FILE, 67, true)); - - cmp("BASE.EGRID", ERT::EclFilename("BASE", ECL_EGRID_FILE)); - cmp("BASE.FEGRID", ERT::EclFilename("BASE", ECL_EGRID_FILE, true)); - - cmp("BASE.EGRID", ERT::EclFilename("BASE", ECL_EGRID_FILE, 67)); - cmp("BASE.FEGRID", ERT::EclFilename("BASE", ECL_EGRID_FILE, 67, true)); - - try { - ERT::EclFilename("BASE", ECL_RESTART_FILE); - test_assert_true(false); - } catch (...) { - test_assert_true(true); - } - - cmp("PATH/BASE.X0067", - ERT::EclFilename("PATH", "BASE", ECL_RESTART_FILE, 67)); - cmp("PATH/BASE.F0067", - ERT::EclFilename("PATH", "BASE", ECL_RESTART_FILE, 67, true)); - - cmp("PATH/BASE.EGRID", ERT::EclFilename("PATH", "BASE", ECL_EGRID_FILE)); - cmp("PATH/BASE.FEGRID", - ERT::EclFilename("PATH", "BASE", ECL_EGRID_FILE, true)); - - cmp("PATH/BASE.EGRID", - ERT::EclFilename("PATH", "BASE", ECL_EGRID_FILE, 67)); - cmp("PATH/BASE.FEGRID", - ERT::EclFilename("PATH", "BASE", ECL_EGRID_FILE, 67, true)); - - try { - ERT::EclFilename("PATH", "BASE", ECL_RESTART_FILE); - test_assert_true(false); - } catch (...) { - test_assert_true(true); - } - - test_assert_int_equal(ECL_EGRID_FILE, ERT::EclFiletype("CASE.EGRID")); - test_assert_int_equal(ECL_RESTART_FILE, ERT::EclFiletype("CASE.F0098")); - test_assert_int_equal(ECL_UNIFIED_RESTART_FILE, - ERT::EclFiletype("CASE.UNRST")); -} diff --git a/lib/ecl/tests/eclxx_types.cpp b/lib/ecl/tests/eclxx_types.cpp deleted file mode 100644 index ebaa369b71..0000000000 --- a/lib/ecl/tests/eclxx_types.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -#include -#include -#include - -void test_ECL_INT() { - ecl_data_type dt = ECL_INT; - test_assert_int_equal(dt.element_size, sizeof(int)); - test_assert_int_equal(dt.type, ECL_INT_TYPE); -} - -void test_ECL_FLOAT() { - ecl_data_type dt = ECL_FLOAT; - test_assert_int_equal(dt.element_size, sizeof(float)); - test_assert_int_equal(dt.type, ECL_FLOAT_TYPE); -} - -void test_ECL_DOUBLE() { - ecl_data_type dt = ECL_DOUBLE; - test_assert_int_equal(dt.element_size, sizeof(double)); - test_assert_int_equal(dt.type, ECL_DOUBLE_TYPE); -} - -void test_ECL_CHAR() { - ecl_data_type dt = ECL_CHAR; - test_assert_int_equal(dt.element_size, ECL_STRING8_LENGTH + 1); - test_assert_int_equal(dt.type, ECL_CHAR_TYPE); -} - -int main(int argc, char **argv) { - test_ECL_INT(); - test_ECL_FLOAT(); - test_ECL_DOUBLE(); - test_ECL_CHAR(); -} diff --git a/lib/ecl/tests/test_ecl_file_index.cpp b/lib/ecl/tests/test_ecl_file_index.cpp deleted file mode 100644 index e8bdc82be5..0000000000 --- a/lib/ecl/tests/test_ecl_file_index.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include - -#include -#include -#include - -#include -#include - -void test_load_nonexisting_file() { - ecl_file_type *ecl_file = ecl_file_fast_open( - "base_file", "a_file_that_does_not_exist_2384623", 0); - test_assert_NULL(ecl_file); -} - -void test_create_and_load_index_file() { - - ecl::util::TestArea ta("Load_index"); - { - const char *file_name = "initial_data_file"; - const char *index_file_name = "index_file"; - - //creating the data file - int data_size = 10; - ecl_kw_type *kw1 = ecl_kw_alloc("TEST1_KW", data_size, ECL_INT); - for (int i = 0; i < data_size; ++i) - ecl_kw_iset_int(kw1, i, 537 + i); - fortio_type *fortio = - fortio_open_writer(file_name, false, ECL_ENDIAN_FLIP); - ecl_kw_fwrite(kw1, fortio); - - data_size = 5; - ecl_kw_type *kw2 = ecl_kw_alloc("TEST2_KW", data_size, ECL_FLOAT); - for (int i = 0; i < data_size; ++i) - ecl_kw_iset_float(kw2, i, 0.15 * i); - ecl_kw_fwrite(kw2, fortio); - fortio_fclose(fortio); - //finished creating data file - - //creating ecl_file - ecl_file_type *ecl_file = ecl_file_open(file_name, 0); - test_assert_true(ecl_file_has_kw(ecl_file, "TEST1_KW")); - ecl_file_write_index(ecl_file, index_file_name); - int ecl_file_size = ecl_file_get_size(ecl_file); - ecl_file_close(ecl_file); - //finished using ecl_file - - test_assert_false(ecl_file_index_valid(file_name, "nofile")); - test_assert_false(ecl_file_index_valid("nofile", index_file_name)); - - struct utimbuf tm1 = {1, 1}; - struct utimbuf tm2 = {2, 2}; - utime(file_name, &tm2); - utime(index_file_name, &tm1); - test_assert_false(ecl_file_index_valid(file_name, index_file_name)); - utime(file_name, &tm1); - utime(index_file_name, &tm2); - test_assert_true(ecl_file_index_valid(file_name, index_file_name)); - - ecl_file_type *ecl_file_index = - ecl_file_fast_open(file_name, index_file_name, 0); - test_assert_true(ecl_file_is_instance(ecl_file_index)); - test_assert_true(ecl_file_get_global_view(ecl_file_index)); - - test_assert_int_equal(ecl_file_size, ecl_file_get_size(ecl_file_index)); - - test_assert_true(ecl_file_has_kw(ecl_file_index, "TEST1_KW")); - test_assert_true(ecl_file_has_kw(ecl_file_index, "TEST2_KW")); - - ecl_kw_type *kwi1 = ecl_file_iget_kw(ecl_file_index, 0); - test_assert_true(ecl_kw_equal(kw1, kwi1)); - test_assert_double_equal(537.0, ecl_kw_iget_as_double(kwi1, 0)); - test_assert_double_equal(546.0, ecl_kw_iget_as_double(kwi1, 9)); - - ecl_kw_type *kwi2 = ecl_file_iget_kw(ecl_file_index, 1); - test_assert_true(ecl_kw_equal(kw2, kwi2)); - test_assert_double_equal(0.15, ecl_kw_iget_as_double(kwi2, 1)); - test_assert_double_equal(0.60, ecl_kw_iget_as_double(kwi2, 4)); - - ecl_kw_free(kw1); - ecl_kw_free(kw2); - ecl_file_close(ecl_file_index); - } -} - -int main(int argc, char **argv) { - util_install_signals(); - test_load_nonexisting_file(); - test_create_and_load_index_file(); -} diff --git a/lib/ecl/tests/test_ecl_nnc_data.cpp b/lib/ecl/tests/test_ecl_nnc_data.cpp deleted file mode 100644 index 5be67eb1c1..0000000000 --- a/lib/ecl/tests/test_ecl_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) { - ecl::util::TestArea ta("nnc-INIT"); - { - int nx = 10; - int ny = 10; - int nz = 10; - ecl_grid_type *grid0 = - ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); - - ecl_grid_add_self_nnc(grid0, 0, nx * ny + 0, 0); - ecl_grid_add_self_nnc(grid0, 1, nx * ny + 1, 1); - ecl_grid_add_self_nnc(grid0, 2, nx * ny + 2, 2); - { - ecl_nnc_geometry_type *nnc_geo = ecl_nnc_geometry_alloc(grid0); - test_assert_int_equal(ecl_nnc_geometry_size(nnc_geo), 3); - /* - Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size. - */ - { - ecl_kw_type *trann_nnc = ecl_kw_alloc( - TRANNNC_KW, ecl_nnc_geometry_size(nnc_geo), ECL_FLOAT); - fortio_type *f = - fortio_open_writer("TEST.INIT", false, ECL_ENDIAN_FLIP); - - if (data_in_file) { - for (int i = 0; i < ecl_kw_get_size(trann_nnc); i++) - ecl_kw_iset_float(trann_nnc, i, i * 1.5); - - ecl_kw_fwrite(trann_nnc, f); - } - fortio_fclose(f); - ecl_kw_free(trann_nnc); - } - - ecl_file_type *init_file = ecl_file_open("TEST.INIT", 0); - ecl_file_view_type *view_file = ecl_file_get_global_view(init_file); - - ecl_nnc_data_type *nnc_geo_data = - ecl_nnc_data_alloc_tran(grid0, nnc_geo, view_file); - - if (data_in_file) { - - int nnc_data_size = ecl_nnc_data_get_size(nnc_geo_data); - test_assert_true(ecl_file_view_has_kw(view_file, TRANNNC_KW)); - test_assert_true(nnc_data_size == 3); - const double *values = ecl_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) - ecl_nnc_data_free(nnc_geo_data); - ecl_nnc_geometry_free(nnc_geo); - ecl_file_close(init_file); - } - ecl_grid_free(grid0); - } -} - -int main(int argc, char **argv) { - - test_alloc_global_only(true); - test_alloc_global_only(false); - - return 0; -} diff --git a/lib/ecl/tests/test_transactions.cpp b/lib/ecl/tests/test_transactions.cpp deleted file mode 100644 index 181a72e0d6..0000000000 --- a/lib/ecl/tests/test_transactions.cpp +++ /dev/null @@ -1,97 +0,0 @@ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -/* - This test is slightly awkward beacuse it tests quite internal implementation details. -*/ - -void test_transaction() { - - ecl::util::TestArea ta("index_testing"); - { - const char *file_name = "data_file"; - fortio_type *fortio = - fortio_open_writer(file_name, false, ECL_ENDIAN_FLIP); - - //creating the data file - int data_size = 10; - ecl_kw_type *kw1 = ecl_kw_alloc("TEST1_KW", data_size, ECL_INT); - for (int i = 0; i < data_size; ++i) - ecl_kw_iset_int(kw1, i, 537 + i); - ecl_kw_fwrite(kw1, fortio); - - data_size = 5; - ecl_kw_type *kw2 = ecl_kw_alloc("TEST2_KW", data_size, ECL_FLOAT); - for (int i = 0; i < data_size; ++i) - ecl_kw_iset_float(kw2, i, 0.15 * i); - ecl_kw_fwrite(kw2, fortio); - - data_size = 3; - ecl_kw_type *kw3 = ecl_kw_alloc("TEST3_KW", data_size, ECL_FLOAT); - for (int i = 0; i < data_size; i++) - ecl_kw_iset_float(kw3, i, 0.45 * i); - ecl_kw_fwrite(kw3, fortio); - - fortio_fclose(fortio); - //finished creating data file - - ecl_file_type *file = ecl_file_open(file_name, 0); - ecl_file_view_type *file_view = ecl_file_get_global_view(file); - ecl_file_kw_type *file_kw0 = ecl_file_view_iget_file_kw(file_view, 0); - ecl_file_kw_type *file_kw1 = ecl_file_view_iget_file_kw(file_view, 1); - ecl_file_kw_type *file_kw2 = ecl_file_view_iget_file_kw(file_view, 2); - - ecl_file_view_iget_kw(file_view, 0); - test_assert_true(ecl_file_kw_get_kw_ptr(file_kw0)); - test_assert_false(ecl_file_kw_get_kw_ptr(file_kw1)); - test_assert_false(ecl_file_kw_get_kw_ptr(file_kw2)); - ecl_file_transaction_type *t1 = - ecl_file_view_start_transaction(file_view); - - ecl_file_view_iget_kw(file_view, 0); - ecl_file_view_iget_kw(file_view, 1); - ecl_file_transaction_type *t2 = - ecl_file_view_start_transaction(file_view); - - ecl_file_view_iget_kw(file_view, 0); - ecl_file_view_iget_kw(file_view, 1); - ecl_file_view_iget_kw(file_view, 1); - ecl_file_view_iget_kw(file_view, 2); - - ecl_file_view_end_transaction(file_view, t2); - - test_assert_true(ecl_file_kw_get_kw_ptr(file_kw0)); - test_assert_true(ecl_file_kw_get_kw_ptr(file_kw1)); - test_assert_false(ecl_file_kw_get_kw_ptr(file_kw2)); - ecl_file_view_iget_kw(file_view, 2); - - ecl_file_view_end_transaction(file_view, t1); - test_assert_true(ecl_file_kw_get_kw_ptr(file_kw0)); - test_assert_false(ecl_file_kw_get_kw_ptr(file_kw1)); - test_assert_false(ecl_file_kw_get_kw_ptr(file_kw2)); - - ecl_file_close(file); - ecl_kw_free(kw1); - ecl_kw_free(kw2); - ecl_kw_free(kw3); - } -} - -int main(int argc, char **argv) { - util_install_signals(); - test_transaction(); - exit(0); -} diff --git a/lib/include/ert/ecl/EclFilename.hpp b/lib/include/ert/ecl/EclFilename.hpp deleted file mode 100644 index 6dd8c0a98d..0000000000 --- a/lib/include/ert/ecl/EclFilename.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ERT_ECL_FILEMAME_HPP -#define ERT_ECL_FILEMAME_HPP -#include - -#include - -namespace ERT { -std::string EclFilename(const std::string &base, ecl_file_enum file_type, - int report_step, bool fmt_file = false); -std::string EclFilename(const std::string &base, ecl_file_enum file_type, - bool fmt_file = false); - -std::string EclFilename(const std::string &path, const std::string &base, - ecl_file_enum file_type, int report_step, - bool fmt_file = false); -std::string EclFilename(const std::string &path, const std::string &base, - ecl_file_enum file_type, bool fmt_file = false); - -ecl_file_enum EclFiletype(const std::string &filename); -} // namespace ERT -#endif diff --git a/lib/include/ert/ecl/EclKW.hpp b/lib/include/ert/ecl/EclKW.hpp deleted file mode 100644 index a9d035501c..0000000000 --- a/lib/include/ert/ecl/EclKW.hpp +++ /dev/null @@ -1,241 +0,0 @@ -#ifndef OPM_ERT_ECL_KW -#define OPM_ERT_ECL_KW - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace ERT { -template struct ecl_type {}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_FLOAT_TYPE}; -}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_DOUBLE_TYPE}; -}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_INT_TYPE}; -}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_BOOL_TYPE}; -}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_CHAR_TYPE}; -}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_CHAR_TYPE}; -}; - -/* - Both std::string and char* are mapped to the eight character string type - ECL_CHAR_TYPE. That implies that the variable length string type - ECL_STRING is invisible from this API. - */ - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_CHAR_TYPE}; -}; - -template <> struct ecl_type { - static const ecl_type_enum type{ECL_CHAR_TYPE}; -}; - -template class EclKW_ref { -public: - explicit EclKW_ref(ecl_kw_type *kw) : m_kw(kw) { - if (ecl_type_get_type(ecl_kw_get_data_type(kw)) != ecl_type::type) - throw std::invalid_argument("Type error"); - } - - EclKW_ref() noexcept = default; - - const char *name() const { return ecl_kw_get_header(this->m_kw); } - - size_t size() const { return size_t(ecl_kw_get_size(this->m_kw)); } - - void fwrite(FortIO &fortio) const { - ecl_kw_fwrite(this->m_kw, fortio.get()); - } - - T at(size_t i) const { - return *static_cast(ecl_kw_iget_ptr(this->m_kw, i)); - } - - T &operator[](size_t i) { - return *static_cast(ecl_kw_iget_ptr(this->m_kw, i)); - } - - const typename std::remove_pointer::type *data() const { - using Tp = const typename std::remove_pointer::type *; - return static_cast(ecl_kw_get_ptr(this->m_kw)); - } - - ecl_kw_type *get() const { return this->m_kw; } - - void resize(size_t new_size) { ecl_kw_resize(this->m_kw, new_size); } - -protected: - ecl_kw_type *m_kw = nullptr; -}; - -template <> inline bool EclKW_ref::at(size_t i) const { - return ecl_kw_iget_bool(this->m_kw, i); -} - -template <> inline const char *EclKW_ref::at(size_t i) const { - return ecl_kw_iget_char_ptr(this->m_kw, i); -} - -template <> inline std::string EclKW_ref::at(size_t i) const { - return ecl_kw_iget_char_ptr(this->m_kw, i); -} - -/* - The current implementation of "string" and "bool" storage in the underlying C - ecl_kw structure does not lend itself to easily implement operator[]. We have - therefore explicitly deleted them here. -*/ - -template <> const char *&EclKW_ref::operator[](size_t i) = delete; - -template <> bool &EclKW_ref::operator[](size_t i) = delete; - -template class EclKW : public EclKW_ref { -private: - using base = EclKW_ref; - -public: - using EclKW_ref::EclKW_ref; - - EclKW(const EclKW &) = delete; - EclKW(EclKW &&rhs) : base(rhs.m_kw) { rhs.m_kw = nullptr; } - - ~EclKW() { - if (this->m_kw) - ecl_kw_free(this->m_kw); - } - - EclKW(const std::string &kw, int size_) - : base(ecl_kw_alloc(kw.c_str(), size_, - ecl_type_create_from_type(ecl_type::type))) {} - - EclKW(const std::string &kw, const std::vector &data) - : EclKW(kw, data.size()) { - ecl_kw_set_memcpy_data(this->m_kw, data.data()); - } - - template - EclKW(const std::string &kw, const std::vector &data) - : EclKW(kw, data.size()) { - T *target = static_cast(ecl_kw_get_ptr(this->m_kw)); - - for (size_t i = 0; i < data.size(); ++i) - target[i] = T(data[i]); - } - - std::vector data() const { - const T *ptr = static_cast(ecl_kw_get_ptr(this->m_kw)); - std::vector vector; - vector.assign(ptr, ptr + this->size()); - return vector; - } - - static EclKW load(FortIO &fortio) { - ecl_kw_type *c_ptr = ecl_kw_fread_alloc(fortio.get()); - - if (!c_ptr) - throw std::invalid_argument("fread kw failed - EOF?"); - - return EclKW(c_ptr); - } -}; - -template <> -inline EclKW::EclKW(const std::string &kw, - const std::vector &data) - : EclKW(kw, data.size()) { - auto *ptr = this->get(); - for (size_t i = 0; i < data.size(); ++i) { - if (strlen(data[i]) > 8) - throw std::range_error("Strings must be maximum 8 characters long"); - ecl_kw_iset_string8(ptr, i, data[i]); - } -} - -template <> -inline EclKW::EclKW(const std::string &kw, - const std::vector &data) - : EclKW(kw, data.size()) { - auto *ptr = this->get(); - for (size_t i = 0; i < data.size(); ++i) { - if (data[i].size() > 8) - throw std::range_error("Strings must be maximum 8 characters long"); - ecl_kw_iset_string8(ptr, i, data[i].c_str()); - } -} - -template <> -template <> -inline EclKW::EclKW(const std::string &kw, - const std::vector &data) - : EclKW(kw, data.size()) { - auto *ptr = this->get(); - for (size_t i = 0; i < data.size(); ++i) { - if (strlen(data[i]) > 8) - throw std::range_error("Strings must be maximum 8 characters long"); - ecl_kw_iset_string8(ptr, i, data[i]); - } -} - -template <> -inline EclKW::EclKW(const std::string &kw, const std::vector &data) - : EclKW(kw, data.size()) { - for (size_t i = 0; i < data.size(); i++) - ecl_kw_iset_bool(this->m_kw, i, data[i]); -} - -template <> inline std::vector EclKW::data() const { - std::vector strings; - auto *ptr = this->get(); - for (size_t i = 0; i < this->size(); ++i) { - std::string s8 = ecl_kw_iget_char_ptr(ptr, i); - s8.erase(s8.find_last_not_of(' ') + 1); - strings.push_back(s8); - } - return strings; -} - -/* - Will write an ecl_kw instance to the open Fortio file. -*/ -template -void write_kw(FortIO &fortio, const std::string &kw, - const std::vector &data) { - EclKW ecl_kw(kw, data); - ecl_kw_fwrite(ecl_kw.get(), fortio.get()); -} - -/* - Will write an empty ecl_kw instance of type 'MESS' to the Fortio file. -*/ -inline void write_mess(FortIO &fortio, const std::string &kw) { - ecl_kw_type *ecl_kw = ecl_kw_alloc(kw.c_str(), 0, ECL_MESS); - ecl_kw_fwrite(ecl_kw, fortio.get()); -} - -} // namespace ERT - -#endif diff --git a/lib/include/ert/ecl/ecl_box.hpp b/lib/include/ert/ecl/ecl_box.hpp deleted file mode 100644 index 7ad7b145fd..0000000000 --- a/lib/include/ert/ecl/ecl_box.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ERT_ECL_BOX_H -#define ERT_ECL_BOX_H - -#include -#include - -namespace ecl { - -class ecl_box { -public: - ecl_box(const ecl_grid_type *grid, int i1, int i2, int j1, int j2, int k1, - int k2); - const std::vector &active_list() const; - -private: - const ecl_grid_type *grid; - - int i1, i2, j1, j2, k1, k2; - std::vector active_index_list; - std::vector global_index_list; -}; - -} // namespace ecl -#endif diff --git a/lib/include/ert/ecl/ecl_coarse_cell.hpp b/lib/include/ert/ecl/ecl_coarse_cell.hpp deleted file mode 100644 index 9f31f22d9e..0000000000 --- a/lib/include/ert/ecl/ecl_coarse_cell.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef ERT_ECL_COARSE_CELL_H -#define ERT_ECL_COARSE_CELL_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_coarse_cell_struct ecl_coarse_cell_type; - -bool ecl_coarse_cell_equal(const ecl_coarse_cell_type *coarse_cell1, - const ecl_coarse_cell_type *coarse_cell2); -ecl_coarse_cell_type *ecl_coarse_cell_alloc(void); -void ecl_coarse_cell_update(ecl_coarse_cell_type *coarse_cell, int i, int j, - int k, int global_index); -void ecl_coarse_cell_free(ecl_coarse_cell_type *coarse_cell); -void ecl_coarse_cell_free__(void *arg); - -int ecl_coarse_cell_get_i1(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_get_j1(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_get_k1(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_get_i2(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_get_j2(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_get_k2(const ecl_coarse_cell_type *coarse_cell); -const int *ecl_coarse_cell_get_box_ptr(const ecl_coarse_cell_type *coarse_cell); - -int ecl_coarse_cell_get_size(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_iget_cell_index(ecl_coarse_cell_type *coarse_cell, - int group_index); -const int *ecl_coarse_cell_get_index_ptr(ecl_coarse_cell_type *coarse_cell); -const int_vector_type * -ecl_coarse_cell_get_index_vector(ecl_coarse_cell_type *coarse_cell); - -void ecl_coarse_cell_reset_active_index(ecl_coarse_cell_type *coarse_cell); -void ecl_coarse_cell_update_index(ecl_coarse_cell_type *coarse_cell, - int global_index, int *active_index, - int *active_fracture_index, int active_value); -int ecl_coarse_cell_get_active_index(const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_get_active_fracture_index( - const ecl_coarse_cell_type *coarse_cell); -int ecl_coarse_cell_iget_active_cell_index( - const ecl_coarse_cell_type *coarse_cell, int index); -int ecl_coarse_cell_iget_active_value(const ecl_coarse_cell_type *coarse_cell, - int index); -int ecl_coarse_cell_get_num_active(const ecl_coarse_cell_type *coarse_cell); -void ecl_coarse_cell_fprintf(const ecl_coarse_cell_type *coarse_cell, - FILE *stream); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_endian_flip.hpp b/lib/include/ert/ecl/ecl_endian_flip.hpp deleted file mode 100644 index 7ea91351c8..0000000000 --- a/lib/include/ert/ecl/ecl_endian_flip.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef ERT_ECL_ENDIAN_FLIP_H -#define ERT_ECL_ENDIAN_FLIP_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/** - This header file checks if the ECLIPSE endianness and the hardware - endianness are equal, and defines the macro ECL_ENDIAN_FLIP - accordingly. - - All the ecl_xxx functions will use the ECL_ENDIAN_FLIP macro to - determine whether the endian flip should be performed. When opening - a fortio instance explicitly you can use the ECL_ENDIAN_FLIP macro - to get the endianness correct (for ECLIPSE usage that is). -*/ - -#define ECLIPSE_BYTE_ORDER __BIG_ENDIAN // Alternatively: __LITTLE_ENDIAN - -#ifdef BYTE_ORDER -#if BYTE_ORDER == ECLIPSE_BYTE_ORDER -#define ECL_ENDIAN_FLIP false -#else -#define ECL_ENDIAN_FLIP true -#endif -#else -#ifdef WIN32 -#define ECL_ENDIAN_FLIP true // Unconditional byte flip on Windows. -#else -#error : The macro BYTE_ORDER is not defined? -#endif -#endif - -#undef ECLIPSE_BYTE_ORDER - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_file.hpp b/lib/include/ert/ecl/ecl_file.hpp deleted file mode 100644 index 686cc06692..0000000000 --- a/lib/include/ert/ecl/ecl_file.hpp +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef ERT_ECL_FILE_H -#define ERT_ECL_FILE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include - -#define ECL_FILE_FLAGS_ENUM_DEFS \ - {.value = 1, .name = "ECL_FILE_CLOSE_STREAM"}, { \ - .value = 2, .name = "ECL_FILE_WRITABLE" \ - } -#define ECL_FILE_FLAGS_ENUM_SIZE 2 - -typedef struct ecl_file_struct ecl_file_type; -bool ecl_file_load_all(ecl_file_type *ecl_file); -ecl_file_type *ecl_file_open(const char *filename, int flags); -ecl_file_type *ecl_file_fast_open(const char *filename, - const char *index_filename, int flags); -bool ecl_file_write_index(const ecl_file_type *ecl_file, - const char *index_filename); -bool ecl_file_index_valid(const char *file_name, const char *index_file_name); -void ecl_file_close(ecl_file_type *ecl_file); -void ecl_file_fortio_detach(ecl_file_type *ecl_file); -void ecl_file_free__(void *arg); -ecl_kw_type *ecl_file_icopy_named_kw(const ecl_file_type *ecl_file, - const char *kw, int ith); -ecl_kw_type *ecl_file_icopy_kw(const ecl_file_type *ecl_file, int index); -bool ecl_file_has_kw(const ecl_file_type *ecl_file, const char *kw); -int ecl_file_get_num_named_kw(const ecl_file_type *ecl_file, const char *kw); -int ecl_file_get_size(const ecl_file_type *ecl_file); -int ecl_file_get_num_distinct_kw(const ecl_file_type *ecl_file); -const char *ecl_file_iget_distinct_kw(const ecl_file_type *ecl_file, int index); -const char *ecl_file_get_src_file(const ecl_file_type *ecl_file); -int ecl_file_iget_occurence(const ecl_file_type *ecl_file, int index); -ecl_version_enum ecl_file_get_ecl_version(const ecl_file_type *file); -void ecl_file_fwrite_fortio(const ecl_file_type *ec_file, fortio_type *fortio, - int offset); -void ecl_file_fwrite(const ecl_file_type *ecl_file, const char *, - bool fmt_file); - -void ecl_file_replace_kw(ecl_file_type *ecl_file, ecl_kw_type *old_kw, - ecl_kw_type *new_kw, bool insert_copy); -int ecl_file_get_phases(const ecl_file_type *init_file); -void ecl_file_fprintf_kw_list(const ecl_file_type *ecl_file, FILE *stream); - -bool ecl_file_writable(const ecl_file_type *ecl_file); -int ecl_file_get_flags(const ecl_file_type *ecl_file); -void ecl_file_set_flags(ecl_file_type *ecl_file, int new_flags); -bool ecl_file_flags_set(const ecl_file_type *ecl_file, int flags); - -ecl_file_kw_type *ecl_file_iget_file_kw(const ecl_file_type *file, - int global_index); -ecl_file_kw_type *ecl_file_iget_named_file_kw(const ecl_file_type *file, - const char *kw, int ith); -ecl_kw_type *ecl_file_iget_kw(const ecl_file_type *file, int global_index); -ecl_data_type ecl_file_iget_data_type(const ecl_file_type *file, - int global_index); -int ecl_file_iget_size(const ecl_file_type *file, int global_index); -const char *ecl_file_iget_header(const ecl_file_type *file, int global_index); -ecl_kw_type *ecl_file_iget_named_kw(const ecl_file_type *file, const char *kw, - int ith); -ecl_data_type ecl_file_iget_named_data_type(const ecl_file_type *file, - const char *kw, int ith); -int ecl_file_iget_named_size(const ecl_file_type *file, const char *kw, - int ith); -void ecl_file_indexed_read(const ecl_file_type *file, const char *kw, int index, - const int_vector_type *index_map, char *buffer); - -ecl_file_view_type *ecl_file_get_global_blockview(ecl_file_type *ecl_file, - const char *kw, - int occurence); -ecl_file_view_type *ecl_file_alloc_global_blockview(ecl_file_type *ecl_file, - const char *kw, - int occurence); -ecl_file_view_type *ecl_file_get_global_view(ecl_file_type *ecl_file); -ecl_file_view_type *ecl_file_get_active_view(ecl_file_type *ecl_file); -//bool ecl_file_writable( const ecl_file_type * ecl_file ); -bool ecl_file_save_kw(const ecl_file_type *ecl_file, const ecl_kw_type *ecl_kw); -bool ecl_file_has_kw_ptr(const ecl_file_type *ecl_file, - const ecl_kw_type *ecl_kw); - -double ecl_file_iget_restart_sim_days(const ecl_file_type *restart_file, - int index); -time_t ecl_file_iget_restart_sim_date(const ecl_file_type *restart_file, - int occurence); -int ecl_file_get_restart_index(const ecl_file_type *restart_file, - time_t sim_time); -bool ecl_file_has_report_step(const ecl_file_type *ecl_file, int report_step); -bool ecl_file_has_sim_time(const ecl_file_type *ecl_file, time_t sim_time); - -void ecl_file_close_fortio_stream(ecl_file_type *ecl_file); - -ecl_file_view_type *ecl_file_get_restart_view(ecl_file_type *ecl_file, - int input_index, int report_step, - time_t sim_time, double sim_days); -ecl_file_view_type *ecl_file_get_summary_view(ecl_file_type *ecl_file, - int report_step); - -UTIL_IS_INSTANCE_HEADER(ecl_file); - -//Deprecated: - -void ecl_file_push_block(ecl_file_type *ecl_file); -void ecl_file_pop_block(ecl_file_type *ecl_file); -bool ecl_file_subselect_block(ecl_file_type *ecl_file, const char *kw, - int occurence); -bool ecl_file_select_block(ecl_file_type *ecl_file, const char *kw, - int occurence); - -bool ecl_file_select_rstblock_sim_time(ecl_file_type *ecl_file, - time_t sim_time); -bool ecl_file_select_rstblock_report_step(ecl_file_type *ecl_file, - int report_step); -bool ecl_file_iselect_rstblock(ecl_file_type *ecl_file, int seqnum_index); -ecl_file_type *ecl_file_open_rstblock_report_step(const char *filename, - int report_step, int flags); -ecl_file_type *ecl_file_open_rstblock_sim_time(const char *filename, - time_t sim_time, int flags); -ecl_file_type *ecl_file_iopen_rstblock(const char *filename, int seqnum_index, - int flags); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_file_kw.hpp b/lib/include/ert/ecl/ecl_file_kw.hpp deleted file mode 100644 index 7d5d86b69c..0000000000 --- a/lib/include/ert/ecl/ecl_file_kw.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef ERT_ECL_FILE_KW_H -#define ERT_ECL_FILE_KW_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -#include -#include - -typedef struct ecl_file_kw_struct ecl_file_kw_type; -typedef struct inv_map_struct inv_map_type; - -inv_map_type *inv_map_alloc(void); -ecl_file_kw_type *inv_map_get_file_kw(inv_map_type *inv_map, - const ecl_kw_type *ecl_kw); -void inv_map_free(inv_map_type *map); -bool ecl_file_kw_equal(const ecl_file_kw_type *kw1, - const ecl_file_kw_type *kw2); -ecl_file_kw_type *ecl_file_kw_alloc(const ecl_kw_type *ecl_kw, - offset_type offset); -ecl_file_kw_type *ecl_file_kw_alloc0(const char *header, - ecl_data_type data_type, int size, - offset_type offset); -void ecl_file_kw_free(ecl_file_kw_type *file_kw); -void ecl_file_kw_free__(void *arg); -ecl_kw_type *ecl_file_kw_get_kw(ecl_file_kw_type *file_kw, fortio_type *fortio, - inv_map_type *inv_map); -ecl_kw_type *ecl_file_kw_get_kw_ptr(ecl_file_kw_type *file_kw); -ecl_file_kw_type *ecl_file_kw_alloc_copy(const ecl_file_kw_type *src); -const char *ecl_file_kw_get_header(const ecl_file_kw_type *file_kw); -int ecl_file_kw_get_size(const ecl_file_kw_type *file_kw); -ecl_data_type ecl_file_kw_get_data_type(const ecl_file_kw_type *); -offset_type ecl_file_kw_get_offset(const ecl_file_kw_type *file_kw); -bool ecl_file_kw_ptr_eq(const ecl_file_kw_type *file_kw, - const ecl_kw_type *ecl_kw); -void ecl_file_kw_replace_kw(ecl_file_kw_type *file_kw, fortio_type *target, - ecl_kw_type *new_kw); -bool ecl_file_kw_fskip_data(const ecl_file_kw_type *file_kw, - fortio_type *fortio); -void ecl_file_kw_inplace_fwrite(ecl_file_kw_type *file_kw, fortio_type *fortio); - -void ecl_file_kw_fwrite(const ecl_file_kw_type *file_kw, FILE *stream); -ecl_file_kw_type **ecl_file_kw_fread_alloc_multiple(FILE *stream, int num); -ecl_file_kw_type *ecl_file_kw_fread_alloc(FILE *stream); - -void ecl_file_kw_start_transaction(const ecl_file_kw_type *file_kw, - int *ref_count); -void ecl_file_kw_end_transaction(ecl_file_kw_type *file_kw, int ref_count); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/include/ert/ecl/ecl_file_view.hpp b/lib/include/ert/ecl/ecl_file_view.hpp deleted file mode 100644 index 92f25c28d7..0000000000 --- a/lib/include/ert/ecl/ecl_file_view.hpp +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef ERT_ECL_FILE_VIEW_H -#define ERT_ECL_FILE_VIEW_H - -#include -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - ECL_FILE_CLOSE_STREAM = 1, /* - This flag will close the underlying FILE object between each access; this is - mainly to save filedescriptors in cases where many ecl_file instances are open at - the same time. */ - ECL_FILE_WRITABLE = 2 /* - This flag opens the file in a mode where it can be updated and modified, but it - must still exist and be readable. I.e. this should not compared with the normal: - fopen(filename , "w") where an existing file is truncated to zero upon successfull - open. - */ -} ecl_file_flag_type; - -typedef struct ecl_file_view_struct ecl_file_view_type; -typedef struct ecl_file_transaction_struct ecl_file_transaction_type; - -bool ecl_file_view_flags_set(const ecl_file_view_type *file_view, - int query_flags); -bool ecl_file_view_check_flags(int state_flags, int query_flags); - -ecl_file_view_type *ecl_file_view_alloc(fortio_type *fortio, int *flags, - inv_map_type *inv_map, bool owner); -int ecl_file_view_get_global_index(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith); -void ecl_file_view_make_index(ecl_file_view_type *ecl_file_view); -bool ecl_file_view_has_kw(const ecl_file_view_type *ecl_file_view, - const char *kw); -ecl_file_kw_type * -ecl_file_view_iget_file_kw(const ecl_file_view_type *ecl_file_view, - int global_index); -ecl_file_kw_type * -ecl_file_view_iget_named_file_kw(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith); -ecl_kw_type *ecl_file_view_iget_kw(const ecl_file_view_type *ecl_file_view, - int index); -void ecl_file_view_index_fload_kw(const ecl_file_view_type *ecl_file_view, - const char *kw, int index, - const int_vector_type *index_map, - char *buffer); -int ecl_file_view_find_kw_value(const ecl_file_view_type *ecl_file_view, - const char *kw, const void *value); -const char * -ecl_file_view_iget_distinct_kw(const ecl_file_view_type *ecl_file_view, - int index); -int ecl_file_view_get_num_distinct_kw(const ecl_file_view_type *ecl_file_view); -int ecl_file_view_get_size(const ecl_file_view_type *ecl_file_view); -ecl_data_type -ecl_file_view_iget_data_type(const ecl_file_view_type *ecl_file_view, - int index); -int ecl_file_view_iget_size(const ecl_file_view_type *ecl_file_view, int index); -const char *ecl_file_view_iget_header(const ecl_file_view_type *ecl_file_view, - int index); -ecl_kw_type * -ecl_file_view_iget_named_kw(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith); -ecl_data_type -ecl_file_view_iget_named_data_type(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith); -int ecl_file_view_iget_named_size(const ecl_file_view_type *ecl_file_view, - const char *kw, int ith); -void ecl_file_view_replace_kw(ecl_file_view_type *ecl_file_view, - ecl_kw_type *old_kw, ecl_kw_type *new_kw, - bool insert_copy); -bool ecl_file_view_load_all(ecl_file_view_type *ecl_file_view); -void ecl_file_view_add_kw(ecl_file_view_type *ecl_file_view, - ecl_file_kw_type *file_kw); -void ecl_file_view_free(ecl_file_view_type *ecl_file_view); -void ecl_file_view_free__(void *arg); -int ecl_file_view_get_num_named_kw(const ecl_file_view_type *ecl_file_view, - const char *kw); -void ecl_file_view_fwrite(const ecl_file_view_type *ecl_file_view, - fortio_type *target, int offset); -int ecl_file_view_iget_occurence(const ecl_file_view_type *ecl_file_view, - int global_index); -void ecl_file_view_fprintf_kw_list(const ecl_file_view_type *ecl_file_view, - FILE *stream); -ecl_file_view_type * -ecl_file_view_add_blockview(ecl_file_view_type *ecl_file_view, - const char *header, int occurence); -ecl_file_view_type * -ecl_file_view_add_blockview2(ecl_file_view_type *ecl_file_view, - const char *start_kw, const char *end_kw, - int occurence); -ecl_file_view_type * -ecl_file_view_add_restart_view(ecl_file_view_type *file_view, int seqnum_index, - int report_step, time_t sim_time, - double sim_days); -ecl_file_view_type * -ecl_file_view_alloc_blockview(const ecl_file_view_type *ecl_file_view, - const char *header, int occurence); -ecl_file_view_type * -ecl_file_view_alloc_blockview2(const ecl_file_view_type *ecl_file_view, - const char *start_kw, const char *end_kw, - int occurence); - -void ecl_file_view_add_child(ecl_file_view_type *parent, - ecl_file_view_type *child); -bool ecl_file_view_drop_flag(ecl_file_view_type *file_view, int flag); -void ecl_file_view_add_flag(ecl_file_view_type *file_view, int flag); - -int ecl_file_view_seqnum_index_from_sim_time(ecl_file_view_type *parent_map, - time_t sim_time); -bool ecl_file_view_has_sim_time(const ecl_file_view_type *ecl_file_view, - time_t sim_time); -int ecl_file_view_find_sim_time(const ecl_file_view_type *ecl_file_view, - time_t sim_time); -double -ecl_file_view_iget_restart_sim_days(const ecl_file_view_type *ecl_file_view, - int seqnum_index); -time_t -ecl_file_view_iget_restart_sim_date(const ecl_file_view_type *ecl_file_view, - int seqnum_index); -bool ecl_file_view_has_report_step(const ecl_file_view_type *ecl_file_view, - int report_step); - -ecl_file_view_type * -ecl_file_view_add_summary_view(ecl_file_view_type *file_view, int report_step); -const char *ecl_file_view_get_src_file(const ecl_file_view_type *file_view); -void ecl_file_view_fclose_stream(ecl_file_view_type *file_view); - -void ecl_file_view_write_index(const ecl_file_view_type *file_view, - FILE *ostream); -ecl_file_view_type *ecl_file_view_fread_alloc(fortio_type *fortio, int *flags, - inv_map_type *inv_map, - FILE *istream); - -ecl_file_transaction_type * -ecl_file_view_start_transaction(ecl_file_view_type *file_view); -void ecl_file_view_end_transaction(ecl_file_view_type *file_view, - ecl_file_transaction_type *transaction); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/include/ert/ecl/ecl_grav.hpp b/lib/include/ert/ecl/ecl_grav.hpp deleted file mode 100644 index 73eeea4359..0000000000 --- a/lib/include/ert/ecl/ecl_grav.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef ERT_ECL_GRAV_H -#define ERT_ECL_GRAV_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif -typedef struct ecl_grav_struct ecl_grav_type; -typedef struct ecl_grav_survey_struct ecl_grav_survey_type; - -void ecl_grav_free(ecl_grav_type *ecl_grav_config); -ecl_grav_type *ecl_grav_alloc(const ecl_grid_type *ecl_grid, - const ecl_file_type *init_file); -ecl_grav_survey_type * -ecl_grav_add_survey_FIP(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file); -ecl_grav_survey_type * -ecl_grav_add_survey_PORMOD(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file); -ecl_grav_survey_type * -ecl_grav_add_survey_RPORV(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file); -ecl_grav_survey_type * -ecl_grav_add_survey_RFIP(ecl_grav_type *grav, const char *name, - const ecl_file_view_type *restart_file); -double ecl_grav_eval(const ecl_grav_type *grav, const char *base, - const char *monitor, ecl_region_type *region, double utm_x, - double utm_y, double depth, int phase_mask); -void ecl_grav_new_std_density(ecl_grav_type *grav, ecl_phase_enum phase, - double default_density); -void ecl_grav_add_std_density(ecl_grav_type *grav, ecl_phase_enum phase, - int pvtnum, double density); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_grav_common.h b/lib/include/ert/ecl/ecl_grav_common.h deleted file mode 100644 index 1f4eb6e704..0000000000 --- a/lib/include/ert/ecl/ecl_grav_common.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_grav_common.hpp b/lib/include/ert/ecl/ecl_grav_common.hpp deleted file mode 100644 index 87a6f7dd6a..0000000000 --- a/lib/include/ert/ecl/ecl_grav_common.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ERT_ECL_GRAV_COMMON_H -#define ERT_ECL_GRAV_COMMON_H - -#include - -#include -#include "detail/ecl/ecl_grid_cache.hpp" - -#ifdef __cplusplus -extern "C" { -#endif - -bool *ecl_grav_common_alloc_aquifer_cell(const ecl::ecl_grid_cache &grid_cache, - const ecl_file_type *init_file); - -double ecl_grav_common_eval_biot_savart(const ecl::ecl_grid_cache &grid_cache, - ecl_region_type *region, - const bool *aquifer, - const double *weight, double utm_x, - double utm_y, double depth); - -double ecl_grav_common_eval_geertsma(const ecl::ecl_grid_cache &grid_cache, - ecl_region_type *region, - const bool *aquifer, const double *weight, - double utm_x, double utm_y, double depth, - double poisson_ratio, double seabed); - -#ifdef __cplusplus -} - -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_grid.hpp b/lib/include/ert/ecl/ecl_grid.hpp deleted file mode 100644 index 1ed89ca7e8..0000000000 --- a/lib/include/ert/ecl/ecl_grid.hpp +++ /dev/null @@ -1,390 +0,0 @@ -#ifndef ERT_ECL_GRID_H -#define ERT_ECL_GRID_H - -#include - -#include -#include -#include - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define ECL_GRID_COORD_SIZE(nx, ny) (((nx) + 1) * ((ny) + 1) * 6) -#define ECL_GRID_ZCORN_SIZE(nx, ny, nz) (((nx) * (ny) * (nz)*8)) - -#define ECL_GRID_GLOBAL_GRID "Global" // used as key in hash tables over grids. -#define ECL_GRID_MAINGRID_LGR_NR 0 - -typedef double(block_function_ftype)(const double_vector_type *); -typedef struct ecl_grid_struct ecl_grid_type; - -bool ecl_grid_have_coarse_cells(const ecl_grid_type *main_grid); -bool ecl_grid_cell_in_coarse_group1(const ecl_grid_type *main_grid, - int global_index); -bool ecl_grid_cell_in_coarse_group3(const ecl_grid_type *main_grid, int i, - int j, int k); -int ecl_grid_get_num_coarse_groups(const ecl_grid_type *main_grid); -ecl_coarse_cell_type *ecl_grid_iget_coarse_group(const ecl_grid_type *ecl_grid, - int coarse_nr); -ecl_coarse_cell_type * -ecl_grid_get_cell_coarse_group1(const ecl_grid_type *ecl_grid, - int global_index); -ecl_coarse_cell_type * -ecl_grid_get_cell_coarse_group3(const ecl_grid_type *ecl_grid, int i, int j, - int k); - -int ecl_grid_get_cell_twist1(const ecl_grid_type *ecl_grid, int global_index); -int ecl_grid_get_cell_twist3(const ecl_grid_type *ecl_grid, int i, int j, - int k); - -void ecl_grid_get_column_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - double_vector_type *column); -int ecl_grid_get_global_index_from_xy_top(const ecl_grid_type *ecl_grid, - double x, double y); -int ecl_grid_get_global_index_from_xy_bottom(const ecl_grid_type *ecl_grid, - double x, double y); -ecl_grid_type *ecl_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, - const double *dx, const double *dy, - const double *dz, - const double *tops, - const int *actnum); - -void ecl_grid_get_cell_corner_xyz3(const ecl_grid_type *grid, int i, int j, - int k, int corner_nr, double *xpos, - double *ypos, double *zpos); -void ecl_grid_get_cell_corner_xyz1(const ecl_grid_type *grid, int global_index, - int corner_nr, double *xpos, double *ypos, - double *zpos); -void ecl_grid_get_corner_xyz(const ecl_grid_type *grid, int i, int j, int k, - double *xpos, double *ypos, double *zpos); - -double ecl_grid_get_cell_dx1A(const ecl_grid_type *grid, int active_index); -double ecl_grid_get_cell_dy1A(const ecl_grid_type *grid, int active_index); -double ecl_grid_get_cell_dz1A(const ecl_grid_type *grid, int active_index); -double ecl_grid_get_cell_thickness1A(const ecl_grid_type *grid, - int active_index); - -double ecl_grid_get_cell_dx1(const ecl_grid_type *grid, int global_index); -double ecl_grid_get_cell_dy1(const ecl_grid_type *grid, int global_index); -double ecl_grid_get_cell_dz1(const ecl_grid_type *grid, int global_index); -double ecl_grid_get_cell_thickness1(const ecl_grid_type *grid, - int global_index); - -double ecl_grid_get_cell_dx3(const ecl_grid_type *grid, int i, int j, int k); -double ecl_grid_get_cell_dy3(const ecl_grid_type *grid, int i, int j, int k); -double ecl_grid_get_cell_dz3(const ecl_grid_type *grid, int i, int j, int k); -double ecl_grid_get_cell_thickness3(const ecl_grid_type *grid, int i, int j, - int k); - -void ecl_grid_get_distance(const ecl_grid_type *grid, int global_index1, - int global_index2, double *dx, double *dy, - double *dz); -double ecl_grid_get_cdepth1A(const ecl_grid_type *grid, int active_index); -double ecl_grid_get_cdepth1(const ecl_grid_type *grid, int global_index); -double ecl_grid_get_cdepth3(const ecl_grid_type *grid, int i, int j, int k); -int ecl_grid_get_global_index_from_xy(const ecl_grid_type *ecl_grid, int k, - bool lower_layer, double x, double y); -bool ecl_grid_cell_contains_xyz1(const ecl_grid_type *ecl_grid, - int global_index, double x, double y, - double z); -bool ecl_grid_cell_contains_xyz3(const ecl_grid_type *ecl_grid, int i, int j, - int k, double x, double y, double z); -double ecl_grid_get_cell_volume1(const ecl_grid_type *ecl_grid, - int global_index); -double ecl_grid_get_cell_volume3(const ecl_grid_type *ecl_grid, int i, int j, - int k); -double ecl_grid_get_cell_volume1A(const ecl_grid_type *ecl_grid, - int active_index); -bool ecl_grid_cell_contains1(const ecl_grid_type *grid, int global_index, - double x, double y, double z); -bool ecl_grid_cell_contains3(const ecl_grid_type *grid, int i, int j, int k, - double x, double y, double z); -int ecl_grid_get_global_index_from_xyz(ecl_grid_type *grid, double x, double y, - double z, int start_index); -bool ecl_grid_get_ijk_from_xyz(ecl_grid_type *grid, double x, double y, - double z, int start_index, int *i, int *j, - int *k); -bool ecl_grid_get_ij_from_xy(const ecl_grid_type *grid, double x, double y, - int k, int *i, int *j); -const char *ecl_grid_get_name(const ecl_grid_type *); -int ecl_grid_get_active_index3(const ecl_grid_type *ecl_grid, int i, int j, - int k); -int ecl_grid_get_active_index1(const ecl_grid_type *ecl_grid, int global_index); -int ecl_grid_get_active_fracture_index3(const ecl_grid_type *ecl_grid, int i, - int j, int k); -int ecl_grid_get_active_fracture_index1(const ecl_grid_type *ecl_grid, - int global_index); -bool ecl_grid_cell_active3(const ecl_grid_type *, int, int, int); -bool ecl_grid_cell_active1(const ecl_grid_type *, int); -bool ecl_grid_ijk_valid(const ecl_grid_type *, int, int, int); -int ecl_grid_get_global_index3(const ecl_grid_type *, int, int, int); -int ecl_grid_get_global_index1A(const ecl_grid_type *ecl_grid, - int active_index); -int ecl_grid_get_global_index1F(const ecl_grid_type *ecl_grid, - int active_fracture_index); - -const nnc_info_type *ecl_grid_get_cell_nnc_info3(const ecl_grid_type *grid, - int i, int j, int k); -const nnc_info_type *ecl_grid_get_cell_nnc_info1(const ecl_grid_type *grid, - int global_index); -void ecl_grid_add_self_nnc(ecl_grid_type *grid1, int g1, int g2, int nnc_index); -void ecl_grid_add_self_nnc_list(ecl_grid_type *grid, const int *g1_list, - const int *g2_list, int num_nnc); - -ecl_grid_type *ecl_grid_alloc_GRDECL_kw(int nx, int ny, int nz, - const ecl_kw_type *zcorn_kw, - const ecl_kw_type *coord_kw, - const ecl_kw_type *actnum_kw, - const ecl_kw_type *mapaxes_kw); -ecl_grid_type *ecl_grid_alloc_GRDECL_data(int, int, int, const float *, - const float *, const int *, - bool apply_mapaxes, - const float *mapaxes); -ecl_grid_type *ecl_grid_alloc_GRID_data(int num_coords, int nx, int ny, int nz, - int coords_size, int **coords, - float **corners, bool apply_mapaxes, - const float *mapaxes); -ecl_grid_type *ecl_grid_alloc(const char *); -ecl_grid_type *ecl_grid_alloc_ext_actnum(const char *, const int *ext_actnum); -ecl_grid_type *ecl_grid_load_case(const char *case_input); -ecl_grid_type *ecl_grid_load_case__(const char *case_input, bool apply_mapaxes); -ecl_grid_type *ecl_grid_alloc_rectangular(int nx, int ny, int nz, double dx, - double dy, double dz, - const int *actnum); -ecl_grid_type *ecl_grid_alloc_regular(int nx, int ny, int nz, - const double *ivec, const double *jvec, - const double *kvec, const int *actnum); -ecl_grid_type *ecl_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, - const double *dxv, const double *dyv, - const double *dzv, const int *actnum); -ecl_grid_type * -ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, - const double *dyv, const double *dzv, - const double *depthz, const int *actnum); -ecl_kw_type *ecl_grid_alloc_volume_kw(const ecl_grid_type *grid, - bool active_size); -ecl_kw_type *ecl_grid_alloc_mapaxes_kw(const ecl_grid_type *grid); -ecl_kw_type *ecl_grid_alloc_coord_kw(const ecl_grid_type *grid); - -bool ecl_grid_exists(const char *case_input); -char *ecl_grid_alloc_case_filename(const char *case_input); - -void ecl_grid_free(ecl_grid_type *); -void ecl_grid_free__(void *arg); -grid_dims_type ecl_grid_iget_dims(const ecl_grid_type *grid, int grid_nr); -void ecl_grid_get_dims(const ecl_grid_type *, int *, int *, int *, int *); -int ecl_grid_get_nz(const ecl_grid_type *grid); -int ecl_grid_get_nx(const ecl_grid_type *grid); -int ecl_grid_get_ny(const ecl_grid_type *grid); -int ecl_grid_get_nactive(const ecl_grid_type *grid); -int ecl_grid_get_nactive_fracture(const ecl_grid_type *grid); -int ecl_grid_get_active_index(const ecl_grid_type *, int, int, int); -void ecl_grid_summarize(const ecl_grid_type *); -void ecl_grid_get_ijk1(const ecl_grid_type *, int global_index, int *, int *, - int *); -void ecl_grid_get_ijk1A(const ecl_grid_type *, int active_index, int *, int *, - int *); -void ecl_grid_get_ijk_from_active_index(const ecl_grid_type *, int, int *, - int *, int *); - -void ecl_grid_get_xyz3(const ecl_grid_type *, int, int, int, double *, double *, - double *); -void ecl_grid_get_xyz1(const ecl_grid_type *grid, int global_index, - double *xpos, double *ypos, double *zpos); -void ecl_grid_get_xyz1A(const ecl_grid_type *grid, int active_index, - double *xpos, double *ypos, double *zpos); - -bool ecl_grid_get_xyz_inside1(const ecl_grid_type *grid, int global_index, - double *xpos, double *ypos, double *zpos); -bool ecl_grid_get_xyz_inside3(const ecl_grid_type *grid, int i, int j, int k, - double *xpos, double *ypos, double *zpos); - -int ecl_grid_get_global_size(const ecl_grid_type *ecl_grid); -bool ecl_grid_compare(const ecl_grid_type *g1, const ecl_grid_type *g2, - bool include_lgr, bool include_nnc, bool verbose); -int ecl_grid_get_active_size(const ecl_grid_type *ecl_grid); - -double ecl_grid_get_bottom1(const ecl_grid_type *grid, int global_index); -double ecl_grid_get_bottom3(const ecl_grid_type *grid, int i, int j, int k); -double ecl_grid_get_bottom1A(const ecl_grid_type *grid, int active_index); -double ecl_grid_get_top1(const ecl_grid_type *grid, int global_index); -double ecl_grid_get_top3(const ecl_grid_type *grid, int i, int j, int k); -double ecl_grid_get_top1A(const ecl_grid_type *grid, int active_index); -double ecl_grid_get_top2(const ecl_grid_type *grid, int i, int j); -double ecl_grid_get_bottom2(const ecl_grid_type *grid, int i, int j); -int ecl_grid_locate_depth(const ecl_grid_type *grid, double depth, int i, - int j); - -void ecl_grid_alloc_blocking_variables(ecl_grid_type *, int); -void ecl_grid_init_blocking(ecl_grid_type *); -double ecl_grid_block_eval3d(ecl_grid_type *grid, int i, int j, int k, - block_function_ftype *blockf); -int ecl_grid_get_block_count3d(const ecl_grid_type *ecl_grid, int i, int j, - int k); -bool ecl_grid_block_value_3d(ecl_grid_type *, double, double, double, double); - -bool ecl_grid_cell_invalid1(const ecl_grid_type *ecl_grid, int global_index); -bool ecl_grid_cell_invalid3(const ecl_grid_type *ecl_grid, int i, int j, int k); -double ecl_grid_cell_invalid1A(const ecl_grid_type *grid, int active_index); - -bool ecl_grid_cell_valid1(const ecl_grid_type *ecl_grid, int global_index); -bool ecl_grid_cell_valid3(const ecl_grid_type *ecl_grid, int i, int j, int k); -double ecl_grid_cell_valid1A(const ecl_grid_type *grid, int active_index); - -void ecl_grid_dump(const ecl_grid_type *grid, FILE *stream); -void ecl_grid_dump_ascii(ecl_grid_type *grid, bool active_only, FILE *stream); -void ecl_grid_dump_ascii_cell1(ecl_grid_type *grid, int global_index, - FILE *stream, const double *offset); -void ecl_grid_dump_ascii_cell3(ecl_grid_type *grid, int i, int j, int k, - FILE *stream, const double *offset); - -/* lgr related functions */ -const ecl_grid_type *ecl_grid_get_cell_lgr3(const ecl_grid_type *grid, int i, - int j, int k); -const ecl_grid_type *ecl_grid_get_cell_lgr1A(const ecl_grid_type *grid, - int active_index); -const ecl_grid_type *ecl_grid_get_cell_lgr1(const ecl_grid_type *grid, - int global_index); -int ecl_grid_get_num_lgr(const ecl_grid_type *main_grid); -int ecl_grid_get_lgr_nr(const ecl_grid_type *ecl_grid); -int ecl_grid_get_lgr_nr_from_name(const ecl_grid_type *grid, const char *name); -ecl_grid_type *ecl_grid_iget_lgr(const ecl_grid_type *main_grid, int lgr_index); -ecl_grid_type *ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type *main_grid, - int lgr_nr); -ecl_grid_type *ecl_grid_get_lgr(const ecl_grid_type *main_grid, - const char *__lgr_name); -bool ecl_grid_has_lgr(const ecl_grid_type *main_grid, const char *__lgr_name); -bool ecl_grid_has_lgr_nr(const ecl_grid_type *main_grid, int lgr_nr); -const char *ecl_grid_iget_lgr_name(const ecl_grid_type *ecl_grid, - int lgr_index); -const char *ecl_grid_get_lgr_name(const ecl_grid_type *ecl_grid, int lgr_nr); -stringlist_type *ecl_grid_alloc_lgr_name_list(const ecl_grid_type *ecl_grid); -int ecl_grid_get_parent_cell1(const ecl_grid_type *grid, int global_index); -int ecl_grid_get_parent_cell3(const ecl_grid_type *grid, int i, int j, int k); -const ecl_grid_type *ecl_grid_get_global_grid(const ecl_grid_type *grid); -bool ecl_grid_is_lgr(const ecl_grid_type *ecl_grid); - -double ecl_grid_get_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, int k); -float ecl_grid_get_float_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - int k); -double ecl_grid_get_double_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - int k); -int ecl_grid_get_int_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, int k); - -void ecl_grid_grdecl_fprintf_kw(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, - const char *special_header, FILE *stream, - double double_default); -bool ecl_grid_test_lgr_consistency(const ecl_grid_type *ecl_grid); - -void ecl_grid_fwrite_dims(const ecl_grid_type *grid, fortio_type *init_file, - ert_ecl_unit_enum output_unit); -void ecl_grid_fwrite_depth(const ecl_grid_type *grid, fortio_type *init_file, - ert_ecl_unit_enum ouput_unit); - -void ecl_grid_fwrite_EGRID(ecl_grid_type *grid, const char *filename, - bool metric_output); -void ecl_grid_fwrite_EGRID2(ecl_grid_type *grid, const char *filename, - ert_ecl_unit_enum output_unit); - -void ecl_grid_fwrite_GRID(const ecl_grid_type *grid, const char *filename); -void ecl_grid_fwrite_GRID2(const ecl_grid_type *grid, const char *filename, - ert_ecl_unit_enum output_unit); - -void ecl_grid_fprintf_grdecl(ecl_grid_type *grid, FILE *stream); -void ecl_grid_fprintf_grdecl2(ecl_grid_type *grid, FILE *stream, - ert_ecl_unit_enum output_unit); - -int ecl_grid_zcorn_index__(int nx, int ny, int i, int j, int k, int c); -int ecl_grid_zcorn_index(const ecl_grid_type *grid, int i, int j, int k, int c); -ecl_grid_type *ecl_grid_alloc_EGRID(const char *grid_file, bool apply_mapaxes); -ecl_grid_type *ecl_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes); - -float *ecl_grid_alloc_zcorn_data(const ecl_grid_type *grid); -ecl_kw_type *ecl_grid_alloc_zcorn_kw(const ecl_grid_type *grid); -int *ecl_grid_alloc_actnum_data(const ecl_grid_type *grid); -ecl_kw_type *ecl_grid_alloc_actnum_kw(const ecl_grid_type *grid); -ecl_kw_type *ecl_grid_alloc_hostnum_kw(const ecl_grid_type *grid); -ecl_kw_type *ecl_grid_alloc_gridhead_kw(int nx, int ny, int nz, int grid_nr); -ecl_grid_type *ecl_grid_alloc_copy(const ecl_grid_type *src_grid); -ecl_grid_type *ecl_grid_alloc_processed_copy(const ecl_grid_type *src_grid, - const double *zcorn, - const int *actnum); - -void ecl_grid_ri_export(const ecl_grid_type *ecl_grid, double *ri_points); -void ecl_grid_cell_ri_export(const ecl_grid_type *ecl_grid, int global_index, - double *ri_points); - -bool ecl_grid_dual_grid(const ecl_grid_type *ecl_grid); -int ecl_grid_get_num_nnc(const ecl_grid_type *grid); - -bool ecl_grid_cell_regular3(const ecl_grid_type *ecl_grid, int i, int j, int k); -bool ecl_grid_cell_regular1(const ecl_grid_type *ecl_grid, int global_index); - -void ecl_grid_init_zcorn_data(const ecl_grid_type *grid, float *zcorn); -void ecl_grid_init_zcorn_data_double(const ecl_grid_type *grid, double *zcorn); -int ecl_grid_get_zcorn_size(const ecl_grid_type *grid); - -void ecl_grid_init_coord_data(const ecl_grid_type *grid, float *coord); -void ecl_grid_init_coord_data_double(const ecl_grid_type *grid, double *coord); -int ecl_grid_get_coord_size(const ecl_grid_type *ecl_grid); - -void ecl_grid_init_actnum_data(const ecl_grid_type *grid, int *actnum); -bool ecl_grid_use_mapaxes(const ecl_grid_type *grid); -void ecl_grid_init_mapaxes_data_double(const ecl_grid_type *grid, - double *mapaxes); -void ecl_grid_reset_actnum(ecl_grid_type *grid, const int *actnum); -void ecl_grid_compressed_kw_copy(const ecl_grid_type *grid, - ecl_kw_type *target_kw, - const ecl_kw_type *src_kw); -void ecl_grid_global_kw_copy(const ecl_grid_type *grid, ecl_kw_type *target_kw, - const ecl_kw_type *src_kw); -void ecl_grid_export_cell_corners1(const ecl_grid_type *grid, int global_index, - double *x, double *y, double *z); - -ert_ecl_unit_enum ecl_grid_get_unit_system(const ecl_grid_type *grid); -void ecl_grid_export_index(const ecl_grid_type *grid, int *global_index, - int *index_data, bool active_only); -void ecl_grid_export_data_as_int(int index_size, const int *global_index, - const ecl_kw_type *kw, int *output); -void ecl_grid_export_data_as_double(int index_size, const int *data_index, - const ecl_kw_type *kw, double *output); -void ecl_grid_export_volume(const ecl_grid_type *grid, int index_size, - const int *global_index, double *output); -void ecl_grid_export_position(const ecl_grid_type *grid, int index_size, - const int *global_index, double *output); -void export_corners(const ecl_grid_type *grid, int index_size, - const int *global_index, double *output); - -UTIL_IS_INSTANCE_HEADER(ecl_grid); -UTIL_SAFE_CAST_HEADER(ecl_grid); - -#ifdef __cplusplus -} -namespace ecl { - -ecl_grid_type *ecl_grid_alloc_GRDECL_data(int nx, int ny, int nz, - const double *zcorn, - const double *coord, - const int *actnum, bool apply_mapaxes, - const float *mapaxes); - -} - -#ifdef __cplusplus -#endif - -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_grid_dims.h b/lib/include/ert/ecl/ecl_grid_dims.h deleted file mode 100644 index 606e7380ac..0000000000 --- a/lib/include/ert/ecl/ecl_grid_dims.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_grid_dims.hpp b/lib/include/ert/ecl/ecl_grid_dims.hpp deleted file mode 100644 index 0e7ee18588..0000000000 --- a/lib/include/ert/ecl/ecl_grid_dims.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ERT_ECL_GRID_DIMS_H -#define ERT_ECL_GRID_DIMS_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct ecl_grid_dims_struct ecl_grid_dims_type; - -ecl_grid_dims_type *ecl_grid_dims_alloc(const char *grid_file, - const char *data_file); -void ecl_grid_dims_free(ecl_grid_dims_type *grid_dims); -int ecl_grid_dims_get_num_grids(const ecl_grid_dims_type *grid_dims); -const grid_dims_type * -ecl_grid_dims_iget_dims(const ecl_grid_dims_type *grid_dims, int grid_nr); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_init_file.h b/lib/include/ert/ecl/ecl_init_file.h deleted file mode 100644 index 3385b0b282..0000000000 --- a/lib/include/ert/ecl/ecl_init_file.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_init_file.hpp b/lib/include/ert/ecl/ecl_init_file.hpp deleted file mode 100644 index c8ea276c6e..0000000000 --- a/lib/include/ert/ecl/ecl_init_file.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ERT_ECL_INIT_FILE_H -#define ERT_ECL_INIT_FILE_H - -#include - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void ecl_init_file_fwrite_header(fortio_type *fortio, const ecl_grid_type *grid, - const ecl_kw_type *poro, - ert_ecl_unit_enum unit_system, int phases, - time_t start_date); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_io_config.h b/lib/include/ert/ecl/ecl_io_config.h deleted file mode 100644 index 7beb99ceff..0000000000 --- a/lib/include/ert/ecl/ecl_io_config.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_io_config.hpp b/lib/include/ert/ecl/ecl_io_config.hpp deleted file mode 100644 index ba77a0961c..0000000000 --- a/lib/include/ert/ecl/ecl_io_config.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ERT_ECL_IO_CONFIG_H -#define ERT_ECL_IO_CONFIG_H -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_io_config_struct ecl_io_config_type; - -/* Modifiers */ -void ecl_io_config_set_formatted(ecl_io_config_type *, bool); -void ecl_io_config_set_unified_restart(ecl_io_config_type *, bool); -void ecl_io_config_set_unified_summary(ecl_io_config_type *, bool); - -/* Accesors */ -bool ecl_io_config_get_formatted(ecl_io_config_type *); -bool ecl_io_config_get_unified_restart(ecl_io_config_type *); -bool ecl_io_config_get_unified_summary(ecl_io_config_type *); - -/* Allocater & destructor */ -ecl_io_config_type *ecl_io_config_alloc(bool, bool, bool); -void ecl_io_config_free(ecl_io_config_type *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_kw.hpp b/lib/include/ert/ecl/ecl_kw.hpp deleted file mode 100644 index 5afada1cc6..0000000000 --- a/lib/include/ert/ecl/ecl_kw.hpp +++ /dev/null @@ -1,294 +0,0 @@ -#ifndef ERT_ECL_KW_H -#define ERT_ECL_KW_H -#ifdef __cplusplus -extern "C" { -#endif -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -UTIL_IS_INSTANCE_HEADER(ecl_kw); - -typedef struct ecl_kw_struct ecl_kw_type; - -typedef enum { ECL_KW_READ_OK = 0, ECL_KW_READ_FAIL = 1 } ecl_read_status_enum; - -/* - The size of an ecl_kw instance is denoted with an integer. The - choice of int to store the size obviously limits the maximum size to - INT_MAX elements. This choice is an historical mistake - it should - probably have been size_t; however the ecl_kw datastructure is - tightly bound to the on-disk binary format supplied by Eclipse, and - there the number of elements is stored as a signed(?) 32 bit - integer - so using int for size does make some sense- -*/ - -#define ECL_KW_MAX_SIZE INT_MAX - -/* - Character data in ECLIPSE files comes as an array of fixed-length - string. Each of these strings is 8 characters long. The type name, - i.e. 'REAL', 'INTE', ... , come as 4 character strings. -*/ -#define ECL_KW_HEADER_DATA_SIZE ECL_STRING8_LENGTH + ECL_TYPE_LENGTH + 4 -#define ECL_KW_HEADER_FORTIO_SIZE ECL_KW_HEADER_DATA_SIZE + 8 - -int ecl_kw_first_different(const ecl_kw_type *kw1, const ecl_kw_type *kw2, - int offset, double abs_epsilon, double rel_epsilon); -size_t ecl_kw_fortio_size(const ecl_kw_type *ecl_kw); -void *ecl_kw_get_ptr(const ecl_kw_type *ecl_kw); -void ecl_kw_set_data_ptr(ecl_kw_type *ecl_kw, void *data); -void ecl_kw_fwrite_data(const ecl_kw_type *_ecl_kw, fortio_type *fortio); -bool ecl_kw_fread_realloc_data(ecl_kw_type *ecl_kw, fortio_type *fortio); -ecl_data_type ecl_kw_get_data_type(const ecl_kw_type *); -const char *ecl_kw_get_header8(const ecl_kw_type *); -const char *ecl_kw_get_header(const ecl_kw_type *ecl_kw); -ecl_kw_type *ecl_kw_alloc_empty(void); -ecl_read_status_enum ecl_kw_fread_header(ecl_kw_type *, fortio_type *); -void ecl_kw_set_header_name(ecl_kw_type *, const char *); -bool ecl_kw_fseek_kw(const char *, bool, bool, fortio_type *); -bool ecl_kw_fseek_last_kw(const char *, bool, fortio_type *); -void ecl_kw_inplace_update_file(const ecl_kw_type *, const char *, int); -void ecl_kw_fskip(fortio_type *); -void ecl_kw_alloc_data(ecl_kw_type *); -void ecl_kw_alloc_double_data(ecl_kw_type *ecl_kw, double *values); -void ecl_kw_alloc_float_data(ecl_kw_type *ecl_kw, float *values); -bool ecl_kw_fread_realloc(ecl_kw_type *, fortio_type *); -void ecl_kw_fread(ecl_kw_type *, fortio_type *); -ecl_kw_type *ecl_kw_fread_alloc(fortio_type *); -ecl_kw_type *ecl_kw_alloc_actnum(const ecl_kw_type *porv_kw, float porv_limit); -ecl_kw_type *ecl_kw_alloc_actnum_bitmask(const ecl_kw_type *porv_kw, - float porv_limit, int actnum_bitmask); -void ecl_kw_free_data(ecl_kw_type *); -void ecl_kw_fread_indexed_data(fortio_type *fortio, offset_type data_offset, - ecl_data_type, int element_count, - const int_vector_type *index_map, char *buffer); -void ecl_kw_free(ecl_kw_type *); -void ecl_kw_free__(void *); -ecl_kw_type *ecl_kw_alloc_copy(const ecl_kw_type *); -ecl_kw_type *ecl_kw_alloc_sub_copy(const ecl_kw_type *src, const char *new_kw, - int offset, int count); -const void *ecl_kw_copyc__(const void *); -ecl_kw_type *ecl_kw_alloc_slice_copy(const ecl_kw_type *src, int index1, - int index2, int stride); -void ecl_kw_resize(ecl_kw_type *ecl_kw, int new_size); -//void * ecl_kw_get_data_ref(const ecl_kw_type *); -void *ecl_kw_alloc_data_copy(const ecl_kw_type *); -void ecl_kw_memcpy(ecl_kw_type *, const ecl_kw_type *); -void ecl_kw_get_memcpy_data(const ecl_kw_type *, void *); -void ecl_kw_get_memcpy_float_data(const ecl_kw_type *ecl_kw, float *target); -void ecl_kw_get_memcpy_double_data(const ecl_kw_type *ecl_kw, double *target); -void ecl_kw_get_memcpy_int_data(const ecl_kw_type *ecl_kw, int *target); -void ecl_kw_set_memcpy_data(ecl_kw_type *, const void *); -bool ecl_kw_fwrite(const ecl_kw_type *, fortio_type *); -void ecl_kw_iget(const ecl_kw_type *, int, void *); -void ecl_kw_iset(ecl_kw_type *ecl_kw, int i, const void *iptr); -void ecl_kw_iset_char_ptr(ecl_kw_type *ecl_kw, int index, const char *s); -void ecl_kw_iset_string8(ecl_kw_type *ecl_kw, int index, const char *s8); -void ecl_kw_iset_string_ptr(ecl_kw_type *, int, const char *); -const char *ecl_kw_iget_string_ptr(const ecl_kw_type *, int); -const char *ecl_kw_iget_char_ptr(const ecl_kw_type *ecl_kw, int i); -void *ecl_kw_iget_ptr(const ecl_kw_type *, int); -int ecl_kw_get_size(const ecl_kw_type *); -bool ecl_kw_ichar_eq(const ecl_kw_type *, int, const char *); -ecl_kw_type *ecl_kw_alloc(const char *header, int size, ecl_data_type); -ecl_kw_type *ecl_kw_alloc_new(const char *, int, ecl_data_type, const void *); -ecl_kw_type *ecl_kw_alloc_new_shared(const char *, int, ecl_data_type, void *); -ecl_kw_type *ecl_kw_alloc_global_copy(const ecl_kw_type *src, - const ecl_kw_type *actnum); -void ecl_kw_fwrite_param(const char *, bool, const char *, ecl_data_type, int, - void *); -void ecl_kw_fwrite_param_fortio(fortio_type *, const char *, ecl_data_type, int, - void *); -void ecl_kw_summarize(const ecl_kw_type *ecl_kw); -void ecl_kw_fread_double_param(const char *, bool, double *); -float ecl_kw_iget_as_float(const ecl_kw_type *ecl_kw, int i); -double ecl_kw_iget_as_double(const ecl_kw_type *ecl_kw, int i); -void ecl_kw_get_data_as_double(const ecl_kw_type *, double *); -void ecl_kw_get_data_as_float(const ecl_kw_type *ecl_kw, float *float_data); -bool ecl_kw_name_equal(const ecl_kw_type *ecl_kw, const char *name); -bool ecl_kw_header_eq(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2); -bool ecl_kw_equal(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2); -bool ecl_kw_size_and_type_equal(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2); -bool ecl_kw_icmp_string(const ecl_kw_type *ecl_kw, int index, - const char *other_string); -bool ecl_kw_numeric_equal(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2, double abs_diff, - double rel_diff); -bool ecl_kw_block_equal(const ecl_kw_type *ecl_kw1, const ecl_kw_type *ecl_kw2, - int cmp_elements); -bool ecl_kw_data_equal(const ecl_kw_type *ecl_kw, const void *data); -bool ecl_kw_content_equal(const ecl_kw_type *ecl_kw1, - const ecl_kw_type *ecl_kw2); -bool ecl_kw_fskip_data__(ecl_data_type, int, fortio_type *); -bool ecl_kw_fskip_data(ecl_kw_type *ecl_kw, fortio_type *fortio); -bool ecl_kw_fread_data(ecl_kw_type *ecl_kw, fortio_type *fortio); -void ecl_kw_fskip_header(fortio_type *fortio); -bool ecl_kw_size_and_numeric_type_equal(const ecl_kw_type *kw1, - const ecl_kw_type *kw2); -bool ecl_kw_inplace_safe_div(ecl_kw_type *target_kw, - const ecl_kw_type *divisor); -void ecl_kw_inplace_sqrt(ecl_kw_type *kw); - -bool ecl_kw_is_kw_file(fortio_type *fortio); - -int ecl_kw_element_sum_int(const ecl_kw_type *ecl_kw); -double ecl_kw_element_sum_float(const ecl_kw_type *ecl_kw); -void ecl_kw_inplace_inv(ecl_kw_type *my_kw); -void ecl_kw_element_sum(const ecl_kw_type *, void *); -void ecl_kw_element_sum_indexed(const ecl_kw_type *ecl_kw, - const int_vector_type *index_list, void *_sum); -void ecl_kw_max_min(const ecl_kw_type *, void *, void *); -void *ecl_kw_get_void_ptr(const ecl_kw_type *ecl_kw); - -ecl_kw_type *ecl_kw_buffer_alloc(buffer_type *buffer); -void ecl_kw_buffer_store(const ecl_kw_type *ecl_kw, buffer_type *buffer); - -void ecl_kw_fprintf_data(const ecl_kw_type *ecl_kw, const char *fmt, - FILE *stream); -void ecl_kw_memcpy_data(ecl_kw_type *target, const ecl_kw_type *src); - -bool ecl_kw_assert_numeric(const ecl_kw_type *kw); -bool ecl_kw_assert_binary(const ecl_kw_type *kw1, const ecl_kw_type *kw2); - -void ecl_kw_scalar_set_bool(ecl_kw_type *ecl_kw, bool bool_value); -void ecl_kw_scalar_set__(ecl_kw_type *ecl_kw, const void *value); -void ecl_kw_scalar_set_float_or_double(ecl_kw_type *ecl_kw, double value); - -#define ECL_KW_SCALAR_SET_TYPED_HEADER(ctype) \ - void ecl_kw_scalar_set_##ctype(ecl_kw_type *ecl_kw, ctype value); -ECL_KW_SCALAR_SET_TYPED_HEADER(int) -ECL_KW_SCALAR_SET_TYPED_HEADER(float) -ECL_KW_SCALAR_SET_TYPED_HEADER(double) -#undef ECL_KW_SCALAR_SET_TYPED_HEADER - -ecl_kw_type *ecl_kw_alloc_scatter_copy(const ecl_kw_type *src_kw, - int target_size, const int *mapping, - void *def_value); - -void ecl_kw_inplace_add_squared(ecl_kw_type *target_kw, - const ecl_kw_type *add_kw); -void ecl_kw_inplace_add(ecl_kw_type *target_kw, const ecl_kw_type *add_kw); -void ecl_kw_inplace_sub(ecl_kw_type *target_kw, const ecl_kw_type *sub_kw); -void ecl_kw_inplace_div(ecl_kw_type *target_kw, const ecl_kw_type *div_kw); -void ecl_kw_inplace_mul(ecl_kw_type *target_kw, const ecl_kw_type *mul_kw); -void ecl_kw_inplace_abs(ecl_kw_type *kw); - -void ecl_kw_inplace_add_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *add_kw); -void ecl_kw_inplace_sub_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *sub_kw); -void ecl_kw_inplace_mul_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *mul_kw); -void ecl_kw_inplace_div_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *div_kw); -void ecl_kw_copy_indexed(ecl_kw_type *target_kw, - const int_vector_type *index_set, - const ecl_kw_type *src_kw); - -bool ecl_kw_assert_binary_numeric(const ecl_kw_type *kw1, - const ecl_kw_type *kw2); -#define ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER(ctype) \ - bool ecl_kw_assert_binary_##ctype(const ecl_kw_type *kw1, \ - const ecl_kw_type *kw2) -ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER(int); -ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER(float); -ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER(double); -#undef ECL_KW_ASSERT_TYPED_BINARY_OP_HEADER - -#define ECL_KW_SCALE_TYPED_HEADER(ctype) \ - void ecl_kw_scale_##ctype(ecl_kw_type *ecl_kw, ctype scale_factor) -ECL_KW_SCALE_TYPED_HEADER(int); -ECL_KW_SCALE_TYPED_HEADER(float); -ECL_KW_SCALE_TYPED_HEADER(double); -#undef ECL_KW_SCALE_TYPED_HEADER -void ecl_kw_scale_float_or_double(ecl_kw_type *ecl_kw, double scale_factor); - -#define ECL_KW_SHIFT_TYPED_HEADER(ctype) \ - void ecl_kw_shift_##ctype(ecl_kw_type *ecl_kw, ctype shift_factor) -ECL_KW_SHIFT_TYPED_HEADER(int); -ECL_KW_SHIFT_TYPED_HEADER(float); -ECL_KW_SHIFT_TYPED_HEADER(double); -#undef ECL_KW_SHIFT_TYPED_HEADER -void ecl_kw_shift_float_or_double(ecl_kw_type *ecl_kw, double shift_value); - -#define ECL_KW_IGET_TYPED_HEADER(type) \ - type ecl_kw_iget_##type(const ecl_kw_type *, int) -ECL_KW_IGET_TYPED_HEADER(double); -ECL_KW_IGET_TYPED_HEADER(float); -ECL_KW_IGET_TYPED_HEADER(int); -#undef ECL_KW_IGET_TYPED_HEADER -bool ecl_kw_iget_bool(const ecl_kw_type *ecl_kw, int i); - -#define ECL_KW_ISET_TYPED_HEADER(type) \ - void ecl_kw_iset_##type(ecl_kw_type *, int, type) -ECL_KW_ISET_TYPED_HEADER(double); -ECL_KW_ISET_TYPED_HEADER(float); -ECL_KW_ISET_TYPED_HEADER(int); -#undef ECL_KW_ISET_TYPED_HEADER -void ecl_kw_iset_bool(ecl_kw_type *ecl_kw, int i, bool bool_value); - -#define ECL_KW_GET_TYPED_PTR_HEADER(type) \ - type *ecl_kw_get_##type##_ptr(const ecl_kw_type *) -ECL_KW_GET_TYPED_PTR_HEADER(double); -ECL_KW_GET_TYPED_PTR_HEADER(float); -ECL_KW_GET_TYPED_PTR_HEADER(int); -ECL_KW_GET_TYPED_PTR_HEADER(bool); -#undef ECL_KW_GET_TYPED_PTR_HEADER - -#define ECL_KW_SET_INDEXED_HEADER(ctype) \ - void ecl_kw_set_indexed_##ctype( \ - ecl_kw_type *ecl_kw, const int_vector_type *index_list, ctype value) -ECL_KW_SET_INDEXED_HEADER(double); -ECL_KW_SET_INDEXED_HEADER(float); -ECL_KW_SET_INDEXED_HEADER(int); -#undef ECL_KW_SET_INDEXED_HEADER - -#define ECL_KW_SHIFT_INDEXED_HEADER(ctype) \ - void ecl_kw_shift_indexed_##ctype( \ - ecl_kw_type *ecl_kw, const int_vector_type *index_list, ctype shift) -ECL_KW_SHIFT_INDEXED_HEADER(int); -ECL_KW_SHIFT_INDEXED_HEADER(float); -ECL_KW_SHIFT_INDEXED_HEADER(double); -#undef ECL_KW_SHIFT_INDEXED_HEADER - -#define ECL_KW_SCALE_INDEXED_HEADER(ctype) \ - void ecl_kw_scale_indexed_##ctype( \ - ecl_kw_type *ecl_kw, const int_vector_type *index_list, ctype scale) -ECL_KW_SCALE_INDEXED_HEADER(int); -ECL_KW_SCALE_INDEXED_HEADER(float); -ECL_KW_SCALE_INDEXED_HEADER(double); -#undef ECL_KW_SCALE_INDEXED_HEADER - -#define ECL_KW_MAX_MIN_HEADER(ctype) \ - void ecl_kw_max_min_##ctype(const ecl_kw_type *ecl_kw, ctype *_max, \ - ctype *_min) -ECL_KW_MAX_MIN_HEADER(int); -ECL_KW_MAX_MIN_HEADER(float); -ECL_KW_MAX_MIN_HEADER(double); -#undef ECL_KW_MAX_MIN_HEADER - -void ecl_kw_fix_uninitialized(ecl_kw_type *ecl_kw, int nx, int ny, int nz, - const int *actnum); - -ecl_type_enum ecl_kw_get_type(const ecl_kw_type *); - -#include - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_kw_grdecl.h b/lib/include/ert/ecl/ecl_kw_grdecl.h deleted file mode 100644 index ba7ad2f50b..0000000000 --- a/lib/include/ert/ecl/ecl_kw_grdecl.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_kw_grdecl.hpp b/lib/include/ert/ecl/ecl_kw_grdecl.hpp deleted file mode 100644 index e60ae89bb0..0000000000 --- a/lib/include/ert/ecl/ecl_kw_grdecl.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - This header does not define datatypes; just a couple of functions. It should - be included from the ecl_kw.h header, so applications do not need to include this - header explicitly. -*/ - -#ifndef ERT_ECL_KW_GRDECL_H -#define ERT_ECL_KW_GRDECL_H -#ifdef __cplusplus -extern "C" { -#endif - -bool ecl_kw_grdecl_fseek_kw(const char *, bool, FILE *); - -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_dynamic__(FILE *stream, const char *kw, - bool strict, ecl_data_type); -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_dynamic(FILE *stream, const char *kw, - ecl_data_type); - -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_data__(FILE *stream, bool strict, - int size, - ecl_data_type data_type); -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_data(FILE *stream, int size, - ecl_data_type data_type); - -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl__(FILE *stream, const char *kw, - bool strict, int size, - ecl_data_type data_type); -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl(FILE *stream, const char *kw, int size, - ecl_data_type data_type); - -ecl_kw_type *ecl_kw_fscanf_alloc_current_grdecl__(FILE *stream, bool strict, - ecl_data_type data_type); -ecl_kw_type *ecl_kw_fscanf_alloc_current_grdecl(FILE *stream, - ecl_data_type data_type); - -bool ecl_kw_grdecl_fseek_next_kw(FILE *stream); -char *ecl_kw_grdecl_alloc_next_header(FILE *stream); - -void ecl_kw_fprintf_grdecl(const ecl_kw_type *ecl_kw, FILE *stream); -void ecl_kw_fprintf_grdecl__(const ecl_kw_type *ecl_kw, - const char *special_header, FILE *stream); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_kw_magic.h b/lib/include/ert/ecl/ecl_kw_magic.h deleted file mode 100644 index 4c386d93e5..0000000000 --- a/lib/include/ert/ecl/ecl_kw_magic.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_nnc_data.h b/lib/include/ert/ecl/ecl_nnc_data.h deleted file mode 100644 index 6e7da9d832..0000000000 --- a/lib/include/ert/ecl/ecl_nnc_data.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_nnc_data.hpp b/lib/include/ert/ecl/ecl_nnc_data.hpp deleted file mode 100644 index 1afb0efb8d..0000000000 --- a/lib/include/ert/ecl/ecl_nnc_data.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef ECL_NNC_DATA_H -#define ECL_NNC_DATA_H - -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_nnc_data_struct ecl_nnc_data_type; - -ecl_nnc_data_type *ecl_nnc_data_alloc_tran(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file); -ecl_nnc_data_type * -ecl_nnc_data_alloc_wat_flux(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file); -ecl_nnc_data_type * -ecl_nnc_data_alloc_oil_flux(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file); -ecl_nnc_data_type * -ecl_nnc_data_alloc_gas_flux(const ecl_grid_type *grid, - const ecl_nnc_geometry_type *nnc_geo, - const ecl_file_view_type *init_file); -void ecl_nnc_data_free(ecl_nnc_data_type *data); - -int ecl_nnc_data_get_size(ecl_nnc_data_type *data); -const double *ecl_nnc_data_get_values(const ecl_nnc_data_type *data); - -double ecl_nnc_data_iget_value(const ecl_nnc_data_type *data, int index); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_nnc_export.h b/lib/include/ert/ecl/ecl_nnc_export.h deleted file mode 100644 index 06248e151f..0000000000 --- a/lib/include/ert/ecl/ecl_nnc_export.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_nnc_export.hpp b/lib/include/ert/ecl/ecl_nnc_export.hpp deleted file mode 100644 index 73056e724a..0000000000 --- a/lib/include/ert/ecl/ecl_nnc_export.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef ERT_ECL_NNC_EXPORT -#define ERT_ECL_NNC_EXPORT - -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define ERT_ECL_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; -} ecl_nnc_type; - -bool ecl_nnc_intersect_format(const ecl_grid_type *grid, - const ecl_file_type *init_file); -int ecl_nnc_export_get_size(const ecl_grid_type *grid, - const ecl_file_type *init_file); -int ecl_nnc_export(const ecl_grid_type *grid, const ecl_file_type *init_file, - ecl_nnc_type *nnc_data); - -ecl_kw_type *ecl_nnc_export_get_tranx_kw(const ecl_grid_type *grid, - const ecl_file_type *init_file, - int lgr_nr1, int lgr_nr2); -ecl_kw_type *ecl_nnc_export_get_tranll_kw(const ecl_grid_type *grid, - const ecl_file_type *init_file, - int lgr_nr1, int lgr_nr2); -ecl_kw_type *ecl_nnc_export_get_tran_kw(const ecl_file_type *init_file, - const char *kw, int lgr_nr); - -bool ecl_nnc_equal(const ecl_nnc_type *nnc1, const ecl_nnc_type *nnc2); -int ecl_nnc_sort_cmp(const ecl_nnc_type *nnc1, const ecl_nnc_type *nnc2); -void ecl_nnc_sort(ecl_nnc_type *nnc_list, int size); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_nnc_geometry.h b/lib/include/ert/ecl/ecl_nnc_geometry.h deleted file mode 100644 index faf16573d7..0000000000 --- a/lib/include/ert/ecl/ecl_nnc_geometry.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_nnc_geometry.hpp b/lib/include/ert/ecl/ecl_nnc_geometry.hpp deleted file mode 100644 index ad3648833f..0000000000 --- a/lib/include/ert/ecl/ecl_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 ecl_nnc_geometry_struct ecl_nnc_geometry_type; -typedef struct ecl_nnc_pair_struct ecl_nnc_pair_type; - -struct ecl_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(ecl_nnc_geometry); -void ecl_nnc_geometry_free(ecl_nnc_geometry_type *nnc_geo); -ecl_nnc_geometry_type *ecl_nnc_geometry_alloc(const ecl_grid_type *grid); -int ecl_nnc_geometry_size(const ecl_nnc_geometry_type *nnc_geo); -const ecl_nnc_pair_type * -ecl_nnc_geometry_iget(const ecl_nnc_geometry_type *nnc_geo, int index); -bool ecl_nnc_geometry_same_kw(const ecl_nnc_pair_type *nnc1, - const ecl_nnc_pair_type *nnc2); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_region.h b/lib/include/ert/ecl/ecl_region.h deleted file mode 100644 index 2caa8c8343..0000000000 --- a/lib/include/ert/ecl/ecl_region.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_region.hpp b/lib/include/ert/ecl/ecl_region.hpp deleted file mode 100644 index 4a23e4fe99..0000000000 --- a/lib/include/ert/ecl/ecl_region.hpp +++ /dev/null @@ -1,261 +0,0 @@ -#ifndef ERT_ECL_REGION_H -#define ERT_ECL_REGION_H -#include - -#include - -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - SELECT_ALL = 0, - DESELECT_ALL = 1, - SELECT_FROM_IJK = 2, - DESELECT_FROM_IJK = 3, - SELECT_FROM_I = 4, - DSELECT_FROM_I = 5, - SELECT_FROM_J = 6, - DSELECT_FROM_J = 7, - SELECT_FROM_K = 8, - DSELECT_FROM_K = 9, - SELECT_EQUAL = 10, - DESELECT_EQUAL = 11, - SELECT_IN_INTERVAL = 12, - DESELECT_IN_INTERVAL = 13, - INVERT_SELECTION = 14 -} ecl_region_select_cmd; - -typedef struct ecl_region_struct ecl_region_type; - -void ecl_region_unlock(ecl_region_type *region); -void ecl_region_lock(ecl_region_type *region); -void ecl_region_reset(ecl_region_type *ecl_region); -ecl_region_type *ecl_region_alloc_copy(const ecl_region_type *ecl_region); -ecl_region_type *ecl_region_alloc(const ecl_grid_type *ecl_grid, - bool preselect); -void ecl_region_free(ecl_region_type *region); -void ecl_region_free__(void *__region); - -const int_vector_type *ecl_region_get_active_list(ecl_region_type *region); -const int_vector_type *ecl_region_get_global_list(ecl_region_type *region); -const int_vector_type * -ecl_region_get_global_active_list(ecl_region_type *region); - -bool ecl_region_contains_ijk(const ecl_region_type *ecl_region, int i, int j, - int k); -bool ecl_region_contains_global(const ecl_region_type *ecl_region, - int global_index); -bool ecl_region_contains_active(const ecl_region_type *ecl_region, - int active_index); - -void ecl_region_select_true(ecl_region_type *region, const ecl_kw_type *ecl_kw); - -void ecl_region_invert_selection(ecl_region_type *region); -void ecl_region_select_all(ecl_region_type *region); -void ecl_region_deselect_all(ecl_region_type *region); -void ecl_region_deselect_true(ecl_region_type *region, - const ecl_kw_type *ecl_kw); -void ecl_region_select_false(ecl_region_type *region, - const ecl_kw_type *ecl_kw); - -void ecl_region_select_in_interval(ecl_region_type *region, - const ecl_kw_type *ecl_kw, float min_value, - float max_value); -void ecl_region_deselect_in_interval(ecl_region_type *region, - const ecl_kw_type *ecl_kw, float min_value, - float max_value); - -void ecl_region_select_equal(ecl_region_type *region, const ecl_kw_type *ecl_kw, - int value); -void ecl_region_deselect_equal(ecl_region_type *region, - const ecl_kw_type *ecl_kw, int value); - -void ecl_region_select_inactive_cells(ecl_region_type *region); -void ecl_region_deselect_inactive_cells(ecl_region_type *region); -void ecl_region_select_active_cells(ecl_region_type *region); -void ecl_region_deselect_active_cells(ecl_region_type *region); - -void ecl_region_select_from_ijkbox(ecl_region_type *region, int i1, int i2, - int j1, int j2, int k1, int k2); -void ecl_region_deselect_from_ijkbox(ecl_region_type *region, int i1, int i2, - int j1, int j2, int k1, int k2); - -void ecl_region_select_i1i2(ecl_region_type *region, int i1, int i2); -void ecl_region_deselect_i1i2(ecl_region_type *region, int i1, int i2); -void ecl_region_select_j1j2(ecl_region_type *region, int j1, int j2); -void ecl_region_deselect_j1j2(ecl_region_type *region, int j1, int i2); -void ecl_region_select_k1k2(ecl_region_type *region, int k1, int k2); -void ecl_region_deselect_k1k2(ecl_region_type *region, int k1, int i2); - -void ecl_region_select_shallow_cells(ecl_region_type *region, - double depth_limit); -void ecl_region_deselect_shallow_cells(ecl_region_type *region, - double depth_limit); -void ecl_region_select_deep_cells(ecl_region_type *region, double depth_limit); -void ecl_region_deselect_deep_cells(ecl_region_type *region, - double depth_limit); - -void ecl_region_select_thin_cells(ecl_region_type *ecl_region, double dz_limit); -void ecl_region_deselect_thin_cells(ecl_region_type *ecl_region, - double dz_limit); -void ecl_region_select_thick_cells(ecl_region_type *ecl_region, - double dz_limit); -void ecl_region_deselect_thick_cells(ecl_region_type *ecl_region, - double dz_limit); - -void ecl_region_select_small_cells(ecl_region_type *ecl_region, - double volum_limit); -void ecl_region_deselect_small_cells(ecl_region_type *ecl_region, - double volum_limit); -void ecl_region_select_large_cells(ecl_region_type *ecl_region, - double volum_limit); -void ecl_region_deselect_large_cells(ecl_region_type *ecl_region, - double volum_limit); - -void ecl_region_select_global_index(ecl_region_type *ecl_region, - int global_index); -void ecl_region_deselect_global_index(ecl_region_type *ecl_region, - int global_index); - -void ecl_region_select_active_index(ecl_region_type *ecl_region, - int active_index); -void ecl_region_deselect_active_index(ecl_region_type *ecl_region, - int active_index); - -void ecl_region_intersection(ecl_region_type *region, - const ecl_region_type *new_region); -void ecl_region_union(ecl_region_type *region, - const ecl_region_type *new_region); -void ecl_region_subtract(ecl_region_type *region, - const ecl_region_type *new_region); -void ecl_region_xor(ecl_region_type *region, const ecl_region_type *new_region); - -void ecl_region_select_smaller(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit); -void ecl_region_deselect_smaller(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit); -void ecl_region_select_larger(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit); -void ecl_region_deselect_larger(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, float limit); - -void ecl_region_cmp_select_less(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, const ecl_kw_type *kw2); -void ecl_region_cmp_deselect_less(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2); -void ecl_region_cmp_select_more(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, const ecl_kw_type *kw2); -void ecl_region_cmp_deselect_more(ecl_region_type *ecl_region, - const ecl_kw_type *kw1, - const ecl_kw_type *kw2); - -void ecl_region_select_in_cylinder(ecl_region_type *region, double x0, - double y0, double R); -void ecl_region_deselect_in_cylinder(ecl_region_type *region, double x0, - double y0, double R); -void ecl_region_select_in_zcylinder(ecl_region_type *region, double x0, - double y0, double R, double z1, double z2); -void ecl_region_deselect_in_zcylinder(ecl_region_type *region, double x0, - double y0, double R, double z1, - double z2); - -void ecl_region_select_above_plane(ecl_region_type *region, const double n[3], - const double p[3]); -void ecl_region_select_below_plane(ecl_region_type *region, const double n[3], - const double p[3]); -void ecl_region_deselect_above_plane(ecl_region_type *region, const double n[3], - const double p[3]); -void ecl_region_deselect_below_plane(ecl_region_type *region, const double n[3], - const double p[3]); - -void ecl_region_select_inside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon); -void ecl_region_deselect_inside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon); -void ecl_region_select_outside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon); -void ecl_region_deselect_outside_polygon(ecl_region_type *region, - const geo_polygon_type *polygon); - -void ecl_region_select_from_layer(ecl_region_type *region, - const layer_type *layer, int k, - int layer_value); -void ecl_region_deselect_from_layer(ecl_region_type *region, - const layer_type *layer, int k, - int layer_value); -void ecl_region_deselect_false(ecl_region_type *region, - const ecl_kw_type *ecl_kw); - -void ecl_region_set_kw_int(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - int value, bool force_active); -void ecl_region_set_kw_float(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - float value, bool force_active); -void ecl_region_set_kw_double(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - double value, bool force_active); -void ecl_region_kw_copy(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *src_kw, bool force_active); -int ecl_region_get_kw_size(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active); - -void ecl_region_kw_iadd(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *delta_kw, bool force_active); -void ecl_region_kw_idiv(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *div_kw, bool force_active); -void ecl_region_kw_imul(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *mul_kw, bool force_active); -void ecl_region_kw_isub(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - const ecl_kw_type *delta_kw, bool force_active); - -bool ecl_region_equal(const ecl_region_type *region1, - const ecl_region_type *region2); - -void ecl_region_scale_kw_float(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - float value, bool force_active); -void ecl_region_scale_kw_double(ecl_region_type *ecl_region, - ecl_kw_type *ecl_kw, double value, - bool force_active); -void ecl_region_scale_kw_int(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - int value, bool force_active); -void ecl_region_shift_kw_int(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - int value, bool force_active); -void ecl_region_shift_kw_double(ecl_region_type *ecl_region, - ecl_kw_type *ecl_kw, double value, - bool force_active); -void ecl_region_shift_kw_float(ecl_region_type *ecl_region, ecl_kw_type *ecl_kw, - float value, bool force_active); - -const int_vector_type *ecl_region_get_kw_index_list(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, - bool force_active); - -void ecl_region_set_name(ecl_region_type *region, const char *name); -const char *ecl_region_get_name(const ecl_region_type *region); - -int ecl_region_get_active_size_cpp(ecl_region_type *region); -int ecl_region_get_global_size_cpp(ecl_region_type *region); -const int *ecl_region_get_active_list_cpp(ecl_region_type *region); -const int *ecl_region_get_global_list_cpp(ecl_region_type *region); - -double ecl_region_sum_kw_double(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active); -int ecl_region_sum_kw_int(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active); -float ecl_region_sum_kw_float(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active); -int ecl_region_sum_kw_bool(ecl_region_type *ecl_region, - const ecl_kw_type *ecl_kw, bool force_active); - -UTIL_IS_INSTANCE_HEADER(ecl_region); -UTIL_SAFE_CAST_HEADER(ecl_region); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_rft_cell.h b/lib/include/ert/ecl/ecl_rft_cell.h deleted file mode 100644 index 8575851ff3..0000000000 --- a/lib/include/ert/ecl/ecl_rft_cell.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_rft_cell.hpp b/lib/include/ert/ecl/ecl_rft_cell.hpp deleted file mode 100644 index a730d6e9ee..0000000000 --- a/lib/include/ert/ecl/ecl_rft_cell.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef ERT_ECL_RFT_CELL_H -#define ERT_ECL_RFT_CELL_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define ECL_RFT_CELL_INVALID_VALUE -1 - -typedef struct ecl_rft_cell_struct ecl_rft_cell_type; - -UTIL_IS_INSTANCE_HEADER(ecl_rft_cell); - -ecl_rft_cell_type * -ecl_rft_cell_alloc_PLT(int i, int j, int k, double depth, double pressure, - double orat, double grat, double wrat, - double connection_start, double connection_end, - double flowrate, double oil_flowrate, - double gas_flowrate, double water_flowrate); - -ecl_rft_cell_type *ecl_rft_cell_alloc_RFT(int i, int j, int k, double depth, - double pressure, double swat, - double sgas); -void ecl_rft_cell_free(ecl_rft_cell_type *cell); -void ecl_rft_cell_free__(void *arg); - -bool ecl_rft_cell_ijk_equal(const ecl_rft_cell_type *cell, int i, int j, int k); -void ecl_rft_cell_get_ijk(const ecl_rft_cell_type *cell, int *i, int *j, - int *k); -int ecl_rft_cell_get_i(const ecl_rft_cell_type *cell); -int ecl_rft_cell_get_j(const ecl_rft_cell_type *cell); -int ecl_rft_cell_get_k(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_depth(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_pressure(const ecl_rft_cell_type *cell); - -double ecl_rft_cell_get_swat(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_sgas(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_soil(const ecl_rft_cell_type *cell); - -double ecl_rft_cell_get_wrat(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_grat(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_orat(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_connection_start(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_connection_end(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_flowrate(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_oil_flowrate(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_gas_flowrate(const ecl_rft_cell_type *cell); -double ecl_rft_cell_get_water_flowrate(const ecl_rft_cell_type *cell); - -int ecl_rft_cell_cmp__(const void *arg1, const void *arg2); -int ecl_rft_cell_cmp(const ecl_rft_cell_type *cell1, - const ecl_rft_cell_type *cell2); -bool ecl_rft_cell_lt(const ecl_rft_cell_type *cell1, - const ecl_rft_cell_type *cell2); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/include/ert/ecl/ecl_rft_file.h b/lib/include/ert/ecl/ecl_rft_file.h deleted file mode 100644 index b90f8007ec..0000000000 --- a/lib/include/ert/ecl/ecl_rft_file.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_rft_file.hpp b/lib/include/ert/ecl/ecl_rft_file.hpp deleted file mode 100644 index e172b4e9ab..0000000000 --- a/lib/include/ert/ecl/ecl_rft_file.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef ERT_ECL_RFT_FILE_H -#define ERT_ECL_RFT_FILE_H -#ifdef __cplusplus -extern "C" { -#endif -#include - -#include - -#include -#include -#include - -typedef struct ecl_rft_file_struct ecl_rft_file_type; - -char *ecl_rft_file_alloc_case_filename(const char *case_input); -const char *ecl_rft_file_get_filename(const ecl_rft_file_type *rft_file); -ecl_rft_file_type *ecl_rft_file_alloc_case(const char *case_input); -bool ecl_rft_file_case_has_rft(const char *case_input); -ecl_rft_file_type *ecl_rft_file_alloc(const char *); -void ecl_rft_file_free(ecl_rft_file_type *); -void ecl_rft_file_block(const ecl_rft_file_type *, double, const char *, int, - const double *, int *, int *, int *); -void ecl_rft_file_fprintf_rft_obs(const ecl_rft_file_type *, double, - const char *, const char *, const char *, - double); -ecl_rft_node_type *ecl_rft_file_get_node(const ecl_rft_file_type *, - const char *); - -int ecl_rft_file_get_size__(const ecl_rft_file_type *rft_file, - const char *well_pattern, time_t recording_time); -int ecl_rft_file_get_size(const ecl_rft_file_type *rft_file); -ecl_rft_node_type * -ecl_rft_file_get_well_time_rft(const ecl_rft_file_type *rft_file, - const char *well, time_t recording_time); -ecl_rft_node_type *ecl_rft_file_iget_node(const ecl_rft_file_type *rft_file, - int index); -ecl_rft_node_type *ecl_rft_file_iget_well_rft(const ecl_rft_file_type *rft_file, - const char *well, int index); -bool ecl_rft_file_has_well(const ecl_rft_file_type *rft_file, const char *well); -int ecl_rft_file_get_well_occurences(const ecl_rft_file_type *rft_file, - const char *well); -stringlist_type * -ecl_rft_file_alloc_well_list(const ecl_rft_file_type *rft_file); -int ecl_rft_file_get_num_wells(const ecl_rft_file_type *rft_file); -void ecl_rft_file_free__(void *arg); -void ecl_rft_file_update(const char *rft_file_name, ecl_rft_node_type **nodes, - int num_nodes, ert_ecl_unit_enum unit_set); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_rft_node.h b/lib/include/ert/ecl/ecl_rft_node.h deleted file mode 100644 index 22c878d448..0000000000 --- a/lib/include/ert/ecl/ecl_rft_node.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_rft_node.hpp b/lib/include/ert/ecl/ecl_rft_node.hpp deleted file mode 100644 index 98dc5c2253..0000000000 --- a/lib/include/ert/ecl/ecl_rft_node.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef ERT_ECL_RFT_NODE_H -#define ERT_ECL_RFT_NODE_H -#ifdef __cplusplus -extern "C" { -#endif -#include - -#include -#include -#include - -typedef enum { - RFT = 1, - PLT = 2, - SEGMENT = 3 /* Not really implemented */ -} ecl_rft_enum; - -typedef struct ecl_rft_node_struct ecl_rft_node_type; - -void ecl_rft_node_inplace_sort_cells(ecl_rft_node_type *rft_node); -const ecl_rft_cell_type * -ecl_rft_node_iget_cell_sorted(ecl_rft_node_type *rft_node, int index); -const ecl_rft_cell_type * -ecl_rft_node_iget_cell(const ecl_rft_node_type *rft_node, int index); -const ecl_rft_cell_type * -ecl_rft_node_lookup_ijk(const ecl_rft_node_type *rft_node, int i, int j, int k); -void ecl_rft_node_fprintf_rft_obs(const ecl_rft_node_type *, double, - const char *, const char *, double); -ecl_rft_node_type *ecl_rft_node_alloc(const ecl_file_view_type *rft_view); -void ecl_rft_node_free(ecl_rft_node_type *); -void ecl_rft_node_free__(void *); -time_t ecl_rft_node_get_date(const ecl_rft_node_type *); -int ecl_rft_node_get_size(const ecl_rft_node_type *); -const char *ecl_rft_node_get_well_name(const ecl_rft_node_type *rft_node); -void ecl_rft_node_iget_ijk(const ecl_rft_node_type *rft_node, int index, int *i, - int *j, int *k); - -bool ecl_rft_node_is_RFT(const ecl_rft_node_type *rft_node); -bool ecl_rft_node_is_PLT(const ecl_rft_node_type *rft_node); -bool ecl_rft_node_is_SEGMENT(const ecl_rft_node_type *rft_node); -bool ecl_rft_node_is_MSW(const ecl_rft_node_type *rft_node); - -double ecl_rft_node_iget_pressure(const ecl_rft_node_type *rft_node, int index); -double ecl_rft_node_iget_depth(const ecl_rft_node_type *rft_node, int index); -double ecl_rft_node_iget_wrat(const ecl_rft_node_type *rft_node, int index); -double ecl_rft_node_iget_grat(const ecl_rft_node_type *rft_node, int index); -double ecl_rft_node_iget_orat(const ecl_rft_node_type *rft_node, int index); - -double ecl_rft_node_iget_swat(const ecl_rft_node_type *rft_node, int index); -double ecl_rft_node_iget_sgas(const ecl_rft_node_type *rft_node, int index); -double ecl_rft_node_iget_soil(const ecl_rft_node_type *rft_node, int index); -void ecl_rft_node_fwrite(const ecl_rft_node_type *rft_node, fortio_type *fortio, - ert_ecl_unit_enum unit_set); -double ecl_rft_node_get_days(const ecl_rft_node_type *rft_node); -int ecl_rft_node_cmp(const ecl_rft_node_type *n1, const ecl_rft_node_type *n2); -bool ecl_rft_node_lt(const ecl_rft_node_type *n1, const ecl_rft_node_type *n2); - -void ecl_rft_node_append_cell(ecl_rft_node_type *rft_node, - ecl_rft_cell_type *cell); -ecl_rft_node_type *ecl_rft_node_alloc_new(const char *well_name, - const char *data_type_string, - const time_t recording_date, - const double days); - -ecl_rft_enum ecl_rft_node_get_type(const ecl_rft_node_type *rft_node); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_rst_file.h b/lib/include/ert/ecl/ecl_rst_file.h deleted file mode 100644 index 1b74189557..0000000000 --- a/lib/include/ert/ecl/ecl_rst_file.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_rst_file.hpp b/lib/include/ert/ecl/ecl_rst_file.hpp deleted file mode 100644 index 61feb2d994..0000000000 --- a/lib/include/ert/ecl/ecl_rst_file.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef ERT_ECL_RST_FILE_H -#define ERT_ECL_RST_FILE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_rst_file_struct ecl_rst_file_type; - -ecl_rst_file_type *ecl_rst_file_open_read(const char *filename); -ecl_rst_file_type *ecl_rst_file_open_write(const char *filename); -ecl_rst_file_type *ecl_rst_file_open_append(const char *filename); -ecl_rst_file_type *ecl_rst_file_open_write_seek(const char *filename, - int report_step); -void ecl_rst_file_close(ecl_rst_file_type *rst_file); - -void ecl_rst_file_start_solution(ecl_rst_file_type *rst_file); -void ecl_rst_file_end_solution(ecl_rst_file_type *rst_file); -void ecl_rst_file_fwrite_header(ecl_rst_file_type *rst_file, int seqnum, - ecl_rsthead_type *rsthead_data); -void ecl_rst_file_add_kw(ecl_rst_file_type *rst_file, - const ecl_kw_type *ecl_kw); -offset_type ecl_rst_file_ftell(const ecl_rst_file_type *rst_file); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/include/ert/ecl/ecl_rsthead.h b/lib/include/ert/ecl/ecl_rsthead.h deleted file mode 100644 index 9a7f4b6f2e..0000000000 --- a/lib/include/ert/ecl/ecl_rsthead.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_smspec.h b/lib/include/ert/ecl/ecl_smspec.h deleted file mode 100644 index 750735a97c..0000000000 --- a/lib/include/ert/ecl/ecl_smspec.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_smspec.hpp b/lib/include/ert/ecl/ecl_smspec.hpp deleted file mode 100644 index 93b140f675..0000000000 --- a/lib/include/ert/ecl/ecl_smspec.hpp +++ /dev/null @@ -1,225 +0,0 @@ -#ifndef ERT_ECL_SMSPEC -#define ERT_ECL_SMSPEC - -#include -#include - -#include -#include - -#include -#include - -typedef struct ecl_smspec_struct ecl_smspec_type; - -#ifdef __cplusplus -#include -const std::vector & -ecl_smspec_get_params_default(const ecl_smspec_type *ecl_smspec); -const ecl::smspec_node & -ecl_smspec_get_well_var_node(const ecl_smspec_type *smspec, const char *well, - const char *var); -const ecl::smspec_node & -ecl_smspec_get_group_var_node(const ecl_smspec_type *smspec, const char *group, - const char *var); -const ecl::smspec_node & -ecl_smspec_get_field_var_node(const ecl_smspec_type *smspec, const char *var); -const ecl::smspec_node & -ecl_smspec_get_region_var_node(const ecl_smspec_type *ecl_smspec, - const char *region_var, int region_nr); -const ecl::smspec_node & -ecl_smspec_get_misc_var_node(const ecl_smspec_type *ecl_smspec, - const char *var); -const ecl::smspec_node & -ecl_smspec_get_block_var_node(const ecl_smspec_type *ecl_smspec, - const char *block_var, int block_nr); -const ecl::smspec_node & -ecl_smspec_get_block_var_node_ijk(const ecl_smspec_type *ecl_smspec, - const char *block_var, int i, int j, int k); -const ecl::smspec_node & -ecl_smspec_get_well_completion_var_node(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var, - int cell_nr); -const ecl::smspec_node & -ecl_smspec_get_general_var_node(const ecl_smspec_type *smspec, - const char *lookup_kw); -const ecl::smspec_node & -ecl_smspec_iget_node_w_node_index(const ecl_smspec_type *smspec, - int node_index); -const ecl::smspec_node & -ecl_smspec_iget_node_w_params_index(const ecl_smspec_type *smspec, - int params_index); -const ecl::smspec_node &ecl_smspec_iget_node(const ecl_smspec_type *smspec, - int index); -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - These are the different variable types, see table 3.4 in the - ECLIPFE file format docuemntation for naming conventions. - - Only the variable types marked with "X" below are supported in the - remaining implementation. To add support for a new variable type - the functions smspec_node_alloc(), ecl_smsepec_fread_header() and - ecl_smspec_install_gen_key() must be updated. -*/ - -int *ecl_smspec_alloc_mapping(const ecl_smspec_type *self, - const ecl_smspec_type *other); -const int *ecl_smspec_get_index_map(const ecl_smspec_type *smspec); -ecl_smspec_var_type ecl_smspec_iget_var_type(const ecl_smspec_type *smspec, - int index); -bool ecl_smspec_needs_num(ecl_smspec_var_type var_type); -bool ecl_smspec_needs_wgname(ecl_smspec_var_type var_type); -const char *ecl_smspec_get_var_type_name(ecl_smspec_var_type var_type); -ecl_smspec_var_type ecl_smspec_identify_var_type(const char *var); -ecl_smspec_type *ecl_smspec_alloc_empty(bool write_mode, - const char *key_join_string); - -ecl_smspec_type *ecl_smspec_alloc_restart_writer( - const char *key_join_string, const char *restart_case, int restart_step, - time_t sim_start, bool time_in_days, int nx, int ny, int nz); - -ecl_smspec_type *ecl_smspec_alloc_writer(const char *key_join_string, - time_t sim_start, bool time_in_days, - int nx, int ny, int nz); -void ecl_smspec_fwrite(const ecl_smspec_type *smspec, const char *ecl_case, - bool fmt_file); - -ecl_smspec_type *ecl_smspec_fread_alloc(const char *header_file, - const char *key_join_string, - bool include_restart); -void ecl_smspec_free(ecl_smspec_type *); - -int ecl_smspec_get_date_day_index(const ecl_smspec_type *smspec); -int ecl_smspec_get_date_month_index(const ecl_smspec_type *smspec); -int ecl_smspec_get_date_year_index(const ecl_smspec_type *smspec); - -int ecl_smspec_get_well_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var); -bool ecl_smspec_has_well_var(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var); - -int ecl_smspec_get_group_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *group, const char *var); -bool ecl_smspec_has_group_var(const ecl_smspec_type *ecl_smspec, - const char *group, const char *var); - -int ecl_smspec_get_field_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *var); -bool ecl_smspec_has_field_var(const ecl_smspec_type *ecl_smspec, - const char *var); - -int ecl_smspec_get_region_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *region_var, - int region_nr); -bool ecl_smspec_has_region_var(const ecl_smspec_type *ecl_smspec, - const char *region_var, int region_nr); - -int ecl_smspec_get_misc_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *var); -bool ecl_smspec_has_misc_var(const ecl_smspec_type *ecl_smspec, - const char *var); - -int ecl_smspec_get_block_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *block_var, int block_nr); -bool ecl_smspec_has_block_var(const ecl_smspec_type *ecl_smspec, - const char *block_var, int block_nr); - -int ecl_smspec_get_block_var_params_index_ijk(const ecl_smspec_type *ecl_smspec, - const char *block_var, int i, - int j, int k); -bool ecl_smspec_has_block_var_ijk(const ecl_smspec_type *ecl_smspec, - const char *block_var, int i, int j, int k); - -int ecl_smspec_get_well_completion_var_params_index( - const ecl_smspec_type *ecl_smspec, const char *well, const char *var, - int cell_nr); -bool ecl_smspec_has_well_completion_var(const ecl_smspec_type *ecl_smspec, - const char *well, const char *var, - int cell_nr); - -int ecl_smspec_get_general_var_params_index(const ecl_smspec_type *ecl_smspec, - const char *lookup_kw); -bool ecl_smspec_has_general_var(const ecl_smspec_type *ecl_smspec, - const char *lookup_kw); -const char *ecl_smspec_get_general_var_unit(const ecl_smspec_type *ecl_smspec, - const char *lookup_kw); - -void ecl_smspec_select_matching_general_var_list(const ecl_smspec_type *smspec, - const char *pattern, - stringlist_type *keys); -stringlist_type * -ecl_smspec_alloc_matching_general_var_list(const ecl_smspec_type *smspec, - const char *pattern); - -int ecl_smspec_get_time_seconds(const ecl_smspec_type *ecl_smspec); -int ecl_smspec_get_time_index(const ecl_smspec_type *ecl_smspec); -time_t ecl_smspec_get_start_time(const ecl_smspec_type *); -bool ecl_smspec_get_formatted(const ecl_smspec_type *ecl_smspec); -const char *ecl_smspec_get_header_file(const ecl_smspec_type *ecl_smspec); -stringlist_type *ecl_smspec_alloc_well_list(const ecl_smspec_type *smspec, - const char *pattern); -stringlist_type *ecl_smspec_alloc_group_list(const ecl_smspec_type *smspec, - const char *pattern); -stringlist_type *ecl_smspec_alloc_well_var_list(const ecl_smspec_type *smspec); -const char *ecl_smspec_get_simulation_path(const ecl_smspec_type *ecl_smspec); -int ecl_smspec_get_first_step(const ecl_smspec_type *ecl_smspec); -int ecl_smspec_get_restart_step(const ecl_smspec_type *ecl_smspec); -const char *ecl_smspec_get_restart_case(const ecl_smspec_type *ecl_smspec); -const char *ecl_smspec_get_join_string(const ecl_smspec_type *smspec); - -const int *ecl_smspec_get_grid_dims(const ecl_smspec_type *smspec); -int ecl_smspec_get_params_size(const ecl_smspec_type *smspec); -int ecl_smspec_num_nodes(const ecl_smspec_type *smspec); - -char *ecl_smspec_alloc_well_key(const ecl_smspec_type *smspec, - const char *keyword, const char *wgname); -bool ecl_smspec_equal(const ecl_smspec_type *self, - const ecl_smspec_type *other); - -// void ecl_smspec_sort( ecl_smspec_type * smspec ); -ert_ecl_unit_enum ecl_smspec_get_unit_system(const ecl_smspec_type *smspec); - -#ifdef __cplusplus -} -#endif - -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const ecl::smspec_node &node); -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, int num, - const char *unit, - float default_value); -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, - const char *unit, - float default_value); -const ecl::smspec_node * -ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, const char *keyword, - const char *wgname, const char *unit, float default_value); -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, - const char *wgname, int num, - const char *unit, - float default_value); -const ecl::smspec_node *ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, - const char *keyword, int num, - const char *unit, - float default_value); - -const ecl::smspec_node * -ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, int params_index, - const char *keyword, const char *wgname, int num, - const char *unit, float default_value); - -const ecl::smspec_node * -ecl_smspec_add_node(ecl_smspec_type *ecl_smspec, int params_index, - const char *keyword, const char *wgname, int num, - const char *unit, const char *lgr, int lgr_i, int lgr_j, - int lgr_k, float default_value); - -#endif diff --git a/lib/include/ert/ecl/ecl_subsidence.h b/lib/include/ert/ecl/ecl_subsidence.h deleted file mode 100644 index 2f5386bf3e..0000000000 --- a/lib/include/ert/ecl/ecl_subsidence.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_subsidence.hpp b/lib/include/ert/ecl/ecl_subsidence.hpp deleted file mode 100644 index b5f3d8441d..0000000000 --- a/lib/include/ert/ecl/ecl_subsidence.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef ERT_ECL_SUBSIDENCE_H -#define ERT_ECL_SUBSIDENCE_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -typedef struct ecl_subsidence_struct ecl_subsidence_type; -typedef struct ecl_subsidence_survey_struct ecl_subsidence_survey_type; - -void ecl_subsidence_free(ecl_subsidence_type *ecl_subsidence_config); -ecl_subsidence_type *ecl_subsidence_alloc(const ecl_grid_type *ecl_grid, - const ecl_file_type *init_file); -ecl_subsidence_survey_type * -ecl_subsidence_add_survey_PRESSURE(ecl_subsidence_type *subsidence, - const char *name, - const ecl_file_view_type *restart_view); - -bool ecl_subsidence_has_survey(const ecl_subsidence_type *subsidence, - const char *name); -double ecl_subsidence_eval(const ecl_subsidence_type *subsidence, - const char *base, const char *monitor, - ecl_region_type *region, double utm_x, double utm_y, - double depth, double compressibility, - double poisson_ratio); - -double ecl_subsidence_eval_geertsma(const ecl_subsidence_type *subsidence, - const char *base, const char *monitor, - ecl_region_type *region, double utm_x, - double utm_y, double depth, - double youngs_modulus, double poisson_ratio, - double seabed); - -double ecl_subsidence_eval_geertsma_rporv(const ecl_subsidence_type *subsidence, - const char *base, const char *monitor, - ecl_region_type *region, double utm_x, - double utm_y, double depth, - double youngs_modulus, - double poisson_ratio, double seabed); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_sum.hpp b/lib/include/ert/ecl/ecl_sum.hpp deleted file mode 100644 index 6542182cef..0000000000 --- a/lib/include/ert/ecl/ecl_sum.hpp +++ /dev/null @@ -1,322 +0,0 @@ -#ifndef ERT_ECL_SUM_H -#define ERT_ECL_SUM_H - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - char *locale; - const char *sep; - const char *newline; - const char *value_fmt; - const char *date_fmt; - const char *days_fmt; - const char *header_fmt; - bool print_header; - bool print_dash; - const char *date_header; - const char *date_dash; - const char *value_dash; -} ecl_sum_fmt_type; - -typedef struct ecl_sum_vector_struct ecl_sum_vector_type; - -typedef struct ecl_sum_struct ecl_sum_type; - -void ecl_sum_fmt_init_summary_x(const ecl_sum_type *ecl_sum, - ecl_sum_fmt_type *fmt); -double ecl_sum_get_from_sim_time(const ecl_sum_type *ecl_sum, time_t sim_time, - const ecl::smspec_node *node); -double ecl_sum_get_from_sim_days(const ecl_sum_type *ecl_sum, double sim_days, - const ecl::smspec_node *node); -double ecl_sum_time2days(const ecl_sum_type *ecl_sum, time_t sim_time); - -void ecl_sum_set_unified(ecl_sum_type *ecl_sum, bool unified); -void ecl_sum_set_fmt_case(ecl_sum_type *ecl_sum, bool fmt_case); - -int ecl_sum_get_report_step_from_time(const ecl_sum_type *sum, time_t sim_time); -int ecl_sum_get_report_step_from_days(const ecl_sum_type *sum, double sim_days); -bool ecl_sum_check_sim_time(const ecl_sum_type *sum, time_t sim_time); -bool ecl_sum_check_sim_days(const ecl_sum_type *sum, double sim_days); -const char *ecl_sum_get_keyword(const ecl_sum_type *sum, const char *gen_key); -const char *ecl_sum_get_wgname(const ecl_sum_type *sum, const char *gen_key); -const char *ecl_sum_get_unit(const ecl_sum_type *sum, const char *gen_key); -int ecl_sum_get_num(const ecl_sum_type *sum, const char *gen_key); - -double ecl_sum_iget(const ecl_sum_type *ecl_sum, int time_index, - int param_index); -int ecl_sum_iget_num(const ecl_sum_type *sum, int param_index); -const char *ecl_sum_iget_wgname(const ecl_sum_type *sum, int param_index); -const char *ecl_sum_iget_keyword(const ecl_sum_type *sum, int param_index); -int ecl_sum_get_data_length(const ecl_sum_type *ecl_sum); -double ecl_sum_iget_from_sim_time(const ecl_sum_type *ecl_sum, time_t sim_time, - int param_index); -double ecl_sum_iget_from_sim_days(const ecl_sum_type *ecl_sum, double sim_days, - int param_index); - -void ecl_sum_summarize(const ecl_sum_type *ecl_sum, FILE *stream); -bool ecl_sum_general_is_total(const ecl_sum_type *ecl_sum, const char *gen_key); -void ecl_sum_free_data(ecl_sum_type *); -void ecl_sum_free__(void *); -void ecl_sum_free(ecl_sum_type *); -ecl_sum_type *ecl_sum_fread_alloc(const char *, - const stringlist_type *data_files, - const char *key_join_string, - bool include_restart, bool lazy_load, - int file_options); -ecl_sum_type *ecl_sum_fread_alloc_case(const char *, - const char *key_join_string); -ecl_sum_type *ecl_sum_fread_alloc_case__(const char *input_file, - const char *key_join_string, - bool include_restart); -ecl_sum_type *ecl_sum_fread_alloc_case2__(const char *, - const char *key_join_string, - bool include_restart, bool lazy_load, - int file_options); -ecl_sum_type *ecl_sum_alloc_resample(const ecl_sum_type *ecl_sum, - const char *ecl_case, - const time_t_vector_type *times, - bool lower_extrapolation, - bool upper_extrapolation); -bool ecl_sum_case_exists(const char *input_file); - -/* Accessor functions : */ -double ecl_sum_get_well_var(const ecl_sum_type *ecl_sum, int time_index, - const char *well, const char *var); -bool ecl_sum_has_well_var(const ecl_sum_type *ecl_sum, const char *well, - const char *var); -double ecl_sum_get_well_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *well, - const char *var); -double ecl_sum_get_well_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *well, - const char *var); - -double ecl_sum_get_group_var(const ecl_sum_type *ecl_sum, int time_index, - const char *group, const char *var); -bool ecl_sum_has_group_var(const ecl_sum_type *ecl_sum, const char *group, - const char *var); - -double ecl_sum_get_field_var(const ecl_sum_type *ecl_sum, int time_index, - const char *var); -bool ecl_sum_has_field_var(const ecl_sum_type *ecl_sum, const char *var); -double ecl_sum_get_field_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *var); -double ecl_sum_get_field_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *var); - -double ecl_sum_get_block_var(const ecl_sum_type *ecl_sum, int time_index, - const char *block_var, int block_nr); -int ecl_sum_get_block_var_index(const ecl_sum_type *ecl_sum, - const char *block_var, int block_nr); -bool ecl_sum_has_block_var(const ecl_sum_type *ecl_sum, const char *block_var, - int block_nr); -double ecl_sum_get_block_var_ijk(const ecl_sum_type *ecl_sum, int time_index, - const char *block_var, int i, int j, int k); -int ecl_sum_get_block_var_index_ijk(const ecl_sum_type *ecl_sum, - const char *block_var, int i, int j, int k); -bool ecl_sum_has_block_var_ijk(const ecl_sum_type *ecl_sum, - const char *block_var, int i, int j, int k); - -double ecl_sum_get_region_var(const ecl_sum_type *ecl_sum, int time_index, - const char *var, int region_nr); -bool ecl_sum_has_region_var(const ecl_sum_type *ecl_sum, const char *var, - int region_nr); - -double ecl_sum_get_misc_var(const ecl_sum_type *ecl_sum, int time_index, - const char *var); -int ecl_sum_get_misc_var_index(const ecl_sum_type *ecl_sum, const char *var); -bool ecl_sum_has_misc_var(const ecl_sum_type *ecl_sum, const char *var); - -double ecl_sum_get_well_completion_var(const ecl_sum_type *ecl_sum, - int time_index, const char *well, - const char *var, int cell_nr); -int ecl_sum_get_well_completion_var_index(const ecl_sum_type *ecl_sum, - const char *well, const char *var, - int cell_nr); -bool ecl_sum_has_well_completion_var(const ecl_sum_type *ecl_sum, - const char *well, const char *var, - int cell_nr); - -double ecl_sum_get_general_var(const ecl_sum_type *ecl_sum, int time_index, - const char *lookup_kw); -int ecl_sum_get_general_var_params_index(const ecl_sum_type *ecl_sum, - const char *lookup_kw); -const ecl::smspec_node * -ecl_sum_get_general_var_node(const ecl_sum_type *ecl_sum, - const char *lookup_kw); -bool ecl_sum_has_general_var(const ecl_sum_type *ecl_sum, - const char *lookup_kw); -bool ecl_sum_has_key(const ecl_sum_type *ecl_sum, const char *lookup_kw); -double ecl_sum_get_general_var_from_sim_days(const ecl_sum_type *ecl_sum, - double sim_days, const char *var); -double ecl_sum_get_general_var_from_sim_time(const ecl_sum_type *ecl_sum, - time_t sim_time, const char *var); -const char *ecl_sum_get_general_var_unit(const ecl_sum_type *ecl_sum, - const char *var); -ert_ecl_unit_enum ecl_sum_get_unit_system(const ecl_sum_type *ecl_sum); - -void ecl_sum_fprintf(const ecl_sum_type *, FILE *, const stringlist_type *, - bool report_only, const ecl_sum_fmt_type *fmt); - -/* Time related functions */ -int ecl_sum_get_restart_step(const ecl_sum_type *ecl_sum); -int ecl_sum_get_first_gt(const ecl_sum_type *ecl_sum, int param_index, - double limit); -int ecl_sum_get_first_lt(const ecl_sum_type *ecl_sum, int param_index, - double limit); -int ecl_sum_get_last_report_step(const ecl_sum_type *ecl_sum); -int ecl_sum_get_first_report_step(const ecl_sum_type *ecl_sum); -bool ecl_sum_has_report_step(const ecl_sum_type *ecl_sum, int report_step); -time_t ecl_sum_get_report_time(const ecl_sum_type *ecl_sum, int report_step); -time_t ecl_sum_iget_sim_time(const ecl_sum_type *ecl_sum, int index); -double ecl_sum_iget_sim_days(const ecl_sum_type *ecl_sum, int time_index); -int ecl_sum_iget_report_step(const ecl_sum_type *ecl_sum, int internal_index); -double ecl_sum_iget_general_var(const ecl_sum_type *ecl_sum, int internal_index, - const char *lookup_kw); - -double_vector_type *ecl_sum_alloc_data_vector(const ecl_sum_type *ecl_sum, - int data_index, bool report_only); -time_t_vector_type *ecl_sum_alloc_time_vector(const ecl_sum_type *ecl_sum, - bool report_only); -time_t ecl_sum_get_data_start(const ecl_sum_type *ecl_sum); -time_t ecl_sum_get_end_time(const ecl_sum_type *ecl_sum); -time_t ecl_sum_get_start_time(const ecl_sum_type *); - -const char *ecl_sum_get_base(const ecl_sum_type *ecl_sum); -const char *ecl_sum_get_path(const ecl_sum_type *ecl_sum); -const char *ecl_sum_get_abs_path(const ecl_sum_type *ecl_sum); -const ecl_sum_type *ecl_sum_get_restart_case(const ecl_sum_type *ecl_sum); -const char *ecl_sum_get_case(const ecl_sum_type *); -bool ecl_sum_same_case(const ecl_sum_type *ecl_sum, const char *input_file); - -void ecl_sum_resample_from_sim_days(const ecl_sum_type *ecl_sum, - const double_vector_type *sim_days, - double_vector_type *value, - const char *gen_key); -void ecl_sum_resample_from_sim_time(const ecl_sum_type *ecl_sum, - const time_t_vector_type *sim_time, - double_vector_type *value, - const char *gen_key); -time_t ecl_sum_time_from_days(const ecl_sum_type *ecl_sum, double sim_days); -double ecl_sum_days_from_time(const ecl_sum_type *ecl_sum, time_t sim_time); -double ecl_sum_get_sim_length(const ecl_sum_type *ecl_sum); -double ecl_sum_get_first_day(const ecl_sum_type *ecl_sum); - -stringlist_type *ecl_sum_alloc_well_list(const ecl_sum_type *ecl_sum, - const char *pattern); -stringlist_type *ecl_sum_alloc_group_list(const ecl_sum_type *ecl_sum, - const char *pattern); -stringlist_type *ecl_sum_alloc_well_var_list(const ecl_sum_type *ecl_sum); -stringlist_type * -ecl_sum_alloc_matching_general_var_list(const ecl_sum_type *ecl_sum, - const char *pattern); -void ecl_sum_select_matching_general_var_list(const ecl_sum_type *ecl_sum, - const char *pattern, - stringlist_type *keys); -ecl_smspec_type *ecl_sum_get_smspec(const ecl_sum_type *ecl_sum); -ecl_smspec_var_type ecl_sum_identify_var_type(const char *var); -ecl_smspec_var_type ecl_sum_get_var_type(const ecl_sum_type *ecl_sum, - const char *gen_key); -bool ecl_sum_var_is_rate(const ecl_sum_type *ecl_sum, const char *gen_key); -bool ecl_sum_var_is_total(const ecl_sum_type *ecl_sum, const char *gen_key); - -int ecl_sum_iget_report_end(const ecl_sum_type *ecl_sum, int report_step); -ecl_sum_type * -ecl_sum_alloc_restart_writer2(const char *ecl_case, const char *restart_case, - int restart_step, bool fmt_output, bool unified, - const char *key_join_string, time_t sim_start, - bool time_in_days, int nx, int ny, int nz); -void ecl_sum_set_case(ecl_sum_type *ecl_sum, const char *input_arg); - -ecl_sum_type *ecl_sum_alloc_restart_writer(const char *ecl_case, - const char *restart_case, - bool fmt_output, bool unified, - const char *key_join_string, - time_t sim_start, bool time_in_days, - int nx, int ny, int nz); -ecl_sum_type *ecl_sum_alloc_writer(const char *ecl_case, bool fmt_output, - bool unified, const char *key_join_string, - time_t sim_start, bool time_in_days, int nx, - int ny, int nz); -void ecl_sum_fwrite(const ecl_sum_type *ecl_sum); -bool ecl_sum_can_write(const ecl_sum_type *ecl_sum); -void ecl_sum_fwrite_smspec(const ecl_sum_type *ecl_sum); -const ecl::smspec_node *ecl_sum_add_smspec_node(ecl_sum_type *ecl_sum, - const ecl::smspec_node *node); -const ecl::smspec_node *ecl_sum_add_var(ecl_sum_type *ecl_sum, - const char *keyword, const char *wgname, - int num, const char *unit, - float default_value); -ecl_sum_tstep_type *ecl_sum_add_tstep(ecl_sum_type *ecl_sum, int report_step, - double sim_seconds); - -bool ecl_sum_is_oil_producer(const ecl_sum_type *ecl_sum, const char *well); -char *ecl_sum_alloc_well_key(const ecl_sum_type *ecl_sum, const char *keyword, - const char *wgname); -bool ecl_sum_report_step_equal(const ecl_sum_type *ecl_sum1, - const ecl_sum_type *ecl_sum2); -bool ecl_sum_report_step_compatible(const ecl_sum_type *ecl_sum1, - const ecl_sum_type *ecl_sum2); -void ecl_sum_export_csv(const ecl_sum_type *ecl_sum, const char *filename, - const stringlist_type *var_list, - const char *date_format, const char *sep); - -double_vector_type *ecl_sum_alloc_seconds_solution(const ecl_sum_type *ecl_sum, - const char *gen_key, - double cmp_value, - bool rates_clamp_lower); -double_vector_type *ecl_sum_alloc_days_solution(const ecl_sum_type *ecl_sum, - const char *gen_key, - double cmp_value, - bool rates_clamp_lower); -time_t_vector_type *ecl_sum_alloc_time_solution(const ecl_sum_type *ecl_sum, - const char *gen_key, - double cmp_value, - bool rates_clamp_lower); - -double ecl_sum_iget_last_value(const ecl_sum_type *ecl_sum, int param_index); -double ecl_sum_get_last_value_gen_key(const ecl_sum_type *ecl_sum, - const char *gen_key); -double ecl_sum_get_last_value_node(const ecl_sum_type *ecl_sum, - const ecl::smspec_node *node); -double ecl_sum_iget_first_value(const ecl_sum_type *ecl_sum, int param_index); -double ecl_sum_get_first_value_gen_key(const ecl_sum_type *ecl_sum, - const char *gen_key); -double ecl_sum_get_first_value_node(const ecl_sum_type *ecl_sum, - const ecl::smspec_node *node); - -void ecl_sum_init_datetime64_vector(const ecl_sum_type *ecl_sum, int64_t *data, - int multiplier); -void ecl_sum_init_double_vector_interp(const ecl_sum_type *ecl_sum, - const char *gen_key, - const time_t_vector_type *time_points, - double *data); -void ecl_sum_init_double_vector(const ecl_sum_type *ecl_sum, - const char *gen_key, double *data); -void ecl_sum_init_double_frame(const ecl_sum_type *ecl_sum, - const ecl_sum_vector_type *keywords, - double *data); -void ecl_sum_init_double_frame_interp(const ecl_sum_type *ecl_sum, - const ecl_sum_vector_type *keywords, - const time_t_vector_type *time_points, - double *data); -UTIL_IS_INSTANCE_HEADER(ecl_sum); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_sum_data.h b/lib/include/ert/ecl/ecl_sum_data.h deleted file mode 100644 index cfc2bbe6e0..0000000000 --- a/lib/include/ert/ecl/ecl_sum_data.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_sum_data.hpp b/lib/include/ert/ecl/ecl_sum_data.hpp deleted file mode 100644 index 827208cd53..0000000000 --- a/lib/include/ert/ecl/ecl_sum_data.hpp +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef ERT_ECL_SUM_DATA_H -#define ERT_ECL_SUM_DATA_H - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_sum_data_struct ecl_sum_data_type; - -void ecl_sum_data_reset_self_map(ecl_sum_data_type *data); -void ecl_sum_data_add_case(ecl_sum_data_type *self, - const ecl_sum_data_type *other); -void ecl_sum_data_fwrite_step(const ecl_sum_data_type *data, - const char *ecl_case, bool fmt_case, bool unified, - int report_step); -void ecl_sum_data_fwrite(const ecl_sum_data_type *data, const char *ecl_case, - bool fmt_case, bool unified); -bool ecl_sum_data_can_write(const ecl_sum_data_type *data); -bool ecl_sum_data_fread(ecl_sum_data_type *data, - const stringlist_type *filelist, bool lazy_load, - int file_options); -ecl_sum_data_type *ecl_sum_data_alloc_writer(ecl_smspec_type *smspec); -ecl_sum_data_type *ecl_sum_data_alloc(ecl_smspec_type *smspec); -double ecl_sum_data_time2days(const ecl_sum_data_type *data, time_t sim_time); -int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type *data, - time_t sim_time); -int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type *data, - double days); -bool ecl_sum_data_check_sim_time(const ecl_sum_data_type *data, - time_t sim_time); -bool ecl_sum_data_check_sim_days(const ecl_sum_data_type *data, - double sim_days); -int ecl_sum_data_get_num_ministep(const ecl_sum_data_type *data); -double_vector_type * -ecl_sum_data_alloc_data_vector(const ecl_sum_data_type *data, int data_index, - bool report_only); -void ecl_sum_data_init_time_vector(const ecl_sum_data_type *data, - time_t_vector_type *time_vector, - bool report_only); -time_t_vector_type * -ecl_sum_data_alloc_time_vector(const ecl_sum_data_type *data, bool report_only); -time_t ecl_sum_data_get_data_start(const ecl_sum_data_type *data); -time_t ecl_sum_data_get_report_time(const ecl_sum_data_type *data, - int report_step); -double ecl_sum_data_get_first_day(const ecl_sum_data_type *data); -time_t ecl_sum_data_get_sim_start(const ecl_sum_data_type *data); -time_t ecl_sum_data_get_sim_end(const ecl_sum_data_type *data); -double ecl_sum_data_get_sim_length(const ecl_sum_data_type *data); -void ecl_sum_data_summarize(const ecl_sum_data_type *data, FILE *stream); -double ecl_sum_data_iget(const ecl_sum_data_type *data, int internal_index, - int params_index); - -double ecl_sum_data_iget_sim_days(const ecl_sum_data_type *, int); -time_t ecl_sum_data_iget_sim_time(const ecl_sum_data_type *, int); -void ecl_sum_data_get_interp_vector(const ecl_sum_data_type *data, - time_t sim_time, - const ecl_sum_vector_type *keylist, - double_vector_type *results); - -bool ecl_sum_data_has_report_step(const ecl_sum_data_type *, int); - -ecl_sum_data_type *ecl_sum_data_fread_alloc(ecl_smspec_type *, - const stringlist_type *filelist, - bool include_restart, - bool lazy_load); -void ecl_sum_data_free(ecl_sum_data_type *); -int ecl_sum_data_get_last_report_step(const ecl_sum_data_type *data); -int ecl_sum_data_get_first_report_step(const ecl_sum_data_type *data); - -double ecl_sum_data_get_from_sim_time(const ecl_sum_data_type *data, - time_t sim_time, - const ecl::smspec_node &smspec_node); -double ecl_sum_data_get_from_sim_days(const ecl_sum_data_type *data, - double sim_days, - const ecl::smspec_node &smspec_node); - -int ecl_sum_data_get_length(const ecl_sum_data_type *data); -int ecl_sum_data_iget_report_step(const ecl_sum_data_type *data, - int internal_index); -int ecl_sum_data_iget_report_end(const ecl_sum_data_type *data, - int report_step); -ecl_sum_tstep_type *ecl_sum_data_add_new_tstep(ecl_sum_data_type *data, - int report_step, - double sim_seconds); -bool ecl_sum_data_report_step_equal(const ecl_sum_data_type *data1, - const ecl_sum_data_type *data2); -bool ecl_sum_data_report_step_compatible(const ecl_sum_data_type *data1, - const ecl_sum_data_type *data2); -void ecl_sum_data_fwrite_interp_csv_line(const ecl_sum_data_type *data, - time_t sim_time, - const ecl_sum_vector_type *keylist, - FILE *fp); -double ecl_sum_data_get_last_value(const ecl_sum_data_type *data, - int param_index); -double ecl_sum_data_iget_last_value(const ecl_sum_data_type *data, - int param_index); -double ecl_sum_data_iget_first_value(const ecl_sum_data_type *data, - int param_index); -void ecl_sum_data_init_double_vector(const ecl_sum_data_type *data, - int params_index, double *output_data); -void ecl_sum_data_init_datetime64_vector(const ecl_sum_data_type *data, - int64_t *output_data, int multiplier); - -void ecl_sum_data_init_double_frame(const ecl_sum_data_type *data, - const ecl_sum_vector_type *keywords, - double *output_data); -double_vector_type * -ecl_sum_data_alloc_seconds_solution(const ecl_sum_data_type *data, - const ecl::smspec_node &node, double value, - bool rates_clamp_lower); -void ecl_sum_data_init_double_frame_interp( - const ecl_sum_data_type *data, const ecl_sum_vector_type *keywords, - const time_t_vector_type *time_points, double *output_data); - -void ecl_sum_data_init_double_vector_interp( - const ecl_sum_data_type *data, const ecl::smspec_node &smspec_node, - const time_t_vector_type *time_points, double *output_data); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_sum_index.h b/lib/include/ert/ecl/ecl_sum_index.h deleted file mode 100644 index 513ebe4806..0000000000 --- a/lib/include/ert/ecl/ecl_sum_index.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_sum_index.hpp b/lib/include/ert/ecl/ecl_sum_index.hpp deleted file mode 100644 index a3c6902324..0000000000 --- a/lib/include/ert/ecl/ecl_sum_index.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ERT_ECL_SUM_INDEX_H -#define ERT_ECL_SUM_INDEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_sum_index_struct ecl_sum_index_type; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_sum_tstep.h b/lib/include/ert/ecl/ecl_sum_tstep.h deleted file mode 100644 index 985476614e..0000000000 --- a/lib/include/ert/ecl/ecl_sum_tstep.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_sum_tstep.hpp b/lib/include/ert/ecl/ecl_sum_tstep.hpp deleted file mode 100644 index aee0aa2fbe..0000000000 --- a/lib/include/ert/ecl/ecl_sum_tstep.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef ERT_ECL_SUM_TSTEP_H -#define ERT_ECL_SUM_TSTEP_H - -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_sum_tstep_struct ecl_sum_tstep_type; - -ecl_sum_tstep_type * -ecl_sum_tstep_alloc_remap_copy(const ecl_sum_tstep_type *src, - const ecl_smspec_type *new_smspec, - float default_value, const int *params_map); -ecl_sum_tstep_type *ecl_sum_tstep_alloc_copy(const ecl_sum_tstep_type *src); -void ecl_sum_tstep_free(ecl_sum_tstep_type *ministep); -void ecl_sum_tstep_free__(void *__ministep); -ecl_sum_tstep_type *ecl_sum_tstep_alloc_from_file( - int report_step, int ministep_nr, const ecl_kw_type *params_kw, - const char *src_file, const ecl_smspec_type *smspec); - -ecl_sum_tstep_type *ecl_sum_tstep_alloc_new(int report_step, int ministep, - float sim_seconds, - const ecl_smspec_type *smspec); - -void ecl_sum_tstep_set_from_node(ecl_sum_tstep_type *tstep, - const ecl::smspec_node &smspec_node, - float value); -double ecl_sum_tstep_get_from_node(const ecl_sum_tstep_type *tstep, - const ecl::smspec_node &smspec_node); - -double ecl_sum_tstep_iget(const ecl_sum_tstep_type *ministep, int index); -time_t ecl_sum_tstep_get_sim_time(const ecl_sum_tstep_type *ministep); -double ecl_sum_tstep_get_sim_days(const ecl_sum_tstep_type *ministep); -double ecl_sum_tstep_get_sim_seconds(const ecl_sum_tstep_type *ministep); - -int ecl_sum_tstep_get_report(const ecl_sum_tstep_type *ministep); -int ecl_sum_tstep_get_ministep(const ecl_sum_tstep_type *ministep); - -void ecl_sum_tstep_fwrite(const ecl_sum_tstep_type *ministep, - const int *index_map, int index_map_size, - fortio_type *fortio); -void ecl_sum_tstep_iset(ecl_sum_tstep_type *tstep, int index, float value); - -/// scales with value; equivalent to iset( iget() * scalar) -void ecl_sum_tstep_iscale(ecl_sum_tstep_type *tstep, int index, float scalar); - -/// adds addend to tstep[index]; equivalent to iset( iget() + addend) -void ecl_sum_tstep_ishift(ecl_sum_tstep_type *tstep, int index, float addend); - -void ecl_sum_tstep_set_from_key(ecl_sum_tstep_type *tstep, const char *gen_key, - float value); -double ecl_sum_tstep_get_from_key(const ecl_sum_tstep_type *tstep, - const char *gen_key); -bool ecl_sum_tstep_has_key(const ecl_sum_tstep_type *tstep, - const char *gen_key); - -bool ecl_sum_tstep_sim_time_equal(const ecl_sum_tstep_type *tstep1, - const ecl_sum_tstep_type *tstep2); - -UTIL_SAFE_CAST_HEADER(ecl_sum_tstep); -UTIL_SAFE_CAST_HEADER_CONST(ecl_sum_tstep); - -#ifdef __cplusplus -} - -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_sum_vector.h b/lib/include/ert/ecl/ecl_sum_vector.h deleted file mode 100644 index 600921b5b5..0000000000 --- a/lib/include/ert/ecl/ecl_sum_vector.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_sum_vector.hpp b/lib/include/ert/ecl/ecl_sum_vector.hpp deleted file mode 100644 index 4432d185ed..0000000000 --- a/lib/include/ert/ecl/ecl_sum_vector.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef ERT_ECL_SUM_VECTOR_H -#define ERT_ECL_SUM_VECTOR_H - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_sum_vector_struct ecl_sum_vector_type; - -void ecl_sum_vector_free(ecl_sum_vector_type *keylist); -ecl_sum_vector_type *ecl_sum_vector_alloc(const ecl_sum_type *ecl_sum, - bool add_keywords); - -bool ecl_sum_vector_add_key(ecl_sum_vector_type *keylist, const char *key); -void ecl_sum_vector_add_keys(ecl_sum_vector_type *keylist, const char *pattern); - -const char *ecl_sum_vector_iget_key(const ecl_sum_vector_type *ecl_sum_vector, - int index); -bool ecl_sum_vector_iget_is_rate(const ecl_sum_vector_type *ecl_sum_vector, - int index); -int ecl_sum_vector_iget_param_index(const ecl_sum_vector_type *ecl_sum_vector, - int index); -int ecl_sum_vector_get_size(const ecl_sum_vector_type *ecl_sum_vector); -bool ecl_sum_vector_iget_valid(const ecl_sum_vector_type *ecl_sum_vector, - int index); - -ecl_sum_vector_type * -ecl_sum_vector_alloc_layout_copy(const ecl_sum_vector_type *src_vector, - const ecl_sum_type *ecl_sum); - -UTIL_IS_INSTANCE_HEADER(ecl_sum_vector); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_type.h b/lib/include/ert/ecl/ecl_type.h deleted file mode 100644 index a48a455b18..0000000000 --- a/lib/include/ert/ecl/ecl_type.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_type.hpp b/lib/include/ert/ecl/ecl_type.hpp deleted file mode 100644 index c64771a88d..0000000000 --- a/lib/include/ert/ecl/ecl_type.hpp +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef ERT_ECL_TYPE_H -#define ERT_ECL_TYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -/* - The type of an eclipse keyword is carried by a struct - ecl_type_struct which contains a type enum, and the size in bytes of - one such element. These structs are for the most part handled with - value semantics, and created with macros ECL_INT, ECL_FLOAT and so - on. - - The macros in C use designated initializers, whereas the C++ macros - use a constructor, for this reason this file has two slightly - different code paths for C and C++. -*/ - -#define ECL_STRING8_LENGTH 8 -#define ECL_TYPE_LENGTH 4 - -typedef enum { - ECL_CHAR_TYPE = 0, - ECL_FLOAT_TYPE = 1, - ECL_DOUBLE_TYPE = 2, - ECL_INT_TYPE = 3, - ECL_BOOL_TYPE = 4, - ECL_MESS_TYPE = 5, - ECL_STRING_TYPE = 7 -} ecl_type_enum; - -#define ECL_TYPE_ENUM_DEFS \ - {.value = 0, .name = "ECL_CHAR_TYPE"}, \ - {.value = 1, .name = "ECL_FLOAT_TYPE"}, \ - {.value = 2, .name = "ECL_DOUBLE_TYPE"}, \ - {.value = 3, .name = "ECL_INT_TYPE"}, \ - {.value = 4, .name = "ECL_BOOL_TYPE"}, \ - {.value = 5, .name = "ECL_MESS_TYPE"}, { \ - .value = 7, .name = "ECL_STRING_TYPE" \ - } - -/* - Character data in ECLIPSE files comes as an array of fixed-length - string. Each of these strings is 8 characters long. The type name, - i.e. 'REAL', 'INTE', ... , come as 4 character strings. -*/ - -#define ECL_STRING8_LENGTH 8 // 'Normal' 8 characters 'CHAR' type. -#define ECL_TYPE_LENGTH 4 - -struct ecl_type_struct { - const ecl_type_enum type; - const size_t element_size; -}; - -#ifdef __cplusplus - -#define ECL_INT \ - ecl_data_type { ECL_INT_TYPE, sizeof(int) } -#define ECL_FLOAT \ - ecl_data_type { ECL_FLOAT_TYPE, sizeof(float) } -#define ECL_DOUBLE \ - ecl_data_type { ECL_DOUBLE_TYPE, sizeof(double) } -#define ECL_BOOL \ - ecl_data_type { ECL_BOOL_TYPE, sizeof(bool) } -#define ECL_CHAR \ - ecl_data_type { ECL_CHAR_TYPE, ECL_STRING8_LENGTH + 1 } -#define ECL_MESS \ - ecl_data_type { ECL_MESS_TYPE, 0 } -#define ECL_STRING(size) \ - ecl_data_type { ECL_STRING_TYPE, (size) + 1 } -} - -#else - -#define ECL_CHAR \ - (ecl_data_type) { \ - .type = ECL_CHAR_TYPE, .element_size = ECL_STRING8_LENGTH + 1 \ - } -#define ECL_INT \ - (ecl_data_type) { .type = ECL_INT_TYPE, .element_size = sizeof(int) } -#define ECL_FLOAT \ - (ecl_data_type) { .type = ECL_FLOAT_TYPE, .element_size = sizeof(float) } -#define ECL_DOUBLE \ - (ecl_data_type) { .type = ECL_DOUBLE_TYPE, .element_size = sizeof(double) } -#define ECL_BOOL \ - (ecl_data_type) { .type = ECL_BOOL_TYPE, .element_size = sizeof(bool) } -#define ECL_MESS \ - (ecl_data_type) { .type = ECL_MESS_TYPE, .element_size = 0 } -#define ECL_STRING(size) \ - (ecl_data_type) { .type = ECL_STRING_TYPE, .element_size = (size) + 1 } - -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ecl_type_struct ecl_data_type; - -ecl_data_type ecl_type_create_from_name(const char *); -ecl_data_type ecl_type_create(const ecl_type_enum, const size_t); -ecl_data_type ecl_type_create_from_type(const ecl_type_enum); - -ecl_type_enum ecl_type_get_type(const ecl_data_type); -char *ecl_type_alloc_name(const ecl_data_type); - -int ecl_type_get_sizeof_ctype(const ecl_data_type); -int ecl_type_get_sizeof_iotype(const ecl_data_type); - -bool ecl_type_is_equal(const ecl_data_type, const ecl_data_type); - -bool ecl_type_is_numeric(const ecl_data_type); -bool ecl_type_is_alpha(const ecl_data_type); -bool ecl_type_is_char(const ecl_data_type); -bool ecl_type_is_int(const ecl_data_type); -bool ecl_type_is_float(const ecl_data_type); -bool ecl_type_is_double(const ecl_data_type); -bool ecl_type_is_mess(const ecl_data_type); -bool ecl_type_is_bool(const ecl_data_type); -bool ecl_type_is_string(const ecl_data_type); - -// Temporary fixup for OPM. -char *ecl_type_get_name(const ecl_data_type); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/include/ert/ecl/ecl_units.h b/lib/include/ert/ecl/ecl_units.h deleted file mode 100644 index 1677637b66..0000000000 --- a/lib/include/ert/ecl/ecl_units.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_units.hpp b/lib/include/ert/ecl/ecl_units.hpp deleted file mode 100644 index 01184be235..0000000000 --- a/lib/include/ert/ecl/ecl_units.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ECL_UNITS_H -#define ECL_UNITS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define ECL_UNITS_CUBIC(x) ((x) * (x) * (x)) -#define ECL_UNITS_MILLI(x) ((x)*0.001) -#define ECL_UNITS_MEGA(x) ((x)*1000000) - -#define ECL_UNITS_LENGTH_INCH 0.0254 -#define ECL_UNITS_LENGTH_FEET 12 * ECL_UNITS_LENGTH_INCH - -#define ECL_UNITS_VOLUME_GALLON 231 * ECL_UNITS_CUBIC(ECL_UNITS_LENGTH_INCH) -#define ECL_UNITS_VOLUME_BARREL ECL_UNITS_VOLUME_GALLON * 42 -#define ECL_UNITS_VOLUME_LITER 0.001 -#define ECL_UNITS_VOLUME_MILLI_LITER ECL_UNITS_MILLI(ECL_UNITS_VOLUME_LITER) -#define ECL_UNITS_VOLUME_GAS_FIELD \ - ECL_UNITS_MEGA(ECL_UNITS_CUBIC(ECL_UNITS_LENGTH_FEET)) - -#define ECL_UNITS_TIME_HOUR 3600 -#define ECL_UNITS_TIME_DAY 24 * ECL_UNITS_TIME_HOUR - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/ecl/ecl_util.h b/lib/include/ert/ecl/ecl_util.h deleted file mode 100644 index f0bf6bd067..0000000000 --- a/lib/include/ert/ecl/ecl_util.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/ecl/ecl_util.hpp b/lib/include/ert/ecl/ecl_util.hpp deleted file mode 100644 index e9b89bc2e9..0000000000 --- a/lib/include/ert/ecl/ecl_util.hpp +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef ERT_ECL_UTIL_H -#define ERT_ECL_UTIL_H -#ifdef __cplusplus -extern "C" { -#endif -#include -#include - -#include -#include -#include -#include - -typedef enum { - ECL_OTHER_FILE = 0, - ECL_RESTART_FILE = 1, - ECL_UNIFIED_RESTART_FILE = 2, - ECL_SUMMARY_FILE = 4, - ECL_UNIFIED_SUMMARY_FILE = 8, - ECL_SUMMARY_HEADER_FILE = 16, - ECL_GRID_FILE = 32, - ECL_EGRID_FILE = 64, - ECL_INIT_FILE = 128, - ECL_RFT_FILE = 256, - ECL_DATA_FILE = 512 -} ecl_file_enum; - -/* - This enum enumerates the four different ways summary and restart information - can be stored. - */ - -typedef enum { - ECL_INVALID_STORAGE = 0, - ECL_BINARY_UNIFIED = 1, - ECL_FORMATTED_UNIFIED = 2, - ECL_BINARY_NON_UNIFIED = 4, - ECL_FORMATTED_NON_UNIFIED = 8 -} ecl_storage_enum; - -/* - The libecl library has been built and tested 99.5% with ECLIPSE100 - as context, but in thye gravity code there is some very limited - functionality related to ECLIPSE100 versus ECLIPSE300 functionality. - - Observe that numerical values found as part of the INTEHAD keyword - differ from these values, and are found in the ecl_kw_magic.h - header. -*/ - -typedef enum { - ECLIPSE_UNDEFINED = 0, - ECLIPSE100 = 1, - ECLIPSE300 = 2, - ECLIPSE300_THERMAL = 3, - INTERSECT = 4, - FRONTSIM = 5 -} ecl_version_enum; - -/* - Observe that the numerical enum VALUES matches those found in item - 14 in the INTEHEAD keyword in the ECLIPSE INIT files; i.e. the - distribution of numerical values 1,2,4 can NOT BE CHANGED. - - The function ecl_util_get_phase_name() can be used to lookup a - string name from an enum value. - - The phases in a simulation will typically be a sum of these - fundamental phases, and represented as an integer. -*/ - -typedef enum { - ECL_OIL_PHASE = 1, - ECL_GAS_PHASE = 2, - ECL_WATER_PHASE = 4 -} ecl_phase_enum; - -#define ECL_PHASE_ENUM_DEFS \ - {.value = 1, .name = "ECL_OIL_PHASE"}, \ - {.value = 2, .name = "ECL_GAS_PHASE"}, { \ - .value = 4, .name = "ECL_WATER_PHASE" \ - } -#define ECL_PHASE_ENUM_SIZE 3 - -typedef enum { - ECL_METRIC_UNITS = 1, - ECL_FIELD_UNITS = 2, - ECL_LAB_UNITS = 3, - ECL_PVT_M_UNITS = 4 -} ert_ecl_unit_enum; - -// For unformatted files: -#define ECL_BOOL_TRUE_INT \ - -1 // Binary representation: 11111111 11111111 11111111 1111111 -#define ECL_BOOL_FALSE_INT \ - 0 // Binary representation: 00000000 00000000 00000000 0000000 -#define ECL_COMMENT_STRING "--" -#define ECL_COMMENT_CHAR '-' // Need to consecutive to make an ECLIPSE comment -#define ECL_DATA_TERMINATION "/" - -bool ecl_util_unified_file(const char *filename); -const char *ecl_util_file_type_name(ecl_file_enum file_type); -char *ecl_util_alloc_base_guess(const char *); -int ecl_util_filename_report_nr(const char *); -ecl_file_enum ecl_util_inspect_extension(const char *ext, bool *_fmt_file, - int *_report_nr); -ecl_file_enum ecl_util_get_file_type(const char *filename, bool *fmt_file, - int *report_nr); -char *ecl_util_alloc_filename(const char * /* path */, const char * /* base */, - ecl_file_enum, bool /* fmt_file */, - int /*report_nr*/); -char *ecl_util_alloc_exfilename(const char * /* path */, - const char * /* base */, ecl_file_enum, - bool /* fmt_file */, int /*report_nr*/); -void ecl_util_memcpy_typed_data(void *, const void *, ecl_data_type, - ecl_data_type, int); -void ecl_util_escape_kw(char *kw); -bool ecl_util_alloc_summary_files(const char *, const char *, const char *, - char **, stringlist_type *); -void ecl_util_alloc_summary_data_files(const char *path, const char *base, - bool fmt_file, - stringlist_type *filelist); -void ecl_util_alloc_restart_files(const char *, const char *, char ***, int *, - bool *, bool *); -time_t ecl_util_get_start_date(const char *); -int ecl_util_get_num_cpu(const char *data_file); -bool ecl_util_fmt_file(const char *filename, bool *__fmt_file); -char *ecl_util_alloc_exfilename_anyfmt(const char *path, const char *base, - ecl_file_enum file_type, bool start_fmt, - int report_nr); -int ecl_util_get_month_nr(const char *month_name); -int ecl_util_fname_report_cmp(const void *f1, const void *f2); -time_t ecl_util_make_date(int mday, int month, int year); -time_t ecl_util_make_date__(int mday, int month, int year, int *year_offset); -time_t ecl_util_make_datetime(int sec, int min, int hour, int mday, int month, - int year); -ert_ecl_unit_enum ecl_util_get_unit_set(const char *data_file); - -bool ecl_util_valid_basename_fmt(const char *basename_fmt); -bool ecl_util_valid_basename(const char *basename); -const char *ecl_util_get_phase_name(ecl_phase_enum phase); - -int ecl_util_select_filelist(const char *path, const char *base, - ecl_file_enum file_type, bool fmt_file, - stringlist_type *filelist); -void ecl_util_append_month_range(time_t_vector_type *date_list, - time_t start_date, time_t end_date, - bool force_append_end); -void ecl_util_init_month_range(time_t_vector_type *date_list, time_t start_date, - time_t end_date); -void ecl_util_set_date_values(time_t t, int *mday, int *month, int *year); -void ecl_util_set_datetime_values(time_t t, int *sec, int *min, int *hour, - int *mday, int *month, int *year); -bool ecl_util_path_access(const char *ecl_case); -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/include/ert/geometry/geo_pointset.h b/lib/include/ert/geometry/geo_pointset.h index 7f737aa1f6..8589cf317c 100644 --- a/lib/include/ert/geometry/geo_pointset.h +++ b/lib/include/ert/geometry/geo_pointset.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/geometry/geo_polygon.h b/lib/include/ert/geometry/geo_polygon.h index 61c2b1a15a..3762193b45 100644 --- a/lib/include/ert/geometry/geo_polygon.h +++ b/lib/include/ert/geometry/geo_polygon.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/geometry/geo_polygon_collection.h b/lib/include/ert/geometry/geo_polygon_collection.h index 72e00a7338..618058edc3 100644 --- a/lib/include/ert/geometry/geo_polygon_collection.h +++ b/lib/include/ert/geometry/geo_polygon_collection.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/geometry/geo_region.h b/lib/include/ert/geometry/geo_region.h index 8f04c28aa1..1cb49024bf 100644 --- a/lib/include/ert/geometry/geo_region.h +++ b/lib/include/ert/geometry/geo_region.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/geometry/geo_surface.h b/lib/include/ert/geometry/geo_surface.h index 91342e93bf..1753232897 100644 --- a/lib/include/ert/geometry/geo_surface.h +++ b/lib/include/ert/geometry/geo_surface.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/geometry/geo_util.h b/lib/include/ert/geometry/geo_util.h index d38aa19b43..0f67a7b312 100644 --- a/lib/include/ert/geometry/geo_util.h +++ b/lib/include/ert/geometry/geo_util.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/buffer.h b/lib/include/ert/util/buffer.h index dc91c28418..8b0bd6b7d8 100644 --- a/lib/include/ert/util/buffer.h +++ b/lib/include/ert/util/buffer.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/ecl_version.h b/lib/include/ert/util/ecl_version.h deleted file mode 100644 index 8caa6874f9..0000000000 --- a/lib/include/ert/util/ecl_version.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - Warning: The libecl code has changed to be compiled as a C++ project. This - header file is retained for a period for compatibility, but you are encouraged - to switch to include the new hpp header directly in your code. -*/ - -#include diff --git a/lib/include/ert/util/ecl_version.hpp b/lib/include/ert/util/ecl_version.hpp deleted file mode 100644 index c05c39cdee..0000000000 --- a/lib/include/ert/util/ecl_version.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ECL_VERSION -#define ECL_VERSION - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -const char *ecl_version_get_git_commit(); -const char *ecl_version_get_git_commit_short(); -const char *ecl_version_get_build_time(); -int ecl_version_get_major_version(); -int ecl_version_get_minor_version(); -const char *ecl_version_get_micro_version(); -bool ecl_version_is_ert_devel_version(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/include/ert/util/hash.h b/lib/include/ert/util/hash.h index f8d8ac481c..283b6f7e09 100644 --- a/lib/include/ert/util/hash.h +++ b/lib/include/ert/util/hash.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/hash_node.h b/lib/include/ert/util/hash_node.h index 1eddeecfeb..0fc9549f56 100644 --- a/lib/include/ert/util/hash_node.h +++ b/lib/include/ert/util/hash_node.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/hash_sll.h b/lib/include/ert/util/hash_sll.h index c8ef946837..796a324206 100644 --- a/lib/include/ert/util/hash_sll.h +++ b/lib/include/ert/util/hash_sll.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/lookup_table.h b/lib/include/ert/util/lookup_table.h index 2bceac5c05..2097639e4a 100644 --- a/lib/include/ert/util/lookup_table.h +++ b/lib/include/ert/util/lookup_table.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/mzran.h b/lib/include/ert/util/mzran.h index 1f391592ce..1ca0fc83a0 100644 --- a/lib/include/ert/util/mzran.h +++ b/lib/include/ert/util/mzran.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/node_ctype.h b/lib/include/ert/util/node_ctype.h index de84e5a0a6..70314cac3f 100644 --- a/lib/include/ert/util/node_ctype.h +++ b/lib/include/ert/util/node_ctype.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/node_data.h b/lib/include/ert/util/node_data.h index 49cda34c5c..ff1af191e2 100644 --- a/lib/include/ert/util/node_data.h +++ b/lib/include/ert/util/node_data.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/parser.h b/lib/include/ert/util/parser.h index 6c6215c01f..8ccfb696d7 100644 --- a/lib/include/ert/util/parser.h +++ b/lib/include/ert/util/parser.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/path_stack.h b/lib/include/ert/util/path_stack.h index 014cc66827..da2e46bc12 100644 --- a/lib/include/ert/util/path_stack.h +++ b/lib/include/ert/util/path_stack.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/perm_vector.h b/lib/include/ert/util/perm_vector.h index 9f36097643..f7a4ca2d14 100644 --- a/lib/include/ert/util/perm_vector.h +++ b/lib/include/ert/util/perm_vector.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/rd_version.h b/lib/include/ert/util/rd_version.h new file mode 100644 index 0000000000..29496a4d34 --- /dev/null +++ b/lib/include/ert/util/rd_version.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/ert/util/rd_version.hpp b/lib/include/ert/util/rd_version.hpp new file mode 100644 index 0000000000..7b5a67695c --- /dev/null +++ b/lib/include/ert/util/rd_version.hpp @@ -0,0 +1,22 @@ +#ifndef RD_VERSION +#define RD_VERSION + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +const char *rd_version_get_git_commit(); +const char *rd_version_get_git_commit_short(); +const char *rd_version_get_build_time(); +int rd_version_get_major_version(); +int rd_version_get_minor_version(); +const char *rd_version_get_micro_version(); +bool rd_version_is_ert_devel_version(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/ert/util/rng.h b/lib/include/ert/util/rng.h index c47e37b804..e0d559cac3 100644 --- a/lib/include/ert/util/rng.h +++ b/lib/include/ert/util/rng.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/ssize_t.h b/lib/include/ert/util/ssize_t.h index e10c3d9e9a..16847b83cc 100644 --- a/lib/include/ert/util/ssize_t.h +++ b/lib/include/ert/util/ssize_t.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/statistics.h b/lib/include/ert/util/statistics.h index d603e52fb7..49c0f5d458 100644 --- a/lib/include/ert/util/statistics.h +++ b/lib/include/ert/util/statistics.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/string_util.h b/lib/include/ert/util/string_util.h index b9c781a27a..6798b64a3a 100644 --- a/lib/include/ert/util/string_util.h +++ b/lib/include/ert/util/string_util.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/stringlist.h b/lib/include/ert/util/stringlist.h index 0f280a4535..f9a1609fb4 100644 --- a/lib/include/ert/util/stringlist.h +++ b/lib/include/ert/util/stringlist.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/test_util.h b/lib/include/ert/util/test_util.h index db18ad8893..8045a747f4 100644 --- a/lib/include/ert/util/test_util.h +++ b/lib/include/ert/util/test_util.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/test_work_area.h b/lib/include/ert/util/test_work_area.h index 8c608f49d6..b4b67e0aab 100644 --- a/lib/include/ert/util/test_work_area.h +++ b/lib/include/ert/util/test_work_area.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/test_work_area.hpp b/lib/include/ert/util/test_work_area.hpp index 6be391619e..0e1ed94157 100644 --- a/lib/include/ert/util/test_work_area.hpp +++ b/lib/include/ert/util/test_work_area.hpp @@ -3,7 +3,7 @@ #include -namespace ecl { +namespace rd { namespace util { class TestArea { @@ -28,9 +28,9 @@ class TestArea { }; } // namespace util -} // namespace ecl +} // namespace rd -typedef ecl::util::TestArea test_work_area_type; +typedef rd::util::TestArea test_work_area_type; #ifdef __cplusplus extern "C" { diff --git a/lib/include/ert/util/type_macros.h b/lib/include/ert/util/type_macros.h index 9d277d98c4..92ba3b82ba 100644 --- a/lib/include/ert/util/type_macros.h +++ b/lib/include/ert/util/type_macros.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/type_vector_functions.h b/lib/include/ert/util/type_vector_functions.h index 1450d45926..f93cb1693c 100644 --- a/lib/include/ert/util/type_vector_functions.h +++ b/lib/include/ert/util/type_vector_functions.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/util/vector.h b/lib/include/ert/util/vector.h index 9ec594b7ae..3cc2314fa8 100644 --- a/lib/include/ert/util/vector.h +++ b/lib/include/ert/util/vector.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ diff --git a/lib/include/ert/ecl/FortIO.hpp b/lib/include/resdata/FortIO.hpp similarity index 71% rename from lib/include/ert/ecl/FortIO.hpp rename to lib/include/resdata/FortIO.hpp index 795434b8e1..f7ec56ff76 100644 --- a/lib/include/ert/ecl/FortIO.hpp +++ b/lib/include/resdata/FortIO.hpp @@ -5,8 +5,8 @@ #include #include -#include -#include +#include +#include #include @@ -15,9 +15,9 @@ class FortIO { public: FortIO(); FortIO(const std::string &filename, std::ios_base::openmode mode, - bool fmt_file = false, bool endian_flip_header = ECL_ENDIAN_FLIP); + bool fmt_file = false, bool endian_flip_header = RD_ENDIAN_FLIP); void open(const std::string &filename, std::ios_base::openmode mode, - bool fmt_file = false, bool endian_flip_header = ECL_ENDIAN_FLIP); + bool fmt_file = false, bool endian_flip_header = RD_ENDIAN_FLIP); void fflush() const; bool ftruncate(offset_type new_size); diff --git a/lib/include/resdata/RDFilename.hpp b/lib/include/resdata/RDFilename.hpp new file mode 100644 index 0000000000..acf09cef60 --- /dev/null +++ b/lib/include/resdata/RDFilename.hpp @@ -0,0 +1,21 @@ +#ifndef ERT_RD_FILEMAME_HPP +#define ERT_RD_FILEMAME_HPP +#include + +#include + +namespace ERT { +std::string RDFilename(const std::string &base, rd_file_enum file_type, + int report_step, bool fmt_file = false); +std::string RDFilename(const std::string &base, rd_file_enum file_type, + bool fmt_file = false); + +std::string RDFilename(const std::string &path, const std::string &base, + rd_file_enum file_type, int report_step, + bool fmt_file = false); +std::string RDFilename(const std::string &path, const std::string &base, + rd_file_enum file_type, bool fmt_file = false); + +rd_file_enum RDFiletype(const std::string &filename); +} // namespace ERT +#endif diff --git a/lib/include/resdata/ResdataKW.hpp b/lib/include/resdata/ResdataKW.hpp new file mode 100644 index 0000000000..f1b4d41c69 --- /dev/null +++ b/lib/include/resdata/ResdataKW.hpp @@ -0,0 +1,244 @@ +#ifndef OPM_ERT_RD_KW +#define OPM_ERT_RD_KW + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace ERT { +template struct rd_type {}; + +template <> struct rd_type { + static const rd_type_enum type{RD_FLOAT_TYPE}; +}; + +template <> struct rd_type { + static const rd_type_enum type{RD_DOUBLE_TYPE}; +}; + +template <> struct rd_type { + static const rd_type_enum type{RD_INT_TYPE}; +}; + +template <> struct rd_type { + static const rd_type_enum type{RD_BOOL_TYPE}; +}; + +template <> struct rd_type { + static const rd_type_enum type{RD_CHAR_TYPE}; +}; + +template <> struct rd_type { + static const rd_type_enum type{RD_CHAR_TYPE}; +}; + +/* + Both std::string and char* are mapped to the eight character string type + RD_CHAR_TYPE. That implies that the variable length string type + RD_STRING is invisible from this API. + */ + +template <> struct rd_type { + static const rd_type_enum type{RD_CHAR_TYPE}; +}; + +template <> struct rd_type { + static const rd_type_enum type{RD_CHAR_TYPE}; +}; + +template class ResdataKW_ref { +public: + explicit ResdataKW_ref(rd_kw_type *kw) : m_kw(kw) { + if (rd_type_get_type(rd_kw_get_data_type(kw)) != rd_type::type) + throw std::invalid_argument("Type error"); + } + + ResdataKW_ref() noexcept = default; + + const char *name() const { return rd_kw_get_header(this->m_kw); } + + size_t size() const { return size_t(rd_kw_get_size(this->m_kw)); } + + void fwrite(FortIO &fortio) const { + rd_kw_fwrite(this->m_kw, fortio.get()); + } + + T at(size_t i) const { + return *static_cast(rd_kw_iget_ptr(this->m_kw, i)); + } + + T &operator[](size_t i) { + return *static_cast(rd_kw_iget_ptr(this->m_kw, i)); + } + + const typename std::remove_pointer::type *data() const { + using Tp = const typename std::remove_pointer::type *; + return static_cast(rd_kw_get_ptr(this->m_kw)); + } + + rd_kw_type *get() const { return this->m_kw; } + + void resize(size_t new_size) { rd_kw_resize(this->m_kw, new_size); } + +protected: + rd_kw_type *m_kw = nullptr; +}; + +template <> inline bool ResdataKW_ref::at(size_t i) const { + return rd_kw_iget_bool(this->m_kw, i); +} + +template <> inline const char *ResdataKW_ref::at(size_t i) const { + return rd_kw_iget_char_ptr(this->m_kw, i); +} + +template <> inline std::string ResdataKW_ref::at(size_t i) const { + return rd_kw_iget_char_ptr(this->m_kw, i); +} + +/* + The current implementation of "string" and "bool" storage in the underlying C + rd_kw structure does not lend itself to easily implement operator[]. We have + therefore explicitly deleted them here. +*/ + +template <> +const char *&ResdataKW_ref::operator[](size_t i) = delete; + +template <> bool &ResdataKW_ref::operator[](size_t i) = delete; + +template class ResdataKW : public ResdataKW_ref { +private: + using base = ResdataKW_ref; + +public: + using ResdataKW_ref::ResdataKW_ref; + + ResdataKW(const ResdataKW &) = delete; + ResdataKW(ResdataKW &&rhs) : base(rhs.m_kw) { rhs.m_kw = nullptr; } + + ~ResdataKW() { + if (this->m_kw) + rd_kw_free(this->m_kw); + } + + ResdataKW(const std::string &kw, int size_) + : base(rd_kw_alloc(kw.c_str(), size_, + rd_type_create_from_type(rd_type::type))) {} + + ResdataKW(const std::string &kw, const std::vector &data) + : ResdataKW(kw, data.size()) { + rd_kw_set_memcpy_data(this->m_kw, data.data()); + } + + template + ResdataKW(const std::string &kw, const std::vector &data) + : ResdataKW(kw, data.size()) { + T *target = static_cast(rd_kw_get_ptr(this->m_kw)); + + for (size_t i = 0; i < data.size(); ++i) + target[i] = T(data[i]); + } + + std::vector data() const { + const T *ptr = static_cast(rd_kw_get_ptr(this->m_kw)); + std::vector vector; + vector.assign(ptr, ptr + this->size()); + return vector; + } + + static ResdataKW load(FortIO &fortio) { + rd_kw_type *c_ptr = rd_kw_fread_alloc(fortio.get()); + + if (!c_ptr) + throw std::invalid_argument("fread kw failed - EOF?"); + + return ResdataKW(c_ptr); + } +}; + +template <> +inline ResdataKW::ResdataKW(const std::string &kw, + const std::vector &data) + : ResdataKW(kw, data.size()) { + auto *ptr = this->get(); + for (size_t i = 0; i < data.size(); ++i) { + if (strlen(data[i]) > 8) + throw std::range_error("Strings must be maximum 8 characters long"); + rd_kw_iset_string8(ptr, i, data[i]); + } +} + +template <> +inline ResdataKW::ResdataKW(const std::string &kw, + const std::vector &data) + : ResdataKW(kw, data.size()) { + auto *ptr = this->get(); + for (size_t i = 0; i < data.size(); ++i) { + if (data[i].size() > 8) + throw std::range_error("Strings must be maximum 8 characters long"); + rd_kw_iset_string8(ptr, i, data[i].c_str()); + } +} + +template <> +template <> +inline ResdataKW::ResdataKW(const std::string &kw, + const std::vector &data) + : ResdataKW(kw, data.size()) { + auto *ptr = this->get(); + for (size_t i = 0; i < data.size(); ++i) { + if (strlen(data[i]) > 8) + throw std::range_error("Strings must be maximum 8 characters long"); + rd_kw_iset_string8(ptr, i, data[i]); + } +} + +template <> +inline ResdataKW::ResdataKW(const std::string &kw, + const std::vector &data) + : ResdataKW(kw, data.size()) { + for (size_t i = 0; i < data.size(); i++) + rd_kw_iset_bool(this->m_kw, i, data[i]); +} + +template <> +inline std::vector ResdataKW::data() const { + std::vector strings; + auto *ptr = this->get(); + for (size_t i = 0; i < this->size(); ++i) { + std::string s8 = rd_kw_iget_char_ptr(ptr, i); + s8.erase(s8.find_last_not_of(' ') + 1); + strings.push_back(s8); + } + return strings; +} + +/* + Will write an rd_kw instance to the open Fortio file. +*/ +template +void write_kw(FortIO &fortio, const std::string &kw, + const std::vector &data) { + ResdataKW rd_kw(kw, data); + rd_kw_fwrite(rd_kw.get(), fortio.get()); +} + +/* + Will write an empty rd_kw instance of type 'MESS' to the Fortio file. +*/ +inline void write_mess(FortIO &fortio, const std::string &kw) { + rd_kw_type *rd_kw = rd_kw_alloc(kw.c_str(), 0, RD_MESS); + rd_kw_fwrite(rd_kw, fortio.get()); +} + +} // namespace ERT + +#endif diff --git a/lib/include/ert/ecl/fault_block.h b/lib/include/resdata/fault_block.h similarity index 57% rename from lib/include/ert/ecl/fault_block.h rename to lib/include/resdata/fault_block.h index b0c438dbf7..33c6eb0a8d 100644 --- a/lib/include/ert/ecl/fault_block.h +++ b/lib/include/resdata/fault_block.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl/fault_block.hpp b/lib/include/resdata/fault_block.hpp similarity index 97% rename from lib/include/ert/ecl/fault_block.hpp rename to lib/include/resdata/fault_block.hpp index 919f03d36f..61157a22ec 100644 --- a/lib/include/ert/ecl/fault_block.hpp +++ b/lib/include/resdata/fault_block.hpp @@ -10,8 +10,8 @@ extern "C" { #include -#include -#include +#include +#include typedef struct fault_block_struct fault_block_type; diff --git a/lib/include/ert/ecl/fault_block_layer.h b/lib/include/resdata/fault_block_layer.h similarity index 56% rename from lib/include/ert/ecl/fault_block_layer.h rename to lib/include/resdata/fault_block_layer.h index e445511ac4..44145a8247 100644 --- a/lib/include/ert/ecl/fault_block_layer.h +++ b/lib/include/resdata/fault_block_layer.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl/fault_block_layer.hpp b/lib/include/resdata/fault_block_layer.hpp similarity index 82% rename from lib/include/ert/ecl/fault_block_layer.hpp rename to lib/include/resdata/fault_block_layer.hpp index ec05f6036f..e7604cae37 100644 --- a/lib/include/ert/ecl/fault_block_layer.hpp +++ b/lib/include/resdata/fault_block_layer.hpp @@ -6,16 +6,16 @@ extern "C" { #include -#include -#include -#include -#include +#include +#include +#include +#include UTIL_IS_INSTANCE_HEADER(fault_block_layer); typedef struct fault_block_layer_struct fault_block_layer_type; -fault_block_layer_type *fault_block_layer_alloc(const ecl_grid_type *grid, +fault_block_layer_type *fault_block_layer_alloc(const rd_grid_type *grid, int k); void fault_block_layer_free(fault_block_layer_type *layer); void fault_block_layer_free__(void *arg); @@ -35,17 +35,17 @@ int fault_block_layer_get_max_id(const fault_block_layer_type *layer); int fault_block_layer_get_next_id(const fault_block_layer_type *layer); int fault_block_layer_get_size(const fault_block_layer_type *layer); bool fault_block_layer_scan_kw(fault_block_layer_type *layer, - const ecl_kw_type *fault_block_kw); + const rd_kw_type *fault_block_kw); bool fault_block_layer_load_kw(fault_block_layer_type *layer, - const ecl_kw_type *fault_block_kw); + const rd_kw_type *fault_block_kw); int fault_block_layer_get_k(const fault_block_layer_type *layer); void fault_block_layer_scan_layer(fault_block_layer_type *fault_layer, layer_type *layer); void fault_block_layer_insert_block_content(fault_block_layer_type *layer, const fault_block_type *src_block); bool fault_block_layer_export(const fault_block_layer_type *layer, - ecl_kw_type *faultblock_kw); -const ecl_grid_type * + rd_kw_type *faultblock_kw); +const rd_grid_type * fault_block_layer_get_grid(const fault_block_layer_type *layer); layer_type *fault_block_layer_get_layer(const fault_block_layer_type *layer); diff --git a/lib/include/ert/ecl/fortio.h b/lib/include/resdata/fortio.h similarity index 100% rename from lib/include/ert/ecl/fortio.h rename to lib/include/resdata/fortio.h diff --git a/lib/include/ert/ecl/grid_dims.h b/lib/include/resdata/grid_dims.h similarity index 57% rename from lib/include/ert/ecl/grid_dims.h rename to lib/include/resdata/grid_dims.h index f49b2b3695..e66d27d5f0 100644 --- a/lib/include/ert/ecl/grid_dims.h +++ b/lib/include/resdata/grid_dims.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl/grid_dims.hpp b/lib/include/resdata/grid_dims.hpp similarity index 100% rename from lib/include/ert/ecl/grid_dims.hpp rename to lib/include/resdata/grid_dims.hpp diff --git a/lib/include/ert/ecl/layer.h b/lib/include/resdata/layer.h similarity index 58% rename from lib/include/ert/ecl/layer.h rename to lib/include/resdata/layer.h index bb0a9b2a92..ed0f62ac9b 100644 --- a/lib/include/ert/ecl/layer.h +++ b/lib/include/resdata/layer.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl/layer.hpp b/lib/include/resdata/layer.hpp similarity index 96% rename from lib/include/ert/ecl/layer.hpp rename to lib/include/resdata/layer.hpp index 0d05afccbd..c8d0135172 100644 --- a/lib/include/ert/ecl/layer.hpp +++ b/lib/include/resdata/layer.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #ifdef __cplusplus extern "C" { @@ -58,7 +58,7 @@ void layer_add_interp_barrier(layer_type *layer, int c1, int c2); void layer_add_ijbarrier(layer_type *layer, int i1, int j1, int i2, int j2); void layer_add_barrier(layer_type *layer, int c1, int c2); void layer_memcpy(layer_type *target_layer, const layer_type *src_layer); -void layer_update_active(layer_type *layer, const ecl_grid_type *grid, int k); +void layer_update_active(layer_type *layer, const rd_grid_type *grid, int k); void layer_clear_cells(layer_type *layer); void layer_update_connected_cells(layer_type *layer, int i, int j, int org_value, int new_value); diff --git a/lib/include/ert/ecl/nnc_info.h b/lib/include/resdata/nnc_info.h similarity index 58% rename from lib/include/ert/ecl/nnc_info.h rename to lib/include/resdata/nnc_info.h index 322273f9e1..de5c44c3f6 100644 --- a/lib/include/ert/ecl/nnc_info.h +++ b/lib/include/resdata/nnc_info.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl/nnc_info.hpp b/lib/include/resdata/nnc_info.hpp similarity index 97% rename from lib/include/ert/ecl/nnc_info.hpp rename to lib/include/resdata/nnc_info.hpp index c518a4b83a..af8ff16242 100644 --- a/lib/include/ert/ecl/nnc_info.hpp +++ b/lib/include/resdata/nnc_info.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include typedef struct nnc_info_struct nnc_info_type; diff --git a/lib/include/ert/ecl/nnc_vector.h b/lib/include/resdata/nnc_vector.h similarity index 57% rename from lib/include/ert/ecl/nnc_vector.h rename to lib/include/resdata/nnc_vector.h index 75f53ed630..067b7d609e 100644 --- a/lib/include/ert/ecl/nnc_vector.h +++ b/lib/include/resdata/nnc_vector.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl/nnc_vector.hpp b/lib/include/resdata/nnc_vector.hpp similarity index 100% rename from lib/include/ert/ecl/nnc_vector.hpp rename to lib/include/resdata/nnc_vector.hpp diff --git a/lib/include/resdata/rd_box.hpp b/lib/include/resdata/rd_box.hpp new file mode 100644 index 0000000000..a1c01a2e79 --- /dev/null +++ b/lib/include/resdata/rd_box.hpp @@ -0,0 +1,24 @@ +#ifndef ERT_RD_BOX_H +#define ERT_RD_BOX_H + +#include +#include + +namespace rd { + +class rd_box { +public: + rd_box(const rd_grid_type *grid, int i1, int i2, int j1, int j2, int k1, + int k2); + const std::vector &active_list() const; + +private: + const rd_grid_type *grid; + + int i1, i2, j1, j2, k1, k2; + std::vector active_index_list; + std::vector global_index_list; +}; + +} // namespace rd +#endif diff --git a/lib/include/ert/ecl/ecl_coarse_cell.h b/lib/include/resdata/rd_coarse_cell.h similarity index 56% rename from lib/include/ert/ecl/ecl_coarse_cell.h rename to lib/include/resdata/rd_coarse_cell.h index c33cf5d116..791be99191 100644 --- a/lib/include/ert/ecl/ecl_coarse_cell.h +++ b/lib/include/resdata/rd_coarse_cell.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_coarse_cell.hpp b/lib/include/resdata/rd_coarse_cell.hpp new file mode 100644 index 0000000000..131ca3a878 --- /dev/null +++ b/lib/include/resdata/rd_coarse_cell.hpp @@ -0,0 +1,51 @@ +#ifndef ERT_RD_COARSE_CELL_H +#define ERT_RD_COARSE_CELL_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_coarse_cell_struct rd_coarse_cell_type; + +bool rd_coarse_cell_equal(const rd_coarse_cell_type *coarse_cell1, + const rd_coarse_cell_type *coarse_cell2); +rd_coarse_cell_type *rd_coarse_cell_alloc(void); +void rd_coarse_cell_update(rd_coarse_cell_type *coarse_cell, int i, int j, + int k, int global_index); +void rd_coarse_cell_free(rd_coarse_cell_type *coarse_cell); +void rd_coarse_cell_free__(void *arg); + +int rd_coarse_cell_get_i1(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_get_j1(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_get_k1(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_get_i2(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_get_j2(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_get_k2(const rd_coarse_cell_type *coarse_cell); +const int *rd_coarse_cell_get_box_ptr(const rd_coarse_cell_type *coarse_cell); + +int rd_coarse_cell_get_size(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_iget_cell_index(rd_coarse_cell_type *coarse_cell, + int group_index); +const int *rd_coarse_cell_get_index_ptr(rd_coarse_cell_type *coarse_cell); +const int_vector_type * +rd_coarse_cell_get_index_vector(rd_coarse_cell_type *coarse_cell); + +void rd_coarse_cell_reset_active_index(rd_coarse_cell_type *coarse_cell); +void rd_coarse_cell_update_index(rd_coarse_cell_type *coarse_cell, + int global_index, int *active_index, + int *active_fracture_index, int active_value); +int rd_coarse_cell_get_active_index(const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_get_active_fracture_index( + const rd_coarse_cell_type *coarse_cell); +int rd_coarse_cell_iget_active_cell_index( + const rd_coarse_cell_type *coarse_cell, int index); +int rd_coarse_cell_iget_active_value(const rd_coarse_cell_type *coarse_cell, + int index); +int rd_coarse_cell_get_num_active(const rd_coarse_cell_type *coarse_cell); +void rd_coarse_cell_fprintf(const rd_coarse_cell_type *coarse_cell, + FILE *stream); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/ert/ecl/ecl_endian_flip.h b/lib/include/resdata/rd_endian_flip.h similarity index 56% rename from lib/include/ert/ecl/ecl_endian_flip.h rename to lib/include/resdata/rd_endian_flip.h index 5502c63780..83b1e62668 100644 --- a/lib/include/ert/ecl/ecl_endian_flip.h +++ b/lib/include/resdata/rd_endian_flip.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_endian_flip.hpp b/lib/include/resdata/rd_endian_flip.hpp new file mode 100644 index 0000000000..c26fcd6bb6 --- /dev/null +++ b/lib/include/resdata/rd_endian_flip.hpp @@ -0,0 +1,41 @@ +#ifndef ERT_RD_ENDIAN_FLIP_H +#define ERT_RD_ENDIAN_FLIP_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + This header file checks if the restart format endianness and the hardware + endianness are equal, and defines the macro RD_ENDIAN_FLIP + accordingly. + + All the rd_xxx functions will use the RD_ENDIAN_FLIP macro to + determine whether the endian flip should be performed. When opening + a fortio instance explicitly you can use the RD_ENDIAN_FLIP macro + to get the endianness correct. +*/ + +#define RD_BYTE_ORDER __BIG_ENDIAN // Alternatively: __LITTLE_ENDIAN + +#ifdef BYTE_ORDER +#if BYTE_ORDER == RD_BYTE_ORDER +#define RD_ENDIAN_FLIP false +#else +#define RD_ENDIAN_FLIP true +#endif +#else +#ifdef WIN32 +#define RD_ENDIAN_FLIP true // Unconditional byte flip on Windows. +#else +#error : The macro BYTE_ORDER is not defined? +#endif +#endif + +#undef RD_BYTE_ORDER + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/ert/ecl/ecl_file.h b/lib/include/resdata/rd_file.h similarity index 58% rename from lib/include/ert/ecl/ecl_file.h rename to lib/include/resdata/rd_file.h index 92590dab85..f510f1073c 100644 --- a/lib/include/ert/ecl/ecl_file.h +++ b/lib/include/resdata/rd_file.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_file.hpp b/lib/include/resdata/rd_file.hpp new file mode 100644 index 0000000000..24bf254c49 --- /dev/null +++ b/lib/include/resdata/rd_file.hpp @@ -0,0 +1,128 @@ +#ifndef ERT_RD_FILE_H +#define ERT_RD_FILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + +#define RD_FILE_FLAGS_ENUM_DEFS \ + {.value = 1, .name = "RD_FILE_CLOSE_STREAM"}, { \ + .value = 2, .name = "RD_FILE_WRITABLE" \ + } +#define RD_FILE_FLAGS_ENUM_SIZE 2 + +typedef struct rd_file_struct rd_file_type; +bool rd_file_load_all(rd_file_type *rd_file); +rd_file_type *rd_file_open(const char *filename, int flags); +rd_file_type *rd_file_fast_open(const char *filename, + const char *index_filename, int flags); +bool rd_file_write_index(const rd_file_type *rd_file, + const char *index_filename); +bool rd_file_index_valid(const char *file_name, const char *index_file_name); +void rd_file_close(rd_file_type *rd_file); +void rd_file_fortio_detach(rd_file_type *rd_file); +void rd_file_free__(void *arg); +rd_kw_type *rd_file_icopy_named_kw(const rd_file_type *rd_file, const char *kw, + int ith); +rd_kw_type *rd_file_icopy_kw(const rd_file_type *rd_file, int index); +bool rd_file_has_kw(const rd_file_type *rd_file, const char *kw); +int rd_file_get_num_named_kw(const rd_file_type *rd_file, const char *kw); +int rd_file_get_size(const rd_file_type *rd_file); +int rd_file_get_num_distinct_kw(const rd_file_type *rd_file); +const char *rd_file_iget_distinct_kw(const rd_file_type *rd_file, int index); +const char *rd_file_get_src_file(const rd_file_type *rd_file); +int rd_file_iget_occurence(const rd_file_type *rd_file, int index); +rd_version_enum rd_file_get_rd_version(const rd_file_type *file); +void rd_file_fwrite_fortio(const rd_file_type *ec_file, fortio_type *fortio, + int offset); +void rd_file_fwrite(const rd_file_type *rd_file, const char *, bool fmt_file); + +void rd_file_replace_kw(rd_file_type *rd_file, rd_kw_type *old_kw, + rd_kw_type *new_kw, bool insert_copy); +int rd_file_get_phases(const rd_file_type *init_file); +void rd_file_fprintf_kw_list(const rd_file_type *rd_file, FILE *stream); + +bool rd_file_writable(const rd_file_type *rd_file); +int rd_file_get_flags(const rd_file_type *rd_file); +void rd_file_set_flags(rd_file_type *rd_file, int new_flags); +bool rd_file_flags_set(const rd_file_type *rd_file, int flags); + +rd_file_kw_type *rd_file_iget_file_kw(const rd_file_type *file, + int global_index); +rd_file_kw_type *rd_file_iget_named_file_kw(const rd_file_type *file, + const char *kw, int ith); +rd_kw_type *rd_file_iget_kw(const rd_file_type *file, int global_index); +rd_data_type rd_file_iget_data_type(const rd_file_type *file, int global_index); +int rd_file_iget_size(const rd_file_type *file, int global_index); +const char *rd_file_iget_header(const rd_file_type *file, int global_index); +rd_kw_type *rd_file_iget_named_kw(const rd_file_type *file, const char *kw, + int ith); +rd_data_type rd_file_iget_named_data_type(const rd_file_type *file, + const char *kw, int ith); +int rd_file_iget_named_size(const rd_file_type *file, const char *kw, int ith); +void rd_file_indexed_read(const rd_file_type *file, const char *kw, int index, + const int_vector_type *index_map, char *buffer); + +rd_file_view_type *rd_file_get_global_blockview(rd_file_type *rd_file, + const char *kw, int occurence); +rd_file_view_type *rd_file_alloc_global_blockview(rd_file_type *rd_file, + const char *kw, + int occurence); +rd_file_view_type *rd_file_get_global_view(rd_file_type *rd_file); +rd_file_view_type *rd_file_get_active_view(rd_file_type *rd_file); +//bool rd_file_writable( const rd_file_type * rd_file ); +bool rd_file_save_kw(const rd_file_type *rd_file, const rd_kw_type *rd_kw); +bool rd_file_has_kw_ptr(const rd_file_type *rd_file, const rd_kw_type *rd_kw); + +double rd_file_iget_restart_sim_days(const rd_file_type *restart_file, + int index); +time_t rd_file_iget_restart_sim_date(const rd_file_type *restart_file, + int occurence); +int rd_file_get_restart_index(const rd_file_type *restart_file, + time_t sim_time); +bool rd_file_has_report_step(const rd_file_type *rd_file, int report_step); +bool rd_file_has_sim_time(const rd_file_type *rd_file, time_t sim_time); + +void rd_file_close_fortio_stream(rd_file_type *rd_file); + +rd_file_view_type *rd_file_get_restart_view(rd_file_type *rd_file, + int input_index, int report_step, + time_t sim_time, double sim_days); +rd_file_view_type *rd_file_get_summary_view(rd_file_type *rd_file, + int report_step); + +UTIL_IS_INSTANCE_HEADER(rd_file); + +//Deprecated: + +void rd_file_push_block(rd_file_type *rd_file); +void rd_file_pop_block(rd_file_type *rd_file); +bool rd_file_subselect_block(rd_file_type *rd_file, const char *kw, + int occurence); +bool rd_file_select_block(rd_file_type *rd_file, const char *kw, int occurence); + +bool rd_file_select_rstblock_sim_time(rd_file_type *rd_file, time_t sim_time); +bool rd_file_select_rstblock_report_step(rd_file_type *rd_file, + int report_step); +bool rd_file_iselect_rstblock(rd_file_type *rd_file, int seqnum_index); +rd_file_type *rd_file_open_rstblock_report_step(const char *filename, + int report_step, int flags); +rd_file_type *rd_file_open_rstblock_sim_time(const char *filename, + time_t sim_time, int flags); +rd_file_type *rd_file_iopen_rstblock(const char *filename, int seqnum_index, + int flags); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/ert/ecl/ecl_file_kw.h b/lib/include/resdata/rd_file_kw.h similarity index 57% rename from lib/include/ert/ecl/ecl_file_kw.h rename to lib/include/resdata/rd_file_kw.h index d099600c45..cba8144a4d 100644 --- a/lib/include/ert/ecl/ecl_file_kw.h +++ b/lib/include/resdata/rd_file_kw.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_file_kw.hpp b/lib/include/resdata/rd_file_kw.hpp new file mode 100644 index 0000000000..f81f16f6bd --- /dev/null +++ b/lib/include/resdata/rd_file_kw.hpp @@ -0,0 +1,54 @@ +#ifndef ERT_RD_FILE_KW_H +#define ERT_RD_FILE_KW_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +#include +#include + +typedef struct rd_file_kw_struct rd_file_kw_type; +typedef struct inv_map_struct inv_map_type; + +inv_map_type *inv_map_alloc(void); +rd_file_kw_type *inv_map_get_file_kw(inv_map_type *inv_map, + const rd_kw_type *rd_kw); +void inv_map_free(inv_map_type *map); +bool rd_file_kw_equal(const rd_file_kw_type *kw1, const rd_file_kw_type *kw2); +rd_file_kw_type *rd_file_kw_alloc(const rd_kw_type *rd_kw, offset_type offset); +rd_file_kw_type *rd_file_kw_alloc0(const char *header, rd_data_type data_type, + int size, offset_type offset); +void rd_file_kw_free(rd_file_kw_type *file_kw); +void rd_file_kw_free__(void *arg); +rd_kw_type *rd_file_kw_get_kw(rd_file_kw_type *file_kw, fortio_type *fortio, + inv_map_type *inv_map); +rd_kw_type *rd_file_kw_get_kw_ptr(rd_file_kw_type *file_kw); +rd_file_kw_type *rd_file_kw_alloc_copy(const rd_file_kw_type *src); +const char *rd_file_kw_get_header(const rd_file_kw_type *file_kw); +int rd_file_kw_get_size(const rd_file_kw_type *file_kw); +rd_data_type rd_file_kw_get_data_type(const rd_file_kw_type *); +offset_type rd_file_kw_get_offset(const rd_file_kw_type *file_kw); +bool rd_file_kw_ptr_eq(const rd_file_kw_type *file_kw, const rd_kw_type *rd_kw); +void rd_file_kw_replace_kw(rd_file_kw_type *file_kw, fortio_type *target, + rd_kw_type *new_kw); +bool rd_file_kw_fskip_data(const rd_file_kw_type *file_kw, fortio_type *fortio); +void rd_file_kw_inplace_fwrite(rd_file_kw_type *file_kw, fortio_type *fortio); + +void rd_file_kw_fwrite(const rd_file_kw_type *file_kw, FILE *stream); +rd_file_kw_type **rd_file_kw_fread_alloc_multiple(FILE *stream, int num); +rd_file_kw_type *rd_file_kw_fread_alloc(FILE *stream); + +void rd_file_kw_start_transaction(const rd_file_kw_type *file_kw, + int *ref_count); +void rd_file_kw_end_transaction(rd_file_kw_type *file_kw, int ref_count); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/ert/ecl/ecl_file_view.h b/lib/include/resdata/rd_file_view.h similarity index 57% rename from lib/include/ert/ecl/ecl_file_view.h rename to lib/include/resdata/rd_file_view.h index 3953e36b8b..91716c472b 100644 --- a/lib/include/ert/ecl/ecl_file_view.h +++ b/lib/include/resdata/rd_file_view.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_file_view.hpp b/lib/include/resdata/rd_file_view.hpp new file mode 100644 index 0000000000..304f9cdd7a --- /dev/null +++ b/lib/include/resdata/rd_file_view.hpp @@ -0,0 +1,145 @@ +#ifndef ERT_RD_FILE_VIEW_H +#define ERT_RD_FILE_VIEW_H + +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + RD_FILE_CLOSE_STREAM = 1, /* + This flag will close the underlying FILE object between each access; this is + mainly to save filedescriptors in cases where many rd_file instances are open at + the same time. */ + RD_FILE_WRITABLE = 2 /* + This flag opens the file in a mode where it can be updated and modified, but it + must still exist and be readable. I.e. this should not compared with the normal: + fopen(filename , "w") where an existing file is truncated to zero upon successfull + open. + */ +} rd_file_flag_type; + +typedef struct rd_file_view_struct rd_file_view_type; +typedef struct rd_file_transaction_struct rd_file_transaction_type; + +bool rd_file_view_flags_set(const rd_file_view_type *file_view, + int query_flags); +bool rd_file_view_check_flags(int state_flags, int query_flags); + +rd_file_view_type *rd_file_view_alloc(fortio_type *fortio, int *flags, + inv_map_type *inv_map, bool owner); +int rd_file_view_get_global_index(const rd_file_view_type *rd_file_view, + const char *kw, int ith); +void rd_file_view_make_index(rd_file_view_type *rd_file_view); +bool rd_file_view_has_kw(const rd_file_view_type *rd_file_view, const char *kw); +rd_file_kw_type * +rd_file_view_iget_file_kw(const rd_file_view_type *rd_file_view, + int global_index); +rd_file_kw_type * +rd_file_view_iget_named_file_kw(const rd_file_view_type *rd_file_view, + const char *kw, int ith); +rd_kw_type *rd_file_view_iget_kw(const rd_file_view_type *rd_file_view, + int index); +void rd_file_view_index_fload_kw(const rd_file_view_type *rd_file_view, + const char *kw, int index, + const int_vector_type *index_map, + char *buffer); +int rd_file_view_find_kw_value(const rd_file_view_type *rd_file_view, + const char *kw, const void *value); +const char *rd_file_view_iget_distinct_kw(const rd_file_view_type *rd_file_view, + int index); +int rd_file_view_get_num_distinct_kw(const rd_file_view_type *rd_file_view); +int rd_file_view_get_size(const rd_file_view_type *rd_file_view); +rd_data_type rd_file_view_iget_data_type(const rd_file_view_type *rd_file_view, + int index); +int rd_file_view_iget_size(const rd_file_view_type *rd_file_view, int index); +const char *rd_file_view_iget_header(const rd_file_view_type *rd_file_view, + int index); +rd_kw_type *rd_file_view_iget_named_kw(const rd_file_view_type *rd_file_view, + const char *kw, int ith); +rd_data_type +rd_file_view_iget_named_data_type(const rd_file_view_type *rd_file_view, + const char *kw, int ith); +int rd_file_view_iget_named_size(const rd_file_view_type *rd_file_view, + const char *kw, int ith); +void rd_file_view_replace_kw(rd_file_view_type *rd_file_view, + rd_kw_type *old_kw, rd_kw_type *new_kw, + bool insert_copy); +bool rd_file_view_load_all(rd_file_view_type *rd_file_view); +void rd_file_view_add_kw(rd_file_view_type *rd_file_view, + rd_file_kw_type *file_kw); +void rd_file_view_free(rd_file_view_type *rd_file_view); +void rd_file_view_free__(void *arg); +int rd_file_view_get_num_named_kw(const rd_file_view_type *rd_file_view, + const char *kw); +void rd_file_view_fwrite(const rd_file_view_type *rd_file_view, + fortio_type *target, int offset); +int rd_file_view_iget_occurence(const rd_file_view_type *rd_file_view, + int global_index); +void rd_file_view_fprintf_kw_list(const rd_file_view_type *rd_file_view, + FILE *stream); +rd_file_view_type *rd_file_view_add_blockview(rd_file_view_type *rd_file_view, + const char *header, + int occurence); +rd_file_view_type *rd_file_view_add_blockview2(rd_file_view_type *rd_file_view, + const char *start_kw, + const char *end_kw, + int occurence); +rd_file_view_type *rd_file_view_add_restart_view(rd_file_view_type *file_view, + int seqnum_index, + int report_step, + time_t sim_time, + double sim_days); +rd_file_view_type * +rd_file_view_alloc_blockview(const rd_file_view_type *rd_file_view, + const char *header, int occurence); +rd_file_view_type * +rd_file_view_alloc_blockview2(const rd_file_view_type *rd_file_view, + const char *start_kw, const char *end_kw, + int occurence); + +void rd_file_view_add_child(rd_file_view_type *parent, + rd_file_view_type *child); +bool rd_file_view_drop_flag(rd_file_view_type *file_view, int flag); +void rd_file_view_add_flag(rd_file_view_type *file_view, int flag); + +int rd_file_view_seqnum_index_from_sim_time(rd_file_view_type *parent_map, + time_t sim_time); +bool rd_file_view_has_sim_time(const rd_file_view_type *rd_file_view, + time_t sim_time); +int rd_file_view_find_sim_time(const rd_file_view_type *rd_file_view, + time_t sim_time); +double rd_file_view_iget_restart_sim_days(const rd_file_view_type *rd_file_view, + int seqnum_index); +time_t rd_file_view_iget_restart_sim_date(const rd_file_view_type *rd_file_view, + int seqnum_index); +bool rd_file_view_has_report_step(const rd_file_view_type *rd_file_view, + int report_step); + +rd_file_view_type *rd_file_view_add_summary_view(rd_file_view_type *file_view, + int report_step); +const char *rd_file_view_get_src_file(const rd_file_view_type *file_view); +void rd_file_view_fclose_stream(rd_file_view_type *file_view); + +void rd_file_view_write_index(const rd_file_view_type *file_view, + FILE *ostream); +rd_file_view_type *rd_file_view_fread_alloc(fortio_type *fortio, int *flags, + inv_map_type *inv_map, + FILE *istream); + +rd_file_transaction_type * +rd_file_view_start_transaction(rd_file_view_type *file_view); +void rd_file_view_end_transaction(rd_file_view_type *file_view, + rd_file_transaction_type *transaction); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/ert/ecl/ecl_grid.h b/lib/include/resdata/rd_grav.h similarity index 58% rename from lib/include/ert/ecl/ecl_grid.h rename to lib/include/resdata/rd_grav.h index 3416a96c54..12e54adf86 100644 --- a/lib/include/ert/ecl/ecl_grid.h +++ b/lib/include/resdata/rd_grav.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_grav.hpp b/lib/include/resdata/rd_grav.hpp new file mode 100644 index 0000000000..ce17a57f7f --- /dev/null +++ b/lib/include/resdata/rd_grav.hpp @@ -0,0 +1,41 @@ +#ifndef ERT_RD_GRAV_H +#define ERT_RD_GRAV_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct rd_grav_struct rd_grav_type; +typedef struct rd_grav_survey_struct rd_grav_survey_type; + +void rd_grav_free(rd_grav_type *rd_grav_config); +rd_grav_type *rd_grav_alloc(const rd_grid_type *rd_grid, + const rd_file_type *init_file); +rd_grav_survey_type * +rd_grav_add_survey_FIP(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file); +rd_grav_survey_type * +rd_grav_add_survey_PORMOD(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file); +rd_grav_survey_type * +rd_grav_add_survey_RPORV(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file); +rd_grav_survey_type * +rd_grav_add_survey_RFIP(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file); +double rd_grav_eval(const rd_grav_type *grav, const char *base, + const char *monitor, rd_region_type *region, double utm_x, + double utm_y, double depth, int phase_mask); +void rd_grav_new_std_density(rd_grav_type *grav, rd_phase_enum phase, + double default_density); +void rd_grav_add_std_density(rd_grav_type *grav, rd_phase_enum phase, + int pvtnum, double density); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_grav_common.h b/lib/include/resdata/rd_grav_common.h new file mode 100644 index 0000000000..bc44af9765 --- /dev/null +++ b/lib/include/resdata/rd_grav_common.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_grav_common.hpp b/lib/include/resdata/rd_grav_common.hpp new file mode 100644 index 0000000000..5b427bb2c3 --- /dev/null +++ b/lib/include/resdata/rd_grav_common.hpp @@ -0,0 +1,32 @@ +#ifndef ERT_RD_GRAV_COMMON_H +#define ERT_RD_GRAV_COMMON_H + +#include + +#include +#include "detail/resdata/rd_grid_cache.hpp" + +#ifdef __cplusplus +extern "C" { +#endif + +bool *rd_grav_common_alloc_aquifer_cell(const rd::rd_grid_cache &grid_cache, + const rd_file_type *init_file); + +double rd_grav_common_eval_biot_savart(const rd::rd_grid_cache &grid_cache, + rd_region_type *region, + const bool *aquifer, + const double *weight, double utm_x, + double utm_y, double depth); + +double rd_grav_common_eval_geertsma(const rd::rd_grid_cache &grid_cache, + rd_region_type *region, const bool *aquifer, + const double *weight, double utm_x, + double utm_y, double depth, + double poisson_ratio, double seabed); + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/lib/include/ert/ecl/ecl_grav.h b/lib/include/resdata/rd_grid.h similarity index 58% rename from lib/include/ert/ecl/ecl_grav.h rename to lib/include/resdata/rd_grid.h index 296d4e0cee..405b359cf2 100644 --- a/lib/include/ert/ecl/ecl_grav.h +++ b/lib/include/resdata/rd_grid.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_grid.hpp b/lib/include/resdata/rd_grid.hpp new file mode 100644 index 0000000000..846d7547af --- /dev/null +++ b/lib/include/resdata/rd_grid.hpp @@ -0,0 +1,372 @@ +#ifndef ERT_RD_GRID_H +#define ERT_RD_GRID_H + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define RD_GRID_COORD_SIZE(nx, ny) (((nx) + 1) * ((ny) + 1) * 6) +#define RD_GRID_ZCORN_SIZE(nx, ny, nz) (((nx) * (ny) * (nz)*8)) + +#define RD_GRID_GLOBAL_GRID "Global" // used as key in hash tables over grids. +#define RD_GRID_MAINGRID_LGR_NR 0 + +typedef double(block_function_ftype)(const double_vector_type *); +typedef struct rd_grid_struct rd_grid_type; + +bool rd_grid_have_coarse_cells(const rd_grid_type *main_grid); +bool rd_grid_cell_in_coarse_group1(const rd_grid_type *main_grid, + int global_index); +bool rd_grid_cell_in_coarse_group3(const rd_grid_type *main_grid, int i, int j, + int k); +int rd_grid_get_num_coarse_groups(const rd_grid_type *main_grid); +rd_coarse_cell_type *rd_grid_iget_coarse_group(const rd_grid_type *rd_grid, + int coarse_nr); +rd_coarse_cell_type *rd_grid_get_cell_coarse_group1(const rd_grid_type *rd_grid, + int global_index); +rd_coarse_cell_type *rd_grid_get_cell_coarse_group3(const rd_grid_type *rd_grid, + int i, int j, int k); + +int rd_grid_get_cell_twist1(const rd_grid_type *rd_grid, int global_index); +int rd_grid_get_cell_twist3(const rd_grid_type *rd_grid, int i, int j, int k); + +void rd_grid_get_column_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, + double_vector_type *column); +int rd_grid_get_global_index_from_xy_top(const rd_grid_type *rd_grid, double x, + double y); +int rd_grid_get_global_index_from_xy_bottom(const rd_grid_type *rd_grid, + double x, double y); +rd_grid_type *rd_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, + const double *dx, const double *dy, + const double *dz, const double *tops, + const int *actnum); + +void rd_grid_get_cell_corner_xyz3(const rd_grid_type *grid, int i, int j, int k, + int corner_nr, double *xpos, double *ypos, + double *zpos); +void rd_grid_get_cell_corner_xyz1(const rd_grid_type *grid, int global_index, + int corner_nr, double *xpos, double *ypos, + double *zpos); +void rd_grid_get_corner_xyz(const rd_grid_type *grid, int i, int j, int k, + double *xpos, double *ypos, double *zpos); + +double rd_grid_get_cell_dx1A(const rd_grid_type *grid, int active_index); +double rd_grid_get_cell_dy1A(const rd_grid_type *grid, int active_index); +double rd_grid_get_cell_dz1A(const rd_grid_type *grid, int active_index); +double rd_grid_get_cell_thickness1A(const rd_grid_type *grid, int active_index); + +double rd_grid_get_cell_dx1(const rd_grid_type *grid, int global_index); +double rd_grid_get_cell_dy1(const rd_grid_type *grid, int global_index); +double rd_grid_get_cell_dz1(const rd_grid_type *grid, int global_index); +double rd_grid_get_cell_thickness1(const rd_grid_type *grid, int global_index); + +double rd_grid_get_cell_dx3(const rd_grid_type *grid, int i, int j, int k); +double rd_grid_get_cell_dy3(const rd_grid_type *grid, int i, int j, int k); +double rd_grid_get_cell_dz3(const rd_grid_type *grid, int i, int j, int k); +double rd_grid_get_cell_thickness3(const rd_grid_type *grid, int i, int j, + int k); + +void rd_grid_get_distance(const rd_grid_type *grid, int global_index1, + int global_index2, double *dx, double *dy, + double *dz); +double rd_grid_get_cdepth1A(const rd_grid_type *grid, int active_index); +double rd_grid_get_cdepth1(const rd_grid_type *grid, int global_index); +double rd_grid_get_cdepth3(const rd_grid_type *grid, int i, int j, int k); +int rd_grid_get_global_index_from_xy(const rd_grid_type *rd_grid, int k, + bool lower_layer, double x, double y); +bool rd_grid_cell_contains_xyz1(const rd_grid_type *rd_grid, int global_index, + double x, double y, double z); +bool rd_grid_cell_contains_xyz3(const rd_grid_type *rd_grid, int i, int j, + int k, double x, double y, double z); +double rd_grid_get_cell_volume1(const rd_grid_type *rd_grid, int global_index); +double rd_grid_get_cell_volume3(const rd_grid_type *rd_grid, int i, int j, + int k); +double rd_grid_get_cell_volume1A(const rd_grid_type *rd_grid, int active_index); +bool rd_grid_cell_contains1(const rd_grid_type *grid, int global_index, + double x, double y, double z); +bool rd_grid_cell_contains3(const rd_grid_type *grid, int i, int j, int k, + double x, double y, double z); +int rd_grid_get_global_index_from_xyz(rd_grid_type *grid, double x, double y, + double z, int start_index); +bool rd_grid_get_ijk_from_xyz(rd_grid_type *grid, double x, double y, double z, + int start_index, int *i, int *j, int *k); +bool rd_grid_get_ij_from_xy(const rd_grid_type *grid, double x, double y, int k, + int *i, int *j); +const char *rd_grid_get_name(const rd_grid_type *); +int rd_grid_get_active_index3(const rd_grid_type *rd_grid, int i, int j, int k); +int rd_grid_get_active_index1(const rd_grid_type *rd_grid, int global_index); +int rd_grid_get_active_fracture_index3(const rd_grid_type *rd_grid, int i, + int j, int k); +int rd_grid_get_active_fracture_index1(const rd_grid_type *rd_grid, + int global_index); +bool rd_grid_cell_active3(const rd_grid_type *, int, int, int); +bool rd_grid_cell_active1(const rd_grid_type *, int); +bool rd_grid_ijk_valid(const rd_grid_type *, int, int, int); +int rd_grid_get_global_index3(const rd_grid_type *, int, int, int); +int rd_grid_get_global_index1A(const rd_grid_type *rd_grid, int active_index); +int rd_grid_get_global_index1F(const rd_grid_type *rd_grid, + int active_fracture_index); + +const nnc_info_type *rd_grid_get_cell_nnc_info3(const rd_grid_type *grid, int i, + int j, int k); +const nnc_info_type *rd_grid_get_cell_nnc_info1(const rd_grid_type *grid, + int global_index); +void rd_grid_add_self_nnc(rd_grid_type *grid1, int g1, int g2, int nnc_index); +void rd_grid_add_self_nnc_list(rd_grid_type *grid, const int *g1_list, + const int *g2_list, int num_nnc); + +rd_grid_type *rd_grid_alloc_GRDECL_kw(int nx, int ny, int nz, + const rd_kw_type *zcorn_kw, + const rd_kw_type *coord_kw, + const rd_kw_type *actnum_kw, + const rd_kw_type *mapaxes_kw); +rd_grid_type *rd_grid_alloc_GRDECL_data(int, int, int, const float *, + const float *, const int *, + bool apply_mapaxes, + const float *mapaxes); +rd_grid_type *rd_grid_alloc_GRID_data(int num_coords, int nx, int ny, int nz, + int coords_size, int **coords, + float **corners, bool apply_mapaxes, + const float *mapaxes); +rd_grid_type *rd_grid_alloc(const char *); +rd_grid_type *rd_grid_alloc_ext_actnum(const char *, const int *ext_actnum); +rd_grid_type *rd_grid_load_case(const char *case_input); +rd_grid_type *rd_grid_load_case__(const char *case_input, bool apply_mapaxes); +rd_grid_type *rd_grid_alloc_rectangular(int nx, int ny, int nz, double dx, + double dy, double dz, + const int *actnum); +rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, const double *ivec, + const double *jvec, const double *kvec, + const int *actnum); +rd_grid_type *rd_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, + const double *dxv, const double *dyv, + const double *dzv, const int *actnum); +rd_grid_type * +rd_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, + const double *dyv, const double *dzv, + const double *depthz, const int *actnum); +rd_kw_type *rd_grid_alloc_volume_kw(const rd_grid_type *grid, bool active_size); +rd_kw_type *rd_grid_alloc_mapaxes_kw(const rd_grid_type *grid); +rd_kw_type *rd_grid_alloc_coord_kw(const rd_grid_type *grid); + +bool rd_grid_exists(const char *case_input); +char *rd_grid_alloc_case_filename(const char *case_input); + +void rd_grid_free(rd_grid_type *); +void rd_grid_free__(void *arg); +grid_dims_type rd_grid_iget_dims(const rd_grid_type *grid, int grid_nr); +void rd_grid_get_dims(const rd_grid_type *, int *, int *, int *, int *); +int rd_grid_get_nz(const rd_grid_type *grid); +int rd_grid_get_nx(const rd_grid_type *grid); +int rd_grid_get_ny(const rd_grid_type *grid); +int rd_grid_get_nactive(const rd_grid_type *grid); +int rd_grid_get_nactive_fracture(const rd_grid_type *grid); +int rd_grid_get_active_index(const rd_grid_type *, int, int, int); +void rd_grid_summarize(const rd_grid_type *); +void rd_grid_get_ijk1(const rd_grid_type *, int global_index, int *, int *, + int *); +void rd_grid_get_ijk1A(const rd_grid_type *, int active_index, int *, int *, + int *); +void rd_grid_get_ijk_from_active_index(const rd_grid_type *, int, int *, int *, + int *); + +void rd_grid_get_xyz3(const rd_grid_type *, int, int, int, double *, double *, + double *); +void rd_grid_get_xyz1(const rd_grid_type *grid, int global_index, double *xpos, + double *ypos, double *zpos); +void rd_grid_get_xyz1A(const rd_grid_type *grid, int active_index, double *xpos, + double *ypos, double *zpos); + +bool rd_grid_get_xyz_inside1(const rd_grid_type *grid, int global_index, + double *xpos, double *ypos, double *zpos); +bool rd_grid_get_xyz_inside3(const rd_grid_type *grid, int i, int j, int k, + double *xpos, double *ypos, double *zpos); + +int rd_grid_get_global_size(const rd_grid_type *rd_grid); +bool rd_grid_compare(const rd_grid_type *g1, const rd_grid_type *g2, + bool include_lgr, bool include_nnc, bool verbose); +int rd_grid_get_active_size(const rd_grid_type *rd_grid); + +double rd_grid_get_bottom1(const rd_grid_type *grid, int global_index); +double rd_grid_get_bottom3(const rd_grid_type *grid, int i, int j, int k); +double rd_grid_get_bottom1A(const rd_grid_type *grid, int active_index); +double rd_grid_get_top1(const rd_grid_type *grid, int global_index); +double rd_grid_get_top3(const rd_grid_type *grid, int i, int j, int k); +double rd_grid_get_top1A(const rd_grid_type *grid, int active_index); +double rd_grid_get_top2(const rd_grid_type *grid, int i, int j); +double rd_grid_get_bottom2(const rd_grid_type *grid, int i, int j); +int rd_grid_locate_depth(const rd_grid_type *grid, double depth, int i, int j); + +void rd_grid_alloc_blocking_variables(rd_grid_type *, int); +void rd_grid_init_blocking(rd_grid_type *); +double rd_grid_block_eval3d(rd_grid_type *grid, int i, int j, int k, + block_function_ftype *blockf); +int rd_grid_get_block_count3d(const rd_grid_type *rd_grid, int i, int j, int k); +bool rd_grid_block_value_3d(rd_grid_type *, double, double, double, double); + +bool rd_grid_cell_invalid1(const rd_grid_type *rd_grid, int global_index); +bool rd_grid_cell_invalid3(const rd_grid_type *rd_grid, int i, int j, int k); +double rd_grid_cell_invalid1A(const rd_grid_type *grid, int active_index); + +bool rd_grid_cell_valid1(const rd_grid_type *rd_grid, int global_index); +bool rd_grid_cell_valid3(const rd_grid_type *rd_grid, int i, int j, int k); +double rd_grid_cell_valid1A(const rd_grid_type *grid, int active_index); + +void rd_grid_dump(const rd_grid_type *grid, FILE *stream); +void rd_grid_dump_ascii(rd_grid_type *grid, bool active_only, FILE *stream); +void rd_grid_dump_ascii_cell1(rd_grid_type *grid, int global_index, + FILE *stream, const double *offset); +void rd_grid_dump_ascii_cell3(rd_grid_type *grid, int i, int j, int k, + FILE *stream, const double *offset); + +/* lgr related functions */ +const rd_grid_type *rd_grid_get_cell_lgr3(const rd_grid_type *grid, int i, + int j, int k); +const rd_grid_type *rd_grid_get_cell_lgr1A(const rd_grid_type *grid, + int active_index); +const rd_grid_type *rd_grid_get_cell_lgr1(const rd_grid_type *grid, + int global_index); +int rd_grid_get_num_lgr(const rd_grid_type *main_grid); +int rd_grid_get_lgr_nr(const rd_grid_type *rd_grid); +int rd_grid_get_lgr_nr_from_name(const rd_grid_type *grid, const char *name); +rd_grid_type *rd_grid_iget_lgr(const rd_grid_type *main_grid, int lgr_index); +rd_grid_type *rd_grid_get_lgr_from_lgr_nr(const rd_grid_type *main_grid, + int lgr_nr); +rd_grid_type *rd_grid_get_lgr(const rd_grid_type *main_grid, + const char *__lgr_name); +bool rd_grid_has_lgr(const rd_grid_type *main_grid, const char *__lgr_name); +bool rd_grid_has_lgr_nr(const rd_grid_type *main_grid, int lgr_nr); +const char *rd_grid_iget_lgr_name(const rd_grid_type *rd_grid, int lgr_index); +const char *rd_grid_get_lgr_name(const rd_grid_type *rd_grid, int lgr_nr); +stringlist_type *rd_grid_alloc_lgr_name_list(const rd_grid_type *rd_grid); +int rd_grid_get_parent_cell1(const rd_grid_type *grid, int global_index); +int rd_grid_get_parent_cell3(const rd_grid_type *grid, int i, int j, int k); +const rd_grid_type *rd_grid_get_global_grid(const rd_grid_type *grid); +bool rd_grid_is_lgr(const rd_grid_type *rd_grid); + +double rd_grid_get_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k); +float rd_grid_get_float_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k); +double rd_grid_get_double_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, + int k); +int rd_grid_get_int_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k); + +void rd_grid_grdecl_fprintf_kw(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, + const char *special_header, FILE *stream, + double double_default); +bool rd_grid_test_lgr_consistency(const rd_grid_type *rd_grid); + +void rd_grid_fwrite_dims(const rd_grid_type *grid, fortio_type *init_file, + ert_rd_unit_enum output_unit); +void rd_grid_fwrite_depth(const rd_grid_type *grid, fortio_type *init_file, + ert_rd_unit_enum ouput_unit); + +void rd_grid_fwrite_EGRID(rd_grid_type *grid, const char *filename, + bool metric_output); +void rd_grid_fwrite_EGRID2(rd_grid_type *grid, const char *filename, + ert_rd_unit_enum output_unit); + +void rd_grid_fwrite_GRID(const rd_grid_type *grid, const char *filename); +void rd_grid_fwrite_GRID2(const rd_grid_type *grid, const char *filename, + ert_rd_unit_enum output_unit); + +void rd_grid_fprintf_grdecl(rd_grid_type *grid, FILE *stream); +void rd_grid_fprintf_grdecl2(rd_grid_type *grid, FILE *stream, + ert_rd_unit_enum output_unit); + +int rd_grid_zcorn_index__(int nx, int ny, int i, int j, int k, int c); +int rd_grid_zcorn_index(const rd_grid_type *grid, int i, int j, int k, int c); +rd_grid_type *rd_grid_alloc_EGRID(const char *grid_file, bool apply_mapaxes); +rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes); + +float *rd_grid_alloc_zcorn_data(const rd_grid_type *grid); +rd_kw_type *rd_grid_alloc_zcorn_kw(const rd_grid_type *grid); +int *rd_grid_alloc_actnum_data(const rd_grid_type *grid); +rd_kw_type *rd_grid_alloc_actnum_kw(const rd_grid_type *grid); +rd_kw_type *rd_grid_alloc_hostnum_kw(const rd_grid_type *grid); +rd_kw_type *rd_grid_alloc_gridhead_kw(int nx, int ny, int nz, int grid_nr); +rd_grid_type *rd_grid_alloc_copy(const rd_grid_type *src_grid); +rd_grid_type *rd_grid_alloc_processed_copy(const rd_grid_type *src_grid, + const double *zcorn, + const int *actnum); + +void rd_grid_ri_export(const rd_grid_type *rd_grid, double *ri_points); +void rd_grid_cell_ri_export(const rd_grid_type *rd_grid, int global_index, + double *ri_points); + +bool rd_grid_dual_grid(const rd_grid_type *rd_grid); +int rd_grid_get_num_nnc(const rd_grid_type *grid); + +bool rd_grid_cell_regular3(const rd_grid_type *rd_grid, int i, int j, int k); +bool rd_grid_cell_regular1(const rd_grid_type *rd_grid, int global_index); + +void rd_grid_init_zcorn_data(const rd_grid_type *grid, float *zcorn); +void rd_grid_init_zcorn_data_double(const rd_grid_type *grid, double *zcorn); +int rd_grid_get_zcorn_size(const rd_grid_type *grid); + +void rd_grid_init_coord_data(const rd_grid_type *grid, float *coord); +void rd_grid_init_coord_data_double(const rd_grid_type *grid, double *coord); +int rd_grid_get_coord_size(const rd_grid_type *rd_grid); + +void rd_grid_init_actnum_data(const rd_grid_type *grid, int *actnum); +bool rd_grid_use_mapaxes(const rd_grid_type *grid); +void rd_grid_init_mapaxes_data_double(const rd_grid_type *grid, + double *mapaxes); +void rd_grid_reset_actnum(rd_grid_type *grid, const int *actnum); +void rd_grid_compressed_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, + const rd_kw_type *src_kw); +void rd_grid_global_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, + const rd_kw_type *src_kw); +void rd_grid_export_cell_corners1(const rd_grid_type *grid, int global_index, + double *x, double *y, double *z); + +ert_rd_unit_enum rd_grid_get_unit_system(const rd_grid_type *grid); +void rd_grid_export_index(const rd_grid_type *grid, int *global_index, + int *index_data, bool active_only); +void rd_grid_export_data_as_int(int index_size, const int *global_index, + const rd_kw_type *kw, int *output); +void rd_grid_export_data_as_double(int index_size, const int *data_index, + const rd_kw_type *kw, double *output); +void rd_grid_export_volume(const rd_grid_type *grid, int index_size, + const int *global_index, double *output); +void rd_grid_export_position(const rd_grid_type *grid, int index_size, + const int *global_index, double *output); +void export_corners(const rd_grid_type *grid, int index_size, + const int *global_index, double *output); + +UTIL_IS_INSTANCE_HEADER(rd_grid); +UTIL_SAFE_CAST_HEADER(rd_grid); + +#ifdef __cplusplus +} +namespace rd { + +rd_grid_type *rd_grid_alloc_GRDECL_data(int nx, int ny, int nz, + const double *zcorn, + const double *coord, const int *actnum, + bool apply_mapaxes, + const float *mapaxes); + +} + +#ifdef __cplusplus +#endif + +#endif +#endif diff --git a/lib/include/resdata/rd_grid_dims.h b/lib/include/resdata/rd_grid_dims.h new file mode 100644 index 0000000000..bf3ed38ac5 --- /dev/null +++ b/lib/include/resdata/rd_grid_dims.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_grid_dims.hpp b/lib/include/resdata/rd_grid_dims.hpp new file mode 100644 index 0000000000..28fd00e079 --- /dev/null +++ b/lib/include/resdata/rd_grid_dims.hpp @@ -0,0 +1,21 @@ +#ifndef ERT_RD_GRID_DIMS_H +#define ERT_RD_GRID_DIMS_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct rd_grid_dims_struct rd_grid_dims_type; + +rd_grid_dims_type *rd_grid_dims_alloc(const char *grid_file, + const char *data_file); +void rd_grid_dims_free(rd_grid_dims_type *grid_dims); +int rd_grid_dims_get_num_grids(const rd_grid_dims_type *grid_dims); +const grid_dims_type *rd_grid_dims_iget_dims(const rd_grid_dims_type *grid_dims, + int grid_nr); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_init_file.h b/lib/include/resdata/rd_init_file.h new file mode 100644 index 0000000000..50a0c3d059 --- /dev/null +++ b/lib/include/resdata/rd_init_file.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_init_file.hpp b/lib/include/resdata/rd_init_file.hpp new file mode 100644 index 0000000000..0ad81993c8 --- /dev/null +++ b/lib/include/resdata/rd_init_file.hpp @@ -0,0 +1,23 @@ +#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/include/resdata/rd_io_config.h b/lib/include/resdata/rd_io_config.h new file mode 100644 index 0000000000..fd23eac204 --- /dev/null +++ b/lib/include/resdata/rd_io_config.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_io_config.hpp b/lib/include/resdata/rd_io_config.hpp new file mode 100644 index 0000000000..d1d360eef9 --- /dev/null +++ b/lib/include/resdata/rd_io_config.hpp @@ -0,0 +1,26 @@ +#ifndef ERT_RD_IO_CONFIG_H +#define ERT_RD_IO_CONFIG_H +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_io_config_struct rd_io_config_type; + +/* Modifiers */ +void rd_io_config_set_formatted(rd_io_config_type *, bool); +void rd_io_config_set_unified_restart(rd_io_config_type *, bool); +void rd_io_config_set_unified_summary(rd_io_config_type *, bool); + +/* Accesors */ +bool rd_io_config_get_formatted(rd_io_config_type *); +bool rd_io_config_get_unified_restart(rd_io_config_type *); +bool rd_io_config_get_unified_summary(rd_io_config_type *); + +/* Allocater & destructor */ +rd_io_config_type *rd_io_config_alloc(bool, bool, bool); +void rd_io_config_free(rd_io_config_type *); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/ert/ecl/ecl_kw.h b/lib/include/resdata/rd_kw.h similarity index 58% rename from lib/include/ert/ecl/ecl_kw.h rename to lib/include/resdata/rd_kw.h index 4924910c1c..93f7690d0c 100644 --- a/lib/include/ert/ecl/ecl_kw.h +++ b/lib/include/resdata/rd_kw.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_kw.hpp b/lib/include/resdata/rd_kw.hpp new file mode 100644 index 0000000000..83c6e7744e --- /dev/null +++ b/lib/include/resdata/rd_kw.hpp @@ -0,0 +1,286 @@ +#ifndef ERT_RD_KW_H +#define ERT_RD_KW_H +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +UTIL_IS_INSTANCE_HEADER(rd_kw); + +typedef struct rd_kw_struct rd_kw_type; + +typedef enum { RD_KW_READ_OK = 0, RD_KW_READ_FAIL = 1 } rd_read_status_enum; + +/* + The size of an rd_kw instance is denoted with an integer. The + choice of int to store the size obviously limits the maximum size to + INT_MAX elements. This choice is an historical mistake - it should + probably have been size_t; however the rd_kw datastructure is + tightly bound to the on-disk binary format supplied by Eclipse, and + there the number of elements is stored as a signed(?) 32 bit + integer - so using int for size does make some sense- +*/ + +#define RD_KW_MAX_SIZE INT_MAX + +/* + Character data in restart format files comes as an array of fixed-length + string. Each of these strings is 8 characters long. The type name, + i.e. 'REAL', 'INTE', ... , come as 4 character strings. +*/ +#define RD_KW_HEADER_DATA_SIZE RD_STRING8_LENGTH + RD_TYPE_LENGTH + 4 +#define RD_KW_HEADER_FORTIO_SIZE RD_KW_HEADER_DATA_SIZE + 8 + +int rd_kw_first_different(const rd_kw_type *kw1, const rd_kw_type *kw2, + int offset, double abs_epsilon, double rel_epsilon); +size_t rd_kw_fortio_size(const rd_kw_type *rd_kw); +void *rd_kw_get_ptr(const rd_kw_type *rd_kw); +void rd_kw_set_data_ptr(rd_kw_type *rd_kw, void *data); +void rd_kw_fwrite_data(const rd_kw_type *_rd_kw, fortio_type *fortio); +bool rd_kw_fread_realloc_data(rd_kw_type *rd_kw, fortio_type *fortio); +rd_data_type rd_kw_get_data_type(const rd_kw_type *); +const char *rd_kw_get_header8(const rd_kw_type *); +const char *rd_kw_get_header(const rd_kw_type *rd_kw); +rd_kw_type *rd_kw_alloc_empty(void); +rd_read_status_enum rd_kw_fread_header(rd_kw_type *, fortio_type *); +void rd_kw_set_header_name(rd_kw_type *, const char *); +bool rd_kw_fseek_kw(const char *, bool, bool, fortio_type *); +bool rd_kw_fseek_last_kw(const char *, bool, fortio_type *); +void rd_kw_inplace_update_file(const rd_kw_type *, const char *, int); +void rd_kw_fskip(fortio_type *); +void rd_kw_alloc_data(rd_kw_type *); +void rd_kw_alloc_double_data(rd_kw_type *rd_kw, double *values); +void rd_kw_alloc_float_data(rd_kw_type *rd_kw, float *values); +bool rd_kw_fread_realloc(rd_kw_type *, fortio_type *); +void rd_kw_fread(rd_kw_type *, fortio_type *); +rd_kw_type *rd_kw_fread_alloc(fortio_type *); +rd_kw_type *rd_kw_alloc_actnum(const rd_kw_type *porv_kw, float porv_limit); +rd_kw_type *rd_kw_alloc_actnum_bitmask(const rd_kw_type *porv_kw, + float porv_limit, int actnum_bitmask); +void rd_kw_free_data(rd_kw_type *); +void rd_kw_fread_indexed_data(fortio_type *fortio, offset_type data_offset, + rd_data_type, int element_count, + const int_vector_type *index_map, char *buffer); +void rd_kw_free(rd_kw_type *); +void rd_kw_free__(void *); +rd_kw_type *rd_kw_alloc_copy(const rd_kw_type *); +rd_kw_type *rd_kw_alloc_sub_copy(const rd_kw_type *src, const char *new_kw, + int offset, int count); +const void *rd_kw_copyc__(const void *); +rd_kw_type *rd_kw_alloc_slice_copy(const rd_kw_type *src, int index1, + int index2, int stride); +void rd_kw_resize(rd_kw_type *rd_kw, int new_size); +//void * rd_kw_get_data_ref(const rd_kw_type *); +void *rd_kw_alloc_data_copy(const rd_kw_type *); +void rd_kw_memcpy(rd_kw_type *, const rd_kw_type *); +void rd_kw_get_memcpy_data(const rd_kw_type *, void *); +void rd_kw_get_memcpy_float_data(const rd_kw_type *rd_kw, float *target); +void rd_kw_get_memcpy_double_data(const rd_kw_type *rd_kw, double *target); +void rd_kw_get_memcpy_int_data(const rd_kw_type *rd_kw, int *target); +void rd_kw_set_memcpy_data(rd_kw_type *, const void *); +bool rd_kw_fwrite(const rd_kw_type *, fortio_type *); +void rd_kw_iget(const rd_kw_type *, int, void *); +void rd_kw_iset(rd_kw_type *rd_kw, int i, const void *iptr); +void rd_kw_iset_char_ptr(rd_kw_type *rd_kw, int index, const char *s); +void rd_kw_iset_string8(rd_kw_type *rd_kw, int index, const char *s8); +void rd_kw_iset_string_ptr(rd_kw_type *, int, const char *); +const char *rd_kw_iget_string_ptr(const rd_kw_type *, int); +const char *rd_kw_iget_char_ptr(const rd_kw_type *rd_kw, int i); +void *rd_kw_iget_ptr(const rd_kw_type *, int); +int rd_kw_get_size(const rd_kw_type *); +bool rd_kw_ichar_eq(const rd_kw_type *, int, const char *); +rd_kw_type *rd_kw_alloc(const char *header, int size, rd_data_type); +rd_kw_type *rd_kw_alloc_new(const char *, int, rd_data_type, const void *); +rd_kw_type *rd_kw_alloc_new_shared(const char *, int, rd_data_type, void *); +rd_kw_type *rd_kw_alloc_global_copy(const rd_kw_type *src, + const rd_kw_type *actnum); +void rd_kw_fwrite_param(const char *, bool, const char *, rd_data_type, int, + void *); +void rd_kw_fwrite_param_fortio(fortio_type *, const char *, rd_data_type, int, + void *); +void rd_kw_summarize(const rd_kw_type *rd_kw); +void rd_kw_fread_double_param(const char *, bool, double *); +float rd_kw_iget_as_float(const rd_kw_type *rd_kw, int i); +double rd_kw_iget_as_double(const rd_kw_type *rd_kw, int i); +void rd_kw_get_data_as_double(const rd_kw_type *, double *); +void rd_kw_get_data_as_float(const rd_kw_type *rd_kw, float *float_data); +bool rd_kw_name_equal(const rd_kw_type *rd_kw, const char *name); +bool rd_kw_header_eq(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2); +bool rd_kw_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2); +bool rd_kw_size_and_type_equal(const rd_kw_type *rd_kw1, + const rd_kw_type *rd_kw2); +bool rd_kw_icmp_string(const rd_kw_type *rd_kw, int index, + const char *other_string); +bool rd_kw_numeric_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2, + double abs_diff, double rel_diff); +bool rd_kw_block_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2, + int cmp_elements); +bool rd_kw_data_equal(const rd_kw_type *rd_kw, const void *data); +bool rd_kw_content_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2); +bool rd_kw_fskip_data__(rd_data_type, int, fortio_type *); +bool rd_kw_fskip_data(rd_kw_type *rd_kw, fortio_type *fortio); +bool rd_kw_fread_data(rd_kw_type *rd_kw, fortio_type *fortio); +void rd_kw_fskip_header(fortio_type *fortio); +bool rd_kw_size_and_numeric_type_equal(const rd_kw_type *kw1, + const rd_kw_type *kw2); +bool rd_kw_inplace_safe_div(rd_kw_type *target_kw, const rd_kw_type *divisor); +void rd_kw_inplace_sqrt(rd_kw_type *kw); + +bool rd_kw_is_kw_file(fortio_type *fortio); + +int rd_kw_element_sum_int(const rd_kw_type *rd_kw); +double rd_kw_element_sum_float(const rd_kw_type *rd_kw); +void rd_kw_inplace_inv(rd_kw_type *my_kw); +void rd_kw_element_sum(const rd_kw_type *, void *); +void rd_kw_element_sum_indexed(const rd_kw_type *rd_kw, + const int_vector_type *index_list, void *_sum); +void rd_kw_max_min(const rd_kw_type *, void *, void *); +void *rd_kw_get_void_ptr(const rd_kw_type *rd_kw); + +rd_kw_type *rd_kw_buffer_alloc(buffer_type *buffer); +void rd_kw_buffer_store(const rd_kw_type *rd_kw, buffer_type *buffer); + +void rd_kw_fprintf_data(const rd_kw_type *rd_kw, const char *fmt, FILE *stream); +void rd_kw_memcpy_data(rd_kw_type *target, const rd_kw_type *src); + +bool rd_kw_assert_numeric(const rd_kw_type *kw); +bool rd_kw_assert_binary(const rd_kw_type *kw1, const rd_kw_type *kw2); + +void rd_kw_scalar_set_bool(rd_kw_type *rd_kw, bool bool_value); +void rd_kw_scalar_set__(rd_kw_type *rd_kw, const void *value); +void rd_kw_scalar_set_float_or_double(rd_kw_type *rd_kw, double value); + +#define RD_KW_SCALAR_SET_TYPED_HEADER(ctype) \ + void rd_kw_scalar_set_##ctype(rd_kw_type *rd_kw, ctype value); +RD_KW_SCALAR_SET_TYPED_HEADER(int) +RD_KW_SCALAR_SET_TYPED_HEADER(float) +RD_KW_SCALAR_SET_TYPED_HEADER(double) +#undef RD_KW_SCALAR_SET_TYPED_HEADER + +rd_kw_type *rd_kw_alloc_scatter_copy(const rd_kw_type *src_kw, int target_size, + const int *mapping, void *def_value); + +void rd_kw_inplace_add_squared(rd_kw_type *target_kw, const rd_kw_type *add_kw); +void rd_kw_inplace_add(rd_kw_type *target_kw, const rd_kw_type *add_kw); +void rd_kw_inplace_sub(rd_kw_type *target_kw, const rd_kw_type *sub_kw); +void rd_kw_inplace_div(rd_kw_type *target_kw, const rd_kw_type *div_kw); +void rd_kw_inplace_mul(rd_kw_type *target_kw, const rd_kw_type *mul_kw); +void rd_kw_inplace_abs(rd_kw_type *kw); + +void rd_kw_inplace_add_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *add_kw); +void rd_kw_inplace_sub_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *sub_kw); +void rd_kw_inplace_mul_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *mul_kw); +void rd_kw_inplace_div_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *div_kw); +void rd_kw_copy_indexed(rd_kw_type *target_kw, const int_vector_type *index_set, + const rd_kw_type *src_kw); + +bool rd_kw_assert_binary_numeric(const rd_kw_type *kw1, const rd_kw_type *kw2); +#define RD_KW_ASSERT_TYPED_BINARY_OP_HEADER(ctype) \ + bool rd_kw_assert_binary_##ctype(const rd_kw_type *kw1, \ + const rd_kw_type *kw2) +RD_KW_ASSERT_TYPED_BINARY_OP_HEADER(int); +RD_KW_ASSERT_TYPED_BINARY_OP_HEADER(float); +RD_KW_ASSERT_TYPED_BINARY_OP_HEADER(double); +#undef RD_KW_ASSERT_TYPED_BINARY_OP_HEADER + +#define RD_KW_SCALE_TYPED_HEADER(ctype) \ + void rd_kw_scale_##ctype(rd_kw_type *rd_kw, ctype scale_factor) +RD_KW_SCALE_TYPED_HEADER(int); +RD_KW_SCALE_TYPED_HEADER(float); +RD_KW_SCALE_TYPED_HEADER(double); +#undef RD_KW_SCALE_TYPED_HEADER +void rd_kw_scale_float_or_double(rd_kw_type *rd_kw, double scale_factor); + +#define RD_KW_SHIFT_TYPED_HEADER(ctype) \ + void rd_kw_shift_##ctype(rd_kw_type *rd_kw, ctype shift_factor) +RD_KW_SHIFT_TYPED_HEADER(int); +RD_KW_SHIFT_TYPED_HEADER(float); +RD_KW_SHIFT_TYPED_HEADER(double); +#undef RD_KW_SHIFT_TYPED_HEADER +void rd_kw_shift_float_or_double(rd_kw_type *rd_kw, double shift_value); + +#define RD_KW_IGET_TYPED_HEADER(type) \ + type rd_kw_iget_##type(const rd_kw_type *, int) +RD_KW_IGET_TYPED_HEADER(double); +RD_KW_IGET_TYPED_HEADER(float); +RD_KW_IGET_TYPED_HEADER(int); +#undef RD_KW_IGET_TYPED_HEADER +bool rd_kw_iget_bool(const rd_kw_type *rd_kw, int i); + +#define RD_KW_ISET_TYPED_HEADER(type) \ + void rd_kw_iset_##type(rd_kw_type *, int, type) +RD_KW_ISET_TYPED_HEADER(double); +RD_KW_ISET_TYPED_HEADER(float); +RD_KW_ISET_TYPED_HEADER(int); +#undef RD_KW_ISET_TYPED_HEADER +void rd_kw_iset_bool(rd_kw_type *rd_kw, int i, bool bool_value); + +#define RD_KW_GET_TYPED_PTR_HEADER(type) \ + type *rd_kw_get_##type##_ptr(const rd_kw_type *) +RD_KW_GET_TYPED_PTR_HEADER(double); +RD_KW_GET_TYPED_PTR_HEADER(float); +RD_KW_GET_TYPED_PTR_HEADER(int); +RD_KW_GET_TYPED_PTR_HEADER(bool); +#undef RD_KW_GET_TYPED_PTR_HEADER + +#define RD_KW_SET_INDEXED_HEADER(ctype) \ + void rd_kw_set_indexed_##ctype( \ + rd_kw_type *rd_kw, const int_vector_type *index_list, ctype value) +RD_KW_SET_INDEXED_HEADER(double); +RD_KW_SET_INDEXED_HEADER(float); +RD_KW_SET_INDEXED_HEADER(int); +#undef RD_KW_SET_INDEXED_HEADER + +#define RD_KW_SHIFT_INDEXED_HEADER(ctype) \ + void rd_kw_shift_indexed_##ctype( \ + rd_kw_type *rd_kw, const int_vector_type *index_list, ctype shift) +RD_KW_SHIFT_INDEXED_HEADER(int); +RD_KW_SHIFT_INDEXED_HEADER(float); +RD_KW_SHIFT_INDEXED_HEADER(double); +#undef RD_KW_SHIFT_INDEXED_HEADER + +#define RD_KW_SCALE_INDEXED_HEADER(ctype) \ + void rd_kw_scale_indexed_##ctype( \ + rd_kw_type *rd_kw, const int_vector_type *index_list, ctype scale) +RD_KW_SCALE_INDEXED_HEADER(int); +RD_KW_SCALE_INDEXED_HEADER(float); +RD_KW_SCALE_INDEXED_HEADER(double); +#undef RD_KW_SCALE_INDEXED_HEADER + +#define RD_KW_MAX_MIN_HEADER(ctype) \ + void rd_kw_max_min_##ctype(const rd_kw_type *rd_kw, ctype *_max, \ + ctype *_min) +RD_KW_MAX_MIN_HEADER(int); +RD_KW_MAX_MIN_HEADER(float); +RD_KW_MAX_MIN_HEADER(double); +#undef RD_KW_MAX_MIN_HEADER + +void rd_kw_fix_uninitialized(rd_kw_type *rd_kw, int nx, int ny, int nz, + const int *actnum); + +rd_type_enum rd_kw_get_type(const rd_kw_type *); + +#include + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_kw_grdecl.h b/lib/include/resdata/rd_kw_grdecl.h new file mode 100644 index 0000000000..366a9afd1a --- /dev/null +++ b/lib/include/resdata/rd_kw_grdecl.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_kw_grdecl.hpp b/lib/include/resdata/rd_kw_grdecl.hpp new file mode 100644 index 0000000000..eb32049c77 --- /dev/null +++ b/lib/include/resdata/rd_kw_grdecl.hpp @@ -0,0 +1,46 @@ +/* + This header does not define datatypes; just a couple of functions. It should + be included from the rd_kw.h header, so applications do not need to include this + header explicitly. +*/ + +#ifndef ERT_RD_KW_GRDECL_H +#define ERT_RD_KW_GRDECL_H +#ifdef __cplusplus +extern "C" { +#endif + +bool rd_kw_grdecl_fseek_kw(const char *, bool, FILE *); + +rd_kw_type *rd_kw_fscanf_alloc_grdecl_dynamic__(FILE *stream, const char *kw, + bool strict, rd_data_type); +rd_kw_type *rd_kw_fscanf_alloc_grdecl_dynamic(FILE *stream, const char *kw, + rd_data_type); + +rd_kw_type *rd_kw_fscanf_alloc_grdecl_data__(FILE *stream, bool strict, + int size, rd_data_type data_type); +rd_kw_type *rd_kw_fscanf_alloc_grdecl_data(FILE *stream, int size, + rd_data_type data_type); + +rd_kw_type *rd_kw_fscanf_alloc_grdecl__(FILE *stream, const char *kw, + bool strict, int size, + rd_data_type data_type); +rd_kw_type *rd_kw_fscanf_alloc_grdecl(FILE *stream, const char *kw, int size, + rd_data_type data_type); + +rd_kw_type *rd_kw_fscanf_alloc_current_grdecl__(FILE *stream, bool strict, + rd_data_type data_type); +rd_kw_type *rd_kw_fscanf_alloc_current_grdecl(FILE *stream, + rd_data_type data_type); + +bool rd_kw_grdecl_fseek_next_kw(FILE *stream); +char *rd_kw_grdecl_alloc_next_header(FILE *stream); + +void rd_kw_fprintf_grdecl(const rd_kw_type *rd_kw, FILE *stream); +void rd_kw_fprintf_grdecl__(const rd_kw_type *rd_kw, const char *special_header, + FILE *stream); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_kw_magic.h b/lib/include/resdata/rd_kw_magic.h new file mode 100644 index 0000000000..2fcabeef27 --- /dev/null +++ b/lib/include/resdata/rd_kw_magic.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/ert/ecl/ecl_kw_magic.hpp b/lib/include/resdata/rd_kw_magic.hpp similarity index 99% rename from lib/include/ert/ecl/ecl_kw_magic.hpp rename to lib/include/resdata/rd_kw_magic.hpp index f47abd259c..062d7d3198 100644 --- a/lib/include/ert/ecl/ecl_kw_magic.hpp +++ b/lib/include/resdata/rd_kw_magic.hpp @@ -1,12 +1,12 @@ -#ifndef ERT_ECL_KW_MAGIC_H -#define ERT_ECL_KW_MAGIC_H +#ifndef ERT_RD_KW_MAGIC_H +#define ERT_RD_KW_MAGIC_H #ifdef __cplusplus extern "C" { #endif /* - This header file contains names and indices of ECLIPSE keywords + This header file contains names and indices of keywords which have special significance in various files. Observe that many of the keywords like e.g. INTEHEAD occur in many different file types, with partly overlapping layout and values. @@ -475,7 +475,7 @@ values (2e20) are denoted with '*'. /* Summary data files: */ #define SEQHDR_KW \ - "SEQHDR" // Contains a single 'magic' integer - not used in libecl. + "SEQHDR" // Contains a single 'magic' integer - not used in resdata. #define PARAMS_KW "PARAMS" // Contains the actual summary data for one timestep. #define MINISTEP_KW "MINISTEP" // Scalar integer - contains the timestep number. @@ -486,7 +486,7 @@ values (2e20) are denoted with '*'. /* There are no magic indices in the summary data files, for all - interesting data the table created from the ecl_smspec file must be + interesting data the table created from the rd_smspec file must be consulted. */ @@ -629,7 +629,7 @@ values (2e20) are denoted with '*'. #define GRIDHEAD_SIZE 100 /* Observe that these indices are one value lower than the values used - in the ecl_smspec file. */ + in the rd_smspec file. */ #define DIMENS_NX_INDEX 0 #define DIMENS_NY_INDEX 1 #define DIMENS_NZ_INDEX 2 diff --git a/lib/include/resdata/rd_nnc_data.h b/lib/include/resdata/rd_nnc_data.h new file mode 100644 index 0000000000..2fa2033058 --- /dev/null +++ b/lib/include/resdata/rd_nnc_data.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_nnc_data.hpp b/lib/include/resdata/rd_nnc_data.hpp new file mode 100644 index 0000000000..4d14a0de50 --- /dev/null +++ b/lib/include/resdata/rd_nnc_data.hpp @@ -0,0 +1,40 @@ +#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.h b/lib/include/resdata/rd_nnc_export.h new file mode 100644 index 0000000000..eb7bbb03ca --- /dev/null +++ b/lib/include/resdata/rd_nnc_export.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_nnc_export.hpp b/lib/include/resdata/rd_nnc_export.hpp new file mode 100644 index 0000000000..2bc1771a66 --- /dev/null +++ b/lib/include/resdata/rd_nnc_export.hpp @@ -0,0 +1,50 @@ +#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.h b/lib/include/resdata/rd_nnc_geometry.h new file mode 100644 index 0000000000..c5520809a0 --- /dev/null +++ b/lib/include/resdata/rd_nnc_geometry.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_nnc_geometry.hpp b/lib/include/resdata/rd_nnc_geometry.hpp new file mode 100644 index 0000000000..b3a3fd0017 --- /dev/null +++ b/lib/include/resdata/rd_nnc_geometry.hpp @@ -0,0 +1,36 @@ +#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/include/resdata/rd_region.h b/lib/include/resdata/rd_region.h new file mode 100644 index 0000000000..97035f9069 --- /dev/null +++ b/lib/include/resdata/rd_region.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_region.hpp b/lib/include/resdata/rd_region.hpp new file mode 100644 index 0000000000..0d7659447d --- /dev/null +++ b/lib/include/resdata/rd_region.hpp @@ -0,0 +1,243 @@ +#ifndef ERT_RD_REGION_H +#define ERT_RD_REGION_H +#include + +#include + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + SELECT_ALL = 0, + DESELECT_ALL = 1, + SELECT_FROM_IJK = 2, + DESELECT_FROM_IJK = 3, + SELECT_FROM_I = 4, + DSELECT_FROM_I = 5, + SELECT_FROM_J = 6, + DSELECT_FROM_J = 7, + SELECT_FROM_K = 8, + DSELECT_FROM_K = 9, + SELECT_EQUAL = 10, + DESELECT_EQUAL = 11, + SELECT_IN_INTERVAL = 12, + DESELECT_IN_INTERVAL = 13, + INVERT_SELECTION = 14 +} rd_region_select_cmd; + +typedef struct rd_region_struct rd_region_type; + +void rd_region_unlock(rd_region_type *region); +void rd_region_lock(rd_region_type *region); +void rd_region_reset(rd_region_type *rd_region); +rd_region_type *rd_region_alloc_copy(const rd_region_type *rd_region); +rd_region_type *rd_region_alloc(const rd_grid_type *rd_grid, bool preselect); +void rd_region_free(rd_region_type *region); +void rd_region_free__(void *__region); + +const int_vector_type *rd_region_get_active_list(rd_region_type *region); +const int_vector_type *rd_region_get_global_list(rd_region_type *region); +const int_vector_type *rd_region_get_global_active_list(rd_region_type *region); + +bool rd_region_contains_ijk(const rd_region_type *rd_region, int i, int j, + int k); +bool rd_region_contains_global(const rd_region_type *rd_region, + int global_index); +bool rd_region_contains_active(const rd_region_type *rd_region, + int active_index); + +void rd_region_select_true(rd_region_type *region, const rd_kw_type *rd_kw); + +void rd_region_invert_selection(rd_region_type *region); +void rd_region_select_all(rd_region_type *region); +void rd_region_deselect_all(rd_region_type *region); +void rd_region_deselect_true(rd_region_type *region, const rd_kw_type *rd_kw); +void rd_region_select_false(rd_region_type *region, const rd_kw_type *rd_kw); + +void rd_region_select_in_interval(rd_region_type *region, + const rd_kw_type *rd_kw, float min_value, + float max_value); +void rd_region_deselect_in_interval(rd_region_type *region, + const rd_kw_type *rd_kw, float min_value, + float max_value); + +void rd_region_select_equal(rd_region_type *region, const rd_kw_type *rd_kw, + int value); +void rd_region_deselect_equal(rd_region_type *region, const rd_kw_type *rd_kw, + int value); + +void rd_region_select_inactive_cells(rd_region_type *region); +void rd_region_deselect_inactive_cells(rd_region_type *region); +void rd_region_select_active_cells(rd_region_type *region); +void rd_region_deselect_active_cells(rd_region_type *region); + +void rd_region_select_from_ijkbox(rd_region_type *region, int i1, int i2, + int j1, int j2, int k1, int k2); +void rd_region_deselect_from_ijkbox(rd_region_type *region, int i1, int i2, + int j1, int j2, int k1, int k2); + +void rd_region_select_i1i2(rd_region_type *region, int i1, int i2); +void rd_region_deselect_i1i2(rd_region_type *region, int i1, int i2); +void rd_region_select_j1j2(rd_region_type *region, int j1, int j2); +void rd_region_deselect_j1j2(rd_region_type *region, int j1, int i2); +void rd_region_select_k1k2(rd_region_type *region, int k1, int k2); +void rd_region_deselect_k1k2(rd_region_type *region, int k1, int i2); + +void rd_region_select_shallow_cells(rd_region_type *region, double depth_limit); +void rd_region_deselect_shallow_cells(rd_region_type *region, + double depth_limit); +void rd_region_select_deep_cells(rd_region_type *region, double depth_limit); +void rd_region_deselect_deep_cells(rd_region_type *region, double depth_limit); + +void rd_region_select_thin_cells(rd_region_type *rd_region, double dz_limit); +void rd_region_deselect_thin_cells(rd_region_type *rd_region, double dz_limit); +void rd_region_select_thick_cells(rd_region_type *rd_region, double dz_limit); +void rd_region_deselect_thick_cells(rd_region_type *rd_region, double dz_limit); + +void rd_region_select_small_cells(rd_region_type *rd_region, + double volum_limit); +void rd_region_deselect_small_cells(rd_region_type *rd_region, + double volum_limit); +void rd_region_select_large_cells(rd_region_type *rd_region, + double volum_limit); +void rd_region_deselect_large_cells(rd_region_type *rd_region, + double volum_limit); + +void rd_region_select_global_index(rd_region_type *rd_region, int global_index); +void rd_region_deselect_global_index(rd_region_type *rd_region, + int global_index); + +void rd_region_select_active_index(rd_region_type *rd_region, int active_index); +void rd_region_deselect_active_index(rd_region_type *rd_region, + int active_index); + +void rd_region_intersection(rd_region_type *region, + const rd_region_type *new_region); +void rd_region_union(rd_region_type *region, const rd_region_type *new_region); +void rd_region_subtract(rd_region_type *region, + const rd_region_type *new_region); +void rd_region_xor(rd_region_type *region, const rd_region_type *new_region); + +void rd_region_select_smaller(rd_region_type *rd_region, + const rd_kw_type *rd_kw, float limit); +void rd_region_deselect_smaller(rd_region_type *rd_region, + const rd_kw_type *rd_kw, float limit); +void rd_region_select_larger(rd_region_type *rd_region, const rd_kw_type *rd_kw, + float limit); +void rd_region_deselect_larger(rd_region_type *rd_region, + const rd_kw_type *rd_kw, float limit); + +void rd_region_cmp_select_less(rd_region_type *rd_region, const rd_kw_type *kw1, + const rd_kw_type *kw2); +void rd_region_cmp_deselect_less(rd_region_type *rd_region, + const rd_kw_type *kw1, const rd_kw_type *kw2); +void rd_region_cmp_select_more(rd_region_type *rd_region, const rd_kw_type *kw1, + const rd_kw_type *kw2); +void rd_region_cmp_deselect_more(rd_region_type *rd_region, + const rd_kw_type *kw1, const rd_kw_type *kw2); + +void rd_region_select_in_cylinder(rd_region_type *region, double x0, double y0, + double R); +void rd_region_deselect_in_cylinder(rd_region_type *region, double x0, + double y0, double R); +void rd_region_select_in_zcylinder(rd_region_type *region, double x0, double y0, + double R, double z1, double z2); +void rd_region_deselect_in_zcylinder(rd_region_type *region, double x0, + double y0, double R, double z1, double z2); + +void rd_region_select_above_plane(rd_region_type *region, const double n[3], + const double p[3]); +void rd_region_select_below_plane(rd_region_type *region, const double n[3], + const double p[3]); +void rd_region_deselect_above_plane(rd_region_type *region, const double n[3], + const double p[3]); +void rd_region_deselect_below_plane(rd_region_type *region, const double n[3], + const double p[3]); + +void rd_region_select_inside_polygon(rd_region_type *region, + const geo_polygon_type *polygon); +void rd_region_deselect_inside_polygon(rd_region_type *region, + const geo_polygon_type *polygon); +void rd_region_select_outside_polygon(rd_region_type *region, + const geo_polygon_type *polygon); +void rd_region_deselect_outside_polygon(rd_region_type *region, + const geo_polygon_type *polygon); + +void rd_region_select_from_layer(rd_region_type *region, + const layer_type *layer, int k, + int layer_value); +void rd_region_deselect_from_layer(rd_region_type *region, + const layer_type *layer, int k, + int layer_value); +void rd_region_deselect_false(rd_region_type *region, const rd_kw_type *rd_kw); + +void rd_region_set_kw_int(rd_region_type *rd_region, rd_kw_type *rd_kw, + int value, bool force_active); +void rd_region_set_kw_float(rd_region_type *rd_region, rd_kw_type *rd_kw, + float value, bool force_active); +void rd_region_set_kw_double(rd_region_type *rd_region, rd_kw_type *rd_kw, + double value, bool force_active); +void rd_region_kw_copy(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *src_kw, bool force_active); +int rd_region_get_kw_size(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active); + +void rd_region_kw_iadd(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *delta_kw, bool force_active); +void rd_region_kw_idiv(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *div_kw, bool force_active); +void rd_region_kw_imul(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *mul_kw, bool force_active); +void rd_region_kw_isub(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *delta_kw, bool force_active); + +bool rd_region_equal(const rd_region_type *region1, + const rd_region_type *region2); + +void rd_region_scale_kw_float(rd_region_type *rd_region, rd_kw_type *rd_kw, + float value, bool force_active); +void rd_region_scale_kw_double(rd_region_type *rd_region, rd_kw_type *rd_kw, + double value, bool force_active); +void rd_region_scale_kw_int(rd_region_type *rd_region, rd_kw_type *rd_kw, + int value, bool force_active); +void rd_region_shift_kw_int(rd_region_type *rd_region, rd_kw_type *rd_kw, + int value, bool force_active); +void rd_region_shift_kw_double(rd_region_type *rd_region, rd_kw_type *rd_kw, + double value, bool force_active); +void rd_region_shift_kw_float(rd_region_type *rd_region, rd_kw_type *rd_kw, + float value, bool force_active); + +const int_vector_type *rd_region_get_kw_index_list(rd_region_type *rd_region, + const rd_kw_type *rd_kw, + bool force_active); + +void rd_region_set_name(rd_region_type *region, const char *name); +const char *rd_region_get_name(const rd_region_type *region); + +int rd_region_get_active_size_cpp(rd_region_type *region); +int rd_region_get_global_size_cpp(rd_region_type *region); +const int *rd_region_get_active_list_cpp(rd_region_type *region); +const int *rd_region_get_global_list_cpp(rd_region_type *region); + +double rd_region_sum_kw_double(rd_region_type *rd_region, + const rd_kw_type *rd_kw, bool force_active); +int rd_region_sum_kw_int(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active); +float rd_region_sum_kw_float(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active); +int rd_region_sum_kw_bool(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active); + +UTIL_IS_INSTANCE_HEADER(rd_region); +UTIL_SAFE_CAST_HEADER(rd_region); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_rft_cell.h b/lib/include/resdata/rd_rft_cell.h new file mode 100644 index 0000000000..52d5dc411b --- /dev/null +++ b/lib/include/resdata/rd_rft_cell.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_rft_cell.hpp b/lib/include/resdata/rd_rft_cell.hpp new file mode 100644 index 0000000000..0009d19b4c --- /dev/null +++ b/lib/include/resdata/rd_rft_cell.hpp @@ -0,0 +1,59 @@ +#ifndef ERT_RD_RFT_CELL_H +#define ERT_RD_RFT_CELL_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define RD_RFT_CELL_INVALID_VALUE -1 + +typedef struct rd_rft_cell_struct rd_rft_cell_type; + +UTIL_IS_INSTANCE_HEADER(rd_rft_cell); + +rd_rft_cell_type * +rd_rft_cell_alloc_PLT(int i, int j, int k, double depth, double pressure, + double orat, double grat, double wrat, + double connection_start, double connection_end, + double flowrate, double oil_flowrate, double gas_flowrate, + double water_flowrate); + +rd_rft_cell_type *rd_rft_cell_alloc_RFT(int i, int j, int k, double depth, + double pressure, double swat, + double sgas); +void rd_rft_cell_free(rd_rft_cell_type *cell); +void rd_rft_cell_free__(void *arg); + +bool rd_rft_cell_ijk_equal(const rd_rft_cell_type *cell, int i, int j, int k); +void rd_rft_cell_get_ijk(const rd_rft_cell_type *cell, int *i, int *j, int *k); +int rd_rft_cell_get_i(const rd_rft_cell_type *cell); +int rd_rft_cell_get_j(const rd_rft_cell_type *cell); +int rd_rft_cell_get_k(const rd_rft_cell_type *cell); +double rd_rft_cell_get_depth(const rd_rft_cell_type *cell); +double rd_rft_cell_get_pressure(const rd_rft_cell_type *cell); + +double rd_rft_cell_get_swat(const rd_rft_cell_type *cell); +double rd_rft_cell_get_sgas(const rd_rft_cell_type *cell); +double rd_rft_cell_get_soil(const rd_rft_cell_type *cell); + +double rd_rft_cell_get_wrat(const rd_rft_cell_type *cell); +double rd_rft_cell_get_grat(const rd_rft_cell_type *cell); +double rd_rft_cell_get_orat(const rd_rft_cell_type *cell); +double rd_rft_cell_get_connection_start(const rd_rft_cell_type *cell); +double rd_rft_cell_get_connection_end(const rd_rft_cell_type *cell); +double rd_rft_cell_get_flowrate(const rd_rft_cell_type *cell); +double rd_rft_cell_get_oil_flowrate(const rd_rft_cell_type *cell); +double rd_rft_cell_get_gas_flowrate(const rd_rft_cell_type *cell); +double rd_rft_cell_get_water_flowrate(const rd_rft_cell_type *cell); + +int rd_rft_cell_cmp__(const void *arg1, const void *arg2); +int rd_rft_cell_cmp(const rd_rft_cell_type *cell1, + const rd_rft_cell_type *cell2); +bool rd_rft_cell_lt(const rd_rft_cell_type *cell1, + const rd_rft_cell_type *cell2); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/resdata/rd_rft_file.h b/lib/include/resdata/rd_rft_file.h new file mode 100644 index 0000000000..8da1a521ed --- /dev/null +++ b/lib/include/resdata/rd_rft_file.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_rft_file.hpp b/lib/include/resdata/rd_rft_file.hpp new file mode 100644 index 0000000000..b3c4047a5f --- /dev/null +++ b/lib/include/resdata/rd_rft_file.hpp @@ -0,0 +1,50 @@ +#ifndef ERT_RD_RFT_FILE_H +#define ERT_RD_RFT_FILE_H +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include + +#include +#include +#include + +typedef struct rd_rft_file_struct rd_rft_file_type; + +char *rd_rft_file_alloc_case_filename(const char *case_input); +const char *rd_rft_file_get_filename(const rd_rft_file_type *rft_file); +rd_rft_file_type *rd_rft_file_alloc_case(const char *case_input); +bool rd_rft_file_case_has_rft(const char *case_input); +rd_rft_file_type *rd_rft_file_alloc(const char *); +void rd_rft_file_free(rd_rft_file_type *); +void rd_rft_file_block(const rd_rft_file_type *, double, const char *, int, + const double *, int *, int *, int *); +void rd_rft_file_fprintf_rft_obs(const rd_rft_file_type *, double, const char *, + const char *, const char *, double); +rd_rft_node_type *rd_rft_file_get_node(const rd_rft_file_type *, const char *); + +int rd_rft_file_get_size__(const rd_rft_file_type *rft_file, + const char *well_pattern, time_t recording_time); +int rd_rft_file_get_size(const rd_rft_file_type *rft_file); +rd_rft_node_type * +rd_rft_file_get_well_time_rft(const rd_rft_file_type *rft_file, + const char *well, time_t recording_time); +rd_rft_node_type *rd_rft_file_iget_node(const rd_rft_file_type *rft_file, + int index); +rd_rft_node_type *rd_rft_file_iget_well_rft(const rd_rft_file_type *rft_file, + const char *well, int index); +bool rd_rft_file_has_well(const rd_rft_file_type *rft_file, const char *well); +int rd_rft_file_get_well_occurences(const rd_rft_file_type *rft_file, + const char *well); +stringlist_type *rd_rft_file_alloc_well_list(const rd_rft_file_type *rft_file); +int rd_rft_file_get_num_wells(const rd_rft_file_type *rft_file); +void rd_rft_file_free__(void *arg); +void rd_rft_file_update(const char *rft_file_name, rd_rft_node_type **nodes, + int num_nodes, ert_rd_unit_enum unit_set); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_rft_node.h b/lib/include/resdata/rd_rft_node.h new file mode 100644 index 0000000000..faa08d1386 --- /dev/null +++ b/lib/include/resdata/rd_rft_node.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_rft_node.hpp b/lib/include/resdata/rd_rft_node.hpp new file mode 100644 index 0000000000..ea92bd28ff --- /dev/null +++ b/lib/include/resdata/rd_rft_node.hpp @@ -0,0 +1,70 @@ +#ifndef ERT_RD_RFT_NODE_H +#define ERT_RD_RFT_NODE_H +#ifdef __cplusplus +extern "C" { +#endif +#include + +#include +#include +#include + +typedef enum { + RFT = 1, + PLT = 2, + SEGMENT = 3 /* Not really implemented */ +} rd_rft_enum; + +typedef struct rd_rft_node_struct rd_rft_node_type; + +void rd_rft_node_inplace_sort_cells(rd_rft_node_type *rft_node); +const rd_rft_cell_type *rd_rft_node_iget_cell_sorted(rd_rft_node_type *rft_node, + int index); +const rd_rft_cell_type *rd_rft_node_iget_cell(const rd_rft_node_type *rft_node, + int index); +const rd_rft_cell_type *rd_rft_node_lookup_ijk(const rd_rft_node_type *rft_node, + int i, int j, int k); +void rd_rft_node_fprintf_rft_obs(const rd_rft_node_type *, double, const char *, + const char *, double); +rd_rft_node_type *rd_rft_node_alloc(const rd_file_view_type *rft_view); +void rd_rft_node_free(rd_rft_node_type *); +void rd_rft_node_free__(void *); +time_t rd_rft_node_get_date(const rd_rft_node_type *); +int rd_rft_node_get_size(const rd_rft_node_type *); +const char *rd_rft_node_get_well_name(const rd_rft_node_type *rft_node); +void rd_rft_node_iget_ijk(const rd_rft_node_type *rft_node, int index, int *i, + int *j, int *k); + +bool rd_rft_node_is_RFT(const rd_rft_node_type *rft_node); +bool rd_rft_node_is_PLT(const rd_rft_node_type *rft_node); +bool rd_rft_node_is_SEGMENT(const rd_rft_node_type *rft_node); +bool rd_rft_node_is_MSW(const rd_rft_node_type *rft_node); + +double rd_rft_node_iget_pressure(const rd_rft_node_type *rft_node, int index); +double rd_rft_node_iget_depth(const rd_rft_node_type *rft_node, int index); +double rd_rft_node_iget_wrat(const rd_rft_node_type *rft_node, int index); +double rd_rft_node_iget_grat(const rd_rft_node_type *rft_node, int index); +double rd_rft_node_iget_orat(const rd_rft_node_type *rft_node, int index); + +double rd_rft_node_iget_swat(const rd_rft_node_type *rft_node, int index); +double rd_rft_node_iget_sgas(const rd_rft_node_type *rft_node, int index); +double rd_rft_node_iget_soil(const rd_rft_node_type *rft_node, int index); +void rd_rft_node_fwrite(const rd_rft_node_type *rft_node, fortio_type *fortio, + ert_rd_unit_enum unit_set); +double rd_rft_node_get_days(const rd_rft_node_type *rft_node); +int rd_rft_node_cmp(const rd_rft_node_type *n1, const rd_rft_node_type *n2); +bool rd_rft_node_lt(const rd_rft_node_type *n1, const rd_rft_node_type *n2); + +void rd_rft_node_append_cell(rd_rft_node_type *rft_node, + rd_rft_cell_type *cell); +rd_rft_node_type *rd_rft_node_alloc_new(const char *well_name, + const char *data_type_string, + const time_t recording_date, + const double days); + +rd_rft_enum rd_rft_node_get_type(const rd_rft_node_type *rft_node); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_rst_file.h b/lib/include/resdata/rd_rst_file.h new file mode 100644 index 0000000000..d10fb5c91c --- /dev/null +++ b/lib/include/resdata/rd_rst_file.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_rst_file.hpp b/lib/include/resdata/rd_rst_file.hpp new file mode 100644 index 0000000000..cdfc09718c --- /dev/null +++ b/lib/include/resdata/rd_rst_file.hpp @@ -0,0 +1,30 @@ +#ifndef ERT_RD_RST_FILE_H +#define ERT_RD_RST_FILE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_rst_file_struct rd_rst_file_type; + +rd_rst_file_type *rd_rst_file_open_read(const char *filename); +rd_rst_file_type *rd_rst_file_open_write(const char *filename); +rd_rst_file_type *rd_rst_file_open_append(const char *filename); +rd_rst_file_type *rd_rst_file_open_write_seek(const char *filename, + int report_step); +void rd_rst_file_close(rd_rst_file_type *rst_file); + +void rd_rst_file_start_solution(rd_rst_file_type *rst_file); +void rd_rst_file_end_solution(rd_rst_file_type *rst_file); +void rd_rst_file_fwrite_header(rd_rst_file_type *rst_file, int seqnum, + rd_rsthead_type *rsthead_data); +void rd_rst_file_add_kw(rd_rst_file_type *rst_file, const rd_kw_type *rd_kw); +offset_type rd_rst_file_ftell(const rd_rst_file_type *rst_file); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/resdata/rd_rsthead.h b/lib/include/resdata/rd_rsthead.h new file mode 100644 index 0000000000..679198fbc8 --- /dev/null +++ b/lib/include/resdata/rd_rsthead.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/ert/ecl/ecl_rsthead.hpp b/lib/include/resdata/rd_rsthead.hpp similarity index 57% rename from lib/include/ert/ecl/ecl_rsthead.hpp rename to lib/include/resdata/rd_rsthead.hpp index 090f616c15..e553981216 100644 --- a/lib/include/ert/ecl/ecl_rsthead.hpp +++ b/lib/include/resdata/rd_rsthead.hpp @@ -1,5 +1,5 @@ -#ifndef ERT_ECL_RSTHEAD_H -#define ERT_ECL_RSTHEAD_H +#ifndef ERT_RD_RSTHEAD_H +#define ERT_RD_RSTHEAD_H #ifdef __cplusplus extern "C" { @@ -7,9 +7,9 @@ extern "C" { #include -#include -#include -#include +#include +#include +#include typedef struct { // The report step is from the SEQNUM keyword for unified files, @@ -22,7 +22,7 @@ typedef struct { int version; // 100, 300, 500 (Eclipse300-Thermal) int phase_sum; // Oil = 1 Gas = 2 Water = 4 - ert_ecl_unit_enum unit_system; + ert_rd_unit_enum unit_system; int nx; int ny; @@ -59,26 +59,26 @@ typedef struct { // Properties from the DOUBHEAD keyword: double sim_days; -} ecl_rsthead_type; +} rd_rsthead_type; -void ecl_rsthead_free(ecl_rsthead_type *rsthead); -ecl_rsthead_type *ecl_rsthead_alloc_from_kw(int report_step, - const ecl_kw_type *intehead_kw, - const ecl_kw_type *doubhead_kw, - const ecl_kw_type *logihead_kw); -ecl_rsthead_type *ecl_rsthead_alloc(const ecl_file_view_type *rst_file, - int report_step); -ecl_rsthead_type *ecl_rsthead_alloc_empty(void); -time_t ecl_rsthead_date(const ecl_kw_type *intehead_kw); -void ecl_rsthead_fprintf(const ecl_rsthead_type *header, FILE *stream); -void ecl_rsthead_fprintf_struct(const ecl_rsthead_type *header, FILE *stream); -bool ecl_rsthead_equal(const ecl_rsthead_type *header1, - const ecl_rsthead_type *header2); -double ecl_rsthead_get_sim_days(const ecl_rsthead_type *header); -int ecl_rsthead_get_report_step(const ecl_rsthead_type *header); -time_t ecl_rsthead_get_sim_time(const ecl_rsthead_type *header); -int ecl_rsthead_get_nxconz(const ecl_rsthead_type *rsthead); -int ecl_rsthead_get_ncwmax(const ecl_rsthead_type *rsthead); +void rd_rsthead_free(rd_rsthead_type *rsthead); +rd_rsthead_type *rd_rsthead_alloc_from_kw(int report_step, + const rd_kw_type *intehead_kw, + const rd_kw_type *doubhead_kw, + const rd_kw_type *logihead_kw); +rd_rsthead_type *rd_rsthead_alloc(const rd_file_view_type *rst_file, + int report_step); +rd_rsthead_type *rd_rsthead_alloc_empty(void); +time_t rd_rsthead_date(const rd_kw_type *intehead_kw); +void rd_rsthead_fprintf(const rd_rsthead_type *header, FILE *stream); +void rd_rsthead_fprintf_struct(const rd_rsthead_type *header, FILE *stream); +bool rd_rsthead_equal(const rd_rsthead_type *header1, + const rd_rsthead_type *header2); +double rd_rsthead_get_sim_days(const rd_rsthead_type *header); +int rd_rsthead_get_report_step(const rd_rsthead_type *header); +time_t rd_rsthead_get_sim_time(const rd_rsthead_type *header); +int rd_rsthead_get_nxconz(const rd_rsthead_type *rsthead); +int rd_rsthead_get_ncwmax(const rd_rsthead_type *rsthead); #ifdef __cplusplus } diff --git a/lib/include/resdata/rd_smspec.h b/lib/include/resdata/rd_smspec.h new file mode 100644 index 0000000000..1de6582ebd --- /dev/null +++ b/lib/include/resdata/rd_smspec.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_smspec.hpp b/lib/include/resdata/rd_smspec.hpp new file mode 100644 index 0000000000..44836f80ec --- /dev/null +++ b/lib/include/resdata/rd_smspec.hpp @@ -0,0 +1,222 @@ +#ifndef ERT_RD_SMSPEC +#define ERT_RD_SMSPEC + +#include +#include + +#include +#include + +#include +#include + +typedef struct rd_smspec_struct rd_smspec_type; + +#ifdef __cplusplus +#include +const std::vector & +rd_smspec_get_params_default(const rd_smspec_type *rd_smspec); +const rd::smspec_node &rd_smspec_get_well_var_node(const rd_smspec_type *smspec, + const char *well, + const char *var); +const rd::smspec_node & +rd_smspec_get_group_var_node(const rd_smspec_type *smspec, const char *group, + const char *var); +const rd::smspec_node & +rd_smspec_get_field_var_node(const rd_smspec_type *smspec, const char *var); +const rd::smspec_node & +rd_smspec_get_region_var_node(const rd_smspec_type *rd_smspec, + const char *region_var, int region_nr); +const rd::smspec_node & +rd_smspec_get_misc_var_node(const rd_smspec_type *rd_smspec, const char *var); +const rd::smspec_node & +rd_smspec_get_block_var_node(const rd_smspec_type *rd_smspec, + const char *block_var, int block_nr); +const rd::smspec_node & +rd_smspec_get_block_var_node_ijk(const rd_smspec_type *rd_smspec, + const char *block_var, int i, int j, int k); +const rd::smspec_node & +rd_smspec_get_well_completion_var_node(const rd_smspec_type *rd_smspec, + const char *well, const char *var, + int cell_nr); +const rd::smspec_node & +rd_smspec_get_general_var_node(const rd_smspec_type *smspec, + const char *lookup_kw); +const rd::smspec_node & +rd_smspec_iget_node_w_node_index(const rd_smspec_type *smspec, int node_index); +const rd::smspec_node & +rd_smspec_iget_node_w_params_index(const rd_smspec_type *smspec, + int params_index); +const rd::smspec_node &rd_smspec_iget_node(const rd_smspec_type *smspec, + int index); +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + These are the different variable types, see table 3.4 in the + ECLIPSE file format docuemntation for naming conventions. + + Only the variable types marked with "X" below are supported in the + remaining implementation. To add support for a new variable type + the functions smspec_node_alloc(), rd_smsepec_fread_header() and + rd_smspec_install_gen_key() must be updated. +*/ + +int *rd_smspec_alloc_mapping(const rd_smspec_type *self, + const rd_smspec_type *other); +const int *rd_smspec_get_index_map(const rd_smspec_type *smspec); +rd_smspec_var_type rd_smspec_iget_var_type(const rd_smspec_type *smspec, + int index); +bool rd_smspec_needs_num(rd_smspec_var_type var_type); +bool rd_smspec_needs_wgname(rd_smspec_var_type var_type); +const char *rd_smspec_get_var_type_name(rd_smspec_var_type var_type); +rd_smspec_var_type rd_smspec_identify_var_type(const char *var); +rd_smspec_type *rd_smspec_alloc_empty(bool write_mode, + const char *key_join_string); + +rd_smspec_type *rd_smspec_alloc_restart_writer( + const char *key_join_string, const char *restart_case, int restart_step, + time_t sim_start, bool time_in_days, int nx, int ny, int nz); + +rd_smspec_type *rd_smspec_alloc_writer(const char *key_join_string, + time_t sim_start, bool time_in_days, + int nx, int ny, int nz); +void rd_smspec_fwrite(const rd_smspec_type *smspec, const char *rd_case, + bool fmt_file); + +rd_smspec_type *rd_smspec_fread_alloc(const char *header_file, + const char *key_join_string, + bool include_restart); +void rd_smspec_free(rd_smspec_type *); + +int rd_smspec_get_date_day_index(const rd_smspec_type *smspec); +int rd_smspec_get_date_month_index(const rd_smspec_type *smspec); +int rd_smspec_get_date_year_index(const rd_smspec_type *smspec); + +int rd_smspec_get_well_var_params_index(const rd_smspec_type *rd_smspec, + const char *well, const char *var); +bool rd_smspec_has_well_var(const rd_smspec_type *rd_smspec, const char *well, + const char *var); + +int rd_smspec_get_group_var_params_index(const rd_smspec_type *rd_smspec, + const char *group, const char *var); +bool rd_smspec_has_group_var(const rd_smspec_type *rd_smspec, const char *group, + const char *var); + +int rd_smspec_get_field_var_params_index(const rd_smspec_type *rd_smspec, + const char *var); +bool rd_smspec_has_field_var(const rd_smspec_type *rd_smspec, const char *var); + +int rd_smspec_get_region_var_params_index(const rd_smspec_type *rd_smspec, + const char *region_var, + int region_nr); +bool rd_smspec_has_region_var(const rd_smspec_type *rd_smspec, + const char *region_var, int region_nr); + +int rd_smspec_get_misc_var_params_index(const rd_smspec_type *rd_smspec, + const char *var); +bool rd_smspec_has_misc_var(const rd_smspec_type *rd_smspec, const char *var); + +int rd_smspec_get_block_var_params_index(const rd_smspec_type *rd_smspec, + const char *block_var, int block_nr); +bool rd_smspec_has_block_var(const rd_smspec_type *rd_smspec, + const char *block_var, int block_nr); + +int rd_smspec_get_block_var_params_index_ijk(const rd_smspec_type *rd_smspec, + const char *block_var, int i, + int j, int k); +bool rd_smspec_has_block_var_ijk(const rd_smspec_type *rd_smspec, + const char *block_var, int i, int j, int k); + +int rd_smspec_get_well_completion_var_params_index( + const rd_smspec_type *rd_smspec, const char *well, const char *var, + int cell_nr); +bool rd_smspec_has_well_completion_var(const rd_smspec_type *rd_smspec, + const char *well, const char *var, + int cell_nr); + +int rd_smspec_get_general_var_params_index(const rd_smspec_type *rd_smspec, + const char *lookup_kw); +bool rd_smspec_has_general_var(const rd_smspec_type *rd_smspec, + const char *lookup_kw); +const char *rd_smspec_get_general_var_unit(const rd_smspec_type *rd_smspec, + const char *lookup_kw); + +void rd_smspec_select_matching_general_var_list(const rd_smspec_type *smspec, + const char *pattern, + stringlist_type *keys); +stringlist_type * +rd_smspec_alloc_matching_general_var_list(const rd_smspec_type *smspec, + const char *pattern); + +int rd_smspec_get_time_seconds(const rd_smspec_type *rd_smspec); +int rd_smspec_get_time_index(const rd_smspec_type *rd_smspec); +time_t rd_smspec_get_start_time(const rd_smspec_type *); +bool rd_smspec_get_formatted(const rd_smspec_type *rd_smspec); +const char *rd_smspec_get_header_file(const rd_smspec_type *rd_smspec); +stringlist_type *rd_smspec_alloc_well_list(const rd_smspec_type *smspec, + const char *pattern); +stringlist_type *rd_smspec_alloc_group_list(const rd_smspec_type *smspec, + const char *pattern); +stringlist_type *rd_smspec_alloc_well_var_list(const rd_smspec_type *smspec); +const char *rd_smspec_get_simulation_path(const rd_smspec_type *rd_smspec); +int rd_smspec_get_first_step(const rd_smspec_type *rd_smspec); +int rd_smspec_get_restart_step(const rd_smspec_type *rd_smspec); +const char *rd_smspec_get_restart_case(const rd_smspec_type *rd_smspec); +const char *rd_smspec_get_join_string(const rd_smspec_type *smspec); + +const int *rd_smspec_get_grid_dims(const rd_smspec_type *smspec); +int rd_smspec_get_params_size(const rd_smspec_type *smspec); +int rd_smspec_num_nodes(const rd_smspec_type *smspec); + +char *rd_smspec_alloc_well_key(const rd_smspec_type *smspec, + const char *keyword, const char *wgname); +bool rd_smspec_equal(const rd_smspec_type *self, const rd_smspec_type *other); + +// void rd_smspec_sort( rd_smspec_type * smspec ); +ert_rd_unit_enum rd_smspec_get_unit_system(const rd_smspec_type *smspec); + +#ifdef __cplusplus +} +#endif + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const rd::smspec_node &node); +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, int num, + const char *unit, + float default_value); +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, const char *unit, + float default_value); +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, + const char *wgname, const char *unit, + float default_value); +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, + const char *wgname, int num, + const char *unit, + float default_value); +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, int num, + const char *unit, + float default_value); + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + int params_index, const char *keyword, + const char *wgname, int num, + const char *unit, + float default_value); + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + int params_index, const char *keyword, + const char *wgname, int num, + const char *unit, const char *lgr, + int lgr_i, int lgr_j, int lgr_k, + float default_value); + +#endif diff --git a/lib/include/resdata/rd_subsidence.h b/lib/include/resdata/rd_subsidence.h new file mode 100644 index 0000000000..af04dd8dfa --- /dev/null +++ b/lib/include/resdata/rd_subsidence.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_subsidence.hpp b/lib/include/resdata/rd_subsidence.hpp new file mode 100644 index 0000000000..04e06e3b61 --- /dev/null +++ b/lib/include/resdata/rd_subsidence.hpp @@ -0,0 +1,48 @@ +#ifndef ERT_RD_SUBSIDENCE_H +#define ERT_RD_SUBSIDENCE_H +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +typedef struct rd_subsidence_struct rd_subsidence_type; +typedef struct rd_subsidence_survey_struct rd_subsidence_survey_type; + +void rd_subsidence_free(rd_subsidence_type *rd_subsidence_config); +rd_subsidence_type *rd_subsidence_alloc(const rd_grid_type *rd_grid, + const rd_file_type *init_file); +rd_subsidence_survey_type * +rd_subsidence_add_survey_PRESSURE(rd_subsidence_type *subsidence, + const char *name, + const rd_file_view_type *restart_view); + +bool rd_subsidence_has_survey(const rd_subsidence_type *subsidence, + const char *name); +double rd_subsidence_eval(const rd_subsidence_type *subsidence, + const char *base, const char *monitor, + rd_region_type *region, double utm_x, double utm_y, + double depth, double compressibility, + double poisson_ratio); + +double rd_subsidence_eval_geertsma(const rd_subsidence_type *subsidence, + const char *base, const char *monitor, + rd_region_type *region, double utm_x, + double utm_y, double depth, + double youngs_modulus, double poisson_ratio, + double seabed); + +double rd_subsidence_eval_geertsma_rporv(const rd_subsidence_type *subsidence, + const char *base, const char *monitor, + rd_region_type *region, double utm_x, + double utm_y, double depth, + double youngs_modulus, + double poisson_ratio, double seabed); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/ert/ecl/ecl_sum.h b/lib/include/resdata/rd_sum.h similarity index 58% rename from lib/include/ert/ecl/ecl_sum.h rename to lib/include/resdata/rd_sum.h index cf032119b1..07a5553332 100644 --- a/lib/include/ert/ecl/ecl_sum.h +++ b/lib/include/resdata/rd_sum.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/resdata/rd_sum.hpp b/lib/include/resdata/rd_sum.hpp new file mode 100644 index 0000000000..eb01070fe6 --- /dev/null +++ b/lib/include/resdata/rd_sum.hpp @@ -0,0 +1,313 @@ +#ifndef ERT_RD_SUM_H +#define ERT_RD_SUM_H + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char *locale; + const char *sep; + const char *newline; + const char *value_fmt; + const char *date_fmt; + const char *days_fmt; + const char *header_fmt; + bool print_header; + bool print_dash; + const char *date_header; + const char *date_dash; + const char *value_dash; +} rd_sum_fmt_type; + +typedef struct rd_sum_vector_struct rd_sum_vector_type; + +typedef struct rd_sum_struct rd_sum_type; + +void rd_sum_fmt_init_summary_x(const rd_sum_type *rd_sum, rd_sum_fmt_type *fmt); +double rd_sum_get_from_sim_time(const rd_sum_type *rd_sum, time_t sim_time, + const rd::smspec_node *node); +double rd_sum_get_from_sim_days(const rd_sum_type *rd_sum, double sim_days, + const rd::smspec_node *node); +double rd_sum_time2days(const rd_sum_type *rd_sum, time_t sim_time); + +void rd_sum_set_unified(rd_sum_type *rd_sum, bool unified); +void rd_sum_set_fmt_case(rd_sum_type *rd_sum, bool fmt_case); + +int rd_sum_get_report_step_from_time(const rd_sum_type *sum, time_t sim_time); +int rd_sum_get_report_step_from_days(const rd_sum_type *sum, double sim_days); +bool rd_sum_check_sim_time(const rd_sum_type *sum, time_t sim_time); +bool rd_sum_check_sim_days(const rd_sum_type *sum, double sim_days); +const char *rd_sum_get_keyword(const rd_sum_type *sum, const char *gen_key); +const char *rd_sum_get_wgname(const rd_sum_type *sum, const char *gen_key); +const char *rd_sum_get_unit(const rd_sum_type *sum, const char *gen_key); +int rd_sum_get_num(const rd_sum_type *sum, const char *gen_key); + +double rd_sum_iget(const rd_sum_type *rd_sum, int time_index, int param_index); +int rd_sum_iget_num(const rd_sum_type *sum, int param_index); +const char *rd_sum_iget_wgname(const rd_sum_type *sum, int param_index); +const char *rd_sum_iget_keyword(const rd_sum_type *sum, int param_index); +int rd_sum_get_data_length(const rd_sum_type *rd_sum); +double rd_sum_iget_from_sim_time(const rd_sum_type *rd_sum, time_t sim_time, + int param_index); +double rd_sum_iget_from_sim_days(const rd_sum_type *rd_sum, double sim_days, + int param_index); + +void rd_sum_summarize(const rd_sum_type *rd_sum, FILE *stream); +bool rd_sum_general_is_total(const rd_sum_type *rd_sum, const char *gen_key); +void rd_sum_free_data(rd_sum_type *); +void rd_sum_free__(void *); +void rd_sum_free(rd_sum_type *); +rd_sum_type *rd_sum_fread_alloc(const char *, const stringlist_type *data_files, + const char *key_join_string, + bool include_restart, bool lazy_load, + int file_options); +rd_sum_type *rd_sum_fread_alloc_case(const char *, const char *key_join_string); +rd_sum_type *rd_sum_fread_alloc_case__(const char *input_file, + const char *key_join_string, + bool include_restart); +rd_sum_type *rd_sum_fread_alloc_case2__(const char *, + const char *key_join_string, + bool include_restart, bool lazy_load, + int file_options); +rd_sum_type *rd_sum_alloc_resample(const rd_sum_type *rd_sum, + const char *rd_case, + const time_t_vector_type *times, + bool lower_extrapolation, + bool upper_extrapolation); +bool rd_sum_case_exists(const char *input_file); + +/* Accessor functions : */ +double rd_sum_get_well_var(const rd_sum_type *rd_sum, int time_index, + const char *well, const char *var); +bool rd_sum_has_well_var(const rd_sum_type *rd_sum, const char *well, + const char *var); +double rd_sum_get_well_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *well, + const char *var); +double rd_sum_get_well_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *well, + const char *var); + +double rd_sum_get_group_var(const rd_sum_type *rd_sum, int time_index, + const char *group, const char *var); +bool rd_sum_has_group_var(const rd_sum_type *rd_sum, const char *group, + const char *var); + +double rd_sum_get_field_var(const rd_sum_type *rd_sum, int time_index, + const char *var); +bool rd_sum_has_field_var(const rd_sum_type *rd_sum, const char *var); +double rd_sum_get_field_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *var); +double rd_sum_get_field_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *var); + +double rd_sum_get_block_var(const rd_sum_type *rd_sum, int time_index, + const char *block_var, int block_nr); +int rd_sum_get_block_var_index(const rd_sum_type *rd_sum, const char *block_var, + int block_nr); +bool rd_sum_has_block_var(const rd_sum_type *rd_sum, const char *block_var, + int block_nr); +double rd_sum_get_block_var_ijk(const rd_sum_type *rd_sum, int time_index, + const char *block_var, int i, int j, int k); +int rd_sum_get_block_var_index_ijk(const rd_sum_type *rd_sum, + const char *block_var, int i, int j, int k); +bool rd_sum_has_block_var_ijk(const rd_sum_type *rd_sum, const char *block_var, + int i, int j, int k); + +double rd_sum_get_region_var(const rd_sum_type *rd_sum, int time_index, + const char *var, int region_nr); +bool rd_sum_has_region_var(const rd_sum_type *rd_sum, const char *var, + int region_nr); + +double rd_sum_get_misc_var(const rd_sum_type *rd_sum, int time_index, + const char *var); +int rd_sum_get_misc_var_index(const rd_sum_type *rd_sum, const char *var); +bool rd_sum_has_misc_var(const rd_sum_type *rd_sum, const char *var); + +double rd_sum_get_well_completion_var(const rd_sum_type *rd_sum, int time_index, + const char *well, const char *var, + int cell_nr); +int rd_sum_get_well_completion_var_index(const rd_sum_type *rd_sum, + const char *well, const char *var, + int cell_nr); +bool rd_sum_has_well_completion_var(const rd_sum_type *rd_sum, const char *well, + const char *var, int cell_nr); + +double rd_sum_get_general_var(const rd_sum_type *rd_sum, int time_index, + const char *lookup_kw); +int rd_sum_get_general_var_params_index(const rd_sum_type *rd_sum, + const char *lookup_kw); +const rd::smspec_node *rd_sum_get_general_var_node(const rd_sum_type *rd_sum, + const char *lookup_kw); +bool rd_sum_has_general_var(const rd_sum_type *rd_sum, const char *lookup_kw); +bool rd_sum_has_key(const rd_sum_type *rd_sum, const char *lookup_kw); +double rd_sum_get_general_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *var); +double rd_sum_get_general_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *var); +const char *rd_sum_get_general_var_unit(const rd_sum_type *rd_sum, + const char *var); +ert_rd_unit_enum rd_sum_get_unit_system(const rd_sum_type *rd_sum); + +void rd_sum_fprintf(const rd_sum_type *, FILE *, const stringlist_type *, + bool report_only, const rd_sum_fmt_type *fmt); + +/* Time related functions */ +int rd_sum_get_restart_step(const rd_sum_type *rd_sum); +int rd_sum_get_first_gt(const rd_sum_type *rd_sum, int param_index, + double limit); +int rd_sum_get_first_lt(const rd_sum_type *rd_sum, int param_index, + double limit); +int rd_sum_get_last_report_step(const rd_sum_type *rd_sum); +int rd_sum_get_first_report_step(const rd_sum_type *rd_sum); +bool rd_sum_has_report_step(const rd_sum_type *rd_sum, int report_step); +time_t rd_sum_get_report_time(const rd_sum_type *rd_sum, int report_step); +time_t rd_sum_iget_sim_time(const rd_sum_type *rd_sum, int index); +double rd_sum_iget_sim_days(const rd_sum_type *rd_sum, int time_index); +int rd_sum_iget_report_step(const rd_sum_type *rd_sum, int internal_index); +double rd_sum_iget_general_var(const rd_sum_type *rd_sum, int internal_index, + const char *lookup_kw); + +double_vector_type *rd_sum_alloc_data_vector(const rd_sum_type *rd_sum, + int data_index, bool report_only); +time_t_vector_type *rd_sum_alloc_time_vector(const rd_sum_type *rd_sum, + bool report_only); +time_t rd_sum_get_data_start(const rd_sum_type *rd_sum); +time_t rd_sum_get_end_time(const rd_sum_type *rd_sum); +time_t rd_sum_get_start_time(const rd_sum_type *); + +const char *rd_sum_get_base(const rd_sum_type *rd_sum); +const char *rd_sum_get_path(const rd_sum_type *rd_sum); +const char *rd_sum_get_abs_path(const rd_sum_type *rd_sum); +const rd_sum_type *rd_sum_get_restart_case(const rd_sum_type *rd_sum); +const char *rd_sum_get_case(const rd_sum_type *); +bool rd_sum_same_case(const rd_sum_type *rd_sum, const char *input_file); + +void rd_sum_resample_from_sim_days(const rd_sum_type *rd_sum, + const double_vector_type *sim_days, + double_vector_type *value, + const char *gen_key); +void rd_sum_resample_from_sim_time(const rd_sum_type *rd_sum, + const time_t_vector_type *sim_time, + double_vector_type *value, + const char *gen_key); +time_t rd_sum_time_from_days(const rd_sum_type *rd_sum, double sim_days); +double rd_sum_days_from_time(const rd_sum_type *rd_sum, time_t sim_time); +double rd_sum_get_sim_length(const rd_sum_type *rd_sum); +double rd_sum_get_first_day(const rd_sum_type *rd_sum); + +stringlist_type *rd_sum_alloc_well_list(const rd_sum_type *rd_sum, + const char *pattern); +stringlist_type *rd_sum_alloc_group_list(const rd_sum_type *rd_sum, + const char *pattern); +stringlist_type *rd_sum_alloc_well_var_list(const rd_sum_type *rd_sum); +stringlist_type * +rd_sum_alloc_matching_general_var_list(const rd_sum_type *rd_sum, + const char *pattern); +void rd_sum_select_matching_general_var_list(const rd_sum_type *rd_sum, + const char *pattern, + stringlist_type *keys); +rd_smspec_type *rd_sum_get_smspec(const rd_sum_type *rd_sum); +rd_smspec_var_type rd_sum_identify_var_type(const char *var); +rd_smspec_var_type rd_sum_get_var_type(const rd_sum_type *rd_sum, + const char *gen_key); +bool rd_sum_var_is_rate(const rd_sum_type *rd_sum, const char *gen_key); +bool rd_sum_var_is_total(const rd_sum_type *rd_sum, const char *gen_key); + +int rd_sum_iget_report_end(const rd_sum_type *rd_sum, int report_step); +rd_sum_type * +rd_sum_alloc_restart_writer2(const char *rd_case, const char *restart_case, + int restart_step, bool fmt_output, bool unified, + const char *key_join_string, time_t sim_start, + bool time_in_days, int nx, int ny, int nz); +void rd_sum_set_case(rd_sum_type *rd_sum, const char *input_arg); + +rd_sum_type *rd_sum_alloc_restart_writer(const char *rd_case, + const char *restart_case, + bool fmt_output, bool unified, + const char *key_join_string, + time_t sim_start, bool time_in_days, + int nx, int ny, int nz); +rd_sum_type *rd_sum_alloc_writer(const char *rd_case, bool fmt_output, + bool unified, const char *key_join_string, + time_t sim_start, bool time_in_days, int nx, + int ny, int nz); +void rd_sum_fwrite(const rd_sum_type *rd_sum); +bool rd_sum_can_write(const rd_sum_type *rd_sum); +void rd_sum_fwrite_smspec(const rd_sum_type *rd_sum); +const rd::smspec_node *rd_sum_add_smspec_node(rd_sum_type *rd_sum, + const rd::smspec_node *node); +const rd::smspec_node *rd_sum_add_var(rd_sum_type *rd_sum, const char *keyword, + const char *wgname, int num, + const char *unit, float default_value); +rd_sum_tstep_type *rd_sum_add_tstep(rd_sum_type *rd_sum, int report_step, + double sim_seconds); + +bool rd_sum_is_oil_producer(const rd_sum_type *rd_sum, const char *well); +char *rd_sum_alloc_well_key(const rd_sum_type *rd_sum, const char *keyword, + const char *wgname); +bool rd_sum_report_step_equal(const rd_sum_type *rd_sum1, + const rd_sum_type *rd_sum2); +bool rd_sum_report_step_compatible(const rd_sum_type *rd_sum1, + const rd_sum_type *rd_sum2); +void rd_sum_export_csv(const rd_sum_type *rd_sum, const char *filename, + const stringlist_type *var_list, const char *date_format, + const char *sep); + +double_vector_type *rd_sum_alloc_seconds_solution(const rd_sum_type *rd_sum, + const char *gen_key, + double cmp_value, + bool rates_clamp_lower); +double_vector_type *rd_sum_alloc_days_solution(const rd_sum_type *rd_sum, + const char *gen_key, + double cmp_value, + bool rates_clamp_lower); +time_t_vector_type *rd_sum_alloc_time_solution(const rd_sum_type *rd_sum, + const char *gen_key, + double cmp_value, + bool rates_clamp_lower); + +double rd_sum_iget_last_value(const rd_sum_type *rd_sum, int param_index); +double rd_sum_get_last_value_gen_key(const rd_sum_type *rd_sum, + const char *gen_key); +double rd_sum_get_last_value_node(const rd_sum_type *rd_sum, + const rd::smspec_node *node); +double rd_sum_iget_first_value(const rd_sum_type *rd_sum, int param_index); +double rd_sum_get_first_value_gen_key(const rd_sum_type *rd_sum, + const char *gen_key); +double rd_sum_get_first_value_node(const rd_sum_type *rd_sum, + const rd::smspec_node *node); + +void rd_sum_init_datetime64_vector(const rd_sum_type *rd_sum, int64_t *data, + int multiplier); +void rd_sum_init_double_vector_interp(const rd_sum_type *rd_sum, + const char *gen_key, + const time_t_vector_type *time_points, + double *data); +void rd_sum_init_double_vector(const rd_sum_type *rd_sum, const char *gen_key, + double *data); +void rd_sum_init_double_frame(const rd_sum_type *rd_sum, + const rd_sum_vector_type *keywords, double *data); +void rd_sum_init_double_frame_interp(const rd_sum_type *rd_sum, + const rd_sum_vector_type *keywords, + const time_t_vector_type *time_points, + double *data); +UTIL_IS_INSTANCE_HEADER(rd_sum); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_sum_data.h b/lib/include/resdata/rd_sum_data.h new file mode 100644 index 0000000000..ea633a1fdf --- /dev/null +++ b/lib/include/resdata/rd_sum_data.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_sum_data.hpp b/lib/include/resdata/rd_sum_data.hpp new file mode 100644 index 0000000000..ca70132f6c --- /dev/null +++ b/lib/include/resdata/rd_sum_data.hpp @@ -0,0 +1,129 @@ +#ifndef ERT_RD_SUM_DATA_H +#define ERT_RD_SUM_DATA_H + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_sum_data_struct rd_sum_data_type; + +void rd_sum_data_reset_self_map(rd_sum_data_type *data); +void rd_sum_data_add_case(rd_sum_data_type *self, + const rd_sum_data_type *other); +void rd_sum_data_fwrite_step(const rd_sum_data_type *data, const char *rd_case, + bool fmt_case, bool unified, int report_step); +void rd_sum_data_fwrite(const rd_sum_data_type *data, const char *rd_case, + bool fmt_case, bool unified); +bool rd_sum_data_can_write(const rd_sum_data_type *data); +bool rd_sum_data_fread(rd_sum_data_type *data, const stringlist_type *filelist, + bool lazy_load, int file_options); +rd_sum_data_type *rd_sum_data_alloc_writer(rd_smspec_type *smspec); +rd_sum_data_type *rd_sum_data_alloc(rd_smspec_type *smspec); +double rd_sum_data_time2days(const rd_sum_data_type *data, time_t sim_time); +int rd_sum_data_get_report_step_from_time(const rd_sum_data_type *data, + time_t sim_time); +int rd_sum_data_get_report_step_from_days(const rd_sum_data_type *data, + double days); +bool rd_sum_data_check_sim_time(const rd_sum_data_type *data, time_t sim_time); +bool rd_sum_data_check_sim_days(const rd_sum_data_type *data, double sim_days); +int rd_sum_data_get_num_ministep(const rd_sum_data_type *data); +double_vector_type *rd_sum_data_alloc_data_vector(const rd_sum_data_type *data, + int data_index, + bool report_only); +void rd_sum_data_init_time_vector(const rd_sum_data_type *data, + time_t_vector_type *time_vector, + bool report_only); +time_t_vector_type *rd_sum_data_alloc_time_vector(const rd_sum_data_type *data, + bool report_only); +time_t rd_sum_data_get_data_start(const rd_sum_data_type *data); +time_t rd_sum_data_get_report_time(const rd_sum_data_type *data, + int report_step); +double rd_sum_data_get_first_day(const rd_sum_data_type *data); +time_t rd_sum_data_get_sim_start(const rd_sum_data_type *data); +time_t rd_sum_data_get_sim_end(const rd_sum_data_type *data); +double rd_sum_data_get_sim_length(const rd_sum_data_type *data); +void rd_sum_data_summarize(const rd_sum_data_type *data, FILE *stream); +double rd_sum_data_iget(const rd_sum_data_type *data, int internal_index, + int params_index); + +double rd_sum_data_iget_sim_days(const rd_sum_data_type *, int); +time_t rd_sum_data_iget_sim_time(const rd_sum_data_type *, int); +void rd_sum_data_get_interp_vector(const rd_sum_data_type *data, + time_t sim_time, + const rd_sum_vector_type *keylist, + double_vector_type *results); + +bool rd_sum_data_has_report_step(const rd_sum_data_type *, int); + +rd_sum_data_type *rd_sum_data_fread_alloc(rd_smspec_type *, + const stringlist_type *filelist, + bool include_restart, bool lazy_load); +void rd_sum_data_free(rd_sum_data_type *); +int rd_sum_data_get_last_report_step(const rd_sum_data_type *data); +int rd_sum_data_get_first_report_step(const rd_sum_data_type *data); + +double rd_sum_data_get_from_sim_time(const rd_sum_data_type *data, + time_t sim_time, + const rd::smspec_node &smspec_node); +double rd_sum_data_get_from_sim_days(const rd_sum_data_type *data, + double sim_days, + const rd::smspec_node &smspec_node); + +int rd_sum_data_get_length(const rd_sum_data_type *data); +int rd_sum_data_iget_report_step(const rd_sum_data_type *data, + int internal_index); +int rd_sum_data_iget_report_end(const rd_sum_data_type *data, int report_step); +rd_sum_tstep_type *rd_sum_data_add_new_tstep(rd_sum_data_type *data, + int report_step, + double sim_seconds); +bool rd_sum_data_report_step_equal(const rd_sum_data_type *data1, + const rd_sum_data_type *data2); +bool rd_sum_data_report_step_compatible(const rd_sum_data_type *data1, + const rd_sum_data_type *data2); +void rd_sum_data_fwrite_interp_csv_line(const rd_sum_data_type *data, + time_t sim_time, + const rd_sum_vector_type *keylist, + FILE *fp); +double rd_sum_data_get_last_value(const rd_sum_data_type *data, + int param_index); +double rd_sum_data_iget_last_value(const rd_sum_data_type *data, + int param_index); +double rd_sum_data_iget_first_value(const rd_sum_data_type *data, + int param_index); +void rd_sum_data_init_double_vector(const rd_sum_data_type *data, + int params_index, double *output_data); +void rd_sum_data_init_datetime64_vector(const rd_sum_data_type *data, + int64_t *output_data, int multiplier); + +void rd_sum_data_init_double_frame(const rd_sum_data_type *data, + const rd_sum_vector_type *keywords, + double *output_data); +double_vector_type * +rd_sum_data_alloc_seconds_solution(const rd_sum_data_type *data, + const rd::smspec_node &node, double value, + bool rates_clamp_lower); +void rd_sum_data_init_double_frame_interp(const rd_sum_data_type *data, + const rd_sum_vector_type *keywords, + const time_t_vector_type *time_points, + double *output_data); + +void rd_sum_data_init_double_vector_interp( + const rd_sum_data_type *data, const rd::smspec_node &smspec_node, + const time_t_vector_type *time_points, double *output_data); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_sum_index.h b/lib/include/resdata/rd_sum_index.h new file mode 100644 index 0000000000..9709a63ed3 --- /dev/null +++ b/lib/include/resdata/rd_sum_index.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_sum_index.hpp b/lib/include/resdata/rd_sum_index.hpp new file mode 100644 index 0000000000..042b19ca68 --- /dev/null +++ b/lib/include/resdata/rd_sum_index.hpp @@ -0,0 +1,13 @@ +#ifndef ERT_RD_SUM_INDEX_H +#define ERT_RD_SUM_INDEX_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_sum_index_struct rd_sum_index_type; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_sum_tstep.h b/lib/include/resdata/rd_sum_tstep.h new file mode 100644 index 0000000000..27faf358f0 --- /dev/null +++ b/lib/include/resdata/rd_sum_tstep.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_sum_tstep.hpp b/lib/include/resdata/rd_sum_tstep.hpp new file mode 100644 index 0000000000..daab8585f4 --- /dev/null +++ b/lib/include/resdata/rd_sum_tstep.hpp @@ -0,0 +1,73 @@ +#ifndef ERT_RD_SUM_TSTEP_H +#define ERT_RD_SUM_TSTEP_H + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_sum_tstep_struct rd_sum_tstep_type; + +rd_sum_tstep_type * +rd_sum_tstep_alloc_remap_copy(const rd_sum_tstep_type *src, + const rd_smspec_type *new_smspec, + float default_value, const int *params_map); +rd_sum_tstep_type *rd_sum_tstep_alloc_copy(const rd_sum_tstep_type *src); +void rd_sum_tstep_free(rd_sum_tstep_type *ministep); +void rd_sum_tstep_free__(void *__ministep); +rd_sum_tstep_type *rd_sum_tstep_alloc_from_file(int report_step, + int ministep_nr, + const rd_kw_type *params_kw, + const char *src_file, + const rd_smspec_type *smspec); + +rd_sum_tstep_type *rd_sum_tstep_alloc_new(int report_step, int ministep, + float sim_seconds, + const rd_smspec_type *smspec); + +void rd_sum_tstep_set_from_node(rd_sum_tstep_type *tstep, + const rd::smspec_node &smspec_node, + float value); +double rd_sum_tstep_get_from_node(const rd_sum_tstep_type *tstep, + const rd::smspec_node &smspec_node); + +double rd_sum_tstep_iget(const rd_sum_tstep_type *ministep, int index); +time_t rd_sum_tstep_get_sim_time(const rd_sum_tstep_type *ministep); +double rd_sum_tstep_get_sim_days(const rd_sum_tstep_type *ministep); +double rd_sum_tstep_get_sim_seconds(const rd_sum_tstep_type *ministep); + +int rd_sum_tstep_get_report(const rd_sum_tstep_type *ministep); +int rd_sum_tstep_get_ministep(const rd_sum_tstep_type *ministep); + +void rd_sum_tstep_fwrite(const rd_sum_tstep_type *ministep, + const int *index_map, int index_map_size, + fortio_type *fortio); +void rd_sum_tstep_iset(rd_sum_tstep_type *tstep, int index, float value); + +/// scales with value; equivalent to iset( iget() * scalar) +void rd_sum_tstep_iscale(rd_sum_tstep_type *tstep, int index, float scalar); + +/// adds addend to tstep[index]; equivalent to iset( iget() + addend) +void rd_sum_tstep_ishift(rd_sum_tstep_type *tstep, int index, float addend); + +void rd_sum_tstep_set_from_key(rd_sum_tstep_type *tstep, const char *gen_key, + float value); +double rd_sum_tstep_get_from_key(const rd_sum_tstep_type *tstep, + const char *gen_key); +bool rd_sum_tstep_has_key(const rd_sum_tstep_type *tstep, const char *gen_key); + +bool rd_sum_tstep_sim_time_equal(const rd_sum_tstep_type *tstep1, + const rd_sum_tstep_type *tstep2); + +UTIL_SAFE_CAST_HEADER(rd_sum_tstep); +UTIL_SAFE_CAST_HEADER_CONST(rd_sum_tstep); + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/lib/include/resdata/rd_sum_vector.h b/lib/include/resdata/rd_sum_vector.h new file mode 100644 index 0000000000..4528fb8f9e --- /dev/null +++ b/lib/include/resdata/rd_sum_vector.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_sum_vector.hpp b/lib/include/resdata/rd_sum_vector.hpp new file mode 100644 index 0000000000..f85504a3bd --- /dev/null +++ b/lib/include/resdata/rd_sum_vector.hpp @@ -0,0 +1,40 @@ +#ifndef ERT_RD_SUM_VECTOR_H +#define ERT_RD_SUM_VECTOR_H + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_sum_vector_struct rd_sum_vector_type; + +void rd_sum_vector_free(rd_sum_vector_type *keylist); +rd_sum_vector_type *rd_sum_vector_alloc(const rd_sum_type *rd_sum, + bool add_keywords); + +bool rd_sum_vector_add_key(rd_sum_vector_type *keylist, const char *key); +void rd_sum_vector_add_keys(rd_sum_vector_type *keylist, const char *pattern); + +const char *rd_sum_vector_iget_key(const rd_sum_vector_type *rd_sum_vector, + int index); +bool rd_sum_vector_iget_is_rate(const rd_sum_vector_type *rd_sum_vector, + int index); +int rd_sum_vector_iget_param_index(const rd_sum_vector_type *rd_sum_vector, + int index); +int rd_sum_vector_get_size(const rd_sum_vector_type *rd_sum_vector); +bool rd_sum_vector_iget_valid(const rd_sum_vector_type *rd_sum_vector, + int index); + +rd_sum_vector_type * +rd_sum_vector_alloc_layout_copy(const rd_sum_vector_type *src_vector, + const rd_sum_type *rd_sum); + +UTIL_IS_INSTANCE_HEADER(rd_sum_vector); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_type.h b/lib/include/resdata/rd_type.h new file mode 100644 index 0000000000..4c6295d565 --- /dev/null +++ b/lib/include/resdata/rd_type.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_type.hpp b/lib/include/resdata/rd_type.hpp new file mode 100644 index 0000000000..9a7988a511 --- /dev/null +++ b/lib/include/resdata/rd_type.hpp @@ -0,0 +1,134 @@ +#ifndef ERT_RD_TYPE_H +#define ERT_RD_TYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* + The type of an eclipse keyword is carried by a struct + rd_type_struct which contains a type enum, and the size in bytes of + one such element. These structs are for the most part handled with + value semantics, and created with macros RD_INT, RD_FLOAT and so + on. + + The macros in C use designated initializers, whereas the C++ macros + use a constructor, for this reason this file has two slightly + different code paths for C and C++. +*/ + +#define RD_STRING8_LENGTH 8 +#define RD_TYPE_LENGTH 4 + +typedef enum { + RD_CHAR_TYPE = 0, + RD_FLOAT_TYPE = 1, + RD_DOUBLE_TYPE = 2, + RD_INT_TYPE = 3, + RD_BOOL_TYPE = 4, + RD_MESS_TYPE = 5, + RD_STRING_TYPE = 7 +} rd_type_enum; + +#define RD_TYPE_ENUM_DEFS \ + {.value = 0, .name = "RD_CHAR_TYPE"}, \ + {.value = 1, .name = "RD_FLOAT_TYPE"}, \ + {.value = 2, .name = "RD_DOUBLE_TYPE"}, \ + {.value = 3, .name = "RD_INT_TYPE"}, \ + {.value = 4, .name = "RD_BOOL_TYPE"}, \ + {.value = 5, .name = "RD_MESS_TYPE"}, { \ + .value = 7, .name = "RD_STRING_TYPE" \ + } + +/* + Character data in restart format files comes as an array of fixed-length + string. Each of these strings is 8 characters long. The type name, + i.e. 'REAL', 'INTE', ... , come as 4 character strings. +*/ + +#define RD_STRING8_LENGTH 8 // 'Normal' 8 characters 'CHAR' type. +#define RD_TYPE_LENGTH 4 + +struct rd_type_struct { + const rd_type_enum type; + const size_t element_size; +}; + +#ifdef __cplusplus + +#define RD_INT \ + rd_data_type { RD_INT_TYPE, sizeof(int) } +#define RD_FLOAT \ + rd_data_type { RD_FLOAT_TYPE, sizeof(float) } +#define RD_DOUBLE \ + rd_data_type { RD_DOUBLE_TYPE, sizeof(double) } +#define RD_BOOL \ + rd_data_type { RD_BOOL_TYPE, sizeof(bool) } +#define RD_CHAR \ + rd_data_type { RD_CHAR_TYPE, RD_STRING8_LENGTH + 1 } +#define RD_MESS \ + rd_data_type { RD_MESS_TYPE, 0 } +#define RD_STRING(size) \ + rd_data_type { RD_STRING_TYPE, (size) + 1 } +} + +#else + +#define RD_CHAR \ + (rd_data_type) { \ + .type = RD_CHAR_TYPE, .element_size = RD_STRING8_LENGTH + 1 \ + } +#define RD_INT \ + (rd_data_type) { .type = RD_INT_TYPE, .element_size = sizeof(int) } +#define RD_FLOAT \ + (rd_data_type) { .type = RD_FLOAT_TYPE, .element_size = sizeof(float) } +#define RD_DOUBLE \ + (rd_data_type) { .type = RD_DOUBLE_TYPE, .element_size = sizeof(double) } +#define RD_BOOL \ + (rd_data_type) { .type = RD_BOOL_TYPE, .element_size = sizeof(bool) } +#define RD_MESS \ + (rd_data_type) { .type = RD_MESS_TYPE, .element_size = 0 } +#define RD_STRING(size) \ + (rd_data_type) { .type = RD_STRING_TYPE, .element_size = (size) + 1 } + +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rd_type_struct rd_data_type; + +rd_data_type rd_type_create_from_name(const char *); +rd_data_type rd_type_create(const rd_type_enum, const size_t); +rd_data_type rd_type_create_from_type(const rd_type_enum); + +rd_type_enum rd_type_get_type(const rd_data_type); +char *rd_type_alloc_name(const rd_data_type); + +int rd_type_get_sizeof_ctype(const rd_data_type); +int rd_type_get_sizeof_iotype(const rd_data_type); + +bool rd_type_is_equal(const rd_data_type, const rd_data_type); + +bool rd_type_is_numeric(const rd_data_type); +bool rd_type_is_alpha(const rd_data_type); +bool rd_type_is_char(const rd_data_type); +bool rd_type_is_int(const rd_data_type); +bool rd_type_is_float(const rd_data_type); +bool rd_type_is_double(const rd_data_type); +bool rd_type_is_mess(const rd_data_type); +bool rd_type_is_bool(const rd_data_type); +bool rd_type_is_string(const rd_data_type); + +// Temporary fixup for OPM. +char *rd_type_get_name(const rd_data_type); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/include/resdata/rd_units.h b/lib/include/resdata/rd_units.h new file mode 100644 index 0000000000..2a9bfea362 --- /dev/null +++ b/lib/include/resdata/rd_units.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_units.hpp b/lib/include/resdata/rd_units.hpp new file mode 100644 index 0000000000..536bbcb052 --- /dev/null +++ b/lib/include/resdata/rd_units.hpp @@ -0,0 +1,28 @@ +#ifndef RD_UNITS_H +#define RD_UNITS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define RD_UNITS_CUBIC(x) ((x) * (x) * (x)) +#define RD_UNITS_MILLI(x) ((x)*0.001) +#define RD_UNITS_MEGA(x) ((x)*1000000) + +#define RD_UNITS_LENGTH_INCH 0.0254 +#define RD_UNITS_LENGTH_FEET 12 * RD_UNITS_LENGTH_INCH + +#define RD_UNITS_VOLUME_GALLON 231 * RD_UNITS_CUBIC(RD_UNITS_LENGTH_INCH) +#define RD_UNITS_VOLUME_BARREL RD_UNITS_VOLUME_GALLON * 42 +#define RD_UNITS_VOLUME_LITER 0.001 +#define RD_UNITS_VOLUME_MILLI_LITER RD_UNITS_MILLI(RD_UNITS_VOLUME_LITER) +#define RD_UNITS_VOLUME_GAS_FIELD \ + RD_UNITS_MEGA(RD_UNITS_CUBIC(RD_UNITS_LENGTH_FEET)) + +#define RD_UNITS_TIME_HOUR 3600 +#define RD_UNITS_TIME_DAY 24 * RD_UNITS_TIME_HOUR + +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/resdata/rd_util.h b/lib/include/resdata/rd_util.h new file mode 100644 index 0000000000..1ef3f5ba28 --- /dev/null +++ b/lib/include/resdata/rd_util.h @@ -0,0 +1,7 @@ +/* + Warning: The resdata code has changed to be compiled as a C++ project. This + header file is retained for a period for compatibility, but you are encouraged + to switch to include the new hpp header directly in your code. +*/ + +#include diff --git a/lib/include/resdata/rd_util.hpp b/lib/include/resdata/rd_util.hpp new file mode 100644 index 0000000000..354f41ea1d --- /dev/null +++ b/lib/include/resdata/rd_util.hpp @@ -0,0 +1,154 @@ +#ifndef ERT_RD_UTIL_H +#define ERT_RD_UTIL_H +#ifdef __cplusplus +extern "C" { +#endif +#include +#include + +#include +#include +#include +#include + +typedef enum { + RD_OTHER_FILE = 0, + RD_RESTART_FILE = 1, + RD_UNIFIED_RESTART_FILE = 2, + RD_SUMMARY_FILE = 4, + RD_UNIFIED_SUMMARY_FILE = 8, + RD_SUMMARY_HEADER_FILE = 16, + RD_GRID_FILE = 32, + RD_EGRID_FILE = 64, + RD_INIT_FILE = 128, + RD_RFT_FILE = 256, + RD_DATA_FILE = 512 +} rd_file_enum; + +/* + This enum enumerates the four different ways summary and restart information + can be stored. + */ + +typedef enum { + RD_INVALID_STORAGE = 0, + RD_BINARY_UNIFIED = 1, + RD_FORMATTED_UNIFIED = 2, + RD_BINARY_NON_UNIFIED = 4, + RD_FORMATTED_NON_UNIFIED = 8 +} rd_storage_enum; + +/* + The resdata library has been built and tested 99.5% with ECLIPSE100 + as context, but in thye gravity code there is some very limited + functionality related to ECLIPSE100 versus ECLIPSE300 functionality. + + Observe that numerical values found as part of the INTEHAD keyword + differ from these values, and are found in the rd_kw_magic.h + header. +*/ + +typedef enum { + ECLIPSE_UNDEFINED = 0, + ECLIPSE100 = 1, + ECLIPSE300 = 2, + ECLIPSE300_THERMAL = 3, + INTERSECT = 4, + FRONTSIM = 5 +} rd_version_enum; + +/* + Observe that the numerical enum VALUES matches those found in item + 14 in the INTEHEAD keyword in the INIT files; i.e. the + distribution of numerical values 1,2,4 can NOT BE CHANGED. + + The function rd_get_phase_name() can be used to lookup a + string name from an enum value. + + The phases in a simulation will typically be a sum of these + fundamental phases, and represented as an integer. +*/ + +typedef enum { + RD_OIL_PHASE = 1, + RD_GAS_PHASE = 2, + RD_WATER_PHASE = 4 +} rd_phase_enum; + +#define RD_PHASE_ENUM_DEFS \ + {.value = 1, .name = "RD_OIL_PHASE"}, \ + {.value = 2, .name = "RD_GAS_PHASE"}, { \ + .value = 4, .name = "RD_WATER_PHASE" \ + } +#define RD_PHASE_ENUM_SIZE 3 + +typedef enum { + RD_METRIC_UNITS = 1, + RD_FIELD_UNITS = 2, + RD_LAB_UNITS = 3, + RD_PVT_M_UNITS = 4 +} ert_rd_unit_enum; + +// For unformatted files: +#define RD_BOOL_TRUE_INT \ + -1 // Binary representation: 11111111 11111111 11111111 1111111 +#define RD_BOOL_FALSE_INT \ + 0 // Binary representation: 00000000 00000000 00000000 0000000 +#define RD_COMMENT_STRING "--" +#define RD_COMMENT_CHAR '-' // Need to consecutive to make an ECLIPSE comment +#define RD_DATA_TERMINATION "/" + +bool rd_unified_file(const char *filename); +const char *rd_file_type_name(rd_file_enum file_type); +char *rd_alloc_base_guess(const char *); +int rd_filename_report_nr(const char *); +rd_file_enum rd_inspect_extension(const char *ext, bool *_fmt_file, + int *_report_nr); +rd_file_enum rd_get_file_type(const char *filename, bool *fmt_file, + int *report_nr); +char *rd_alloc_filename(const char * /* path */, const char * /* base */, + rd_file_enum, bool /* fmt_file */, int /*report_nr*/); +char *rd_alloc_exfilename(const char * /* path */, const char * /* base */, + rd_file_enum, bool /* fmt_file */, int /*report_nr*/); +void rd_memcpy_typed_data(void *, const void *, rd_data_type, rd_data_type, + int); +void rd_escape_kw(char *kw); +bool rd_alloc_summary_files(const char *, const char *, const char *, char **, + stringlist_type *); +void rd_alloc_summary_data_files(const char *path, const char *base, + bool fmt_file, stringlist_type *filelist); +void rd_alloc_restart_files(const char *, const char *, char ***, int *, bool *, + bool *); +time_t rd_get_start_date(const char *); +int rd_get_num_cpu(const char *data_file); +bool rd_fmt_file(const char *filename, bool *__fmt_file); +char *rd_alloc_exfilename_anyfmt(const char *path, const char *base, + rd_file_enum file_type, bool start_fmt, + int report_nr); +int rd_get_month_nr(const char *month_name); +int rd_fname_report_cmp(const void *f1, const void *f2); +time_t rd_make_date(int mday, int month, int year); +time_t rd_make_date__(int mday, int month, int year, int *year_offset); +time_t rd_make_datetime(int sec, int min, int hour, int mday, int month, + int year); +ert_rd_unit_enum rd_get_unit_set(const char *data_file); + +bool rd_valid_basename_fmt(const char *basename_fmt); +bool rd_valid_basename(const char *basename); +const char *rd_get_phase_name(rd_phase_enum phase); + +int rd_select_filelist(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file, + stringlist_type *filelist); +void rd_append_month_range(time_t_vector_type *date_list, time_t start_date, + time_t end_date, bool force_append_end); +void rd_init_month_range(time_t_vector_type *date_list, time_t start_date, + time_t end_date); +void rd_set_date_values(time_t t, int *mday, int *month, int *year); +void rd_set_datetime_values(time_t t, int *sec, int *min, int *hour, int *mday, + int *month, int *year); +bool rd_path_access(const char *rd_case); +#ifdef __cplusplus +} +#endif +#endif diff --git a/lib/include/ert/ecl/smspec_node.h b/lib/include/resdata/smspec_node.h similarity index 83% rename from lib/include/ert/ecl/smspec_node.h rename to lib/include/resdata/smspec_node.h index a3bf445c2b..9c16accfee 100644 --- a/lib/include/ert/ecl/smspec_node.h +++ b/lib/include/resdata/smspec_node.h @@ -1,5 +1,5 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ @@ -25,22 +25,22 @@ extern "C" { #define SMSPEC_YEARS_NUMS_VALUE -32676 typedef enum { - ECL_SMSPEC_INVALID_VAR = 0, - ECL_SMSPEC_FIELD_VAR = 1, /* X */ - ECL_SMSPEC_REGION_VAR = 2, /* X */ - ECL_SMSPEC_GROUP_VAR = 3, /* X */ - ECL_SMSPEC_WELL_VAR = 4, /* X */ - ECL_SMSPEC_SEGMENT_VAR = 5, /* X */ - ECL_SMSPEC_BLOCK_VAR = 6, /* X */ - ECL_SMSPEC_AQUIFER_VAR = 7, - ECL_SMSPEC_COMPLETION_VAR = 8, /* X */ - ECL_SMSPEC_NETWORK_VAR = 9, - ECL_SMSPEC_REGION_2_REGION_VAR = 10, - ECL_SMSPEC_LOCAL_BLOCK_VAR = 11, /* X */ - ECL_SMSPEC_LOCAL_COMPLETION_VAR = 12, /* X */ - ECL_SMSPEC_LOCAL_WELL_VAR = 13, /* X */ - ECL_SMSPEC_MISC_VAR = 14 /* X */ -} ecl_smspec_var_type; + RD_SMSPEC_INVALID_VAR = 0, + RD_SMSPEC_FIELD_VAR = 1, /* X */ + RD_SMSPEC_REGION_VAR = 2, /* X */ + RD_SMSPEC_GROUP_VAR = 3, /* X */ + RD_SMSPEC_WELL_VAR = 4, /* X */ + RD_SMSPEC_SEGMENT_VAR = 5, /* X */ + RD_SMSPEC_BLOCK_VAR = 6, /* X */ + RD_SMSPEC_AQUIFER_VAR = 7, + RD_SMSPEC_COMPLETION_VAR = 8, /* X */ + RD_SMSPEC_NETWORK_VAR = 9, + RD_SMSPEC_REGION_2_REGION_VAR = 10, + RD_SMSPEC_LOCAL_BLOCK_VAR = 11, /* X */ + RD_SMSPEC_LOCAL_COMPLETION_VAR = 12, /* X */ + RD_SMSPEC_LOCAL_WELL_VAR = 13, /* X */ + RD_SMSPEC_MISC_VAR = 14 /* X */ +} rd_smspec_var_type; #define SMSPEC_NUMS_INVALID -991199 #define SMSPEC_NUMS_WELL 1 @@ -83,12 +83,12 @@ char *smspec_alloc_local_completion_key(const char *join_string, int k); bool smspec_node_identify_total(const char *keyword, - ecl_smspec_var_type var_type); + rd_smspec_var_type var_type); bool smspec_node_identify_rate(const char *keyword); bool smspec_node_equal(const void *node1, const void *node2); -void smspec_node_init(void *smspec_node, ecl_smspec_var_type var_type, +void smspec_node_init(void *smspec_node, rd_smspec_var_type var_type, const char *wgname, const char *keyword, const char *unit, const char *key_join_string, const int grid_dims[3], int num); @@ -98,7 +98,7 @@ void *smspec_node_alloc(int param_index, const char *keyword, const int grid_dims[3], float default_value, const char *key_join_string); -void *smspec_node_alloc_lgr(ecl_smspec_var_type var_type, const char *wgname, +void *smspec_node_alloc_lgr(rd_smspec_var_type var_type, const char *wgname, const char *keyword, const char *unit, const char *lgr, const char *key_join_string, int lgr_i, int lgr_j, int lgr_k, int param_index, @@ -112,7 +112,7 @@ void smspec_node_set_params_index(void *smspec_node, int params_index); int smspec_node_get_params_index(const void *smspec_node); const char *smspec_node_get_gen_key1(const void *smspec_node); const char *smspec_node_get_gen_key2(const void *smspec_node); -ecl_smspec_var_type smspec_node_get_var_type(const void *smspec_node); +rd_smspec_var_type smspec_node_get_var_type(const void *smspec_node); int smspec_node_get_num(const void *smspec_node); const char *smspec_node_get_wgname(const void *smspec_node); const char *smspec_node_get_keyword(const void *smspec_node); diff --git a/lib/include/ert/ecl/smspec_node.hpp b/lib/include/resdata/smspec_node.hpp similarity index 90% rename from lib/include/ert/ecl/smspec_node.hpp rename to lib/include/resdata/smspec_node.hpp index 66804758b5..ac6c30dbd8 100644 --- a/lib/include/ert/ecl/smspec_node.hpp +++ b/lib/include/resdata/smspec_node.hpp @@ -9,9 +9,9 @@ #include -#include +#include -namespace ecl { +namespace rd { class smspec_node { private: @@ -30,7 +30,7 @@ class smspec_node { gen_key1; /* The main composite key, i.e. WWCT:OP3 for this element. */ std::string gen_key2; /* Some of the ijk based elements will have both a xxx:i,j,k and a xxx:num key. Some of the region_2_region elements will have both a xxx:num and a xxx:r2-r2 key. Mostly NULL. */ - ecl_smspec_var_type var_type; /* The variable type */ + rd_smspec_var_type var_type; /* The variable type */ std::array ijk; /* The ijk coordinates (NB: OFFSET 1) corresponding to the nums value - will be NULL if not relevant. */ bool @@ -40,7 +40,7 @@ class smspec_node { int params_index; /* The index of this variable (applies to all the vectors - in particular the PARAMS vectors of the summary files *.Snnnn / *.UNSMRY ). */ float default_value; /* Default value for this variable. */ - static ecl_smspec_var_type identify_special_var(const char *var); + static rd_smspec_var_type identify_special_var(const char *var); void set_wgname(const char *wgname); void set_num(const int grid_dims[3], int num_); void set_gen_keys(const char *key_join_string_); @@ -48,8 +48,8 @@ class smspec_node { void set_lgr_ijk(int lgr_i, int lgr_j, int lgr_k); public: - static ecl_smspec_var_type valid_type(const char *keyword, - const char *wgname, int num); + static rd_smspec_var_type valid_type(const char *keyword, + const char *wgname, int num); int cmp(const smspec_node &node2) const; static int cmp(const smspec_node &node1, const smspec_node &node2); @@ -76,7 +76,7 @@ class smspec_node { const char *key_join_string); smspec_node(const smspec_node &node, int param_index); - static ecl_smspec_var_type identify_var_type(const char *var); + static rd_smspec_var_type identify_var_type(const char *var); static int cmp(const smspec_node *node1, const smspec_node *node2) { return node1->cmp(*node2); @@ -86,7 +86,7 @@ class smspec_node { int get_R2() const; const char *get_gen_key1() const; const char *get_gen_key2() const; - ecl_smspec_var_type get_var_type() const; + rd_smspec_var_type get_var_type() const; int get_num() const; const char *get_wgname() const; const char *get_keyword() const; @@ -103,6 +103,6 @@ class smspec_node { const std::array &get_lgr_ijk() const; }; -} // namespace ecl +} // namespace rd #endif diff --git a/lib/include/ert/ecl_well/well_branch_collection.h b/lib/include/resdata/well/well_branch_collection.h similarity index 54% rename from lib/include/ert/ecl_well/well_branch_collection.h rename to lib/include/resdata/well/well_branch_collection.h index 4b913b0a9f..9e7d20b6dd 100644 --- a/lib/include/ert/ecl_well/well_branch_collection.h +++ b/lib/include/resdata/well/well_branch_collection.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_branch_collection.hpp b/lib/include/resdata/well/well_branch_collection.hpp similarity index 96% rename from lib/include/ert/ecl_well/well_branch_collection.hpp rename to lib/include/resdata/well/well_branch_collection.hpp index 76e50ac35d..a4258da588 100644 --- a/lib/include/ert/ecl_well/well_branch_collection.hpp +++ b/lib/include/resdata/well/well_branch_collection.hpp @@ -9,7 +9,7 @@ extern "C" { #include -#include +#include typedef struct well_branch_collection_struct well_branch_collection_type; diff --git a/lib/include/ert/ecl_well/well_conn.h b/lib/include/resdata/well/well_conn.h similarity index 56% rename from lib/include/ert/ecl_well/well_conn.h rename to lib/include/resdata/well/well_conn.h index 02a53b61c4..d76f4cb124 100644 --- a/lib/include/ert/ecl_well/well_conn.h +++ b/lib/include/resdata/well/well_conn.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_conn.hpp b/lib/include/resdata/well/well_conn.hpp similarity index 85% rename from lib/include/ert/ecl_well/well_conn.hpp rename to lib/include/resdata/well/well_conn.hpp index 3a7a5ba71d..1c57ce19f2 100644 --- a/lib/include/ert/ecl_well/well_conn.hpp +++ b/lib/include/resdata/well/well_conn.hpp @@ -5,7 +5,7 @@ #include -#include +#include #ifdef __cplusplus extern "C" { @@ -40,13 +40,13 @@ well_conn_type *well_conn_alloc_fracture_MSW(int i, int j, int k, bool well_conn_MSW(const well_conn_type *conn); -well_conn_type *well_conn_alloc_from_kw(const ecl_kw_type *icon_kw, - const ecl_kw_type *scon_kw, - const ecl_kw_type *xcon_kw, - const ecl_rsthead_type *header, +well_conn_type *well_conn_alloc_from_kw(const rd_kw_type *icon_kw, + const rd_kw_type *scon_kw, + const rd_kw_type *xcon_kw, + const rd_rsthead_type *header, int well_nr, int conn_nr); -well_conn_type *well_conn_alloc_wellhead(const ecl_kw_type *iwel_kw, - const ecl_rsthead_type *header, +well_conn_type *well_conn_alloc_wellhead(const rd_kw_type *iwel_kw, + const rd_rsthead_type *header, int well_nr); int well_conn_get_i(const well_conn_type *conn); diff --git a/lib/include/ert/ecl_well/well_conn_collection.h b/lib/include/resdata/well/well_conn_collection.h similarity index 54% rename from lib/include/ert/ecl_well/well_conn_collection.h rename to lib/include/resdata/well/well_conn_collection.h index e74ae47c1f..ec38f7ca6c 100644 --- a/lib/include/ert/ecl_well/well_conn_collection.h +++ b/lib/include/resdata/well/well_conn_collection.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_conn_collection.hpp b/lib/include/resdata/well/well_conn_collection.hpp similarity index 72% rename from lib/include/ert/ecl_well/well_conn_collection.hpp rename to lib/include/resdata/well/well_conn_collection.hpp index ad74ad0a6f..2cf2dfee30 100644 --- a/lib/include/ert/ecl_well/well_conn_collection.hpp +++ b/lib/include/resdata/well/well_conn_collection.hpp @@ -7,9 +7,9 @@ extern "C" { #include -#include +#include -#include +#include typedef struct well_conn_collection_struct well_conn_collection_type; @@ -27,11 +27,11 @@ void well_conn_collection_add(well_conn_collection_type *wellcc, void well_conn_collection_add_ref(well_conn_collection_type *wellcc, well_conn_type *conn); int well_conn_collection_load_from_kw(well_conn_collection_type *wellcc, - const ecl_kw_type *iwel_kw, - const ecl_kw_type *icon_kw, - const ecl_kw_type *scon_kw, - const ecl_kw_type *xcon_kw, int iwell, - const ecl_rsthead_type *rst_head); + const rd_kw_type *iwel_kw, + const rd_kw_type *icon_kw, + const rd_kw_type *scon_kw, + const rd_kw_type *xcon_kw, int iwell, + const rd_rsthead_type *rst_head); UTIL_IS_INSTANCE_HEADER(well_conn_collection); diff --git a/lib/include/ert/ecl_well/well_const.h b/lib/include/resdata/well/well_const.h similarity index 56% rename from lib/include/ert/ecl_well/well_const.h rename to lib/include/resdata/well/well_const.h index 8644d73116..6f83d36a67 100644 --- a/lib/include/ert/ecl_well/well_const.h +++ b/lib/include/resdata/well/well_const.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_const.hpp b/lib/include/resdata/well/well_const.hpp similarity index 96% rename from lib/include/ert/ecl_well/well_const.hpp rename to lib/include/resdata/well/well_const.hpp index b07f43bbe0..26d9de2e4a 100644 --- a/lib/include/ert/ecl_well/well_const.hpp +++ b/lib/include/resdata/well/well_const.hpp @@ -119,19 +119,19 @@ extern "C" { typedef enum { ERT_UNDOCUMENTED_ZERO = 0, // Deprecated - retained for Resinsight compatibility - ECL_WELL_ZERO = 0, + RD_WELL_ZERO = 0, ERT_PRODUCER = 1, // Deprecated - ECL_WELL_PRODUCER = 1, + RD_WELL_PRODUCER = 1, ERT_OIL_INJECTOR = 2, // Deprecated - ECL_WELL_OIL_INJECTOR = 2, + RD_WELL_OIL_INJECTOR = 2, ERT_WATER_INJECTOR = 3, // Deprecated - ECL_WELL_WATER_INJECTOR = 3, + RD_WELL_WATER_INJECTOR = 3, ERT_GAS_INJECTOR = 4, // Deprecated - ECL_WELL_GAS_INJECTOR = 4, + RD_WELL_GAS_INJECTOR = 4, } well_type_enum; #ifdef __cplusplus diff --git a/lib/include/ert/ecl_well/well_info.h b/lib/include/resdata/well/well_info.h similarity index 56% rename from lib/include/ert/ecl_well/well_info.h rename to lib/include/resdata/well/well_info.h index 0e86ca9d4f..4bc5fef4d5 100644 --- a/lib/include/ert/ecl_well/well_info.h +++ b/lib/include/resdata/well/well_info.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_info.hpp b/lib/include/resdata/well/well_info.hpp similarity index 77% rename from lib/include/ert/ecl_well/well_info.hpp rename to lib/include/resdata/well/well_info.hpp index 3ec26d1a49..11d1768e1b 100644 --- a/lib/include/ert/ecl_well/well_info.hpp +++ b/lib/include/resdata/well/well_info.hpp @@ -1,10 +1,10 @@ #ifndef ERT_WELL_INFO_H #define ERT_WELL_INFO_H -#include -#include +#include +#include -#include +#include #ifdef __cplusplus extern "C" { @@ -12,22 +12,22 @@ extern "C" { typedef struct well_info_struct well_info_type; -well_info_type *well_info_alloc(const ecl_grid_type *grid); +well_info_type *well_info_alloc(const rd_grid_type *grid); void well_info_add_UNRST_wells2(well_info_type *well_info, - ecl_file_view_type *rst_view, + rd_file_view_type *rst_view, bool load_segment_information); void well_info_add_UNRST_wells(well_info_type *well_info, - ecl_file_type *rst_file, + rd_file_type *rst_file, bool load_segment_information); -void well_info_add_wells(well_info_type *well_info, ecl_file_type *rst_file, +void well_info_add_wells(well_info_type *well_info, rd_file_type *rst_file, int report_nr, bool load_segment_information); void well_info_add_wells2(well_info_type *well_info, - ecl_file_view_type *rst_view, int report_nr, + rd_file_view_type *rst_view, int report_nr, bool load_segment_information); void well_info_load_rstfile(well_info_type *well_info, const char *filename, bool load_segment_information); -void well_info_load_rst_eclfile(well_info_type *well_info, - ecl_file_type *rst_file, +void well_info_load_rst_resfile(well_info_type *well_info, + rd_file_type *rst_file, bool load_segment_information); void well_info_free(well_info_type *well_info); diff --git a/lib/include/ert/ecl_well/well_rseg_loader.h b/lib/include/resdata/well/well_rseg_loader.h similarity index 55% rename from lib/include/ert/ecl_well/well_rseg_loader.h rename to lib/include/resdata/well/well_rseg_loader.h index 0f4404706c..b0a4d247ce 100644 --- a/lib/include/ert/ecl_well/well_rseg_loader.h +++ b/lib/include/resdata/well/well_rseg_loader.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_rseg_loader.hpp b/lib/include/resdata/well/well_rseg_loader.hpp similarity index 81% rename from lib/include/ert/ecl_well/well_rseg_loader.hpp rename to lib/include/resdata/well/well_rseg_loader.hpp index 3fd1f330b2..9a8be56acd 100644 --- a/lib/include/ert/ecl_well/well_rseg_loader.hpp +++ b/lib/include/resdata/well/well_rseg_loader.hpp @@ -5,11 +5,11 @@ extern "C" { #endif -#include +#include typedef struct well_rseg_loader_struct well_rseg_loader_type; -well_rseg_loader_type *well_rseg_loader_alloc(ecl_file_view_type *rst_view); +well_rseg_loader_type *well_rseg_loader_alloc(rd_file_view_type *rst_view); void well_rseg_loader_free(well_rseg_loader_type *well_rseg_loader); int well_rseg_loader_element_count( diff --git a/lib/include/ert/ecl_well/well_segment.h b/lib/include/resdata/well/well_segment.h similarity index 56% rename from lib/include/ert/ecl_well/well_segment.h rename to lib/include/resdata/well/well_segment.h index cd7e90531a..76011c3885 100644 --- a/lib/include/ert/ecl_well/well_segment.h +++ b/lib/include/resdata/well/well_segment.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_segment.hpp b/lib/include/resdata/well/well_segment.hpp similarity index 83% rename from lib/include/ert/ecl_well/well_segment.hpp rename to lib/include/resdata/well/well_segment.hpp index 2ca4152daf..c6ae44cce2 100644 --- a/lib/include/ert/ecl_well/well_segment.hpp +++ b/lib/include/resdata/well/well_segment.hpp @@ -7,19 +7,19 @@ extern "C" { #include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include typedef struct well_segment_struct well_segment_type; well_segment_type * -well_segment_alloc_from_kw(const ecl_kw_type *iseg_kw, +well_segment_alloc_from_kw(const rd_kw_type *iseg_kw, const well_rseg_loader_type *rseg_loader, - const ecl_rsthead_type *header, int well_nr, + const rd_rsthead_type *header, int well_nr, int segment_index, int segment_id); well_segment_type *well_segment_alloc(int segment_id, int outlet_segment_id, int branch_id, const double *rseg_data); @@ -49,8 +49,8 @@ well_segment_get_connections(const well_segment_type *segment, const char *grid_name); const well_conn_collection_type * well_segment_get_global_connections(const well_segment_type *segment); -bool well_segment_well_is_MSW(int well_nr, const ecl_kw_type *iwel_kw, - const ecl_rsthead_type *rst_head); +bool well_segment_well_is_MSW(int well_nr, const rd_kw_type *iwel_kw, + const rd_rsthead_type *rst_head); double well_segment_get_depth(const well_segment_type *segment); double well_segment_get_length(const well_segment_type *segment); diff --git a/lib/include/ert/ecl_well/well_segment_collection.h b/lib/include/resdata/well/well_segment_collection.h similarity index 54% rename from lib/include/ert/ecl_well/well_segment_collection.h rename to lib/include/resdata/well/well_segment_collection.h index 8ad0ad690d..290c8b638c 100644 --- a/lib/include/ert/ecl_well/well_segment_collection.h +++ b/lib/include/resdata/well/well_segment_collection.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_segment_collection.hpp b/lib/include/resdata/well/well_segment_collection.hpp similarity index 81% rename from lib/include/ert/ecl_well/well_segment_collection.hpp rename to lib/include/resdata/well/well_segment_collection.hpp index de259da347..435847e681 100644 --- a/lib/include/ert/ecl_well/well_segment_collection.hpp +++ b/lib/include/resdata/well/well_segment_collection.hpp @@ -7,12 +7,12 @@ extern "C" { #include -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include typedef struct well_segment_collection_struct well_segment_collection_type; @@ -32,8 +32,8 @@ well_segment_type *well_segment_collection_iget( const well_segment_collection_type *segment_collection, int index); int well_segment_collection_load_from_kw( well_segment_collection_type *segment_collection, int well_nr, - const ecl_kw_type *iwel_kw, const ecl_kw_type *iseg_kw, - const well_rseg_loader_type *rseg_loader, const ecl_rsthead_type *rst_head, + const rd_kw_type *iwel_kw, const rd_kw_type *iseg_kw, + const well_rseg_loader_type *rseg_loader, const rd_rsthead_type *rst_head, bool load_segment_information, bool *is_MSW_well); void well_segment_collection_link( diff --git a/lib/include/ert/ecl_well/well_state.h b/lib/include/resdata/well/well_state.h similarity index 56% rename from lib/include/ert/ecl_well/well_state.h rename to lib/include/resdata/well/well_state.h index 3c6bc3a720..d4bb315802 100644 --- a/lib/include/ert/ecl_well/well_state.h +++ b/lib/include/resdata/well/well_state.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_state.hpp b/lib/include/resdata/well/well_state.hpp similarity index 76% rename from lib/include/ert/ecl_well/well_state.hpp rename to lib/include/resdata/well/well_state.hpp index 95f5803cb0..b61b1f1aee 100644 --- a/lib/include/ert/ecl_well/well_state.hpp +++ b/lib/include/resdata/well/well_state.hpp @@ -3,14 +3,14 @@ #include -#include -#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -24,28 +24,28 @@ typedef struct well_state_struct well_state_type; well_state_type *well_state_alloc(const char *well_name, int global_well_nr, bool open, well_type_enum type, int report_nr, time_t valid_from); -well_state_type *well_state_alloc_from_file(ecl_file_type *ecl_file, - const ecl_grid_type *grid, +well_state_type *well_state_alloc_from_file(rd_file_type *rd_file, + const rd_grid_type *grid, int report_step, int well_nr, bool load_segment_information); -well_state_type *well_state_alloc_from_file2(ecl_file_view_type *file_view, - const ecl_grid_type *grid, +well_state_type *well_state_alloc_from_file2(rd_file_view_type *file_view, + const rd_grid_type *grid, int report_nr, int global_well_nr, bool load_segment_information); void well_state_add_connections2(well_state_type *well_state, - const ecl_grid_type *grid, - ecl_file_view_type *rst_view, int well_nr); + const rd_grid_type *grid, + rd_file_view_type *rst_view, int well_nr); void well_state_add_connections(well_state_type *well_state, - const ecl_grid_type *grid, - ecl_file_type *rst_file, int well_nr); + const rd_grid_type *grid, + rd_file_type *rst_file, int well_nr); -bool well_state_add_MSW(well_state_type *well_state, ecl_file_type *rst_file, +bool well_state_add_MSW(well_state_type *well_state, rd_file_type *rst_file, int well_nr, bool load_segment_information); bool well_state_add_MSW2(well_state_type *well_state, - ecl_file_view_type *rst_view, int well_nr, + rd_file_view_type *rst_view, int well_nr, bool load_segment_information); bool well_state_is_MSW(const well_state_type *well_state); @@ -72,7 +72,7 @@ well_state_iget_wellhead(const well_state_type *well_state, int grid_nr); const well_conn_type *well_state_get_wellhead(const well_state_type *well_state, const char *grid_name); -well_type_enum well_state_translate_ecl_type_int(int int_type); +well_type_enum well_state_translate_rd_type_int(int int_type); const well_conn_collection_type * well_state_get_grid_connections(const well_state_type *well_state, diff --git a/lib/include/ert/ecl_well/well_ts.h b/lib/include/resdata/well/well_ts.h similarity index 57% rename from lib/include/ert/ecl_well/well_ts.h rename to lib/include/resdata/well/well_ts.h index 7af5639c7e..bd23fc6617 100644 --- a/lib/include/ert/ecl_well/well_ts.h +++ b/lib/include/resdata/well/well_ts.h @@ -1,7 +1,7 @@ /* - Warning: The libecl code has changed to be compiled as a C++ project. This + Warning: The resdata code has changed to be compiled as a C++ project. This header file is retained for a period for compatibility, but you are encouraged to switch to include the new hpp header directly in your code. */ -#include +#include diff --git a/lib/include/ert/ecl_well/well_ts.hpp b/lib/include/resdata/well/well_ts.hpp similarity index 96% rename from lib/include/ert/ecl_well/well_ts.hpp rename to lib/include/resdata/well/well_ts.hpp index c06ec6e472..52c08a474a 100644 --- a/lib/include/ert/ecl_well/well_ts.hpp +++ b/lib/include/resdata/well/well_ts.hpp @@ -1,7 +1,7 @@ #ifndef ERT_WELL_TS_H #define ERT_WELL_TS_H -#include +#include #ifdef __cplusplus extern "C" { diff --git a/lib/private-include/detail/ecl/layer_cxx.hpp b/lib/private-include/detail/resdata/layer_cxx.hpp similarity index 90% rename from lib/private-include/detail/ecl/layer_cxx.hpp rename to lib/private-include/detail/resdata/layer_cxx.hpp index 69492c208b..22536b8df2 100644 --- a/lib/private-include/detail/ecl/layer_cxx.hpp +++ b/lib/private-include/detail/resdata/layer_cxx.hpp @@ -2,7 +2,7 @@ #define LAYER_CXX_HPP #include -#include +#include bool layer_trace_block_edge(const layer_type *layer, int i, int j, int value, std::vector &corner_list, diff --git a/lib/private-include/detail/ecl/ecl_grid_cache.hpp b/lib/private-include/detail/resdata/rd_grid_cache.hpp similarity index 71% rename from lib/private-include/detail/ecl/ecl_grid_cache.hpp rename to lib/private-include/detail/resdata/rd_grid_cache.hpp index 62ade55b0a..3bc793e312 100644 --- a/lib/private-include/detail/ecl/ecl_grid_cache.hpp +++ b/lib/private-include/detail/resdata/rd_grid_cache.hpp @@ -1,14 +1,14 @@ -#ifndef ERT_ECL_GRID_CACHE_H -#define ERT_ECL_GRID_CACHE_H +#ifndef ERT_RD_GRID_CACHE_H +#define ERT_RD_GRID_CACHE_H #include -#include +#include -namespace ecl { -class ecl_grid_cache { +namespace rd { +class rd_grid_cache { public: - ecl_grid_cache(const ecl_grid_type *grid); + rd_grid_cache(const rd_grid_type *grid); const std::vector &volume() const; const std::vector &xpos() const { return this->xp; } @@ -18,13 +18,13 @@ class ecl_grid_cache { int size() const { return this->xp.size(); } private: - const ecl_grid_type *grid; + const rd_grid_type *grid; std::vector gi; std::vector xp; std::vector yp; std::vector zp; mutable std::vector v; }; -} // namespace ecl +} // namespace rd #endif diff --git a/lib/private-include/detail/ecl/ecl_sum_file_data.hpp b/lib/private-include/detail/resdata/rd_sum_file_data.hpp similarity index 80% rename from lib/private-include/detail/ecl/ecl_sum_file_data.hpp rename to lib/private-include/detail/resdata/rd_sum_file_data.hpp index 5843d64e9f..192fa5a152 100644 --- a/lib/private-include/detail/ecl/ecl_sum_file_data.hpp +++ b/lib/private-include/detail/resdata/rd_sum_file_data.hpp @@ -5,11 +5,11 @@ #include -#include -#include -#include +#include +#include +#include -namespace ecl { +namespace rd { #define INVALID_MINISTEP_NR -1 #define INVALID_TIME_T 0 @@ -81,12 +81,12 @@ class TimeIndex { class unsmry_loader; -class ecl_sum_file_data { +class rd_sum_file_data { public: - ecl_sum_file_data(const ecl_smspec_type *smspec); - ~ecl_sum_file_data(); - const ecl_smspec_type *smspec() const; + rd_sum_file_data(const rd_smspec_type *smspec); + ~rd_sum_file_data(); + const rd_smspec_type *smspec() const; int length_before(time_t end_time) const; void get_time(int length, time_t *data); @@ -98,12 +98,12 @@ class ecl_sum_file_data { time_t iget_sim_time(int time_index) const; double iget_sim_days(int time_index) const; double iget_sim_seconds(int time_index) const; - ecl_sum_tstep_type *iget_ministep(int internal_index) const; + rd_sum_tstep_type *iget_ministep(int internal_index) const; double get_days_start() const; double get_sim_length() const; std::pair report_range(int report_step) const; - bool report_step_equal(const ecl_sum_file_data &other, bool strict) const; + bool report_step_equal(const rd_sum_file_data &other, bool strict) const; int report_before(time_t end_time) const; int get_time_report(int max_internal_index, time_t *data); int get_data_report(int params_index, int max_internal_index, double *data, @@ -115,26 +115,26 @@ class ecl_sum_file_data { int report_step_from_days(double sim_days) const; int report_step_from_time(time_t sim_time) const; - ecl_sum_tstep_type *add_new_tstep(int report_step, double sim_seconds); + rd_sum_tstep_type *add_new_tstep(int report_step, double sim_seconds); bool can_write() const; void fwrite_unified(fortio_type *fortio) const; - void fwrite_multiple(const char *ecl_case, bool fmt_case) const; + void fwrite_multiple(const char *rd_case, bool fmt_case) const; bool fread(const stringlist_type *filelist, bool lazy_load, int file_options); private: - const ecl_smspec_type *ecl_smspec; + const rd_smspec_type *rd_smspec; TimeIndex index; vector_type *data; - std::unique_ptr loader; + std::unique_ptr loader; - void append_tstep(ecl_sum_tstep_type *tstep); + void append_tstep(rd_sum_tstep_type *tstep); void build_index(); void fwrite_report(int report_step, fortio_type *fortio) const; - bool check_file(ecl_file_type *ecl_file); - void add_ecl_file(int report_step, const ecl_file_view_type *summary_view); + bool check_file(rd_file_type *rd_file); + void add_rd_file(int report_step, const rd_file_view_type *summary_view); }; -} // namespace ecl +} // namespace rd diff --git a/lib/private-include/detail/ecl/ecl_unsmry_loader.hpp b/lib/private-include/detail/resdata/rd_unsmry_loader.hpp similarity index 76% rename from lib/private-include/detail/ecl/ecl_unsmry_loader.hpp rename to lib/private-include/detail/resdata/rd_unsmry_loader.hpp index b65f3e9c29..e1d0060762 100644 --- a/lib/private-include/detail/ecl/ecl_unsmry_loader.hpp +++ b/lib/private-include/detail/resdata/rd_unsmry_loader.hpp @@ -3,14 +3,14 @@ #include #include -#include -#include +#include +#include -namespace ecl { +namespace rd { class unsmry_loader { public: - unsmry_loader(const ecl_smspec_type *smspec, const std::string &filename, + unsmry_loader(const rd_smspec_type *smspec, const std::string &filename, int file_options); ~unsmry_loader(); @@ -32,8 +32,8 @@ class unsmry_loader { int m_length; //Number of PARAMS in the UNSMRY file std::array date_index; - ecl_file_type *file; - ecl_file_view_type *file_view; + rd_file_type *file; + rd_file_view_type *file_view; }; -} // namespace ecl +} // namespace rd diff --git a/lib/private-include/detail/util/path.hpp b/lib/private-include/detail/util/path.hpp index a2d03d3cce..09e9b83a1f 100644 --- a/lib/private-include/detail/util/path.hpp +++ b/lib/private-include/detail/util/path.hpp @@ -2,7 +2,7 @@ #define PATH_UTIL #include -namespace ecl { +namespace rd { namespace util { namespace path { /* @@ -25,6 +25,6 @@ std::string basename(const std::string &fname); std::string extension(const std::string &fname); } // namespace path } // namespace util -} // namespace ecl +} // namespace rd #endif diff --git a/lib/private-include/detail/util/string_util.hpp b/lib/private-include/detail/util/string_util.hpp index b20e2c2ac8..d93e678549 100644 --- a/lib/private-include/detail/util/string_util.hpp +++ b/lib/private-include/detail/util/string_util.hpp @@ -1,11 +1,11 @@ -#ifndef ECL_STRING_UTIL -#define ECL_STRING_UTIL +#ifndef RD_STRING_UTIL +#define RD_STRING_UTIL #include -namespace ecl { +namespace rd { namespace util { std::string string_format(const char *fmt, ...); } -} // namespace ecl +} // namespace rd #endif diff --git a/lib/ecl/FortIO.cpp b/lib/resdata/FortIO.cpp similarity index 97% rename from lib/ecl/FortIO.cpp rename to lib/resdata/FortIO.cpp index c0f3e307b4..db9aef7559 100644 --- a/lib/ecl/FortIO.cpp +++ b/lib/resdata/FortIO.cpp @@ -2,7 +2,7 @@ #include -#include +#include namespace ERT { diff --git a/lib/resdata/RDFilename.cpp b/lib/resdata/RDFilename.cpp new file mode 100644 index 0000000000..e9baf7d937 --- /dev/null +++ b/lib/resdata/RDFilename.cpp @@ -0,0 +1,67 @@ +#include +#include + +#include + +namespace ERT { + +std::string RDFilename(const std::string &path, const std::string &base, + rd_file_enum file_type, int report_step, bool fmt_file) { + char *tmp = rd_alloc_filename(path.c_str(), base.c_str(), file_type, + fmt_file, report_step); + std::string retval = tmp; + free(tmp); + return retval; +} + +std::string RDFilename(const std::string &base, rd_file_enum file_type, + int report_step, bool fmt_file) { + char *tmp = rd_alloc_filename(nullptr, base.c_str(), file_type, fmt_file, + report_step); + std::string retval = tmp; + free(tmp); + return retval; +} + +namespace { +bool require_report_step(rd_file_enum file_type) { + if ((file_type == RD_RESTART_FILE) || (file_type == RD_SUMMARY_FILE)) + return true; + else + return false; +} +} // namespace + +std::string RDFilename(const std::string &path, const std::string &base, + rd_file_enum file_type, bool fmt_file) { + if (require_report_step(file_type)) + throw std::runtime_error( + "Must use overload with report step for this file type"); + else { + char *tmp = rd_alloc_filename(path.c_str(), base.c_str(), file_type, + fmt_file, -1); + std::string retval = tmp; + free(tmp); + return retval; + } +} + +std::string RDFilename(const std::string &base, rd_file_enum file_type, + bool fmt_file) { + if (require_report_step(file_type)) + throw std::runtime_error( + "Must use overload with report step for this file type"); + else { + char *tmp = + rd_alloc_filename(nullptr, base.c_str(), file_type, fmt_file, -1); + std::string retval = tmp; + free(tmp); + return retval; + } +} + +rd_file_enum RDFiletype(const std::string &filename) { + return rd_get_file_type(filename.c_str(), nullptr, nullptr); +} + +} // namespace ERT diff --git a/lib/ecl/fault_block.cpp b/lib/resdata/fault_block.cpp similarity index 90% rename from lib/ecl/fault_block.cpp rename to lib/resdata/fault_block.cpp index b69d7ae547..8103a5bef7 100644 --- a/lib/ecl/fault_block.cpp +++ b/lib/resdata/fault_block.cpp @@ -7,19 +7,19 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include "detail/ecl/layer_cxx.hpp" +#include "detail/resdata/layer_cxx.hpp" #define FAULT_BLOCK_ID 3297376 struct fault_block_struct { UTIL_TYPE_ID_DECLARATION; - const ecl_grid_type *grid; + const rd_grid_type *grid; const fault_block_layer_type *parent_layer; int_vector_type *i_list; int_vector_type *j_list; @@ -77,7 +77,7 @@ void fault_block_add_cell(fault_block_type *fault_block, int i, int j) { int_vector_append(fault_block->j_list, j); int_vector_append( fault_block->global_index_list, - ecl_grid_get_global_index3(fault_block->grid, i, j, fault_block->k)); + rd_grid_get_global_index3(fault_block->grid, i, j, fault_block->k)); fault_block->valid_center = false; layer_iset_cell_value( fault_block_layer_get_layer(fault_block->parent_layer), i, j, @@ -109,11 +109,11 @@ static void fault_block_assert_center(fault_block_type *fault_block) { for (index = 0; index < int_vector_size(fault_block->i_list); index++) { int i = int_vector_iget(fault_block->i_list, index); int j = int_vector_iget(fault_block->j_list, index); - int g = ecl_grid_get_global_index3(fault_block->grid, i, j, - fault_block->k); + int g = rd_grid_get_global_index3(fault_block->grid, i, j, + fault_block->k); double x, y, z; - ecl_grid_get_xyz1(fault_block->grid, g, &x, &y, &z); + rd_grid_get_xyz1(fault_block->grid, g, &x, &y, &z); xc += x; yc += y; } @@ -141,7 +141,7 @@ void fault_block_export_cell(const fault_block_type *fault_block, int index, *j = int_vector_iget(fault_block->j_list, index); *k = fault_block->k; - ecl_grid_get_xyz3(fault_block->grid, *i, *j, *k, x, y, z); + rd_grid_get_xyz3(fault_block->grid, *i, *j, *k, x, y, z); } int fault_block_iget_i(const fault_block_type *fault_block, int index) { @@ -178,8 +178,8 @@ bool fault_block_trace_edge(const fault_block_type *block, for (const auto &p : corner_list) { double x, y, z; - ecl_grid_get_corner_xyz(block->grid, p.i, p.j, block->k, &x, &y, - &z); + rd_grid_get_corner_xyz(block->grid, p.i, p.j, block->k, &x, &y, + &z); double_vector_append(x_list, x); double_vector_append(y_list, y); } @@ -194,13 +194,13 @@ static bool fault_block_neighbour_xpolyline(const fault_block_type *block, int i1, int j1, int i2, int j2, const geo_polygon_collection_type *polylines) { - int g1 = ecl_grid_get_global_index3(block->grid, i1, j1, block->k); - int g2 = ecl_grid_get_global_index3(block->grid, i2, j2, block->k); + int g1 = rd_grid_get_global_index3(block->grid, i1, j1, block->k); + int g2 = rd_grid_get_global_index3(block->grid, i2, j2, block->k); double x1, y1, z1; double x2, y2, z2; - ecl_grid_get_xyz1(block->grid, g1, &x1, &y1, &z1); - ecl_grid_get_xyz1(block->grid, g2, &x2, &y2, &z2); + rd_grid_get_xyz1(block->grid, g1, &x1, &y1, &z1); + rd_grid_get_xyz1(block->grid, g2, &x2, &y2, &z2); { int polyline_index = 0; @@ -241,7 +241,7 @@ fault_block_connected_neighbour(const fault_block_type *block, int i1, int j1, Inactive cells do "not exist" - can not be connected neighbour with an inactive cell. */ - if (!ecl_grid_cell_active3(block->grid, i2, j2, block->k)) + if (!rd_grid_cell_active3(block->grid, i2, j2, block->k)) return false; { diff --git a/lib/ecl/fault_block_layer.cpp b/lib/resdata/fault_block_layer.cpp similarity index 80% rename from lib/ecl/fault_block_layer.cpp rename to lib/resdata/fault_block_layer.cpp index e79e513715..e9b7968f52 100644 --- a/lib/ecl/fault_block_layer.cpp +++ b/lib/resdata/fault_block_layer.cpp @@ -3,11 +3,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define FAULT_BLOCK_LAYER_ID 2297476 @@ -32,7 +32,7 @@ void fault_block_free(fault_block_type *block, int block_id); struct fault_block_layer_struct { UTIL_TYPE_ID_DECLARATION; - const ecl_grid_type *grid; + const rd_grid_type *grid; int_vector_type *block_map; layer_type *layer; int k; @@ -89,7 +89,7 @@ void fault_block_layer_scan_layer(fault_block_layer_type *fault_layer, } /* - Observe that the id values from the ecl_kw instance are not + Observe that the id values from the rd_kw instance are not retained; the fault_block_layer instance gets new block id numbers, including a nonzero value for the cells which have value zero in the keyword. @@ -105,24 +105,23 @@ void fault_block_layer_scan_layer(fault_block_layer_type *fault_layer, */ bool fault_block_layer_scan_kw(fault_block_layer_type *layer, - const ecl_kw_type *fault_block_kw) { + const rd_kw_type *fault_block_kw) { bool assign_zero = true; - if (ecl_kw_get_size(fault_block_kw) != - ecl_grid_get_global_size(layer->grid)) + if (rd_kw_get_size(fault_block_kw) != rd_grid_get_global_size(layer->grid)) return false; - else if (!ecl_type_is_int(ecl_kw_get_data_type(fault_block_kw))) + else if (!rd_type_is_int(rd_kw_get_data_type(fault_block_kw))) return false; else { int i, j; int max_block_id = 0; - layer_type *work_layer = layer_alloc(ecl_grid_get_nx(layer->grid), - ecl_grid_get_ny(layer->grid)); + layer_type *work_layer = layer_alloc(rd_grid_get_nx(layer->grid), + rd_grid_get_ny(layer->grid)); - for (j = 0; j < ecl_grid_get_ny(layer->grid); j++) { - for (i = 0; i < ecl_grid_get_nx(layer->grid); i++) { - int g = ecl_grid_get_global_index3(layer->grid, i, j, layer->k); - int block_id = ecl_kw_iget_int(fault_block_kw, g); + for (j = 0; j < rd_grid_get_ny(layer->grid); j++) { + for (i = 0; i < rd_grid_get_nx(layer->grid); i++) { + int g = rd_grid_get_global_index3(layer->grid, i, j, layer->k); + int block_id = rd_kw_iget_int(fault_block_kw, g); if (block_id > 0) { layer_iset_cell_value(work_layer, i, j, block_id); @@ -147,19 +146,18 @@ bool fault_block_layer_scan_kw(fault_block_layer_type *layer, */ bool fault_block_layer_load_kw(fault_block_layer_type *layer, - const ecl_kw_type *fault_block_kw) { - if (ecl_kw_get_size(fault_block_kw) != - ecl_grid_get_global_size(layer->grid)) + const rd_kw_type *fault_block_kw) { + if (rd_kw_get_size(fault_block_kw) != rd_grid_get_global_size(layer->grid)) return false; - else if (!ecl_type_is_int(ecl_kw_get_data_type(fault_block_kw))) + else if (!rd_type_is_int(rd_kw_get_data_type(fault_block_kw))) return false; else { int i, j; - for (j = 0; j < ecl_grid_get_ny(layer->grid); j++) { - for (i = 0; i < ecl_grid_get_nx(layer->grid); i++) { - int g = ecl_grid_get_global_index3(layer->grid, i, j, layer->k); - int block_id = ecl_kw_iget_int(fault_block_kw, g); + for (j = 0; j < rd_grid_get_ny(layer->grid); j++) { + for (i = 0; i < rd_grid_get_nx(layer->grid); i++) { + int g = rd_grid_get_global_index3(layer->grid, i, j, layer->k); + int block_id = rd_kw_iget_int(fault_block_kw, g); if (block_id > 0) { fault_block_layer_add_block(layer, block_id); { @@ -175,9 +173,9 @@ bool fault_block_layer_load_kw(fault_block_layer_type *layer, } } -fault_block_layer_type *fault_block_layer_alloc(const ecl_grid_type *grid, +fault_block_layer_type *fault_block_layer_alloc(const rd_grid_type *grid, int k) { - if ((k < 0) || (k >= ecl_grid_get_nz(grid))) + if ((k < 0) || (k >= rd_grid_get_nz(grid))) return NULL; else { fault_block_layer_type *layer = @@ -187,8 +185,7 @@ fault_block_layer_type *fault_block_layer_alloc(const ecl_grid_type *grid, layer->k = k; layer->block_map = int_vector_alloc(0, -1); layer->blocks = vector_alloc_new(); - layer->layer = - layer_alloc(ecl_grid_get_nx(grid), ecl_grid_get_ny(grid)); + layer->layer = layer_alloc(rd_grid_get_nx(grid), rd_grid_get_ny(grid)); return layer; } @@ -287,17 +284,17 @@ void fault_block_layer_insert_block_content(fault_block_layer_type *layer, } bool fault_block_layer_export(const fault_block_layer_type *layer, - ecl_kw_type *faultblock_kw) { - if (ecl_type_is_int(ecl_kw_get_data_type(faultblock_kw)) && - (ecl_kw_get_size(faultblock_kw) == - ecl_grid_get_global_size(layer->grid))) { + rd_kw_type *faultblock_kw) { + if (rd_type_is_int(rd_kw_get_data_type(faultblock_kw)) && + (rd_kw_get_size(faultblock_kw) == + rd_grid_get_global_size(layer->grid))) { int i, j; - for (j = 0; j < ecl_grid_get_ny(layer->grid); j++) { - for (i = 0; i < ecl_grid_get_nx(layer->grid); i++) { - int g = ecl_grid_get_global_index3(layer->grid, i, j, layer->k); + for (j = 0; j < rd_grid_get_ny(layer->grid); j++) { + for (i = 0; i < rd_grid_get_nx(layer->grid); i++) { + int g = rd_grid_get_global_index3(layer->grid, i, j, layer->k); int cell_value = layer_iget_cell_value(layer->layer, i, j); - ecl_kw_iset_int(faultblock_kw, g, cell_value); + rd_kw_iset_int(faultblock_kw, g, cell_value); } } return true; @@ -305,7 +302,7 @@ bool fault_block_layer_export(const fault_block_layer_type *layer, return false; } -const ecl_grid_type * +const rd_grid_type * fault_block_layer_get_grid(const fault_block_layer_type *layer) { return layer->grid; } diff --git a/lib/ecl/fortio.c b/lib/resdata/fortio.c similarity index 99% rename from lib/ecl/fortio.c rename to lib/resdata/fortio.c index 1fd3009aa4..2c2d5f6b47 100644 --- a/lib/ecl/fortio.c +++ b/lib/resdata/fortio.c @@ -24,7 +24,7 @@ #include #include -#include +#include #define FORTIO_ID 345116 diff --git a/lib/ecl/grid_dims.cpp b/lib/resdata/grid_dims.cpp similarity index 94% rename from lib/ecl/grid_dims.cpp rename to lib/resdata/grid_dims.cpp index a4e973821b..184d9046ba 100644 --- a/lib/ecl/grid_dims.cpp +++ b/lib/resdata/grid_dims.cpp @@ -2,7 +2,7 @@ #include -#include +#include void grid_dims_init(grid_dims_type *dims, int nx, int ny, int nz, int nactive) { dims->nx = nx; diff --git a/lib/ecl/layer.cpp b/lib/resdata/layer.cpp similarity index 98% rename from lib/ecl/layer.cpp rename to lib/resdata/layer.cpp index 61cdc4439f..6faea053fb 100644 --- a/lib/ecl/layer.cpp +++ b/lib/resdata/layer.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #define LAYER_TYPE_ID 55185409 @@ -762,12 +762,12 @@ int layer_count_equal(const layer_type *layer, int value) { return num_equal; } -void layer_update_active(layer_type *layer, const ecl_grid_type *grid, int k) { +void layer_update_active(layer_type *layer, const rd_grid_type *grid, int k) { int i, j; - for (j = 0; j < ecl_grid_get_ny(grid); j++) { - for (i = 0; i < ecl_grid_get_nx(grid); i++) { + for (j = 0; j < rd_grid_get_ny(grid); j++) { + for (i = 0; i < rd_grid_get_nx(grid); i++) { cell_type *cell = layer_iget_cell(layer, i, j); - cell->active = ecl_grid_cell_active3(grid, i, j, k); + cell->active = rd_grid_cell_active3(grid, i, j, k); } } } diff --git a/lib/ecl/nnc_info.cpp b/lib/resdata/nnc_info.cpp similarity index 98% rename from lib/ecl/nnc_info.cpp rename to lib/resdata/nnc_info.cpp index 9b1444a420..d83b3b0e8c 100644 --- a/lib/ecl/nnc_info.cpp +++ b/lib/resdata/nnc_info.cpp @@ -9,9 +9,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define NNC_INFO_TYPE_ID 675415078 diff --git a/lib/ecl/nnc_vector.cpp b/lib/resdata/nnc_vector.cpp similarity index 98% rename from lib/ecl/nnc_vector.cpp rename to lib/resdata/nnc_vector.cpp index 0fb3c78fac..c140d8647f 100644 --- a/lib/ecl/nnc_vector.cpp +++ b/lib/resdata/nnc_vector.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #define NNC_VECTOR_TYPE_ID 875615078 diff --git a/lib/ecl/ecl_box.cpp b/lib/resdata/rd_box.cpp similarity index 61% rename from lib/ecl/ecl_box.cpp rename to lib/resdata/rd_box.cpp index ecc5bf7c2a..70f0f6be87 100644 --- a/lib/ecl/ecl_box.cpp +++ b/lib/resdata/rd_box.cpp @@ -4,12 +4,12 @@ #include -#include -#include +#include +#include -namespace ecl { -ecl_box::ecl_box(const ecl_grid_type *grid, int i1, int i2, int j1, int j2, - int k1, int k2) +namespace rd { +rd_box::rd_box(const rd_grid_type *grid, int i1, int i2, int j1, int j2, int k1, + int k2) : grid(grid), i1(std::min(i1, i2)), i2(std::max(i1, i2)), j1(std::min(j1, j2)), j2(std::max(j1, j2)), k1(std::min(k1, k2)), k2(std::max(k1, k2)) { @@ -17,16 +17,16 @@ ecl_box::ecl_box(const ecl_grid_type *grid, int i1, int i2, int j1, int j2, for (int j = this->j1; j <= this->j2; j++) for (int i = this->i1; i <= this->i2; i++) { int active_index = - ecl_grid_get_active_index3(this->grid, i, j, k); + rd_grid_get_active_index3(this->grid, i, j, k); if (active_index >= 0) this->active_index_list.push_back(active_index); this->global_index_list.push_back( - ecl_grid_get_global_index3(this->grid, i, j, k)); + rd_grid_get_global_index3(this->grid, i, j, k)); } } -const std::vector &ecl_box::active_list() const { +const std::vector &rd_box::active_list() const { return this->active_index_list; } -} // namespace ecl +} // namespace rd diff --git a/lib/ecl/ecl_coarse_cell.cpp b/lib/resdata/rd_coarse_cell.cpp similarity index 73% rename from lib/ecl/ecl_coarse_cell.cpp rename to lib/resdata/rd_coarse_cell.cpp index c40177659e..aef3bc3b9c 100644 --- a/lib/ecl/ecl_coarse_cell.cpp +++ b/lib/resdata/rd_coarse_cell.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include /* @@ -68,12 +68,12 @@ current grid active_index == 3 will point to the coarse cell, and all the cells in the coarse region will: - - ecl_grid_cell_active1( grid , global_index) => True - - ecl_grid_get_active_index1( grid , global_index) => 3 + - rd_grid_cell_active1( grid , global_index) => True + - rd_grid_get_active_index1( grid , global_index) => 3 -For the example above the ecl_coarse_cell datastructure would have the +For the example above the rd_coarse_cell datastructure would have the following content: ijk = {0 , 5 , 0 , 4 , k1 , k2 } @@ -84,9 +84,9 @@ following content: */ -#define ECL_COARSE_CELL_TYPE_ID 91554106 +#define RD_COARSE_CELL_TYPE_ID 91554106 -struct ecl_coarse_cell_struct { +struct rd_coarse_cell_struct { UTIL_TYPE_ID_DECLARATION; int ijk[6]; // {i1, i2 , j1 , j2 , k1 , k2} int active_index; @@ -98,9 +98,9 @@ struct ecl_coarse_cell_struct { int_vector_type *active_values; }; -static UTIL_SAFE_CAST_FUNCTION(ecl_coarse_cell, ECL_COARSE_CELL_TYPE_ID) +static UTIL_SAFE_CAST_FUNCTION(rd_coarse_cell, RD_COARSE_CELL_TYPE_ID) - void ecl_coarse_cell_assert(ecl_coarse_cell_type *coarse_cell) { + void rd_coarse_cell_assert(rd_coarse_cell_type *coarse_cell) { int box_size = (1 + coarse_cell->ijk[1] - coarse_cell->ijk[0]) * (1 + coarse_cell->ijk[2] - coarse_cell->ijk[3]) * (1 + coarse_cell->ijk[4] - coarse_cell->ijk[5]); @@ -111,11 +111,11 @@ static UTIL_SAFE_CAST_FUNCTION(ecl_coarse_cell, ECL_COARSE_CELL_TYPE_ID) __func__, box_size, int_vector_size(coarse_cell->cell_list)); } -ecl_coarse_cell_type *ecl_coarse_cell_alloc() { +rd_coarse_cell_type *rd_coarse_cell_alloc() { const int LARGE = 1 << 30; - ecl_coarse_cell_type *coarse_cell = - (ecl_coarse_cell_type *)util_malloc(sizeof *coarse_cell); - UTIL_TYPE_ID_INIT(coarse_cell, ECL_COARSE_CELL_TYPE_ID); + rd_coarse_cell_type *coarse_cell = + (rd_coarse_cell_type *)util_malloc(sizeof *coarse_cell); + UTIL_TYPE_ID_INIT(coarse_cell, RD_COARSE_CELL_TYPE_ID); coarse_cell->ijk[0] = LARGE; coarse_cell->ijk[2] = LARGE; @@ -134,8 +134,8 @@ ecl_coarse_cell_type *ecl_coarse_cell_alloc() { return coarse_cell; } -bool ecl_coarse_cell_equal(const ecl_coarse_cell_type *coarse_cell1, - const ecl_coarse_cell_type *coarse_cell2) { +bool rd_coarse_cell_equal(const rd_coarse_cell_type *coarse_cell1, + const rd_coarse_cell_type *coarse_cell2) { bool equal = true; if (coarse_cell1->active_index != coarse_cell2->active_index) equal = false; @@ -163,8 +163,8 @@ bool ecl_coarse_cell_equal(const ecl_coarse_cell_type *coarse_cell1, int_vector_equal(coarse_cell1->cell_list, coarse_cell2->cell_list); if (!equal) { - ecl_coarse_cell_fprintf(coarse_cell1, stdout); - ecl_coarse_cell_fprintf(coarse_cell2, stdout); + rd_coarse_cell_fprintf(coarse_cell1, stdout); + rd_coarse_cell_fprintf(coarse_cell2, stdout); } return equal; @@ -175,8 +175,8 @@ bool ecl_coarse_cell_equal(const ecl_coarse_cell_type *coarse_cell1, not checked. */ -void ecl_coarse_cell_update(ecl_coarse_cell_type *coarse_cell, int i, int j, - int k, int global_index) { +void rd_coarse_cell_update(rd_coarse_cell_type *coarse_cell, int i, int j, + int k, int global_index) { coarse_cell->ijk[0] = util_int_min(coarse_cell->ijk[0], i); coarse_cell->ijk[2] = util_int_min(coarse_cell->ijk[2], j); coarse_cell->ijk[4] = util_int_min(coarse_cell->ijk[4], k); @@ -188,84 +188,82 @@ void ecl_coarse_cell_update(ecl_coarse_cell_type *coarse_cell, int i, int j, int_vector_append(coarse_cell->cell_list, global_index); } -void ecl_coarse_cell_free(ecl_coarse_cell_type *coarse_cell) { +void rd_coarse_cell_free(rd_coarse_cell_type *coarse_cell) { int_vector_free(coarse_cell->cell_list); int_vector_free(coarse_cell->active_cells); int_vector_free(coarse_cell->active_values); free(coarse_cell); } -void ecl_coarse_cell_free__(void *arg) { - ecl_coarse_cell_type *coarse_cell = ecl_coarse_cell_safe_cast(arg); - ecl_coarse_cell_free(coarse_cell); +void rd_coarse_cell_free__(void *arg) { + rd_coarse_cell_type *coarse_cell = rd_coarse_cell_safe_cast(arg); + rd_coarse_cell_free(coarse_cell); } -static void ecl_coarse_cell_sort(ecl_coarse_cell_type *coarse_cell) { +static void rd_coarse_cell_sort(rd_coarse_cell_type *coarse_cell) { if (!coarse_cell->__cell_list_sorted) { int_vector_sort(coarse_cell->cell_list); coarse_cell->__cell_list_sorted = true; } } -int ecl_coarse_cell_get_size(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_size(const rd_coarse_cell_type *coarse_cell) { return int_vector_size(coarse_cell->cell_list); } -int ecl_coarse_cell_iget_cell_index(ecl_coarse_cell_type *coarse_cell, - int group_index) { - ecl_coarse_cell_sort(coarse_cell); +int rd_coarse_cell_iget_cell_index(rd_coarse_cell_type *coarse_cell, + int group_index) { + rd_coarse_cell_sort(coarse_cell); return int_vector_iget(coarse_cell->cell_list, group_index); } -const int *ecl_coarse_cell_get_index_ptr(ecl_coarse_cell_type *coarse_cell) { - ecl_coarse_cell_sort(coarse_cell); +const int *rd_coarse_cell_get_index_ptr(rd_coarse_cell_type *coarse_cell) { + rd_coarse_cell_sort(coarse_cell); return int_vector_get_const_ptr(coarse_cell->cell_list); } const int_vector_type * -ecl_coarse_cell_get_index_vector(ecl_coarse_cell_type *coarse_cell) { - ecl_coarse_cell_sort(coarse_cell); +rd_coarse_cell_get_index_vector(rd_coarse_cell_type *coarse_cell) { + rd_coarse_cell_sort(coarse_cell); return coarse_cell->cell_list; } -int ecl_coarse_cell_get_i1(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_i1(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk[0]; } -int ecl_coarse_cell_get_i2(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_i2(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk[1]; } -int ecl_coarse_cell_get_j1(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_j1(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk[2]; } -int ecl_coarse_cell_get_j2(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_j2(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk[3]; } -int ecl_coarse_cell_get_k1(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_k1(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk[4]; } -int ecl_coarse_cell_get_k2(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_k2(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk[5]; } -const int * -ecl_coarse_cell_get_box_ptr(const ecl_coarse_cell_type *coarse_cell) { +const int *rd_coarse_cell_get_box_ptr(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->ijk; } -void ecl_coarse_cell_reset_active_index(ecl_coarse_cell_type *coarse_cell) { +void rd_coarse_cell_reset_active_index(rd_coarse_cell_type *coarse_cell) { coarse_cell->active_index = -1; coarse_cell->active_fracture_index = -1; } -void ecl_coarse_cell_update_index(ecl_coarse_cell_type *coarse_cell, - int global_index, int *active_index, - int *active_fracture_index, - int active_value) { +void rd_coarse_cell_update_index(rd_coarse_cell_type *coarse_cell, + int global_index, int *active_index, + int *active_fracture_index, int active_value) { if (active_value & CELL_ACTIVE_MATRIX) { if (coarse_cell->active_index == -1) { coarse_cell->active_index = *active_index; @@ -293,12 +291,12 @@ void ecl_coarse_cell_update_index(ecl_coarse_cell_type *coarse_cell, } } -int ecl_coarse_cell_get_active_index(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_active_index(const rd_coarse_cell_type *coarse_cell) { return coarse_cell->active_index; } -int ecl_coarse_cell_get_active_fracture_index( - const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_active_fracture_index( + const rd_coarse_cell_type *coarse_cell) { return coarse_cell->active_fracture_index; } @@ -306,22 +304,22 @@ int ecl_coarse_cell_get_active_fracture_index( Will return the global index of the 'ith active cell in the coarse cell. */ -int ecl_coarse_cell_iget_active_cell_index( - const ecl_coarse_cell_type *coarse_cell, int index) { +int rd_coarse_cell_iget_active_cell_index( + const rd_coarse_cell_type *coarse_cell, int index) { return int_vector_iget(coarse_cell->active_cells, index); } -int ecl_coarse_cell_iget_active_value(const ecl_coarse_cell_type *coarse_cell, - int index) { +int rd_coarse_cell_iget_active_value(const rd_coarse_cell_type *coarse_cell, + int index) { return int_vector_iget(coarse_cell->active_values, index); } -int ecl_coarse_cell_get_num_active(const ecl_coarse_cell_type *coarse_cell) { +int rd_coarse_cell_get_num_active(const rd_coarse_cell_type *coarse_cell) { return int_vector_size(coarse_cell->active_cells); } -void ecl_coarse_cell_fprintf(const ecl_coarse_cell_type *coarse_cell, - FILE *stream) { +void rd_coarse_cell_fprintf(const rd_coarse_cell_type *coarse_cell, + FILE *stream) { fprintf(stream, "Coarse box: \n"); fprintf(stream, " i : %3d - %3d\n", coarse_cell->ijk[0], coarse_cell->ijk[1]); diff --git a/lib/resdata/rd_file.cpp b/lib/resdata/rd_file.cpp new file mode 100644 index 0000000000..d3ffab86c2 --- /dev/null +++ b/lib/resdata/rd_file.cpp @@ -0,0 +1,999 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + This file implements functionality to load a file in + restart format. The implementation works by first searching through + the complete file to create an index over all the keywords present + in the file. The actual keyword data is not loaded before they are + explicitly requested. + + The rd_file_type is the middle layer of abstraction in the resdata + hierarchy (see the file overview.txt in this directory); it works + with a collection of rd_kw instances and has various query + functions, however it does not utilize knowledge of the + structure/content of the files in the way e.g. rd_grid.c does[1]. + + The main datatype here is the rd_file type, but in addition each + rd_kw instance is wrapped in an rd_file_kw (implemented in + rd_file_kw.c) structure and all the indexing is implemented with + the rd_file_view type. The rd_file_view type is not used outside this file. + + When the file is opened an index of all the keywords is created and + stored in the field global_map, and the field active_view is set to + point to global_map, i.e. all query/get operations on the rd_file + will be based on the complete index: + + In many cases (in particular for unified restart files) it is quite + painful to work with this large and unvieldy index, and it is + convenient to create a sub index based on a subset of the + keywords. The creation of these sub indices is based on identifying + a keyword from name and occurence number, and then including all + keywords up to the next occurence of the same keyword: + + SEQHDR ---\ + MINISTEP 0 | + PARAMS ..... | + MINISTEP 1 | Block 0 + PARAMS ..... | + MINISTEP 2 | + PARAMS ..... | + SEQHDR ---+ + MINISTEP 3 | + PARAMS ..... | + MINISTEP 4 | Block 1 + PARAMS ..... | + MINISTEP 5 | + SEQHDR ---+ + MINISTEP 6 | Block 2 + PARAMS .... | + SEQHDR ---+ + MINISTEP 7 | + PARAMS .... | Block 3 + MINISTEP 8 | + PARAMS .... | + + For the unified summary file depicted here e.g. the call + + rd_file_get_blockmap( rd_file , "SEQHDR" , 2 ) + + Will create a sub-index consisting of the (three) keywords in what + is called 'Block 2' in the figure above. In particular for restart + files this abstraction is very convenient, because an extra layer + of functionality is required to get from natural time coordinates + (i.e. simulation time or report step) to the occurence number (see + rd_rstfile for more details). + + To select a subindex as the active index you use the + rd_file_select_block() function, or alternatively you can use + rd_file_open_block() to directly select the relevant block + immediately after the open() statement. Observe that when using a + sub index thorugh rd_file_select_block() function the global_map + will still be present in the rd_file instance, and subsequent + calls to create a new sub index will also use the global_map index + - i.e. the indexing is not recursive, a sub index is always created + based on the global_map, and not on the currently active map. + + + [1]: This is not entirely true - in the file rd_rstfile.c; which + is included from this file are several specialized function + for working with restart files. However the restart files are + still treated as collections of rd_kw instances, and not + internalized as in e.g. rd_sum. +*/ + +#define RD_FILE_ID 776107 + +struct rd_file_struct { + UTIL_TYPE_ID_DECLARATION; + fortio_type *fortio; /* The source of all the keywords - must be retained + open for reading for the entire lifetime of the + rd_file object. */ + rd_file_view_type + *global_view; /* The index of all the rd_kw instances in the file. */ + rd_file_view_type *active_view; /* The currently active index. */ + bool read_only; + int flags; + vector_type *map_stack; + inv_map_type *inv_view; +}; + +/* + This illustrates the indexing. The rd_file instance contains in + total 7 rd_kw instances, the global index [0...6] is the internal + way to access the various keywords. The kw_index is a hash table + with entries 'SEQHDR', 'MINISTEP' and 'PARAMS'. Each entry in the + hash table is an integer vector which again contains the internal + index of the various occurences: + + ------------------ + SEQHDR \ + MINISTEP 0 | + PARAMS ..... | + MINISTEP 1 | + PARAMS ..... | + MINISTEP 2 | + PARAMS ..... / + ------------------ + + kw_index = {"SEQHDR": [0], "MINISTEP": [1,3,5], "PARAMS": [2,4,6]} <== This is hash table. + kw_list = [SEQHDR , MINISTEP , PARAMS , MINISTEP , PARAMS , MINISTEP , PARAMS] + distinct_kw = [SEQHDR , MINISTEP , PARAMS] + +*/ + +UTIL_SAFE_CAST_FUNCTION(rd_file, RD_FILE_ID) +UTIL_IS_INSTANCE_FUNCTION(rd_file, RD_FILE_ID) + +rd_file_type *rd_file_alloc_empty(int flags) { + rd_file_type *rd_file = (rd_file_type *)util_malloc(sizeof *rd_file); + UTIL_TYPE_ID_INIT(rd_file, RD_FILE_ID); + rd_file->map_stack = vector_alloc_new(); + rd_file->inv_view = inv_map_alloc(); + rd_file->flags = flags; + return rd_file; +} + +void rd_file_fwrite_fortio(const rd_file_type *rd_file, fortio_type *target, + int offset) { + rd_file_view_fwrite(rd_file->active_view, target, offset); +} + +/* + Observe : if the filename is a standard filename which can be used + to infer formatted/unformatted automagically the fmt_file variable + is NOT consulted. +*/ + +void rd_file_fwrite(const rd_file_type *rd_file, const char *filename, + bool fmt_file) { + bool __fmt_file; + rd_file_enum file_type; + + file_type = rd_get_file_type(filename, &__fmt_file, NULL); + if (file_type == RD_OTHER_FILE) + __fmt_file = fmt_file; + + { + fortio_type *target = + fortio_open_writer(filename, __fmt_file, RD_ENDIAN_FLIP); + rd_file_fwrite_fortio(rd_file, target, 0); + fortio_fclose(target); + } +} + +/** + Here comes several functions for querying the rd_file instance, and + getting pointers to the rd_kw content of the rd_file. For getting + rd_kw instances there are two principally different access methods: + + * rd_file_iget_named_kw(): This function will take a keyword + (char *) and an integer as input. The integer corresponds to the + ith occurence of the keyword in the file. + + * rd_file_iget_kw(): This function just takes an integer index as + input, and returns the corresponding rd_kw instance - without + considering which keyword it is. + + ------- + + In addition the functions rd_file_get_num_distinct_kw() and + rd_file_iget_distinct_kw() will return the number of distinct + keywords, and distinct keyword keyword nr i (as a const char *). + + + Possible usage pattern: + + .... + for (ikw = 0; ikw < rd_file_get_num_distinct_kw(rd_file); ikw++) { + const char * kw = rd_file_iget_distinct_kw(rd_file , ikw); + + printf("The file contains: %d occurences of \'%s\' \n",rd_file_get_num_named_kw( rd_file , kw) , kw); + } + .... + + For the summary file showed in the top this code will produce: + + The file contains 1 occurences of 'SEQHDR' + The file contains 3 occurences of 'MINISTEP' + The file contains 3 occurences of 'PARAMS' + +*/ + +/** + This function will iterate through the rd_file instance and search + for the rd_kw instance @old_kw - the search is based on pointer + equality, i.e. the actual rd_kw instance, and not on content + equality. + + When @old_kw is found that keyword instance will be discarded with + rd_kw_free() and the new keyword @new_kw will be inserted. If + @old_kw can not be found the function will fail hard - to verify + that @new_kw is indeed in the rd_file instance you should use + rd_file_has_kw_ptr() first. + + The rd_file function typically gives out references to the + internal rd_kw instances via the rd_file_iget_kw() function. Use + of rd_file_replace_kw() might lead to invalidating rd_kw + instances held by the calling scope: + + + .... + rd_file_type * restart_file = rd_file_fread_alloc( "CASE.UNRST" ); + rd_kw_type * initial_pressure = rd_file_iget_named_kw( rd_file , "PRESSURE" , 0); + rd_kw_type * faked_pressure = rd_kw_alloc_copy( initial_pressure ); + + rd_kw_scale( faked_pressure , 1.25 ); + rd_file_replace_kw( restart_file , initial_pressure , faked_pressure , false ); <--- This call will invalidate the inital_pressure reference + .... + .... + // This will fail horribly: + printf("The initial pressure in cell(0) was:%g \n",rd_kw_iget_double( initial_pressure , 0 )); + /|\ + | + +---------> Using initial_pressure => Crash and burn! + + The rd_file structure takes ownership of all the keywords, and + will also take ownership of the newly instered @new_kw instance; if + the boolean @insert_copy is set to true the function will insert a + copy of @new_kw, leaving the original reference untouched. +*/ + +void rd_file_replace_kw(rd_file_type *rd_file, rd_kw_type *old_kw, + rd_kw_type *new_kw, bool insert_copy) { + rd_file_view_replace_kw(rd_file->active_view, old_kw, new_kw, insert_copy); +} + +rd_kw_type *rd_file_icopy_named_kw(const rd_file_type *rd_file, const char *kw, + int ith) { + return rd_kw_alloc_copy(rd_file_iget_named_kw(rd_file, kw, ith)); +} + +/* + Will return the number of times a particular keyword occurs in a + rd_file instance. Will return 0 if the keyword can not be found. +*/ + +int rd_file_get_num_named_kw(const rd_file_type *rd_file, const char *kw) { + return rd_file_view_get_num_named_kw(rd_file->active_view, kw); +} + +/** + This function does the following: + + 1. Takes an input index which goes in to the global kw_list vector. + 2. Looks up the corresponding keyword. + 3. Return the number of this particular keyword instance, among + the other instance with the same header. + + With the example above we get: + + rd_file_iget_occurence(rd_file , 2) -> 0; Global index 2 will + look up the first occurence of PARAMS. + + rd_file_iget_occurence(rd_file , 5) -> 2; Global index 5 will + look up th third occurence of MINISTEP. + + The enkf layer uses this funny functionality. +*/ + +int rd_file_iget_occurence(const rd_file_type *rd_file, int index) { + return rd_file_view_iget_occurence(rd_file->active_view, index); +} + +/** + Returns the total number of rd_kw instances in the rd_file + instance. +*/ +int rd_file_get_size(const rd_file_type *rd_file) { + return rd_file_view_get_size(rd_file->active_view); +} + +/** + Returns true if the rd_file instance has at-least one occurence of + rd_kw 'kw'. +*/ +bool rd_file_has_kw(const rd_file_type *rd_file, const char *kw) { + return rd_file_view_has_kw(rd_file->active_view, kw); +} + +int rd_file_get_num_distinct_kw(const rd_file_type *rd_file) { + return rd_file_view_get_num_distinct_kw(rd_file->active_view); +} + +const char *rd_file_iget_distinct_kw(const rd_file_type *rd_file, int index) { + return rd_file_view_iget_distinct_kw(rd_file->active_view, index); +} + +const char *rd_file_get_src_file(const rd_file_type *rd_file) { + return fortio_filename_ref(rd_file->fortio); +} + +void rd_file_fprintf_kw_list(const rd_file_type *rd_file, FILE *stream) { + rd_file_view_fprintf_kw_list(rd_file->active_view, stream); +} + +rd_file_kw_type *rd_file_iget_file_kw(const rd_file_type *file, + int global_index) { + return rd_file_view_iget_file_kw(file->active_view, global_index); +} + +rd_file_kw_type *rd_file_iget_named_file_kw(const rd_file_type *file, + const char *kw, int ith) { + return rd_file_view_iget_named_file_kw(file->active_view, kw, ith); +} + +rd_kw_type *rd_file_iget_kw(const rd_file_type *file, int global_index) { + return rd_file_view_iget_kw(file->active_view, global_index); +} + +rd_data_type rd_file_iget_data_type(const rd_file_type *file, + int global_index) { + return rd_file_view_iget_data_type(file->active_view, global_index); +} + +int rd_file_iget_size(const rd_file_type *file, int global_index) { + return rd_file_view_iget_size(file->active_view, global_index); +} + +const char *rd_file_iget_header(const rd_file_type *file, int global_index) { + return rd_file_view_iget_header(file->active_view, global_index); +} + +/* + This function will return the ith occurence of 'kw' in + rd_file. Will abort hard if the request can not be satisifed - use + query functions if you can not take that. +*/ + +rd_kw_type *rd_file_iget_named_kw(const rd_file_type *file, const char *kw, + int ith) { + return rd_file_view_iget_named_kw(file->active_view, kw, ith); +} + +void rd_file_indexed_read(const rd_file_type *file, const char *kw, int index, + const int_vector_type *index_map, char *buffer) { + rd_file_view_index_fload_kw(file->active_view, kw, index, index_map, + buffer); +} + +rd_data_type rd_file_iget_named_data_type(const rd_file_type *file, + const char *kw, int ith) { + return rd_file_view_iget_named_data_type(file->active_view, kw, ith); +} + +int rd_file_iget_named_size(const rd_file_type *file, const char *kw, int ith) { + return rd_file_view_iget_named_size(file->active_view, kw, ith); +} + +rd_file_view_type *rd_file_get_global_view(rd_file_type *rd_file) { + return rd_file->global_view; +} + +// Very deprecated ... +rd_file_view_type *rd_file_get_active_view(rd_file_type *rd_file) { + return rd_file->active_view; +} + +rd_file_view_type *rd_file_get_global_blockview(rd_file_type *rd_file, + const char *kw, int occurence) { + rd_file_view_type *view = + rd_file_view_add_blockview(rd_file->global_view, kw, occurence); + return view; +} + +rd_file_view_type *rd_file_alloc_global_blockview2(rd_file_type *rd_file, + const char *start_kw, + const char *end_kw, + int occurence) { + rd_file_view_type *view = rd_file_view_alloc_blockview2( + rd_file->global_view, start_kw, end_kw, occurence); + return view; +} + +rd_file_view_type *rd_file_alloc_global_blockview(rd_file_type *rd_file, + const char *kw, + int occurence) { + return rd_file_alloc_global_blockview2(rd_file, kw, kw, occurence); +} + +rd_file_view_type *rd_file_get_restart_view(rd_file_type *rd_file, + int input_index, int report_step, + time_t sim_time, double sim_days) { + rd_file_view_type *view = rd_file_view_add_restart_view( + rd_file->global_view, input_index, report_step, sim_time, sim_days); + return view; +} + +rd_file_view_type *rd_file_get_summary_view(rd_file_type *rd_file, + int report_step) { + rd_file_view_type *view = + rd_file_view_add_summary_view(rd_file->global_view, report_step); + return view; +} + +/* + Different functions to open and close a file. +*/ + +/** + The rd_file_scan() function will scan through the whole file and build up an + index of all the kewyords. The map created from this scan will be stored + under the 'global_view' field; and all subsequent lookup operations will + ultimately be based on the global map. + + The rd_file_scan function will scan through the file as long as it finds + valid rd_kw instances on the disk; it will return when EOF is encountered or + an invalid rd_kw instance is detected. This implies that for a partly broken + file the rd_file_scan function will index the valid keywords which are in + the file, possible garbage at the end will be ignored. +*/ + +static void rd_file_scan(rd_file_type *rd_file) { + fortio_fseek(rd_file->fortio, 0, SEEK_SET); + { + rd_kw_type *work_kw = rd_kw_alloc_new("WORK-KW", 0, RD_INT, NULL); + + while (true) { + if (fortio_read_at_eof(rd_file->fortio)) + break; + + { + offset_type current_offset = fortio_ftell(rd_file->fortio); + rd_read_status_enum read_status = + rd_kw_fread_header(work_kw, rd_file->fortio); + if (read_status == RD_KW_READ_FAIL) + break; + + if (read_status == RD_KW_READ_OK) { + rd_file_kw_type *file_kw = + rd_file_kw_alloc(work_kw, current_offset); + + if (rd_file_kw_fskip_data(file_kw, rd_file->fortio)) + rd_file_view_add_kw(rd_file->global_view, file_kw); + else { + rd_file_kw_free(file_kw); + break; + } + } + } + } + + rd_kw_free(work_kw); + } + rd_file_view_make_index(rd_file->global_view); +} + +void rd_file_select_global(rd_file_type *rd_file) { + rd_file->active_view = rd_file->global_view; +} + +/** + The fundamental open file function; all alternative open() + functions start by calling this one. This function will read + through the complete file, extract all the keyword headers and + create the map/index stored in the global_view field of the rd_file + structure. No keyword data will be loaded from the file. + + The rd_file instance will retain an open fortio reference to the + file until rd_file_close() is called. +*/ + +static fortio_type *rd_file_alloc_fortio(const char *filename, int flags) { + fortio_type *fortio = NULL; + bool fmt_file; + + rd_fmt_file(filename, &fmt_file); + + if (rd_file_view_check_flags(flags, RD_FILE_WRITABLE)) + fortio = fortio_open_readwrite(filename, fmt_file, RD_ENDIAN_FLIP); + else + fortio = fortio_open_reader(filename, fmt_file, RD_ENDIAN_FLIP); + + return fortio; +} + +rd_file_type *rd_file_open(const char *filename, int flags) { + fortio_type *fortio = rd_file_alloc_fortio(filename, flags); + + if (fortio) { + rd_file_type *rd_file = rd_file_alloc_empty(flags); + rd_file->fortio = fortio; + rd_file->global_view = rd_file_view_alloc( + rd_file->fortio, &rd_file->flags, rd_file->inv_view, true); + + rd_file_scan(rd_file); + rd_file_select_global(rd_file); + + if (rd_file_view_check_flags(rd_file->flags, RD_FILE_CLOSE_STREAM)) + fortio_fclose_stream(rd_file->fortio); + + return rd_file; + } else + return NULL; +} + +int rd_file_get_flags(const rd_file_type *rd_file) { return rd_file->flags; } + +void rd_file_set_flags(rd_file_type *rd_file, int flags) { + rd_file->flags = flags; +} + +bool rd_file_flags_set(const rd_file_type *rd_file, int flags) { + return rd_file_view_check_flags(rd_file->flags, flags); +} + +bool rd_file_writable(const rd_file_type *rd_file) { + return rd_file_view_check_flags(rd_file->flags, RD_FILE_WRITABLE); +} + +/** + The rd_file_close() function will close the fortio instance and + free all the data created by the rd_file instance; this includes + the rd_kw instances which have been loaded on demand. +*/ + +void rd_file_close(rd_file_type *rd_file) { + if (rd_file->fortio != NULL) + fortio_fclose(rd_file->fortio); + + if (rd_file->global_view) + rd_file_view_free(rd_file->global_view); + + inv_map_free(rd_file->inv_view); + vector_free(rd_file->map_stack); + free(rd_file); +} + +void rd_file_close_fortio_stream(rd_file_type *rd_file) { + if (rd_file->fortio != NULL) { + fortio_fclose_stream(rd_file->fortio); + } +} + +/** + This function will detach the current rd_file instance from the + underlying fortio instance. The rd_file instance can be used + further to access the rd_kw instances which have been loaded + already, but if you try on-demand loading of a keyword you will get + crash-and-burn. To ensure that all keywords are in memory you can + call rd_file_load_all() prior to the detach call. +*/ + +void rd_file_fortio_detach(rd_file_type *rd_file) { + fortio_fclose(rd_file->fortio); + rd_file->fortio = NULL; +} + +bool rd_file_load_all(rd_file_type *rd_file) { + return rd_file_view_load_all(rd_file->active_view); +} + +void rd_file_free__(void *arg) { rd_file_close(rd_file_safe_cast(arg)); } + +/* Functions specialized to work with restart files. */ + +/* Query functions. */ +/** + Will look through all the INTEHEAD kw instances of the current + rd_file and look for @sim_time. If the value is found true is + returned, otherwise false. +*/ + +bool rd_file_has_sim_time(const rd_file_type *rd_file, time_t sim_time) { + return rd_file_view_has_sim_time(rd_file->active_view, sim_time); +} + +/* + This function will determine the restart block corresponding to the + world time @sim_time; if @sim_time can not be found the function + will return 0. + + The returned index is the 'occurence number' in the restart file, + i.e. in the (quite typical case) that not all report steps are + present the return value will not agree with report step. + + The return value from this function can then be used to get a + corresponding solution field directly, or the file map can + restricted to this block. + + Direct access: + + int index = rd_file_get_restart_index( rd_file , sim_time ); + if (index >= 0) { + rd_kw_type * pressure_kw = rd_file_iget_named_kw( rd_file , "PRESSURE" , index ); + .... + } + + + Using block restriction: + + int index = rd_file_get_restart_index( rd_file , sim_time ); + if (index >= 0) { + rd_file_iselect_rstblock( rd_file , index ); + { + rd_kw_type * pressure_kw = rd_file_iget_named_kw( rd_file , "PRESSURE" , 0 ); + .... + } + } + + Specially in the case of LGRs the block restriction should be used. + */ + +int rd_file_get_restart_index(const rd_file_type *rd_file, time_t sim_time) { + int active_index = + rd_file_view_find_sim_time(rd_file->active_view, sim_time); + return active_index; +} + +/** + Will look through all the SEQNUM kw instances of the current + rd_file and look for @report_step. If the value is found true is + returned, otherwise false. +*/ + +bool rd_file_has_report_step(const rd_file_type *rd_file, int report_step) { + return rd_file_view_has_report_step(rd_file->active_view, report_step); +} + +/** + This function will look up the INTEHEAD keyword in a rd_file_type + instance, and calculate simulation date from this instance. + + Will return -1 if the requested INTEHEAD keyword can not be found. +*/ + +time_t rd_file_iget_restart_sim_date(const rd_file_type *restart_file, + int index) { + return rd_file_view_iget_restart_sim_date(restart_file->active_view, index); +} + +double rd_file_iget_restart_sim_days(const rd_file_type *restart_file, + int index) { + return rd_file_view_iget_restart_sim_days(restart_file->active_view, index); +} + +/* + The input @file must be either an INIT file or a restart file. Will + fail hard if an INTEHEAD kw can not be found - or if the INTEHEAD + keyword is not sufficiently large. + + The eclipse files can distinguish between ECLIPSE300 ( value == 300) + and ECLIPSE300-Thermal option (value == 500). This function will + return ECLIPSE300 in both those cases. +*/ + +rd_version_enum rd_file_get_rd_version(const rd_file_type *file) { + rd_kw_type *intehead_kw = rd_file_iget_named_kw(file, INTEHEAD_KW, 0); + int int_value = rd_kw_iget_int(intehead_kw, INTEHEAD_IPROG_INDEX); + + if (int_value == INTEHEAD_ECLIPSE100_VALUE) + return ECLIPSE100; + + if (int_value == INTEHEAD_ECLIPSE300_VALUE) + return ECLIPSE300; + + if (int_value == INTEHEAD_ECLIPSE300THERMAL_VALUE) + return ECLIPSE300_THERMAL; + + if (int_value == INTEHEAD_INTERSECT_VALUE) + return INTERSECT; + + if (int_value == INTEHEAD_FRONTSIM_VALUE) + return FRONTSIM; + + util_abort("%s: Simulator version value:%d not recognized \n", __func__, + int_value); + return (rd_version_enum)0; +} + +/* + 1: Oil + 2: Water + 3: Oil + water + 4: Gas + 5: Gas + Oil + 6: Gas + water + 7: Gas + Water + Oil +*/ + +int rd_file_get_phases(const rd_file_type *init_file) { + rd_kw_type *intehead_kw = rd_file_iget_named_kw(init_file, INTEHEAD_KW, 0); + int phases = rd_kw_iget_int(intehead_kw, INTEHEAD_PHASE_INDEX); + return phases; +} + +/* +bool rd_file_writable( const rd_file_type * rd_file ) { + return fortio_writable( rd_file->fortio ); +} +*/ + +/** + Checks if the rd_file contains rd_kw; this check is based on + pointer equality - i.e. we check if the rd_file contains exactly + this keyword - not an arbitrary equivalent keyword. + + This function can be called as a safeguard before calling + rd_file_save_kw(). +*/ + +bool rd_file_has_kw_ptr(const rd_file_type *rd_file, const rd_kw_type *rd_kw) { + rd_file_kw_type *file_kw = inv_map_get_file_kw(rd_file->inv_view, rd_kw); + if (file_kw == NULL) + return false; + else + return true; +} + +/* + Will save the content of @rd_kw to the on-disk file wrapped by the + rd_file instance. This function is quite strict: + + 1. The actual keyword which should be updated is identified using + pointer comparison; i.e. the rd_kw argument must be the actual + return value from an earlier rd_file_get_kw() operation. To + check this you can call rd_file_has_kw_ptr(). + + 2. The header data of the rd_kw must be unmodified; this is checked + by the rd_file_kw_inplace_fwrite() function and crash-and-burn + will ensue if this is not satisfied. + + 3. The rd_file must have been opened with one of the _writable() + open functions. +*/ + +bool rd_file_save_kw(const rd_file_type *rd_file, const rd_kw_type *rd_kw) { + rd_file_kw_type *file_kw = inv_map_get_file_kw( + rd_file->inv_view, + rd_kw); // We just verify that the input rd_kw points to an rd_kw + if (file_kw != + NULL) { // we manage; from then on we use the reference contained in + if (fortio_assert_stream_open( + rd_file->fortio)) { // the corresponding rd_file_kw instance. + + rd_file_kw_inplace_fwrite(file_kw, rd_file->fortio); + + if (rd_file_view_check_flags(rd_file->flags, RD_FILE_CLOSE_STREAM)) + fortio_fclose_stream(rd_file->fortio); + + return true; + } else + return false; + } else { + util_abort("%s: keyword pointer:%p not found in rd_file instance. \n", + __func__, rd_kw); + return false; + } +} + +/* DEPRECATED */ +void rd_file_push_block(rd_file_type *rd_file) { + vector_append_ref(rd_file->map_stack, rd_file->active_view); +} + +void rd_file_pop_block(rd_file_type *rd_file) { + rd_file->active_view = + (rd_file_view_type *)vector_pop_back(rd_file->map_stack); +} + +static rd_file_view_type *rd_file_get_relative_blockview(rd_file_type *rd_file, + const char *kw, + int occurence) { + rd_file_view_type *view = + rd_file_view_add_blockview(rd_file->active_view, kw, occurence); + return view; +} + +bool rd_file_subselect_block(rd_file_type *rd_file, const char *kw, + int occurence) { + rd_file_view_type *blockmap = + rd_file_get_relative_blockview(rd_file, kw, occurence); + if (blockmap != NULL) { + rd_file->active_view = blockmap; + return true; + } else + return false; +} + +bool rd_file_select_block(rd_file_type *rd_file, const char *kw, + int occurence) { + rd_file_view_type *blockmap = + rd_file_get_global_blockview(rd_file, kw, occurence); + if (blockmap != NULL) { + rd_file->active_view = blockmap; + return true; + } else + return false; +} + +/* + Will select restart block nr @seqnum_index - without considering + report_steps or simulation time. +*/ +bool rd_file_iselect_rstblock(rd_file_type *rd_file, int seqnum_index) { + return rd_file_select_block(rd_file, SEQNUM_KW, seqnum_index); +} + +bool rd_file_select_rstblock_sim_time(rd_file_type *rd_file, time_t sim_time) { + int seqnum_index = + rd_file_view_seqnum_index_from_sim_time(rd_file->global_view, sim_time); + + if (seqnum_index >= 0) + return rd_file_iselect_rstblock(rd_file, seqnum_index); + else + return false; +} + +bool rd_file_select_rstblock_report_step(rd_file_type *rd_file, + int report_step) { + int global_index = rd_file_view_find_kw_value(rd_file->global_view, + SEQNUM_KW, &report_step); + if (global_index >= 0) { + int seqnum_index = + rd_file_view_iget_occurence(rd_file->global_view, global_index); + return rd_file_iselect_rstblock(rd_file, seqnum_index); + } else + return false; +} + +static rd_file_type *rd_file_open_rstblock_report_step__(const char *filename, + int report_step, + int flags) { + rd_file_type *rd_file = rd_file_open(filename, flags); + if (rd_file) { + if (!rd_file_select_rstblock_report_step(rd_file, report_step)) { + rd_file_close(rd_file); + rd_file = NULL; + } + } + return rd_file; +} + +rd_file_type *rd_file_open_rstblock_report_step(const char *filename, + int report_step, int flags) { + return rd_file_open_rstblock_report_step__(filename, report_step, flags); +} + +static rd_file_type *rd_file_open_rstblock_sim_time__(const char *filename, + time_t sim_time, + int flags) { + rd_file_type *rd_file = rd_file_open(filename, flags); + if (rd_file) { + if (!rd_file_select_rstblock_sim_time(rd_file, sim_time)) { + rd_file_close(rd_file); + rd_file = NULL; + } + } + return rd_file; +} + +rd_file_type *rd_file_open_rstblock_sim_time(const char *filename, + time_t sim_time, int flags) { + return rd_file_open_rstblock_sim_time__(filename, sim_time, flags); +} + +static rd_file_type *rd_file_iopen_rstblock__(const char *filename, + int seqnum_index, int flags) { + rd_file_type *rd_file = rd_file_open(filename, flags); + if (rd_file) { + if (!rd_file_iselect_rstblock(rd_file, seqnum_index)) { + rd_file_close(rd_file); + rd_file = NULL; + } + } + return rd_file; +} + +rd_file_type *rd_file_iopen_rstblock(const char *filename, int seqnum_index, + int flags) { + return rd_file_iopen_rstblock__(filename, seqnum_index, flags); +} + +static bool rd_file_index_valid0(const char *file_name, + const char *index_file_name) { + if (!util_file_exists(file_name)) + return false; + + if (!util_file_exists(index_file_name)) + return false; + + if (util_file_difftime(file_name, index_file_name) > 0) + return false; + + return true; +} + +static bool rd_file_index_valid1(const char *file_name, FILE *stream) { + bool name_equal; + char *source_file = util_fread_alloc_string(stream); + char *input_name = util_split_alloc_filename(file_name); + + name_equal = util_string_equal(source_file, input_name); + + free(source_file); + free(input_name); + return name_equal; +} + +bool rd_file_index_valid(const char *file_name, const char *index_file_name) { + if (!rd_file_index_valid0(file_name, index_file_name)) + return false; + + bool valid = false; + FILE *stream = fopen(index_file_name, "rb"); + if (stream) { + valid = rd_file_index_valid1(file_name, stream); + fclose(stream); + } + + return valid; +} + +bool rd_file_write_index(const rd_file_type *rd_file, + const char *index_filename) { + FILE *ostream = fopen(index_filename, "wb"); + if (!ostream) + return false; + { + char *filename = + util_split_alloc_filename(fortio_filename_ref(rd_file->fortio)); + util_fwrite_string(filename, ostream); + free(filename); + } + rd_file_view_write_index(rd_file->global_view, ostream); + fclose(ostream); + return true; +} + +rd_file_type *rd_file_fast_open(const char *file_name, + const char *index_file_name, int flags) { + if (!rd_file_index_valid0(file_name, index_file_name)) + return NULL; + + FILE *istream = fopen(index_file_name, "rb"); + if (!istream) + return NULL; + + rd_file_type *rd_file = NULL; + + if (rd_file_index_valid1(file_name, istream)) { + fortio_type *fortio = rd_file_alloc_fortio(file_name, flags); + if (fortio) { + rd_file = rd_file_alloc_empty(flags); + rd_file->fortio = fortio; + rd_file->global_view = rd_file_view_fread_alloc( + rd_file->fortio, &rd_file->flags, rd_file->inv_view, istream); + if (rd_file->global_view) { + rd_file_select_global(rd_file); + if (rd_file_view_check_flags(rd_file->flags, + RD_FILE_CLOSE_STREAM)) + fortio_fclose_stream(rd_file->fortio); + } else { + rd_file_close(rd_file); + rd_file = NULL; + } + } + } + fclose(istream); + return rd_file; +} diff --git a/lib/resdata/rd_file_kw.cpp b/lib/resdata/rd_file_kw.cpp new file mode 100644 index 0000000000..c0153cddff --- /dev/null +++ b/lib/resdata/rd_file_kw.cpp @@ -0,0 +1,422 @@ +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +/* + This file implements the datatype rd_file_kw which is used to hold + header-information about an rd_kw instance on file. When a + rd_file_kw instance is created it is initialized with the header + information (name, size, type) for an rd_kw instance and the offset + in a file actually containing the keyword. + + If and when the keyword is actually queried for at a later stage the + rd_file_kw_get_kw() method will seek to the keyword position in an + open fortio instance and call rd_kw_fread_alloc() to instantiate + the keyword itself. + + The rd_file_kw datatype is mainly used by the rd_file datatype; + whose index tables consists of rd_file_kw instances. +*/ + +#define RD_FILE_KW_TYPE_ID 646107 + +struct inv_map_struct { + size_t_vector_type *file_kw_ptr; + size_t_vector_type *rd_kw_ptr; + bool sorted; +}; + +struct rd_file_kw_struct { + UTIL_TYPE_ID_DECLARATION; + offset_type file_offset; + rd_data_type data_type; + int kw_size; + int ref_count; + char *header; + rd_kw_type *kw; +}; + +inv_map_type *inv_map_alloc() { + inv_map_type *map = (inv_map_type *)util_malloc(sizeof *map); + map->file_kw_ptr = size_t_vector_alloc(0, 0); + map->rd_kw_ptr = size_t_vector_alloc(0, 0); + map->sorted = false; + return map; +} + +void inv_map_free(inv_map_type *map) { + size_t_vector_free(map->file_kw_ptr); + size_t_vector_free(map->rd_kw_ptr); + free(map); +} + +static void inv_map_assert_sort(inv_map_type *map) { + if (!map->sorted) { + perm_vector_type *perm = size_t_vector_alloc_sort_perm(map->rd_kw_ptr); + + size_t_vector_permute(map->rd_kw_ptr, perm); + size_t_vector_permute(map->file_kw_ptr, perm); + map->sorted = true; + + perm_vector_free(perm); + } +} + +static void inv_map_drop_kw(inv_map_type *map, const rd_kw_type *rd_kw) { + inv_map_assert_sort(map); + { + int index = size_t_vector_index_sorted(map->rd_kw_ptr, (size_t)rd_kw); + if (index == -1) + util_abort("%s: trying to drop non-existent kw \n", __func__); + + size_t_vector_idel(map->rd_kw_ptr, index); + size_t_vector_idel(map->file_kw_ptr, index); + map->sorted = false; + } +} + +static void inv_map_add_kw(inv_map_type *map, const rd_file_kw_type *file_kw, + const rd_kw_type *rd_kw) { + size_t_vector_append(map->file_kw_ptr, (size_t)file_kw); + size_t_vector_append(map->rd_kw_ptr, (size_t)rd_kw); + map->sorted = false; +} + +rd_file_kw_type *inv_map_get_file_kw(inv_map_type *inv_map, + const rd_kw_type *rd_kw) { + inv_map_assert_sort(inv_map); + { + int index = + size_t_vector_index_sorted(inv_map->rd_kw_ptr, (size_t)rd_kw); + if (index == -1) + /* rd_kw ptr not found. */ + return NULL; + else + return (rd_file_kw_type *)size_t_vector_iget(inv_map->file_kw_ptr, + index); + } +} + +static UTIL_SAFE_CAST_FUNCTION(rd_file_kw, RD_FILE_KW_TYPE_ID) + UTIL_IS_INSTANCE_FUNCTION(rd_file_kw, RD_FILE_KW_TYPE_ID) + + rd_file_kw_type *rd_file_kw_alloc0(const char *header, + rd_data_type data_type, int size, + offset_type offset) { + rd_file_kw_type *file_kw = (rd_file_kw_type *)util_malloc(sizeof *file_kw); + UTIL_TYPE_ID_INIT(file_kw, RD_FILE_KW_TYPE_ID); + + file_kw->header = util_alloc_string_copy(header); + memcpy(&file_kw->data_type, &data_type, sizeof data_type); + file_kw->kw_size = size; + file_kw->file_offset = offset; + file_kw->ref_count = 0; + file_kw->kw = NULL; + + return file_kw; +} + +/** + Create a new rd_file_kw instance based on header information from + the input keyword. Typically only the header has been loaded from + the keyword. + + Observe that it is the users responsability that the @offset + argument in rd_file_kw_alloc() comes from the same fortio instance + as used when calling rd_file_kw_get_kw() to actually instatiate + the rd_kw. This is automatically assured when using rd_file to + access the rd_file_kw instances. +*/ + +rd_file_kw_type *rd_file_kw_alloc(const rd_kw_type *rd_kw, offset_type offset) { + return rd_file_kw_alloc0(rd_kw_get_header(rd_kw), + rd_kw_get_data_type(rd_kw), rd_kw_get_size(rd_kw), + offset); +} + +/** + Does NOT copy the kw pointer which must be reloaded. +*/ +rd_file_kw_type *rd_file_kw_alloc_copy(const rd_file_kw_type *src) { + return rd_file_kw_alloc0(src->header, rd_file_kw_get_data_type(src), + src->kw_size, src->file_offset); +} + +void rd_file_kw_free(rd_file_kw_type *file_kw) { + if (file_kw->kw != NULL) { + rd_kw_free(file_kw->kw); + file_kw->kw = NULL; + } + free(file_kw->header); + free(file_kw); +} + +void rd_file_kw_free__(void *arg) { + rd_file_kw_type *file_kw = rd_file_kw_safe_cast(arg); + rd_file_kw_free(file_kw); +} + +bool rd_file_kw_equal(const rd_file_kw_type *kw1, const rd_file_kw_type *kw2) { + if (kw1->file_offset != kw2->file_offset) + return false; + + if (kw1->kw_size != kw2->kw_size) + return false; + + if (!rd_type_is_equal(kw1->data_type, kw2->data_type)) + return false; + + return util_string_equal(kw1->header, kw2->header); +} + +static void rd_file_kw_assert_kw(const rd_file_kw_type *file_kw) { + if (!rd_type_is_equal(rd_file_kw_get_data_type(file_kw), + rd_kw_get_data_type(file_kw->kw))) + util_abort("%s: type mismatch between header and file.\n", __func__); + + if (file_kw->kw_size != rd_kw_get_size(file_kw->kw)) + util_abort("%s: size mismatch between header and file.\n", __func__); + + if (strcmp(file_kw->header, rd_kw_get_header(file_kw->kw)) != 0) + util_abort("%s: name mismatch between header and file.\n", __func__); +} + +static void rd_file_kw_drop_kw(rd_file_kw_type *file_kw, + inv_map_type *inv_map) { + if (file_kw->kw != NULL) { + inv_map_drop_kw(inv_map, file_kw->kw); + rd_kw_free(file_kw->kw); + file_kw->kw = NULL; + } +} + +static void rd_file_kw_load_kw(rd_file_kw_type *file_kw, fortio_type *fortio, + inv_map_type *inv_map) { + if (fortio == NULL) + util_abort("%s: trying to load a keyword after the backing file has " + "been detached.\n", + __func__); + + if (file_kw->kw != NULL) + rd_file_kw_drop_kw(file_kw, inv_map); + + { + fortio_fseek(fortio, file_kw->file_offset, SEEK_SET); + file_kw->kw = rd_kw_fread_alloc(fortio); + rd_file_kw_assert_kw(file_kw); + inv_map_add_kw(inv_map, file_kw, file_kw->kw); + } +} + +/* + Calling scope will handle the NULL return value, and (optionally) + reopen the fortio stream and then call the rd_file_kw_get_kw() + function. +*/ + +rd_kw_type *rd_file_kw_get_kw_ptr(rd_file_kw_type *file_kw) { + if (file_kw->ref_count == 0) + return NULL; + + file_kw->ref_count++; + return file_kw->kw; +} + +/* + Will return the rd_kw instance of this file_kw; if it is not + currently loaded the method will instantiate the rd_kw instance + from the @fortio input handle. + + After loading the keyword it will be kept in memory, so a possible + subsequent lookup will be served from memory. + + The rd_file layer maintains a pointer mapping between the + rd_kw_type pointers and their rd_file_kw_type containers; this + mapping needs the new_load return value from the + rd_file_kw_get_kw() function. +*/ + +rd_kw_type *rd_file_kw_get_kw(rd_file_kw_type *file_kw, fortio_type *fortio, + inv_map_type *inv_map) { + if (file_kw->ref_count == 0) + rd_file_kw_load_kw(file_kw, fortio, inv_map); + + if (file_kw->kw) + file_kw->ref_count++; + + return file_kw->kw; +} + +bool rd_file_kw_ptr_eq(const rd_file_kw_type *file_kw, + const rd_kw_type *rd_kw) { + if (file_kw->kw == rd_kw) + return true; + else + return false; +} + +void rd_file_kw_replace_kw(rd_file_kw_type *file_kw, fortio_type *target, + rd_kw_type *new_kw) { + if (!rd_type_is_equal(rd_file_kw_get_data_type(file_kw), + rd_kw_get_data_type(new_kw))) + util_abort("%s: sorry type mismatch between in-file keyword and new " + "keyword \n", + __func__); + if (file_kw->kw_size != rd_kw_get_size(new_kw)) + util_abort("%s: sorry size mismatch between in-file keyword and new " + "keyword \n", + __func__); + + if (file_kw->kw != NULL) + rd_kw_free(file_kw->kw); + + file_kw->kw = new_kw; + fortio_fseek(target, file_kw->file_offset, SEEK_SET); + rd_kw_fwrite(file_kw->kw, target); +} + +const char *rd_file_kw_get_header(const rd_file_kw_type *file_kw) { + return file_kw->header; +} + +int rd_file_kw_get_size(const rd_file_kw_type *file_kw) { + return file_kw->kw_size; +} + +rd_data_type rd_file_kw_get_data_type(const rd_file_kw_type *file_kw) { + return file_kw->data_type; +} + +offset_type rd_file_kw_get_offset(const rd_file_kw_type *file_kw) { + return file_kw->file_offset; +} + +bool rd_file_kw_fskip_data(const rd_file_kw_type *file_kw, + fortio_type *fortio) { + return rd_kw_fskip_data__(rd_file_kw_get_data_type(file_kw), + file_kw->kw_size, fortio); +} + +/** + This function will replace the file content of the keyword pointed + to by @file_kw, with the new content given by @rd_kw. The new + @rd_kw keyword must have identical header to the one already + present in the file. +*/ + +void rd_file_kw_inplace_fwrite(rd_file_kw_type *file_kw, fortio_type *fortio) { + rd_file_kw_assert_kw(file_kw); + fortio_fseek(fortio, file_kw->file_offset, SEEK_SET); + rd_kw_fskip_header(fortio); + fortio_fclean(fortio); + rd_kw_fwrite_data(file_kw->kw, fortio); +} + +void rd_file_kw_fwrite(const rd_file_kw_type *file_kw, FILE *stream) { + int header_length = strlen(file_kw->header); + for (int i = 0; i < RD_STRING8_LENGTH; i++) { + if (i < header_length) + fputc(file_kw->header[i], stream); + else + fputc(' ', stream); + } + + util_fwrite_int(file_kw->kw_size, stream); + util_fwrite_offset(file_kw->file_offset, stream); + util_fwrite_int(rd_type_get_type(file_kw->data_type), stream); + util_fwrite_size_t(rd_type_get_sizeof_iotype(file_kw->data_type), stream); +} + +rd_file_kw_type **rd_file_kw_fread_alloc_multiple(FILE *stream, int num) { + + size_t file_kw_size = RD_STRING8_LENGTH + 2 * sizeof(int) + + sizeof(offset_type) + sizeof(size_t); + size_t buffer_size = num * file_kw_size; + char *buffer = (char *)util_malloc(buffer_size * sizeof *buffer); + size_t num_read = fread(buffer, 1, buffer_size, stream); + + if (num_read != buffer_size) { + free(buffer); + return NULL; + } + + { + rd_file_kw_type **kw_list = + (rd_file_kw_type **)util_malloc(num * sizeof *kw_list); + for (int ikw = 0; ikw < num; ikw++) { + int buffer_offset = ikw * file_kw_size; + char header[RD_STRING8_LENGTH + 1]; + int kw_size; + offset_type file_offset; + rd_type_enum rd_type; + size_t type_size; + { + int index = 0; + while (true) { + if (buffer[index + buffer_offset] != ' ') + header[index] = buffer[index + buffer_offset]; + else + break; + + index++; + if (index == RD_STRING8_LENGTH) + break; + } + header[index] = '\0'; + buffer_offset += RD_STRING8_LENGTH; + } + + memcpy(&kw_size, &buffer[buffer_offset], sizeof kw_size); + buffer_offset += sizeof kw_size; + + memcpy(&file_offset, &buffer[buffer_offset], sizeof file_offset); + buffer_offset += sizeof file_offset; + + memcpy(&rd_type, &buffer[buffer_offset], sizeof rd_type); + buffer_offset += sizeof rd_type; + + memcpy(&type_size, &buffer[buffer_offset], sizeof type_size); + buffer_offset += sizeof type_size; + + kw_list[ikw] = + rd_file_kw_alloc0(header, rd_type_create(rd_type, type_size), + kw_size, file_offset); + } + + free(buffer); + return kw_list; + } +} + +rd_file_kw_type *rd_file_kw_fread_alloc(FILE *stream) { + rd_file_kw_type *file_kw = NULL; + rd_file_kw_type **multiple = rd_file_kw_fread_alloc_multiple(stream, 1); + + if (multiple) { + file_kw = multiple[0]; + free(multiple); + } + + return file_kw; +} + +void rd_file_kw_start_transaction(const rd_file_kw_type *file_kw, + int *ref_count) { + *ref_count = file_kw->ref_count; +} + +void rd_file_kw_end_transaction(rd_file_kw_type *file_kw, int ref_count) { + if (ref_count == 0 && file_kw->ref_count > 0) { + rd_kw_free(file_kw->kw); + file_kw->kw = NULL; + } + file_kw->ref_count = ref_count; +} diff --git a/lib/resdata/rd_file_view.cpp b/lib/resdata/rd_file_view.cpp new file mode 100644 index 0000000000..ad18c99392 --- /dev/null +++ b/lib/resdata/rd_file_view.cpp @@ -0,0 +1,840 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +struct rd_file_view_struct { + std::vector kw_list; + std::map> kw_index; + std::vector + distinct_kw; /* A list of the keywords occuring in the file - each string occurs ONLY ONCE. */ + fortio_type * + fortio; /* The same fortio instance pointer as in the rd_file styructure. */ + bool + owner; /* Is this map the owner of the rd_file_kw instances; only true for the global_map. */ + inv_map_type + *inv_map; /* Shared reference owned by the rd_file structure. */ + std::vector child_list; + int *flags; +}; + +struct rd_file_transaction_struct { + const rd_file_view_type *file_view; + int *ref_count; +}; + +bool rd_file_view_check_flags(int state_flags, int query_flags) { + if ((state_flags & query_flags) == query_flags) + return true; + else + return false; +} + +bool rd_file_view_flags_set(const rd_file_view_type *file_view, + int query_flags) { + return rd_file_view_check_flags(*file_view->flags, query_flags); +} + +const char *rd_file_view_get_src_file(const rd_file_view_type *file_view) { + return fortio_filename_ref(file_view->fortio); +} + +rd_file_view_type *rd_file_view_alloc(fortio_type *fortio, int *flags, + inv_map_type *inv_map, bool owner) { + rd_file_view_type *rd_file_view = new rd_file_view_type(); + + rd_file_view->owner = owner; + rd_file_view->fortio = fortio; + rd_file_view->inv_map = inv_map; + rd_file_view->flags = flags; + + return rd_file_view; +} + +int rd_file_view_get_global_index(const rd_file_view_type *rd_file_view, + const char *kw, int ith) { + const auto &index_vector = rd_file_view->kw_index.at(kw); + return index_vector[ith]; +} + +/** + This function iterates over the kw_list vector and builds the + internal index fields 'kw_index' and 'distinct_kw'. This function + must be called every time the content of the kw_list vector is + modified (otherwise the rd_file instance will be in an + inconsistent state). +*/ + +void rd_file_view_make_index(rd_file_view_type *rd_file_view) { + rd_file_view->distinct_kw.clear(); + rd_file_view->kw_index.clear(); + { + int global_index = 0; + for (const auto &file_kw : rd_file_view->kw_list) { + const std::string &header = rd_file_kw_get_header(file_kw); + if (rd_file_view->kw_index.find(header) == + rd_file_view->kw_index.end()) + rd_file_view->distinct_kw.push_back(header); + + auto &index_vector = rd_file_view->kw_index[header]; + index_vector.push_back(global_index); + global_index++; + } + } +} + +bool rd_file_view_has_kw(const rd_file_view_type *rd_file_view, + const char *kw) { + return (rd_file_view->kw_index.find(kw) != rd_file_view->kw_index.end()); +} + +rd_file_kw_type * +rd_file_view_iget_file_kw(const rd_file_view_type *rd_file_view, + int global_index) { + return rd_file_view->kw_list[global_index]; +} + +rd_file_kw_type * +rd_file_view_iget_named_file_kw(const rd_file_view_type *rd_file_view, + const char *kw, int ith) { + int global_index = rd_file_view_get_global_index(rd_file_view, kw, ith); + rd_file_kw_type *file_kw = + rd_file_view_iget_file_kw(rd_file_view, global_index); + return file_kw; +} + +bool rd_file_view_drop_flag(rd_file_view_type *file_view, int flag) { + bool flag_set = rd_file_view_flags_set(file_view, flag); + if (flag_set) + *file_view->flags -= flag; + + return flag_set; +} + +void rd_file_view_add_flag(rd_file_view_type *file_view, int flag) { + *file_view->flags |= flag; +} + +static rd_kw_type *rd_file_view_get_kw(const rd_file_view_type *rd_file_view, + rd_file_kw_type *file_kw) { + rd_kw_type *rd_kw = rd_file_kw_get_kw_ptr(file_kw); + if (!rd_kw) { + if (fortio_assert_stream_open(rd_file_view->fortio)) { + + rd_kw = rd_file_kw_get_kw(file_kw, rd_file_view->fortio, + rd_file_view->inv_map); + + if (rd_file_view_flags_set(rd_file_view, RD_FILE_CLOSE_STREAM)) + fortio_fclose_stream(rd_file_view->fortio); + } + } + return rd_kw; +} + +rd_kw_type *rd_file_view_iget_kw(const rd_file_view_type *rd_file_view, + int index) { + rd_file_kw_type *file_kw = rd_file_view_iget_file_kw(rd_file_view, index); + return rd_file_view_get_kw(rd_file_view, file_kw); +} + +void rd_file_view_index_fload_kw(const rd_file_view_type *rd_file_view, + const char *kw, int index, + const int_vector_type *index_map, + char *io_buffer) { + rd_file_kw_type *file_kw = + rd_file_view_iget_named_file_kw(rd_file_view, kw, index); + + if (fortio_assert_stream_open(rd_file_view->fortio)) { + offset_type offset = rd_file_kw_get_offset(file_kw); + rd_data_type data_type = rd_file_kw_get_data_type(file_kw); + int element_count = rd_file_kw_get_size(file_kw); + + rd_kw_fread_indexed_data(rd_file_view->fortio, + offset + RD_KW_HEADER_FORTIO_SIZE, data_type, + element_count, index_map, io_buffer); + } +} + +int rd_file_view_find_kw_value(const rd_file_view_type *rd_file_view, + const char *kw, const void *value) { + int global_index = -1; + if (rd_file_view_has_kw(rd_file_view, kw)) { + const auto &index_list = rd_file_view->kw_index.at(kw); + size_t index = 0; + while (index < index_list.size()) { + const rd_kw_type *rd_kw = + rd_file_view_iget_kw(rd_file_view, index_list[index]); + if (rd_kw_data_equal(rd_kw, value)) { + global_index = index_list[index]; + break; + } + index++; + } + } + return global_index; +} + +const char *rd_file_view_iget_distinct_kw(const rd_file_view_type *rd_file_view, + int index) { + const std::string &string = rd_file_view->distinct_kw[index]; + return string.c_str(); +} + +int rd_file_view_get_num_distinct_kw(const rd_file_view_type *rd_file_view) { + return rd_file_view->distinct_kw.size(); +} + +int rd_file_view_get_size(const rd_file_view_type *rd_file_view) { + return rd_file_view->kw_list.size(); +} + +rd_data_type rd_file_view_iget_data_type(const rd_file_view_type *rd_file_view, + int index) { + rd_file_kw_type *file_kw = rd_file_view_iget_file_kw(rd_file_view, index); + return rd_file_kw_get_data_type(file_kw); +} + +int rd_file_view_iget_size(const rd_file_view_type *rd_file_view, int index) { + rd_file_kw_type *file_kw = rd_file_view_iget_file_kw(rd_file_view, index); + return rd_file_kw_get_size(file_kw); +} + +const char *rd_file_view_iget_header(const rd_file_view_type *rd_file_view, + int index) { + rd_file_kw_type *file_kw = rd_file_view_iget_file_kw(rd_file_view, index); + return rd_file_kw_get_header(file_kw); +} + +rd_kw_type *rd_file_view_iget_named_kw(const rd_file_view_type *rd_file_view, + const char *kw, int ith) { + rd_file_kw_type *file_kw = + rd_file_view_iget_named_file_kw(rd_file_view, kw, ith); + return rd_file_view_get_kw(rd_file_view, file_kw); +} + +rd_data_type +rd_file_view_iget_named_data_type(const rd_file_view_type *rd_file_view, + const char *kw, int ith) { + rd_file_kw_type *file_kw = + rd_file_view_iget_named_file_kw(rd_file_view, kw, ith); + return rd_file_kw_get_data_type(file_kw); +} + +int rd_file_view_iget_named_size(const rd_file_view_type *rd_file_view, + const char *kw, int ith) { + rd_file_kw_type *file_kw = + rd_file_view_iget_named_file_kw(rd_file_view, kw, ith); + return rd_file_kw_get_size(file_kw); +} + +void rd_file_view_replace_kw(rd_file_view_type *rd_file_view, + rd_kw_type *old_kw, rd_kw_type *new_kw, + bool insert_copy) { + size_t index = 0; + while (index < rd_file_view->kw_list.size()) { + auto *ikw = rd_file_view->kw_list[index]; + if (rd_file_kw_ptr_eq(ikw, old_kw)) { + /* + Found it; observe that the vector_iset() function will + automatically invoke the destructor on the old_kw. + */ + rd_kw_type *insert_kw = new_kw; + + if (insert_copy) + insert_kw = rd_kw_alloc_copy(new_kw); + rd_file_kw_replace_kw(ikw, rd_file_view->fortio, insert_kw); + + rd_file_view_make_index(rd_file_view); + return; + } + index++; + } + util_abort("%s: could not find rd_kw ptr: %p \n", __func__, old_kw); +} + +bool rd_file_view_load_all(rd_file_view_type *rd_file_view) { + bool loadOK = false; + + if (fortio_assert_stream_open(rd_file_view->fortio)) { + for (rd_file_kw_type *file_kw : rd_file_view->kw_list) + rd_file_kw_get_kw(file_kw, rd_file_view->fortio, + rd_file_view->inv_map); + loadOK = true; + } + + if (rd_file_view_flags_set(rd_file_view, RD_FILE_CLOSE_STREAM)) + fortio_fclose_stream(rd_file_view->fortio); + + return loadOK; +} + +void rd_file_view_add_kw(rd_file_view_type *rd_file_view, + rd_file_kw_type *file_kw) { + rd_file_view->kw_list.push_back(file_kw); +} + +void rd_file_view_free(rd_file_view_type *rd_file_view) { + + for (auto &child_ptr : rd_file_view->child_list) + rd_file_view_free(child_ptr); + + if (rd_file_view->owner) { + for (auto &kw_ptr : rd_file_view->kw_list) + rd_file_kw_free(kw_ptr); + } + + delete rd_file_view; +} + +void rd_file_view_free__(void *arg) { + rd_file_view_type *rd_file_view = (rd_file_view_type *)arg; + rd_file_view_free(rd_file_view); +} + +int rd_file_view_get_num_named_kw(const rd_file_view_type *rd_file_view, + const char *kw) { + if (rd_file_view_has_kw(rd_file_view, kw)) { + const auto &index_vector = rd_file_view->kw_index.at(kw); + return index_vector.size(); + } else + return 0; +} + +void rd_file_view_fwrite(const rd_file_view_type *rd_file_view, + fortio_type *target, int offset) { + for (size_t index = offset; index < rd_file_view->kw_list.size(); index++) { + rd_kw_type *rd_kw = rd_file_view_iget_kw(rd_file_view, index); + rd_kw_fwrite(rd_kw, target); + } +} + +int rd_file_view_iget_occurence(const rd_file_view_type *rd_file_view, + int global_index) { + const rd_file_kw_type *file_kw = rd_file_view->kw_list[global_index]; + const char *header = rd_file_kw_get_header(file_kw); + const auto &index_vector = rd_file_view->kw_index.at(header); + + int occurence = -1; + { + /* Manual reverse lookup. */ + for (size_t i = 0; i < index_vector.size(); i++) { + if (index_vector[i] == global_index) + occurence = i; + } + } + if (occurence < 0) + util_abort("%s: internal error ... \n", __func__); + + return occurence; +} + +void rd_file_view_fprintf_kw_list(const rd_file_view_type *rd_file_view, + FILE *stream) { + for (auto &file_kw : rd_file_view->kw_list) { + char *type_name = rd_type_alloc_name(rd_file_kw_get_data_type(file_kw)); + fprintf(stream, "%-8s %7d:%s\n", rd_file_kw_get_header(file_kw), + rd_file_kw_get_size(file_kw), type_name); + free(type_name); + } +} + +rd_file_view_type * +rd_file_view_alloc_blockview2(const rd_file_view_type *rd_file_view, + const char *start_kw, const char *end_kw, + int occurence) { + if ((start_kw != NULL) && + rd_file_view_get_num_named_kw(rd_file_view, start_kw) <= occurence) + return NULL; + + rd_file_view_type *block_map = + rd_file_view_alloc(rd_file_view->fortio, rd_file_view->flags, + rd_file_view->inv_map, false); + size_t kw_index = 0; + if (start_kw) + kw_index = + rd_file_view_get_global_index(rd_file_view, start_kw, occurence); + + { + rd_file_kw_type *file_kw = rd_file_view->kw_list[kw_index]; + while (true) { + rd_file_view_add_kw(block_map, file_kw); + + kw_index++; + if (kw_index == rd_file_view->kw_list.size()) + break; + else { + if (end_kw) { + file_kw = rd_file_view->kw_list[kw_index]; + if (strcmp(end_kw, rd_file_kw_get_header(file_kw)) == 0) + break; + } + } + } + } + rd_file_view_make_index(block_map); + return block_map; +} + +/** + Will return NULL if the block which is asked for is not present. +*/ +rd_file_view_type * +rd_file_view_alloc_blockview(const rd_file_view_type *rd_file_view, + const char *header, int occurence) { + return rd_file_view_alloc_blockview2(rd_file_view, header, header, + occurence); +} + +rd_file_view_type *rd_file_view_add_blockview(rd_file_view_type *file_view, + const char *header, + int occurence) { + rd_file_view_type *child = + rd_file_view_alloc_blockview2(file_view, header, header, occurence); + + if (child) + file_view->child_list.push_back(child); + + return child; +} + +rd_file_view_type *rd_file_view_add_blockview2(rd_file_view_type *rd_file_view, + const char *start_kw, + const char *end_kw, + int occurence) { + rd_file_view_type *child = rd_file_view_alloc_blockview2( + rd_file_view, start_kw, end_kw, occurence); + + if (child) + rd_file_view->child_list.push_back(child); + + return child; +} + +/* + There is no special datastructure for working with restart files, + they are 100% stock rd_file instances with the following limited + structure: + + * They are organized in blocks; where each block starts with a + SEQNUM keyword, which contains the report step. + + * Each block contains an INTEHEAD keyword, immediately after the + SEQNUM keyword, which contains the true simulation date of of the + block, and also some other data. Observe that also INIT files and + GRID files contain an INTEHEAD keyword; and that for files with + LGRs there is one INTEHEAD keyword for each LGR. This creates an + extra level of mess. + + The natural time ordering when working with the file data is just + the running index in the file; however from a user perspective the + natural way to indicate time coordinate is through the report step + or the true simulation time (i.e. 22.th of October 2009). This file + is all about converting the natural input unit time and report_step + to the internal indexing. This is achieved by consulting the value + of the INTEHEAD and SEQNUM keywords respectively. +*/ + +/* +About the time-direction +======================== + +For the following discussion we will focus on the following simplified +unified restart file. The leading number is the global index of the +keyword, the value in [] corresponds to the relevant part of the +content of the keyword on the line, the labels A,B,C,D,E are used for +references in the text below. + + 0 | SEQNUM [0] \ A + 1 | INTEHEAD [01.01.2005] | + 2 | PRESSURE [... ] | + 3 | SWAT [...] | + | -----------------------+ + 4 | SEQNUM [5] | B + 5 | INTEHEAD [01.06.2005] | + 6 | PRESSURE [... ] | + 7 | SWAT [...] | + |------------------------+ + 8 | SEQNUM [10] | C + 9 | INTEHEAD [01.12.2006] | +10 | PRESSURE [...] | +11 | SWAT [...] | + |------------------------+ +12 | SEQNUM [20] | D +13 | INTEHEAD [01.12.2007] | +14 | PRESSURE [...] | +15 | SWAT [...] | +16 | OIL_DEN [...] | + |------------------------+ +17 | SEQNUM [40] | E +18 | INTEHEAD [01.12.2009] | +19 | PRESSURE [...] | +20 | SWAT [...] / + + +This restart file has the following features: + + o It contains in total 16 keywords. + + o It contains 5 blocks of collected keywords corresponding to one + time instant, each of these blocks is called a report_step, + typcially coming from one DATES keyword in the ECLIPSE + datafile. Observe that the file does not have the block structure + visualized on this figure, the only thing separating the blocks in + the file is the occurence of a SEQNUM keyword. + + o Only a few of the report steps are present, namely 0, 5, 10, 20 and + 40. + + o The different blocks are not equally long, the fourth block has an + extra keyword OIL_DEN. + +To adress these keywords and blocks using different time coordinates +we have introduced the following concepts: + + report_step: This corresponds to the value of the SEQNUM keword, + i.e. to do queries based on the report_step we must load the + seqnum kewyord and read the value. + + rd_file_get_unrstmap_report_step( rd_file , 0 ) => A + rd_file_get_unrstmap_report_step( rd_file , 1 ) => NULL + + rd_file_has_report_step( rd_file , 5 ) => True + rd_file_has_report_step( rd_file , 2 ) => False + + sim_time: This correpsonds to the true simulation time of the report + step, the simulation time is stored as integers DAY, MONTH, YEAR + in the INTEHEAD keyword; the function INTEHEAD_date() will extract + the DAY, MONTH and YEAR values from an INTEHEAD keyword instance + and convert to a time_t instance. The functions: + + rd_file_get_unrstmap_sim_time() and rd_file_has_has_sim_time() + + can be used to query for simulation times and get the + corresponding block maps. + + index/global_index : This is typically the global running index of + the keyword in the file; this is the unique address of the keyword + which is used for the final lookup. + + occurence: The nth' time a particular keyword has occured in the + file, i.e. the SEQNUM keyword in block C is the third occurence of + SEQNUM. Instead of occurence xxxx_index is also used to indicate + the occurence of keyword xxxx. The occurence number is the integer + argument to the xxx_iget_named_kw() function, and also the final + call to create blockmaps. + +*/ + +bool rd_file_view_has_report_step(const rd_file_view_type *rd_file_view, + int report_step) { + int global_index = + rd_file_view_find_kw_value(rd_file_view, SEQNUM_KW, &report_step); + if (global_index >= 0) + return true; + else + return false; +} + +time_t rd_file_view_iget_restart_sim_date(const rd_file_view_type *rd_file_view, + int seqnum_index) { + time_t sim_time = -1; + rd_file_view_type *seqnum_map = + rd_file_view_alloc_blockview(rd_file_view, SEQNUM_KW, seqnum_index); + + if (seqnum_map != NULL) { + rd_kw_type *intehead_kw = + rd_file_view_iget_named_kw(seqnum_map, INTEHEAD_KW, 0); + sim_time = rd_rsthead_date(intehead_kw); + rd_file_view_free(seqnum_map); + } + + return sim_time; +} + +double rd_file_view_iget_restart_sim_days(const rd_file_view_type *rd_file_view, + int seqnum_index) { + double sim_days = 0; + rd_file_view_type *seqnum_map = + rd_file_view_alloc_blockview(rd_file_view, SEQNUM_KW, seqnum_index); + + if (seqnum_map != NULL) { + rd_kw_type *doubhead_kw = + rd_file_view_iget_named_kw(seqnum_map, DOUBHEAD_KW, 0); + sim_days = rd_kw_iget_double(doubhead_kw, DOUBHEAD_DAYS_INDEX); + rd_file_view_free(seqnum_map); + } + + return sim_days; +} + +int rd_file_view_find_sim_time(const rd_file_view_type *rd_file_view, + time_t sim_time) { + int seqnum_index = -1; + if (rd_file_view_has_kw(rd_file_view, INTEHEAD_KW)) { + const auto &intehead_index_list = + rd_file_view->kw_index.at(INTEHEAD_KW); + size_t index = 0; + while (index < intehead_index_list.size()) { + const rd_kw_type *intehead_kw = + rd_file_view_iget_kw(rd_file_view, intehead_index_list[index]); + if (rd_rsthead_date(intehead_kw) == sim_time) { + seqnum_index = index; + break; + } + index++; + } + } + return seqnum_index; +} + +/** + This function will scan through the rd_file looking for INTEHEAD + headers corresponding to sim_time. If sim_time is found the + function will return the INTEHEAD occurence number, i.e. for a + unified restart file like: + + INTEHEAD / 01.01.2000 + ... + PRESSURE + SWAT + ... + INTEHEAD / 01.03.2000 + ... + PRESSURE + SWAT + ... + INTEHEAD / 01.05.2000 + ... + PRESSURE + SWAT + .... + + The function call: + + rd_file_get_restart_index( restart_file , (time_t) "01.03.2000") + + will return 1. Observe that this will in general NOT agree with the + DATES step number. + + If the sim_time can not be found the function will return -1, that + includes the case when the file in question is not a restart file + at all, and no INTEHEAD headers can be found. + + Observe that the function requires on-the-second-equality; which is + of course quite strict. + + Each report step only has one occurence of SEQNUM, but one INTEHEAD + for each LGR; i.e. one should call iselect_rstblock() prior to + calling this function. +*/ + +bool rd_file_view_has_sim_time(const rd_file_view_type *rd_file_view, + time_t sim_time) { + int num_INTEHEAD = rd_file_view_get_num_named_kw(rd_file_view, INTEHEAD_KW); + if (num_INTEHEAD == 0) + return false; /* We have no INTEHEAD headers - probably not a restart file at all. */ + else { + int intehead_index = 0; + while (true) { + time_t itime = rd_file_view_iget_restart_sim_date(rd_file_view, + intehead_index); + + if (itime == sim_time) /* Perfect hit. */ + return true; + + if (itime > + sim_time) /* We have gone past the target_time - i.e. we do not have it. */ + return false; + + intehead_index++; + if (intehead_index == + num_INTEHEAD) /* We have iterated through the whole thing without finding sim_time. */ + return false; + } + } +} + +bool rd_file_view_has_sim_days(const rd_file_view_type *rd_file_view, + double sim_days) { + int num_DOUBHEAD = rd_file_view_get_num_named_kw(rd_file_view, DOUBHEAD_KW); + if (num_DOUBHEAD == 0) + return false; /* We have no DOUBHEAD headers - probably not a restart file at all. */ + else { + int doubhead_index = 0; + while (true) { + double file_sim_days = rd_file_view_iget_restart_sim_days( + rd_file_view, doubhead_index); + + if (util_double_approx_equal(sim_days, + file_sim_days)) /* Perfect hit. */ + return true; + + if (file_sim_days > + sim_days) /* We have gone past the target_time - i.e. we do not have it. */ + return false; + + doubhead_index++; + if (doubhead_index == + num_DOUBHEAD) /* We have iterated through the whole thing without finding sim_time. */ + return false; + } + } +} + +int rd_file_view_seqnum_index_from_sim_time(rd_file_view_type *parent_map, + time_t sim_time) { + int num_seqnum = rd_file_view_get_num_named_kw(parent_map, SEQNUM_KW); + rd_file_view_type *seqnum_map; + + for (int s_idx = 0; s_idx < num_seqnum; s_idx++) { + seqnum_map = rd_file_view_alloc_blockview(parent_map, SEQNUM_KW, s_idx); + + if (!seqnum_map) + continue; + + bool sim = rd_file_view_has_sim_time(seqnum_map, sim_time); + rd_file_view_free(seqnum_map); + if (sim) + return s_idx; + } + return -1; +} + +int rd_file_view_seqnum_index_from_sim_days(rd_file_view_type *file_view, + double sim_days) { + int num_seqnum = rd_file_view_get_num_named_kw(file_view, SEQNUM_KW); + int seqnum_index = 0; + rd_file_view_type *seqnum_map; + + while (true) { + seqnum_map = + rd_file_view_alloc_blockview(file_view, SEQNUM_KW, seqnum_index); + + if (seqnum_map != NULL) { + if (rd_file_view_has_sim_days(seqnum_map, sim_days)) { + rd_file_view_free(seqnum_map); + return seqnum_index; + } else { + rd_file_view_free(seqnum_map); + seqnum_index++; + } + } + + if (num_seqnum == seqnum_index) + return -1; + } +} + +/* + Will mulitplex on the four input arguments. +*/ +rd_file_view_type *rd_file_view_add_restart_view(rd_file_view_type *file_view, + int input_index, + int report_step, + time_t sim_time, + double sim_days) { + rd_file_view_type *child = NULL; + int seqnum_index = -1; + + if (input_index >= 0) + seqnum_index = input_index; + else if (report_step >= 0) { + int global_index = + rd_file_view_find_kw_value(file_view, SEQNUM_KW, &report_step); + if (global_index >= 0) + seqnum_index = rd_file_view_iget_occurence(file_view, global_index); + } else if (sim_time != -1) + seqnum_index = + rd_file_view_seqnum_index_from_sim_time(file_view, sim_time); + else if (sim_days >= 0) + seqnum_index = + rd_file_view_seqnum_index_from_sim_days(file_view, sim_days); + + if (seqnum_index >= 0) + child = rd_file_view_add_blockview(file_view, SEQNUM_KW, seqnum_index); + + return child; +} + +rd_file_view_type *rd_file_view_add_summary_view(rd_file_view_type *file_view, + int report_step) { + rd_file_view_type *child = + rd_file_view_add_blockview(file_view, SEQHDR_KW, report_step); + return child; +} + +void rd_file_view_fclose_stream(rd_file_view_type *file_view) { + fortio_fclose_stream(file_view->fortio); +} + +void rd_file_view_write_index(const rd_file_view_type *file_view, + FILE *ostream) { + int size = rd_file_view_get_size(file_view); + util_fwrite_int(size, ostream); + + rd_file_kw_type *file_kw; + for (int i = 0; i < size; i++) { + file_kw = rd_file_view_iget_file_kw(file_view, i); + rd_file_kw_fwrite(file_kw, ostream); + } +} + +rd_file_view_type *rd_file_view_fread_alloc(fortio_type *fortio, int *flags, + inv_map_type *inv_map, + FILE *istream) { + + int index_size = util_fread_int(istream); + rd_file_kw_type **file_kw_list = + rd_file_kw_fread_alloc_multiple(istream, index_size); + if (file_kw_list) { + rd_file_view_type *file_view = + rd_file_view_alloc(fortio, flags, inv_map, true); + for (int i = 0; i < index_size; i++) + rd_file_view_add_kw(file_view, file_kw_list[i]); + + free(file_kw_list); + rd_file_view_make_index(file_view); + return file_view; + } else { + fprintf(stderr, "%s: error reading rd_file_type index file.\n", + __func__); + return NULL; + } +} + +rd_file_transaction_type * +rd_file_view_start_transaction(rd_file_view_type *file_view) { + rd_file_transaction_type *t = + (rd_file_transaction_type *)util_malloc(sizeof *t); + int size = rd_file_view_get_size(file_view); + t->file_view = file_view; + t->ref_count = (int *)util_malloc(size * sizeof *t->ref_count); + for (int i = 0; i < size; i++) { + rd_file_kw_type *file_kw = rd_file_view_iget_file_kw(file_view, i); + rd_file_kw_start_transaction(file_kw, &t->ref_count[i]); + } + + return t; +} + +void rd_file_view_end_transaction(rd_file_view_type *file_view, + rd_file_transaction_type *transaction) { + if (transaction->file_view != file_view) + util_abort("%s: internal error - file_view / transaction mismatch\n", + __func__); + + const int *ref_count = transaction->ref_count; + for (int i = 0; i < rd_file_view_get_size(file_view); i++) { + rd_file_kw_type *file_kw = rd_file_view_iget_file_kw(file_view, i); + rd_file_kw_end_transaction(file_kw, ref_count[i]); + } + free(transaction->ref_count); + free(transaction); +} diff --git a/lib/resdata/rd_grav.cpp b/lib/resdata/rd_grav.cpp new file mode 100644 index 0000000000..c7ad324bd3 --- /dev/null +++ b/lib/resdata/rd_grav.cpp @@ -0,0 +1,690 @@ +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "detail/resdata/rd_grid_cache.hpp" + +/** + This file contains datastructures for calculating changes in + gravitational response in reservoirs. The main datastructure is the + rd_grav_type structure (which is the only structure which is + exported). +*/ + +#define GRAV_CALC_USE_PORV 128 +#define GRAV_CALC_USE_RHO \ + 256 // The GRAV_CALC_USE_RHO value is currently not used. + +typedef enum { + GRAV_CALC_RPORV = 1 + GRAV_CALC_USE_PORV + GRAV_CALC_USE_RHO, + GRAV_CALC_PORMOD = 2 + GRAV_CALC_USE_PORV + GRAV_CALC_USE_RHO, + GRAV_CALC_FIP = 3, + GRAV_CALC_RFIP = 4 + GRAV_CALC_USE_RHO +} grav_calc_type; + +typedef struct rd_grav_phase_struct rd_grav_phase_type; + +/** + The rd_grav_struct datastructure is the main structure for + calculating the gravimetric response from time lapse ECLIPSE + simulations. +*/ + +struct rd_grav_struct { + const rd_file_type * + init_file; /* The init file - a shared reference owned by calling scope. */ + rd::rd_grid_cache * + grid_cache; /* An internal specialized structure to facilitate fast grid lookup. */ + bool *aquifer_cell; /* Numerical aquifer cells should be ignored. */ + + std::unordered_map surveys; + std::unordered_map default_density; + std::unordered_map> std_density; +}; + +/** + Data structure representing one gravimetric survey. +*/ + +#define RD_GRAV_SURVEY_ID 88517 +struct rd_grav_survey_struct { + UTIL_TYPE_ID_DECLARATION; + const rd::rd_grid_cache *grid_cache; + const bool *aquifer_cell; + char *name; /* Name of the survey - arbitrary string. */ + double * + porv; /* Reference shared by the rd_grav_phase structures - i.e. it must not be updated. */ + std::vector + phase_list; /* rd_grav_phase_type objects - one for each phase present in the model. */ + std::unordered_map + phase_map; /* The same objects as in the phase_list vector - accessible by the "SWAT", "SGAS" and "SOIL" keys. */ +}; + +/** + Data structure representing the results from one phase at one survey. +*/ + +#define RD_GRAV_PHASE_TYPE_ID 1066652 +struct rd_grav_phase_struct { + UTIL_TYPE_ID_DECLARATION; + const rd::rd_grid_cache *grid_cache; + const bool *aquifer_cell; + double * + fluid_mass; /* The total fluid in place (mass) of this phase - for each active cell.*/ + double *work; /* Temporary used in the summation over all cells. */ + rd_phase_enum phase; +}; + +static const char *get_den_kw(rd_phase_enum phase, rd_version_enum rd_version) { + if (rd_version == ECLIPSE100) { + switch (phase) { + case (RD_OIL_PHASE): + return ECLIPSE100_OIL_DEN_KW; + break; + case (RD_GAS_PHASE): + return ECLIPSE100_GAS_DEN_KW; + break; + case (RD_WATER_PHASE): + return ECLIPSE100_WATER_DEN_KW; + break; + default: + util_abort("%s: unrecognized phase id:%d \n", __func__, phase); + return NULL; + } + } else if ((rd_version == ECLIPSE300) || + (rd_version == ECLIPSE300_THERMAL)) { + switch (phase) { + case (RD_OIL_PHASE): + return ECLIPSE300_OIL_DEN_KW; + break; + case (RD_GAS_PHASE): + return ECLIPSE300_GAS_DEN_KW; + break; + case (RD_WATER_PHASE): + return ECLIPSE300_WATER_DEN_KW; + break; + default: + util_abort("%s: unrecognized phase id:%d \n", __func__, phase); + return NULL; + } + } else { + util_abort("%s: unrecognized simulator id:%d \n", __func__, rd_version); + return NULL; + } +} + +static void rd_grav_phase_ensure_work(rd_grav_phase_type *grav_phase) { + if (grav_phase->work == NULL) + grav_phase->work = (double *)util_calloc(grav_phase->grid_cache->size(), + sizeof *grav_phase->work); +} + +static double rd_grav_phase_eval(rd_grav_phase_type *base_phase, + const rd_grav_phase_type *monitor_phase, + rd_region_type *region, double utm_x, + double utm_y, double depth) { + + rd_grav_phase_ensure_work(base_phase); + if ((monitor_phase == NULL) || + (base_phase->phase == monitor_phase->phase)) { + const rd::rd_grid_cache &grid_cache = *(base_phase->grid_cache); + const bool *aquifer = base_phase->aquifer_cell; + double *mass_diff = base_phase->work; + double deltag; + /* + Initialize a work array to contain the difference in mass for + every cell. + */ + { + int index; + if (monitor_phase == NULL) { + for (index = 0; index < grid_cache.size(); index++) + mass_diff[index] = -base_phase->fluid_mass[index]; + } else { + for (index = 0; index < grid_cache.size(); index++) + mass_diff[index] = monitor_phase->fluid_mass[index] - + base_phase->fluid_mass[index]; + } + } + + /** + The Gravitational constant is 6.67E-11 N (m/kg)^2, we + return the result in microGal, i.e. we scale with 10^2 * + 10^6 => 6.67E-3. + */ + deltag = 6.67428E-3 * rd_grav_common_eval_biot_savart( + grid_cache, region, aquifer, mass_diff, utm_x, + utm_y, depth); + + return deltag; + } else { + util_abort("%s comparing different phases ... \n", __func__); + return -1; + } +} + +static rd_grav_phase_type * +rd_grav_phase_alloc(rd_grav_type *rd_grav, rd_grav_survey_type *survey, + rd_phase_enum phase, const rd_file_view_type *restart_file, + grav_calc_type calc_type) { + + const rd_file_type *init_file = rd_grav->init_file; + const rd::rd_grid_cache *grid_cache = rd_grav->grid_cache; + const char *sat_kw_name = rd_get_phase_name(phase); + { + rd_grav_phase_type *grav_phase = new rd_grav_phase_type(); + const int size = grid_cache->size(); + + UTIL_TYPE_ID_INIT(grav_phase, RD_GRAV_PHASE_TYPE_ID); + grav_phase->grid_cache = grid_cache; + grav_phase->aquifer_cell = rd_grav->aquifer_cell; + grav_phase->fluid_mass = + (double *)util_calloc(size, sizeof *grav_phase->fluid_mass); + grav_phase->phase = phase; + grav_phase->work = NULL; + + if (calc_type == GRAV_CALC_FIP) { + rd_kw_type *pvtnum_kw = + rd_file_iget_named_kw(init_file, PVTNUM_KW, 0); + const std::vector std_density = + rd_grav->std_density[std::string(rd_get_phase_name(phase))]; + rd_kw_type *fip_kw; + + if (phase == RD_OIL_PHASE) + fip_kw = rd_file_view_iget_named_kw(restart_file, FIPOIL_KW, 0); + else if (phase == RD_GAS_PHASE) + fip_kw = rd_file_view_iget_named_kw(restart_file, FIPGAS_KW, 0); + else + fip_kw = rd_file_view_iget_named_kw(restart_file, FIPWAT_KW, 0); + + { + int iactive; + for (iactive = 0; iactive < size; iactive++) { + double fip = rd_kw_iget_as_double(fip_kw, iactive); + int pvtnum = rd_kw_iget_int(pvtnum_kw, iactive); + grav_phase->fluid_mass[iactive] = fip * std_density[pvtnum]; + } + } + } else { + rd_version_enum rd_version = rd_file_get_rd_version(init_file); + const char *den_kw_name = get_den_kw(phase, rd_version); + const rd_kw_type *den_kw = + rd_file_view_iget_named_kw(restart_file, den_kw_name, 0); + + if (calc_type == GRAV_CALC_RFIP) { + rd_kw_type *rfip_kw; + if (phase == RD_OIL_PHASE) + rfip_kw = + rd_file_view_iget_named_kw(restart_file, RFIPOIL_KW, 0); + else if (phase == RD_GAS_PHASE) + rfip_kw = + rd_file_view_iget_named_kw(restart_file, RFIPGAS_KW, 0); + else + rfip_kw = + rd_file_view_iget_named_kw(restart_file, RFIPWAT_KW, 0); + + { + int iactive; + for (iactive = 0; iactive < size; iactive++) { + double rho = rd_kw_iget_as_double(den_kw, iactive); + double rfip = rd_kw_iget_as_double(rfip_kw, iactive); + grav_phase->fluid_mass[iactive] = rho * rfip; + } + } + } else { + /* (calc_type == GRAV_CALC_RPORV) || (calc_type == GRAV_CALC_PORMOD) */ + rd_kw_type *sat_kw; + bool private_sat_kw = false; + if (rd_file_view_has_kw(restart_file, sat_kw_name)) + sat_kw = rd_file_view_iget_named_kw(restart_file, + sat_kw_name, 0); + else { + /* We are targeting the residual phase, e.g. the OIL phase in a three phase system. */ + const rd_kw_type *swat_kw = + rd_file_view_iget_named_kw(restart_file, "SWAT", 0); + sat_kw = rd_kw_alloc_copy(swat_kw); + rd_kw_scalar_set_float(sat_kw, 1.0); + rd_kw_inplace_sub(sat_kw, swat_kw); /* sat = 1 - SWAT */ + + if (rd_file_view_has_kw(restart_file, "SGAS")) { + const rd_kw_type *sgas_kw = + rd_file_view_iget_named_kw(restart_file, "SGAS", 0); + rd_kw_inplace_sub(sat_kw, sgas_kw); /* sat -= SGAS */ + } + private_sat_kw = true; + } + + { + int iactive; + for (iactive = 0; iactive < size; iactive++) { + double rho = rd_kw_iget_as_double(den_kw, iactive); + double sat = rd_kw_iget_as_double(sat_kw, iactive); + grav_phase->fluid_mass[iactive] = + rho * sat * survey->porv[iactive]; + } + } + + if (private_sat_kw) + rd_kw_free(sat_kw); + } + } + + return grav_phase; + } +} + +static void rd_grav_phase_free(rd_grav_phase_type *grav_phase) { + free(grav_phase->work); + free(grav_phase->fluid_mass); + delete grav_phase; +} + +static void rd_grav_survey_add_phase(rd_grav_survey_type *survey, + rd_phase_enum phase, + rd_grav_phase_type *grav_phase) { + survey->phase_list.push_back(grav_phase); + survey->phase_map[std::string(rd_get_phase_name(phase))] = grav_phase; +} + +static void rd_grav_survey_add_phases(rd_grav_type *rd_grav, + rd_grav_survey_type *survey, + const rd_file_view_type *restart_file, + grav_calc_type calc_type) { + int phases = rd_file_get_phases(rd_grav->init_file); + if (phases & RD_OIL_PHASE) { + rd_grav_phase_type *oil_phase = rd_grav_phase_alloc( + rd_grav, survey, RD_OIL_PHASE, restart_file, calc_type); + rd_grav_survey_add_phase(survey, RD_OIL_PHASE, oil_phase); + } + + if (phases & RD_GAS_PHASE) { + rd_grav_phase_type *gas_phase = rd_grav_phase_alloc( + rd_grav, survey, RD_GAS_PHASE, restart_file, calc_type); + rd_grav_survey_add_phase(survey, RD_GAS_PHASE, gas_phase); + } + + if (phases & RD_WATER_PHASE) { + rd_grav_phase_type *water_phase = rd_grav_phase_alloc( + rd_grav, survey, RD_WATER_PHASE, restart_file, calc_type); + rd_grav_survey_add_phase(survey, RD_WATER_PHASE, water_phase); + } +} + +static rd_grav_survey_type * +rd_grav_survey_alloc_empty(const rd_grav_type *rd_grav, const char *name, + grav_calc_type calc_type) { + rd_grav_survey_type *survey = new rd_grav_survey_type(); + UTIL_TYPE_ID_INIT(survey, RD_GRAV_SURVEY_ID); + survey->grid_cache = rd_grav->grid_cache; + survey->aquifer_cell = rd_grav->aquifer_cell; + survey->name = util_alloc_string_copy(name); + + if (calc_type & GRAV_CALC_USE_PORV) + survey->porv = (double *)util_calloc(rd_grav->grid_cache->size(), + sizeof *survey->porv); + else + survey->porv = NULL; + + return survey; +} + +/** + Check that the rporv values are in the right ballpark. For ECLIPSE + version 2008.2 they are way off. Check PORV versus RPORV + for some random locations in the grid. +*/ + +static void rd_grav_survey_assert_RPORV(const rd_grav_survey_type *survey, + const rd_file_type *init_file) { + const rd::rd_grid_cache &grid_cache = *(survey->grid_cache); + int active_size = grid_cache.size(); + const rd_kw_type *init_porv_kw = + rd_file_iget_named_kw(init_file, PORV_KW, 0); + int check_points = 100; + int check_nr = 0; + const std::vector &global_index = grid_cache.global_index(); + + while (check_nr < check_points) { + int active_index = rand() % active_size; + + double init_porv = rd_kw_iget_as_double( + init_porv_kw, + global_index[active_index]); /* NB - this uses global indexing. */ + if (init_porv > 0) { + double rporv = survey->porv[active_index]; + double log_pormod = log10(rporv / init_porv); + + if (fabs(log_pormod) > 1) { + /* Detected as error if the effective pore volume multiplier + is greater than 10 or less than 0.10. */ + fprintf(stderr, "----------------------------------------------" + "-------------------\n"); + fprintf(stderr, "INIT PORV : %g \n", init_porv); + fprintf(stderr, "RPORV : %g \n", rporv); + fprintf(stderr, "Hmmm - the RPORV values extracted from the " + "restart file seem to be \n"); + fprintf(stderr, "veeery different from the initial porv value. " + "This might indicate \n"); + fprintf(stderr, "an ECLIPSE bug in the RPORV handling. Try " + "using another ECLIPSE version,\n"); + fprintf(stderr, + "or alternatively the PORMOD approach instead\n"); + fprintf(stderr, "----------------------------------------------" + "-------------------\n"); + exit(1); + } + check_nr++; + } + } +} + +/** + There are currently two main methods to add a survey; differentiated by + how the mass of various phases in each cell is calculated: + + 1. We can calculate the mass of each phase from the relation: + + mass = saturation * pore_volume * mass_density. + + This method requires access to the instantaneous pore volume. This + can be accessed in two different ways, based either on the RPORV + keyword or the PORV_MOD keyword. This functionality is available + through the rd_grav_survey_alloc_RPORV() and + rd_grav_survey_alloc_PORMOD() functions. + + + 2. The mass of each phase can be calculated based on the fluid in place + values (volume of phase when the matter is brought to standard + conditions), i.e. the FIPGAS, FIPWAT and FIPOIL keywords, and the + corresponding densities at surface conditions. This functionality is + implemented with the rd_grav_survey_alloc_FIP() function. + + Observe that use of the FIP based method requires densities entered + with rd_grav_new_std_density()/rd_grav_add_std_density() prior to + adding the actual survey. +*/ + +/** + Allocate one survey based on using the RPORV keyword from the + restart file to calculate the instantaneous pore volume in each + cell. + + Unfortunately different versions of ECLIPSE have showed a wide + range of bugs related to the RPORV keyword, including: + + - Using the pressure values instead of pore volumes - this will be + cached by the rd_grav_survey_assert_RPORV() function. + + - Ignoring the dynamic pore volume changes, and just using + RPORV == INIT PORV. +*/ + +static rd_grav_survey_type * +rd_grav_survey_alloc_RPORV(rd_grav_type *rd_grav, + const rd_file_view_type *restart_file, + const char *name) { + rd_grav_survey_type *survey = + rd_grav_survey_alloc_empty(rd_grav, name, GRAV_CALC_RPORV); + if (rd_file_view_has_kw(restart_file, RPORV_KW)) { + rd_kw_type *rporv_kw = + rd_file_view_iget_named_kw(restart_file, RPORV_KW, 0); + int iactive; + for (iactive = 0; iactive < rd_kw_get_size(rporv_kw); iactive++) + survey->porv[iactive] = rd_kw_iget_as_double(rporv_kw, iactive); + } else + util_abort("%s: restart file did not contain %s keyword??\n", __func__, + RPORV_KW); + + { + const rd_file_type *init_file = rd_grav->init_file; + rd_grav_survey_assert_RPORV(survey, init_file); + rd_grav_survey_add_phases(rd_grav, survey, restart_file, + GRAV_CALC_RPORV); + } + return survey; +} + +static rd_grav_survey_type * +rd_grav_survey_alloc_PORMOD(rd_grav_type *rd_grav, + const rd_file_view_type *restart_file, + const char *name) { + rd::rd_grid_cache &grid_cache = *(rd_grav->grid_cache); + rd_grav_survey_type *survey = + rd_grav_survey_alloc_empty(rd_grav, name, GRAV_CALC_PORMOD); + rd_kw_type *init_porv_kw = rd_file_iget_named_kw( + rd_grav->init_file, PORV_KW, 0); /* Global indexing */ + rd_kw_type *pormod_kw = rd_file_view_iget_named_kw(restart_file, PORMOD_KW, + 0); /* Active indexing */ + const int size = grid_cache.size(); + const auto &global_index = grid_cache.global_index(); + int active_index; + + for (active_index = 0; active_index < size; active_index++) + survey->porv[active_index] = + rd_kw_iget_float(pormod_kw, active_index) * + rd_kw_iget_float(init_porv_kw, global_index[active_index]); + + rd_grav_survey_add_phases(rd_grav, survey, restart_file, GRAV_CALC_PORMOD); + + return survey; +} + +/** + Use of the rd_grav_survey_alloc_FIP() function requires that the densities + have been added for all phases with the rd_grav_new_std_density() and + possibly also the rd_grav_add_std_density() functions. +*/ + +static rd_grav_survey_type * +rd_grav_survey_alloc_FIP(rd_grav_type *rd_grav, + const rd_file_view_type *restart_file, + const char *name) { + + rd_grav_survey_type *survey = + rd_grav_survey_alloc_empty(rd_grav, name, GRAV_CALC_FIP); + rd_grav_survey_add_phases(rd_grav, survey, restart_file, GRAV_CALC_FIP); + + return survey; +} + +static rd_grav_survey_type * +rd_grav_survey_alloc_RFIP(rd_grav_type *rd_grav, + const rd_file_view_type *restart_file, + const char *name) { + + rd_grav_survey_type *survey = + rd_grav_survey_alloc_empty(rd_grav, name, GRAV_CALC_RFIP); + rd_grav_survey_add_phases(rd_grav, survey, restart_file, GRAV_CALC_RFIP); + + return survey; +} + +static void rd_grav_survey_free(rd_grav_survey_type *grav_survey) { + free(grav_survey->name); + free(grav_survey->porv); + for (auto *phase : grav_survey->phase_list) + rd_grav_phase_free(phase); + + delete grav_survey; +} + +static double rd_grav_survey_eval(const rd_grav_survey_type *base_survey, + const rd_grav_survey_type *monitor_survey, + rd_region_type *region, double utm_x, + double utm_y, double depth, int phase_mask) { + double deltag = 0; + for (std::size_t phase_nr = 0; phase_nr < base_survey->phase_list.size(); + phase_nr++) { + rd_grav_phase_type *base_phase = base_survey->phase_list[phase_nr]; + if (base_phase->phase & phase_mask) { + if (monitor_survey != NULL) { + const rd_grav_phase_type *monitor_phase = + monitor_survey->phase_list[phase_nr]; + deltag += rd_grav_phase_eval(base_phase, monitor_phase, region, + utm_x, utm_y, depth); + } else + deltag += rd_grav_phase_eval(base_phase, NULL, region, utm_x, + utm_y, depth); + } + } + return deltag; +} + +/** + The grid instance is only used during the construction phase. The + @init_file object is used by the rd_grav_add_survey_XXX() + functions; and calling scope must NOT destroy this object before + all surveys have been added. +*/ + +rd_grav_type *rd_grav_alloc(const rd_grid_type *rd_grid, + const rd_file_type *init_file) { + rd_grav_type *rd_grav = new rd_grav_type(); + + rd_grav->init_file = init_file; + rd_grav->grid_cache = new rd::rd_grid_cache(rd_grid); + rd_grav->aquifer_cell = rd_grav_common_alloc_aquifer_cell( + *(rd_grav->grid_cache), rd_grav->init_file); + + return rd_grav; +} + +static void rd_grav_add_survey__(rd_grav_type *grav, const char *name, + rd_grav_survey_type *survey) { + grav->surveys[name] = survey; +} + +rd_grav_survey_type * +rd_grav_add_survey_RPORV(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file) { + rd_grav_survey_type *survey = + rd_grav_survey_alloc_RPORV(grav, restart_file, name); + rd_grav_add_survey__(grav, name, survey); + return survey; +} + +rd_grav_survey_type * +rd_grav_add_survey_FIP(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file) { + rd_grav_survey_type *survey = + rd_grav_survey_alloc_FIP(grav, restart_file, name); + rd_grav_add_survey__(grav, name, survey); + return survey; +} + +rd_grav_survey_type * +rd_grav_add_survey_RFIP(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file) { + rd_grav_survey_type *survey = + rd_grav_survey_alloc_RFIP(grav, restart_file, name); + rd_grav_add_survey__(grav, name, survey); + return survey; +} + +rd_grav_survey_type * +rd_grav_add_survey_PORMOD(rd_grav_type *grav, const char *name, + const rd_file_view_type *restart_file) { + rd_grav_survey_type *survey = + rd_grav_survey_alloc_PORMOD(grav, restart_file, name); + rd_grav_add_survey__(grav, name, survey); + return survey; +} + +static rd_grav_survey_type *rd_grav_get_survey(const rd_grav_type *grav, + const char *name) { + if (name == NULL) + return NULL; // Calling scope must determine if this is OK? + else { + if (grav->surveys.count(name) > 0) + return grav->surveys.at(name); + else { + fprintf(stderr, + "Survey name:%s not registered. Available surveys are: " + "\n\n ", + name); + + for (const auto &survey_pair : grav->surveys) + fprintf(stderr, "%s ", survey_pair.first.c_str()); + + fprintf(stderr, "\n\n"); + exit(1); + } + } +} + +double rd_grav_eval(const rd_grav_type *grav, const char *base, + const char *monitor, rd_region_type *region, double utm_x, + double utm_y, double depth, int phase_mask) { + rd_grav_survey_type *base_survey = rd_grav_get_survey(grav, base); + rd_grav_survey_type *monitor_survey = rd_grav_get_survey(grav, monitor); + + return rd_grav_survey_eval(base_survey, monitor_survey, region, utm_x, + utm_y, depth, phase_mask); +} + +/* The functions rd_grav_new_std_density() and rd_grav_add_std_density() are + used to "install" standard conditions densities for the various phases + involved. These functions must be called prior to calling + rd_grav_add_survey_FIP() - failure to do so will lead to hard failure. +*/ + +/** + The function rd_grav_new_std_density() is used to add a default density for + a new phase. +*/ + +void rd_grav_new_std_density(rd_grav_type *grav, rd_phase_enum phase, + double default_density) { + const char *phase_key = rd_get_phase_name(phase); + grav->default_density[std::string(phase_key)] = default_density; +} + +/** + In cases with many PVT regions it is possible to install per PVT + region densities. The rd_grav_new_std_density() must be called + first to install a default density for the phase, and then this + function can be called afterwards to install density for a + particular PVT region. In the example below we set the default gas + density to 0.75, but in PVT regions 2 and 7 the density is + different: + + rd_grav_new_std_density( grav , RD_GAS_PHASE , 0.75 ); + rd_grav_add_std_density( grav , RD_GAS_PHASE , 2 , 0.70 ); + rd_grav_add_std_density( grav , RD_GAS_PHASE , 7 , 0.80 ); +*/ + +void rd_grav_add_std_density(rd_grav_type *grav, rd_phase_enum phase, + int pvtnum, double density) { + std::vector &std_density = + grav->std_density[std::string(rd_get_phase_name(phase))]; + if (std_density.size() <= static_cast(pvtnum)) + std_density.resize( + pvtnum + 1, + grav->default_density[std::string(rd_get_phase_name(phase))]); + std_density[pvtnum] = density; +} + +void rd_grav_free(rd_grav_type *rd_grav) { + delete rd_grav->grid_cache; + free(rd_grav->aquifer_cell); + + for (const auto &survey_pair : rd_grav->surveys) + rd_grav_survey_free(survey_pair.second); + + delete rd_grav; +} diff --git a/lib/ecl/ecl_grav_common.cpp b/lib/resdata/rd_grav_common.cpp similarity index 66% rename from lib/ecl/ecl_grav_common.cpp rename to lib/resdata/rd_grav_common.cpp index a7ab347602..46de8d7ff8 100644 --- a/lib/ecl/ecl_grav_common.cpp +++ b/lib/resdata/rd_grav_common.cpp @@ -4,31 +4,31 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include "detail/ecl/ecl_grid_cache.hpp" +#include "detail/resdata/rd_grid_cache.hpp" /* - This file contains code which is common to both the ecl_grav - implementation for gravity changes, and the ecl_subsidence + This file contains code which is common to both the rd_grav + implementation for gravity changes, and the rd_subsidence implementation for changes in subsidence. */ -bool *ecl_grav_common_alloc_aquifer_cell(const ecl::ecl_grid_cache &grid_cache, - const ecl_file_type *init_file) { +bool *rd_grav_common_alloc_aquifer_cell(const rd::rd_grid_cache &grid_cache, + const rd_file_type *init_file) { bool *aquifer_cell = (bool *)util_calloc(grid_cache.size(), sizeof *aquifer_cell); for (int active_index = 0; active_index < grid_cache.size(); active_index++) aquifer_cell[active_index] = false; - if (ecl_file_has_kw(init_file, AQUIFER_KW)) { - ecl_kw_type *aquifer_kw = - ecl_file_iget_named_kw(init_file, AQUIFER_KW, 0); - const int *aquifer_data = ecl_kw_get_int_ptr(aquifer_kw); + if (rd_file_has_kw(init_file, AQUIFER_KW)) { + rd_kw_type *aquifer_kw = + rd_file_iget_named_kw(init_file, AQUIFER_KW, 0); + const int *aquifer_data = rd_kw_get_int_ptr(aquifer_kw); for (int active_index = 0; active_index < grid_cache.size(); active_index++) { @@ -40,11 +40,11 @@ bool *ecl_grav_common_alloc_aquifer_cell(const ecl::ecl_grid_cache &grid_cache, return aquifer_cell; } -double ecl_grav_common_eval_biot_savart(const ecl::ecl_grid_cache &grid_cache, - ecl_region_type *region, - const bool *aquifer, - const double *weight, double utm_x, - double utm_y, double depth) { +double rd_grav_common_eval_biot_savart(const rd::rd_grid_cache &grid_cache, + rd_region_type *region, + const bool *aquifer, + const double *weight, double utm_x, + double utm_y, double depth) { const auto &xpos = grid_cache.xpos(); const auto &ypos = grid_cache.ypos(); const auto &zpos = grid_cache.zpos(); @@ -68,8 +68,7 @@ double ecl_grav_common_eval_biot_savart(const ecl::ecl_grid_cache &grid_cache, } } } else { - const int_vector_type *index_vector = - ecl_region_get_active_list(region); + const int_vector_type *index_vector = rd_region_get_active_list(region); const int size = int_vector_size(index_vector); const int *index_list = int_vector_get_const_ptr(index_vector); int i, index; @@ -90,10 +89,10 @@ double ecl_grav_common_eval_biot_savart(const ecl::ecl_grid_cache &grid_cache, } static inline double -ecl_grav_common_eval_geertsma_kernel(int index, const double *xpos, - const double *ypos, const double *zpos, - double utm_x, double utm_y, double depth, - double poisson_ratio, double seabed) { +rd_grav_common_eval_geertsma_kernel(int index, const double *xpos, + const double *ypos, const double *zpos, + double utm_x, double utm_y, double depth, + double poisson_ratio, double seabed) { double z = zpos[index]; z -= seabed; double dist_x = xpos[index] - utm_x; @@ -116,11 +115,11 @@ ecl_grav_common_eval_geertsma_kernel(int index, const double *xpos, return displacement; } -double ecl_grav_common_eval_geertsma(const ecl::ecl_grid_cache &grid_cache, - ecl_region_type *region, - const bool *aquifer, const double *weight, - double utm_x, double utm_y, double depth, - double poisson_ratio, double seabed) { +double rd_grav_common_eval_geertsma(const rd::rd_grid_cache &grid_cache, + rd_region_type *region, const bool *aquifer, + const double *weight, double utm_x, + double utm_y, double depth, + double poisson_ratio, double seabed) { const auto &xpos = grid_cache.xpos(); const auto &ypos = grid_cache.ypos(); const auto &zpos = grid_cache.zpos(); @@ -131,7 +130,7 @@ double ecl_grav_common_eval_geertsma(const ecl::ecl_grid_cache &grid_cache, for (index = 0; index < size; index++) { if (!aquifer[index]) { - double displacement = ecl_grav_common_eval_geertsma_kernel( + double displacement = rd_grav_common_eval_geertsma_kernel( index, xpos.data(), ypos.data(), zpos.data(), utm_x, utm_y, depth, poisson_ratio, seabed); @@ -143,15 +142,14 @@ double ecl_grav_common_eval_geertsma(const ecl::ecl_grid_cache &grid_cache, } } } else { - const int_vector_type *index_vector = - ecl_region_get_active_list(region); + const int_vector_type *index_vector = rd_region_get_active_list(region); const int size = int_vector_size(index_vector); const int *index_list = int_vector_get_const_ptr(index_vector); int i, index; for (i = 0; i < size; i++) { index = index_list[i]; if (!aquifer[index]) { - double displacement = ecl_grav_common_eval_geertsma_kernel( + double displacement = rd_grav_common_eval_geertsma_kernel( index, xpos.data(), ypos.data(), zpos.data(), utm_x, utm_y, depth, poisson_ratio, seabed); sum += weight[index] * displacement; diff --git a/lib/ecl/ecl_grid.cpp b/lib/resdata/rd_grid.cpp similarity index 57% rename from lib/ecl/ecl_grid.cpp rename to lib/resdata/rd_grid.cpp index f069fac50e..1c81aa09b1 100644 --- a/lib/ecl/ecl_grid.cpp +++ b/lib/resdata/rd_grid.cpp @@ -18,16 +18,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /** this function implements functionality to load eclispe grid files, @@ -51,9 +51,9 @@ ways. the expected arguments are indicated as the last part of the function name: - ecl_grid_get_pos3() - 3: this function expects i,j,k - ecl_grid_get_pos1() - 1: this function expects a global index - ecl_grid_get_pos1a() - 1a: this function expects an active index. + rd_grid_get_pos3() - 3: this function expects i,j,k + rd_grid_get_pos1() - 1: this function expects a global index + rd_grid_get_pos1a() - 1a: this function expects an active index. */ @@ -183,11 +183,11 @@ the lgr implementation in is based on the following main principles: - 1. when loading a egrid/grid file one ecl_grid_type instance will + 1. when loading a egrid/grid file one rd_grid_type instance will be allocated; this grid will contain the main grid, and all the lgr grids. - 2. only one datatype (ecl_grid_type) is used both for the main grid + 2. only one datatype (rd_grid_type) is used both for the main grid and the lgr grids. 3. the main grid will own (memory wise) all the lgr grids, this @@ -201,34 +201,34 @@ -------- { - ecl_file_type * restart_data = ecl_file_fread_alloc(restart_filename , true); // load some restart info to inspect - ecl_grid_type * grid = ecl_grid_alloc(grid_filename , true); // bootstrap ecl_grid instance - stringlist_type * lgr_names = ecl_grid_alloc_name_list( grid ); // get a list of all the lgr names. + rd_file_type * restart_data = rd_file_fread_alloc(restart_filename , true); // load some restart info to inspect + rd_grid_type * grid = rd_grid_alloc(grid_filename , true); // bootstrap rd_grid instance + stringlist_type * lgr_names = rd_grid_alloc_name_list( grid ); // get a list of all the lgr names. printf("grid:%s has %d a total of %d lgr's \n", grid_filename , stringlist_get_size( lgr_names )); for (int lgr_nr = 0; lgr_nr < stringlist_get_size( lgr_names); lgr_nr++) { - ecl_grid_type * lgr_grid = ecl_grid_get_lgr( grid , stringlist_iget( lgr_names , lgr_nr )); // get the ecl_grid instance of the lgr - by name. - ecl_kw_type * pressure_kw; + rd_grid_type * lgr_grid = rd_grid_get_lgr( grid , stringlist_iget( lgr_names , lgr_nr )); // get the rd_grid instance of the lgr - by name. + rd_kw_type * pressure_kw; int nx,ny,nz,active_size; - ecl_grid_get_dims( lgr_grid , &nx , &ny , &nz , &active_size); // get some size info from this lgr. + rd_grid_get_dims( lgr_grid , &nx , &ny , &nz , &active_size); // get some size info from this lgr. printf("lgr:%s has %d x %d x %d elements \n",stringlist_iget(lgr_names , lgr_nr ) , nx , ny , nz); // ok - now we want to extract the solution vector (pressure) corresponding to this lgr: - pressure_kw = ecl_file_iget_named_kw( ecl_file , "pressure" , ecl_grid_get_grid_nr( lgr_grid )); + pressure_kw = rd_file_iget_named_kw( rd_file , "pressure" , rd_grid_get_grid_nr( lgr_grid )); /|\ | | we query the lgr_grid instance to find which occurence of the solution data we should look - up in the ecl_file instance with restart data. puuhh!! + up in the rd_file instance with restart data. puuhh!! { - int center_index = ecl_grid_get_global_index3( lgr_grid , nx/2 , ny/2 , nz/2 ); // ask the lgr_grid to get the index at the center of the lgr grid. - printf("the pressure in the middle of %s is %g \n", stinglist_iget( lgr_names , lgr_nr ) , ecl_kw_iget_as_double( pressure_kw , center_index )); + int center_index = rd_grid_get_global_index3( lgr_grid , nx/2 , ny/2 , nz/2 ); // ask the lgr_grid to get the index at the center of the lgr grid. + printf("the pressure in the middle of %s is %g \n", stinglist_iget( lgr_names , lgr_nr ) , rd_kw_iget_as_double( pressure_kw , center_index )); } } - ecl_file_free( restart_data ); - ecl_grid_free( grid ); + rd_file_free( restart_data ); + rd_grid_free( grid ); stringlist_free( lgr_names ); } @@ -246,9 +246,9 @@ the coarse group that the current cell is part of, or the value COARSE_NONE for cells which are not part of a coarsening group. - 2. The details of a coarse cell is implemented in ecl_coarse_cell.c. + 2. The details of a coarse cell is implemented in rd_coarse_cell.c. - 3. The ecl_grid structure contains a list of ecl_coarse_cell + 3. The rd_grid structure contains a list of rd_coarse_cell instances in the coarse_cells vector. 4. The introduction of coarse groups makes the concept of active @@ -266,12 +266,12 @@ The api for coarse related tasks is briefly: - - int ecl_grid_get_num_coarse_groups( const ecl_grid_type * main_grid ) - - bool ecl_grid_have_coarse_cells( const ecl_grid_type * main_grid ) - - ecl_coarse_cell_type * ecl_grid_iget_coarse_group( const ecl_grid_type * ecl_grid , int coarse_nr ); - - ecl_coarse_cell_type * ecl_grid_get_cell_coarse_group1( const ecl_grid_type * ecl_grid , int global_index); + - int rd_grid_get_num_coarse_groups( const rd_grid_type * main_grid ) + - bool rd_grid_have_coarse_cells( const rd_grid_type * main_grid ) + - rd_coarse_cell_type * rd_grid_iget_coarse_group( const rd_grid_type * rd_grid , int coarse_nr ); + - rd_coarse_cell_type * rd_grid_get_cell_coarse_group1( const rd_grid_type * rd_grid , int global_index); - In addition to the API presented by the ecl_coarse_cell.c implementation. + In addition to the API presented by the rd_coarse_cell.c implementation. */ /* @@ -321,16 +321,16 @@ { char fracture_kw[9]; char matrix_kw[9]; - int matrix_size = ecl_grid_get_nactive( ecl_grid ); - int fracture_size = ecl_grid_get_nactive_fracture( ecl_grid ); + int matrix_size = rd_grid_get_nactive( rd_grid ); + int fracture_size = rd_grid_get_nactive_fracture( rd_grid ); - swat = ecl_file_iget_name_kw( rst_file , "SWAT" , 0); + swat = rd_file_iget_name_kw( rst_file , "SWAT" , 0); - snsprintf(fracture_kw , 9 , "F-%6s" , ecl_kw_get_header( swat )); - snsprintf(matrix_kw , 9 , "M-%6s" , ecl_kw_get_header( swat )); + snsprintf(fracture_kw , 9 , "F-%6s" , rd_kw_get_header( swat )); + snsprintf(matrix_kw , 9 , "M-%6s" , rd_kw_get_header( swat )); - ecl_kw_type * M = ecl_kw_alloc_sub_copy( swat , matrix_kw , 0 , matrix_size ); - ecl_kw_type * F = ecl_kw_alloc_sub_copy( swat , fracture_kw , matrix_size , fracture_size ); + rd_kw_type * M = rd_kw_alloc_sub_copy( swat , matrix_kw , 0 , matrix_size ); + rd_kw_type * F = rd_kw_alloc_sub_copy( swat , fracture_kw , matrix_size , fracture_size ); } */ @@ -355,16 +355,16 @@ Example usage: -------------- - ecl_grid_type * grid = ecl_grid_alloc("FILE.EGRID"); + rd_grid_type * grid = rd_grid_alloc("FILE.EGRID"); // Get a int_vector instance with all the cells which have nnc info // attached. - const int_vector_type * cells_with_nnc = ecl_grid_get_nnc_index_list( grid ); + const int_vector_type * cells_with_nnc = rd_grid_get_nnc_index_list( grid ); // Iterate over all the cells with nnc info: for (int i=0; i < int_vector_size( cells_with_nnc ); i++) { int cell_index = int_vector_iget( cells_with_nnc , i); - const nnc_info_type * nnc_info = ecl_grid_get_nnc_info1( grid , cell_index); + const nnc_info_type * nnc_info = rd_grid_get_nnc_info1( grid , cell_index); // Get all the nnc connections from @cell_index to other cells in the same grid { @@ -381,7 +381,7 @@ if (lgr_nr != nnc_info_get_lgr_nr( nnc_info )) { const int_vector_type * nnc_list = nnc_vector_get_index_list( nnc_vector ); for (int j=0; j < int_vector_size( nnc_list ); j++) - printf("Cell[%d] -> %d in lgr:%d/%s \n",cell_index , int_vector_iget(nnc_list , j) , lgr_nr , ecl_grid_get_lgr_name(ecl_grid , lgr_nr)); + printf("Cell[%d] -> %d in lgr:%d/%s \n",cell_index , int_vector_iget(nnc_list , j) , lgr_nr , rd_grid_get_lgr_name(rd_grid , lgr_nr)); } } } @@ -433,7 +433,7 @@ 0---1 4---5 - table entries are ripped from eclpost code - file: kvpvos.f in + table entries are ripped from resdatapost code - file: kvpvos.f in klib/ */ @@ -441,7 +441,7 @@ About ordering of the corners in the cell ----------------------------------------- -This code reads and builds the grid structure from the ECLIPSE +This code reads and builds the grid structure from the GRID/EGRID files without really considering the question about where the cells are located in "the real world", the format is quite general and it should(?) be possible to formulate different conventions @@ -520,8 +520,8 @@ static const int tetrahedron_permutations[2][12][3] = {{// K- the implementation is based on a hierarchy of three datatypes: - 1. ecl_grid - this is the only exported datatype - 2. ecl_cell - internal + 1. rd_grid - this is the only exported datatype + 2. rd_cell - internal 3. point - internal */ @@ -651,7 +651,7 @@ static void point_copy_values(point_type *p, const point_type *src) { 4 /* Keep invalid cells out of real-world calculations with some heuristics.*/ #define CELL_FLAG_VOLUME 8 -typedef struct ecl_cell_struct ecl_cell_type; +typedef struct rd_cell_struct rd_cell_type; #define GET_CELL_FLAG(cell, flag) \ (((cell->cell_flags & (flag)) == 0) ? false : true) @@ -659,7 +659,7 @@ typedef struct ecl_cell_struct ecl_cell_type; #define METER_TO_FEET_SCALE_FACTOR 3.28084 #define METER_TO_CM_SCALE_FACTOR 100.0 -struct ecl_cell_struct { +struct rd_cell_struct { point_type center; point_type corner_list[8]; @@ -668,7 +668,7 @@ struct ecl_cell_struct { int active; int active_index [2]; /* [0]: The active matrix index; [1]: the active fracture index */ - const ecl_grid_type * + const rd_grid_type * lgr; /* if this cell is part of an lgr; this will point to a grid instance for that lgr; NULL if not part of lgr. */ int host_cell; /* the global index of the host cell for an lgr cell, set to -1 for normal cells. */ int coarse_group; /* The index of the coarse group holding this cell -1 for non-coarsened cells. */ @@ -676,16 +676,16 @@ struct ecl_cell_struct { nnc_info_type *nnc_info; /* Non-neighbour connection info*/ }; -static ert_ecl_unit_enum -ecl_grid_check_unit_system(const ecl_kw_type *gridunit_kw); -static void ecl_grid_init_mapaxes_data_float(const ecl_grid_type *grid, - float *mapaxes); -float *ecl_grid_alloc_coord_data(const ecl_grid_type *grid); -static const float *ecl_grid_get_mapaxes(const ecl_grid_type *grid); +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); -#define ECL_GRID_ID 991010 +#define RD_GRID_ID 991010 -struct ecl_grid_struct { +struct rd_grid_struct { UTIL_TYPE_ID_DECLARATION; int lgr_nr; /* EGRID files: corresponds to item 4 in gridhead - 0 for the main grid. GRID files: 0 for the main grid, then 1 -> number of LGRs in order read from file*/ @@ -707,15 +707,15 @@ struct ecl_grid_struct { int * inv_fracture_index_map; /* For fractures: this is list of total_active elements - which point back to the index_map. */ - ecl_cell_type *cells; + rd_cell_type *cells; char * parent_name; /* the name of the parent for a nested lgr - for the main grid, and also a lgr descending directly from the main grid this will be NULL. */ - std::unordered_map children; - const ecl_grid_type * + std::unordered_map children; + const rd_grid_type * parent_grid; /* the parent grid for this (lgr) - NULL for the main grid. */ - const ecl_grid_type + const rd_grid_type *global_grid; /* the global grid - NULL for the main grid. */ bool coarsening_active; @@ -726,11 +726,11 @@ struct ecl_grid_struct { lgr_nr > 0. */ vector_type * - LGR_list; /* a vector of ecl_grid instances for LGRs - the index corresponds to the order LGRs are read from file*/ + LGR_list; /* a vector of rd_grid instances for LGRs - the index corresponds to the order LGRs are read from file*/ int_vector_type * lgr_index_map; /* a vector that maps LGR-nr for EGRID files to index into the LGR_list.*/ - std::unordered_map - LGR_hash; /* a hash of pointers to ecl_grid instances - for name based lookup of lgr. */ + std::unordered_map + LGR_hash; /* a hash of pointers to rd_grid instances - for name based lookup of lgr. */ int parent_box [6]; /* integers i1,i2, j1,j2, k1,k2 of the parent grid region containing this lgr. the indices are inclusive - zero offset */ /* not used yet .. */ @@ -746,22 +746,22 @@ struct ecl_grid_struct { int block_size; int last_block_index; double_vector_type **values; - ecl_kw_type *coord_kw; /* Retained for writing the grid to file. + rd_kw_type *coord_kw; /* Retained for writing the grid to file. In principal it should be possible to recalculate this from the cell coordinates, but in cases with skewed cells this has proved numerically challenging. */ - ert_ecl_unit_enum unit_system; + ert_rd_unit_enum unit_system; int eclipse_version; }; -ert_ecl_unit_enum ecl_grid_get_unit_system(const ecl_grid_type *grid) { +ert_rd_unit_enum rd_grid_get_unit_system(const rd_grid_type *grid) { return grid->unit_system; } -static void ecl_cell_compare(const ecl_cell_type *c1, const ecl_cell_type *c2, - bool include_nnc, bool *equal) { +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) @@ -790,23 +790,23 @@ static void ecl_cell_compare(const ecl_cell_type *c1, const ecl_cell_type *c2, } } -static void ecl_cell_dump(const ecl_cell_type *cell, FILE *stream) { +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 ecl_cell_assert_center(ecl_cell_type *cell); +static void rd_cell_assert_center(rd_cell_type *cell); -static void ecl_cell_dump_ascii(ecl_cell_type *cell, int i, int j, int k, - FILE *stream, const double *offset) { +static void rd_cell_dump_ascii(rd_cell_type *cell, int i, int j, int k, + FILE *stream, const double *offset) { fprintf(stream, "Cell: i:%3d j:%3d k:%3d host_cell:%d CoarseGroup:%4d " "active_nr:%6d active:%d \nCorners:\n", i, j, k, cell->host_cell, cell->coarse_group, cell->active_index[MATRIX_INDEX], cell->active); - ecl_cell_assert_center(cell); + rd_cell_assert_center(cell); fprintf(stream, "Center : "); point_dump_ascii(&cell->center, stream, offset); fprintf(stream, "\n"); @@ -822,33 +822,33 @@ static void ecl_cell_dump_ascii(ecl_cell_type *cell, int i, int j, int k, fprintf(stream, "\n"); } -static void ecl_cell_fwrite_GRID(const ecl_grid_type *grid, - const ecl_cell_type *cell, bool fracture_cell, - int coords_size, int i, int j, int k, - int global_index, ecl_kw_type *coords_kw, - ecl_kw_type *corners_kw, fortio_type *fortio) { - ecl_kw_iset_int(coords_kw, 0, i + 1); - ecl_kw_iset_int(coords_kw, 1, j + 1); - ecl_kw_iset_int(coords_kw, 2, k + 1); - ecl_kw_iset_int(coords_kw, 3, global_index + 1); +static void rd_cell_fwrite_GRID(const rd_grid_type *grid, + const rd_cell_type *cell, bool fracture_cell, + int coords_size, int i, int j, int k, + int global_index, rd_kw_type *coords_kw, + rd_kw_type *corners_kw, fortio_type *fortio) { + rd_kw_iset_int(coords_kw, 0, i + 1); + rd_kw_iset_int(coords_kw, 1, j + 1); + rd_kw_iset_int(coords_kw, 2, k + 1); + rd_kw_iset_int(coords_kw, 3, global_index + 1); - ecl_kw_iset_int(coords_kw, 4, 0); + rd_kw_iset_int(coords_kw, 4, 0); if (fracture_cell) { if (cell->active & CELL_ACTIVE_FRACTURE) - ecl_kw_iset_int(coords_kw, 4, 1); + rd_kw_iset_int(coords_kw, 4, 1); } else { if (cell->active & CELL_ACTIVE_MATRIX) - ecl_kw_iset_int(coords_kw, 4, 1); + rd_kw_iset_int(coords_kw, 4, 1); } if (coords_size == 7) { - ecl_kw_iset_int(coords_kw, 5, cell->host_cell + 1); - ecl_kw_iset_int(coords_kw, 6, cell->coarse_group + 1); + rd_kw_iset_int(coords_kw, 5, cell->host_cell + 1); + rd_kw_iset_int(coords_kw, 6, cell->coarse_group + 1); } - ecl_kw_fwrite(coords_kw, fortio); + rd_kw_fwrite(coords_kw, fortio); { - float *corners = (float *)ecl_kw_get_void_ptr(corners_kw); + float *corners = (float *)rd_kw_get_void_ptr(corners_kw); point_type point; int c; @@ -863,13 +863,13 @@ static void ecl_cell_fwrite_GRID(const ecl_grid_type *grid, corners[3 * c + 2] = point.z; } } - ecl_kw_fwrite(corners_kw, fortio); + rd_kw_fwrite(corners_kw, fortio); } -//static const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; -static void ecl_cell_ri_export(const ecl_cell_type *cell, double *ri_points) { - int ecl_offset = 4; - int ri_offset = ecl_offset * 3; +//static const size_t cellMappingRDRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 }; +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 @@ -881,34 +881,34 @@ static void ecl_cell_ri_export(const ecl_cell_type *cell, double *ri_points) { // Points 4 & 5 ri_points[ri_offset + point_nr * 3] = - cell->corner_list[ecl_offset + point_nr].x; + cell->corner_list[rd_offset + point_nr].x; ri_points[ri_offset + point_nr * 3 + 1] = - cell->corner_list[ecl_offset + point_nr].y; + cell->corner_list[rd_offset + point_nr].y; ri_points[ri_offset + point_nr * 3 + 2] = - -cell->corner_list[ecl_offset + point_nr].z; + -cell->corner_list[rd_offset + point_nr].z; } } { - int ecl_point; + 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 (ecl_point = 2; ecl_point < 4; ecl_point++) { - int ri_point = 5 - ecl_point; + 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[ecl_point].x; - ri_points[ri_point * 3 + 1] = cell->corner_list[ecl_point].y; - ri_points[ri_point * 3 + 2] = -cell->corner_list[ecl_point].z; + 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[ecl_offset + ecl_point].x; + cell->corner_list[rd_offset + rd_point].x; ri_points[ri_offset + ri_point * 3 + 1] = - cell->corner_list[ecl_offset + ecl_point].y; + cell->corner_list[rd_offset + rd_point].y; ri_points[ri_offset + ri_point * 3 + 2] = - -cell->corner_list[ecl_offset + ecl_point].z; + -cell->corner_list[rd_offset + rd_point].z; } } } @@ -935,12 +935,12 @@ static double min8(double x1, double x2, double x3, double x4, double x5, return min2(min4(x1, x2, x3, x4), min4(x5, x6, x7, x8)); } -static double ecl_cell_min_z(const ecl_cell_type *cell) { +static double rd_cell_min_z(const rd_cell_type *cell) { return min4(cell->corner_list[0].z, cell->corner_list[1].z, cell->corner_list[2].z, cell->corner_list[3].z); } -static double ecl_cell_max_z(const ecl_cell_type *cell) { +static double rd_cell_max_z(const rd_cell_type *cell) { return max4(cell->corner_list[4].z, cell->corner_list[5].z, cell->corner_list[6].z, cell->corner_list[7].z); } @@ -950,28 +950,28 @@ static double ecl_cell_max_z(const ecl_cell_type *cell) { plane for the x/y min/max. */ -static double ecl_cell_min_x(const ecl_cell_type *cell) { +static double rd_cell_min_x(const rd_cell_type *cell) { return min8(cell->corner_list[0].x, cell->corner_list[1].x, cell->corner_list[2].x, cell->corner_list[3].x, cell->corner_list[4].x, cell->corner_list[5].x, cell->corner_list[6].x, cell->corner_list[7].x); } -static double ecl_cell_max_x(const ecl_cell_type *cell) { +static double rd_cell_max_x(const rd_cell_type *cell) { return max8(cell->corner_list[0].x, cell->corner_list[1].x, cell->corner_list[2].x, cell->corner_list[3].x, cell->corner_list[4].x, cell->corner_list[5].x, cell->corner_list[6].x, cell->corner_list[7].x); } -static double ecl_cell_min_y(const ecl_cell_type *cell) { +static double rd_cell_min_y(const rd_cell_type *cell) { return min8(cell->corner_list[0].y, cell->corner_list[1].y, cell->corner_list[2].y, cell->corner_list[3].y, cell->corner_list[4].y, cell->corner_list[5].y, cell->corner_list[6].y, cell->corner_list[7].y); } -static double ecl_cell_max_y(const ecl_cell_type *cell) { +static double rd_cell_max_y(const rd_cell_type *cell) { return max8(cell->corner_list[0].y, cell->corner_list[1].y, cell->corner_list[2].y, cell->corner_list[3].y, cell->corner_list[4].y, cell->corner_list[5].y, @@ -1011,7 +1011,7 @@ static double ecl_cell_max_y(const ecl_cell_type *cell) { active elements. */ -static void ecl_cell_taint_cell(ecl_cell_type *cell) { +static void rd_cell_taint_cell(rd_cell_type *cell) { int c; for (c = 0; c < 8; c++) { const point_type p = cell->corner_list[c]; @@ -1047,7 +1047,7 @@ static void ecl_cell_taint_cell(ecl_cell_type *cell) { } } -static int ecl_cell_get_twist(const ecl_cell_type *cell) { +static int rd_cell_get_twist(const rd_cell_type *cell) { int twist_count = 0; for (int c = 0; c < 4; c++) { @@ -1065,7 +1065,7 @@ static int ecl_cell_get_twist(const ecl_cell_type *cell) { will have a coords/corners section in the grid file. */ -static void ecl_cell_init(ecl_cell_type *cell, bool init_valid) { +static void rd_cell_init(rd_cell_type *cell, bool init_valid) { cell->active = CELL_NOT_ACTIVE; cell->lgr = NULL; cell->host_cell = HOST_CELL_NONE; @@ -1081,13 +1081,13 @@ static void ecl_cell_init(ecl_cell_type *cell, bool init_valid) { /* #define mod(x,n) ((x) % (n)) -static int ecl_cell_get_tetrahedron_method( int i , int j , int k) { +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 ecl_cell_set_center(ecl_cell_type *cell) { +static void rd_cell_set_center(rd_cell_type *cell) { point_set(&cell->center, 0, 0, 0); { int c; @@ -1099,18 +1099,18 @@ static void ecl_cell_set_center(ecl_cell_type *cell) { SET_CELL_FLAG(cell, CELL_FLAG_CENTER); } -static void ecl_cell_assert_center(ecl_cell_type *cell) { +static void rd_cell_assert_center(rd_cell_type *cell) { if (!GET_CELL_FLAG(cell, CELL_FLAG_CENTER)) - ecl_cell_set_center(cell); + rd_cell_set_center(cell); } -static void ecl_cell_memcpy(ecl_cell_type *target_cell, - const ecl_cell_type *src_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 ecl_cell_install_lgr(ecl_cell_type *cell, - const ecl_grid_type *lgr_grid) { +static void rd_cell_install_lgr(rd_cell_type *cell, + const rd_grid_type *lgr_grid) { cell->lgr = lgr_grid; } @@ -1143,7 +1143,7 @@ static double C(double *r, int f1, int f2, int f3) { } } -static double ecl_cell_get_volume(ecl_cell_type *cell) { +static double rd_cell_get_volume(rd_cell_type *cell) { double volume = 0; int pb, pg, qa, qg, ra, rb; double X[8]; @@ -1338,8 +1338,8 @@ static bool triangle_contains3d(const point_type *p0, const point_type *p1, triangle_contains(). */ -static bool ecl_cell_layer_contains_xy(const ecl_cell_type *cell, - bool lower_layer, double x, double y) { +static bool rd_cell_layer_contains_xy(const rd_cell_type *cell, + bool lower_layer, double x, double y) { if (GET_CELL_FLAG(cell, CELL_FLAG_TAINTED)) return false; { @@ -1371,10 +1371,10 @@ static bool ecl_cell_layer_contains_xy(const ecl_cell_type *cell, | | | | 0---1 4---5 */ -static void ecl_cell_init_regular(ecl_cell_type *cell, const double *offset, - int i, int j, int k, int global_index, - const double *ivec, const double *jvec, - const double *kvec, const int *actnum) { +static void rd_cell_init_regular(rd_cell_type *cell, const double *offset, + int i, int j, int k, int global_index, + const double *ivec, const double *jvec, + const double *kvec, const int *actnum) { point_set(&cell->corner_list[0], offset[0], offset[1], offset[2]); // Point 0 @@ -1401,57 +1401,57 @@ static void ecl_cell_init_regular(ecl_cell_type *cell, const double *offset, cell->active = CELL_ACTIVE; } -UTIL_SAFE_CAST_FUNCTION(ecl_grid, ECL_GRID_ID); -UTIL_IS_INSTANCE_FUNCTION(ecl_grid, ECL_GRID_ID); +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 ecl_cell_type *ecl_grid_get_cell(const ecl_grid_type *grid, - int global_index) { +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 - ecl_cell_taint_cell() which actually does it. + rd_cell_taint_cell() which actually does it. */ -static void ecl_grid_taint_cells(ecl_grid_type *ecl_grid) { +static void rd_grid_taint_cells(rd_grid_type *rd_grid) { int index; - for (index = 0; index < ecl_grid->size; index++) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, index); - ecl_cell_taint_cell(cell); + for (index = 0; index < rd_grid->size; index++) { + rd_cell_type *cell = rd_grid_get_cell(rd_grid, index); + rd_cell_taint_cell(cell); } } -static void ecl_grid_free_cells(ecl_grid_type *grid) { +static void rd_grid_free_cells(rd_grid_type *grid) { if (!grid->cells) return; for (int i = 0; i < grid->size; i++) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, i); + rd_cell_type *cell = rd_grid_get_cell(grid, i); if (cell->nnc_info) nnc_info_free(cell->nnc_info); } free(grid->cells); } -static bool ecl_grid_alloc_cells(ecl_grid_type *grid, bool init_valid) { - grid->cells = (ecl_cell_type *)malloc(grid->size * sizeof *grid->cells); +static bool rd_grid_alloc_cells(rd_grid_type *grid, bool init_valid) { + grid->cells = (rd_cell_type *)malloc(grid->size * sizeof *grid->cells); if (!grid->cells) return false; { - ecl_cell_type *cell0 = ecl_grid_get_cell(grid, 0); - ecl_cell_init(cell0, init_valid); + 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++) { - ecl_cell_type *target_cell = ecl_grid_get_cell(grid, i); - ecl_cell_memcpy(target_cell, cell0); + rd_cell_type *target_cell = rd_grid_get_cell(grid, i); + rd_cell_memcpy(target_cell, cell0); } } return true; @@ -1466,11 +1466,10 @@ static bool ecl_grid_alloc_cells(ecl_grid_type *grid, bool init_valid) { is performed. */ -static ecl_grid_type *ecl_grid_alloc_empty(ecl_grid_type *global_grid, - ert_ecl_unit_enum unit_system, - int dualp_flag, int nx, int ny, - int nz, int lgr_nr, - bool init_valid) { +static rd_grid_type *rd_grid_alloc_empty(rd_grid_type *global_grid, + ert_rd_unit_enum unit_system, + int dualp_flag, int nx, int ny, int nz, + int lgr_nr, bool init_valid) { /* Check for int overflow in a roundabout way */ long size = static_cast(nx) * static_cast(ny); if (nx < 0 || ny < 0 || nz < 0 || size > INT_MAX) @@ -1479,8 +1478,8 @@ static ecl_grid_type *ecl_grid_alloc_empty(ecl_grid_type *global_grid, if (size > INT_MAX) return NULL; - ecl_grid_type *grid = new ecl_grid_type(); - UTIL_TYPE_ID_INIT(grid, ECL_GRID_ID); + rd_grid_type *grid = new rd_grid_type(); + UTIL_TYPE_ID_INIT(grid, RD_GRID_ID); grid->total_active = 0; grid->total_active_fracture = 0; grid->nx = nx; @@ -1526,7 +1525,7 @@ static ecl_grid_type *ecl_grid_alloc_empty(ecl_grid_type *global_grid, grid->block_dim = 0; grid->values = NULL; - if (ECL_GRID_MAINGRID_LGR_NR == lgr_nr) { /* this is the main grid */ + if (RD_GRID_MAINGRID_LGR_NR == lgr_nr) { /* this is the main grid */ grid->LGR_list = vector_alloc_new(); grid->lgr_index_map = int_vector_alloc(0, 0); } else { @@ -1540,25 +1539,25 @@ static ecl_grid_type *ecl_grid_alloc_empty(ecl_grid_type *global_grid, grid->eclipse_version = 0; /* This is the large allocation - which can potentially fail. */ - if (!ecl_grid_alloc_cells(grid, init_valid)) { - ecl_grid_free(grid); + if (!rd_grid_alloc_cells(grid, init_valid)) { + rd_grid_free(grid); grid = NULL; } return grid; } -static int ecl_grid_get_global_index__(const ecl_grid_type *ecl_grid, int i, - int j, int k) { - return i + j * ecl_grid->nx + k * ecl_grid->nx * ecl_grid->ny; +static int rd_grid_get_global_index__(const rd_grid_type *rd_grid, int i, int j, + int k) { + return i + j * rd_grid->nx + k * rd_grid->nx * rd_grid->ny; } -static void ecl_grid_set_cell_EGRID(ecl_grid_type *ecl_grid, int i, int j, - int k, double x[4][2], double y[4][2], - double z[4][2], const int *actnum, - const int *corsnum) { +static void rd_grid_set_cell_EGRID(rd_grid_type *rd_grid, int i, int j, int k, + double x[4][2], double y[4][2], + double z[4][2], const int *actnum, + const int *corsnum) { - const int global_index = ecl_grid_get_global_index__(ecl_grid, i, j, k); - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); + 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); int ip, iz; for (iz = 0; iz < 2; iz++) { @@ -1566,9 +1565,9 @@ static void ecl_grid_set_cell_EGRID(ecl_grid_type *ecl_grid, int i, int j, int c = ip + iz * 4; point_set(&cell->corner_list[c], x[ip][iz], y[ip][iz], z[ip][iz]); - if (ecl_grid->use_mapaxes) - point_mapaxes_transform(&cell->corner_list[c], ecl_grid->origo, - ecl_grid->unit_x, ecl_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); } } @@ -1587,14 +1586,14 @@ static void ecl_grid_set_cell_EGRID(ecl_grid_type *ecl_grid, int i, int j, cell->coarse_group = corsnum[global_index] - 1; } -static void ecl_grid_set_cell_GRID(ecl_grid_type *ecl_grid, int coords_size, - const int *coords, const float *corners) { +static void rd_grid_set_cell_GRID(rd_grid_type *rd_grid, int coords_size, + const int *coords, const float *corners) { const int i = coords[0] - 1; /* eclipse 1 offset */ const int j = coords[1] - 1; int k = coords[2] - 1; int global_index; - ecl_cell_type *cell; + rd_cell_type *cell; bool matrix_cell = true; int active_value = CELL_ACTIVE_MATRIX; @@ -1606,14 +1605,14 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type *ecl_grid, int coords_size, properties of the fracture. */ - if (k >= ecl_grid->nz) { - k -= ecl_grid->nz; + if (k >= rd_grid->nz) { + k -= rd_grid->nz; matrix_cell = false; active_value = CELL_ACTIVE_FRACTURE; } - global_index = ecl_grid_get_global_index__(ecl_grid, i, j, k); - cell = ecl_grid_get_cell(ecl_grid, global_index); + global_index = rd_grid_get_global_index__(rd_grid, i, j, k); + cell = rd_grid_get_cell(rd_grid, global_index); /* the coords keyword can optionally contain 4,5 or 7 elements: @@ -1630,21 +1629,19 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type *ecl_grid, int coords_size, keyword called LGRILG which maps out the parent box containing an LGR - this only duplicates the information which can be learned from the coords[5] element, and is not used in the - current code - however in good Schlum tradition a file with - 4/5 element COORDS keywords and LGRs might come any day. + current code. */ { int c; /* - The ECL_GRID_MAINGRID_LGR_NR != ecl_grid->lgr_nr test checks if + 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 ((ECL_GRID_MAINGRID_LGR_NR != ecl_grid->lgr_nr) && - (coords_size != 7)) + 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__); @@ -1661,7 +1658,7 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type *ecl_grid, int coords_size, cell->host_cell = coords[5] - 1; cell->coarse_group = coords[6] - 1; if (cell->coarse_group >= 0) - ecl_grid->coarsening_active = true; + rd_grid->coarsening_active = true; break; default: util_abort("%s: coord size:%d unrecognized - should 4,5 or 7.\n", @@ -1673,10 +1670,10 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type *ecl_grid, int coords_size, point_set(&cell->corner_list[c], corners[3 * c], corners[3 * c + 1], corners[3 * c + 2]); - if (ecl_grid->use_mapaxes) + if (rd_grid->use_mapaxes) point_mapaxes_transform(&cell->corner_list[c], - ecl_grid->origo, ecl_grid->unit_x, - ecl_grid->unit_y); + rd_grid->origo, rd_grid->unit_x, + rd_grid->unit_y); } } } @@ -1684,16 +1681,16 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type *ecl_grid, int coords_size, } /** - The function ecl_grid_set_active_index() must be called immediately + The function rd_grid_set_active_index() must be called immediately prior to calling this function, to ensure that - ecl_grid->total_active is correct. + rd_grid->total_active is correct. */ -static void ecl_grid_init_index_map__(ecl_grid_type *ecl_grid, int *index_map, - int *inv_index_map, int active_mask, - int type_index) { - for (int global_index = 0; global_index < ecl_grid->size; global_index++) { - const ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); +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); if (cell->active & active_mask) { index_map[global_index] = cell->active_index[type_index]; @@ -1705,29 +1702,29 @@ static void ecl_grid_init_index_map__(ecl_grid_type *ecl_grid, int *index_map, } } -static void ecl_grid_realloc_index_map(ecl_grid_type *ecl_grid) { +static void rd_grid_realloc_index_map(rd_grid_type *rd_grid) { /* Creating the inverse mapping for the matrix cells. */ - ecl_grid->index_map = (int *)util_realloc( - ecl_grid->index_map, ecl_grid->size * sizeof *ecl_grid->index_map); - ecl_grid->inv_index_map = (int *)util_realloc( - ecl_grid->inv_index_map, - ecl_grid->total_active * sizeof *ecl_grid->inv_index_map); - ecl_grid_init_index_map__(ecl_grid, ecl_grid->index_map, - ecl_grid->inv_index_map, CELL_ACTIVE_MATRIX, - MATRIX_INDEX); + rd_grid->index_map = (int *)util_realloc( + rd_grid->index_map, rd_grid->size * sizeof *rd_grid->index_map); + rd_grid->inv_index_map = (int *)util_realloc( + rd_grid->inv_index_map, + rd_grid->total_active * sizeof *rd_grid->inv_index_map); + rd_grid_init_index_map__(rd_grid, rd_grid->index_map, + rd_grid->inv_index_map, CELL_ACTIVE_MATRIX, + MATRIX_INDEX); /* Create the inverse mapping for the fractures. */ - if (ecl_grid->dualp_flag != FILEHEAD_SINGLE_POROSITY) { - ecl_grid->fracture_index_map = (int *)util_realloc( - ecl_grid->fracture_index_map, - ecl_grid->size * sizeof *ecl_grid->fracture_index_map); - ecl_grid->inv_fracture_index_map = - (int *)util_realloc(ecl_grid->inv_fracture_index_map, - ecl_grid->total_active_fracture * - sizeof *ecl_grid->inv_fracture_index_map); - ecl_grid_init_index_map__(ecl_grid, ecl_grid->fracture_index_map, - ecl_grid->inv_fracture_index_map, - CELL_ACTIVE_FRACTURE, FRACTURE_INDEX); + if (rd_grid->dualp_flag != FILEHEAD_SINGLE_POROSITY) { + rd_grid->fracture_index_map = (int *)util_realloc( + rd_grid->fracture_index_map, + rd_grid->size * sizeof *rd_grid->fracture_index_map); + rd_grid->inv_fracture_index_map = + (int *)util_realloc(rd_grid->inv_fracture_index_map, + rd_grid->total_active_fracture * + sizeof *rd_grid->inv_fracture_index_map); + rd_grid_init_index_map__(rd_grid, rd_grid->fracture_index_map, + rd_grid->inv_fracture_index_map, + CELL_ACTIVE_FRACTURE, FRACTURE_INDEX); } /* Update the inverse map in the case of coarse cells. Observe that @@ -1735,45 +1732,44 @@ static void ecl_grid_realloc_index_map(ecl_grid_type *ecl_grid) { main grid, the inverse active -> global mapping will map to the first active cell in the coarse cell. */ - int size = ecl_grid_get_num_coarse_groups(ecl_grid); + int size = rd_grid_get_num_coarse_groups(rd_grid); for (int coarse_group = 0; coarse_group < size; coarse_group++) { - ecl_coarse_cell_type *coarse_cell = - ecl_grid_iget_coarse_group(ecl_grid, coarse_group); + rd_coarse_cell_type *coarse_cell = + rd_grid_iget_coarse_group(rd_grid, coarse_group); // Coarse cell group numbering is not necessarily in consecutive order if (coarse_cell == NULL) { continue; } - if (ecl_coarse_cell_get_num_active(coarse_cell) > 0) { + if (rd_coarse_cell_get_num_active(coarse_cell) > 0) { int global_index = - ecl_coarse_cell_iget_active_cell_index(coarse_cell, 0); - int active_value = - ecl_coarse_cell_iget_active_value(coarse_cell, 0); - int active_index = ecl_coarse_cell_get_active_index(coarse_cell); + rd_coarse_cell_iget_active_cell_index(coarse_cell, 0); + int active_value = rd_coarse_cell_iget_active_value(coarse_cell, 0); + int active_index = rd_coarse_cell_get_active_index(coarse_cell); int active_fracture_index = - ecl_coarse_cell_get_active_fracture_index(coarse_cell); + rd_coarse_cell_get_active_fracture_index(coarse_cell); if (active_value & CELL_ACTIVE_MATRIX) // active->global mapping point to one "random" cell in the coarse group - ecl_grid->inv_index_map[active_index] = global_index; + rd_grid->inv_index_map[active_index] = global_index; if (active_value & CELL_ACTIVE_FRACTURE) - ecl_grid->inv_fracture_index_map[active_fracture_index] = + rd_grid->inv_fracture_index_map[active_fracture_index] = global_index; - int coarse_size = ecl_coarse_cell_get_size(coarse_cell); + int coarse_size = rd_coarse_cell_get_size(coarse_cell); const int_vector_type *global_index_list = - ecl_coarse_cell_get_index_vector(coarse_cell); + rd_coarse_cell_get_index_vector(coarse_cell); for (int ic = 0; ic < coarse_size; ic++) { int gi = int_vector_iget(global_index_list, ic); if (active_value & CELL_ACTIVE_MATRIX) // All cells in the coarse group point to the same active index. - ecl_grid->index_map[gi] = active_index; + rd_grid->index_map[gi] = active_index; if (active_value & CELL_ACTIVE_FRACTURE) - ecl_grid->fracture_index_map[gi] = active_fracture_index; + rd_grid->fracture_index_map[gi] = active_fracture_index; } } // else the coarse cell does not have any active cells. } @@ -1781,20 +1777,20 @@ static void ecl_grid_realloc_index_map(ecl_grid_type *ecl_grid) { /* This function goes through the entire grid and sets the active_index - of all the cells. The functione ecl_grid_realloc_index_map() + of all the cells. The functione rd_grid_realloc_index_map() subsequently reads this to create and initialize the index map. */ -static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { +static void rd_grid_set_active_index(rd_grid_type *rd_grid) { int global_index; int active_index = 0; int active_fracture_index = 0; - if (!ecl_grid_have_coarse_cells(ecl_grid)) { + if (!rd_grid_have_coarse_cells(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 < ecl_grid->size; global_index++) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, 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); if (cell->active & CELL_ACTIVE_MATRIX) { cell->active_index[MATRIX_INDEX] = active_index; @@ -1802,10 +1798,10 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { } } - if (ecl_grid->dualp_flag != FILEHEAD_SINGLE_POROSITY) { - for (global_index = 0; global_index < ecl_grid->size; + if (rd_grid->dualp_flag != FILEHEAD_SINGLE_POROSITY) { + for (global_index = 0; global_index < rd_grid->size; global_index++) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); + rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); if (cell->active & CELL_ACTIVE_FRACTURE) { cell->active_index[FRACTURE_INDEX] = active_fracture_index; active_fracture_index++; @@ -1816,18 +1812,18 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { /* --- More involved path in the case of coarsening groups. --- */ /* 1: Reset the coarse cell active_indices. - In the involved path ecl_coarse_cell_update_index() only updates + In the involved path rd_coarse_cell_update_index() only updates the coarse cells' active_index if it is -1. */ for (int coarse_index = 0; - coarse_index < vector_get_size(ecl_grid->coarse_cells); + coarse_index < vector_get_size(rd_grid->coarse_cells); coarse_index++) { - ecl_coarse_cell_type *coarse_cell = - (ecl_coarse_cell_type *)vector_iget_const( - ecl_grid->coarse_cells, coarse_index); + rd_coarse_cell_type *coarse_cell = + (rd_coarse_cell_type *)vector_iget_const(rd_grid->coarse_cells, + coarse_index); // Coarse cell group numbering is not necessarily in consecutive order if (coarse_cell != NULL) { - ecl_coarse_cell_reset_active_index(coarse_cell); + rd_coarse_cell_reset_active_index(coarse_cell); } } @@ -1835,8 +1831,8 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { case of coarse cells we only set the common active index of the entire coarse cell. */ - for (global_index = 0; global_index < ecl_grid->size; global_index++) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, 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); if (cell->active != CELL_NOT_ACTIVE) { if (cell->coarse_group == COARSE_GROUP_NONE) { @@ -1852,10 +1848,9 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { } } else { - ecl_coarse_cell_type *coarse_cell = - ecl_grid_iget_coarse_group(ecl_grid, - cell->coarse_group); - ecl_coarse_cell_update_index( + rd_coarse_cell_type *coarse_cell = + rd_grid_iget_coarse_group(rd_grid, cell->coarse_group); + rd_coarse_cell_update_index( coarse_cell, global_index, &active_index, &active_fracture_index, cell->active); } @@ -1868,30 +1863,30 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { common value for the coarse cell. */ - int size = ecl_grid_get_num_coarse_groups(ecl_grid); + int size = rd_grid_get_num_coarse_groups(rd_grid); for (int coarse_group = 0; coarse_group < size; coarse_group++) { - ecl_coarse_cell_type *coarse_cell = - ecl_grid_iget_coarse_group(ecl_grid, coarse_group); + rd_coarse_cell_type *coarse_cell = + rd_grid_iget_coarse_group(rd_grid, coarse_group); // Coarse cell group numbering is not necessarily in consecutive order if (coarse_cell == NULL) { continue; } - if (ecl_coarse_cell_get_num_active(coarse_cell) > 0) { + if (rd_coarse_cell_get_num_active(coarse_cell) > 0) { int cell_active_index = - ecl_coarse_cell_get_active_index(coarse_cell); + rd_coarse_cell_get_active_index(coarse_cell); int cell_active_value = - ecl_coarse_cell_iget_active_value(coarse_cell, 0); - int group_size = ecl_coarse_cell_get_size(coarse_cell); + rd_coarse_cell_iget_active_value(coarse_cell, 0); + int group_size = rd_coarse_cell_get_size(coarse_cell); const int *coarse_cell_list = - ecl_coarse_cell_get_index_ptr(coarse_cell); + rd_coarse_cell_get_index_ptr(coarse_cell); for (int i = 0; i < group_size; i++) { global_index = coarse_cell_list[i]; - ecl_cell_type *cell = - ecl_grid_get_cell(ecl_grid, global_index); + rd_cell_type *cell = + rd_grid_get_cell(rd_grid, global_index); if (cell_active_value & CELL_ACTIVE_MATRIX) cell->active_index[MATRIX_INDEX] = cell_active_index; @@ -1899,7 +1894,7 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { /* Coarse cell and dual porosity - that is probably close to zero measure. */ if (cell_active_value & CELL_ACTIVE_FRACTURE) { int cell_active_fracture_index = - ecl_coarse_cell_get_active_fracture_index( + rd_coarse_cell_get_active_fracture_index( coarse_cell); cell->active_index[FRACTURE_INDEX] = cell_active_fracture_index; @@ -1908,84 +1903,79 @@ static void ecl_grid_set_active_index(ecl_grid_type *ecl_grid) { } } } - ecl_grid->total_active = active_index; - ecl_grid->total_active_fracture = active_fracture_index; + rd_grid->total_active = active_index; + rd_grid->total_active_fracture = active_fracture_index; } -static void ecl_grid_update_index(ecl_grid_type *ecl_grid) { - ecl_grid_set_active_index(ecl_grid); - ecl_grid_realloc_index_map(ecl_grid); +static void rd_grid_update_index(rd_grid_type *rd_grid) { + rd_grid_set_active_index(rd_grid); + rd_grid_realloc_index_map(rd_grid); } -static ecl_coarse_cell_type * -ecl_grid_get_or_create_coarse_cell(ecl_grid_type *ecl_grid, int coarse_nr) { - if (vector_safe_iget(ecl_grid->coarse_cells, coarse_nr) == NULL) - vector_iset_owned_ref(ecl_grid->coarse_cells, coarse_nr, - ecl_coarse_cell_alloc(), ecl_coarse_cell_free__); +static rd_coarse_cell_type * +rd_grid_get_or_create_coarse_cell(rd_grid_type *rd_grid, int coarse_nr) { + if (vector_safe_iget(rd_grid->coarse_cells, coarse_nr) == NULL) + vector_iset_owned_ref(rd_grid->coarse_cells, coarse_nr, + rd_coarse_cell_alloc(), rd_coarse_cell_free__); - return (ecl_coarse_cell_type *)vector_iget(ecl_grid->coarse_cells, - coarse_nr); + return (rd_coarse_cell_type *)vector_iget(rd_grid->coarse_cells, coarse_nr); } -static void ecl_grid_init_coarse_cells(ecl_grid_type *ecl_grid) { - if (ecl_grid->coarsening_active) { +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 < ecl_grid->size; global_index++) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, 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); if (cell->coarse_group != COARSE_GROUP_NONE) { - ecl_coarse_cell_type *coarse_cell = - ecl_grid_get_or_create_coarse_cell(ecl_grid, - cell->coarse_group); + rd_coarse_cell_type *coarse_cell = + rd_grid_get_or_create_coarse_cell(rd_grid, + cell->coarse_group); int i, j, k; - ecl_grid_get_ijk1(ecl_grid, global_index, &i, &j, &k); - ecl_coarse_cell_update(coarse_cell, i, j, k, global_index); + rd_grid_get_ijk1(rd_grid, global_index, &i, &j, &k); + rd_coarse_cell_update(coarse_cell, i, j, k, global_index); } } } } -ecl_coarse_cell_type *ecl_grid_iget_coarse_group(const ecl_grid_type *ecl_grid, - int coarse_nr) { - return (ecl_coarse_cell_type *)vector_iget(ecl_grid->coarse_cells, - coarse_nr); +rd_coarse_cell_type *rd_grid_iget_coarse_group(const rd_grid_type *rd_grid, + int coarse_nr) { + return (rd_coarse_cell_type *)vector_iget(rd_grid->coarse_cells, coarse_nr); } -ecl_coarse_cell_type * -ecl_grid_get_cell_coarse_group1(const ecl_grid_type *ecl_grid, - int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); +rd_coarse_cell_type *rd_grid_get_cell_coarse_group1(const rd_grid_type *rd_grid, + int global_index) { + rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); if (cell->coarse_group == COARSE_GROUP_NONE) return NULL; else - return ecl_grid_iget_coarse_group(ecl_grid, cell->coarse_group); + return rd_grid_iget_coarse_group(rd_grid, cell->coarse_group); } -ecl_coarse_cell_type * -ecl_grid_get_cell_coarse_group3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_get_cell_coarse_group1(ecl_grid, global_index); +rd_coarse_cell_type *rd_grid_get_cell_coarse_group3(const rd_grid_type *rd_grid, + int i, int j, int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_get_cell_coarse_group1(rd_grid, global_index); } -bool ecl_grid_cell_in_coarse_group1(const ecl_grid_type *main_grid, - int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(main_grid, global_index); +bool rd_grid_cell_in_coarse_group1(const rd_grid_type *main_grid, + int global_index) { + rd_cell_type *cell = rd_grid_get_cell(main_grid, global_index); if (cell->coarse_group == COARSE_GROUP_NONE) return false; else return true; } -bool ecl_grid_cell_in_coarse_group3(const ecl_grid_type *main_grid, int i, - int j, int k) { - return ecl_grid_cell_in_coarse_group1( - main_grid, ecl_grid_get_global_index3(main_grid, i, j, k)); +bool rd_grid_cell_in_coarse_group3(const rd_grid_type *main_grid, int i, int j, + int k) { + return rd_grid_cell_in_coarse_group1( + main_grid, rd_grid_get_global_index3(main_grid, i, j, k)); } -static void ecl_grid_pillar_cross_planes(const point_type *p0, double e_x, - double e_y, double e_z, - const double *z, double *x, - double *y) { +static void rd_grid_pillar_cross_planes(const point_type *p0, double e_x, + double e_y, double e_z, const double *z, + double *x, double *y) { int k; if (e_z != 0) { for (k = 0; k < 2; k++) { @@ -2008,9 +1998,9 @@ static void ecl_grid_pillar_cross_planes(const point_type *p0, double e_x, settings from the global grid. */ -static void ecl_grid_init_mapaxes(ecl_grid_type *ecl_grid, bool apply_mapaxes, - const float *mapaxes) { - if (ecl_grid->global_grid != NULL) +static void rd_grid_init_mapaxes(rd_grid_type *rd_grid, bool apply_mapaxes, + const float *mapaxes) { + if (rd_grid->global_grid != NULL) util_abort("%s: GridError: Trying to grid transformation data from " "mapaxes for a subgrid(lgr)\n", __func__); @@ -2025,27 +2015,27 @@ static void ecl_grid_init_mapaxes(ecl_grid_type *ecl_grid, bool apply_mapaxes, double norm_y = 1.0 / sqrt(unit_y[0] * unit_y[0] + unit_y[1] * unit_y[1]); - ecl_grid->unit_x[0] = unit_x[0] * norm_x; - ecl_grid->unit_x[1] = unit_x[1] * norm_x; - ecl_grid->unit_y[0] = unit_y[0] * norm_y; - ecl_grid->unit_y[1] = unit_y[1] * norm_y; + rd_grid->unit_x[0] = unit_x[0] * norm_x; + rd_grid->unit_x[1] = unit_x[1] * norm_x; + rd_grid->unit_y[0] = unit_y[0] * norm_y; + rd_grid->unit_y[1] = unit_y[1] * norm_y; } - ecl_grid->origo[0] = mapaxes[2]; - ecl_grid->origo[1] = mapaxes[3]; - ecl_grid->mapaxes = (float *)util_malloc(6 * sizeof *ecl_grid->mapaxes); - memcpy(ecl_grid->mapaxes, mapaxes, 6 * sizeof(float)); + rd_grid->origo[0] = mapaxes[2]; + rd_grid->origo[1] = mapaxes[3]; + rd_grid->mapaxes = (float *)util_malloc(6 * sizeof *rd_grid->mapaxes); + memcpy(rd_grid->mapaxes, mapaxes, 6 * sizeof(float)); /* If the apply_mapaxes variable is false we will not apply the transformation; however we will still internalize the mapaxes information, and also output that if the file is saved again. */ - ecl_grid->use_mapaxes = apply_mapaxes; + rd_grid->use_mapaxes = apply_mapaxes; } } /** - this function will add a ecl_grid instance as a lgr to the main + this function will add a rd_grid instance as a lgr to the main grid. the lgr grid as added to two different structures of the main grid: @@ -2074,9 +2064,8 @@ static void ecl_grid_init_mapaxes(ecl_grid_type *ecl_grid, bool apply_mapaxes, in the _install_egrid / install_grid functions further down. */ -static void ecl_grid_add_lgr(ecl_grid_type *main_grid, - ecl_grid_type *lgr_grid) { - vector_append_owned_ref(main_grid->LGR_list, lgr_grid, ecl_grid_free__); +static void rd_grid_add_lgr(rd_grid_type *main_grid, rd_grid_type *lgr_grid) { + vector_append_owned_ref(main_grid->LGR_list, lgr_grid, rd_grid_free__); if (lgr_grid->lgr_nr >= int_vector_size(main_grid->lgr_index_map)) int_vector_resize(main_grid->lgr_index_map, lgr_grid->lgr_nr + 1, 0); int_vector_iset(main_grid->lgr_index_map, lgr_grid->lgr_nr, @@ -2084,51 +2073,51 @@ static void ecl_grid_add_lgr(ecl_grid_type *main_grid, main_grid->LGR_hash[lgr_grid->name] = lgr_grid; } -static void ecl_grid_install_lgr_common(ecl_grid_type *host_grid, - ecl_grid_type *lgr_grid) { +static void rd_grid_install_lgr_common(rd_grid_type *host_grid, + rd_grid_type *lgr_grid) { host_grid->children[lgr_grid->name] = lgr_grid; lgr_grid->parent_grid = host_grid; } /** this function will set the lgr pointer of the relevant cells in the - host grid to point to the lgr_grid. observe that the ecl_cell_type + host grid to point to the lgr_grid. observe that the rd_cell_type instances do *not* own the lgr_grid - all lgr_grid instances are owned by the main grid. */ -static void ecl_grid_install_lgr_EGRID(ecl_grid_type *host_grid, - ecl_grid_type *lgr_grid, - const int *hostnum) { +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 (global_lgr_index = 0; global_lgr_index < lgr_grid->size; global_lgr_index++) { int host_index = hostnum[global_lgr_index] - 1; - ecl_cell_type *lgr_cell = ecl_grid_get_cell(lgr_grid, global_lgr_index); - ecl_cell_type *host_cell = ecl_grid_get_cell(host_grid, host_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, host_index); - ecl_cell_install_lgr(host_cell, lgr_grid); + rd_cell_install_lgr(host_cell, lgr_grid); lgr_cell->host_cell = host_index; } - ecl_grid_install_lgr_common(host_grid, lgr_grid); + rd_grid_install_lgr_common(host_grid, lgr_grid); } /** - similar to ecl_grid_install_lgr_egrid for grid based instances. + similar to rd_grid_install_lgr_egrid for grid based instances. */ -static void ecl_grid_install_lgr_GRID(ecl_grid_type *host_grid, - ecl_grid_type *lgr_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++) { - ecl_cell_type *lgr_cell = ecl_grid_get_cell(lgr_grid, global_lgr_index); - ecl_cell_type *host_cell = - ecl_grid_get_cell(host_grid, lgr_cell->host_cell); - ecl_cell_install_lgr(host_cell, lgr_grid); + 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); } - ecl_grid_install_lgr_common(host_grid, lgr_grid); + rd_grid_install_lgr_common(host_grid, lgr_grid); } /** @@ -2137,19 +2126,18 @@ static void ecl_grid_install_lgr_GRID(ecl_grid_type *host_grid, the parent_name is set to NULL. */ -static void ecl_grid_set_lgr_name_EGRID(ecl_grid_type *lgr_grid, - const ecl_file_type *ecl_file, - int grid_nr) { - ecl_kw_type *lgrname_kw = - ecl_file_iget_named_kw(ecl_file, LGR_KW, grid_nr - 1); - lgr_grid->name = - (char *)util_alloc_strip_copy((const char *)ecl_kw_iget_ptr( - lgrname_kw, 0)); /* trailing zeros are stripped away. */ - if (ecl_file_has_kw(ecl_file, LGR_PARENT_KW)) { - ecl_kw_type *parent_kw = - ecl_file_iget_named_kw(ecl_file, LGR_PARENT_KW, grid_nr - 1); +static void rd_grid_set_lgr_name_EGRID(rd_grid_type *lgr_grid, + const rd_file_type *rd_file, + int grid_nr) { + rd_kw_type *lgrname_kw = + rd_file_iget_named_kw(rd_file, LGR_KW, grid_nr - 1); + lgr_grid->name = (char *)util_alloc_strip_copy((const char *)rd_kw_iget_ptr( + lgrname_kw, 0)); /* trailing zeros are stripped away. */ + if (rd_file_has_kw(rd_file, LGR_PARENT_KW)) { + rd_kw_type *parent_kw = + rd_file_iget_named_kw(rd_file, LGR_PARENT_KW, grid_nr - 1); char *parent = (char *)util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(parent_kw, 0)); + (const char *)rd_kw_iget_ptr(parent_kw, 0)); if (strlen(parent) > 0) lgr_grid->parent_name = parent; @@ -2165,22 +2153,21 @@ static void ecl_grid_set_lgr_name_EGRID(ecl_grid_type *lgr_grid, cool?). anyway global -> NULL. */ -static void ecl_grid_set_lgr_name_GRID(ecl_grid_type *lgr_grid, - const ecl_file_type *ecl_file, - int grid_nr) { - ecl_kw_type *lgr_kw = ecl_file_iget_named_kw(ecl_file, LGR_KW, grid_nr - 1); - lgr_grid->name = - (char *)util_alloc_strip_copy((const char *)ecl_kw_iget_ptr( - lgr_kw, 0)); /* trailing zeros are stripped away. */ +static void rd_grid_set_lgr_name_GRID(rd_grid_type *lgr_grid, + const rd_file_type *rd_file, + int grid_nr) { + rd_kw_type *lgr_kw = rd_file_iget_named_kw(rd_file, LGR_KW, grid_nr - 1); + lgr_grid->name = (char *)util_alloc_strip_copy((const char *)rd_kw_iget_ptr( + lgr_kw, 0)); /* trailing zeros are stripped away. */ { /** the lgr keyword can have one or two elements; in the case of two elements the second element will be the name of the parent grid - in the case of only one element the current lgr is assumed to descend from the main grid */ - if (ecl_kw_get_size(lgr_kw) == 2) { + if (rd_kw_get_size(lgr_kw) == 2) { char *parent = (char *)util_alloc_strip_copy( - (const char *)ecl_kw_iget_ptr(lgr_kw, 1)); + (const char *)rd_kw_iget_ptr(lgr_kw, 1)); if ((strlen(parent) == 0) || (strcmp(parent, GLOBAL_STRING) == 0)) free(parent); @@ -2198,7 +2185,7 @@ static void ecl_grid_set_lgr_name_GRID(ecl_grid_type *lgr_grid, the zcorn vector. */ -int ecl_grid_zcorn_index__(int nx, int ny, int i, int j, int k, int c) { +int rd_grid_zcorn_index__(int nx, int ny, int i, int j, int k, int c) { int zcorn_index = k * 8 * nx * ny + j * 4 * nx + 2 * i; if ((c % 2) == 1) zcorn_index += 1; @@ -2215,18 +2202,17 @@ int ecl_grid_zcorn_index__(int nx, int ny, int i, int j, int k, int c) { return zcorn_index; } -int ecl_grid_zcorn_index(const ecl_grid_type *grid, int i, int j, int k, - int c) { - return ecl_grid_zcorn_index__(grid->nx, grid->ny, i, j, k, c); +int rd_grid_zcorn_index(const rd_grid_type *grid, int i, int j, int k, int c) { + return rd_grid_zcorn_index__(grid->nx, grid->ny, i, j, k, c); } -static void ecl_grid_init_GRDECL_data_jslice(ecl_grid_type *ecl_grid, - const double *zcorn, - const double *coord, - const int *actnum, - const int *corsnum, int j) { - const int nx = ecl_grid->nx; - const int ny = ecl_grid->ny; - const int nz = ecl_grid->nz; +static void rd_grid_init_GRDECL_data_jslice(rd_grid_type *rd_grid, + const double *zcorn, + const double *coord, + const int *actnum, + const int *corsnum, int j) { + 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++) { @@ -2287,26 +2273,26 @@ static void ecl_grid_init_GRDECL_data_jslice(ecl_grid_type *ecl_grid, { int ip; for (ip = 0; ip < 4; ip++) - ecl_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], - ey[ip], ez[ip], z[ip], - x[ip], y[ip]); + rd_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], + ey[ip], ez[ip], z[ip], + x[ip], y[ip]); } - ecl_grid_set_cell_EGRID(ecl_grid, i, j, k, x, y, z, actnum, - corsnum); + rd_grid_set_cell_EGRID(rd_grid, i, j, k, x, y, z, actnum, + corsnum); } } } } -static void ecl_grid_init_GRDECL_data_jslice(ecl_grid_type *ecl_grid, - const float *zcorn, - const float *coord, - const int *actnum, - const int *corsnum, int j) { - const int nx = ecl_grid->nx; - const int ny = ecl_grid->ny; - const int nz = ecl_grid->nz; +static void rd_grid_init_GRDECL_data_jslice(rd_grid_type *rd_grid, + const float *zcorn, + const float *coord, + const int *actnum, + const int *corsnum, int j) { + 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++) { @@ -2367,38 +2353,38 @@ static void ecl_grid_init_GRDECL_data_jslice(ecl_grid_type *ecl_grid, { int ip; for (ip = 0; ip < 4; ip++) - ecl_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], - ey[ip], ez[ip], z[ip], - x[ip], y[ip]); + rd_grid_pillar_cross_planes(&pillars[ip][0], ex[ip], + ey[ip], ez[ip], z[ip], + x[ip], y[ip]); } - ecl_grid_set_cell_EGRID(ecl_grid, i, j, k, x, y, z, actnum, - corsnum); + rd_grid_set_cell_EGRID(rd_grid, i, j, k, x, y, z, actnum, + corsnum); } } } } -void ecl_grid_init_GRDECL_data(ecl_grid_type *ecl_grid, const double *zcorn, - const double *coord, const int *actnum, - const int *corsnum) { - const int ny = ecl_grid->ny; +void rd_grid_init_GRDECL_data(rd_grid_type *rd_grid, const double *zcorn, + const double *coord, const int *actnum, + const int *corsnum) { + const int ny = rd_grid->ny; int j; #pragma omp parallel for for (j = 0; j < ny; j++) - ecl_grid_init_GRDECL_data_jslice(ecl_grid, zcorn, coord, actnum, - corsnum, j); + rd_grid_init_GRDECL_data_jslice(rd_grid, zcorn, coord, actnum, corsnum, + j); } -void ecl_grid_init_GRDECL_data(ecl_grid_type *ecl_grid, const float *zcorn, - const float *coord, const int *actnum, - const int *corsnum) { - const int ny = ecl_grid->ny; +void rd_grid_init_GRDECL_data(rd_grid_type *rd_grid, const float *zcorn, + const float *coord, const int *actnum, + const int *corsnum) { + const int ny = rd_grid->ny; int j; #pragma omp parallel for for (j = 0; j < ny; j++) - ecl_grid_init_GRDECL_data_jslice(ecl_grid, zcorn, coord, actnum, - corsnum, j); + rd_grid_init_GRDECL_data_jslice(rd_grid, zcorn, coord, actnum, corsnum, + j); } /* @@ -2407,65 +2393,65 @@ void ecl_grid_init_GRDECL_data(ecl_grid_type *ecl_grid, const float *zcorn, 0---1 */ -static ecl_grid_type *ecl_grid_alloc_GRDECL_data__( - ecl_grid_type *global_grid, ert_ecl_unit_enum unit_system, int dualp_flag, +static rd_grid_type *rd_grid_alloc_GRDECL_data__( + rd_grid_type *global_grid, ert_rd_unit_enum unit_system, int dualp_flag, bool apply_mapaxes, int nx, int ny, int nz, const double *zcorn, const double *coord, const int *actnum, const float *mapaxes, const int *corsnum, int lgr_nr) { - ecl_grid_type *ecl_grid = ecl_grid_alloc_empty( + rd_grid_type *rd_grid = rd_grid_alloc_empty( global_grid, unit_system, dualp_flag, nx, ny, nz, lgr_nr, true); - if (ecl_grid) { + if (rd_grid) { if (mapaxes != NULL) - ecl_grid_init_mapaxes(ecl_grid, apply_mapaxes, mapaxes); + rd_grid_init_mapaxes(rd_grid, apply_mapaxes, mapaxes); if (corsnum != NULL) - ecl_grid->coarsening_active = true; + rd_grid->coarsening_active = true; - ecl_grid->coord_kw = - ecl_kw_alloc("COORD", 6 * (nx + 1) * (ny + 1), ECL_FLOAT); + rd_grid->coord_kw = + rd_kw_alloc("COORD", 6 * (nx + 1) * (ny + 1), RD_FLOAT); { - float *coord_float = (float *)ecl_kw_get_ptr(ecl_grid->coord_kw); - for (int i = 0; i < ecl_kw_get_size(ecl_grid->coord_kw); i++) + float *coord_float = (float *)rd_kw_get_ptr(rd_grid->coord_kw); + for (int i = 0; i < rd_kw_get_size(rd_grid->coord_kw); i++) coord_float[i] = coord[i]; } - ecl_grid_init_GRDECL_data(ecl_grid, zcorn, coord, actnum, corsnum); + rd_grid_init_GRDECL_data(rd_grid, zcorn, coord, actnum, corsnum); - ecl_grid_init_coarse_cells(ecl_grid); - ecl_grid_update_index(ecl_grid); - ecl_grid_taint_cells(ecl_grid); + rd_grid_init_coarse_cells(rd_grid); + rd_grid_update_index(rd_grid); + rd_grid_taint_cells(rd_grid); } - return ecl_grid; + return rd_grid; } -static ecl_grid_type *ecl_grid_alloc_GRDECL_data__( - ecl_grid_type *global_grid, ert_ecl_unit_enum unit_system, int dualp_flag, +static rd_grid_type *rd_grid_alloc_GRDECL_data__( + rd_grid_type *global_grid, ert_rd_unit_enum unit_system, int dualp_flag, bool apply_mapaxes, int nx, int ny, int nz, const float *zcorn, const float *coord, const int *actnum, const float *mapaxes, const int *corsnum, int lgr_nr) { - ecl_grid_type *ecl_grid = ecl_grid_alloc_empty( + rd_grid_type *rd_grid = rd_grid_alloc_empty( global_grid, unit_system, dualp_flag, nx, ny, nz, lgr_nr, true); - if (ecl_grid) { + if (rd_grid) { if (mapaxes != NULL) - ecl_grid_init_mapaxes(ecl_grid, apply_mapaxes, mapaxes); + rd_grid_init_mapaxes(rd_grid, apply_mapaxes, mapaxes); if (corsnum != NULL) - ecl_grid->coarsening_active = true; + rd_grid->coarsening_active = true; - ecl_grid->coord_kw = ecl_kw_alloc_new("COORD", 6 * (nx + 1) * (ny + 1), - ECL_FLOAT, coord); - ecl_grid_init_GRDECL_data(ecl_grid, zcorn, coord, actnum, corsnum); + rd_grid->coord_kw = + rd_kw_alloc_new("COORD", 6 * (nx + 1) * (ny + 1), RD_FLOAT, coord); + rd_grid_init_GRDECL_data(rd_grid, zcorn, coord, actnum, corsnum); - ecl_grid_init_coarse_cells(ecl_grid); - ecl_grid_update_index(ecl_grid); - ecl_grid_taint_cells(ecl_grid); + rd_grid_init_coarse_cells(rd_grid); + rd_grid_update_index(rd_grid); + rd_grid_taint_cells(rd_grid); } - return ecl_grid; + return rd_grid; } -static void ecl_grid_copy_mapaxes(ecl_grid_type *target_grid, - const ecl_grid_type *src_grid) { +static void rd_grid_copy_mapaxes(rd_grid_type *target_grid, + const rd_grid_type *src_grid) { target_grid->use_mapaxes = src_grid->use_mapaxes; if (src_grid->mapaxes) target_grid->mapaxes = @@ -2482,77 +2468,75 @@ static void ecl_grid_copy_mapaxes(ecl_grid_type *target_grid, } } -static void ecl_grid_copy_content(ecl_grid_type *target_grid, - const ecl_grid_type *src_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++) { - ecl_cell_type *target_cell = - ecl_grid_get_cell(target_grid, global_index); - const ecl_cell_type *src_cell = - ecl_grid_get_cell(src_grid, 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); - ecl_cell_memcpy(target_cell, src_cell); + rd_cell_memcpy(target_cell, src_cell); if (src_cell->nnc_info) target_cell->nnc_info = nnc_info_alloc_copy(src_cell->nnc_info); } - ecl_grid_copy_mapaxes(target_grid, src_grid); + rd_grid_copy_mapaxes(target_grid, src_grid); target_grid->parent_name = util_alloc_string_copy(src_grid->parent_name); target_grid->name = util_alloc_string_copy(src_grid->name); target_grid->coarsening_active = src_grid->coarsening_active; - ecl_grid_init_coarse_cells(target_grid); + rd_grid_init_coarse_cells(target_grid); } -static ecl_grid_type *ecl_grid_alloc_copy__(const ecl_grid_type *src_grid, - ecl_grid_type *main_grid) { - ecl_grid_type *copy_grid = ecl_grid_alloc_empty( +static rd_grid_type *rd_grid_alloc_copy__(const rd_grid_type *src_grid, + rd_grid_type *main_grid) { + rd_grid_type *copy_grid = rd_grid_alloc_empty( main_grid, src_grid->unit_system, src_grid->dualp_flag, - ecl_grid_get_nx(src_grid), ecl_grid_get_ny(src_grid), - ecl_grid_get_nz(src_grid), 0, false); + rd_grid_get_nx(src_grid), rd_grid_get_ny(src_grid), + rd_grid_get_nz(src_grid), 0, false); if (copy_grid) { - ecl_grid_copy_content( + rd_grid_copy_content( copy_grid, src_grid); // This will handle everything except LGR relationships which is established in the calling routine - ecl_grid_update_index(copy_grid); + rd_grid_update_index(copy_grid); } return copy_grid; } -ecl_grid_type *ecl_grid_alloc_copy(const ecl_grid_type *src_grid) { - ecl_grid_type *copy_grid = ecl_grid_alloc_copy__(src_grid, NULL); +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 ecl_grid_type *src_lgr = - (const ecl_grid_type *)vector_iget_const(src_grid->LGR_list, - grid_nr); - ecl_grid_type *copy_lgr = ecl_grid_alloc_copy__(src_lgr, copy_grid); - ecl_grid_type *host_grid; + 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; - ecl_grid_add_lgr( + 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 = ecl_grid_get_lgr(copy_grid, copy_lgr->parent_name); + host_grid = rd_grid_get_lgr(copy_grid, copy_lgr->parent_name); { int global_lgr_index; for (global_lgr_index = 0; global_lgr_index < copy_lgr->size; global_lgr_index++) { - ecl_cell_type *lgr_cell = - ecl_grid_get_cell(copy_lgr, global_lgr_index); - ecl_cell_type *host_cell = - ecl_grid_get_cell(host_grid, lgr_cell->host_cell); + 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); - ecl_cell_install_lgr(host_cell, copy_lgr); + rd_cell_install_lgr(host_cell, copy_lgr); } - ecl_grid_install_lgr_common(host_grid, copy_lgr); + rd_grid_install_lgr_common(host_grid, copy_lgr); } } } @@ -2563,34 +2547,33 @@ ecl_grid_type *ecl_grid_alloc_copy(const ecl_grid_type *src_grid) { /* Does not handle LGR */ -ecl_grid_type *ecl_grid_alloc_processed_copy(const ecl_grid_type *src_grid, - const double *zcorn, - const int *actnum) { - ecl_grid_type *grid; +rd_grid_type *rd_grid_alloc_processed_copy(const rd_grid_type *src_grid, + const double *zcorn, + const int *actnum) { + rd_grid_type *grid; if (zcorn == NULL) { - grid = ecl_grid_alloc_copy__(src_grid, NULL); + grid = rd_grid_alloc_copy__(src_grid, NULL); if (actnum) - ecl_grid_reset_actnum(grid, actnum); + rd_grid_reset_actnum(grid, actnum); } else { int nx, ny, nz, na; - int zcorn_size = ecl_grid_get_zcorn_size(src_grid); + int zcorn_size = rd_grid_get_zcorn_size(src_grid); float *zcorn_float = (float *)util_malloc(zcorn_size * sizeof *zcorn_float); - float *coord = ecl_grid_alloc_coord_data(src_grid); + float *coord = rd_grid_alloc_coord_data(src_grid); float *mapaxes = NULL; - if (ecl_grid_get_mapaxes(src_grid)) { + if (rd_grid_get_mapaxes(src_grid)) { mapaxes = (float *)util_malloc(6 * sizeof *mapaxes); - ecl_grid_init_mapaxes_data_float(src_grid, mapaxes); + rd_grid_init_mapaxes_data_float(src_grid, mapaxes); } - ecl_grid_get_dims(src_grid, &nx, &ny, &nz, &na); + rd_grid_get_dims(src_grid, &nx, &ny, &nz, &na); for (int i = 0; i < zcorn_size; i++) zcorn_float[i] = zcorn[i]; - grid = - ecl_grid_alloc_GRDECL_data(nx, ny, nz, zcorn_float, coord, actnum, - src_grid->use_mapaxes, mapaxes); + grid = rd_grid_alloc_GRDECL_data(nx, ny, nz, zcorn_float, coord, actnum, + src_grid->use_mapaxes, mapaxes); free(mapaxes); free(coord); @@ -2607,35 +2590,34 @@ ecl_grid_type *ecl_grid_alloc_processed_copy(const ecl_grid_type *src_grid, a lgr hierarchy - or cell coarsening. */ -ecl_grid_type *ecl_grid_alloc_GRDECL_data(int nx, int ny, int nz, - const float *zcorn, - const float *coord, const int *actnum, - bool apply_mapaxes, - const float *mapaxes) { +rd_grid_type *rd_grid_alloc_GRDECL_data(int nx, int ny, int nz, + const float *zcorn, const float *coord, + const int *actnum, bool apply_mapaxes, + const float *mapaxes) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - return ecl_grid_alloc_GRDECL_data__( + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + return rd_grid_alloc_GRDECL_data__( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, apply_mapaxes, nx, ny, nz, zcorn, coord, actnum, mapaxes, NULL, 0); } -namespace ecl { +namespace rd { -ecl_grid_type *ecl_grid_alloc_GRDECL_data(int nx, int ny, int nz, - const double *zcorn, - const double *coord, - const int *actnum, bool apply_mapaxes, - const float *mapaxes) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - return ecl_grid_alloc_GRDECL_data__( +rd_grid_type *rd_grid_alloc_GRDECL_data(int nx, int ny, int nz, + const double *zcorn, + const double *coord, const int *actnum, + bool apply_mapaxes, + const float *mapaxes) { + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + return rd_grid_alloc_GRDECL_data__( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, apply_mapaxes, nx, ny, nz, zcorn, coord, actnum, mapaxes, NULL, 0); } -} // namespace ecl +} // namespace rd -const float *ecl_grid_get_mapaxes_from_kw__(const ecl_kw_type *mapaxes_kw) { - const float *mapaxes_data = ecl_kw_get_float_ptr(mapaxes_kw); +const float *rd_grid_get_mapaxes_from_kw__(const rd_kw_type *mapaxes_kw) { + const float *mapaxes_data = rd_kw_get_float_ptr(mapaxes_kw); float x1 = mapaxes_data[2]; float y1 = mapaxes_data[3]; @@ -2651,27 +2633,25 @@ const float *ecl_grid_get_mapaxes_from_kw__(const ecl_kw_type *mapaxes_kw) { return mapaxes_data; } -static ecl_grid_type * -ecl_grid_alloc_GRDECL_kw__(ecl_grid_type *global_grid, int dualp_flag, - bool apply_mapaxes, const ecl_kw_type *gridhead_kw, - const ecl_kw_type *zcorn_kw, - const ecl_kw_type *coord_kw, - const ecl_kw_type *gridunit_kw, /* Can be NULL */ - const ecl_kw_type *mapaxes_kw, /* Can be NULL */ - const ecl_kw_type *corsnum_kw, /* Can be NULL */ - const int *actnum_data) { /* Can be NULL */ +static rd_grid_type *rd_grid_alloc_GRDECL_kw__( + rd_grid_type *global_grid, int dualp_flag, bool apply_mapaxes, + const rd_kw_type *gridhead_kw, const rd_kw_type *zcorn_kw, + const rd_kw_type *coord_kw, const rd_kw_type *gridunit_kw, /* Can be NULL */ + const rd_kw_type *mapaxes_kw, /* Can be NULL */ + const rd_kw_type *corsnum_kw, /* Can be NULL */ + const int *actnum_data) { /* Can be NULL */ int gtype, nx, ny, nz, lgr_nr; - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - gtype = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_TYPE_INDEX); - nx = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); - ny = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); - nz = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); - lgr_nr = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_LGR_INDEX); + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + gtype = rd_kw_iget_int(gridhead_kw, GRIDHEAD_TYPE_INDEX); + nx = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); + ny = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); + nz = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); + lgr_nr = rd_kw_iget_int(gridhead_kw, GRIDHEAD_LGR_INDEX); /* The code used to have this test: - if (grid_nr != ecl_kw_iget_int( gridhead_kw , GRIDHEAD_LGR_INDEX)) + if (grid_nr != rd_kw_iget_int( gridhead_kw , GRIDHEAD_LGR_INDEX)) util_abort("%s: internal error in grid loader - lgr index mismatch\n",__func__); But then suddenly a EGRID file where this did not apply appeared :-( @@ -2687,62 +2667,62 @@ ecl_grid_alloc_GRDECL_kw__(ecl_grid_type *global_grid, int dualp_flag, const int *corsnum_data = NULL; if (mapaxes_kw) - mapaxes_data = ecl_grid_get_mapaxes_from_kw__(mapaxes_kw); + mapaxes_data = rd_grid_get_mapaxes_from_kw__(mapaxes_kw); if (corsnum_kw) - corsnum_data = ecl_kw_get_int_ptr(corsnum_kw); + corsnum_data = rd_kw_get_int_ptr(corsnum_kw); if (gridunit_kw) - unit_system = ecl_grid_check_unit_system(gridunit_kw); + unit_system = rd_grid_check_unit_system(gridunit_kw); - return ecl_grid_alloc_GRDECL_data__( + return rd_grid_alloc_GRDECL_data__( global_grid, unit_system, dualp_flag, apply_mapaxes, nx, ny, nz, - ecl_kw_get_float_ptr(zcorn_kw), ecl_kw_get_float_ptr(coord_kw), + rd_kw_get_float_ptr(zcorn_kw), rd_kw_get_float_ptr(coord_kw), actnum_data, mapaxes_data, corsnum_data, lgr_nr); } } /** - If you create/load ecl_kw instances for the various fields, this + If you create/load rd_kw instances for the various fields, this function can be used to create a GRID instance, without going through a GRID/EGRID file. Does not support LGR or coarsening hierarchies. */ -ecl_grid_type * -ecl_grid_alloc_GRDECL_kw(int nx, int ny, int nz, const ecl_kw_type *zcorn_kw, - const ecl_kw_type *coord_kw, - const ecl_kw_type *actnum_kw, /* Can be NULL */ - const ecl_kw_type *mapaxes_kw) { /* Can be NULL */ +rd_grid_type * +rd_grid_alloc_GRDECL_kw(int nx, int ny, int nz, const rd_kw_type *zcorn_kw, + const rd_kw_type *coord_kw, + const rd_kw_type *actnum_kw, /* Can be NULL */ + const rd_kw_type *mapaxes_kw) { /* Can be NULL */ const int *actnum_data = NULL; if (actnum_kw) - actnum_data = ecl_kw_get_int_ptr(actnum_kw); + actnum_data = rd_kw_get_int_ptr(actnum_kw); bool apply_mapaxes = true; - ecl_kw_type *gridhead_kw = ecl_grid_alloc_gridhead_kw(nx, ny, nz, 0); - ecl_kw_type *gridunit_kw = NULL; - ecl_grid_type *ecl_grid = ecl_grid_alloc_GRDECL_kw__( + rd_kw_type *gridhead_kw = rd_grid_alloc_gridhead_kw(nx, ny, nz, 0); + rd_kw_type *gridunit_kw = NULL; + rd_grid_type *rd_grid = rd_grid_alloc_GRDECL_kw__( NULL, FILEHEAD_SINGLE_POROSITY, apply_mapaxes, gridhead_kw, zcorn_kw, coord_kw, gridunit_kw, mapaxes_kw, NULL, actnum_data); - ecl_kw_free(gridhead_kw); - return ecl_grid; + rd_kw_free(gridhead_kw); + return rd_grid; } -static void ecl_grid_init_cell_nnc_info(ecl_grid_type *ecl_grid, - int global_index) { - ecl_cell_type *grid_cell = ecl_grid_get_cell(ecl_grid, global_index); +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); if (!grid_cell->nnc_info) - grid_cell->nnc_info = nnc_info_alloc(ecl_grid->lgr_nr); + grid_cell->nnc_info = nnc_info_alloc(rd_grid->lgr_nr); } /* - The function ecl_grid_add_self_nnc() will add a NNC connection + The function rd_grid_add_self_nnc() will add a NNC connection between two cells in the same grid. Observe that there are two peculiarities with this implementation: - 1. In the ecl_grid structure the nnc information is distributed + 1. In the rd_grid structure the nnc information is distributed among the cells. The main purpose of adding the nnc information like this is to include the NNC information in the EGRID files when writing to disk. Before being written to disk the NNC @@ -2758,32 +2738,32 @@ static void ecl_grid_init_cell_nnc_info(ecl_grid_type *ecl_grid, 2. To get valid NNC information to load in e.g. Resinsight the corresponding TRANNNC keyword must be added to the INIT file, - i.e. the calling scope must create a ecl_kw with + i.e. the calling scope must create a rd_kw with transmissibility values in parallell with adding NNC information to the grid: fortio_type * init_file = fortio_open_writer( "CASE.INIT" , ... - ecl_grid_type * grid ... - ecl_kw_type * trannnc_kw = ecl_kw_alloc( "TRANNNC" , num_nnc , ECL_FLOAT_TYPE ); + rd_grid_type * grid ... + rd_kw_type * trannnc_kw = rd_kw_alloc( "TRANNNC" , num_nnc , RD_FLOAT_TYPE ); for (int i = 0; i < num_nnc; i++) { int g1 = ... int g2 = .. float T = .. - ecl_grid_add_self_nnc( grid , g1 , g2 , i ); - ecl_kw_iset( trannnc_kw , i , T ); + rd_grid_add_self_nnc( grid , g1 , g2 , i ); + rd_kw_iset( trannnc_kw , i , T ); } ... - ecl_grid_fwrite_EGRID( grid , ... ); - ecl_kw_fwrite( trannnc_kw , init_file ); + rd_grid_fwrite_EGRID( grid , ... ); + rd_kw_fwrite( trannnc_kw , init_file ); */ -void ecl_grid_add_self_nnc(ecl_grid_type *grid, int cell_index1, - int cell_index2, int nnc_index) { - ecl_cell_type *grid_cell = ecl_grid_get_cell(grid, cell_index1); - ecl_grid_init_cell_nnc_info(grid, cell_index1); +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_grid_init_cell_nnc_info(grid, cell_index1); nnc_info_add_nnc(grid_cell->nnc_info, grid->lgr_nr, cell_index2, nnc_index); } @@ -2793,11 +2773,11 @@ void ecl_grid_add_self_nnc(ecl_grid_type *grid, int cell_index1, consecutively running nnc_index = [0,num_nnc). */ -void ecl_grid_add_self_nnc_list(ecl_grid_type *grid, const int *g1_list, - const int *g2_list, int num_nnc) { +void rd_grid_add_self_nnc_list(rd_grid_type *grid, const int *g1_list, + const int *g2_list, int num_nnc) { int i; for (i = 0; i < num_nnc; i++) - ecl_grid_add_self_nnc(grid, g1_list[i], g2_list[i], i); + rd_grid_add_self_nnc(grid, g1_list[i], g2_list[i], i); } /* @@ -2814,13 +2794,13 @@ void ecl_grid_add_self_nnc_list(ecl_grid_type *grid, const int *g1_list, NNA1 -> NNA2 For links between different LGRs */ -static void ecl_grid_init_nnc_cells(ecl_grid_type *grid1, ecl_grid_type *grid2, - const ecl_kw_type *keyword1, - const ecl_kw_type *keyword2) { +static void rd_grid_init_nnc_cells(rd_grid_type *grid1, rd_grid_type *grid2, + const rd_kw_type *keyword1, + const rd_kw_type *keyword2) { - int *grid1_nnc_cells = ecl_kw_get_int_ptr(keyword1); - int *grid2_nnc_cells = ecl_kw_get_int_ptr(keyword2); - int nnc_count = ecl_kw_get_size(keyword2); + int *grid1_nnc_cells = rd_kw_get_int_ptr(keyword1); + 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++) { @@ -2828,7 +2808,7 @@ static void ecl_grid_init_nnc_cells(ecl_grid_type *grid1, ecl_grid_type *grid2, int grid2_cell_index = grid2_nnc_cells[nnc_index] - 1; /* - In the ECLIPSE output format grids with dual porosity are (to some + In the EGRID file, grids with dual porosity are (to some extent ...) modeled as two independent grids stacked on top of eachother, where the fracture cells have global index in the range [nx*ny*nz, 2*nx*ny*nz). @@ -2846,9 +2826,9 @@ static void ecl_grid_init_nnc_cells(ecl_grid_type *grid1, ecl_grid_type *grid2, break; { - ecl_cell_type *grid1_cell = - ecl_grid_get_cell(grid1, grid1_cell_index); - ecl_grid_init_cell_nnc_info(grid1, grid1_cell_index); + rd_cell_type *grid1_cell = + rd_grid_get_cell(grid1, 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); } @@ -2858,9 +2838,8 @@ static void ecl_grid_init_nnc_cells(ecl_grid_type *grid1, ecl_grid_type *grid2, /* This function reads the non-neighbour connection data from file and initializes the grid structure with the the nnc data */ -static void ecl_grid_init_nnc(ecl_grid_type *main_grid, - ecl_file_type *ecl_file) { - int num_nnchead_kw = ecl_file_get_num_named_kw(ecl_file, NNCHEAD_KW); +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; /* @@ -2875,42 +2854,42 @@ static void ecl_grid_init_nnc(ecl_grid_type *main_grid, */ for (i = 0; i < num_nnchead_kw; i++) { - ecl_file_view_type *lgr_view = - ecl_file_alloc_global_blockview(ecl_file, NNCHEAD_KW, i); - ecl_kw_type *nnchead_kw = - ecl_file_view_iget_named_kw(lgr_view, NNCHEAD_KW, 0); - int lgr_nr = ecl_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX); - - if (ecl_file_view_has_kw(lgr_view, NNC1_KW)) { - const ecl_kw_type *nnc1 = - ecl_file_view_iget_named_kw(lgr_view, NNC1_KW, 0); - const ecl_kw_type *nnc2 = - ecl_file_view_iget_named_kw(lgr_view, NNC2_KW, 0); + rd_file_view_type *lgr_view = + rd_file_alloc_global_blockview(rd_file, NNCHEAD_KW, i); + rd_kw_type *nnchead_kw = + rd_file_view_iget_named_kw(lgr_view, NNCHEAD_KW, 0); + int lgr_nr = rd_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX); + + if (rd_file_view_has_kw(lgr_view, NNC1_KW)) { + const rd_kw_type *nnc1 = + rd_file_view_iget_named_kw(lgr_view, NNC1_KW, 0); + const rd_kw_type *nnc2 = + rd_file_view_iget_named_kw(lgr_view, NNC2_KW, 0); { - ecl_grid_type *grid = + rd_grid_type *grid = (lgr_nr > 0) - ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) + ? rd_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid; - ecl_grid_init_nnc_cells(grid, grid, nnc1, nnc2); + rd_grid_init_nnc_cells(grid, grid, nnc1, nnc2); } } - if (ecl_file_view_has_kw(lgr_view, NNCL_KW)) { - const ecl_kw_type *nncl = - ecl_file_view_iget_named_kw(lgr_view, NNCL_KW, 0); - const ecl_kw_type *nncg = - ecl_file_view_iget_named_kw(lgr_view, NNCG_KW, 0); + if (rd_file_view_has_kw(lgr_view, NNCL_KW)) { + const rd_kw_type *nncl = + rd_file_view_iget_named_kw(lgr_view, NNCL_KW, 0); + const rd_kw_type *nncg = + rd_file_view_iget_named_kw(lgr_view, NNCG_KW, 0); { - ecl_grid_type *grid = + rd_grid_type *grid = (lgr_nr > 0) - ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) + ? rd_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid; - ecl_grid_init_nnc_cells(main_grid, grid, nncg, nncl); + rd_grid_init_nnc_cells(main_grid, grid, nncg, nncl); } } - ecl_file_view_free(lgr_view); + rd_file_view_free(lgr_view); } } @@ -2919,26 +2898,26 @@ static void ecl_grid_init_nnc(ecl_grid_type *main_grid, amalgamated LGRs (that is, non-neighbour connections between two LGRs) and initializes the grid structure with the nnc data. */ -static void ecl_grid_init_nnc_amalgamated(ecl_grid_type *main_grid, - ecl_file_type *ecl_file) { - int num_nncheada_kw = ecl_file_get_num_named_kw(ecl_file, NNCHEADA_KW); +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++) { - ecl_kw_type *nncheada_kw = - ecl_file_iget_named_kw(ecl_file, NNCHEADA_KW, i); - int lgr_nr1 = ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC1_INDEX); - int lgr_nr2 = ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC2_INDEX); + 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); + int lgr_nr2 = rd_kw_iget_int(nncheada_kw, NNCHEADA_ILOC2_INDEX); - ecl_grid_type *lgr_grid1 = - ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr1); - ecl_grid_type *lgr_grid2 = - ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr2); + rd_grid_type *lgr_grid1 = + rd_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr1); + rd_grid_type *lgr_grid2 = + rd_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr2); - ecl_kw_type *nna1_kw = ecl_file_iget_named_kw(ecl_file, NNA1_KW, i); - ecl_kw_type *nna2_kw = ecl_file_iget_named_kw(ecl_file, NNA2_KW, i); + rd_kw_type *nna1_kw = rd_file_iget_named_kw(rd_file, NNA1_KW, i); + rd_kw_type *nna2_kw = rd_file_iget_named_kw(rd_file, NNA2_KW, i); - ecl_grid_init_nnc_cells(lgr_grid1, lgr_grid2, nna1_kw, nna2_kw); + rd_grid_init_nnc_cells(lgr_grid1, lgr_grid2, nna1_kw, nna2_kw); } } @@ -2952,29 +2931,29 @@ static void ecl_grid_init_nnc_amalgamated(ecl_grid_type *main_grid, The point is that external scope can create grid based on both a list of keywords, and actual data - in addition to the normal loading of a full file. Currently the 'shortcuts' - ecl_grid_alloc_grdecl_kw() and ecl_grid_alloc_grdecl_data() do not + rd_grid_alloc_grdecl_kw() and rd_grid_alloc_grdecl_data() do not support LGRs. */ -static ecl_grid_type *ecl_grid_alloc_EGRID__(ecl_grid_type *main_grid, - const ecl_file_type *ecl_file, - int grid_nr, bool apply_mapaxes, - const int *ext_actnum) { - ecl_kw_type *gridhead_kw = - ecl_file_iget_named_kw(ecl_file, GRIDHEAD_KW, grid_nr); - ecl_kw_type *zcorn_kw = ecl_file_iget_named_kw(ecl_file, ZCORN_KW, grid_nr); - ecl_kw_type *coord_kw = ecl_file_iget_named_kw(ecl_file, COORD_KW, grid_nr); - ecl_kw_type *corsnum_kw = NULL; - ecl_kw_type *actnum_kw = NULL; - ecl_kw_type *gridunit_kw = NULL; - ecl_kw_type *mapaxes_kw = NULL; +static rd_grid_type *rd_grid_alloc_EGRID__(rd_grid_type *main_grid, + const rd_file_type *rd_file, + int grid_nr, bool apply_mapaxes, + const int *ext_actnum) { + rd_kw_type *gridhead_kw = + rd_file_iget_named_kw(rd_file, GRIDHEAD_KW, grid_nr); + rd_kw_type *zcorn_kw = rd_file_iget_named_kw(rd_file, ZCORN_KW, grid_nr); + rd_kw_type *coord_kw = rd_file_iget_named_kw(rd_file, COORD_KW, grid_nr); + rd_kw_type *corsnum_kw = NULL; + rd_kw_type *actnum_kw = NULL; + rd_kw_type *gridunit_kw = NULL; + rd_kw_type *mapaxes_kw = NULL; int dualp_flag; int eclipse_version; if (grid_nr == 0) { - ecl_kw_type *filehead_kw = - ecl_file_iget_named_kw(ecl_file, FILEHEAD_KW, grid_nr); - dualp_flag = ecl_kw_iget_int(filehead_kw, FILEHEAD_DUALP_INDEX); - eclipse_version = ecl_kw_iget_int(filehead_kw, FILEHEAD_YEAR_INDEX); + rd_kw_type *filehead_kw = + rd_file_iget_named_kw(rd_file, FILEHEAD_KW, grid_nr); + dualp_flag = rd_kw_iget_int(filehead_kw, FILEHEAD_DUALP_INDEX); + eclipse_version = rd_kw_iget_int(filehead_kw, FILEHEAD_YEAR_INDEX); } else { dualp_flag = main_grid->dualp_flag; eclipse_version = main_grid->eclipse_version; @@ -2988,116 +2967,116 @@ static ecl_grid_type *ecl_grid_alloc_EGRID__(ecl_grid_type *main_grid, if (ext_actnum) actnum_data = ext_actnum; else { - if (ecl_file_get_num_named_kw(ecl_file, ACTNUM_KW) > grid_nr) { - actnum_kw = ecl_file_iget_named_kw(ecl_file, ACTNUM_KW, grid_nr); - actnum_data = ecl_kw_get_int_ptr(actnum_kw); + if (rd_file_get_num_named_kw(rd_file, ACTNUM_KW) > grid_nr) { + actnum_kw = rd_file_iget_named_kw(rd_file, ACTNUM_KW, grid_nr); + actnum_data = rd_kw_get_int_ptr(actnum_kw); } } if (grid_nr == 0) { /* MAPAXES and COARSENING only apply to the global grid. */ - if (ecl_file_has_kw(ecl_file, MAPAXES_KW)) - mapaxes_kw = ecl_file_iget_named_kw(ecl_file, MAPAXES_KW, 0); + if (rd_file_has_kw(rd_file, MAPAXES_KW)) + mapaxes_kw = rd_file_iget_named_kw(rd_file, MAPAXES_KW, 0); - if (ecl_file_has_kw(ecl_file, CORSNUM_KW)) - corsnum_kw = ecl_file_iget_named_kw(ecl_file, CORSNUM_KW, 0); + if (rd_file_has_kw(rd_file, CORSNUM_KW)) + corsnum_kw = rd_file_iget_named_kw(rd_file, CORSNUM_KW, 0); - if (ecl_file_has_kw(ecl_file, GRIDUNIT_KW)) - gridunit_kw = ecl_file_iget_named_kw(ecl_file, GRIDUNIT_KW, 0); + if (rd_file_has_kw(rd_file, GRIDUNIT_KW)) + gridunit_kw = rd_file_iget_named_kw(rd_file, GRIDUNIT_KW, 0); } { - ecl_grid_type *ecl_grid = ecl_grid_alloc_GRDECL_kw__( + rd_grid_type *rd_grid = rd_grid_alloc_GRDECL_kw__( main_grid, dualp_flag, apply_mapaxes, gridhead_kw, zcorn_kw, coord_kw, gridunit_kw, mapaxes_kw, corsnum_kw, actnum_data); - if (ECL_GRID_MAINGRID_LGR_NR != grid_nr) - ecl_grid_set_lgr_name_EGRID(ecl_grid, ecl_file, grid_nr); - ecl_grid->eclipse_version = eclipse_version; - return ecl_grid; + if (RD_GRID_MAINGRID_LGR_NR != grid_nr) + rd_grid_set_lgr_name_EGRID(rd_grid, rd_file, grid_nr); + rd_grid->eclipse_version = eclipse_version; + return rd_grid; } } -static ecl_grid_type *ecl_grid_alloc_GRID_all_grids(const char *filename) { +static rd_grid_type *rd_grid_alloc_GRID_all_grids(const char *filename) { util_abort("%s .GRID files - %s - not supported \n", __func__, filename); return NULL; } -static ecl_grid_type *ecl_grid_alloc_EGRID_all_grids(const char *grid_file, - bool apply_mapaxes, - const int *ext_actnum) { - ecl_file_enum file_type; - file_type = ecl_util_get_file_type(grid_file, NULL, NULL); - if (file_type != ECL_EGRID_FILE) +static rd_grid_type *rd_grid_alloc_EGRID_all_grids(const char *grid_file, + bool apply_mapaxes, + const int *ext_actnum) { + rd_file_enum file_type; + file_type = rd_get_file_type(grid_file, NULL, NULL); + if (file_type != RD_EGRID_FILE) util_abort( "%s: %s wrong file type - expected .EGRID file - aborting \n", __func__, grid_file); { - ecl_file_type *ecl_file = ecl_file_open(grid_file, 0); - if (ecl_file) { - int num_grid = ecl_file_get_num_named_kw(ecl_file, GRIDHEAD_KW); - ecl_grid_type *main_grid = ecl_grid_alloc_EGRID__( - NULL, ecl_file, 0, apply_mapaxes, ext_actnum); + rd_file_type *rd_file = rd_file_open(grid_file, 0); + if (rd_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++) { // The apply_mapaxes argument is ignored for LGR - // it inherits from parent anyway. - ecl_grid_type *lgr_grid = ecl_grid_alloc_EGRID__( - main_grid, ecl_file, grid_nr, false, NULL); - ecl_grid_add_lgr(main_grid, lgr_grid); + rd_grid_type *lgr_grid = rd_grid_alloc_EGRID__( + main_grid, rd_file, grid_nr, false, NULL); + rd_grid_add_lgr(main_grid, lgr_grid); { - ecl_grid_type *host_grid; - ecl_kw_type *hostnum_kw = ecl_file_iget_named_kw( - ecl_file, HOSTNUM_KW, grid_nr - 1); + rd_grid_type *host_grid; + rd_kw_type *hostnum_kw = + rd_file_iget_named_kw(rd_file, HOSTNUM_KW, grid_nr - 1); if (lgr_grid->parent_name == NULL) host_grid = main_grid; else host_grid = - ecl_grid_get_lgr(main_grid, lgr_grid->parent_name); + rd_grid_get_lgr(main_grid, lgr_grid->parent_name); - ecl_grid_install_lgr_EGRID(host_grid, lgr_grid, - ecl_kw_get_int_ptr(hostnum_kw)); + rd_grid_install_lgr_EGRID(host_grid, lgr_grid, + rd_kw_get_int_ptr(hostnum_kw)); } } main_grid->name = util_alloc_string_copy(grid_file); - ecl_grid_init_nnc(main_grid, ecl_file); - ecl_grid_init_nnc_amalgamated(main_grid, ecl_file); + rd_grid_init_nnc(main_grid, rd_file); + rd_grid_init_nnc_amalgamated(main_grid, rd_file); - ecl_file_close(ecl_file); + rd_file_close(rd_file); return main_grid; } else return NULL; } } -ecl_grid_type *ecl_grid_alloc_EGRID(const char *grid_file, bool apply_mapaxes) { - return ecl_grid_alloc_EGRID_all_grids(grid_file, apply_mapaxes, NULL); +rd_grid_type *rd_grid_alloc_EGRID(const char *grid_file, bool apply_mapaxes) { + return rd_grid_alloc_EGRID_all_grids(grid_file, apply_mapaxes, NULL); } -static ecl_grid_type *ecl_grid_alloc_GRID_data__( - ecl_grid_type *global_grid, int num_coords, ert_ecl_unit_enum unit_system, +static rd_grid_type *rd_grid_alloc_GRID_data__( + rd_grid_type *global_grid, int num_coords, ert_rd_unit_enum unit_system, int dualp_flag, bool apply_mapaxes, int nx, int ny, int nz, int grid_nr, int coords_size, int **coords, float **corners, const float *mapaxes) { if (dualp_flag != FILEHEAD_SINGLE_POROSITY) nz = nz / 2; { - ecl_grid_type *grid = ecl_grid_alloc_empty( + rd_grid_type *grid = rd_grid_alloc_empty( global_grid, unit_system, dualp_flag, nx, ny, nz, grid_nr, false); if (grid) { if (mapaxes != NULL) - ecl_grid_init_mapaxes(grid, apply_mapaxes, mapaxes); + rd_grid_init_mapaxes(grid, apply_mapaxes, mapaxes); { int index; for (index = 0; index < num_coords; index++) - ecl_grid_set_cell_GRID(grid, coords_size, coords[index], - corners[index]); + rd_grid_set_cell_GRID(grid, coords_size, coords[index], + corners[index]); } - ecl_grid_init_coarse_cells(grid); - ecl_grid_update_index(grid); - ecl_grid_taint_cells(grid); + rd_grid_init_coarse_cells(grid); + rd_grid_update_index(grid); + rd_grid_taint_cells(grid); } return grid; } @@ -3108,33 +3087,33 @@ static ecl_grid_type *ecl_grid_alloc_GRID_data__( corners[num_coords][24] */ -ecl_grid_type *ecl_grid_alloc_GRID_data(int num_coords, int nx, int ny, int nz, - int coords_size, int **coords, - float **corners, bool apply_mapaxes, - const float *mapaxes) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - return ecl_grid_alloc_GRID_data__( +rd_grid_type *rd_grid_alloc_GRID_data(int num_coords, int nx, int ny, int nz, + int coords_size, int **coords, + float **corners, bool apply_mapaxes, + const float *mapaxes) { + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + return rd_grid_alloc_GRID_data__( NULL, num_coords, unit_system, FILEHEAD_SINGLE_POROSITY, /* Does currently not support to determine dualp_flag from inspection. */ apply_mapaxes, nx, ny, nz, 0, coords_size, coords, corners, mapaxes); } -static int ecl_grid_dual_porosity_GRID_check(ecl_file_type *ecl_file) { - ecl_kw_type *dimens_kw = ecl_file_iget_named_kw(ecl_file, DIMENS_KW, 0); - int nx = ecl_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); - int ny = ecl_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); - int nz = ecl_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); +static int rd_grid_dual_porosity_GRID_check(rd_file_type *rd_file) { + rd_kw_type *dimens_kw = rd_file_iget_named_kw(rd_file, DIMENS_KW, 0); + int nx = rd_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); + int ny = rd_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); + int nz = rd_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); if ((nz % 2) == 1) return FILEHEAD_SINGLE_POROSITY; else { int dualp_flag = FILEHEAD_DUAL_POROSITY; - int num_corners = ecl_file_get_num_named_kw(ecl_file, CORNERS_KW); + int num_corners = rd_file_get_num_named_kw(rd_file, CORNERS_KW); int matrix_index = 0; int fracture_index; - ecl_kw_type *matrix_kw; - ecl_kw_type *fracture_kw; + rd_kw_type *matrix_kw; + rd_kw_type *fracture_kw; if (num_corners > nx * ny * nz) fracture_index = nx * ny * nz / 2; @@ -3143,11 +3122,11 @@ static int ecl_grid_dual_porosity_GRID_check(ecl_file_type *ecl_file) { while (true) { matrix_kw = - ecl_file_iget_named_kw(ecl_file, CORNERS_KW, matrix_index); + rd_file_iget_named_kw(rd_file, CORNERS_KW, matrix_index); fracture_kw = - ecl_file_iget_named_kw(ecl_file, CORNERS_KW, fracture_index); + rd_file_iget_named_kw(rd_file, CORNERS_KW, fracture_index); - if (!ecl_kw_equal(matrix_kw, fracture_kw)) { + if (!rd_kw_equal(matrix_kw, fracture_kw)) { dualp_flag = FILEHEAD_SINGLE_POROSITY; break; } @@ -3162,38 +3141,37 @@ static int ecl_grid_dual_porosity_GRID_check(ecl_file_type *ecl_file) { } } -static ecl_grid_type *ecl_grid_alloc_GRID__(ecl_grid_type *global_grid, - const ecl_file_type *ecl_file, - int cell_offset, int grid_nr, - int dualp_flag, - bool apply_mapaxes) { +static rd_grid_type *rd_grid_alloc_GRID__(rd_grid_type *global_grid, + const rd_file_type *rd_file, + int cell_offset, int grid_nr, + int dualp_flag, bool apply_mapaxes) { int nx, ny, nz; const float *mapaxes_data = NULL; - ecl_grid_type *grid; - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; + rd_grid_type *grid; + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; // 1: Fetching header data from the DIMENS keyword. { - ecl_kw_type *dimens_kw = - ecl_file_iget_named_kw(ecl_file, DIMENS_KW, grid_nr); - nx = ecl_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); - ny = ecl_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); - nz = ecl_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); + rd_kw_type *dimens_kw = + rd_file_iget_named_kw(rd_file, DIMENS_KW, grid_nr); + nx = rd_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); + ny = rd_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); + nz = rd_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); } // 2: Fetching the mapaxes data from the MAPAXES keyword; the // keyword is optional, and is only applicable to the global grid. { - if ((grid_nr == 0) && (ecl_file_has_kw(ecl_file, MAPAXES_KW))) { - const ecl_kw_type *mapaxes_kw = - ecl_file_iget_named_kw(ecl_file, MAPAXES_KW, 0); - mapaxes_data = ecl_grid_get_mapaxes_from_kw__(mapaxes_kw); + if ((grid_nr == 0) && (rd_file_has_kw(rd_file, MAPAXES_KW))) { + const rd_kw_type *mapaxes_kw = + rd_file_iget_named_kw(rd_file, MAPAXES_KW, 0); + mapaxes_data = rd_grid_get_mapaxes_from_kw__(mapaxes_kw); } } - if ((grid_nr == 0) && (ecl_file_has_kw(ecl_file, GRIDUNIT_KW))) - unit_system = ecl_grid_check_unit_system( - ecl_file_iget_named_kw(ecl_file, GRIDUNIT_KW, 0)); + if ((grid_nr == 0) && (rd_file_has_kw(rd_file, GRIDUNIT_KW))) + unit_system = rd_grid_check_unit_system( + rd_file_iget_named_kw(rd_file, GRIDUNIT_KW, 0)); /* The number of COORDS/CORNERS blocks depends on the GRIDFILE option @@ -3226,7 +3204,7 @@ static ecl_grid_type *ecl_grid_alloc_GRID__(ecl_grid_type *global_grid, Possible LGR cells will follow *AFTER* the first nx*ny*nz cells; the loop stops at nx*ny*nz. Additionally the LGR cells should be - discarded (by checking coords[5]) in the ecl_grid_set_cell_GRID() + discarded (by checking coords[5]) in the rd_grid_set_cell_GRID() function. */ @@ -3235,7 +3213,7 @@ static ecl_grid_type *ecl_grid_alloc_GRID__(ecl_grid_type *global_grid, if (global_grid == NULL) { /* This is the main grid - can be both nactive or nx*ny*nz coord elements. */ - int num_coords_kw = ecl_file_get_num_named_kw(ecl_file, COORDS_KW); + int num_coords_kw = rd_file_get_num_named_kw(rd_file, COORDS_KW); if (num_coords_kw >= nx * ny * nz) num_coords = nx * ny * nz; else @@ -3255,17 +3233,17 @@ static ecl_grid_type *ecl_grid_alloc_GRID__(ecl_grid_type *global_grid, (float **)util_calloc(num_coords, sizeof *corners); for (index = 0; index < num_coords; index++) { - const ecl_kw_type *coords_kw = ecl_file_iget_named_kw( - ecl_file, COORDS_KW, index + cell_offset); - const ecl_kw_type *corners_kw = ecl_file_iget_named_kw( - ecl_file, CORNERS_KW, index + cell_offset); - - coords[index] = ecl_kw_get_int_ptr(coords_kw); - corners[index] = ecl_kw_get_float_ptr(corners_kw); - coords_size = ecl_kw_get_size(coords_kw); + 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( + rd_file, CORNERS_KW, index + cell_offset); + + coords[index] = rd_kw_get_int_ptr(coords_kw); + corners[index] = rd_kw_get_float_ptr(corners_kw); + coords_size = rd_kw_get_size(coords_kw); } // Create the grid: - grid = ecl_grid_alloc_GRID_data__( + grid = rd_grid_alloc_GRID_data__( global_grid, num_coords, unit_system, dualp_flag, apply_mapaxes, nx, ny, nz, grid_nr, coords_size, coords, corners, mapaxes_data); @@ -3276,50 +3254,50 @@ static ecl_grid_type *ecl_grid_alloc_GRID__(ecl_grid_type *global_grid, } if (grid_nr > 0) - ecl_grid_set_lgr_name_GRID(grid, ecl_file, grid_nr); + rd_grid_set_lgr_name_GRID(grid, rd_file, grid_nr); return grid; } -ecl_grid_type *ecl_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes) { +rd_grid_type *rd_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes) { - ecl_file_enum file_type; - file_type = ecl_util_get_file_type(grid_file, NULL, NULL); - if (file_type != ECL_GRID_FILE) + rd_file_enum file_type; + file_type = rd_get_file_type(grid_file, NULL, NULL); + if (file_type != RD_GRID_FILE) util_abort("%s: %s wrong file type - expected .GRID file - aborting \n", __func__, grid_file); { int cell_offset = 0; - ecl_file_type *ecl_file = ecl_file_open(grid_file, 0); - int num_grid = ecl_file_get_num_named_kw(ecl_file, DIMENS_KW); - ecl_grid_type *main_grid; + 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 = ecl_grid_dual_porosity_GRID_check(ecl_file); - main_grid = ecl_grid_alloc_GRID__(NULL, ecl_file, cell_offset, 0, - dualp_flag, apply_mapaxes); - cell_offset += ecl_grid_get_global_size(main_grid); + dualp_flag = rd_grid_dual_porosity_GRID_check(rd_file); + main_grid = rd_grid_alloc_GRID__(NULL, rd_file, cell_offset, 0, + dualp_flag, apply_mapaxes); + cell_offset += rd_grid_get_global_size(main_grid); for (grid_nr = 1; grid_nr < num_grid; grid_nr++) { - ecl_grid_type *lgr_grid = ecl_grid_alloc_GRID__( - main_grid, ecl_file, cell_offset, grid_nr, dualp_flag, false); - cell_offset += ecl_grid_get_global_size(lgr_grid); - ecl_grid_add_lgr(main_grid, lgr_grid); + 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); + rd_grid_add_lgr(main_grid, lgr_grid); { - ecl_grid_type *host_grid; + rd_grid_type *host_grid; if (lgr_grid->parent_name == NULL) host_grid = main_grid; else host_grid = - ecl_grid_get_lgr(main_grid, lgr_grid->parent_name); + rd_grid_get_lgr(main_grid, lgr_grid->parent_name); - ecl_grid_install_lgr_GRID(host_grid, lgr_grid); + rd_grid_install_lgr_GRID(host_grid, lgr_grid); } } main_grid->name = util_alloc_string_copy(grid_file); - ecl_file_close(ecl_file); + rd_file_close(rd_file); return main_grid; } } @@ -3334,11 +3312,11 @@ ecl_grid_type *ecl_grid_alloc_GRID(const char *grid_file, bool apply_mapaxes) { cells and 0 for inactive cells. The actnum array can be NULL, in which case all cells will be active. */ -ecl_grid_type *ecl_grid_alloc_regular(int nx, int ny, int nz, - const double *ivec, const double *jvec, - const double *kvec, const int *actnum) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - ecl_grid_type *grid = ecl_grid_alloc_empty( +rd_grid_type *rd_grid_alloc_regular(int nx, int ny, int nz, const double *ivec, + const double *jvec, const double *kvec, + const int *actnum) { + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + rd_grid_type *grid = rd_grid_alloc_empty( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, 0, true); if (grid) { const double grid_offset[3] = {0, 0, 0}; @@ -3355,13 +3333,13 @@ ecl_grid_type *ecl_grid_alloc_regular(int nx, int ny, int nz, grid_offset[2] + i * ivec[2] + j * jvec[2] + k * kvec[2]}; - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); - ecl_cell_init_regular(cell, offset, i, j, k, global_index, - ivec, jvec, kvec, actnum); + rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + rd_cell_init_regular(cell, offset, i, j, k, global_index, + ivec, jvec, kvec, actnum); } } } - ecl_grid_update_index(grid); + rd_grid_update_index(grid); } return grid; @@ -3378,14 +3356,14 @@ ecl_grid_type *ecl_grid_alloc_regular(int nx, int ny, int nz, which case all cells will be active. */ -ecl_grid_type *ecl_grid_alloc_rectangular(int nx, int ny, int nz, double dx, - double dy, double dz, - const int *actnum) { +rd_grid_type *rd_grid_alloc_rectangular(int nx, int ny, int nz, double dx, + double dy, double dz, + const int *actnum) { const double ivec[3] = {dx, 0, 0}; const double jvec[3] = {0, dy, 0}; const double kvec[3] = {0, 0, dz}; - return ecl_grid_alloc_regular(nx, ny, nz, ivec, jvec, kvec, actnum); + return rd_grid_alloc_regular(nx, ny, nz, ivec, jvec, kvec, actnum); } /** @@ -3398,12 +3376,11 @@ ecl_grid_type *ecl_grid_alloc_rectangular(int nx, int ny, int nz, double dx, nx*ny*nz where actnum[i + j*nx + k*nx*ny] == 1 for active cells and 0 for inactive cells. The actnum array can be NULL, in which case all cells will be active. */ -ecl_grid_type *ecl_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, - const double *dxv, const double *dyv, - const double *dzv, - const int *actnum) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - ecl_grid_type *grid = ecl_grid_alloc_empty( +rd_grid_type *rd_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, + const double *dxv, const double *dyv, + const double *dzv, const int *actnum) { + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + rd_grid_type *grid = rd_grid_alloc_empty( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, /*lgr_nr=*/0, /*init_valid=*/true); if (grid) { @@ -3423,29 +3400,29 @@ ecl_grid_type *ecl_grid_alloc_dxv_dyv_dzv(int nx, int ny, int nz, offset[0] = grid_offset[0]; for (i = 0; i < nx; i++) { int global_index = i + j * nx + k * nx * ny; - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); + rd_cell_type *cell = rd_grid_get_cell(grid, global_index); ivec[0] = dxv[i]; - ecl_cell_init_regular(cell, offset, i, j, k, global_index, - ivec, jvec, kvec, actnum); + rd_cell_init_regular(cell, offset, i, j, k, global_index, + ivec, jvec, kvec, actnum); offset[0] += dxv[i]; } offset[1] += dyv[j]; } offset[2] += dzv[k]; } - ecl_grid_update_index(grid); + rd_grid_update_index(grid); } return grid; } -ecl_grid_type * -ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, - const double *dyv, const double *dzv, - const double *depthz, const int *actnum) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - ecl_grid_type *grid = ecl_grid_alloc_empty( +rd_grid_type * +rd_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, + const double *dyv, const double *dzv, + const double *depthz, const int *actnum) { + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + rd_grid_type *grid = rd_grid_alloc_empty( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, /*lgr_nr=*/0, /*init_valid=*/true); @@ -3458,7 +3435,7 @@ ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, double x0 = 0; for (i = 0; i < nx; i++) { int global_index = i + j * nx + k * nx * ny; - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); + rd_cell_type *cell = rd_grid_get_cell(grid, global_index); double z0 = depthz[i + j * (nx + 1)]; double z1 = depthz[i + 1 + j * (nx + 1)]; double z2 = depthz[i + (j + 1) * (nx + 1)]; @@ -3489,8 +3466,8 @@ ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, for (i = 0; i < nx; i++) { int g2 = i + j * nx + k * nx * ny; int g1 = i + j * nx + (k - 1) * nx * ny; - ecl_cell_type *cell2 = ecl_grid_get_cell(grid, g2); - ecl_cell_type *cell1 = ecl_grid_get_cell(grid, g1); + rd_cell_type *cell2 = rd_grid_get_cell(grid, g2); + rd_cell_type *cell1 = rd_grid_get_cell(grid, g1); int c; for (c = 0; c < 4; c++) { @@ -3509,7 +3486,7 @@ ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { int global_index = i + j * nx + k * nx * ny; - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); + rd_cell_type *cell = rd_grid_get_cell(grid, global_index); if (actnum) cell->active = actnum[global_index]; @@ -3521,7 +3498,7 @@ ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, } if (grid) - ecl_grid_update_index(grid); + rd_grid_update_index(grid); return grid; } @@ -3543,13 +3520,12 @@ ecl_grid_alloc_dxv_dyv_dzv_depthz(int nx, int ny, int nz, const double *dxv, trickery must be performed before calling this function. */ -ecl_grid_type *ecl_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, - const double *dx, const double *dy, - const double *dz, - const double *tops, - const int *actnum) { - ert_ecl_unit_enum unit_system = ECL_METRIC_UNITS; - ecl_grid_type *grid = ecl_grid_alloc_empty( +rd_grid_type *rd_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, + const double *dx, const double *dy, + const double *dz, const double *tops, + const int *actnum) { + ert_rd_unit_enum unit_system = RD_METRIC_UNITS; + rd_grid_type *grid = rd_grid_alloc_empty( NULL, unit_system, FILEHEAD_SINGLE_POROSITY, nx, ny, nz, 0, true); if (grid) { int i, j, k; @@ -3563,7 +3539,7 @@ ecl_grid_type *ecl_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, double x0 = 0; for (i = 0; i < nx; i++) { int g = i + j * nx + k * nx * ny; - ecl_cell_type *cell = ecl_grid_get_cell(grid, g); + rd_cell_type *cell = rd_grid_get_cell(grid, g); double z0 = tops[g]; point_set(&cell->corner_list[0], x0, y0[i], z0); @@ -3592,54 +3568,54 @@ ecl_grid_type *ecl_grid_alloc_dx_dy_dz_tops(int nx, int ny, int nz, } free(y0); - ecl_grid_update_index(grid); + rd_grid_update_index(grid); } return grid; } /** - This function will allocate a ecl_grid instance. As input it takes + This function will allocate a rd_grid instance. As input it takes a filename, which can be both a GRID file and an EGRID file (both formatted and unformatted). When allocating based on an EGRID file the COORDS, ZCORN and ACTNUM - keywords are extracted, and the ecl_grid_alloc_GRDECL() function is + keywords are extracted, and the rd_grid_alloc_GRDECL() function is called with these keywords. This function can be called directly with these keywords. */ -ecl_grid_type *ecl_grid_alloc__(const char *grid_file, bool apply_mapaxes) { - ecl_file_enum file_type; - ecl_grid_type *ecl_grid = NULL; +rd_grid_type *rd_grid_alloc__(const char *grid_file, bool apply_mapaxes) { + rd_file_enum file_type; + rd_grid_type *rd_grid = NULL; - file_type = ecl_util_get_file_type(grid_file, NULL, NULL); - if (file_type == ECL_GRID_FILE) - ecl_grid = ecl_grid_alloc_GRID(grid_file, apply_mapaxes); - else if (file_type == ECL_EGRID_FILE) - ecl_grid = ecl_grid_alloc_EGRID(grid_file, apply_mapaxes); + file_type = rd_get_file_type(grid_file, NULL, NULL); + if (file_type == RD_GRID_FILE) + rd_grid = rd_grid_alloc_GRID(grid_file, apply_mapaxes); + else if (file_type == RD_EGRID_FILE) + rd_grid = rd_grid_alloc_EGRID(grid_file, apply_mapaxes); else util_abort("%s must have .GRID or .EGRID file - %s not recognized \n", __func__, grid_file); - return ecl_grid; + return rd_grid; } -ecl_grid_type *ecl_grid_alloc(const char *grid_file) { +rd_grid_type *rd_grid_alloc(const char *grid_file) { bool apply_mapaxes = true; - return ecl_grid_alloc__(grid_file, apply_mapaxes); + return rd_grid_alloc__(grid_file, apply_mapaxes); } // This function is used to override use of the keyword ACTNUM from the EGRID file. // ext_actnum must have size equal to the number of cells in the main grid // if ext_actnum = NULL, actnum is taken from file, otherwise ext_actnums // determines which cells are active. -ecl_grid_type *ecl_grid_alloc_ext_actnum(const char *grid_file, - const int *ext_actnum) { - ecl_file_enum file_type = ecl_util_get_file_type(grid_file, NULL, NULL); - if (file_type == ECL_EGRID_FILE) - return ecl_grid_alloc_EGRID_all_grids(grid_file, true, ext_actnum); - else if (file_type == ECL_GRID_FILE) - ecl_grid_alloc_GRID_all_grids(grid_file); +rd_grid_type *rd_grid_alloc_ext_actnum(const char *grid_file, + const int *ext_actnum) { + rd_file_enum file_type = rd_get_file_type(grid_file, NULL, NULL); + if (file_type == RD_EGRID_FILE) + return rd_grid_alloc_EGRID_all_grids(grid_file, true, ext_actnum); + else if (file_type == RD_GRID_FILE) + rd_grid_alloc_GRID_all_grids(grid_file); else util_abort("%s must have .EGRID file - %s not recognized \n", __func__, grid_file); @@ -3647,48 +3623,48 @@ ecl_grid_type *ecl_grid_alloc_ext_actnum(const char *grid_file, return NULL; } -static void ecl_grid_file_nactive_dims(fortio_type *data_fortio, int *dims) { +static void rd_grid_file_nactive_dims(fortio_type *data_fortio, int *dims) { if (data_fortio) { - if (ecl_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { - ecl_kw_type *intehead_kw = ecl_kw_fread_alloc(data_fortio); - dims[3] = ecl_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); - ecl_kw_free(intehead_kw); + if (rd_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { + rd_kw_type *intehead_kw = rd_kw_fread_alloc(data_fortio); + dims[3] = rd_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); + rd_kw_free(intehead_kw); } } } -static bool ecl_grid_file_EGRID_dims(fortio_type *grid_fortio, - fortio_type *data_fortio, int *dims) { +static bool rd_grid_file_EGRID_dims(fortio_type *grid_fortio, + fortio_type *data_fortio, int *dims) { - if (ecl_kw_fseek_kw(GRIDHEAD_KW, false, false, grid_fortio)) { + if (rd_kw_fseek_kw(GRIDHEAD_KW, false, false, grid_fortio)) { { - ecl_kw_type *gridhead_kw = ecl_kw_fread_alloc(grid_fortio); - dims[0] = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); - dims[1] = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); - dims[2] = ecl_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); + rd_kw_type *gridhead_kw = rd_kw_fread_alloc(grid_fortio); + dims[0] = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); + dims[1] = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); + dims[2] = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); - ecl_kw_free(gridhead_kw); + rd_kw_free(gridhead_kw); } - ecl_grid_file_nactive_dims(data_fortio, dims); + rd_grid_file_nactive_dims(data_fortio, dims); return true; } else return false; } -static bool ecl_grid_file_GRID_dims(fortio_type *grid_fortio, - fortio_type *data_fortio, int *dims) { +static bool rd_grid_file_GRID_dims(fortio_type *grid_fortio, + fortio_type *data_fortio, int *dims) { - if (ecl_kw_fseek_kw(DIMENS_KW, false, false, grid_fortio)) { + if (rd_kw_fseek_kw(DIMENS_KW, false, false, grid_fortio)) { { - ecl_kw_type *dimens_kw = ecl_kw_fread_alloc(grid_fortio); - dims[0] = ecl_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); - dims[1] = ecl_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); - dims[2] = ecl_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); + rd_kw_type *dimens_kw = rd_kw_fread_alloc(grid_fortio); + dims[0] = rd_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); + dims[1] = rd_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); + dims[2] = rd_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); - ecl_kw_free(dimens_kw); + rd_kw_free(dimens_kw); } - ecl_grid_file_nactive_dims(data_fortio, dims); + rd_grid_file_nactive_dims(data_fortio, dims); return true; } else return false; @@ -3715,34 +3691,32 @@ static bool ecl_grid_file_GRID_dims(fortio_type *grid_fortio, dims vector is not touched. */ -bool ecl_grid_file_dims(const char *grid_filename, - const char *init_restart_filename, int *dims) { +bool rd_grid_file_dims(const char *grid_filename, + const char *init_restart_filename, int *dims) { bool input_file_OK = false; bool grid_fmt_file; - ecl_file_enum grid_file_type = - ecl_util_get_file_type(grid_filename, &grid_fmt_file, NULL); + rd_file_enum grid_file_type = + rd_get_file_type(grid_filename, &grid_fmt_file, NULL); - if ((grid_file_type == ECL_GRID_FILE) || - (grid_file_type == ECL_EGRID_FILE)) { + if ((grid_file_type == RD_GRID_FILE) || (grid_file_type == RD_EGRID_FILE)) { fortio_type *grid_fortio = - fortio_open_reader(grid_filename, grid_fmt_file, ECL_ENDIAN_FLIP); + fortio_open_reader(grid_filename, grid_fmt_file, RD_ENDIAN_FLIP); if (grid_fortio) { fortio_type *data_fortio = NULL; bool data_fmt_file; if (init_restart_filename) { - ecl_util_get_file_type(init_restart_filename, &data_fmt_file, - NULL); - data_fortio = fortio_open_reader( - init_restart_filename, data_fmt_file, ECL_ENDIAN_FLIP); + rd_get_file_type(init_restart_filename, &data_fmt_file, NULL); + data_fortio = fortio_open_reader(init_restart_filename, + data_fmt_file, RD_ENDIAN_FLIP); } - if (grid_file_type == ECL_GRID_FILE) + if (grid_file_type == RD_GRID_FILE) input_file_OK = - ecl_grid_file_GRID_dims(grid_fortio, data_fortio, dims); + rd_grid_file_GRID_dims(grid_fortio, data_fortio, dims); else input_file_OK = - ecl_grid_file_EGRID_dims(grid_fortio, data_fortio, dims); + rd_grid_file_EGRID_dims(grid_fortio, data_fortio, dims); if (data_fortio) fortio_fclose(data_fortio); @@ -3762,11 +3736,11 @@ bool ecl_grid_file_dims(const char *grid_filename, 1 case_input - an existing GRID/EGRID file: Just load the file - with no further ado. - 2 case_input - an existing ECLIPSE file which is not a grid file; + 2 case_input - an existing file which is not a grid file; if it has definite formatted/unformatted status look only for those GRID/EGRID with the same formatted/unformatted status. - 3 case_input is only an ECLIPSE base, look for + 3 case_input is only a basename, look for formatted/unformatted files with the correct basename. @@ -3778,31 +3752,31 @@ bool ecl_grid_file_dims(const char *grid_filename, files can be found. */ -char *ecl_grid_alloc_case_filename(const char *case_input) { - ecl_file_enum file_type; +char *rd_grid_alloc_case_filename(const char *case_input) { + rd_file_enum file_type; bool fmt_file; - file_type = ecl_util_get_file_type(case_input, &fmt_file, NULL); + file_type = rd_get_file_type(case_input, &fmt_file, NULL); - if (file_type == ECL_GRID_FILE) + if (file_type == RD_GRID_FILE) return util_alloc_string_copy(case_input); /* Case 1 */ - else if (file_type == ECL_EGRID_FILE) + else if (file_type == RD_EGRID_FILE) return util_alloc_string_copy(case_input); /* Case 1 */ else { char *grid_file = NULL; char *path; char *basename; util_alloc_file_components(case_input, &path, &basename, NULL); - if ((file_type == ECL_OTHER_FILE) || + if ((file_type == RD_OTHER_FILE) || (file_type == - ECL_DATA_FILE)) { /* Case 3 - only basename recognized */ - char *EGRID = ecl_util_alloc_filename(path, basename, - ECL_EGRID_FILE, false, -1); - char *GRID = ecl_util_alloc_filename(path, basename, ECL_GRID_FILE, - false, -1); - char *FEGRID = ecl_util_alloc_filename(path, basename, - ECL_EGRID_FILE, true, -1); - char *FGRID = ecl_util_alloc_filename(path, basename, ECL_GRID_FILE, - true, -1); + RD_DATA_FILE)) { /* Case 3 - only basename recognized */ + char *EGRID = + rd_alloc_filename(path, basename, RD_EGRID_FILE, false, -1); + char *GRID = + rd_alloc_filename(path, basename, RD_GRID_FILE, false, -1); + char *FEGRID = + rd_alloc_filename(path, basename, RD_EGRID_FILE, true, -1); + char *FGRID = + rd_alloc_filename(path, basename, RD_GRID_FILE, true, -1); if (util_file_exists(EGRID)) grid_file = util_alloc_string_copy(EGRID); @@ -3821,10 +3795,10 @@ char *ecl_grid_alloc_case_filename(const char *case_input) { free(GRID); free(FGRID); } else { /* Case 2 - we know the formatted / unformatted status. */ - char *EGRID = ecl_util_alloc_filename(path, basename, - ECL_EGRID_FILE, fmt_file, -1); - char *GRID = ecl_util_alloc_filename(path, basename, ECL_GRID_FILE, - fmt_file, -1); + char *EGRID = + rd_alloc_filename(path, basename, RD_EGRID_FILE, fmt_file, -1); + char *GRID = + rd_alloc_filename(path, basename, RD_GRID_FILE, fmt_file, -1); if (util_file_exists(EGRID)) grid_file = util_alloc_string_copy(EGRID); @@ -3838,28 +3812,27 @@ char *ecl_grid_alloc_case_filename(const char *case_input) { } } -ecl_grid_type *ecl_grid_load_case__(const char *case_input, - bool apply_mapaxes) { - ecl_grid_type *ecl_grid = NULL; - char *grid_file = ecl_grid_alloc_case_filename(case_input); +rd_grid_type *rd_grid_load_case__(const char *case_input, bool apply_mapaxes) { + rd_grid_type *rd_grid = NULL; + char *grid_file = rd_grid_alloc_case_filename(case_input); if (grid_file != NULL) { if (util_file_exists(grid_file)) - ecl_grid = ecl_grid_alloc__(grid_file, apply_mapaxes); + rd_grid = rd_grid_alloc__(grid_file, apply_mapaxes); free(grid_file); } - return ecl_grid; + return rd_grid; } -ecl_grid_type *ecl_grid_load_case(const char *case_input) { +rd_grid_type *rd_grid_load_case(const char *case_input) { bool apply_mapaxes = true; - return ecl_grid_load_case__(case_input, apply_mapaxes); + return rd_grid_load_case__(case_input, apply_mapaxes); } -bool ecl_grid_exists(const char *case_input) { +bool rd_grid_exists(const char *case_input) { bool exists = false; - char *grid_file = ecl_grid_alloc_case_filename(case_input); + char *grid_file = rd_grid_alloc_case_filename(case_input); if (grid_file != NULL) { exists = true; free(grid_file); @@ -3867,23 +3840,22 @@ bool ecl_grid_exists(const char *case_input) { return exists; } -static bool ecl_grid_compare_coarse_cells(const ecl_grid_type *g1, - const ecl_grid_type *g2, - bool verbose) { +static bool rd_grid_compare_coarse_cells(const rd_grid_type *g1, + const rd_grid_type *g2, bool verbose) { 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++) { - const ecl_coarse_cell_type *coarse_cell1 = - (const ecl_coarse_cell_type *)vector_iget_const( - g1->coarse_cells, c); - const ecl_coarse_cell_type *coarse_cell2 = - (const ecl_coarse_cell_type *)vector_iget_const( - g2->coarse_cells, c); - - equal = ecl_coarse_cell_equal(coarse_cell1, coarse_cell2); + const rd_coarse_cell_type *coarse_cell1 = + (const rd_coarse_cell_type *)vector_iget_const(g1->coarse_cells, + c); + const rd_coarse_cell_type *coarse_cell2 = + (const rd_coarse_cell_type *)vector_iget_const(g2->coarse_cells, + c); + + equal = rd_coarse_cell_equal(coarse_cell1, coarse_cell2); if (!equal) if (verbose) fprintf(stderr, "Difference in coarse cell:%d \n", c); @@ -3893,32 +3865,32 @@ static bool ecl_grid_compare_coarse_cells(const ecl_grid_type *g1, return false; } -static bool ecl_grid_compare_cells(const ecl_grid_type *g1, - const ecl_grid_type *g2, bool include_nnc, - bool verbose) { +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++) { bool this_equal = true; - ecl_cell_type *c1 = ecl_grid_get_cell(g1, g); - ecl_cell_type *c2 = ecl_grid_get_cell(g2, g); - ecl_cell_compare(c1, c2, include_nnc, &this_equal); + rd_cell_type *c1 = rd_grid_get_cell(g1, g); + rd_cell_type *c2 = rd_grid_get_cell(g2, g); + rd_cell_compare(c1, c2, include_nnc, &this_equal); if (!this_equal) { if (verbose) { int i, j, k; - ecl_grid_get_ijk1(g1, g, &i, &j, &k); + rd_grid_get_ijk1(g1, g, &i, &j, &k); printf("Difference in cell: %d : %d,%d,%d nnc_equal:%d " "Volume:%g \n", g, i, j, k, nnc_info_equal(c1->nnc_info, c2->nnc_info), - ecl_cell_get_volume(c1)); + rd_cell_get_volume(c1)); printf("-------------------------------------------------------" "----------\n"); - ecl_cell_dump_ascii(c1, i, j, k, stdout, NULL); + rd_cell_dump_ascii(c1, i, j, k, stdout, NULL); printf("-------------------------------------------------------" "----------\n"); - ecl_cell_dump_ascii(c2, i, j, k, stdout, NULL); + rd_cell_dump_ascii(c2, i, j, k, stdout, NULL); printf("-------------------------------------------------------" "----------\n"); } @@ -3929,8 +3901,8 @@ static bool ecl_grid_compare_cells(const ecl_grid_type *g1, return equal; } -static bool ecl_grid_compare_index(const ecl_grid_type *g1, - const ecl_grid_type *g2, bool verbose) { +static bool rd_grid_compare_index(const rd_grid_type *g1, + const rd_grid_type *g2, bool verbose) { bool equal = true; if (g1->total_active != g2->total_active) { @@ -3988,8 +3960,8 @@ static bool ecl_grid_compare_index(const ecl_grid_type *g1, return equal; } -static bool ecl_grid_compare_mapaxes(const ecl_grid_type *g1, - const ecl_grid_type *g2, bool verbose) { +static bool rd_grid_compare_mapaxes(const rd_grid_type *g1, + const rd_grid_type *g2, bool verbose) { bool equal = true; if (g1->use_mapaxes == g2->use_mapaxes) { if (g1->mapaxes) { @@ -4010,8 +3982,8 @@ static bool ecl_grid_compare_mapaxes(const ecl_grid_type *g1, return true all cells must be identical. */ -static bool ecl_grid_compare__(const ecl_grid_type *g1, const ecl_grid_type *g2, - bool include_nnc, bool verbose) { +static bool rd_grid_compare__(const rd_grid_type *g1, const rd_grid_type *g2, + bool include_nnc, bool verbose) { bool equal = true; if (g1->size != g2->size) @@ -4038,38 +4010,38 @@ static bool ecl_grid_compare__(const ecl_grid_type *g1, const ecl_grid_type *g2, } if (equal) - equal = ecl_grid_compare_cells(g1, g2, include_nnc, verbose); + equal = rd_grid_compare_cells(g1, g2, include_nnc, verbose); if (equal) - equal = ecl_grid_compare_index(g1, g2, true /*verbose*/); + equal = rd_grid_compare_index(g1, g2, true /*verbose*/); if (equal) - equal = ecl_grid_compare_coarse_cells(g1, g2, verbose); + equal = rd_grid_compare_coarse_cells(g1, g2, verbose); if (equal) - equal = ecl_grid_compare_mapaxes(g1, g2, verbose); + equal = rd_grid_compare_mapaxes(g1, g2, verbose); return equal; } -bool ecl_grid_compare(const ecl_grid_type *g1, const ecl_grid_type *g2, - bool include_lgr, bool include_nnc, bool verbose) { - bool equal = ecl_grid_compare__(g1, g2, include_nnc, verbose); +bool rd_grid_compare(const rd_grid_type *g1, const rd_grid_type *g2, + bool include_lgr, bool include_nnc, bool verbose) { + bool equal = rd_grid_compare__(g1, g2, include_nnc, verbose); 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); grid_nr++) { - const ecl_grid_type *lgr1 = - (const ecl_grid_type *)vector_iget_const(g1->LGR_list, - grid_nr); - const ecl_grid_type *lgr2 = - (const ecl_grid_type *)vector_iget_const(g2->LGR_list, - grid_nr); + const rd_grid_type *lgr1 = + (const rd_grid_type *)vector_iget_const(g1->LGR_list, + grid_nr); + const rd_grid_type *lgr2 = + (const rd_grid_type *)vector_iget_const(g2->LGR_list, + grid_nr); printf("Comparing lgr grid:%d \n", grid_nr); - equal = ecl_grid_compare__(lgr1, lgr2, include_nnc, verbose); + equal = rd_grid_compare__(lgr1, lgr2, include_nnc, verbose); if (!equal) break; } @@ -4089,24 +4061,24 @@ typedef enum { Returns whether the given point is contained within the minimal cube encapsulating the cell that has all faces parallel to a coordinate plane. */ -static bool ecl_grid_cube_contains(const ecl_cell_type *cell, - const point_type *p) { - if (p->z < ecl_cell_min_z(cell)) +static bool rd_grid_cube_contains(const rd_cell_type *cell, + const point_type *p) { + if (p->z < rd_cell_min_z(cell)) return false; - if (p->z > ecl_cell_max_z(cell)) + if (p->z > rd_cell_max_z(cell)) return false; - if (p->x < ecl_cell_min_x(cell)) + if (p->x < rd_cell_min_x(cell)) return false; - if (p->x > ecl_cell_max_x(cell)) + if (p->x > rd_cell_max_x(cell)) return false; - if (p->y < ecl_cell_min_y(cell)) + if (p->y < rd_cell_min_y(cell)) return false; - if (p->y > ecl_cell_max_y(cell)) + if (p->y > rd_cell_max_y(cell)) return false; return true; @@ -4115,8 +4087,8 @@ static bool ecl_grid_cube_contains(const ecl_cell_type *cell, /* Returns true if and only if p is on plane "plane" of cell when decomposed by "method". */ -static bool ecl_grid_on_plane(const ecl_cell_type *cell, const int method, - const int plane, const point_type *p) { +static bool rd_grid_on_plane(const rd_cell_type *cell, const int method, + const int plane, const point_type *p) { const point_type *p0 = &cell->corner_list[tetrahedron_permutations[method][plane][0]]; const point_type *p1 = @@ -4144,17 +4116,18 @@ static bool ecl_grid_on_plane(const ecl_cell_type *cell, const int method, Note: The correctness of this function relies *HEAVILY* on the permutation of the tetrahedrons in the decompositions. */ -static face_status_enum -ecl_grid_on_cell_face(const ecl_cell_type *cell, const int method, - const point_type *p, const bool max_i, const bool max_j, - const bool max_k) { +static face_status_enum rd_grid_on_cell_face(const rd_cell_type *cell, + const int method, + const point_type *p, + const bool max_i, const bool max_j, + const bool max_k) { int k_minus = 0, j_pluss = 1, i_minus = 2, i_pluss = 3, j_minus = 4, k_pluss = 5; bool on[6]; for (int i = 0; i < 6; ++i) { - on[i] = (ecl_grid_on_plane(cell, method, 2 * i, p) || - ecl_grid_on_plane(cell, method, 2 * i + 1, p)); + on[i] = (rd_grid_on_plane(cell, method, 2 * i, p) || + rd_grid_on_plane(cell, method, 2 * i + 1, p)); } // Not on any of the cell sides @@ -4225,7 +4198,7 @@ static bool tetrahedron_by_points_contains(const point_type *p0, Note: This function relies *HEAVILY* on the permutation of tetrahedron_permutations. */ -static bool concave_cell_contains(const ecl_cell_type *cell, int method, +static bool concave_cell_contains(const rd_cell_type *cell, int method, const point_type *p) { const point_type *dia[2][2] = { @@ -4271,14 +4244,14 @@ static bool concave_cell_contains(const ecl_cell_type *cell, int method, warning will be printed on stderr if a cell is discarded due to twist. - - See the documentation of ecl_grid_on_cell_face for caveats regarding + - See the documentation of rd_grid_on_cell_face for caveats regarding containtment of points of cell faces. */ -bool ecl_grid_cell_contains_xyz3(const ecl_grid_type *ecl_grid, int i, int j, - int k, double x, double y, double z) { +bool rd_grid_cell_contains_xyz3(const rd_grid_type *rd_grid, int i, int j, + int k, double x, double y, double z) { point_type p; - ecl_cell_type *cell = ecl_grid_get_cell( - ecl_grid, ecl_grid_get_global_index3(ecl_grid, i, j, k)); + rd_cell_type *cell = + rd_grid_get_cell(rd_grid, rd_grid_get_global_index3(rd_grid, i, j, k)); point_set(&p, x, y, z); int method = (i + j + k) % @@ -4288,22 +4261,22 @@ bool ecl_grid_cell_contains_xyz3(const ecl_grid_type *ecl_grid, int i, int j, return false; // Pruning - if (!ecl_grid_cube_contains(cell, &p)) + if (!rd_grid_cube_contains(cell, &p)) return false; // Checks if point is on one of the faces of the cell, and if so whether it // "belongs" to this cell. - bool max_i = (i == ecl_grid->nx - 1); - bool max_j = (j == ecl_grid->ny - 1); - bool max_k = (k == ecl_grid->nz - 1); + bool max_i = (i == rd_grid->nx - 1); + bool max_j = (j == rd_grid->ny - 1); + bool max_k = (k == rd_grid->nz - 1); face_status_enum face_status = - ecl_grid_on_cell_face(cell, method, &p, max_i, max_j, max_k); + rd_grid_on_cell_face(cell, method, &p, max_i, max_j, max_k); if (face_status != NOT_ON_FACE) return face_status == BELONGS_TO_CELL; // Twisted cells - if (ecl_cell_get_twist(cell) > 0) { + if (rd_cell_get_twist(cell) > 0) { fprintf(stderr, "** Warning: Point (%g,%g,%g) is in vicinity of twisted cell: " "(%d,%d,%d) - function:%s might be mistaken.\n", @@ -4315,47 +4288,45 @@ bool ecl_grid_cell_contains_xyz3(const ecl_grid_type *ecl_grid, int i, int j, return concave_cell_contains(cell, method, &p); } -bool ecl_grid_cell_contains_xyz1(const ecl_grid_type *ecl_grid, - int global_index, double x, double y, - double z) { +bool rd_grid_cell_contains_xyz1(const rd_grid_type *rd_grid, int global_index, + double x, double y, double z) { int i, j, k; - ecl_grid_get_ijk1(ecl_grid, global_index, &i, &j, &k); - return ecl_grid_cell_contains_xyz3(ecl_grid, i, j, k, x, y, z); + rd_grid_get_ijk1(rd_grid, global_index, &i, &j, &k); + return rd_grid_cell_contains_xyz3(rd_grid, i, j, k, x, y, z); } /** This function returns the global index for the cell (in layer 'k') which contains the point x,y. Observe that if you are looking for - (i,j) you must call the function ecl_grid_get_ijk1() on the return value. + (i,j) you must call the function rd_grid_get_ijk1() on the return value. */ -int ecl_grid_get_global_index_from_xy(const ecl_grid_type *ecl_grid, int k, - bool lower_layer, double x, double y) { +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 < ecl_grid->ny; j++) - for (i = 0; i < ecl_grid->nx; i++) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - if (ecl_cell_layer_contains_xy( - ecl_grid_get_cell(ecl_grid, global_index), lower_layer, x, - y)) + for (j = 0; j < rd_grid->ny; j++) + for (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)) return global_index; } return -1; /* Did not find x,y */ } -int ecl_grid_get_global_index_from_xy_top(const ecl_grid_type *ecl_grid, - double x, double y) { - return ecl_grid_get_global_index_from_xy(ecl_grid, ecl_grid->nz - 1, false, - x, y); +int rd_grid_get_global_index_from_xy_top(const rd_grid_type *rd_grid, double x, + double y) { + return rd_grid_get_global_index_from_xy(rd_grid, rd_grid->nz - 1, false, x, + y); } -int ecl_grid_get_global_index_from_xy_bottom(const ecl_grid_type *ecl_grid, - double x, double y) { - return ecl_grid_get_global_index_from_xy(ecl_grid, 0, true, x, y); +int rd_grid_get_global_index_from_xy_bottom(const rd_grid_type *rd_grid, + double x, double y) { + return rd_grid_get_global_index_from_xy(rd_grid, 0, true, x, y); } -static void ecl_grid_clear_visited(ecl_grid_type *grid) { +static void rd_grid_clear_visited(rd_grid_type *grid) { if (grid->visited == NULL) grid->visited = (bool *)util_calloc(grid->size, sizeof *grid->visited); @@ -4369,20 +4340,20 @@ static void ecl_grid_clear_visited(ecl_grid_type *grid) { /* Box coordinates are not inclusive, i.e. [i1,i2) */ -static int ecl_grid_box_contains_xyz(const ecl_grid_type *grid, int i1, int i2, - int j1, int j2, int k1, int k2, - const point_type *p) { +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++) { - global_index = ecl_grid_get_global_index3(grid, i, j, k); + global_index = rd_grid_get_global_index3(grid, i, j, k); if (!grid->visited[global_index]) { grid->visited[global_index] = true; - if (ecl_grid_cell_contains_xyz1(grid, global_index, p->x, - p->y, p->z)) { + if (rd_grid_cell_contains_xyz1(grid, global_index, p->x, + p->y, p->z)) { return global_index; } } @@ -4393,15 +4364,17 @@ static int ecl_grid_box_contains_xyz(const ecl_grid_type *grid, int i1, int i2, /** * Search for given xyz coordinate around global start_index in a box of size bx */ -static int ecl_grid_get_global_index_from_xyz_around_box( - ecl_grid_type *grid, double x, double y, double z, int start_index, int bx, - point_type *p) { +static int rd_grid_get_global_index_from_xyz_around_box(rd_grid_type *grid, + double x, double y, + double z, + int start_index, int bx, + point_type *p) { /* Try neighbours */ int i, j, k; int i1, i2, j1, j2, k1, k2; int nx, ny, nz; - ecl_grid_get_dims(grid, &nx, &ny, &nz, NULL); - ecl_grid_get_ijk1(grid, start_index, &i, &j, &k); + rd_grid_get_dims(grid, &nx, &ny, &nz, NULL); + rd_grid_get_ijk1(grid, start_index, &i, &j, &k); i1 = util_int_max(0, i - bx); j1 = util_int_max(0, j - bx); @@ -4412,7 +4385,7 @@ static int ecl_grid_get_global_index_from_xyz_around_box( k2 = util_int_min(nz, k + bx); int global_index = - ecl_grid_box_contains_xyz(grid, i1, i2, j1, j2, k1, k2, p); + rd_grid_box_contains_xyz(grid, i1, i2, j1, j2, k1, k2, p); return global_index; } @@ -4440,21 +4413,21 @@ static int ecl_grid_get_global_index_from_xyz_around_box( 3. Give up and do a linear search starting from start_index. */ -int ecl_grid_get_global_index_from_xyz(ecl_grid_type *grid, double x, double y, - double z, int start_index) { +int rd_grid_get_global_index_from_xyz(rd_grid_type *grid, double x, double y, + double z, int start_index) { int global_index; point_type p; point_set(&p, x, y, z); - ecl_grid_clear_visited(grid); + rd_grid_clear_visited(grid); if (start_index >= 0) { /* Try start index */ - if (ecl_grid_cell_contains_xyz1(grid, start_index, x, y, z)) + if (rd_grid_cell_contains_xyz1(grid, start_index, x, y, z)) return start_index; else { /* Try boxes 2, 4, 8, ..., 64 */ for (int bx = 1; bx <= 6; bx++) { - global_index = ecl_grid_get_global_index_from_xyz_around_box( + global_index = rd_grid_get_global_index_from_xyz_around_box( grid, x, y, z, start_index, 1 << bx, &p); if (global_index >= 0) return global_index; @@ -4469,27 +4442,26 @@ int ecl_grid_get_global_index_from_xyz(ecl_grid_type *grid, double x, double y, global_index = -1; for (int index = 0; index < grid->size; index++) { - if (ecl_grid_cell_contains_xyz1(grid, index, x, y, z)) + if (rd_grid_cell_contains_xyz1(grid, index, x, y, z)) return index; } return -1; } -bool ecl_grid_get_ijk_from_xyz(ecl_grid_type *grid, double x, double y, - double z, int start_index, int *i, int *j, - int *k) { - int g = ecl_grid_get_global_index_from_xyz(grid, x, y, z, start_index); +bool rd_grid_get_ijk_from_xyz(rd_grid_type *grid, double x, double y, double z, + int start_index, int *i, int *j, int *k) { + int g = rd_grid_get_global_index_from_xyz(grid, x, y, z, start_index); if (g < 0) return false; - ecl_grid_get_ijk1(grid, g, i, j, k); + rd_grid_get_ijk1(grid, g, i, j, k); return true; } -static bool ecl_grid_sublayer_contanins_xy__(const ecl_grid_type *grid, - double x, double y, int k, int i1, - int i2, int j1, int j2, - geo_polygon_type *polygon) { +static bool rd_grid_sublayer_contanins_xy__(const rd_grid_type *grid, double x, + double y, int k, int i1, int i2, + int j1, int j2, + geo_polygon_type *polygon) { int i, j; geo_polygon_reset(polygon); @@ -4497,45 +4469,45 @@ static bool ecl_grid_sublayer_contanins_xy__(const ecl_grid_type *grid, /* Bottom edge */ for (i = i1; i < i2; i++) { double corner_pos[3]; - ecl_grid_get_corner_xyz(grid, i, j1, k, &corner_pos[0], &corner_pos[1], - &corner_pos[2]); + rd_grid_get_corner_xyz(grid, i, j1, k, &corner_pos[0], &corner_pos[1], + &corner_pos[2]); geo_polygon_add_point(polygon, corner_pos[0], corner_pos[1]); } /* Right edge */ for (j = j1; j < j2; j++) { double corner_pos[3]; - ecl_grid_get_corner_xyz(grid, i2, j, k, &corner_pos[0], &corner_pos[1], - &corner_pos[2]); + rd_grid_get_corner_xyz(grid, i2, j, k, &corner_pos[0], &corner_pos[1], + &corner_pos[2]); geo_polygon_add_point(polygon, corner_pos[0], corner_pos[1]); } /* Top edge */ for (i = i2; i > i1; i--) { double corner_pos[3]; - ecl_grid_get_corner_xyz(grid, i, j2, k, &corner_pos[0], &corner_pos[1], - &corner_pos[2]); + rd_grid_get_corner_xyz(grid, i, j2, k, &corner_pos[0], &corner_pos[1], + &corner_pos[2]); geo_polygon_add_point(polygon, corner_pos[0], corner_pos[1]); } /* Left edge */ for (j = j2; j > j1; j--) { double corner_pos[3]; - ecl_grid_get_corner_xyz(grid, i1, j, k, &corner_pos[0], &corner_pos[1], - &corner_pos[2]); + rd_grid_get_corner_xyz(grid, i1, j, k, &corner_pos[0], &corner_pos[1], + &corner_pos[2]); geo_polygon_add_point(polygon, corner_pos[0], corner_pos[1]); } geo_polygon_close(polygon); return geo_polygon_contains_point__(polygon, x, y, true); } -bool ecl_grid_get_ij_from_xy(const ecl_grid_type *grid, double x, double y, - int k, int *i, int *j) { +bool rd_grid_get_ij_from_xy(const rd_grid_type *grid, double x, double y, int k, + int *i, int *j) { geo_polygon_type *polygon = geo_polygon_alloc(NULL); - int nx = ecl_grid_get_nx(grid); - int ny = ecl_grid_get_ny(grid); + int nx = rd_grid_get_nx(grid); + int ny = rd_grid_get_ny(grid); bool inside = - ecl_grid_sublayer_contanins_xy__(grid, x, y, k, 0, nx, 0, ny, polygon); + rd_grid_sublayer_contanins_xy__(grid, x, y, k, 0, nx, 0, ny, polygon); if (inside) { int i1 = 0; int i2 = nx; @@ -4545,12 +4517,12 @@ bool ecl_grid_get_ij_from_xy(const ecl_grid_type *grid, double x, double y, while (true) { if ((i2 - i1) > 1) { int ic = (i1 + i2) / 2; - if (ecl_grid_sublayer_contanins_xy__(grid, x, y, k, i1, ic, j1, - j2, polygon)) + if (rd_grid_sublayer_contanins_xy__(grid, x, y, k, i1, ic, j1, + j2, polygon)) i2 = ic; else { - if (!ecl_grid_sublayer_contanins_xy__(grid, x, y, k, ic, i2, - j1, j2, polygon)) + if (!rd_grid_sublayer_contanins_xy__(grid, x, y, k, ic, i2, + j1, j2, polygon)) util_abort("%s: point nowhere to be found ... \n", __func__); i1 = ic; @@ -4559,12 +4531,12 @@ bool ecl_grid_get_ij_from_xy(const ecl_grid_type *grid, double x, double y, if ((j2 - j1) > 1) { int jc = (j1 + j2) / 2; - if (ecl_grid_sublayer_contanins_xy__(grid, x, y, k, i1, i2, j1, - jc, polygon)) + if (rd_grid_sublayer_contanins_xy__(grid, x, y, k, i1, i2, j1, + jc, polygon)) j2 = jc; else { - if (!ecl_grid_sublayer_contanins_xy__(grid, x, y, k, i1, i2, - jc, j2, polygon)) + if (!rd_grid_sublayer_contanins_xy__(grid, x, y, k, i1, i2, + jc, j2, polygon)) util_abort("%s: point nowhere to be found ... \n", __func__); j1 = jc; @@ -4583,7 +4555,7 @@ bool ecl_grid_get_ij_from_xy(const ecl_grid_type *grid, double x, double y, return inside; } -void ecl_grid_alloc_blocking_variables(ecl_grid_type *grid, int block_dim) { +void rd_grid_alloc_blocking_variables(rd_grid_type *grid, int block_dim) { int index; grid->block_dim = block_dim; if (block_dim == 2) @@ -4600,19 +4572,19 @@ void ecl_grid_alloc_blocking_variables(ecl_grid_type *grid, int block_dim) { grid->values[index] = double_vector_alloc(0, 0.0); } -void ecl_grid_init_blocking(ecl_grid_type *grid) { +void rd_grid_init_blocking(rd_grid_type *grid) { int index; for (index = 0; index < grid->block_size; index++) double_vector_reset(grid->values[index]); grid->last_block_index = 0; } -bool ecl_grid_block_value_3d(ecl_grid_type *grid, double x, double y, double z, - double value) { +bool rd_grid_block_value_3d(rd_grid_type *grid, double x, double y, double z, + double value) { if (grid->block_dim != 3) util_abort("%s: Wrong blocking dimension \n", __func__); { - int global_index = ecl_grid_get_global_index_from_xyz( + int global_index = rd_grid_get_global_index_from_xyz( grid, x, y, z, grid->last_block_index); if (global_index >= 0) { double_vector_append(grid->values[global_index], value); @@ -4623,19 +4595,19 @@ bool ecl_grid_block_value_3d(ecl_grid_type *grid, double x, double y, double z, } } -double ecl_grid_block_eval3d(ecl_grid_type *grid, int i, int j, int k, - block_function_ftype *blockf) { - int global_index = ecl_grid_get_global_index3(grid, i, j, k); +double rd_grid_block_eval3d(rd_grid_type *grid, int i, int j, int k, + block_function_ftype *blockf) { + int global_index = rd_grid_get_global_index3(grid, i, j, k); return blockf(grid->values[global_index]); } -int ecl_grid_get_block_count3d(const ecl_grid_type *grid, int i, int j, int k) { - int global_index = ecl_grid_get_global_index3(grid, i, j, k); +int rd_grid_get_block_count3d(const rd_grid_type *grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index3(grid, i, j, k); return double_vector_size(grid->values[global_index]); } -void ecl_grid_free(ecl_grid_type *grid) { - ecl_grid_free_cells(grid); +void rd_grid_free(rd_grid_type *grid) { + rd_grid_free_cells(grid); free(grid->index_map); free(grid->inv_index_map); @@ -4649,12 +4621,12 @@ void ecl_grid_free(ecl_grid_type *grid) { double_vector_free(grid->values[i]); free(grid->values); } - if (ECL_GRID_MAINGRID_LGR_NR == grid->lgr_nr) { /* This is the main grid. */ + if (RD_GRID_MAINGRID_LGR_NR == grid->lgr_nr) { /* This is the main grid. */ vector_free(grid->LGR_list); int_vector_free(grid->lgr_index_map); } if (grid->coord_kw != NULL) - ecl_kw_free(grid->coord_kw); + rd_kw_free(grid->coord_kw); vector_free(grid->coarse_cells); free(grid->parent_name); @@ -4663,19 +4635,19 @@ void ecl_grid_free(ecl_grid_type *grid) { delete grid; } -void ecl_grid_free__(void *arg) { - ecl_grid_type *ecl_grid = ecl_grid_safe_cast(arg); - ecl_grid_free(ecl_grid); +void rd_grid_free__(void *arg) { + rd_grid_type *rd_grid = rd_grid_safe_cast(arg); + rd_grid_free(rd_grid); } -void ecl_grid_get_distance(const ecl_grid_type *grid, int global_index1, - int global_index2, double *dx, double *dy, - double *dz) { - ecl_cell_type *cell1 = ecl_grid_get_cell(grid, global_index1); - ecl_cell_type *cell2 = ecl_grid_get_cell(grid, global_index2); +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); - ecl_cell_assert_center(cell1); - ecl_cell_assert_center(cell2); + rd_cell_assert_center(cell1); + rd_cell_assert_center(cell2); { *dx = cell1->center.x - cell2->center.x; *dy = cell1->center.y - cell2->center.y; @@ -4692,7 +4664,7 @@ void ecl_grid_get_distance(const ecl_grid_type *grid, int global_index1, */ -bool ecl_grid_ijk_valid(const ecl_grid_type *grid, int i, int j, int k) { +bool rd_grid_ijk_valid(const rd_grid_type *grid, int i, int j, int k) { bool OK = false; if (i >= 0 && i < grid->nx) @@ -4703,8 +4675,8 @@ bool ecl_grid_ijk_valid(const ecl_grid_type *grid, int i, int j, int k) { return OK; } -void ecl_grid_get_dims(const ecl_grid_type *grid, int *nx, int *ny, int *nz, - int *active_size) { +void rd_grid_get_dims(const rd_grid_type *grid, int *nx, int *ny, int *nz, + int *active_size) { if (nx != NULL) *nx = grid->nx; if (ny != NULL) @@ -4715,24 +4687,22 @@ void ecl_grid_get_dims(const ecl_grid_type *grid, int *nx, int *ny, int *nz, *active_size = grid->total_active; } -int ecl_grid_get_nz(const ecl_grid_type *grid) { return grid->nz; } +int rd_grid_get_nz(const rd_grid_type *grid) { return grid->nz; } -int ecl_grid_get_nx(const ecl_grid_type *grid) { return grid->nx; } +int rd_grid_get_nx(const rd_grid_type *grid) { return grid->nx; } -int ecl_grid_get_ny(const ecl_grid_type *grid) { return grid->ny; } +int rd_grid_get_ny(const rd_grid_type *grid) { return grid->ny; } -int ecl_grid_get_nactive(const ecl_grid_type *grid) { - return grid->total_active; -} +int rd_grid_get_nactive(const rd_grid_type *grid) { return grid->total_active; } -grid_dims_type ecl_grid_iget_dims(const ecl_grid_type *grid, int grid_nr) { +grid_dims_type rd_grid_iget_dims(const rd_grid_type *grid, int grid_nr) { grid_dims_type dims; - const ecl_grid_type *lgr; + const rd_grid_type *lgr; if (grid_nr == 0) lgr = grid; else - lgr = ecl_grid_iget_lgr(grid, grid_nr - 1); + lgr = rd_grid_iget_lgr(grid, grid_nr - 1); dims.nx = lgr->nx; dims.ny = lgr->ny; @@ -4742,32 +4712,32 @@ grid_dims_type ecl_grid_iget_dims(const ecl_grid_type *grid, int grid_nr) { return dims; } -int ecl_grid_get_nactive_fracture(const ecl_grid_type *grid) { +int rd_grid_get_nactive_fracture(const rd_grid_type *grid) { return grid->total_active_fracture; } -int ecl_grid_get_parent_cell1(const ecl_grid_type *grid, int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); +int rd_grid_get_parent_cell1(const rd_grid_type *grid, int global_index) { + const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); return cell->host_cell; } -int ecl_grid_get_parent_cell3(const ecl_grid_type *grid, int i, int j, int k) { - int global_index = ecl_grid_get_global_index__(grid, i, j, k); - return ecl_grid_get_parent_cell1(grid, global_index); +int rd_grid_get_parent_cell3(const rd_grid_type *grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index__(grid, i, j, k); + return rd_grid_get_parent_cell1(grid, global_index); } /** Converts: (i,j,k) -> global_index. i,j,k are zero offset. */ -int ecl_grid_get_global_index3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - if (ecl_grid_ijk_valid(ecl_grid, i, j, k)) - return ecl_grid_get_global_index__(ecl_grid, i, j, k); +int rd_grid_get_global_index3(const rd_grid_type *rd_grid, int i, int j, + int k) { + if (rd_grid_ijk_valid(rd_grid, i, j, k)) + return rd_grid_get_global_index__(rd_grid, i, j, k); else { util_abort("%s: i,j,k = (%d,%d,%d) is invalid:\n\n nx: [0,%d>\n ny: " "[0,%d>\n nz: [0,%d>\n", - __func__, i, j, k, ecl_grid->nx, ecl_grid->ny, ecl_grid->nz); + __func__, i, j, k, rd_grid->nx, rd_grid->ny, rd_grid->nz); return -1; /* Compiler shut up. */ } } @@ -4776,14 +4746,13 @@ int ecl_grid_get_global_index3(const ecl_grid_type *ecl_grid, int i, int j, Converts: active_index -> global_index */ -int ecl_grid_get_global_index1A(const ecl_grid_type *ecl_grid, - int active_index) { - return ecl_grid->inv_index_map[active_index]; +int rd_grid_get_global_index1A(const rd_grid_type *rd_grid, int active_index) { + return rd_grid->inv_index_map[active_index]; } -int ecl_grid_get_global_index1F(const ecl_grid_type *ecl_grid, - int active_fracture_index) { - return ecl_grid->inv_fracture_index_map[active_fracture_index]; +int rd_grid_get_global_index1F(const rd_grid_type *rd_grid, + int active_fracture_index) { + return rd_grid->inv_fracture_index_map[active_fracture_index]; } /** @@ -4793,11 +4762,11 @@ int ecl_grid_get_global_index1F(const ecl_grid_type *ecl_grid, Will return -1 if the cell is not active. */ -int ecl_grid_get_active_index3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - int global_index = ecl_grid_get_global_index3( - ecl_grid, i, j, k); /* In range: [0,nx*ny*nz) */ - return ecl_grid_get_active_index1(ecl_grid, global_index); +int rd_grid_get_active_index3(const rd_grid_type *rd_grid, int i, int j, + int k) { + int global_index = rd_grid_get_global_index3( + rd_grid, i, j, k); /* In range: [0,nx*ny*nz) */ + return rd_grid_get_active_index1(rd_grid, global_index); } /** @@ -4806,16 +4775,15 @@ int ecl_grid_get_active_index3(const ecl_grid_type *ecl_grid, int i, int j, Will return -1 if the cell is not active. */ -int ecl_grid_get_active_index1(const ecl_grid_type *ecl_grid, - int global_index) { - return ecl_grid->index_map[global_index]; +int rd_grid_get_active_index1(const rd_grid_type *rd_grid, int global_index) { + return rd_grid->index_map[global_index]; } -int ecl_grid_get_active_fracture_index3(const ecl_grid_type *ecl_grid, int i, - int j, int k) { - int global_index = ecl_grid_get_global_index3( - ecl_grid, i, j, k); /* In range: [0,nx*ny*nz) */ - return ecl_grid_get_active_fracture_index1(ecl_grid, global_index); +int rd_grid_get_active_fracture_index3(const rd_grid_type *rd_grid, int i, + int j, int k) { + int global_index = rd_grid_get_global_index3( + rd_grid, i, j, k); /* In range: [0,nx*ny*nz) */ + return rd_grid_get_active_fracture_index1(rd_grid, global_index); } /** @@ -4824,12 +4792,12 @@ int ecl_grid_get_active_fracture_index3(const ecl_grid_type *ecl_grid, int i, Will return -1 if the cell is not active. */ -int ecl_grid_get_active_fracture_index1(const ecl_grid_type *ecl_grid, - int global_index) { - if (ecl_grid->fracture_index_map == NULL) +int rd_grid_get_active_fracture_index1(const rd_grid_type *rd_grid, + int global_index) { + if (rd_grid->fracture_index_map == NULL) return -1; else - return ecl_grid->fracture_index_map[global_index]; + return rd_grid->fracture_index_map[global_index]; } /* @@ -4838,8 +4806,8 @@ int ecl_grid_get_active_fracture_index1(const ecl_grid_type *ecl_grid, This function returns C-based zero offset indices. cell_ */ -void ecl_grid_get_ijk1(const ecl_grid_type *grid, int global_index, int *i, - int *j, int *k) { +void rd_grid_get_ijk1(const rd_grid_type *grid, int global_index, int *i, + int *j, int *k) { *k = global_index / (grid->nx * grid->ny); global_index -= (*k) * (grid->nx * grid->ny); *j = global_index / grid->nx; @@ -4851,15 +4819,15 @@ void ecl_grid_get_ijk1(const ecl_grid_type *grid, int global_index, int *i, Converts active_index -> (i,j,k) */ -void ecl_grid_get_ijk1A(const ecl_grid_type *ecl_grid, int active_index, int *i, - int *j, int *k) { - if (active_index >= 0 && active_index < ecl_grid->total_active) { - int global_index = ecl_grid_get_global_index1A(ecl_grid, active_index); - ecl_grid_get_ijk1(ecl_grid, global_index, i, j, k); +void rd_grid_get_ijk1A(const rd_grid_type *rd_grid, int active_index, int *i, + int *j, int *k) { + if (active_index >= 0 && active_index < rd_grid->total_active) { + int global_index = rd_grid_get_global_index1A(rd_grid, active_index); + rd_grid_get_ijk1(rd_grid, global_index, i, j, k); } else util_abort("%s: error active_index:%d invalid - grid has only:%d " "active cells. \n", - __func__, active_index, ecl_grid->total_active); + __func__, active_index, rd_grid->total_active); } /* @@ -4872,10 +4840,10 @@ void ecl_grid_get_ijk1A(const ecl_grid_type *ecl_grid, int active_index, int *i, actually is on the inside of the cell. */ -void ecl_grid_get_xyz1(const ecl_grid_type *grid, int global_index, - double *xpos, double *ypos, double *zpos) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); - ecl_cell_assert_center(cell); +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_assert_center(cell); { *xpos = cell->center.x; *ypos = cell->center.y; @@ -4883,10 +4851,10 @@ void ecl_grid_get_xyz1(const ecl_grid_type *grid, int global_index, } } -void ecl_grid_get_xyz3(const ecl_grid_type *grid, int i, int j, int k, - double *xpos, double *ypos, double *zpos) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, k); - ecl_grid_get_xyz1(grid, global_index, xpos, ypos, zpos); +void rd_grid_get_xyz3(const rd_grid_type *grid, int i, int j, int k, + double *xpos, double *ypos, double *zpos) { + const int global_index = rd_grid_get_global_index__(grid, i, j, k); + rd_grid_get_xyz1(grid, global_index, xpos, ypos, zpos); } /** @@ -4895,11 +4863,11 @@ void ecl_grid_get_xyz3(const ecl_grid_type *grid, int i, int j, int k, tetraheder decomposition for the numbering of the corners. */ -void ecl_grid_get_cell_corner_xyz1(const ecl_grid_type *grid, int global_index, - int corner_nr, double *xpos, double *ypos, - double *zpos) { +void rd_grid_get_cell_corner_xyz1(const rd_grid_type *grid, int global_index, + int corner_nr, double *xpos, double *ypos, + double *zpos) { if ((corner_nr >= 0) && (corner_nr <= 7)) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); + const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); const point_type point = cell->corner_list[corner_nr]; *xpos = point.x; *ypos = point.y; @@ -4907,9 +4875,9 @@ void ecl_grid_get_cell_corner_xyz1(const ecl_grid_type *grid, int global_index, } } -void ecl_grid_export_cell_corners1(const ecl_grid_type *grid, int global_index, - double *x, double *y, double *z) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, 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); for (int i = 0; i < 8; i++) { const point_type point = cell->corner_list[i]; x[i] = point.x; @@ -4918,16 +4886,16 @@ void ecl_grid_export_cell_corners1(const ecl_grid_type *grid, int global_index, } } -void ecl_grid_get_cell_corner_xyz3(const ecl_grid_type *grid, int i, int j, - int k, int corner_nr, double *xpos, - double *ypos, double *zpos) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, k); - ecl_grid_get_cell_corner_xyz1(grid, global_index, corner_nr, xpos, ypos, - zpos); +void rd_grid_get_cell_corner_xyz3(const rd_grid_type *grid, int i, int j, int k, + int corner_nr, double *xpos, double *ypos, + double *zpos) { + const int global_index = rd_grid_get_global_index__(grid, i, j, k); + rd_grid_get_cell_corner_xyz1(grid, global_index, corner_nr, xpos, ypos, + zpos); } -void ecl_grid_get_corner_xyz(const ecl_grid_type *grid, int i, int j, int k, - double *xpos, double *ypos, double *zpos) { +void rd_grid_get_corner_xyz(const rd_grid_type *grid, int i, int j, int k, + double *xpos, double *ypos, double *zpos) { if (i < 0 || i > grid->nx) util_abort("%s: invalid i value:%d Valid range: [0,%d] \n", __func__, i, grid->nx); @@ -4957,46 +4925,45 @@ void ecl_grid_get_corner_xyz(const ecl_grid_type *grid, int i, int j, int k, corner_nr += 4; } - ecl_grid_get_cell_corner_xyz3(grid, i, j, k, corner_nr, xpos, ypos, - zpos); + rd_grid_get_cell_corner_xyz3(grid, i, j, k, corner_nr, xpos, ypos, + zpos); } } -void ecl_grid_get_xyz1A(const ecl_grid_type *grid, int active_index, - double *xpos, double *ypos, double *zpos) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - ecl_grid_get_xyz1(grid, global_index, xpos, ypos, zpos); +void rd_grid_get_xyz1A(const rd_grid_type *grid, int active_index, double *xpos, + double *ypos, double *zpos) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + rd_grid_get_xyz1(grid, global_index, xpos, ypos, zpos); } -double ecl_grid_get_cdepth1(const ecl_grid_type *grid, int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); - ecl_cell_assert_center(cell); +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_assert_center(cell); return cell->center.z; } -double ecl_grid_get_cdepth3(const ecl_grid_type *grid, int i, int j, int k) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, k); - return ecl_grid_get_cdepth1(grid, global_index); +double rd_grid_get_cdepth3(const rd_grid_type *grid, int i, int j, int k) { + const int global_index = rd_grid_get_global_index__(grid, i, j, k); + return rd_grid_get_cdepth1(grid, global_index); } -double ecl_grid_get_cdepth1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_cdepth1(grid, global_index); +double rd_grid_get_cdepth1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_cdepth1(grid, global_index); } -int ecl_grid_locate_depth(const ecl_grid_type *grid, double depth, int i, - int j) { - if (depth < ecl_grid_get_top2(grid, i, j)) +int rd_grid_locate_depth(const rd_grid_type *grid, double depth, int i, int j) { + if (depth < rd_grid_get_top2(grid, i, j)) return -1; - else if (depth >= ecl_grid_get_bottom2(grid, i, j)) + else if (depth >= rd_grid_get_bottom2(grid, i, j)) return -1 * grid->nz; else { int k = 0; - double bottom = ecl_grid_get_top3(grid, i, j, k); + double bottom = rd_grid_get_top3(grid, i, j, k); while (true) { double top = bottom; - bottom = ecl_grid_get_bottom3(grid, i, j, k); + bottom = rd_grid_get_bottom3(grid, i, j, k); if ((depth >= top) && (depth < bottom)) return k; @@ -5013,8 +4980,8 @@ int ecl_grid_locate_depth(const ecl_grid_type *grid, double depth, int i, Returns the depth of the top surface of the cell. */ -double ecl_grid_get_top1(const ecl_grid_type *grid, int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); +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); double depth = 0; int ij; @@ -5024,33 +4991,33 @@ double ecl_grid_get_top1(const ecl_grid_type *grid, int global_index) { return depth * 0.25; } -double ecl_grid_get_top3(const ecl_grid_type *grid, int i, int j, int k) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, k); - return ecl_grid_get_top1(grid, global_index); +double rd_grid_get_top3(const rd_grid_type *grid, int i, int j, int k) { + const int global_index = rd_grid_get_global_index__(grid, i, j, k); + return rd_grid_get_top1(grid, global_index); } -double ecl_grid_get_top2(const ecl_grid_type *grid, int i, int j) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, 0); - return ecl_grid_get_top1(grid, global_index); +double rd_grid_get_top2(const rd_grid_type *grid, int i, int j) { + const int global_index = rd_grid_get_global_index__(grid, i, j, 0); + return rd_grid_get_top1(grid, global_index); } -double ecl_grid_get_bottom2(const ecl_grid_type *grid, int i, int j) { +double rd_grid_get_bottom2(const rd_grid_type *grid, int i, int j) { const int global_index = - ecl_grid_get_global_index__(grid, i, j, grid->nz - 1); - return ecl_grid_get_bottom1(grid, global_index); + rd_grid_get_global_index__(grid, i, j, grid->nz - 1); + return rd_grid_get_bottom1(grid, global_index); } -double ecl_grid_get_top1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_top1(grid, global_index); +double rd_grid_get_top1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_top1(grid, global_index); } /** Returns the depth of the bottom surface of the cell. */ -double ecl_grid_get_bottom1(const ecl_grid_type *grid, int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_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); double depth = 0; int ij; @@ -5060,18 +5027,18 @@ double ecl_grid_get_bottom1(const ecl_grid_type *grid, int global_index) { return depth * 0.25; } -double ecl_grid_get_bottom3(const ecl_grid_type *grid, int i, int j, int k) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, k); - return ecl_grid_get_bottom1(grid, global_index); +double rd_grid_get_bottom3(const rd_grid_type *grid, int i, int j, int k) { + const int global_index = rd_grid_get_global_index__(grid, i, j, k); + return rd_grid_get_bottom1(grid, global_index); } -double ecl_grid_get_bottom1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_bottom1(grid, global_index); +double rd_grid_get_bottom1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_bottom1(grid, global_index); } -double ecl_grid_get_cell_dz1(const ecl_grid_type *grid, int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); +double rd_grid_get_cell_dz1(const rd_grid_type *grid, int global_index) { + const rd_cell_type *cell = rd_grid_get_cell(grid, global_index); double dz = 0; int ij; @@ -5081,33 +5048,32 @@ double ecl_grid_get_cell_dz1(const ecl_grid_type *grid, int global_index) { return dz * 0.25; } -double ecl_grid_get_cell_dz3(const ecl_grid_type *grid, int i, int j, int k) { - const int global_index = ecl_grid_get_global_index3(grid, i, j, k); - return ecl_grid_get_cell_dz1(grid, global_index); +double rd_grid_get_cell_dz3(const rd_grid_type *grid, int i, int j, int k) { + const int global_index = rd_grid_get_global_index3(grid, i, j, k); + return rd_grid_get_cell_dz1(grid, global_index); } -double ecl_grid_get_cell_dz1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_cell_dz1(grid, global_index); +double rd_grid_get_cell_dz1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_cell_dz1(grid, global_index); } -double ecl_grid_get_cell_thickness1(const ecl_grid_type *grid, - int global_index) { - return ecl_grid_get_cell_dz1(grid, global_index); +double rd_grid_get_cell_thickness1(const rd_grid_type *grid, int global_index) { + return rd_grid_get_cell_dz1(grid, global_index); } -double ecl_grid_get_cell_thickness3(const ecl_grid_type *grid, int i, int j, - int k) { - return ecl_grid_get_cell_dz3(grid, i, j, k); +double rd_grid_get_cell_thickness3(const rd_grid_type *grid, int i, int j, + int k) { + return rd_grid_get_cell_dz3(grid, i, j, k); } -double ecl_grid_get_cell_thickness1A(const ecl_grid_type *grid, - int active_index) { - return ecl_grid_get_cell_dz1A(grid, active_index); +double rd_grid_get_cell_thickness1A(const rd_grid_type *grid, + int active_index) { + return rd_grid_get_cell_dz1A(grid, active_index); } -double ecl_grid_get_cell_dx1(const ecl_grid_type *grid, int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, 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); double dx = 0; double dy = 0; int c; @@ -5122,14 +5088,14 @@ double ecl_grid_get_cell_dx1(const ecl_grid_type *grid, int global_index) { return sqrt(dx * dx + dy * dy); } -double ecl_grid_get_cell_dx3(const ecl_grid_type *grid, int i, int j, int k) { - const int global_index = ecl_grid_get_global_index3(grid, i, j, k); - return ecl_grid_get_cell_dx1(grid, global_index); +double rd_grid_get_cell_dx3(const rd_grid_type *grid, int i, int j, int k) { + const int global_index = rd_grid_get_global_index3(grid, i, j, k); + return rd_grid_get_cell_dx1(grid, global_index); } -double ecl_grid_get_cell_dx1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_cell_dx1(grid, global_index); +double rd_grid_get_cell_dx1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_cell_dx1(grid, global_index); } /* @@ -5145,8 +5111,8 @@ double ecl_grid_get_cell_dx1A(const ecl_grid_type *grid, int active_index) { does generally not hold. */ -double ecl_grid_get_cell_dy1(const ecl_grid_type *grid, int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_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); double dx = 0; double dy = 0; @@ -5164,100 +5130,99 @@ double ecl_grid_get_cell_dy1(const ecl_grid_type *grid, int global_index) { return sqrt(dx * dx + dy * dy); } -double ecl_grid_get_cell_dy3(const ecl_grid_type *grid, int i, int j, int k) { - const int global_index = ecl_grid_get_global_index3(grid, i, j, k); - return ecl_grid_get_cell_dy1(grid, global_index); +double rd_grid_get_cell_dy3(const rd_grid_type *grid, int i, int j, int k) { + const int global_index = rd_grid_get_global_index3(grid, i, j, k); + return rd_grid_get_cell_dy1(grid, global_index); } -double ecl_grid_get_cell_dy1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_cell_dy1(grid, global_index); +double rd_grid_get_cell_dy1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_cell_dy1(grid, global_index); } -const nnc_info_type *ecl_grid_get_cell_nnc_info1(const ecl_grid_type *grid, - int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_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); return cell->nnc_info; } -const nnc_info_type *ecl_grid_get_cell_nnc_info3(const ecl_grid_type *grid, - int i, int j, int k) { - const int global_index = ecl_grid_get_global_index3(grid, i, j, k); - return ecl_grid_get_cell_nnc_info1(grid, global_index); +const nnc_info_type *rd_grid_get_cell_nnc_info3(const rd_grid_type *grid, int i, + int j, int k) { + const int global_index = rd_grid_get_global_index3(grid, i, j, k); + return rd_grid_get_cell_nnc_info1(grid, global_index); } /* Global index in [0,...,nx*ny*nz) */ -bool ecl_grid_cell_active1(const ecl_grid_type *ecl_grid, int global_index) { - if (ecl_grid->index_map[global_index] >= 0) +bool rd_grid_cell_active1(const rd_grid_type *rd_grid, int global_index) { + if (rd_grid->index_map[global_index] >= 0) return true; else return false; } -bool ecl_grid_cell_active3(const ecl_grid_type *ecl_grid, int i, int j, int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_cell_active1(ecl_grid, global_index); +bool rd_grid_cell_active3(const rd_grid_type *rd_grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_cell_active1(rd_grid, global_index); } -bool ecl_grid_cell_invalid1(const ecl_grid_type *ecl_grid, int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); +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); return GET_CELL_FLAG(cell, CELL_FLAG_TAINTED); } -bool ecl_grid_cell_invalid3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_cell_invalid1(ecl_grid, global_index); +bool rd_grid_cell_invalid3(const rd_grid_type *rd_grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_cell_invalid1(rd_grid, global_index); } -double ecl_grid_cell_invalid1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_cell_invalid1(grid, global_index); +double rd_grid_cell_invalid1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_cell_invalid1(grid, global_index); } -bool ecl_grid_cell_valid1(const ecl_grid_type *ecl_grid, int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); +bool rd_grid_cell_valid1(const rd_grid_type *rd_grid, int global_index) { + rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); if (GET_CELL_FLAG(cell, CELL_FLAG_TAINTED)) return false; else return (GET_CELL_FLAG(cell, CELL_FLAG_VALID)); } -bool ecl_grid_cell_valid3(const ecl_grid_type *ecl_grid, int i, int j, int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_cell_valid1(ecl_grid, global_index); +bool rd_grid_cell_valid3(const rd_grid_type *rd_grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_cell_valid1(rd_grid, global_index); } -double ecl_grid_cell_valid1A(const ecl_grid_type *grid, int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_cell_valid1(grid, global_index); +double rd_grid_cell_valid1A(const rd_grid_type *grid, int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_cell_valid1(grid, global_index); } -static void __assert_main_grid(const ecl_grid_type *ecl_grid) { - if (ecl_grid->lgr_nr != ECL_GRID_MAINGRID_LGR_NR) +static void __assert_main_grid(const rd_grid_type *rd_grid) { + if (rd_grid->lgr_nr != RD_GRID_MAINGRID_LGR_NR) util_abort("%s: tried to get LGR grid from another LGR_grid - only " "main grid can be used as first input \n", __func__); } /** - This functon will return a a ecl_grid instance corresponding to the + This functon will return a a rd_grid instance corresponding to the lgr with name lgr_name. The function will fail HARD if no lgr with this name is installed under the present main grid; check first - with ecl_grid_has_lgr() if you are whimp. + with rd_grid_has_lgr() if you are whimp. Leading/trailing spaces on lgr_name are stripped prior to the hash lookup. */ -ecl_grid_type *ecl_grid_get_lgr(const ecl_grid_type *main_grid, - const char *__lgr_name) { +rd_grid_type *rd_grid_get_lgr(const rd_grid_type *main_grid, + const char *__lgr_name) { __assert_main_grid(main_grid); { char *lgr_name = util_alloc_strip_copy(__lgr_name); - ecl_grid_type *lgr_grid = main_grid->LGR_hash.at(lgr_name); + rd_grid_type *lgr_grid = main_grid->LGR_hash.at(lgr_name); free(lgr_name); return lgr_grid; } @@ -5268,7 +5233,7 @@ ecl_grid_type *ecl_grid_get_lgr(const ecl_grid_type *main_grid, __lgr_name. Leading/trailing spaces are stripped before checking. */ -bool ecl_grid_has_lgr(const ecl_grid_type *main_grid, const char *__lgr_name) { +bool rd_grid_has_lgr(const rd_grid_type *main_grid, const char *__lgr_name) { if (!__lgr_name) return false; @@ -5281,7 +5246,7 @@ bool ecl_grid_has_lgr(const ecl_grid_type *main_grid, const char *__lgr_name) { } } -bool ecl_grid_has_lgr_nr(const ecl_grid_type *main_grid, int lgr_nr) { +bool rd_grid_has_lgr_nr(const rd_grid_type *main_grid, int lgr_nr) { __assert_main_grid(main_grid); { if (int_vector_size(main_grid->lgr_index_map) > lgr_nr) @@ -5291,11 +5256,11 @@ bool ecl_grid_has_lgr_nr(const ecl_grid_type *main_grid, int lgr_nr) { } } -int ecl_grid_get_num_coarse_groups(const ecl_grid_type *main_grid) { +int rd_grid_get_num_coarse_groups(const rd_grid_type *main_grid) { return vector_get_size(main_grid->coarse_cells); } -bool ecl_grid_have_coarse_cells(const ecl_grid_type *main_grid) { +bool rd_grid_have_coarse_cells(const rd_grid_type *main_grid) { if (vector_get_size(main_grid->coarse_cells) == 0) return false; else @@ -5306,22 +5271,21 @@ bool ecl_grid_have_coarse_cells(const ecl_grid_type *main_grid) { Return the number of LGR's associated with this main grid instance. The main grid is not counted. */ -int ecl_grid_get_num_lgr(const ecl_grid_type *main_grid) { +int rd_grid_get_num_lgr(const rd_grid_type *main_grid) { __assert_main_grid(main_grid); return vector_get_size(main_grid->LGR_list); } /** The lgr_index has zero offset - ecl_grid_iget_lgr( ecl_grid , 0); will return the first lgr - ecl_grid_iget_lgr( ecl_grid , 1); will return the second lgr + rd_grid_iget_lgr( rd_grid , 0); will return the first lgr + rd_grid_iget_lgr( rd_grid , 1); will return the second lgr The method will fail HARD if lgr_index is out of bounds. */ -ecl_grid_type *ecl_grid_iget_lgr(const ecl_grid_type *main_grid, - int lgr_index) { +rd_grid_type *rd_grid_iget_lgr(const rd_grid_type *main_grid, int lgr_index) { __assert_main_grid(main_grid); - return (ecl_grid_type *)vector_iget(main_grid->LGR_list, lgr_index); + return (rd_grid_type *)vector_iget(main_grid->LGR_list, lgr_index); } /* @@ -5334,12 +5298,12 @@ ecl_grid_type *ecl_grid_iget_lgr(const ecl_grid_type *main_grid, lgr_nr is 0 for all grids. */ -ecl_grid_type *ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type *main_grid, - int lgr_nr) { +rd_grid_type *rd_grid_get_lgr_from_lgr_nr(const rd_grid_type *main_grid, + int lgr_nr) { __assert_main_grid(main_grid); { int lgr_index = int_vector_iget(main_grid->lgr_index_map, lgr_nr); - return (ecl_grid_type *)vector_iget(main_grid->LGR_list, lgr_index); + return (rd_grid_type *)vector_iget(main_grid->LGR_list, lgr_index); } } @@ -5357,29 +5321,29 @@ ecl_grid_type *ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type *main_grid, deeper into the refinement hierarchy. */ -const ecl_grid_type *ecl_grid_get_cell_lgr1(const ecl_grid_type *grid, - int global_index) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); +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); return cell->lgr; } -const ecl_grid_type *ecl_grid_get_cell_lgr3(const ecl_grid_type *grid, int i, - int j, int k) { - const int global_index = ecl_grid_get_global_index__(grid, i, j, k); - return ecl_grid_get_cell_lgr1(grid, global_index); +const rd_grid_type *rd_grid_get_cell_lgr3(const rd_grid_type *grid, int i, + int j, int k) { + const int global_index = rd_grid_get_global_index__(grid, i, j, k); + return rd_grid_get_cell_lgr1(grid, global_index); } -const ecl_grid_type *ecl_grid_get_cell_lgr1A(const ecl_grid_type *grid, - int active_index) { - const int global_index = ecl_grid_get_global_index1A(grid, active_index); - return ecl_grid_get_cell_lgr1(grid, global_index); +const rd_grid_type *rd_grid_get_cell_lgr1A(const rd_grid_type *grid, + int active_index) { + const int global_index = rd_grid_get_global_index1A(grid, active_index); + return rd_grid_get_cell_lgr1(grid, global_index); } /** Will return the global grid for a lgr. If the input grid is indeed a global grid itself the function will return NULL. */ -const ecl_grid_type *ecl_grid_get_global_grid(const ecl_grid_type *grid) { +const rd_grid_type *rd_grid_get_global_grid(const rd_grid_type *grid) { return grid->global_grid; } @@ -5387,43 +5351,42 @@ const ecl_grid_type *ecl_grid_get_global_grid(const ecl_grid_type *grid) { Allocates a stringlist instance with the lookup names of the lgr names in this grid. */ -stringlist_type *ecl_grid_alloc_lgr_name_list(const ecl_grid_type *ecl_grid) { - __assert_main_grid(ecl_grid); +stringlist_type *rd_grid_alloc_lgr_name_list(const rd_grid_type *rd_grid) { + __assert_main_grid(rd_grid); { stringlist_type *s = stringlist_alloc_new(); - for (const auto &lgr_pair : ecl_grid->LGR_hash) + for (const auto &lgr_pair : rd_grid->LGR_hash) stringlist_append_copy(s, lgr_pair.first.c_str()); return s; } } -const char *ecl_grid_iget_lgr_name(const ecl_grid_type *ecl_grid, - int lgr_index) { - __assert_main_grid(ecl_grid); - if (lgr_index < (vector_get_size(ecl_grid->LGR_list))) { - const ecl_grid_type *lgr = - (const ecl_grid_type *)vector_iget(ecl_grid->LGR_list, lgr_index); +const char *rd_grid_iget_lgr_name(const rd_grid_type *rd_grid, int lgr_index) { + __assert_main_grid(rd_grid); + if (lgr_index < (vector_get_size(rd_grid->LGR_list))) { + const rd_grid_type *lgr = + (const rd_grid_type *)vector_iget(rd_grid->LGR_list, lgr_index); return lgr->name; } else return NULL; } -const char *ecl_grid_get_lgr_name(const ecl_grid_type *ecl_grid, int lgr_nr) { - __assert_main_grid(ecl_grid); +const char *rd_grid_get_lgr_name(const rd_grid_type *rd_grid, int lgr_nr) { + __assert_main_grid(rd_grid); if (lgr_nr == 0) - return ecl_grid->name; + return rd_grid->name; { - int lgr_index = int_vector_iget(ecl_grid->lgr_index_map, lgr_nr); - return ecl_grid_iget_lgr_name(ecl_grid, lgr_index); + int lgr_index = int_vector_iget(rd_grid->lgr_index_map, lgr_nr); + return rd_grid_iget_lgr_name(rd_grid, lgr_index); } } -int ecl_grid_get_lgr_nr_from_name(const ecl_grid_type *grid, const char *name) { +int rd_grid_get_lgr_nr_from_name(const rd_grid_type *grid, const char *name) { __assert_main_grid(grid); if (strcmp(name, grid->name) == 0) return 0; else { - const ecl_grid_type *lgr = ecl_grid_get_lgr(grid, name); + const rd_grid_type *lgr = rd_grid_get_lgr(grid, name); return lgr->lgr_nr; } } @@ -5436,36 +5399,33 @@ int ecl_grid_get_lgr_nr_from_name(const ecl_grid_type *grid, const char *name) { gridhead). */ -int ecl_grid_get_lgr_nr(const ecl_grid_type *ecl_grid) { - return ecl_grid->lgr_nr; -} +int rd_grid_get_lgr_nr(const rd_grid_type *rd_grid) { return rd_grid->lgr_nr; } -const char *ecl_grid_get_name(const ecl_grid_type *ecl_grid) { - return ecl_grid->name; +const char *rd_grid_get_name(const rd_grid_type *rd_grid) { + return rd_grid->name; } -int ecl_grid_get_global_size(const ecl_grid_type *ecl_grid) { - return ecl_grid->nx * ecl_grid->ny * ecl_grid->nz; +int rd_grid_get_global_size(const rd_grid_type *rd_grid) { + return rd_grid->nx * rd_grid->ny * rd_grid->nz; } -int ecl_grid_get_active_size(const ecl_grid_type *ecl_grid) { - return ecl_grid_get_nactive(ecl_grid); +int rd_grid_get_active_size(const rd_grid_type *rd_grid) { + return rd_grid_get_nactive(rd_grid); } -bool ecl_grid_cell_regular1(const ecl_grid_type *ecl_grid, int global_index) { +bool rd_grid_cell_regular1(const rd_grid_type *rd_grid, int global_index) { double x, y, z; - ecl_grid_get_xyz1(ecl_grid, global_index, &x, &y, &z); - return ecl_grid_cell_contains_xyz1(ecl_grid, global_index, x, y, z); + rd_grid_get_xyz1(rd_grid, global_index, &x, &y, &z); + return rd_grid_cell_contains_xyz1(rd_grid, global_index, x, y, z); } -bool ecl_grid_cell_regular3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_cell_regular1(ecl_grid, global_index); +bool rd_grid_cell_regular3(const rd_grid_type *rd_grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_cell_regular1(rd_grid, global_index); } /* - The function ecl_grid_get_cell_twist() is an attempt to measure how + The function rd_grid_get_cell_twist() is an attempt to measure how twisted or deformed a cell is. For a 'normal' cell the corners [0..3] will z value <= the corners [4..7]. This function will count the number of times the z value from the [4..7] is lower than the @@ -5473,147 +5433,145 @@ bool ecl_grid_cell_regular3(const ecl_grid_type *ecl_grid, int i, int j, The purpose of the function is to detect twisted cells before embarking on cell contains calculation. The current - ecl_cell_contains_xyz( ) implementation will fail badly for twisted + rd_cell_contains_xyz( ) implementation will fail badly for twisted cells. If the function return 4 you probably have an inverted z-axis! */ -int ecl_grid_get_cell_twist1(const ecl_grid_type *ecl_grid, int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); - return ecl_cell_get_twist(cell); +int rd_grid_get_cell_twist1(const rd_grid_type *rd_grid, int global_index) { + rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); + return rd_cell_get_twist(cell); } -int ecl_grid_get_cell_twist3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_get_cell_twist1(ecl_grid, global_index); +int rd_grid_get_cell_twist3(const rd_grid_type *rd_grid, int i, int j, int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_get_cell_twist1(rd_grid, global_index); } -double ecl_grid_get_cell_volume1(const ecl_grid_type *ecl_grid, - int global_index) { - ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); +double rd_grid_get_cell_volume1(const rd_grid_type *rd_grid, int global_index) { + rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); int i, j, k; - ecl_grid_get_ijk1(ecl_grid, global_index, &i, &j, &k); - return ecl_cell_get_volume(cell); + rd_grid_get_ijk1(rd_grid, global_index, &i, &j, &k); + return rd_cell_get_volume(cell); } -double ecl_grid_get_cell_volume1A(const ecl_grid_type *ecl_grid, - int active_index) { - int global_index = ecl_grid_get_global_index1A(ecl_grid, active_index); - return ecl_grid_get_cell_volume1(ecl_grid, global_index); +double rd_grid_get_cell_volume1A(const rd_grid_type *rd_grid, + int active_index) { + int global_index = rd_grid_get_global_index1A(rd_grid, active_index); + return rd_grid_get_cell_volume1(rd_grid, global_index); } -double ecl_grid_get_cell_volume3(const ecl_grid_type *ecl_grid, int i, int j, - int k) { - int global_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - return ecl_grid_get_cell_volume1(ecl_grid, global_index); +double rd_grid_get_cell_volume3(const rd_grid_type *rd_grid, int i, int j, + int k) { + int global_index = rd_grid_get_global_index3(rd_grid, i, j, k); + return rd_grid_get_cell_volume1(rd_grid, global_index); } -void ecl_grid_summarize(const ecl_grid_type *ecl_grid) { +void rd_grid_summarize(const rd_grid_type *rd_grid) { int active_cells, nx, ny, nz; - ecl_grid_get_dims(ecl_grid, &nx, &ny, &nz, &active_cells); - printf(" Name ..................: %s \n", ecl_grid->name); - printf(" Grid nr ...............: %d \n", ecl_grid->lgr_nr); + rd_grid_get_dims(rd_grid, &nx, &ny, &nz, &active_cells); + printf(" Name ..................: %s \n", rd_grid->name); + printf(" Grid nr ...............: %d \n", rd_grid->lgr_nr); printf(" Active cells ..........: %d \n", active_cells); printf(" Active fracture cells..: %d \n", - ecl_grid_get_nactive_fracture(ecl_grid)); + rd_grid_get_nactive_fracture(rd_grid)); printf(" nx ....................: %d \n", nx); printf(" ny ....................: %d \n", ny); printf(" nz ....................: %d \n", nz); printf(" Volume ................: %d \n", nx * ny * nz); - printf(" Origo X................: %10.2f \n", ecl_grid->origo[0]); - printf(" Origo Y................: %10.2f \n", ecl_grid->origo[1]); + printf(" Origo X................: %10.2f \n", rd_grid->origo[0]); + printf(" Origo Y................: %10.2f \n", rd_grid->origo[1]); - if (ECL_GRID_MAINGRID_LGR_NR == ecl_grid->lgr_nr) { + if (RD_GRID_MAINGRID_LGR_NR == rd_grid->lgr_nr) { int grid_nr; - for (grid_nr = 1; grid_nr < vector_get_size(ecl_grid->LGR_list); + for (grid_nr = 1; grid_nr < vector_get_size(rd_grid->LGR_list); grid_nr++) { printf("\n"); - ecl_grid_summarize((const ecl_grid_type *)vector_iget_const( - ecl_grid->LGR_list, grid_nr)); + rd_grid_summarize((const rd_grid_type *)vector_iget_const( + rd_grid->LGR_list, grid_nr)); } } - ecl_grid_test_lgr_consistency(ecl_grid); + rd_grid_test_lgr_consistency(rd_grid); } /** - This function is used to translate (with the help of the ecl_grid + This function is used to translate (with the help of the rd_grid functionality) i,j,k to an index which can be used to look up an - element in the ecl_kw instance. It is just a minor convenience + element in the rd_kw instance. It is just a minor convenience function. - * If the ecl_kw instance has nx*ny*nz (i,j,k) are translated to a - global index with ecl_grid_get_global_index3(). This is typically - the case when the ecl_kw instance represents a petrophysical + * If the rd_kw instance has nx*ny*nz (i,j,k) are translated to a + global index with rd_grid_get_global_index3(). This is typically + the case when the rd_kw instance represents a petrophysical property which is e.g. loaded from a INIT file. - * If the ecl_kw instance has nactive elements the (i,j,k) indices + * If the rd_kw instance has nactive elements the (i,j,k) indices are converted to an active index with - ecl_grid_get_active_index3(). This is typically the case if the - ecl_kw instance is a solution vector which has been loaded from a + rd_grid_get_active_index3(). This is typically the case if the + rd_kw instance is a solution vector which has been loaded from a restart file. If you ask for an inactive cell the function will return -1. - * If the ecl_kw instance has neither nx*ny*nz nor nactive elements + * If the rd_kw instance has neither nx*ny*nz nor nactive elements the function will fail HARD. * The return value is double, irrespective of the type of the - underlying datatype of the ecl_kw instance - the function will + underlying datatype of the rd_kw instance - the function will fail HARD if the underlying type can not be safely converted to - double, i.e. if it is not in the set [ecl_float_type , - ecl_int_type , ecl_double_type]. + double, i.e. if it is not in the set [rd_float_type , + rd_int_type , rd_double_type]. * i,j,k: C-based zero offset grid coordinates. */ -static int ecl_grid_get_property_index__(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, - int j, int k) { - int kw_size = ecl_kw_get_size(ecl_kw); +static int rd_grid_get_property_index__(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, + int k) { + int kw_size = rd_kw_get_size(rd_kw); int lookup_index = -1; - if (kw_size == ecl_grid->nx * ecl_grid->ny * ecl_grid->nz) - lookup_index = ecl_grid_get_global_index3(ecl_grid, i, j, k); - else if (kw_size == ecl_grid->total_active) + if (kw_size == rd_grid->nx * rd_grid->ny * rd_grid->nz) + lookup_index = rd_grid_get_global_index3(rd_grid, i, j, k); + else if (kw_size == rd_grid->total_active) /* Will be set to -1 if the cell is not active. */ - lookup_index = ecl_grid_get_active_index3(ecl_grid, i, j, k); + lookup_index = rd_grid_get_active_index3(rd_grid, i, j, k); else util_abort("%s: incommensurable size ... \n", __func__); return lookup_index; } -static bool ecl_grid_get_property__(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - int k, void *value) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - if (ecl_type_is_numeric(data_type)) { +static bool rd_grid_get_property__(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k, + void *value) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + if (rd_type_is_numeric(data_type)) { int lookup_index = - ecl_grid_get_property_index__(ecl_grid, ecl_kw, i, j, k); + rd_grid_get_property_index__(rd_grid, rd_kw, i, j, k); if (lookup_index >= 0) { - ecl_kw_iget(ecl_kw, lookup_index, value); + rd_kw_iget(rd_kw, lookup_index, value); return true; } else return false; } else { - util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n", - __func__, ecl_type_alloc_name(data_type), __func__); + util_abort("%s: sorry - can not lookup type:%s with %s.\n", __func__, + rd_type_alloc_name(data_type), __func__); return false; } } -double ecl_grid_get_double_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - int k) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - if (ecl_type_is_double(data_type)) { +double rd_grid_get_double_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, + int k) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + if (rd_type_is_double(data_type)) { double value; - if (ecl_grid_get_property__(ecl_grid, ecl_kw, i, j, k, &value)) + if (rd_grid_get_property__(rd_grid, rd_kw, i, j, k, &value)) return value; else return -1; // (i,j,k) Points to an inactive cell. @@ -5623,13 +5581,13 @@ double ecl_grid_get_double_property(const ecl_grid_type *ecl_grid, } } -int ecl_grid_get_int_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, int k) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - if (ecl_type_is_int(data_type)) { +int rd_grid_get_int_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + if (rd_type_is_int(data_type)) { int value; - if (ecl_grid_get_property__(ecl_grid, ecl_kw, i, j, k, &value)) + if (rd_grid_get_property__(rd_grid, rd_kw, i, j, k, &value)) return value; else return -1; // (i,j,k) Points to an inactive cell. @@ -5640,14 +5598,13 @@ int ecl_grid_get_int_property(const ecl_grid_type *ecl_grid, } } -float ecl_grid_get_float_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - int k) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - if (ecl_type_is_float(data_type)) { +float rd_grid_get_float_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + if (rd_type_is_float(data_type)) { float value; - if (ecl_grid_get_property__(ecl_grid, ecl_kw, i, j, k, &value)) + if (rd_grid_get_property__(rd_grid, rd_kw, i, j, k, &value)) return value; else return -1; // (i,j,k) Points to an inactive cell. @@ -5658,84 +5615,84 @@ float ecl_grid_get_float_property(const ecl_grid_type *ecl_grid, } } -double ecl_grid_get_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, int k) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - if (ecl_type_is_numeric(data_type)) { +double rd_grid_get_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, int k) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + if (rd_type_is_numeric(data_type)) { int lookup_index = - ecl_grid_get_property_index__(ecl_grid, ecl_kw, i, j, k); + rd_grid_get_property_index__(rd_grid, rd_kw, i, j, k); if (lookup_index >= 0) - return ecl_kw_iget_as_double(ecl_kw, lookup_index); + return rd_kw_iget_as_double(rd_kw, lookup_index); else return -1; /* Tried to lookup an inactive cell. */ } else { - util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n", - __func__, ecl_type_alloc_name(data_type), __func__); + util_abort("%s: sorry - can not lookup type:%s with %s.\n", __func__, + rd_type_alloc_name(data_type), __func__); return -1; } } /** Will fill the double_vector instance @column with values from - ecl_kw from the column given by (i,j). If @ecl_kw has size nactive + rd_kw from the column given by (i,j). If @rd_kw has size nactive the inactive k values will not be set, i.e. you should make sure that the default value of the @column instance has been properly set beforehand. The column vector will be filled with double values, the content of - ecl_kw will be converted to double in the case INTE,REAL and DOUB + rd_kw will be converted to double in the case INTE,REAL and DOUB types, otherwsie it is crash and burn. */ -void ecl_grid_get_column_property(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, int i, int j, - double_vector_type *column) { - ecl_data_type data_type = ecl_kw_get_data_type(ecl_kw); - if (ecl_type_is_numeric(data_type)) { - int kw_size = ecl_kw_get_size(ecl_kw); +void rd_grid_get_column_property(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, int i, int j, + double_vector_type *column) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + if (rd_type_is_numeric(data_type)) { + int kw_size = rd_kw_get_size(rd_kw); bool use_global_index = false; - if (kw_size == ecl_grid->nx * ecl_grid->ny * ecl_grid->nz) + if (kw_size == rd_grid->nx * rd_grid->ny * rd_grid->nz) use_global_index = true; - else if (kw_size == ecl_grid->total_active) + else if (kw_size == rd_grid->total_active) use_global_index = false; else util_abort("%s: incommensurable sizes: nx*ny*nz = %d nactive=%d " "kw_size:%d \n", - __func__, ecl_grid->size, ecl_grid->total_active, - ecl_kw_get_size(ecl_kw)); + __func__, rd_grid->size, rd_grid->total_active, + rd_kw_get_size(rd_kw)); double_vector_reset(column); { int k; - for (k = 0; k < ecl_grid->nz; k++) { + for (k = 0; k < rd_grid->nz; k++) { if (use_global_index) { int global_index = - ecl_grid_get_global_index3(ecl_grid, i, j, k); + rd_grid_get_global_index3(rd_grid, i, j, k); double_vector_iset( - column, k, ecl_kw_iget_as_double(ecl_kw, global_index)); + column, k, rd_kw_iget_as_double(rd_kw, global_index)); } else { int active_index = - ecl_grid_get_active_index3(ecl_grid, i, j, k); + rd_grid_get_active_index3(rd_grid, i, j, k); if (active_index >= 0) double_vector_iset( column, k, - ecl_kw_iget_as_double(ecl_kw, active_index)); + rd_kw_iget_as_double(rd_kw, active_index)); } } } } else - util_abort("%s: sorry - can not lookup ECLIPSE type:%s with %s.\n", - __func__, ecl_type_alloc_name(data_type), __func__); + util_abort("%s: sorry - can not lookup type:%s with %s.\n", __func__, + rd_type_alloc_name(data_type), __func__); } /** This function will look up all the indices in the grid where the - region_kw has a certain value (region_value). The ecl_kw instance + region_kw has a certain value (region_value). The rd_kw instance must be loaded beforehand, typically with the functions - ecl_kw_grdecl_fseek_kw / ecl_kw_fscanf_alloc_grdecl_data. + rd_kw_grdecl_fseek_kw / rd_kw_fscanf_alloc_grdecl_data. The two boolean flags active_only and export_active_index determine how active/inactive indieces should be handled: @@ -5749,39 +5706,39 @@ void ecl_grid_get_column_property(const ecl_grid_type *ecl_grid, cell is in the space of active cells, otherwise it is in terms of the global indexing. - Observe the following about the ecl_kw instance wth region data: + Observe the following about the rd_kw instance wth region data: * It must be of type integer - otherwise we blow up hard. The * size must be the total number of cells (should handle boxes and so on ...) Observe that there is no way to get ijk from this function, then - you must call ecl_grid_get_ijk() afterwards. the return value is + you must call rd_grid_get_ijk() afterwards. the return value is the number of cells found. */ -int ecl_grid_get_region_cells(const ecl_grid_type *ecl_grid, - const ecl_kw_type *region_kw, int region_value, - bool active_only, bool export_active_index, - int_vector_type *index_list) { +int rd_grid_get_region_cells(const rd_grid_type *rd_grid, + const rd_kw_type *region_kw, int region_value, + bool active_only, bool export_active_index, + int_vector_type *index_list) { int cells_found = 0; - if (ecl_kw_get_size(region_kw) == ecl_grid->size) { - if (ecl_type_is_int(ecl_kw_get_data_type(region_kw))) { - const int *region_ptr = (const int *)ecl_kw_iget_ptr(region_kw, 0); + if (rd_kw_get_size(region_kw) == rd_grid->size) { + if (rd_type_is_int(rd_kw_get_data_type(region_kw))) { + const int *region_ptr = (const int *)rd_kw_iget_ptr(region_kw, 0); int_vector_reset(index_list); { int global_index; - for (global_index = 0; global_index < ecl_grid->size; + for (global_index = 0; global_index < rd_grid->size; global_index++) { if (region_ptr[global_index] == region_value) { if (!active_only || - (ecl_grid->index_map[global_index] >= 0)) { + (rd_grid->index_map[global_index] >= 0)) { /* Okay - this index should be included */ if (export_active_index) int_vector_iset( index_list, cells_found, - ecl_grid->index_map[global_index]); + rd_grid->index_map[global_index]); else int_vector_iset(index_list, cells_found, global_index); @@ -5798,39 +5755,38 @@ int ecl_grid_get_region_cells(const ecl_grid_type *ecl_grid, } else util_abort( "%s: size mismatch grid has %d cells - region specifier:%d \n", - __func__, ecl_grid->size, ecl_kw_get_size(region_kw)); + __func__, rd_grid->size, rd_kw_get_size(region_kw)); return cells_found; } -void ecl_grid_grdecl_fprintf_kw(const ecl_grid_type *ecl_grid, - const ecl_kw_type *ecl_kw, - const char *special_header, FILE *stream, - double double_default) { - int src_size = ecl_kw_get_size(ecl_kw); - if (src_size == ecl_grid->size) - ecl_kw_fprintf_grdecl__(ecl_kw, special_header, stream); - else if (src_size == ecl_grid->total_active) { +void rd_grid_grdecl_fprintf_kw(const rd_grid_type *rd_grid, + const rd_kw_type *rd_kw, + const char *special_header, FILE *stream, + double double_default) { + int src_size = rd_kw_get_size(rd_kw); + if (src_size == rd_grid->size) + rd_kw_fprintf_grdecl__(rd_kw, special_header, stream); + else if (src_size == rd_grid->total_active) { void *default_ptr = NULL; float float_default; int int_default; int bool_default; - ecl_type_enum ecl_type = - ecl_type_get_type(ecl_kw_get_data_type(ecl_kw)); + rd_type_enum rd_type = rd_type_get_type(rd_kw_get_data_type(rd_kw)); - if (ecl_type == ECL_FLOAT_TYPE) { + if (rd_type == RD_FLOAT_TYPE) { float_default = (float)double_default; default_ptr = &float_default; - } else if (ecl_type == ECL_INT_TYPE) { + } else if (rd_type == RD_INT_TYPE) { int_default = (int)double_default; default_ptr = &int_default; - } else if (ecl_type == ECL_DOUBLE_TYPE) { + } else if (rd_type == RD_DOUBLE_TYPE) { default_ptr = &double_default; - } else if (ecl_type == ECL_BOOL_TYPE) { + } else if (rd_type == RD_BOOL_TYPE) { int tmp = (int)double_default; if (tmp == 1) - bool_default = ECL_BOOL_TRUE_INT; + bool_default = RD_BOOL_TRUE_INT; else if (tmp == 0) - bool_default = ECL_BOOL_FALSE_INT; + bool_default = RD_BOOL_FALSE_INT; else util_abort( "%s: only 0 and 1 are allowed for bool interpolation\n", @@ -5842,27 +5798,27 @@ void ecl_grid_grdecl_fprintf_kw(const ecl_grid_type *ecl_grid, util_abort("%s: invalid type \n", __func__); { - ecl_kw_type *tmp_kw = ecl_kw_alloc_scatter_copy( - ecl_kw, ecl_grid->size, ecl_grid->inv_index_map, default_ptr); - ecl_kw_fprintf_grdecl__(tmp_kw, special_header, stream); - ecl_kw_free(tmp_kw); + rd_kw_type *tmp_kw = rd_kw_alloc_scatter_copy( + rd_kw, rd_grid->size, rd_grid->inv_index_map, default_ptr); + rd_kw_fprintf_grdecl__(tmp_kw, special_header, stream); + rd_kw_free(tmp_kw); } } else - util_abort("%s: size mismatch. ecl_kw must have either nx*ny*ny " + util_abort("%s: size mismatch. rd_kw must have either nx*ny*ny " "elements or nactive elements\n", __func__); } -static bool ecl_grid_test_lgr_consistency2(const ecl_grid_type *parent, - const ecl_grid_type *child) { +static bool rd_grid_test_lgr_consistency2(const rd_grid_type *parent, + const rd_grid_type *child) { bool consistent = true; - int child_size = ecl_grid_get_global_size(child); + int child_size = rd_grid_get_global_size(child); int child_index; for (child_index = 0; child_index < child_size; child_index++) { - int parent_cell = ecl_grid_get_parent_cell1(child, child_index); + int parent_cell = rd_grid_get_parent_cell1(child, child_index); if (parent_cell >= 0) { - const ecl_grid_type *child_test = - ecl_grid_get_cell_lgr1(parent, parent_cell); + const rd_grid_type *child_test = + rd_grid_get_cell_lgr1(parent, parent_cell); if (child != child_test) { fprintf(stderr, "Child parent mapping failure : ptr difference.\n"); @@ -5877,17 +5833,17 @@ static bool ecl_grid_test_lgr_consistency2(const ecl_grid_type *parent, return consistent; } -bool ecl_grid_test_lgr_consistency(const ecl_grid_type *ecl_grid) { +bool rd_grid_test_lgr_consistency(const rd_grid_type *rd_grid) { bool consistent = true; - for (const auto &lgr_pair : ecl_grid->children) { - const ecl_grid_type *lgr = lgr_pair.second; - consistent &= ecl_grid_test_lgr_consistency2(ecl_grid, lgr); - consistent &= ecl_grid_test_lgr_consistency(lgr); + for (const auto &lgr_pair : rd_grid->children) { + const rd_grid_type *lgr = lgr_pair.second; + consistent &= rd_grid_test_lgr_consistency2(rd_grid, lgr); + consistent &= rd_grid_test_lgr_consistency(lgr); } return consistent; } -static void ecl_grid_dump__(const ecl_grid_type *grid, FILE *stream) { +static void rd_grid_dump__(const rd_grid_type *grid, FILE *stream) { util_fwrite_int(grid->lgr_nr, stream); util_fwrite_string(grid->name, stream); util_fwrite_int(grid->nx, stream); @@ -5902,14 +5858,14 @@ static void ecl_grid_dump__(const ecl_grid_type *grid, FILE *stream) { { int i; for (i = 0; i < grid->size; i++) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, i); - ecl_cell_dump(cell, stream); + const rd_cell_type *cell = rd_grid_get_cell(grid, i); + rd_cell_dump(cell, stream); } } } -static void ecl_grid_dump_ascii__(ecl_grid_type *grid, bool active_only, - FILE *stream) { +static void rd_grid_dump_ascii__(rd_grid_type *grid, bool active_only, + FILE *stream) { fprintf(stream, "Grid nr : %d\n", grid->lgr_nr); fprintf(stream, "Grid name : %s\n", grid->name); fprintf(stream, "nx : %6d\n", grid->nx); @@ -5921,11 +5877,11 @@ static void ecl_grid_dump_ascii__(ecl_grid_type *grid, bool active_only, { int l; for (l = 0; l < grid->size; l++) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, l); + rd_cell_type *cell = rd_grid_get_cell(grid, l); if (cell->active_index[MATRIX_INDEX] >= 0 || !active_only) { int i, j, k; - ecl_grid_get_ijk1(grid, l, &i, &j, &k); - ecl_cell_dump_ascii(cell, i, j, k, stream, NULL); + rd_grid_get_ijk1(grid, l, &i, &j, &k); + rd_cell_dump_ascii(cell, i, j, k, stream, NULL); } } } @@ -5939,41 +5895,40 @@ static void ecl_grid_dump_ascii__(ecl_grid_type *grid, bool active_only, to be read. */ -void ecl_grid_dump(const ecl_grid_type *grid, FILE *stream) { - ecl_grid_dump__(grid, stream); +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++) - ecl_grid_dump__( - (const ecl_grid_type *)vector_iget_const(grid->LGR_list, i), + rd_grid_dump__( + (const rd_grid_type *)vector_iget_const(grid->LGR_list, i), stream); } } -void ecl_grid_dump_ascii(ecl_grid_type *grid, bool active_only, FILE *stream) { - ecl_grid_dump_ascii__(grid, active_only, 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++) - ecl_grid_dump_ascii__( - (ecl_grid_type *)vector_iget(grid->LGR_list, i), active_only, - stream); + rd_grid_dump_ascii__((rd_grid_type *)vector_iget(grid->LGR_list, i), + active_only, stream); } } -void ecl_grid_dump_ascii_cell1(ecl_grid_type *grid, int global_index, - FILE *stream, const double *offset) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); +void rd_grid_dump_ascii_cell1(rd_grid_type *grid, int global_index, + FILE *stream, const double *offset) { + rd_cell_type *cell = rd_grid_get_cell(grid, global_index); int i, j, k; - ecl_grid_get_ijk1(grid, global_index, &i, &j, &k); - ecl_cell_dump_ascii(cell, i, j, k, stream, offset); + rd_grid_get_ijk1(grid, global_index, &i, &j, &k); + rd_cell_dump_ascii(cell, i, j, k, stream, offset); } -void ecl_grid_dump_ascii_cell3(ecl_grid_type *grid, int i, int j, int k, - FILE *stream, const double *offset) { - int global_index = ecl_grid_get_global_index3(grid, i, j, k); - ecl_cell_type *cell = ecl_grid_get_cell(grid, global_index); - ecl_cell_dump_ascii(cell, i, j, k, stream, offset); +void rd_grid_dump_ascii_cell3(rd_grid_type *grid, int i, int j, int k, + FILE *stream, const double *offset) { + int global_index = rd_grid_get_global_index3(grid, i, j, k); + rd_cell_type *cell = rd_grid_get_cell(grid, global_index); + rd_cell_dump_ascii(cell, i, j, k, stream, offset); } /* @@ -6005,179 +5960,177 @@ void ecl_grid_dump_ascii_cell3(ecl_grid_type *grid, int i, int j, int k, ... */ -bool ecl_grid_use_mapaxes(const ecl_grid_type *grid) { - return grid->use_mapaxes; -} +bool rd_grid_use_mapaxes(const rd_grid_type *grid) { return grid->use_mapaxes; } -void ecl_grid_init_mapaxes_data_double(const ecl_grid_type *grid, - double *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 ecl_grid_init_mapaxes_data_float(const ecl_grid_type *grid, - float *mapaxes) { +static void rd_grid_init_mapaxes_data_float(const rd_grid_type *grid, + float *mapaxes) { int i; for (i = 0; i < 6; i++) mapaxes[i] = grid->mapaxes[i]; } -static const float *ecl_grid_get_mapaxes(const ecl_grid_type *grid) { +static const float *rd_grid_get_mapaxes(const rd_grid_type *grid) { return grid->mapaxes; } -ecl_kw_type *ecl_grid_alloc_mapaxes_kw(const ecl_grid_type *grid) { - return ecl_kw_alloc_new(MAPAXES_KW, 6, ECL_FLOAT, grid->mapaxes); +rd_kw_type *rd_grid_alloc_mapaxes_kw(const rd_grid_type *grid) { + return rd_kw_alloc_new(MAPAXES_KW, 6, RD_FLOAT, grid->mapaxes); } -static ecl_kw_type *ecl_grid_alloc_mapunits_kw(ert_ecl_unit_enum output_unit) { - ecl_kw_type *mapunits_kw = ecl_kw_alloc(MAPUNITS_KW, 1, ECL_CHAR); +static rd_kw_type *rd_grid_alloc_mapunits_kw(ert_rd_unit_enum output_unit) { + rd_kw_type *mapunits_kw = rd_kw_alloc(MAPUNITS_KW, 1, RD_CHAR); - if (output_unit == ECL_FIELD_UNITS) - ecl_kw_iset_string8(mapunits_kw, 0, "FEET"); + if (output_unit == RD_FIELD_UNITS) + rd_kw_iset_string8(mapunits_kw, 0, "FEET"); - if (output_unit == ECL_METRIC_UNITS) - ecl_kw_iset_string8(mapunits_kw, 0, "METRES"); + if (output_unit == RD_METRIC_UNITS) + rd_kw_iset_string8(mapunits_kw, 0, "METRES"); - if (output_unit == ECL_LAB_UNITS) - ecl_kw_iset_string8(mapunits_kw, 0, "CM"); + if (output_unit == RD_LAB_UNITS) + rd_kw_iset_string8(mapunits_kw, 0, "CM"); return mapunits_kw; } -static ecl_kw_type *ecl_grid_alloc_gridunits_kw(ert_ecl_unit_enum output_unit) { - ecl_kw_type *gridunits_kw = ecl_kw_alloc(GRIDUNIT_KW, 2, ECL_CHAR); +static rd_kw_type *rd_grid_alloc_gridunits_kw(ert_rd_unit_enum output_unit) { + rd_kw_type *gridunits_kw = rd_kw_alloc(GRIDUNIT_KW, 2, RD_CHAR); - if (output_unit == ECL_FIELD_UNITS) - ecl_kw_iset_string8(gridunits_kw, 0, "FEET"); + if (output_unit == RD_FIELD_UNITS) + rd_kw_iset_string8(gridunits_kw, 0, "FEET"); - if (output_unit == ECL_METRIC_UNITS) - ecl_kw_iset_string8(gridunits_kw, 0, "METRES"); + if (output_unit == RD_METRIC_UNITS) + rd_kw_iset_string8(gridunits_kw, 0, "METRES"); - if (output_unit == ECL_LAB_UNITS) - ecl_kw_iset_string8(gridunits_kw, 0, "CM"); + if (output_unit == RD_LAB_UNITS) + rd_kw_iset_string8(gridunits_kw, 0, "CM"); - ecl_kw_iset_string8(gridunits_kw, 1, ""); + rd_kw_iset_string8(gridunits_kw, 1, ""); return gridunits_kw; } -static ert_ecl_unit_enum -ecl_grid_check_unit_system(const ecl_kw_type *gridunit_kw) { - const char *length_unit = ecl_kw_iget_char_ptr(gridunit_kw, 0); +static ert_rd_unit_enum +rd_grid_check_unit_system(const rd_kw_type *gridunit_kw) { + const char *length_unit = rd_kw_iget_char_ptr(gridunit_kw, 0); if (strncmp(length_unit, "FEET", 4) == 0) - return ECL_FIELD_UNITS; + return RD_FIELD_UNITS; if (strncmp(length_unit, "CM", 2) == 0) - return ECL_LAB_UNITS; + return RD_LAB_UNITS; - return ECL_METRIC_UNITS; + return RD_METRIC_UNITS; } -static float ecl_grid_output_scaling(const ecl_grid_type *grid, - ert_ecl_unit_enum output_unit) { +static float rd_grid_output_scaling(const rd_grid_type *grid, + ert_rd_unit_enum output_unit) { if (grid->unit_system == output_unit) return 1.0; else { double scale_factor = 1; - if (grid->unit_system == ECL_FIELD_UNITS) + if (grid->unit_system == RD_FIELD_UNITS) scale_factor = 1.0 / METER_TO_FEET_SCALE_FACTOR; - if (grid->unit_system == ECL_LAB_UNITS) + if (grid->unit_system == RD_LAB_UNITS) scale_factor = 1.0 / METER_TO_CM_SCALE_FACTOR; - if (output_unit == ECL_FIELD_UNITS) + if (output_unit == RD_FIELD_UNITS) scale_factor *= METER_TO_FEET_SCALE_FACTOR; - if (output_unit == ECL_LAB_UNITS) + if (output_unit == RD_LAB_UNITS) scale_factor *= METER_TO_CM_SCALE_FACTOR; return scale_factor; } } -static void ecl_grid_fwrite_mapaxes(const ecl_grid_type *grid, - fortio_type *fortio) { - ecl_kw_type *mapaxes_kw = ecl_grid_alloc_mapaxes_kw(grid); - ecl_kw_fwrite(mapaxes_kw, fortio); - ecl_kw_free(mapaxes_kw); +static void rd_grid_fwrite_mapaxes(const rd_grid_type *grid, + fortio_type *fortio) { + rd_kw_type *mapaxes_kw = rd_grid_alloc_mapaxes_kw(grid); + rd_kw_fwrite(mapaxes_kw, fortio); + rd_kw_free(mapaxes_kw); } -static void ecl_grid_fwrite_mapunits(fortio_type *fortio, - ert_ecl_unit_enum output_unit) { - ecl_kw_type *mapunits_kw = ecl_grid_alloc_mapunits_kw(output_unit); - ecl_kw_fwrite(mapunits_kw, fortio); - ecl_kw_free(mapunits_kw); +static void rd_grid_fwrite_mapunits(fortio_type *fortio, + ert_rd_unit_enum output_unit) { + rd_kw_type *mapunits_kw = rd_grid_alloc_mapunits_kw(output_unit); + rd_kw_fwrite(mapunits_kw, fortio); + rd_kw_free(mapunits_kw); } -static void ecl_grid_fwrite_gridunits(fortio_type *fortio, - ert_ecl_unit_enum output_unit) { - ecl_kw_type *gridunits_kw = ecl_grid_alloc_gridunits_kw(output_unit); - ecl_kw_fwrite(gridunits_kw, fortio); - ecl_kw_free(gridunits_kw); +static void rd_grid_fwrite_gridunits(fortio_type *fortio, + ert_rd_unit_enum output_unit) { + rd_kw_type *gridunits_kw = rd_grid_alloc_gridunits_kw(output_unit); + rd_kw_fwrite(gridunits_kw, fortio); + rd_kw_free(gridunits_kw); } -static void ecl_grid_fwrite_main_GRID_headers(const ecl_grid_type *ecl_grid, - fortio_type *fortio, - ert_ecl_unit_enum output_unit) { - ecl_grid_fwrite_mapunits(fortio, output_unit); +static void rd_grid_fwrite_main_GRID_headers(const rd_grid_type *rd_grid, + fortio_type *fortio, + ert_rd_unit_enum output_unit) { + rd_grid_fwrite_mapunits(fortio, output_unit); - if (ecl_grid->use_mapaxes) - ecl_grid_fwrite_mapaxes(ecl_grid, fortio); + if (rd_grid->use_mapaxes) + rd_grid_fwrite_mapaxes(rd_grid, fortio); - ecl_grid_fwrite_gridunits(fortio, output_unit); + rd_grid_fwrite_gridunits(fortio, output_unit); } -static void ecl_grid_fwrite_GRID__(const ecl_grid_type *grid, int coords_size, - fortio_type *fortio, - ert_ecl_unit_enum output_unit) { +static void rd_grid_fwrite_GRID__(const rd_grid_type *grid, int coords_size, + fortio_type *fortio, + ert_rd_unit_enum output_unit) { if (grid->parent_grid != NULL) { - ecl_kw_type *lgr_kw = ecl_kw_alloc(LGR_KW, 1, ECL_CHAR); - ecl_kw_iset_string8(lgr_kw, 0, grid->name); - ecl_kw_fwrite(lgr_kw, fortio); - ecl_kw_free(lgr_kw); + rd_kw_type *lgr_kw = rd_kw_alloc(LGR_KW, 1, RD_CHAR); + rd_kw_iset_string8(lgr_kw, 0, grid->name); + rd_kw_fwrite(lgr_kw, fortio); + rd_kw_free(lgr_kw); } { - ecl_kw_type *dimens_kw = ecl_kw_alloc(DIMENS_KW, 3, ECL_INT); - ecl_kw_iset_int(dimens_kw, 0, grid->nx); - ecl_kw_iset_int(dimens_kw, 1, grid->ny); + rd_kw_type *dimens_kw = rd_kw_alloc(DIMENS_KW, 3, RD_INT); + rd_kw_iset_int(dimens_kw, 0, grid->nx); + rd_kw_iset_int(dimens_kw, 1, grid->ny); if (grid->dualp_flag == FILEHEAD_SINGLE_POROSITY) - ecl_kw_iset_int(dimens_kw, 2, grid->nz); + rd_kw_iset_int(dimens_kw, 2, grid->nz); else - ecl_kw_iset_int(dimens_kw, 2, 2 * grid->nz); + rd_kw_iset_int(dimens_kw, 2, 2 * grid->nz); - ecl_kw_fwrite(dimens_kw, fortio); - ecl_kw_free(dimens_kw); + rd_kw_fwrite(dimens_kw, fortio); + rd_kw_free(dimens_kw); } if (grid->parent_grid == NULL) - ecl_grid_fwrite_main_GRID_headers(grid, fortio, output_unit); + rd_grid_fwrite_main_GRID_headers(grid, fortio, output_unit); { - ecl_kw_type *radial_kw = ecl_kw_alloc(RADIAL_KW, 1, ECL_CHAR); - ecl_kw_iset_string8(radial_kw, 0, "FALSE"); - ecl_kw_fwrite(radial_kw, fortio); - ecl_kw_free(radial_kw); + rd_kw_type *radial_kw = rd_kw_alloc(RADIAL_KW, 1, RD_CHAR); + rd_kw_iset_string8(radial_kw, 0, "FALSE"); + rd_kw_fwrite(radial_kw, fortio); + rd_kw_free(radial_kw); } { - ecl_kw_type *coords_kw = ecl_kw_alloc(COORDS_KW, coords_size, ECL_INT); - ecl_kw_type *corners_kw = ecl_kw_alloc(CORNERS_KW, 24, ECL_FLOAT); + rd_kw_type *coords_kw = rd_kw_alloc(COORDS_KW, coords_size, RD_INT); + rd_kw_type *corners_kw = rd_kw_alloc(CORNERS_KW, 24, RD_FLOAT); int i, j, k; for (k = 0; k < grid->nz; k++) { for (j = 0; j < grid->ny; j++) { for (i = 0; i < grid->nx; i++) { int global_index = - ecl_grid_get_global_index__(grid, i, j, k); - const ecl_cell_type *cell = - ecl_grid_get_cell(grid, global_index); + rd_grid_get_global_index__(grid, i, j, k); + const rd_cell_type *cell = + rd_grid_get_cell(grid, global_index); - ecl_cell_fwrite_GRID(grid, cell, false, coords_size, i, j, - k, global_index, coords_kw, corners_kw, - fortio); + rd_cell_fwrite_GRID(grid, cell, false, coords_size, i, j, k, + global_index, coords_kw, corners_kw, + fortio); } } } @@ -6186,53 +6139,52 @@ static void ecl_grid_fwrite_GRID__(const ecl_grid_type *grid, int coords_size, for (k = grid->nz; k < 2 * grid->nz; k++) { for (j = 0; j < grid->ny; j++) { for (i = 0; i < grid->nx; i++) { - int global_index = ecl_grid_get_global_index__( + int global_index = rd_grid_get_global_index__( grid, i, j, k - grid->nz); - const ecl_cell_type *cell = - ecl_grid_get_cell(grid, global_index); + const rd_cell_type *cell = + rd_grid_get_cell(grid, global_index); - ecl_cell_fwrite_GRID(grid, cell, true, coords_size, i, - j, k, global_index, coords_kw, - corners_kw, fortio); + rd_cell_fwrite_GRID(grid, cell, true, coords_size, i, j, + k, global_index, coords_kw, + corners_kw, fortio); } } } } - ecl_kw_free(coords_kw); - ecl_kw_free(corners_kw); + rd_kw_free(coords_kw); + rd_kw_free(corners_kw); } } -void ecl_grid_fwrite_GRID2(const ecl_grid_type *grid, const char *filename, - ert_ecl_unit_enum output_unit) { +void rd_grid_fwrite_GRID2(const rd_grid_type *grid, const char *filename, + ert_rd_unit_enum output_unit) { int coords_size = 5; bool fmt_file = false; fortio_type *fortio = - fortio_open_writer(filename, fmt_file, ECL_ENDIAN_FLIP); + fortio_open_writer(filename, fmt_file, RD_ENDIAN_FLIP); if (grid->children.size() > 0) coords_size = 7; if (grid->coarsening_active) coords_size = 7; - ecl_grid_fwrite_GRID__(grid, coords_size, fortio, output_unit); + 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 ecl_grid_type *igrid = - (const ecl_grid_type *)vector_iget_const(grid->LGR_list, - grid_nr); - ecl_grid_fwrite_GRID__(igrid, coords_size, fortio, output_unit); + 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); } -void ecl_grid_fwrite_GRID(const ecl_grid_type *grid, const char *filename) { - ecl_grid_fwrite_GRID2(grid, filename, ECL_METRIC_UNITS); +void rd_grid_fwrite_GRID(const rd_grid_type *grid, const char *filename) { + rd_grid_fwrite_GRID2(grid, filename, RD_METRIC_UNITS); } /* @@ -6253,43 +6205,43 @@ ENDGRID 0:INTE a standard EGRID header without creating a grid instance first. */ -static void ecl_grid_fwrite_main_EGRID_header(const ecl_grid_type *grid, - fortio_type *fortio, - ert_ecl_unit_enum output_unit) { +static void rd_grid_fwrite_main_EGRID_header(const rd_grid_type *grid, + fortio_type *fortio, + ert_rd_unit_enum output_unit) { int EGRID_VERSION = 3; int RELEASE_YEAR = 2007; int COMPAT_VERSION = 0; - const float *mapaxes = ecl_grid_get_mapaxes(grid); + const float *mapaxes = rd_grid_get_mapaxes(grid); { - ecl_kw_type *filehead_kw = ecl_kw_alloc(FILEHEAD_KW, 100, ECL_INT); - ecl_kw_scalar_set_int(filehead_kw, 0); + rd_kw_type *filehead_kw = rd_kw_alloc(FILEHEAD_KW, 100, RD_INT); + rd_kw_scalar_set_int(filehead_kw, 0); - ecl_kw_iset_int(filehead_kw, FILEHEAD_VERSION_INDEX, EGRID_VERSION); - ecl_kw_iset_int(filehead_kw, FILEHEAD_YEAR_INDEX, RELEASE_YEAR); - ecl_kw_iset_int(filehead_kw, FILEHEAD_COMPAT_INDEX, COMPAT_VERSION); - ecl_kw_iset_int(filehead_kw, FILEHEAD_TYPE_INDEX, - FILEHEAD_GRIDTYPE_CORNERPOINT); - ecl_kw_iset_int(filehead_kw, FILEHEAD_DUALP_INDEX, grid->dualp_flag); - ecl_kw_iset_int(filehead_kw, FILEHEAD_ORGFORMAT_INDEX, - FILEHEAD_ORGTYPE_CORNERPOINT); + rd_kw_iset_int(filehead_kw, FILEHEAD_VERSION_INDEX, EGRID_VERSION); + rd_kw_iset_int(filehead_kw, FILEHEAD_YEAR_INDEX, RELEASE_YEAR); + rd_kw_iset_int(filehead_kw, FILEHEAD_COMPAT_INDEX, COMPAT_VERSION); + rd_kw_iset_int(filehead_kw, FILEHEAD_TYPE_INDEX, + FILEHEAD_GRIDTYPE_CORNERPOINT); + rd_kw_iset_int(filehead_kw, FILEHEAD_DUALP_INDEX, grid->dualp_flag); + rd_kw_iset_int(filehead_kw, FILEHEAD_ORGFORMAT_INDEX, + FILEHEAD_ORGTYPE_CORNERPOINT); - ecl_kw_fwrite(filehead_kw, fortio); - ecl_kw_free(filehead_kw); + rd_kw_fwrite(filehead_kw, fortio); + rd_kw_free(filehead_kw); } - ecl_grid_fwrite_mapunits(fortio, output_unit); + rd_grid_fwrite_mapunits(fortio, output_unit); if (mapaxes != NULL) - ecl_grid_fwrite_mapaxes(grid, fortio); + rd_grid_fwrite_mapaxes(grid, fortio); - ecl_grid_fwrite_gridunits(fortio, output_unit); + rd_grid_fwrite_gridunits(fortio, output_unit); } -static void ecl_grid_fwrite_gridhead_kw(int nx, int ny, int nz, int grid_nr, - fortio_type *fortio) { - ecl_kw_type *gridhead_kw = ecl_grid_alloc_gridhead_kw(nx, ny, nz, grid_nr); - ecl_kw_fwrite(gridhead_kw, fortio); - ecl_kw_free(gridhead_kw); +static void rd_grid_fwrite_gridhead_kw(int nx, int ny, int nz, int grid_nr, + fortio_type *fortio) { + rd_kw_type *gridhead_kw = rd_grid_alloc_gridhead_kw(nx, ny, nz, grid_nr); + rd_kw_fwrite(gridhead_kw, fortio); + rd_kw_free(gridhead_kw); } /* @@ -6297,17 +6249,17 @@ static void ecl_grid_fwrite_gridhead_kw(int nx, int ny, int nz, int grid_nr, valid geometry. If no cell is found the function will return -1. */ -static int ecl_grid_get_valid_index(const ecl_grid_type *grid, int i, int j, - int k1, int k2) { +static int rd_grid_get_valid_index(const rd_grid_type *grid, int i, int j, + int k1, int k2) { int global_index; int k = k1; int delta = (k1 < k2) ? 1 : -1; while (true) { - ecl_cell_type *cell; - global_index = ecl_grid_get_global_index3(grid, i, j, k); + rd_cell_type *cell; + global_index = rd_grid_get_global_index3(grid, i, j, k); - cell = ecl_grid_get_cell(grid, global_index); + cell = rd_grid_get_cell(grid, global_index); if (GET_CELL_FLAG(cell, CELL_FLAG_VALID)) return global_index; else { @@ -6318,23 +6270,22 @@ static int ecl_grid_get_valid_index(const ecl_grid_type *grid, int i, int j, } } -static int ecl_grid_get_bottom_valid_index(const ecl_grid_type *grid, int i, - int j) { - return ecl_grid_get_valid_index(grid, i, j, grid->nz - 1, -1); +static int rd_grid_get_bottom_valid_index(const rd_grid_type *grid, int i, + int j) { + return rd_grid_get_valid_index(grid, i, j, grid->nz - 1, -1); } -static int ecl_grid_get_top_valid_index(const ecl_grid_type *grid, int i, - int j) { - return ecl_grid_get_valid_index(grid, i, j, 0, grid->nz); +static int rd_grid_get_top_valid_index(const rd_grid_type *grid, int i, int j) { + return rd_grid_get_valid_index(grid, i, j, 0, grid->nz); } -static bool ecl_grid_init_coord_section__(const ecl_grid_type *grid, int i, - int j, int i_corner, int j_corner, - bool force_set, float *coord_float, - double *coord_double) { +static bool rd_grid_init_coord_section__(const rd_grid_type *grid, int i, int j, + int i_corner, int j_corner, + bool force_set, float *coord_float, + double *coord_double) { - const int top_index = ecl_grid_get_top_valid_index(grid, i, j); - const int bottom_index = ecl_grid_get_bottom_valid_index(grid, i, j); + const int top_index = rd_grid_get_top_valid_index(grid, i, j); + const int bottom_index = rd_grid_get_bottom_valid_index(grid, i, j); if (top_index == -1) util_exit("% : no cell with a valid geometry description found in " @@ -6345,9 +6296,8 @@ static bool ecl_grid_init_coord_section__(const ecl_grid_type *grid, int i, point_type top_point; point_type bottom_point; - const ecl_cell_type *bottom_cell = - ecl_grid_get_cell(grid, bottom_index); - const ecl_cell_type *top_cell = ecl_grid_get_cell(grid, top_index); + 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); /* 2---3 @@ -6398,9 +6348,9 @@ static bool ecl_grid_init_coord_section__(const ecl_grid_type *grid, int i, } } -static void ecl_grid_init_coord_section(const ecl_grid_type *grid, int i, int j, - float *coord_float, - double *coord_double) { +static void rd_grid_init_coord_section(const rd_grid_type *grid, int i, int j, + float *coord_float, + double *coord_double) { int i_corner = 0; int j_corner = 0; @@ -6414,12 +6364,11 @@ static void ecl_grid_init_coord_section(const ecl_grid_type *grid, int i, int j, j_corner = 1; } - ecl_grid_init_coord_section__(grid, i, j, i_corner, j_corner, - /*force_set=*/true, coord_float, - coord_double); + rd_grid_init_coord_section__(grid, i, j, i_corner, j_corner, + /*force_set=*/true, coord_float, coord_double); } -void ecl_grid_init_coord_data(const ecl_grid_type *grid, float *coord) { +void rd_grid_init_coord_data(const rd_grid_type *grid, float *coord) { /* The coord vector contains the points defining the top and bottom of the pillars. The vector contains (nx + 1) * (ny + 1) 6 element @@ -6429,11 +6378,11 @@ void ecl_grid_init_coord_data(const ecl_grid_type *grid, float *coord) { int i, j; for (j = 0; j <= grid->ny; j++) { for (i = 0; i <= grid->nx; i++) - ecl_grid_init_coord_section(grid, i, j, coord, NULL); + rd_grid_init_coord_section(grid, i, j, coord, NULL); } } -void ecl_grid_init_coord_data_double(const ecl_grid_type *grid, double *coord) { +void rd_grid_init_coord_data_double(const rd_grid_type *grid, double *coord) { /* The coord vector contains the points defining the top and bottom of the pillars. The vector contains (nx + 1) * (ny + 1) 6 element @@ -6443,29 +6392,29 @@ void ecl_grid_init_coord_data_double(const ecl_grid_type *grid, double *coord) { int i, j; for (j = 0; j <= grid->ny; j++) { for (i = 0; i <= grid->nx; i++) - ecl_grid_init_coord_section(grid, i, j, NULL, coord); + rd_grid_init_coord_section(grid, i, j, NULL, coord); } } -float *ecl_grid_alloc_coord_data(const ecl_grid_type *grid) { +float *rd_grid_alloc_coord_data(const rd_grid_type *grid) { float *coord = - (float *)util_calloc(ecl_grid_get_coord_size(grid), sizeof *coord); - ecl_grid_init_coord_data(grid, coord); + (float *)util_calloc(rd_grid_get_coord_size(grid), sizeof *coord); + rd_grid_init_coord_data(grid, coord); return coord; } -void ecl_grid_assert_coord_kw(ecl_grid_type *grid) { +void rd_grid_assert_coord_kw(rd_grid_type *grid) { if (grid->coord_kw == NULL) { grid->coord_kw = - ecl_kw_alloc(COORD_KW, ecl_grid_get_coord_size(grid), ECL_FLOAT); - ecl_grid_init_coord_data(grid, - (float *)ecl_kw_get_void_ptr(grid->coord_kw)); + rd_kw_alloc(COORD_KW, rd_grid_get_coord_size(grid), RD_FLOAT); + rd_grid_init_coord_data(grid, + (float *)rd_kw_get_void_ptr(grid->coord_kw)); } } -static void ecl_grid_init_zcorn_data__(const ecl_grid_type *grid, - float *zcorn_float, - double *zcorn_double) { +static void rd_grid_init_zcorn_data__(const rd_grid_type *grid, + float *zcorn_float, + double *zcorn_double) { int nx = grid->nx; int ny = grid->ny; int nz = grid->nz; @@ -6473,9 +6422,8 @@ static void ecl_grid_init_zcorn_data__(const ecl_grid_type *grid, for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { for (k = 0; k < nz; k++) { - const int cell_index = - ecl_grid_get_global_index3(grid, i, j, k); - const ecl_cell_type *cell = ecl_grid_get_cell(grid, cell_index); + 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++) { @@ -6512,63 +6460,63 @@ static void ecl_grid_init_zcorn_data__(const ecl_grid_type *grid, } } -void ecl_grid_init_zcorn_data(const ecl_grid_type *grid, float *zcorn) { - ecl_grid_init_zcorn_data__(grid, zcorn, NULL); +void rd_grid_init_zcorn_data(const rd_grid_type *grid, float *zcorn) { + rd_grid_init_zcorn_data__(grid, zcorn, NULL); } -void ecl_grid_init_zcorn_data_double(const ecl_grid_type *grid, double *zcorn) { - ecl_grid_init_zcorn_data__(grid, NULL, zcorn); +void rd_grid_init_zcorn_data_double(const rd_grid_type *grid, double *zcorn) { + rd_grid_init_zcorn_data__(grid, NULL, zcorn); } -float *ecl_grid_alloc_zcorn_data(const ecl_grid_type *grid) { +float *rd_grid_alloc_zcorn_data(const rd_grid_type *grid) { float *zcorn = (float *)util_calloc(8 * grid->size, sizeof *zcorn); - ecl_grid_init_zcorn_data(grid, zcorn); + rd_grid_init_zcorn_data(grid, zcorn); return zcorn; } -ecl_kw_type *ecl_grid_alloc_zcorn_kw(const ecl_grid_type *grid) { - ecl_kw_type *zcorn_kw = - ecl_kw_alloc(ZCORN_KW, ecl_grid_get_zcorn_size(grid), ECL_FLOAT); - ecl_grid_init_zcorn_data(grid, (float *)ecl_kw_get_void_ptr(zcorn_kw)); +rd_kw_type *rd_grid_alloc_zcorn_kw(const rd_grid_type *grid) { + rd_kw_type *zcorn_kw = + rd_kw_alloc(ZCORN_KW, rd_grid_get_zcorn_size(grid), RD_FLOAT); + rd_grid_init_zcorn_data(grid, (float *)rd_kw_get_void_ptr(zcorn_kw)); return zcorn_kw; } -ecl_kw_type *ecl_grid_alloc_coord_kw(const ecl_grid_type *grid) { +rd_kw_type *rd_grid_alloc_coord_kw(const rd_grid_type *grid) { if (grid->coord_kw) - return ecl_kw_alloc_copy(grid->coord_kw); + return rd_kw_alloc_copy(grid->coord_kw); - ecl_kw_type *coord_kw = ecl_kw_alloc( - COORD_KW, ECL_GRID_COORD_SIZE(grid->nx, grid->ny), ECL_FLOAT); - ecl_grid_init_coord_data(grid, ecl_kw_get_float_ptr(coord_kw)); + rd_kw_type *coord_kw = + rd_kw_alloc(COORD_KW, RD_GRID_COORD_SIZE(grid->nx, grid->ny), RD_FLOAT); + rd_grid_init_coord_data(grid, rd_kw_get_float_ptr(coord_kw)); return coord_kw; } -int ecl_grid_get_coord_size(const ecl_grid_type *grid) { - return ECL_GRID_COORD_SIZE(grid->nx, grid->ny); +int rd_grid_get_coord_size(const rd_grid_type *grid) { + return RD_GRID_COORD_SIZE(grid->nx, grid->ny); } -int ecl_grid_get_zcorn_size(const ecl_grid_type *grid) { - return ECL_GRID_ZCORN_SIZE(grid->nx, grid->ny, grid->nz); +int rd_grid_get_zcorn_size(const rd_grid_type *grid) { + return RD_GRID_ZCORN_SIZE(grid->nx, grid->ny, grid->nz); } -void ecl_grid_init_actnum_data(const ecl_grid_type *grid, int *actnum) { +void rd_grid_init_actnum_data(const rd_grid_type *grid, int *actnum) { int i; for (i = 0; i < grid->size; i++) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, i); + const rd_cell_type *cell = rd_grid_get_cell(grid, i); if (cell->coarse_group == COARSE_GROUP_NONE) actnum[i] = cell->active; else { /* In the case of coarse cells we must query the coarse cell for the original, uncoarsened distribution of actnum values. */ - ecl_coarse_cell_type *coarse_cell = - ecl_grid_iget_coarse_group(grid, cell->coarse_group); + rd_coarse_cell_type *coarse_cell = + rd_grid_iget_coarse_group(grid, cell->coarse_group); /* 1: Set all the elements in the coarse group to inactive. */ { - int group_size = ecl_coarse_cell_get_size(coarse_cell); + int group_size = rd_coarse_cell_get_size(coarse_cell); const int *index_ptr = - ecl_coarse_cell_get_index_ptr(coarse_cell); + rd_coarse_cell_get_index_ptr(coarse_cell); int j; for (j = 0; j < group_size; j++) actnum[index_ptr[j]] = CELL_NOT_ACTIVE; @@ -6577,14 +6525,14 @@ void ecl_grid_init_actnum_data(const ecl_grid_type *grid, int *actnum) { /* 2: Explicitly pick up the active cells from the coarse group and mark them correctly. */ { - int num_active = ecl_coarse_cell_get_num_active(coarse_cell); + int num_active = rd_coarse_cell_get_num_active(coarse_cell); int j; for (j = 0; j < num_active; j++) { int global_index = - ecl_coarse_cell_iget_active_cell_index(coarse_cell, j); + rd_coarse_cell_iget_active_cell_index(coarse_cell, j); int active_value = - ecl_coarse_cell_iget_active_value(coarse_cell, j); + rd_coarse_cell_iget_active_value(coarse_cell, j); actnum[global_index] = active_value; } @@ -6593,137 +6541,133 @@ void ecl_grid_init_actnum_data(const ecl_grid_type *grid, int *actnum) { } } -int *ecl_grid_alloc_actnum_data(const ecl_grid_type *grid) { +int *rd_grid_alloc_actnum_data(const rd_grid_type *grid) { int *actnum = (int *)util_calloc(grid->size, sizeof *actnum); - ecl_grid_init_actnum_data(grid, actnum); + rd_grid_init_actnum_data(grid, actnum); return actnum; } -ecl_kw_type *ecl_grid_alloc_actnum_kw(const ecl_grid_type *grid) { - ecl_kw_type *actnum_kw = ecl_kw_alloc(ACTNUM_KW, grid->size, ECL_INT); - ecl_grid_init_actnum_data(grid, (int *)ecl_kw_get_void_ptr(actnum_kw)); +rd_kw_type *rd_grid_alloc_actnum_kw(const rd_grid_type *grid) { + rd_kw_type *actnum_kw = rd_kw_alloc(ACTNUM_KW, grid->size, RD_INT); + rd_grid_init_actnum_data(grid, (int *)rd_kw_get_void_ptr(actnum_kw)); return actnum_kw; } -void ecl_grid_compressed_kw_copy(const ecl_grid_type *grid, - ecl_kw_type *target_kw, - const ecl_kw_type *src_kw) { - if ((ecl_kw_get_size(target_kw) == ecl_grid_get_nactive(grid)) && - (ecl_kw_get_size(src_kw) == ecl_grid_get_global_size(grid))) { +void rd_grid_compressed_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, + const rd_kw_type *src_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 < ecl_grid_get_global_size(grid); + for (global_index = 0; global_index < rd_grid_get_global_size(grid); global_index++) { - if (ecl_grid_cell_active1(grid, global_index)) { - ecl_kw_iset(target_kw, active_index, - ecl_kw_iget_ptr(src_kw, global_index)); + if (rd_grid_cell_active1(grid, global_index)) { + rd_kw_iset(target_kw, active_index, + rd_kw_iget_ptr(src_kw, global_index)); active_index++; } } } else util_abort("%s: size mismatch target:%d src:%d expected %d,%d \n", - ecl_kw_get_size(target_kw), ecl_kw_get_size(src_kw), - ecl_grid_get_nactive(grid), ecl_grid_get_global_size(grid)); + rd_kw_get_size(target_kw), rd_kw_get_size(src_kw), + rd_grid_get_nactive(grid), rd_grid_get_global_size(grid)); } -void ecl_grid_global_kw_copy(const ecl_grid_type *grid, ecl_kw_type *target_kw, - const ecl_kw_type *src_kw) { - if ((ecl_kw_get_size(src_kw) == ecl_grid_get_nactive(grid)) && - (ecl_kw_get_size(target_kw) == ecl_grid_get_global_size(grid))) { +void rd_grid_global_kw_copy(const rd_grid_type *grid, rd_kw_type *target_kw, + const rd_kw_type *src_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 < ecl_grid_get_global_size(grid); + for (global_index = 0; global_index < rd_grid_get_global_size(grid); global_index++) { - if (ecl_grid_cell_active1(grid, global_index)) { - ecl_kw_iset(target_kw, global_index, - ecl_kw_iget_ptr(src_kw, active_index)); + if (rd_grid_cell_active1(grid, global_index)) { + rd_kw_iset(target_kw, global_index, + rd_kw_iget_ptr(src_kw, active_index)); active_index++; } } } else util_abort("%s: size mismatch target:%d src:%d expected %d,%d \n", - ecl_kw_get_size(target_kw), ecl_kw_get_size(src_kw), - ecl_grid_get_global_size(grid), ecl_grid_get_nactive(grid)); + rd_kw_get_size(target_kw), rd_kw_get_size(src_kw), + rd_grid_get_global_size(grid), rd_grid_get_nactive(grid)); } -static void ecl_grid_init_hostnum_data(const ecl_grid_type *grid, - int *hostnum) { +static void rd_grid_init_hostnum_data(const rd_grid_type *grid, int *hostnum) { int i; for (i = 0; i < grid->size; i++) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, i); + const rd_cell_type *cell = rd_grid_get_cell(grid, i); hostnum[i] = cell->host_cell; } } -int *ecl_grid_alloc_hostnum_data(const ecl_grid_type *grid) { +int *rd_grid_alloc_hostnum_data(const rd_grid_type *grid) { int *hostnum = (int *)util_calloc(grid->size, sizeof *hostnum); - ecl_grid_init_hostnum_data(grid, hostnum); + rd_grid_init_hostnum_data(grid, hostnum); return hostnum; } -ecl_kw_type *ecl_grid_alloc_hostnum_kw(const ecl_grid_type *grid) { - ecl_kw_type *hostnum_kw = ecl_kw_alloc(HOSTNUM_KW, grid->size, ECL_INT); - ecl_grid_init_hostnum_data(grid, (int *)ecl_kw_get_void_ptr(hostnum_kw)); +rd_kw_type *rd_grid_alloc_hostnum_kw(const rd_grid_type *grid) { + rd_kw_type *hostnum_kw = rd_kw_alloc(HOSTNUM_KW, grid->size, RD_INT); + rd_grid_init_hostnum_data(grid, (int *)rd_kw_get_void_ptr(hostnum_kw)); return hostnum_kw; } -static void ecl_grid_init_corsnum_data(const ecl_grid_type *grid, - int *corsnum) { +static void rd_grid_init_corsnum_data(const rd_grid_type *grid, int *corsnum) { int i; for (i = 0; i < grid->size; i++) { - const ecl_cell_type *cell = ecl_grid_get_cell(grid, i); + const rd_cell_type *cell = rd_grid_get_cell(grid, i); corsnum[i] = cell->coarse_group + 1; } } -int *ecl_grid_alloc_corsnum_data(const ecl_grid_type *grid) { +int *rd_grid_alloc_corsnum_data(const rd_grid_type *grid) { int *corsnum = (int *)util_calloc(grid->size, sizeof *corsnum); - ecl_grid_init_corsnum_data(grid, corsnum); + rd_grid_init_corsnum_data(grid, corsnum); return corsnum; } -ecl_kw_type *ecl_grid_alloc_corsnum_kw(const ecl_grid_type *grid) { - ecl_kw_type *corsnum_kw = ecl_kw_alloc(CORSNUM_KW, grid->size, ECL_INT); - ecl_grid_init_corsnum_data(grid, (int *)ecl_kw_get_void_ptr(corsnum_kw)); +rd_kw_type *rd_grid_alloc_corsnum_kw(const rd_grid_type *grid) { + rd_kw_type *corsnum_kw = rd_kw_alloc(CORSNUM_KW, grid->size, RD_INT); + rd_grid_init_corsnum_data(grid, (int *)rd_kw_get_void_ptr(corsnum_kw)); return corsnum_kw; } -ecl_kw_type *ecl_grid_alloc_gridhead_kw(int nx, int ny, int nz, int grid_nr) { - ecl_kw_type *gridhead_kw = - ecl_kw_alloc(GRIDHEAD_KW, GRIDHEAD_SIZE, ECL_INT); - ecl_kw_scalar_set_int(gridhead_kw, 0); - ecl_kw_iset_int(gridhead_kw, GRIDHEAD_TYPE_INDEX, - GRIDHEAD_GRIDTYPE_CORNERPOINT); - ecl_kw_iset_int(gridhead_kw, GRIDHEAD_NX_INDEX, nx); - ecl_kw_iset_int(gridhead_kw, GRIDHEAD_NY_INDEX, ny); - ecl_kw_iset_int(gridhead_kw, GRIDHEAD_NZ_INDEX, nz); - ecl_kw_iset_int(gridhead_kw, GRIDHEAD_NUMRES_INDEX, 1); - ecl_kw_iset_int(gridhead_kw, GRIDHEAD_LGR_INDEX, grid_nr); +rd_kw_type *rd_grid_alloc_gridhead_kw(int nx, int ny, int nz, int grid_nr) { + rd_kw_type *gridhead_kw = rd_kw_alloc(GRIDHEAD_KW, GRIDHEAD_SIZE, RD_INT); + rd_kw_scalar_set_int(gridhead_kw, 0); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_TYPE_INDEX, + GRIDHEAD_GRIDTYPE_CORNERPOINT); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NX_INDEX, nx); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NY_INDEX, ny); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NZ_INDEX, nz); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_NUMRES_INDEX, 1); + rd_kw_iset_int(gridhead_kw, GRIDHEAD_LGR_INDEX, grid_nr); return gridhead_kw; } -void ecl_grid_reset_actnum(ecl_grid_type *grid, const int *actnum) { - const int global_size = ecl_grid_get_global_size(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++) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, g); + rd_cell_type *cell = rd_grid_get_cell(grid, g); if (actnum) cell->active = actnum[g]; else cell->active = 1; } - ecl_grid_update_index(grid); + rd_grid_update_index(grid); } -static void ecl_grid_fwrite_self_nnc(const ecl_grid_type *grid, - fortio_type *fortio) { +static void rd_grid_fwrite_self_nnc(const rd_grid_type *grid, + fortio_type *fortio) { 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 < ecl_grid_get_global_size(grid); g++) { - ecl_cell_type *cell = ecl_grid_get_cell(grid, g); + for (g = 0; g < rd_grid_get_global_size(grid); g++) { + rd_cell_type *cell = rd_grid_get_cell(grid, g); const nnc_info_type *nnc_info = cell->nnc_info; if (nnc_info) { const nnc_vector_type *nnc_vector = @@ -6739,224 +6683,220 @@ static void ecl_grid_fwrite_self_nnc(const ecl_grid_type *grid, } { int num_nnc = int_vector_size(g1); - ecl_kw_type *nnc1_kw = ecl_kw_alloc_new_shared( - NNC1_KW, num_nnc, ECL_INT, int_vector_get_ptr(g1)); - ecl_kw_type *nnc2_kw = ecl_kw_alloc_new_shared( - NNC2_KW, num_nnc, ECL_INT, int_vector_get_ptr(g2)); - ecl_kw_type *nnchead_kw = - ecl_kw_alloc(NNCHEAD_KW, NNCHEAD_SIZE, ECL_INT); + rd_kw_type *nnc1_kw = rd_kw_alloc_new_shared(NNC1_KW, num_nnc, RD_INT, + int_vector_get_ptr(g1)); + rd_kw_type *nnc2_kw = rd_kw_alloc_new_shared(NNC2_KW, num_nnc, RD_INT, + int_vector_get_ptr(g2)); + rd_kw_type *nnchead_kw = rd_kw_alloc(NNCHEAD_KW, NNCHEAD_SIZE, RD_INT); - ecl_kw_scalar_set_int(nnchead_kw, 0); - ecl_kw_iset_int(nnchead_kw, NNCHEAD_NUMNNC_INDEX, num_nnc); - ecl_kw_iset_int(nnchead_kw, NNCHEAD_LGR_INDEX, grid->lgr_nr); + rd_kw_scalar_set_int(nnchead_kw, 0); + rd_kw_iset_int(nnchead_kw, NNCHEAD_NUMNNC_INDEX, num_nnc); + rd_kw_iset_int(nnchead_kw, NNCHEAD_LGR_INDEX, grid->lgr_nr); - ecl_kw_fwrite(nnchead_kw, fortio); - ecl_kw_fwrite(nnc1_kw, fortio); - ecl_kw_fwrite(nnc2_kw, fortio); + rd_kw_fwrite(nnchead_kw, fortio); + rd_kw_fwrite(nnc1_kw, fortio); + rd_kw_fwrite(nnc2_kw, fortio); - ecl_kw_free(nnchead_kw); - ecl_kw_free(nnc2_kw); - ecl_kw_free(nnc1_kw); + rd_kw_free(nnchead_kw); + rd_kw_free(nnc2_kw); + rd_kw_free(nnc1_kw); } int_vector_free(g1); int_vector_free(g2); } -static void ecl_grid_fwrite_EGRID__(ecl_grid_type *grid, fortio_type *fortio, - ert_ecl_unit_enum output_unit) { +static void rd_grid_fwrite_EGRID__(rd_grid_type *grid, fortio_type *fortio, + ert_rd_unit_enum output_unit) { bool is_lgr = true; if (grid->parent_grid == NULL) is_lgr = false; /* Writing header */ if (!is_lgr) { - ecl_grid_fwrite_main_EGRID_header(grid, fortio, output_unit); + rd_grid_fwrite_main_EGRID_header(grid, fortio, output_unit); } else { { - ecl_kw_type *lgr_kw = ecl_kw_alloc(LGR_KW, 1, ECL_CHAR); - ecl_kw_iset_string8(lgr_kw, 0, grid->name); - ecl_kw_fwrite(lgr_kw, fortio); - ecl_kw_free(lgr_kw); + rd_kw_type *lgr_kw = rd_kw_alloc(LGR_KW, 1, RD_CHAR); + rd_kw_iset_string8(lgr_kw, 0, grid->name); + rd_kw_fwrite(lgr_kw, fortio); + rd_kw_free(lgr_kw); } { - ecl_kw_type *lgr_parent_kw = - ecl_kw_alloc(LGR_PARENT_KW, 1, ECL_CHAR); + rd_kw_type *lgr_parent_kw = rd_kw_alloc(LGR_PARENT_KW, 1, RD_CHAR); if (grid->parent_name != NULL) - ecl_kw_iset_string8(lgr_parent_kw, 0, grid->parent_name); + rd_kw_iset_string8(lgr_parent_kw, 0, grid->parent_name); else - ecl_kw_iset_string8(lgr_parent_kw, 0, ""); + rd_kw_iset_string8(lgr_parent_kw, 0, ""); - ecl_kw_fwrite(lgr_parent_kw, fortio); - ecl_kw_free(lgr_parent_kw); + rd_kw_fwrite(lgr_parent_kw, fortio); + rd_kw_free(lgr_parent_kw); } } - ecl_grid_fwrite_gridhead_kw(grid->nx, grid->ny, grid->nz, grid->lgr_nr, - fortio); + rd_grid_fwrite_gridhead_kw(grid->nx, grid->ny, grid->nz, grid->lgr_nr, + fortio); /* Writing main grid data */ { - ecl_grid_assert_coord_kw(grid); + rd_grid_assert_coord_kw(grid); { - ecl_kw_type *coord_kw = ecl_kw_alloc_copy(grid->coord_kw); - ecl_kw_type *zcorn_kw = ecl_grid_alloc_zcorn_kw(grid); + rd_kw_type *coord_kw = rd_kw_alloc_copy(grid->coord_kw); + rd_kw_type *zcorn_kw = rd_grid_alloc_zcorn_kw(grid); if (output_unit != grid->unit_system) { - double scale_factor = - ecl_grid_output_scaling(grid, output_unit); - ecl_kw_scale_float(coord_kw, scale_factor); - ecl_kw_scale_float(zcorn_kw, scale_factor); + double scale_factor = rd_grid_output_scaling(grid, output_unit); + rd_kw_scale_float(coord_kw, scale_factor); + rd_kw_scale_float(zcorn_kw, scale_factor); } - ecl_kw_fwrite(coord_kw, fortio); - ecl_kw_fwrite(zcorn_kw, fortio); - ecl_kw_free(zcorn_kw); - ecl_kw_free(coord_kw); + rd_kw_fwrite(coord_kw, fortio); + rd_kw_fwrite(zcorn_kw, fortio); + rd_kw_free(zcorn_kw); + rd_kw_free(coord_kw); } { - ecl_kw_type *actnum_kw = ecl_grid_alloc_actnum_kw(grid); - ecl_kw_fwrite(actnum_kw, fortio); - ecl_kw_free(actnum_kw); + rd_kw_type *actnum_kw = rd_grid_alloc_actnum_kw(grid); + rd_kw_fwrite(actnum_kw, fortio); + rd_kw_free(actnum_kw); } if (is_lgr) { - ecl_kw_type *hostnum_kw = ecl_grid_alloc_hostnum_kw(grid); - ecl_kw_fwrite(hostnum_kw, fortio); - ecl_kw_free(hostnum_kw); + rd_kw_type *hostnum_kw = rd_grid_alloc_hostnum_kw(grid); + rd_kw_fwrite(hostnum_kw, fortio); + rd_kw_free(hostnum_kw); } if (grid->coarsening_active) { - ecl_kw_type *corsnum_kw = ecl_grid_alloc_corsnum_kw(grid); - ecl_kw_fwrite(corsnum_kw, fortio); - ecl_kw_free(corsnum_kw); + rd_kw_type *corsnum_kw = rd_grid_alloc_corsnum_kw(grid); + rd_kw_fwrite(corsnum_kw, fortio); + rd_kw_free(corsnum_kw); } { - ecl_kw_type *endgrid_kw = ecl_kw_alloc(ENDGRID_KW, 0, ECL_INT); - ecl_kw_fwrite(endgrid_kw, fortio); - ecl_kw_free(endgrid_kw); + rd_kw_type *endgrid_kw = rd_kw_alloc(ENDGRID_KW, 0, RD_INT); + rd_kw_fwrite(endgrid_kw, fortio); + rd_kw_free(endgrid_kw); } } if (is_lgr) { - ecl_kw_type *endlgr_kw = ecl_kw_alloc(ENDLGR_KW, 0, ECL_INT); - ecl_kw_fwrite(endlgr_kw, fortio); - ecl_kw_free(endlgr_kw); + rd_kw_type *endlgr_kw = rd_kw_alloc(ENDLGR_KW, 0, RD_INT); + rd_kw_fwrite(endlgr_kw, fortio); + rd_kw_free(endlgr_kw); } - ecl_grid_fwrite_self_nnc(grid, fortio); + rd_grid_fwrite_self_nnc(grid, fortio); } -void ecl_grid_fwrite_EGRID2(ecl_grid_type *grid, const char *filename, - ert_ecl_unit_enum output_unit) { +void rd_grid_fwrite_EGRID2(rd_grid_type *grid, const char *filename, + ert_rd_unit_enum output_unit) { bool fmt_file = false; { bool is_fmt; - if (ecl_util_get_file_type(filename, &is_fmt, NULL) != ECL_OTHER_FILE) + if (rd_get_file_type(filename, &is_fmt, NULL) != RD_OTHER_FILE) fmt_file = is_fmt; } fortio_type *fortio = - fortio_open_writer(filename, fmt_file, ECL_ENDIAN_FLIP); + fortio_open_writer(filename, fmt_file, RD_ENDIAN_FLIP); - ecl_grid_fwrite_EGRID__(grid, fortio, output_unit); + 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++) { - ecl_grid_type *igrid = - (ecl_grid_type *)vector_iget(grid->LGR_list, grid_nr); - ecl_grid_fwrite_EGRID__(igrid, fortio, output_unit); + 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); } /* - The construction with ecl_grid_fwrite_EGRID() and - ecl_grid_fwrite_EGRID2() is an attempt to create API stability. New - code should use the ecl_grid_fwrite_EGRID2() function. + The construction with rd_grid_fwrite_EGRID() and + rd_grid_fwrite_EGRID2() is an attempt to create API stability. New + code should use the rd_grid_fwrite_EGRID2() function. */ -void ecl_grid_fwrite_EGRID(ecl_grid_type *grid, const char *filename, - bool output_metric) { - ert_ecl_unit_enum output_unit = ECL_METRIC_UNITS; +void rd_grid_fwrite_EGRID(rd_grid_type *grid, const char *filename, + bool output_metric) { + ert_rd_unit_enum output_unit = RD_METRIC_UNITS; if (!output_metric) - output_unit = ECL_FIELD_UNITS; + output_unit = RD_FIELD_UNITS; - ecl_grid_fwrite_EGRID2(grid, filename, output_unit); + rd_grid_fwrite_EGRID2(grid, filename, output_unit); } -void ecl_grid_fwrite_depth(const ecl_grid_type *grid, fortio_type *init_file, - ert_ecl_unit_enum output_unit) { - ecl_kw_type *depth_kw = - ecl_kw_alloc("DEPTH", ecl_grid_get_nactive(grid), ECL_FLOAT); +void rd_grid_fwrite_depth(const rd_grid_type *grid, fortio_type *init_file, + ert_rd_unit_enum output_unit) { + rd_kw_type *depth_kw = + rd_kw_alloc("DEPTH", rd_grid_get_nactive(grid), RD_FLOAT); { - float *depth_ptr = (float *)ecl_kw_get_ptr(depth_kw); - for (int i = 0; i < ecl_grid_get_nactive(grid); i++) - depth_ptr[i] = ecl_grid_get_cdepth1A(grid, i); + float *depth_ptr = (float *)rd_kw_get_ptr(depth_kw); + for (int i = 0; i < rd_grid_get_nactive(grid); i++) + depth_ptr[i] = rd_grid_get_cdepth1A(grid, i); } - ecl_kw_scale_float(depth_kw, ecl_grid_output_scaling(grid, output_unit)); - ecl_kw_fwrite(depth_kw, init_file); - ecl_kw_free(depth_kw); + rd_kw_scale_float(depth_kw, rd_grid_output_scaling(grid, output_unit)); + rd_kw_fwrite(depth_kw, init_file); + rd_kw_free(depth_kw); } -void ecl_grid_fwrite_dims(const ecl_grid_type *grid, fortio_type *init_file, - ert_ecl_unit_enum output_unit) { - ecl_kw_type *dx = ecl_kw_alloc("DX", ecl_grid_get_nactive(grid), ECL_FLOAT); - ecl_kw_type *dy = ecl_kw_alloc("DY", ecl_grid_get_nactive(grid), ECL_FLOAT); - ecl_kw_type *dz = ecl_kw_alloc("DZ", ecl_grid_get_nactive(grid), ECL_FLOAT); +void rd_grid_fwrite_dims(const rd_grid_type *grid, fortio_type *init_file, + ert_rd_unit_enum output_unit) { + rd_kw_type *dx = rd_kw_alloc("DX", rd_grid_get_nactive(grid), RD_FLOAT); + rd_kw_type *dy = rd_kw_alloc("DY", rd_grid_get_nactive(grid), RD_FLOAT); + rd_kw_type *dz = rd_kw_alloc("DZ", rd_grid_get_nactive(grid), RD_FLOAT); { { - float *dx_ptr = (float *)ecl_kw_get_ptr(dx); - float *dy_ptr = (float *)ecl_kw_get_ptr(dy); - float *dz_ptr = (float *)ecl_kw_get_ptr(dz); - - for (int i = 0; i < ecl_grid_get_nactive(grid); i++) { - dx_ptr[i] = ecl_grid_get_cell_dx1A(grid, i); - dy_ptr[i] = ecl_grid_get_cell_dy1A(grid, i); - dz_ptr[i] = ecl_grid_get_cell_dz1A(grid, i); + float *dx_ptr = (float *)rd_kw_get_ptr(dx); + float *dy_ptr = (float *)rd_kw_get_ptr(dy); + float *dz_ptr = (float *)rd_kw_get_ptr(dz); + + for (int i = 0; i < rd_grid_get_nactive(grid); i++) { + dx_ptr[i] = rd_grid_get_cell_dx1A(grid, i); + dy_ptr[i] = rd_grid_get_cell_dy1A(grid, i); + dz_ptr[i] = rd_grid_get_cell_dz1A(grid, i); } } { - float scale_factor = ecl_grid_output_scaling(grid, output_unit); - ecl_kw_scale_float(dx, scale_factor); - ecl_kw_scale_float(dy, scale_factor); - ecl_kw_scale_float(dz, scale_factor); + float scale_factor = rd_grid_output_scaling(grid, output_unit); + rd_kw_scale_float(dx, scale_factor); + rd_kw_scale_float(dy, scale_factor); + rd_kw_scale_float(dz, scale_factor); } } - ecl_kw_fwrite(dx, init_file); - ecl_kw_fwrite(dy, init_file); - ecl_kw_fwrite(dz, init_file); - ecl_kw_free(dx); - ecl_kw_free(dy); - ecl_kw_free(dz); + rd_kw_fwrite(dx, init_file); + rd_kw_fwrite(dy, init_file); + rd_kw_fwrite(dz, init_file); + rd_kw_free(dx); + rd_kw_free(dy); + rd_kw_free(dz); } /** - Writes the current grid as grdecl keywords suitable to be read by - ECLIPSE. This function will only write the main grid and not + Writes the current grid as grdecl keywords. This function will only write the main grid and not possible LGRs which are attached. */ -void ecl_grid_fprintf_grdecl2(ecl_grid_type *grid, FILE *stream, - ert_ecl_unit_enum output_unit) { +void rd_grid_fprintf_grdecl2(rd_grid_type *grid, FILE *stream, + ert_rd_unit_enum output_unit) { { - ecl_kw_type *mapunits_kw = ecl_grid_alloc_mapunits_kw(output_unit); - ecl_kw_fprintf_grdecl(mapunits_kw, stream); - ecl_kw_free(mapunits_kw); + rd_kw_type *mapunits_kw = rd_grid_alloc_mapunits_kw(output_unit); + rd_kw_fprintf_grdecl(mapunits_kw, stream); + rd_kw_free(mapunits_kw); fprintf(stream, "\n"); } if (grid->mapaxes != NULL) { - ecl_kw_type *mapaxes_kw = ecl_grid_alloc_mapaxes_kw(grid); - ecl_kw_fprintf_grdecl(mapaxes_kw, stream); - ecl_kw_free(mapaxes_kw); + rd_kw_type *mapaxes_kw = rd_grid_alloc_mapaxes_kw(grid); + rd_kw_fprintf_grdecl(mapaxes_kw, stream); + rd_kw_free(mapaxes_kw); } { - ecl_kw_type *gridunits_kw = ecl_grid_alloc_gridunits_kw(output_unit); - ecl_kw_fprintf_grdecl(gridunits_kw, stream); - ecl_kw_free(gridunits_kw); + rd_kw_type *gridunits_kw = rd_grid_alloc_gridunits_kw(output_unit); + rd_kw_fprintf_grdecl(gridunits_kw, stream); + rd_kw_free(gridunits_kw); fprintf(stream, "\n"); } @@ -6973,28 +6913,28 @@ void ecl_grid_fprintf_grdecl2(ecl_grid_type *grid, FILE *stream, } { - ecl_grid_assert_coord_kw(grid); - ecl_kw_fprintf_grdecl(grid->coord_kw, stream); + rd_grid_assert_coord_kw(grid); + rd_kw_fprintf_grdecl(grid->coord_kw, stream); fprintf(stream, "\n"); } { - ecl_kw_type *zcorn_kw = ecl_grid_alloc_zcorn_kw(grid); - ecl_kw_fprintf_grdecl(zcorn_kw, stream); - ecl_kw_free(zcorn_kw); + rd_kw_type *zcorn_kw = rd_grid_alloc_zcorn_kw(grid); + rd_kw_fprintf_grdecl(zcorn_kw, stream); + rd_kw_free(zcorn_kw); fprintf(stream, "\n"); } { - ecl_kw_type *actnum_kw = ecl_grid_alloc_actnum_kw(grid); - ecl_kw_fprintf_grdecl(actnum_kw, stream); - ecl_kw_free(actnum_kw); + rd_kw_type *actnum_kw = rd_grid_alloc_actnum_kw(grid); + rd_kw_fprintf_grdecl(actnum_kw, stream); + rd_kw_free(actnum_kw); fprintf(stream, "\n"); } } -void ecl_grid_fprintf_grdecl(ecl_grid_type *grid, FILE *stream) { - ecl_grid_fprintf_grdecl2(grid, stream, ECL_METRIC_UNITS); +void rd_grid_fprintf_grdecl(rd_grid_type *grid, FILE *stream) { + rd_grid_fprintf_grdecl2(grid, stream, RD_METRIC_UNITS); } /** @@ -7003,100 +6943,100 @@ void ecl_grid_fprintf_grdecl(ecl_grid_type *grid, FILE *stream) { global_index. */ -void ecl_grid_cell_ri_export(const ecl_grid_type *ecl_grid, int global_index, - double *ri_points) { - const ecl_cell_type *cell = ecl_grid_get_cell(ecl_grid, global_index); +void rd_grid_cell_ri_export(const rd_grid_type *rd_grid, int global_index, + double *ri_points) { + const rd_cell_type *cell = rd_grid_get_cell(rd_grid, global_index); int offset = global_index * 8 * 3; - ecl_cell_ri_export(cell, &ri_points[offset]); + rd_cell_ri_export(cell, &ri_points[offset]); } -void ecl_grid_ri_export(const ecl_grid_type *ecl_grid, double *ri_points) { +void rd_grid_ri_export(const rd_grid_type *rd_grid, double *ri_points) { int global_index; - for (global_index = 0; global_index < ecl_grid->size; global_index++) - ecl_grid_cell_ri_export(ecl_grid, global_index, ri_points); + for (global_index = 0; global_index < rd_grid->size; global_index++) + rd_grid_cell_ri_export(rd_grid, global_index, ri_points); } -bool ecl_grid_dual_grid(const ecl_grid_type *ecl_grid) { - if (ecl_grid->dualp_flag == FILEHEAD_SINGLE_POROSITY) +bool rd_grid_dual_grid(const rd_grid_type *rd_grid) { + if (rd_grid->dualp_flag == FILEHEAD_SINGLE_POROSITY) return false; else return true; } -static int ecl_grid_get_num_nnc__(const ecl_grid_type *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++) { - const nnc_info_type *nnc_info = ecl_grid_get_cell_nnc_info1(grid, 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); } return num_nnc; } -int ecl_grid_get_num_nnc(const ecl_grid_type *grid) { - int num_nnc = ecl_grid_get_num_nnc__(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++) { - ecl_grid_type *igrid = - (ecl_grid_type *)vector_iget(grid->LGR_list, grid_nr); - num_nnc += ecl_grid_get_num_nnc__(igrid); + 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; } -static ecl_kw_type *ecl_grid_alloc_volume_kw_active(const ecl_grid_type *grid) { - ecl_kw_type *volume_kw = - ecl_kw_alloc("VOLUME", ecl_grid_get_active_size(grid), ECL_DOUBLE); +static rd_kw_type *rd_grid_alloc_volume_kw_active(const rd_grid_type *grid) { + rd_kw_type *volume_kw = + rd_kw_alloc("VOLUME", rd_grid_get_active_size(grid), RD_DOUBLE); { - double *volume_data = (double *)ecl_kw_get_ptr(volume_kw); + double *volume_data = (double *)rd_kw_get_ptr(volume_kw); int active_index; - for (active_index = 0; active_index < ecl_grid_get_active_size(grid); + for (active_index = 0; active_index < rd_grid_get_active_size(grid); active_index++) { - double cell_volume = ecl_grid_get_cell_volume1A(grid, active_index); + double cell_volume = rd_grid_get_cell_volume1A(grid, active_index); volume_data[active_index] = cell_volume; } } return volume_kw; } -static ecl_kw_type *ecl_grid_alloc_volume_kw_global(const ecl_grid_type *grid) { - ecl_kw_type *volume_kw = - ecl_kw_alloc("VOLUME", ecl_grid_get_global_size(grid), ECL_DOUBLE); +static rd_kw_type *rd_grid_alloc_volume_kw_global(const rd_grid_type *grid) { + rd_kw_type *volume_kw = + rd_kw_alloc("VOLUME", rd_grid_get_global_size(grid), RD_DOUBLE); { - double *volume_data = (double *)ecl_kw_get_ptr(volume_kw); + double *volume_data = (double *)rd_kw_get_ptr(volume_kw); int global_index; - for (global_index = 0; global_index < ecl_grid_get_global_size(grid); + for (global_index = 0; global_index < rd_grid_get_global_size(grid); global_index++) { - double cell_volume = ecl_grid_get_cell_volume1(grid, global_index); + double cell_volume = rd_grid_get_cell_volume1(grid, global_index); volume_data[global_index] = cell_volume; } } return volume_kw; } -ecl_kw_type *ecl_grid_alloc_volume_kw(const ecl_grid_type *grid, - bool active_size) { +rd_kw_type *rd_grid_alloc_volume_kw(const rd_grid_type *grid, + bool active_size) { if (active_size) - return ecl_grid_alloc_volume_kw_active(grid); + return rd_grid_alloc_volume_kw_active(grid); else - return ecl_grid_alloc_volume_kw_global(grid); + return rd_grid_alloc_volume_kw_global(grid); } //This function is meant to be used w/ pandas datafram and numpy -//Note: global_index must be allocated w/ ecl_grid->total_active or ecl_grid->global_size int32 data points -// index_data must be allocated w/ (4 * ecl_grid->total_active or ecl_grid->global_size) int32 data points. -void ecl_grid_export_index(const ecl_grid_type *grid, int *global_index, - int *index_data, bool active_only) { +//Note: global_index must be allocated w/ rd_grid->total_active or rd_grid->global_size int32 data points +// index_data must be allocated w/ (4 * rd_grid->total_active or rd_grid->global_size) int32 data points. +void rd_grid_export_index(const rd_grid_type *grid, int *global_index, + int *index_data, bool active_only) { int pos_indx = 0; int pos_data = 0; for (int k = 0; k < grid->nz; k++) for (int j = 0; j < grid->ny; j++) for (int i = 0; i < grid->nx; i++) { - int g = ecl_grid_get_global_index__(grid, i, j, k); + int g = rd_grid_get_global_index__(grid, i, j, k); if (!active_only || grid->cells[g].active_index[0] >= 0) { global_index[pos_indx++] = g; index_data[pos_data++] = i; @@ -7109,9 +7049,9 @@ void ecl_grid_export_index(const ecl_grid_type *grid, int *global_index, //This function is meant to be used w/ pandas datafram and numpy //Note: index_size must equal allocated size of output -void ecl_grid_export_data_as_int(int index_size, const int *data_index, - const ecl_kw_type *kw, int *output) { - int *input = ecl_kw_get_int_ptr(kw); +void rd_grid_export_data_as_int(int index_size, const int *data_index, + const rd_kw_type *kw, int *output) { + int *input = rd_kw_get_int_ptr(kw); for (int i = 0; i < index_size; i++) { int di = data_index[i]; if (di >= 0) @@ -7121,42 +7061,42 @@ void ecl_grid_export_data_as_int(int index_size, const int *data_index, //This function is meant to be used w/ pandas datafram and numpy //Note: index_size must equal allocated size of output -void ecl_grid_export_data_as_double(int index_size, const int *data_index, - const ecl_kw_type *kw, double *output) { +void rd_grid_export_data_as_double(int index_size, const int *data_index, + const rd_kw_type *kw, double *output) { for (int i = 0; i < index_size; i++) { int di = data_index[i]; if (di >= 0) - output[i] = ecl_kw_iget_as_double(kw, di); + output[i] = rd_kw_iget_as_double(kw, di); } } //This function is meant to be used w/ pandas datafram and numpy -void ecl_grid_export_volume(const ecl_grid_type *grid, int index_size, - const int *global_index, double *output) { +void rd_grid_export_volume(const rd_grid_type *grid, int index_size, + const int *global_index, double *output) { for (int i = 0; i < index_size; i++) { int g = global_index[i]; - output[i] = ecl_grid_get_cell_volume1(grid, g); + output[i] = rd_grid_get_cell_volume1(grid, g); } } //This function is meant to be used w/ pandas datafram and numpy -void ecl_grid_export_position(const ecl_grid_type *grid, int index_size, - const int *global_index, double *output) { +void rd_grid_export_position(const rd_grid_type *grid, int index_size, + const int *global_index, double *output) { for (int i = 0; i < index_size; i++) { int g = global_index[i]; int j = 3 * i; - ecl_grid_get_xyz1(grid, g, &output[j], &output[j + 1], &output[j + 2]); + rd_grid_get_xyz1(grid, g, &output[j], &output[j + 1], &output[j + 2]); } } //This function is meant to be used w/ pandas dataframe and numpy -void export_corners(const ecl_grid_type *grid, int index_size, +void export_corners(const rd_grid_type *grid, int index_size, const int *global_index, double *output) { double x[8], y[8], z[8]; int pos = 0; for (int i = 0; i < index_size; i++) { int g = global_index[i]; - ecl_grid_export_cell_corners1(grid, g, x, y, z); + rd_grid_export_cell_corners1(grid, g, x, y, z); for (int j = 0; j < 8; j++) { output[pos++] = x[j]; output[pos++] = y[j]; diff --git a/lib/resdata/rd_grid_cache.cpp b/lib/resdata/rd_grid_cache.cpp new file mode 100644 index 0000000000..104ed49fd8 --- /dev/null +++ b/lib/resdata/rd_grid_cache.cpp @@ -0,0 +1,45 @@ +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "detail/resdata/rd_grid_cache.hpp" + +/** + The rd_grid_cache_struct data structure internalizes the world + position of all the active cells. This is just a minor + simplification to speed up repeated calls to get the true world + coordinates of a cell. +*/ + +namespace rd { +rd_grid_cache::rd_grid_cache(const rd_grid_type *grid) : grid(grid) { + for (int active_index = 0; + active_index < rd_grid_get_active_size(this->grid); active_index++) { + double x, y, z; + int global_index = rd_grid_get_global_index1A(this->grid, active_index); + rd_grid_get_xyz1(this->grid, global_index, &x, &y, &z); + + this->gi.push_back(global_index); + this->xp.push_back(x); + this->yp.push_back(y); + this->zp.push_back(z); + } +} + +const std::vector &rd_grid_cache::volume() const { + if (this->v.empty()) { + for (int active_index = 0; active_index < this->size(); active_index++) + this->v.push_back( + rd_grid_get_cell_volume1A(this->grid, active_index)); + } + return this->v; +} + +} // namespace rd diff --git a/lib/resdata/rd_grid_dims.cpp b/lib/resdata/rd_grid_dims.cpp new file mode 100644 index 0000000000..9bdcc91f26 --- /dev/null +++ b/lib/resdata/rd_grid_dims.cpp @@ -0,0 +1,129 @@ +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +struct rd_grid_dims_struct { + vector_type *dims_list; +}; + +static void rd_grid_dims_read_EGRID(rd_grid_dims_type *grid_dims, + fortio_type *grid_fortio, + fortio_type *data_fortio) { + while (rd_kw_fseek_kw(GRIDHEAD_KW, false, false, grid_fortio)) { + grid_dims_type *dims; + { + rd_kw_type *gridhead_kw = rd_kw_fread_alloc(grid_fortio); + + int nx = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NX_INDEX); + int ny = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NY_INDEX); + int nz = rd_kw_iget_int(gridhead_kw, GRIDHEAD_NZ_INDEX); + + dims = grid_dims_alloc(nx, ny, nz, 0); + rd_kw_free(gridhead_kw); + } + + if (data_fortio) { + if (rd_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { + rd_kw_type *intehead_kw = rd_kw_fread_alloc(data_fortio); + dims->nactive = + rd_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); + rd_kw_free(intehead_kw); + } + } + + vector_append_owned_ref(grid_dims->dims_list, dims, grid_dims_free__); + } +} + +static void rd_grid_dims_read_GRID(rd_grid_dims_type *grid_dims, + fortio_type *grid_fortio, + fortio_type *data_fortio) { + while (rd_kw_fseek_kw(DIMENS_KW, false, false, grid_fortio)) { + grid_dims_type *dims; + { + rd_kw_type *dimens_kw = rd_kw_fread_alloc(grid_fortio); + + int nx = rd_kw_iget_int(dimens_kw, DIMENS_NX_INDEX); + int ny = rd_kw_iget_int(dimens_kw, DIMENS_NY_INDEX); + int nz = rd_kw_iget_int(dimens_kw, DIMENS_NZ_INDEX); + + dims = grid_dims_alloc(nx, ny, nz, 0); + rd_kw_free(dimens_kw); + } + + if (data_fortio) { + if (rd_kw_fseek_kw(INTEHEAD_KW, false, false, data_fortio)) { + rd_kw_type *intehead_kw = rd_kw_fread_alloc(data_fortio); + dims->nactive = + rd_kw_iget_int(intehead_kw, INTEHEAD_NACTIVE_INDEX); + rd_kw_free(intehead_kw); + } + } + + vector_append_owned_ref(grid_dims->dims_list, dims, grid_dims_free__); + } +} + +rd_grid_dims_type *rd_grid_dims_alloc(const char *grid_file, + const char *data_file) { + rd_grid_dims_type *grid_dims = NULL; + bool grid_fmt_file; + rd_file_enum grid_file_type = + rd_get_file_type(grid_file, &grid_fmt_file, NULL); + + if ((grid_file_type == RD_GRID_FILE) || (grid_file_type == RD_EGRID_FILE)) { + fortio_type *grid_fortio = + fortio_open_reader(grid_file, grid_fmt_file, RD_ENDIAN_FLIP); + if (grid_fortio) { + grid_dims = (rd_grid_dims_type *)util_malloc(sizeof *grid_dims); + grid_dims->dims_list = vector_alloc_new(); + + { + fortio_type *data_fortio = NULL; + bool data_fmt_file; + + if (data_file) { + rd_get_file_type(data_file, &data_fmt_file, NULL); + data_fortio = fortio_open_reader(data_file, data_fmt_file, + RD_ENDIAN_FLIP); + } + + if (grid_file_type == RD_EGRID_FILE) + rd_grid_dims_read_EGRID(grid_dims, grid_fortio, + data_fortio); + else + rd_grid_dims_read_GRID(grid_dims, grid_fortio, data_fortio); + + if (data_fortio) + fortio_fclose(data_fortio); + } + fortio_fclose(grid_fortio); + } + } + + return grid_dims; +} + +void rd_grid_dims_free(rd_grid_dims_type *grid_dims) { + vector_free(grid_dims->dims_list); + free(grid_dims); +} + +int rd_grid_dims_get_num_grids(const rd_grid_dims_type *grid_dims) { + return vector_get_size(grid_dims->dims_list); +} + +const grid_dims_type *rd_grid_dims_iget_dims(const rd_grid_dims_type *grid_dims, + int grid_nr) { + return (const grid_dims_type *)vector_iget_const(grid_dims->dims_list, + grid_nr); +} diff --git a/lib/resdata/rd_init_file.cpp b/lib/resdata/rd_init_file.cpp new file mode 100644 index 0000000000..a27cb86d58 --- /dev/null +++ b/lib/resdata/rd_init_file.cpp @@ -0,0 +1,217 @@ +/* + 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/ecl/ecl_io_config.cpp b/lib/resdata/rd_io_config.cpp similarity index 58% rename from lib/ecl/ecl_io_config.cpp rename to lib/resdata/rd_io_config.cpp index 3fcb5e7d6c..ed947f39b5 100644 --- a/lib/ecl/ecl_io_config.cpp +++ b/lib/resdata/rd_io_config.cpp @@ -3,8 +3,8 @@ #include -#include -#include +#include +#include /** This file implements a pathetically small struct which is used to @@ -29,48 +29,47 @@ typedef enum { FMT_UNDEFINED = 2 } formatted_type; -struct ecl_io_config_struct { +struct rd_io_config_struct { formatted_type formatted; unified_type unified_restart; unified_type unified_summary; }; -static ecl_io_config_type *ecl_io_config_alloc__() { - ecl_io_config_type *ecl_io_config = - (ecl_io_config_type *)util_malloc(sizeof *ecl_io_config); +static rd_io_config_type *rd_io_config_alloc__() { + rd_io_config_type *rd_io_config = + (rd_io_config_type *)util_malloc(sizeof *rd_io_config); - ecl_io_config->formatted = FMT_UNDEFINED; - ecl_io_config->unified_restart = UNIF_UNDEFINED; - ecl_io_config->unified_summary = UNIF_UNDEFINED; + rd_io_config->formatted = FMT_UNDEFINED; + rd_io_config->unified_restart = UNIF_UNDEFINED; + rd_io_config->unified_summary = UNIF_UNDEFINED; - return ecl_io_config; + return rd_io_config; } -void ecl_io_config_set_formatted(ecl_io_config_type *io_config, - bool formatted) { +void rd_io_config_set_formatted(rd_io_config_type *io_config, bool formatted) { if (formatted) io_config->formatted = FORMATTED; else io_config->formatted = UNFORMATTED; } -void ecl_io_config_set_unified_restart(ecl_io_config_type *io_config, - bool unified) { +void rd_io_config_set_unified_restart(rd_io_config_type *io_config, + bool unified) { if (unified) io_config->unified_restart = UNIFIED; else io_config->unified_restart = MULTIPLE; } -void ecl_io_config_set_unified_summary(ecl_io_config_type *io_config, - bool unified) { +void rd_io_config_set_unified_summary(rd_io_config_type *io_config, + bool unified) { if (unified) io_config->unified_summary = UNIFIED; else io_config->unified_summary = MULTIPLE; } -bool ecl_io_config_get_formatted(ecl_io_config_type *io_config) { +bool rd_io_config_get_formatted(rd_io_config_type *io_config) { if (io_config->formatted == FORMATTED) return true; else if (io_config->formatted == UNFORMATTED) @@ -81,7 +80,7 @@ bool ecl_io_config_get_formatted(ecl_io_config_type *io_config) { } } -bool ecl_io_config_get_unified_summary(ecl_io_config_type *io_config) { +bool rd_io_config_get_unified_summary(rd_io_config_type *io_config) { if (io_config->unified_summary == UNIFIED) return true; else if (io_config->unified_summary == MULTIPLE) @@ -92,7 +91,7 @@ bool ecl_io_config_get_unified_summary(ecl_io_config_type *io_config) { } } -bool ecl_io_config_get_unified_restart(ecl_io_config_type *io_config) { +bool rd_io_config_get_unified_restart(rd_io_config_type *io_config) { if (io_config->unified_restart == UNIFIED) return true; else if (io_config->unified_restart == MULTIPLE) @@ -103,15 +102,15 @@ bool ecl_io_config_get_unified_restart(ecl_io_config_type *io_config) { } } -ecl_io_config_type *ecl_io_config_alloc(bool formatted, bool unified_summary, - bool unified_restart) { - ecl_io_config_type *ecl_io_config = ecl_io_config_alloc__(); +rd_io_config_type *rd_io_config_alloc(bool formatted, bool unified_summary, + bool unified_restart) { + rd_io_config_type *rd_io_config = rd_io_config_alloc__(); - ecl_io_config_set_formatted(ecl_io_config, formatted); - ecl_io_config_set_unified_restart(ecl_io_config, unified_restart); - ecl_io_config_set_unified_summary(ecl_io_config, unified_summary); + rd_io_config_set_formatted(rd_io_config, formatted); + rd_io_config_set_unified_restart(rd_io_config, unified_restart); + rd_io_config_set_unified_summary(rd_io_config, unified_summary); - return ecl_io_config; + return rd_io_config; } -void ecl_io_config_free(ecl_io_config_type *io_config) { free(io_config); } +void rd_io_config_free(rd_io_config_type *io_config) { free(io_config); } diff --git a/lib/resdata/rd_kw.cpp b/lib/resdata/rd_kw.cpp new file mode 100644 index 0000000000..dfe2543b93 --- /dev/null +++ b/lib/resdata/rd_kw.cpp @@ -0,0 +1,2842 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#define RD_KW_TYPE_ID 6111098 + +struct rd_kw_struct { + UTIL_TYPE_ID_DECLARATION; + int size; + rd_data_type data_type; + char * + header8; /* Header which is right padded with ' ' to become exactly 8 characters long. Should only be used internally.*/ + char *header; /* Header which is trimmed to no-space. */ + char *data; /* The actual data vector. */ + bool shared_data; /* Whether this keyword has shared data or not. */ +}; + +UTIL_IS_INSTANCE_FUNCTION(rd_kw, RD_KW_TYPE_ID) + +/* For some peculiar reason the keyword data is written in blocks, all + numeric data is in blocks of 1000 elements, and character data is + in blocks of 105 elements. +*/ + +#define BLOCKSIZE_NUMERIC 1000 +#define BLOCKSIZE_CHAR 105 + +/* When writing formatted data, the data comes in columns, with a + certain number of elements in each row, i.e. four columns for float + data: + + 0.000 0.000 0.000 0.000 + 0.000 0.000 0.000 0.000 + 0.000 0.000 0.000 0.000 + .... + + These #define symbols define the number of columns for the + different datatypes. +*/ +#define COLUMNS_CHAR 7 +#define COLUMNS_FLOAT 4 +#define COLUMNS_DOUBLE 3 +#define COLUMNS_INT 6 +#define COLUMNS_MESSAGE 1 +#define COLUMNS_BOOL 25 + +/* Format string used when writing a formatted header. */ +#define WRITE_HEADER_FMT " '%-8s' %11d '%-4s'\n" + +/* Format string used when reading and writing formatted + files. Observe the following about these format strings: + + 1. The format string for reading double contains two '%' + identifiers, that is because doubles are read by parsing a + prefix and power separately. + + 2. For both double and float the write format contains two '%' + characters - that is because the values are split in a prefix + and a power prior to writing - see the function + __fprintf_scientific(). + + 3. The logical type involves converting back and forth between 'T' + and 'F' and internal logical representation. The format strings + are therefore for reading/writing a character. + +*/ + +#define READ_FMT_CHAR "%8c" +#define READ_FMT_FLOAT "%gE" +#define READ_FMT_INT "%d" +#define READ_FMT_MESS "%8c" +#define READ_FMT_BOOL " %c" +#define READ_FMT_DOUBLE "%lgD%d" + +#define WRITE_FMT_CHAR " '%-8s'" +#define WRITE_FMT_INT " %11d" +#define WRITE_FMT_FLOAT " %11.8fE%+03d" +#define WRITE_FMT_DOUBLE " %17.14fD%+03d" +#define WRITE_FMT_MESS "%s" +#define WRITE_FMT_BOOL " %c" + +/* The boolean type is not a native type which can be uniquely + identified between Fortran, C, formatted and unformatted + files: + + o In the formatted files the characters BOOL_TRUE_CHAR and + BOOL_FALSE_CHAR are used to represent true and false values + repsectively. + + o In the unformatted files the boolean values are + represented as integers with the values RD_BOOL_TRUE_INT and + RD_BOOL_FALSE_INT respectively. + + Internally in an rd_kw instance boolean values are represented as + integers (NOT bool), with the representation given by RD_BOOL_TRUE_INT + and RD_BOOL_FALSE_INT. This implies that read/write of unformatted + data can go transparently without between ECLIPSE and the rd_kw + implementation, but exported set()/get() functions with bool must + intercept the bool values and convert to the appropriate integer + value. +*/ + +// For formatted files: +#define BOOL_TRUE_CHAR 'T' +#define BOOL_FALSE_CHAR 'F' + +rd_type_enum rd_kw_get_type(const rd_kw_type *); +void rd_kw_set_data_type(rd_kw_type *rd_kw, rd_data_type data_type); + +static char *alloc_read_fmt_string(const rd_data_type rd_type) { + return util_alloc_sprintf("%%%dc", rd_type_get_sizeof_iotype(rd_type)); +} + +static char *alloc_read_fmt(const rd_data_type data_type) { + switch (rd_type_get_type(data_type)) { + case (RD_CHAR_TYPE): + return util_alloc_string_copy(READ_FMT_CHAR); + case (RD_INT_TYPE): + return util_alloc_string_copy(READ_FMT_INT); + case (RD_FLOAT_TYPE): + return util_alloc_string_copy(READ_FMT_FLOAT); + case (RD_DOUBLE_TYPE): + return util_alloc_string_copy(READ_FMT_DOUBLE); + case (RD_BOOL_TYPE): + return util_alloc_string_copy(READ_FMT_BOOL); + case (RD_MESS_TYPE): + return util_alloc_string_copy(READ_FMT_MESS); + case (RD_STRING_TYPE): + return alloc_read_fmt_string(data_type); + default: + util_abort("%s: invalid rd_type:%s \n", __func__, + rd_type_alloc_name(data_type)); + return NULL; + } +} + +static char *alloc_write_fmt_string(const rd_data_type rd_type) { + return util_alloc_sprintf(" '%%-%ds'", rd_type_get_sizeof_iotype(rd_type)); +} + +static char *alloc_write_fmt(const rd_data_type data_type) { + switch (rd_type_get_type(data_type)) { + case (RD_CHAR_TYPE): + return util_alloc_string_copy(WRITE_FMT_CHAR); + case (RD_INT_TYPE): + return util_alloc_string_copy(WRITE_FMT_INT); + case (RD_FLOAT_TYPE): + return util_alloc_string_copy(WRITE_FMT_FLOAT); + case (RD_DOUBLE_TYPE): + return util_alloc_string_copy(WRITE_FMT_DOUBLE); + case (RD_BOOL_TYPE): + return util_alloc_string_copy(WRITE_FMT_BOOL); + case (RD_MESS_TYPE): + return util_alloc_string_copy(WRITE_FMT_MESS); + case (RD_STRING_TYPE): + return alloc_write_fmt_string(data_type); + default: + util_abort("%s: invalid rd_type: %s\n", __func__, + rd_type_alloc_name(data_type)); + return NULL; + } +} + +static int get_blocksize(rd_data_type data_type) { + if (rd_type_is_alpha(data_type)) + return BLOCKSIZE_CHAR; + + return BLOCKSIZE_NUMERIC; +} + +static int get_columns(const rd_data_type data_type) { + switch (rd_type_get_type(data_type)) { + case (RD_CHAR_TYPE): + return COLUMNS_CHAR; + case (RD_INT_TYPE): + return COLUMNS_INT; + case (RD_FLOAT_TYPE): + return COLUMNS_FLOAT; + case (RD_DOUBLE_TYPE): + return COLUMNS_DOUBLE; + case (RD_BOOL_TYPE): + return COLUMNS_BOOL; + case (RD_MESS_TYPE): + return COLUMNS_MESSAGE; + case (RD_STRING_TYPE): + return COLUMNS_CHAR; // TODO: Is this correct? + default: + util_abort("%s: invalid rd_type: %s\n", __func__, + rd_type_alloc_name(data_type)); + return -1; + } +} + +static void rd_kw_assert_index(const rd_kw_type *rd_kw, int index, + const char *caller) { + if (index < 0 || index >= rd_kw->size) + util_abort( + "%s: Invalid index lookup. kw:%s input_index:%d size:%d \n", + caller, rd_kw->header, index, rd_kw->size); +} + +static char *rd_kw_alloc_output_buffer(const rd_kw_type *rd_kw) { + size_t sizeof_iotype = rd_type_get_sizeof_iotype(rd_kw->data_type); + size_t buffer_size = rd_kw->size * sizeof_iotype; + char *buffer = (char *)util_malloc(buffer_size); + + if (rd_type_is_bool(rd_kw->data_type)) { + int *int_data = (int *)buffer; + bool *bool_data = (bool *)rd_kw->data; + + for (int i = 0; i < rd_kw->size; i++) + if (bool_data[i]) + int_data[i] = RD_BOOL_TRUE_INT; + else + int_data[i] = RD_BOOL_FALSE_INT; + + util_endian_flip_vector(buffer, sizeof_iotype, rd_kw->size); + return buffer; + } + + if (rd_type_is_char(rd_kw->data_type) || + rd_type_is_string(rd_kw->data_type)) { + size_t sizeof_ctype = rd_type_get_sizeof_ctype(rd_kw->data_type); + for (int i = 0; i < rd_kw->size; i++) { + size_t buffer_offset = i * sizeof_iotype; + size_t data_offset = i * sizeof_ctype; + size_t string_length = strlen(&rd_kw->data[data_offset]); + + for (size_t i = 0; i < string_length; i++) + buffer[buffer_offset + i] = rd_kw->data[data_offset + i]; + + // Pad with spaces + for (size_t i = string_length; i < sizeof_iotype; i++) + buffer[buffer_offset + i] = ' '; + } + + return buffer; + } + + if (rd_type_is_mess(rd_kw->data_type)) + return buffer; + + if (rd_kw->data) { + memcpy(buffer, rd_kw->data, buffer_size); + util_endian_flip_vector(buffer, sizeof_iotype, rd_kw->size); + } + + return buffer; +} + +static char *rd_kw_alloc_input_buffer(const rd_kw_type *rd_kw) { + size_t buffer_size = + rd_kw->size * rd_type_get_sizeof_iotype(rd_kw->data_type); + char *buffer = (char *)util_malloc(buffer_size); + + return buffer; +} + +static void rd_kw_load_from_input_buffer(rd_kw_type *rd_kw, char *buffer) { + size_t sizeof_iotype = rd_type_get_sizeof_iotype(rd_kw->data_type); + size_t sizeof_ctype = rd_type_get_sizeof_ctype(rd_kw->data_type); + size_t buffer_size = rd_kw->size * sizeof_iotype; + if (RD_ENDIAN_FLIP) { + if (rd_type_is_numeric(rd_kw->data_type) || + rd_type_is_bool(rd_kw->data_type)) + util_endian_flip_vector(buffer, sizeof_iotype, rd_kw->size); + } + + /* + Special case bool: Return Eclipse integer representation of bool to native bool. + */ + if (rd_type_is_bool(rd_kw->data_type)) { + int *int_data = (int *)buffer; + bool *bool_data = (bool *)rd_kw->data; + + for (int i = 0; i < rd_kw->size; i++) { + if (int_data[i] == RD_BOOL_TRUE_INT) + bool_data[i] = true; + else + bool_data[i] = false; + } + return; + } + + /* + Special case: insert '\0' termination at end of strings loaded from file; + when writing out again strlen() will be called on data - i.e. it is + paramount to add this '\0'. + */ + if (rd_type_is_char(rd_kw->data_type) || + rd_type_is_string(rd_kw->data_type)) { + const char null_char = '\0'; + for (int i = 0; i < rd_kw->size; i++) { + size_t buffer_offset = i * sizeof_iotype; + size_t data_offset = i * sizeof_ctype; + memcpy(&rd_kw->data[data_offset], &buffer[buffer_offset], + sizeof_iotype); + rd_kw->data[data_offset + sizeof_iotype] = null_char; + } + return; + } + + if (rd_type_is_mess(rd_kw->data_type)) + return; + + /* + Plain int, double, float data - that can be copied straight over to the ->data field. + */ + memcpy(rd_kw->data, buffer, buffer_size); +} + +const char *rd_kw_get_header8(const rd_kw_type *rd_kw) { + return rd_kw->header8; +} + +/* + Return the header without the trailing spaces +*/ +const char *rd_kw_get_header(const rd_kw_type *rd_kw) { return rd_kw->header; } + +bool rd_kw_name_equal(const rd_kw_type *rd_kw, const char *name) { + return (strcmp(rd_kw->header, name) == 0); +} + +void rd_kw_get_memcpy_data(const rd_kw_type *rd_kw, void *target) { + memcpy(target, rd_kw->data, + rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type)); +} + +void rd_kw_get_memcpy_int_data(const rd_kw_type *rd_kw, int *target) { + if (rd_type_is_int(rd_kw->data_type)) + rd_kw_get_memcpy_data(rd_kw, target); +} + +void rd_kw_get_memcpy_float_data(const rd_kw_type *rd_kw, float *target) { + if (rd_type_is_float(rd_kw->data_type)) + rd_kw_get_memcpy_data(rd_kw, target); +} + +void rd_kw_get_memcpy_double_data(const rd_kw_type *rd_kw, double *target) { + if (rd_type_is_double(rd_kw->data_type)) + rd_kw_get_memcpy_data(rd_kw, target); +} + +/** Allocates a untyped buffer with exactly the same content as the rd_kw instances data. */ +void *rd_kw_alloc_data_copy(const rd_kw_type *rd_kw) { + void *buffer = util_alloc_copy( + rd_kw->data, rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type)); + return buffer; +} + +void rd_kw_set_memcpy_data(rd_kw_type *rd_kw, const void *src) { + if (src != NULL) + memcpy(rd_kw->data, src, + rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type)); +} + +static bool rd_kw_string_eq(const char *s1, const char *s2) { + const char space_char = ' '; + const char *long_kw = (strlen(s1) >= strlen(s2)) ? s1 : s2; + const char *short_kw = (strlen(s1) < strlen(s2)) ? s1 : s2; + const int len1 = strlen(long_kw); + const int len2 = strlen(short_kw); + int index; + bool eq = true; + if (len1 > RD_STRING8_LENGTH) + util_abort("%s : eclipse keyword:%s is too long - aborting \n", + __func__, long_kw); + + for (index = 0; index < len2; index++) + eq = eq & (long_kw[index] == short_kw[index]); + + if (eq) { + for (index = len2; index < len1; index++) + eq = eq & (long_kw[index] == space_char); + } + + return eq; +} + +bool rd_kw_ichar_eq(const rd_kw_type *rd_kw, int i, const char *value) { + char s1[RD_STRING8_LENGTH + 1]; + rd_kw_iget(rd_kw, i, s1); + return rd_kw_string_eq(s1, value); +} + +bool rd_kw_size_and_type_equal(const rd_kw_type *rd_kw1, + const rd_kw_type *rd_kw2) { + return (rd_kw1->size == rd_kw2->size && + rd_type_is_equal(rd_kw1->data_type, rd_kw2->data_type)); +} + +bool rd_kw_header_eq(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2) { + bool equal = true; + + if (strcmp(rd_kw1->header8, rd_kw2->header8) != 0) + equal = false; + else + equal = rd_kw_size_and_type_equal(rd_kw1, rd_kw2); + + return equal; +} + +static bool rd_kw_data_equal__(const rd_kw_type *rd_kw, const void *data, + int cmp_elements) { + int cmp = memcmp(rd_kw->data, data, + cmp_elements * rd_type_get_sizeof_ctype(rd_kw->data_type)); + if (cmp == 0) + return true; + else + return false; +} + +/** + Observe that the comparison is done with memcmp() - + i.e. "reasonably good" numerical agreement is *not* enough. +*/ + +bool rd_kw_data_equal(const rd_kw_type *rd_kw, const void *data) { + return rd_kw_data_equal__(rd_kw, data, rd_kw->size); +} + +bool rd_kw_content_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2) { + if (rd_kw_size_and_type_equal(rd_kw1, rd_kw2)) + return rd_kw_data_equal__(rd_kw1, rd_kw2->data, rd_kw1->size); + else + return false; +} + +/** + This function compares two rd_kw instances, and returns true if they are equal. +*/ + +bool rd_kw_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2) { + bool equal = rd_kw_header_eq(rd_kw1, rd_kw2); + if (equal) + equal = rd_kw_data_equal(rd_kw1, rd_kw2->data); + + return equal; +} + +#define RD_KW_NUMERIC_CMP(ctype) \ + static bool rd_kw_numeric_equal_##ctype(const rd_kw_type *rd_kw1, \ + const rd_kw_type *rd_kw2, \ + ctype abs_diff, ctype rel_diff) { \ + int index; \ + bool equal = true; \ + { \ + const ctype *data1 = (const ctype *)rd_kw1->data; \ + const ctype *data2 = (const ctype *)rd_kw2->data; \ + for (index = 0; index < rd_kw1->size; index++) { \ + equal = util_##ctype##_approx_equal__( \ + data1[index], data2[index], rel_diff, abs_diff); \ + if (!equal) \ + break; \ + } \ + } \ + return equal; \ + } + +RD_KW_NUMERIC_CMP(float) +RD_KW_NUMERIC_CMP(double) +#undef RD_KW_NUMERIC_CMP + +/** + This function compares the data of two rd_kw instances, and + returns true if the relative numerical difference is less than + @rel_diff. Does not consider consider the kw header. +*/ + +bool rd_kw_numeric_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2, + double abs_diff, double rel_diff) { + if (!rd_kw_size_and_type_equal(rd_kw1, rd_kw2)) + return false; + + if (rd_type_is_float(rd_kw1->data_type)) + return rd_kw_numeric_equal_float(rd_kw1, rd_kw2, abs_diff, rel_diff); + else if (rd_type_is_double(rd_kw1->data_type)) + return rd_kw_numeric_equal_double(rd_kw1, rd_kw2, abs_diff, rel_diff); + else + return rd_kw_data_equal(rd_kw1, rd_kw2->data); +} + +bool rd_kw_block_equal(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2, + int cmp_elements) { + if (rd_kw_header_eq(rd_kw1, rd_kw2)) { + if (cmp_elements == 0) + cmp_elements = rd_kw1->size; + + return rd_kw_data_equal__(rd_kw1, rd_kw2->data, cmp_elements); + } else + return false; +} + +static void rd_kw_set_shared_ref(rd_kw_type *rd_kw, void *data_ptr) { + if (!rd_kw->shared_data) { + if (rd_kw->data != NULL) + util_abort("%s: can not change to shared for keyword with " + "allocated storage - aborting \n", + __func__); + } + rd_kw->shared_data = true; + rd_kw->data = (char *)data_ptr; +} + +static void rd_kw_initialize(rd_kw_type *rd_kw, const char *header, int size, + rd_data_type data_type) { + rd_kw_set_data_type(rd_kw, data_type); + rd_kw_set_header_name(rd_kw, header); + rd_kw->size = size; +} + +static size_t rd_kw_fortio_data_size(const rd_kw_type *rd_kw) { + const int blocksize = get_blocksize(rd_kw->data_type); + const int num_blocks = + rd_kw->size / blocksize + (rd_kw->size % blocksize == 0 ? 0 : 1); + + return num_blocks * (4 + 4) + // Fortran fluff for each block + rd_kw->size * + rd_type_get_sizeof_iotype(rd_kw->data_type); // Actual data +} + +/** + Returns the number of bytes this rd_kw instance would occupy in + BINARY file; we add 2*4 to the header size to include the size of + the fortran header and trailer combo. +*/ + +size_t rd_kw_fortio_size(const rd_kw_type *rd_kw) { + size_t size = RD_KW_HEADER_FORTIO_SIZE; + size += rd_kw_fortio_data_size(rd_kw); + return size; +} + +/** + The data is copied from the input argument to the rd_kw; data can be NULL. +*/ +rd_kw_type *rd_kw_alloc_new(const char *header, int size, + rd_data_type data_type, const void *data) { + rd_kw_type *rd_kw; + rd_kw = rd_kw_alloc_empty(); + rd_kw_initialize(rd_kw, header, size, data_type); + if (data != NULL) { + rd_kw_alloc_data(rd_kw); + rd_kw_set_memcpy_data(rd_kw, data); + } + return rd_kw; +} + +rd_kw_type *rd_kw_alloc(const char *header, int size, rd_data_type data_type) { + rd_kw_type *rd_kw; + + rd_kw = rd_kw_alloc_empty(); + rd_kw_initialize(rd_kw, header, size, data_type); + rd_kw_alloc_data(rd_kw); + + return rd_kw; +} + +rd_kw_type *rd_kw_alloc_new_shared(const char *header, int size, + rd_data_type data_type, void *data) { + rd_kw_type *rd_kw; + rd_kw = rd_kw_alloc_empty(); + rd_kw_initialize(rd_kw, header, size, data_type); + rd_kw_set_shared_ref(rd_kw, data); + return rd_kw; +} + +rd_kw_type *rd_kw_alloc_empty() { + rd_kw_type *rd_kw; + + rd_kw = (rd_kw_type *)util_malloc(sizeof *rd_kw); + rd_kw->header = NULL; + rd_kw->header8 = NULL; + rd_kw->data = NULL; + rd_kw->shared_data = false; + rd_kw->size = 0; + + UTIL_TYPE_ID_INIT(rd_kw, RD_KW_TYPE_ID); + + return rd_kw; +} + +void rd_kw_free(rd_kw_type *rd_kw) { + free(rd_kw->header); + free(rd_kw->header8); + rd_kw_free_data(rd_kw); + free(rd_kw); +} + +void rd_kw_free__(void *void_rd_kw) { rd_kw_free((rd_kw_type *)void_rd_kw); } + +void rd_kw_memcpy_data(rd_kw_type *target, const rd_kw_type *src) { + if (!rd_kw_size_and_type_equal(target, src)) + util_abort("%s: type/size mismatch \n", __func__); + + memcpy(target->data, src->data, + target->size * rd_type_get_sizeof_ctype(target->data_type)); +} + +void rd_kw_memcpy(rd_kw_type *target, const rd_kw_type *src) { + target->size = src->size; + rd_kw_set_data_type(target, src->data_type); + + rd_kw_set_header_name(target, src->header); + rd_kw_alloc_data(target); + rd_kw_memcpy_data(target, src); +} + +rd_kw_type *rd_kw_alloc_copy(const rd_kw_type *src) { + rd_kw_type *new_; + new_ = rd_kw_alloc_empty(); + rd_kw_memcpy(new_, src); + return new_; +} + +/** + This function will allocate a new copy of @src, where only the + elements corresponding to the slice [index1:index2) is included. + + The input parameters @index1 and @index2 can to some extent be + out-of-range: + + index1 = max( index1 , 0 ); + index2 = min( index2 , size ); + + If index1 > index2 it will fail hard; the same applies if stride is + <= 0. +*/ + +rd_kw_type *rd_kw_alloc_slice_copy(const rd_kw_type *src, int index1, + int index2, int stride) { + if (index1 < 0) + index1 = 0; + if (index2 > src->size) + index2 = src->size; + if (index1 >= src->size) + util_abort("%s: index1=%d > size:%d \n", __func__, index1, src->size); + if (stride <= 0) + util_abort("%s: stride:%d completely broken ...\n", __func__, stride); + { + rd_kw_type *new_kw = NULL; + int src_index = index1; + /* 1: Determine size of the sliced copy. */ + { + int new_size = 0; + while (src_index < index2) { + new_size++; + src_index += stride; + } + if (new_size > 0) { + new_kw = rd_kw_alloc_empty(); + rd_kw_initialize(new_kw, src->header, new_size, src->data_type); + rd_kw_alloc_data(new_kw); + + /* 2: Copy over the elements. */ + src_index = index1; + { + int target_index = 0; + const char *src_ptr = src->data; + char *new_ptr = new_kw->data; + int sizeof_ctype = + rd_type_get_sizeof_ctype(new_kw->data_type); + + while (src_index < index2) { + memcpy(&new_ptr[target_index * sizeof_ctype], + &src_ptr[src_index * sizeof_ctype], + sizeof_ctype); + src_index += stride; + target_index += 1; + } + } + } + } + return new_kw; + } +} + +void rd_kw_resize(rd_kw_type *rd_kw, int new_size) { + if (rd_kw->shared_data) + util_abort("%s: trying to allocate data for rd_kw object which has " + "been declared with shared storage - aborting \n", + __func__); + + if (new_size != rd_kw->size) { + size_t old_byte_size = + rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type); + size_t new_byte_size = + new_size * rd_type_get_sizeof_ctype(rd_kw->data_type); + + rd_kw->data = (char *)util_realloc(rd_kw->data, new_byte_size); + if (new_byte_size > old_byte_size) { + size_t offset = old_byte_size; + memset(&rd_kw->data[offset], 0, new_byte_size - old_byte_size); + } + rd_kw->size = new_size; + } +} + +/** + Will allocate a copy of the src_kw. Will copy @count elements + starting at @offset. If @count < 0 all remaining elements from + @offset will be copied. If new_kw == NULL the new keyword will have + the same header as the @src, otherwise the value @new_kw will be + used. +*/ + +rd_kw_type *rd_kw_alloc_sub_copy(const rd_kw_type *src, const char *new_kw, + int offset, int count) { + if (new_kw == NULL) + new_kw = src->header; + + if (count < 0) + count = src->size - offset; + + if ((offset < 0) || (offset >= src->size)) + util_abort("%s: invalid offset - limits: [%d,%d) \n", __func__, 0, + src->size); + if ((count + offset) > src->size) + util_abort("%s: invalid count value: %d \n", __func__, count); + + { + void *src_data = rd_kw_iget_ptr(src, offset); + return rd_kw_alloc_new(new_kw, count, src->data_type, src_data); + } +} + +const void *rd_kw_copyc__(const void *void_kw) { + return rd_kw_alloc_copy((const rd_kw_type *)void_kw); +} + +static void *rd_kw_iget_ptr_static(const rd_kw_type *rd_kw, int i) { + rd_kw_assert_index(rd_kw, i, __func__); + return &rd_kw->data[i * rd_type_get_sizeof_ctype(rd_kw->data_type)]; +} + +static void rd_kw_iget_static(const rd_kw_type *rd_kw, int i, void *iptr) { + memcpy(iptr, rd_kw_iget_ptr_static(rd_kw, i), + rd_type_get_sizeof_ctype(rd_kw->data_type)); +} + +static void rd_kw_iset_static(rd_kw_type *rd_kw, int i, const void *iptr) { + size_t sizeof_ctype = rd_type_get_sizeof_ctype(rd_kw->data_type); + rd_kw_assert_index(rd_kw, i, __func__); + memcpy(&rd_kw->data[i * sizeof_ctype], iptr, sizeof_ctype); +} + +void rd_kw_iget(const rd_kw_type *rd_kw, int i, void *iptr) { + rd_kw_iget_static(rd_kw, i, iptr); +} + +/** + Will return a double value for underlying data types of double, + float and int. +*/ +double rd_kw_iget_as_double(const rd_kw_type *rd_kw, int index) { + if (rd_type_is_float(rd_kw->data_type)) + return rd_kw_iget_float( + rd_kw, + index); /* Here the compiler will silently insert a float -> double conversion. */ + else if (rd_type_is_double(rd_kw->data_type)) + return rd_kw_iget_double(rd_kw, index); + else if (rd_type_is_int(rd_kw->data_type)) + return rd_kw_iget_int(rd_kw, index); /* */ + else { + util_abort("%s: can not be converted to double - no data for you! \n", + __func__); + return -1; + } +} + +/** + Will return a float value for underlying data types of double and float. +*/ + +float rd_kw_iget_as_float(const rd_kw_type *rd_kw, int i) { + if (rd_type_is_float(rd_kw->data_type)) + return rd_kw_iget_float(rd_kw, i); + else if (rd_type_is_double(rd_kw->data_type)) + return (float)rd_kw_iget_double(rd_kw, i); + else { + util_abort("%s: can not be converted to float - no data for you! \n", + __func__); + return -1; + } +} + +#define RD_KW_IGET_TYPED(ctype, RD_TYPE) \ + ctype rd_kw_iget_##ctype(const rd_kw_type *rd_kw, int i) { \ + ctype value; \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + rd_kw_iget_static(rd_kw, i, &value); \ + return value; \ + } + +RD_KW_IGET_TYPED(double, RD_DOUBLE_TYPE); +RD_KW_IGET_TYPED(float, RD_FLOAT_TYPE); +RD_KW_IGET_TYPED(int, RD_INT_TYPE); +RD_KW_IGET_TYPED(bool, RD_BOOL_TYPE); +#undef RD_KW_IGET_TYPED + +const char *rd_kw_iget_char_ptr(const rd_kw_type *rd_kw, int i) { + if (rd_kw_get_type(rd_kw) != RD_CHAR_TYPE) + util_abort("%s: Keyword: %s is wrong type - aborting \n", __func__, + rd_kw_get_header8(rd_kw)); + return (const char *)rd_kw_iget_ptr(rd_kw, i); +} + +const char *rd_kw_iget_string_ptr(const rd_kw_type *rd_kw, int i) { + if (rd_kw_get_type(rd_kw) != RD_STRING_TYPE) + util_abort("%s: Keyword: %s is wrong type - aborting \n", __func__, + rd_kw_get_header8(rd_kw)); + return (const char *)rd_kw_iget_ptr(rd_kw, i); +} + +/** + This will set the elemnts of the rd_kw data storage in index to + the value of s8; if s8 is shorter than 8 characters the result will + be padded, if s8 is longer than 8 characters the characters from 9 + and out will be ignored. +*/ +void rd_kw_iset_string8(rd_kw_type *rd_kw, int index, const char *s8) { + char *rd_string = (char *)rd_kw_iget_ptr(rd_kw, index); + if (strlen(s8) >= RD_STRING8_LENGTH) { + /* The whole string goes in - possibly loosing content at the end. */ + int i; + for (i = 0; i < RD_STRING8_LENGTH; i++) + rd_string[i] = s8[i]; + } else { + /* The string is padded with trailing spaces. */ + int string_length = strlen(s8); + int i; + + for (i = 0; i < string_length; i++) + rd_string[i] = s8[i]; + + for (i = string_length; i < RD_STRING8_LENGTH; i++) + rd_string[i] = ' '; + } + + rd_string[RD_STRING8_LENGTH] = '\0'; +} + +/** + This function will set the string @index in the rd_kw string array + to @s. IFF @s is longer than 8 characters, the first part will go + in element @index, and then we will continue writing into the next + elements. If the resulting index goes beyond the length of the + keyword - WhamBang! + + You should know what you are doing when sending in a string of + length greater than 8 - maybe the overwriting of consecutive + elements is not what you want? +*/ +void rd_kw_iset_char_ptr(rd_kw_type *rd_kw, int index, const char *s) { + int strings = strlen(s) / RD_STRING8_LENGTH; + if ((strlen(s) % RD_STRING8_LENGTH) != 0) + strings++; + { + int sub_index; + for (sub_index = 0; sub_index < strings; sub_index++) + rd_kw_iset_string8(rd_kw, index + sub_index, + &s[sub_index * RD_STRING8_LENGTH]); + } +} + +/** + This function will verify that the given string is of approperiate + length (0 <= lenght <= data_type.element_size). If so, the elements + of @s will be written to the @rd_kw string array starting at + @index. If the input string is shorter than the type length the + string will be padded with trailing spaces. + */ +void rd_kw_iset_string_ptr(rd_kw_type *rd_kw, int index, const char *s) { + if (!rd_type_is_alpha(rd_kw_get_data_type(rd_kw))) { + char *type_name = rd_type_alloc_name(rd_kw_get_data_type(rd_kw)); + util_abort( + "%s: Expected alphabetic data type (CHAR, CXXX or MESS), was %s\n", + __func__, type_name); + } + + size_t input_len = strlen(s); + size_t type_len = rd_type_get_sizeof_iotype(rd_kw->data_type); + + if (input_len > type_len) + util_abort( + "%s: String of length %d cannot hold input string of length %d\n", + __func__, type_len, input_len); + + { + char *rd_string = (char *)rd_kw_iget_ptr(rd_kw, index); + size_t i; + + for (i = 0; i < input_len; ++i) + rd_string[i] = s[i]; + + for (i = input_len; i < type_len; ++i) + rd_string[i] = ' '; + + rd_string[type_len] = '\0'; + } +} + +/** + This function will compare the string at position @index with the + input @other string. The comparison will be done in a + 'space-tolerant', i.e. trailing spaces are ignored in the + comparison. If the strings are considered equal true is returned. +*/ + +bool rd_kw_icmp_string(const rd_kw_type *rd_kw, int index, + const char *other_string) { + const char *kw_string = (const char *)rd_kw_iget_char_ptr(rd_kw, index); + if (strlen(other_string)) { + const char *match = strstr(kw_string, other_string); + if (match == kw_string) + return true; + } + + return false; +} + +#define RD_KW_ISET_TYPED(ctype, RD_TYPE) \ + void rd_kw_iset_##ctype(rd_kw_type *rd_kw, int i, ctype value) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + rd_kw_iset_static(rd_kw, i, &value); \ + } + +RD_KW_ISET_TYPED(double, RD_DOUBLE_TYPE); +RD_KW_ISET_TYPED(float, RD_FLOAT_TYPE); +RD_KW_ISET_TYPED(int, RD_INT_TYPE); +RD_KW_ISET_TYPED(bool, RD_BOOL_TYPE); +#undef RD_KW_ISET_TYPED + +#define RD_KW_SET_INDEXED(ctype, RD_TYPE) \ + void rd_kw_set_indexed_##ctype( \ + rd_kw_type *rd_kw, const int_vector_type *index_list, ctype value) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + { \ + ctype *data = (ctype *)rd_kw->data; \ + int size = int_vector_size(index_list); \ + const int *index_ptr = int_vector_get_const_ptr(index_list); \ + int i; \ + for (i = 0; i < size; i++) \ + data[index_ptr[i]] = value; \ + } \ + } + +RD_KW_SET_INDEXED(double, RD_DOUBLE_TYPE); +RD_KW_SET_INDEXED(float, RD_FLOAT_TYPE); +RD_KW_SET_INDEXED(int, RD_INT_TYPE); +#undef RD_KW_SET_INDEXED + +#define RD_KW_SHIFT_INDEXED(ctype, RD_TYPE) \ + void rd_kw_shift_indexed_##ctype( \ + rd_kw_type *rd_kw, const int_vector_type *index_list, ctype shift) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + { \ + ctype *data = (ctype *)rd_kw->data; \ + int size = int_vector_size(index_list); \ + const int *index_ptr = int_vector_get_const_ptr(index_list); \ + int i; \ + for (i = 0; i < size; i++) \ + data[index_ptr[i]] += shift; \ + } \ + } + +RD_KW_SHIFT_INDEXED(double, RD_DOUBLE_TYPE); +RD_KW_SHIFT_INDEXED(float, RD_FLOAT_TYPE); +RD_KW_SHIFT_INDEXED(int, RD_INT_TYPE); +#undef RD_KW_SHIFT_INDEXED + +#define RD_KW_SCALE_INDEXED(ctype, RD_TYPE) \ + void rd_kw_scale_indexed_##ctype( \ + rd_kw_type *rd_kw, const int_vector_type *index_list, ctype scale) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + { \ + ctype *data = (ctype *)rd_kw->data; \ + int size = int_vector_size(index_list); \ + const int *index_ptr = int_vector_get_const_ptr(index_list); \ + int i; \ + for (i = 0; i < size; i++) \ + data[index_ptr[i]] *= scale; \ + } \ + } + +RD_KW_SCALE_INDEXED(double, RD_DOUBLE_TYPE); +RD_KW_SCALE_INDEXED(float, RD_FLOAT_TYPE); +RD_KW_SCALE_INDEXED(int, RD_INT_TYPE); +#undef RD_KW_SCALE_INDEXED + +#define RD_KW_GET_TYPED_PTR(ctype, RD_TYPE) \ + ctype *rd_kw_get_##ctype##_ptr(const rd_kw_type *rd_kw) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + return (ctype *)rd_kw->data; \ + } + +RD_KW_GET_TYPED_PTR(double, RD_DOUBLE_TYPE); +RD_KW_GET_TYPED_PTR(float, RD_FLOAT_TYPE); +RD_KW_GET_TYPED_PTR(int, RD_INT_TYPE); +RD_KW_GET_TYPED_PTR(bool, RD_BOOL_TYPE); +#undef RD_KW_GET_TYPED_PTR + +void *rd_kw_get_void_ptr(const rd_kw_type *rd_kw) { return rd_kw->data; } + +void *rd_kw_iget_ptr(const rd_kw_type *rd_kw, int i) { + return rd_kw_iget_ptr_static(rd_kw, i); +} + +void rd_kw_iset(rd_kw_type *rd_kw, int i, const void *iptr) { + rd_kw_iset_static(rd_kw, i, iptr); +} + +static bool rd_kw_qskip(FILE *stream) { + const char sep = '\''; + const char space = ' '; + const char newline = '\n'; + const char tab = '\t'; + bool OK = true; + char c; + bool cont = true; + while (cont) { + c = fgetc(stream); + if (c == EOF) { + cont = false; + OK = false; + } else { + if (c == space || c == newline || c == tab) + cont = true; + else if (c == sep) + cont = false; + } + } + return OK; +} + +static bool rd_kw_fscanf_qstring(char *s, const char *fmt, int len, + FILE *stream) { + const char null_char = '\0'; + char last_sep; + bool OK; + OK = rd_kw_qskip(stream); + if (OK) { + int read_count = 0; + read_count += fscanf(stream, fmt, s); + s[len] = null_char; + read_count += fscanf(stream, "%c", &last_sep); + + if (read_count != 2) + util_abort("%s: reading \'xxxxxxxx\' formatted string failed \n", + __func__); + } + return OK; +} + +/* + This rather painful parsing is because formatted eclipse double + format : 0.ddddD+01 - difficult to parse the 'D'; +*/ +/** Should be: NESTED */ + +static double __fscanf_RD_double(FILE *stream, const char *fmt) { + int read_count, power; + double value, arg; + read_count = fscanf(stream, fmt, &arg, &power); + if (read_count == 2) + value = arg * pow(10, power); + else { + util_abort("%s: read failed \n", __func__); + value = -1; + } + return value; +} + +bool rd_kw_fread_data(rd_kw_type *rd_kw, fortio_type *fortio) { + bool fmt_file = fortio_fmt_file(fortio); + if (rd_kw->size > 0) { + const int blocksize = get_blocksize(rd_kw->data_type); + if (fmt_file) { + const int blocks = rd_kw->size / blocksize + + (rd_kw->size % blocksize == 0 ? 0 : 1); + char *read_fmt = alloc_read_fmt(rd_kw->data_type); + FILE *stream = fortio_get_FILE(fortio); + int offset = 0; + int index = 0; + int ib, ir; + for (ib = 0; ib < blocks; ib++) { + int read_elm = util_int_min((ib + 1) * blocksize, rd_kw->size) - + ib * blocksize; + for (ir = 0; ir < read_elm; ir++) { + switch (rd_kw_get_type(rd_kw)) { + case (RD_CHAR_TYPE): + rd_kw_fscanf_qstring(&rd_kw->data[offset], read_fmt, 8, + stream); + break; + case (RD_STRING_TYPE): + rd_kw_fscanf_qstring(&rd_kw->data[offset], read_fmt, + rd_type_get_sizeof_iotype( + rd_kw_get_data_type(rd_kw)), + stream); + break; + case (RD_INT_TYPE): { + int iread = fscanf(stream, read_fmt, + (int *)&rd_kw->data[offset]); + if (iread != 1) + util_abort( + "%s: after reading %d values reading of " + "keyword:%s from:%s failed - aborting \n", + __func__, + offset / + rd_type_get_sizeof_ctype(rd_kw->data_type), + rd_kw->header8, fortio_filename_ref(fortio)); + } break; + case (RD_FLOAT_TYPE): { + int iread = fscanf(stream, read_fmt, + (float *)&rd_kw->data[offset]); + if (iread != 1) { + util_abort( + "%s: after reading %d values reading of " + "keyword:%s from:%s failed - aborting \n", + __func__, + offset / + rd_type_get_sizeof_ctype(rd_kw->data_type), + rd_kw->header8, fortio_filename_ref(fortio)); + } + } break; + case (RD_DOUBLE_TYPE): { + double value = __fscanf_RD_double(stream, read_fmt); + rd_kw_iset(rd_kw, index, &value); + } break; + case (RD_BOOL_TYPE): { + char bool_char; + if (fscanf(stream, read_fmt, &bool_char) == 1) { + if (bool_char == BOOL_TRUE_CHAR) + rd_kw_iset_bool(rd_kw, index, true); + else if (bool_char == BOOL_FALSE_CHAR) + rd_kw_iset_bool(rd_kw, index, false); + else + util_abort("%s: Logical value: [%c] not " + "recogniced - aborting \n", + __func__, bool_char); + } else + util_abort( + "%s: read failed - premature file end? \n", + __func__); + } break; + case (RD_MESS_TYPE): + rd_kw_fscanf_qstring(&rd_kw->data[offset], read_fmt, 8, + stream); + break; + default: + util_abort("%s: Internal error: internal eclipse_type: " + "%d not recognized - aborting \n", + __func__, rd_kw_get_type(rd_kw)); + } + offset += rd_type_get_sizeof_ctype(rd_kw->data_type); + index++; + } + } + + /* Skip the trailing newline */ + fortio_fseek(fortio, 1, SEEK_CUR); + free(read_fmt); + return true; + } else { + char *buffer = rd_kw_alloc_input_buffer(rd_kw); + const int sizeof_iotype = + rd_type_get_sizeof_iotype(rd_kw->data_type); + bool read_ok = fortio_fread_buffer(fortio, buffer, + rd_kw->size * sizeof_iotype); + + if (read_ok) + rd_kw_load_from_input_buffer(rd_kw, buffer); + + free(buffer); + return read_ok; + } + } else + /* The keyword has zero size - and reading data is trivially OK. */ + return true; +} + +void rd_kw_fread_indexed_data(fortio_type *fortio, offset_type data_offset, + rd_data_type data_type, int element_count, + const int_vector_type *index_map, + char *io_buffer) { + const int block_size = get_blocksize(data_type); + FILE *stream = fortio_get_FILE(fortio); + int index; + int sizeof_iotype = rd_type_get_sizeof_iotype(data_type); + + for (index = 0; index < int_vector_size(index_map); index++) { + int element_index = int_vector_iget(index_map, index); + + if (element_index < 0 || element_index >= element_count) + util_abort("%s: Element index is out of range 0 <= %d < %d\n", + __func__, element_index, element_count); + + fortio_data_fseek(fortio, data_offset, element_index, sizeof_iotype, + element_count, block_size); + util_fread(&io_buffer[index * sizeof_iotype], sizeof_iotype, 1, stream, + __func__); + } + + if (RD_ENDIAN_FLIP) + util_endian_flip_vector(io_buffer, sizeof_iotype, + int_vector_size(index_map)); +} + +/** + Allocates storage and reads data. +*/ +bool rd_kw_fread_realloc_data(rd_kw_type *rd_kw, fortio_type *fortio) { + rd_kw_alloc_data(rd_kw); + return rd_kw_fread_data(rd_kw, fortio); +} + +/** + Static method without a class instance. +*/ + +bool rd_kw_fskip_data__(rd_data_type data_type, const int element_count, + fortio_type *fortio) { + if (element_count <= 0) + return true; + + bool fmt_file = fortio_fmt_file(fortio); + if (fmt_file) { + /* Formatted skipping actually involves reading the data - nice ??? */ + rd_kw_type *tmp_kw = rd_kw_alloc_empty(); + rd_kw_initialize(tmp_kw, "WORK", element_count, data_type); + rd_kw_alloc_data(tmp_kw); + rd_kw_fread_data(tmp_kw, fortio); + rd_kw_free(tmp_kw); + } else { + const int blocksize = get_blocksize(data_type); + const int block_count = + element_count / blocksize + (element_count % blocksize != 0); + int element_size = rd_type_get_sizeof_iotype(data_type); + + if (!fortio_data_fskip(fortio, element_size, element_count, + block_count)) + return false; + } + + return true; +} + +bool rd_kw_fskip_data(rd_kw_type *rd_kw, fortio_type *fortio) { + return rd_kw_fskip_data__(rd_kw_get_data_type(rd_kw), rd_kw->size, fortio); +} + +/** + This function will skip the header part of an rd_kw instance. The + function will read the file content at the current position, it is + therefore essential that the file pointer is positioned at the + beginning of a keyword when this function is called; otherwise it + will be complete crash and burn. +*/ + +void rd_kw_fskip_header(fortio_type *fortio) { + bool fmt_file = fortio_fmt_file(fortio); + if (fmt_file) { + rd_kw_type *rd_kw = rd_kw_alloc_empty(); + rd_kw_fread_header(rd_kw, fortio); + rd_kw_free(rd_kw); + } else + fortio_fskip_record(fortio); +} + +rd_read_status_enum rd_kw_fread_header(rd_kw_type *rd_kw, fortio_type *fortio) { + const char null_char = '\0'; + FILE *stream = fortio_get_FILE(fortio); + bool fmt_file = fortio_fmt_file(fortio); + char header[RD_STRING8_LENGTH + 1]; + char rd_type_str[RD_TYPE_LENGTH + 1]; + int record_size; + int size; + + if (fmt_file) { + if (!rd_kw_fscanf_qstring(header, "%8c", 8, stream)) + return RD_KW_READ_FAIL; + + int read_count = fscanf(stream, "%d", &size); + if (read_count != 1) + return RD_KW_READ_FAIL; + + if (!rd_kw_fscanf_qstring(rd_type_str, "%4c", 4, stream)) + return RD_KW_READ_FAIL; + + fgetc(stream); /* Reading the trailing newline ... */ + } else { + header[RD_STRING8_LENGTH] = null_char; + rd_type_str[RD_TYPE_LENGTH] = null_char; + record_size = fortio_init_read(fortio); + + if (record_size <= 0) + return RD_KW_READ_FAIL; + + char buffer[RD_KW_HEADER_DATA_SIZE]; + size_t read_bytes = fread(buffer, 1, RD_KW_HEADER_DATA_SIZE, stream); + + if (read_bytes != RD_KW_HEADER_DATA_SIZE) + return RD_KW_READ_FAIL; + + memcpy(header, &buffer[0], RD_STRING8_LENGTH); + void *ptr = &buffer[RD_STRING8_LENGTH]; + size = *((int *)ptr); + + memcpy(rd_type_str, &buffer[RD_STRING8_LENGTH + sizeof(size)], + RD_TYPE_LENGTH); + + if (!fortio_complete_read(fortio, record_size)) + return RD_KW_READ_FAIL; + + if (RD_ENDIAN_FLIP) + util_endian_flip_vector(&size, sizeof size, 1); + } + + rd_data_type data_type = rd_type_create_from_name(rd_type_str); + rd_kw_initialize(rd_kw, header, size, data_type); + + return RD_KW_READ_OK; +} + +/** + Will seek through the open fortio file and search for a keyword with + header 'kw'. It will always start the search from the present + position in the file, but if rewind is true it will rewind the + fortio file if not finding 'kw' between current offset and EOF. + + If the kw is found the fortio pointer is positioned at the + beginning of the keyword, and the function returns true. If the the + 'kw' is NOT found the file will be repositioned to the initial + position, and the function will return false; unless abort_on_error + == true in which case the function will abort if the 'kw' is not + found. +*/ + +bool rd_kw_fseek_kw(const char *kw, bool rewind, bool abort_on_error, + fortio_type *fortio) { + rd_kw_type *tmp_kw = rd_kw_alloc_empty(); + long int init_pos = fortio_ftell(fortio); + bool cont, kw_found; + + cont = true; + kw_found = false; + while (cont) { + long current_pos = fortio_ftell(fortio); + if (rd_kw_fread_header(tmp_kw, fortio) == RD_KW_READ_OK) { + if (rd_kw_string_eq(rd_kw_get_header8(tmp_kw), kw)) { + fortio_fseek(fortio, current_pos, SEEK_SET); + kw_found = true; + cont = false; + } else + rd_kw_fskip_data(tmp_kw, fortio); + } else { + if (rewind) { + fortio_rewind(fortio); + rewind = false; + } else + cont = false; + } + } + if (!kw_found) { + if (abort_on_error) + util_abort( + "%s: failed to locate keyword:%s in file:%s - aborting \n", + __func__, kw, fortio_filename_ref(fortio)); + + fortio_fseek(fortio, init_pos, SEEK_SET); + } + + rd_kw_free(tmp_kw); + return kw_found; +} + +bool rd_kw_ifseek_kw(const char *kw, fortio_type *fortio, int index) { + int i = 0; + do { + rd_kw_fseek_kw(kw, false, true, fortio); + i++; + } while (i <= index); + return true; +} + +bool rd_kw_fseek_last_kw(const char *kw, bool abort_on_error, + fortio_type *fortio) { + long int init_pos = fortio_ftell(fortio); + bool kw_found = false; + + fortio_fseek(fortio, 0L, SEEK_SET); + kw_found = rd_kw_fseek_kw(kw, false, false, fortio); + if (kw_found) { + bool cont = true; + do { + long int current_pos = fortio_ftell(fortio); + rd_kw_fskip(fortio); + cont = rd_kw_fseek_kw(kw, false, false, fortio); + if (!cont) + fortio_fseek(fortio, current_pos, SEEK_SET); + } while (cont); + } else { + if (abort_on_error) + util_abort("%s: could not locate keyword:%s - aborting \n", + __func__, kw); + else + fortio_fseek(fortio, init_pos, SEEK_SET); + } + return kw_found; +} + +void rd_kw_set_data_ptr(rd_kw_type *rd_kw, void *data) { + if (!rd_kw->shared_data) + free(rd_kw->data); + rd_kw->data = (char *)data; +} + +/** + This is where the storage buffer of the rd_kw is allocated. +*/ +void rd_kw_alloc_data(rd_kw_type *rd_kw) { + if (rd_kw->shared_data) + util_abort("%s: trying to allocate data for rd_kw object which has " + "been declared with shared storage - aborting \n", + __func__); + + { + size_t byte_size = + rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type); + rd_kw->data = (char *)util_realloc(rd_kw->data, byte_size); + if (rd_kw->data) { + memset(rd_kw->data, 0, byte_size); + } + } +} + +void rd_kw_free_data(rd_kw_type *rd_kw) { + if (!rd_kw->shared_data) + free(rd_kw->data); + + rd_kw->data = NULL; +} + +void rd_kw_set_header_name(rd_kw_type *rd_kw, const char *header) { + rd_kw->header8 = (char *)realloc(rd_kw->header8, RD_STRING8_LENGTH + 1); + if (strlen(header) <= 8) { + sprintf(rd_kw->header8, "%-8s", header); + + /* Internalizing a header without the trailing spaces as well. */ + free(rd_kw->header); + rd_kw->header = util_alloc_strip_copy(rd_kw->header8); + } else { + rd_kw->header = (char *)util_alloc_copy(header, strlen(header) + 1); + } +} + +void rd_kw_set_data_type(rd_kw_type *rd_kw, rd_data_type data_type) { + memcpy(&rd_kw->data_type, &data_type, sizeof data_type); +} + +bool rd_kw_fread_realloc(rd_kw_type *rd_kw, fortio_type *fortio) { + if (rd_kw_fread_header(rd_kw, fortio) == RD_KW_READ_OK) + return rd_kw_fread_realloc_data(rd_kw, fortio); + else + return false; +} + +void rd_kw_fread(rd_kw_type *rd_kw, fortio_type *fortio) { + int current_size = rd_kw->size; + if (rd_kw_fread_header(rd_kw, fortio) != RD_KW_READ_OK) + util_abort("%s: failed to read header for rd_kw - aborting \n", + __func__); + + if (rd_kw->size == current_size) + rd_kw_fread_data(rd_kw, fortio); + else + util_abort("%s: size mismatch - aborting \n", __func__); +} + +rd_kw_type *rd_kw_fread_alloc(fortio_type *fortio) { + bool OK; + rd_kw_type *rd_kw = rd_kw_alloc_empty(); + OK = rd_kw_fread_realloc(rd_kw, fortio); + if (!OK) { + rd_kw_free(rd_kw); + rd_kw = NULL; + } + + return rd_kw; +} + +void rd_kw_fskip(fortio_type *fortio) { + rd_kw_type *tmp_kw; + tmp_kw = rd_kw_fread_alloc(fortio); + rd_kw_free(tmp_kw); +} + +static void rd_kw_fwrite_data_unformatted(const rd_kw_type *rd_kw, + fortio_type *fortio) { + char *iobuffer = rd_kw_alloc_output_buffer(rd_kw); + int sizeof_iotype = rd_type_get_sizeof_iotype(rd_kw->data_type); + { + const int blocksize = get_blocksize(rd_kw->data_type); + const int num_blocks = + rd_kw->size / blocksize + (rd_kw->size % blocksize == 0 ? 0 : 1); + int block_nr; + + for (block_nr = 0; block_nr < num_blocks; block_nr++) { + int this_blocksize = + util_int_min((block_nr + 1) * blocksize, rd_kw->size) - + block_nr * blocksize; + int record_size = + this_blocksize * + sizeof_iotype; /* The total size in bytes of the record written by the fortio layer. */ + fortio_fwrite_record( + fortio, &iobuffer[block_nr * blocksize * sizeof_iotype], + record_size); + } + } + free(iobuffer); +} + +/** + The point of this awkward function is that I have not managed to + use C fprintf() syntax to reproduce the ECLIPSE + formatting. ECLIPSE expects the following formatting for float + and double values: + + 0.ddddddddE+03 (float) + 0.ddddddddddddddD+03 (double) + + The problem with printf have been: + + 1. To force the radix part to start with 0. + 2. To use 'D' as the exponent start for double values. + + If you are more proficient with C fprintf() format strings than I + am, the __fprintf_scientific() function should be removed, and + the WRITE_FMT_DOUBLE and WRITE_FMT_FLOAT format specifiers + updated accordingly. + */ + +static void __fprintf_scientific(FILE *stream, const char *fmt, double x) { + double pow_x = ceil(log10(fabs(x))); + double arg_x = x / pow(10.0, pow_x); + if (x != 0.0) { + if (fabs(arg_x) == 1.0) { + arg_x *= 0.10; + pow_x += 1; + } + } else { + arg_x = 0.0; + pow_x = 0.0; + } + fprintf(stream, fmt, arg_x, (int)pow_x); +} + +static void rd_kw_fwrite_data_formatted(rd_kw_type *rd_kw, + fortio_type *fortio) { + + { + + FILE *stream = fortio_get_FILE(fortio); + const int blocksize = get_blocksize(rd_kw->data_type); + const int columns = get_columns(rd_kw->data_type); + char *write_fmt = alloc_write_fmt(rd_kw->data_type); + const int num_blocks = + rd_kw->size / blocksize + (rd_kw->size % blocksize == 0 ? 0 : 1); + int block_nr; + + for (block_nr = 0; block_nr < num_blocks; block_nr++) { + int this_blocksize = + util_int_min((block_nr + 1) * blocksize, rd_kw->size) - + block_nr * blocksize; + int num_lines = this_blocksize / columns + + (this_blocksize % columns == 0 ? 0 : 1); + int line_nr; + for (line_nr = 0; line_nr < num_lines; line_nr++) { + int num_columns = + util_int_min((line_nr + 1) * columns, this_blocksize) - + columns * line_nr; + int col_nr; + for (col_nr = 0; col_nr < num_columns; col_nr++) { + int data_index = + block_nr * blocksize + line_nr * columns + col_nr; + void *data_ptr = rd_kw_iget_ptr_static(rd_kw, data_index); + switch (rd_kw_get_type(rd_kw)) { + case (RD_CHAR_TYPE): + fprintf(stream, write_fmt, data_ptr); + break; + case (RD_STRING_TYPE): + fprintf(stream, write_fmt, data_ptr); + break; + case (RD_INT_TYPE): { + int int_value = ((int *)data_ptr)[0]; + fprintf(stream, write_fmt, int_value); + } break; + case (RD_BOOL_TYPE): { + bool bool_value = ((bool *)data_ptr)[0]; + if (bool_value) + fprintf(stream, write_fmt, BOOL_TRUE_CHAR); + else + fprintf(stream, write_fmt, BOOL_FALSE_CHAR); + } break; + case (RD_FLOAT_TYPE): { + float float_value = ((float *)data_ptr)[0]; + __fprintf_scientific(stream, write_fmt, float_value); + } break; + case (RD_DOUBLE_TYPE): { + double double_value = ((double *)data_ptr)[0]; + __fprintf_scientific(stream, write_fmt, double_value); + } break; + case (RD_MESS_TYPE): + util_abort("%s: Internal inconsistency : message type " + "keywords should not have data\n", + __func__); + break; + } + } + fprintf(stream, "\n"); + } + } + + free(write_fmt); + } +} + +void rd_kw_fwrite_data(const rd_kw_type *_rd_kw, fortio_type *fortio) { + rd_kw_type *rd_kw = (rd_kw_type *)_rd_kw; + bool fmt_file = fortio_fmt_file(fortio); + + if (fmt_file) + rd_kw_fwrite_data_formatted(rd_kw, fortio); + else + rd_kw_fwrite_data_unformatted(rd_kw, fortio); +} + +void rd_kw_fwrite_header(const rd_kw_type *rd_kw, fortio_type *fortio) { + FILE *stream = fortio_get_FILE(fortio); + bool fmt_file = fortio_fmt_file(fortio); + char *type_name = rd_type_alloc_name(rd_kw->data_type); + + if (fmt_file) + fprintf(stream, WRITE_HEADER_FMT, rd_kw->header8, rd_kw->size, + type_name); + else { + int size = rd_kw->size; + if (RD_ENDIAN_FLIP) + util_endian_flip_vector(&size, sizeof size, 1); + + fortio_init_write(fortio, RD_KW_HEADER_DATA_SIZE); + + fwrite(rd_kw->header8, sizeof(char), RD_STRING8_LENGTH, stream); + fwrite(&size, sizeof(int), 1, stream); + fwrite(type_name, sizeof(char), RD_TYPE_LENGTH, stream); + + fortio_complete_write(fortio, RD_KW_HEADER_DATA_SIZE); + } + + free(type_name); +} + +bool rd_kw_fwrite(const rd_kw_type *rd_kw, fortio_type *fortio) { + if (strlen(rd_kw_get_header(rd_kw)) > RD_STRING8_LENGTH) { + fortio_fwrite_error(fortio); + return false; + } + rd_kw_fwrite_header(rd_kw, fortio); + rd_kw_fwrite_data(rd_kw, fortio); + return true; +} + +static void *rd_kw_get_data_ref(const rd_kw_type *rd_kw) { return rd_kw->data; } + +void *rd_kw_get_ptr(const rd_kw_type *rd_kw) { + return rd_kw_get_data_ref(rd_kw); +} + +int rd_kw_get_size(const rd_kw_type *rd_kw) { return rd_kw->size; } + +rd_type_enum rd_kw_get_type(const rd_kw_type *rd_kw) { + return rd_type_get_type(rd_kw->data_type); +} + +rd_data_type rd_kw_get_data_type(const rd_kw_type *rd_kw) { + return rd_kw->data_type; +} + +rd_kw_type *rd_kw_buffer_alloc(buffer_type *buffer) { + const char *header = buffer_fread_string(buffer); + int size = buffer_fread_int(buffer); + rd_type_enum rd_type = (rd_type_enum)buffer_fread_int(buffer); + size_t element_size = buffer_fread_int(buffer); + + rd_data_type data_type = rd_type_create(rd_type, element_size); + rd_kw_type *rd_kw = rd_kw_alloc_empty(); + rd_kw_initialize(rd_kw, header, size, data_type); + rd_kw_alloc_data(rd_kw); + buffer_fread(buffer, rd_kw->data, + rd_type_get_sizeof_ctype(rd_kw->data_type), rd_kw->size); + return rd_kw; +} + +void rd_kw_buffer_store(const rd_kw_type *rd_kw, buffer_type *buffer) { + buffer_fwrite_string(buffer, rd_kw->header8); + buffer_fwrite_int(buffer, rd_kw->size); + buffer_fwrite_int(buffer, rd_type_get_type(rd_kw->data_type)); + buffer_fwrite_int(buffer, rd_type_get_sizeof_ctype(rd_kw->data_type)); + buffer_fwrite(buffer, rd_kw->data, + rd_type_get_sizeof_ctype(rd_kw->data_type), rd_kw->size); +} + +void rd_kw_fwrite_param_fortio(fortio_type *fortio, const char *header, + rd_data_type data_type, int size, void *data) { + rd_kw_type *rd_kw = rd_kw_alloc_new_shared(header, size, data_type, data); + rd_kw_fwrite(rd_kw, fortio); + rd_kw_free(rd_kw); +} + +void rd_kw_fwrite_param(const char *filename, bool fmt_file, const char *header, + rd_data_type data_type, int size, void *data) { + fortio_type *fortio = + fortio_open_writer(filename, fmt_file, RD_ENDIAN_FLIP); + rd_kw_fwrite_param_fortio(fortio, header, data_type, size, data); + fortio_fclose(fortio); +} + +void rd_kw_get_data_as_double(const rd_kw_type *rd_kw, double *double_data) { + + if (rd_type_is_double(rd_kw->data_type)) + // Direct memcpy - no conversion + rd_kw_get_memcpy_data(rd_kw, double_data); + else { + if (rd_type_is_float(rd_kw->data_type)) { + const float *float_data = (const float *)rd_kw->data; + util_float_to_double(double_data, float_data, rd_kw->size); + } else if (rd_type_is_int(rd_kw->data_type)) { + const int *int_data = (const int *)rd_kw->data; + int i; + for (i = 0; i < rd_kw->size; i++) + double_data[i] = int_data[i]; + } else { + fprintf(stderr, + "%s: type can not be converted to double - aborting \n", + __func__); + rd_kw_summarize(rd_kw); + util_abort("%s: Aborting \n", __func__); + } + } +} + +void rd_kw_get_data_as_float(const rd_kw_type *rd_kw, float *float_data) { + + if (rd_type_is_float(rd_kw->data_type)) + // Direct memcpy - no conversion + rd_kw_get_memcpy_data(rd_kw, float_data); + else { + if (rd_type_is_double(rd_kw->data_type)) { + const double *double_data = (const double *)rd_kw->data; + util_double_to_float(float_data, double_data, rd_kw->size); + } else if (rd_type_is_int(rd_kw->data_type)) { + const int *int_data = (const int *)rd_kw->data; + int i; + for (i = 0; i < rd_kw->size; i++) + float_data[i] = (float)int_data[i]; + } else { + fprintf(stderr, + "%s: type can not be converted to float - aborting \n", + __func__); + rd_kw_summarize(rd_kw); + util_abort("%s: Aborting \n", __func__); + } + } +} + +/** + Will create a new keyword of the same type as src_kw, and size + @target_size. The integer array mapping is a list sizeof(src_kw) + elements, where each element is the new index, i.e. + + new_kw[ mapping[i] ] = src_kw[i] + + For all inactive elements in new kw are set as follows: + + 0 - For float / int / double + False - For logical + "" - For char +*/ + +rd_kw_type *rd_kw_alloc_scatter_copy(const rd_kw_type *src_kw, int target_size, + const int *mapping, void *def_value) { + int default_int = 0; + double default_double = 0; + float default_float = 0; + bool default_bool = false; + const char *default_char = ""; + rd_kw_type *new_kw = + rd_kw_alloc(src_kw->header, target_size, src_kw->data_type); + + if (def_value != NULL) + rd_kw_scalar_set__(new_kw, def_value); + else { + /** Initialize with defaults .*/ + switch (rd_kw_get_type(src_kw)) { + case (RD_INT_TYPE): + rd_kw_scalar_set__(new_kw, &default_int); + break; + case (RD_FLOAT_TYPE): + rd_kw_scalar_set__(new_kw, &default_float); + break; + case (RD_DOUBLE_TYPE): + rd_kw_scalar_set__(new_kw, &default_double); + break; + case (RD_BOOL_TYPE): + rd_kw_scalar_set__(new_kw, &default_bool); + break; + case (RD_CHAR_TYPE): + rd_kw_scalar_set__(new_kw, default_char); + break; + default: + util_abort("%s: unsupported type:%d \n", __func__, + rd_kw_get_type(src_kw)); + } + } + + { + int sizeof_ctype = rd_type_get_sizeof_ctype(src_kw->data_type); + int i; + for (i = 0; i < src_kw->size; i++) { + int target_index = mapping[i]; + memcpy(&new_kw->data[target_index * sizeof_ctype], + &src_kw->data[i * sizeof_ctype], sizeof_ctype); + } + } + + return new_kw; +} + +rd_kw_type *rd_kw_alloc_global_copy(const rd_kw_type *src, + const rd_kw_type *actnum) { + if (rd_kw_get_type(actnum) != RD_INT_TYPE) + return NULL; + + const int global_size = rd_kw_get_size(actnum); + rd_kw_type *global_copy = + rd_kw_alloc(rd_kw_get_header(src), global_size, src->data_type); + const int *mapping = rd_kw_get_int_ptr(actnum); + const int src_size = rd_kw_get_size(src); + int src_index = 0; + for (int global_index = 0; global_index < global_size; global_index++) { + if (mapping[global_index]) { + /* We ran through and beyond the size of the src keyword. */ + if (src_index >= src_size) { + rd_kw_free(global_copy); + global_copy = NULL; + break; + } + const void *value_ptr = rd_kw_iget_ptr(src, src_index); + rd_kw_iset_static(global_copy, global_index, value_ptr); + src_index++; + } + } + + /* Not all the src data was distributed. */ + if (src_index < src_size) { + rd_kw_free(global_copy); + global_copy = NULL; + } + + return global_copy; +} + +void rd_kw_fread_double_param(const char *filename, bool fmt_file, + double *double_data) { + fortio_type *fortio = + fortio_open_reader(filename, fmt_file, RD_ENDIAN_FLIP); + rd_kw_type *rd_kw = rd_kw_fread_alloc(fortio); + fortio_fclose(fortio); + + if (rd_kw == NULL) + util_abort( + "%s: fatal error: loading parameter from: %s failed - aborting \n", + __func__, filename); + + rd_kw_get_data_as_double(rd_kw, double_data); + rd_kw_free(rd_kw); +} + +void rd_kw_summarize(const rd_kw_type *rd_kw) { + char *type_name = rd_type_alloc_name(rd_kw->data_type); + printf("%8s %10d:%4s \n", rd_kw_get_header8(rd_kw), rd_kw_get_size(rd_kw), + type_name); + free(type_name); +} + +#define RD_KW_SCALAR_SET_TYPED(ctype, RD_TYPE) \ + void rd_kw_scalar_set_##ctype(rd_kw_type *rd_kw, ctype value) { \ + if (rd_kw_get_type(rd_kw) == RD_TYPE) { \ + ctype *data = (ctype *)rd_kw_get_data_ref(rd_kw); \ + int i; \ + for (i = 0; i < rd_kw->size; i++) \ + data[i] = value; \ + } else \ + util_abort("%s: wrong type\n", __func__); \ + } + +RD_KW_SCALAR_SET_TYPED(int, RD_INT_TYPE) +RD_KW_SCALAR_SET_TYPED(float, RD_FLOAT_TYPE) +RD_KW_SCALAR_SET_TYPED(double, RD_DOUBLE_TYPE) +RD_KW_SCALAR_SET_TYPED(bool, RD_BOOL_TYPE) +#undef RD_KW_SCALAR_SET_TYPED + +void rd_kw_scalar_set_float_or_double(rd_kw_type *rd_kw, double value) { + rd_type_enum rd_type = rd_kw_get_type(rd_kw); + if (rd_type == RD_FLOAT_TYPE) + rd_kw_scalar_set_float(rd_kw, (float)value); + else if (rd_type == RD_DOUBLE_TYPE) + rd_kw_scalar_set_double(rd_kw, value); + else + util_abort("%s: wrong type \n", __func__); +} + +/* + Untyped - low level alternative. +*/ +void rd_kw_scalar_set__(rd_kw_type *rd_kw, const void *value) { + int sizeof_ctype = rd_type_get_sizeof_ctype(rd_kw->data_type); + int i; + for (i = 0; i < rd_kw->size; i++) + memcpy(&rd_kw->data[i * sizeof_ctype], value, sizeof_ctype); +} + +void rd_kw_alloc_double_data(rd_kw_type *rd_kw, double *values) { + rd_kw_alloc_data(rd_kw); + memcpy(rd_kw->data, values, + rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type)); +} + +void rd_kw_alloc_float_data(rd_kw_type *rd_kw, float *values) { + rd_kw_alloc_data(rd_kw); + memcpy(rd_kw->data, values, + rd_kw->size * rd_type_get_sizeof_ctype(rd_kw->data_type)); +} + +#define RD_KW_SCALE_TYPED(ctype, RD_TYPE) \ + void rd_kw_scale_##ctype(rd_kw_type *rd_kw, ctype scale_factor) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + { \ + ctype *data = (ctype *)rd_kw_get_data_ref(rd_kw); \ + int size = rd_kw_get_size(rd_kw); \ + int i; \ + for (i = 0; i < size; i++) \ + data[i] *= scale_factor; \ + } \ + } + +RD_KW_SCALE_TYPED(int, RD_INT_TYPE) +RD_KW_SCALE_TYPED(float, RD_FLOAT_TYPE) +RD_KW_SCALE_TYPED(double, RD_DOUBLE_TYPE) +#undef RD_KW_SCALE_TYPED + +void rd_kw_scale_float_or_double(rd_kw_type *rd_kw, double scale_factor) { + rd_type_enum rd_type = rd_kw_get_type(rd_kw); + if (rd_type == RD_FLOAT_TYPE) + rd_kw_scale_float(rd_kw, (float)scale_factor); + else if (rd_type == RD_DOUBLE_TYPE) + rd_kw_scale_double(rd_kw, scale_factor); + else + util_abort("%s: wrong type \n", __func__); +} + +#define RD_KW_SHIFT_TYPED(ctype, RD_TYPE) \ + void rd_kw_shift_##ctype(rd_kw_type *rd_kw, ctype shift_value) { \ + if (rd_kw_get_type(rd_kw) != RD_TYPE) \ + util_abort("%s: Keyword: %s is wrong type - aborting \n", \ + __func__, rd_kw_get_header8(rd_kw)); \ + { \ + ctype *data = (ctype *)rd_kw_get_data_ref(rd_kw); \ + int size = rd_kw_get_size(rd_kw); \ + int i; \ + for (i = 0; i < size; i++) \ + data[i] += shift_value; \ + } \ + } + +RD_KW_SHIFT_TYPED(int, RD_INT_TYPE) +RD_KW_SHIFT_TYPED(float, RD_FLOAT_TYPE) +RD_KW_SHIFT_TYPED(double, RD_DOUBLE_TYPE) +#undef RD_KW_SHIFT_TYPED + +void rd_kw_shift_float_or_double(rd_kw_type *rd_kw, double shift_value) { + rd_type_enum rd_type = rd_kw_get_type(rd_kw); + if (rd_type == RD_FLOAT_TYPE) + rd_kw_shift_float(rd_kw, (float)shift_value); + else if (rd_type == RD_DOUBLE_TYPE) + rd_kw_shift_double(rd_kw, shift_value); + else + util_abort("%s: wrong type \n", __func__); +} + +bool rd_kw_size_and_numeric_type_equal(const rd_kw_type *kw1, + const rd_kw_type *kw2) { + return rd_kw_size_and_type_equal(kw1, kw2) && + rd_type_is_numeric(kw1->data_type); +} + +#define RD_KW_ASSERT_TYPED_BINARY_OP(ctype, RD_TYPE) \ + bool rd_kw_assert_binary_##ctype(const rd_kw_type *kw1, \ + const rd_kw_type *kw2) { \ + if (!rd_kw_size_and_numeric_type_equal(kw1, kw2)) \ + return false; \ + if (rd_kw_get_type(kw1) != RD_TYPE) \ + return false; /* Type mismatch */ \ + return true; \ + } + +RD_KW_ASSERT_TYPED_BINARY_OP(int, RD_INT_TYPE) +RD_KW_ASSERT_TYPED_BINARY_OP(float, RD_FLOAT_TYPE) +RD_KW_ASSERT_TYPED_BINARY_OP(double, RD_DOUBLE_TYPE) +#undef RD_KW_ASSERT_TYPED_BINARY_OP + +void rd_kw_copy_indexed(rd_kw_type *target_kw, const int_vector_type *index_set, + const rd_kw_type *src_kw) { + if (!rd_kw_size_and_type_equal(target_kw, src_kw)) + util_abort("%s: type/size mismatch\n", __func__); + { + char *target_data = (char *)rd_kw_get_data_ref(target_kw); + const char *src_data = (const char *)rd_kw_get_data_ref(src_kw); + int sizeof_ctype = rd_type_get_sizeof_ctype(target_kw->data_type); + int set_size = int_vector_size(index_set); + const int *index_data = int_vector_get_const_ptr(index_set); + int i; + for (i = 0; i < set_size; i++) { + int index = index_data[i]; + memcpy(&target_data[index * sizeof_ctype], + &src_data[index * sizeof_ctype], sizeof_ctype); + } + } +} + +#define RD_KW_TYPED_INPLACE_ADD_INDEXED(ctype) \ + static void rd_kw_inplace_add_indexed_##ctype( \ + rd_kw_type *target_kw, const int_vector_type *index_set, \ + const rd_kw_type *add_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, add_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *add_data = (const ctype *)rd_kw_get_data_ref(add_kw); \ + int set_size = int_vector_size(index_set); \ + const int *index_data = int_vector_get_const_ptr(index_set); \ + int i; \ + for (i = 0; i < set_size; i++) { \ + int index = index_data[i]; \ + target_data[index] += add_data[index]; \ + } \ + } \ + } + +RD_KW_TYPED_INPLACE_ADD_INDEXED(int) +RD_KW_TYPED_INPLACE_ADD_INDEXED(double) +RD_KW_TYPED_INPLACE_ADD_INDEXED(float) +#undef RD_KW_TYPED_INPLACE_ADD + +void rd_kw_inplace_add_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *add_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_add_indexed_float(target_kw, index_set, add_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_add_indexed_double(target_kw, index_set, add_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_add_indexed_int(target_kw, index_set, add_kw); + break; + default: + util_abort("%s: inplace add not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_ADD(ctype) \ + static void rd_kw_inplace_add_##ctype(rd_kw_type *target_kw, \ + const rd_kw_type *add_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, add_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *add_data = (const ctype *)rd_kw_get_data_ref(add_kw); \ + int i; \ + for (i = 0; i < target_kw->size; i++) \ + target_data[i] += add_data[i]; \ + } \ + } +RD_KW_TYPED_INPLACE_ADD(int) +RD_KW_TYPED_INPLACE_ADD(double) +RD_KW_TYPED_INPLACE_ADD(float) + +#undef RD_KW_TYPED_INPLACE_ADD + +void rd_kw_inplace_add(rd_kw_type *target_kw, const rd_kw_type *add_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_add_float(target_kw, add_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_add_double(target_kw, add_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_add_int(target_kw, add_kw); + break; + default: + util_abort("%s: inplace add not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_ADD_SQUARED(ctype) \ + static void rd_kw_inplace_add_squared_##ctype(rd_kw_type *target_kw, \ + const rd_kw_type *add_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, add_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *add_data = (const ctype *)rd_kw_get_data_ref(add_kw); \ + int i; \ + for (i = 0; i < target_kw->size; i++) \ + target_data[i] += add_data[i] * add_data[i]; \ + } \ + } +RD_KW_TYPED_INPLACE_ADD_SQUARED(int) +RD_KW_TYPED_INPLACE_ADD_SQUARED(double) +RD_KW_TYPED_INPLACE_ADD_SQUARED(float) + +#undef RD_KW_TYPED_INPLACE_ADD + +void rd_kw_inplace_add_squared(rd_kw_type *target_kw, + const rd_kw_type *add_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_add_squared_float(target_kw, add_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_add_squared_double(target_kw, add_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_add_squared_int(target_kw, add_kw); + break; + default: + util_abort("%s: inplace add not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_SUB(ctype) \ + void rd_kw_inplace_sub_##ctype(rd_kw_type *target_kw, \ + const rd_kw_type *sub_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, sub_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *sub_data = (const ctype *)rd_kw_get_data_ref(sub_kw); \ + int i; \ + for (i = 0; i < target_kw->size; i++) \ + target_data[i] -= sub_data[i]; \ + } \ + } +RD_KW_TYPED_INPLACE_SUB(int) +RD_KW_TYPED_INPLACE_SUB(double) +RD_KW_TYPED_INPLACE_SUB(float) +#undef RD_KW_TYPED_INPLACE_SUB + +void rd_kw_inplace_sub(rd_kw_type *target_kw, const rd_kw_type *sub_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_sub_float(target_kw, sub_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_sub_double(target_kw, sub_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_sub_int(target_kw, sub_kw); + break; + default: + util_abort("%s: inplace sub not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_SUB_INDEXED(ctype) \ + static void rd_kw_inplace_sub_indexed_##ctype( \ + rd_kw_type *target_kw, const int_vector_type *index_set, \ + const rd_kw_type *sub_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, sub_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *sub_data = (const ctype *)rd_kw_get_data_ref(sub_kw); \ + int set_size = int_vector_size(index_set); \ + const int *index_data = int_vector_get_const_ptr(index_set); \ + int i; \ + for (i = 0; i < set_size; i++) { \ + int index = index_data[i]; \ + target_data[index] -= sub_data[index]; \ + } \ + } \ + } + +RD_KW_TYPED_INPLACE_SUB_INDEXED(int) +RD_KW_TYPED_INPLACE_SUB_INDEXED(double) +RD_KW_TYPED_INPLACE_SUB_INDEXED(float) +#undef RD_KW_TYPED_INPLACE_SUB + +void rd_kw_inplace_sub_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *sub_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_sub_indexed_float(target_kw, index_set, sub_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_sub_indexed_double(target_kw, index_set, sub_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_sub_indexed_int(target_kw, index_set, sub_kw); + break; + default: + util_abort("%s: inplace sub not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_ABS(ctype, abs_func) \ + void rd_kw_inplace_abs_##ctype(rd_kw_type *kw) { \ + ctype *data = (ctype *)rd_kw_get_data_ref(kw); \ + int i; \ + for (i = 0; i < kw->size; i++) \ + data[i] = abs_func(data[i]); \ + } + +RD_KW_TYPED_INPLACE_ABS(int, abs) +RD_KW_TYPED_INPLACE_ABS(double, fabs) +RD_KW_TYPED_INPLACE_ABS(float, fabsf) +#undef RD_KW_TYPED_INPLACE_ABS + +void rd_kw_inplace_abs(rd_kw_type *kw) { + rd_type_enum type = rd_kw_get_type(kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_abs_float(kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_abs_double(kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_abs_int(kw); + break; + default: + util_abort("%s: inplace abs not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(kw))); + } +} + +static int sqrti(int x) { return round(sqrt(x)); } + +#define RD_KW_TYPED_INPLACE_SQRT(ctype, sqrt_func) \ + void rd_kw_inplace_sqrt_##ctype(rd_kw_type *kw) { \ + ctype *data = (ctype *)rd_kw_get_data_ref(kw); \ + int i; \ + for (i = 0; i < kw->size; i++) \ + data[i] = sqrt_func(data[i]); \ + } + +RD_KW_TYPED_INPLACE_SQRT(double, sqrt) +RD_KW_TYPED_INPLACE_SQRT(float, sqrtf) +RD_KW_TYPED_INPLACE_SQRT(int, sqrti) +#undef RD_KW_TYPED_INPLACE_SQRT + +void rd_kw_inplace_sqrt(rd_kw_type *kw) { + rd_type_enum type = rd_kw_get_type(kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_sqrt_float(kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_sqrt_double(kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_sqrt_int(kw); + break; + default: + util_abort("%s: inplace sqrt not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(kw))); + } +} + +#define RD_KW_TYPED_INPLACE_MUL(ctype) \ + void rd_kw_inplace_mul_##ctype(rd_kw_type *target_kw, \ + const rd_kw_type *mul_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, mul_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *mul_data = (const ctype *)rd_kw_get_data_ref(mul_kw); \ + int i; \ + for (i = 0; i < target_kw->size; i++) \ + target_data[i] *= mul_data[i]; \ + } \ + } +RD_KW_TYPED_INPLACE_MUL(int) +RD_KW_TYPED_INPLACE_MUL(double) +RD_KW_TYPED_INPLACE_MUL(float) +#undef RD_KW_TYPED_INPLACE_MUL + +void rd_kw_inplace_mul(rd_kw_type *target_kw, const rd_kw_type *mul_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_mul_float(target_kw, mul_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_mul_double(target_kw, mul_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_mul_int(target_kw, mul_kw); + break; + default: + util_abort("%s: inplace mul not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_MUL_INDEXED(ctype) \ + static void rd_kw_inplace_mul_indexed_##ctype( \ + rd_kw_type *target_kw, const int_vector_type *index_set, \ + const rd_kw_type *mul_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, mul_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *mul_data = (const ctype *)rd_kw_get_data_ref(mul_kw); \ + int set_size = int_vector_size(index_set); \ + const int *index_data = int_vector_get_const_ptr(index_set); \ + int i; \ + for (i = 0; i < set_size; i++) { \ + int index = index_data[i]; \ + target_data[index] *= mul_data[index]; \ + } \ + } \ + } + +RD_KW_TYPED_INPLACE_MUL_INDEXED(int) +RD_KW_TYPED_INPLACE_MUL_INDEXED(double) +RD_KW_TYPED_INPLACE_MUL_INDEXED(float) +#undef RD_KW_TYPED_INPLACE_MUL + +void rd_kw_inplace_mul_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *mul_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_mul_indexed_float(target_kw, index_set, mul_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_mul_indexed_double(target_kw, index_set, mul_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_mul_indexed_int(target_kw, index_set, mul_kw); + break; + default: + util_abort("%s: inplace mul not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_DIV(ctype) \ + void rd_kw_inplace_div_##ctype(rd_kw_type *target_kw, \ + const rd_kw_type *div_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, div_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *div_data = (const ctype *)rd_kw_get_data_ref(div_kw); \ + int i; \ + for (i = 0; i < target_kw->size; i++) \ + target_data[i] /= div_data[i]; \ + } \ + } +RD_KW_TYPED_INPLACE_DIV(int) +RD_KW_TYPED_INPLACE_DIV(double) +RD_KW_TYPED_INPLACE_DIV(float) +#undef RD_KW_TYPED_INPLACE_DIV + +void rd_kw_inplace_div(rd_kw_type *target_kw, const rd_kw_type *div_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_div_float(target_kw, div_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_div_double(target_kw, div_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_div_int(target_kw, div_kw); + break; + default: + util_abort("%s: inplace div not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +#define RD_KW_TYPED_INPLACE_DIV_INDEXED(ctype) \ + static void rd_kw_inplace_div_indexed_##ctype( \ + rd_kw_type *target_kw, const int_vector_type *index_set, \ + const rd_kw_type *div_kw) { \ + if (!rd_kw_assert_binary_##ctype(target_kw, div_kw)) \ + util_abort("%s: type/size mismatch\n", __func__); \ + { \ + ctype *target_data = (ctype *)rd_kw_get_data_ref(target_kw); \ + const ctype *div_data = (const ctype *)rd_kw_get_data_ref(div_kw); \ + int set_size = int_vector_size(index_set); \ + const int *index_data = int_vector_get_const_ptr(index_set); \ + int i; \ + for (i = 0; i < set_size; i++) { \ + int index = index_data[i]; \ + target_data[index] *= div_data[index]; \ + } \ + } \ + } + +RD_KW_TYPED_INPLACE_DIV_INDEXED(int) +RD_KW_TYPED_INPLACE_DIV_INDEXED(double) +RD_KW_TYPED_INPLACE_DIV_INDEXED(float) +#undef RD_KW_TYPED_INPLACE_DIV + +void rd_kw_inplace_div_indexed(rd_kw_type *target_kw, + const int_vector_type *index_set, + const rd_kw_type *div_kw) { + rd_type_enum type = rd_kw_get_type(target_kw); + switch (type) { + case (RD_FLOAT_TYPE): + rd_kw_inplace_div_indexed_float(target_kw, index_set, div_kw); + break; + case (RD_DOUBLE_TYPE): + rd_kw_inplace_div_indexed_double(target_kw, index_set, div_kw); + break; + case (RD_INT_TYPE): + rd_kw_inplace_div_indexed_int(target_kw, index_set, div_kw); + break; + default: + util_abort("%s: inplace div not implemented for type:%s \n", __func__, + rd_type_alloc_name(rd_kw_get_data_type(target_kw))); + } +} + +bool rd_kw_inplace_safe_div(rd_kw_type *target_kw, const rd_kw_type *divisor) { + if (rd_kw_get_type(target_kw) != RD_FLOAT_TYPE) + return false; + + if (rd_kw_get_type(divisor) != RD_INT_TYPE) + return false; + + float *target_data = (float *)rd_kw_get_data_ref(target_kw); + const int *div_data = (const int *)rd_kw_get_data_ref(divisor); + for (int i = 0; i < target_kw->size; i++) { + if (div_data[i] != 0) + target_data[i] /= div_data[i]; + } + + return true; +} + +void rd_kw_inplace_inv(rd_kw_type *my_kw) { + int size = rd_kw_get_size(my_kw); + rd_type_enum type = rd_kw_get_type(my_kw); + { + int i; + void *my_data = rd_kw_get_data_ref(my_kw); + + switch (type) { + case (RD_DOUBLE_TYPE): { + double *my_double = (double *)my_data; + for (i = 0; i < size; i++) + my_double[i] = 1.0 / my_double[i]; + break; + } + case (RD_FLOAT_TYPE): { + float *my_float = (float *)my_data; + for (i = 0; i < size; i++) + my_float[i] = 1.0f / my_float[i]; + break; + } + default: + util_abort("%s: can only be called on RD_FLOAT_TYPE and " + "RD_DOUBLE_TYPE - aborting \n", + __func__); + } + } +} + +void rd_kw_inplace_update_file(const rd_kw_type *rd_kw, const char *filename, + int index) { + if (util_file_exists(filename)) { + bool fmt_file = util_fmt_bit8(filename); + + { + fortio_type *fortio = + fortio_open_readwrite(filename, fmt_file, RD_ENDIAN_FLIP); + rd_kw_ifseek_kw(rd_kw_get_header8(rd_kw), fortio, index); + { + rd_kw_type *file_kw = rd_kw_alloc_empty(); + long int current_pos = fortio_ftell(fortio); + rd_kw_fread_header(file_kw, fortio); + fortio_fseek(fortio, current_pos, SEEK_SET); + + if (!rd_kw_size_and_type_equal(rd_kw, file_kw)) + util_abort( + "%s: header mismatch when trying to update:%s in %s \n", + __func__, rd_kw_get_header8(rd_kw), filename); + rd_kw_free(file_kw); + } + + fortio_fflush(fortio); + rd_kw_fwrite(rd_kw, fortio); + fortio_fclose(fortio); + } + } +} + +bool rd_kw_is_kw_file(fortio_type *fortio) { + const long int init_pos = fortio_ftell(fortio); + bool kw_file; + + { + rd_kw_type *rd_kw = rd_kw_alloc_empty(); + + if (fortio_fmt_file(fortio)) + kw_file = (rd_kw_fread_header(rd_kw, fortio) != RD_KW_READ_FAIL); + else { + if (fortio_is_fortio_file(fortio)) + kw_file = + (rd_kw_fread_header(rd_kw, fortio) != RD_KW_READ_FAIL); + else + kw_file = false; + } + + rd_kw_free(rd_kw); + } + + fortio_fseek(fortio, init_pos, SEEK_SET); + return kw_file; +} + +#define KW_MAX_MIN(type) \ + { \ + type *data = (type *)rd_kw_get_data_ref(rd_kw); \ + type max = data[0]; \ + type min = data[0]; \ + int i; \ + for (i = 1; i < rd_kw_get_size(rd_kw); i++) \ + util_update_##type##_max_min(data[i], &max, &min); \ + memcpy(_max, &max, rd_type_get_sizeof_ctype(rd_kw->data_type)); \ + memcpy(_min, &min, rd_type_get_sizeof_ctype(rd_kw->data_type)); \ + } + +void rd_kw_max_min(const rd_kw_type *rd_kw, void *_max, void *_min) { + switch (rd_kw_get_type(rd_kw)) { + case (RD_FLOAT_TYPE): + KW_MAX_MIN(float); + break; + case (RD_DOUBLE_TYPE): + KW_MAX_MIN(double); + break; + case (RD_INT_TYPE): + KW_MAX_MIN(int); + break; + default: + util_abort("%s: invalid type for element sum \n", __func__); + } +} + +#define RD_KW_MAX_MIN(ctype) \ + void rd_kw_max_min_##ctype(const rd_kw_type *rd_kw, ctype *_max, \ + ctype *_min) { \ + KW_MAX_MIN(ctype); \ + } + +#define RD_KW_MAX(ctype) \ + ctype rd_kw_##ctype##_max(const rd_kw_type *rd_kw) { \ + ctype max, min; \ + rd_kw_max_min_##ctype(rd_kw, &max, &min); \ + return max; \ + } + +#define RD_KW_MIN(ctype) \ + ctype rd_kw_##ctype##_min(const rd_kw_type *rd_kw) { \ + ctype max, min; \ + rd_kw_max_min_##ctype(rd_kw, &max, &min); \ + return min; \ + } + +RD_KW_MAX_MIN(int) +RD_KW_MAX_MIN(float) +RD_KW_MAX_MIN(double) + +RD_KW_MAX(int) +RD_KW_MAX(float) +RD_KW_MAX(double) + +RD_KW_MIN(int) +RD_KW_MIN(float) +RD_KW_MIN(double) + +#undef RD_KW_MAX +#undef RD_KW_MIN +#undef KW_MAX_MIN +#undef RD_KW_MAX_MIN + +#define KW_SUM_INDEXED(type) \ + { \ + const type *data = (const type *)rd_kw_get_data_ref(rd_kw); \ + type sum = 0; \ + int size = int_vector_size(index_list); \ + const int *index_ptr = int_vector_get_const_ptr(index_list); \ + for (int i = 0; i < size; i++) \ + sum += data[index_ptr[i]]; \ + memcpy(_sum, &sum, rd_type_get_sizeof_ctype(rd_kw->data_type)); \ + } + +void rd_kw_element_sum_indexed(const rd_kw_type *rd_kw, + const int_vector_type *index_list, void *_sum) { + switch (rd_kw_get_type(rd_kw)) { + case (RD_FLOAT_TYPE): + KW_SUM_INDEXED(float); + break; + case (RD_DOUBLE_TYPE): + KW_SUM_INDEXED(double); + break; + case (RD_INT_TYPE): + KW_SUM_INDEXED(int); + break; + case (RD_BOOL_TYPE): { + const bool *data = (const bool *)rd_kw_get_data_ref(rd_kw); + const int *index_ptr = int_vector_get_const_ptr(index_list); + const int size = int_vector_size(index_list); + int sum = 0; + for (int i = 0; i < size; i++) + sum += (data[index_ptr[i]]); + + memcpy(_sum, &sum, sizeof sum); + } break; + default: + util_abort("%s: invalid type for element sum \n", __func__); + } +} +#undef KW_SUM + +#define KW_SUM(type) \ + { \ + const type *data = (const type *)rd_kw_get_data_ref(rd_kw); \ + type sum = 0; \ + for (int i = 0; i < rd_kw_get_size(rd_kw); i++) \ + sum += data[i]; \ + memcpy(_sum, &sum, rd_type_get_sizeof_ctype(rd_kw->data_type)); \ + } + +void rd_kw_element_sum(const rd_kw_type *rd_kw, void *_sum) { + switch (rd_kw_get_type(rd_kw)) { + case (RD_FLOAT_TYPE): + KW_SUM(float); + break; + case (RD_DOUBLE_TYPE): + KW_SUM(double); + break; + case (RD_INT_TYPE): + KW_SUM(int); + break; + default: + util_abort("%s: invalid type for element sum \n", __func__); + } +} +#undef KW_SUM + +double rd_kw_element_sum_float(const rd_kw_type *rd_kw) { + float float_sum; + double double_sum; + void *sum_ptr = NULL; + + if (rd_type_is_double(rd_kw->data_type)) + sum_ptr = &double_sum; + else if (rd_type_is_float(rd_kw->data_type)) + sum_ptr = &float_sum; + else + util_abort("%s: invalid type: \n", __func__); + + rd_kw_element_sum(rd_kw, sum_ptr); + + if (rd_type_is_double(rd_kw->data_type)) + return double_sum; + else if (rd_type_is_float(rd_kw->data_type)) + return float_sum; + else + return 0; +} + +int rd_kw_element_sum_int(const rd_kw_type *rd_kw) { + int int_sum; + rd_kw_element_sum(rd_kw, &int_sum); + + return int_sum; +} + +#define RD_KW_FPRINTF_DATA(ctype) \ + static void rd_kw_fprintf_data_##ctype(const rd_kw_type *rd_kw, \ + const char *fmt, FILE *stream) { \ + const ctype *data = (const ctype *)rd_kw->data; \ + int i; \ + for (i = 0; i < rd_kw->size; i++) \ + fprintf(stream, fmt, data[i]); \ + } + +RD_KW_FPRINTF_DATA(int) +RD_KW_FPRINTF_DATA(float) +RD_KW_FPRINTF_DATA(double) +RD_KW_FPRINTF_DATA(bool) +#undef RD_KW_FPRINTF_DATA + +static void rd_kw_fprintf_data_string(const rd_kw_type *rd_kw, const char *fmt, + FILE *stream) { + int i; + for (i = 0; i < rd_kw->size; i++) + fprintf(stream, fmt, + &rd_kw->data[i * rd_type_get_sizeof_ctype(rd_kw->data_type)]); +} + +void rd_kw_fprintf_data(const rd_kw_type *rd_kw, const char *fmt, + FILE *stream) { + if (rd_type_is_double(rd_kw->data_type)) + rd_kw_fprintf_data_double(rd_kw, fmt, stream); + else if (rd_type_is_float(rd_kw->data_type)) + rd_kw_fprintf_data_float(rd_kw, fmt, stream); + else if (rd_type_is_int(rd_kw->data_type)) + rd_kw_fprintf_data_int(rd_kw, fmt, stream); + else if (rd_type_is_bool(rd_kw->data_type)) + rd_kw_fprintf_data_bool(rd_kw, fmt, stream); + else if (rd_type_is_char(rd_kw->data_type) || + rd_type_is_string(rd_kw->data_type)) + rd_kw_fprintf_data_string(rd_kw, fmt, stream); +} + +static bool rd_kw_elm_equal_numeric__(const rd_kw_type *rd_kw1, + const rd_kw_type *rd_kw2, int offset, + double abs_epsilon, double rel_epsilon) { + double v1 = rd_kw_iget_as_double(rd_kw1, offset); + double v2 = rd_kw_iget_as_double(rd_kw2, offset); + return util_double_approx_equal__(v1, v2, rel_epsilon, abs_epsilon); +} + +static bool rd_kw_elm_equal__(const rd_kw_type *rd_kw1, + const rd_kw_type *rd_kw2, int offset) { + size_t data_offset = rd_type_get_sizeof_ctype(rd_kw1->data_type) * offset; + int cmp = memcmp(&rd_kw1->data[data_offset], &rd_kw2->data[data_offset], + rd_type_get_sizeof_ctype(rd_kw1->data_type)); + if (cmp == 0) + return true; + else + return false; +} + +int rd_kw_first_different(const rd_kw_type *rd_kw1, const rd_kw_type *rd_kw2, + int offset, double abs_epsilon, double rel_epsilon) { + if (!rd_kw_size_and_type_equal(rd_kw1, rd_kw2)) + util_abort("%s: sorry invalid comparison\n", __func__); + + if (offset >= rd_kw_get_size(rd_kw1)) + util_abort("%s: sorry - invalid offset value\n", __func__); + + { + bool numeric_compare = false; + + if (((abs_epsilon > 0) || (rel_epsilon > 0)) && + ((rd_kw_get_type(rd_kw1) == RD_FLOAT_TYPE) || + (rd_kw_get_type(rd_kw1) == RD_DOUBLE_TYPE))) + numeric_compare = true; + { + int index = offset; + + while (true) { + bool equal = + (numeric_compare) + ? rd_kw_elm_equal_numeric__(rd_kw1, rd_kw2, index, + abs_epsilon, rel_epsilon) + : rd_kw_elm_equal__(rd_kw1, rd_kw2, index); + if (!equal) + break; + + index++; + if (index == rd_kw_get_size(rd_kw1)) + break; + } + + return index; + } + } +} + +#include "rd_kw_functions.cpp" diff --git a/lib/ecl/ecl_kw_functions.cpp b/lib/resdata/rd_kw_functions.cpp similarity index 76% rename from lib/ecl/ecl_kw_functions.cpp rename to lib/resdata/rd_kw_functions.cpp index 54d3ce4820..1c02a0ab9e 100644 --- a/lib/ecl/ecl_kw_functions.cpp +++ b/lib/resdata/rd_kw_functions.cpp @@ -1,12 +1,12 @@ /* - This file is included from the ecl_kw.c file during compilation. It - contains functions which are not really related to the ecl_kw as a - datastructure, but rather use an ecl_kw instance in a function. + This file is included from the rd_kw.c file during compilation. It + contains functions which are not really related to the rd_kw as a + datastructure, but rather use an rd_kw instance in a function. */ /* This is an extremely special-case function written for the region - creation code. Given a completed ecl_kw regions keyword, the purpose + creation code. Given a completed rd_kw regions keyword, the purpose of this function is to "detect and correct" uninitialized cells with value 0. This function is purely heuristic: @@ -19,10 +19,10 @@ value zero are not considered when comparing. */ -void ecl_kw_fix_uninitialized(ecl_kw_type *ecl_kw, int nx, int ny, int nz, - const int *actnum) { +void rd_kw_fix_uninitialized(rd_kw_type *rd_kw, int nx, int ny, int nz, + const int *actnum) { int i, j, k; - int *data = (int *)ecl_kw_get_ptr(ecl_kw); + int *data = (int *)rd_kw_get_ptr(rd_kw); int_vector_type *undetermined1 = int_vector_alloc(0, 0); int_vector_type *undetermined2 = int_vector_alloc(0, 0); @@ -127,17 +127,17 @@ void ecl_kw_fix_uninitialized(ecl_kw_type *ecl_kw, int nx, int ny, int nz, int_vector_free(undetermined2); } -ecl_kw_type *ecl_kw_alloc_actnum(const ecl_kw_type *porv_kw, float porv_limit) { - if (!ecl_type_is_float(porv_kw->data_type)) +rd_kw_type *rd_kw_alloc_actnum(const rd_kw_type *porv_kw, float porv_limit) { + if (!rd_type_is_float(porv_kw->data_type)) return NULL; - if (!util_string_equal(PORV_KW, ecl_kw_get_header(porv_kw))) + if (!util_string_equal(PORV_KW, rd_kw_get_header(porv_kw))) return NULL; - const int size = ecl_kw_get_size(porv_kw); - ecl_kw_type *actnum_kw = ecl_kw_alloc(ACTNUM_KW, size, ECL_INT); - const float *porv_values = ecl_kw_get_float_ptr(porv_kw); - int *actnum_values = ecl_kw_get_int_ptr(actnum_kw); + const int size = rd_kw_get_size(porv_kw); + rd_kw_type *actnum_kw = rd_kw_alloc(ACTNUM_KW, size, RD_INT); + const float *porv_values = rd_kw_get_float_ptr(porv_kw); + int *actnum_values = rd_kw_get_int_ptr(actnum_kw); for (int i = 0; i < size; i++) { if (porv_values[i] > porv_limit) @@ -153,20 +153,20 @@ ecl_kw_type *ecl_kw_alloc_actnum(const ecl_kw_type *porv_kw, float porv_limit) { Allocate actnum, and assign actnum_bitmask to all cells with pore volume larger than zero. The bit mask can be any combination of CELL_ACTIVE_MATRIX and CELL_ACTIVE_FRACTURE. - See documentation in top of ecl_grid.cpp + See documentation in top of rd_grid.cpp */ -ecl_kw_type *ecl_kw_alloc_actnum_bitmask(const ecl_kw_type *porv_kw, - float porv_limit, int actnum_bitmask) { - if (!ecl_type_is_float(porv_kw->data_type)) +rd_kw_type *rd_kw_alloc_actnum_bitmask(const rd_kw_type *porv_kw, + float porv_limit, int actnum_bitmask) { + if (!rd_type_is_float(porv_kw->data_type)) return NULL; - if (!util_string_equal(PORV_KW, ecl_kw_get_header(porv_kw))) + if (!util_string_equal(PORV_KW, rd_kw_get_header(porv_kw))) return NULL; - const int size = ecl_kw_get_size(porv_kw); - ecl_kw_type *actnum_kw = ecl_kw_alloc(ACTNUM_KW, size, ECL_INT); - const float *porv_values = ecl_kw_get_float_ptr(porv_kw); - int *actnum_values = ecl_kw_get_int_ptr(actnum_kw); + const int size = rd_kw_get_size(porv_kw); + rd_kw_type *actnum_kw = rd_kw_alloc(ACTNUM_KW, size, RD_INT); + const float *porv_values = rd_kw_get_float_ptr(porv_kw); + int *actnum_values = rd_kw_get_int_ptr(actnum_kw); for (int i = 0; i < size; i++) { if (porv_values[i] > porv_limit) diff --git a/lib/ecl/ecl_kw_grdecl.cpp b/lib/resdata/rd_kw_grdecl.cpp similarity index 78% rename from lib/ecl/ecl_kw_grdecl.cpp rename to lib/resdata/rd_kw_grdecl.cpp index e95a0b69b5..e9d8969a2f 100644 --- a/lib/ecl/ecl_kw_grdecl.cpp +++ b/lib/resdata/rd_kw_grdecl.cpp @@ -3,9 +3,9 @@ #include -#include -#include -#include +#include +#include +#include #define MAX_GRDECL_HEADER_SIZE 512 @@ -25,7 +25,7 @@ formatted numbers it is in general impossible to determine whether the underlying datatype should be integer, float or double. Therefore all the file-reading routines here expect an - ecl_data_type as input. + rd_data_type as input. 2. The files can have comment sections; even in the data block. @@ -52,7 +52,7 @@ are ignored. */ -bool ecl_kw_grdecl_fseek_next_kw(FILE *stream) { +bool rd_kw_grdecl_fseek_next_kw(FILE *stream) { long start_pos = util_ftell(stream); long current_pos; char next_kw[MAX_GRDECL_HEADER_SIZE]; @@ -100,7 +100,7 @@ bool ecl_kw_grdecl_fseek_next_kw(FILE *stream) { while (true) { current_pos = util_ftell(stream); if (fscanf(stream, "%s", next_kw) == 1) { - if ((next_kw[0] == next_kw[1]) && (next_kw[0] == ECL_COMMENT_CHAR)) + if ((next_kw[0] == next_kw[1]) && (next_kw[0] == RD_COMMENT_CHAR)) // This is a comment line - skip it. util_fskip_lines(stream, 1); else { @@ -117,14 +117,14 @@ bool ecl_kw_grdecl_fseek_next_kw(FILE *stream) { } /** - Will use the ecl_kw_grdecl_fseek_next_header() to seek out the next + Will use the rd_kw_grdecl_fseek_next_header() to seek out the next header string, and read and return that string. If no more headers are found the function will return NULL. The storage allocated by this function must be free'd by the calling scope. */ -char *ecl_kw_grdecl_alloc_next_header(FILE *stream) { - if (ecl_kw_grdecl_fseek_next_kw(stream)) { +char *rd_kw_grdecl_alloc_next_header(FILE *stream) { + if (rd_kw_grdecl_fseek_next_kw(stream)) { char next_kw[MAX_GRDECL_HEADER_SIZE]; fscanf(stream, "%s", next_kw); return util_alloc_string_copy(next_kw); @@ -135,7 +135,7 @@ char *ecl_kw_grdecl_alloc_next_header(FILE *stream) { /** This function will search through a GRDECL file to look for the 'kw'; input variables and return vales are similar to - ecl_kw_fseek_kw(). Observe that the GRDECL files are extremely + rd_kw_fseek_kw(). Observe that the GRDECL files are extremely weakly structured, it is therefore veeeery easy to fool this function with a malformed GRDECL file. @@ -145,10 +145,10 @@ char *ecl_kw_grdecl_alloc_next_header(FILE *stream) { If the kw is not found the file pointer is repositioned. */ -static bool ecl_kw_grdecl_fseek_kw__(const char *kw, FILE *stream) { +static bool rd_kw_grdecl_fseek_kw__(const char *kw, FILE *stream) { long init_pos = util_ftell(stream); while (true) { - if (ecl_kw_grdecl_fseek_next_kw(stream)) { + if (rd_kw_grdecl_fseek_next_kw(stream)) { char next_kw[256]; fscanf(stream, "%s", next_kw); if (strcmp(kw, next_kw) == 0) { @@ -163,14 +163,14 @@ static bool ecl_kw_grdecl_fseek_kw__(const char *kw, FILE *stream) { } } -bool ecl_kw_grdecl_fseek_kw(const char *kw, bool rewind, FILE *stream) { - if (ecl_kw_grdecl_fseek_kw__(kw, stream)) +bool rd_kw_grdecl_fseek_kw(const char *kw, bool rewind, FILE *stream) { + if (rd_kw_grdecl_fseek_kw__(kw, stream)) return true; /* OK - we found the kw between current file pos and EOF. */ else if (rewind) { long int init_pos = util_ftell(stream); util_fseek(stream, 0L, SEEK_SET); - if (ecl_kw_grdecl_fseek_kw__( + if (rd_kw_grdecl_fseek_kw__( kw, stream)) /* Try again from the beginning of the file. */ return true; else @@ -229,21 +229,21 @@ static void iset_range(char *data, int data_index, int sizeof_ctype, */ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, - ecl_data_type data_type, int *kw_size, + rd_data_type data_type, int *kw_size, FILE *stream) { char newline = '\n'; bool atEOF = false; size_t init_size = 32; size_t buffer_size = 64; size_t data_index = 0; - int sizeof_ctype = ecl_type_get_sizeof_ctype(data_type); + int sizeof_ctype = rd_type_get_sizeof_ctype(data_type); size_t data_size = init_size; char *buffer = (char *)util_calloc((buffer_size + 1), sizeof *buffer); char *data = (char *)util_calloc(sizeof_ctype * data_size, sizeof *data); while (true) { if (fscanf(stream, "%32s", buffer) == 1) { - if (strcmp(buffer, ECL_COMMENT_STRING) == 0) { + if (strcmp(buffer, RD_COMMENT_STRING) == 0) { // We have read a comment marker - just read up to the end of line. char c; while (true) { @@ -255,7 +255,7 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, break; } } - } else if (strcmp(buffer, ECL_DATA_TERMINATION) == 0) + } else if (strcmp(buffer, RD_DATA_TERMINATION) == 0) break; else { // We have read a valid input string; scan numerical input values from it. @@ -270,7 +270,7 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, int multiplier; bool char_input = false; - if (ecl_type_is_int(data_type)) { + if (rd_type_is_int(data_type)) { if (sscanf(buffer, "%d*%d", &multiplier, &value.i) == 2) { } else if (sscanf(buffer, "%d", &value.i) == 1) multiplier = 1; @@ -281,7 +281,7 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, "reading keyword:%s \n", __func__, buffer, header); } - } else if (ecl_type_is_float(data_type)) { + } else if (rd_type_is_float(data_type)) { if (sscanf(buffer, "%d*%g", &multiplier, &value.f) == 2) { } else if (sscanf(buffer, "%g", &value.f) == 1) multiplier = 1; @@ -292,7 +292,7 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, "reading keyword:%s \n", __func__, buffer, header); } - } else if (ecl_type_is_double(data_type)) { + } else if (rd_type_is_double(data_type)) { if (sscanf(buffer, "%d*%lg", &multiplier, &value.d) == 2) { } else if (sscanf(buffer, "%lg", &value.d) == 1) multiplier = 1; @@ -305,7 +305,7 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, } } else util_abort("%s: sorry type:%s not supported \n", __func__, - ecl_type_alloc_name(data_type)); + rd_type_alloc_name(data_type)); /* Removing this warning on user request: @@ -315,11 +315,11 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, if (!char_input) { size_t min_size = data_index + multiplier; if (min_size >= data_size) { - if (min_size <= ECL_KW_MAX_SIZE) { + if (min_size <= RD_KW_MAX_SIZE) { size_t byte_size = sizeof_ctype * sizeof *data; data_size = util_size_t_min( - ECL_KW_MAX_SIZE, 2 * (data_index + multiplier)); + RD_KW_MAX_SIZE, 2 * (data_index + multiplier)); byte_size *= data_size; data = (char *)util_realloc(data, byte_size); @@ -357,20 +357,20 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, first. Observe that the grdecl files are very weakly structured, so the - loading of ecl_kw instances from a grdecl file can go wrong in many + loading of rd_kw instances from a grdecl file can go wrong in many ways; if the loading fails the function returns NULL. The main loop is extremely simple - it is just repeated calls to fscanf() to read one-number-at-atime; when that reading fails that is interpreted as the end of the keyword. - Currently ONLY integer and float types are supported in ecl_type - + Currently ONLY integer and float types are supported in rd_type - any other types will lead to a hard failure. - The ecl_kw class has a quite deeply wired assumption that the + The rd_kw class has a quite deeply wired assumption that the header is a string of length 8 (I hope/think that is an ECLIPSE limitation). The class cannot read/write kw with headers longer than 8 bytes. - ecl_kw_grdecl is a workaround allowing for reading/writing kw with long + rd_kw_grdecl is a workaround allowing for reading/writing kw with long headers. ----------------------------------------------------------------- @@ -398,9 +398,9 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, elements found on the file. - ecl_type: The files have no embedded type information and the type + rd_type: The files have no embedded type information and the type must be supplied by the calling scope. Currently only the - ECL_FLOAT_TYPE and ECL_INT_TYPE types are supported. + RD_FLOAT_TYPE and RD_INT_TYPE types are supported. ----------------------------------------------------------------- @@ -409,21 +409,21 @@ static char *fscanf_alloc_grdecl_data(const char *header, bool strict, if there is something wrong it can be difficult to detect. */ -static ecl_kw_type *__ecl_kw_fscanf_alloc_grdecl__(FILE *stream, - const char *header, - bool strict, int size, - ecl_data_type data_type) { +static rd_kw_type *__rd_kw_fscanf_alloc_grdecl__(FILE *stream, + const char *header, + bool strict, int size, + rd_data_type data_type) { if (header && strlen(header) > MAX_GRDECL_HEADER_SIZE) util_abort( "%s cannot read KW of more than %d bytes. strlen(header) == %d\n", __func__, MAX_GRDECL_HEADER_SIZE, strlen(header)); - if (!ecl_type_is_numeric(data_type)) + if (!rd_type_is_numeric(data_type)) util_abort("%s: sorry only types FLOAT, INT and DOUBLE supported\n", __func__); if (header != NULL) - if (!ecl_kw_grdecl_fseek_kw(header, true, stream)) + if (!rd_kw_grdecl_fseek_kw(header, true, stream)) return NULL; /* Could not find it. */ { @@ -443,10 +443,10 @@ static ecl_kw_type *__ecl_kw_fscanf_alloc_grdecl__(FILE *stream, } { - ecl_kw_type *ecl_kw = - ecl_kw_alloc_new(file_header, kw_size, data_type, NULL); - ecl_kw_set_data_ptr(ecl_kw, data); - return ecl_kw; + rd_kw_type *rd_kw = + rd_kw_alloc_new(file_header, kw_size, data_type, NULL); + rd_kw_set_data_ptr(rd_kw, data); + return rd_kw; } } else @@ -462,17 +462,15 @@ static ecl_kw_type *__ecl_kw_fscanf_alloc_grdecl__(FILE *stream, incorrectly positioned this will most probably blow up big time. */ -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_data__(FILE *stream, bool strict, - int size, - ecl_data_type data_type) { - return __ecl_kw_fscanf_alloc_grdecl__(stream, NULL, strict, size, - data_type); +rd_kw_type *rd_kw_fscanf_alloc_grdecl_data__(FILE *stream, bool strict, + int size, rd_data_type data_type) { + return __rd_kw_fscanf_alloc_grdecl__(stream, NULL, strict, size, data_type); } -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_data(FILE *stream, int size, - ecl_data_type data_type) { +rd_kw_type *rd_kw_fscanf_alloc_grdecl_data(FILE *stream, int size, + rd_data_type data_type) { bool strict = true; - return ecl_kw_fscanf_alloc_grdecl_data__(stream, strict, size, data_type); + return rd_kw_fscanf_alloc_grdecl_data__(stream, strict, size, data_type); } /* @@ -485,16 +483,16 @@ ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_data(FILE *stream, int size, the whole keyword is loaded, and then return. */ -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_dynamic__(FILE *stream, const char *kw, - bool strict, - ecl_data_type data_type) { - return __ecl_kw_fscanf_alloc_grdecl__(stream, kw, strict, 0, data_type); +rd_kw_type *rd_kw_fscanf_alloc_grdecl_dynamic__(FILE *stream, const char *kw, + bool strict, + rd_data_type data_type) { + return __rd_kw_fscanf_alloc_grdecl__(stream, kw, strict, 0, data_type); } -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_dynamic(FILE *stream, const char *kw, - ecl_data_type data_type) { +rd_kw_type *rd_kw_fscanf_alloc_grdecl_dynamic(FILE *stream, const char *kw, + rd_data_type data_type) { bool strict = true; - return ecl_kw_fscanf_alloc_grdecl_dynamic__(stream, kw, strict, data_type); + return rd_kw_fscanf_alloc_grdecl_dynamic__(stream, kw, strict, data_type); } /* @@ -506,20 +504,20 @@ ecl_kw_type *ecl_kw_fscanf_alloc_grdecl_dynamic(FILE *stream, const char *kw, When the data has been loaded the function will compare actual size with the supplied size argument and verify equality; if they differ it will crash hard. If you are uncertain of the size use the - ecl_kw_fscanf_alloc_grdecl_dynamic() function instead; or supply + rd_kw_fscanf_alloc_grdecl_dynamic() function instead; or supply size == 0. */ -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl__(FILE *stream, const char *kw, - bool strict, int size, - ecl_data_type data_type) { - return __ecl_kw_fscanf_alloc_grdecl__(stream, kw, strict, size, data_type); +rd_kw_type *rd_kw_fscanf_alloc_grdecl__(FILE *stream, const char *kw, + bool strict, int size, + rd_data_type data_type) { + return __rd_kw_fscanf_alloc_grdecl__(stream, kw, strict, size, data_type); } -ecl_kw_type *ecl_kw_fscanf_alloc_grdecl(FILE *stream, const char *kw, int size, - ecl_data_type data_type) { +rd_kw_type *rd_kw_fscanf_alloc_grdecl(FILE *stream, const char *kw, int size, + rd_data_type data_type) { bool strict = true; - return ecl_kw_fscanf_alloc_grdecl__(stream, kw, strict, size, data_type); + return rd_kw_fscanf_alloc_grdecl__(stream, kw, strict, size, data_type); } /* @@ -530,15 +528,15 @@ ecl_kw_type *ecl_kw_fscanf_alloc_grdecl(FILE *stream, const char *kw, int size, that the input file is well formatted. */ -ecl_kw_type *ecl_kw_fscanf_alloc_current_grdecl__(FILE *stream, bool strict, - ecl_data_type data_type) { - return __ecl_kw_fscanf_alloc_grdecl__(stream, NULL, strict, 0, data_type); +rd_kw_type *rd_kw_fscanf_alloc_current_grdecl__(FILE *stream, bool strict, + rd_data_type data_type) { + return __rd_kw_fscanf_alloc_grdecl__(stream, NULL, strict, 0, data_type); } -ecl_kw_type *ecl_kw_fscanf_alloc_current_grdecl(FILE *stream, - ecl_data_type data_type) { +rd_kw_type *rd_kw_fscanf_alloc_current_grdecl(FILE *stream, + rd_data_type data_type) { bool strict = true; - return ecl_kw_fscanf_alloc_current_grdecl__(stream, strict, data_type); + return rd_kw_fscanf_alloc_current_grdecl__(stream, strict, data_type); } /* @@ -547,23 +545,23 @@ ecl_kw_type *ecl_kw_fscanf_alloc_current_grdecl(FILE *stream, length limit; i.e. loading it back naively will fail. */ -void ecl_kw_fprintf_grdecl__(const ecl_kw_type *ecl_kw, - const char *special_header, FILE *stream) { +void rd_kw_fprintf_grdecl__(const rd_kw_type *rd_kw, const char *special_header, + FILE *stream) { if (special_header) fprintf(stream, "%s\n", special_header); else - fprintf(stream, "%s\n", ecl_kw_get_header(ecl_kw)); + fprintf(stream, "%s\n", rd_kw_get_header(rd_kw)); { fortio_type *fortio = fortio_alloc_FILE_wrapper( NULL, false, true, true, stream); /* Endian flip should *NOT* be used */ - ecl_kw_fwrite_data(ecl_kw, fortio); + rd_kw_fwrite_data(rd_kw, fortio); fortio_free_FILE_wrapper(fortio); } fprintf(stream, "/\n"); } -void ecl_kw_fprintf_grdecl(const ecl_kw_type *ecl_kw, FILE *stream) { - ecl_kw_fprintf_grdecl__(ecl_kw, NULL, stream); +void rd_kw_fprintf_grdecl(const rd_kw_type *rd_kw, FILE *stream) { + rd_kw_fprintf_grdecl__(rd_kw, NULL, stream); } diff --git a/lib/resdata/rd_nnc_data.cpp b/lib/resdata/rd_nnc_data.cpp new file mode 100644 index 0000000000..479634336c --- /dev/null +++ b/lib/resdata/rd_nnc_data.cpp @@ -0,0 +1,270 @@ +#define RD_NNC_DATA_TYPE_ID 83756236 + +#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 new file mode 100644 index 0000000000..58872c7398 --- /dev/null +++ b/lib/resdata/rd_nnc_export.cpp @@ -0,0 +1,288 @@ +#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/ecl/ecl_nnc_geometry.cpp b/lib/resdata/rd_nnc_geometry.cpp similarity index 55% rename from lib/ecl/ecl_nnc_geometry.cpp rename to lib/resdata/rd_nnc_geometry.cpp index 8ffa986dec..0a0ff2ad21 100644 --- a/lib/ecl/ecl_nnc_geometry.cpp +++ b/lib/resdata/rd_nnc_geometry.cpp @@ -1,18 +1,18 @@ #include #include -#include +#include -#define ECL_NNC_GEOMETRY_TYPE_ID 6124343 +#define RD_NNC_GEOMETRY_TYPE_ID 6124343 -struct ecl_nnc_geometry_struct { +struct rd_nnc_geometry_struct { UTIL_TYPE_ID_DECLARATION; - std::vector *data; + std::vector *data; }; -UTIL_IS_INSTANCE_FUNCTION(ecl_nnc_geometry, ECL_NNC_GEOMETRY_TYPE_ID) +UTIL_IS_INSTANCE_FUNCTION(rd_nnc_geometry, RD_NNC_GEOMETRY_TYPE_ID) -int ecl_nnc_geometry_size(const ecl_nnc_geometry_type *nnc_geo) { +int rd_nnc_geometry_size(const rd_nnc_geometry_type *nnc_geo) { return nnc_geo->data->size(); } @@ -26,18 +26,18 @@ int ecl_nnc_geometry_size(const ecl_nnc_geometry_type *nnc_geo) { cells (grid_nr1, global_index1) and (grid_nr2, global_index2). */ -static void ecl_nnc_geometry_add_pairs(const ecl_nnc_geometry_type *nnc_geo, - const ecl_grid_type *grid) { - int lgr_nr1 = ecl_grid_get_lgr_nr(grid); - const ecl_grid_type *global_grid = ecl_grid_get_global_grid(grid); +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 < ecl_grid_get_global_size(grid); + for (int global_index1 = 0; global_index1 < rd_grid_get_global_size(grid); global_index1++) { const nnc_info_type *nnc_info = - ecl_grid_get_cell_nnc_info1(grid, global_index1); + rd_grid_get_cell_nnc_info1(grid, global_index1); if (!nnc_info) continue; @@ -53,7 +53,7 @@ static void ecl_nnc_geometry_add_pairs(const ecl_nnc_geometry_type *nnc_geo, for (int index2 = 0; index2 < nnc_vector_get_size(nnc_vector); index2++) { - ecl_nnc_pair_type pair; + rd_nnc_pair_type pair; pair.grid_nr1 = lgr_nr1; pair.global_index1 = global_index1; pair.grid_nr2 = lgr_nr2; @@ -65,8 +65,8 @@ static void ecl_nnc_geometry_add_pairs(const ecl_nnc_geometry_type *nnc_geo, } } -static bool ecl_nnc_cmp(const ecl_nnc_pair_type &nnc1, - const ecl_nnc_pair_type &nnc2) { +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; @@ -82,35 +82,35 @@ static bool ecl_nnc_cmp(const ecl_nnc_pair_type &nnc1, return false; } -ecl_nnc_geometry_type *ecl_nnc_geometry_alloc(const ecl_grid_type *grid) { - ecl_nnc_geometry_type *nnc_geo = - (ecl_nnc_geometry_type *)util_malloc(sizeof *nnc_geo); - UTIL_TYPE_ID_INIT(nnc_geo, ECL_NNC_GEOMETRY_TYPE_ID); - nnc_geo->data = new std::vector(); +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(); - ecl_nnc_geometry_add_pairs(nnc_geo, grid); - for (int lgr_index = 0; lgr_index < ecl_grid_get_num_lgr(grid); + rd_nnc_geometry_add_pairs(nnc_geo, grid); + for (int lgr_index = 0; lgr_index < rd_grid_get_num_lgr(grid); lgr_index++) { - ecl_grid_type *igrid = ecl_grid_iget_lgr(grid, lgr_index); - ecl_nnc_geometry_add_pairs(nnc_geo, igrid); + 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(), ecl_nnc_cmp); + std::sort(nnc_geo->data->begin(), nnc_geo->data->end(), rd_nnc_cmp); return nnc_geo; } -void ecl_nnc_geometry_free(ecl_nnc_geometry_type *nnc_geo) { +void rd_nnc_geometry_free(rd_nnc_geometry_type *nnc_geo) { delete nnc_geo->data; free(nnc_geo); } -const ecl_nnc_pair_type * -ecl_nnc_geometry_iget(const ecl_nnc_geometry_type *nnc_geo, int index) { - const std::vector &nnc_data = *nnc_geo->data; +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 ecl_nnc_geometry_same_kw(const ecl_nnc_pair_type *nnc1, - const ecl_nnc_pair_type *nnc2) { +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; diff --git a/lib/resdata/rd_region.cpp b/lib/resdata/rd_region.cpp new file mode 100644 index 0000000000..8c69fa8295 --- /dev/null +++ b/lib/resdata/rd_region.cpp @@ -0,0 +1,1528 @@ +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +/** + This file implements a type called rd_region which is a way to + select and keep track of designated cells in an reservoir + grid. An instance is allocated with a grid (a shared reference + which is NOT modified). Then we can select/deselect cells based on: + + 1. Integer equality - rd_region_select_equal() + 2. Float interval - rd_region_select_in_interval() + 3. A rectangualar box - rd_region_select_from_box() + 4. Subsections of i/j/k - rd_region_select_i1i2() / rd_region_seleect_j1j2() / ... + 5. All cells - rd_region_select_all() + + When allocating an instance you determine whether all cells should + be initially selected, or not-selected. The various select + functions can (of course ...) be chained together. All functions + exist in a xxx_select() and an opposite xxx_deselect() version. + + When you are finished with selecting you can query the rd_region + instance for the number of active cells, and get a (const int *) to + the indices. You can also get the results in term of global + indices. (Refer to rd_grid for the difference between active and + global indices). + + For the functions which take rd_kw input, the rd_kw instance must + have either nx*ny*nz elements, or nactive(from the grid) + elements. This is checked, and the program will fail hard if it is + not satisfied. + + Example: + -------- + + rd_grid_type * rd_grid; + rd_kw_type * soil; + rd_kw_type * regions; + rd_region_type * rd_region; + + // Load grid, soil and regions somehow. + + rd_region = rd_region_alloc( rd_grid , false ); // Start with nothing selected + rd_region_select_in_interval( rd_region , soil , 0.50, 1.00); // Select all cells with soil > 0.50 + rd_region_select_equal( rd_region , regions , 3 ); // Only consider region 3. + rd_region_select_k1k2( rd_region , 5 , 8); // Select layers 5,6,7,8 + { + int num_cells = rd_region_get_global_size( rd_region ); // How many cells are active + const int * cell_list = rd_region_get_global_list( rd_region ); // Get a list of indices + int i; + printf("%d cells satisfy your selection. The cells are: \n"); + + for (i=0; i < num_cells; i++) + printf("Cell: %d \n",cell_list[i]); + } + + rd_region_free( rd_region ); + +*/ + +#define RD_REGION_TYPE_ID 1106377 + +struct rd_region_struct { + UTIL_TYPE_ID_DECLARATION; + bool * + active_mask; /* This marks active|inactive in the region, which is unrelated to active in the grid. */ + int_vector_type * + global_index_list; /* This is a list of the cells in the region - irrespective of whether they are active in the grid or not. */ + int_vector_type * + active_index_list; /* This means cells in the region which are also active in the grid */ + int_vector_type * + global_active_list; /* This is a list of (maximum) nactive elements, where the values are in the [0,..nx*ny*nz) range. */ + bool global_index_list_valid; + bool active_index_list_valid; + + char *name; /* User name attached to region will typically be NULL. */ + bool preselect; + /* Grid properties */ + int grid_nx, grid_ny, grid_nz, grid_vol, grid_active; + const rd_grid_type *parent_grid; +}; + +UTIL_IS_INSTANCE_FUNCTION(rd_region, RD_REGION_TYPE_ID) +UTIL_SAFE_CAST_FUNCTION(rd_region, RD_REGION_TYPE_ID) + +static void rd_region_invalidate_index_list(rd_region_type *region) { + region->global_index_list_valid = false; + region->active_index_list_valid = false; +} + +void rd_region_lock(rd_region_type *region) { + int_vector_set_read_only(region->global_index_list, true); + int_vector_set_read_only(region->active_index_list, true); + int_vector_set_read_only(region->global_active_list, true); +} + +void rd_region_unlock(rd_region_type *region) { + int_vector_set_read_only(region->global_index_list, false); + int_vector_set_read_only(region->active_index_list, false); + int_vector_set_read_only(region->global_active_list, false); +} + +rd_region_type *rd_region_alloc(const rd_grid_type *rd_grid, bool preselect) { + rd_region_type *region = (rd_region_type *)util_malloc(sizeof *region); + UTIL_TYPE_ID_INIT(region, RD_REGION_TYPE_ID); + region->parent_grid = rd_grid; + rd_grid_get_dims(rd_grid, ®ion->grid_nx, ®ion->grid_ny, + ®ion->grid_nz, ®ion->grid_active); + region->grid_vol = region->grid_nx * region->grid_ny * region->grid_nz; + region->active_mask = + (bool *)util_calloc(region->grid_vol, sizeof *region->active_mask); + region->active_index_list = int_vector_alloc(0, 0); + region->global_index_list = int_vector_alloc(0, 0); + region->global_active_list = int_vector_alloc(0, 0); + region->preselect = preselect; + region->name = NULL; + rd_region_reset( + region); /* This MUST be called to ensure that xxx_valid is correctly initialized. */ + return region; +} + +rd_region_type *rd_region_alloc_copy(const rd_region_type *rd_region) { + rd_region_type *new_region = + rd_region_alloc(rd_region->parent_grid, rd_region->preselect); + memcpy(new_region->active_mask, rd_region->active_mask, + rd_region->grid_vol * sizeof *rd_region->active_mask); + rd_region_invalidate_index_list(new_region); + return new_region; +} + +void rd_region_free(rd_region_type *region) { + free(region->active_mask); + int_vector_free(region->active_index_list); + int_vector_free(region->global_index_list); + int_vector_free(region->global_active_list); + free(region->name); + free(region); +} + +void rd_region_free__(void *__region) { + rd_region_type *region = rd_region_safe_cast(__region); + rd_region_free(region); +} + +static void rd_region_assert_global_index_list(rd_region_type *region) { + if (!region->global_index_list_valid) { + int global_index; + + int_vector_reset(region->global_index_list); + for (global_index = 0; global_index < region->grid_vol; global_index++) + if (region->active_mask[global_index]) + int_vector_append(region->global_index_list, global_index); + + region->global_index_list_valid = true; + } +} + +static void rd_region_assert_active_index_list(rd_region_type *region) { + if (!region->active_index_list_valid) { + int global_index; + + int_vector_reset(region->active_index_list); + int_vector_reset(region->global_active_list); + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (region->active_mask[global_index]) { + int active_index = rd_grid_get_active_index1( + region->parent_grid, global_index); + if (active_index >= 0) { + int_vector_append(region->active_index_list, active_index); + int_vector_append(region->global_active_list, global_index); + } + } + } + region->active_index_list_valid = true; + } +} + +const int_vector_type *rd_region_get_active_list(rd_region_type *region) { + rd_region_assert_active_index_list(region); + return region->active_index_list; +} + +const int_vector_type * +rd_region_get_global_active_list(rd_region_type *region) { + rd_region_assert_active_index_list(region); + return region->global_active_list; +} + +const int_vector_type *rd_region_get_global_list(rd_region_type *region) { + rd_region_assert_global_index_list(region); + return region->global_index_list; +} + +/* Cpp compat/legacy/cruft functions. */ +int rd_region_get_active_size_cpp(rd_region_type *region) { + return int_vector_size(rd_region_get_active_list(region)); +} + +int rd_region_get_global_size_cpp(rd_region_type *region) { + return int_vector_size(rd_region_get_global_list(region)); +} + +const int *rd_region_get_active_list_cpp(rd_region_type *region) { + return int_vector_get_const_ptr(rd_region_get_active_list(region)); +} + +const int *rd_region_get_global_list_cpp(rd_region_type *region) { + return int_vector_get_const_ptr(rd_region_get_global_list(region)); +} + +static void rd_region_assert_kw(const rd_region_type *region, + const rd_kw_type *rd_kw, bool *global_kw) { + int kw_size = rd_kw_get_size(rd_kw); + if (!(kw_size == region->grid_vol || kw_size == region->grid_active)) + util_abort( + "%s: size mismatch between rd_kw instance and region->grid \n", + __func__); + if (kw_size == region->grid_vol) + *global_kw = true; + else + *global_kw = false; +} + +void rd_region_reset(rd_region_type *rd_region) { + int i; + for (i = 0; i < rd_region->grid_vol; i++) + rd_region->active_mask[i] = rd_region->preselect; + rd_region_invalidate_index_list(rd_region); +} + +static void rd_region_select_cell__(rd_region_type *region, int i, int j, int k, + bool select) { + int global_index = rd_grid_get_global_index3(region->parent_grid, i, j, k); + region->active_mask[global_index] = select; + rd_region_invalidate_index_list(region); +} + +void rd_region_select_cell(rd_region_type *region, int i, int j, int k) { + rd_region_select_cell__(region, i, j, k, true); +} + +void rd_region_deselect_cell(rd_region_type *region, int i, int j, int k) { + rd_region_select_cell__(region, i, j, k, false); +} + +static void rd_region_select_equal__(rd_region_type *region, + const rd_kw_type *rd_kw, int value, + bool select) { + bool global_kw; + rd_region_assert_kw(region, rd_kw, &global_kw); + if (!rd_type_is_int(rd_kw_get_data_type(rd_kw))) + util_abort("%s: sorry - select by equality is only supported for " + "integer keywords \n", + __func__); + { + const int *kw_data = rd_kw_get_int_ptr(rd_kw); + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (kw_data[global_index] == value) + region->active_mask[global_index] = select; + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (kw_data[active_index] == value) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_equal(rd_region_type *region, const rd_kw_type *rd_kw, + int value) { + rd_region_select_equal__(region, rd_kw, value, true); +} + +void rd_region_deselect_equal(rd_region_type *region, const rd_kw_type *rd_kw, + int value) { + rd_region_select_equal__(region, rd_kw, value, false); +} + +static void rd_region_select_bool_equal__(rd_region_type *region, + const rd_kw_type *rd_kw, bool value, + bool select) { + bool global_kw; + rd_region_assert_kw(region, rd_kw, &global_kw); + if (!rd_type_is_bool(rd_kw_get_data_type(rd_kw))) + util_abort("%s: sorry - select by equality is only supported for " + "boolean keywords \n", + __func__); + { + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (rd_kw_iget_bool(rd_kw, global_index) == value) + region->active_mask[global_index] = select; + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (rd_kw_iget_bool(rd_kw, active_index) == value) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_true(rd_region_type *region, const rd_kw_type *rd_kw) { + rd_region_select_bool_equal__(region, rd_kw, true, true); +} + +void rd_region_deselect_true(rd_region_type *region, const rd_kw_type *rd_kw) { + rd_region_select_bool_equal__(region, rd_kw, true, false); +} + +void rd_region_select_false(rd_region_type *region, const rd_kw_type *rd_kw) { + rd_region_select_bool_equal__(region, rd_kw, false, true); +} + +void rd_region_deselect_false(rd_region_type *region, const rd_kw_type *rd_kw) { + rd_region_select_bool_equal__(region, rd_kw, false, false); +} + +static void rd_region_select_in_interval__(rd_region_type *region, + const rd_kw_type *rd_kw, + float min_value, float max_value, + bool select) { + bool global_kw; + rd_region_assert_kw(region, rd_kw, &global_kw); + if (!rd_type_is_float(rd_kw_get_data_type(rd_kw))) + util_abort("%s: sorry - select by in_interval is only supported for " + "float keywords \n", + __func__); + { + const float *kw_data = rd_kw_get_float_ptr(rd_kw); + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (kw_data[global_index] >= min_value && + kw_data[global_index] < max_value) + region->active_mask[global_index] = select; + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (kw_data[active_index] >= min_value && + kw_data[active_index] < max_value) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_in_interval(rd_region_type *region, + const rd_kw_type *rd_kw, float min_value, + float max_value) { + rd_region_select_in_interval__(region, rd_kw, min_value, max_value, true); +} + +void rd_region_deselect_in_interval(rd_region_type *region, + const rd_kw_type *rd_kw, float min_value, + float max_value) { + rd_region_select_in_interval__(region, rd_kw, min_value, max_value, false); +} + +/** + This is too large: + + Float / Int / double * Active / Global * More / Less ==> In total 12 code blocks written out ... +*/ + +/* + NBNBNBNB: Select >= on float values and select > on integer!!!!!! +*/ +static void rd_region_select_with_limit__(rd_region_type *region, + const rd_kw_type *rd_kw, float limit, + bool select_less, bool select) { + bool global_kw; + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + rd_region_assert_kw(region, rd_kw, &global_kw); + if (!rd_type_is_numeric(data_type)) + util_abort("%s: sorry - select by in_interval is only supported for " + "float and integer keywords \n", + __func__); + + { + if (rd_type_is_float(data_type)) { + const float *kw_data = rd_kw_get_float_ptr(rd_kw); + float float_limit = limit; + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (select_less) { + if (kw_data[global_index] < float_limit) + region->active_mask[global_index] = select; + } else { + if (kw_data[global_index] >= float_limit) + region->active_mask[global_index] = select; + } + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (select_less) { + if (kw_data[active_index] < float_limit) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } else { + if (kw_data[active_index] >= float_limit) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + } else if (rd_type_is_int(data_type)) { + const int *kw_data = rd_kw_get_int_ptr(rd_kw); + int int_limit = (int)limit; + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (select_less) { + if (kw_data[global_index] < int_limit) + region->active_mask[global_index] = select; + } else { + if (kw_data[global_index] > int_limit) + region->active_mask[global_index] = select; + } + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (select_less) { + if (kw_data[active_index] < int_limit) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } else { + if (kw_data[active_index] > int_limit) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + } else if (rd_type_is_double(data_type)) { + const double *kw_data = rd_kw_get_double_ptr(rd_kw); + double double_limit = (double)limit; + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (select_less) { + if (kw_data[global_index] < double_limit) + region->active_mask[global_index] = select; + } else { + if (kw_data[global_index] >= double_limit) + region->active_mask[global_index] = select; + } + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (select_less) { + if (kw_data[active_index] < double_limit) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } else { + if (kw_data[active_index] >= double_limit) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_smaller(rd_region_type *rd_region, + const rd_kw_type *rd_kw, float limit) { + rd_region_select_with_limit__(rd_region, rd_kw, limit, true, true); +} + +void rd_region_deselect_smaller(rd_region_type *rd_region, + const rd_kw_type *rd_kw, float limit) { + rd_region_select_with_limit__(rd_region, rd_kw, limit, true, false); +} + +void rd_region_select_larger(rd_region_type *rd_region, const rd_kw_type *rd_kw, + float limit) { + rd_region_select_with_limit__(rd_region, rd_kw, limit, false, true); +} + +void rd_region_deselect_larger(rd_region_type *rd_region, + const rd_kw_type *rd_kw, float limit) { + rd_region_select_with_limit__(rd_region, rd_kw, limit, false, false); +} + +/** + Selection based on comparing two keywords. +*/ + +static void rd_region_cmp_select__(rd_region_type *region, + const rd_kw_type *kw1, const rd_kw_type *kw2, + bool select_less, bool select) { + bool global_kw; + rd_region_assert_kw(region, kw1, &global_kw); + if (!rd_type_is_float(rd_kw_get_data_type(kw1))) + util_abort("%s: sorry - select by cmp() is only supported for float " + "keywords \n", + __func__); + { + if (rd_kw_size_and_type_equal(kw1, kw2)) { + + const float *kw1_data = rd_kw_get_float_ptr(kw1); + const float *kw2_data = rd_kw_get_float_ptr(kw2); + + if (global_kw) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + if (select_less) { + if (kw1_data[global_index] < kw2_data[global_index]) + region->active_mask[global_index] = select; + } else { + if (kw1_data[global_index] >= kw2_data[global_index]) + region->active_mask[global_index] = select; + } + } + } else { + int active_index; + for (active_index = 0; active_index < region->grid_active; + active_index++) { + if (select_less) { + if (kw1_data[active_index] < kw2_data[active_index]) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } else { + if (kw1_data[active_index] >= kw2_data[active_index]) { + int global_index = rd_grid_get_global_index1A( + region->parent_grid, active_index); + region->active_mask[global_index] = select; + } + } + } + } + } else + util_abort("%s: type/size mismatch between keywords. \n", __func__); + } + rd_region_invalidate_index_list(region); +} + +void rd_region_cmp_select_less(rd_region_type *rd_region, const rd_kw_type *kw1, + const rd_kw_type *kw2) { + rd_region_cmp_select__(rd_region, kw1, kw2, true, true); +} + +void rd_region_cmp_deselect_less(rd_region_type *rd_region, + const rd_kw_type *kw1, const rd_kw_type *kw2) { + rd_region_cmp_select__(rd_region, kw1, kw2, true, false); +} + +void rd_region_cmp_select_more(rd_region_type *rd_region, const rd_kw_type *kw1, + const rd_kw_type *kw2) { + rd_region_cmp_select__(rd_region, kw1, kw2, false, true); +} + +void rd_region_cmp_deselect_more(rd_region_type *rd_region, + const rd_kw_type *kw1, const rd_kw_type *kw2) { + rd_region_cmp_select__(rd_region, kw1, kw2, false, false); +} + +/** + Will select all the cells in the box. Remember that the box is + defined as an inclusive geometry. Alternatively the functions + xxx_ijkbox() can be used, these functions take i1,i2,j1,j2,k1,k2 as + input and create a temporary box object. +*/ + +static void rd_region_select_from_box__(rd_region_type *region, + const rd::rd_box &rd_box, bool select) { + for (auto global_index : rd_box.active_list()) + region->active_mask[global_index] = select; + + rd_region_invalidate_index_list(region); +} + +/** + Observe that: + + 1. All the indices are inclusive. + 2. All the indices have zero offset. + + Only a thin wrapper around the rd_region_select_from_box() function. +*/ + +static void rd_region_select_from_ijkbox__(rd_region_type *region, int i1, + int i2, int j1, int j2, int k1, + int k2, bool select) { + rd::rd_box tmp_box(region->parent_grid, i1, i2, j1, j2, k1, k2); + rd_region_select_from_box__(region, tmp_box, select); +} + +void rd_region_select_from_ijkbox(rd_region_type *region, int i1, int i2, + int j1, int j2, int k1, int k2) { + rd_region_select_from_ijkbox__(region, i1, i2, j1, j2, k1, k2, true); +} + +void rd_region_deselect_from_ijkbox(rd_region_type *region, int i1, int i2, + int j1, int j2, int k1, int k2) { + rd_region_select_from_ijkbox__(region, i1, i2, j1, j2, k1, k2, false); +} + +/** + Observe that i1 and i2 are: + + * ZERO offset. + * An inclusive interval : [i1,i2] + + Input values below zero or above the upper limit are truncated. +*/ + +static void rd_region_select_i1i2__(rd_region_type *region, int i1, int i2, + bool select) { + if (i1 > i2) + util_abort("%s: i1 > i2 - this is illogical ... \n", __func__); + i1 = util_int_max(0, i1); + i2 = util_int_min(region->grid_nx - 1, i2); + { + int i, j, k; + for (k = 0; k < region->grid_nz; k++) + for (j = 0; j < region->grid_ny; j++) + for (i = i1; i <= i2; i++) { + int global_index = + rd_grid_get_global_index3(region->parent_grid, i, j, k); + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_i1i2(rd_region_type *region, int i1, int i2) { + rd_region_select_i1i2__(region, i1, i2, true); +} + +void rd_region_deselect_i1i2(rd_region_type *region, int i1, int i2) { + rd_region_select_i1i2__(region, i1, i2, false); +} + +/** + Observe that j1 and j2 are: + + * ZERO offset. + * An inclusive interval : [i1,i2] + + Input values below zero or above the upper limit are truncated. +*/ + +static void rd_region_select_j1j2__(rd_region_type *region, int j1, int j2, + bool select) { + if (j1 > j2) + util_abort("%s: i1 > i2 - this is illogical ... \n", __func__); + + j1 = util_int_max(0, j1); + j2 = util_int_min(region->grid_ny - 1, j2); + { + int i, j, k; + for (k = 0; k < region->grid_nz; k++) + for (j = j1; j <= j2; j++) + for (i = 0; i < region->grid_nx; i++) { + int global_index = + rd_grid_get_global_index3(region->parent_grid, i, j, k); + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_j1j2(rd_region_type *region, int j1, int j2) { + rd_region_select_j1j2__(region, j1, j2, true); +} + +void rd_region_deselect_j1j2(rd_region_type *region, int j1, int j2) { + rd_region_select_j1j2__(region, j1, j2, false); +} + +/** + Observe that k1 and k2 are: + + * ZERO offset. + * An inclusive interval : [i1,i2] + + Input values below zero or above the upper limit are truncated. +*/ + +static void rd_region_select_k1k2__(rd_region_type *region, int k1, int k2, + bool select) { + if (k1 > k2) + util_abort("%s: i1 > i2 - this is illogical ... \n", __func__); + k1 = util_int_max(0, k1); + k2 = util_int_min(region->grid_nz - 1, k2); + { + int i, j, k; + for (k = k1; k <= k2; k++) + for (j = 0; j < region->grid_ny; j++) + for (i = 0; i < region->grid_nx; i++) { + int global_index = + rd_grid_get_global_index3(region->parent_grid, i, j, k); + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_k1k2(rd_region_type *region, int k1, int k2) { + rd_region_select_k1k2__(region, k1, k2, true); +} + +void rd_region_deselect_k1k2(rd_region_type *region, int k1, int k2) { + rd_region_select_k1k2__(region, k1, k2, false); +} + +/** + This function will select all the cells with depth below the input + parameter @depth (if @select_below == true). The depth of a cell is + determined by the depth of the center of a cell. +*/ + +static void rd_region_select_from_depth__(rd_region_type *region, + double depth_limit, bool select_deep, + bool select) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) { + double cell_depth = + rd_grid_get_cdepth1(region->parent_grid, global_index); + if (select_deep) { + // The select/deselect mechanism should be applied to deep cells. + if (cell_depth >= depth_limit) + region->active_mask[global_index] = select; + } else { + // The select/deselect mechanism should be applied to shallow cells. + if (cell_depth <= depth_limit) + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_shallow_cells(rd_region_type *region, + double depth_limit) { + rd_region_select_from_depth__(region, depth_limit, false, true); +} + +void rd_region_deselect_shallow_cells(rd_region_type *region, + double depth_limit) { + rd_region_select_from_depth__(region, depth_limit, false, false); +} + +void rd_region_select_deep_cells(rd_region_type *region, double depth_limit) { + rd_region_select_from_depth__(region, depth_limit, true, true); +} + +void rd_region_deselect_deep_cells(rd_region_type *region, double depth_limit) { + rd_region_select_from_depth__(region, depth_limit, true, false); +} + +static void rd_region_select_from_volume__(rd_region_type *region, + double volum_limit, + bool select_small, bool select) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) { + double cell_size = + rd_grid_get_cell_volume1(region->parent_grid, global_index); + if (select_small) { + // The select/deselect mechanism should be applied to small cells. + if (cell_size <= volum_limit) + region->active_mask[global_index] = select; + } else { + // The select/deselect mechanism should be applied to large cells. + if (cell_size >= volum_limit) + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_small_cells(rd_region_type *rd_region, + double volum_limit) { + rd_region_select_from_volume__(rd_region, volum_limit, true, true); +} + +void rd_region_deselect_small_cells(rd_region_type *rd_region, + double volum_limit) { + rd_region_select_from_volume__(rd_region, volum_limit, true, false); +} + +void rd_region_select_large_cells(rd_region_type *rd_region, + double volum_limit) { + rd_region_select_from_volume__(rd_region, volum_limit, false, true); +} + +void rd_region_deselect_large_cells(rd_region_type *rd_region, + double volum_limit) { + rd_region_select_from_volume__(rd_region, volum_limit, false, false); +} + +static void rd_region_select_from_dz__(rd_region_type *region, double dz_limit, + bool select_thin, bool select) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) { + double cell_dz = + rd_grid_get_cell_thickness1(region->parent_grid, global_index); + if (select_thin) { + // The select/deselect mechanism should be applied to thin cells. + if (cell_dz <= dz_limit) + region->active_mask[global_index] = select; + } else { + // The select/deselect mechanism should be applied to thick cells. + if (cell_dz >= dz_limit) + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_thin_cells(rd_region_type *rd_region, double dz_limit) { + rd_region_select_from_dz__(rd_region, dz_limit, true, true); +} + +void rd_region_deselect_thin_cells(rd_region_type *rd_region, double dz_limit) { + rd_region_select_from_dz__(rd_region, dz_limit, true, false); +} + +void rd_region_select_thick_cells(rd_region_type *rd_region, double dz_limit) { + rd_region_select_from_dz__(rd_region, dz_limit, false, true); +} + +void rd_region_deselect_thick_cells(rd_region_type *rd_region, + double dz_limit) { + rd_region_select_from_dz__(rd_region, dz_limit, false, false); +} + +static void rd_region_select_active_cells__(rd_region_type *rd_region, + bool select_active, bool select) { + int global_index; + for (global_index = 0; global_index < rd_region->grid_vol; global_index++) { + if (select_active) { + if (rd_grid_get_active_index1(rd_region->parent_grid, + global_index) >= 0) + rd_region->active_mask[global_index] = select; + } else { + if (rd_grid_get_active_index1(rd_region->parent_grid, + global_index) < 0) + rd_region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(rd_region); +} + +void rd_region_select_active_cells(rd_region_type *region) { + rd_region_select_active_cells__(region, true, true); +} + +void rd_region_deselect_active_cells(rd_region_type *region) { + rd_region_select_active_cells__(region, true, false); +} + +void rd_region_select_inactive_cells(rd_region_type *region) { + rd_region_select_active_cells__(region, false, true); +} + +void rd_region_deselect_inactive_cells(rd_region_type *region) { + rd_region_select_active_cells__(region, false, false); +} + +/** + This function will select a cell based on global_index. +*/ + +static void rd_region_select_global_index__(rd_region_type *region, + int global_index, bool select) { + if ((global_index >= 0) && (global_index < region->grid_vol)) + region->active_mask[global_index] = select; + else + util_abort("%s: global_index:%d invalid - legal interval: [0,%d) \n", + __func__, global_index, region->grid_vol); + rd_region_invalidate_index_list(region); +} + +void rd_region_select_global_index(rd_region_type *region, int global_index) { + rd_region_select_global_index__(region, global_index, true); +} + +void rd_region_deselect_global_index(rd_region_type *region, int global_index) { + rd_region_select_global_index__(region, global_index, false); +} + +/** + Here comes functions for selecting all the cells which are in the + vertical cylinder located at (x0,y0) with radius R. The functions + with name 'zcylinder' operate on a finite cylinder in the z + direction, specified with the additional arguments z1 and z2; the + functions without z1 and z2 arguments operate on an infinite + cylinder piercing the complete reservoir. + + Currently all user-exported functions call the + rd_region_clyinder_select__() with select_inside == true. +*/ + +static void rd_region_cylinder_select__(rd_region_type *region, double x0, + double y0, double R, double z1, + double z2, bool select_inside, + bool select) { + double R2 = R * R; + + if (z1 < z2) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + double x, y, z; + rd_grid_get_xyz1(region->parent_grid, global_index, &x, &y, &z); + if ((z >= z1) && (z <= z2)) { + double pointR2 = (x - x0) * (x - x0) + (y - y0) * (y - y0); + if ((pointR2 < R2) && (select_inside)) + region->active_mask[global_index] = select; + else if ((pointR2 > R2) && (!select_inside)) + region->active_mask[global_index] = select; + } + } + } else { + const int nx = region->grid_nx; + const int ny = region->grid_ny; + const int nz = region->grid_nz; + int i, j; + for (i = 0; i < nx; i++) { + for (j = 0; j < ny; j++) { + double x, y, z; + rd_grid_get_xyz3(region->parent_grid, i, j, 0, &x, &y, &z); + { + double pointR2 = (x - x0) * (x - x0) + (y - y0) * (y - y0); + bool select_column = false; + + if ((pointR2 < R2) && (select_inside)) + select_column = true; + else if ((pointR2 > R2) && (!select_inside)) + select_column = true; + + if (select_column) { + int k; + for (k = 0; k < nz; k++) { + int global_index = rd_grid_get_global_index3( + region->parent_grid, i, j, k); + region->active_mask[global_index] = select; + } + } + } + } + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_in_cylinder(rd_region_type *region, double x0, double y0, + double R) { + rd_region_cylinder_select__(region, x0, y0, R, 1, 0, true, true); +} + +void rd_region_deselect_in_cylinder(rd_region_type *region, double x0, + double y0, double R) { + rd_region_cylinder_select__(region, x0, y0, R, 1, 0, true, false); +} + +void rd_region_select_in_zcylinder(rd_region_type *region, double x0, double y0, + double R, double z1, double z2) { + rd_region_cylinder_select__(region, x0, y0, R, util_double_min(z1, z2), + util_double_max(z1, z2), true, true); +} + +void rd_region_deselect_in_zcylinder(rd_region_type *region, double x0, + double y0, double R, double z1, + double z2) { + rd_region_cylinder_select__(region, x0, y0, R, util_double_min(z1, z2), + util_double_max(z1, z2), true, false); +} + +/** + Select or deselect points based on their distance to the plane + specified by normal vector @n and point @p. +*/ + +static void rd_region_plane_select__(rd_region_type *region, const double n[3], + const double p[3], bool select_above, + bool select) { + const double a = n[0]; + const double b = n[1]; + const double c = -n[2]; + const double d = -a * p[0] - b * p[1] - c * p[2]; + /** + Plane: ax + by + cz + d = 0 + */ + { + int global_index; + for (global_index = 0; global_index < region->grid_vol; + global_index++) { + double x, y, z; + double D; + rd_grid_get_xyz1(region->parent_grid, global_index, &x, &y, &z); + D = a * x + b * y + c * z + d; + if ((D >= 0) && (select_above)) + region->active_mask[global_index] = select; + else if ((D < 0) && (!select_above)) + region->active_mask[global_index] = select; + } + } + rd_region_invalidate_index_list(region); +} + +void rd_region_select_above_plane(rd_region_type *region, const double n[3], + const double p[3]) { + rd_region_plane_select__(region, n, p, true, true); +} + +void rd_region_select_below_plane(rd_region_type *region, const double n[3], + const double p[3]) { + rd_region_plane_select__(region, n, p, false, true); +} + +void rd_region_deselect_above_plane(rd_region_type *region, const double n[3], + const double p[3]) { + rd_region_plane_select__(region, n, p, true, false); +} + +void rd_region_deselect_below_plane(rd_region_type *region, const double n[3], + const double p[3]) { + rd_region_plane_select__(region, n, p, false, false); +} + +/** + When it comes to depth the polygon select function works as + follows: + + 1. The defining polygon is layed out at the top of the reservoir. + + 2. The set {(i,j,0)} of cells in the top layer inside the polygon + is selected by checking the polygon perimeter. + + 3. The set {(i,j,0)} is extended to all k vertically. This implies that: + + * If the pillars of the grid are not vertical the selection + polygon will effectively qbe translated as a function of + depth. + + * If the pillars are not parallell the selection polygon will + effectively change in size. +*/ + +static void rd_region_polygon_select__(rd_region_type *region, + const geo_polygon_type *polygon, + bool select_inside, bool select) { + + const int define_k = 0; // The k-level where the polygon is checked. + const int k1 = 0; // Selection range in k + const int k2 = region->grid_nz; + + { + int i, j; + for (i = 0; i < region->grid_nx; i++) { + for (j = 0; j < region->grid_ny; j++) { + double x, y, z; + bool inside; + int global_index = rd_grid_get_global_index3( + region->parent_grid, i, j, define_k); + + rd_grid_get_xyz1(region->parent_grid, global_index, &x, &y, &z); + inside = geo_polygon_contains_point(polygon, x, y); + + if (select_inside == inside) { + int k; + for (k = k1; k < k2; k++) { + global_index = rd_grid_get_global_index3( + region->parent_grid, i, j, k); + region->active_mask[global_index] = select; + } + } + } + } + } +} + +void rd_region_select_inside_polygon(rd_region_type *region, + const geo_polygon_type *polygon) { + rd_region_polygon_select__(region, polygon, true, true); +} + +void rd_region_deselect_inside_polygon(rd_region_type *region, + const geo_polygon_type *polygon) { + rd_region_polygon_select__(region, polygon, true, false); +} + +void rd_region_select_outside_polygon(rd_region_type *region, + const geo_polygon_type *polygon) { + rd_region_polygon_select__(region, polygon, false, true); +} + +void rd_region_deselect_outside_polygon(rd_region_type *region, + const geo_polygon_type *polygon) { + rd_region_polygon_select__(region, polygon, false, false); +} + +/** + This function will select a cell based on active_index. +*/ + +static void rd_region_select_active_index__(rd_region_type *region, + int active_index, bool select) { + if ((active_index >= 0) && (active_index < region->grid_active)) { + int global_index = + rd_grid_get_global_index1A(region->parent_grid, active_index); + region->active_mask[global_index] = select; + } else + util_abort("%s: active_index:%d invalid - legal interval: [0,%d) \n", + __func__, active_index, region->grid_vol); + rd_region_invalidate_index_list(region); +} + +void rd_region_select_active_index(rd_region_type *region, int active_index) { + rd_region_select_active_index__(region, active_index, true); +} + +void rd_region_deselect_active_index(rd_region_type *region, int active_index) { + rd_region_select_active_index__(region, active_index, false); +} + +static void rd_region_select_from_layer__(rd_region_type *region, + const layer_type *layer, int k, + int layer_value, bool select) { + int_vector_type *i_list = int_vector_alloc(0, 0); + int_vector_type *j_list = int_vector_alloc(0, 0); + + layer_cells_equal(layer, layer_value, i_list, j_list); + { + const int *i = int_vector_get_ptr(i_list); + const int *j = int_vector_get_ptr(j_list); + + int index; + for (index = 0; index < int_vector_size(i_list); index++) { + int global_index = rd_grid_get_global_index3(region->parent_grid, + i[index], j[index], k); + region->active_mask[global_index] = select; + } + } + if (int_vector_size(i_list) > 0) + rd_region_invalidate_index_list(region); + + int_vector_free(i_list); + int_vector_free(j_list); +} + +void rd_region_select_from_layer(rd_region_type *region, + const layer_type *layer, int k, + int layer_value) { + rd_region_select_from_layer__(region, layer, k, layer_value, true); +} + +void rd_region_deselect_from_layer(rd_region_type *region, + const layer_type *layer, int k, + int layer_value) { + rd_region_select_from_layer__(region, layer, k, layer_value, false); +} + +static void rd_region_select_all__(rd_region_type *region, bool select) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) + region->active_mask[global_index] = select; + rd_region_invalidate_index_list(region); +} + +void rd_region_select_all(rd_region_type *region) { + rd_region_select_all__(region, true); +} + +void rd_region_deselect_all(rd_region_type *region) { + rd_region_select_all__(region, false); +} + +void rd_region_invert_selection(rd_region_type *region) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) + region->active_mask[global_index] = !region->active_mask[global_index]; + rd_region_invalidate_index_list(region); +} + +/** + + Returns true if the region has selected grid cell ijk. + + ijk have zero offset. +*/ + +bool rd_region_contains_ijk(const rd_region_type *rd_region, int i, int j, + int k) { + int global_index = + rd_grid_get_global_index3(rd_region->parent_grid, i, j, k); + return rd_region->active_mask[global_index]; +} + +bool rd_region_contains_global(const rd_region_type *rd_region, + int global_index) { + return rd_region->active_mask[global_index]; +} + +bool rd_region_contains_active(const rd_region_type *rd_region, + int active_index) { + int global_index = + rd_grid_get_global_index1A(rd_region->parent_grid, active_index); + return rd_region->active_mask[global_index]; +} + +/** + Will update the selection in @region to ONLY contain the elements + which are also present in @new_region. Will FAIL hard if the two + regions do not share the same grid instance (checked by pointer + equality). + + A &= B +*/ + +void rd_region_intersection(rd_region_type *region, + const rd_region_type *new_region) { + if (region->parent_grid == new_region->parent_grid) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) + region->active_mask[global_index] = + (region->active_mask[global_index] && + new_region->active_mask[global_index]); + + rd_region_invalidate_index_list(region); + } else + util_abort("%s: The two regions do not share grid - aborting \n", + __func__); +} + +/** + Will update the selection in @region to contain all the elements + which are selected in either @region or @new_region. + + A |= B +*/ +void rd_region_union(rd_region_type *region, const rd_region_type *new_region) { + if (region->parent_grid == new_region->parent_grid) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) + region->active_mask[global_index] = + (region->active_mask[global_index] || + new_region->active_mask[global_index]); + + rd_region_invalidate_index_list(region); + } else + util_abort("%s: The two regions do not share grid - aborting \n", + __func__); +} + +/** + Will update the selection in @region to deselect the elements which + are also in new_region: + + A &= !B +*/ +void rd_region_subtract(rd_region_type *region, + const rd_region_type *new_region) { + if (region->parent_grid == new_region->parent_grid) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) + region->active_mask[global_index] &= + !new_region->active_mask[global_index]; + + rd_region_invalidate_index_list(region); + } else + util_abort("%s: The two regions do not share grid - aborting \n", + __func__); +} + +/** + Will update the selection in @region to seselect the elements which + are either in region or new_region: + + A ^= B +*/ +void rd_region_xor(rd_region_type *region, const rd_region_type *new_region) { + if (region->parent_grid == new_region->parent_grid) { + int global_index; + for (global_index = 0; global_index < region->grid_vol; global_index++) + region->active_mask[global_index] ^= + !new_region->active_mask[global_index]; + + rd_region_invalidate_index_list(region); + } else + util_abort("%s: The two regions do not share grid - aborting \n", + __func__); +} + +const int_vector_type *rd_region_get_kw_index_list(rd_region_type *rd_region, + const rd_kw_type *rd_kw, + bool force_active) { + const int_vector_type *index_set = NULL; + int kw_size = rd_kw_get_size(rd_kw); + int grid_active = rd_grid_get_active_size(rd_region->parent_grid); + int grid_global = rd_grid_get_global_size(rd_region->parent_grid); + + if (kw_size == grid_active) + index_set = rd_region_get_active_list(rd_region); + else if (kw_size == grid_global) { + if (force_active) + index_set = rd_region_get_global_active_list(rd_region); + else + index_set = rd_region_get_global_list(rd_region); + } else + util_abort( + "%s: size mismatch: grid_active:%d grid_global:%d kw_size:%d \n", + __func__, grid_active, grid_global, kw_size); + + return index_set; +} + +void rd_region_set_kw_int(rd_region_type *rd_region, rd_kw_type *rd_kw, + int value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_set_indexed_int(rd_kw, index_set, value); +} + +void rd_region_set_kw_float(rd_region_type *rd_region, rd_kw_type *rd_kw, + float value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_set_indexed_float(rd_kw, index_set, value); +} + +void rd_region_set_kw_double(rd_region_type *rd_region, rd_kw_type *rd_kw, + double value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_set_indexed_double(rd_kw, index_set, value); +} + +void rd_region_shift_kw_int(rd_region_type *rd_region, rd_kw_type *rd_kw, + int value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_shift_indexed_int(rd_kw, index_set, value); +} + +void rd_region_shift_kw_float(rd_region_type *rd_region, rd_kw_type *rd_kw, + float value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_shift_indexed_float(rd_kw, index_set, value); +} + +void rd_region_shift_kw_double(rd_region_type *rd_region, rd_kw_type *rd_kw, + double value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_shift_indexed_double(rd_kw, index_set, value); +} + +void rd_region_scale_kw_int(rd_region_type *rd_region, rd_kw_type *rd_kw, + int value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_scale_indexed_int(rd_kw, index_set, value); +} + +void rd_region_scale_kw_float(rd_region_type *rd_region, rd_kw_type *rd_kw, + float value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_scale_indexed_float(rd_kw, index_set, value); +} + +void rd_region_scale_kw_double(rd_region_type *rd_region, rd_kw_type *rd_kw, + double value, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_scale_indexed_double(rd_kw, index_set, value); +} + +void rd_region_kw_iadd(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *delta_kw, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_inplace_add_indexed(rd_kw, index_set, delta_kw); +} + +void rd_region_kw_idiv(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *div_kw, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_inplace_div_indexed(rd_kw, index_set, div_kw); +} + +void rd_region_kw_imul(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *mul_kw, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_inplace_mul_indexed(rd_kw, index_set, mul_kw); +} + +void rd_region_kw_isub(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *delta_kw, bool force_active) { + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_inplace_sub_indexed(rd_kw, index_set, delta_kw); +} + +void rd_region_kw_copy(rd_region_type *rd_region, rd_kw_type *rd_kw, + const rd_kw_type *src_kw, bool force_active) { + const int_vector_type *target_index = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_copy_indexed(rd_kw, target_index, src_kw); +} + +void rd_region_set_name(rd_region_type *region, const char *name) { + region->name = util_realloc_string_copy(region->name, name); +} + +const char *rd_region_get_name(const rd_region_type *region) { + return region->name; +} + +bool rd_region_equal(const rd_region_type *region1, + const rd_region_type *region2) { + if (region1->parent_grid == + region2 + ->parent_grid) { // Must be exactly the same grid instance to compare as equal. + if (memcmp(region1->active_mask, region2->active_mask, + region1->grid_vol * sizeof *region1->active_mask) == 0) + return true; + else + return false; + } else + return false; +} + +int rd_region_sum_kw_int(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active) { + int sum; + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_element_sum_indexed(rd_kw, index_set, &sum); + return sum; +} + +float rd_region_sum_kw_float(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active) { + float sum; + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_element_sum_indexed(rd_kw, index_set, &sum); + return sum; +} + +double rd_region_sum_kw_double(rd_region_type *rd_region, + const rd_kw_type *rd_kw, bool force_active) { + double sum; + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_element_sum_indexed(rd_kw, index_set, &sum); + return sum; +} + +int rd_region_sum_kw_bool(rd_region_type *rd_region, const rd_kw_type *rd_kw, + bool force_active) { + int sum; + const int_vector_type *index_set = + rd_region_get_kw_index_list(rd_region, rd_kw, force_active); + rd_kw_element_sum_indexed(rd_kw, index_set, &sum); + return sum; +} diff --git a/lib/ecl/ecl_rft_cell.cpp b/lib/resdata/rd_rft_cell.cpp similarity index 55% rename from lib/ecl/ecl_rft_cell.cpp rename to lib/resdata/rd_rft_cell.cpp index 4820f5de7d..b1a8099ddb 100644 --- a/lib/ecl/ecl_rft_cell.cpp +++ b/lib/resdata/rd_rft_cell.cpp @@ -8,16 +8,16 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#define ECL_RFT_CELL_TYPE_ID 99164012 +#define RD_RFT_CELL_TYPE_ID 99164012 #define RFT_DATA_TYPE_ID 66787166 #define PLT_DATA_TYPE_ID 87166667 -struct ecl_rft_cell_struct { +struct rd_rft_cell_struct { UTIL_TYPE_ID_DECLARATION; int i, j, k; double pressure; @@ -95,15 +95,17 @@ static UTIL_TRY_CAST_FUNCTION_CONST( PLT_DATA_TYPE_ID) static UTIL_SAFE_CAST_FUNCTION( - ecl_rft_cell, - ECL_RFT_CELL_TYPE_ID) static UTIL_SAFE_CAST_FUNCTION_CONST(ecl_rft_cell, - ECL_RFT_CELL_TYPE_ID) - UTIL_IS_INSTANCE_FUNCTION(ecl_rft_cell, ECL_RFT_CELL_TYPE_ID) - - static ecl_rft_cell_type *ecl_rft_cell_alloc_common( - int i, int j, int k, double depth, double pressure) { - ecl_rft_cell_type *cell = (ecl_rft_cell_type *)util_malloc(sizeof *cell); - UTIL_TYPE_ID_INIT(cell, ECL_RFT_CELL_TYPE_ID); + rd_rft_cell, + RD_RFT_CELL_TYPE_ID) static UTIL_SAFE_CAST_FUNCTION_CONST(rd_rft_cell, + RD_RFT_CELL_TYPE_ID) + UTIL_IS_INSTANCE_FUNCTION(rd_rft_cell, RD_RFT_CELL_TYPE_ID) + + static rd_rft_cell_type *rd_rft_cell_alloc_common(int i, int j, + int k, + double depth, + double pressure) { + rd_rft_cell_type *cell = (rd_rft_cell_type *)util_malloc(sizeof *cell); + UTIL_TYPE_ID_INIT(cell, RD_RFT_CELL_TYPE_ID); cell->i = i; cell->j = j; @@ -114,25 +116,23 @@ static UTIL_TRY_CAST_FUNCTION_CONST( return cell; } -ecl_rft_cell_type *ecl_rft_cell_alloc_RFT(int i, int j, int k, double depth, - double pressure, double swat, - double sgas) { - ecl_rft_cell_type *cell = - ecl_rft_cell_alloc_common(i, j, k, depth, pressure); +rd_rft_cell_type *rd_rft_cell_alloc_RFT(int i, int j, int k, double depth, + double pressure, double swat, + double sgas) { + rd_rft_cell_type *cell = rd_rft_cell_alloc_common(i, j, k, depth, pressure); cell->data = rft_data_alloc(swat, sgas); return cell; } -ecl_rft_cell_type * -ecl_rft_cell_alloc_PLT(int i, int j, int k, double depth, double pressure, - double orat, double grat, double wrat, - double connection_start, double connection_end, - double flowrate, double oil_flowrate, - double gas_flowrate, double water_flowrate) { +rd_rft_cell_type * +rd_rft_cell_alloc_PLT(int i, int j, int k, double depth, double pressure, + double orat, double grat, double wrat, + double connection_start, double connection_end, + double flowrate, double oil_flowrate, double gas_flowrate, + double water_flowrate) { - ecl_rft_cell_type *cell = - ecl_rft_cell_alloc_common(i, j, k, depth, pressure); + rd_rft_cell_type *cell = rd_rft_cell_alloc_common(i, j, k, depth, pressure); cell->data = plt_data_alloc(orat, grat, wrat, connection_start, connection_end, @@ -140,7 +140,7 @@ ecl_rft_cell_alloc_PLT(int i, int j, int k, double depth, double pressure, return cell; } -void ecl_rft_cell_free(ecl_rft_cell_type *cell) { +void rd_rft_cell_free(rd_rft_cell_type *cell) { if (rft_data_is_instance(cell->data)) rft_data_free((rft_data_type *)cell->data); else if (plt_data_is_instance(cell->data)) @@ -149,140 +149,138 @@ void ecl_rft_cell_free(ecl_rft_cell_type *cell) { free(cell); } -void ecl_rft_cell_free__(void *arg) { - ecl_rft_cell_type *cell = ecl_rft_cell_safe_cast(arg); - ecl_rft_cell_free(cell); +void rd_rft_cell_free__(void *arg) { + rd_rft_cell_type *cell = rd_rft_cell_safe_cast(arg); + rd_rft_cell_free(cell); } -int ecl_rft_cell_get_i(const ecl_rft_cell_type *cell) { return cell->i; } +int rd_rft_cell_get_i(const rd_rft_cell_type *cell) { return cell->i; } -int ecl_rft_cell_get_j(const ecl_rft_cell_type *cell) { return cell->j; } +int rd_rft_cell_get_j(const rd_rft_cell_type *cell) { return cell->j; } -int ecl_rft_cell_get_k(const ecl_rft_cell_type *cell) { return cell->k; } +int rd_rft_cell_get_k(const rd_rft_cell_type *cell) { return cell->k; } -void ecl_rft_cell_get_ijk(const ecl_rft_cell_type *cell, int *i, int *j, - int *k) { +void rd_rft_cell_get_ijk(const rd_rft_cell_type *cell, int *i, int *j, int *k) { *i = cell->i; *j = cell->j; *k = cell->k; } -double ecl_rft_cell_get_depth(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_depth(const rd_rft_cell_type *cell) { return cell->depth; } -double ecl_rft_cell_get_pressure(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_pressure(const rd_rft_cell_type *cell) { return cell->pressure; } -double ecl_rft_cell_get_swat(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_swat(const rd_rft_cell_type *cell) { const rft_data_type *data = rft_data_try_cast_const(cell->data); if (data) return data->swat; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_sgas(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_sgas(const rd_rft_cell_type *cell) { const rft_data_type *data = rft_data_try_cast_const(cell->data); if (data) return data->sgas; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_soil(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_soil(const rd_rft_cell_type *cell) { const rft_data_type *data = rft_data_try_cast_const(cell->data); if (data) return 1 - (data->swat + data->sgas); else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_orat(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_orat(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->orat; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_grat(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_grat(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->grat; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_wrat(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_wrat(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->wrat; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_connection_start(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_connection_start(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->connection_start; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_connection_end(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_connection_end(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->connection_end; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_flowrate(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_flowrate(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->flowrate; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_oil_flowrate(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_oil_flowrate(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->oil_flowrate; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_gas_flowrate(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_gas_flowrate(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->gas_flowrate; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -double ecl_rft_cell_get_water_flowrate(const ecl_rft_cell_type *cell) { +double rd_rft_cell_get_water_flowrate(const rd_rft_cell_type *cell) { const plt_data_type *data = plt_data_try_cast_const(cell->data); if (data) return data->water_flowrate; else - return ECL_RFT_CELL_INVALID_VALUE; + return RD_RFT_CELL_INVALID_VALUE; } -bool ecl_rft_cell_ijk_equal(const ecl_rft_cell_type *cell, int i, int j, - int k) { +bool rd_rft_cell_ijk_equal(const rd_rft_cell_type *cell, int i, int j, int k) { return ((i == cell->i) && (j == cell->j) && (k == cell->k)); } /* Currently only comparison based on connection length along PLT is supported. */ -int ecl_rft_cell_cmp(const ecl_rft_cell_type *cell1, - const ecl_rft_cell_type *cell2) { - double val1 = ecl_rft_cell_get_connection_start(cell1); - double val2 = ecl_rft_cell_get_connection_start(cell2); +int rd_rft_cell_cmp(const rd_rft_cell_type *cell1, + const rd_rft_cell_type *cell2) { + double val1 = rd_rft_cell_get_connection_start(cell1); + double val2 = rd_rft_cell_get_connection_start(cell2); if (val1 < val2) return -1; @@ -292,13 +290,13 @@ int ecl_rft_cell_cmp(const ecl_rft_cell_type *cell1, return 1; } -int ecl_rft_cell_cmp__(const void *arg1, const void *arg2) { - const ecl_rft_cell_type *cell1 = ecl_rft_cell_safe_cast_const(arg1); - const ecl_rft_cell_type *cell2 = ecl_rft_cell_safe_cast_const(arg2); - return ecl_rft_cell_cmp(cell1, cell2); +int rd_rft_cell_cmp__(const void *arg1, const void *arg2) { + const rd_rft_cell_type *cell1 = rd_rft_cell_safe_cast_const(arg1); + const rd_rft_cell_type *cell2 = rd_rft_cell_safe_cast_const(arg2); + return rd_rft_cell_cmp(cell1, cell2); } -bool ecl_rft_cell_lt(const ecl_rft_cell_type *cell1, - const ecl_rft_cell_type *cell2) { - return (ecl_rft_cell_cmp(cell1, cell2) < 0); +bool rd_rft_cell_lt(const rd_rft_cell_type *cell1, + const rd_rft_cell_type *cell2) { + return (rd_rft_cell_cmp(cell1, cell2) < 0); } diff --git a/lib/ecl/ecl_rft_file.cpp b/lib/resdata/rd_rft_file.cpp similarity index 51% rename from lib/ecl/ecl_rft_file.cpp rename to lib/resdata/rd_rft_file.cpp index 6e51ef9b91..d69b5f2a63 100644 --- a/lib/ecl/ecl_rft_file.cpp +++ b/lib/resdata/rd_rft_file.cpp @@ -14,11 +14,11 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /** This data structure is for loading one eclipse RFT file. One RFT @@ -29,23 +29,23 @@ All of this is just lumped together in one long vector, both in the file, and in this implementation. The data for one specific RFT - (one well, one time) is internalized in the ecl_rft_node type. + (one well, one time) is internalized in the rd_rft_node type. */ -#define ECL_RFT_FILE_ID 6610632 +#define RD_RFT_FILE_ID 6610632 -struct ecl_rft_file_struct { +struct rd_rft_file_struct { UTIL_TYPE_ID_DECLARATION; std::string filename; - std::vector + std::vector data; /* This vector just contains all the rft nodes in one long vector. */ std::map> well_index; }; -static ecl_rft_file_type *ecl_rft_file_alloc_empty(const char *filename) { - ecl_rft_file_type *rft_vector = new ecl_rft_file_type(); +static rd_rft_file_type *rd_rft_file_alloc_empty(const char *filename) { + rd_rft_file_type *rft_vector = new rd_rft_file_type(); - UTIL_TYPE_ID_INIT(rft_vector, ECL_RFT_FILE_ID); + UTIL_TYPE_ID_INIT(rft_vector, RD_RFT_FILE_ID); rft_vector->filename = std::string(filename); return rft_vector; @@ -54,33 +54,33 @@ static ecl_rft_file_type *ecl_rft_file_alloc_empty(const char *filename) { /** Generating the two functions: - bool ecl_rft_file_is_instance( void * ); - ecl_rft_file_type * ecl_rft_file_safe_cast( void * ); + bool rd_rft_file_is_instance( void * ); + rd_rft_file_type * rd_rft_file_safe_cast( void * ); */ -UTIL_SAFE_CAST_FUNCTION(ecl_rft_file, ECL_RFT_FILE_ID); -UTIL_IS_INSTANCE_FUNCTION(ecl_rft_file, ECL_RFT_FILE_ID); +UTIL_SAFE_CAST_FUNCTION(rd_rft_file, RD_RFT_FILE_ID); +UTIL_IS_INSTANCE_FUNCTION(rd_rft_file, RD_RFT_FILE_ID); -static void ecl_rft_file_add_node(ecl_rft_file_type *rft_vector, - ecl_rft_node_type *rft_node) { +static void rd_rft_file_add_node(rd_rft_file_type *rft_vector, + rd_rft_node_type *rft_node) { rft_vector->data.push_back(rft_node); } -ecl_rft_file_type *ecl_rft_file_alloc(const char *filename) { - ecl_rft_file_type *rft_vector = ecl_rft_file_alloc_empty(filename); - ecl_file_type *ecl_file = ecl_file_open(filename, 0); +rd_rft_file_type *rd_rft_file_alloc(const char *filename) { + rd_rft_file_type *rft_vector = rd_rft_file_alloc_empty(filename); + rd_file_type *rd_file = rd_file_open(filename, 0); int global_index = 0; int block_nr = 0; while (true) { - ecl_file_view_type *rft_view = - ecl_file_alloc_global_blockview(ecl_file, TIME_KW, block_nr); + rd_file_view_type *rft_view = + rd_file_alloc_global_blockview(rd_file, TIME_KW, block_nr); if (rft_view) { - ecl_rft_node_type *rft_node = ecl_rft_node_alloc(rft_view); + rd_rft_node_type *rft_node = rd_rft_node_alloc(rft_view); if (rft_node) { - const char *well_name = ecl_rft_node_get_well_name(rft_node); - ecl_rft_file_add_node(rft_vector, rft_node); + const char *well_name = rd_rft_node_get_well_name(rft_node); + rd_rft_file_add_node(rft_vector, rft_node); auto &index_vector = rft_vector->well_index[well_name]; index_vector.push_back(global_index); @@ -90,38 +90,38 @@ ecl_rft_file_type *ecl_rft_file_alloc(const char *filename) { break; block_nr++; - ecl_file_view_free(rft_view); + rd_file_view_free(rft_view); } - ecl_file_close(ecl_file); + rd_file_close(rd_file); return rft_vector; } /** Will look for .RFT / .FRFT files very similar to the - ecl_grid_load_case(). Will return NULL if no RFT file can be found, + rd_grid_load_case(). Will return NULL if no RFT file can be found, and the name of RFT file if it is found. New storage is allocated for the new name. */ -char *ecl_rft_file_alloc_case_filename(const char *case_input) { - ecl_file_enum file_type; +char *rd_rft_file_alloc_case_filename(const char *case_input) { + rd_file_enum file_type; bool fmt_file; - file_type = ecl_util_get_file_type(case_input, &fmt_file, NULL); - if (file_type == ECL_RFT_FILE) + file_type = rd_get_file_type(case_input, &fmt_file, NULL); + if (file_type == RD_RFT_FILE) return util_alloc_string_copy(case_input); else { char *return_file = NULL; char *path; char *basename; util_alloc_file_components(case_input, &path, &basename, NULL); - if ((file_type == ECL_OTHER_FILE) || + if ((file_type == RD_OTHER_FILE) || (file_type == - ECL_DATA_FILE)) { /* Impossible to infer formatted/unformatted from the case_input */ - char *RFT_file = ecl_util_alloc_filename(path, basename, - ECL_RFT_FILE, false, -1); + RD_DATA_FILE)) { /* Impossible to infer formatted/unformatted from the case_input */ + char *RFT_file = + rd_alloc_filename(path, basename, RD_RFT_FILE, false, -1); char *FRFT_file = - ecl_util_alloc_filename(path, basename, ECL_RFT_FILE, true, -1); + rd_alloc_filename(path, basename, RD_RFT_FILE, true, -1); if (util_file_exists(RFT_file)) return_file = util_alloc_string_copy(RFT_file); @@ -131,8 +131,8 @@ char *ecl_rft_file_alloc_case_filename(const char *case_input) { free(RFT_file); free(FRFT_file); } else { - char *RFT_file = ecl_util_alloc_filename( - path, basename, ECL_RFT_FILE, fmt_file, -1); + char *RFT_file = + rd_alloc_filename(path, basename, RD_RFT_FILE, fmt_file, -1); if (util_file_exists(RFT_file)) return_file = util_alloc_string_copy(RFT_file); @@ -143,20 +143,20 @@ char *ecl_rft_file_alloc_case_filename(const char *case_input) { } } -ecl_rft_file_type *ecl_rft_file_alloc_case(const char *case_input) { - ecl_rft_file_type *ecl_rft_file = NULL; - char *file_name = ecl_rft_file_alloc_case_filename(case_input); +rd_rft_file_type *rd_rft_file_alloc_case(const char *case_input) { + rd_rft_file_type *rd_rft_file = NULL; + char *file_name = rd_rft_file_alloc_case_filename(case_input); if (file_name != NULL) { - ecl_rft_file = ecl_rft_file_alloc(file_name); + rd_rft_file = rd_rft_file_alloc(file_name); free(file_name); } - return ecl_rft_file; + return rd_rft_file; } -bool ecl_rft_file_case_has_rft(const char *case_input) { +bool rd_rft_file_case_has_rft(const char *case_input) { bool has_rft = false; - char *file_name = ecl_rft_file_alloc_case_filename(case_input); + char *file_name = rd_rft_file_alloc_case_filename(case_input); if (file_name != NULL) { has_rft = true; @@ -166,15 +166,15 @@ bool ecl_rft_file_case_has_rft(const char *case_input) { return has_rft; } -void ecl_rft_file_free(ecl_rft_file_type *rft_vector) { +void rd_rft_file_free(rd_rft_file_type *rft_vector) { for (auto node_ptr : rft_vector->data) - ecl_rft_node_free(node_ptr); + rd_rft_node_free(node_ptr); delete rft_vector; } -void ecl_rft_file_free__(void *arg) { - ecl_rft_file_free(ecl_rft_file_safe_cast(arg)); +void rd_rft_file_free__(void *arg) { + rd_rft_file_free(rd_rft_file_safe_cast(arg)); } /** @@ -182,7 +182,7 @@ void ecl_rft_file_free__(void *arg) { only wells matching @well be included. The @well variable can contain '*', so the function call - ecl_rft_file_get_size__( rft_file , "OP*" , -1) + rd_rft_file_get_size__( rft_file , "OP*" , -1) will count the number of rft instances with a well name matching well "OP*". @@ -191,24 +191,24 @@ void ecl_rft_file_free__(void *arg) { @recording_time are included. */ -int ecl_rft_file_get_size__(const ecl_rft_file_type *rft_file, - const char *well_pattern, time_t recording_time) { +int rd_rft_file_get_size__(const rd_rft_file_type *rft_file, + const char *well_pattern, time_t recording_time) { if ((well_pattern == NULL) && (recording_time < 0)) return rft_file->data.size(); else { int match_count = 0; for (size_t i = 0; i < rft_file->data.size(); i++) { - const ecl_rft_node_type *rft = rft_file->data[i]; + const rd_rft_node_type *rft = rft_file->data[i]; if (well_pattern) { if (util_fnmatch(well_pattern, - ecl_rft_node_get_well_name(rft)) != 0) + rd_rft_node_get_well_name(rft)) != 0) continue; } /*OK - we either do not care about the well, or alternatively the well matches. */ if (recording_time >= 0) { - if (recording_time != ecl_rft_node_get_date(rft)) + if (recording_time != rd_rft_node_get_date(rft)) continue; } match_count++; @@ -222,11 +222,11 @@ int ecl_rft_file_get_size__(const ecl_rft_file_type *rft_file, the same well occurse many times and so on. */ -int ecl_rft_file_get_size(const ecl_rft_file_type *rft_file) { - return ecl_rft_file_get_size__(rft_file, NULL, -1); +int rd_rft_file_get_size(const rd_rft_file_type *rft_file) { + return rd_rft_file_get_size__(rft_file, NULL, -1); } -const char *ecl_rft_file_get_filename(const ecl_rft_file_type *rft_file) { +const char *rd_rft_file_get_filename(const rd_rft_file_type *rft_file) { return rft_file->filename.c_str(); } @@ -235,17 +235,17 @@ const char *ecl_rft_file_get_filename(const ecl_rft_file_type *rft_file) { particular RFT is from, or which well it is. If you ask for an index which is beyond the size of the vector it will - go up in flames - use ecl_file_get_size() first if you can not + go up in flames - use rd_file_get_size() first if you can not handle that. */ -ecl_rft_node_type *ecl_rft_file_iget_node(const ecl_rft_file_type *rft_file, - int index) { +rd_rft_node_type *rd_rft_file_iget_node(const rd_rft_file_type *rft_file, + int index) { return rft_file->data[index]; } /** - This function will return ecl_rft_node nr index - for well + This function will return rd_rft_node nr index - for well 'well'. I.e. for an RFT file which looks like this: RFT - Well P1: 01/01/2000 @@ -257,26 +257,26 @@ ecl_rft_node_type *ecl_rft_file_iget_node(const ecl_rft_file_type *rft_file, The function call: - ecl_rft_iget_well_rft(rft_file , "P2" , 1) + rd_rft_iget_well_rft(rft_file , "P2" , 1) will return the rft node indicated by the arrow (i.e. the second occurence of well "P2" in the file.) If the rft_file does not have the well, or that occurence, the function will go down in flames with util_abort(). Use - ecl_rft_file_has_well() and ecl_rft_file_get_well_occurences() + rd_rft_file_has_well() and rd_rft_file_get_well_occurences() first if you can not take util_abort(). */ -ecl_rft_node_type *ecl_rft_file_iget_well_rft(const ecl_rft_file_type *rft_file, - const char *well, int index) { +rd_rft_node_type *rd_rft_file_iget_well_rft(const rd_rft_file_type *rft_file, + const char *well, int index) { const auto &index_vector = rft_file->well_index.at(well); - return ecl_rft_file_iget_node(rft_file, index_vector[index]); + return rd_rft_file_iget_node(rft_file, index_vector[index]); } -static int -ecl_rft_file_get_node_index_time_rft(const ecl_rft_file_type *rft_file, - const char *well, time_t recording_time) { +static int rd_rft_file_get_node_index_time_rft(const rd_rft_file_type *rft_file, + const char *well, + time_t recording_time) { const auto &pair_iter = rft_file->well_index.find(well); if (pair_iter == rft_file->well_index.end()) return -1; @@ -289,9 +289,9 @@ ecl_rft_file_get_node_index_time_rft(const ecl_rft_file_type *rft_file, break; { - const ecl_rft_node_type *node = - ecl_rft_file_iget_node(rft_file, index_vector[well_index]); - if (ecl_rft_node_get_date(node) == recording_time) { + const rd_rft_node_type *node = + rd_rft_file_iget_node(rft_file, index_vector[well_index]); + if (rd_rft_node_get_date(node) == recording_time) { global_index = index_vector[well_index]; break; } @@ -308,20 +308,19 @@ ecl_rft_file_get_node_index_time_rft(const ecl_rft_file_type *rft_file, time; the function will return NULL. */ -ecl_rft_node_type * -ecl_rft_file_get_well_time_rft(const ecl_rft_file_type *rft_file, - const char *well, time_t recording_time) { +rd_rft_node_type * +rd_rft_file_get_well_time_rft(const rd_rft_file_type *rft_file, + const char *well, time_t recording_time) { int index = - ecl_rft_file_get_node_index_time_rft(rft_file, well, recording_time); + rd_rft_file_get_node_index_time_rft(rft_file, well, recording_time); if (index != -1) { - return ecl_rft_file_iget_node(rft_file, index); + return rd_rft_file_iget_node(rft_file, index); } else { return NULL; } } -bool ecl_rft_file_has_well(const ecl_rft_file_type *rft_file, - const char *well) { +bool rd_rft_file_has_well(const rd_rft_file_type *rft_file, const char *well) { return (rft_file->well_index.find(well) != rft_file->well_index.end()); } @@ -329,8 +328,8 @@ bool ecl_rft_file_has_well(const ecl_rft_file_type *rft_file, Returns the number of occurences of 'well' in rft_file. */ -int ecl_rft_file_get_well_occurences(const ecl_rft_file_type *rft_file, - const char *well) { +int rd_rft_file_get_well_occurences(const rd_rft_file_type *rft_file, + const char *well) { const auto &pair_iter = rft_file->well_index.find(well); if (pair_iter == rft_file->well_index.end()) return 0; @@ -341,12 +340,11 @@ int ecl_rft_file_get_well_occurences(const ecl_rft_file_type *rft_file, /** Returns the number of distinct wells in RFT file. */ -int ecl_rft_file_get_num_wells(const ecl_rft_file_type *rft_file) { +int rd_rft_file_get_num_wells(const rd_rft_file_type *rft_file) { return rft_file->well_index.size(); } -stringlist_type * -ecl_rft_file_alloc_well_list(const ecl_rft_file_type *rft_file) { +stringlist_type *rd_rft_file_alloc_well_list(const rd_rft_file_type *rft_file) { stringlist_type *well_list = stringlist_alloc_new(); for (const auto &pair : rft_file->well_index) @@ -355,56 +353,55 @@ ecl_rft_file_alloc_well_list(const ecl_rft_file_type *rft_file) { return well_list; } -void ecl_rft_file_update(const char *rft_file_name, ecl_rft_node_type **nodes, - int num_nodes, ert_ecl_unit_enum unit_set) { - ecl_rft_file_type *rft_file; +void rd_rft_file_update(const char *rft_file_name, rd_rft_node_type **nodes, + int num_nodes, ert_rd_unit_enum unit_set) { + rd_rft_file_type *rft_file; if (util_file_exists(rft_file_name)) { int node_index; - rft_file = ecl_rft_file_alloc(rft_file_name); + rft_file = rd_rft_file_alloc(rft_file_name); for (node_index = 0; node_index < num_nodes; node_index++) { - ecl_rft_node_type *new_node = nodes[node_index]; - int storage_index = ecl_rft_file_get_node_index_time_rft( - rft_file, ecl_rft_node_get_well_name(new_node), - ecl_rft_node_get_date(new_node)); + rd_rft_node_type *new_node = nodes[node_index]; + int storage_index = rd_rft_file_get_node_index_time_rft( + rft_file, rd_rft_node_get_well_name(new_node), + rd_rft_node_get_date(new_node)); if (storage_index == -1) { - ecl_rft_file_add_node(rft_file, new_node); + rd_rft_file_add_node(rft_file, new_node); } else { - ecl_rft_node_free(rft_file->data[storage_index]); + rd_rft_node_free(rft_file->data[storage_index]); rft_file->data[storage_index] = new_node; } } } else { int node_index; - rft_file = ecl_rft_file_alloc_empty(rft_file_name); + rft_file = rd_rft_file_alloc_empty(rft_file_name); for (node_index = 0; node_index < num_nodes; node_index++) { - ecl_rft_file_add_node(rft_file, nodes[node_index]); + rd_rft_file_add_node(rft_file, nodes[node_index]); } } { bool fmt_file = false; fortio_type *fortio = - fortio_open_writer(rft_file_name, fmt_file, ECL_ENDIAN_FLIP); + fortio_open_writer(rft_file_name, fmt_file, RD_ENDIAN_FLIP); /** The sorting here works directly on the internal node storage rft_file->data; that might in principle ruin the indexing of - the ecl_file object - it is therefore absolutely essential - that this ecl_rft_file object does not live beyond this - function, and also that the ecl_rft_file api functions are + the rd_file object - it is therefore absolutely essential + that this rd_rft_file object does not live beyond this + function, and also that the rd_rft_file api functions are avoided for the rest of this function. */ - std::sort(rft_file->data.begin(), rft_file->data.end(), - ecl_rft_node_lt); + std::sort(rft_file->data.begin(), rft_file->data.end(), rd_rft_node_lt); for (size_t node_index = 0; node_index < rft_file->data.size(); node_index++) { - const ecl_rft_node_type *new_node = rft_file->data[node_index]; - ecl_rft_node_fwrite(new_node, fortio, unit_set); + const rd_rft_node_type *new_node = rft_file->data[node_index]; + rd_rft_node_fwrite(new_node, fortio, unit_set); } fortio_fclose(fortio); } - ecl_rft_file_free(rft_file); + rd_rft_file_free(rft_file); } diff --git a/lib/resdata/rd_rft_node.cpp b/lib/resdata/rd_rft_node.cpp new file mode 100644 index 0000000000..f2af6f966c --- /dev/null +++ b/lib/resdata/rd_rft_node.cpp @@ -0,0 +1,608 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +/** + The RFT's from several wells, and possibly also several timesteps + are lumped togeheter in one .RFT file. The rd_rft_node + implemented in this file contains the information for one + well/report step. +*/ + +/* + If the type is RFT, PLT or SEGMENT depends on the options used when + the .RFT file is created. RFT and PLT are quite similar, SEGMENT is + not really supported. +*/ + +#define RD_RFT_NODE_ID 887195 +struct rd_rft_node_struct { + UTIL_TYPE_ID_DECLARATION; + std::string well_name; + + rd_rft_enum data_type; /* What type of data: RFT|PLT|SEGMENT */ + time_t recording_date; /* When was the RFT recorded - date.*/ + double days; /* When was the RFT recorded - days after simulaton start. */ + bool MSW; + + std::vector cells; +}; + +/* + The implementation of cell types based on _either_ RFT data or PLT + data is based on a misunderstanding and is currently WRONG. One + section in an RFT file can contain RFT data, PLT data and SEGMENT + data. The @data_type string should therefore not be interpreted as a + type string, but rather as a "bit mask": + + + "R" => Section contains only RFT data. + "P" => Section contains only PLT data. + "RP" => Section contains *BOTH* RFT data and PLT data. +*/ + +/** + Will return NULL if the data_type_string is equal to "SEGMENT" - + that is not (yet) supported. +*/ +static rd_rft_enum +translate_from_sting_to_rd_rft_enum(const char *data_type_string) { + rd_rft_enum data_type = SEGMENT; + /* According to the ECLIPSE documentaton. */ + if (strchr(data_type_string, 'P') != NULL) + data_type = PLT; + else if (strchr(data_type_string, 'R') != NULL) + data_type = RFT; + else if (strchr(data_type_string, 'S') != NULL) + data_type = SEGMENT; + else + util_abort( + "%s: Could not determine type of RFT/PLT/SEGMENT data - aborting\n", + __func__); + + return data_type; +} + +rd_rft_node_type *rd_rft_node_alloc_new(const char *well_name, + const char *data_type_string, + const time_t recording_date, + const double days) { + rd_rft_enum data_type = + translate_from_sting_to_rd_rft_enum(data_type_string); + rd_rft_node_type *rft_node = new rd_rft_node_type(); + + UTIL_TYPE_ID_INIT(rft_node, RD_RFT_NODE_ID); + rft_node->well_name = std::string(well_name); + rft_node->recording_date = recording_date; + rft_node->days = days; + rft_node->data_type = data_type; + + return rft_node; +} + +static rd_rft_node_type *rd_rft_node_alloc_empty(const char *data_type_string) { + rd_rft_enum data_type = + translate_from_sting_to_rd_rft_enum(data_type_string); + + /* Can return NULL */ + if (data_type == SEGMENT) { + fprintf( + stderr, + "%s: sorry SEGMENT PLT/RFT is not supported - file a complaint. \n", + __func__); + return NULL; + } + + { + rd_rft_node_type *rft_node = new rd_rft_node_type(); + + UTIL_TYPE_ID_INIT(rft_node, RD_RFT_NODE_ID); + rft_node->data_type = data_type; + + return rft_node; + } +} + +UTIL_SAFE_CAST_FUNCTION(rd_rft_node, RD_RFT_NODE_ID); +UTIL_IS_INSTANCE_FUNCTION(rd_rft_node, RD_RFT_NODE_ID); + +void rd_rft_node_append_cell(rd_rft_node_type *rft_node, + rd_rft_cell_type *cell) { + if (rft_node->MSW) { + auto pos_iter = + std::upper_bound(rft_node->cells.begin(), rft_node->cells.end(), + cell, rd_rft_cell_lt); + rft_node->cells.insert(pos_iter, cell); + } else + rft_node->cells.push_back(cell); +} + +static rd_kw_type *rd_rft_node_get_pressure_kw(rd_rft_node_type *rft_node, + const rd_file_view_type *rft) { + if (rft_node->data_type == RFT) + return rd_file_view_iget_named_kw(rft, PRESSURE_KW, 0); + else { + rd_kw_type *conpres_kw = rd_file_view_iget_named_kw(rft, CONPRES_KW, 0); + if (rd_kw_element_sum_float(conpres_kw) > 0.0) + return conpres_kw; + else if (rd_file_view_has_kw(rft, PRESSURE_KW)) + return rd_file_view_iget_named_kw(rft, PRESSURE_KW, 0); + else { + fprintf(stderr, + "WARNING: %s returned a CONPRES_KW with all values at " + "zero. PRESSURE_KW not found.\n", + __func__); + return conpres_kw; + } + } +} + +static void rd_rft_node_init_RFT_cells(rd_rft_node_type *rft_node, + const rd_file_view_type *rft_view) { + const rd_kw_type *conipos = + rd_file_view_iget_named_kw(rft_view, CONIPOS_KW, 0); + const rd_kw_type *conjpos = + rd_file_view_iget_named_kw(rft_view, CONJPOS_KW, 0); + const rd_kw_type *conkpos = + rd_file_view_iget_named_kw(rft_view, CONKPOS_KW, 0); + const rd_kw_type *depth_kw = + rd_file_view_iget_named_kw(rft_view, DEPTH_KW, 0); + const rd_kw_type *swat_kw = + rd_file_view_iget_named_kw(rft_view, SWAT_KW, 0); + const rd_kw_type *sgas_kw = + rd_file_view_iget_named_kw(rft_view, SGAS_KW, 0); + const rd_kw_type *pressure_kw = + rd_rft_node_get_pressure_kw(rft_node, rft_view); + + const float *SW = rd_kw_get_float_ptr(swat_kw); + const float *SG = rd_kw_get_float_ptr(sgas_kw); + const float *P = rd_kw_get_float_ptr(pressure_kw); + const float *depth = rd_kw_get_float_ptr(depth_kw); + const int *i = rd_kw_get_int_ptr(conipos); + const int *j = rd_kw_get_int_ptr(conjpos); + const int *k = rd_kw_get_int_ptr(conkpos); + + { + int c; + for (c = 0; c < rd_kw_get_size(conipos); c++) { + /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ + rd_rft_cell_type *cell = rd_rft_cell_alloc_RFT( + i[c] - 1, j[c] - 1, k[c] - 1, depth[c], P[c], SW[c], SG[c]); + rd_rft_node_append_cell(rft_node, cell); + } + } +} + +static void rd_rft_node_init_PLT_cells(rd_rft_node_type *rft_node, + const rd_file_view_type *rft_view) { + /* For PLT there is quite a lot of extra information which is not yet internalized. */ + const rd_kw_type *conipos = + rd_file_view_iget_named_kw(rft_view, CONIPOS_KW, 0); + const rd_kw_type *conjpos = + rd_file_view_iget_named_kw(rft_view, CONJPOS_KW, 0); + const rd_kw_type *conkpos = + rd_file_view_iget_named_kw(rft_view, CONKPOS_KW, 0); + + const int *i = rd_kw_get_int_ptr(conipos); + const int *j = rd_kw_get_int_ptr(conjpos); + const int *k = rd_kw_get_int_ptr(conkpos); + + const float *WR = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONWRAT_KW, 0)); + const float *GR = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONGRAT_KW, 0)); + const float *OR = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONORAT_KW, 0)); + const float *P = + rd_kw_get_float_ptr(rd_rft_node_get_pressure_kw(rft_node, rft_view)); + const float *depth = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONDEPTH_KW, 0)); + const float *flowrate = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONVTUB_KW, 0)); + const float *oil_flowrate = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONOTUB_KW, 0)); + const float *gas_flowrate = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONGTUB_KW, 0)); + const float *water_flowrate = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONWTUB_KW, 0)); + const float *connection_start = NULL; + const float *connection_end = NULL; + + /* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */ + if (rd_file_view_has_kw(rft_view, CONLENST_KW)) + connection_start = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONLENST_KW, 0)); + + if (rd_file_view_has_kw(rft_view, CONLENEN_KW)) + connection_end = rd_kw_get_float_ptr( + rd_file_view_iget_named_kw(rft_view, CONLENEN_KW, 0)); + + { + int c; + for (c = 0; c < rd_kw_get_size(conipos); c++) { + rd_rft_cell_type *cell; + double cs = 0; + double ce = 0; + + if (connection_start) + cs = connection_start[c]; + + if (connection_end) + ce = connection_end[c]; + + /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ + cell = rd_rft_cell_alloc_PLT(i[c] - 1, j[c] - 1, k[c] - 1, depth[c], + P[c], OR[c], GR[c], WR[c], cs, ce, + flowrate[c], oil_flowrate[c], + gas_flowrate[c], water_flowrate[c]); + rd_rft_node_append_cell(rft_node, cell); + } + } +} + +static void rd_rft_node_init_cells(rd_rft_node_type *rft_node, + const rd_file_view_type *rft_view) { + + if (rft_node->data_type == RFT) + rd_rft_node_init_RFT_cells(rft_node, rft_view); + else if (rft_node->data_type == PLT) + rd_rft_node_init_PLT_cells(rft_node, rft_view); +} + +rd_rft_node_type *rd_rft_node_alloc(const rd_file_view_type *rft_view) { + rd_kw_type *welletc = rd_file_view_iget_named_kw(rft_view, WELLETC_KW, 0); + rd_rft_node_type *rft_node = rd_rft_node_alloc_empty( + (const char *)rd_kw_iget_ptr(welletc, WELLETC_TYPE_INDEX)); + + if (rft_node != NULL) { + rd_kw_type *date_kw = rd_file_view_iget_named_kw(rft_view, DATE_KW, 0); + { + char *tmp = util_alloc_strip_copy( + (const char *)rd_kw_iget_ptr(welletc, WELLETC_NAME_INDEX)); + rft_node->well_name = std::string(tmp); + free(tmp); + } + /* Time information. */ + { + int *time = rd_kw_get_int_ptr(date_kw); + rft_node->recording_date = + rd_make_date(time[DATE_DAY_INDEX], time[DATE_MONTH_INDEX], + time[DATE_YEAR_INDEX]); + } + rft_node->days = rd_kw_iget_float( + rd_file_view_iget_named_kw(rft_view, TIME_KW, 0), 0); + if (rd_file_view_has_kw(rft_view, CONLENST_KW)) + rft_node->MSW = true; + else + rft_node->MSW = false; + + rd_rft_node_init_cells(rft_node, rft_view); + } + return rft_node; +} + +const char *rd_rft_node_get_well_name(const rd_rft_node_type *rft_node) { + return rft_node->well_name.c_str(); +} + +void rd_rft_node_free(rd_rft_node_type *rft_node) { + for (auto cell_ptr : rft_node->cells) + rd_rft_cell_free(cell_ptr); + + delete rft_node; +} + +void rd_rft_node_free__(void *void_node) { + rd_rft_node_free(rd_rft_node_safe_cast(void_node)); +} + +int rd_rft_node_get_size(const rd_rft_node_type *rft_node) { + return rft_node->cells.size(); +} +time_t rd_rft_node_get_date(const rd_rft_node_type *rft_node) { + return rft_node->recording_date; +} +rd_rft_enum rd_rft_node_get_type(const rd_rft_node_type *rft_node) { + return rft_node->data_type; +} + +const rd_rft_cell_type *rd_rft_node_iget_cell(const rd_rft_node_type *rft_node, + int index) { + return rft_node->cells[index]; +} + +const rd_rft_cell_type *rd_rft_node_iget_cell_sorted(rd_rft_node_type *rft_node, + int index) { + return rft_node->cells[index]; +} + +double rd_rft_node_iget_depth(const rd_rft_node_type *rft_node, int index) { + const rd_rft_cell_type *cell = rd_rft_node_iget_cell(rft_node, index); + return rd_rft_cell_get_depth(cell); +} + +double rd_rft_node_iget_pressure(const rd_rft_node_type *rft_node, int index) { + const rd_rft_cell_type *cell = rd_rft_node_iget_cell(rft_node, index); + return rd_rft_cell_get_pressure(cell); +} + +void rd_rft_node_iget_ijk(const rd_rft_node_type *rft_node, int index, int *i, + int *j, int *k) { + const rd_rft_cell_type *cell = rd_rft_node_iget_cell(rft_node, index); + + rd_rft_cell_get_ijk(cell, i, j, k); +} + +const rd_rft_cell_type *rd_rft_node_lookup_ijk(const rd_rft_node_type *rft_node, + int i, int j, int k) { + int index = 0; + int size = rd_rft_node_get_size(rft_node); + while (true) { + const rd_rft_cell_type *cell = rd_rft_node_iget_cell(rft_node, index); + + if (rd_rft_cell_ijk_equal(cell, i, j, k)) + return cell; + + index++; + if (index == size) /* Could not find it. */ + return NULL; + } +} + +static void assert_type_and_index(const rd_rft_node_type *rft_node, + rd_rft_enum target_type, int index) { + if (rft_node->data_type != target_type) + util_abort("%s: wrong type \n", __func__); + + if ((index < 0) || (index >= static_cast(rft_node->cells.size()))) + util_abort("%s: invalid index:%d \n", __func__, index); +} + +double rd_rft_node_iget_sgas(const rd_rft_node_type *rft_node, int index) { + assert_type_and_index(rft_node, RFT, index); + { + const rd_rft_cell_type *cell = rd_rft_node_iget_cell(rft_node, index); + return rd_rft_cell_get_sgas(cell); + } +} + +double rd_rft_node_iget_swat(const rd_rft_node_type *rft_node, int index) { + assert_type_and_index(rft_node, RFT, index); + { + const rd_rft_cell_type *cell = rft_node->cells[index]; + return rd_rft_cell_get_swat(cell); + } +} + +double rd_rft_node_get_days(const rd_rft_node_type *rft_node) { + return rft_node->days; +} + +double rd_rft_node_iget_soil(const rd_rft_node_type *rft_node, int index) { + assert_type_and_index(rft_node, RFT, index); + { + const rd_rft_cell_type *cell = rft_node->cells[index]; + return rd_rft_cell_get_soil(cell); + } +} + +double rd_rft_node_iget_orat(const rd_rft_node_type *rft_node, int index) { + assert_type_and_index(rft_node, PLT, index); + { + const rd_rft_cell_type *cell = rft_node->cells[index]; + return rd_rft_cell_get_orat(cell); + } +} + +double rd_rft_node_iget_wrat(const rd_rft_node_type *rft_node, int index) { + assert_type_and_index(rft_node, PLT, index); + { + const rd_rft_cell_type *cell = rft_node->cells[index]; + return rd_rft_cell_get_wrat(cell); + } +} + +double rd_rft_node_iget_grat(const rd_rft_node_type *rft_node, int index) { + assert_type_and_index(rft_node, PLT, index); + { + const rd_rft_cell_type *cell = rft_node->cells[index]; + return rd_rft_cell_get_grat(cell); + } +} + +bool rd_rft_node_is_MSW(const rd_rft_node_type *rft_node) { + return rft_node->MSW; +} + +bool rd_rft_node_is_PLT(const rd_rft_node_type *rft_node) { + if (rft_node->data_type == PLT) + return true; + else + return false; +} + +bool rd_rft_node_is_SEGMENT(const rd_rft_node_type *rft_node) { + if (rft_node->data_type == SEGMENT) + return true; + else + return false; +} + +bool rd_rft_node_is_RFT(const rd_rft_node_type *rft_node) { + if (rft_node->data_type == RFT) + return true; + else + return false; +} + +static void rd_rft_node_fill_welletc(rd_kw_type *welletc, + ert_rd_unit_enum unit_set) { + if (unit_set == RD_METRIC_UNITS) { + rd_kw_iset_string8(welletc, 0, " DAYS"); + rd_kw_iset_string8(welletc, 2, ""); + rd_kw_iset_string8(welletc, 3, " METRES"); + rd_kw_iset_string8(welletc, 4, " BARSA"); + rd_kw_iset_string8(welletc, 6, "STANDARD"); + rd_kw_iset_string8(welletc, 7, " SM3/DAY"); + rd_kw_iset_string8(welletc, 8, " SM3/DAY"); + rd_kw_iset_string8(welletc, 9, " RM3/DAY"); + rd_kw_iset_string8(welletc, 10, " M/SEC"); + rd_kw_iset_string8(welletc, 11, ""); + rd_kw_iset_string8(welletc, 12, " CP"); + rd_kw_iset_string8(welletc, 13, " KG/SM3"); + rd_kw_iset_string8(welletc, 14, " KG/DAY"); + rd_kw_iset_string8(welletc, 15, " KG/KG"); + } else if (unit_set == RD_FIELD_UNITS) { + rd_kw_iset_string8(welletc, 0, " DAYS"); + rd_kw_iset_string8(welletc, 2, ""); + rd_kw_iset_string8(welletc, 3, " FEET"); + rd_kw_iset_string8(welletc, 4, " PISA"); + rd_kw_iset_string8(welletc, 6, "STANDARD"); + rd_kw_iset_string8(welletc, 7, " STB/DAY"); + rd_kw_iset_string8(welletc, 8, " MSCF/DAY"); + rd_kw_iset_string8(welletc, 9, " RB/DAY"); + rd_kw_iset_string8(welletc, 10, " FT/SEC"); + rd_kw_iset_string8(welletc, 11, ""); + rd_kw_iset_string8(welletc, 12, " CP"); + rd_kw_iset_string8(welletc, 13, " LB/STB"); + rd_kw_iset_string8(welletc, 14, " LB/DAY"); + rd_kw_iset_string8(welletc, 15, " LB/LB"); + + } else if (unit_set == RD_LAB_UNITS) { + rd_kw_iset_string8(welletc, 0, " HR"); + rd_kw_iset_string8(welletc, 2, ""); + rd_kw_iset_string8(welletc, 3, " CM"); + rd_kw_iset_string8(welletc, 4, " ATMA"); + rd_kw_iset_string8(welletc, 6, "STANDARD"); + rd_kw_iset_string8(welletc, 7, " SCC/HR"); + rd_kw_iset_string8(welletc, 8, " SCC/HR"); + rd_kw_iset_string8(welletc, 9, " RCC/SCC"); + rd_kw_iset_string8(welletc, 10, " CM/SEC"); + rd_kw_iset_string8(welletc, 11, ""); + rd_kw_iset_string8(welletc, 12, " CP"); + rd_kw_iset_string8(welletc, 13, " GM/SCC"); + rd_kw_iset_string8(welletc, 14, " GH/HR"); + rd_kw_iset_string8(welletc, 15, " GM/GM"); + } +} + +void rd_rft_node_fwrite(const rd_rft_node_type *rft_node, fortio_type *fortio, + ert_rd_unit_enum unit_set) { + rd_rft_enum type = rd_rft_node_get_type(rft_node); + if (type != RFT) + util_abort( + "%s: sorry - only writing of simple RFT is currently implemented", + __func__); + + { + rd_kw_type *time = rd_kw_alloc(TIME_KW, 1, RD_FLOAT); + rd_kw_iset_float(time, 0, rd_rft_node_get_days(rft_node)); + rd_kw_fwrite(time, fortio); + rd_kw_free(time); + } + + { + rd_kw_type *datevalue = rd_kw_alloc(DATE_KW, 3, RD_INT); + time_t date = rd_rft_node_get_date(rft_node); + int day; + int month; + int year; + rd_set_date_values(date, &day, &month, &year); + rd_kw_iset_int(datevalue, 0, day); + rd_kw_iset_int(datevalue, 1, month); + rd_kw_iset_int(datevalue, 2, year); + rd_kw_fwrite(datevalue, fortio); + rd_kw_free(datevalue); + } + + { + rd_kw_type *welletc = rd_kw_alloc(WELLETC_KW, 16, RD_CHAR); + rd_rft_enum type = rd_rft_node_get_type(rft_node); + + rd_kw_iset_string8(welletc, 1, rd_rft_node_get_well_name(rft_node)); + + if (type == PLT) { + rd_kw_iset_string8(welletc, 5, "P"); + } else if (type == RFT) { + rd_kw_iset_string8(welletc, 5, "R"); + } else if (type == SEGMENT) { + rd_kw_iset_string8(welletc, 5, "S"); + } + rd_rft_node_fill_welletc(welletc, unit_set); + rd_kw_fwrite(welletc, fortio); + rd_kw_free(welletc); + } + + { + int size_cells = rd_rft_node_get_size(rft_node); + rd_kw_type *conipos = rd_kw_alloc(CONIPOS_KW, size_cells, RD_INT); + rd_kw_type *conjpos = rd_kw_alloc(CONJPOS_KW, size_cells, RD_INT); + rd_kw_type *conkpos = rd_kw_alloc(CONKPOS_KW, size_cells, RD_INT); + rd_kw_type *hostgrid = rd_kw_alloc(HOSTGRID_KW, size_cells, RD_CHAR); + rd_kw_type *depth = rd_kw_alloc(DEPTH_KW, size_cells, RD_FLOAT); + rd_kw_type *pressure = rd_kw_alloc(PRESSURE_KW, size_cells, RD_FLOAT); + rd_kw_type *swat = rd_kw_alloc(SWAT_KW, size_cells, RD_FLOAT); + rd_kw_type *sgas = rd_kw_alloc(SGAS_KW, size_cells, RD_FLOAT); + + for (int i = 0; i < size_cells; i++) { + const rd_rft_cell_type *cell = rft_node->cells[i]; + rd_kw_iset_int(conipos, i, rd_rft_cell_get_i(cell) + 1); + rd_kw_iset_int(conjpos, i, rd_rft_cell_get_j(cell) + 1); + rd_kw_iset_int(conkpos, i, rd_rft_cell_get_k(cell) + 1); + rd_kw_iset_float(depth, i, rd_rft_cell_get_depth(cell)); + rd_kw_iset_float(pressure, i, rd_rft_cell_get_pressure(cell)); + rd_kw_iset_float(swat, i, rd_rft_cell_get_swat(cell)); + rd_kw_iset_float(sgas, i, rd_rft_cell_get_sgas(cell)); + } + rd_kw_fwrite(conipos, fortio); + rd_kw_fwrite(conjpos, fortio); + rd_kw_fwrite(conkpos, fortio); + rd_kw_fwrite(hostgrid, fortio); + rd_kw_fwrite(depth, fortio); + rd_kw_fwrite(pressure, fortio); + rd_kw_fwrite(swat, fortio); + rd_kw_fwrite(sgas, fortio); + + rd_kw_free(conipos); + rd_kw_free(conjpos); + rd_kw_free(conkpos); + rd_kw_free(hostgrid); + rd_kw_free(depth); + rd_kw_free(pressure); + rd_kw_free(swat); + rd_kw_free(sgas); + } +} + +int rd_rft_node_cmp(const rd_rft_node_type *n1, const rd_rft_node_type *n2) { + time_t val1 = rd_rft_node_get_date(n1); + time_t val2 = rd_rft_node_get_date(n2); + + if (val1 < val2) + return -1; + else if (val1 == val2) + return 0; + else + return 1; +} + +bool rd_rft_node_lt(const rd_rft_node_type *n1, const rd_rft_node_type *n2) { + return (rd_rft_node_cmp(n1, n2) < 0); +} diff --git a/lib/resdata/rd_rst_file.cpp b/lib/resdata/rd_rst_file.cpp new file mode 100644 index 0000000000..87a5346f30 --- /dev/null +++ b/lib/resdata/rd_rst_file.cpp @@ -0,0 +1,276 @@ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct rd_rst_file_struct { + fortio_type *fortio; + bool unified; + bool fmt_file; +}; + +static rd_rst_file_type *rd_rst_file_alloc(const char *filename) { + bool unified = rd_unified_file(filename); + bool fmt_file; + rd_rst_file_type *rst_file = + (rd_rst_file_type *)util_malloc(sizeof *rst_file); + + if (rd_fmt_file(filename, &fmt_file)) { + rst_file->unified = unified; + rst_file->fmt_file = fmt_file; + return rst_file; + } else { + util_abort("%s: invalid restart filename:%s - could not determine " + "formatted/unformatted status\n", + __func__, filename); + return NULL; + } +} + +/** + Observe that all the open() functions expect that filename conforms + to the standard conventions, i.e. with extension .FUNRST / + .UNRST / .Xnnnn / .Fnnnn. +*/ + +rd_rst_file_type *rd_rst_file_open_read(const char *filename) { + rd_rst_file_type *rst_file = rd_rst_file_alloc(filename); + rst_file->fortio = + fortio_open_reader(filename, rst_file->fmt_file, RD_ENDIAN_FLIP); + return rst_file; +} + +/* + This function will scan through the file and look for seqnum + headers, and position the file pointer in the right location to + start writing data for the report step given by @report_step. The + file is truncated, so that the filepointer will be at the (new) EOF + when returning. +*/ + +rd_rst_file_type *rd_rst_file_open_write_seek(const char *filename, + int report_step) { + rd_rst_file_type *rst_file = rd_rst_file_alloc(filename); + offset_type target_pos = 0; + bool seqnum_found = false; + rst_file->fortio = + fortio_open_readwrite(filename, rst_file->fmt_file, RD_ENDIAN_FLIP); + /* + If the file does not exist at all the fortio_open_readwrite() + will fail, we just try again - opening a new file in normal write + mode, and then immediately returning. + */ + if (!rst_file->fortio) { + rst_file->fortio = + fortio_open_writer(filename, rst_file->fmt_file, RD_ENDIAN_FLIP); + return rst_file; + } + + fortio_fseek(rst_file->fortio, 0, SEEK_SET); + { + rd_kw_type *work_kw = rd_kw_alloc_new("WORK-KW", 0, RD_INT, NULL); + + while (true) { + offset_type current_offset = fortio_ftell(rst_file->fortio); + + if (fortio_read_at_eof(rst_file->fortio)) { + if (seqnum_found) + target_pos = current_offset; + break; + } + + if (rd_kw_fread_header(work_kw, rst_file->fortio) == + RD_KW_READ_FAIL) + break; + + if (rd_kw_name_equal(work_kw, SEQNUM_KW)) { + rd_kw_fread_realloc_data(work_kw, rst_file->fortio); + int file_step = rd_kw_iget_int(work_kw, 0); + if (file_step >= report_step) { + target_pos = current_offset; + break; + } + seqnum_found = true; + } else + rd_kw_fskip_data(work_kw, rst_file->fortio); + } + + rd_kw_free(work_kw); + } + + fortio_fseek(rst_file->fortio, target_pos, SEEK_SET); + fortio_ftruncate_current(rst_file->fortio); + return rst_file; +} + +rd_rst_file_type *rd_rst_file_open_write(const char *filename) { + rd_rst_file_type *rst_file = rd_rst_file_alloc(filename); + rst_file->fortio = + fortio_open_writer(filename, rst_file->fmt_file, RD_ENDIAN_FLIP); + return rst_file; +} + +rd_rst_file_type *rd_rst_file_open_append(const char *filename) { + rd_rst_file_type *rst_file = rd_rst_file_alloc(filename); + rst_file->fortio = + fortio_open_append(filename, rst_file->fmt_file, RD_ENDIAN_FLIP); + return rst_file; +} + +void rd_rst_file_close(rd_rst_file_type *rst_file) { + fortio_fclose(rst_file->fortio); + free(rst_file); +} + +static void rd_rst_file_fwrite_SEQNUM(rd_rst_file_type *rst_file, int seqnum) { + rd_kw_type *seqnum_kw = rd_kw_alloc(SEQNUM_KW, 1, RD_INT); + rd_kw_iset_int(seqnum_kw, 0, seqnum); + rd_kw_fwrite(seqnum_kw, rst_file->fortio); + rd_kw_free(seqnum_kw); +} + +void rd_rst_file_start_solution(rd_rst_file_type *rst_file) { + rd_kw_type *startsol_kw = rd_kw_alloc(STARTSOL_KW, 0, RD_MESS); + rd_kw_fwrite(startsol_kw, rst_file->fortio); + rd_kw_free(startsol_kw); +} + +void rd_rst_file_end_solution(rd_rst_file_type *rst_file) { + rd_kw_type *endsol_kw = rd_kw_alloc(ENDSOL_KW, 0, RD_MESS); + rd_kw_fwrite(endsol_kw, rst_file->fortio); + rd_kw_free(endsol_kw); +} + +static rd_kw_type *rd_rst_file_alloc_INTEHEAD(rd_rst_file_type *rst_file, + rd_rsthead_type *rsthead, + int simulator) { + rd_kw_type *intehead_kw = + rd_kw_alloc(INTEHEAD_KW, INTEHEAD_RESTART_SIZE, RD_INT); + rd_kw_scalar_set_int(intehead_kw, 0); + + rd_kw_iset_int(intehead_kw, INTEHEAD_UNIT_INDEX, rsthead->unit_system); + rd_kw_iset_int(intehead_kw, INTEHEAD_NX_INDEX, rsthead->nx); + rd_kw_iset_int(intehead_kw, INTEHEAD_NY_INDEX, rsthead->ny); + rd_kw_iset_int(intehead_kw, INTEHEAD_NZ_INDEX, rsthead->nz); + rd_kw_iset_int(intehead_kw, INTEHEAD_NACTIVE_INDEX, rsthead->nactive); + rd_kw_iset_int(intehead_kw, INTEHEAD_PHASE_INDEX, rsthead->phase_sum); + + /* All well properties are hardcoded to zero. */ + { + int NGMAXZ = 0; + int NWGMAX = 0; + int NIGRPZ = 0; + int NSWLMX = 0; + int NSEGMX = 0; + int NISEGZ = 0; + + rd_kw_iset_int(intehead_kw, INTEHEAD_NWELLS_INDEX, rsthead->nwells); + rd_kw_iset_int(intehead_kw, INTEHEAD_NCWMAX_INDEX, rsthead->ncwmax); + rd_kw_iset_int(intehead_kw, INTEHEAD_NWGMAX_INDEX, NWGMAX); + rd_kw_iset_int(intehead_kw, INTEHEAD_NGMAXZ_INDEX, NGMAXZ); + rd_kw_iset_int(intehead_kw, INTEHEAD_NIWELZ_INDEX, rsthead->niwelz); + rd_kw_iset_int(intehead_kw, INTEHEAD_NZWELZ_INDEX, rsthead->nzwelz); + rd_kw_iset_int(intehead_kw, INTEHEAD_NICONZ_INDEX, rsthead->niconz); + rd_kw_iset_int(intehead_kw, INTEHEAD_NIGRPZ_INDEX, NIGRPZ); + + { + rd_set_date_values(rsthead->sim_time, &rsthead->day, + &rsthead->month, &rsthead->year); + rd_kw_iset_int(intehead_kw, INTEHEAD_DAY_INDEX, rsthead->day); + rd_kw_iset_int(intehead_kw, INTEHEAD_MONTH_INDEX, rsthead->month); + rd_kw_iset_int(intehead_kw, INTEHEAD_YEAR_INDEX, rsthead->year); + } + + rd_kw_iset_int(intehead_kw, INTEHEAD_IPROG_INDEX, simulator); + rd_kw_iset_int(intehead_kw, INTEHEAD_NSWLMX_INDEX, NSWLMX); + rd_kw_iset_int(intehead_kw, INTEHEAD_NSEGMX_INDEX, NSEGMX); + rd_kw_iset_int(intehead_kw, INTEHEAD_NISEGZ_INDEX, NISEGZ); + } + return intehead_kw; +} + +static rd_kw_type *rd_rst_file_alloc_LOGIHEAD(int simulator) { + bool dual_porosity = false; + bool radial_grid_ECLIPSE100 = false; + bool radial_grid_ECLIPSE300 = false; + + rd_kw_type *logihead_kw = + rd_kw_alloc(LOGIHEAD_KW, LOGIHEAD_RESTART_SIZE, RD_BOOL); + + rd_kw_scalar_set_bool(logihead_kw, false); + + if (simulator == INTEHEAD_ECLIPSE100_VALUE) + rd_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL100_INDEX, + radial_grid_ECLIPSE100); + else + rd_kw_iset_bool(logihead_kw, LOGIHEAD_RADIAL300_INDEX, + radial_grid_ECLIPSE300); + + rd_kw_iset_bool(logihead_kw, LOGIHEAD_DUALP_INDEX, dual_porosity); + return logihead_kw; +} + +static rd_kw_type *rd_rst_file_alloc_DOUBHEAD(rd_rst_file_type *rst_file, + double days) { + rd_kw_type *doubhead_kw = + rd_kw_alloc(DOUBHEAD_KW, DOUBHEAD_RESTART_SIZE, RD_DOUBLE); + + rd_kw_scalar_set_double(doubhead_kw, 0); + rd_kw_iset_double(doubhead_kw, DOUBHEAD_DAYS_INDEX, days); + + return doubhead_kw; +} + +void rd_rst_file_fwrite_header(rd_rst_file_type *rst_file, int seqnum, + rd_rsthead_type *rsthead_data) { + + if (rst_file->unified) + rd_rst_file_fwrite_SEQNUM(rst_file, seqnum); + + { + rd_kw_type *intehead_kw = rd_rst_file_alloc_INTEHEAD( + rst_file, rsthead_data, INTEHEAD_ECLIPSE100_VALUE); + rd_kw_fwrite(intehead_kw, rst_file->fortio); + rd_kw_free(intehead_kw); + } + + { + rd_kw_type *logihead_kw = + rd_rst_file_alloc_LOGIHEAD(INTEHEAD_ECLIPSE100_VALUE); + rd_kw_fwrite(logihead_kw, rst_file->fortio); + rd_kw_free(logihead_kw); + } + + { + rd_kw_type *doubhead_kw = + rd_rst_file_alloc_DOUBHEAD(rst_file, rsthead_data->sim_days); + rd_kw_fwrite(doubhead_kw, rst_file->fortio); + rd_kw_free(doubhead_kw); + } +} + +void rd_rst_file_add_kw(rd_rst_file_type *rst_file, const rd_kw_type *rd_kw) { + rd_kw_fwrite(rd_kw, rst_file->fortio); +} + +offset_type rd_rst_file_ftell(const rd_rst_file_type *rst_file) { + return fortio_ftell(rst_file->fortio); +} diff --git a/lib/ecl/ecl_rsthead.cpp b/lib/resdata/rd_rsthead.cpp similarity index 65% rename from lib/ecl/ecl_rsthead.cpp rename to lib/resdata/rd_rsthead.cpp index 8f51a73d66..037759c226 100644 --- a/lib/ecl/ecl_rsthead.cpp +++ b/lib/resdata/rd_rsthead.cpp @@ -2,43 +2,42 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static time_t rsthead_date(int day, int month, int year) { - return ecl_util_make_date(day, month, year); + return rd_make_date(day, month, year); } -time_t ecl_rsthead_date(const ecl_kw_type *intehead_kw) { - return rsthead_date(ecl_kw_iget_int(intehead_kw, INTEHEAD_DAY_INDEX), - ecl_kw_iget_int(intehead_kw, INTEHEAD_MONTH_INDEX), - ecl_kw_iget_int(intehead_kw, INTEHEAD_YEAR_INDEX)); +time_t rd_rsthead_date(const rd_kw_type *intehead_kw) { + return rsthead_date(rd_kw_iget_int(intehead_kw, INTEHEAD_DAY_INDEX), + rd_kw_iget_int(intehead_kw, INTEHEAD_MONTH_INDEX), + rd_kw_iget_int(intehead_kw, INTEHEAD_YEAR_INDEX)); } -time_t ecl_rsthead_get_sim_time(const ecl_rsthead_type *header) { +time_t rd_rsthead_get_sim_time(const rd_rsthead_type *header) { return header->sim_time; } -double ecl_rsthead_get_sim_days(const ecl_rsthead_type *header) { +double rd_rsthead_get_sim_days(const rd_rsthead_type *header) { return header->sim_days; } -int ecl_rsthead_get_report_step(const ecl_rsthead_type *header) { +int rd_rsthead_get_report_step(const rd_rsthead_type *header) { return header->report_step; } -ecl_rsthead_type *ecl_rsthead_alloc_from_kw(int report_step, - const ecl_kw_type *intehead_kw, - const ecl_kw_type *doubhead_kw, - const ecl_kw_type *logihead_kw) { - ecl_rsthead_type *rsthead = - (ecl_rsthead_type *)util_malloc(sizeof *rsthead); +rd_rsthead_type *rd_rsthead_alloc_from_kw(int report_step, + const rd_kw_type *intehead_kw, + const rd_kw_type *doubhead_kw, + const rd_kw_type *logihead_kw) { + rd_rsthead_type *rsthead = (rd_rsthead_type *)util_malloc(sizeof *rsthead); rsthead->report_step = report_step; { - const int *data = (const int *)ecl_kw_get_void_ptr(intehead_kw); + const int *data = (const int *)rd_kw_get_void_ptr(intehead_kw); rsthead->day = data[INTEHEAD_DAY_INDEX]; rsthead->month = data[INTEHEAD_MONTH_INDEX]; @@ -69,9 +68,9 @@ ecl_rsthead_type *ecl_rsthead_alloc_from_kw(int report_step, rsthead->sim_time = rsthead_date(rsthead->day, rsthead->month, rsthead->year); } - rsthead->sim_days = ecl_kw_iget_double(doubhead_kw, DOUBHEAD_DAYS_INDEX); + rsthead->sim_days = rd_kw_iget_double(doubhead_kw, DOUBHEAD_DAYS_INDEX); if (logihead_kw) - rsthead->dualp = ecl_kw_iget_bool(logihead_kw, LOGIHEAD_DUALP_INDEX); + rsthead->dualp = rd_kw_iget_bool(logihead_kw, LOGIHEAD_DUALP_INDEX); return rsthead; } @@ -86,30 +85,29 @@ ecl_rsthead_type *ecl_rsthead_alloc_from_kw(int report_step, *prior* to calling this function. */ -ecl_rsthead_type *ecl_rsthead_alloc(const ecl_file_view_type *rst_view, - int report_step) { - const ecl_kw_type *intehead_kw = - ecl_file_view_iget_named_kw(rst_view, INTEHEAD_KW, 0); - const ecl_kw_type *doubhead_kw = - ecl_file_view_iget_named_kw(rst_view, DOUBHEAD_KW, 0); - const ecl_kw_type *logihead_kw = NULL; - - if (ecl_file_view_has_kw(rst_view, LOGIHEAD_KW)) - logihead_kw = ecl_file_view_iget_named_kw(rst_view, LOGIHEAD_KW, 0); - - if (ecl_file_view_has_kw(rst_view, SEQNUM_KW)) { - const ecl_kw_type *seqnum_kw = - ecl_file_view_iget_named_kw(rst_view, SEQNUM_KW, 0); - report_step = ecl_kw_iget_int(seqnum_kw, 0); +rd_rsthead_type *rd_rsthead_alloc(const rd_file_view_type *rst_view, + int report_step) { + const rd_kw_type *intehead_kw = + rd_file_view_iget_named_kw(rst_view, INTEHEAD_KW, 0); + const rd_kw_type *doubhead_kw = + rd_file_view_iget_named_kw(rst_view, DOUBHEAD_KW, 0); + const rd_kw_type *logihead_kw = NULL; + + if (rd_file_view_has_kw(rst_view, LOGIHEAD_KW)) + logihead_kw = rd_file_view_iget_named_kw(rst_view, LOGIHEAD_KW, 0); + + if (rd_file_view_has_kw(rst_view, SEQNUM_KW)) { + const rd_kw_type *seqnum_kw = + rd_file_view_iget_named_kw(rst_view, SEQNUM_KW, 0); + report_step = rd_kw_iget_int(seqnum_kw, 0); } - return ecl_rsthead_alloc_from_kw(report_step, intehead_kw, doubhead_kw, - logihead_kw); + return rd_rsthead_alloc_from_kw(report_step, intehead_kw, doubhead_kw, + logihead_kw); } -ecl_rsthead_type *ecl_rsthead_alloc_empty() { - ecl_rsthead_type *rsthead = - (ecl_rsthead_type *)util_malloc(sizeof *rsthead); +rd_rsthead_type *rd_rsthead_alloc_empty() { + rd_rsthead_type *rsthead = (rd_rsthead_type *)util_malloc(sizeof *rsthead); rsthead->day = 0; rsthead->month = 0; @@ -143,14 +141,14 @@ ecl_rsthead_type *ecl_rsthead_alloc_empty() { return rsthead; } -void ecl_rsthead_fprintf(const ecl_rsthead_type *header, FILE *stream) { +void rd_rsthead_fprintf(const rd_rsthead_type *header, FILE *stream) { fprintf(stream, "nx %d \n", header->nx); fprintf(stream, "nwells %d \n", header->nwells); fprintf(stream, "niwelz %d \n\n", header->niwelz); } -bool ecl_rsthead_equal(const ecl_rsthead_type *header1, - const ecl_rsthead_type *header2) { +bool rd_rsthead_equal(const rd_rsthead_type *header1, + const rd_rsthead_type *header2) { bool equal = true; equal = equal && (header1->day == header2->day); @@ -180,7 +178,7 @@ bool ecl_rsthead_equal(const ecl_rsthead_type *header1, return equal; } -void ecl_rsthead_fprintf_struct(const ecl_rsthead_type *header, FILE *stream) { +void rd_rsthead_fprintf_struct(const rd_rsthead_type *header, FILE *stream) { fprintf(stream, "{.day = %d,\n", header->day); fprintf(stream, ".year = %d,\n", header->year); fprintf(stream, ".month = %d,\n", header->month); @@ -205,12 +203,12 @@ void ecl_rsthead_fprintf_struct(const ecl_rsthead_type *header, FILE *stream) { fprintf(stream, ".sim_days = %g};\n", header->sim_days); } -void ecl_rsthead_free(ecl_rsthead_type *rsthead) { free(rsthead); } +void rd_rsthead_free(rd_rsthead_type *rsthead) { free(rsthead); } -int ecl_rsthead_get_nxconz(const ecl_rsthead_type *rsthead) { +int rd_rsthead_get_nxconz(const rd_rsthead_type *rsthead) { return rsthead->nxconz; } -int ecl_rsthead_get_ncwmax(const ecl_rsthead_type *rsthead) { +int rd_rsthead_get_ncwmax(const rd_rsthead_type *rsthead) { return rsthead->ncwmax; } diff --git a/lib/resdata/rd_smspec.cpp b/lib/resdata/rd_smspec.cpp new file mode 100644 index 0000000000..8575b5df3c --- /dev/null +++ b/lib/resdata/rd_smspec.cpp @@ -0,0 +1,1794 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include "detail/util/path.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_FNMATCH +#include +#endif + +/** + This file implements the indexing into the summary files. +*/ + +/* + Supporting a new variable type: + ------------------------------- + + 1. The function smspec_node_alloc() must be updated to return a valid + rd::smspec_node instance when called with the new var_type. + + 2. Update the function rd_smpec_install_gen_key() to install smpec_index + instances of this particular type. The format of the general key is + implicitly defined in this function. + + 3. The rd_smspec structure supports two different types of lookup: + + a) Lookup based on general key like e.g. WWCT:OP6 + b) Specific lookup based on the variable type, i.e. : + + rd_smspec_get_well_var( xxx , well_name , var). + + Historically everything started with specific lookup as in case b); + however the general lookup proved to be very convenient, and the + specfic lookup method has seen less use[*]. The final step in + supporting a new variable is to update the function + rd_smspec_fread_header(). + + If you want to support specific lookup of the new variable type you + must add the necessary datastructures to the rd_smspec_struct + structure and then subsequently fill that structure in the big + switch() in rd_smspec_fread_header() - if you do not care about + specific lookup you just have to add an empty case() slot to the + switch in rd_smspec_fread_header(). The LGR variables, and also + RD_SMSPEC_SEGMENT_VAR do not support specific lookup. + + [*]: The advantage of the specific lookup is that it is possible + to supply better error messages (The well 'XX' does not + exist, instead of just unknown key: 'WWCT:XX'), and it is + also possible to support queries like: give me all the + well names. + + 4. Mark the variable type as supported with a 'X' in the defintion of + rd_smspec_var_type in rd_smspec.h. + + */ + +#define RD_SMSPEC_ID 806647 +#define PARAMS_GLOBAL_DEFAULT -99 + +typedef std::map node_map; + +struct rd_smspec_struct { + UTIL_TYPE_ID_DECLARATION; + /* + All the hash tables listed below here are different ways to access + smspec_node instances. The actual smspec_node instances are + owned by the smspec_nodes vector; + */ + node_map field_var_index; + node_map misc_var_index; /* Variables like 'TCPU' and 'NEWTON'. */ + node_map + gen_var_index /* This is "everything" - things can either be found as gen_var("WWCT:OP_X") or as well_var("WWCT" , "OP_X") */ + ; + + std::map + well_var_index; /* Indexes for all well variables: + {well1: {var1: index1 , var2: index2} , well2: {var1: index1 , var2: index2}} */ + std::map + group_var_index; /* Indexes for group variables.*/ + std::map + region_var_index; /* The stored index is an offset. */ + std::map block_var_index; /* Block variables like BPR */ + std::map> + well_completion_var_index; /* Indexes for completion indexes .*/ + + std::vector> smspec_nodes; + bool write_mode; + bool need_nums; + std::vector index_map; + std::map inv_index_map; + int params_size; + + int time_seconds; + int grid_dims[3]; /* Grid dimensions - in DIMENS[1,2,3] */ + int num_regions; + int Nwells, param_offset; + std::string + key_join_string; /* The string used to join keys when building gen_key keys - typically ":" - + but arbitrary - NOT necessary to be able to invert the joining. */ + std::string + header_file; /* FULL path to the currenbtly loaded header_file. */ + + bool + formatted; /* Has this summary instance been loaded from a formatted (i.e. FSMSPEC file) or unformatted (i.e. SMSPEC) file. */ + time_t sim_start_time; /* When did the simulation start - worldtime. */ + + int time_index; /* The fields time_index, day_index, month_index and year_index */ + int day_index; /* are used by the rd_sum_data object to locate per. timestep */ + int month_index; /* time information. */ + int year_index; + bool has_lgr; + std::vector params_default; + + std::string restart_case; + ert_rd_unit_enum unit_system; + int restart_step; +}; + +/** +About indexing: +--------------- + +The RDISPE summary files are organised (roughly) like this: + + 1. A header-file called xxx.SMPSEC is written, which is common to + every timestep. + + 2. For each timestep the summary vector is written in the form of a + vector 'PARAMS' of length N with floats. In the PARAMS vector all + types of data are stacked togeheter, and one must use the header + info in the SMSPEC file to disentangle the summary data. + +Here I will try to describe how the header in SMSPEC is organised, and +how that support is imlemented here. The SMSPEC header is organized +around three character vectors, of length N. To find the position in +the PARAMS vector of a certain quantity, you must consult one, two or +all three of these vectors. The most important vecor - which must +always be consulted is the KEYWORDS vector, then it is the WGNAMES and +NUMS (integer) vectors whcih must be consulted for some variable +types. + + +Let us a consider a system consisting of: + + * Two wells: P1 and P2 - for each well we have variables WOPR, WWCT + and WGOR. + + * Three regions: For each region we have variables RPR and RXX(??) + + * We have stored field properties FOPT and FWPT + + +KEYWORDS = ['TIME','FOPR','FPR','FWCT','WOPR','WOPR,'WWCT','WWCT] + .... + + + +general_var: +------------ +VAR_TYPE:(WELL_NAME|GROUP_NAME|NUMBER):NUMBER + +Field var: VAR_TYPE +Misc var: VAR_TYPE +Well var: VAR_TYPE:WELL_NAME +Group var: VAR_TYPE:GROUP_NAME +Block var: VAR_TYPE:i,j,k (where i,j,k is calculated form NUM) +Region var VAR_TYPE:index (where index is NOT from the nums vector, it it is just an offset). +Completion var: VAR_TYPE:WELL_NAME:NUM +.... + +*/ + +/* + The smspec_required_keywords variable contains a list of keywords + which are *absolutely* required in the SMSPEC file, but observe that + depending on the content of the "KEYWORDS" array other keywords + might bre requred as well - this typically includes the NUMS + keyword. Such 'second-order' dependencies are not accounted for with + this simple list. +*/ + +static const size_t num_req_keywords = 5; +static const char *smspec_required_keywords[] = { + WGNAMES_KW, KEYWORDS_KW, STARTDAT_KW, UNITS_KW, DIMENS_KW}; + +namespace { + +const rd::smspec_node *rd_smspec_get_var_node(const node_map &mp, + const char *var) { + const auto it = mp.find(var); + if (it == mp.end()) + return nullptr; + + return it->second; +} + +const rd::smspec_node * +rd_smspec_get_str_key_var_node(const std::map &mp, + const char *key, const char *var) { + const auto key_it = mp.find(key); + if (key_it == mp.end()) + return nullptr; + + const node_map &var_map = key_it->second; + return rd_smspec_get_var_node(var_map, var); +} + +const rd::smspec_node * +rd_smspec_get_int_key_var_node(const std::map &mp, int key, + const char *var) { + const auto key_it = mp.find(key); + if (key_it == mp.end()) + return nullptr; + + const auto &var_map = key_it->second; + return rd_smspec_get_var_node(var_map, var); +} + +} //end namespace + +int rd_smspec_num_nodes(const rd_smspec_type *smspec) { + return smspec->smspec_nodes.size(); +} + +/* + When loading a summary case from file many of the nodes can be ignored, in + that case the size of PARAMS vector in the data files is larger than the + number of internalized nodes. Therefor we need to maintain the + params_size member. +*/ + +int rd_smspec_get_params_size(const rd_smspec_type *smspec) { + return smspec->params_size; +} + +rd_smspec_type *rd_smspec_alloc_empty(bool write_mode, + const char *key_join_string) { + rd_smspec_type *rd_smspec = new rd_smspec_type(); + UTIL_TYPE_ID_INIT(rd_smspec, RD_SMSPEC_ID); + + rd_smspec->sim_start_time = -1; + rd_smspec->key_join_string = key_join_string; + rd_smspec->header_file = ""; + + rd_smspec->time_index = -1; + rd_smspec->day_index = -1; + rd_smspec->year_index = -1; + rd_smspec->month_index = -1; + rd_smspec->time_seconds = -1; + rd_smspec->params_size = -1; + + /* + The unit system is given as an integer in the INTEHEAD keyword. The INTEHEAD + keyword is optional, and we have for a long time been completely oblivious + to the possibility of extracting unit system information from the SMSPEC file. + */ + rd_smspec->unit_system = RD_METRIC_UNITS; + + rd_smspec->restart_step = -1; + rd_smspec->write_mode = write_mode; + rd_smspec->need_nums = false; + + return rd_smspec; +} + +int *rd_smspec_alloc_mapping(const rd_smspec_type *self, + const rd_smspec_type *other) { + int params_size = rd_smspec_get_params_size(self); + int *mapping = (int *)util_malloc(params_size * sizeof *mapping); + + for (int i = 0; i < params_size; i++) + mapping[i] = -1; + + for (int i = 0; i < rd_smspec_num_nodes(self); i++) { + const rd::smspec_node &self_node = + rd_smspec_iget_node_w_node_index(self, i); + int self_index = self_node.get_params_index(); + const char *key = self_node.get_gen_key1(); + if (rd_smspec_has_general_var(other, key)) { + const rd::smspec_node &other_node = + rd_smspec_get_general_var_node(other, key); + int other_index = other_node.get_params_index(); + mapping[self_index] = other_index; + } + } + + return mapping; +} + +/** + Observe that the index here is into the __INTERNAL__ indexing in + the smspec_nodes vector; and in general widely different from the + params_index of the returned smspec_node instance. +*/ + +const rd::smspec_node & +rd_smspec_iget_node_w_node_index(const rd_smspec_type *smspec, int node_index) { + const auto &node = smspec->smspec_nodes[node_index]; + return *node.get(); +} + +/* + The rd_smspec_iget_node() function is only retained for compatibility; should be + replaced with calls to the more explicit: rd_smspec_iget_node_w_node_index(). +*/ + +const rd::smspec_node &rd_smspec_iget_node(const rd_smspec_type *smspec, + int index) { + return rd_smspec_iget_node_w_node_index(smspec, index); +} + +const rd::smspec_node & +rd_smspec_iget_node_w_params_index(const rd_smspec_type *smspec, + int params_index) { + int node_index = smspec->inv_index_map.at(params_index); + return rd_smspec_iget_node_w_node_index(smspec, node_index); +} + +/** + * Returns an ecl data type for which all names will fit. If the maximum name + * length is at most 8, an RD_CHAR is returned and otherwise a large enough + * RD_STRING. + */ +static rd_data_type get_wgnames_type(const rd_smspec_type *smspec) { + size_t max_len = 0; + for (int i = 0; i < rd_smspec_num_nodes(smspec); ++i) { + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(smspec, i); + const char *name = smspec_node_get_wgname(&node); + if (name) + max_len = util_size_t_max(max_len, strlen(name)); + } + + return max_len <= RD_STRING8_LENGTH ? RD_CHAR : RD_STRING(max_len); +} + +static void rd_smspec_fwrite_INTEHEAD(const rd_smspec_type *smspec, + fortio_type *fortio) { + rd_kw_type *intehead = + rd_kw_alloc(INTEHEAD_KW, INTEHEAD_SMSPEC_SIZE, RD_INT); + rd_kw_iset_int(intehead, INTEHEAD_SMSPEC_UNIT_INDEX, smspec->unit_system); + /* + The simulator type is just hardcoded to ECLIPSE100. + */ + rd_kw_iset_int(intehead, INTEHEAD_SMSPEC_IPROG_INDEX, + INTEHEAD_ECLIPSE100_VALUE); + rd_kw_fwrite(intehead, fortio); + rd_kw_free(intehead); +} + +static void rd_smspec_fwrite_RESTART(const rd_smspec_type *smspec, + fortio_type *fortio) { + rd_kw_type *restart_kw = + rd_kw_alloc(RESTART_KW, SUMMARY_RESTART_SIZE, RD_CHAR); + for (int i = 0; i < SUMMARY_RESTART_SIZE; i++) + rd_kw_iset_string8(restart_kw, i, ""); + + if (smspec->restart_case.size() > 0) { + size_t restart_case_len = smspec->restart_case.size(); + + size_t offset = 0; + for (size_t i = 0; i < SUMMARY_RESTART_SIZE; i++) { + if (offset < restart_case_len) + rd_kw_iset_string8(restart_kw, i, + &smspec->restart_case[offset]); + offset += RD_STRING8_LENGTH; + } + } + rd_kw_fwrite(restart_kw, fortio); + rd_kw_free(restart_kw); +} + +static void rd_smspec_fwrite_DIMENS(const rd_smspec_type *smspec, + fortio_type *fortio) { + rd_kw_type *dimens_kw = rd_kw_alloc(DIMENS_KW, DIMENS_SIZE, RD_INT); + int num_nodes = rd_smspec_num_nodes(smspec); + rd_kw_iset_int(dimens_kw, DIMENS_SMSPEC_SIZE_INDEX, num_nodes); + rd_kw_iset_int(dimens_kw, DIMENS_SMSPEC_NX_INDEX, smspec->grid_dims[0]); + rd_kw_iset_int(dimens_kw, DIMENS_SMSPEC_NY_INDEX, smspec->grid_dims[1]); + rd_kw_iset_int(dimens_kw, DIMENS_SMSPEC_NZ_INDEX, smspec->grid_dims[2]); + rd_kw_iset_int(dimens_kw, 4, 0); // Do not know what this is for. + rd_kw_iset_int(dimens_kw, DIMENS_SMSPEC_RESTART_STEP_INDEX, + smspec->restart_step); + + rd_kw_fwrite(dimens_kw, fortio); + rd_kw_free(dimens_kw); +} + +static void rd_smspec_fwrite_STARTDAT(const rd_smspec_type *smspec, + fortio_type *fortio) { + rd_kw_type *startdat_kw = rd_kw_alloc(STARTDAT_KW, STARTDAT_SIZE, RD_INT); + int second, minute, hour, mday, month, year; + rd_set_datetime_values(smspec->sim_start_time, &second, &minute, &hour, + &mday, &month, &year); + + rd_kw_iset_int(startdat_kw, STARTDAT_DAY_INDEX, mday); + rd_kw_iset_int(startdat_kw, STARTDAT_MONTH_INDEX, month); + rd_kw_iset_int(startdat_kw, STARTDAT_YEAR_INDEX, year); + rd_kw_iset_int(startdat_kw, STARTDAT_HOUR_INDEX, hour); + rd_kw_iset_int(startdat_kw, STARTDAT_MINUTE_INDEX, minute); + rd_kw_iset_int(startdat_kw, STARTDAT_MICRO_SECOND_INDEX, second * 1000000); + + rd_kw_fwrite(startdat_kw, fortio); + rd_kw_free(startdat_kw); +} + +static void rd_smspec_fortio_fwrite(const rd_smspec_type *smspec, + fortio_type *fortio) { + rd_smspec_fwrite_INTEHEAD(smspec, fortio); + rd_smspec_fwrite_RESTART(smspec, fortio); + rd_smspec_fwrite_DIMENS(smspec, fortio); + + int num_nodes = rd_smspec_num_nodes(smspec); + rd_kw_type *keywords_kw = rd_kw_alloc(KEYWORDS_KW, num_nodes, RD_CHAR); + rd_kw_type *units_kw = rd_kw_alloc(UNITS_KW, num_nodes, RD_CHAR); + rd_kw_type *nums_kw = NULL; + + // If the names_type is an RD_STRING we expect this to be an INTERSECT + // summary, otherwise an ECLIPSE summary. + rd_data_type names_type = get_wgnames_type(smspec); + rd_kw_type *wgnames_kw = + rd_kw_alloc(rd_type_is_char(names_type) ? WGNAMES_KW : NAMES_KW, + num_nodes, names_type); + + if (smspec->need_nums) + nums_kw = rd_kw_alloc(NUMS_KW, num_nodes, RD_INT); + + for (int i = 0; i < rd_smspec_num_nodes(smspec); i++) { + const rd::smspec_node &smspec_node = + rd_smspec_iget_node_w_node_index(smspec, i); + /* + It is possible to add variables with deferred initialisation + with the rd_sum_add_blank_var() function. Before these + variables can be actually used for anything interesting they + must be initialized with the rd_sum_init_var() function. + + If a call to save the smspec file comes before all the + variable have been initialized things will potentially go + belly up. This is solved with the following uber-hack: + + o One of the well related keywords is chosen; in + particular 'WWCT' in this case. + + o The wgname value is set to DUMMY_WELL + + The use of DUMMY_WELL ensures that this field will be + ignored when/if this smspec file is read in at a later + stage. + */ + if (smspec_node.get_var_type() == RD_SMSPEC_INVALID_VAR) { + rd_kw_iset_string8(keywords_kw, i, "WWCT"); + rd_kw_iset_string8(units_kw, i, "????????"); + rd_kw_iset_string_ptr(wgnames_kw, i, DUMMY_WELL); + } else { + rd_kw_iset_string8(keywords_kw, i, + smspec_node_get_keyword(&smspec_node)); + rd_kw_iset_string8(units_kw, i, smspec_node_get_unit(&smspec_node)); + { + const char *wgname = DUMMY_WELL; + if (smspec_node_get_wgname(&smspec_node)) + wgname = smspec_node_get_wgname(&smspec_node); + rd_kw_iset_string_ptr(wgnames_kw, i, wgname); + } + } + + if (nums_kw != NULL) + rd_kw_iset_int(nums_kw, i, smspec_node.get_num()); + } + rd_kw_fwrite(keywords_kw, fortio); + rd_kw_fwrite(wgnames_kw, fortio); + if (nums_kw != NULL) + rd_kw_fwrite(nums_kw, fortio); + rd_kw_fwrite(units_kw, fortio); + + rd_kw_free(keywords_kw); + rd_kw_free(wgnames_kw); + rd_kw_free(units_kw); + if (nums_kw != NULL) + rd_kw_free(nums_kw); + + rd_smspec_fwrite_STARTDAT(smspec, fortio); +} + +void rd_smspec_fwrite(const rd_smspec_type *smspec, const char *rd_case, + bool fmt_file) { + char *filename = + rd_alloc_filename(NULL, rd_case, RD_SUMMARY_HEADER_FILE, fmt_file, 0); + fortio_type *fortio = + fortio_open_writer(filename, fmt_file, RD_ENDIAN_FLIP); + + if (!fortio) { + const char *error_fmt_msg = + "%s: Unable to open fortio file %s, error: %s .\n"; + util_abort(error_fmt_msg, __func__, filename, strerror(errno)); + } + + rd_smspec_fortio_fwrite(smspec, fortio); + + fortio_fclose(fortio); + free(filename); +} + +static rd_smspec_type * +rd_smspec_alloc_writer__(const char *key_join_string, const char *restart_case, + int restart_step, time_t sim_start, bool time_in_days, + int nx, int ny, int nz) { + rd_smspec_type *rd_smspec = rd_smspec_alloc_empty(true, key_join_string); + /* + Only a total of 9 * 8 characters is set aside for the restart keyword, if + the supplied restart case is longer than that we silently ignore it. + */ + if (restart_case) { + if (strlen(restart_case) <= + (SUMMARY_RESTART_SIZE * RD_STRING8_LENGTH)) { + rd_smspec->restart_case = restart_case; + rd_smspec->restart_step = restart_step; + } + } + rd_smspec->grid_dims[0] = nx; + rd_smspec->grid_dims[1] = ny; + rd_smspec->grid_dims[2] = nz; + rd_smspec->sim_start_time = sim_start; + + { + const rd::smspec_node *time_node; + + if (time_in_days) { + rd_smspec->time_seconds = 3600 * 24; + time_node = rd_smspec_add_node(rd_smspec, "TIME", "DAYS", 0); + } else { + rd_smspec->time_seconds = 3600; + time_node = rd_smspec_add_node(rd_smspec, "TIME", "HOURS", 0); + } + rd_smspec->time_index = time_node->get_params_index(); + } + return rd_smspec; +} + +rd_smspec_type *rd_smspec_alloc_restart_writer( + const char *key_join_string, const char *restart_case, int restart_step, + time_t sim_start, bool time_in_days, int nx, int ny, int nz) { + return rd_smspec_alloc_writer__(key_join_string, restart_case, restart_step, + sim_start, time_in_days, nx, ny, nz); +} + +rd_smspec_type *rd_smspec_alloc_writer(const char *key_join_string, + time_t sim_start, bool time_in_days, + int nx, int ny, int nz) { + return rd_smspec_alloc_writer__(key_join_string, NULL, 0, sim_start, + time_in_days, nx, ny, nz); +} + +UTIL_SAFE_CAST_FUNCTION(rd_smspec, RD_SMSPEC_ID) + +rd_smspec_var_type rd_smspec_identify_var_type(const char *var) { + return rd::smspec_node::identify_var_type(var); +} + +static bool rd_smspec_lgr_var_type(rd_smspec_var_type var_type) { + if ((var_type == RD_SMSPEC_LOCAL_BLOCK_VAR) || + (var_type == RD_SMSPEC_LOCAL_WELL_VAR) || + (var_type == RD_SMSPEC_LOCAL_COMPLETION_VAR)) + + return true; + else + return false; +} + +/** + Takes a rd_smspec_var_type variable as input, and return a string + representation of this var_type. Suitable for debug messages +++ +*/ + +const char *rd_smspec_get_var_type_name(rd_smspec_var_type var_type) { + switch (var_type) { + case (RD_SMSPEC_INVALID_VAR): + return "INVALID_VAR"; + break; + case (RD_SMSPEC_AQUIFER_VAR): + return "AQUIFER_VAR"; + break; + case (RD_SMSPEC_WELL_VAR): + return "WELL_VAR"; + break; + case (RD_SMSPEC_REGION_VAR): + return "REGION_VAR"; + break; + case (RD_SMSPEC_FIELD_VAR): + return "FIELD_VAR"; + break; + case (RD_SMSPEC_GROUP_VAR): + return "GROUP_VAR"; + break; + case (RD_SMSPEC_BLOCK_VAR): + return "BLOCK_VAR"; + break; + case (RD_SMSPEC_COMPLETION_VAR): + return "COMPLETION_VAR"; + break; + case (RD_SMSPEC_LOCAL_BLOCK_VAR): + return "LOCAL_BLOCK_VAR"; + break; + case (RD_SMSPEC_LOCAL_COMPLETION_VAR): + return "LOCAL_COMPLETION_VAR"; + break; + case (RD_SMSPEC_LOCAL_WELL_VAR): + return "LOCAL_WELL_VAR"; + break; + case (RD_SMSPEC_NETWORK_VAR): + return "NETWORK_VAR"; + break; + case (RD_SMSPEC_REGION_2_REGION_VAR): + return "REGION_2_REGION_VAR"; + break; + case (RD_SMSPEC_SEGMENT_VAR): + return "SEGMENT_VAR"; + break; + case (RD_SMSPEC_MISC_VAR): + return "MISC_VAR"; + break; + default: + util_abort("%s: Unrecognized variable type:%d \n", __func__, var_type); + return NULL; + } +} + +/** + Input i,j,k are assumed to be in the interval [1..nx] , [1..ny], + [1..nz], return value is a global index which can be used in the + xxx_block_xxx routines. +*/ + +static int rd_smspec_get_global_grid_index(const rd_smspec_type *smspec, int i, + int j, int k) { + return i + (j - 1) * smspec->grid_dims[0] + + (k - 1) * smspec->grid_dims[0] * smspec->grid_dims[1]; +} + +/** + This function takes a fully initialized smspec_node instance, generates the + corresponding key and inserts smspec_node instance in the main hash table + smspec->gen_var_index. + + The format strings used, i.e. VAR:WELL for well based variables is implicitly + defined through the format strings used in this function. +*/ + +static void rd_smspec_install_gen_keys(rd_smspec_type *smspec, + const rd::smspec_node &smspec_node) { + /* Insert the default general mapping. */ + { + const char *gen_key1 = smspec_node.get_gen_key1(); + if (gen_key1) + smspec->gen_var_index[gen_key1] = &smspec_node; + } + + /* Insert the (optional) extra mapping for block related variables and region_2_region variables: */ + { + const char *gen_key2 = smspec_node.get_gen_key2(); + if (gen_key2) + smspec->gen_var_index[gen_key2] = &smspec_node; + } +} + +static void rd_smspec_install_special_keys(rd_smspec_type *rd_smspec, + const rd::smspec_node &smspec_node) { + /** + This large switch is for installing keys which have custom lookup + paths, in addition to the lookup based on general keys. Examples + of this is e.g. well variables which can be looked up through: + + rd_smspec_get_well_var_index( smspec , well_name , var ); + */ + + const char *well = smspec_node_get_wgname(&smspec_node); + const char *group = well; + const int num = smspec_node_get_num(&smspec_node); + const char *keyword = smspec_node_get_keyword(&smspec_node); + rd_smspec_var_type var_type = smspec_node_get_var_type(&smspec_node); + + switch (var_type) { + case (RD_SMSPEC_COMPLETION_VAR): + rd_smspec->well_completion_var_index[well][num][keyword] = &smspec_node; + break; + case (RD_SMSPEC_FIELD_VAR): + rd_smspec->field_var_index[keyword] = &smspec_node; + break; + case (RD_SMSPEC_GROUP_VAR): + rd_smspec->group_var_index[group][keyword] = &smspec_node; + break; + case (RD_SMSPEC_REGION_VAR): + rd_smspec->region_var_index[num][keyword] = &smspec_node; + rd_smspec->num_regions = util_int_max(rd_smspec->num_regions, num); + break; + case (RD_SMSPEC_WELL_VAR): + rd_smspec->well_var_index[well][keyword] = &smspec_node; + break; + case (RD_SMSPEC_MISC_VAR): + /* Misc variable - i.e. date or CPU time ... */ + rd_smspec->misc_var_index[keyword] = &smspec_node; + break; + case (RD_SMSPEC_BLOCK_VAR): + rd_smspec->block_var_index[num][keyword] = &smspec_node; + break; + /** + The variables below are ONLY accesable through the gen_key + setup; but the must be mentioned in this switch statement, + otherwise they will induce a hard failure in the default: target + below. + */ + case (RD_SMSPEC_LOCAL_BLOCK_VAR): + break; + case (RD_SMSPEC_LOCAL_COMPLETION_VAR): + break; + case (RD_SMSPEC_LOCAL_WELL_VAR): + break; + case (RD_SMSPEC_SEGMENT_VAR): + break; + case (RD_SMSPEC_REGION_2_REGION_VAR): + break; + case (RD_SMSPEC_AQUIFER_VAR): + break; + default: + throw std::invalid_argument("Internal error - should not be here \n"); + } +} + +/** + The usage of this functon breaks down completely if LGR's are involved. +*/ + +bool rd_smspec_needs_wgname(rd_smspec_var_type var_type) { + switch (var_type) { + case (RD_SMSPEC_COMPLETION_VAR): + return true; + break; + case (RD_SMSPEC_FIELD_VAR): + return false; + break; + case (RD_SMSPEC_GROUP_VAR): + return true; + break; + case (RD_SMSPEC_WELL_VAR): + return true; + break; + case (RD_SMSPEC_REGION_VAR): + return false; + break; + case (RD_SMSPEC_REGION_2_REGION_VAR): + return false; + break; + case (RD_SMSPEC_MISC_VAR): + return false; + break; + case (RD_SMSPEC_BLOCK_VAR): + return false; + break; + case (RD_SMSPEC_AQUIFER_VAR): + return false; + break; + case (RD_SMSPEC_SEGMENT_VAR): + return true; + break; + default: + util_exit("Sorry: support for variables of type:%s is not implemented " + "in %s.\n", + rd_smspec_get_var_type_name(var_type), __FILE__); + } + /* Really should not be here. */ + return false; +} + +/** + The usage of this functon breaks down completely if LGR's are involved. +*/ +bool rd_smspec_needs_num(rd_smspec_var_type var_type) { + switch (var_type) { + case (RD_SMSPEC_COMPLETION_VAR): + return true; + break; + case (RD_SMSPEC_AQUIFER_VAR): + return true; + break; + case (RD_SMSPEC_FIELD_VAR): + return false; + break; + case (RD_SMSPEC_GROUP_VAR): + return false; + break; + case (RD_SMSPEC_WELL_VAR): + return false; + break; + case (RD_SMSPEC_REGION_VAR): + return true; + break; + case (RD_SMSPEC_REGION_2_REGION_VAR): + return true; + break; + case (RD_SMSPEC_MISC_VAR): + return false; + break; + case (RD_SMSPEC_BLOCK_VAR): + return true; + break; + default: + util_exit("Sorry: support for variables of type:%s is not implemented " + "in %s.\n", + rd_smspec_get_var_type_name(var_type), __FILE__); + } + return false; +} + +bool rd_smspec_equal(const rd_smspec_type *self, const rd_smspec_type *other) { + if (self->smspec_nodes.size() != other->smspec_nodes.size()) + return false; + + for (size_t i = 0; i < self->smspec_nodes.size(); i++) { + const rd::smspec_node *node1 = self->smspec_nodes[i].get(); + const rd::smspec_node *node2 = other->smspec_nodes[i].get(); + + if (node1->cmp(*node2) != 0) + return false; + } + + return true; +} + +static void rd_smspec_load_restart(rd_smspec_type *rd_smspec, + const rd_file_type *header) { + if (rd_file_has_kw(header, RESTART_KW)) { + const rd_kw_type *restart_kw = + rd_file_iget_named_kw(header, RESTART_KW, 0); + char tmp_base + [73]; /* To accomodate a maximum of 9 items which consist of 8 characters each. */ + char *restart_base; + int i; + tmp_base[0] = '\0'; + for (i = 0; i < rd_kw_get_size(restart_kw); i++) + strcat(tmp_base, (const char *)rd_kw_iget_ptr(restart_kw, i)); + + restart_base = util_alloc_strip_copy(tmp_base); + if (strlen(restart_base)) { /* We ignore the empty ones. */ + char *smspec_header; + + /* + The conditional block here is to support the following situation: + + 1. A simulation with a restart has been performed on Posix with path + separator '/'. + + 2. The simulation is loaded on windows, where the native path + separator is '\'. + + This code block will translate '/' -> '\' in the restart keyword which + is read from the summary file. + */ + +#ifdef ERT_WINDOWS + for (int i = 0; i < strlen(restart_base); i++) { + if (restart_base[i] == UTIL_POSIX_PATH_SEP_CHAR) + restart_base[i] = UTIL_PATH_SEP_CHAR; + } +#endif + + std::string path = rd::util::path::dirname(rd_smspec->header_file); + smspec_header = rd_alloc_exfilename(path.c_str(), restart_base, + RD_SUMMARY_HEADER_FILE, + rd_smspec->formatted, 0); + if (smspec_header) { + if (!util_same_file( + smspec_header, + rd_smspec->header_file + .c_str())) /* Restart from the current case is ignored. */ + { + if (util_is_abs_path(restart_base)) + rd_smspec->restart_case = restart_base; + else { + char *tmp_path = util_alloc_filename( + path.c_str(), restart_base, NULL); + char *abs_path = util_alloc_abs_path(tmp_path); + rd_smspec->restart_case = abs_path; + free(abs_path); + free(tmp_path); + } + } + free(smspec_header); + } + } + free(restart_base); + } +} + +static const rd::smspec_node * +rd_smspec_insert_node(rd_smspec_type *rd_smspec, + std::unique_ptr smspec_node) { + int params_index = smspec_node->get_params_index(); + + /* This indexing must be used when writing. */ + rd_smspec->index_map.push_back(params_index); + rd_smspec->params_default.resize(params_index + 1, PARAMS_GLOBAL_DEFAULT); + rd_smspec->params_default[params_index] = smspec_node->get_default(); + rd_smspec->inv_index_map.insert( + std::make_pair(params_index, rd_smspec->smspec_nodes.size())); + + rd_smspec_install_gen_keys(rd_smspec, *smspec_node.get()); + rd_smspec_install_special_keys(rd_smspec, *smspec_node.get()); + + if (smspec_node->need_nums()) + rd_smspec->need_nums = true; + + rd_smspec->smspec_nodes.push_back(std::move(smspec_node)); + + if (params_index > rd_smspec->params_size) + rd_smspec->params_size = params_index + 1; + + if (static_cast(rd_smspec->smspec_nodes.size()) > + rd_smspec->params_size) + rd_smspec->params_size = rd_smspec->smspec_nodes.size(); + + const auto &node = rd_smspec->smspec_nodes.back(); + return node.get(); +} + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, int num, + const char *unit, + float default_value) { + int params_index = rd_smspec->smspec_nodes.size(); + return rd_smspec_insert_node( + rd_smspec, std::unique_ptr(new rd::smspec_node( + params_index, keyword, num, unit, rd_smspec->grid_dims, + default_value, rd_smspec->key_join_string.c_str()))); +} + +//copy given node with a new index +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const rd::smspec_node &node) { + int params_index = rd_smspec->smspec_nodes.size(); + return rd_smspec_insert_node(rd_smspec, + std::unique_ptr( + new rd::smspec_node(node, params_index))); +} + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, const char *unit, + float default_value) { + int params_index = rd_smspec->smspec_nodes.size(); + return rd_smspec_insert_node( + rd_smspec, std::unique_ptr(new rd::smspec_node( + params_index, keyword, unit, default_value))); +} + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, + const char *wgname, const char *unit, + float default_value) { + int params_index = rd_smspec->smspec_nodes.size(); + return rd_smspec_insert_node( + rd_smspec, std::unique_ptr(new rd::smspec_node( + params_index, keyword, wgname, unit, default_value, + rd_smspec->key_join_string.c_str()))); +} + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + const char *keyword, + const char *wgname, int num, + const char *unit, + float default_value) { + int params_index = rd_smspec->smspec_nodes.size(); + return rd_smspec_insert_node( + rd_smspec, + std::unique_ptr(new rd::smspec_node( + params_index, keyword, wgname, num, unit, rd_smspec->grid_dims, + default_value, rd_smspec->key_join_string.c_str()))); +} + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + int params_index, const char *keyword, + const char *wgname, int num, + const char *unit, + float default_value) { + return rd_smspec_insert_node( + rd_smspec, + std::unique_ptr(new rd::smspec_node( + params_index, keyword, wgname, num, unit, rd_smspec->grid_dims, + default_value, rd_smspec->key_join_string.c_str()))); +} + +const rd::smspec_node *rd_smspec_add_node(rd_smspec_type *rd_smspec, + int params_index, const char *keyword, + const char *wgname, int num, + const char *unit, const char *lgr, + int lgr_i, int lgr_j, int lgr_k, + float default_value) { + return rd_smspec_insert_node( + rd_smspec, + std::unique_ptr(new rd::smspec_node( + params_index, keyword, wgname, unit, lgr, lgr_i, lgr_j, lgr_k, + default_value, rd_smspec->key_join_string.c_str()))); +} + +const int *rd_smspec_get_index_map(const rd_smspec_type *smspec) { + return smspec->index_map.data(); +} + +/** + * This function is to support the NAMES alias for WGNAMES. If similar + * situations occur in the future, this is a sane starting point for general + * support. + */ +static const char *get_active_keyword_alias(rd_file_type *header, + const char *keyword) { + if (strcmp(keyword, WGNAMES_KW) == 0 || strcmp(keyword, NAMES_KW) == 0) + return rd_file_has_kw(header, WGNAMES_KW) ? WGNAMES_KW : NAMES_KW; + + return keyword; +} + +static bool rd_smspec_check_header(rd_file_type *header) { + bool OK = true; + for (size_t i = 0; i < num_req_keywords && OK; i++) { + OK &= rd_file_has_kw(header, get_active_keyword_alias( + header, smspec_required_keywords[i])); + } + + return OK; +} + +static bool rd_smspec_fread_header(rd_smspec_type *rd_smspec, + const char *header_file, + bool include_restart) { + rd_file_type *header = rd_file_open(header_file, 0); + if (header && rd_smspec_check_header(header)) { + const char *names_alias = get_active_keyword_alias(header, WGNAMES_KW); + rd_kw_type *wells = rd_file_iget_named_kw(header, names_alias, 0); + rd_kw_type *keywords = rd_file_iget_named_kw(header, KEYWORDS_KW, 0); + rd_kw_type *startdat = rd_file_iget_named_kw(header, STARTDAT_KW, 0); + rd_kw_type *units = rd_file_iget_named_kw(header, UNITS_KW, 0); + rd_kw_type *dimens = rd_file_iget_named_kw(header, DIMENS_KW, 0); + rd_kw_type *nums = NULL; + rd_kw_type *lgrs = NULL; + rd_kw_type *numlx = NULL; + rd_kw_type *numly = NULL; + rd_kw_type *numlz = NULL; + + int params_index; + rd_smspec->num_regions = 0; + rd_smspec->params_size = rd_kw_get_size(keywords); + if (startdat == NULL) + util_abort( + "%s: could not locate STARTDAT keyword in header - aborting \n", + __func__); + + if (rd_file_has_kw(header, NUMS_KW)) + nums = rd_file_iget_named_kw(header, NUMS_KW, 0); + + if (rd_file_has_kw(header, INTEHEAD_KW)) { + const rd_kw_type *intehead = + rd_file_iget_named_kw(header, INTEHEAD_KW, 0); + rd_smspec->unit_system = (ert_rd_unit_enum)rd_kw_iget_int( + intehead, INTEHEAD_SMSPEC_UNIT_INDEX); + /* + The second item in the INTEHEAD vector is an integer designating which + simulator has been used for the current simulation, that is currently + ignored. + */ + } + + if (rd_file_has_kw(header, + LGRS_KW)) { /* The file has LGR information. */ + lgrs = rd_file_iget_named_kw(header, LGRS_KW, 0); + numlx = rd_file_iget_named_kw(header, NUMLX_KW, 0); + numly = rd_file_iget_named_kw(header, NUMLY_KW, 0); + numlz = rd_file_iget_named_kw(header, NUMLZ_KW, 0); + rd_smspec->has_lgr = true; + } else + rd_smspec->has_lgr = false; + + { + int *date = rd_kw_get_int_ptr(startdat); + int year = date[STARTDAT_YEAR_INDEX]; + int month = date[STARTDAT_MONTH_INDEX]; + int day = date[STARTDAT_DAY_INDEX]; + int hour = 0; + int min = 0; + int sec = 0; + if (rd_kw_get_size(startdat) == 6) { + hour = date[STARTDAT_HOUR_INDEX]; + min = date[STARTDAT_MINUTE_INDEX]; + sec = date[STARTDAT_MICRO_SECOND_INDEX] / 1000000; + } + + rd_smspec->sim_start_time = + rd_make_datetime(sec, min, hour, day, month, year); + } + + rd_smspec->grid_dims[0] = + rd_kw_iget_int(dimens, DIMENS_SMSPEC_NX_INDEX); + rd_smspec->grid_dims[1] = + rd_kw_iget_int(dimens, DIMENS_SMSPEC_NY_INDEX); + rd_smspec->grid_dims[2] = + rd_kw_iget_int(dimens, DIMENS_SMSPEC_NZ_INDEX); + rd_smspec->restart_step = + rd_kw_iget_int(dimens, DIMENS_SMSPEC_RESTART_STEP_INDEX); + + rd_get_file_type(header_file, &rd_smspec->formatted, NULL); + + { + for (params_index = 0; params_index < rd_kw_get_size(wells); + params_index++) { + float default_value = PARAMS_GLOBAL_DEFAULT; + int num = SMSPEC_NUMS_INVALID; + char *well = (char *)util_alloc_strip_copy( + (const char *)rd_kw_iget_ptr(wells, params_index)); + char *kw = (char *)util_alloc_strip_copy( + (const char *)rd_kw_iget_ptr(keywords, params_index)); + char *unit = (char *)util_alloc_strip_copy( + (const char *)rd_kw_iget_ptr(units, params_index)); + + rd_smspec_var_type var_type; + if (nums != NULL) + num = rd_kw_iget_int(nums, params_index); + var_type = rd::smspec_node::valid_type(kw, well, num); + if (var_type == RD_SMSPEC_INVALID_VAR) { + free(kw); + free(well); + free(unit); + continue; + } + + if (rd_smspec_lgr_var_type(var_type)) { + int lgr_i = rd_kw_iget_int(numlx, params_index); + int lgr_j = rd_kw_iget_int(numly, params_index); + int lgr_k = rd_kw_iget_int(numlz, params_index); + char *lgr_name = (char *)util_alloc_strip_copy( + (const char *)rd_kw_iget_ptr(lgrs, params_index)); + + rd_smspec_insert_node( + rd_smspec, + std::unique_ptr(new rd::smspec_node( + params_index, kw, well, unit, lgr_name, lgr_i, + lgr_j, lgr_k, default_value, + rd_smspec->key_join_string.c_str()))); + free(lgr_name); + } else + rd_smspec_insert_node( + rd_smspec, + std::unique_ptr(new rd::smspec_node( + params_index, kw, well, num, unit, + rd_smspec->grid_dims, default_value, + rd_smspec->key_join_string.c_str()))); + + free(kw); + free(well); + free(unit); + } + } + + char *header_str = util_alloc_realpath(header_file); + rd_smspec->header_file = header_str; + free(header_str); + if (include_restart) + rd_smspec_load_restart(rd_smspec, header); + + rd_file_close(header); + + return true; + } else + return false; +} + +rd_smspec_type *rd_smspec_fread_alloc(const char *header_file, + const char *key_join_string, + bool include_restart) { + rd_smspec_type *rd_smspec; + + { + char *path; + util_alloc_file_components(header_file, &path, NULL, NULL); + rd_smspec = rd_smspec_alloc_empty(false, key_join_string); + free(path); + } + + if (rd_smspec_fread_header(rd_smspec, header_file, include_restart)) { + + const rd::smspec_node *time_node = + rd_smspec_get_var_node(rd_smspec->misc_var_index, "TIME"); + if (time_node) { + const char *time_unit = time_node->get_unit(); + rd_smspec->time_index = time_node->get_params_index(); + + if (util_string_equal(time_unit, "DAYS")) + rd_smspec->time_seconds = 3600 * 24; + else if (util_string_equal(time_unit, "HOURS")) + rd_smspec->time_seconds = 3600; + else + util_abort("%s: time_unit:%s not recognized \n", __func__, + time_unit); + } + + const rd::smspec_node *day_node = + rd_smspec_get_var_node(rd_smspec->misc_var_index, "DAY"); + if (day_node != NULL) { + rd_smspec->day_index = smspec_node_get_params_index(day_node); + rd_smspec->month_index = smspec_node_get_params_index( + &rd_smspec->misc_var_index["MONTH"]); + rd_smspec->year_index = smspec_node_get_params_index( + &rd_smspec->misc_var_index["YEAR"]); + } + + if ((rd_smspec->time_index == -1) && (rd_smspec->day_index == -1)) { + /* Unusable configuration. + + Seems the restart file can also have time specified with + 'YEARS' as basic time unit; that mode is not supported. + */ + + util_abort("%s: Sorry the SMSPEC file seems to lack all time " + "information, need either TIME, or DAY/MONTH/YEAR " + "information. Can not proceed.", + __func__); + return NULL; + } + return rd_smspec; + } else { + /** Failed to load from disk. */ + rd_smspec_free(rd_smspec); + return NULL; + } +} + +int rd_smspec_get_num_groups(const rd_smspec_type *rd_smspec) { + return rd_smspec->group_var_index.size(); +} + +/*char ** rd_smspec_alloc_group_names(const rd_smspec_type * rd_smspec) { + return hash_alloc_keylist(rd_smspec->group_var_index); +}*/ + +int rd_smspec_get_num_regions(const rd_smspec_type *rd_smspec) { + return rd_smspec->num_regions; +} + +/* + For each type of summary data (according to the types in + rd_smcspec_var_type there are a set accessor functions: + + xx_get_xx: This function will take the apropriate input, and + return a double value. The function will fail with util_abort() + if the rd_smspec object can not recognize the input. THis + function is not here. + + xxx_has_xx: Ths will return true / false depending on whether the + rd_smspec object the variable we ask for. + + xxx_get_xxx_index: This function will rerturn an (internal) + integer index of where the variable in question is stored, this + index can then be subsequently used for faster lookup. If the + variable can not be found, the function will return -1. + + In general the index function is the real function, the others are + only wrappers around this. In addition there are specialized + functions, like get_well_names() and so on. +*/ + +namespace { + +bool node_exists(const rd::smspec_node *node_ptr) { + if (node_ptr) + return true; + + return false; +} + +int node_valid_index(const rd::smspec_node *node_ptr) { + if (node_ptr) + return node_ptr->get_params_index(); + + throw std::out_of_range("Invalid lookup summary object"); +} + +} // namespace + +const rd::smspec_node &rd_smspec_get_well_var_node(const rd_smspec_type *smspec, + const char *well, + const char *var) { + const auto node_ptr = + rd_smspec_get_str_key_var_node(smspec->well_var_index, well, var); + if (!node_ptr) + throw std::out_of_range("The well: " + std::string(well) + + " variable: " + std::string(var) + + " combination does not exist."); + + return *node_ptr; +} + +int rd_smspec_get_well_var_params_index(const rd_smspec_type *rd_smspec, + const char *well, const char *var) { + const auto node_ptr = + rd_smspec_get_str_key_var_node(rd_smspec->well_var_index, well, var); + return node_valid_index(node_ptr); +} + +bool rd_smspec_has_well_var(const rd_smspec_type *rd_smspec, const char *well, + const char *var) { + const auto node_ptr = + rd_smspec_get_str_key_var_node(rd_smspec->well_var_index, well, var); + return node_exists(node_ptr); +} + +const rd::smspec_node & +rd_smspec_get_group_var_node(const rd_smspec_type *smspec, const char *group, + const char *var) { + const auto node_ptr = + rd_smspec_get_str_key_var_node(smspec->group_var_index, group, var); + if (!node_ptr) + throw std::out_of_range("The group: " + std::string(group) + + " variable: " + std::string(var) + + " combination does not exist."); + + return *node_ptr; +} + +int rd_smspec_get_group_var_params_index(const rd_smspec_type *rd_smspec, + const char *group, const char *var) { + const auto node_ptr = + rd_smspec_get_str_key_var_node(rd_smspec->group_var_index, group, var); + return node_valid_index(node_ptr); +} + +bool rd_smspec_has_group_var(const rd_smspec_type *rd_smspec, const char *group, + const char *var) { + const auto node_ptr = + rd_smspec_get_str_key_var_node(rd_smspec->group_var_index, group, var); + return node_exists(node_ptr); +} + +const rd::smspec_node & +rd_smspec_get_field_var_node(const rd_smspec_type *rd_smspec, const char *var) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->field_var_index, var); + if (!node_ptr) + throw std::out_of_range("The field variable: " + std::string(var) + + " does not exist."); + + return *node_ptr; +} + +int rd_smspec_get_field_var_params_index(const rd_smspec_type *rd_smspec, + const char *var) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->field_var_index, var); + return node_valid_index(node_ptr); +} + +bool rd_smspec_has_field_var(const rd_smspec_type *rd_smspec, const char *var) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->field_var_index, var); + return node_exists(node_ptr); +} + +/** + Observe that block_nr is represented as char literal, + i.e. "2345". This is because it will be used as a hash key. + + This is the final low level function which actually consults the + hash tables. +*/ + +const rd::smspec_node & +rd_smspec_get_block_var_node(const rd_smspec_type *rd_smspec, + const char *block_var, int block_nr) { + const auto node_ptr = rd_smspec_get_int_key_var_node( + rd_smspec->block_var_index, block_nr, block_var); + if (!node_ptr) + throw std::out_of_range("No such block variable"); + + return *node_ptr; +} + +const rd::smspec_node & +rd_smspec_get_block_var_node_ijk(const rd_smspec_type *rd_smspec, + const char *block_var, int i, int j, int k) { + return rd_smspec_get_block_var_node( + rd_smspec, block_var, + rd_smspec_get_global_grid_index(rd_smspec, i, j, k)); +} + +bool rd_smspec_has_block_var(const rd_smspec_type *rd_smspec, + const char *block_var, int block_nr) { + const auto node_ptr = rd_smspec_get_int_key_var_node( + rd_smspec->block_var_index, block_nr, block_var); + return node_exists(node_ptr); +} + +bool rd_smspec_has_block_var_ijk(const rd_smspec_type *rd_smspec, + const char *block_var, int i, int j, int k) { + return rd_smspec_has_block_var( + rd_smspec, block_var, + rd_smspec_get_global_grid_index(rd_smspec, i, j, k)); +} + +int rd_smspec_get_block_var_params_index(const rd_smspec_type *rd_smspec, + const char *block_var, int block_nr) { + const auto node_ptr = rd_smspec_get_int_key_var_node( + rd_smspec->block_var_index, block_nr, block_var); + return node_valid_index(node_ptr); +} + +int rd_smspec_get_block_var_params_index_ijk(const rd_smspec_type *rd_smspec, + const char *block_var, int i, + int j, int k) { + return rd_smspec_get_block_var_params_index( + rd_smspec, block_var, + rd_smspec_get_global_grid_index(rd_smspec, i, j, k)); +} + +/** + region_nr: [1...num_regions] (NOT C-based indexing) +*/ + +const rd::smspec_node & +rd_smspec_get_region_var_node(const rd_smspec_type *rd_smspec, + const char *region_var, int region_nr) { + const auto node_ptr = rd_smspec_get_int_key_var_node( + rd_smspec->region_var_index, region_nr, region_var); + if (!node_ptr) + throw std::out_of_range("No such block variable"); + + return *node_ptr; +} + +bool rd_smspec_has_region_var(const rd_smspec_type *rd_smspec, + const char *region_var, int region_nr) { + const auto node_ptr = rd_smspec_get_int_key_var_node( + rd_smspec->region_var_index, region_nr, region_var); + return node_exists(node_ptr); +} + +int rd_smspec_get_region_var_params_index(const rd_smspec_type *rd_smspec, + const char *region_var, + int region_nr) { + const auto node_ptr = rd_smspec_get_int_key_var_node( + rd_smspec->region_var_index, region_nr, region_var); + return node_valid_index(node_ptr); +} + +const rd::smspec_node & +rd_smspec_get_misc_var_node(const rd_smspec_type *rd_smspec, const char *var) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->misc_var_index, var); + if (!node_ptr) + throw std::out_of_range("No such misc variable"); + + return *node_ptr; +} + +bool rd_smspec_has_misc_var(const rd_smspec_type *rd_smspec, const char *var) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->misc_var_index, var); + return node_exists(node_ptr); +} + +int rd_smspec_get_misc_var_params_index(const rd_smspec_type *rd_smspec, + const char *var) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->misc_var_index, var); + return node_valid_index(node_ptr); +} + +const rd::smspec_node * +rd_smspec_get_well_completion_var_node__(const rd_smspec_type *rd_smspec, + const char *well, const char *var, + int cell_nr) { + const auto well_iter = rd_smspec->well_completion_var_index.find(well); + if (well_iter == rd_smspec->well_completion_var_index.end()) + return nullptr; + + const auto &num_map = well_iter->second; + return rd_smspec_get_int_key_var_node(num_map, cell_nr, var); +} + +const rd::smspec_node & +rd_smspec_get_well_completion_var_node(const rd_smspec_type *rd_smspec, + const char *well, const char *var, + int cell_nr) { + const auto node_ptr = + rd_smspec_get_well_completion_var_node__(rd_smspec, well, var, cell_nr); + if (!node_ptr) + throw std::out_of_range("No such well/var/completion"); + + return *node_ptr; +} + +bool rd_smspec_has_well_completion_var(const rd_smspec_type *rd_smspec, + const char *well, const char *var, + int cell_nr) { + const auto node_ptr = + rd_smspec_get_well_completion_var_node__(rd_smspec, well, var, cell_nr); + return node_exists(node_ptr); +} + +int rd_smspec_get_well_completion_var_params_index( + const rd_smspec_type *rd_smspec, const char *well, const char *var, + int cell_nr) { + const auto node_ptr = + rd_smspec_get_well_completion_var_node__(rd_smspec, well, var, cell_nr); + return node_valid_index(node_ptr); +} + +/* There is a quite wide range of error which are just returned as + "Not found" (i.e. -1). */ +/* Completions not supported yet. */ + +const rd::smspec_node & +rd_smspec_get_general_var_node(const rd_smspec_type *smspec, + const char *lookup_kw) { + const auto node_ptr = + rd_smspec_get_var_node(smspec->gen_var_index, lookup_kw); + if (!node_ptr) + throw std::out_of_range("No such variable: " + std::string(lookup_kw)); + + return *node_ptr; +} + +int rd_smspec_get_general_var_params_index(const rd_smspec_type *rd_smspec, + const char *lookup_kw) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->gen_var_index, lookup_kw); + return node_valid_index(node_ptr); +} + +bool rd_smspec_has_general_var(const rd_smspec_type *rd_smspec, + const char *lookup_kw) { + const auto node_ptr = + rd_smspec_get_var_node(rd_smspec->gen_var_index, lookup_kw); + return node_exists(node_ptr); +} + +/** DIES if the lookup_kw is not present. */ +const char *rd_smspec_get_general_var_unit(const rd_smspec_type *rd_smspec, + const char *lookup_kw) { + const auto smspec_node = + rd_smspec_get_general_var_node(rd_smspec, lookup_kw); + return smspec_node_get_unit(&smspec_node); +} + +int rd_smspec_get_time_seconds(const rd_smspec_type *rd_smspec) { + return rd_smspec->time_seconds; +} + +int rd_smspec_get_time_index(const rd_smspec_type *rd_smspec) { + return rd_smspec->time_index; +} + +time_t rd_smspec_get_start_time(const rd_smspec_type *rd_smspec) { + return rd_smspec->sim_start_time; +} + +bool rd_smspec_get_formatted(const rd_smspec_type *rd_smspec) { + return rd_smspec->formatted; +} + +const char *rd_smspec_get_header_file(const rd_smspec_type *rd_smspec) { + return rd_smspec->header_file.c_str(); +} + +int rd_smspec_get_restart_step(const rd_smspec_type *rd_smspec) { + return rd_smspec->restart_step; +} + +int rd_smspec_get_first_step(const rd_smspec_type *rd_smspec) { + if (rd_smspec->restart_step > 0) + return rd_smspec->restart_step + 1; + else + return 1; +} + +const char *rd_smspec_get_restart_case(const rd_smspec_type *rd_smspec) { + if (rd_smspec->restart_case.size() > 0) + return rd_smspec->restart_case.c_str(); + else + return NULL; +} + +const std::vector & +rd_smspec_get_params_default(const rd_smspec_type *rd_smspec) { + return rd_smspec->params_default; +} + +void rd_smspec_free(rd_smspec_type *rd_smspec) { delete rd_smspec; } + +void rd_smspec_free__(void *__rd_smspec) { + rd_smspec_type *rd_smspec = rd_smspec_safe_cast(__rd_smspec); + rd_smspec_free(rd_smspec); +} + +int rd_smspec_get_date_day_index(const rd_smspec_type *smspec) { + return smspec->day_index; +} + +int rd_smspec_get_date_month_index(const rd_smspec_type *smspec) { + return smspec->month_index; +} + +int rd_smspec_get_date_year_index(const rd_smspec_type *smspec) { + return smspec->year_index; +} + +/** + This function checks whether an input general key (i.e. FWPR or + GGPT:NORTH) represents an accumulated total. If the variable is not + internalized the function will fail hard. +*/ + +bool rd_smspec_general_is_total(const rd_smspec_type *smspec, + const char *gen_key) { + const rd::smspec_node &smspec_node = + rd_smspec_get_general_var_node(smspec, gen_key); + return smspec_node_is_total(&smspec_node); +} + +/** + Fills a stringlist instance with all the gen_key string matching + the supplied pattern. I.e. + + rd_smspec_alloc_matching_general_var_list( smspec , "WGOR:*"); + + will give a list of WGOR for ALL the wells. The function is + unfortunately not as useful as one might think because ECLIPSE + will for instance happily give you the WOPR for a + water injector or WWIR for an oil producer. + + The function can be called several times with different patterns, + the stringlist is not cleared on startup; the keys in the list are + unique - keys are not added multiple times. If pattern == NULL all + keys will match. +*/ + +void rd_smspec_select_matching_general_var_list(const rd_smspec_type *smspec, + const char *pattern, + stringlist_type *keys) { + std::set ex_keys; + for (int i = 0; i < stringlist_get_size(keys); i++) + ex_keys.insert(stringlist_iget(keys, i)); + + { + for (const auto &pair : smspec->gen_var_index) { + const char *key = pair.first.c_str(); + + /* + The TIME is typically special cased by output and will not + match the 'all keys' wildcard. + */ + if (util_string_equal(key, "TIME")) { + if ((pattern == NULL) || (util_string_equal(pattern, "*"))) + continue; + } + + if ((pattern == NULL) || (util_fnmatch(pattern, key) == 0)) { + if (ex_keys.find(key) == ex_keys.end()) + stringlist_append_copy(keys, key); + } + } + } + + stringlist_sort(keys, (string_cmp_ftype *)util_strcmp_int); +} + +/** + Allocates a new stringlist and initializes it with the + rd_smspec_select_matching_general_var_list() function. +*/ + +stringlist_type * +rd_smspec_alloc_matching_general_var_list(const rd_smspec_type *smspec, + const char *pattern) { + stringlist_type *keys = stringlist_alloc_new(); + rd_smspec_select_matching_general_var_list(smspec, pattern, keys); + return keys; +} + +const char *rd_smspec_get_join_string(const rd_smspec_type *smspec) { + return smspec->key_join_string.c_str(); +} + +/** + Returns a stringlist instance with all the (valid) well names. It + is the responsability of the calling scope to free the stringlist + with stringlist_free(); + + + If @pattern is different from NULL only wells which 'match' the + pattern is included; if @pattern == NULL all wells are + included. The match is done with function fnmatch() - + i.e. standard shell wildcards. +*/ + +static stringlist_type * +rd_smspec_alloc_map_list(const std::map &mp, + const char *pattern) { + stringlist_type *map_list = stringlist_alloc_new(); + + for (const auto &pair : mp) { + const char *map_name = pair.first.c_str(); + + if (pattern == NULL) + stringlist_append_copy(map_list, map_name); + else if (util_fnmatch(pattern, map_name) == 0) + stringlist_append_copy(map_list, map_name); + } + stringlist_sort(map_list, (string_cmp_ftype *)util_strcmp_int); + return map_list; +} + +stringlist_type *rd_smspec_alloc_well_list(const rd_smspec_type *smspec, + const char *pattern) { + return rd_smspec_alloc_map_list(smspec->well_var_index, pattern); +} + +/** + Returns a stringlist instance with all the (valid) group names. It + is the responsability of the calling scope to free the stringlist + with stringlist_free(); +*/ + +stringlist_type *rd_smspec_alloc_group_list(const rd_smspec_type *smspec, + const char *pattern) { + return rd_smspec_alloc_map_list(smspec->group_var_index, pattern); +} + +/** + Returns a stringlist instance with all the well variables. It is + the responsability of the calling scope to free the stringlist + with stringlist_free(); +*/ + +stringlist_type *rd_smspec_alloc_well_var_list(const rd_smspec_type *smspec) { + stringlist_type *stringlist = stringlist_alloc_new(); + for (const auto &pair : smspec->well_var_index) + stringlist_append_copy(stringlist, pair.first.c_str()); + + return stringlist; +} + +const int *rd_smspec_get_grid_dims(const rd_smspec_type *smspec) { + return smspec->grid_dims; +} + +char *rd_smspec_alloc_well_key(const rd_smspec_type *smspec, + const char *keyword, const char *wgname) { + return smspec_alloc_well_key(smspec->key_join_string.c_str(), keyword, + wgname); +} + +/*void rd_smspec_sort( rd_smspec_type * smspec ) { + std::sort(smspec->smspec_nodes.begin(), smspec->smspec_nodes.end(), smspec_node_lt); + + for (int i=0; i < static_cast(smspec->smspec_nodes.size()); i++) { + rd::smspec_node& node = *smspec->smspec_nodes[i].get(); + smspec_node_set_params_index( &node , i ); + } +} +*/ + +ert_rd_unit_enum rd_smspec_get_unit_system(const rd_smspec_type *smspec) { + return smspec->unit_system; +} diff --git a/lib/resdata/rd_subsidence.cpp b/lib/resdata/rd_subsidence.cpp new file mode 100644 index 0000000000..61786ca925 --- /dev/null +++ b/lib/resdata/rd_subsidence.cpp @@ -0,0 +1,339 @@ +#include +#define _USE_MATH_DEFINES // for C WINDOWS +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "detail/resdata/rd_grid_cache.hpp" + +/** + This file contains datastructures for calculating changes in + subsidence from compression of reservoirs. The main datastructure is the + rd_subsidence_type structure (which is the only structure which is + exported). +*/ + +/** + The rd_subsidence_struct datastructure is the main structure for + calculating the subsidence from time lapse ECLIPSE simulations. +*/ + +struct rd_subsidence_struct { + const rd_file_type * + init_file; /* The init file - a shared reference owned by calling scope. */ + rd::rd_grid_cache *grid_cache; + bool *aquifer_cell; + hash_type * + surveys; /* A hash table containg rd_subsidence_survey_type instances; one instance + for each interesting time. */ + double *compressibility; /*total compressibility*/ + double *poisson_ratio; +}; + +/** + Data structure representing one subsidence survey. +*/ + +#define RD_SUBSIDENCE_SURVEY_ID 88517 +struct rd_subsidence_survey_struct { + UTIL_TYPE_ID_DECLARATION; + const rd::rd_grid_cache *grid_cache; + const bool * + aquifer_cell; /* Is this cell a numerical aquifer cell - must be disregarded. */ + char *name; /* Name of the survey - arbitrary string. */ + double *porv; /* Reference pore volume */ + double *pressure; /* Pressure in each grid cell at survey time */ + double + *dynamic_porevolume; /* Porevolume in each grid cell at survey time */ +}; + +static rd_subsidence_survey_type * +rd_subsidence_survey_alloc_empty(const rd_subsidence_type *sub, + const char *name) { + rd_subsidence_survey_type *survey = + (rd_subsidence_survey_type *)util_malloc(sizeof *survey); + UTIL_TYPE_ID_INIT(survey, RD_SUBSIDENCE_SURVEY_ID); + survey->grid_cache = sub->grid_cache; + survey->aquifer_cell = sub->aquifer_cell; + survey->name = util_alloc_string_copy(name); + + survey->porv = + (double *)util_calloc(sub->grid_cache->size(), sizeof *survey->porv); + survey->pressure = (double *)util_calloc(sub->grid_cache->size(), + sizeof *survey->pressure); + survey->dynamic_porevolume = NULL; + + return survey; +} + +static UTIL_SAFE_CAST_FUNCTION(rd_subsidence_survey, RD_SUBSIDENCE_SURVEY_ID) + + static rd_subsidence_survey_type *rd_subsidence_survey_alloc_PRESSURE( + rd_subsidence_type *rd_subsidence, + const rd_file_view_type *restart_view, const char *name) { + + rd_subsidence_survey_type *survey = + rd_subsidence_survey_alloc_empty(rd_subsidence, name); + const rd::rd_grid_cache &grid_cache = *(rd_subsidence->grid_cache); + const auto &global_index = grid_cache.global_index(); + const int size = grid_cache.size(); + + int active_index; + rd_kw_type *init_porv_kw = rd_file_iget_named_kw( + rd_subsidence->init_file, PORV_KW, 0); /*Global indexing*/ + rd_kw_type *pressure_kw = rd_file_view_iget_named_kw( + restart_view, PRESSURE_KW, 0); /*Active indexing*/ + + rd_kw_type *rporv_kw = NULL; + if (rd_file_view_has_kw(restart_view, RPORV_KW)) { + survey->dynamic_porevolume = + (double *)util_calloc(rd_subsidence->grid_cache->size(), + sizeof *survey->dynamic_porevolume); + rporv_kw = rd_file_view_iget_named_kw(restart_view, RPORV_KW, 0); + } + + for (active_index = 0; active_index < size; active_index++) { + survey->porv[active_index] = + rd_kw_iget_float(init_porv_kw, global_index[active_index]); + survey->pressure[active_index] = + rd_kw_iget_float(pressure_kw, active_index); + + if (rporv_kw) + survey->dynamic_porevolume[active_index] = + rd_kw_iget_float(rporv_kw, active_index); + } + return survey; +} + +static void +rd_subsidence_survey_free(rd_subsidence_survey_type *subsidence_survey) { + free(subsidence_survey->name); + free(subsidence_survey->porv); + free(subsidence_survey->pressure); + free(subsidence_survey->dynamic_porevolume); + free(subsidence_survey); +} + +static void rd_subsidence_survey_free__(void *__subsidence_survey) { + rd_subsidence_survey_type *subsidence_survey = + rd_subsidence_survey_safe_cast(__subsidence_survey); + rd_subsidence_survey_free(subsidence_survey); +} + +static double +rd_subsidence_survey_eval(const rd_subsidence_survey_type *base_survey, + const rd_subsidence_survey_type *monitor_survey, + rd_region_type *region, double utm_x, double utm_y, + double depth, double compressibility, + double poisson_ratio) { + + const rd::rd_grid_cache &grid_cache = *(base_survey->grid_cache); + const int size = grid_cache.size(); + double *weight = (double *)util_calloc(size, sizeof *weight); + double deltaz; + int index; + + if (monitor_survey != NULL) { + for (index = 0; index < size; index++) + weight[index] = + base_survey->porv[index] * (base_survey->pressure[index] - + monitor_survey->pressure[index]); + } else { + for (index = 0; index < size; index++) + weight[index] = + base_survey->porv[index] * base_survey->pressure[index]; + } + + deltaz = compressibility * 31.83099 * (1 - poisson_ratio) * + rd_grav_common_eval_biot_savart(grid_cache, region, + base_survey->aquifer_cell, weight, + utm_x, utm_y, depth); + + free(weight); + return deltaz; +} + +static double rd_subsidence_survey_eval_geertsma( + const rd_subsidence_survey_type *base_survey, + const rd_subsidence_survey_type *monitor_survey, rd_region_type *region, + double utm_x, double utm_y, double depth, double youngs_modulus, + double poisson_ratio, double seabed) { + + const rd::rd_grid_cache &grid_cache = *(base_survey->grid_cache); + const auto &cell_volume = grid_cache.volume(); + const int size = grid_cache.size(); + double scale_factor = 1e4 * (1 + poisson_ratio) * (1 - 2 * poisson_ratio) / + (4 * M_PI * (1 - poisson_ratio) * youngs_modulus); + double *weight = (double *)util_calloc(size, sizeof *weight); + double deltaz; + + for (int index = 0; index < size; index++) { + if (monitor_survey) { + weight[index] = scale_factor * cell_volume[index] * + (base_survey->pressure[index] - + monitor_survey->pressure[index]); + } else { + weight[index] = scale_factor * cell_volume[index] * + (base_survey->pressure[index]); + } + } + + deltaz = rd_grav_common_eval_geertsma( + grid_cache, region, base_survey->aquifer_cell, weight, utm_x, utm_y, + depth, poisson_ratio, seabed); + + free(weight); + return deltaz; +} + +static double rd_subsidence_survey_eval_geertsma_rporv( + const rd_subsidence_survey_type *base_survey, + const rd_subsidence_survey_type *monitor_survey, rd_region_type *region, + double utm_x, double utm_y, double depth, double youngs_modulus, + double poisson_ratio, double seabed) { + + const rd::rd_grid_cache &grid_cache = *(base_survey->grid_cache); + std::vector weight(grid_cache.size()); + + if (!base_survey->dynamic_porevolume) { + util_abort( + "%s: Keyword RPORV not defined in .UNRST file for %s. Please add " + "RPORV keyword to output in RPTRST clause in .DATA file.\n", + __func__, base_survey->name); + } + + if (monitor_survey && !monitor_survey->dynamic_porevolume) { + util_abort( + "%s: Keyword RPORV not defined in .UNRST file for %s. Please add " + "RPORV keyword to output in RPTRST clause in .DATA file.\n", + __func__, monitor_survey->name); + } + + for (size_t index = 0; index < weight.size(); ++index) { + if (monitor_survey) + weight[index] = (base_survey->dynamic_porevolume[index] - + monitor_survey->dynamic_porevolume[index]) / + (4 * M_PI); + else + weight[index] = base_survey->dynamic_porevolume[index] / (4 * M_PI); + } + + return rd_grav_common_eval_geertsma( + grid_cache, region, base_survey->aquifer_cell, weight.data(), utm_x, + utm_y, depth, poisson_ratio, seabed); +} + +/** + The grid instance is only used during the construction phase. The + @init_file object is used by the rd_subsidence_add_survey_XXX() + functions; and calling scope must NOT destroy this object before + all surveys have been added. +*/ + +rd_subsidence_type *rd_subsidence_alloc(const rd_grid_type *rd_grid, + const rd_file_type *init_file) { + rd_subsidence_type *rd_subsidence = + (rd_subsidence_type *)util_malloc(sizeof *rd_subsidence); + rd_subsidence->init_file = init_file; + rd_subsidence->grid_cache = new rd::rd_grid_cache(rd_grid); + rd_subsidence->aquifer_cell = rd_grav_common_alloc_aquifer_cell( + *(rd_subsidence->grid_cache), init_file); + + rd_subsidence->surveys = hash_alloc(); + return rd_subsidence; +} + +static void rd_subsidence_add_survey__(rd_subsidence_type *subsidence, + const char *name, + rd_subsidence_survey_type *survey) { + hash_insert_hash_owned_ref(subsidence->surveys, name, survey, + rd_subsidence_survey_free__); +} + +rd_subsidence_survey_type * +rd_subsidence_add_survey_PRESSURE(rd_subsidence_type *subsidence, + const char *name, + const rd_file_view_type *restart_view) { + rd_subsidence_survey_type *survey = + rd_subsidence_survey_alloc_PRESSURE(subsidence, restart_view, name); + rd_subsidence_add_survey__(subsidence, name, survey); + return survey; +} + +bool rd_subsidence_has_survey(const rd_subsidence_type *subsidence, + const char *name) { + return hash_has_key(subsidence->surveys, name); +} + +static rd_subsidence_survey_type * +rd_subsidence_get_survey(const rd_subsidence_type *subsidence, + const char *name) { + if (name == NULL) + return NULL; // Calling scope must determine if this is OK? + else + return (rd_subsidence_survey_type *)hash_get(subsidence->surveys, name); +} + +double rd_subsidence_eval(const rd_subsidence_type *subsidence, + const char *base, const char *monitor, + rd_region_type *region, double utm_x, double utm_y, + double depth, double compressibility, + double poisson_ratio) { + rd_subsidence_survey_type *base_survey = + rd_subsidence_get_survey(subsidence, base); + rd_subsidence_survey_type *monitor_survey = + rd_subsidence_get_survey(subsidence, monitor); + return rd_subsidence_survey_eval(base_survey, monitor_survey, region, utm_x, + utm_y, depth, compressibility, + poisson_ratio); +} + +double rd_subsidence_eval_geertsma(const rd_subsidence_type *subsidence, + const char *base, const char *monitor, + rd_region_type *region, double utm_x, + double utm_y, double depth, + double youngs_modulus, double poisson_ratio, + double seabed) { + rd_subsidence_survey_type *base_survey = + rd_subsidence_get_survey(subsidence, base); + rd_subsidence_survey_type *monitor_survey = + rd_subsidence_get_survey(subsidence, monitor); + return rd_subsidence_survey_eval_geertsma( + base_survey, monitor_survey, region, utm_x, utm_y, depth, + youngs_modulus, poisson_ratio, seabed); +} + +double rd_subsidence_eval_geertsma_rporv(const rd_subsidence_type *subsidence, + const char *base, const char *monitor, + rd_region_type *region, double utm_x, + double utm_y, double depth, + double youngs_modulus, + double poisson_ratio, double seabed) { + rd_subsidence_survey_type *base_survey = + rd_subsidence_get_survey(subsidence, base); + rd_subsidence_survey_type *monitor_survey = + rd_subsidence_get_survey(subsidence, monitor); + return rd_subsidence_survey_eval_geertsma_rporv( + base_survey, monitor_survey, region, utm_x, utm_y, depth, + youngs_modulus, poisson_ratio, seabed); +} + +void rd_subsidence_free(rd_subsidence_type *rd_subsidence) { + delete rd_subsidence->grid_cache; + + free(rd_subsidence->aquifer_cell); + hash_free(rd_subsidence->surveys); + free(rd_subsidence); +} diff --git a/lib/resdata/rd_sum.cpp b/lib/resdata/rd_sum.cpp new file mode 100644 index 0000000000..5d2da6bfc8 --- /dev/null +++ b/lib/resdata/rd_sum.cpp @@ -0,0 +1,1526 @@ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "detail/util/path.hpp" + +/** + The summary data is organised in a header file (.SMSPEC) + and the actual summary data. This file implements a data structure + rd_sum_type which holds summary data. Most of the actual + implementation is in separate files rd_smspec.c for the SMSPEC + header, and rd_sum_data for the actual data. + + Observe that this datastructure is built up around internalizing + summary data, the code has NO AMBITION of being able to + write summary data. + + + Header in CASE.SMSPEC file Actual data; many 'PARAMS' blocks in .Snnnn or .UNSMRY file + + ------------------------------......... ----------- ----------- ----------- ----------- ----------- + | WGNAMES KEYWORDS NUMS | INDEX : | PARAMS | | PARAMS | | PARAMS | | PARAMS | | PARAMS | + |----------------------------|........: |---------| |---------| |---------| |---------| |---------| + | OP-1 WOPR X | 0 : | 652 | | 752 | | 862 | | 852 | | 962 | + | OP-1 WWPR X | 1 : | 45 | | 47 | | 55 | | 59 | | 62 | + | GI-1 WGIR X | 2 : | 500 | | 500 | | 786 | | 786 | | 486 | + | :+:+:+:+ FOPT X | 3 : | 7666 | | 7666 | | 8811 | | 7688 | | 8649 | + | :+:+:+:+ RPR 5 | 4 : | 255 | | 255 | | 266 | | 257 | | 277 | + | :+:+:+:+ BPR 3457 | 5 : | 167 | | 167 | | 189 | | 201 | | 166 | + ------------------------------......... ----------- ----------- ----------- ----------- ----------- + + <------------------------ Time direction -------------------------> + + As illustrated in the figure above header information is stored in + the SMSPEC file; the header information is organised in several + keywords; at least the WGNAMES and KEYWORDS arrays, and often also + the NUMS array. Together these three arrays uniquely specify a + summary vector. + + The INDEX column in the header information is NOT part of the + SMSPEC file, but an important part of the rd_smspec + implementation. The the values from WGNAMES/KEYWORDS/NUMS are + combined to create a unique key; and the corresponding index is + used to lookup a numerical value from the PARAMS vector with actual + data. + + These matters are documented further in the rd_smspec.c and + rd_sum_data.c files. +*/ + +#define RD_SUM_ID 89067 + +struct rd_sum_struct { + UTIL_TYPE_ID_DECLARATION; + rd_smspec_type *smspec; /* Internalized version of the SMSPEC file. */ + rd_sum_data_type *data; /* The data - can be NULL. */ + rd_sum_type *restart_case; + + bool fmt_case; + bool unified; + char *key_join_string; + char * + path; /* The path - as given for the case input. Can be NULL for cwd. */ + char *abs_path; /* Absolute path. */ + char *base; /* Only the basename. */ + char * + rd_case; /* This is the current case, with optional path component. == path + base*/ + char * + ext; /* Only to support selective loading of formatted|unformatted and unified|multiple. (can be NULL) */ +}; + +UTIL_SAFE_CAST_FUNCTION(rd_sum, RD_SUM_ID); +UTIL_IS_INSTANCE_FUNCTION(rd_sum, RD_SUM_ID); + +/** + Reads the data from summary files, can either be a list of + files BASE.S0000, BASE.S0001, BASE.S0002,.. or one unified + file. Formatted/unformatted is detected automagically. + + The actual loading is implemented in the rd_sum_data.c file. +*/ + +void rd_sum_set_case(rd_sum_type *rd_sum, const char *input_arg) { + free(rd_sum->rd_case); + free(rd_sum->path); + free(rd_sum->abs_path); + free(rd_sum->base); + free(rd_sum->ext); + { + std::string path = rd::util::path::dirname(input_arg); + std::string base = rd::util::path::basename(input_arg); + std::string ext = rd::util::path::extension(input_arg); + + rd_sum->rd_case = util_alloc_filename(path.c_str(), base.c_str(), NULL); + if (path.size()) + rd_sum->path = util_alloc_string_copy(path.c_str()); + else + rd_sum->path = NULL; + + if (base.size()) + rd_sum->base = util_alloc_string_copy(base.c_str()); + else + rd_sum->base = NULL; + + if (ext.size()) + rd_sum->ext = util_alloc_string_copy(ext.c_str()); + else + rd_sum->ext = NULL; + + if (path.size() > 0) + rd_sum->abs_path = util_alloc_abs_path(path.c_str()); + else + rd_sum->abs_path = util_alloc_cwd(); + } +} + +static rd_sum_type *rd_sum_alloc__(const char *input_arg, + const char *key_join_string) { + if (!rd_path_access(input_arg)) + return NULL; + + rd_sum_type *rd_sum = (rd_sum_type *)util_malloc(sizeof *rd_sum); + UTIL_TYPE_ID_INIT(rd_sum, RD_SUM_ID); + + rd_sum->rd_case = NULL; + rd_sum->path = NULL; + rd_sum->base = NULL; + rd_sum->ext = NULL; + rd_sum->abs_path = NULL; + rd_sum_set_case(rd_sum, input_arg); + rd_sum->key_join_string = util_alloc_string_copy(key_join_string); + + rd_sum->smspec = NULL; + rd_sum->data = NULL; + rd_sum->restart_case = NULL; + + return rd_sum; +} + +static bool rd_sum_fread_data(rd_sum_type *rd_sum, + const stringlist_type *data_files, + bool include_restart, bool lazy_load, + int file_options) { + if (rd_sum->data != NULL) + rd_sum_free_data(rd_sum); + + rd_sum->data = rd_sum_data_alloc(rd_sum->smspec); + return rd_sum_data_fread(rd_sum->data, data_files, lazy_load, file_options); +} + +static void rd_sum_fread_history(rd_sum_type *rd_sum, bool lazy_load, + int file_options) { + char *restart_header = rd_alloc_filename( + NULL, rd_smspec_get_restart_case(rd_sum->smspec), + RD_SUMMARY_HEADER_FILE, rd_smspec_get_formatted(rd_sum->smspec), -1); + rd_sum_type *restart_case = rd_sum_fread_alloc_case2__( + restart_header, ":", true, lazy_load, file_options); + if (restart_case) { + rd_sum->restart_case = restart_case; + rd_sum_data_add_case(rd_sum->data, restart_case->data); + } + free(restart_header); +} + +static bool rd_sum_fread(rd_sum_type *rd_sum, const char *header_file, + const stringlist_type *data_files, + bool include_restart, bool lazy_load, + int file_options) { + rd_sum->smspec = rd_smspec_fread_alloc(header_file, rd_sum->key_join_string, + include_restart); + if (rd_sum->smspec) { + bool fmt_file; + rd_get_file_type(header_file, &fmt_file, NULL); + rd_sum_set_fmt_case(rd_sum, fmt_file); + } else + return false; + + if (rd_sum_fread_data(rd_sum, data_files, include_restart, lazy_load, + file_options)) { + rd_file_enum file_type = + rd_get_file_type(stringlist_iget(data_files, 0), NULL, NULL); + + if (file_type == RD_SUMMARY_FILE) + rd_sum_set_unified(rd_sum, false); + else if (file_type == RD_UNIFIED_SUMMARY_FILE) + rd_sum_set_unified(rd_sum, true); + else + util_abort("%s: FileTypeError, should be RD_SUMMARY_FILE OR " + "RD_UNIFIED_SUMMARY_FILE \n", + __func__); + } else + return false; + + if (include_restart && rd_smspec_get_restart_case(rd_sum->smspec)) + rd_sum_fread_history(rd_sum, lazy_load, file_options); + + return true; +} + +static bool rd_sum_fread_case(rd_sum_type *rd_sum, bool include_restart, + bool lazy_load, int file_options) { + char *header_file; + stringlist_type *summary_file_list = stringlist_alloc_new(); + + bool caseOK = false; + + rd_alloc_summary_files(rd_sum->path, rd_sum->base, rd_sum->ext, + &header_file, summary_file_list); + if ((header_file != NULL) && (stringlist_get_size(summary_file_list) > 0)) { + caseOK = rd_sum_fread(rd_sum, header_file, summary_file_list, + include_restart, lazy_load, file_options); + } + free(header_file); + stringlist_free(summary_file_list); + + return caseOK; +} + +/** + This will explicitly load the summary specified by @header_file and + @data_files, i.e. if the case has been restarted from another case, + it will NOT look for old summary information - that functionality + is only invoked when using rd_sum_fread_alloc_case() function; + however the list of data_files could in principle be achieved by + initializing the data_files list with files from the restarted + case. +*/ + +rd_sum_type *rd_sum_fread_alloc(const char *header_file, + const stringlist_type *data_files, + const char *key_join_string, + bool include_restart, bool lazy_load, + int file_options) { + rd_sum_type *rd_sum = rd_sum_alloc__(header_file, key_join_string); + if (rd_sum) { + if (!rd_sum_fread(rd_sum, header_file, data_files, include_restart, + lazy_load, file_options)) { + rd_sum_free(rd_sum); + rd_sum = NULL; + } + } + return rd_sum; +} + +void rd_sum_set_unified(rd_sum_type *rd_sum, bool unified) { + rd_sum->unified = unified; +} + +void rd_sum_set_fmt_case(rd_sum_type *rd_sum, bool fmt_case) { + rd_sum->fmt_case = fmt_case; +} + +const rd::smspec_node *rd_sum_add_var(rd_sum_type *rd_sum, const char *keyword, + const char *wgname, int num, + const char *unit, float default_value) { + if (rd_sum_data_get_length(rd_sum->data) > 0) + throw std::invalid_argument( + "Can not interchange variable adding and timesteps.\n"); + + return rd_smspec_add_node(rd_sum->smspec, keyword, wgname, num, unit, + default_value); +} + +const rd::smspec_node *rd_sum_add_smspec_node(rd_sum_type *rd_sum, + const rd::smspec_node *node) { + return rd_smspec_add_node(rd_sum->smspec, *node); +} + +/* + Observe the time argument in rd_sum_add_tstep() and the bool flag + time_in_days in rd_sum_alloc_writer() can be misleading: + + - The time argument 'sim_seconds' to rd_sum_add_tstep() should + *ALWAYS* be in seconds. + + - The 'sim_in_days' argument to the rd_sum_alloc_writer( ) is just + a very very basic unit support in the output. If sim_in_days == + true the output time unit will be days, otherwise it will be hours. +*/ + +rd_sum_tstep_type *rd_sum_add_tstep(rd_sum_type *rd_sum, int report_step, + double sim_seconds) { + rd_sum_tstep_type *new_tstep = + rd_sum_data_add_new_tstep(rd_sum->data, report_step, sim_seconds); + return new_tstep; +} + +static rd_sum_type * +rd_sum_alloc_writer__(const char *rd_case, const char *restart_case, + int restart_step, bool fmt_output, bool unified, + const char *key_join_string, time_t sim_start, + bool time_in_days, int nx, int ny, int nz) { + + rd_sum_type *rd_sum = rd_sum_alloc__(rd_case, key_join_string); + if (rd_sum) { + rd_sum_set_unified(rd_sum, unified); + rd_sum_set_fmt_case(rd_sum, fmt_output); + + if (restart_case) + rd_sum->smspec = rd_smspec_alloc_restart_writer( + key_join_string, restart_case, restart_step, sim_start, + time_in_days, nx, ny, nz); + else + rd_sum->smspec = rd_smspec_alloc_writer(key_join_string, sim_start, + time_in_days, nx, ny, nz); + + rd_sum->data = rd_sum_data_alloc_writer(rd_sum->smspec); + } + return rd_sum; +} + +rd_sum_type * +rd_sum_alloc_restart_writer2(const char *rd_case, const char *restart_case, + int restart_step, bool fmt_output, bool unified, + const char *key_join_string, time_t sim_start, + bool time_in_days, int nx, int ny, int nz) { + return rd_sum_alloc_writer__(rd_case, restart_case, restart_step, + fmt_output, unified, key_join_string, + sim_start, time_in_days, nx, ny, nz); +} + +/* + This does not take in the restart_step argument is depcrecated. You should use the + rd_sum_alloc_restart_writer2() function. +*/ + +rd_sum_type *rd_sum_alloc_restart_writer(const char *rd_case, + const char *restart_case, + bool fmt_output, bool unified, + const char *key_join_string, + time_t sim_start, bool time_in_days, + int nx, int ny, int nz) { + int restart_step = 0; + return rd_sum_alloc_writer__(rd_case, restart_case, restart_step, + fmt_output, unified, key_join_string, + sim_start, time_in_days, nx, ny, nz); +} + +rd_sum_type *rd_sum_alloc_writer(const char *rd_case, bool fmt_output, + bool unified, const char *key_join_string, + time_t sim_start, bool time_in_days, int nx, + int ny, int nz) { + return rd_sum_alloc_writer__(rd_case, NULL, 0, fmt_output, unified, + key_join_string, sim_start, time_in_days, nx, + ny, nz); +} + +void rd_sum_fwrite(const rd_sum_type *rd_sum) { + rd_sum_fwrite_smspec(rd_sum); + rd_sum_data_fwrite(rd_sum->data, rd_sum->rd_case, rd_sum->fmt_case, + rd_sum->unified); +} + +bool rd_sum_can_write(const rd_sum_type *rd_sum) { + return rd_sum_data_can_write(rd_sum->data); +} + +void rd_sum_fwrite_smspec(const rd_sum_type *rd_sum) { + rd_smspec_fwrite(rd_sum->smspec, rd_sum->rd_case, rd_sum->fmt_case); +} + +/** + This function frees the data from the rd_sum instance and sets the + data pointer to NULL. The SMSPEC data is still valid, and can be + reused with calls to rd_sum_fread_realloc_data(). +*/ + +void rd_sum_free_data(rd_sum_type *rd_sum) { + rd_sum_data_free(rd_sum->data); + rd_sum->data = NULL; +} + +void rd_sum_free(rd_sum_type *rd_sum) { + if (rd_sum->restart_case) + rd_sum_free(rd_sum->restart_case); + + if (rd_sum->data) + rd_sum_free_data(rd_sum); + + if (rd_sum->smspec) + rd_smspec_free(rd_sum->smspec); + + free(rd_sum->path); + free(rd_sum->ext); + free(rd_sum->abs_path); + + free(rd_sum->base); + free(rd_sum->rd_case); + + free(rd_sum->key_join_string); + free(rd_sum); +} + +void rd_sum_free__(void *__rd_sum) { + rd_sum_type *rd_sum = rd_sum_safe_cast(__rd_sum); + rd_sum_free(rd_sum); +} + +/** + This function takes an input file, and loads the corresponding + summary. The function extracts the path part, and the basename from + the input file. The extension is not considered (the input need not + even be a valid file). In principle a simulation directory with a + given basename can contain four different simulation cases: + + * Formatted and unformatted. + * Unified and not unified. + + The program will load the most recent dataset, by looking at the + modification time stamps of the files; if no simulation case is + found the function will return NULL. + + If the SMSPEC file contains the RESTART keyword the function will + iterate backwards to load summary information from previous runs + (this is goverened by the local variable include_restart). +*/ + +rd_sum_type *rd_sum_fread_alloc_case2__(const char *input_file, + const char *key_join_string, + bool include_restart, bool lazy_load, + int file_options) { + rd_sum_type *rd_sum = rd_sum_alloc__(input_file, key_join_string); + if (!rd_sum) + return NULL; + + if (rd_sum_fread_case(rd_sum, include_restart, lazy_load, file_options)) + return rd_sum; + else { + /* + Loading a case failed - we discard the partly initialized + rd_sum structure and jump ship. + */ + rd_sum_free(rd_sum); + return NULL; + } +} + +rd_sum_type *rd_sum_fread_alloc_case__(const char *input_file, + const char *key_join_string, + bool include_restart) { + bool lazy_load = true; + int file_options = 0; + return rd_sum_fread_alloc_case2__(input_file, key_join_string, + include_restart, lazy_load, file_options); +} + +rd_sum_type *rd_sum_fread_alloc_case(const char *input_file, + const char *key_join_string) { + bool include_restart = true; + bool lazy_load = true; + int file_options = 0; + return rd_sum_fread_alloc_case2__(input_file, key_join_string, + include_restart, lazy_load, file_options); +} + +bool rd_sum_case_exists(const char *input_file) { + char *smspec_file = NULL; + stringlist_type *data_files = stringlist_alloc_new(); + char *path; + char *basename; + char *extension; + bool case_exists; + + util_alloc_file_components(input_file, &path, &basename, &extension); + case_exists = rd_alloc_summary_files(path, basename, extension, + &smspec_file, data_files); + + free(path); + free(basename); + free(extension); + free(smspec_file); + stringlist_free(data_files); + + return case_exists; +} + +double rd_sum_get_from_sim_time(const rd_sum_type *rd_sum, time_t sim_time, + const rd::smspec_node *node) { + return rd_sum_data_get_from_sim_time(rd_sum->data, sim_time, *node); +} + +double rd_sum_get_from_sim_days(const rd_sum_type *rd_sum, double sim_days, + const rd::smspec_node *node) { + return rd_sum_data_get_from_sim_days(rd_sum->data, sim_days, *node); +} + +double rd_sum_time2days(const rd_sum_type *rd_sum, time_t sim_time) { + return rd_sum_data_time2days(rd_sum->data, sim_time); +} + +bool rd_sum_has_well_var(const rd_sum_type *rd_sum, const char *well, + const char *var) { + return rd_smspec_has_well_var(rd_sum->smspec, well, var); +} + +double rd_sum_get_well_var(const rd_sum_type *rd_sum, int time_index, + const char *well, const char *var) { + int params_index = + rd_smspec_get_well_var_params_index(rd_sum->smspec, well, var); + return rd_sum_data_iget(rd_sum->data, time_index, params_index); +} + +double rd_sum_get_well_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *well, + const char *var) { + const rd::smspec_node &node = + rd_smspec_get_well_var_node(rd_sum->smspec, well, var); + return rd_sum_get_from_sim_time(rd_sum, sim_time, &node); +} + +double rd_sum_get_well_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *well, + const char *var) { + const rd::smspec_node &node = + rd_smspec_get_well_var_node(rd_sum->smspec, well, var); + return rd_sum_get_from_sim_days(rd_sum, sim_days, &node); +} + +bool rd_sum_has_group_var(const rd_sum_type *rd_sum, const char *group, + const char *var) { + return rd_smspec_has_group_var(rd_sum->smspec, group, var); +} + +double rd_sum_get_group_var(const rd_sum_type *rd_sum, int time_index, + const char *group, const char *var) { + int params_index = + rd_smspec_get_group_var_params_index(rd_sum->smspec, group, var); + return rd_sum_data_iget(rd_sum->data, time_index, params_index); +} + +double rd_sum_get_group_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *group, + const char *var) { + const rd::smspec_node &node = + rd_smspec_get_group_var_node(rd_sum->smspec, group, var); + return rd_sum_get_from_sim_time(rd_sum, sim_time, &node); +} + +double rd_sum_get_group_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *group, + const char *var) { + const rd::smspec_node &node = + rd_smspec_get_group_var_node(rd_sum->smspec, group, var); + return rd_sum_get_from_sim_days(rd_sum, sim_days, &node); +} + +bool rd_sum_has_field_var(const rd_sum_type *rd_sum, const char *var) { + return rd_smspec_has_field_var(rd_sum->smspec, var); +} + +double rd_sum_get_field_var(const rd_sum_type *rd_sum, int time_index, + const char *var) { + int params_index = + rd_smspec_get_field_var_params_index(rd_sum->smspec, var); + return rd_sum_data_iget(rd_sum->data, time_index, params_index); +} + +double rd_sum_get_field_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *var) { + const rd::smspec_node &node = + rd_smspec_get_field_var_node(rd_sum->smspec, var); + return rd_sum_get_from_sim_time(rd_sum, sim_time, &node); +} + +double rd_sum_get_field_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *var) { + const rd::smspec_node &node = + rd_smspec_get_field_var_node(rd_sum->smspec, var); + return rd_sum_get_from_sim_days(rd_sum, sim_days, &node); +} + +bool rd_sum_has_block_var(const rd_sum_type *rd_sum, const char *block_var, + int block_nr) { + return rd_smspec_has_block_var(rd_sum->smspec, block_var, block_nr); +} + +double rd_sum_get_block_var(const rd_sum_type *rd_sum, int time_index, + const char *block_var, int block_nr) { + int params_index = rd_smspec_get_block_var_params_index( + rd_sum->smspec, block_var, block_nr); + return rd_sum_data_iget(rd_sum->data, time_index, params_index); +} + +int rd_sum_get_block_var_index_ijk(const rd_sum_type *rd_sum, + const char *block_var, int i, int j, int k) { + return rd_smspec_get_block_var_params_index_ijk(rd_sum->smspec, block_var, + i, j, k); +} + +bool rd_sum_has_block_var_ijk(const rd_sum_type *rd_sum, const char *block_var, + int i, int j, int k) { + return rd_smspec_has_block_var_ijk(rd_sum->smspec, block_var, i, j, k); +} + +double rd_sum_get_block_var_ijk(const rd_sum_type *rd_sum, int time_index, + const char *block_var, int i, int j, int k) { + int index = rd_sum_get_block_var_index_ijk(rd_sum, block_var, i, j, k); + return rd_sum_data_iget(rd_sum->data, time_index, index); +} + +double rd_sum_get_block_var_ijk_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, + const char *block_var, int i, + int j, int k) { + const rd::smspec_node &node = + rd_smspec_get_block_var_node_ijk(rd_sum->smspec, block_var, i, j, k); + return rd_sum_get_from_sim_time(rd_sum, sim_time, &node); +} + +double rd_sum_get_block_var_ijk_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, + const char *block_var, int i, + int j, int k) { + const rd::smspec_node &node = + rd_smspec_get_block_var_node_ijk(rd_sum->smspec, block_var, i, j, k); + return rd_sum_get_from_sim_days(rd_sum, sim_days, &node); +} + +/** + region_nr: [1...num_regions] (NOT C-based indexing) +*/ + +bool rd_sum_has_region_var(const rd_sum_type *rd_sum, const char *var, + int region_nr) { + return rd_smspec_has_region_var(rd_sum->smspec, var, region_nr); +} + +double rd_sum_get_region_var(const rd_sum_type *rd_sum, int time_index, + const char *var, int region_nr) { + int params_index = + rd_smspec_get_region_var_params_index(rd_sum->smspec, var, region_nr); + return rd_sum_data_iget(rd_sum->data, time_index, params_index); +} + +double rd_sum_get_region_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *var, + int region_nr) { + const rd::smspec_node &node = + rd_smspec_get_region_var_node(rd_sum->smspec, var, region_nr); + return rd_sum_get_from_sim_time(rd_sum, sim_time, &node); +} + +double rd_sum_get_region_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *var, + int region_nr) { + const rd::smspec_node &node = + rd_smspec_get_region_var_node(rd_sum->smspec, var, region_nr); + return rd_sum_get_from_sim_days(rd_sum, sim_days, &node); +} + +int rd_sum_get_misc_var_index(const rd_sum_type *rd_sum, const char *var) { + return rd_smspec_get_misc_var_params_index(rd_sum->smspec, var); +} + +bool rd_sum_has_misc_var(const rd_sum_type *rd_sum, const char *var) { + return rd_smspec_has_misc_var(rd_sum->smspec, var); +} + +double rd_sum_get_misc_var(const rd_sum_type *rd_sum, int time_index, + const char *var) { + int index = rd_sum_get_misc_var_index(rd_sum, var); + return rd_sum_data_iget(rd_sum->data, time_index, index); +} + +int rd_sum_get_well_completion_var_index(const rd_sum_type *rd_sum, + const char *well, const char *var, + int cell_nr) { + return rd_smspec_get_well_completion_var_params_index(rd_sum->smspec, well, + var, cell_nr); +} + +bool rd_sum_has_well_completion_var(const rd_sum_type *rd_sum, const char *well, + const char *var, int cell_nr) { + return rd_smspec_has_well_completion_var(rd_sum->smspec, well, var, + cell_nr); +} + +double rd_sum_get_well_completion_var(const rd_sum_type *rd_sum, int time_index, + const char *well, const char *var, + int cell_nr) { + int index = + rd_sum_get_well_completion_var_index(rd_sum, well, var, cell_nr); + return rd_sum_data_iget(rd_sum->data, time_index, index); +} + +const rd::smspec_node *rd_sum_get_general_var_node(const rd_sum_type *rd_sum, + const char *lookup_kw) { + const rd::smspec_node &node = + rd_smspec_get_general_var_node(rd_sum->smspec, lookup_kw); + return &node; +} + +int rd_sum_get_general_var_params_index(const rd_sum_type *rd_sum, + const char *lookup_kw) { + return rd_smspec_get_general_var_params_index(rd_sum->smspec, lookup_kw); +} + +bool rd_sum_has_general_var(const rd_sum_type *rd_sum, const char *lookup_kw) { + return rd_smspec_has_general_var(rd_sum->smspec, lookup_kw); +} + +bool rd_sum_has_key(const rd_sum_type *rd_sum, const char *lookup_kw) { + return rd_sum_has_general_var(rd_sum, lookup_kw); +} + +double rd_sum_get_general_var(const rd_sum_type *rd_sum, int time_index, + const char *lookup_kw) { + int params_index = rd_sum_get_general_var_params_index(rd_sum, lookup_kw); + return rd_sum_data_iget(rd_sum->data, time_index, params_index); +} + +#ifdef __cplusplus +extern "C" { + +void rd_sum_get_interp_vector(const rd_sum_type *rd_sum, time_t sim_time, + const rd_sum_vector_type *key_words, + double_vector_type *data) { + rd_sum_data_get_interp_vector(rd_sum->data, sim_time, key_words, data); +} + +void rd_sum_fwrite_interp_csv_line(const rd_sum_type *rd_sum, time_t sim_time, + const rd_sum_vector_type *key_words, + FILE *fp) { + rd_sum_data_fwrite_interp_csv_line(rd_sum->data, sim_time, key_words, fp); +} +} +#endif + +double rd_sum_get_general_var_from_sim_time(const rd_sum_type *rd_sum, + time_t sim_time, const char *var) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, var); + return rd_sum_get_from_sim_time(rd_sum, sim_time, node); +} + +double rd_sum_get_general_var_from_sim_days(const rd_sum_type *rd_sum, + double sim_days, const char *var) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, var); + return rd_sum_data_get_from_sim_days(rd_sum->data, sim_days, *node); +} + +const char *rd_sum_get_general_var_unit(const rd_sum_type *rd_sum, + const char *var) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, var); + return smspec_node_get_unit(node); +} + +rd_sum_type *rd_sum_alloc_resample(const rd_sum_type *rd_sum, + const char *rd_case, + const time_t_vector_type *times, + bool lower_extrapolation, + bool upper_extrapolation) { + /* + If lower and / or upper extrapolation is set to true it makes sure that resampling returns the first / last value of the simulation + or in the case of derivate / rate then it gets zero. if these are set to false, we jus throw exception + */ + + time_t start_time = rd_sum_get_data_start(rd_sum); + time_t end_time = rd_sum_get_end_time(rd_sum); + time_t input_start = time_t_vector_get_first(times); + time_t input_end = time_t_vector_get_last(times); + + if (!lower_extrapolation && input_start < start_time) + return NULL; + if (!upper_extrapolation && input_end > end_time) + return NULL; + if (!time_t_vector_is_sorted(times, false)) + return NULL; + + const int *grid_dims = rd_smspec_get_grid_dims(rd_sum->smspec); + + bool time_in_days = false; + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(rd_sum->smspec, 0); + if (util_string_equal(smspec_node_get_unit(&node), "DAYS")) + time_in_days = true; + + //create elc_sum_resampled with TIME node only + rd_sum_type *rd_sum_resampled = rd_sum_alloc_writer( + rd_case, rd_sum->fmt_case, rd_sum->unified, rd_sum->key_join_string, + input_start, time_in_days, grid_dims[0], grid_dims[1], grid_dims[2]); + + //add remaining nodes + for (int i = 0; i < rd_smspec_num_nodes(rd_sum->smspec); i++) { + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(rd_sum->smspec, i); + if (util_string_equal(smspec_node_get_gen_key1(&node), "TIME")) + continue; + + rd_sum_add_smspec_node(rd_sum_resampled, &node); + } + + /* + The SMSPEC header structure has been completely initialized, it is time to + start filling it up with data. + + */ + rd_sum_vector_type *rd_sum_vector = rd_sum_vector_alloc(rd_sum, true); + double_vector_type *data = + double_vector_alloc(rd_sum_vector_get_size(rd_sum_vector), 0); + + for (int report_step = 0; report_step < time_t_vector_size(times); + report_step++) { + time_t input_t = time_t_vector_iget(times, report_step); + if (input_t < start_time) { + //clamping to the first value for t < start_time or if it is a rate than derivative is 0 + for (int i = 1; i < rd_smspec_num_nodes(rd_sum->smspec); i++) { + double value = 0; + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(rd_sum->smspec, i); + if (!node.is_rate()) + value = rd_sum_iget_first_value(rd_sum, + node.get_params_index()); + double_vector_iset(data, i - 1, value); + } + } else if (input_t > end_time) { + //clamping to the last value for t > end_time or if it is a rate than derivative is 0 + for (int i = 1; i < rd_smspec_num_nodes(rd_sum->smspec); i++) { + double value = 0; + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(rd_sum->smspec, i); + if (!node.is_rate()) + value = + rd_sum_iget_last_value(rd_sum, node.get_params_index()); + double_vector_iset(data, i - 1, value); + } + } else { + /* Look up interpolated data in the original case. */ + rd_sum_get_interp_vector(rd_sum, input_t, rd_sum_vector, data); + } + + /* Add timestep corresponding to the interpolated data in the resampled case. */ + rd_sum_tstep_type *tstep = rd_sum_add_tstep( + rd_sum_resampled, report_step, input_t - input_start); + for (int data_index = 0; + data_index < rd_sum_vector_get_size(rd_sum_vector); data_index++) { + double value = double_vector_iget(data, data_index); + int params_index = + data_index + + 1; // The +1 shift is because the first element in the tstep is time value. + rd_sum_tstep_iset(tstep, params_index, value); + } + } + double_vector_free(data); + rd_sum_vector_free(rd_sum_vector); + return rd_sum_resampled; +} + +double rd_sum_iget(const rd_sum_type *rd_sum, int time_index, int param_index) { + return rd_sum_data_iget(rd_sum->data, time_index, param_index); +} + +bool rd_sum_var_is_rate(const rd_sum_type *rd_sum, const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_is_rate(node); +} + +bool rd_sum_var_is_total(const rd_sum_type *rd_sum, const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_is_total(node); +} + +rd_smspec_var_type rd_sum_identify_var_type(const char *var) { + return rd_smspec_identify_var_type(var); +} + +rd_smspec_var_type rd_sum_get_var_type(const rd_sum_type *rd_sum, + const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_get_var_type(node); +} + +const char *rd_sum_get_unit(const rd_sum_type *rd_sum, const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_get_unit(node); +} + +int rd_sum_get_num(const rd_sum_type *rd_sum, const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_get_num(node); +} + +const char *rd_sum_get_wgname(const rd_sum_type *rd_sum, const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_get_wgname(node); +} + +const char *rd_sum_get_keyword(const rd_sum_type *rd_sum, const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return smspec_node_get_keyword(node); +} + +bool rd_sum_has_report_step(const rd_sum_type *rd_sum, int report_step) { + return rd_sum_data_has_report_step(rd_sum->data, report_step); +} + +int rd_sum_get_last_report_step(const rd_sum_type *rd_sum) { + return rd_sum_data_get_last_report_step(rd_sum->data); +} + +int rd_sum_get_first_report_step(const rd_sum_type *rd_sum) { + return rd_sum_data_get_first_report_step(rd_sum->data); +} + +int rd_sum_iget_report_end(const rd_sum_type *rd_sum, int report_step) { + return rd_sum_data_iget_report_end(rd_sum->data, report_step); +} + +int rd_sum_iget_report_step(const rd_sum_type *rd_sum, int internal_index) { + return rd_sum_data_iget_report_step(rd_sum->data, internal_index); +} + +time_t_vector_type *rd_sum_alloc_time_vector(const rd_sum_type *rd_sum, + bool report_only) { + return rd_sum_data_alloc_time_vector(rd_sum->data, report_only); +} + +void rd_sum_init_double_vector__(const rd_sum_type *rd_sum, int params_index, + double *data) { + rd_sum_data_init_double_vector(rd_sum->data, params_index, data); +} + +void rd_sum_init_double_vector(const rd_sum_type *rd_sum, const char *gen_key, + double *data) { + int params_index = rd_sum_get_general_var_params_index(rd_sum, gen_key); + rd_sum_init_double_vector__(rd_sum, params_index, data); +} + +void rd_sum_init_double_vector_interp(const rd_sum_type *rd_sum, + const char *gen_key, + const time_t_vector_type *time_points, + double *data) { + const rd::smspec_node &node = + rd_smspec_get_general_var_node(rd_sum->smspec, gen_key); + rd_sum_data_init_double_vector_interp(rd_sum->data, node, time_points, + data); +} + +void rd_sum_init_datetime64_vector(const rd_sum_type *rd_sum, int64_t *data, + int multiplier) { + rd_sum_data_init_datetime64_vector(rd_sum->data, data, multiplier); +} + +void rd_sum_init_double_frame(const rd_sum_type *rd_sum, + const rd_sum_vector_type *keywords, + double *data) { + rd_sum_data_init_double_frame(rd_sum->data, keywords, data); +} + +void rd_sum_init_double_frame_interp(const rd_sum_type *rd_sum, + const rd_sum_vector_type *keywords, + const time_t_vector_type *time_points, + double *data) { + rd_sum_data_init_double_frame_interp(rd_sum->data, keywords, time_points, + data); +} + +double_vector_type *rd_sum_alloc_data_vector(const rd_sum_type *rd_sum, + int data_index, bool report_only) { + return rd_sum_data_alloc_data_vector(rd_sum->data, data_index, report_only); +} + +void rd_sum_summarize(const rd_sum_type *rd_sum, FILE *stream) { + rd_sum_data_summarize(rd_sum->data, stream); +} + +/** + Returns the first internal index where a limiting value is + reached. If the limiting value is never reached, -1 is + returned. The smspec_index should be calculated first with one of + the + + rd_sum_get_XXXX_index() + + functions. I.e. the following code will give the first index where + the water wut in well PX exceeds 0.25: + + { + int smspec_index = rd_sum_get_well_var( rd_sum , "PX" , "WWCT" ); + int first_index = rd_sum_get_first_gt( rd_sum , smspec_index , 0.25); + } + +*/ + +static int rd_sum_get_limiting(const rd_sum_type *rd_sum, int smspec_index, + double limit, bool gt) { + const int length = rd_sum_data_get_length(rd_sum->data); + int internal_index = 0; + do { + double value = + rd_sum_data_iget(rd_sum->data, internal_index, smspec_index); + if (gt) { + if (value > limit) + break; + } else { + if (value < limit) + break; + } + internal_index++; + } while (internal_index < length); + + if (internal_index == length) /* Did not find it */ + internal_index = -1; + + return internal_index; +} + +int rd_sum_get_first_gt(const rd_sum_type *rd_sum, int param_index, + double limit) { + return rd_sum_get_limiting(rd_sum, param_index, limit, true); +} + +int rd_sum_get_first_lt(const rd_sum_type *rd_sum, int param_index, + double limit) { + return rd_sum_get_limiting(rd_sum, param_index, limit, false); +} + +time_t rd_sum_get_report_time(const rd_sum_type *rd_sum, int report_step) { + return rd_sum_data_get_report_time(rd_sum->data, report_step); +} + +time_t rd_sum_iget_sim_time(const rd_sum_type *rd_sum, int index) { + return rd_sum_data_iget_sim_time(rd_sum->data, index); +} + +time_t rd_sum_get_data_start(const rd_sum_type *rd_sum) { + return rd_sum_data_get_data_start(rd_sum->data); +} + +time_t rd_sum_get_start_time(const rd_sum_type *rd_sum) { + return rd_smspec_get_start_time(rd_sum->smspec); +} + +time_t rd_sum_get_end_time(const rd_sum_type *rd_sum) { + try { + return rd_sum_data_get_sim_end(rd_sum->data); + } catch (std::out_of_range) { + return rd_smspec_get_start_time(rd_sum->smspec); + } +} + +double rd_sum_iget_sim_days(const rd_sum_type *rd_sum, int index) { + return rd_sum_data_iget_sim_days(rd_sum->data, index); +} + +void rd_sum_fmt_init_summary_x(const rd_sum_type *rd_sum, + rd_sum_fmt_type *fmt) { + fmt->locale = NULL; + fmt->sep = ""; + fmt->date_fmt = "%d/%m/%Y "; + fmt->value_fmt = " %15.6g "; + + if (util_string_equal(rd_sum_get_unit(rd_sum, "TIME"), "DAYS")) + fmt->days_fmt = "%7.2f "; + else + fmt->days_fmt = "%7.4f "; + + fmt->header_fmt = " %15s "; + + fmt->newline = "\n"; + fmt->print_header = true; + fmt->print_dash = true; + fmt->date_dash = "-----------------------"; + fmt->value_dash = "-----------------"; + fmt->date_header = "-- Days dd/mm/yyyy "; +} + +/*#define DAYS_DATE_FORMAT "%7.2f %02d/%02d/%04d " +#define FLOAT_FORMAT " %15.6g " +#define HEADER_FORMAT " %15s " +#define DATE_DASH "-----------------------" +#define FLOAT_DASH "-----------------" +*/ + +#define DATE_HEADER "-- Days dd/mm/yyyy " +#define DATE_STRING_LENGTH 128 + +static void __rd_sum_fprintf_line(const rd_sum_type *rd_sum, FILE *stream, + int internal_index, + const bool_vector_type *has_var, + const int_vector_type *var_index, + char *date_string, + const rd_sum_fmt_type *fmt) { + fprintf(stream, fmt->days_fmt, + rd_sum_iget_sim_days(rd_sum, internal_index)); + fprintf(stream, "%s", fmt->sep); + + { + struct tm ts; + time_t sim_time = rd_sum_iget_sim_time(rd_sum, internal_index); + util_time_utc(&sim_time, &ts); + strftime(date_string, DATE_STRING_LENGTH - 1, fmt->date_fmt, &ts); + fprintf(stream, "%s", date_string); + } + + { + int ivar; + for (ivar = 0; ivar < int_vector_size(var_index); ivar++) { + if (bool_vector_iget(has_var, ivar)) { + fprintf(stream, "%s", fmt->sep); + fprintf(stream, fmt->value_fmt, + rd_sum_iget(rd_sum, internal_index, + int_vector_iget(var_index, ivar))); + } + } + } + + fprintf(stream, "%s", fmt->newline); +} + +static void rd_sum_fprintf_header(const rd_sum_type *rd_sum, + const stringlist_type *key_list, + const bool_vector_type *has_var, FILE *stream, + const rd_sum_fmt_type *fmt) { + fprintf(stream, "%s", fmt->date_header); + { + int i; + for (i = 0; i < stringlist_get_size(key_list); i++) + if (bool_vector_iget(has_var, i)) { + fprintf(stream, "%s", fmt->sep); + fprintf(stream, fmt->header_fmt, stringlist_iget(key_list, i)); + } + } + + fprintf(stream, "%s", fmt->newline); + if (fmt->print_dash) { + fprintf(stream, "%s", fmt->date_dash); + + { + int i; + for (i = 0; i < stringlist_get_size(key_list); i++) + if (bool_vector_iget(has_var, i)) + fprintf(stream, "%s", fmt->value_dash); + } + fprintf(stream, "%s", fmt->newline); + } +} + +void rd_sum_fprintf(const rd_sum_type *rd_sum, FILE *stream, + const stringlist_type *var_list, bool report_only, + const rd_sum_fmt_type *fmt) { + bool_vector_type *has_var = + bool_vector_alloc(stringlist_get_size(var_list), false); + int_vector_type *var_index = + int_vector_alloc(stringlist_get_size(var_list), -1); + char *date_string = + (char *)util_malloc(DATE_STRING_LENGTH * sizeof *date_string); + + char *current_locale = NULL; + if (fmt->locale != NULL) + current_locale = setlocale(LC_NUMERIC, fmt->locale); + + { + int ivar; + for (ivar = 0; ivar < stringlist_get_size(var_list); ivar++) { + if (rd_sum_has_general_var(rd_sum, + stringlist_iget(var_list, ivar))) { + bool_vector_iset(has_var, ivar, true); + int_vector_iset(var_index, ivar, + rd_sum_get_general_var_params_index( + rd_sum, stringlist_iget(var_list, ivar))); + } else { + fprintf(stderr, + "** Warning: could not find variable: \'%s\' in " + "summary file \n", + stringlist_iget(var_list, ivar)); + bool_vector_iset(has_var, ivar, false); + } + } + } + + if (fmt->print_header) + rd_sum_fprintf_header(rd_sum, var_list, has_var, stream, fmt); + + if (report_only) { + int first_report = rd_sum_get_first_report_step(rd_sum); + int last_report = rd_sum_get_last_report_step(rd_sum); + int report; + + for (report = first_report; report <= last_report; report++) { + if (rd_sum_data_has_report_step(rd_sum->data, report)) { + int time_index; + time_index = rd_sum_data_iget_report_end(rd_sum->data, report); + __rd_sum_fprintf_line(rd_sum, stream, time_index, has_var, + var_index, date_string, fmt); + } + } + } else { + int time_index; + for (time_index = 0; time_index < rd_sum_get_data_length(rd_sum); + time_index++) + __rd_sum_fprintf_line(rd_sum, stream, time_index, has_var, + var_index, date_string, fmt); + } + + int_vector_free(var_index); + bool_vector_free(has_var); + if (current_locale != NULL) + setlocale(LC_NUMERIC, current_locale); + free(date_string); +} +#undef DATE_STRING_LENGTH + +static void rd_sum_fmt_init_csv(rd_sum_fmt_type *fmt, const char *date_format, + const char *date_header, const char *sep) { + fmt->locale = NULL; //"Norwegian"; + fmt->sep = sep; + fmt->date_fmt = date_format; + fmt->value_fmt = "%g"; + fmt->days_fmt = "%7.2f"; + fmt->header_fmt = "%s"; + + fmt->newline = "\r\n"; + fmt->date_header = date_header; + fmt->print_header = true; + fmt->print_dash = false; +} + +void rd_sum_export_csv(const rd_sum_type *rd_sum, const char *filename, + const stringlist_type *var_list, const char *date_format, + const char *sep) { + FILE *stream = util_mkdir_fopen(filename, "w"); + char *date_header = util_alloc_sprintf("DAYS%sDATE", sep); + bool report_only = false; + rd_sum_fmt_type fmt; + rd_sum_fmt_init_csv(&fmt, date_format, date_header, sep); + rd_sum_fprintf(rd_sum, stream, var_list, report_only, &fmt); + fclose(stream); + free(date_header); +} + +const rd_sum_type *rd_sum_get_restart_case(const rd_sum_type *rd_sum) { + return rd_sum->restart_case; +} + +int rd_sum_get_restart_step(const rd_sum_type *rd_sum) { + return rd_smspec_get_restart_step(rd_sum->smspec); +} + +const char *rd_sum_get_case(const rd_sum_type *rd_sum) { + return rd_sum->rd_case; +} + +const char *rd_sum_get_path(const rd_sum_type *rd_sum) { return rd_sum->path; } + +const char *rd_sum_get_abs_path(const rd_sum_type *rd_sum) { + return rd_sum->abs_path; +} + +const char *rd_sum_get_base(const rd_sum_type *rd_sum) { return rd_sum->base; } + +/** + This function will check if the currently loaded case corresponds + to the case specified by @input_file. The extension of @input file + can be arbitrary (or nonexistent) and will be ignored (this can + lead to errors with formatted/unformatted mixup if the simulation + directory has been changed after the rd_sum instance has been + loaded). +*/ + +bool rd_sum_same_case(const rd_sum_type *rd_sum, const char *input_file) { + bool same_case = false; + { + char *path; + char *base; + + util_alloc_file_components(input_file, &path, &base, NULL); + { + bool fmt_file = rd_smspec_get_formatted(rd_sum->smspec); + char *header_file = rd_alloc_exfilename( + path, base, RD_SUMMARY_HEADER_FILE, fmt_file, -1); + if (header_file != NULL) { + same_case = util_same_file( + header_file, rd_smspec_get_header_file(rd_sum->smspec)); + free(header_file); + } + } + + free(path); + free(base); + } + return same_case; +} + +stringlist_type * +rd_sum_alloc_matching_general_var_list(const rd_sum_type *rd_sum, + const char *pattern) { + return rd_smspec_alloc_matching_general_var_list(rd_sum->smspec, pattern); +} + +void rd_sum_select_matching_general_var_list(const rd_sum_type *rd_sum, + const char *pattern, + stringlist_type *keys) { + rd_smspec_select_matching_general_var_list(rd_sum->smspec, pattern, keys); +} + +stringlist_type *rd_sum_alloc_well_list(const rd_sum_type *rd_sum, + const char *pattern) { + return rd_smspec_alloc_well_list(rd_sum->smspec, pattern); +} + +stringlist_type *rd_sum_alloc_group_list(const rd_sum_type *rd_sum, + const char *pattern) { + return rd_smspec_alloc_group_list(rd_sum->smspec, pattern); +} + +stringlist_type *rd_sum_alloc_well_var_list(const rd_sum_type *rd_sum) { + return rd_smspec_alloc_well_var_list(rd_sum->smspec); +} + +void rd_sum_resample_from_sim_time(const rd_sum_type *rd_sum, + const time_t_vector_type *sim_time, + double_vector_type *value, + const char *gen_key) { + const rd::smspec_node &node = + rd_smspec_get_general_var_node(rd_sum->smspec, gen_key); + double_vector_reset(value); + { + int i; + for (i = 0; i < time_t_vector_size(sim_time); i++) + double_vector_iset( + value, i, + rd_sum_data_get_from_sim_time( + rd_sum->data, time_t_vector_iget(sim_time, i), node)); + } +} + +void rd_sum_resample_from_sim_days(const rd_sum_type *rd_sum, + const double_vector_type *sim_days, + double_vector_type *value, + const char *gen_key) { + const rd::smspec_node &node = + rd_smspec_get_general_var_node(rd_sum->smspec, gen_key); + double_vector_reset(value); + { + int i; + for (i = 0; i < double_vector_size(sim_days); i++) + double_vector_iset( + value, i, + rd_sum_data_get_from_sim_days( + rd_sum->data, double_vector_iget(sim_days, i), node)); + } +} + +time_t rd_sum_time_from_days(const rd_sum_type *rd_sum, double sim_days) { + time_t t = rd_smspec_get_start_time(rd_sum->smspec); + util_inplace_forward_days_utc(&t, sim_days); + return t; +} + +double rd_sum_days_from_time(const rd_sum_type *rd_sum, time_t sim_time) { + double seconds_diff = + util_difftime(rd_smspec_get_start_time(rd_sum->smspec), sim_time, NULL, + NULL, NULL, NULL); + return seconds_diff * 1.0 / (3600 * 24.0); +} + +double rd_sum_get_first_day(const rd_sum_type *rd_sum) { + return rd_sum_data_get_first_day(rd_sum->data); +} + +double rd_sum_get_sim_length(const rd_sum_type *rd_sum) { + return rd_sum_data_get_sim_length(rd_sum->data); +} + +/** + Will return the number of data blocks. +*/ +int rd_sum_get_data_length(const rd_sum_type *rd_sum) { + return rd_sum_data_get_length(rd_sum->data); +} + +bool rd_sum_check_sim_time(const rd_sum_type *sum, time_t sim_time) { + return rd_sum_data_check_sim_time(sum->data, sim_time); +} + +bool rd_sum_check_sim_days(const rd_sum_type *sum, double sim_days) { + return rd_sum_data_check_sim_days(sum->data, sim_days); +} + +int rd_sum_get_report_step_from_time(const rd_sum_type *sum, time_t sim_time) { + return rd_sum_data_get_report_step_from_time(sum->data, sim_time); +} + +int rd_sum_get_report_step_from_days(const rd_sum_type *sum, double sim_days) { + return rd_sum_data_get_report_step_from_days(sum->data, sim_days); +} + +rd_smspec_type *rd_sum_get_smspec(const rd_sum_type *rd_sum) { + return rd_sum->smspec; +} + +/* + The functions below are extremly simple functions which only serve + as an easy access to the smspec_alloc_xxx_key() functions which + know how to create the various composite keys. +*/ + +char *rd_sum_alloc_well_key(const rd_sum_type *rd_sum, const char *keyword, + const char *wgname) { + return rd_smspec_alloc_well_key(rd_sum->smspec, keyword, wgname); +} + +bool rd_sum_is_oil_producer(const rd_sum_type *rd_sum, const char *well) { + const char *WOPT_KEY = "WOPT"; + bool oil_producer = false; + + if (rd_sum_has_well_var(rd_sum, well, WOPT_KEY)) { + int last_step = rd_sum_get_data_length(rd_sum) - 1; + double wopt = rd_sum_get_well_var(rd_sum, last_step, well, WOPT_KEY); + + if (wopt > 0) + oil_producer = true; + } + + return oil_producer; +} + +bool rd_sum_report_step_equal(const rd_sum_type *rd_sum1, + const rd_sum_type *rd_sum2) { + if (rd_sum1 == rd_sum2) + return true; + else + return rd_sum_data_report_step_equal(rd_sum1->data, rd_sum2->data); +} + +bool rd_sum_report_step_compatible(const rd_sum_type *rd_sum1, + const rd_sum_type *rd_sum2) { + if (rd_sum1 == rd_sum2) + return true; + else + return rd_sum_data_report_step_compatible(rd_sum1->data, rd_sum2->data); +} + +double_vector_type *rd_sum_alloc_seconds_solution(const rd_sum_type *rd_sum, + const char *gen_key, + double cmp_value, + bool rates_clamp_lower) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return rd_sum_data_alloc_seconds_solution(rd_sum->data, *node, cmp_value, + rates_clamp_lower); +} + +double_vector_type *rd_sum_alloc_days_solution(const rd_sum_type *rd_sum, + const char *gen_key, + double cmp_value, + bool rates_clamp_lower) { + double_vector_type *solution = rd_sum_alloc_seconds_solution( + rd_sum, gen_key, cmp_value, rates_clamp_lower); + double_vector_scale(solution, 1.0 / 86400); + return solution; +} + +time_t_vector_type *rd_sum_alloc_time_solution(const rd_sum_type *rd_sum, + const char *gen_key, + double cmp_value, + bool rates_clamp_lower) { + time_t_vector_type *solution = time_t_vector_alloc(0, 0); + { + double_vector_type *seconds = rd_sum_alloc_seconds_solution( + rd_sum, gen_key, cmp_value, rates_clamp_lower); + time_t start_time = rd_sum_get_start_time(rd_sum); + for (int i = 0; i < double_vector_size(seconds); i++) { + time_t t = start_time; + util_inplace_forward_seconds_utc(&t, + double_vector_iget(seconds, i)); + time_t_vector_append(solution, t); + } + double_vector_free(seconds); + } + return solution; +} + +ert_rd_unit_enum rd_sum_get_unit_system(const rd_sum_type *rd_sum) { + return rd_smspec_get_unit_system(rd_sum->smspec); +} + +double rd_sum_iget_last_value(const rd_sum_type *rd_sum, int param_index) { + return rd_sum_data_iget_last_value(rd_sum->data, param_index); +} + +double rd_sum_get_last_value_gen_key(const rd_sum_type *rd_sum, + const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return rd_sum_iget_last_value(rd_sum, smspec_node_get_params_index(node)); +} + +double rd_sum_get_last_value_node(const rd_sum_type *rd_sum, + const rd::smspec_node *node) { + return rd_sum_iget_last_value(rd_sum, smspec_node_get_params_index(node)); +} + +double rd_sum_iget_first_value(const rd_sum_type *rd_sum, int param_index) { + return rd_sum_data_iget_first_value(rd_sum->data, param_index); +} + +double rd_sum_get_first_value_gen_key(const rd_sum_type *rd_sum, + const char *gen_key) { + const rd::smspec_node *node = rd_sum_get_general_var_node(rd_sum, gen_key); + return rd_sum_iget_first_value(rd_sum, smspec_node_get_params_index(node)); +} + +double rd_sum_get_first_value_node(const rd_sum_type *rd_sum, + const rd::smspec_node *node) { + return rd_sum_iget_first_value(rd_sum, smspec_node_get_params_index(node)); +} diff --git a/lib/ecl/ecl_sum_data.cpp b/lib/resdata/rd_sum_data.cpp similarity index 59% rename from lib/ecl/ecl_sum_data.cpp rename to lib/resdata/rd_sum_data.cpp index c1a2327111..e12150e07f 100644 --- a/lib/ecl/ecl_sum_data.cpp +++ b/lib/resdata/rd_sum_data.cpp @@ -13,37 +13,37 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "detail/ecl/ecl_sum_file_data.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "detail/resdata/rd_sum_file_data.hpp" /* - This file implements the sruct ecl_sum_data which manages the actual simulated + This file implements the sruct rd_sum_data which manages the actual simulated values from a summary file, including all time-related information. In the case of restarted simulations the different summary cases will be internalized - as separate ecl_sum_file_data instances. The ecl_sum_file_data class is an + as separate rd_sum_file_data instances. The rd_sum_file_data class is an internal implemenation detail which is not exported. More details about the internal storage of summary data can be found in that file. For this file the implementation mainly consists of maintaining an ordered - list of ecl_sum_file_data instances and dispatching method calls to the right - ecl_sum_file_data instance. + list of rd_sum_file_data instances and dispatching method calls to the right + rd_sum_file_data instance. */ namespace { /* The class CaseIndex and the struct IndexNode are used to maintain a list of - the ecl_sum_file_data instances, and lookup the correct one based one various + the rd_sum_file_data instances, and lookup the correct one based one various time related arguments. */ @@ -209,18 +209,18 @@ class CaseIndex { } // namespace -struct ecl_sum_data_struct { - const ecl_smspec_type *smspec; - std::vector - data_files; // List of ecl_sum_file_data instances +struct rd_sum_data_struct { + const rd_smspec_type *smspec; + std::vector + data_files; // List of rd_sum_file_data instances CaseIndex index; }; -static void ecl_sum_data_build_index(ecl_sum_data_type *self); -static double ecl_sum_data_iget_sim_seconds(const ecl_sum_data_type *data, - int internal_index); +static void rd_sum_data_build_index(rd_sum_data_type *self); +static double rd_sum_data_iget_sim_seconds(const rd_sum_data_type *data, + int internal_index); -void ecl_sum_data_free(ecl_sum_data_type *data) { +void rd_sum_data_free(rd_sum_data_type *data) { if (!data) throw std::invalid_argument(__func__ + std::string(": invalid delete")); @@ -230,18 +230,18 @@ void ecl_sum_data_free(ecl_sum_data_type *data) { delete data; } -ecl_sum_data_type *ecl_sum_data_alloc(ecl_smspec_type *smspec) { - ecl_sum_data_type *data = new ecl_sum_data_type(); +rd_sum_data_type *rd_sum_data_alloc(rd_smspec_type *smspec) { + rd_sum_data_type *data = new rd_sum_data_type(); data->smspec = smspec; return data; } -void ecl_sum_data_reset_self_map(ecl_sum_data_type *data) { - ecl_sum_data_build_index(data); +void rd_sum_data_reset_self_map(rd_sum_data_type *data) { + rd_sum_data_build_index(data); } -static void ecl_sum_data_append_file_data(ecl_sum_data_type *sum_data, - ecl::ecl_sum_file_data *file_data) { +static void rd_sum_data_append_file_data(rd_sum_data_type *sum_data, + rd::rd_sum_file_data *file_data) { sum_data->data_files.push_back(file_data); } @@ -263,37 +263,37 @@ static void ecl_sum_data_append_file_data(ecl_sum_data_type *sum_data, return values to -1 (the return value from safe_iget). In that case it is the responsability of the calling scope to check the return values, alternatively one can use the query function - ecl_sum_data_has_report_step() first. + rd_sum_data_has_report_step() first. */ -static double ecl_sum_data_iget_sim_seconds(const ecl_sum_data_type *data, - int internal_index) { +static double rd_sum_data_iget_sim_seconds(const rd_sum_data_type *data, + int internal_index) { const auto index_node = data->index.lookup(internal_index); const auto data_file = data->data_files[index_node.data_index]; return data_file->iget_sim_seconds(internal_index - index_node.offset); } -double ecl_sum_data_iget_sim_days(const ecl_sum_data_type *data, - int internal_index) { +double rd_sum_data_iget_sim_days(const rd_sum_data_type *data, + int internal_index) { const auto index_node = data->index.lookup(internal_index); const auto data_file = data->data_files[index_node.data_index]; return data_file->iget_sim_days(internal_index - index_node.offset); } -ecl_sum_data_type *ecl_sum_data_alloc_writer(ecl_smspec_type *smspec) { - ecl_sum_data_type *data = ecl_sum_data_alloc(smspec); - ecl::ecl_sum_file_data *file_data = new ecl::ecl_sum_file_data(smspec); - ecl_sum_data_append_file_data(data, file_data); - ecl_sum_data_build_index(data); +rd_sum_data_type *rd_sum_data_alloc_writer(rd_smspec_type *smspec) { + rd_sum_data_type *data = rd_sum_data_alloc(smspec); + rd::rd_sum_file_data *file_data = new rd::rd_sum_file_data(smspec); + rd_sum_data_append_file_data(data, file_data); + rd_sum_data_build_index(data); return data; } -static void ecl_sum_data_fwrite_unified(const ecl_sum_data_type *data, - const char *ecl_case, bool fmt_case) { - char *filename = ecl_util_alloc_filename( - NULL, ecl_case, ECL_UNIFIED_SUMMARY_FILE, fmt_case, 0); +static void rd_sum_data_fwrite_unified(const rd_sum_data_type *data, + const char *rd_case, bool fmt_case) { + char *filename = + rd_alloc_filename(NULL, rd_case, RD_UNIFIED_SUMMARY_FILE, fmt_case, 0); fortio_type *fortio = - fortio_open_writer(filename, fmt_case, ECL_ENDIAN_FLIP); + fortio_open_writer(filename, fmt_case, RD_ENDIAN_FLIP); for (size_t index = 0; index < data->data_files.size(); index++) data->data_files[index]->fwrite_unified(fortio); @@ -302,22 +302,22 @@ static void ecl_sum_data_fwrite_unified(const ecl_sum_data_type *data, free(filename); } -static void ecl_sum_data_fwrite_multiple(const ecl_sum_data_type *data, - const char *ecl_case, bool fmt_case) { +static void rd_sum_data_fwrite_multiple(const rd_sum_data_type *data, + const char *rd_case, bool fmt_case) { for (size_t index = 0; index < data->data_files.size(); index++) - data->data_files[index]->fwrite_multiple(ecl_case, fmt_case); + data->data_files[index]->fwrite_multiple(rd_case, fmt_case); } -void ecl_sum_data_fwrite(const ecl_sum_data_type *data, const char *ecl_case, - bool fmt_case, bool unified) { +void rd_sum_data_fwrite(const rd_sum_data_type *data, const char *rd_case, + bool fmt_case, bool unified) { if (unified) - ecl_sum_data_fwrite_unified(data, ecl_case, fmt_case); + rd_sum_data_fwrite_unified(data, rd_case, fmt_case); else - ecl_sum_data_fwrite_multiple(data, ecl_case, fmt_case); + rd_sum_data_fwrite_multiple(data, rd_case, fmt_case); } -bool ecl_sum_data_can_write(const ecl_sum_data_type *data) { +bool rd_sum_data_can_write(const rd_sum_data_type *data) { bool can_write = true; for (const auto &file_ptr : data->data_files) can_write &= file_ptr->can_write(); @@ -325,20 +325,20 @@ bool ecl_sum_data_can_write(const ecl_sum_data_type *data) { return can_write; } -time_t ecl_sum_data_get_sim_end(const ecl_sum_data_type *data) { +time_t rd_sum_data_get_sim_end(const rd_sum_data_type *data) { if (data->data_files.empty()) - throw std::out_of_range("ecl_sum_data_get_sim_end: data_files empty"); + throw std::out_of_range("rd_sum_data_get_sim_end: data_files empty"); const auto &file_data = data->data_files.back(); return file_data->get_sim_end(); } -time_t ecl_sum_data_get_data_start(const ecl_sum_data_type *data) { +time_t rd_sum_data_get_data_start(const rd_sum_data_type *data) { const auto &file_data = data->data_files[0]; return file_data->get_data_start(); } -double ecl_sum_data_get_first_day(const ecl_sum_data_type *data) { +double rd_sum_data_get_first_day(const rd_sum_data_type *data) { const auto &file_data = data->data_files[0]; return file_data->get_days_start(); } @@ -349,7 +349,7 @@ double ecl_sum_data_get_first_day(const ecl_sum_data_type *data) { actually been loaded) to the last loaded simulation step. */ -double ecl_sum_data_get_sim_length(const ecl_sum_data_type *data) { +double rd_sum_data_get_sim_length(const rd_sum_data_type *data) { const auto &file_data = data->data_files.back(); return file_data->get_sim_length(); } @@ -362,21 +362,19 @@ double ecl_sum_data_get_sim_length(const ecl_sum_data_type *data) { start with no data. */ -bool ecl_sum_data_check_sim_time(const ecl_sum_data_type *data, - time_t sim_time) { - if (sim_time < ecl_sum_data_get_data_start(data)) +bool rd_sum_data_check_sim_time(const rd_sum_data_type *data, time_t sim_time) { + if (sim_time < rd_sum_data_get_data_start(data)) return false; - if (sim_time > ecl_sum_data_get_sim_end(data)) + if (sim_time > rd_sum_data_get_sim_end(data)) return false; return true; } -bool ecl_sum_data_check_sim_days(const ecl_sum_data_type *data, - double sim_days) { - return sim_days >= ecl_sum_data_get_first_day(data) && - sim_days <= ecl_sum_data_get_sim_length(data); +bool rd_sum_data_check_sim_days(const rd_sum_data_type *data, double sim_days) { + return sim_days >= rd_sum_data_get_first_day(data) && + sim_days <= rd_sum_data_get_sim_length(data); } /** @@ -385,7 +383,7 @@ bool ecl_sum_data_check_sim_days(const ecl_sum_data_type *data, before the simulation start, or after the end of the simulation. Check with - ecl_smspec_get_start_time() and ecl_sum_data_get_sim_end() + rd_smspec_get_start_time() and rd_sum_data_get_sim_end() first. @@ -422,14 +420,14 @@ static void fprintf_date_utc(time_t t, FILE *stream) { fprintf(stream, "%02d/%02d/%4d", mday, month, year); } -static int ecl_sum_data_get_index_from_sim_time(const ecl_sum_data_type *data, - time_t sim_time) { - if (!ecl_sum_data_check_sim_time(data, sim_time)) { - time_t start_time = ecl_sum_data_get_data_start(data); - time_t end_time = ecl_sum_data_get_sim_end(data); +static int rd_sum_data_get_index_from_sim_time(const rd_sum_data_type *data, + time_t sim_time) { + if (!rd_sum_data_check_sim_time(data, sim_time)) { + time_t start_time = rd_sum_data_get_data_start(data); + time_t end_time = rd_sum_data_get_sim_end(data); fprintf(stderr, "Simulation start: "); - fprintf_date_utc(ecl_smspec_get_start_time(data->smspec), stderr); + fprintf_date_utc(rd_smspec_get_start_time(data->smspec), stderr); fprintf(stderr, "Data start......: "); fprintf_date_utc(start_time, stderr); fprintf(stderr, "Simulation end .: "); @@ -448,13 +446,13 @@ static int ecl_sum_data_get_index_from_sim_time(const ecl_sum_data_type *data, */ int low_index = 0; - int high_index = ecl_sum_data_get_length(data) - 1; + int high_index = rd_sum_data_get_length(data) - 1; // perform binary search while (low_index + 1 < high_index) { int center_index = (low_index + high_index) / 2; const time_t center_time = - ecl_sum_data_iget_sim_time(data, center_index); + rd_sum_data_iget_sim_time(data, center_index); if (sim_time > center_time) low_index = center_index; @@ -462,15 +460,15 @@ static int ecl_sum_data_get_index_from_sim_time(const ecl_sum_data_type *data, high_index = center_index; } - return sim_time <= ecl_sum_data_iget_sim_time(data, low_index) ? low_index - : high_index; + return sim_time <= rd_sum_data_iget_sim_time(data, low_index) ? low_index + : high_index; } -int ecl_sum_data_get_index_from_sim_days(const ecl_sum_data_type *data, - double sim_days) { - time_t sim_time = ecl_smspec_get_start_time(data->smspec); +int rd_sum_data_get_index_from_sim_days(const rd_sum_data_type *data, + double sim_days) { + time_t sim_time = rd_smspec_get_start_time(data->smspec); util_inplace_forward_days_utc(&sim_time, sim_days); - return ecl_sum_data_get_index_from_sim_time(data, sim_time); + return rd_sum_data_get_index_from_sim_time(data, sim_time); } /** @@ -479,7 +477,7 @@ int ecl_sum_data_get_index_from_sim_days(const ecl_sum_data_type *data, corresponding weights are calculated. The actual value we are interested in can then be computed with the - ecl_sum_data_interp_get() function: + rd_sum_data_interp_get() function: int param_index; @@ -488,8 +486,8 @@ int ecl_sum_data_get_index_from_sim_days(const ecl_sum_data_type *data, int ministep1 , ministep2; double weight1 , weight2; - ecl_sum_data_init_interp_from_sim_time( data , sim_time , &ministep1 , &ministep2 , &weight1 , &weight2); - return ecl_sum_data_interp_get( data , ministep1 , ministep2 , weight1 , weight2 , param_index ); + rd_sum_data_init_interp_from_sim_time( data , sim_time , &ministep1 , &ministep2 , &weight1 , &weight2); + return rd_sum_data_interp_get( data , ministep1 , ministep2 , weight1 , weight2 , param_index ); } @@ -498,11 +496,11 @@ int ecl_sum_data_get_index_from_sim_days(const ecl_sum_data_type *data, file. */ -void ecl_sum_data_init_interp_from_sim_time(const ecl_sum_data_type *data, - time_t sim_time, int *index1, - int *index2, double *weight1, - double *weight2) { - int idx = ecl_sum_data_get_index_from_sim_time(data, sim_time); +void rd_sum_data_init_interp_from_sim_time(const rd_sum_data_type *data, + time_t sim_time, int *index1, + int *index2, double *weight1, + double *weight2) { + int idx = rd_sum_data_get_index_from_sim_time(data, sim_time); // if sim_time is first date, idx=0 and then we cannot interpolate, so we give // weight 1 to index1=index2=0. @@ -514,8 +512,8 @@ void ecl_sum_data_init_interp_from_sim_time(const ecl_sum_data_type *data, return; } - time_t sim_time1 = ecl_sum_data_iget_sim_time(data, idx - 1); - time_t sim_time2 = ecl_sum_data_iget_sim_time(data, idx); + time_t sim_time1 = rd_sum_data_iget_sim_time(data, idx - 1); + time_t sim_time2 = rd_sum_data_iget_sim_time(data, idx); *index1 = idx - 1; *index2 = idx; @@ -529,31 +527,31 @@ void ecl_sum_data_init_interp_from_sim_time(const ecl_sum_data_type *data, *weight2 = time_dist1 / time_diff; } -void ecl_sum_data_init_interp_from_sim_days(const ecl_sum_data_type *data, - double sim_days, int *step1, - int *step2, double *weight1, - double *weight2) { - time_t sim_time = ecl_smspec_get_start_time(data->smspec); +void rd_sum_data_init_interp_from_sim_days(const rd_sum_data_type *data, + double sim_days, int *step1, + int *step2, double *weight1, + double *weight2) { + time_t sim_time = rd_smspec_get_start_time(data->smspec); util_inplace_forward_days_utc(&sim_time, sim_days); - ecl_sum_data_init_interp_from_sim_time(data, sim_time, step1, step2, - weight1, weight2); + rd_sum_data_init_interp_from_sim_time(data, sim_time, step1, step2, weight1, + weight2); } double_vector_type * -ecl_sum_data_alloc_seconds_solution(const ecl_sum_data_type *data, - const ecl::smspec_node &node, - double cmp_value, bool rates_clamp_lower) { +rd_sum_data_alloc_seconds_solution(const rd_sum_data_type *data, + const rd::smspec_node &node, + double cmp_value, bool rates_clamp_lower) { double_vector_type *solution = double_vector_alloc(0, 0); const int param_index = smspec_node_get_params_index(&node); - const int size = ecl_sum_data_get_length(data); + const int size = rd_sum_data_get_length(data); if (size <= 1) return solution; for (int index = 0; index < size; ++index) { int prev_index = util_int_max(0, index - 1); - double value = ecl_sum_data_iget(data, index, param_index); - double prev_value = ecl_sum_data_iget(data, prev_index, param_index); + double value = rd_sum_data_iget(data, index, param_index); + double prev_value = rd_sum_data_iget(data, prev_index, param_index); // cmp_value in interval value (closed) and prev_value (open) bool contained = (value == cmp_value); @@ -563,8 +561,8 @@ ecl_sum_data_alloc_seconds_solution(const ecl_sum_data_type *data, if (!contained) continue; - double prev_time = ecl_sum_data_iget_sim_seconds(data, prev_index); - double time = ecl_sum_data_iget_sim_seconds(data, index); + double prev_time = rd_sum_data_iget_sim_seconds(data, prev_index); + double time = rd_sum_data_iget_sim_seconds(data, index); if (smspec_node_is_rate(&node)) { double_vector_append(solution, @@ -578,10 +576,10 @@ ecl_sum_data_alloc_seconds_solution(const ecl_sum_data_type *data, return solution; } -static void ecl_sum_data_build_index(ecl_sum_data_type *self) { +static void rd_sum_data_build_index(rd_sum_data_type *self) { std::sort(self->data_files.begin(), self->data_files.end(), - [](const ecl::ecl_sum_file_data *case1, - const ecl::ecl_sum_file_data *case2) { + [](const rd::rd_sum_file_data *case1, + const rd::rd_sum_file_data *case2) { return case1->get_data_start() < case2->get_data_start(); }); @@ -614,10 +612,9 @@ static void ecl_sum_data_build_index(ecl_sum_data_type *self) { node.days2 = data->get_sim_length(); { int *tmp_map = - ecl_smspec_alloc_mapping(self->smspec, data->smspec()); + rd_smspec_alloc_mapping(self->smspec, data->smspec()); node.params_map.assign( - tmp_map, - tmp_map + ecl_smspec_get_params_size(self->smspec)); + tmp_map, tmp_map + rd_smspec_get_params_size(self->smspec)); free(tmp_map); } } @@ -628,21 +625,21 @@ static void ecl_sum_data_build_index(ecl_sum_data_type *self) { This function is meant to be called in write mode; and will create a new and empty tstep which is appended to the current data. The tstep will also be returned, so the calling scope can call - ecl_sum_tstep_iset() to set elements in the tstep. + rd_sum_tstep_iset() to set elements in the tstep. */ -ecl_sum_tstep_type *ecl_sum_data_add_new_tstep(ecl_sum_data_type *data, - int report_step, - double sim_seconds) { - ecl::ecl_sum_file_data *file_data = data->data_files.back(); - ecl_sum_tstep_type *tstep = +rd_sum_tstep_type *rd_sum_data_add_new_tstep(rd_sum_data_type *data, + int report_step, + double sim_seconds) { + rd::rd_sum_file_data *file_data = data->data_files.back(); + rd_sum_tstep_type *tstep = file_data->add_new_tstep(report_step, sim_seconds); - ecl_sum_data_build_index(data); + rd_sum_data_build_index(data); return tstep; } -int *ecl_sum_data_alloc_param_mapping(int *current_param_mapping, - int *old_param_mapping, size_t size) { +int *rd_sum_data_alloc_param_mapping(int *current_param_mapping, + int *old_param_mapping, size_t size) { int *new_param_mapping = (int *)util_malloc(size * sizeof *new_param_mapping); for (size_t i = 0; i < size; i++) { @@ -654,31 +651,29 @@ int *ecl_sum_data_alloc_param_mapping(int *current_param_mapping, return new_param_mapping; } -void ecl_sum_data_add_case(ecl_sum_data_type *self, - const ecl_sum_data_type *other) { +void rd_sum_data_add_case(rd_sum_data_type *self, + const rd_sum_data_type *other) { for (auto other_file : other->data_files) self->data_files.push_back(other_file); - ecl_sum_data_build_index(self); + rd_sum_data_build_index(self); } /* Observe that this can be called several times (but not with the same data - that will die). - Warning: The index information of the ecl_sum_data instance has + Warning: The index information of the rd_sum_data instance has __NOT__ been updated when leaving this function. That is done with a - call to ecl_sum_data_build_index(). + call to rd_sum_data_build_index(). */ -bool ecl_sum_data_fread(ecl_sum_data_type *data, - const stringlist_type *filelist, bool lazy_load, - int file_options) { - ecl::ecl_sum_file_data *file_data = - new ecl::ecl_sum_file_data(data->smspec); +bool rd_sum_data_fread(rd_sum_data_type *data, const stringlist_type *filelist, + bool lazy_load, int file_options) { + rd::rd_sum_file_data *file_data = new rd::rd_sum_file_data(data->smspec); if (file_data->fread(filelist, lazy_load, file_options)) { - ecl_sum_data_append_file_data(data, file_data); - ecl_sum_data_build_index(data); + rd_sum_data_append_file_data(data, file_data); + rd_sum_data_build_index(data); return true; } return false; @@ -692,22 +687,22 @@ bool ecl_sum_data_fread(ecl_sum_data_type *data, (manually) changed from the historical part. */ -ecl_sum_data_type *ecl_sum_data_fread_alloc(ecl_smspec_type *smspec, - const stringlist_type *filelist, - bool include_restart, - bool lazy_load, int file_options) { - ecl_sum_data_type *data = ecl_sum_data_alloc(smspec); - ecl_sum_data_fread(data, filelist, lazy_load, file_options); +rd_sum_data_type *rd_sum_data_fread_alloc(rd_smspec_type *smspec, + const stringlist_type *filelist, + bool include_restart, bool lazy_load, + int file_options) { + rd_sum_data_type *data = rd_sum_data_alloc(smspec); + rd_sum_data_fread(data, filelist, lazy_load, file_options); /* OK - now we have loaded all the data. Must sort the internal storage vector, and build up various internal indexing vectors; this is done in a sepearate function. */ - ecl_sum_data_build_index(data); + rd_sum_data_build_index(data); return data; } -void ecl_sum_data_summarize(const ecl_sum_data_type *data, FILE *stream) { +void rd_sum_data_summarize(const rd_sum_data_type *data, FILE *stream) { fprintf(stream, "REPORT INDEX DATE DAYS\n"); fprintf( @@ -715,13 +710,13 @@ void ecl_sum_data_summarize(const ecl_sum_data_type *data, FILE *stream) { "---------------------------------------------------------------\n"); { int index; - for (index = 0; index < ecl_sum_data_get_length(data); index++) { - time_t sim_time = ecl_sum_data_iget_sim_time(data, index); - int report_step = ecl_sum_data_iget_report_step(data, index); - double days = ecl_sum_data_iget_sim_days(data, index); + for (index = 0; index < rd_sum_data_get_length(data); index++) { + time_t sim_time = rd_sum_data_iget_sim_time(data, index); + int report_step = rd_sum_data_iget_report_step(data, index); + double days = rd_sum_data_iget_sim_days(data, index); int day, month, year; - ecl_util_set_date_values(sim_time, &day, &month, &year); + rd_set_date_values(sim_time, &day, &month, &year); fprintf(stream, "%04d %6d %02d/%02d/%4d " "%7.2f \n", @@ -733,8 +728,8 @@ void ecl_sum_data_summarize(const ecl_sum_data_type *data, FILE *stream) { "---------------------------------------------------------------\n"); } -bool ecl_sum_data_has_report_step(const ecl_sum_data_type *data, - int report_step) { +bool rd_sum_data_has_report_step(const rd_sum_data_type *data, + int report_step) { if (!data->index.has_report(report_step)) return false; @@ -750,16 +745,15 @@ bool ecl_sum_data_has_report_step(const ecl_sum_data_type *data, calling scope. */ -int ecl_sum_data_iget_report_end(const ecl_sum_data_type *data, - int report_step) { +int rd_sum_data_iget_report_end(const rd_sum_data_type *data, int report_step) { const auto &index_node = data->index.lookup_report(report_step); const auto &file_data = data->data_files[index_node.data_index]; auto range = file_data->report_range(report_step); return range.second; } -int ecl_sum_data_iget_report_step(const ecl_sum_data_type *data, - int internal_index) { +int rd_sum_data_iget_report_step(const rd_sum_data_type *data, + int internal_index) { const auto &index_node = data->index.lookup(internal_index); const auto &file_data = data->data_files[index_node.data_index]; return file_data->iget_report(internal_index - index_node.offset); @@ -771,17 +765,17 @@ int ecl_sum_data_iget_report_step(const ecl_sum_data_type *data, any holes. */ -double ecl_sum_data_iget(const ecl_sum_data_type *data, int time_index, - int params_index) { +double rd_sum_data_iget(const rd_sum_data_type *data, int time_index, + int params_index) { const auto &index_node = data->index.lookup(time_index); - ecl::ecl_sum_file_data *file_data = data->data_files[index_node.data_index]; + rd::rd_sum_file_data *file_data = data->data_files[index_node.data_index]; const auto ¶ms_map = index_node.params_map; if (params_map[params_index] >= 0) return file_data->iget(time_index - index_node.offset, params_map[params_index]); else { - const ecl::smspec_node &smspec_node = - ecl_smspec_iget_node_w_params_index(data->smspec, params_index); + const rd::smspec_node &smspec_node = + rd_smspec_iget_node_w_params_index(data->smspec, params_index); return smspec_node.get_default(); } } @@ -791,56 +785,56 @@ double ecl_sum_data_iget(const ecl_sum_data_type *data, int time_index, @ministep1 and @ministep2. The weights and the ministep indices should (typically) be determined by the - ecl_sum_data_init_interp_from_sim_xxx() + rd_sum_data_init_interp_from_sim_xxx() functions. The function will typically the last function called when we seek a reservoir state variable at an intermediate time between two ministeps. */ -static double ecl_sum_data_interp_get(const ecl_sum_data_type *data, - int time_index1, int time_index2, - double weight1, double weight2, - int params_index) { - return ecl_sum_data_iget(data, time_index1, params_index) * weight1 + - ecl_sum_data_iget(data, time_index2, params_index) * weight2; +static double rd_sum_data_interp_get(const rd_sum_data_type *data, + int time_index1, int time_index2, + double weight1, double weight2, + int params_index) { + return rd_sum_data_iget(data, time_index1, params_index) * weight1 + + rd_sum_data_iget(data, time_index2, params_index) * weight2; } -static double ecl_sum_data_vector_iget(const ecl_sum_data_type *data, - time_t sim_time, int params_index, - bool is_rate, int time_index1, - int time_index2, double weight1, - double weight2) { +static double rd_sum_data_vector_iget(const rd_sum_data_type *data, + time_t sim_time, int params_index, + bool is_rate, int time_index1, + int time_index2, double weight1, + double weight2) { double value = 0.0; if (is_rate) { - int time_index = ecl_sum_data_get_index_from_sim_time(data, sim_time); + int time_index = rd_sum_data_get_index_from_sim_time(data, sim_time); // uses step function since it is a rate - value = ecl_sum_data_iget(data, time_index, params_index); + value = rd_sum_data_iget(data, time_index, params_index); } else { // uses interpolation between timesteps - value = ecl_sum_data_interp_get(data, time_index1, time_index2, weight1, - weight2, params_index); + value = rd_sum_data_interp_get(data, time_index1, time_index2, weight1, + weight2, params_index); } return value; } -void ecl_sum_data_fwrite_interp_csv_line(const ecl_sum_data_type *data, - time_t sim_time, - const ecl_sum_vector_type *keylist, - FILE *fp) { - int num_keywords = ecl_sum_vector_get_size(keylist); +void rd_sum_data_fwrite_interp_csv_line(const rd_sum_data_type *data, + time_t sim_time, + const rd_sum_vector_type *keylist, + FILE *fp) { + int num_keywords = rd_sum_vector_get_size(keylist); double weight1, weight2; int time_index1, time_index2; - ecl_sum_data_init_interp_from_sim_time(data, sim_time, &time_index1, - &time_index2, &weight1, &weight2); + rd_sum_data_init_interp_from_sim_time(data, sim_time, &time_index1, + &time_index2, &weight1, &weight2); for (int i = 0; i < num_keywords; i++) { - if (ecl_sum_vector_iget_valid(keylist, i)) { - int params_index = ecl_sum_vector_iget_param_index(keylist, i); - bool is_rate = ecl_sum_vector_iget_is_rate(keylist, i); - double value = ecl_sum_data_vector_iget( + if (rd_sum_vector_iget_valid(keylist, i)) { + int params_index = rd_sum_vector_iget_param_index(keylist, i); + bool is_rate = rd_sum_vector_iget_is_rate(keylist, i); + double value = rd_sum_data_vector_iget( data, sim_time, params_index, is_rate, time_index1, time_index2, weight1, weight2); @@ -862,27 +856,27 @@ void ecl_sum_data_fwrite_interp_csv_line(const ecl_sum_data_type *data, results vector will *not* be updated; i.e. it is smart to initialize the results vector with an invalid-value marker before calling this function: - double_vector_type * results = double_vector_alloc( ecl_sum_vector_get_size(keys), NAN); - ecl_sum_data_get_interp_vector( data, sim_time, keys, results); + double_vector_type * results = double_vector_alloc( rd_sum_vector_get_size(keys), NAN); + rd_sum_data_get_interp_vector( data, sim_time, keys, results); */ -void ecl_sum_data_get_interp_vector(const ecl_sum_data_type *data, - time_t sim_time, - const ecl_sum_vector_type *keylist, - double_vector_type *results) { - int num_keywords = ecl_sum_vector_get_size(keylist); +void rd_sum_data_get_interp_vector(const rd_sum_data_type *data, + time_t sim_time, + const rd_sum_vector_type *keylist, + double_vector_type *results) { + int num_keywords = rd_sum_vector_get_size(keylist); double weight1, weight2; int time_index1, time_index2; - ecl_sum_data_init_interp_from_sim_time(data, sim_time, &time_index1, - &time_index2, &weight1, &weight2); + rd_sum_data_init_interp_from_sim_time(data, sim_time, &time_index1, + &time_index2, &weight1, &weight2); double_vector_reset(results); for (int i = 0; i < num_keywords; i++) { - if (ecl_sum_vector_iget_valid(keylist, i)) { - int params_index = ecl_sum_vector_iget_param_index(keylist, i); - bool is_rate = ecl_sum_vector_iget_is_rate(keylist, i); - double value = ecl_sum_data_vector_iget( + if (rd_sum_vector_iget_valid(keylist, i)) { + int params_index = rd_sum_vector_iget_param_index(keylist, i); + bool is_rate = rd_sum_vector_iget_is_rate(keylist, i); + double value = rd_sum_data_vector_iget( data, sim_time, params_index, is_rate, time_index1, time_index2, weight1, weight2); double_vector_iset(results, i, value); @@ -890,9 +884,9 @@ void ecl_sum_data_get_interp_vector(const ecl_sum_data_type *data, } } -double ecl_sum_data_get_from_sim_time(const ecl_sum_data_type *data, - time_t sim_time, - const ecl::smspec_node &smspec_node) { +double rd_sum_data_get_from_sim_time(const rd_sum_data_type *data, + time_t sim_time, + const rd::smspec_node &smspec_node) { int params_index = smspec_node_get_params_index(&smspec_node); if (smspec_node_is_rate(&smspec_node)) { /* @@ -905,27 +899,27 @@ double ecl_sum_data_get_from_sim_time(const ecl_sum_data_type *data, However - as indicated on the figure above there is a zero measure point right at the start which corresponds to time_index == 0; this is to ensure that there is correspondance - with the ECLIPSE results if you ask for a value interpolated to + with the simulator results if you ask for a value interpolated to the starting time. */ - int time_index = ecl_sum_data_get_index_from_sim_time(data, sim_time); - return ecl_sum_data_iget(data, time_index, params_index); + int time_index = rd_sum_data_get_index_from_sim_time(data, sim_time); + return rd_sum_data_iget(data, time_index, params_index); } else { /* Interpolated lookup based on two (hopefully) consecutive ministeps. */ double weight1, weight2; int time_index1, time_index2; - ecl_sum_data_init_interp_from_sim_time( - data, sim_time, &time_index1, &time_index2, &weight1, &weight2); - return ecl_sum_data_interp_get(data, time_index1, time_index2, weight1, - weight2, params_index); + rd_sum_data_init_interp_from_sim_time(data, sim_time, &time_index1, + &time_index2, &weight1, &weight2); + return rd_sum_data_interp_get(data, time_index1, time_index2, weight1, + weight2, params_index); } } -int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type *data, - double sim_days) { - if ((sim_days < ecl_sum_data_get_first_day(data)) || - (sim_days > ecl_sum_data_get_sim_length(data))) +int rd_sum_data_get_report_step_from_days(const rd_sum_data_type *data, + double sim_days) { + if ((sim_days < rd_sum_data_get_first_day(data)) || + (sim_days > rd_sum_data_get_sim_length(data))) return -1; else { auto files = data->index.lookup_days(sim_days); @@ -956,9 +950,9 @@ int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type *data, report_step input. */ -int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type *data, - time_t sim_time) { - if (!ecl_sum_data_check_sim_time(data, sim_time)) +int rd_sum_data_get_report_step_from_time(const rd_sum_data_type *data, + time_t sim_time) { + if (!rd_sum_data_check_sim_time(data, sim_time)) return -1; else { auto files = data->index.lookup_time(sim_time); @@ -970,32 +964,32 @@ int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type *data, } } -double ecl_sum_data_time2days(const ecl_sum_data_type *data, time_t sim_time) { - time_t start_time = ecl_smspec_get_start_time(data->smspec); +double rd_sum_data_time2days(const rd_sum_data_type *data, time_t sim_time) { + time_t start_time = rd_smspec_get_start_time(data->smspec); return util_difftime_days(start_time, sim_time); } -double ecl_sum_data_get_from_sim_days(const ecl_sum_data_type *data, - double sim_days, - const ecl::smspec_node &smspec_node) { - time_t sim_time = ecl_smspec_get_start_time(data->smspec); +double rd_sum_data_get_from_sim_days(const rd_sum_data_type *data, + double sim_days, + const rd::smspec_node &smspec_node) { + time_t sim_time = rd_smspec_get_start_time(data->smspec); util_inplace_forward_days_utc(&sim_time, sim_days); - return ecl_sum_data_get_from_sim_time(data, sim_time, smspec_node); + return rd_sum_data_get_from_sim_time(data, sim_time, smspec_node); } -time_t ecl_sum_data_iget_sim_time(const ecl_sum_data_type *data, - int ministep_index) { +time_t rd_sum_data_iget_sim_time(const rd_sum_data_type *data, + int ministep_index) { const auto &index_node = data->index.lookup(ministep_index); const auto data_file = data->data_files[index_node.data_index]; return data_file->iget_sim_time(ministep_index - index_node.offset); } -time_t ecl_sum_data_get_report_time(const ecl_sum_data_type *data, - int report_step) { +time_t rd_sum_data_get_report_time(const rd_sum_data_type *data, + int report_step) { if (report_step == 0) - return ecl_smspec_get_start_time(data->smspec); + return rd_smspec_get_start_time(data->smspec); else { - int internal_index = ecl_sum_data_iget_report_end(data, report_step); + int internal_index = rd_sum_data_iget_report_end(data, report_step); if (internal_index == -1) throw std::out_of_range( "Tried to look up step nr: " + std::to_string(report_step) + @@ -1003,23 +997,23 @@ time_t ecl_sum_data_get_report_time(const ecl_sum_data_type *data, "exist. \n" + "The step entries in summary file must cover all entries " "in the restart file."); - return ecl_sum_data_iget_sim_time(data, internal_index); + return rd_sum_data_iget_sim_time(data, internal_index); } } -int ecl_sum_data_get_first_report_step(const ecl_sum_data_type *data) { +int rd_sum_data_get_first_report_step(const rd_sum_data_type *data) { const auto &data_file = data->data_files[0]; return data_file->first_report(); } -int ecl_sum_data_get_last_report_step(const ecl_sum_data_type *data) { +int rd_sum_data_get_last_report_step(const rd_sum_data_type *data) { const auto &data_file = data->data_files.back(); return data_file->last_report(); } -static void ecl_sum_data_init_time_vector__(const ecl_sum_data_type *data, - time_t *output_data, - bool report_only) { +static void rd_sum_data_init_time_vector__(const rd_sum_data_type *data, + time_t *output_data, + bool report_only) { int offset = 0; for (const auto &index_node : data->index) { const auto &data_file = data->data_files[index_node.data_index]; @@ -1034,22 +1028,21 @@ static void ecl_sum_data_init_time_vector__(const ecl_sum_data_type *data, } } -void ecl_sum_data_init_time_vector(const ecl_sum_data_type *data, - time_t *output_data) { - ecl_sum_data_init_time_vector__(data, output_data, false); +void rd_sum_data_init_time_vector(const rd_sum_data_type *data, + time_t *output_data) { + rd_sum_data_init_time_vector__(data, output_data, false); } -time_t_vector_type * -ecl_sum_data_alloc_time_vector(const ecl_sum_data_type *data, - bool report_only) { +time_t_vector_type *rd_sum_data_alloc_time_vector(const rd_sum_data_type *data, + bool report_only) { std::vector output_data; if (report_only) - output_data.resize(1 + ecl_sum_data_get_last_report_step(data) - - ecl_sum_data_get_first_report_step(data)); + output_data.resize(1 + rd_sum_data_get_last_report_step(data) - + rd_sum_data_get_first_report_step(data)); else - output_data.resize(ecl_sum_data_get_length(data)); + output_data.resize(rd_sum_data_get_length(data)); - ecl_sum_data_init_time_vector__(data, output_data.data(), report_only); + rd_sum_data_init_time_vector__(data, output_data.data(), report_only); time_t_vector_type *time_vector = time_t_vector_alloc(output_data.size(), 0); { @@ -1060,10 +1053,10 @@ ecl_sum_data_alloc_time_vector(const ecl_sum_data_type *data, return time_vector; } -static void ecl_sum_data_init_double_vector__(const ecl_sum_data_type *data, - int main_params_index, - double *output_data, - bool report_only) { +static void rd_sum_data_init_double_vector__(const rd_sum_data_type *data, + int main_params_index, + double *output_data, + bool report_only) { int offset = 0; for (const auto &index_node : data->index) { const auto &data_file = data->data_files[index_node.data_index]; @@ -1071,9 +1064,9 @@ static void ecl_sum_data_init_double_vector__(const ecl_sum_data_type *data, int params_index = params_map[main_params_index]; if (report_only) { - const ecl::smspec_node &smspec_node = - ecl_smspec_iget_node_w_params_index(data->smspec, - main_params_index); + const rd::smspec_node &smspec_node = + rd_smspec_iget_node_w_params_index(data->smspec, + main_params_index); double default_value = smspec_node.get_default(); offset += data_file->get_data_report(params_index, index_node.length, @@ -1084,9 +1077,9 @@ static void ecl_sum_data_init_double_vector__(const ecl_sum_data_type *data, data_file->get_data(params_index, index_node.length, &output_data[offset]); else { - const ecl::smspec_node &smspec_node = - ecl_smspec_iget_node_w_params_index(data->smspec, - main_params_index); + const rd::smspec_node &smspec_node = + rd_smspec_iget_node_w_params_index(data->smspec, + main_params_index); for (int i = 0; i < index_node.length; i++) output_data[offset + i] = smspec_node.get_default(); } @@ -1095,32 +1088,32 @@ static void ecl_sum_data_init_double_vector__(const ecl_sum_data_type *data, } } -void ecl_sum_data_init_datetime64_vector(const ecl_sum_data_type *data, - int64_t *output_data, int multiplier) { - for (int i = 0; i < ecl_sum_data_get_length(data); i++) - output_data[i] = ecl_sum_data_iget_sim_time(data, i) * multiplier; +void rd_sum_data_init_datetime64_vector(const rd_sum_data_type *data, + int64_t *output_data, int multiplier) { + for (int i = 0; i < rd_sum_data_get_length(data); i++) + output_data[i] = rd_sum_data_iget_sim_time(data, i) * multiplier; } -void ecl_sum_data_init_double_vector(const ecl_sum_data_type *data, - int params_index, double *output_data) { - ecl_sum_data_init_double_vector__(data, params_index, output_data, false); +void rd_sum_data_init_double_vector(const rd_sum_data_type *data, + int params_index, double *output_data) { + rd_sum_data_init_double_vector__(data, params_index, output_data, false); } -double_vector_type * -ecl_sum_data_alloc_data_vector(const ecl_sum_data_type *data, int params_index, - bool report_only) { +double_vector_type *rd_sum_data_alloc_data_vector(const rd_sum_data_type *data, + int params_index, + bool report_only) { std::vector output_data; if (report_only) - output_data.resize(1 + ecl_sum_data_get_last_report_step(data) - - ecl_sum_data_get_first_report_step(data)); + output_data.resize(1 + rd_sum_data_get_last_report_step(data) - + rd_sum_data_get_first_report_step(data)); else - output_data.resize(ecl_sum_data_get_length(data)); + output_data.resize(rd_sum_data_get_length(data)); - if (params_index >= ecl_smspec_get_params_size(data->smspec)) + if (params_index >= rd_smspec_get_params_size(data->smspec)) throw std::out_of_range("Out of range"); - ecl_sum_data_init_double_vector__(data, params_index, output_data.data(), - report_only); + rd_sum_data_init_double_vector__(data, params_index, output_data.data(), + report_only); double_vector_type *data_vector = double_vector_alloc(output_data.size(), 0); { @@ -1131,19 +1124,19 @@ ecl_sum_data_alloc_data_vector(const ecl_sum_data_type *data, int params_index, return data_vector; } -void ecl_sum_data_init_double_vector_interp( - const ecl_sum_data_type *data, const ecl::smspec_node &smspec_node, +void rd_sum_data_init_double_vector_interp( + const rd_sum_data_type *data, const rd::smspec_node &smspec_node, const time_t_vector_type *time_points, double *output_data) { bool is_rate = smspec_node_is_rate(&smspec_node); int params_index = smspec_node_get_params_index(&smspec_node); - time_t start_time = ecl_sum_data_get_data_start(data); - time_t end_time = ecl_sum_data_get_sim_end(data); + time_t start_time = rd_sum_data_get_data_start(data); + time_t end_time = rd_sum_data_get_sim_end(data); double start_value = 0; double end_value = 0; if (!is_rate) { - start_value = ecl_sum_data_iget_first_value(data, params_index); - end_value = ecl_sum_data_iget_last_value(data, params_index); + start_value = rd_sum_data_iget_first_value(data, params_index); + end_value = rd_sum_data_iget_last_value(data, params_index); } for (int time_index = 0; time_index < time_t_vector_size(time_points); @@ -1159,44 +1152,45 @@ void ecl_sum_data_init_double_vector_interp( else { int time_index1, time_index2; double weight1, weight2; - ecl_sum_data_init_interp_from_sim_time( + rd_sum_data_init_interp_from_sim_time( data, sim_time, &time_index1, &time_index2, &weight1, &weight2); - value = ecl_sum_data_vector_iget(data, sim_time, params_index, - is_rate, time_index1, time_index2, - weight1, weight2); + value = rd_sum_data_vector_iget(data, sim_time, params_index, + is_rate, time_index1, time_index2, + weight1, weight2); } output_data[time_index] = value; } } -void ecl_sum_data_init_double_frame(const ecl_sum_data_type *data, - const ecl_sum_vector_type *keywords, - double *output_data) { - int time_stride = ecl_sum_vector_get_size(keywords); +void rd_sum_data_init_double_frame(const rd_sum_data_type *data, + const rd_sum_vector_type *keywords, + double *output_data) { + int time_stride = rd_sum_vector_get_size(keywords); int key_stride = 1; - for (int time_index = 0; time_index < ecl_sum_data_get_length(data); + for (int time_index = 0; time_index < rd_sum_data_get_length(data); time_index++) { - for (int key_index = 0; key_index < ecl_sum_vector_get_size(keywords); + for (int key_index = 0; key_index < rd_sum_vector_get_size(keywords); key_index++) { int param_index = - ecl_sum_vector_iget_param_index(keywords, key_index); + rd_sum_vector_iget_param_index(keywords, key_index); int data_index = key_index * key_stride + time_index * time_stride; output_data[data_index] = - ecl_sum_data_iget(data, time_index, param_index); + rd_sum_data_iget(data, time_index, param_index); } } } -void ecl_sum_data_init_double_frame_interp( - const ecl_sum_data_type *data, const ecl_sum_vector_type *keywords, - const time_t_vector_type *time_points, double *output_data) { - int num_keywords = ecl_sum_vector_get_size(keywords); +void rd_sum_data_init_double_frame_interp(const rd_sum_data_type *data, + const rd_sum_vector_type *keywords, + const time_t_vector_type *time_points, + double *output_data) { + int num_keywords = rd_sum_vector_get_size(keywords); int time_stride = num_keywords; int key_stride = 1; - time_t start_time = ecl_sum_data_get_data_start(data); - time_t end_time = ecl_sum_data_get_sim_end(data); + time_t start_time = rd_sum_data_get_data_start(data); + time_t end_time = rd_sum_data_get_sim_end(data); for (int time_index = 0; time_index < time_t_vector_size(time_points); time_index++) { @@ -1204,43 +1198,43 @@ void ecl_sum_data_init_double_frame_interp( if (sim_time < start_time) { for (int key_index = 0; key_index < num_keywords; key_index++) { int param_index = - ecl_sum_vector_iget_param_index(keywords, key_index); + rd_sum_vector_iget_param_index(keywords, key_index); int data_index = key_index * key_stride + time_index * time_stride; - bool is_rate = ecl_sum_vector_iget_is_rate(keywords, key_index); + bool is_rate = rd_sum_vector_iget_is_rate(keywords, key_index); if (is_rate) output_data[data_index] = 0; else output_data[data_index] = - ecl_sum_data_iget_first_value(data, param_index); + rd_sum_data_iget_first_value(data, param_index); } } else if (sim_time > end_time) { for (int key_index = 0; key_index < num_keywords; key_index++) { int param_index = - ecl_sum_vector_iget_param_index(keywords, key_index); + rd_sum_vector_iget_param_index(keywords, key_index); int data_index = key_index * key_stride + time_index * time_stride; - bool is_rate = ecl_sum_vector_iget_is_rate(keywords, key_index); + bool is_rate = rd_sum_vector_iget_is_rate(keywords, key_index); if (is_rate) output_data[data_index] = 0; else output_data[data_index] = - ecl_sum_data_iget_last_value(data, param_index); + rd_sum_data_iget_last_value(data, param_index); } } else { double weight1, weight2; int time_index1, time_index2; - ecl_sum_data_init_interp_from_sim_time( + rd_sum_data_init_interp_from_sim_time( data, sim_time, &time_index1, &time_index2, &weight1, &weight2); for (int key_index = 0; key_index < num_keywords; key_index++) { int param_index = - ecl_sum_vector_iget_param_index(keywords, key_index); + rd_sum_vector_iget_param_index(keywords, key_index); int data_index = key_index * key_stride + time_index * time_stride; - bool is_rate = ecl_sum_vector_iget_is_rate(keywords, key_index); - double value = ecl_sum_data_vector_iget( + bool is_rate = rd_sum_vector_iget_is_rate(keywords, key_index); + double value = rd_sum_data_vector_iget( data, sim_time, param_index, is_rate, time_index1, time_index2, weight1, weight2); output_data[data_index] = value; @@ -1251,17 +1245,17 @@ void ecl_sum_data_init_double_frame_interp( /** This function will return the total number of ministeps in the - current ecl_sum_data instance; but observe that actual series of + current rd_sum_data instance; but observe that actual series of ministeps can have non-zero offset and also "holes" in the series. */ -int ecl_sum_data_get_length(const ecl_sum_data_type *data) { +int rd_sum_data_get_length(const rd_sum_data_type *data) { return data->index.length(); } -static bool ecl_sum_data_report_step_equal__(const ecl_sum_data_type *data1, - const ecl_sum_data_type *data2, - bool strict) { +static bool rd_sum_data_report_step_equal__(const rd_sum_data_type *data1, + const rd_sum_data_type *data2, + bool strict) { if (data1->data_files.size() != data2->data_files.size()) return false; @@ -1276,28 +1270,28 @@ static bool ecl_sum_data_report_step_equal__(const ecl_sum_data_type *data1, return true; } -bool ecl_sum_data_report_step_compatible(const ecl_sum_data_type *data1, - const ecl_sum_data_type *data2) { - return ecl_sum_data_report_step_equal__(data1, data2, false); +bool rd_sum_data_report_step_compatible(const rd_sum_data_type *data1, + const rd_sum_data_type *data2) { + return rd_sum_data_report_step_equal__(data1, data2, false); } -bool ecl_sum_data_report_step_equal(const ecl_sum_data_type *data1, - const ecl_sum_data_type *data2) { - return ecl_sum_data_report_step_equal__(data1, data2, true); +bool rd_sum_data_report_step_equal(const rd_sum_data_type *data1, + const rd_sum_data_type *data2) { + return rd_sum_data_report_step_equal__(data1, data2, true); } -double ecl_sum_data_iget_last_value(const ecl_sum_data_type *data, - int param_index) { - return ecl_sum_data_iget(data, ecl_sum_data_get_length(data) - 1, - param_index); +double rd_sum_data_iget_last_value(const rd_sum_data_type *data, + int param_index) { + return rd_sum_data_iget(data, rd_sum_data_get_length(data) - 1, + param_index); } -double ecl_sum_data_get_last_value(const ecl_sum_data_type *data, - int param_index) { - return ecl_sum_data_iget_last_value(data, param_index); +double rd_sum_data_get_last_value(const rd_sum_data_type *data, + int param_index) { + return rd_sum_data_iget_last_value(data, param_index); } -double ecl_sum_data_iget_first_value(const ecl_sum_data_type *data, - int param_index) { - return ecl_sum_data_iget(data, 0, param_index); +double rd_sum_data_iget_first_value(const rd_sum_data_type *data, + int param_index) { + return rd_sum_data_iget(data, 0, param_index); } diff --git a/lib/ecl/ecl_sum_file_data.cpp b/lib/resdata/rd_sum_file_data.cpp similarity index 65% rename from lib/ecl/ecl_sum_file_data.cpp rename to lib/resdata/rd_sum_file_data.cpp index 5f0e03065d..8237d3ddde 100644 --- a/lib/ecl/ecl_sum_file_data.cpp +++ b/lib/resdata/rd_sum_file_data.cpp @@ -3,23 +3,23 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include "detail/ecl/ecl_sum_file_data.hpp" -#include "detail/ecl/ecl_unsmry_loader.hpp" +#include "detail/resdata/rd_sum_file_data.hpp" +#include "detail/resdata/rd_unsmry_loader.hpp" /* - This file implements the type ecl_sum_data_type. The data structure - is involved with holding all the actual summary data (i.e. the - PARAMS vectors in ECLIPSE speak), in addition the time-information + This file implements the type rd_sum_data_type. The data structure + is involved with holding all the actual summary data (the + PARAMS vectors), in addition the time-information with MINISTEPS / REPORT_STEPS and so on is implemented here. This file has no information about how to index into the PARAMS vector, i.e. at which location can the WWCT for well P6 be found, - that is the responsibility of the ecl_smspec_type. + that is the responsibility of the rd_smspec_type. The time direction in this system is implemented in terms of ministeps. There are some query / convert functions based on report @@ -83,7 +83,7 @@ About MINISTEP, REPORTSTEP, rates and continous sim_time/sim_days: ------------------------------------------------------------------ - For ECLIPSE summary files the smallest unit of time resolution is + For summary files the smallest unit of time resolution is called the ministep - a ministep corresponds to a time step in the underlying partial differential equation, i.e. the length of the timesteps is controlled by the simulator itself - there is no finer @@ -142,13 +142,13 @@ of 'X' on the timeline, i.e. in the middle of ministep M3. If we are interested in the rate at this time the function: - ecl_sum_data_get_from_sim_time() + rd_sum_data_get_from_sim_time() will just return the M3 value, whereas if you are interested in e.g. pressure at this time the function will return a weighted average of the M2 and M3 values. Whether a variable in question is interpreted as a 'rate' is effectively determined by the - ecl_smspec_set_rate_var() function in ecl_smspec.c. + rd_smspec_set_rate_var() function in rd_smspec.c. @@ -163,32 +163,32 @@ Partly due to EnKF heritage the MINISTEP nr has been the main method to access the time dimension of the data, i.e. all the - functions like ecl_sum_get_general_var() expect the time direction + functions like rd_sum_get_general_var() expect the time direction to be given as a ministep; however it is also possible to get the data by giving an internal (not that internal ...) index. In - ecl_sum_data.c the latter functions have _iget(): + rd_sum_data.c the latter functions have _iget(): - ecl_sum_data_get_xxx : Expects the time direction given as a ministep_nr. - ecl_sum_data_iget_xxx: Expects the time direction given as an internal index. + rd_sum_data_get_xxx : Expects the time direction given as a ministep_nr. + rd_sum_data_iget_xxx: Expects the time direction given as an internal index. */ -namespace ecl { +namespace rd { -ecl_sum_file_data::ecl_sum_file_data(const ecl_smspec_type *smspec) - : ecl_smspec(smspec), data(vector_alloc_new()) {} +rd_sum_file_data::rd_sum_file_data(const rd_smspec_type *smspec) + : rd_smspec(smspec), data(vector_alloc_new()) {} -ecl_sum_file_data::~ecl_sum_file_data() { vector_free(data); } +rd_sum_file_data::~rd_sum_file_data() { vector_free(data); } -int ecl_sum_file_data::length() const { +int rd_sum_file_data::length() const { if (this->loader) return this->loader->length(); else return this->index.size(); } -int ecl_sum_file_data::length_before(time_t end_time) const { +int rd_sum_file_data::length_before(time_t end_time) const { int offset = 0; while (true) { time_t itime = this->iget_sim_time(offset); @@ -201,7 +201,7 @@ int ecl_sum_file_data::length_before(time_t end_time) const { } } -int ecl_sum_file_data::report_before(time_t end_time) const { +int rd_sum_file_data::report_before(time_t end_time) const { if (end_time < this->first_report()) throw std::invalid_argument("time argument before first report step"); @@ -219,30 +219,30 @@ int ecl_sum_file_data::report_before(time_t end_time) const { } } -int ecl_sum_file_data::first_report() const { +int rd_sum_file_data::first_report() const { const auto &node = this->index[0]; return node.report_step; } -int ecl_sum_file_data::last_report() const { +int rd_sum_file_data::last_report() const { const auto &node = this->index.back(); return node.report_step; } -time_t ecl_sum_file_data::get_data_start() const { +time_t rd_sum_file_data::get_data_start() const { const auto &node = this->index[0]; return node.sim_time; } -time_t ecl_sum_file_data::get_sim_end() const { +time_t rd_sum_file_data::get_sim_end() const { if (this->index.size() == 0) throw std::out_of_range( - "ecl_sum_file_data::get_sim_end(): index size is 0"); + "rd_sum_file_data::get_sim_end(): index size is 0"); const auto &node = this->index.back(); return node.sim_time; } -time_t ecl_sum_file_data::iget_sim_time(int time_index) const { +time_t rd_sum_file_data::iget_sim_time(int time_index) const { const auto &node = this->index[time_index]; return node.sim_time; } @@ -250,45 +250,45 @@ time_t ecl_sum_file_data::iget_sim_time(int time_index) const { /* Will return the length of the simulation in whatever units were used in input. */ -double ecl_sum_file_data::get_sim_length() const { +double rd_sum_file_data::get_sim_length() const { const auto &node = this->index.back(); - return node.sim_seconds / ecl_smspec_get_time_seconds(this->ecl_smspec); + return node.sim_seconds / rd_smspec_get_time_seconds(this->rd_smspec); } -double ecl_sum_file_data::iget(int time_index, int params_index) const { +double rd_sum_file_data::iget(int time_index, int params_index) const { if (this->loader) return this->loader->iget(time_index, params_index); else { - const ecl_sum_tstep_type *ministep_data = iget_ministep(time_index); - return ecl_sum_tstep_iget(ministep_data, params_index); + const rd_sum_tstep_type *ministep_data = iget_ministep(time_index); + return rd_sum_tstep_iget(ministep_data, params_index); } } -void ecl_sum_file_data::append_tstep(ecl_sum_tstep_type *tstep) { +void rd_sum_file_data::append_tstep(rd_sum_tstep_type *tstep) { /* Here the tstep is just appended naively, the vector will be sorted by ministep_nr before the data instance is returned. */ - vector_append_owned_ref(data, tstep, ecl_sum_tstep_free__); + vector_append_owned_ref(data, tstep, rd_sum_tstep_free__); } /* This function is meant to be called in write mode; and will create a new and empty tstep which is appended to the current data. The tstep will also be returned, so the calling scope can call - ecl_sum_tstep_iset() to set elements in the tstep. + rd_sum_tstep_iset() to set elements in the tstep. */ -ecl_sum_tstep_type *ecl_sum_file_data::add_new_tstep(int report_step, - double sim_seconds) { +rd_sum_tstep_type *rd_sum_file_data::add_new_tstep(int report_step, + double sim_seconds) { int ministep_nr = vector_get_size(data); - ecl_sum_tstep_type *tstep = ecl_sum_tstep_alloc_new( - report_step, ministep_nr, sim_seconds, ecl_smspec); - ecl_sum_tstep_type *prev_tstep = NULL; + rd_sum_tstep_type *tstep = rd_sum_tstep_alloc_new(report_step, ministep_nr, + sim_seconds, rd_smspec); + rd_sum_tstep_type *prev_tstep = NULL; if (vector_get_size(data) > 0) - prev_tstep = (ecl_sum_tstep_type *)vector_get_last(data); + prev_tstep = (rd_sum_tstep_type *)vector_get_last(data); append_tstep(tstep); @@ -296,21 +296,20 @@ ecl_sum_tstep_type *ecl_sum_file_data::add_new_tstep(int report_step, /* In the simple case that we just add another timestep to the currently active report_step, we do a limited update of the - index, otherwise we call ecl_sum_data_build_index() to get a + index, otherwise we call rd_sum_data_build_index() to get a full recalculation of the index. */ if (!prev_tstep) goto exit; - if (ecl_sum_tstep_get_report(prev_tstep) != ecl_sum_tstep_get_report(tstep)) + if (rd_sum_tstep_get_report(prev_tstep) != rd_sum_tstep_get_report(tstep)) goto exit; - if (ecl_sum_tstep_get_sim_days(prev_tstep) >= - ecl_sum_tstep_get_sim_days(tstep)) + if (rd_sum_tstep_get_sim_days(prev_tstep) >= + rd_sum_tstep_get_sim_days(tstep)) goto exit; - this->index.add(ecl_sum_tstep_get_sim_time(tstep), sim_seconds, - report_step); + this->index.add(rd_sum_tstep_get_sim_time(tstep), sim_seconds, report_step); rebuild_index = false; exit: @@ -320,26 +319,26 @@ ecl_sum_tstep_type *ecl_sum_file_data::add_new_tstep(int report_step, return tstep; } -ecl_sum_tstep_type *ecl_sum_file_data::iget_ministep(int internal_index) const { - return (ecl_sum_tstep_type *)vector_iget(data, internal_index); +rd_sum_tstep_type *rd_sum_file_data::iget_ministep(int internal_index) const { + return (rd_sum_tstep_type *)vector_iget(data, internal_index); } -double ecl_sum_file_data::iget_sim_days(int time_index) const { +double rd_sum_file_data::iget_sim_days(int time_index) const { const auto &node = this->index[time_index]; return node.sim_seconds / 86400; } -double ecl_sum_file_data::iget_sim_seconds(int time_index) const { +double rd_sum_file_data::iget_sim_seconds(int time_index) const { const auto &node = this->index[time_index]; return node.sim_seconds; } static int cmp_ministep(const void *arg1, const void *arg2) { - const ecl_sum_tstep_type *ministep1 = ecl_sum_tstep_safe_cast_const(arg1); - const ecl_sum_tstep_type *ministep2 = ecl_sum_tstep_safe_cast_const(arg2); + const rd_sum_tstep_type *ministep1 = rd_sum_tstep_safe_cast_const(arg1); + const rd_sum_tstep_type *ministep2 = rd_sum_tstep_safe_cast_const(arg2); - time_t time1 = ecl_sum_tstep_get_sim_time(ministep1); - time_t time2 = ecl_sum_tstep_get_sim_time(ministep2); + time_t time1 = rd_sum_tstep_get_sim_time(ministep1); + time_t time2 = rd_sum_tstep_get_sim_time(ministep2); if (time1 < time2) return -1; @@ -349,11 +348,11 @@ static int cmp_ministep(const void *arg1, const void *arg2) { return 1; } -void ecl_sum_file_data::build_index() { +void rd_sum_file_data::build_index() { this->index.clear(); if (this->loader) { - int offset = ecl_smspec_get_first_step(this->ecl_smspec) - 1; + int offset = rd_smspec_get_first_step(this->rd_smspec) - 1; std::vector report_steps = this->loader->report_steps(offset); std::vector sim_time = this->loader->sim_time(); std::vector sim_seconds = this->loader->sim_seconds(); @@ -365,20 +364,20 @@ void ecl_sum_file_data::build_index() { vector_sort(data, cmp_ministep); for (int internal_index = 0; internal_index < vector_get_size(data); internal_index++) { - const ecl_sum_tstep_type *ministep = iget_ministep(internal_index); - this->index.add(ecl_sum_tstep_get_sim_time(ministep), - ecl_sum_tstep_get_sim_seconds(ministep), - ecl_sum_tstep_get_report(ministep)); + const rd_sum_tstep_type *ministep = iget_ministep(internal_index); + this->index.add(rd_sum_tstep_get_sim_time(ministep), + rd_sum_tstep_get_sim_seconds(ministep), + rd_sum_tstep_get_report(ministep)); } } } -void ecl_sum_file_data::get_time(int length, time_t *data) { +void rd_sum_file_data::get_time(int length, time_t *data) { for (int time_index = 0; time_index < length; time_index++) data[time_index] = this->iget_sim_time(time_index); } -int ecl_sum_file_data::get_time_report(int end_index, time_t *data) { +int rd_sum_file_data::get_time_report(int end_index, time_t *data) { int offset = 0; for (int report_step = this->first_report(); @@ -395,7 +394,7 @@ int ecl_sum_file_data::get_time_report(int end_index, time_t *data) { return offset; } -void ecl_sum_file_data::get_data(int params_index, int length, double *data) { +void rd_sum_file_data::get_data(int params_index, int length, double *data) { if (this->loader) { const auto tmp_data = loader->get_vector(params_index); memcpy(data, tmp_data.data(), length * sizeof data); @@ -405,8 +404,8 @@ void ecl_sum_file_data::get_data(int params_index, int length, double *data) { } } -int ecl_sum_file_data::get_data_report(int params_index, int end_index, - double *data, double default_value) { +int rd_sum_file_data::get_data_report(int params_index, int end_index, + double *data, double default_value) { int offset = 0; for (int report_step = this->first_report(); @@ -425,35 +424,35 @@ int ecl_sum_file_data::get_data_report(int params_index, int end_index, return offset; } -bool ecl_sum_file_data::has_report(int report_step) const { +bool rd_sum_file_data::has_report(int report_step) const { return this->index.has_report(report_step); } -std::pair ecl_sum_file_data::report_range(int report_step) const { +std::pair rd_sum_file_data::report_range(int report_step) const { return this->index.report_range(report_step); } -void ecl_sum_file_data::fwrite_report(int report_step, - fortio_type *fortio) const { +void rd_sum_file_data::fwrite_report(int report_step, + fortio_type *fortio) const { { - ecl_kw_type *seqhdr_kw = ecl_kw_alloc(SEQHDR_KW, SEQHDR_SIZE, ECL_INT); - ecl_kw_iset_int(seqhdr_kw, 0, 0); - ecl_kw_fwrite(seqhdr_kw, fortio); - ecl_kw_free(seqhdr_kw); + rd_kw_type *seqhdr_kw = rd_kw_alloc(SEQHDR_KW, SEQHDR_SIZE, RD_INT); + rd_kw_iset_int(seqhdr_kw, 0, 0); + rd_kw_fwrite(seqhdr_kw, fortio); + rd_kw_free(seqhdr_kw); } { auto range = this->report_range(report_step); for (int index = range.first; index <= range.second; index++) { - const ecl_sum_tstep_type *tstep = iget_ministep(index); - //ecl_sum_tstep_fwrite( tstep , ecl_smspec_get_index_map( ecl_smspec ) , fortio ); - ecl_sum_tstep_fwrite(tstep, ecl_smspec_get_index_map(ecl_smspec), - ecl_smspec_num_nodes(ecl_smspec), fortio); + const rd_sum_tstep_type *tstep = iget_ministep(index); + //rd_sum_tstep_fwrite( tstep , rd_smspec_get_index_map( rd_smspec ) , fortio ); + rd_sum_tstep_fwrite(tstep, rd_smspec_get_index_map(rd_smspec), + rd_smspec_num_nodes(rd_smspec), fortio); } } } -void ecl_sum_file_data::fwrite_unified(fortio_type *fortio) const { +void rd_sum_file_data::fwrite_unified(fortio_type *fortio) const { if (this->length() == 0) return; @@ -464,18 +463,18 @@ void ecl_sum_file_data::fwrite_unified(fortio_type *fortio) const { } } -void ecl_sum_file_data::fwrite_multiple(const char *ecl_case, - bool fmt_case) const { +void rd_sum_file_data::fwrite_multiple(const char *rd_case, + bool fmt_case) const { if (this->length() == 0) return; for (int report_step = this->first_report(); report_step <= this->last_report(); report_step++) { if (this->has_report(report_step)) { - char *filename = ecl_util_alloc_filename( - NULL, ecl_case, ECL_SUMMARY_FILE, fmt_case, report_step); + char *filename = rd_alloc_filename(NULL, rd_case, RD_SUMMARY_FILE, + fmt_case, report_step); fortio_type *fortio = - fortio_open_writer(filename, fmt_case, ECL_ENDIAN_FLIP); + fortio_open_writer(filename, fmt_case, RD_ENDIAN_FLIP); fwrite_report(report_step, fortio); @@ -485,22 +484,22 @@ void ecl_sum_file_data::fwrite_multiple(const char *ecl_case, } } -bool ecl_sum_file_data::can_write() const { +bool rd_sum_file_data::can_write() const { if (this->loader) return false; return true; } -double ecl_sum_file_data::get_days_start() const { +double rd_sum_file_data::get_days_start() const { const auto &node = this->index[0]; return node.sim_seconds * 86400; } -bool ecl_sum_file_data::check_file(ecl_file_type *ecl_file) { - return ecl_file_has_kw(ecl_file, PARAMS_KW) && - (ecl_file_get_num_named_kw(ecl_file, PARAMS_KW) == - ecl_file_get_num_named_kw(ecl_file, MINISTEP_KW)); +bool rd_sum_file_data::check_file(rd_file_type *rd_file) { + return rd_file_has_kw(rd_file, PARAMS_KW) && + (rd_file_get_num_named_kw(rd_file, PARAMS_KW) == + rd_file_get_num_named_kw(rd_file, MINISTEP_KW)); } /** @@ -512,40 +511,40 @@ bool ecl_sum_file_data::check_file(ecl_file_type *ecl_file) { containing only the 'SEQHDR' keyword is written - this is currently an 'invalid' summary section. - 2. ECLIPSE simulates as best it can. + 2. ECLIPSE simulates. 3. When the time step is complete data is written to the summary file. - Now - if ECLIPSE goes down in flames during step 2 a malformed + Now - if ECLIPSE goes down during step 2 a malformed summary file will be left around, to handle this situation - reasonably gracefully we check that the ecl_file instance has at + reasonably gracefully we check that the rd_file instance has at least one "PARAMS" keyword. - One ecl_file corresponds to one report_step (limited by SEQHDR); in + One rd_file corresponds to one report_step (limited by SEQHDR); in the case of non unfied summary files these objects correspond to one BASE.Annnn or BASE.Snnnn file, in the case of unified files the calling routine will read the unified summary file partly. */ -void ecl_sum_file_data::add_ecl_file(int report_step, - const ecl_file_view_type *summary_view) { +void rd_sum_file_data::add_rd_file(int report_step, + const rd_file_view_type *summary_view) { - int num_ministep = ecl_file_view_get_num_named_kw(summary_view, PARAMS_KW); + int num_ministep = rd_file_view_get_num_named_kw(summary_view, PARAMS_KW); if (num_ministep > 0) { int ikw; for (ikw = 0; ikw < num_ministep; ikw++) { - ecl_kw_type *ministep_kw = - ecl_file_view_iget_named_kw(summary_view, MINISTEP_KW, ikw); - ecl_kw_type *params_kw = - ecl_file_view_iget_named_kw(summary_view, PARAMS_KW, ikw); + rd_kw_type *ministep_kw = + rd_file_view_iget_named_kw(summary_view, MINISTEP_KW, ikw); + rd_kw_type *params_kw = + rd_file_view_iget_named_kw(summary_view, PARAMS_KW, ikw); { - int ministep_nr = ecl_kw_iget_int(ministep_kw, 0); - ecl_sum_tstep_type *tstep = ecl_sum_tstep_alloc_from_file( + int ministep_nr = rd_kw_iget_int(ministep_kw, 0); + rd_sum_tstep_type *tstep = rd_sum_tstep_alloc_from_file( report_step, ministep_nr, params_kw, - ecl_file_view_get_src_file(summary_view), this->ecl_smspec); + rd_file_view_get_src_file(summary_view), this->rd_smspec); if (tstep) append_tstep(tstep); @@ -554,43 +553,43 @@ void ecl_sum_file_data::add_ecl_file(int report_step, } } -bool ecl_sum_file_data::fread(const stringlist_type *filelist, bool lazy_load, - int file_options) { +bool rd_sum_file_data::fread(const stringlist_type *filelist, bool lazy_load, + int file_options) { if (stringlist_get_size(filelist) == 0) return false; - ecl_file_enum file_type = - ecl_util_get_file_type(stringlist_iget(filelist, 0), NULL, NULL); - if ((stringlist_get_size(filelist) > 1) && (file_type != ECL_SUMMARY_FILE)) + rd_file_enum file_type = + rd_get_file_type(stringlist_iget(filelist, 0), NULL, NULL); + if ((stringlist_get_size(filelist) > 1) && (file_type != RD_SUMMARY_FILE)) util_abort("%s: internal error - when calling with more than one file " "- you can not supply a unified file - come on?! \n", __func__); - if (file_type == ECL_SUMMARY_FILE) { + if (file_type == RD_SUMMARY_FILE) { /* Not unified. */ for (int filenr = 0; filenr < stringlist_get_size(filelist); filenr++) { const char *data_file = stringlist_iget(filelist, filenr); - ecl_file_enum file_type; + rd_file_enum file_type; int report_step; - file_type = ecl_util_get_file_type(data_file, NULL, &report_step); - if (file_type != ECL_SUMMARY_FILE) + file_type = rd_get_file_type(data_file, NULL, &report_step); + if (file_type != RD_SUMMARY_FILE) util_abort("%s: file:%s has wrong type \n", __func__, data_file); { - ecl_file_type *ecl_file = ecl_file_open(data_file, 0); - if (ecl_file && check_file(ecl_file)) { - this->add_ecl_file(report_step, - ecl_file_get_global_view(ecl_file)); - ecl_file_close(ecl_file); + rd_file_type *rd_file = rd_file_open(data_file, 0); + if (rd_file && check_file(rd_file)) { + this->add_rd_file(report_step, + rd_file_get_global_view(rd_file)); + rd_file_close(rd_file); } } } - } else if (file_type == ECL_UNIFIED_SUMMARY_FILE) { + } else if (file_type == RD_UNIFIED_SUMMARY_FILE) { if (lazy_load) { try { this->loader.reset(new unsmry_loader( - this->ecl_smspec, stringlist_iget(filelist, 0), + this->rd_smspec, stringlist_iget(filelist, 0), file_options)); } catch (const std::bad_alloc &e) { return false; @@ -599,30 +598,30 @@ bool ecl_sum_file_data::fread(const stringlist_type *filelist, bool lazy_load, // Is this correct for a restarted chain of UNSMRY files? Looks like the // report step sequence will be restarted? - ecl_file_type *ecl_file = - ecl_file_open(stringlist_iget(filelist, 0), 0); - if (ecl_file && check_file(ecl_file)) { + rd_file_type *rd_file = + rd_file_open(stringlist_iget(filelist, 0), 0); + if (rd_file && check_file(rd_file)) { int first_report_step = - ecl_smspec_get_first_step(this->ecl_smspec); + rd_smspec_get_first_step(this->rd_smspec); int block_index = 0; while (true) { /* Observe that there is a number discrepancy between ECLIPSE - and the ecl_file_select_smryblock() function. ECLIPSE + and the rd_file_select_smryblock() function. ECLIPSE starts counting report steps at 1; whereas the first SEQHDR block in the unified summary file is block zero (in ert counting). */ - ecl_file_view_type *summary_view = - ecl_file_get_summary_view(ecl_file, block_index); + rd_file_view_type *summary_view = + rd_file_get_summary_view(rd_file, block_index); if (summary_view) { - this->add_ecl_file(block_index + first_report_step, - summary_view); + this->add_rd_file(block_index + first_report_step, + summary_view); block_index++; } else break; } - ecl_file_close(ecl_file); + rd_file_close(rd_file); } } } @@ -631,12 +630,12 @@ bool ecl_sum_file_data::fread(const stringlist_type *filelist, bool lazy_load, return (length() > 0); } -const ecl_smspec_type *ecl_sum_file_data::smspec() const { - return this->ecl_smspec; +const rd_smspec_type *rd_sum_file_data::smspec() const { + return this->rd_smspec; } -bool ecl_sum_file_data::report_step_equal(const ecl_sum_file_data &other, - bool strict) const { +bool rd_sum_file_data::report_step_equal(const rd_sum_file_data &other, + bool strict) const { if (strict && this->first_report() != other.first_report()) return false; @@ -669,7 +668,7 @@ bool ecl_sum_file_data::report_step_equal(const ecl_sum_file_data &other, return true; } -int ecl_sum_file_data::report_step_from_days(double sim_days) const { +int rd_sum_file_data::report_step_from_days(double sim_days) const { int report_step = this->first_report(); double sim_seconds = sim_days * 86400; while (true) { @@ -688,7 +687,7 @@ int ecl_sum_file_data::report_step_from_days(double sim_days) const { } } -int ecl_sum_file_data::report_step_from_time(time_t sim_time) const { +int rd_sum_file_data::report_step_from_time(time_t sim_time) const { int report_step = this->first_report(); while (true) { const auto &range = this->index.report_range(report_step); @@ -704,9 +703,9 @@ int ecl_sum_file_data::report_step_from_time(time_t sim_time) const { } } -int ecl_sum_file_data::iget_report(int time_index) const { +int rd_sum_file_data::iget_report(int time_index) const { const auto &index_node = this->index[time_index]; return index_node.report_step; } -} // namespace ecl +} // namespace rd diff --git a/lib/ecl/ecl_sum_index.cpp b/lib/resdata/rd_sum_index.cpp similarity index 72% rename from lib/ecl/ecl_sum_index.cpp rename to lib/resdata/rd_sum_index.cpp index c0c0cc4cfa..c14b2af27d 100644 --- a/lib/ecl/ecl_sum_index.cpp +++ b/lib/resdata/rd_sum_index.cpp @@ -1,15 +1,15 @@ -#include +#include /* This file contains all the internalized information from parsing a - SMSPEC file. In most cases the ecl_sum object will contain a - ecl_sum_index_type instance, and the end-user will not have direct - interaction with the ecl_sum_index_type - but for instance when + SMSPEC file. In most cases the rd_sum object will contain a + rd_sum_index_type instance, and the end-user will not have direct + interaction with the rd_sum_index_type - but for instance when working with an ensemble of identical summary results one can use a - shared ecl_sum_index instance. + shared rd_sum_index instance. */ -struct ecl_sum_index_type { +struct rd_sum_index_type { hash_type *well_var_index; /* Indexes for all well variables. */ hash_type *well_completion_var_index; /* Indexes for completion indexes .*/ hash_type *group_var_index; /* Indexes for group variables. */ diff --git a/lib/resdata/rd_sum_tstep.cpp b/lib/resdata/rd_sum_tstep.cpp new file mode 100644 index 0000000000..d47749b518 --- /dev/null +++ b/lib/resdata/rd_sum_tstep.cpp @@ -0,0 +1,333 @@ +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#define RD_SUM_TSTEP_ID 88631 + +/* + This file implements the rd_sum_tstep datatype which contains the + summary information for all summary vectors at one instant in + time. If we view the summary data as this: + + +Header direction: rd_smspec DAYS WWCT:OP_3 FOPT BPR:15,10,25 + -------------------------------------------- + /|\ 0.00 0.00 0.00 256.00 <-- One timestep rd_sum_tstep + | 10.00 0.56 10.00 255.00 + Time direction: rd_sum_data 20.00 0.61 18.70 253.00 + | 30.00 0.63 21.20 251.00 + | ... + \|/ 90.00 0.80 39.70 244.00 + -------------------------------------------- + + The rd_sum_tstep structure corresponds to one 'horizontal line' in + the summary data. + + These timesteps correspond exactly to the simulators timesteps, + i.e. when convergence is poor they are closely spaced. In the + summary files these time steps are called "MINISTEPS" - and + that term is also used some places in the rd_sum_xxx codebase. + */ + +struct rd_sum_tstep_struct { + UTIL_TYPE_ID_DECLARATION; + std::vector + data; /* A memcpy copy of the PARAMS vector in rd_kw instance - the raw data. */ + time_t + sim_time; /* The true time (i.e. 20.th of october 2010) of corresponding to this timestep. */ + int ministep; /* The simulator time-step number; one ministep per numerical timestep. */ + int report_step; /* The report step this time-step is part of - in general there can be many timestep for each report step. */ + double sim_seconds; /* Accumulated simulation time up to this ministep. */ + int internal_index; /* Used for lookups of the next / previous ministep based on an existing ministep. */ + const rd_smspec_type * + smspec; /* The smespec header information for this tstep - must be compatible. */ +}; + +rd_sum_tstep_type * +rd_sum_tstep_alloc_remap_copy(const rd_sum_tstep_type *src, + const rd_smspec_type *new_smspec, + float default_value, const int *params_map) { + int params_size = rd_smspec_get_params_size(new_smspec); + rd_sum_tstep_type *target = new rd_sum_tstep_type(); + UTIL_TYPE_ID_INIT(target, RD_SUM_TSTEP_ID); + target->report_step = src->report_step; + target->ministep = src->ministep; + + target->smspec = new_smspec; + target->data.resize(params_size); + for (int i = 0; i < params_size; i++) { + + if (params_map[i] >= 0) + target->data[i] = src->data[params_map[i]]; + else + target->data[i] = default_value; + } + return target; +} + +rd_sum_tstep_type *rd_sum_tstep_alloc_copy(const rd_sum_tstep_type *src) { + rd_sum_tstep_type *target = new rd_sum_tstep_type(); + UTIL_TYPE_ID_INIT(target, RD_SUM_TSTEP_ID); + target->smspec = src->smspec; + target->report_step = src->report_step; + target->ministep = src->ministep; + target->data = src->data; + return target; +} + +static rd_sum_tstep_type *rd_sum_tstep_alloc(int report_step, int ministep_nr, + const rd_smspec_type *smspec) { + rd_sum_tstep_type *tstep = new rd_sum_tstep_type(); + UTIL_TYPE_ID_INIT(tstep, RD_SUM_TSTEP_ID); + tstep->smspec = smspec; + tstep->report_step = report_step; + tstep->ministep = ministep_nr; + tstep->data.resize(rd_smspec_get_params_size(smspec)); + return tstep; +} + +UTIL_SAFE_CAST_FUNCTION(rd_sum_tstep, RD_SUM_TSTEP_ID) +UTIL_SAFE_CAST_FUNCTION_CONST(rd_sum_tstep, RD_SUM_TSTEP_ID) + +void rd_sum_tstep_free(rd_sum_tstep_type *ministep) { delete ministep; } + +void rd_sum_tstep_free__(void *__ministep) { + rd_sum_tstep_type *ministep = rd_sum_tstep_safe_cast(__ministep); + rd_sum_tstep_free(ministep); +} + +/** + This function sets the internal time representation in the + rd_sum_tstep. The treatment of time is a bit weird; on the one + hand the time elements in the summary data are just like any other + element like e.g. the FOPT or GGPR:NAME - on the other hand the + time information is strictly required and the summary file will + fall to pieces if it is missing. + + The time can be provided in using (at least) two different + keywords: + + DAYS/HOURS: The data vector will contain the number of + days/hours since the simulation start (hours in the case + of lab units). + + DAY,MONTH,YEAR: The data vector will contain the true date of + the tstep. + + The rd_sum_tstep class can utilize both types of information, but + will select the DAYS variety if both are present. +*/ + +static void rd_sum_tstep_set_time_info_from_seconds(rd_sum_tstep_type *tstep, + time_t sim_start, + double sim_seconds) { + tstep->sim_seconds = sim_seconds; + tstep->sim_time = sim_start; + util_inplace_forward_seconds_utc(&tstep->sim_time, tstep->sim_seconds); +} + +static void rd_sum_tstep_set_time_info_from_date(rd_sum_tstep_type *tstep, + time_t sim_start, + time_t sim_time) { + tstep->sim_time = sim_time; + tstep->sim_seconds = util_difftime_seconds(sim_start, tstep->sim_time); +} + +static void rd_sum_tstep_set_time_info(rd_sum_tstep_type *tstep, + const rd_smspec_type *smspec) { + int date_day_index = rd_smspec_get_date_day_index(smspec); + int date_month_index = rd_smspec_get_date_month_index(smspec); + int date_year_index = rd_smspec_get_date_year_index(smspec); + int sim_time_index = rd_smspec_get_time_index(smspec); + time_t sim_start = rd_smspec_get_start_time(smspec); + + if (sim_time_index >= 0) { + double sim_time = tstep->data[sim_time_index]; + double sim_seconds = sim_time * rd_smspec_get_time_seconds(smspec); + rd_sum_tstep_set_time_info_from_seconds(tstep, sim_start, sim_seconds); + } else if (date_day_index >= 0) { + int day = util_roundf(tstep->data[date_day_index]); + int month = util_roundf(tstep->data[date_month_index]); + int year = util_roundf(tstep->data[date_year_index]); + + time_t sim_time = rd_make_date(day, month, year); + rd_sum_tstep_set_time_info_from_date(tstep, sim_start, sim_time); + } else + util_abort("%s: Hmmm - could not extract date/time information from " + "SMSPEC header file? \n", + __func__); +} + +/** + If the rd_kw instance is in some way invalid (i.e. wrong size); + the function will return NULL: +*/ + +rd_sum_tstep_type *rd_sum_tstep_alloc_from_file(int report_step, + int ministep_nr, + const rd_kw_type *params_kw, + const char *src_file, + const rd_smspec_type *smspec) { + + int data_size = rd_kw_get_size(params_kw); + + if (data_size == rd_smspec_get_params_size(smspec)) { + rd_sum_tstep_type *ministep = + rd_sum_tstep_alloc(report_step, ministep_nr, smspec); + rd_kw_get_memcpy_data(params_kw, ministep->data.data()); + rd_sum_tstep_set_time_info(ministep, smspec); + return ministep; + } else { + /* + This is actually a fatal error / bug; the difference in smspec + header structure should have been detected already in the + rd_smspec_load_restart() function and the restart case + discarded. + */ + fprintf(stderr, + "** Warning size mismatch between timestep loaded from:%s(%d) " + "and header:%s(%d) - timestep discarded.\n", + src_file, data_size, rd_smspec_get_header_file(smspec), + rd_smspec_get_params_size(smspec)); + return NULL; + } +} + +/* + Should be called in write mode. +*/ + +rd_sum_tstep_type *rd_sum_tstep_alloc_new(int report_step, int ministep, + float sim_seconds, + const rd_smspec_type *smspec) { + rd_sum_tstep_type *tstep = + rd_sum_tstep_alloc(report_step, ministep, smspec); + tstep->data = rd_smspec_get_params_default(smspec); + + rd_sum_tstep_set_time_info_from_seconds( + tstep, rd_smspec_get_start_time(smspec), sim_seconds); + rd_sum_tstep_iset(tstep, rd_smspec_get_time_index(smspec), + sim_seconds / rd_smspec_get_time_seconds(smspec)); + return tstep; +} + +double rd_sum_tstep_iget(const rd_sum_tstep_type *ministep, int index) { + if ((index >= 0) && (index < (int)ministep->data.size())) + return ministep->data[index]; + else { + util_abort("%s: param index:%d invalid: Valid range: [0,%d) \n", + __func__, index, ministep->data.size()); + return -1; + } +} + +time_t rd_sum_tstep_get_sim_time(const rd_sum_tstep_type *ministep) { + return ministep->sim_time; +} + +double rd_sum_tstep_get_sim_days(const rd_sum_tstep_type *ministep) { + return ministep->sim_seconds / (24 * 3600); +} + +double rd_sum_tstep_get_sim_seconds(const rd_sum_tstep_type *ministep) { + return ministep->sim_seconds; +} + +int rd_sum_tstep_get_report(const rd_sum_tstep_type *ministep) { + return ministep->report_step; +} + +int rd_sum_tstep_get_ministep(const rd_sum_tstep_type *ministep) { + return ministep->ministep; +} + +void rd_sum_tstep_fwrite(const rd_sum_tstep_type *ministep, + const int *index_map, int index_map_size, + fortio_type *fortio) { + { + rd_kw_type *ministep_kw = rd_kw_alloc(MINISTEP_KW, 1, RD_INT); + rd_kw_iset_int(ministep_kw, 0, ministep->ministep); + rd_kw_fwrite(ministep_kw, fortio); + rd_kw_free(ministep_kw); + } + + { + int compact_size = index_map_size; + rd_kw_type *params_kw = rd_kw_alloc(PARAMS_KW, compact_size, RD_FLOAT); + + float *data = (float *)rd_kw_get_ptr(params_kw); + + { + int i; + for (i = 0; i < compact_size; i++) + data[i] = ministep->data[index_map[i]]; + } + rd_kw_fwrite(params_kw, fortio); + rd_kw_free(params_kw); + } +} + +void rd_sum_tstep_iset(rd_sum_tstep_type *tstep, int index, float value) { + if ((index < static_cast(tstep->data.size())) && (index >= 0)) + tstep->data[index] = value; + else + util_abort("%s: index:%d invalid. Valid range: [0,%d) \n", __func__, + index, tstep->data.size()); +} + +void rd_sum_tstep_iscale(rd_sum_tstep_type *tstep, int index, float scalar) { + rd_sum_tstep_iset(tstep, index, rd_sum_tstep_iget(tstep, index) * scalar); +} + +void rd_sum_tstep_ishift(rd_sum_tstep_type *tstep, int index, float addend) { + rd_sum_tstep_iset(tstep, index, rd_sum_tstep_iget(tstep, index) + addend); +} + +void rd_sum_tstep_set_from_node(rd_sum_tstep_type *tstep, + const rd::smspec_node &smspec_node, + float value) { + int data_index = smspec_node_get_params_index(&smspec_node); + rd_sum_tstep_iset(tstep, data_index, value); +} + +double rd_sum_tstep_get_from_node(const rd_sum_tstep_type *tstep, + const rd::smspec_node &smspec_node) { + int data_index = smspec_node_get_params_index(&smspec_node); + return rd_sum_tstep_iget(tstep, data_index); +} + +void rd_sum_tstep_set_from_key(rd_sum_tstep_type *tstep, const char *gen_key, + float value) { + const rd::smspec_node &smspec_node = + rd_smspec_get_general_var_node(tstep->smspec, gen_key); + rd_sum_tstep_set_from_node(tstep, smspec_node, value); +} + +double rd_sum_tstep_get_from_key(const rd_sum_tstep_type *tstep, + const char *gen_key) { + const rd::smspec_node &smspec_node = + rd_smspec_get_general_var_node(tstep->smspec, gen_key); + return rd_sum_tstep_get_from_node(tstep, smspec_node); +} + +bool rd_sum_tstep_has_key(const rd_sum_tstep_type *tstep, const char *gen_key) { + return rd_smspec_has_general_var(tstep->smspec, gen_key); +} + +bool rd_sum_tstep_sim_time_equal(const rd_sum_tstep_type *tstep1, + const rd_sum_tstep_type *tstep2) { + if (tstep1->sim_time == tstep2->sim_time) + return true; + else + return false; +} diff --git a/lib/resdata/rd_sum_vector.cpp b/lib/resdata/rd_sum_vector.cpp new file mode 100644 index 0000000000..76098f4d46 --- /dev/null +++ b/lib/resdata/rd_sum_vector.cpp @@ -0,0 +1,145 @@ +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#define RD_SUM_VECTOR_TYPE_ID 8768778 + +struct rd_sum_vector_struct { + UTIL_TYPE_ID_DECLARATION; + std::vector node_index_list; + std::vector is_rate_list; + std::vector key_list; + const rd_sum_type *rd_sum; +}; + +void rd_sum_vector_free(rd_sum_vector_type *rd_sum_vector) { + delete rd_sum_vector; +} + +UTIL_IS_INSTANCE_FUNCTION(rd_sum_vector, RD_SUM_VECTOR_TYPE_ID) + +static void rd_sum_vector_add_node(rd_sum_vector_type *vector, + const rd::smspec_node *node, + const char *key) { + int params_index = smspec_node_get_params_index(node); + bool is_rate_key = smspec_node_is_rate(node); + + vector->node_index_list.push_back(params_index); + vector->is_rate_list.push_back(is_rate_key); + vector->key_list.push_back(key); +} + +rd_sum_vector_type *rd_sum_vector_alloc(const rd_sum_type *rd_sum, + bool add_keywords) { + rd_sum_vector_type *rd_sum_vector = new rd_sum_vector_type(); + UTIL_TYPE_ID_INIT(rd_sum_vector, RD_SUM_VECTOR_TYPE_ID); + rd_sum_vector->rd_sum = rd_sum; + if (add_keywords) { + const rd_smspec_type *smspec = rd_sum_get_smspec(rd_sum); + for (int i = 0; i < rd_smspec_num_nodes(smspec); i++) { + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(smspec, i); + const char *key = smspec_node_get_gen_key1(&node); + /* + The TIME keyword is special case handled to not be included; that is + to match the same special casing in the key matching function. + */ + if (!util_string_equal(key, "TIME")) + rd_sum_vector_add_node(rd_sum_vector, &node, key); + } + } + return rd_sum_vector; +} + +static void rd_sum_vector_add_invalid_key(rd_sum_vector_type *vector, + const char *key) { + vector->node_index_list.push_back(-1); + vector->is_rate_list.push_back(false); + vector->key_list.push_back(key); +} + +/* + This function will allocate a keyword vector for the keys in the @rd_sum + argument passed in, it will contain all the same keys as in the input argument + @src_vector. If the @src_vector contains keys which are not present in + @rd_sum an entry marked as *invalid* will be added. The whole point about + this function is to ensure that calls to: + + rd_sum_fwrite_interp_csv_line( ) + + will result in nicely aligned output even if the different summary cases do + not have the exact same keys. +*/ + +rd_sum_vector_type * +rd_sum_vector_alloc_layout_copy(const rd_sum_vector_type *src_vector, + const rd_sum_type *rd_sum) { + rd_sum_vector_type *new_vector = rd_sum_vector_alloc(rd_sum, false); + for (size_t i = 0; i < src_vector->key_list.size(); i++) { + const char *key = src_vector->key_list[i].c_str(); + if (rd_sum_has_general_var(rd_sum, key)) + rd_sum_vector_add_key(new_vector, key); + else + rd_sum_vector_add_invalid_key(new_vector, key); + } + return new_vector; +} + +bool rd_sum_vector_add_key(rd_sum_vector_type *rd_sum_vector, const char *key) { + if (rd_sum_has_general_var(rd_sum_vector->rd_sum, key)) { + const rd::smspec_node *node = + rd_sum_get_general_var_node(rd_sum_vector->rd_sum, key); + rd_sum_vector_add_node(rd_sum_vector, node, key); + return true; + } else + return false; +} + +void rd_sum_vector_add_keys(rd_sum_vector_type *rd_sum_vector, + const char *pattern) { + stringlist_type *keylist = + rd_sum_alloc_matching_general_var_list(rd_sum_vector->rd_sum, pattern); + + int num_keywords = stringlist_get_size(keylist); + int i; + for (i = 0; i < num_keywords; i++) { + const char *key = stringlist_iget(keylist, i); + const rd::smspec_node *node = + rd_sum_get_general_var_node(rd_sum_vector->rd_sum, key); + rd_sum_vector_add_node(rd_sum_vector, node, key); + } + stringlist_free(keylist); +} + +int rd_sum_vector_get_size(const rd_sum_vector_type *rd_sum_vector) { + return rd_sum_vector->node_index_list.size(); +} + +bool rd_sum_vector_iget_is_rate(const rd_sum_vector_type *rd_sum_vector, + int index) { + return rd_sum_vector->is_rate_list[index]; +} + +bool rd_sum_vector_iget_valid(const rd_sum_vector_type *rd_sum_vector, + int index) { + return (rd_sum_vector->node_index_list[index] >= 0); +} + +int rd_sum_vector_iget_param_index(const rd_sum_vector_type *rd_sum_vector, + int index) { + return rd_sum_vector->node_index_list[index]; +} + +const char *rd_sum_vector_iget_key(const rd_sum_vector_type *rd_sum_vector, + int index) { + return rd_sum_vector->key_list[index].c_str(); +} diff --git a/lib/resdata/rd_type.cpp b/lib/resdata/rd_type.cpp new file mode 100644 index 0000000000..66059803e0 --- /dev/null +++ b/lib/resdata/rd_type.cpp @@ -0,0 +1,184 @@ +#include +#include +#include + +#include +#include + +#define RD_TYPE_NAME_CHAR "CHAR" +#define RD_TYPE_NAME_FLOAT "REAL" +#define RD_TYPE_NAME_INT "INTE" +#define RD_TYPE_NAME_DOUBLE "DOUB" +#define RD_TYPE_NAME_BOOL "LOGI" +#define RD_TYPE_NAME_MESSAGE "MESS" + +static char *alloc_string_name(const rd_data_type rd_type) { + return util_alloc_sprintf("C%03d", rd_type_get_sizeof_iotype(rd_type)); +} + +static bool is_rd_string_name(const char *type_name) { + return (type_name[0] == 'C' && isdigit(type_name[1]) && + isdigit(type_name[2]) && isdigit(type_name[3])); +} + +static size_t get_rd_string_length(const char *type_name) { + if (!is_rd_string_name(type_name)) + util_abort("%s: Expected eclipse string (CXXX), received %s\n", + __func__, type_name); + + return atoi(type_name + 1); +} + +rd_data_type rd_type_create(const rd_type_enum type, + const size_t element_size) { + rd_data_type rd_type = + (type == RD_STRING_TYPE ? RD_STRING(element_size) + : rd_type_create_from_type(type)); + + if ((size_t)rd_type_get_sizeof_iotype(rd_type) != element_size) + util_abort( + "%s: element_size mismatch for type %d, was: %d, expected: %d\n", + __func__, type, element_size, rd_type_get_sizeof_iotype(rd_type)); + + return rd_type; +} + +rd_data_type rd_type_create_from_type(const rd_type_enum type) { + switch (type) { + case (RD_CHAR_TYPE): + return RD_CHAR; + case (RD_INT_TYPE): + return RD_INT; + case (RD_FLOAT_TYPE): + return RD_FLOAT; + case (RD_DOUBLE_TYPE): + return RD_DOUBLE; + case (RD_BOOL_TYPE): + return RD_BOOL; + case (RD_MESS_TYPE): + return RD_MESS; + case (RD_STRING_TYPE): + util_abort("%s: Variable length string type cannot be created" + " from type alone!\n", + __func__); + return RD_STRING(0); /* Dummy */ + default: + util_abort("%s: invalid rd_type: %d\n", __func__, type); + return RD_INT; /* Dummy */ + } +} + +rd_type_enum rd_type_get_type(const rd_data_type rd_type) { + return rd_type.type; +} + +char *rd_type_alloc_name(const rd_data_type rd_type) { + switch (rd_type.type) { + case (RD_CHAR_TYPE): + return util_alloc_string_copy(RD_TYPE_NAME_CHAR); + case (RD_STRING_TYPE): + return alloc_string_name(rd_type); + case (RD_FLOAT_TYPE): + return util_alloc_string_copy(RD_TYPE_NAME_FLOAT); + case (RD_DOUBLE_TYPE): + return util_alloc_string_copy(RD_TYPE_NAME_DOUBLE); + case (RD_INT_TYPE): + return util_alloc_string_copy(RD_TYPE_NAME_INT); + case (RD_BOOL_TYPE): + return util_alloc_string_copy(RD_TYPE_NAME_BOOL); + case (RD_MESS_TYPE): + return util_alloc_string_copy(RD_TYPE_NAME_MESSAGE); + default: + util_abort("Internal error in %s - internal eclipse_type: %d not " + "recognized - aborting \n", + __func__, rd_type.type); + return NULL; /* Dummy */ + } +} + +rd_data_type rd_type_create_from_name(const char *type_name) { + if (strncmp(type_name, RD_TYPE_NAME_FLOAT, RD_TYPE_LENGTH) == 0) + return RD_FLOAT; + else if (strncmp(type_name, RD_TYPE_NAME_INT, RD_TYPE_LENGTH) == 0) + return RD_INT; + else if (strncmp(type_name, RD_TYPE_NAME_DOUBLE, RD_TYPE_LENGTH) == 0) + return RD_DOUBLE; + else if (strncmp(type_name, RD_TYPE_NAME_CHAR, RD_TYPE_LENGTH) == 0) + return RD_CHAR; + else if (is_rd_string_name(type_name)) + return RD_STRING(get_rd_string_length(type_name)); + else if (strncmp(type_name, RD_TYPE_NAME_MESSAGE, RD_TYPE_LENGTH) == 0) + return RD_MESS; + else if (strncmp(type_name, RD_TYPE_NAME_BOOL, RD_TYPE_LENGTH) == 0) + return RD_BOOL; + else { + util_abort("%s: unrecognized type name:%s \n", __func__, type_name); + return RD_INT; /* Dummy */ + } +} + +int rd_type_get_sizeof_ctype(const rd_data_type rd_type) { + return rd_type.element_size; +} + +int rd_type_get_sizeof_iotype(const rd_data_type rd_type) { + if (rd_type_is_bool(rd_type)) + return sizeof(int); + + if (rd_type_is_char(rd_type)) + return rd_type.element_size - 1; + + if (rd_type_is_string(rd_type)) + return rd_type.element_size - 1; + + return rd_type.element_size; +} + +bool rd_type_is_numeric(const rd_data_type rd_type) { + return (rd_type_is_int(rd_type) || rd_type_is_float(rd_type) || + rd_type_is_double(rd_type)); +} + +bool rd_type_is_alpha(const rd_data_type rd_type) { + return (rd_type_is_char(rd_type) || rd_type_is_mess(rd_type) || + rd_type_is_string(rd_type)); +} + +bool rd_type_is_equal(const rd_data_type rd_type1, + const rd_data_type rd_type2) { + return (rd_type1.type == rd_type2.type && + rd_type1.element_size == rd_type2.element_size); +} + +bool rd_type_is_char(const rd_data_type rd_type) { + return (rd_type.type == RD_CHAR_TYPE); +} + +bool rd_type_is_int(const rd_data_type rd_type) { + return (rd_type.type == RD_INT_TYPE); +} + +bool rd_type_is_float(const rd_data_type rd_type) { + return (rd_type.type == RD_FLOAT_TYPE); +} + +bool rd_type_is_double(const rd_data_type rd_type) { + return (rd_type.type == RD_DOUBLE_TYPE); +} + +bool rd_type_is_mess(const rd_data_type rd_type) { + return (rd_type.type == RD_MESS_TYPE); +} + +bool rd_type_is_bool(const rd_data_type rd_type) { + return (rd_type.type == RD_BOOL_TYPE); +} + +bool rd_type_is_string(const rd_data_type rd_type) { + return (rd_type.type == RD_STRING_TYPE); +} + +// Temporary fixup for OPM. +char *rd_type_get_name(const rd_data_type rd_type) { + return rd_type_alloc_name(rd_type); +} diff --git a/lib/resdata/rd_type_python.cpp b/lib/resdata/rd_type_python.cpp new file mode 100644 index 0000000000..1e79eaf485 --- /dev/null +++ b/lib/resdata/rd_type_python.cpp @@ -0,0 +1,118 @@ +#include +#include +#include + +/** + * + * Functions only to be used by the *PYTHON* prototype for ResDataType + * + */ + +#ifdef __cplusplus +extern "C" { + +rd_data_type *rd_type_alloc_copy_python(const rd_data_type *src_type) { + rd_data_type *data_type = (rd_data_type *)util_malloc(sizeof *src_type); + memcpy(data_type, src_type, sizeof *data_type); + return data_type; +} + +rd_data_type *rd_type_alloc_python(const rd_type_enum type, + const size_t element_size) { + rd_data_type src_type = rd_type_create(type, element_size); + return rd_type_alloc_copy_python(&src_type); +} + +rd_data_type *rd_type_alloc_from_type_python(const rd_type_enum type) { + rd_data_type src_type = rd_type_create_from_type(type); + return rd_type_alloc_copy_python(&src_type); +} + +rd_data_type *rd_type_alloc_from_name_python(const char *name) { + rd_data_type src_type = rd_type_create_from_name(name); + return rd_type_alloc_copy_python(&src_type); +} + +void rd_type_free_python(rd_data_type *data_type) { free(data_type); } + +rd_type_enum rd_type_get_type_python(const rd_data_type *rd_type) { + return rd_type_get_type(*rd_type); +} + +const char *rd_type_alloc_name_python(const rd_data_type *rd_type) { + return rd_type_alloc_name(*rd_type); +} + +int rd_type_get_sizeof_iotype_python(const rd_data_type *rd_type) { + return rd_type_get_sizeof_iotype(*rd_type); +} + +int rd_type_get_sizeof_ctype_python(const rd_data_type *rd_type) { + return rd_type_get_sizeof_ctype(*rd_type); +} + +bool rd_type_is_numeric_python(const rd_data_type *rd_type) { + return rd_type_is_numeric(*rd_type); +} + +bool rd_type_is_equal_python(const rd_data_type *rd_type1, + const rd_data_type *rd_type2) { + return rd_type_is_equal(*rd_type1, *rd_type2); +} + +bool rd_type_is_char_python(const rd_data_type *rd_type) { + return rd_type_is_char(*rd_type); +} + +bool rd_type_is_int_python(const rd_data_type *rd_type) { + return rd_type_is_int(*rd_type); +} + +bool rd_type_is_float_python(const rd_data_type *rd_type) { + return rd_type_is_float(*rd_type); +} + +bool rd_type_is_double_python(const rd_data_type *rd_type) { + return rd_type_is_double(*rd_type); +} + +bool rd_type_is_mess_python(const rd_data_type *rd_type) { + return rd_type_is_mess(*rd_type); +} + +bool rd_type_is_bool_python(const rd_data_type *rd_type) { + return rd_type_is_bool(*rd_type); +} + +bool rd_type_is_string_python(const rd_data_type *rd_type) { + return rd_type_is_string(*rd_type); +} + +/** + * + * Functions for the ResdataKw prototype + * + */ +rd_kw_type *rd_kw_fscanf_alloc_grdecl_dynamic_python( + FILE *stream, const char *kw, bool strict, const rd_data_type *data_type) { + return rd_kw_fscanf_alloc_grdecl_dynamic__(stream, kw, strict, *data_type); +} + +rd_kw_type *rd_kw_alloc_python(const char *header, int size, + const rd_data_type *data_type) { + return rd_kw_alloc(header, size, *data_type); +} + +rd_data_type *rd_kw_get_data_type_python(const rd_kw_type *rd_kw) { + rd_data_type data_type = rd_kw_get_data_type(rd_kw); + return rd_type_alloc_copy_python(&data_type); +} + +void rd_kw_fread_indexed_data_python( + fortio_type *fortio, offset_type data_offset, const rd_data_type *data_type, + int element_count, const int_vector_type *index_map, char *buffer) { + return rd_kw_fread_indexed_data(fortio, data_offset, *data_type, + element_count, index_map, buffer); +} +} +#endif diff --git a/lib/ecl/ecl_unsmry_loader.cpp b/lib/resdata/rd_unsmry_loader.cpp similarity index 61% rename from lib/ecl/ecl_unsmry_loader.cpp rename to lib/resdata/rd_unsmry_loader.cpp index 5ccc99e862..d62deb134f 100644 --- a/lib/ecl/ecl_unsmry_loader.cpp +++ b/lib/resdata/rd_unsmry_loader.cpp @@ -4,43 +4,43 @@ #include -#include -#include +#include +#include -#include "detail/ecl/ecl_unsmry_loader.hpp" +#include "detail/resdata/rd_unsmry_loader.hpp" -namespace ecl { +namespace rd { -unsmry_loader::unsmry_loader(const ecl_smspec_type *smspec, +unsmry_loader::unsmry_loader(const rd_smspec_type *smspec, const std::string &filename, int file_options) - : size(ecl_smspec_get_params_size(smspec)), - time_index(ecl_smspec_get_time_index(smspec)), - time_seconds(ecl_smspec_get_time_seconds(smspec)), - sim_start(ecl_smspec_get_start_time(smspec)) { - ecl_file_type *file = ecl_file_open(filename.c_str(), file_options); + : size(rd_smspec_get_params_size(smspec)), + time_index(rd_smspec_get_time_index(smspec)), + time_seconds(rd_smspec_get_time_seconds(smspec)), + sim_start(rd_smspec_get_start_time(smspec)) { + rd_file_type *file = rd_file_open(filename.c_str(), file_options); if (!file) throw std::bad_alloc(); - if (!ecl_file_has_kw(file, PARAMS_KW)) { - ecl_file_close(file); + if (!rd_file_has_kw(file, PARAMS_KW)) { + rd_file_close(file); throw std::bad_alloc(); } - if (ecl_file_get_num_named_kw(file, PARAMS_KW) != - ecl_file_get_num_named_kw(file, MINISTEP_KW)) { - ecl_file_close(file); + if (rd_file_get_num_named_kw(file, PARAMS_KW) != + rd_file_get_num_named_kw(file, MINISTEP_KW)) { + rd_file_close(file); throw std::bad_alloc(); } - this->date_index = {{ecl_smspec_get_date_day_index(smspec), - ecl_smspec_get_date_month_index(smspec), - ecl_smspec_get_date_year_index(smspec)}}; + this->date_index = {{rd_smspec_get_date_day_index(smspec), + rd_smspec_get_date_month_index(smspec), + rd_smspec_get_date_year_index(smspec)}}; this->file = file; - this->file_view = ecl_file_get_global_view(this->file); - this->m_length = ecl_file_view_get_num_named_kw(this->file_view, PARAMS_KW); + this->file_view = rd_file_get_global_view(this->file); + this->m_length = rd_file_view_get_num_named_kw(this->file_view, PARAMS_KW); } -unsmry_loader::~unsmry_loader() { ecl_file_close(file); } +unsmry_loader::~unsmry_loader() { rd_file_close(file); } int unsmry_loader::length() const { return this->m_length; } @@ -55,15 +55,15 @@ std::vector unsmry_loader::get_vector(int pos) const { char buffer[4]; for (int index = 0; index < this->length(); index++) { - ecl_file_view_index_fload_kw(file_view, PARAMS_KW, index, index_map, - buffer); + rd_file_view_index_fload_kw(file_view, PARAMS_KW, index, index_map, + buffer); float *data_value = (float *)buffer; data[index] = *data_value; } int_vector_free(index_map); - if (ecl_file_view_flags_set(file_view, ECL_FILE_CLOSE_STREAM)) - ecl_file_view_fclose_stream(file_view); + if (rd_file_view_flags_set(file_view, RD_FILE_CLOSE_STREAM)) + rd_file_view_fclose_stream(file_view); return data; } @@ -72,8 +72,8 @@ std::vector unsmry_loader::get_vector(int pos) const { double unsmry_loader::iget(int time_index, int params_index) const { int_vector_type *index_map = int_vector_alloc(1, params_index); float value; - ecl_file_view_index_fload_kw(this->file_view, PARAMS_KW, time_index, - index_map, (char *)&value); + rd_file_view_index_fload_kw(this->file_view, PARAMS_KW, time_index, + index_map, (char *)&value); int_vector_free(index_map); return value; } @@ -91,13 +91,12 @@ time_t unsmry_loader::iget_sim_time(int time_index) const { int_vector_iset(index_map, 2, this->date_index[2]); float values[3]; - ecl_file_view_index_fload_kw(this->file_view, PARAMS_KW, time_index, - index_map, (char *)&values); + rd_file_view_index_fload_kw(this->file_view, PARAMS_KW, time_index, + index_map, (char *)&values); int_vector_free(index_map); - return ecl_util_make_date(util_roundf(values[0]), - util_roundf(values[1]), - util_roundf(values[2])); + return rd_make_date(util_roundf(values[0]), util_roundf(values[1]), + util_roundf(values[2])); } } @@ -114,13 +113,13 @@ double unsmry_loader::iget_sim_seconds(int time_index) const { std::vector unsmry_loader::report_steps(int offset) const { std::vector report_steps; int current_step = offset; - for (int i = 0; i < ecl_file_view_get_size(this->file_view); i++) { - const ecl_file_kw_type *file_kw = - ecl_file_view_iget_file_kw(this->file_view, i); - if (util_string_equal(SEQHDR_KW, ecl_file_kw_get_header(file_kw))) + for (int i = 0; i < rd_file_view_get_size(this->file_view); i++) { + const rd_file_kw_type *file_kw = + rd_file_view_iget_file_kw(this->file_view, i); + if (util_string_equal(SEQHDR_KW, rd_file_kw_get_header(file_kw))) current_step++; - if (util_string_equal(PARAMS_KW, ecl_file_kw_get_header(file_kw))) + if (util_string_equal(PARAMS_KW, rd_file_kw_get_header(file_kw))) report_steps.push_back(current_step); } return report_steps; @@ -143,8 +142,8 @@ std::vector unsmry_loader::sim_time() const { std::vector st(this->length()); for (size_t i = 0; i < st.size(); i++) - st[i] = ecl_util_make_date(util_round(day[i]), util_round(month[i]), - util_round(year[i])); + st[i] = rd_make_date(util_round(day[i]), util_round(month[i]), + util_round(year[i])); return st; } @@ -168,4 +167,4 @@ std::vector unsmry_loader::sim_seconds() const { } } -} // namespace ecl +} // namespace rd diff --git a/lib/ecl/ecl_util.cpp b/lib/resdata/rd_util.cpp similarity index 70% rename from lib/ecl/ecl_util.cpp rename to lib/resdata/rd_util.cpp index 564af1c713..75b74a9209 100644 --- a/lib/ecl/ecl_util.cpp +++ b/lib/resdata/rd_util.cpp @@ -11,41 +11,41 @@ #include #include -#include -#include +#include +#include -#define ECL_PHASE_NAME_OIL \ +#define RD_PHASE_NAME_OIL \ "SOIL" // SHould match the keywords found in restart file -#define ECL_PHASE_NAME_WATER "SWAT" -#define ECL_PHASE_NAME_GAS "SGAS" - -#define ECL_OTHER_FILE_FMT_PATTERN "*" -#define ECL_UNIFIED_RESTART_FMT_PATTERN "FUNRST" -#define ECL_UNIFIED_SUMMARY_FMT_PATTERN "FUNSMRY" -#define ECL_GRID_FMT_PATTERN "FGRID" -#define ECL_EGRID_FMT_PATTERN "FEGRID" -#define ECL_INIT_FMT_PATTERN "FINIT" -#define ECL_RFT_FMT_PATTERN "FRFT" -#define ECL_DATA_PATTERN "DATA" - -#define ECL_OTHER_FILE_UFMT_PATTERN "*" -#define ECL_UNIFIED_RESTART_UFMT_PATTERN "UNRST" -#define ECL_UNIFIED_SUMMARY_UFMT_PATTERN "UNSMRY" -#define ECL_GRID_UFMT_PATTERN "GRID" -#define ECL_EGRID_UFMT_PATTERN "EGRID" -#define ECL_INIT_UFMT_PATTERN "INIT" -#define ECL_RFT_UFMT_PATTERN "RFT" - -const char *ecl_util_get_phase_name(ecl_phase_enum phase) { +#define RD_PHASE_NAME_WATER "SWAT" +#define RD_PHASE_NAME_GAS "SGAS" + +#define RD_OTHER_FILE_FMT_PATTERN "*" +#define RD_UNIFIED_RESTART_FMT_PATTERN "FUNRST" +#define RD_UNIFIED_SUMMARY_FMT_PATTERN "FUNSMRY" +#define RD_GRID_FMT_PATTERN "FGRID" +#define RD_EGRID_FMT_PATTERN "FEGRID" +#define RD_INIT_FMT_PATTERN "FINIT" +#define RD_RFT_FMT_PATTERN "FRFT" +#define RD_DATA_PATTERN "DATA" + +#define RD_OTHER_FILE_UFMT_PATTERN "*" +#define RD_UNIFIED_RESTART_UFMT_PATTERN "UNRST" +#define RD_UNIFIED_SUMMARY_UFMT_PATTERN "UNSMRY" +#define RD_GRID_UFMT_PATTERN "GRID" +#define RD_EGRID_UFMT_PATTERN "EGRID" +#define RD_INIT_UFMT_PATTERN "INIT" +#define RD_RFT_UFMT_PATTERN "RFT" + +const char *rd_get_phase_name(rd_phase_enum phase) { switch (phase) { - case (ECL_OIL_PHASE): - return ECL_PHASE_NAME_OIL; + case (RD_OIL_PHASE): + return RD_PHASE_NAME_OIL; break; - case (ECL_WATER_PHASE): - return ECL_PHASE_NAME_WATER; + case (RD_WATER_PHASE): + return RD_PHASE_NAME_WATER; break; - case (ECL_GAS_PHASE): - return ECL_PHASE_NAME_GAS; + case (RD_GAS_PHASE): + return RD_PHASE_NAME_GAS; break; default: util_abort("%s: phase enum value:%d not recognized \n", __func__, @@ -54,7 +54,7 @@ const char *ecl_util_get_phase_name(ecl_phase_enum phase) { } } -char *ecl_util_alloc_base_guess(const char *path) { +char *rd_alloc_base_guess(const char *path) { char *base = NULL; stringlist_type *data_files = stringlist_alloc_new(); stringlist_type *DATA_files = stringlist_alloc_new(); @@ -79,90 +79,90 @@ char *ecl_util_alloc_base_guess(const char *path) { return base; } -int ecl_util_filename_report_nr(const char *filename) { +int rd_filename_report_nr(const char *filename) { int report_nr = -1; - ecl_util_get_file_type(filename, NULL, &report_nr); + rd_get_file_type(filename, NULL, &report_nr); return report_nr; } /* We accept mixed lowercase/uppercase Eclipse file extensions even if Eclipse itself does not accept them. */ -ecl_file_enum ecl_util_inspect_extension(const char *ext, bool *_fmt_file, - int *_report_nr) { - ecl_file_enum file_type = ECL_OTHER_FILE; +rd_file_enum rd_inspect_extension(const char *ext, bool *_fmt_file, + int *_report_nr) { + rd_file_enum file_type = RD_OTHER_FILE; bool fmt_file = true; int report_nr = -1; char *upper_ext = util_alloc_strupr_copy(ext); if (strcmp(upper_ext, "UNRST") == 0) { - file_type = ECL_UNIFIED_RESTART_FILE; + file_type = RD_UNIFIED_RESTART_FILE; fmt_file = false; } else if (strcmp(upper_ext, "FUNRST") == 0) { - file_type = ECL_UNIFIED_RESTART_FILE; + file_type = RD_UNIFIED_RESTART_FILE; fmt_file = true; } else if (strcmp(upper_ext, "UNSMRY") == 0) { - file_type = ECL_UNIFIED_SUMMARY_FILE; + file_type = RD_UNIFIED_SUMMARY_FILE; fmt_file = false; } else if (strcmp(upper_ext, "FUNSMRY") == 0) { - file_type = ECL_UNIFIED_SUMMARY_FILE; + file_type = RD_UNIFIED_SUMMARY_FILE; fmt_file = true; } else if (strcmp(upper_ext, "SMSPEC") == 0) { - file_type = ECL_SUMMARY_HEADER_FILE; + file_type = RD_SUMMARY_HEADER_FILE; fmt_file = false; } else if (strcmp(upper_ext, "FSMSPEC") == 0) { - file_type = ECL_SUMMARY_HEADER_FILE; + file_type = RD_SUMMARY_HEADER_FILE; fmt_file = true; } else if (strcmp(upper_ext, "GRID") == 0) { - file_type = ECL_GRID_FILE; + file_type = RD_GRID_FILE; fmt_file = false; } else if (strcmp(upper_ext, "FGRID") == 0) { - file_type = ECL_GRID_FILE; + file_type = RD_GRID_FILE; fmt_file = true; } else if (strcmp(upper_ext, "EGRID") == 0) { - file_type = ECL_EGRID_FILE; + file_type = RD_EGRID_FILE; fmt_file = false; } else if (strcmp(upper_ext, "FEGRID") == 0) { - file_type = ECL_EGRID_FILE; + file_type = RD_EGRID_FILE; fmt_file = true; } else if (strcmp(upper_ext, "INIT") == 0) { - file_type = ECL_INIT_FILE; + file_type = RD_INIT_FILE; fmt_file = false; } else if (strcmp(upper_ext, "FINIT") == 0) { - file_type = ECL_INIT_FILE; + file_type = RD_INIT_FILE; fmt_file = true; } else if (strcmp(upper_ext, "FRFT") == 0) { - file_type = ECL_RFT_FILE; + file_type = RD_RFT_FILE; fmt_file = true; } else if (strcmp(upper_ext, "RFT") == 0) { - file_type = ECL_RFT_FILE; + file_type = RD_RFT_FILE; fmt_file = false; } else if (strcmp(upper_ext, "DATA") == 0) { - file_type = ECL_DATA_FILE; + file_type = RD_DATA_FILE; fmt_file = true; /* Not really relevant ... */ } else { switch (upper_ext[0]) { case ('X'): - file_type = ECL_RESTART_FILE; + file_type = RD_RESTART_FILE; fmt_file = false; break; case ('F'): - file_type = ECL_RESTART_FILE; + file_type = RD_RESTART_FILE; fmt_file = true; break; case ('S'): - file_type = ECL_SUMMARY_FILE; + file_type = RD_SUMMARY_FILE; fmt_file = false; break; case ('A'): - file_type = ECL_SUMMARY_FILE; + file_type = RD_SUMMARY_FILE; fmt_file = true; break; default: - file_type = ECL_OTHER_FILE; + file_type = RD_OTHER_FILE; } - if (file_type != ECL_OTHER_FILE) + if (file_type != RD_OTHER_FILE) if (!util_sscanf_int(&upper_ext[1], &report_nr)) - file_type = ECL_OTHER_FILE; + file_type = RD_OTHER_FILE; } if (_fmt_file != NULL) @@ -183,42 +183,41 @@ ecl_file_enum ecl_util_inspect_extension(const char *ext, bool *_fmt_file, report number this corresponds to. */ -ecl_file_enum ecl_util_get_file_type(const char *filename, bool *fmt_file, - int *report_nr) { +rd_file_enum rd_get_file_type(const char *filename, bool *fmt_file, + int *report_nr) { char *ext = (char *)strrchr(filename, '.'); if (ext == NULL) - return ECL_OTHER_FILE; + return RD_OTHER_FILE; - return ecl_util_inspect_extension(&ext[1], fmt_file, report_nr); + return rd_inspect_extension(&ext[1], fmt_file, report_nr); } -static const char *ecl_util_get_file_pattern(ecl_file_enum file_type, - bool fmt_file) { +static const char *rd_get_file_pattern(rd_file_enum file_type, bool fmt_file) { if (fmt_file) { switch (file_type) { - case (ECL_OTHER_FILE): - return ECL_OTHER_FILE_FMT_PATTERN; /* '*' */ + case (RD_OTHER_FILE): + return RD_OTHER_FILE_FMT_PATTERN; /* '*' */ break; - case (ECL_UNIFIED_RESTART_FILE): - return ECL_UNIFIED_RESTART_FMT_PATTERN; + case (RD_UNIFIED_RESTART_FILE): + return RD_UNIFIED_RESTART_FMT_PATTERN; break; - case (ECL_UNIFIED_SUMMARY_FILE): - return ECL_UNIFIED_SUMMARY_FMT_PATTERN; + case (RD_UNIFIED_SUMMARY_FILE): + return RD_UNIFIED_SUMMARY_FMT_PATTERN; break; - case (ECL_GRID_FILE): - return ECL_GRID_FMT_PATTERN; + case (RD_GRID_FILE): + return RD_GRID_FMT_PATTERN; break; - case (ECL_EGRID_FILE): - return ECL_EGRID_FMT_PATTERN; + case (RD_EGRID_FILE): + return RD_EGRID_FMT_PATTERN; break; - case (ECL_INIT_FILE): - return ECL_INIT_FMT_PATTERN; + case (RD_INIT_FILE): + return RD_INIT_FMT_PATTERN; break; - case (ECL_RFT_FILE): - return ECL_RFT_FMT_PATTERN; + case (RD_RFT_FILE): + return RD_RFT_FMT_PATTERN; break; - case (ECL_DATA_FILE): - return ECL_DATA_PATTERN; + case (RD_DATA_FILE): + return RD_DATA_PATTERN; break; default: util_abort("%s: No pattern defined for til_type:%d \n", __func__, @@ -227,26 +226,26 @@ static const char *ecl_util_get_file_pattern(ecl_file_enum file_type, } } else { switch (file_type) { - case (ECL_OTHER_FILE): - return ECL_OTHER_FILE_UFMT_PATTERN; /* '*' */ + case (RD_OTHER_FILE): + return RD_OTHER_FILE_UFMT_PATTERN; /* '*' */ break; - case (ECL_UNIFIED_RESTART_FILE): - return ECL_UNIFIED_RESTART_UFMT_PATTERN; + case (RD_UNIFIED_RESTART_FILE): + return RD_UNIFIED_RESTART_UFMT_PATTERN; break; - case (ECL_UNIFIED_SUMMARY_FILE): - return ECL_UNIFIED_SUMMARY_UFMT_PATTERN; + case (RD_UNIFIED_SUMMARY_FILE): + return RD_UNIFIED_SUMMARY_UFMT_PATTERN; break; - case (ECL_GRID_FILE): - return ECL_GRID_UFMT_PATTERN; + case (RD_GRID_FILE): + return RD_GRID_UFMT_PATTERN; break; - case (ECL_EGRID_FILE): - return ECL_EGRID_UFMT_PATTERN; + case (RD_EGRID_FILE): + return RD_EGRID_UFMT_PATTERN; break; - case (ECL_INIT_FILE): - return ECL_INIT_UFMT_PATTERN; + case (RD_INIT_FILE): + return RD_INIT_UFMT_PATTERN; break; - case (ECL_RFT_FILE): - return ECL_RFT_UFMT_PATTERN; + case (RD_RFT_FILE): + return RD_RFT_UFMT_PATTERN; break; default: util_abort("%s: No pattern defined for til_type:%d \n", __func__, @@ -257,43 +256,43 @@ static const char *ecl_util_get_file_pattern(ecl_file_enum file_type, } /** - Takes an ecl_file_enum variable and returns string with a + Takes an rd_file_enum variable and returns string with a descriptive name of this file type. */ -const char *ecl_util_file_type_name(ecl_file_enum file_type) { +const char *rd_file_type_name(rd_file_enum file_type) { switch (file_type) { - case (ECL_OTHER_FILE): - return "ECL_OTHER_FILE"; + case (RD_OTHER_FILE): + return "RD_OTHER_FILE"; break; - case (ECL_RESTART_FILE): - return "ECL_RESTART_FILE"; + case (RD_RESTART_FILE): + return "RD_RESTART_FILE"; break; - case (ECL_UNIFIED_RESTART_FILE): - return "ECL_UNIFIED_RESTART_FILE"; + case (RD_UNIFIED_RESTART_FILE): + return "RD_UNIFIED_RESTART_FILE"; break; - case (ECL_SUMMARY_FILE): - return "ECL_SUMMARY_FILE"; + case (RD_SUMMARY_FILE): + return "RD_SUMMARY_FILE"; break; - case (ECL_UNIFIED_SUMMARY_FILE): - return "ECL_UNIFIED_SUMMARY_FILE"; + case (RD_UNIFIED_SUMMARY_FILE): + return "RD_UNIFIED_SUMMARY_FILE"; break; - case (ECL_SUMMARY_HEADER_FILE): - return "ECL_SUMMARY_HEADER_FILE"; + case (RD_SUMMARY_HEADER_FILE): + return "RD_SUMMARY_HEADER_FILE"; break; - case (ECL_GRID_FILE): - return "ECL_GRID_FILE"; + case (RD_GRID_FILE): + return "RD_GRID_FILE"; break; - case (ECL_EGRID_FILE): - return "ECL_EGRID_FILE"; + case (RD_EGRID_FILE): + return "RD_EGRID_FILE"; break; - case (ECL_INIT_FILE): - return "ECL_INIT_FILE"; + case (RD_INIT_FILE): + return "RD_INIT_FILE"; break; - case (ECL_RFT_FILE): - return "ECL_RFT_FILE"; + case (RD_RFT_FILE): + return "RD_RFT_FILE"; break; - case (ECL_DATA_FILE): - return "ECL_DATA_FILE"; + case (RD_DATA_FILE): + return "RD_DATA_FILE"; break; default: util_abort("%s: internal error type.%d not recognizxed \n", __func__, @@ -325,82 +324,81 @@ static bool base_has_upper(const char *input_base) { not exist NULL is returned. */ -static char *ecl_util_alloc_filename_static(const char *path, const char *base, - ecl_file_enum file_type, - bool fmt_file, int report_nr, - bool must_exist) { +static char *rd_alloc_filename_static(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file, + int report_nr, bool must_exist) { char *filename; char *ext; switch (file_type) { - case (ECL_RESTART_FILE): + case (RD_RESTART_FILE): if (fmt_file) ext = util_alloc_sprintf("F%04d", report_nr); else ext = util_alloc_sprintf("X%04d", report_nr); break; - case (ECL_UNIFIED_RESTART_FILE): + case (RD_UNIFIED_RESTART_FILE): if (fmt_file) ext = util_alloc_string_copy("FUNRST"); else ext = util_alloc_string_copy("UNRST"); break; - case (ECL_SUMMARY_FILE): + case (RD_SUMMARY_FILE): if (fmt_file) ext = util_alloc_sprintf("A%04d", report_nr); else ext = util_alloc_sprintf("S%04d", report_nr); break; - case (ECL_UNIFIED_SUMMARY_FILE): + case (RD_UNIFIED_SUMMARY_FILE): if (fmt_file) ext = util_alloc_string_copy("FUNSMRY"); else ext = util_alloc_string_copy("UNSMRY"); break; - case (ECL_SUMMARY_HEADER_FILE): + case (RD_SUMMARY_HEADER_FILE): if (fmt_file) ext = util_alloc_string_copy("FSMSPEC"); else ext = util_alloc_string_copy("SMSPEC"); break; - case (ECL_GRID_FILE): + case (RD_GRID_FILE): if (fmt_file) ext = util_alloc_string_copy("FGRID"); else ext = util_alloc_string_copy("GRID"); break; - case (ECL_EGRID_FILE): + case (RD_EGRID_FILE): if (fmt_file) ext = util_alloc_string_copy("FEGRID"); else ext = util_alloc_string_copy("EGRID"); break; - case (ECL_INIT_FILE): + case (RD_INIT_FILE): if (fmt_file) ext = util_alloc_string_copy("FINIT"); else ext = util_alloc_string_copy("INIT"); break; - case (ECL_RFT_FILE): + case (RD_RFT_FILE): if (fmt_file) ext = util_alloc_string_copy("FRFT"); else ext = util_alloc_string_copy("RFT"); break; - case (ECL_DATA_FILE): + case (RD_DATA_FILE): ext = util_alloc_string_copy("DATA"); break; default: - util_abort("%s: Invalid input file_type to ecl_util_alloc_filename - " + util_abort("%s: Invalid input file_type to rd_alloc_filename - " "aborting \n", __func__); /* Dummy to shut up compiler */ @@ -425,18 +423,17 @@ static char *ecl_util_alloc_filename_static(const char *path, const char *base, return filename; } -char *ecl_util_alloc_filename(const char *path, const char *base, - ecl_file_enum file_type, bool fmt_file, - int report_nr) { - return ecl_util_alloc_filename_static(path, base, file_type, fmt_file, - report_nr, false); +char *rd_alloc_filename(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file, int report_nr) { + return rd_alloc_filename_static(path, base, file_type, fmt_file, report_nr, + false); } -char *ecl_util_alloc_exfilename(const char *path, const char *base, - ecl_file_enum file_type, bool fmt_file, - int report_nr) { - return ecl_util_alloc_filename_static(path, base, file_type, fmt_file, - report_nr, true); +char *rd_alloc_exfilename(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file, + int report_nr) { + return rd_alloc_filename_static(path, base, file_type, fmt_file, report_nr, + true); } /** @@ -445,16 +442,16 @@ char *ecl_util_alloc_exfilename(const char *path, const char *base, will return NULL. */ -char *ecl_util_alloc_exfilename_anyfmt(const char *path, const char *base, - ecl_file_enum file_type, - bool fmt_file_first, int report_nr) { +char *rd_alloc_exfilename_anyfmt(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file_first, + int report_nr) { - char *filename = ecl_util_alloc_filename(path, base, file_type, - fmt_file_first, report_nr); + char *filename = + rd_alloc_filename(path, base, file_type, fmt_file_first, report_nr); if (!util_file_exists(filename)) { free(filename); - filename = ecl_util_alloc_filename(path, base, file_type, - !fmt_file_first, report_nr); + filename = rd_alloc_filename(path, base, file_type, !fmt_file_first, + report_nr); } if (!util_file_exists(filename)) { @@ -472,15 +469,15 @@ char *ecl_util_alloc_exfilename_anyfmt(const char *path, const char *base, is not checked for). o Both files are of type WITH a nnnn number at the end, the - function will fail hard in ecl_util_filename_report_nr() if + function will fail hard in rd_filename_report_nr() if this is not the case. */ -int ecl_util_fname_report_cmp(const void *f1, const void *f2) { +int rd_fname_report_cmp(const void *f1, const void *f2) { - int t1 = ecl_util_filename_report_nr((const char *)f1); - int t2 = ecl_util_filename_report_nr((const char *)f2); + int t1 = rd_filename_report_nr((const char *)f1); + int t2 = rd_filename_report_nr((const char *)f2); if (t1 < t2) return -1; @@ -492,10 +489,10 @@ int ecl_util_fname_report_cmp(const void *f1, const void *f2) { /** This function will scan the directory @path (or cwd if @path == NULL) - for all ECLIPSE files of type @file_type. If base == NULL it will use - '*' as pattern for basename. If file_type == ECL_OTHER_FILE it will + for all files of type @file_type. If base == NULL it will use + '*' as pattern for basename. If file_type == RD_OTHER_FILE it will use '*' as pattern for the extension (as a consequence files which do - not originate from ECLIPSE will also be included). + not originate from the simulator will also be included). The stringlist will be cleared before the actual matching process starts. @@ -555,11 +552,10 @@ static bool restart_lowercase_BINARY(const char *filename, const void *base) { return numeric_extension_predicate(filename, (const char *)base, 'x'); } -static int ecl_util_select_predicate_filelist(const char *path, - const char *base, - ecl_file_enum file_type, - bool fmt_file, bool upper_case, - stringlist_type *filelist) { +static int rd_select_predicate_filelist(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file, + bool upper_case, + stringlist_type *filelist) { file_pred_ftype *predicate = NULL; char *full_path = NULL; char *pure_base = NULL; @@ -569,7 +565,7 @@ static int ecl_util_select_predicate_filelist(const char *path, free(tmp); } - if (file_type == ECL_SUMMARY_FILE) { + if (file_type == RD_SUMMARY_FILE) { if (fmt_file) { if (upper_case) predicate = summary_UPPERCASE_ASCII; @@ -581,7 +577,7 @@ static int ecl_util_select_predicate_filelist(const char *path, else predicate = summary_lowercase_BINARY; } - } else if (file_type == ECL_RESTART_FILE) { + } else if (file_type == RD_RESTART_FILE) { if (fmt_file) { if (upper_case) predicate = restart_UPPERCASE_ASCII; @@ -599,24 +595,24 @@ static int ecl_util_select_predicate_filelist(const char *path, __func__, file_type); stringlist_select_files(filelist, full_path, predicate, pure_base); - stringlist_sort(filelist, ecl_util_fname_report_cmp); + stringlist_sort(filelist, rd_fname_report_cmp); free(pure_base); free(full_path); return stringlist_get_size(filelist); } -int ecl_util_select_filelist(const char *path, const char *base, - ecl_file_enum file_type, bool fmt_file, - stringlist_type *filelist) { +int rd_select_filelist(const char *path, const char *base, + rd_file_enum file_type, bool fmt_file, + stringlist_type *filelist) { stringlist_clear(filelist); bool upper_case = base_has_upper(base); - if (file_type == ECL_SUMMARY_FILE || file_type == ECL_RESTART_FILE) - return ecl_util_select_predicate_filelist( - path, base, file_type, fmt_file, upper_case, filelist); + if (file_type == RD_SUMMARY_FILE || file_type == RD_RESTART_FILE) + return rd_select_predicate_filelist(path, base, file_type, fmt_file, + upper_case, filelist); char *ext_pattern = - util_alloc_string_copy(ecl_util_get_file_pattern(file_type, fmt_file)); + util_alloc_string_copy(rd_get_file_pattern(file_type, fmt_file)); if (!upper_case) { for (size_t i = 0; i < strlen(ext_pattern); i++) @@ -636,39 +632,39 @@ int ecl_util_select_filelist(const char *path, const char *base, return stringlist_get_size(filelist); } -bool ecl_util_unified_file(const char *filename) { +bool rd_unified_file(const char *filename) { int report_nr; - ecl_file_enum file_type; + rd_file_enum file_type; bool fmt_file; - file_type = ecl_util_get_file_type(filename, &fmt_file, &report_nr); + file_type = rd_get_file_type(filename, &fmt_file, &report_nr); - if ((file_type == ECL_UNIFIED_RESTART_FILE) || - (file_type == ECL_UNIFIED_SUMMARY_FILE)) + if ((file_type == RD_UNIFIED_RESTART_FILE) || + (file_type == RD_UNIFIED_SUMMARY_FILE)) return true; else return false; } -bool ecl_util_fmt_file(const char *filename, bool *__fmt_file) { +bool rd_fmt_file(const char *filename, bool *__fmt_file) { /*const int min_size = 32768;*/ const int min_size = 256; /* Veeeery small */ int report_nr; - ecl_file_enum file_type; + rd_file_enum file_type; bool status = true; bool fmt_file = 0; if (util_file_exists(filename)) { - file_type = ecl_util_get_file_type(filename, &fmt_file, &report_nr); - if (file_type == ECL_OTHER_FILE) { + file_type = rd_get_file_type(filename, &fmt_file, &report_nr); + if (file_type == RD_OTHER_FILE) { if (util_file_size(filename) > min_size) fmt_file = util_fmt_bit8(filename); else status = false; // Do not know ?? } } else { - file_type = ecl_util_get_file_type(filename, &fmt_file, &report_nr); - if (file_type == ECL_OTHER_FILE) + file_type = rd_get_file_type(filename, &fmt_file, &report_nr); + if (file_type == RD_OTHER_FILE) status = false; // Do not know ?? } @@ -682,24 +678,24 @@ bool ecl_util_fmt_file(const char *filename, bool *__fmt_file) { appropriate numerical conversion is applied. */ -void ecl_util_memcpy_typed_data(void *_target_data, const void *_src_data, - ecl_data_type target_type, - ecl_data_type src_type, int size) { +void rd_memcpy_typed_data(void *_target_data, const void *_src_data, + rd_data_type target_type, rd_data_type src_type, + int size) { int i; - if (ecl_type_is_equal(target_type, src_type)) + if (rd_type_is_equal(target_type, src_type)) memcpy(_target_data, _src_data, - size * ecl_type_get_sizeof_ctype(src_type)); + size * rd_type_get_sizeof_ctype(src_type)); else { - switch (ecl_type_get_type(target_type)) { - case (ECL_DOUBLE_TYPE): { + switch (rd_type_get_type(target_type)) { + case (RD_DOUBLE_TYPE): { double *target_data = (double *)_target_data; - switch (ecl_type_get_type(src_type)) { - case (ECL_FLOAT_TYPE): + switch (rd_type_get_type(src_type)) { + case (RD_FLOAT_TYPE): util_float_to_double(target_data, (const float *)_src_data, size); break; - case (ECL_INT_TYPE): + case (RD_INT_TYPE): for (i = 0; i < size; i++) target_data[i] = ((int *)_src_data)[i]; break; @@ -710,14 +706,14 @@ void ecl_util_memcpy_typed_data(void *_target_data, const void *_src_data, } break; } - case (ECL_FLOAT_TYPE): { + case (RD_FLOAT_TYPE): { float *target_data = (float *)_target_data; - switch (ecl_type_get_type(src_type)) { - case (ECL_FLOAT_TYPE): + switch (rd_type_get_type(src_type)) { + case (RD_FLOAT_TYPE): util_double_to_float(target_data, (const double *)_src_data, size); break; - case (ECL_INT_TYPE): + case (RD_INT_TYPE): for (i = 0; i < size; i++) target_data[i] = ((int *)_src_data)[i]; break; @@ -730,8 +726,8 @@ void ecl_util_memcpy_typed_data(void *_target_data, const void *_src_data, } default: util_abort("%s con not convert %s -> %s \n", __func__, - ecl_type_alloc_name(src_type), - ecl_type_alloc_name(target_type)); + rd_type_alloc_name(src_type), + rd_type_alloc_name(target_type)); } } } @@ -742,13 +738,12 @@ void ecl_util_memcpy_typed_data(void *_target_data, const void *_src_data, @base input can contain an embedded path component. */ -void ecl_util_alloc_summary_data_files(const char *path, const char *base, - bool fmt_file, - stringlist_type *filelist) { - char *unif_data_file = ecl_util_alloc_exfilename( - path, base, ECL_UNIFIED_SUMMARY_FILE, fmt_file, -1); - int files = ecl_util_select_filelist(path, base, ECL_SUMMARY_FILE, fmt_file, - filelist); +void rd_alloc_summary_data_files(const char *path, const char *base, + bool fmt_file, stringlist_type *filelist) { + char *unif_data_file = + rd_alloc_exfilename(path, base, RD_UNIFIED_SUMMARY_FILE, fmt_file, -1); + int files = + rd_select_filelist(path, base, RD_SUMMARY_FILE, fmt_file, filelist); if ((files > 0) && (unif_data_file != NULL)) { /* @@ -813,9 +808,9 @@ void ecl_util_alloc_summary_data_files(const char *path, const char *base, surely possible to fool it. */ -bool ecl_util_alloc_summary_files(const char *path, const char *_base, - const char *ext, char **_header_file, - stringlist_type *filelist) { +bool rd_alloc_summary_files(const char *path, const char *_base, + const char *ext, char **_header_file, + stringlist_type *filelist) { bool fmt_input = false; bool fmt_set = false; bool fmt_file = true; @@ -834,33 +829,33 @@ bool ecl_util_alloc_summary_files(const char *path, const char *_base, */ if (_base == NULL) - base = ecl_util_alloc_base_guess(path); + base = rd_alloc_base_guess(path); else base = (char *)_base; if (ext != NULL) { - ecl_file_enum input_type; + rd_file_enum input_type; { char *test_name = util_alloc_filename(NULL, base, ext); - input_type = ecl_util_get_file_type(test_name, &fmt_input, NULL); + input_type = rd_get_file_type(test_name, &fmt_input, NULL); free(test_name); } - if ((input_type != ECL_OTHER_FILE) && (input_type != ECL_DATA_FILE)) { + if ((input_type != RD_OTHER_FILE) && (input_type != RD_DATA_FILE)) { /* The file has been recognized as a file type from which we can at least infer formatted/unformatted inforamtion. */ fmt_set = true; switch (input_type) { - case (ECL_SUMMARY_FILE): - case (ECL_RESTART_FILE): + case (RD_SUMMARY_FILE): + case (RD_RESTART_FILE): unif_input = false; unif_set = true; break; - case (ECL_UNIFIED_SUMMARY_FILE): - case (ECL_UNIFIED_RESTART_FILE): + case (RD_UNIFIED_SUMMARY_FILE): + case (RD_UNIFIED_RESTART_FILE): unif_input = true; unif_set = true; break; @@ -875,10 +870,10 @@ bool ecl_util_alloc_summary_files(const char *path, const char *_base, */ { - char *fsmspec_file = ecl_util_alloc_exfilename( - path, base, ECL_SUMMARY_HEADER_FILE, true, -1); - char *smspec_file = ecl_util_alloc_exfilename( - path, base, ECL_SUMMARY_HEADER_FILE, false, -1); + char *fsmspec_file = + rd_alloc_exfilename(path, base, RD_SUMMARY_HEADER_FILE, true, -1); + char *smspec_file = + rd_alloc_exfilename(path, base, RD_SUMMARY_HEADER_FILE, false, -1); if ((fsmspec_file == NULL) && (smspec_file == NULL)) /* Neither file exists */ @@ -923,17 +918,16 @@ bool ecl_util_alloc_summary_files(const char *path, const char *_base, non-unified input files. */ if (unif_input) { - char *unif_data_file = ecl_util_alloc_exfilename( - path, base, ECL_UNIFIED_SUMMARY_FILE, fmt_file, -1); + char *unif_data_file = rd_alloc_exfilename( + path, base, RD_UNIFIED_SUMMARY_FILE, fmt_file, -1); if (unif_data_file != NULL) { stringlist_append_copy(filelist, unif_data_file); free(unif_data_file); } } else - ecl_util_select_filelist(path, base, ECL_SUMMARY_FILE, fmt_file, - filelist); + rd_select_filelist(path, base, RD_SUMMARY_FILE, fmt_file, filelist); } else - ecl_util_alloc_summary_data_files(path, base, fmt_file, filelist); + rd_alloc_summary_data_files(path, base, fmt_file, filelist); if (_base == NULL) free(base); @@ -943,10 +937,9 @@ bool ecl_util_alloc_summary_files(const char *path, const char *_base, return (stringlist_get_size(filelist) > 0) ? true : false; } -void ecl_util_alloc_restart_files(const char *path, const char *_base, - char ***_restart_files, - int *num_restart_files, bool *_fmt_file, - bool *_unified) { +void rd_alloc_restart_files(const char *path, const char *_base, + char ***_restart_files, int *num_restart_files, + bool *_fmt_file, bool *_unified) { util_exit("Function:%s currently not implemented - sorry \n", __func__); } @@ -959,7 +952,7 @@ safely used as filenames, i.e for instance the substitution: The escape process is done 'in-place' memory-wise. */ -void ecl_util_escape_kw(char *kw) { +void rd_escape_kw(char *kw) { size_t index; for (index = 0; index < strlen(kw); index++) { switch (kw[index]) { @@ -977,7 +970,7 @@ void ecl_util_escape_kw(char *kw) { Will return -1 for an unrecognized month name. */ -static int ecl_util_get_month_nr__(const char *_month_name) { +static int rd_get_month_nr__(const char *_month_name) { int month_nr = -1; char *month_name = util_alloc_string_copy(_month_name); util_strupr(month_name); @@ -1018,8 +1011,8 @@ static int ecl_util_get_month_nr__(const char *_month_name) { return month_nr; } -int ecl_util_get_month_nr(const char *month_name) { - int month_nr = ecl_util_get_month_nr__(month_name); +int rd_get_month_nr(const char *month_name) { + int month_nr = rd_get_month_nr__(month_name); if (month_nr < 0) util_abort("%s: %s not a valid month name - aborting \n", __func__, month_name); @@ -1036,7 +1029,7 @@ int ecl_util_get_month_nr(const char *month_name) { */ -time_t ecl_util_get_start_date(const char *data_file) { +time_t rd_get_start_date(const char *data_file) { basic_parser_type *parser = basic_parser_alloc(" \t\r\n", "\"\'", NULL, NULL, "--", "\n"); time_t start_date = -1; @@ -1071,8 +1064,8 @@ time_t ecl_util_get_start_date(const char *data_file) { int day, year, month_nr; if (util_sscanf_int(stringlist_iget(tokens, 0), &day) && util_sscanf_int(stringlist_iget(tokens, 2), &year)) { - month_nr = ecl_util_get_month_nr(stringlist_iget(tokens, 1)); - start_date = ecl_util_make_date(day, month_nr, year); + month_nr = rd_get_month_nr(stringlist_iget(tokens, 1)); + start_date = rd_make_date(day, month_nr, year); } else util_abort("%s: failed to parse DAY MONTH YEAR from : \"%s\" \n", __func__, buffer); @@ -1086,9 +1079,8 @@ time_t ecl_util_get_start_date(const char *data_file) { return start_date; } -static int ecl_util_get_num_parallel_cpu__(basic_parser_type *parser, - FILE *stream, - const char *data_file) { +static int rd_get_num_parallel_cpu__(basic_parser_type *parser, FILE *stream, + const char *data_file) { int num_cpu = 1; char *buffer; long int start_pos = util_ftell(stream); @@ -1127,8 +1119,8 @@ static int ecl_util_get_num_parallel_cpu__(basic_parser_type *parser, return num_cpu; } -static int ecl_util_get_num_slave_cpu__(basic_parser_type *parser, FILE *stream, - const char *data_file) { +static int rd_get_num_slave_cpu__(basic_parser_type *parser, FILE *stream, + const char *data_file) { int num_cpu = 0; int linecount = 0; @@ -1184,8 +1176,8 @@ static int ecl_util_get_num_slave_cpu__(basic_parser_type *parser, FILE *stream, the first occurence of a keyword outside of titles and comments. This code is somewhat complicated since it seems that the spec allows for multiple titles and (possibly) blank lines between the title keyword and the title. */ -static bool ecl_util_find_keyword__(basic_parser_type *parser, FILE *stream, - const char *keyword) { +static bool rd_find_keyword__(basic_parser_type *parser, FILE *stream, + const char *keyword) { long int title_pos = -1; /* Find the first occurenced of TITLE, if any. */ @@ -1241,16 +1233,16 @@ static bool ecl_util_find_keyword__(basic_parser_type *parser, FILE *stream, return false; } -int ecl_util_get_num_cpu(const char *data_file) { +int rd_get_num_cpu(const char *data_file) { int num_cpu = 1; basic_parser_type *parser = basic_parser_alloc(" \t\r\n", "\"\'", NULL, NULL, "--", "\n"); FILE *stream = util_fopen(data_file, "r"); - if (ecl_util_find_keyword__(parser, stream, "PARALLEL")) { - num_cpu = ecl_util_get_num_parallel_cpu__(parser, stream, data_file); - } else if (ecl_util_find_keyword__(parser, stream, "SLAVES")) { - num_cpu = ecl_util_get_num_slave_cpu__(parser, stream, data_file) + 1; + if (rd_find_keyword__(parser, stream, "PARALLEL")) { + num_cpu = rd_get_num_parallel_cpu__(parser, stream, data_file); + } else if (rd_find_keyword__(parser, stream, "SLAVES")) { + num_cpu = rd_get_num_slave_cpu__(parser, stream, data_file) + 1; fprintf(stderr, "Information: \"SLAVES\" option found, returning %d number " "of CPUs", @@ -1262,18 +1254,18 @@ int ecl_util_get_num_cpu(const char *data_file) { return num_cpu; } -ert_ecl_unit_enum ecl_util_get_unit_set(const char *data_file) { - ert_ecl_unit_enum units = ECL_METRIC_UNITS; +ert_rd_unit_enum rd_get_unit_set(const char *data_file) { + ert_rd_unit_enum units = RD_METRIC_UNITS; basic_parser_type *parser = basic_parser_alloc(" \t\r\n", "\"\'", NULL, NULL, "--", "\n"); FILE *stream = util_fopen(data_file, "r"); if (basic_parser_fseek_string(parser, stream, "FIELD", true, true)) { /* Seeks case insensitive. */ - units = ECL_FIELD_UNITS; + units = RD_FIELD_UNITS; } else if (basic_parser_fseek_string(parser, stream, "LAB", true, true)) { /* Seeks case insensitive. */ - units = ECL_LAB_UNITS; + units = RD_LAB_UNITS; } basic_parser_free(parser); @@ -1281,7 +1273,7 @@ ert_ecl_unit_enum ecl_util_get_unit_set(const char *data_file) { return units; } -bool ecl_util_valid_basename_fmt(const char *basename_fmt) { +bool rd_valid_basename_fmt(const char *basename_fmt) { char *eclbasename_fmt = util_split_alloc_filename(basename_fmt); bool valid = true; @@ -1325,9 +1317,8 @@ bool ecl_util_valid_basename_fmt(const char *basename_fmt) { to insertion. */ -void ecl_util_append_month_range(time_t_vector_type *date_list, - time_t start_date, time_t end_date, - bool force_append_end) { +void rd_append_month_range(time_t_vector_type *date_list, time_t start_date, + time_t end_date, bool force_append_end) { start_date = util_make_pure_date_utc(start_date); end_date = util_make_pure_date_utc(end_date); @@ -1345,7 +1336,7 @@ void ecl_util_append_month_range(time_t_vector_type *date_list, } else month += 1; - current_date = ecl_util_make_date(1, month, year); + current_date = rd_make_date(1, month, year); if (current_date < end_date) time_t_vector_append(date_list, current_date); else { @@ -1359,18 +1350,17 @@ void ecl_util_append_month_range(time_t_vector_type *date_list, } } -void ecl_util_init_month_range(time_t_vector_type *date_list, time_t start_date, - time_t end_date) { +void rd_init_month_range(time_t_vector_type *date_list, time_t start_date, + time_t end_date) { time_t_vector_reset(date_list); if (!util_is_first_day_in_month_utc(start_date)) time_t_vector_append(date_list, util_make_pure_date_utc(start_date)); - ecl_util_append_month_range(date_list, start_date, end_date, true); + rd_append_month_range(date_list, start_date, end_date, true); } -static time_t ecl_util_make_datetime__(int sec, int min, int hour, int mday, - int month, int year, - int *__year_offset) { +static time_t rd_make_datetime__(int sec, int min, int hour, int mday, + int month, int year, int *__year_offset) { time_t date; #ifdef ERT_TIME_T_64BIT_ACCEPT_PRE1970 @@ -1398,28 +1388,27 @@ static time_t ecl_util_make_datetime__(int sec, int min, int hour, int mday, return date; } -time_t ecl_util_make_date__(int mday, int month, int year, int *__year_offset) { - return ecl_util_make_datetime__(0, 0, 0, mday, month, year, __year_offset); +time_t rd_make_date__(int mday, int month, int year, int *__year_offset) { + return rd_make_datetime__(0, 0, 0, mday, month, year, __year_offset); } -time_t ecl_util_make_date(int mday, int month, int year) { +time_t rd_make_date(int mday, int month, int year) { int year_offset; - return ecl_util_make_date__(mday, month, year, &year_offset); + return rd_make_date__(mday, month, year, &year_offset); } -time_t ecl_util_make_datetime(int sec, int min, int hour, int mday, int month, - int year) { +time_t rd_make_datetime(int sec, int min, int hour, int mday, int month, + int year) { int year_offset; - return ecl_util_make_datetime__(sec, min, hour, mday, month, year, - &year_offset); + return rd_make_datetime__(sec, min, hour, mday, month, year, &year_offset); } -void ecl_util_set_date_values(time_t t, int *mday, int *month, int *year) { +void rd_set_date_values(time_t t, int *mday, int *month, int *year) { return util_set_date_values_utc(t, mday, month, year); } -void ecl_util_set_datetime_values(time_t t, int *sec, int *min, int *hour, - int *mday, int *month, int *year) { +void rd_set_datetime_values(time_t t, int *sec, int *min, int *hour, int *mday, + int *month, int *year) { return util_set_datetime_values_utc(t, sec, min, hour, mday, month, year); } @@ -1429,14 +1418,14 @@ void ecl_util_set_datetime_values(time_t t, int *sec, int *min, int *hour, /* This is a small function which tries to give a sensible answer to the - question: Do I have read access to this eclipse simulation? The ecl_case + question: Do I have read access to this eclipse simulation? The rd_case argument can either be a directory or the full path to a file, the filename need not exists. The approach is as follows: - 1. If @ecl_case corresponds to an existing filesystem entry - just return - access(ecl_case, R_OK). + 1. If @rd_case corresponds to an existing filesystem entry - just return + access(rd_case, R_OK). - 2. If @ecl_case corresponds to a non-existing entry: + 2. If @rd_case corresponds to a non-existing entry: a) If there is a directory part - return access(dir, R_OK). b) No directory part - return access(cwd, R_OK); @@ -1445,17 +1434,17 @@ void ecl_util_set_datetime_values(time_t t, int *sec, int *min, int *hour, that could in principle be denied - but that is a highly contrived situation and we just return true. - ecl_util_access_path("PATH") -> access("PATH", R_OK); - ecl_util_access_path("PATH/FILE_EXISTS") -> access("PATH/FILE_EXISTS", R_OK); - ecl_util_access_path("PATH/FILE_DOES_NOT_EXIST") -> access("PATH", R_OK); - ecl_util_access_path("PATH_DOES_NOT_EXIST") -> true + rd_access_path("PATH") -> access("PATH", R_OK); + rd_access_path("PATH/FILE_EXISTS") -> access("PATH/FILE_EXISTS", R_OK); + rd_access_path("PATH/FILE_DOES_NOT_EXIST") -> access("PATH", R_OK); + rd_access_path("PATH_DOES_NOT_EXIST") -> true */ -bool ecl_util_path_access(const char *ecl_case) { - if (util_access(ecl_case, R_OK)) +bool rd_path_access(const char *rd_case) { + if (util_access(rd_case, R_OK)) return true; - if (util_access(ecl_case, F_OK)) + if (util_access(rd_case, F_OK)) return false; /* Check if the input argument corresponds to an existing directory and one @@ -1464,14 +1453,14 @@ bool ecl_util_path_access(const char *ecl_case) { { bool path_access; char *dir_name; - const char *path_sep = strrchr(ecl_case, UTIL_PATH_SEP_CHAR); + const char *path_sep = strrchr(rd_case, UTIL_PATH_SEP_CHAR); if (!path_sep) /* We are trying to access CWD - we return true without actually checking access. */ return true; - dir_name = util_alloc_substring_copy(ecl_case, 0, path_sep - ecl_case); + dir_name = util_alloc_substring_copy(rd_case, 0, path_sep - rd_case); path_access = util_access(dir_name, R_OK); free(dir_name); return path_access; diff --git a/lib/ecl/smspec_node.cpp b/lib/resdata/smspec_node.cpp similarity index 75% rename from lib/ecl/smspec_node.cpp rename to lib/resdata/smspec_node.cpp index 73c7d80c79..254a145dba 100644 --- a/lib/ecl/smspec_node.cpp +++ b/lib/resdata/smspec_node.cpp @@ -20,12 +20,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "detail/util/string_util.hpp" @@ -33,14 +33,14 @@ The special_vars list is used to associate keywords with special types, when the kewyord name is in conflict with the default vector naming convention; all the variables mentioned in the list below - are given the type ECL_SMSPEC_MISC_VAR. + are given the type RD_SMSPEC_MISC_VAR. For instance the keyword 'NEWTON' starts with 'N' and is classified as a NETWORK type variable. However it should rather be classified as a MISC type variable. The special_vars list is used in the functions - ecl_smspec_identify_special_var() and ecl_smspec_identify_var_type(). + rd_smspec_identify_special_var() and rd_smspec_identify_var_type(). */ static const char *special_vars[] = { @@ -61,22 +61,22 @@ static const int nums_unused = 0; Goes through the special_vars static table to check if @var is one the special variables which does not follow normal naming convention. If the test evaluates to true the function will return - ECL_SMSPEC_MISC_VAR, otherwise the function will return - ECL_SMSPEC_INVALID_VAR and the variable type will be determined + RD_SMSPEC_MISC_VAR, otherwise the function will return + RD_SMSPEC_INVALID_VAR and the variable type will be determined from the var name according to standard naming conventions. It is important that this function is called before the standard method. */ -ecl_smspec_var_type ecl::smspec_node::identify_special_var(const char *var) { - ecl_smspec_var_type var_type = ECL_SMSPEC_INVALID_VAR; +rd_smspec_var_type rd::smspec_node::identify_special_var(const char *var) { + rd_smspec_var_type var_type = RD_SMSPEC_INVALID_VAR; int num_special = sizeof(special_vars) / sizeof(special_vars[0]); int i; for (i = 0; i < num_special; i++) { if (strcmp(var, special_vars[i]) == 0) { - var_type = ECL_SMSPEC_MISC_VAR; + var_type = RD_SMSPEC_MISC_VAR; break; } } @@ -87,41 +87,41 @@ ecl_smspec_var_type ecl::smspec_node::identify_special_var(const char *var) { /* See table 3.4 in the ECLIPSE file format reference manual. - Observe that the combined ecl_sum style keys like e.g. WWCT:OP1 + Observe that the combined rd_sum style keys like e.g. WWCT:OP1 should be formatted with the keyword first, so that this function - will identify both 'WWCT' and 'WWCT:OP_1' as a ECL_SMSPEC_WELL_VAR + will identify both 'WWCT' and 'WWCT:OP_1' as a RD_SMSPEC_WELL_VAR instance. */ -ecl_smspec_var_type ecl::smspec_node::identify_var_type(const char *var) { - ecl_smspec_var_type var_type = ecl::smspec_node::identify_special_var(var); - if (var_type == ECL_SMSPEC_INVALID_VAR) { +rd_smspec_var_type rd::smspec_node::identify_var_type(const char *var) { + rd_smspec_var_type var_type = rd::smspec_node::identify_special_var(var); + if (var_type == RD_SMSPEC_INVALID_VAR) { switch (var[0]) { case ('A'): - var_type = ECL_SMSPEC_AQUIFER_VAR; + var_type = RD_SMSPEC_AQUIFER_VAR; break; case ('B'): - var_type = ECL_SMSPEC_BLOCK_VAR; + var_type = RD_SMSPEC_BLOCK_VAR; break; case ('C'): - var_type = ECL_SMSPEC_COMPLETION_VAR; + var_type = RD_SMSPEC_COMPLETION_VAR; break; case ('F'): - var_type = ECL_SMSPEC_FIELD_VAR; + var_type = RD_SMSPEC_FIELD_VAR; break; case ('G'): - var_type = ECL_SMSPEC_GROUP_VAR; + var_type = RD_SMSPEC_GROUP_VAR; break; case ('L'): switch (var[1]) { case ('B'): - var_type = ECL_SMSPEC_LOCAL_BLOCK_VAR; + var_type = RD_SMSPEC_LOCAL_BLOCK_VAR; break; case ('C'): - var_type = ECL_SMSPEC_LOCAL_COMPLETION_VAR; + var_type = RD_SMSPEC_LOCAL_COMPLETION_VAR; break; case ('W'): - var_type = ECL_SMSPEC_LOCAL_WELL_VAR; + var_type = RD_SMSPEC_LOCAL_WELL_VAR; break; default: /* @@ -131,11 +131,11 @@ ecl_smspec_var_type ecl::smspec_node::identify_var_type(const char *var) { category; at least the LLINEAR keyword is an example of such a keyword. */ - var_type = ECL_SMSPEC_MISC_VAR; + var_type = RD_SMSPEC_MISC_VAR; } break; case ('N'): - var_type = ECL_SMSPEC_NETWORK_VAR; + var_type = RD_SMSPEC_NETWORK_VAR; break; case ('R'): { /* @@ -161,24 +161,24 @@ ecl_smspec_var_type ecl::smspec_node::identify_var_type(const char *var) { */ if (strlen(var) == 3 && var[2] == 'F') { - var_type = ECL_SMSPEC_REGION_2_REGION_VAR; + var_type = RD_SMSPEC_REGION_2_REGION_VAR; break; } if (util_string_equal(var, "RNLF")) { - var_type = ECL_SMSPEC_REGION_2_REGION_VAR; + var_type = RD_SMSPEC_REGION_2_REGION_VAR; break; } if (util_string_equal(var, "RORFR")) { - var_type = ECL_SMSPEC_REGION_VAR; + var_type = RD_SMSPEC_REGION_VAR; break; } if (strlen(var) >= 4) { if (var[2] == 'F') { if (var[3] == 'T' || var[3] == 'R') { - var_type = ECL_SMSPEC_REGION_2_REGION_VAR; + var_type = RD_SMSPEC_REGION_2_REGION_VAR; break; } } @@ -187,26 +187,26 @@ ecl_smspec_var_type ecl::smspec_node::identify_var_type(const char *var) { if (strlen(var) >= 5) { if (var[3] == 'F') { if (var[4] == 'T' || var[4] == 'R') { - var_type = ECL_SMSPEC_REGION_2_REGION_VAR; + var_type = RD_SMSPEC_REGION_2_REGION_VAR; break; } } } - var_type = ECL_SMSPEC_REGION_VAR; + var_type = RD_SMSPEC_REGION_VAR; } break; case ('S'): - var_type = ECL_SMSPEC_SEGMENT_VAR; + var_type = RD_SMSPEC_SEGMENT_VAR; break; case ('W'): - var_type = ECL_SMSPEC_WELL_VAR; + var_type = RD_SMSPEC_WELL_VAR; break; default: /* It is unfortunately impossible to recognize an error situation - the rest just goes in "other" variables. */ - var_type = ECL_SMSPEC_MISC_VAR; + var_type = RD_SMSPEC_MISC_VAR; } } @@ -216,65 +216,65 @@ ecl_smspec_var_type ecl::smspec_node::identify_var_type(const char *var) { /* The key formats for the combined keys like e.g. 'WWCT:OP_5' should have the keyword, i.e. 'WWCT', as the first part of the string. That - guarantees that the function ecl_smspec_identify_var_type() can take - both a pure ECLIPSE variable name, like .e.g 'WWCT' and also an - ecl_sum combined key like 'WWCT:OPX' as input. + guarantees that the function rd_smspec_identify_var_type() can take + both a restart format variable name, like .e.g 'WWCT' and also an + rd_sum combined key like 'WWCT:OPX' as input. */ -#define ECL_SUM_KEYFMT_AQUIFER "%s%s%d" -#define ECL_SUM_KEYFMT_BLOCK_IJK "%s%s%d,%d,%d" -#define ECL_SUM_KEYFMT_BLOCK_NUM "%s%s%d" -#define ECL_SUM_KEYFMT_LOCAL_BLOCK "%s%s%s%s%d,%d,%d" -#define ECL_SUM_KEYFMT_COMPLETION_IJK "%s%s%s%s%d,%d,%d" -#define ECL_SUM_KEYFMT_COMPLETION_NUM "%s%s%s%s%d" -#define ECL_SUM_KEYFMT_LOCAL_COMPLETION "%s%s%s%s%s%s%d,%d,%d" -#define ECL_SUM_KEYFMT_GROUP "%s%s%s" -#define ECL_SUM_KEYFMT_WELL "%s%s%s" -#define ECL_SUM_KEYFMT_REGION "%s%s%d" -#define ECL_SUM_KEYFMT_REGION_2_REGION_R1R2 "%s%s%d-%d" -#define ECL_SUM_KEYFMT_REGION_2_REGION_NUM "%s%s%d" -#define ECL_SUM_KEYFMT_SEGMENT "%s%s%s%s%d" -#define ECL_SUM_KEYFMT_LOCAL_WELL "%s%s%s%s%s" +#define RD_SUM_KEYFMT_AQUIFER "%s%s%d" +#define RD_SUM_KEYFMT_BLOCK_IJK "%s%s%d,%d,%d" +#define RD_SUM_KEYFMT_BLOCK_NUM "%s%s%d" +#define RD_SUM_KEYFMT_LOCAL_BLOCK "%s%s%s%s%d,%d,%d" +#define RD_SUM_KEYFMT_COMPLETION_IJK "%s%s%s%s%d,%d,%d" +#define RD_SUM_KEYFMT_COMPLETION_NUM "%s%s%s%s%d" +#define RD_SUM_KEYFMT_LOCAL_COMPLETION "%s%s%s%s%s%s%d,%d,%d" +#define RD_SUM_KEYFMT_GROUP "%s%s%s" +#define RD_SUM_KEYFMT_WELL "%s%s%s" +#define RD_SUM_KEYFMT_REGION "%s%s%d" +#define RD_SUM_KEYFMT_REGION_2_REGION_R1R2 "%s%s%d-%d" +#define RD_SUM_KEYFMT_REGION_2_REGION_NUM "%s%s%d" +#define RD_SUM_KEYFMT_SEGMENT "%s%s%s%s%d" +#define RD_SUM_KEYFMT_LOCAL_WELL "%s%s%s%s%s" std::string smspec_alloc_block_num_key(const char *join_string, const std::string &keyword, int num) { - return ecl::util::string_format(ECL_SUM_KEYFMT_BLOCK_NUM, keyword.c_str(), - join_string, num); + return rd::util::string_format(RD_SUM_KEYFMT_BLOCK_NUM, keyword.c_str(), + join_string, num); } std::string smspec_alloc_aquifer_key(const char *join_string, const std::string &keyword, int num) { - return ecl::util::string_format(ECL_SUM_KEYFMT_AQUIFER, keyword.c_str(), - join_string, num); + return rd::util::string_format(RD_SUM_KEYFMT_AQUIFER, keyword.c_str(), + join_string, num); } std::string smspec_alloc_local_block_key(const char *join_string, const std::string &keyword, const std::string &lgr_name, int i, int j, int k) { - return ecl::util::string_format(ECL_SUM_KEYFMT_LOCAL_BLOCK, keyword.c_str(), - join_string, lgr_name.c_str(), join_string, - i, j, k); + return rd::util::string_format(RD_SUM_KEYFMT_LOCAL_BLOCK, keyword.c_str(), + join_string, lgr_name.c_str(), join_string, + i, j, k); } std::string smspec_alloc_region_key(const char *join_string, const std::string &keyword, int num) { - return ecl::util::string_format(ECL_SUM_KEYFMT_REGION, keyword.c_str(), - join_string, num); + return rd::util::string_format(RD_SUM_KEYFMT_REGION, keyword.c_str(), + join_string, num); } std::string smspec_alloc_region_2_region_r1r2_key(const char *join_string, const std::string &keyword, int r1, int r2) { - return ecl::util::string_format(ECL_SUM_KEYFMT_REGION_2_REGION_R1R2, - keyword.c_str(), join_string, r1, r2); + return rd::util::string_format(RD_SUM_KEYFMT_REGION_2_REGION_R1R2, + keyword.c_str(), join_string, r1, r2); } std::string smspec_alloc_region_2_region_num_key(const char *join_string, const std::string &keyword, int num) { - return ecl::util::string_format(ECL_SUM_KEYFMT_REGION_2_REGION_NUM, - keyword.c_str(), join_string, num); + return rd::util::string_format(RD_SUM_KEYFMT_REGION_2_REGION_NUM, + keyword.c_str(), join_string, num); } char *smspec_alloc_completion_ijk_key(const char *join_string, @@ -282,9 +282,9 @@ char *smspec_alloc_completion_ijk_key(const char *join_string, const std::string &wgname, int i, int j, int k) { if (wgname.size() > 0) - return util_alloc_sprintf(ECL_SUM_KEYFMT_COMPLETION_IJK, - keyword.c_str(), join_string, wgname.c_str(), - join_string, i, j, k); + return util_alloc_sprintf(RD_SUM_KEYFMT_COMPLETION_IJK, keyword.c_str(), + join_string, wgname.c_str(), join_string, i, + j, k); else return NULL; } @@ -293,9 +293,9 @@ char *smspec_alloc_completion_num_key(const char *join_string, const std::string &keyword, const std::string &wgname, int num) { if (wgname.size() > 0) - return util_alloc_sprintf(ECL_SUM_KEYFMT_COMPLETION_NUM, - keyword.c_str(), join_string, wgname.c_str(), - join_string, num); + return util_alloc_sprintf(RD_SUM_KEYFMT_COMPLETION_NUM, keyword.c_str(), + join_string, wgname.c_str(), join_string, + num); else return NULL; } @@ -311,8 +311,8 @@ static std::string smspec_alloc_wgname_key(const char *join_string, const std::string &keyword, const std::string &wgname) { if (wgname.size() > 0) - return ecl::util::string_format(ECL_SUM_KEYFMT_WELL, keyword.c_str(), - join_string, wgname.c_str()); + return rd::util::string_format(RD_SUM_KEYFMT_WELL, keyword.c_str(), + join_string, wgname.c_str()); else return ""; } @@ -335,28 +335,27 @@ std::string smspec_alloc_well_key(const char *join_string, char *smspec_alloc_well_key(const char *join_string, const char *keyword, const char *wgname) { - return util_alloc_sprintf(ECL_SUM_KEYFMT_WELL, keyword, join_string, - wgname); + return util_alloc_sprintf(RD_SUM_KEYFMT_WELL, keyword, join_string, wgname); } char *smspec_alloc_block_ijk_key(const char *join_string, const char *keyword, int i, int j, int k) { - return util_alloc_sprintf(ECL_SUM_KEYFMT_BLOCK_IJK, keyword, join_string, i, + return util_alloc_sprintf(RD_SUM_KEYFMT_BLOCK_IJK, keyword, join_string, i, j, k); } std::string smspec_alloc_block_ijk_key(const char *join_string, const std::string &keyword, int i, int j, int k) { - return ecl::util::string_format(ECL_SUM_KEYFMT_BLOCK_IJK, keyword.c_str(), - join_string, i, j, k); + return rd::util::string_format(RD_SUM_KEYFMT_BLOCK_IJK, keyword.c_str(), + join_string, i, j, k); } char *smspec_alloc_segment_key(const char *join_string, const std::string &keyword, const std::string &wgname, int num) { if (wgname.size() > 0) - return util_alloc_sprintf(ECL_SUM_KEYFMT_SEGMENT, keyword.c_str(), + return util_alloc_sprintf(RD_SUM_KEYFMT_SEGMENT, keyword.c_str(), join_string, wgname.c_str(), join_string, num); else @@ -368,7 +367,7 @@ char *smspec_alloc_local_well_key(const char *join_string, const std::string &lgr_name, const std::string &wgname) { if (wgname.size() > 0) - return util_alloc_sprintf(ECL_SUM_KEYFMT_LOCAL_WELL, keyword.c_str(), + return util_alloc_sprintf(RD_SUM_KEYFMT_LOCAL_WELL, keyword.c_str(), join_string, lgr_name.c_str(), join_string, wgname.c_str()); else @@ -381,7 +380,7 @@ char *smspec_alloc_local_completion_key(const char *join_string, const std::string &wgname, int i, int j, int k) { if (wgname.size() > 0) - return util_alloc_sprintf(ECL_SUM_KEYFMT_LOCAL_COMPLETION, + return util_alloc_sprintf(RD_SUM_KEYFMT_LOCAL_COMPLETION, keyword.c_str(), join_string, lgr_name.c_str(), join_string, wgname.c_str(), join_string, i, j, k); @@ -431,16 +430,16 @@ bool smspec_node_identify_rate(const char *keyword) { Special gas rates (like gas lift, import, export, consumption, sales ++) Solvents, tracers, brines and environmental tracers Production ratios (unitless, not really rates) - ECL_SMSPEC_SEGMENT_VAR and ECL_SMSPEC_REGION_2_REGION_VAR are handled + RD_SMSPEC_SEGMENT_VAR and RD_SMSPEC_REGION_2_REGION_VAR are handled separately as they do not overlap much with the rest. */ - auto var_type = ecl_smspec_identify_var_type(keyword); - if (var_type == ECL_SMSPEC_WELL_VAR || var_type == ECL_SMSPEC_GROUP_VAR || - var_type == ECL_SMSPEC_FIELD_VAR || var_type == ECL_SMSPEC_REGION_VAR || - var_type == ECL_SMSPEC_COMPLETION_VAR || - var_type == ECL_SMSPEC_LOCAL_WELL_VAR || - var_type == ECL_SMSPEC_LOCAL_COMPLETION_VAR) { + auto var_type = rd_smspec_identify_var_type(keyword); + if (var_type == RD_SMSPEC_WELL_VAR || var_type == RD_SMSPEC_GROUP_VAR || + var_type == RD_SMSPEC_FIELD_VAR || var_type == RD_SMSPEC_REGION_VAR || + var_type == RD_SMSPEC_COMPLETION_VAR || + var_type == RD_SMSPEC_LOCAL_WELL_VAR || + var_type == RD_SMSPEC_LOCAL_COMPLETION_VAR) { static const std::vector rate_vars{ {"OPR", "OIR", "OVPR", "OVIR", "OFR", "OPP", "OPI", "OMR", "GPR", "GIR", "GVPR", "GVIR", "GFR", "GPP", "GPI", "GMR", @@ -449,14 +448,14 @@ bool smspec_node_identify_rate(const char *keyword) { "RGR", "EGR", "EXGR", "SGR", "GSR", "FGR", "GIMR", "GCR", "NPR", "NIR", "CPR", "CIR", "SIR", "SPR", "TIR", "TPR", "GOR", "WCT", "OGR", "WGR", "GLR"}}; - if (var_type == ECL_SMSPEC_LOCAL_WELL_VAR || - var_type == ECL_SMSPEC_LOCAL_COMPLETION_VAR) { + if (var_type == RD_SMSPEC_LOCAL_WELL_VAR || + var_type == RD_SMSPEC_LOCAL_COMPLETION_VAR) { //LOCAL var_type's are prefixed with L (that we ignore) return match_keyword_vector(2, rate_vars, keyword); } return match_keyword_vector(1, rate_vars, keyword); } - if (var_type == ECL_SMSPEC_SEGMENT_VAR) { + if (var_type == RD_SMSPEC_SEGMENT_VAR) { static const std::vector seg_rate_vars{{ "OFR", "GFR", @@ -472,7 +471,7 @@ bool smspec_node_identify_rate(const char *keyword) { }}; return match_keyword_vector(1, seg_rate_vars, keyword); } - if (var_type == ECL_SMSPEC_REGION_2_REGION_VAR) { + if (var_type == RD_SMSPEC_REGION_2_REGION_VAR) { //Region to region rates are identified by R*FR or R**FR if (match_keyword_string(2, "FR", keyword)) { return true; @@ -483,7 +482,7 @@ bool smspec_node_identify_rate(const char *keyword) { } bool smspec_node_identify_total(const char *keyword, - ecl_smspec_var_type var_type) { + rd_smspec_var_type var_type) { /* Identify vectors that are likely to be cumulative vectors. First input character is ignored (e.g. F, G, W and R for Field, Group, Well and Region) @@ -498,14 +497,14 @@ bool smspec_node_identify_total(const char *keyword, Liquid + reservoir voidage totals Special gas totals (like import, export, consumption, sales ++) Solvents, tracers, brines and environmental tracers - ECL_SMSPEC_SEGMENT_VAR and ECL_SMSPEC_REGION_2_REGION_VAR are handled + RD_SMSPEC_SEGMENT_VAR and RD_SMSPEC_REGION_2_REGION_VAR are handled separately as they do not overlap much with the rest. */ - if (var_type == ECL_SMSPEC_WELL_VAR || var_type == ECL_SMSPEC_GROUP_VAR || - var_type == ECL_SMSPEC_FIELD_VAR || var_type == ECL_SMSPEC_REGION_VAR || - var_type == ECL_SMSPEC_COMPLETION_VAR || - var_type == ECL_SMSPEC_LOCAL_WELL_VAR || - var_type == ECL_SMSPEC_LOCAL_COMPLETION_VAR) { + if (var_type == RD_SMSPEC_WELL_VAR || var_type == RD_SMSPEC_GROUP_VAR || + var_type == RD_SMSPEC_FIELD_VAR || var_type == RD_SMSPEC_REGION_VAR || + var_type == RD_SMSPEC_COMPLETION_VAR || + var_type == RD_SMSPEC_LOCAL_WELL_VAR || + var_type == RD_SMSPEC_LOCAL_COMPLETION_VAR) { static const std::vector rate_vars{{ "OPT", "OIT", "OVPT", "OVIT", "OMT", "GPT", "GIT", "GVPT", "GVIT", "GMT", "WGPT", "WGIT", "WPT", "WIT", "WVPT", "WVIT", @@ -514,14 +513,14 @@ bool smspec_node_identify_total(const char *keyword, "SIT", "SPT", "TIT", "TPT", }}; - if (var_type == ECL_SMSPEC_LOCAL_WELL_VAR || - var_type == ECL_SMSPEC_LOCAL_COMPLETION_VAR) { + if (var_type == RD_SMSPEC_LOCAL_WELL_VAR || + var_type == RD_SMSPEC_LOCAL_COMPLETION_VAR) { //LOCAL var_type's are prefixed with L (that we ignore) return match_keyword_vector(2, rate_vars, keyword); } return match_keyword_vector(1, rate_vars, keyword); } - if (var_type == ECL_SMSPEC_SEGMENT_VAR) { + if (var_type == RD_SMSPEC_SEGMENT_VAR) { static const std::vector seg_rate_vars{{ "OFT", "GFT", @@ -529,7 +528,7 @@ bool smspec_node_identify_total(const char *keyword, }}; return match_keyword_vector(1, seg_rate_vars, keyword); } - if (var_type == ECL_SMSPEC_REGION_2_REGION_VAR) { + if (var_type == RD_SMSPEC_REGION_2_REGION_VAR) { //Region to region totals are identified by R*FT or R**FT if (match_keyword_string(2, "FT", keyword)) { return true; @@ -539,7 +538,7 @@ bool smspec_node_identify_total(const char *keyword, return false; } -namespace ecl { +namespace rd { float smspec_node::get_default() const { return this->default_value; } @@ -561,11 +560,11 @@ void smspec_node::set_wgname(const char *wgname) { if (IS_DUMMY_WELL(wgname)) return; - if (this->var_type == ECL_SMSPEC_WELL_VAR || - this->var_type == ECL_SMSPEC_GROUP_VAR || - this->var_type == ECL_SMSPEC_COMPLETION_VAR || - this->var_type == ECL_SMSPEC_SEGMENT_VAR || - this->var_type == ECL_SMSPEC_LOCAL_WELL_VAR) + if (this->var_type == RD_SMSPEC_WELL_VAR || + this->var_type == RD_SMSPEC_GROUP_VAR || + this->var_type == RD_SMSPEC_COMPLETION_VAR || + this->var_type == RD_SMSPEC_SEGMENT_VAR || + this->var_type == RD_SMSPEC_LOCAL_WELL_VAR) this->wgname = wgname; } @@ -575,8 +574,8 @@ void smspec_node::set_num(const int *grid_dims, int num_) { "seems like a bug?!\n", __func__); this->num = num_; - if ((var_type == ECL_SMSPEC_COMPLETION_VAR) || - (var_type == ECL_SMSPEC_BLOCK_VAR)) { + if ((var_type == RD_SMSPEC_COMPLETION_VAR) || + (var_type == RD_SMSPEC_BLOCK_VAR)) { int global_index = this->num - 1; this->ijk[2] = global_index / (grid_dims[0] * grid_dims[1]); global_index -= this->ijk[2] * (grid_dims[0] * grid_dims[1]); @@ -591,7 +590,7 @@ void smspec_node::set_num(const int *grid_dims, int num_) { } void smspec_node::decode_R1R2(int *r1, int *r2) const { - if (var_type == ECL_SMSPEC_REGION_2_REGION_VAR) { + if (var_type == RD_SMSPEC_REGION_2_REGION_VAR) { *r1 = this->num % 32768; *r2 = ((this->num - (*r1)) / 32768) - 10; } else { @@ -626,35 +625,35 @@ void smspec_node::set_gen_keys(const char *key_join_string_) { auto k2 = std::unique_ptr(nullptr); switch (var_type) { - case (ECL_SMSPEC_COMPLETION_VAR): + case (RD_SMSPEC_COMPLETION_VAR): // KEYWORD:WGNAME:NUM k1.reset(smspec_alloc_completion_ijk_key( key_join_string_, keyword, wgname, ijk[0], ijk[1], ijk[2])); k2.reset(smspec_alloc_completion_num_key(key_join_string_, keyword, wgname, num)); break; - case (ECL_SMSPEC_FIELD_VAR): + case (RD_SMSPEC_FIELD_VAR): // KEYWORD gen_key1 = keyword; break; - case (ECL_SMSPEC_GROUP_VAR): + case (RD_SMSPEC_GROUP_VAR): // KEYWORD:WGNAME gen_key1 = smspec_alloc_group_key(key_join_string_, keyword, wgname); break; - case (ECL_SMSPEC_WELL_VAR): + case (RD_SMSPEC_WELL_VAR): // KEYWORD:WGNAME gen_key1 = smspec_alloc_well_key(key_join_string_, keyword, wgname); break; - case (ECL_SMSPEC_REGION_VAR): + case (RD_SMSPEC_REGION_VAR): // KEYWORD:NUM gen_key1 = smspec_alloc_region_key(key_join_string_, keyword, num); break; - case (ECL_SMSPEC_SEGMENT_VAR): + case (RD_SMSPEC_SEGMENT_VAR): // KEYWORD:WGNAME:NUM k1.reset( smspec_alloc_segment_key(key_join_string_, keyword, wgname, num)); break; - case (ECL_SMSPEC_REGION_2_REGION_VAR): + case (RD_SMSPEC_REGION_2_REGION_VAR): // KEYWORDS:RXF:NUM and RXF:R1-R2 { int r1, r2; @@ -665,36 +664,36 @@ void smspec_node::set_gen_keys(const char *key_join_string_) { gen_key2 = smspec_alloc_region_2_region_num_key(key_join_string_, keyword, num); break; - case (ECL_SMSPEC_MISC_VAR): + case (RD_SMSPEC_MISC_VAR): // KEYWORD /* Misc variable - i.e. date or CPU time ... */ gen_key1 = keyword; break; - case (ECL_SMSPEC_BLOCK_VAR): + case (RD_SMSPEC_BLOCK_VAR): // KEYWORD:NUM gen_key1 = smspec_alloc_block_ijk_key(key_join_string_, keyword, ijk[0], ijk[1], ijk[2]); gen_key2 = smspec_alloc_block_num_key(key_join_string_, keyword, num); break; - case (ECL_SMSPEC_LOCAL_WELL_VAR): + case (RD_SMSPEC_LOCAL_WELL_VAR): /** KEYWORD:LGR:WGNAME */ k1.reset(smspec_alloc_local_well_key(key_join_string_, keyword, lgr_name, wgname)); break; - case (ECL_SMSPEC_LOCAL_BLOCK_VAR): + case (RD_SMSPEC_LOCAL_BLOCK_VAR): /* KEYWORD:LGR:i,j,k */ gen_key1 = smspec_alloc_local_block_key(key_join_string_, keyword, lgr_name, lgr_ijk[0], lgr_ijk[1], lgr_ijk[2]); break; - case (ECL_SMSPEC_LOCAL_COMPLETION_VAR): + case (RD_SMSPEC_LOCAL_COMPLETION_VAR): /* KEYWORD:LGR:WELL:i,j,k */ k1.reset(smspec_alloc_local_completion_key(key_join_string_, keyword, lgr_name, wgname, lgr_ijk[0], lgr_ijk[1], lgr_ijk[2])); break; - case (ECL_SMSPEC_AQUIFER_VAR): + case (RD_SMSPEC_AQUIFER_VAR): gen_key1 = smspec_alloc_aquifer_key(key_join_string_, keyword, num); break; default: @@ -720,24 +719,24 @@ void smspec_node::set_gen_keys(const char *key_join_string_) { */ -ecl_smspec_var_type smspec_node::valid_type(const char *keyword, - const char *wgname, int num) { +rd_smspec_var_type smspec_node::valid_type(const char *keyword, + const char *wgname, int num) { auto var_type = smspec_node::identify_var_type(keyword); - if (var_type == ECL_SMSPEC_MISC_VAR) + if (var_type == RD_SMSPEC_MISC_VAR) return var_type; - if (var_type == ECL_SMSPEC_FIELD_VAR) + if (var_type == RD_SMSPEC_FIELD_VAR) return var_type; - if (var_type == ECL_SMSPEC_LOCAL_BLOCK_VAR) + if (var_type == RD_SMSPEC_LOCAL_BLOCK_VAR) return var_type; - if (var_type == ECL_SMSPEC_WELL_VAR || var_type == ECL_SMSPEC_GROUP_VAR || - var_type == ECL_SMSPEC_LOCAL_WELL_VAR || - var_type == ECL_SMSPEC_LOCAL_COMPLETION_VAR) { + if (var_type == RD_SMSPEC_WELL_VAR || var_type == RD_SMSPEC_GROUP_VAR || + var_type == RD_SMSPEC_LOCAL_WELL_VAR || + var_type == RD_SMSPEC_LOCAL_COMPLETION_VAR) { if (IS_DUMMY_WELL(wgname)) - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; /* In most cases the dummy well ':+:+:+:+' is used in situations where a @@ -747,37 +746,36 @@ ecl_smspec_var_type smspec_node::valid_type(const char *keyword, */ if (!wgname) - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; if (strlen(wgname) == 0) - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; return var_type; } - if (var_type == ECL_SMSPEC_COMPLETION_VAR || - var_type == ECL_SMSPEC_SEGMENT_VAR) { + if (var_type == RD_SMSPEC_COMPLETION_VAR || + var_type == RD_SMSPEC_SEGMENT_VAR) { if (IS_DUMMY_WELL(wgname)) - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; if (num < 0) - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; return var_type; } - if (var_type == ECL_SMSPEC_REGION_VAR || - var_type == ECL_SMSPEC_REGION_2_REGION_VAR || - var_type == ECL_SMSPEC_BLOCK_VAR || - var_type == ECL_SMSPEC_AQUIFER_VAR) { + if (var_type == RD_SMSPEC_REGION_VAR || + var_type == RD_SMSPEC_REGION_2_REGION_VAR || + var_type == RD_SMSPEC_BLOCK_VAR || var_type == RD_SMSPEC_AQUIFER_VAR) { if (num < 0) - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; return var_type; } - return ECL_SMSPEC_INVALID_VAR; + return RD_SMSPEC_INVALID_VAR; } /** @@ -790,8 +788,8 @@ ecl_smspec_var_type smspec_node::valid_type(const char *keyword, This function initializes a valid smspec_node instance based on the supplied var_type, and the input. Observe that when a new variable type is supported, the big switch() statement must be - updated in the functions ecl_smspec_install_gen_key() and - ecl_smspec_fread_header() functions in addition. UGGGLY + updated in the functions rd_smspec_install_gen_key() and + rd_smspec_fread_header() functions in addition. UGGGLY */ smspec_node::smspec_node(int param_index, const char *keyword, int num, @@ -837,7 +835,7 @@ smspec_node::smspec_node(int param_index, const char *keyword, Well and group names in the wgname parameter is quite messy. The situation is as follows: - o The ECLIPSE SMSPEC files are very verbose, and contain many + o The SMSPEC files are very verbose, and contain many entries like this: KEYWORD : "WWCT" @@ -853,7 +851,7 @@ smspec_node::smspec_node(int param_index, const char *keyword, the macro IS_DUMMY_WELL(wgname) can used to compare with the DUMMY_WELL value. - o When the ecl_sum instance is created in write mode; it must be + o When the rd_sum instance is created in write mode; it must be possible to add smspec nodes for wells/groups which do not have a name yet. In this case we accept NULL as input value for the wgname parameter. @@ -863,7 +861,7 @@ smspec_node::smspec_node(int param_index, const char *keyword, completely. */ this->var_type = this->valid_type(keyword, wgname, num); - if (this->var_type == ECL_SMSPEC_INVALID_VAR) + if (this->var_type == RD_SMSPEC_INVALID_VAR) throw std::invalid_argument( "Could not construct smspec_node from this input."); @@ -879,36 +877,36 @@ smspec_node::smspec_node(int param_index, const char *keyword, this->set_wgname(wgname); switch (this->var_type) { - case (ECL_SMSPEC_COMPLETION_VAR): + case (RD_SMSPEC_COMPLETION_VAR): /* Completion variable : WGNAME & NUM */ set_num(grid_dims, num); break; - case (ECL_SMSPEC_GROUP_VAR): + case (RD_SMSPEC_GROUP_VAR): /* Group variable : WGNAME */ break; - case (ECL_SMSPEC_WELL_VAR): + case (RD_SMSPEC_WELL_VAR): /* Well variable : WGNAME */ break; - case (ECL_SMSPEC_SEGMENT_VAR): + case (RD_SMSPEC_SEGMENT_VAR): set_num(grid_dims, num); break; - case (ECL_SMSPEC_FIELD_VAR): + case (RD_SMSPEC_FIELD_VAR): /* Field variable : */ /* Fully initialized with the smspec_common_init() function */ break; - case (ECL_SMSPEC_REGION_VAR): + case (RD_SMSPEC_REGION_VAR): /* Region variable : NUM */ set_num(grid_dims, num); break; - case (ECL_SMSPEC_REGION_2_REGION_VAR): + case (RD_SMSPEC_REGION_2_REGION_VAR): /* Region 2 region variable : NUM */ set_num(grid_dims, num); break; - case (ECL_SMSPEC_BLOCK_VAR): + case (RD_SMSPEC_BLOCK_VAR): /* A block variable : NUM*/ set_num(grid_dims, num); break; - case (ECL_SMSPEC_MISC_VAR): + case (RD_SMSPEC_MISC_VAR): /* Misc variable : */ /* @@ -925,7 +923,7 @@ smspec_node::smspec_node(int param_index, const char *keyword, set_num(grid_dims, SMSPEC_YEARS_NUMS_VALUE); break; - case (ECL_SMSPEC_AQUIFER_VAR): + case (RD_SMSPEC_AQUIFER_VAR): set_num(grid_dims, num); break; default: @@ -941,7 +939,7 @@ smspec_node::smspec_node(int param_index_, const char *keyword_, float default_value_, const char *key_join_string_) { this->var_type = this->valid_type(keyword_, wgname_, -1); - if (this->var_type == ECL_SMSPEC_INVALID_VAR) + if (this->var_type == RD_SMSPEC_INVALID_VAR) throw std::invalid_argument( "Could not construct smspec_node from this input."); @@ -958,12 +956,12 @@ smspec_node::smspec_node(int param_index_, const char *keyword_, this->num = nums_unused; switch (this->var_type) { - case (ECL_SMSPEC_LOCAL_WELL_VAR): + case (RD_SMSPEC_LOCAL_WELL_VAR): break; - case (ECL_SMSPEC_LOCAL_BLOCK_VAR): + case (RD_SMSPEC_LOCAL_BLOCK_VAR): set_lgr_ijk(lgr_i, lgr_j, lgr_k); break; - case (ECL_SMSPEC_LOCAL_COMPLETION_VAR): + case (RD_SMSPEC_LOCAL_COMPLETION_VAR): set_lgr_ijk(lgr_i, lgr_j, lgr_k); break; default: @@ -1006,7 +1004,7 @@ const char *smspec_node::get_keyword() const { return get_cstring(this->keyword); } -ecl_smspec_var_type smspec_node::get_var_type() const { return this->var_type; } +rd_smspec_var_type smspec_node::get_var_type() const { return this->var_type; } int smspec_node::get_num() const { return this->num; } @@ -1033,11 +1031,11 @@ const std::array &smspec_node::get_lgr_ijk() const { /* Will return -1 for smspec_node variables which are not - of type ECL_SMSPEC_REGION_2_REGION_VAR. + of type RD_SMSPEC_REGION_2_REGION_VAR. */ int smspec_node::get_R1() const { - if (var_type == ECL_SMSPEC_REGION_2_REGION_VAR) { + if (var_type == RD_SMSPEC_REGION_2_REGION_VAR) { int r1, r2; decode_R1R2(&r1, &r2); return r1; @@ -1046,7 +1044,7 @@ int smspec_node::get_R1() const { } int smspec_node::get_R2() const { - if (var_type == ECL_SMSPEC_REGION_2_REGION_VAR) { + if (var_type == RD_SMSPEC_REGION_2_REGION_VAR) { int r1, r2; decode_R1R2(&r1, &r2); return r2; @@ -1061,12 +1059,12 @@ bool smspec_node::need_nums() const { file. */ { - if (this->var_type == ECL_SMSPEC_COMPLETION_VAR || - this->var_type == ECL_SMSPEC_SEGMENT_VAR || - this->var_type == ECL_SMSPEC_REGION_VAR || - this->var_type == ECL_SMSPEC_REGION_2_REGION_VAR || - this->var_type == ECL_SMSPEC_BLOCK_VAR || - this->var_type == ECL_SMSPEC_AQUIFER_VAR) + if (this->var_type == RD_SMSPEC_COMPLETION_VAR || + this->var_type == RD_SMSPEC_SEGMENT_VAR || + this->var_type == RD_SMSPEC_REGION_VAR || + this->var_type == RD_SMSPEC_REGION_2_REGION_VAR || + this->var_type == RD_SMSPEC_BLOCK_VAR || + this->var_type == RD_SMSPEC_AQUIFER_VAR) return true; else { if (this->num == SMSPEC_NUMS_INVALID) @@ -1235,8 +1233,8 @@ int cmp_key1(const smspec_node &node1, const smspec_node &node2) { int smspec_node::cmp(const smspec_node &node1, const smspec_node &node2) { /* 1: Start with special casing for the MISC variables. */ - if ((node1.var_type == ECL_SMSPEC_MISC_VAR) || - (node2.var_type == ECL_SMSPEC_MISC_VAR)) + if ((node1.var_type == RD_SMSPEC_MISC_VAR) || + (node2.var_type == RD_SMSPEC_MISC_VAR)) return cmp_MISC(node1, node2); /* 2: Sort according to variable type */ @@ -1249,33 +1247,33 @@ int smspec_node::cmp(const smspec_node &node1, const smspec_node &node2) { /* 3: Internal sort of variables of the same type. */ switch (node1.var_type) { - case (ECL_SMSPEC_FIELD_VAR): + case (RD_SMSPEC_FIELD_VAR): return cmp_KEYWORD(node1, node2); - case (ECL_SMSPEC_WELL_VAR): - case (ECL_SMSPEC_GROUP_VAR): + case (RD_SMSPEC_WELL_VAR): + case (RD_SMSPEC_GROUP_VAR): return cmp_KEYWORD_WGNAME(node1, node2); - case (ECL_SMSPEC_BLOCK_VAR): - case (ECL_SMSPEC_REGION_VAR): - case (ECL_SMSPEC_REGION_2_REGION_VAR): - case (ECL_SMSPEC_AQUIFER_VAR): + case (RD_SMSPEC_BLOCK_VAR): + case (RD_SMSPEC_REGION_VAR): + case (RD_SMSPEC_REGION_2_REGION_VAR): + case (RD_SMSPEC_AQUIFER_VAR): return cmp_KEYWORD_NUM(node1, node2); - case (ECL_SMSPEC_COMPLETION_VAR): - case (ECL_SMSPEC_SEGMENT_VAR): + case (RD_SMSPEC_COMPLETION_VAR): + case (RD_SMSPEC_SEGMENT_VAR): return cmp_KEYWORD_WGNAME_NUM(node1, node2); - case (ECL_SMSPEC_NETWORK_VAR): + case (RD_SMSPEC_NETWORK_VAR): return cmp_key1(node1, node2); - case (ECL_SMSPEC_LOCAL_BLOCK_VAR): + case (RD_SMSPEC_LOCAL_BLOCK_VAR): return cmp_KEYWORD_LGR_LGRIJK(node1, node2); - case (ECL_SMSPEC_LOCAL_WELL_VAR): + case (RD_SMSPEC_LOCAL_WELL_VAR): return cmp_KEYWORD_WGNAME_LGR(node1, node2); - case (ECL_SMSPEC_LOCAL_COMPLETION_VAR): + case (RD_SMSPEC_LOCAL_COMPLETION_VAR): return cmp_KEYWORD_WGNAME_LGR_LGRIJK(node1, node2); default: @@ -1288,105 +1286,105 @@ int smspec_node::cmp(const smspec_node &node2) const { return smspec_node::cmp(*this, node2); } -} // end namespace ecl +} // end namespace rd /************************************** OLD API functions ***********************''''' */ void smspec_node_free(void *index) { - delete static_cast(index); + delete static_cast(index); } void smspec_node_free__(void *arg) { smspec_node_free(arg); } float smspec_node_get_default(const void *smspec_node) { - return static_cast(smspec_node)->get_default(); + return static_cast(smspec_node)->get_default(); } int smspec_node_get_params_index(const void *smspec_node) { - return static_cast(smspec_node) + return static_cast(smspec_node) ->get_params_index(); } // void smspec_node_set_params_index( void * smspec_node , int params_index) { -// static_cast(smspec_node)->set_params_index( params_index ); +// static_cast(smspec_node)->set_params_index( params_index ); // } const char *smspec_node_get_gen_key1(const void *smspec_node) { - return static_cast(smspec_node)->get_gen_key1(); + return static_cast(smspec_node)->get_gen_key1(); } const char *smspec_node_get_gen_key2(const void *smspec_node) { - return static_cast(smspec_node)->get_gen_key2(); + return static_cast(smspec_node)->get_gen_key2(); } const char *smspec_node_get_wgname(const void *smspec_node) { - return static_cast(smspec_node)->get_wgname(); + return static_cast(smspec_node)->get_wgname(); } const char *smspec_node_get_keyword(const void *smspec_node) { - return static_cast(smspec_node)->get_keyword(); + return static_cast(smspec_node)->get_keyword(); } -ecl_smspec_var_type smspec_node_get_var_type(const void *smspec_node) { - return static_cast(smspec_node)->get_var_type(); +rd_smspec_var_type smspec_node_get_var_type(const void *smspec_node) { + return static_cast(smspec_node)->get_var_type(); } int smspec_node_get_num(const void *smspec_node) { - return static_cast(smspec_node)->get_num(); + return static_cast(smspec_node)->get_num(); } bool smspec_node_is_rate(const void *smspec_node) { - return static_cast(smspec_node)->is_rate(); + return static_cast(smspec_node)->is_rate(); } bool smspec_node_is_total(const void *smspec_node) { - return static_cast(smspec_node)->is_total(); + return static_cast(smspec_node)->is_total(); } bool smspec_node_is_historical(const void *smspec_node) { - return static_cast(smspec_node)->is_historical(); + return static_cast(smspec_node)->is_historical(); } const char *smspec_node_get_unit(const void *smspec_node) { - return static_cast(smspec_node)->get_unit(); + return static_cast(smspec_node)->get_unit(); } // Will be garbage for smspec_nodes which do not have i,j,k const int *smspec_node_get_ijk(const void *smspec_node) { - return static_cast(smspec_node)->get_ijk().data(); + return static_cast(smspec_node)->get_ijk().data(); } // Will be NULL for smspec_nodes which are not related to an LGR. const char *smspec_node_get_lgr_name(const void *smspec_node) { - return static_cast(smspec_node)->get_lgr_name(); + return static_cast(smspec_node)->get_lgr_name(); } // Will be garbage for smspec_nodes which are not related to an LGR. const int *smspec_node_get_lgr_ijk(const void *smspec_node) { - return static_cast(smspec_node) + return static_cast(smspec_node) ->get_lgr_ijk() .data(); } int smspec_node_get_R1(const void *smspec_node) { - return static_cast(smspec_node)->get_R1(); + return static_cast(smspec_node)->get_R1(); } int smspec_node_get_R2(const void *smspec_node) { - return static_cast(smspec_node)->get_R2(); + return static_cast(smspec_node)->get_R2(); } bool smspec_node_need_nums(const void *smspec_node) { - return static_cast(smspec_node)->need_nums(); + return static_cast(smspec_node)->need_nums(); } void smspec_node_fprintf(const void *smspec_node, FILE *stream) { - static_cast(smspec_node)->fprintf__(stream); + static_cast(smspec_node)->fprintf__(stream); } int smspec_node_cmp(const void *node1, const void *node2) { - return ecl::smspec_node::cmp(static_cast(node1), - static_cast(node2)); + return rd::smspec_node::cmp(static_cast(node1), + static_cast(node2)); } int smspec_node_cmp__(const void *node1, const void *node2) { @@ -1398,40 +1396,40 @@ void *smspec_node_alloc(int param_index, const char *keyword, const int grid_dims[3], float default_value, const char *key_join_string) { - ecl::smspec_node *node = NULL; + rd::smspec_node *node = NULL; try { - node = new ecl::smspec_node(param_index, keyword, wgname, num, unit, - grid_dims, default_value, key_join_string); + node = new rd::smspec_node(param_index, keyword, wgname, num, unit, + grid_dims, default_value, key_join_string); } catch (const std::invalid_argument &e) { node = NULL; } return node; } -void *smspec_node_alloc_lgr(ecl_smspec_var_type var_type, const char *wgname, +void *smspec_node_alloc_lgr(rd_smspec_var_type var_type, const char *wgname, const char *keyword, const char *unit, const char *lgr, const char *key_join_string, int lgr_i, int lgr_j, int lgr_k, int param_index, float default_value) { - return new ecl::smspec_node(param_index, keyword, wgname, unit, lgr, lgr_i, - lgr_j, lgr_k, default_value, key_join_string); + return new rd::smspec_node(param_index, keyword, wgname, unit, lgr, lgr_i, + lgr_j, lgr_k, default_value, key_join_string); } bool smspec_node_equal(const void *node1, const void *node2) { - return ecl::smspec_node::cmp( - static_cast(node1), - static_cast(node2)) == 0; + return rd::smspec_node::cmp(static_cast(node1), + static_cast(node2)) == + 0; } bool smspec_node_gt(const void *node1, const void *node2) { - return ecl::smspec_node::cmp(static_cast(node1), - static_cast(node2)) > + return rd::smspec_node::cmp(static_cast(node1), + static_cast(node2)) > 0; } bool smspec_node_lt(const void *node1, const void *node2) { - return ecl::smspec_node::cmp(static_cast(node1), - static_cast(node2)) < + return rd::smspec_node::cmp(static_cast(node1), + static_cast(node2)) < 0; } diff --git a/lib/ecl/tests/data/num_cpu1 b/lib/resdata/tests/data/num_cpu1 similarity index 100% rename from lib/ecl/tests/data/num_cpu1 rename to lib/resdata/tests/data/num_cpu1 diff --git a/lib/ecl/tests/data/num_cpu2 b/lib/resdata/tests/data/num_cpu2 similarity index 100% rename from lib/ecl/tests/data/num_cpu2 rename to lib/resdata/tests/data/num_cpu2 diff --git a/lib/ecl/tests/data/num_cpu3 b/lib/resdata/tests/data/num_cpu3 similarity index 100% rename from lib/ecl/tests/data/num_cpu3 rename to lib/resdata/tests/data/num_cpu3 diff --git a/lib/ecl/tests/data/num_cpu4 b/lib/resdata/tests/data/num_cpu4 similarity index 100% rename from lib/ecl/tests/data/num_cpu4 rename to lib/resdata/tests/data/num_cpu4 diff --git a/lib/ecl/tests/data/num_cpu5 b/lib/resdata/tests/data/num_cpu5 similarity index 100% rename from lib/ecl/tests/data/num_cpu5 rename to lib/resdata/tests/data/num_cpu5 diff --git a/lib/resdata/tests/rd_coarse_test.cpp b/lib/resdata/tests/rd_coarse_test.cpp new file mode 100644 index 0000000000..edfb5dc51b --- /dev/null +++ b/lib/resdata/tests/rd_coarse_test.cpp @@ -0,0 +1,88 @@ +#include +#include + +#include + +#include +#include +#include +#include + +void test_coarse_cell(const rd_grid_type *grid, rd_coarse_cell_type *cell) { + const int_vector_type *global_index_list = + rd_coarse_cell_get_index_vector(cell); + const int *ijk = rd_coarse_cell_get_box_ptr(cell); + int c; + int prev_active = 0; + + for (c = 0; c < rd_coarse_cell_get_size(cell); c++) { + int gi = int_vector_iget(global_index_list, c); + int i, j, k; + + /* The coordinates are right */ + rd_grid_get_ijk1(grid, gi, &i, &j, &k); + if ((i < ijk[0]) || (i > ijk[1])) + test_error_exit("i:%d not inside range [%d,%d] \n", i, ijk[0], + ijk[1]); + + if ((j < ijk[2]) || (j > ijk[3])) + test_error_exit("j:%d not inside range [%d,%d] \n", j, ijk[2], + ijk[3]); + + if ((k < ijk[4]) || (k > ijk[5])) + test_error_exit("k:%d not inside range [%d,%d] \n", k, ijk[4], + ijk[4]); + + if (c == 0) + prev_active = rd_grid_get_active_index1(grid, gi); + else { + /* All the cells have the same active value */ + int this_active = rd_grid_get_active_index1(grid, gi); + test_assert_int_equal(prev_active, this_active); + prev_active = this_active; + } + } +} + +int main(int argc, char **argv) { + const char *case_path = argv[1]; + char *egrid_file = + rd_alloc_filename(NULL, case_path, RD_EGRID_FILE, false, 0); + char *rst_file = + rd_alloc_filename(NULL, case_path, RD_RESTART_FILE, false, 0); + char *init_file = + rd_alloc_filename(NULL, case_path, RD_INIT_FILE, false, 0); + + rd_grid_type *GRID = rd_grid_alloc(egrid_file); + rd_file_type *RST_file = rd_file_open(rst_file, 0); + rd_file_type *INIT_file = rd_file_open(init_file, 0); + + { + test_assert_true(rd_grid_have_coarse_cells(GRID)); + test_assert_int_equal(rd_grid_get_num_coarse_groups(GRID), 3384); + } + + { + const rd_kw_type *swat0 = rd_file_iget_named_kw(RST_file, "SWAT", 0); + const rd_kw_type *porv = rd_file_iget_named_kw(INIT_file, "PORV", 0); + + test_assert_int_equal(rd_kw_get_size(swat0), + rd_grid_get_active_size(GRID)); + test_assert_int_equal(rd_kw_get_size(porv), + rd_grid_get_global_size(GRID)); + } + + { + int ic; + for (ic = 0; ic < rd_grid_get_num_coarse_groups(GRID); ic++) { + rd_coarse_cell_type *coarse_cell = + rd_grid_iget_coarse_group(GRID, ic); + test_coarse_cell(GRID, coarse_cell); + } + } + + rd_file_close(INIT_file); + rd_file_close(RST_file); + rd_grid_free(GRID); + exit(0); +} diff --git a/lib/resdata/tests/rd_dualp.cpp b/lib/resdata/tests/rd_dualp.cpp new file mode 100644 index 0000000000..d9301b5b08 --- /dev/null +++ b/lib/resdata/tests/rd_dualp.cpp @@ -0,0 +1,69 @@ +#include +#include + +#include + +#include +#include +#include +#include + +int main(int argc, char **argv) { + const char *case_path = argv[1]; + char *grid_file = + rd_alloc_filename(NULL, case_path, RD_EGRID_FILE, false, 0); + char *init_file = + rd_alloc_filename(NULL, case_path, RD_INIT_FILE, false, 0); + char *rst_file = + rd_alloc_filename(NULL, case_path, RD_RESTART_FILE, false, 0); + + rd_grid_type *rd_grid = rd_grid_alloc(grid_file); + rd_file_type *RST_file = rd_file_open(rst_file, 0); + rd_file_type *INIT_file = rd_file_open(init_file, 0); + rd_file_type *GRID_file = rd_file_open(grid_file, 0); + + { + rd_kw_type *actnum = rd_file_iget_named_kw(GRID_file, "ACTNUM", 0); + rd_kw_type *swat = rd_file_iget_named_kw(RST_file, "SWAT", 0); + rd_kw_type *permx = rd_file_iget_named_kw(INIT_file, "PERMX", 0); + int fracture_size = rd_grid_get_nactive_fracture(rd_grid); + int matrix_size = rd_grid_get_nactive(rd_grid); + + test_assert_int_equal(fracture_size + matrix_size, + rd_kw_get_size(swat)); + test_assert_int_equal(fracture_size + matrix_size, + rd_kw_get_size(permx)); + + { + int gi; + int matrix_index = 0; + int fracture_index = 0; + + for (gi = 0; gi < rd_grid_get_global_size(rd_grid); gi++) { + if (rd_kw_iget_int(actnum, gi) & CELL_ACTIVE_MATRIX) { + test_assert_int_equal( + rd_grid_get_active_index1(rd_grid, gi), matrix_index); + test_assert_int_equal( + rd_grid_get_global_index1A(rd_grid, matrix_index), gi); + matrix_index++; + } + + if (rd_kw_iget_int(actnum, gi) & CELL_ACTIVE_FRACTURE) { + test_assert_int_equal( + rd_grid_get_active_fracture_index1(rd_grid, gi), + fracture_index); + test_assert_int_equal( + rd_grid_get_global_index1F(rd_grid, fracture_index), + gi); + fracture_index++; + } + } + } + } + + rd_file_close(RST_file); + rd_file_close(INIT_file); + rd_grid_free(rd_grid); + + exit(0); +} diff --git a/lib/ecl/tests/ecl_fault_block_collection_equinor.cpp b/lib/resdata/tests/rd_fault_block_collection_equinor.cpp similarity index 55% rename from lib/ecl/tests/ecl_fault_block_collection_equinor.cpp rename to lib/resdata/tests/rd_fault_block_collection_equinor.cpp index ba0d1c38db..adc0cd5622 100644 --- a/lib/ecl/tests/ecl_fault_block_collection_equinor.cpp +++ b/lib/resdata/tests/rd_fault_block_collection_equinor.cpp @@ -4,30 +4,30 @@ #include -#include -#include -#include +#include +#include +#include -void test_create(const ecl_grid_type *grid, const ecl_kw_type *fault_block_kw) { +void test_create(const rd_grid_type *grid, const rd_kw_type *fault_block_kw) { fault_block_collection_type *fault_blocks = fault_block_collection_alloc(grid); test_assert_true(fault_block_collection_is_instance(fault_blocks)); - test_assert_int_equal(ecl_grid_get_nz(grid), + test_assert_int_equal(rd_grid_get_nz(grid), fault_block_collection_num_layers(fault_blocks)); fault_block_collection_free(fault_blocks); } -void test_get_layer(const ecl_grid_type *grid, - const ecl_kw_type *fault_block_kw) { +void test_get_layer(const rd_grid_type *grid, + const rd_kw_type *fault_block_kw) { fault_block_collection_type *fault_blocks = fault_block_collection_alloc(grid); test_assert_NULL(fault_block_collection_get_layer(fault_blocks, -1)); test_assert_NULL( - fault_block_collection_get_layer(fault_blocks, ecl_grid_get_nz(grid))); + fault_block_collection_get_layer(fault_blocks, rd_grid_get_nz(grid))); { int k; - for (k = 0; k < ecl_grid_get_nz(grid); k++) { + for (k = 0; k < rd_grid_get_nz(grid); k++) { fault_block_layer_type *layer = fault_block_collection_get_layer(fault_blocks, k); test_assert_true(fault_block_layer_is_instance(layer)); @@ -39,20 +39,19 @@ void test_get_layer(const ecl_grid_type *grid, int main(int argc, char **argv) { const char *grid_file = argv[1]; const char *fault_blk_file = argv[2]; - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_file); - ecl_kw_type *fault_blk_kw; + rd_grid_type *rd_grid = rd_grid_alloc(grid_file); + rd_kw_type *fault_blk_kw; { FILE *stream = util_fopen(fault_blk_file, "r"); - fault_blk_kw = ecl_kw_fscanf_alloc_grdecl( - stream, "FAULTBLK", ecl_grid_get_global_size(ecl_grid), - ECL_INT_TYPE); + fault_blk_kw = rd_kw_fscanf_alloc_grdecl( + stream, "FAULTBLK", rd_grid_get_global_size(rd_grid), RD_INT_TYPE); fclose(stream); } - test_create(ecl_grid, fault_blk_kw); - test_get_layer(ecl_grid, fault_blk_kw); + test_create(rd_grid, fault_blk_kw); + test_get_layer(rd_grid, fault_blk_kw); - ecl_grid_free(ecl_grid); - ecl_kw_free(fault_blk_kw); + rd_grid_free(rd_grid); + rd_kw_free(fault_blk_kw); exit(0); } diff --git a/lib/ecl/tests/ecl_fault_block_layer.cpp b/lib/resdata/tests/rd_fault_block_layer.cpp similarity index 57% rename from lib/ecl/tests/ecl_fault_block_layer.cpp rename to lib/resdata/tests/rd_fault_block_layer.cpp index 2b2187c73d..5350d20736 100644 --- a/lib/ecl/tests/ecl_fault_block_layer.cpp +++ b/lib/resdata/tests/rd_fault_block_layer.cpp @@ -6,20 +6,20 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include -void test_create(const ecl_grid_type *grid, ecl_kw_type *fault_block_kw) { +void test_create(const rd_grid_type *grid, rd_kw_type *fault_block_kw) { int k = 0; int i, j; - for (j = 0; j < ecl_grid_get_ny(grid); j++) { - for (i = 0; i < ecl_grid_get_nx(grid); i++) { + for (j = 0; j < rd_grid_get_ny(grid); j++) { + for (i = 0; i < rd_grid_get_nx(grid); i++) { - int g = ecl_grid_get_global_index3(grid, i, j, k); - ecl_kw_iset_int(fault_block_kw, g, 9); + int g = rd_grid_get_global_index3(grid, i, j, k); + rd_kw_iset_int(fault_block_kw, g, 9); } } @@ -30,7 +30,7 @@ void test_create(const ecl_grid_type *grid, ecl_kw_type *fault_block_kw) { { fault_block_type *block = fault_block_layer_iget_block(layer, 0); double x, y, z; - ecl_grid_get_xyz3(grid, 4, 4, k, &x, &y, &z); + rd_grid_get_xyz3(grid, 4, 4, k, &x, &y, &z); test_assert_double_equal(x, fault_block_get_xc(block)); test_assert_double_equal(y, fault_block_get_yc(block)); } @@ -39,16 +39,16 @@ void test_create(const ecl_grid_type *grid, ecl_kw_type *fault_block_kw) { } } -void test_create_invalid(const ecl_grid_type *grid) { - ecl_kw_type *fault_blk_kw = - ecl_kw_alloc("FAULTBLK", ecl_grid_get_global_size(grid) - 1, ECL_INT); +void test_create_invalid(const rd_grid_type *grid) { + rd_kw_type *fault_blk_kw = + rd_kw_alloc("FAULTBLK", rd_grid_get_global_size(grid) - 1, RD_INT); test_assert_NULL(fault_block_layer_alloc(grid, 7)); - ecl_kw_free(fault_blk_kw); + rd_kw_free(fault_blk_kw); } -void test_trace_edge(const ecl_grid_type *grid) { +void test_trace_edge(const rd_grid_type *grid) { const int k = 1; fault_block_layer_type *layer = fault_block_layer_alloc(grid, k); double_vector_type *x_list = double_vector_alloc(0, 0); @@ -81,14 +81,14 @@ void test_trace_edge(const ecl_grid_type *grid) { double_vector_free(y_list); } -void test_export(const ecl_grid_type *grid) { +void test_export(const rd_grid_type *grid) { fault_block_layer_type *layer = fault_block_layer_alloc(grid, 0); - ecl_kw_type *ecl_kw1 = - ecl_kw_alloc("FAULTBLK", ecl_grid_get_global_size(grid), ECL_INT); - ecl_kw_type *ecl_kw2 = - ecl_kw_alloc("FAULTBLK", ecl_grid_get_global_size(grid) + 1, ECL_INT); - ecl_kw_type *ecl_kw3 = - ecl_kw_alloc("FAULTBLK", ecl_grid_get_global_size(grid), ECL_FLOAT); + rd_kw_type *rd_kw1 = + rd_kw_alloc("FAULTBLK", rd_grid_get_global_size(grid), RD_INT); + rd_kw_type *rd_kw2 = + rd_kw_alloc("FAULTBLK", rd_grid_get_global_size(grid) + 1, RD_INT); + rd_kw_type *rd_kw3 = + rd_kw_alloc("FAULTBLK", rd_grid_get_global_size(grid), RD_FLOAT); fault_block_type *block = fault_block_layer_add_block(layer, 10); fault_block_add_cell(block, 0, 0); @@ -96,39 +96,39 @@ void test_export(const ecl_grid_type *grid) { fault_block_add_cell(block, 1, 1); fault_block_add_cell(block, 0, 1); - test_assert_true(fault_block_layer_export(layer, ecl_kw1)); - test_assert_false(fault_block_layer_export(layer, ecl_kw2)); - test_assert_false(fault_block_layer_export(layer, ecl_kw3)); + test_assert_true(fault_block_layer_export(layer, rd_kw1)); + test_assert_false(fault_block_layer_export(layer, rd_kw2)); + test_assert_false(fault_block_layer_export(layer, rd_kw3)); { - int nx = ecl_grid_get_nx(grid); + int nx = rd_grid_get_nx(grid); - test_assert_int_equal(ecl_kw_iget_int(ecl_kw1, 0), 10); - test_assert_int_equal(ecl_kw_iget_int(ecl_kw1, 1), 10); - test_assert_int_equal(ecl_kw_iget_int(ecl_kw1, nx), 10); - test_assert_int_equal(ecl_kw_iget_int(ecl_kw1, nx + 1), 10); + test_assert_int_equal(rd_kw_iget_int(rd_kw1, 0), 10); + test_assert_int_equal(rd_kw_iget_int(rd_kw1, 1), 10); + test_assert_int_equal(rd_kw_iget_int(rd_kw1, nx), 10); + test_assert_int_equal(rd_kw_iget_int(rd_kw1, nx + 1), 10); } - test_assert_int_equal(40, ecl_kw_element_sum_int(ecl_kw1)); + test_assert_int_equal(40, rd_kw_element_sum_int(rd_kw1)); fault_block_layer_free(layer); - ecl_kw_free(ecl_kw1); - ecl_kw_free(ecl_kw2); - ecl_kw_free(ecl_kw3); + rd_kw_free(rd_kw1); + rd_kw_free(rd_kw2); + rd_kw_free(rd_kw3); } -void test_neighbours(const ecl_grid_type *grid) { +void test_neighbours(const rd_grid_type *grid) { const int k = 0; fault_block_layer_type *layer = fault_block_layer_alloc(grid, k); geo_polygon_collection_type *polylines = geo_polygon_collection_alloc(); - ecl_kw_type *ecl_kw = - ecl_kw_alloc("FAULTBLK", ecl_grid_get_global_size(grid), ECL_INT); + rd_kw_type *rd_kw = + rd_kw_alloc("FAULTBLK", rd_grid_get_global_size(grid), RD_INT); - ecl_kw_iset_int(ecl_kw, 0, 1); - ecl_kw_iset_int(ecl_kw, ecl_grid_get_global_index3(grid, 3, 3, k), 2); - ecl_kw_iset_int(ecl_kw, ecl_grid_get_global_index3(grid, 4, 3, k), 3); - ecl_kw_iset_int(ecl_kw, ecl_grid_get_global_index3(grid, 5, 3, k), 4); - ecl_kw_iset_int(ecl_kw, ecl_grid_get_global_index3(grid, 4, 2, k), 5); - fault_block_layer_load_kw(layer, ecl_kw); + rd_kw_iset_int(rd_kw, 0, 1); + rd_kw_iset_int(rd_kw, rd_grid_get_global_index3(grid, 3, 3, k), 2); + rd_kw_iset_int(rd_kw, rd_grid_get_global_index3(grid, 4, 3, k), 3); + rd_kw_iset_int(rd_kw, rd_grid_get_global_index3(grid, 5, 3, k), 4); + rd_kw_iset_int(rd_kw, rd_grid_get_global_index3(grid, 4, 2, k), 5); + fault_block_layer_load_kw(layer, rd_kw); { int_vector_type *neighbours = int_vector_alloc(0, 0); @@ -152,22 +152,21 @@ void test_neighbours(const ecl_grid_type *grid) { geo_polygon_collection_free(polylines); fault_block_layer_free(layer); - ecl_kw_free(ecl_kw); + rd_kw_free(rd_kw); } int main(int argc, char **argv) { - ecl_grid_type *ecl_grid = - ecl_grid_alloc_rectangular(9, 9, 2, 1, 1, 1, NULL); - ecl_kw_type *fault_blk_kw = - ecl_kw_alloc("FAULTBLK", ecl_grid_get_global_size(ecl_grid), ECL_INT); - - test_create(ecl_grid, fault_blk_kw); - test_create_invalid(ecl_grid); - test_trace_edge(ecl_grid); - test_export(ecl_grid); - test_neighbours(ecl_grid); - - ecl_grid_free(ecl_grid); - ecl_kw_free(fault_blk_kw); + rd_grid_type *rd_grid = rd_grid_alloc_rectangular(9, 9, 2, 1, 1, 1, NULL); + rd_kw_type *fault_blk_kw = + rd_kw_alloc("FAULTBLK", rd_grid_get_global_size(rd_grid), RD_INT); + + test_create(rd_grid, fault_blk_kw); + test_create_invalid(rd_grid); + test_trace_edge(rd_grid); + test_export(rd_grid); + test_neighbours(rd_grid); + + rd_grid_free(rd_grid); + rd_kw_free(fault_blk_kw); exit(0); } diff --git a/lib/ecl/tests/ecl_fault_block_layer_equinor.cpp b/lib/resdata/tests/rd_fault_block_layer_equinor.cpp similarity index 71% rename from lib/ecl/tests/ecl_fault_block_layer_equinor.cpp rename to lib/resdata/tests/rd_fault_block_layer_equinor.cpp index e5b95045b1..13afb72b1c 100644 --- a/lib/ecl/tests/ecl_fault_block_layer_equinor.cpp +++ b/lib/resdata/tests/rd_fault_block_layer_equinor.cpp @@ -4,17 +4,17 @@ #include -#include -#include -#include +#include +#include +#include -void test_create(const ecl_grid_type *grid, const ecl_kw_type *fault_block_kw) { +void test_create(const rd_grid_type *grid, const rd_kw_type *fault_block_kw) { test_assert_NULL(fault_block_layer_alloc(grid, -1)); - test_assert_NULL(fault_block_layer_alloc(grid, ecl_grid_get_nz(grid))); + test_assert_NULL(fault_block_layer_alloc(grid, rd_grid_get_nz(grid))); { int k; - for (k = 0; k < ecl_grid_get_nz(grid); k++) { + for (k = 0; k < rd_grid_get_nz(grid); k++) { fault_block_layer_type *layer = fault_block_layer_alloc(grid, k); test_assert_true(fault_block_layer_is_instance(layer)); @@ -52,18 +52,18 @@ void test_create(const ecl_grid_type *grid, const ecl_kw_type *fault_block_kw) { int main(int argc, char **argv) { const char *grid_file = argv[1]; const char *fault_blk_file = argv[2]; - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_file); - ecl_kw_type *fault_blk_kw; + rd_grid_type *rd_grid = rd_grid_alloc(grid_file); + rd_kw_type *fault_blk_kw; { FILE *stream = util_fopen(fault_blk_file, "r"); - fault_blk_kw = ecl_kw_fscanf_alloc_grdecl( - stream, "FAULTBLK", ecl_grid_get_global_size(ecl_grid), ECL_INT); + fault_blk_kw = rd_kw_fscanf_alloc_grdecl( + stream, "FAULTBLK", rd_grid_get_global_size(rd_grid), RD_INT); fclose(stream); } - test_create(ecl_grid, fault_blk_kw); + test_create(rd_grid, fault_blk_kw); - ecl_grid_free(ecl_grid); - ecl_kw_free(fault_blk_kw); + rd_grid_free(rd_grid); + rd_kw_free(fault_blk_kw); exit(0); } diff --git a/lib/resdata/tests/rd_file.cpp b/lib/resdata/tests/rd_file.cpp new file mode 100644 index 0000000000..bd60bbe6da --- /dev/null +++ b/lib/resdata/tests/rd_file.cpp @@ -0,0 +1,107 @@ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +void test_writable(size_t data_size) { + rd::util::TestArea ta("file_writable"); + const char *data_file_name = "test_file"; + + rd_kw_type *kw = rd_kw_alloc("TEST_KW", data_size, RD_INT); + for (size_t i = 0; i < data_size; ++i) + rd_kw_iset_int(kw, i, ((i * 37) + 11) % data_size); + + fortio_type *fortio = fortio_open_writer(data_file_name, false, true); + rd_kw_fwrite(kw, fortio); + fortio_fclose(fortio); + + for (int i = 0; i < 4; ++i) { + rd_file_type *rd_file = rd_file_open(data_file_name, RD_FILE_WRITABLE); + rd_kw_type *loaded_kw = + rd_file_view_iget_kw(rd_file_get_global_view(rd_file), 0); + test_assert_true(rd_kw_equal(kw, loaded_kw)); + + rd_file_save_kw(rd_file, loaded_kw); + rd_file_close(rd_file); + } + + rd_kw_free(kw); +} + +void test_truncated() { + rd::util::TestArea ta("truncate_file"); + int num_kw; + { + rd_grid_type *grid = + rd_grid_alloc_rectangular(20, 20, 20, 1, 1, 1, NULL); + rd_grid_fwrite_EGRID2(grid, "TEST.EGRID", RD_METRIC_UNITS); + rd_grid_free(grid); + } + { + rd_file_type *rd_file = rd_file_open("TEST.EGRID", 0); + test_assert_true(rd_file_is_instance(rd_file)); + num_kw = rd_file_get_size(rd_file); + test_assert_int_equal(rd_file_get_num_distinct_kw(rd_file), 11); + rd_file_close(rd_file); + } + + { + offset_type file_size = util_file_size("TEST.EGRID"); + FILE *stream = util_fopen("TEST.EGRID", "r+"); + util_ftruncate(stream, file_size / 2); + fclose(stream); + } + { + rd_file_type *rd_file = rd_file_open("TEST.EGRID", 0); + test_assert_true(rd_file_get_size(rd_file) < num_kw); + rd_file_close(rd_file); + } +} + +void test_mixed_case() { + rd::util::TestArea ta("mixed_case_file"); + int num_kw; + { + rd_grid_type *grid = + rd_grid_alloc_rectangular(20, 20, 20, 1, 1, 1, NULL); + rd_grid_fwrite_EGRID2(grid, "TESTcase.EGRID", RD_METRIC_UNITS); + rd_grid_free(grid); + } + { + rd_file_type *rd_file = rd_file_open("TESTcase.EGRID", 0); + test_assert_true(rd_file_is_instance(rd_file)); + num_kw = rd_file_get_size(rd_file); + test_assert_int_equal(rd_file_get_num_distinct_kw(rd_file), 11); + rd_file_close(rd_file); + } + + { + offset_type file_size = util_file_size("TESTcase.EGRID"); + FILE *stream = util_fopen("TESTcase.EGRID", "r+"); + util_ftruncate(stream, file_size / 2); + fclose(stream); + } + { + rd_file_type *rd_file = rd_file_open("TESTcase.EGRID", 0); + test_assert_true(rd_file_get_size(rd_file) < num_kw); + rd_file_close(rd_file); + } +} + +int main(int argc, char **argv) { + test_writable(10); + test_writable(1337); + test_truncated(); + test_mixed_case(); + exit(0); +} diff --git a/lib/resdata/tests/rd_file_equinor.cpp b/lib/resdata/tests/rd_file_equinor.cpp new file mode 100644 index 0000000000..ad890aaebc --- /dev/null +++ b/lib/resdata/tests/rd_file_equinor.cpp @@ -0,0 +1,123 @@ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +void test_flags(const char *filename) { + int FLAG1 = 1; + int FLAG2 = 2; + int FLAG3 = 4; + int FLAG4 = 8; + + int FLAGS = FLAG1 + FLAG2 + FLAG3; + + rd_file_type *rd_file = rd_file_open(filename, FLAGS); + + test_assert_int_equal(rd_file_get_flags(rd_file), FLAGS); + test_assert_true(rd_file_flags_set(rd_file, FLAG1)); + test_assert_true(rd_file_flags_set(rd_file, FLAG1 | FLAG2)); + test_assert_true(rd_file_flags_set(rd_file, FLAG1 | FLAG3)); + test_assert_true(rd_file_flags_set(rd_file, FLAG1 | FLAG3 | FLAG2)); + test_assert_false(rd_file_flags_set(rd_file, FLAG1 | FLAG3 | FLAG4)); + rd_file_close(rd_file); +} + +void test_close_stream2(const char *src_file, const char *target_file) { + util_copy_file(src_file, target_file); + rd_file_type *rd_file = rd_file_open(target_file, RD_FILE_CLOSE_STREAM); + + rd_file_load_all(rd_file); + unlink(target_file); + rd_kw_type *kw2 = rd_file_iget_kw(rd_file, 2); + test_assert_not_NULL(kw2); + rd_file_close(rd_file); +} + +void test_loadall(const char *src_file, const char *target_file) { + util_copy_file(src_file, target_file); + { + rd_file_type *rd_file = rd_file_open(target_file, RD_FILE_CLOSE_STREAM); + + test_assert_true(rd_file_load_all(rd_file)); + rd_file_close(rd_file); + } + + { + rd_file_type *rd_file = rd_file_open(target_file, RD_FILE_CLOSE_STREAM); + unlink(target_file); + + test_assert_false(rd_file_load_all(rd_file)); + rd_file_close(rd_file); + } +} + +void test_close_stream1(const char *src_file, const char *target_file) { + util_copy_file(src_file, target_file); + + rd_file_type *rd_file = rd_file_open(target_file, RD_FILE_CLOSE_STREAM); + rd_kw_type *kw0 = rd_file_iget_kw(rd_file, 0); + rd_kw_type *kw1 = rd_file_iget_kw(rd_file, 1); + unlink(target_file); + rd_kw_type *kw1b = rd_file_iget_kw(rd_file, 1); + + test_assert_not_NULL(kw0); + test_assert_not_NULL(kw1); + test_assert_ptr_equal(kw1, kw1b); + + rd_kw_type *kw2 = rd_file_iget_kw(rd_file, 2); + test_assert_NULL(kw2); + + test_assert_false(rd_file_writable(rd_file)); + + rd_file_close(rd_file); +} + +void test_writable(const char *src_file) { + rd::util::TestArea ta("file_writable"); + char *fname = util_split_alloc_filename(src_file); + + ta.copy_file(src_file); + { + test_flags(fname); + rd_file_type *rd_file = rd_file_open(fname, RD_FILE_WRITABLE); + rd_kw_type *swat = rd_file_iget_named_kw(rd_file, "SWAT", 0); + rd_kw_type *swat0 = rd_kw_alloc_copy(swat); + test_assert_true(rd_kw_equal(swat, swat0)); + rd_kw_iset_float(swat, 0, 1000.0); + rd_file_save_kw(rd_file, swat); + test_assert_true(rd_file_writable(rd_file)); + rd_file_close(rd_file); + + rd_file = rd_file_open(fname, 0); + swat = rd_file_iget_named_kw(rd_file, "SWAT", 0); + test_assert_true( + util_double_approx_equal(rd_kw_iget_float(swat, 0), 1000)); + } +} + +int main(int argc, char **argv) { + const char *src_file = argv[1]; + const char *target_file = argv[2]; + + { + rd::util::TestArea ta("file_equinor"); + + ta.copy_file(src_file); + test_loadall(src_file, target_file); + + test_close_stream1(src_file, target_file); + test_close_stream2(src_file, target_file); + test_writable(src_file); + } + exit(0); +} diff --git a/lib/resdata/tests/rd_file_view.cpp b/lib/resdata/tests/rd_file_view.cpp new file mode 100644 index 0000000000..02f0edb27b --- /dev/null +++ b/lib/resdata/tests/rd_file_view.cpp @@ -0,0 +1,102 @@ +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +void test_file_kw_equal() { + rd_file_kw_type *kw1 = rd_file_kw_alloc0("PRESSURE", RD_FLOAT, 1000, 66); + rd_file_kw_type *kw2 = rd_file_kw_alloc0("PRESSURE", RD_FLOAT, 1000, 66); + rd_file_kw_type *kw3 = rd_file_kw_alloc0("SWAT", RD_FLOAT, 1000, 66); + rd_file_kw_type *kw4 = rd_file_kw_alloc0("PRESSURE", RD_DOUBLE, 1000, 66); + rd_file_kw_type *kw5 = rd_file_kw_alloc0("PRESSURE", RD_FLOAT, 10, 66); + rd_file_kw_type *kw6 = rd_file_kw_alloc0("PRESSURE", RD_FLOAT, 1000, 67); + + test_assert_true(rd_file_kw_equal(kw1, kw1)); + test_assert_true(rd_file_kw_equal(kw1, kw2)); + test_assert_false(rd_file_kw_equal(kw1, kw3)); + test_assert_false(rd_file_kw_equal(kw1, kw4)); + test_assert_false(rd_file_kw_equal(kw1, kw5)); + test_assert_false(rd_file_kw_equal(kw1, kw6)); + + rd_file_kw_free(kw6); + rd_file_kw_free(kw5); + rd_file_kw_free(kw4); + rd_file_kw_free(kw3); + rd_file_kw_free(kw2); + rd_file_kw_free(kw1); +} + +void test_create_file_kw() { + rd_file_kw_type *file_kw0 = + rd_file_kw_alloc0("PRESSURE", RD_FLOAT, 1000, 66); + rd_file_kw_type *file_kw1 = + rd_file_kw_alloc0("TEST1_KW", RD_FLOAT, 2000, 1066); + rd_file_kw_type *file_kw2 = + rd_file_kw_alloc0("TEST2_KW", RD_FLOAT, 3000, 2066); + test_assert_string_equal(rd_file_kw_get_header(file_kw0), "PRESSURE"); + test_assert_int_equal(rd_file_kw_get_size(file_kw0), 1000); + test_assert_true( + rd_type_is_equal(rd_file_kw_get_data_type(file_kw0), RD_FLOAT)); + { + rd::util::TestArea ta("file_kw"); + { + FILE *ostream = util_fopen("file_kw", "w"); + rd_file_kw_fwrite(file_kw0, ostream); + fclose(ostream); + } + { + FILE *istream = util_fopen("file_kw", "r"); + rd_file_kw_type *disk_kw = rd_file_kw_fread_alloc(istream); + test_assert_true(rd_file_kw_equal(file_kw0, disk_kw)); + + /* Beyond the end of stream - return NULL */ + test_assert_NULL(rd_file_kw_fread_alloc(istream)); + rd_file_kw_free(disk_kw); + fclose(istream); + } + + { + FILE *ostream = util_fopen("file_kw", "w"); + rd_file_kw_fwrite(file_kw0, ostream); + rd_file_kw_fwrite(file_kw1, ostream); + rd_file_kw_fwrite(file_kw2, ostream); + fclose(ostream); + } + + { + FILE *istream = util_fopen("file_kw", "r"); + rd_file_kw_type **disk_kw = + rd_file_kw_fread_alloc_multiple(istream, 3); + test_assert_true(rd_file_kw_equal(file_kw0, disk_kw[0])); + test_assert_true(rd_file_kw_equal(file_kw1, disk_kw[1])); + test_assert_true(rd_file_kw_equal(file_kw2, disk_kw[2])); + + for (int i = 0; i < 3; i++) + rd_file_kw_free(disk_kw[i]); + free(disk_kw); + fclose(istream); + } + { + FILE *istream = util_fopen("file_kw", "r"); + test_assert_NULL(rd_file_kw_fread_alloc_multiple(istream, 10)); + fclose(istream); + } + } + rd_file_kw_free(file_kw0); + rd_file_kw_free(file_kw1); + rd_file_kw_free(file_kw2); +} + +int main(int argc, char **argv) { + util_install_signals(); + test_file_kw_equal(); + test_create_file_kw(); +} diff --git a/lib/ecl/tests/ecl_util_filenames.cpp b/lib/resdata/tests/rd_filenames.cpp similarity index 58% rename from lib/ecl/tests/ecl_util_filenames.cpp rename to lib/resdata/tests/rd_filenames.cpp index 0570a0962f..1311f5581e 100644 --- a/lib/ecl/tests/ecl_util_filenames.cpp +++ b/lib/resdata/tests/rd_filenames.cpp @@ -6,28 +6,23 @@ #include #include -#include +#include void test_filename_report_nr() { test_assert_int_equal( - 78, ecl_util_filename_report_nr("Path/with/mixedCASE/case.x0078")); - test_assert_int_equal(78, ecl_util_filename_report_nr("Case.X0078")); + 78, rd_filename_report_nr("Path/with/mixedCASE/case.x0078")); + test_assert_int_equal(78, rd_filename_report_nr("Case.X0078")); test_assert_int_equal( - ECL_EGRID_FILE, - ecl_util_get_file_type("path/WITH/xase/MyGrid.EGrid", NULL, NULL)); + RD_EGRID_FILE, + rd_get_file_type("path/WITH/xase/MyGrid.EGrid", NULL, NULL)); } void test_filename_case() { - char *f1 = - ecl_util_alloc_filename(NULL, "mixedBase", ECL_EGRID_FILE, false, -1); - char *f2 = - ecl_util_alloc_filename(NULL, "UPPER", ECL_EGRID_FILE, false, -1); - char *f3 = - ecl_util_alloc_filename(NULL, "lower", ECL_EGRID_FILE, false, -1); - char *f4 = - ecl_util_alloc_filename(NULL, "lower1", ECL_EGRID_FILE, false, -1); - char *f5 = - ecl_util_alloc_filename(NULL, "UPPER1", ECL_EGRID_FILE, false, -1); + char *f1 = rd_alloc_filename(NULL, "mixedBase", RD_EGRID_FILE, false, -1); + char *f2 = rd_alloc_filename(NULL, "UPPER", RD_EGRID_FILE, false, -1); + char *f3 = rd_alloc_filename(NULL, "lower", RD_EGRID_FILE, false, -1); + char *f4 = rd_alloc_filename(NULL, "lower1", RD_EGRID_FILE, false, -1); + char *f5 = rd_alloc_filename(NULL, "UPPER1", RD_EGRID_FILE, false, -1); test_assert_string_equal(f1, "mixedBase.EGRID"); test_assert_string_equal(f2, "UPPER.EGRID"); @@ -43,12 +38,11 @@ void test_filename_case() { } void test_file_list() { - ecl::util::TestArea ta("file_list"); + rd::util::TestArea ta("file_list"); stringlist_type *s = stringlist_alloc_new(); for (int i = 0; i < 10; i += 2) { - char *fname = - ecl_util_alloc_filename(NULL, "case", ECL_RESTART_FILE, true, i); + char *fname = rd_alloc_filename(NULL, "case", RD_RESTART_FILE, true, i); FILE *stream = util_fopen(fname, "w"); fclose(stream); free(fname); @@ -68,26 +62,26 @@ void test_file_list() { free(fname); } - ecl_util_select_filelist(NULL, "case", ECL_RESTART_FILE, true, s); + rd_select_filelist(NULL, "case", RD_RESTART_FILE, true, s); test_assert_int_equal(stringlist_get_size(s), 5); for (int i = 0; i < 5; i++) { - char *fname = ecl_util_alloc_filename(NULL, "case", ECL_RESTART_FILE, - true, 2 * i); + char *fname = + rd_alloc_filename(NULL, "case", RD_RESTART_FILE, true, 2 * i); test_assert_string_equal(fname, stringlist_iget(s, i)); free(fname); } - ecl_util_select_filelist(NULL, "CaseMiXed", ECL_RESTART_FILE, true, s); + rd_select_filelist(NULL, "CaseMiXed", RD_RESTART_FILE, true, s); test_assert_int_equal(stringlist_get_size(s), 5); util_make_path("path"); for (int i = 0; i < 10; i++) { - char *summary_file1 = ecl_util_alloc_filename( - "path", "CASE1", ECL_SUMMARY_FILE, false, i); + char *summary_file1 = + rd_alloc_filename("path", "CASE1", RD_SUMMARY_FILE, false, i); char *summary_file2 = - ecl_util_alloc_filename("path", "CASE2", ECL_SUMMARY_FILE, true, i); - char *restart_file1 = ecl_util_alloc_filename( - "path", "CASE1", ECL_RESTART_FILE, false, i); + rd_alloc_filename("path", "CASE2", RD_SUMMARY_FILE, true, i); + char *restart_file1 = + rd_alloc_filename("path", "CASE1", RD_RESTART_FILE, false, i); FILE *f1 = fopen(summary_file1, "w"); fclose(f1); @@ -104,22 +98,22 @@ void test_file_list() { } printf( "-----------------------------------------------------------------\n"); - ecl_util_select_filelist(NULL, "path/CASE1", ECL_SUMMARY_FILE, false, s); + rd_select_filelist(NULL, "path/CASE1", RD_SUMMARY_FILE, false, s); test_assert_int_equal(stringlist_get_size(s), 10); - ecl_util_select_filelist(NULL, "path/CASE1", ECL_SUMMARY_FILE, true, s); + rd_select_filelist(NULL, "path/CASE1", RD_SUMMARY_FILE, true, s); test_assert_int_equal(stringlist_get_size(s), 0); - ecl_util_select_filelist(NULL, "path/CASE2", ECL_SUMMARY_FILE, true, s); + rd_select_filelist(NULL, "path/CASE2", RD_SUMMARY_FILE, true, s); test_assert_int_equal(stringlist_get_size(s), 10); - ecl_util_select_filelist("path", "CASE1", ECL_SUMMARY_FILE, false, s); + rd_select_filelist("path", "CASE1", RD_SUMMARY_FILE, false, s); test_assert_int_equal(stringlist_get_size(s), 10); - ecl_util_select_filelist("path", "CASE1", ECL_SUMMARY_FILE, true, s); + rd_select_filelist("path", "CASE1", RD_SUMMARY_FILE, true, s); test_assert_int_equal(stringlist_get_size(s), 0); - ecl_util_select_filelist("path", "CASE2", ECL_SUMMARY_FILE, true, s); + rd_select_filelist("path", "CASE2", RD_SUMMARY_FILE, true, s); test_assert_int_equal(stringlist_get_size(s), 10); stringlist_free(s); diff --git a/lib/ecl/tests/ecl_fmt.cpp b/lib/resdata/tests/rd_fmt.cpp similarity index 66% rename from lib/ecl/tests/ecl_fmt.cpp rename to lib/resdata/tests/rd_fmt.cpp index 15367b0969..adb16b5a33 100644 --- a/lib/ecl/tests/ecl_fmt.cpp +++ b/lib/resdata/tests/rd_fmt.cpp @@ -6,9 +6,9 @@ #include #include -#include +#include -void test_content(const ecl::util::TestArea &ta, const char *src_file, +void test_content(const rd::util::TestArea &ta, const char *src_file, bool fmt_file) { ta.copy_file(src_file); { @@ -21,7 +21,7 @@ void test_content(const ecl::util::TestArea &ta, const char *src_file, util_copy_file(file_name, base_name); - test_assert_true(ecl_util_fmt_file(base_name, &fmt)); + test_assert_true(rd_fmt_file(base_name, &fmt)); test_assert_bool_equal(fmt, fmt_file); free(file_name); @@ -37,30 +37,30 @@ void test_small() { fprintf(stream, "Some bytes\n"); fclose(stream); - test_assert_false(ecl_util_fmt_file("small.txt", &fmt)); + test_assert_false(rd_fmt_file("small.txt", &fmt)); } int main(int argc, char **argv) { - ecl::util::TestArea ta("ecl_fmt"); + rd::util::TestArea ta("rd_fmt"); { const char *binary_file = argv[1]; const char *text_file = argv[2]; bool fmt_file; - test_assert_true(ecl_util_fmt_file(binary_file, &fmt_file)); + test_assert_true(rd_fmt_file(binary_file, &fmt_file)); test_assert_false(fmt_file); - test_assert_true(ecl_util_fmt_file(text_file, &fmt_file)); + test_assert_true(rd_fmt_file(text_file, &fmt_file)); test_assert_true(fmt_file); - test_assert_true(ecl_util_fmt_file("TEST.EGRID", &fmt_file)); + test_assert_true(rd_fmt_file("TEST.EGRID", &fmt_file)); test_assert_false(fmt_file); - test_assert_true(ecl_util_fmt_file("TEST.FEGRID", &fmt_file)); + test_assert_true(rd_fmt_file("TEST.FEGRID", &fmt_file)); test_assert_true(fmt_file); - test_assert_false(ecl_util_fmt_file("TEST_DOES_NOT_EXIST", &fmt_file)); + test_assert_false(rd_fmt_file("TEST_DOES_NOT_EXIST", &fmt_file)); test_content(ta, binary_file, false); test_content(ta, text_file, true); diff --git a/lib/ecl/tests/ecl_fortio.cpp b/lib/resdata/tests/rd_fortio.cpp similarity index 89% rename from lib/ecl/tests/ecl_fortio.cpp rename to lib/resdata/tests/rd_fortio.cpp index ac8a59b6cd..94185a0b6a 100644 --- a/lib/ecl/tests/ecl_fortio.cpp +++ b/lib/resdata/tests/rd_fortio.cpp @@ -6,11 +6,11 @@ #include #include -#include -#include +#include +#include void test_existing_read(const char *filename) { - fortio_type *fortio = fortio_open_reader(filename, false, ECL_ENDIAN_FLIP); + fortio_type *fortio = fortio_open_reader(filename, false, RD_ENDIAN_FLIP); test_assert_not_NULL(fortio); fortio_fclose(fortio); } @@ -18,7 +18,7 @@ void test_existing_read(const char *filename) { void test_fortio_is_instance(const char *filename) { { fortio_type *fortio = - fortio_open_reader(filename, false, ECL_ENDIAN_FLIP); + fortio_open_reader(filename, false, RD_ENDIAN_FLIP); test_assert_not_NULL(fortio); test_assert_true(fortio_is_instance(fortio)); fortio_fclose(fortio); @@ -31,7 +31,7 @@ void test_fortio_is_instance(const char *filename) { } void test_fortio_safe_cast(const char *filename) { - void *i_am_a_fortio = fortio_open_reader(filename, false, ECL_ENDIAN_FLIP); + void *i_am_a_fortio = fortio_open_reader(filename, false, RD_ENDIAN_FLIP); test_assert_not_NULL(i_am_a_fortio); fortio_type *fortio = fortio_safe_cast(i_am_a_fortio); test_assert_true(fortio_is_instance(fortio)); @@ -46,12 +46,12 @@ void test_fortio_unsafe_cast(void *arg) { void test_not_existing_read() { fortio_type *fortio = - fortio_open_reader("/does/not/exist", false, ECL_ENDIAN_FLIP); + fortio_open_reader("/does/not/exist", false, RD_ENDIAN_FLIP); test_assert_NULL(fortio); } void test_write(const char *filename, bool path_exists) { - fortio_type *fortio = fortio_open_writer(filename, false, ECL_ENDIAN_FLIP); + fortio_type *fortio = fortio_open_writer(filename, false, RD_ENDIAN_FLIP); if (path_exists) { test_assert_not_NULL(fortio); fortio_fclose(fortio); @@ -74,7 +74,7 @@ void test_wrapper(const char *filename) { } void test_open_close_read(const char *filename) { - fortio_type *fortio = fortio_open_reader(filename, false, ECL_ENDIAN_FLIP); + fortio_type *fortio = fortio_open_reader(filename, false, RD_ENDIAN_FLIP); test_assert_not_NULL(fortio); test_assert_true(fortio_stream_is_open(fortio)); @@ -89,7 +89,7 @@ void test_open_close_read(const char *filename) { } void test_fread_truncated_data() { - ecl::util::TestArea work_area("fortio_truncated"); + rd::util::TestArea work_area("fortio_truncated"); { const size_t buffer_size = 1000; char *buffer = (char *)util_malloc(buffer_size); @@ -118,7 +118,7 @@ void test_fread_truncated_data() { } void test_fread_truncated_head() { - ecl::util::TestArea work_area("fortio_truncated"); + rd::util::TestArea work_area("fortio_truncated"); { { FILE *stream = util_fopen("PRESSURE", "w"); @@ -137,7 +137,7 @@ void test_fread_truncated_head() { } void test_fread_truncated_tail() { - ecl::util::TestArea work_area("fortio_truncated3"); + rd::util::TestArea work_area("fortio_truncated3"); { const size_t buffer_size = 1000; char *buffer = (char *)util_malloc(buffer_size); @@ -162,7 +162,7 @@ void test_fread_truncated_tail() { } void test_fread_invalid_tail() { - ecl::util::TestArea work_area("fortio_invalid"); + rd::util::TestArea work_area("fortio_invalid"); int record_size = 10; char *buffer = (char *)util_malloc(record_size); { @@ -191,7 +191,7 @@ void test_fread_invalid_tail() { } void test_at_eof() { - ecl::util::TestArea work_area("fortio_truncated3"); + rd::util::TestArea work_area("fortio_truncated3"); { fortio_type *fortio = fortio_open_writer("PRESSURE", false, true); char *buffer = (char *)util_malloc(100); @@ -215,7 +215,7 @@ void test_at_eof() { } void test_fseek() { - ecl::util::TestArea work_area("fortio_fseek"); + rd::util::TestArea work_area("fortio_fseek"); { fortio_type *fortio = fortio_open_writer("PRESSURE", false, true); char *buffer = (char *)util_malloc(100); @@ -238,7 +238,7 @@ void test_fseek() { } void test_write_failure() { - ecl::util::TestArea work_area("fortio_truncated"); + rd::util::TestArea work_area("fortio_truncated"); { fortio_type *fortio = fortio_open_writer("PRESSURE", false, true); char *buffer = (char *)util_malloc(100); @@ -276,7 +276,7 @@ int main(int argc, char **argv) { test_write("/tmp/path/does/not/exist", false); { - ecl::util::TestArea work_area("ecl_fortio_write"); + rd::util::TestArea work_area("rd_fortio_write"); util_make_path("path"); test_write("path/file.x", true); } diff --git a/lib/resdata/tests/rd_get_num_cpu_test.cpp b/lib/resdata/tests/rd_get_num_cpu_test.cpp new file mode 100644 index 0000000000..deef44d2bb --- /dev/null +++ b/lib/resdata/tests/rd_get_num_cpu_test.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include +#include + +int main(int argc, char **argv) { + const char *filename1 = argv[1]; + const char *filename2 = argv[2]; + const char *filename3 = argv[3]; + const char *filename4 = argv[4]; + const char *filename5 = argv[5]; + + test_assert_int_equal(rd_get_num_cpu(filename1), 4); + test_assert_int_equal(rd_get_num_cpu(filename2), 4); + test_assert_int_equal(rd_get_num_cpu(filename3), 15); + test_assert_int_equal(rd_get_num_cpu(filename4), 4); + test_assert_int_equal(rd_get_num_cpu(filename5), 4); + exit(0); +} diff --git a/lib/resdata/tests/rd_grid_add_nnc.cpp b/lib/resdata/tests/rd_grid_add_nnc.cpp new file mode 100644 index 0000000000..37cf773f6e --- /dev/null +++ b/lib/resdata/tests/rd_grid_add_nnc.cpp @@ -0,0 +1,119 @@ +#include +#include + +#include +#include +#include + +#include + +void verify_simple_nnc(const rd_grid_type *grid) { + test_assert_not_NULL(rd_grid_get_cell_nnc_info1(grid, 5)); + test_assert_not_NULL(rd_grid_get_cell_nnc_info1(grid, 8)); + + // Cell 5: + { + const nnc_info_type *nnc_info = rd_grid_get_cell_nnc_info1(grid, 5); + const nnc_vector_type *nnc_vector = nnc_info_iget_vector(nnc_info, 0); + test_assert_int_equal(2, nnc_vector_get_size(nnc_vector)); + test_assert_int_equal(6, nnc_vector_iget_grid_index(nnc_vector, 0)); + test_assert_int_equal(7, nnc_vector_iget_grid_index(nnc_vector, 1)); + + test_assert_int_equal(0, nnc_vector_iget_nnc_index(nnc_vector, 0)); + test_assert_int_equal(1, nnc_vector_iget_nnc_index(nnc_vector, 1)); + } + + // Cell 8: + { + const nnc_info_type *nnc_info = rd_grid_get_cell_nnc_info1(grid, 8); + const nnc_vector_type *nnc_vector = nnc_info_iget_vector(nnc_info, 0); + test_assert_int_equal(1, nnc_vector_get_size(nnc_vector)); + test_assert_int_equal(9, nnc_vector_iget_grid_index(nnc_vector, 0)); + test_assert_int_equal(2, nnc_vector_iget_nnc_index(nnc_vector, 0)); + } +} + +void simple_test() { + rd_grid_type *grid0 = rd_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); + rd_grid_add_self_nnc(grid0, 5, 6, 0); + rd_grid_add_self_nnc(grid0, 5, 7, 1); + rd_grid_add_self_nnc(grid0, 8, 9, 2); + + verify_simple_nnc(grid0); + { + rd::util::TestArea ta("simple_nnc"); + rd_grid_type *grid1; + rd_grid_fwrite_EGRID2(grid0, "TEST.EGRID", RD_METRIC_UNITS); + grid1 = rd_grid_alloc("TEST.EGRID"); + + verify_simple_nnc(grid1); + rd_grid_free(grid1); + } + rd_grid_free(grid0); +} + +void overwrite_test() { + rd_grid_type *grid0 = rd_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); + + /* + This first list of nnc will be overwritten, and will not survive + the serialization to disk. + */ + + rd_grid_add_self_nnc(grid0, 1, 2, 0); + rd_grid_add_self_nnc(grid0, 1, 3, 1); + rd_grid_add_self_nnc(grid0, 1, 4, 2); + + rd_grid_add_self_nnc(grid0, 5, 6, 0); + rd_grid_add_self_nnc(grid0, 5, 7, 1); + rd_grid_add_self_nnc(grid0, 8, 9, 2); + + verify_simple_nnc(grid0); + { + rd::util::TestArea ta("overwrite"); + rd_grid_type *grid1; + rd_grid_fwrite_EGRID2(grid0, "TEST.EGRID", RD_METRIC_UNITS); + grid1 = rd_grid_alloc("TEST.EGRID"); + + verify_simple_nnc(grid1); + rd_grid_free(grid1); + } + rd_grid_free(grid0); +} + +void list_test() { + rd_grid_type *grid0 = rd_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); + int_vector_type *g1 = int_vector_alloc(0, 0); + int_vector_type *g2 = int_vector_alloc(0, 0); + + int_vector_append(g1, 5); + int_vector_append(g2, 6); + int_vector_append(g1, 5); + int_vector_append(g2, 7); + int_vector_append(g1, 8); + int_vector_append(g2, 9); + + rd_grid_add_self_nnc_list(grid0, int_vector_get_ptr(g1), + int_vector_get_ptr(g2), int_vector_size(g1)); + + verify_simple_nnc(grid0); + { + rd::util::TestArea ta("list_test"); + rd_grid_type *grid1; + rd_grid_fwrite_EGRID2(grid0, "TEST.EGRID", RD_METRIC_UNITS); + grid1 = rd_grid_alloc("TEST.EGRID"); + + verify_simple_nnc(grid1); + rd_grid_free(grid1); + } + int_vector_free(g1); + int_vector_free(g2); + rd_grid_free(grid0); +} + +int main(int argc, char **argv) { + simple_test(); + list_test(); + overwrite_test(); + exit(0); +} diff --git a/lib/resdata/tests/rd_grid_cell_contains.cpp b/lib/resdata/tests/rd_grid_cell_contains.cpp new file mode 100644 index 0000000000..0cd154cec5 --- /dev/null +++ b/lib/resdata/tests/rd_grid_cell_contains.cpp @@ -0,0 +1,279 @@ +#include +#include +#include + +#include +#include + +bool get_test_point1(const rd_grid_type *grid, int global_index, double *_xpos, + double *_ypos, double *_zpos) { + const int corners[4] = {1, 2, 5, 6}; + double xpos = 0; + double ypos = 0; + double zpos = 0; + const double min_volume = 1e-8; + + if (fabs(rd_grid_get_cell_volume1(grid, global_index)) <= min_volume) + return false; + + if (rd_grid_get_cell_twist1(grid, global_index) > 0) + return false; + + if (!rd_grid_cell_regular1(grid, global_index)) + return false; + + for (int ci = 0; ci < 4; ci++) { + int corner = corners[ci]; + double x, y, z; + rd_grid_get_cell_corner_xyz1(grid, global_index, corner, &x, &y, &z); + xpos += x; + ypos += y; + zpos += z; + } + + *_xpos = xpos * 0.25; + *_ypos = ypos * 0.25; + *_zpos = zpos * 0.25; + + return rd_grid_cell_contains_xyz1(grid, global_index, *_xpos, *_ypos, + *_zpos); +} + +bool get_test_point3(const rd_grid_type *grid, int i, int j, int k, + double *_xpos, double *_ypos, double *_zpos) { + const int global_index = rd_grid_get_global_index3(grid, i, j, k); + return get_test_point1(grid, global_index, _xpos, _ypos, _zpos); +} + +void test_grid_covering(const rd_grid_type *grid) { + const int nx = rd_grid_get_nx(grid); + const int ny = rd_grid_get_ny(grid); + const int nz = rd_grid_get_nz(grid); + + for (int k = 0; k < nz - 1; k++) { + for (int j = 0; j < ny; j++) { + for (int i = 0; i < nx; i++) { + int g1 = rd_grid_get_global_index3(grid, i, j, k); + int g2 = rd_grid_get_global_index3(grid, i, j, k + 1); + double p1[3]; + double p2[3]; + + for (int l = 0; l < 4; l++) { + rd_grid_get_cell_corner_xyz1(grid, g1, l + 4, &p1[0], + &p1[1], &p1[2]); + rd_grid_get_cell_corner_xyz1(grid, g2, l, &p2[0], &p2[1], + &p2[2]); + test_assert_true(p1[0] == p2[0]); + test_assert_true(p1[1] == p2[1]); + test_assert_true(p1[2] == p2[2]); + } + + for (int l = 0; l < 4; l++) { + rd_grid_get_cell_corner_xyz1(grid, g1, l, &p1[0], &p1[1], + &p1[2]); + rd_grid_get_cell_corner_xyz1(grid, g1, l + 4, &p2[0], + &p2[1], &p2[2]); + + test_assert_true(p2[2] >= p1[2]); + } + } + } + } +} + +void assert_contains(const rd_grid_type *grid, int i, int j, int k, double x, + double y, double z) { + if (!rd_grid_cell_contains_xyz3(grid, i, j, k, x, y, z)) + fprintf(stderr, " Point: (%g,%g,%g) not found in cell: (%d,%d,%d) \n", + x, y, z, i, j, k); + + test_assert_true(rd_grid_cell_contains_xyz3(grid, i, j, k, x, y, z)); +} + +void test_contains(const rd_grid_type *grid) { + const int nx = rd_grid_get_nx(grid); + const int ny = rd_grid_get_ny(grid); + const int nz = rd_grid_get_nz(grid); + + for (int k = 0; k < nz; k++) { + for (int j = 0; j < ny; j++) { + for (int i = 0; i < nx; i++) { + if (rd_grid_get_cell_twist3(grid, i, j, k) != 0) { + double x, y, z; + if (get_test_point3(grid, i, j, k, &x, &y, &z)) { + assert_contains(grid, i, j, k, x, y, z); + { + int i2, j2, k2; + int kmin = util_int_max(0, k - 1); + int kmax = util_int_min(nz, k + 1); + + int jmin = util_int_max(0, j - 1); + int jmax = util_int_min(ny, j + 1); + + int imin = util_int_max(0, i - 1); + int imax = util_int_min(nx, i + 1); + + for (k2 = kmin; k2 < kmax; k2++) { + for (j2 = jmin; j2 < jmax; j2++) { + for (i2 = imin; i2 < imax; i2++) { + if ((i != i2) && (j != j2) && + (k != k2)) { + if (rd_grid_get_cell_twist3( + grid, i2, j2, k2) == 0) + test_assert_false( + rd_grid_cell_contains_xyz3( + grid, i2, j2, k2, x, y, + z)); + } + } + } + } + } + } + } + } + } + } +} + +void test_find(rd_grid_type *grid) { + int init_index; + int find_count = 100; + int delta = util_int_max(1, rd_grid_get_global_size(grid) / find_count); + for (init_index = 0; init_index < rd_grid_get_global_size(grid); + init_index += delta) { + if (rd_grid_get_cell_twist1(grid, init_index) == 0) { + double x, y, z; + int find_index; + int start_index = 0; + + if (get_test_point1(grid, init_index, &x, &y, &z)) { + find_index = rd_grid_get_global_index_from_xyz(grid, x, y, z, + start_index); + if (init_index != find_index) { + int i1, j1, k1, i2, j2, k2; + + rd_grid_get_ijk1(grid, init_index, &i1, &j1, &k1); + rd_grid_get_ijk1(grid, find_index, &i2, &j2, &k2); + printf(" point: %14.7f %14.7f %14.7f \n", x, y, z); + printf(" Regular: %d / %d \n", + rd_grid_cell_regular3(grid, i1, j1, k1), + rd_grid_cell_regular3(grid, i2, j2, k2)); + printf( + " init: contains(%7d) : %d (%d,%d,%d) V:%g \n", + init_index, + rd_grid_cell_contains_xyz1(grid, init_index, x, y, z), + i1 + 1, j1 + 1, k1 + 1, + rd_grid_get_cell_volume1(grid, init_index)); + printf( + "ERROR: find: contains(%7d) : %d (%d,%d,%d) V:%g " + "\n\n", + find_index, + rd_grid_cell_contains_xyz1(grid, find_index, x, y, z), + i2 + 1, j2 + 1, k2 + 1, + rd_grid_get_cell_volume1(grid, find_index)); + test_assert_int_equal(init_index, find_index); + } + } + } + } +} + +void test_corners() { + rd_grid_type *grid = rd_grid_alloc_rectangular(3, 3, 3, 1, 1, 1, NULL); + + test_assert_int_equal( + -1, rd_grid_get_global_index_from_xyz(grid, -1, -1, -1, 0)); + test_assert_int_equal(-1, + rd_grid_get_global_index_from_xyz(grid, -1, 1, 1, 0)); + test_assert_int_equal(-1, + rd_grid_get_global_index_from_xyz(grid, 1, -1, 1, 0)); + test_assert_int_equal(-1, + rd_grid_get_global_index_from_xyz(grid, 1, 1, -1, 0)); + + test_assert_int_equal( + -1, rd_grid_get_global_index_from_xyz(grid, 3.5, 3.5, 3.5, 0)); + test_assert_int_equal( + -1, rd_grid_get_global_index_from_xyz(grid, 3.5, 1, 1, 0)); + test_assert_int_equal( + -1, rd_grid_get_global_index_from_xyz(grid, 1, 3.5, 1, 0)); + test_assert_int_equal( + -1, rd_grid_get_global_index_from_xyz(grid, 1, 1, 3.5, 0)); + + { + double x, y, z; + int i; + rd_grid_get_cell_corner_xyz3(grid, 0, 0, 0, 0, &x, &y, &z); + test_assert_int_equal( + 0, rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + for (i = 1; i < 8; i++) { + rd_grid_get_cell_corner_xyz3(grid, 0, 0, 0, i, &x, &y, &z); + test_assert_int_not_equal( + 0, rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + } + + // Corner 1 + rd_grid_get_cell_corner_xyz3(grid, 2, 0, 0, 1, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 2, 0, 0), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + // Corner 2 + rd_grid_get_cell_corner_xyz3(grid, 0, 2, 0, 2, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 0, 2, 0), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + // Corner 3 + rd_grid_get_cell_corner_xyz3(grid, 2, 2, 0, 3, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 2, 2, 0), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + // Corner 4 + rd_grid_get_cell_corner_xyz3(grid, 0, 0, 2, 4, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 0, 0, 2), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + // Corner 5 + rd_grid_get_cell_corner_xyz3(grid, 2, 0, 2, 5, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 2, 0, 2), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + // Corner 6 + rd_grid_get_cell_corner_xyz3(grid, 0, 2, 2, 6, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 0, 2, 2), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + + // Corner 7 + rd_grid_get_cell_corner_xyz3(grid, 2, 2, 2, 7, &x, &y, &z); + test_assert_int_equal( + rd_grid_get_global_index3(grid, 2, 2, 2), + rd_grid_get_global_index_from_xyz(grid, x, y, z, 0)); + } + + rd_grid_free(grid); +} + +int main(int argc, char **argv) { + rd_grid_type *grid; + + util_install_signals(); + + if (argc == 1) { + grid = rd_grid_alloc_rectangular(6, 6, 6, 1, 2, 3, NULL); + } else + grid = rd_grid_alloc(argv[1]); + + test_grid_covering(grid); + test_contains(grid); + + test_find(grid); + test_corners(); + rd_grid_free(grid); + exit(0); +} diff --git a/lib/ecl/tests/ecl_grid_cell_contains_wellpath.cpp b/lib/resdata/tests/rd_grid_cell_contains_wellpath.cpp similarity index 62% rename from lib/ecl/tests/ecl_grid_cell_contains_wellpath.cpp rename to lib/resdata/tests/rd_grid_cell_contains_wellpath.cpp index 58188ba23c..83a13de868 100644 --- a/lib/ecl/tests/ecl_grid_cell_contains_wellpath.cpp +++ b/lib/resdata/tests/rd_grid_cell_contains_wellpath.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include typedef struct { @@ -19,7 +19,7 @@ typedef struct { bool skip; } point_type; -vector_type *load_expected(const ecl_grid_type *grid, const char *filename) { +vector_type *load_expected(const rd_grid_type *grid, const char *filename) { FILE *stream = util_fopen(filename, "r"); vector_type *expected = vector_alloc_new(); @@ -38,7 +38,7 @@ vector_type *load_expected(const ecl_grid_type *grid, const char *filename) { p->j = j - 1; p->k = k - 1; p->skip = skip; - p->g = ecl_grid_get_global_index3(grid, p->i, p->j, p->k); + p->g = rd_grid_get_global_index3(grid, p->i, p->j, p->k); vector_append_owned_ref(expected, p, free); } else break; @@ -49,28 +49,28 @@ vector_type *load_expected(const ecl_grid_type *grid, const char *filename) { return expected; } -void test_well_point(ecl_grid_type *grid, const point_type *expected) { - int g = ecl_grid_get_global_index_from_xyz(grid, expected->x, expected->y, - expected->z, 0); - if (g != ecl_grid_get_global_index3(grid, expected->i, expected->j, - expected->k)) { +void test_well_point(rd_grid_type *grid, const point_type *expected) { + int g = rd_grid_get_global_index_from_xyz(grid, expected->x, expected->y, + expected->z, 0); + if (g != rd_grid_get_global_index3(grid, expected->i, expected->j, + expected->k)) { int i, j, k; - ecl_grid_get_ijk1(grid, g, &i, &j, &k); - bool g_contains_xyz = ecl_grid_cell_contains_xyz1( + rd_grid_get_ijk1(grid, g, &i, &j, &k); + bool g_contains_xyz = rd_grid_cell_contains_xyz1( grid, expected->g, expected->x, expected->y, expected->z); fprintf(stderr, - "(%g,%g,%g) differs: EclGrid: %d:(%d,%d,%d) Expected: " + "(%g,%g,%g) differs: Grid: %d:(%d,%d,%d) Expected: " "%d:(%d,%d,%d) contains:%d\n", expected->x, expected->y, expected->z, g, i, j, k, expected->g, expected->i, expected->j, expected->k, g_contains_xyz); } if (!expected->skip) - test_assert_int_equal(g, ecl_grid_get_global_index3(grid, expected->i, - expected->j, - expected->k)); + test_assert_int_equal(g, rd_grid_get_global_index3(grid, expected->i, + expected->j, + expected->k)); else { - if (g != ecl_grid_get_global_index3(grid, expected->i, expected->j, - expected->k)) + if (g != rd_grid_get_global_index3(grid, expected->i, expected->j, + expected->k)) fprintf(stderr, " ** Skipping failed test for point: %g %g %g \n", expected->x, expected->y, expected->z); } @@ -79,7 +79,7 @@ void test_well_point(ecl_grid_type *grid, const point_type *expected) { int main(int argc, char **argv) { util_install_signals(); { - ecl_grid_type *grid = ecl_grid_alloc(argv[1]); + rd_grid_type *grid = rd_grid_alloc(argv[1]); vector_type *expected = load_expected(grid, argv[2]); for (int c = 0; c < vector_get_size(expected); c++) { @@ -87,7 +87,7 @@ int main(int argc, char **argv) { (const point_type *)vector_iget_const(expected, c); test_well_point(grid, p); } - ecl_grid_free(grid); + rd_grid_free(grid); vector_free(expected); } exit(0); diff --git a/lib/resdata/tests/rd_grid_copy.cpp b/lib/resdata/tests/rd_grid_copy.cpp new file mode 100644 index 0000000000..c96349ca71 --- /dev/null +++ b/lib/resdata/tests/rd_grid_copy.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include +#include +#include + +#include + +void test_copy_grid(const rd_grid_type *grid) { + rd_grid_type *grid_copy = rd_grid_alloc_copy(grid); + test_assert_true(rd_grid_compare(grid, grid_copy, true, true, true)); + rd_grid_free(grid_copy); +} + +void test_copy_grid_file(const char *filename) { + rd_grid_type *src_grid = rd_grid_alloc(filename); + rd_grid_type *copy_grid = rd_grid_alloc_copy(src_grid); + test_assert_true(rd_grid_compare(src_grid, copy_grid, true, true, true)); + rd_grid_free(copy_grid); + rd_grid_free(src_grid); +} + +int main(int argc, char **argv) { + if (argc < 2) { + rd_grid_type *grid = + rd_grid_alloc_rectangular(10, 11, 12, 1, 2, 3, NULL); + test_copy_grid(grid); + rd_grid_free(grid); + } else { + test_copy_grid_file(argv[1]); + } + exit(0); +} diff --git a/lib/ecl/tests/ecl_grid_corner.cpp b/lib/resdata/tests/rd_grid_corner.cpp similarity index 53% rename from lib/ecl/tests/ecl_grid_corner.cpp rename to lib/resdata/tests/rd_grid_corner.cpp index 1e93b6fafb..44f5b4d586 100644 --- a/lib/ecl/tests/ecl_grid_corner.cpp +++ b/lib/resdata/tests/rd_grid_corner.cpp @@ -3,43 +3,43 @@ #include -#include +#include void invalid_call1(void *arg) { - ecl_grid_type *grid = ecl_grid_safe_cast(arg); + rd_grid_type *grid = rd_grid_safe_cast(arg); double x, y, z; - ecl_grid_get_corner_xyz(grid, 10, 10, 11, &x, &y, &z); + rd_grid_get_corner_xyz(grid, 10, 10, 11, &x, &y, &z); } -void test_invalid(ecl_grid_type *grid) { - test_assert_util_abort("ecl_grid_get_corner_xyz", invalid_call1, grid); +void test_invalid(rd_grid_type *grid) { + test_assert_util_abort("rd_grid_get_corner_xyz", invalid_call1, grid); } -void test_OK(const ecl_grid_type *grid) { +void test_OK(const rd_grid_type *grid) { double x, y, z; double x8[8]; double y8[8]; double z8[8]; - ecl_grid_get_corner_xyz(grid, 0, 0, 0, &x, &y, &z); + rd_grid_get_corner_xyz(grid, 0, 0, 0, &x, &y, &z); test_assert_double_equal(x, 0); test_assert_double_equal(y, 0); test_assert_double_equal(z, 0); - ecl_grid_get_corner_xyz(grid, 4, 5, 6, &x, &y, &z); + rd_grid_get_corner_xyz(grid, 4, 5, 6, &x, &y, &z); test_assert_double_equal(x, 4); test_assert_double_equal(y, 5); test_assert_double_equal(z, 6); - ecl_grid_get_corner_xyz(grid, 10, 10, 10, &x, &y, &z); + rd_grid_get_corner_xyz(grid, 10, 10, 10, &x, &y, &z); test_assert_double_equal(x, 10); test_assert_double_equal(y, 10); test_assert_double_equal(z, 10); - ecl_grid_export_cell_corners1(grid, 456, x8, y8, z8); + rd_grid_export_cell_corners1(grid, 456, x8, y8, z8); for (int i = 0; i < 8; i++) { - ecl_grid_get_cell_corner_xyz1(grid, 456, i, &x, &y, &z); + rd_grid_get_cell_corner_xyz1(grid, 456, i, &x, &y, &z); test_assert_double_equal(x, x8[i]); test_assert_double_equal(y, y8[i]); test_assert_double_equal(z, z8[i]); @@ -47,11 +47,11 @@ void test_OK(const ecl_grid_type *grid) { } int main(int argc, char **argv) { - ecl_grid_type *grid = ecl_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); + rd_grid_type *grid = rd_grid_alloc_rectangular(10, 10, 10, 1, 1, 1, NULL); test_invalid(grid); test_OK(grid); - ecl_grid_free(grid); + rd_grid_free(grid); exit(0); } diff --git a/lib/ecl/tests/ecl_grid_create.cpp b/lib/resdata/tests/rd_grid_create.cpp similarity index 76% rename from lib/ecl/tests/ecl_grid_create.cpp rename to lib/resdata/tests/rd_grid_create.cpp index 812498a72c..f925ec76e3 100644 --- a/lib/ecl/tests/ecl_grid_create.cpp +++ b/lib/resdata/tests/rd_grid_create.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include void test_create2() { int nx = 10; @@ -32,18 +32,18 @@ void test_create2() { } { - ecl_grid_type *grid = - ecl_grid_alloc_dx_dy_dz_tops(nx, ny, nz, dx, dy, dz, tops, NULL); + rd_grid_type *grid = + rd_grid_alloc_dx_dy_dz_tops(nx, ny, nz, dx, dy, dz, tops, NULL); - test_assert_int_equal(nx * ny * nz, ecl_grid_get_global_size(grid)); - test_assert_int_equal(nx * ny * nz, ecl_grid_get_active_size(grid)); + test_assert_int_equal(nx * ny * nz, rd_grid_get_global_size(grid)); + test_assert_int_equal(nx * ny * nz, rd_grid_get_active_size(grid)); for (int k = 0; k < nz; k++) { for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { int g = k * nx * ny + j * nx + i; - test_assert_double_equal(ecl_grid_get_cell_volume1(grid, g), + test_assert_double_equal(rd_grid_get_cell_volume1(grid, g), dx[g] * dy[g] * dz[g]); } } @@ -51,12 +51,12 @@ void test_create2() { { double x, y, z; - ecl_grid_get_xyz1(grid, 0, &x, &y, &z); + rd_grid_get_xyz1(grid, 0, &x, &y, &z); test_assert_double_equal(x, dx[0] * 0.5); test_assert_double_equal(y, dy[0] * 0.5); test_assert_double_equal(z, dz[0] * 0.5 + tops[0]); } - ecl_grid_free(grid); + rd_grid_free(grid); } free(tops); free(dx); @@ -89,23 +89,23 @@ void test_create1() { } { - ecl_grid_type *grid = - ecl_grid_alloc_dx_dy_dz_tops(nx, ny, nz, dx, dy, dz, tops, NULL); + rd_grid_type *grid = + rd_grid_alloc_dx_dy_dz_tops(nx, ny, nz, dx, dy, dz, tops, NULL); - test_assert_int_equal(nx * ny * nz, ecl_grid_get_global_size(grid)); - test_assert_int_equal(nx * ny * nz, ecl_grid_get_active_size(grid)); + test_assert_int_equal(nx * ny * nz, rd_grid_get_global_size(grid)); + test_assert_int_equal(nx * ny * nz, rd_grid_get_active_size(grid)); for (int k = 0; k < nz; k++) { for (int j = 0; j < ny; j++) { for (int i = 0; i < nx; i++) { int g = k * nx * ny + j * nx + i; - test_assert_double_equal(ecl_grid_get_cell_volume1(grid, g), + test_assert_double_equal(rd_grid_get_cell_volume1(grid, g), dx[g] * dy[g] * dz[g]); { double x, y, z; - ecl_grid_get_xyz1(grid, g, &x, &y, &z); + rd_grid_get_xyz1(grid, g, &x, &y, &z); test_assert_double_equal(x, i + 0.5); test_assert_double_equal(y, j + 0.5); test_assert_double_equal(z, k + 0.5); @@ -113,7 +113,7 @@ void test_create1() { } } } - ecl_grid_free(grid); + rd_grid_free(grid); } free(tops); free(dx); diff --git a/lib/ecl/tests/ecl_grid_dims.cpp b/lib/resdata/tests/rd_grid_dims.cpp similarity index 67% rename from lib/ecl/tests/ecl_grid_dims.cpp rename to lib/resdata/tests/rd_grid_dims.cpp index ed8e7e2bd2..1c8a48f54c 100644 --- a/lib/ecl/tests/ecl_grid_dims.cpp +++ b/lib/resdata/tests/rd_grid_dims.cpp @@ -5,21 +5,21 @@ #include #include -#include -#include +#include +#include void test_grid(const char *grid_filename, const char *data_filename) { - ecl_grid_type *ecl_grid = ecl_grid_alloc(grid_filename); - ecl_grid_dims_type *grid_dims = - ecl_grid_dims_alloc(grid_filename, data_filename); + rd_grid_type *rd_grid = rd_grid_alloc(grid_filename); + rd_grid_dims_type *grid_dims = + rd_grid_dims_alloc(grid_filename, data_filename); test_assert_not_NULL(grid_dims); - test_assert_int_equal(ecl_grid_get_num_lgr(ecl_grid) + 1, - ecl_grid_dims_get_num_grids(grid_dims)); - for (int i = 0; i < ecl_grid_dims_get_num_grids(grid_dims); i++) { + test_assert_int_equal(rd_grid_get_num_lgr(rd_grid) + 1, + rd_grid_dims_get_num_grids(grid_dims)); + for (int i = 0; i < rd_grid_dims_get_num_grids(grid_dims); i++) { - grid_dims_type d1 = ecl_grid_iget_dims(ecl_grid, i); - const grid_dims_type *d2 = ecl_grid_dims_iget_dims(grid_dims, i); + grid_dims_type d1 = rd_grid_iget_dims(rd_grid, i); + const grid_dims_type *d2 = rd_grid_dims_iget_dims(grid_dims, i); test_assert_int_equal(d1.nx, d2->nx); test_assert_int_equal(d1.ny, d2->ny); @@ -50,7 +50,7 @@ int main(int argc, char **argv) { util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */ if (argc == 1) { - ecl_grid_dims_type *grid_dims = ecl_grid_dims_alloc(argv[0], NULL); + rd_grid_dims_type *grid_dims = rd_grid_dims_alloc(argv[0], NULL); test_assert_NULL(grid_dims); test_dims(); } else { diff --git a/lib/resdata/tests/rd_grid_dx_dy_dz.cpp b/lib/resdata/tests/rd_grid_dx_dy_dz.cpp new file mode 100644 index 0000000000..97ed7fa8e8 --- /dev/null +++ b/lib/resdata/tests/rd_grid_dx_dy_dz.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +double err(double a, double b) { return (a - b) / a; } + +void test_dxdydz(const std::string &grid_fname, const std::string &init_fname) { + double eps_x = 1e-4; + double eps_y = 1e-4; + double eps_z = 1e-3; + rd_grid_type *grid = rd_grid_alloc(grid_fname.c_str()); + rd_file_type *init_file = rd_file_open(init_fname.c_str(), 0); + rd_kw_type *dx = rd_file_iget_named_kw(init_file, "DX", 0); + rd_kw_type *dy = rd_file_iget_named_kw(init_file, "DY", 0); + rd_kw_type *dz = rd_file_iget_named_kw(init_file, "DZ", 0); + for (int a = 0; a < rd_grid_get_active_size(grid); a += 100) { + int g = rd_grid_get_global_index1A(grid, a); + + double dxg = rd_grid_get_cell_dx1(grid, g); + double dyg = rd_grid_get_cell_dy1(grid, g); + double dzg = rd_grid_get_cell_dz1(grid, g); + + double dxi = rd_kw_iget_float(dx, a); + double dyi = rd_kw_iget_float(dy, a); + double dzi = rd_kw_iget_float(dz, a); + + double err_x = fabs(err(dxg, dxi)); + double err_y = fabs(err(dyg, dyi)); + double err_z = fabs(err(dzg, dzi)); + + test_assert_true(err_x < eps_x); + test_assert_true(err_y < eps_y); + test_assert_true(err_z < eps_z); + } + rd_file_close(init_file); + rd_grid_free(grid); +} + +int main(int argc, char **argv) { + const std::string rd_case = argv[1]; + std::string grid_file = rd_case + ".EGRID"; + std::string init_file = rd_case + ".INIT"; + + test_dxdydz(grid_file, init_file); + + exit(0); +} diff --git a/lib/resdata/tests/rd_grid_export.cpp b/lib/resdata/tests/rd_grid_export.cpp new file mode 100644 index 0000000000..2a9418cb67 --- /dev/null +++ b/lib/resdata/tests/rd_grid_export.cpp @@ -0,0 +1,176 @@ +#include +#include + +#include +#include + +#include +#include +#include + +void export_actnum(const rd_grid_type *rd_grid, rd_file_type *rd_file) { + rd_kw_type *actnum_kw = rd_file_iget_named_kw(rd_file, "ACTNUM", 0); + int *actnum = + (int *)util_malloc(rd_kw_get_size(actnum_kw) * sizeof *actnum); + + rd_grid_init_actnum_data(rd_grid, actnum); + for (int i = 0; i < rd_kw_get_size(actnum_kw); i++) + test_assert_int_equal(actnum[i], rd_kw_iget_int(actnum_kw, i)); + + free(actnum); +} + +void export_coord(const rd_grid_type *grid, rd_file_type *rd_file) { + rd_kw_type *coord_kw = rd_file_iget_named_kw(rd_file, "COORD", 0); + test_assert_int_equal(rd_kw_get_size(coord_kw), + rd_grid_get_coord_size(grid)); + { + float *coord_float = (float *)util_malloc(rd_grid_get_coord_size(grid) * + sizeof *coord_float); + double *coord_double = (double *)util_malloc( + rd_grid_get_coord_size(grid) * sizeof *coord_double); + + rd_grid_init_coord_data(grid, coord_float); + rd_grid_init_coord_data_double(grid, coord_double); + + for (int i = 0; i < rd_grid_get_coord_size(grid); i++) + test_assert_double_equal(coord_double[i], coord_float[i]); + + free(coord_float); + free(coord_double); + } +} + +void export_zcorn(const rd_grid_type *grid, rd_file_type *rd_file) { + rd_kw_type *zcorn_kw = rd_file_iget_named_kw(rd_file, "ZCORN", 0); + test_assert_int_equal(rd_kw_get_size(zcorn_kw), + rd_grid_get_zcorn_size(grid)); + { + float *zcorn_float = (float *)util_malloc(rd_grid_get_zcorn_size(grid) * + sizeof *zcorn_float); + double *zcorn_double = (double *)util_malloc( + rd_grid_get_zcorn_size(grid) * sizeof *zcorn_double); + + rd_grid_init_zcorn_data(grid, zcorn_float); + rd_grid_init_zcorn_data_double(grid, zcorn_double); + + for (int i = 0; i < rd_grid_get_zcorn_size(grid); i++) { + test_assert_double_equal(zcorn_double[i], zcorn_float[i]); + test_assert_float_equal(zcorn_float[i], + rd_kw_iget_float(zcorn_kw, i)); + } + + free(zcorn_float); + free(zcorn_double); + } +} + +void copy_processed(const rd_grid_type *src) { + { + rd_grid_type *copy = rd_grid_alloc_processed_copy(src, NULL, NULL); + test_assert_true(rd_grid_compare(src, copy, true, true, false)); + rd_grid_free(copy); + } + + { + int *actnum = + (int *)util_malloc(rd_grid_get_global_size(src) * sizeof *actnum); + int index = 0; + rd_grid_init_actnum_data(src, actnum); + + while (true) { + if (actnum[index] == 1) { + actnum[index] = 0; + break; + } + index++; + } + + { + rd_grid_type *copy = + rd_grid_alloc_processed_copy(src, NULL, actnum); + test_assert_int_equal(1, rd_grid_get_active_size(src) - + rd_grid_get_active_size(copy)); + rd_grid_free(copy); + } + free(actnum); + } + + { + double *zcorn_double = (double *)util_malloc( + rd_grid_get_zcorn_size(src) * sizeof *zcorn_double); + int i = 0; + int j = 0; + int k = 0; + + rd_grid_init_zcorn_data_double(src, zcorn_double); + { + rd_grid_type *copy = + rd_grid_alloc_processed_copy(src, zcorn_double, NULL); + test_assert_double_equal(rd_grid_get_cell_volume3(src, i, j, k), + rd_grid_get_cell_volume3(copy, i, j, k)); + rd_grid_free(copy); + } + + for (int c = 0; c < 4; c++) { + double dz = zcorn_double[rd_grid_zcorn_index(src, i, j, k, c + 4)] - + zcorn_double[rd_grid_zcorn_index(src, i, j, k, c)]; + zcorn_double[rd_grid_zcorn_index(src, i, j, k, c + 4)] += dz; + } + { + rd_grid_type *copy = + rd_grid_alloc_processed_copy(src, zcorn_double, NULL); + test_assert_double_equal(rd_grid_get_cell_volume3(src, i, j, k) * 2, + rd_grid_get_cell_volume3(copy, i, j, k)); + rd_grid_free(copy); + } + + free(zcorn_double); + } +} + +void export_mapaxes(const rd_grid_type *grid, rd_file_type *rd_file) { + if (rd_file_has_kw(rd_file, "MAPAXES")) { + rd_kw_type *mapaxes_kw = rd_file_iget_named_kw(rd_file, "MAPAXES", 0); + double mapaxes[6]; + int i; + + test_assert_true(rd_grid_use_mapaxes(grid)); + rd_grid_init_mapaxes_data_double(grid, mapaxes); + for (i = 0; i < 6; i++) + test_assert_double_equal(rd_kw_iget_float(mapaxes_kw, i), + mapaxes[i]); + } +} + +int main(int argc, char **argv) { + rd::util::TestArea ta("grid_export"); + { + const char *test_grid = "TEST.EGRID"; + const char *grid_file; + if (argc == 1) { + rd_grid_type *grid = + rd_grid_alloc_rectangular(4, 4, 2, 1, 1, 1, NULL); + grid_file = test_grid; + rd_grid_fwrite_EGRID(grid, grid_file, true); + rd_grid_free(grid); + } else + grid_file = argv[1]; + + { + rd_grid_type *rd_grid = rd_grid_alloc(grid_file); + if (argc == 1) + test_assert_true(rd_grid_get_unit_system(rd_grid) == + RD_METRIC_UNITS); + rd_file_type *rd_file = rd_file_open(grid_file, 0); + + export_actnum(rd_grid, rd_file); + export_coord(rd_grid, rd_file); + export_zcorn(rd_grid, rd_file); + export_mapaxes(rd_grid, rd_file); + copy_processed(rd_grid); + rd_file_close(rd_file); + rd_grid_free(rd_grid); + } + } +} diff --git a/lib/resdata/tests/rd_grid_ext_actnum.cpp b/lib/resdata/tests/rd_grid_ext_actnum.cpp new file mode 100644 index 0000000000..15613367e2 --- /dev/null +++ b/lib/resdata/tests/rd_grid_ext_actnum.cpp @@ -0,0 +1,59 @@ +#include + +#include +#include + +#include +#include +#include +#include +#include + +void test_1() { + + rd::util::TestArea ta("test1"); + { + const char *filename = "FILE.EGRID"; + + rd_grid_type *grid_write = + rd_grid_alloc_rectangular(2, 3, 1, 1, 1, 1, NULL); + rd_grid_fwrite_EGRID(grid_write, filename, true); + rd_grid_free(grid_write); + + rd_file_type *rd_file = rd_file_open(filename, 0); + rd_kw_type *filehead_kw = + rd_file_iget_named_kw(rd_file, FILEHEAD_KW, 0); + int *filehead_data = rd_kw_get_int_ptr(filehead_kw); + filehead_data[FILEHEAD_DUALP_INDEX] = FILEHEAD_DUAL_POROSITY; + + rd_kw_type *actnum_kw = rd_file_iget_named_kw(rd_file, ACTNUM_KW, 0); + int *actnum_data = rd_kw_get_int_ptr(actnum_kw); + actnum_data[0] = 1; + actnum_data[1] = 2; + actnum_data[2] = 2; + actnum_data[3] = 0; + actnum_data[4] = 1; + actnum_data[5] = 1; + const char *filename1 = "FILE1.EGRID"; + fortio_type *f = fortio_open_writer(filename1, false, RD_ENDIAN_FLIP); + rd_file_fwrite_fortio(rd_file, f, 0); + fortio_fclose(f); + rd_file_close(rd_file); + + std::vector ext_actnum = {0, 1, 0, 1, 1, 1}; + rd_grid_type *grid = + rd_grid_alloc_ext_actnum(filename1, ext_actnum.data()); + test_assert_int_equal(4, rd_grid_get_nactive(grid)); + test_assert_int_equal(0, rd_grid_get_nactive_fracture(grid)); + test_assert_true(!rd_grid_cell_active1(grid, 0)); + + test_assert_true(!rd_grid_cell_active1(grid, 2)); + test_assert_true(rd_grid_cell_active1(grid, 3)); + test_assert_true(rd_grid_cell_active1(grid, 4)); + test_assert_true(rd_grid_cell_active1(grid, 5)); + + rd_grid_free(grid); + } +} + +int main() { test_1(); } diff --git a/lib/resdata/tests/rd_grid_init_fwrite.cpp b/lib/resdata/tests/rd_grid_init_fwrite.cpp new file mode 100644 index 0000000000..085fb320f2 --- /dev/null +++ b/lib/resdata/tests/rd_grid_init_fwrite.cpp @@ -0,0 +1,85 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +void test_write_depth(const rd_grid_type *grid) { + rd::util::TestArea ta("write_depth"); + { + fortio_type *init_file = + fortio_open_writer("INIT", false, RD_ENDIAN_FLIP); + rd_grid_fwrite_depth(grid, init_file, RD_METRIC_UNITS); + fortio_fclose(init_file); + } + { + rd_file_type *init_file = rd_file_open("INIT", 0); + rd_kw_type *depth = rd_file_iget_named_kw(init_file, "DEPTH", 0); + + test_assert_int_equal(rd_kw_get_size(depth), rd_grid_get_nactive(grid)); + for (int i = 0; i < rd_grid_get_nactive(grid); i++) + test_assert_double_equal(rd_kw_iget_as_double(depth, i), + rd_grid_get_cdepth1A(grid, i)); + + rd_file_close(init_file); + } +} + +void test_write_dims(const rd_grid_type *grid) { + rd::util::TestArea ta("write_dims"); + { + fortio_type *init_file = + fortio_open_writer("INIT", false, RD_ENDIAN_FLIP); + rd_grid_fwrite_dims(grid, init_file, RD_METRIC_UNITS); + fortio_fclose(init_file); + } + { + rd_file_type *init_file = rd_file_open("INIT", 0); + rd_kw_type *DX = rd_file_iget_named_kw(init_file, "DX", 0); + rd_kw_type *DY = rd_file_iget_named_kw(init_file, "DY", 0); + rd_kw_type *DZ = rd_file_iget_named_kw(init_file, "DZ", 0); + + test_assert_int_equal(rd_kw_get_size(DX), rd_grid_get_nactive(grid)); + test_assert_int_equal(rd_kw_get_size(DY), rd_grid_get_nactive(grid)); + test_assert_int_equal(rd_kw_get_size(DZ), rd_grid_get_nactive(grid)); + for (int i = 0; i < rd_grid_get_nactive(grid); i++) { + test_assert_double_equal(rd_kw_iget_as_double(DX, i), + rd_grid_get_cell_dx1A(grid, i)); + test_assert_double_equal(rd_kw_iget_as_double(DY, i), + rd_grid_get_cell_dy1A(grid, i)); + test_assert_double_equal(rd_kw_iget_as_double(DZ, i), + rd_grid_get_cell_dz1A(grid, i)); + } + rd_file_close(init_file); + } +} + +rd_grid_type *create_grid() { + int nx = 10; + int ny = 10; + int nz = 8; + int_vector_type *actnum = int_vector_alloc(nx * ny * nz, 1); + + rd_grid_type *rd_grid = rd_grid_alloc_rectangular( + nx, ny, nz, 1, 1, 1, int_vector_get_ptr(actnum)); + int_vector_free(actnum); + return rd_grid; +} + +int main(int argc, char **argv) { + util_install_signals(); + { + rd_grid_type *grid = create_grid(); + + test_write_depth(grid); + test_write_dims(grid); + rd_grid_free(grid); + } +} diff --git a/lib/resdata/tests/rd_grid_layer_contains.cpp b/lib/resdata/tests/rd_grid_layer_contains.cpp new file mode 100644 index 0000000000..bbf6237358 --- /dev/null +++ b/lib/resdata/tests/rd_grid_layer_contains.cpp @@ -0,0 +1,31 @@ +#include +#include + +#include + +#include + +void test_layer(const rd_grid_type *grid) { + int g; + + for (g = 0; g < rd_grid_get_global_size(grid); g += 25) { + double x, y, z; + int i, j, k; + + rd_grid_get_xyz1(grid, g, &x, &y, &z); + rd_grid_get_ijk1(grid, g, &i, &j, &k); + { + int find_i, find_j; + test_assert_true( + rd_grid_get_ij_from_xy(grid, x, y, k, &find_i, &find_j)); + test_assert_int_equal(i, find_i); + test_assert_int_equal(j, find_j); + } + } +} + +int main(int argc, char **argv) { + rd_grid_type *grid = rd_grid_alloc(argv[1]); + test_layer(grid); + rd_grid_free(grid); +} diff --git a/lib/ecl/tests/ecl_grid_lgr_name.cpp b/lib/resdata/tests/rd_grid_lgr_name.cpp similarity index 72% rename from lib/ecl/tests/ecl_grid_lgr_name.cpp rename to lib/resdata/tests/rd_grid_lgr_name.cpp index b7300a3cec..cf95892a10 100644 --- a/lib/ecl/tests/ecl_grid_lgr_name.cpp +++ b/lib/resdata/tests/rd_grid_lgr_name.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include /* Name ..................: LG003017 @@ -26,14 +26,14 @@ Grid nr ...............: 110 */ -void test_name(const ecl_grid_type *grid, int lgr_nr, const char *name) { - test_assert_string_equal(name, ecl_grid_get_lgr_name(grid, lgr_nr)); - test_assert_int_equal(lgr_nr, ecl_grid_get_lgr_nr_from_name(grid, name)); +void test_name(const rd_grid_type *grid, int lgr_nr, const char *name) { + test_assert_string_equal(name, rd_grid_get_lgr_name(grid, lgr_nr)); + test_assert_int_equal(lgr_nr, rd_grid_get_lgr_nr_from_name(grid, name)); } int main(int argc, char **argv) { const char *grid_file = argv[1]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); + rd_grid_type *grid = rd_grid_alloc(grid_file); test_name(grid, 104, "LG003017"); test_name(grid, 2, "LG006024"); @@ -43,6 +43,6 @@ int main(int argc, char **argv) { test_name(grid, 110, "LG003014"); test_name(grid, 0, grid_file); - ecl_grid_free(grid); + rd_grid_free(grid); exit(0); } diff --git a/lib/resdata/tests/rd_grid_reset_actnum.cpp b/lib/resdata/tests/rd_grid_reset_actnum.cpp new file mode 100644 index 0000000000..842b5a339c --- /dev/null +++ b/lib/resdata/tests/rd_grid_reset_actnum.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include + +#include + +int main(int argc, char **argv) { + const int nx = 5; + const int ny = 4; + const int nz = 2; + const int g = nx * ny * nz; + const int nactive = g - 9; + const int actnum1[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + const int actnum2[] = {0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, + 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0}; + rd_grid_type *grid = + rd_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, actnum1); + + test_assert_int_equal(g, rd_grid_get_nactive(grid)); + rd_grid_reset_actnum(grid, actnum2); + test_assert_int_equal(nactive, rd_grid_get_nactive(grid)); + + test_assert_int_equal(-1, rd_grid_get_active_index1(grid, 0)); + test_assert_int_equal(0, rd_grid_get_active_index1(grid, 1)); + test_assert_int_equal(-1, rd_grid_get_active_index1(grid, 2)); + test_assert_int_equal(1, rd_grid_get_global_index1A(grid, 0)); + test_assert_int_equal(3, rd_grid_get_global_index1A(grid, 1)); + test_assert_int_equal(5, rd_grid_get_global_index1A(grid, 2)); + + rd_grid_reset_actnum(grid, NULL); + test_assert_int_equal(g, rd_grid_get_nactive(grid)); + test_assert_int_equal(0, rd_grid_get_active_index1(grid, 0)); + test_assert_int_equal(1, rd_grid_get_active_index1(grid, 1)); + test_assert_int_equal(2, rd_grid_get_active_index1(grid, 2)); + test_assert_int_equal(0, rd_grid_get_global_index1A(grid, 0)); + test_assert_int_equal(1, rd_grid_get_global_index1A(grid, 1)); + test_assert_int_equal(2, rd_grid_get_global_index1A(grid, 2)); + + rd_grid_free(grid); + exit(0); +} diff --git a/lib/resdata/tests/rd_grid_unit_system.cpp b/lib/resdata/tests/rd_grid_unit_system.cpp new file mode 100644 index 0000000000..f12bbc02d5 --- /dev/null +++ b/lib/resdata/tests/rd_grid_unit_system.cpp @@ -0,0 +1,38 @@ +#include +#include + +#include +#include + +#include +#include +#include + +void test_EGRID(const char *filename, ert_rd_unit_enum unit_system) { + rd_grid_type *grid = rd_grid_alloc_rectangular(4, 4, 2, 1, 1, 1, NULL); + rd_grid_fwrite_EGRID2(grid, filename, unit_system); + rd_grid_free(grid); + + rd_grid_type *grid2 = rd_grid_alloc(filename); + test_assert_int_equal(rd_grid_get_unit_system(grid2), unit_system); + rd_grid_free(grid2); +} + +void test_GRID(const char *filename, ert_rd_unit_enum unit_system) { + rd_grid_type *grid = rd_grid_alloc_rectangular(4, 4, 2, 1, 1, 1, NULL); + rd_grid_fwrite_GRID2(grid, filename, unit_system); + rd_grid_free(grid); + + rd_grid_type *grid2 = rd_grid_alloc(filename); + test_assert_int_equal(rd_grid_get_unit_system(grid2), unit_system); + rd_grid_free(grid2); +} + +int main(int argc, char **argv) { + rd::util::TestArea ta("grid_unit_system"); + + test_EGRID("METRIC.EGRID", RD_METRIC_UNITS); + test_EGRID("FIELD.EGRID", RD_FIELD_UNITS); + test_GRID("METRIC.GRID", RD_METRIC_UNITS); + test_GRID("FIELD.GRID", RD_FIELD_UNITS); +} diff --git a/lib/resdata/tests/rd_grid_volume.cpp b/lib/resdata/tests/rd_grid_volume.cpp new file mode 100644 index 0000000000..646c1667e3 --- /dev/null +++ b/lib/resdata/tests/rd_grid_volume.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +int main(int argc, char **argv) { + const char *path_case = argv[1]; + char *grid_file = + rd_alloc_filename(NULL, path_case, RD_EGRID_FILE, false, 0); + char *init_file = + rd_alloc_filename(NULL, path_case, RD_INIT_FILE, false, 0); + + rd_file_type *init = rd_file_open(init_file, 0); + rd_grid_type *grid = rd_grid_alloc(grid_file); + const rd_kw_type *poro_kw = rd_file_iget_named_kw(init, "PORO", 0); + const rd_kw_type *porv_kw = rd_file_iget_named_kw(init, "PORV", 0); + rd_kw_type *multpv = NULL; + rd_kw_type *NTG = NULL; + bool error_found = false; + + double total_volume = 0; + double total_diff = 0; + int error_count = 0; + int iactive; + + if (rd_file_has_kw(init, "NTG")) + NTG = rd_file_iget_named_kw(init, "NTG", 0); + + if (rd_file_has_kw(init, "MULTPV")) + multpv = rd_file_iget_named_kw(init, "MULTPV", 0); + + for (iactive = 0; iactive < rd_grid_get_nactive(grid); ++iactive) { + int iglobal = rd_grid_get_global_index1A(grid, iactive); + double grid_volume = rd_grid_get_cell_volume1(grid, iglobal); + double eclipse_volume = rd_kw_iget_float(porv_kw, iglobal) / + rd_kw_iget_float(poro_kw, iactive); + + if (NTG) + eclipse_volume /= rd_kw_iget_float(NTG, iactive); + + if (multpv) + eclipse_volume *= rd_kw_iget_float(multpv, iactive); + + total_volume += grid_volume; + total_diff += fabs(eclipse_volume - grid_volume); + if (!util_double_approx_equal__(grid_volume, eclipse_volume, 2.5e-3, + 0.00)) { + double diff = 100 * (grid_volume - eclipse_volume) / eclipse_volume; + printf("Error in cell: %d V1: %g V2: %g diff:%g %% \n", + iglobal, grid_volume, eclipse_volume, diff); + error_count++; + error_found = true; + } + } + printf("Total volume difference: %g %% \n", + 100 * total_diff / total_volume); + + rd_grid_free(grid); + rd_file_close(init); + free(grid_file); + free(init_file); + if (error_found) { + printf("Error_count: %d / %d \n", error_count, + rd_grid_get_nactive(grid)); + exit(1); + } else + exit(0); +} diff --git a/lib/resdata/tests/rd_init_file.cpp b/lib/resdata/tests/rd_init_file.cpp new file mode 100644 index 0000000000..0e04feb3fe --- /dev/null +++ b/lib/resdata/tests/rd_init_file.cpp @@ -0,0 +1,79 @@ +#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); +} diff --git a/lib/resdata/tests/rd_kw_cmp_string.cpp b/lib/resdata/tests/rd_kw_cmp_string.cpp new file mode 100644 index 0000000000..bad7e1e093 --- /dev/null +++ b/lib/resdata/tests/rd_kw_cmp_string.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include +#include +#include + +void test_cmp_string() { + rd_kw_type *rd_kw = rd_kw_alloc("HEADER", 1, RD_CHAR); + + rd_kw_iset_string8(rd_kw, 0, "ABCD"); + + test_assert_int_equal(0, strcmp(rd_kw_iget_char_ptr(rd_kw, 0), "ABCD ")); + test_assert_true(rd_kw_icmp_string(rd_kw, 0, "ABCD")); + test_assert_true(rd_kw_icmp_string(rd_kw, 0, "ABCD ")); + test_assert_true(rd_kw_icmp_string(rd_kw, 0, "ABCD ")); + + test_assert_false(rd_kw_icmp_string(rd_kw, 0, "Different")); + test_assert_false(rd_kw_icmp_string(rd_kw, 0, "")); + test_assert_false(rd_kw_icmp_string(rd_kw, 0, "")); + + rd_kw_free(rd_kw); +} + +int main(int argc, char **argv) { + test_cmp_string(); + + exit(0); +} diff --git a/lib/resdata/tests/rd_kw_equal.cpp b/lib/resdata/tests/rd_kw_equal.cpp new file mode 100644 index 0000000000..e915742ba5 --- /dev/null +++ b/lib/resdata/tests/rd_kw_equal.cpp @@ -0,0 +1,49 @@ +#include +#include + +#include +#include +#include +#include + +int main(int argc, char **argv) { + rd_kw_type *rd_kw1 = rd_kw_alloc("KW", 10, RD_INT); + int data[10]; + int i; + for (i = 0; i < 10; i++) { + rd_kw_iset_int(rd_kw1, i, i); + data[i] = i; + } + + { + rd_kw_type *rd_kw2 = rd_kw_alloc_copy(rd_kw1); + + test_assert_true(rd_kw_equal(rd_kw1, rd_kw2)); + + rd_kw_iset_int(rd_kw2, 1, 77); + test_assert_false(rd_kw_equal(rd_kw1, rd_kw2)); + rd_kw_iset_int(rd_kw2, 1, 1); + test_assert_true(rd_kw_equal(rd_kw1, rd_kw2)); + + rd_kw_set_header_name(rd_kw2, "TEST"); + test_assert_false(rd_kw_equal(rd_kw1, rd_kw2)); + test_assert_true(rd_kw_content_equal(rd_kw1, rd_kw2)); + rd_kw_free(rd_kw2); + } + + { + rd_kw_type *rd_ikw = rd_kw_alloc_new_shared("KW", 10, RD_INT, data); + rd_kw_type *rd_fkw = rd_kw_alloc_new_shared("KW", 10, RD_FLOAT, data); + + test_assert_true(rd_kw_content_equal(rd_kw1, rd_ikw)); + test_assert_false(rd_kw_content_equal(rd_kw1, rd_fkw)); + + rd_kw_free(rd_ikw); + rd_kw_free(rd_fkw); + } + + test_assert_true(rd_kw_data_equal(rd_kw1, data)); + data[0] = 99; + test_assert_false(rd_kw_data_equal(rd_kw1, data)); + rd_kw_free(rd_kw1); +} diff --git a/lib/resdata/tests/rd_kw_fread.cpp b/lib/resdata/tests/rd_kw_fread.cpp new file mode 100644 index 0000000000..d59429bdbd --- /dev/null +++ b/lib/resdata/tests/rd_kw_fread.cpp @@ -0,0 +1,110 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +void test_truncated(const char *filename, offset_type truncate_size) { + { + FILE *stream = util_fopen(filename, "r+"); + util_ftruncate(stream, truncate_size); + fclose(stream); + } + { + fortio_type *fortio = fortio_open_reader(filename, false, true); + rd_kw_type *kw2 = rd_kw_fread_alloc(fortio); + test_assert_NULL(kw2); + fortio_fclose(fortio); + } +} + +void test_fread_alloc() { + rd::util::TestArea ta("fread_alloc"); + { + rd_kw_type *kw1 = rd_kw_alloc("INT", 100, RD_INT); + int i; + for (i = 0; i < 100; i++) + rd_kw_iset_int(kw1, i, i); + { + fortio_type *fortio = fortio_open_writer("INT", false, true); + rd_kw_fwrite(kw1, fortio); + fortio_fclose(fortio); + } + { + fortio_type *fortio = fortio_open_reader("INT", false, true); + rd_kw_type *kw2 = rd_kw_fread_alloc(fortio); + test_assert_true(rd_kw_is_instance(kw2)); + test_assert_true(rd_kw_equal(kw1, kw2)); + rd_kw_free(kw2); + fortio_fclose(fortio); + } + + { + offset_type file_size = util_file_size("INT"); + test_truncated("INT", file_size - 4); + test_truncated("INT", file_size - 25); + test_truncated("INT", 5); + test_truncated("INT", 0); + } + rd_kw_free(kw1); + } +} + +void test_kw_io_charlength() { + rd::util::TestArea ta("io_charlength"); + { + const char *KW0 = "QWERTYUI"; + const char *KW1 = "ABCDEFGHIJTTTTTTTTTTTTTTTTTTTTTTABCDEFGHIJKLMNOP"; + rd_kw_type *rd_kw_out0 = rd_kw_alloc(KW0, 5, RD_FLOAT); + rd_kw_type *rd_kw_out1 = rd_kw_alloc(KW1, 5, RD_FLOAT); + for (int i = 0; i < rd_kw_get_size(rd_kw_out1); i++) { + rd_kw_iset_float(rd_kw_out0, i, i * 1.5); + rd_kw_iset_float(rd_kw_out1, i, i * 1.5); + } + + { + fortio_type *f = fortio_open_writer("TEST1", false, RD_ENDIAN_FLIP); + test_assert_true(rd_kw_fwrite(rd_kw_out0, f)); + test_assert_false(rd_kw_fwrite(rd_kw_out1, f)); + fortio_fclose(f); + } + + { test_assert_false(util_file_exists("TEST1")); } + + { + FILE *file = util_fopen("TEST2", "w"); + rd_kw_fprintf_grdecl(rd_kw_out1, file); + fclose(file); + } + + { + FILE *file = util_fopen("TEST2", "r"); + rd_kw_type *rd_kw_in = + rd_kw_fscanf_alloc_grdecl(file, KW1, -1, RD_FLOAT); + test_assert_string_equal(KW1, rd_kw_get_header(rd_kw_in)); + test_assert_int_equal(5, rd_kw_get_size(rd_kw_in)); + + test_assert_double_equal(rd_kw_iget_as_double(rd_kw_in, 0), 0.0); + test_assert_double_equal(rd_kw_iget_as_double(rd_kw_in, 4), 6.0); + + rd_kw_free(rd_kw_in); + fclose(file); + } + + rd_kw_free(rd_kw_out0); + rd_kw_free(rd_kw_out1); + } +} + +int main(int argc, char **argv) { + test_fread_alloc(); + test_kw_io_charlength(); + exit(0); +} diff --git a/lib/resdata/tests/rd_kw_grdecl.cpp b/lib/resdata/tests/rd_kw_grdecl.cpp new file mode 100644 index 0000000000..9c15732f0c --- /dev/null +++ b/lib/resdata/tests/rd_kw_grdecl.cpp @@ -0,0 +1,57 @@ +#include +#include + +#include +#include +#include + +#include + +int main(int argc, char **argv) { + int i; + rd_kw_type *rd_kw = rd_kw_alloc("HEAD", 10, RD_INT); + + for (i = 0; i < 10; i++) + rd_kw_iset_int(rd_kw, i, i); + + { + rd::util::TestArea ta("kw_grdecl"); + FILE *stream = util_fopen("FILE.grdecl", "w"); + + rd_kw_fprintf_grdecl(rd_kw, stream); + fclose(stream); + + stream = util_fopen("FILE.grdecl", "r"); + { + rd_kw_type *rd_kw2 = + rd_kw_fscanf_alloc_grdecl(stream, "HEAD", 10, RD_INT); + + test_assert_not_NULL(rd_kw2); + test_assert_true(rd_kw_equal(rd_kw, rd_kw2)); + rd_kw_free(rd_kw2); + } + fclose(stream); + + stream = util_fopen("FILE.grdecl", "w"); + rd_kw_fprintf_grdecl__(rd_kw, "HEAD1234", stream); + fclose(stream); + + stream = util_fopen("FILE.grdecl", "r"); + { + rd_kw_type *rd_kw2 = + rd_kw_fscanf_alloc_grdecl(stream, "HEAD", 10, RD_INT); + + test_assert_NULL(rd_kw2); + rd_kw2 = rd_kw_fscanf_alloc_grdecl(stream, "HEAD1234", 10, RD_INT); + test_assert_not_NULL(rd_kw2); + + test_assert_string_equal(rd_kw_get_header(rd_kw2), "HEAD1234"); + test_assert_true(rd_kw_content_equal(rd_kw, rd_kw2)); + rd_kw_free(rd_kw2); + } + fclose(stream); + } + rd_kw_free(rd_kw); + + exit(0); +} diff --git a/lib/ecl/tests/ecl_kw_init.cpp b/lib/resdata/tests/rd_kw_init.cpp similarity index 54% rename from lib/ecl/tests/ecl_kw_init.cpp rename to lib/resdata/tests/rd_kw_init.cpp index 28ba04cc97..e11b4f04be 100644 --- a/lib/ecl/tests/ecl_kw_init.cpp +++ b/lib/resdata/tests/rd_kw_init.cpp @@ -5,54 +5,54 @@ #include #include -#include +#include void test_int() { int N = 1000; int i; - ecl_kw_type *kw = ecl_kw_alloc("KW", N, ECL_INT); + rd_kw_type *kw = rd_kw_alloc("KW", N, RD_INT); for (i = 0; i < N; i++) - test_assert_int_equal(0, ecl_kw_iget_int(kw, i)); + test_assert_int_equal(0, rd_kw_iget_int(kw, i)); - ecl_kw_free(kw); + rd_kw_free(kw); } void test_double() { int N = 1000; double i; - ecl_kw_type *kw = ecl_kw_alloc("KW", N, ECL_DOUBLE); + rd_kw_type *kw = rd_kw_alloc("KW", N, RD_DOUBLE); for (i = 0; i < N; i++) - test_assert_double_equal(0, ecl_kw_iget_double(kw, i)); + test_assert_double_equal(0, rd_kw_iget_double(kw, i)); - ecl_kw_free(kw); + rd_kw_free(kw); } void test_float() { int N = 1000; int i; - ecl_kw_type *kw = ecl_kw_alloc("KW", N, ECL_FLOAT); + rd_kw_type *kw = rd_kw_alloc("KW", N, RD_FLOAT); for (i = 0; i < N; i++) - test_assert_int_equal(0, ecl_kw_iget_float(kw, i)); + test_assert_int_equal(0, rd_kw_iget_float(kw, i)); - ecl_kw_free(kw); + rd_kw_free(kw); } void test_bool() { int N = 100; bool *data = (bool *)util_malloc(N * sizeof *data); - ecl_kw_type *kw = ecl_kw_alloc("BOOL", N, ECL_BOOL); + rd_kw_type *kw = rd_kw_alloc("BOOL", N, RD_BOOL); for (int i = 0; i < N / 2; i++) { - ecl_kw_iset_bool(kw, 2 * i, true); - ecl_kw_iset_bool(kw, 2 * i + 1, false); + rd_kw_iset_bool(kw, 2 * i, true); + rd_kw_iset_bool(kw, 2 * i + 1, false); data[2 * i] = true; data[2 * i + 1] = false; } - const bool *internal_data = ecl_kw_get_bool_ptr(kw); + const bool *internal_data = rd_kw_get_bool_ptr(kw); test_assert_int_equal(memcmp(internal_data, data, N * sizeof *data), 0); - ecl_kw_free(kw); + rd_kw_free(kw); free(data); } diff --git a/lib/ecl/tests/ecl_kw_space_pad.cpp b/lib/resdata/tests/rd_kw_space_pad.cpp similarity index 70% rename from lib/ecl/tests/ecl_kw_space_pad.cpp rename to lib/resdata/tests/rd_kw_space_pad.cpp index af7b079f6d..1b09cc74ce 100644 --- a/lib/ecl/tests/ecl_kw_space_pad.cpp +++ b/lib/resdata/tests/rd_kw_space_pad.cpp @@ -4,18 +4,18 @@ #include #include -#include +#include int main(int argc, char **argv) { - ecl::util::TestArea ta("grid_unit_system"); + rd::util::TestArea ta("grid_unit_system"); - // 1. Write a ecl_kw instance with string data - uninitialized. + // 1. Write a rd_kw instance with string data - uninitialized. { - ecl_kw_type *ecl_kw = ecl_kw_alloc("SPACE", 1, ECL_CHAR); + rd_kw_type *rd_kw = rd_kw_alloc("SPACE", 1, RD_CHAR); fortio_type *f = fortio_open_writer("file", false, true); - ecl_kw_fwrite(ecl_kw, f); + rd_kw_fwrite(rd_kw, f); fortio_fclose(f); - ecl_kw_free(ecl_kw); + rd_kw_free(rd_kw); } // 2. Open file with normal fopen() and verify that the data section consists of only spaces. diff --git a/lib/ecl/tests/ecl_layer.cpp b/lib/resdata/tests/rd_layer.cpp similarity index 99% rename from lib/ecl/tests/ecl_layer.cpp rename to lib/resdata/tests/rd_layer.cpp index 4725bd2717..f93f4678fd 100644 --- a/lib/ecl/tests/ecl_layer.cpp +++ b/lib/resdata/tests/rd_layer.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include "detail/ecl/layer_cxx.hpp" +#include +#include "detail/resdata/layer_cxx.hpp" void test_create() { layer_type *layer = layer_alloc(10, 20); diff --git a/lib/ecl/tests/ecl_layer_equinor.cpp b/lib/resdata/tests/rd_layer_equinor.cpp similarity index 60% rename from lib/ecl/tests/ecl_layer_equinor.cpp rename to lib/resdata/tests/rd_layer_equinor.cpp index 31f1beec86..fb2fc295b1 100644 --- a/lib/ecl/tests/ecl_layer_equinor.cpp +++ b/lib/resdata/tests/rd_layer_equinor.cpp @@ -6,32 +6,32 @@ #include #include -#include -#include -#include +#include +#include +#include -#include "detail/ecl/layer_cxx.hpp" +#include "detail/resdata/layer_cxx.hpp" -ecl_kw_type *alloc_faultblock_kw(const char *filename, int grid_size) { +rd_kw_type *alloc_faultblock_kw(const char *filename, int grid_size) { FILE *stream = util_fopen(filename, "r"); - ecl_kw_type *kw = - ecl_kw_fscanf_alloc_grdecl(stream, "FAULTBLK", grid_size, ECL_INT); + rd_kw_type *kw = + rd_kw_fscanf_alloc_grdecl(stream, "FAULTBLK", grid_size, RD_INT); fclose(stream); return kw; } -void test_layer(const ecl_grid_type *ecl_grid, const ecl_kw_type *faultblock_kw, +void test_layer(const rd_grid_type *rd_grid, const rd_kw_type *faultblock_kw, int k) { - int nx = ecl_grid_get_nx(ecl_grid); - int ny = ecl_grid_get_ny(ecl_grid); + int nx = rd_grid_get_nx(rd_grid); + int ny = rd_grid_get_ny(rd_grid); layer_type *layer = layer_alloc(nx, ny); int i, j; for (j = 0; j < ny; j++) for (i = 0; i < nx; i++) { - int g = ecl_grid_get_global_index3(ecl_grid, i, j, k); - int fblk = ecl_kw_iget_int(faultblock_kw, g); + int g = rd_grid_get_global_index3(rd_grid, i, j, k); + int fblk = rd_kw_iget_int(faultblock_kw, g); layer_iset_cell_value(layer, i, j, fblk); } @@ -62,15 +62,15 @@ void test_layer(const ecl_grid_type *ecl_grid, const ecl_kw_type *faultblock_kw, } int main(int argc, char **argv) { - ecl_grid_type *ecl_grid = ecl_grid_alloc(argv[1]); - ecl_kw_type *faultblock_kw = - alloc_faultblock_kw(argv[2], ecl_grid_get_global_size(ecl_grid)); + rd_grid_type *rd_grid = rd_grid_alloc(argv[1]); + rd_kw_type *faultblock_kw = + alloc_faultblock_kw(argv[2], rd_grid_get_global_size(rd_grid)); int k; - for (k = 0; k < ecl_grid_get_nz(ecl_grid); k++) - test_layer(ecl_grid, faultblock_kw, k); + for (k = 0; k < rd_grid_get_nz(rd_grid); k++) + test_layer(rd_grid, faultblock_kw, k); - ecl_kw_free(faultblock_kw); - ecl_grid_free(ecl_grid); + rd_kw_free(faultblock_kw); + rd_grid_free(rd_grid); exit(0); } diff --git a/lib/ecl/tests/ecl_lfs.cpp b/lib/resdata/tests/rd_lfs.cpp similarity index 61% rename from lib/ecl/tests/ecl_lfs.cpp rename to lib/resdata/tests/rd_lfs.cpp index dc1f4d9c72..6599a90c16 100644 --- a/lib/ecl/tests/ecl_lfs.cpp +++ b/lib/resdata/tests/rd_lfs.cpp @@ -1,44 +1,44 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { int num_kw = 1000; // Total file size should roughly exceed 2GB int kw_size = 600000; - ecl_kw_type *kw = ecl_kw_alloc("KW", kw_size, ECL_INT); + rd_kw_type *kw = rd_kw_alloc("KW", kw_size, RD_INT); int i; offset_type file_size; for (i = 0; i < kw_size; i++) - ecl_kw_iset_int(kw, i, i); + rd_kw_iset_int(kw, i, i); { fortio_type *fortio = - fortio_open_writer("LARGE_FILE.UNRST", false, ECL_ENDIAN_FLIP); + fortio_open_writer("LARGE_FILE.UNRST", false, RD_ENDIAN_FLIP); for (i = 0; i < num_kw; i++) { printf("Writing keyword %d/%d to file:LARGE_FILE.UNRST \n", i + 1, num_kw); - ecl_kw_fwrite(kw, fortio); + rd_kw_fwrite(kw, fortio); } fortio_fclose(fortio); } /*{ - fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , RD_ENDIAN_FLIP); for (i = 0; i < num_kw - 1; i++) { printf("SKipping keyword %d/%d from file:LARGE_FILE.UNRST \n",i+1 , num_kw ); - ecl_kw_fskip( fortio ); + rd_kw_fskip( fortio ); } { - ecl_kw_type * file_kw = ecl_kw_fread_alloc( fortio ); - if (ecl_kw_equal( kw , file_kw )) + rd_kw_type * file_kw = rd_kw_fread_alloc( fortio ); + if (rd_kw_equal( kw , file_kw )) printf("Keyword read back from file correctly :-) \n"); else printf("Fatal error - keyword different on return ...\n"); - ecl_kw_free( file_kw ); + rd_kw_free( file_kw ); } fortio_fclose( fortio ); } @@ -47,22 +47,22 @@ int main(int argc, char **argv) { printf("File size: %lld \n", file_size); { fortio_type *fortio = - fortio_open_reader("LARGE_FILE.UNRST", false, ECL_ENDIAN_FLIP); + fortio_open_reader("LARGE_FILE.UNRST", false, RD_ENDIAN_FLIP); printf("Seeking to file end: "); fortio_fseek(fortio, file_size, SEEK_SET); fortio_fclose(fortio); printf("Seek OK \n"); } - printf("Doing ecl_file_open(..)\n"); + printf("Doing rd_file_open(..)\n"); { - ecl_file_type *file = ecl_file_open("LARGE_FILE.UNRST", 0); - ecl_kw_type *file_kw = ecl_file_iget_named_kw(file, "KW", num_kw - 1); - if (ecl_kw_equal(kw, file_kw)) + rd_file_type *file = rd_file_open("LARGE_FILE.UNRST", 0); + rd_kw_type *file_kw = rd_file_iget_named_kw(file, "KW", num_kw - 1); + if (rd_kw_equal(kw, file_kw)) printf("Keyword read back from file correctly :-) \n"); else printf("Fatal error - keyword different on return ...\n"); - ecl_file_close(file); + rd_file_close(file); } remove("LARGE_FILE.UNRST"); diff --git a/lib/resdata/tests/rd_lgr_name.cpp b/lib/resdata/tests/rd_lgr_name.cpp new file mode 100644 index 0000000000..14d9f120df --- /dev/null +++ b/lib/resdata/tests/rd_lgr_name.cpp @@ -0,0 +1,28 @@ +#include +#include + +#include + +#include + +int main(int argc, char **argv) { + rd_grid_type *grid = rd_grid_alloc(argv[1]); + + int num_lgr = rd_grid_get_num_lgr(grid); + int lgr_index; + for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) { + rd_grid_type *lgr_from_index = rd_grid_iget_lgr(grid, lgr_index); + int lgr_nr = rd_grid_get_lgr_nr(lgr_from_index); + rd_grid_type *lgr_from_nr = rd_grid_get_lgr_from_lgr_nr(grid, lgr_nr); + + test_assert_ptr_equal(lgr_from_index, lgr_from_nr); + + test_assert_string_equal(rd_grid_get_lgr_name(grid, lgr_nr), + rd_grid_iget_lgr_name(grid, lgr_index)); + printf("Grid[%d:%d] : %s \n", lgr_index, lgr_nr, + rd_grid_iget_lgr_name(grid, lgr_index)); + } + rd_grid_free(grid); + + exit(0); +} diff --git a/lib/resdata/tests/rd_lgr_test.cpp b/lib/resdata/tests/rd_lgr_test.cpp new file mode 100644 index 0000000000..a20ae7881a --- /dev/null +++ b/lib/resdata/tests/rd_lgr_test.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include +#include + +#include +#include +#include + +int main(int argc, char **argv) { + const char *grid_file = argv[1]; + rd_grid_type *rd_grid = rd_grid_alloc(grid_file); + rd_file_type *rd_file = rd_file_open(grid_file, 0); + + rd_grid_test_lgr_consistency(rd_grid); + + if (rd_file_get_num_named_kw(rd_file, COORD_KW)) + test_assert_int_equal(rd_file_get_num_named_kw(rd_file, COORD_KW) - 1, + rd_grid_get_num_lgr(rd_grid)); + + rd_grid_free(rd_grid); + rd_file_close(rd_file); + exit(0); +} diff --git a/lib/ecl/tests/ecl_util_make_date_no_shift.cpp b/lib/resdata/tests/rd_make_date_no_shift.cpp similarity index 79% rename from lib/ecl/tests/ecl_util_make_date_no_shift.cpp rename to lib/resdata/tests/rd_make_date_no_shift.cpp index 20466a714e..78bd60d578 100644 --- a/lib/ecl/tests/ecl_util_make_date_no_shift.cpp +++ b/lib/resdata/tests/rd_make_date_no_shift.cpp @@ -5,10 +5,10 @@ #include #include -#include +#include void test_date(int mday, int month, int year) { - time_t t0 = ecl_util_make_date(mday, month, year); + time_t t0 = rd_make_date(mday, month, year); time_t t1 = util_make_date_utc(mday, month, year); test_assert_time_t_equal(t0, t1); @@ -16,7 +16,7 @@ void test_date(int mday, int month, int year) { void test_offset(int mday, int month, int year) { int year_offset; - ecl_util_make_date__(mday, month, year, &year_offset); + rd_make_date__(mday, month, year, &year_offset); test_assert_int_equal(0, year_offset); } diff --git a/lib/ecl/tests/ecl_util_make_date_shift.cpp b/lib/resdata/tests/rd_make_date_shift.cpp similarity index 80% rename from lib/ecl/tests/ecl_util_make_date_shift.cpp rename to lib/resdata/tests/rd_make_date_shift.cpp index ef90275bfa..b745bc39ca 100644 --- a/lib/ecl/tests/ecl_util_make_date_shift.cpp +++ b/lib/resdata/tests/rd_make_date_shift.cpp @@ -5,17 +5,17 @@ #include #include -#include +#include void test_date(int mday, int month, int year, int *year_offset) { - time_t t0 = ecl_util_make_date__(mday, month, year, year_offset); + time_t t0 = rd_make_date__(mday, month, year, year_offset); time_t t1 = util_make_date_utc(mday, month, year + *year_offset); test_assert_time_t_equal(t0, t1); } void test_offset(int mday, int month, int year, int current_offset) { int year_offset; - time_t t0 = ecl_util_make_date__(mday, month, year, &year_offset); + time_t t0 = rd_make_date__(mday, month, year, &year_offset); time_t t1 = util_make_date_utc(mday, month, year + current_offset); test_assert_time_t_equal(t0, t1); diff --git a/lib/ecl/tests/ecl_util_month_range.cpp b/lib/resdata/tests/rd_month_range.cpp similarity index 95% rename from lib/ecl/tests/ecl_util_month_range.cpp rename to lib/resdata/tests/rd_month_range.cpp index d12d3c46e3..b9cede0b21 100644 --- a/lib/ecl/tests/ecl_util_month_range.cpp +++ b/lib/resdata/tests/rd_month_range.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include void test_body(time_t_vector_type *date_list, int offset) { int i; @@ -39,7 +39,7 @@ void test_append(const char *name, time_t_vector_type *date_list, time_t date1, printf("%s ...", name); fflush(stdout); - ecl_util_append_month_range(date_list, date1, date2, force_append_end); + rd_append_month_range(date_list, date1, date2, force_append_end); // The start: test_assert_true(util_make_pure_date_utc(date1) <= @@ -64,7 +64,7 @@ void test_init(const char *name, time_t_vector_type *date_list, printf("%s ...", name); fflush(stdout); { - ecl_util_init_month_range(date_list, start_date, end_date); + rd_init_month_range(date_list, start_date, end_date); test_assert_time_t_equal(time_t_vector_get_first(date_list), util_make_pure_date_utc(start_date)); test_body(date_list, 1); diff --git a/lib/resdata/tests/rd_nnc_data_equinor_root.cpp b/lib/resdata/tests/rd_nnc_data_equinor_root.cpp new file mode 100644 index 0000000000..abf660f452 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_data_equinor_root.cpp @@ -0,0 +1,113 @@ +#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 new file mode 100644 index 0000000000..beacceb5b2 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_export.cpp @@ -0,0 +1,359 @@ +#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 new file mode 100644 index 0000000000..6cb3ee6600 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_export_get_tran.cpp @@ -0,0 +1,149 @@ +#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 new file mode 100644 index 0000000000..32fb7f7799 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_export_intersect.cpp @@ -0,0 +1,95 @@ +// #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 new file mode 100644 index 0000000000..fa4a1cdc48 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_geometry.cpp @@ -0,0 +1,62 @@ +#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/ecl/tests/ecl_nnc_index_list.cpp b/lib/resdata/tests/rd_nnc_index_list.cpp similarity index 98% rename from lib/ecl/tests/ecl_nnc_index_list.cpp rename to lib/resdata/tests/rd_nnc_index_list.cpp index 4ec6aa906f..0f49f48f96 100644 --- a/lib/ecl/tests/ecl_nnc_index_list.cpp +++ b/lib/resdata/tests/rd_nnc_index_list.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include void test_create() { nnc_index_list_type *index_list = nnc_index_list_alloc(); diff --git a/lib/resdata/tests/rd_nnc_index_list_grid.cpp b/lib/resdata/tests/rd_nnc_index_list_grid.cpp new file mode 100644 index 0000000000..6ec6ffd4f7 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_index_list_grid.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include + +int main(int argc, char **argv) { + const char *egrid_file = argv[1]; + + rd_grid_type *grid = rd_grid_alloc(egrid_file); + rd_file_type *gfile = rd_file_open(egrid_file, 0); + const rd_kw_type *nnc1_kw = rd_file_iget_named_kw(gfile, "NNC1", 0); + const rd_kw_type *nnc2_kw = rd_file_iget_named_kw(gfile, "NNC2", 0); + const int_vector_type *index_list = rd_grid_get_nnc_index_list(grid); + + { + int_vector_type *nnc = int_vector_alloc(0, 0); + + int_vector_set_many(nnc, 0, rd_kw_get_ptr(nnc1_kw), + rd_kw_get_size(nnc1_kw)); + int_vector_append_many(nnc, rd_kw_get_ptr(nnc2_kw), + rd_kw_get_size(nnc2_kw)); + int_vector_select_unique(nnc); + test_assert_int_equal(int_vector_size(index_list), + int_vector_size(nnc)); + + { + int i; + for (i = 0; i < int_vector_size(nnc); i++) + test_assert_int_equal(int_vector_iget(nnc, i) - 1, + int_vector_iget(index_list, i)); + } + int_vector_free(nnc); + } + + rd_file_close(gfile); + rd_grid_free(grid); + + exit(0); +} diff --git a/lib/ecl/tests/ecl_nnc_info_test.cpp b/lib/resdata/tests/rd_nnc_info_test.cpp similarity index 96% rename from lib/ecl/tests/ecl_nnc_info_test.cpp rename to lib/resdata/tests/rd_nnc_info_test.cpp index 02dc6ce600..085f1f1a0b 100644 --- a/lib/ecl/tests/ecl_nnc_info_test.cpp +++ b/lib/resdata/tests/rd_nnc_info_test.cpp @@ -7,10 +7,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include void test_equal() { diff --git a/lib/ecl/tests/ecl_nnc_pair.cpp b/lib/resdata/tests/rd_nnc_pair.cpp similarity index 61% rename from lib/ecl/tests/ecl_nnc_pair.cpp rename to lib/resdata/tests/rd_nnc_pair.cpp index 1811ca785c..f8f0f39e9d 100644 --- a/lib/ecl/tests/ecl_nnc_pair.cpp +++ b/lib/resdata/tests/rd_nnc_pair.cpp @@ -4,14 +4,14 @@ #include #include -#include +#include void test_pair(int grid1_1, int grid1_2, int grid2_1, int grid2_2, bool expected) { - ecl_nnc_pair_type pair1 = {grid1_1, grid1_2, 0, 0}; - ecl_nnc_pair_type pair2 = {grid2_1, grid2_2, 0, 0}; + 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(ecl_nnc_geometry_same_kw(&pair1, &pair2), expected); + test_assert_bool_equal(rd_nnc_geometry_same_kw(&pair1, &pair2), expected); } int main(int argc, char **argv) { diff --git a/lib/resdata/tests/rd_nnc_test.cpp b/lib/resdata/tests/rd_nnc_test.cpp new file mode 100644 index 0000000000..db8b29cd85 --- /dev/null +++ b/lib/resdata/tests/rd_nnc_test.cpp @@ -0,0 +1,133 @@ +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +void test_scan(const char *grid_filename) { + rd_grid_type *rd_grid = rd_grid_alloc(grid_filename); + rd_file_type *grid_file = rd_file_open(grid_filename, 0); + int block_nr; + + for (block_nr = 0; + block_nr < rd_file_get_num_named_kw(grid_file, NNCHEAD_KW); + block_nr++) { + rd_grid_type *lgr = rd_grid; + int lgr_nr; + rd_file_view_type *nnc_view = + rd_file_alloc_global_blockview(grid_file, NNCHEAD_KW, block_nr); + { + if (block_nr > 0) + lgr = rd_grid_iget_lgr(rd_grid, block_nr - 1); + lgr_nr = rd_grid_get_lgr_nr(lgr); + + /* Internal nnc */ + { + 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); + int i; + for (i = 0; i < rd_kw_get_size(nnc1_kw); i++) { + const int g1 = rd_kw_iget_int(nnc1_kw, i) - 1; + const int g2 = rd_kw_iget_int(nnc2_kw, i) - 1; + + if (g2 < + rd_grid_get_global_size( + lgr)) { // Skipping matrix <-> fracture link in dual poro. + const nnc_info_type *nnc_info = + rd_grid_get_cell_nnc_info1(lgr, g1); + const std::vector &index_list = + nnc_info_get_grid_index_list(nnc_info, lgr_nr); + test_assert_not_NULL(nnc_info); + test_assert_int_not_equal( + -1, vector_util_index(index_list, g2)); + } + } + } + } + } + + /* Global -> lgr */ + { + if (rd_file_view_has_kw(nnc_view, NNCG_KW)) { + rd_kw_type *nnchead_kw = + rd_file_view_iget_named_kw(nnc_view, NNCHEAD_KW, 0); + rd_kw_type *nncg_kw = + rd_file_view_iget_named_kw(nnc_view, NNCG_KW, 0); + rd_kw_type *nncl_kw = + rd_file_view_iget_named_kw(nnc_view, NNCL_KW, 0); + int i; + int lgr_nr = rd_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX); + for (i = 0; i < rd_kw_get_size(nncg_kw); i++) { + const int g = rd_kw_iget_int(nncg_kw, i) - 1; + const int l = rd_kw_iget_int(nncl_kw, i) - 1; + + const nnc_info_type *nnc_info = + rd_grid_get_cell_nnc_info1(rd_grid, g); + test_assert_not_NULL(nnc_info); + { + const std::vector &index_list = + nnc_info_get_grid_index_list(nnc_info, lgr_nr); + test_assert_true( + nnc_info_has_grid_index_list(nnc_info, lgr_nr)); + test_assert_int_not_equal( + -1, vector_util_index(index_list, l)); + } + } + } + } + + /* Amalgamated: LGR -> LGR */ + { + if (rd_file_view_has_kw(nnc_view, NNCHEADA_KW)) { + rd_kw_type *nncheada_kw = + rd_file_view_iget_named_kw(nnc_view, NNCHEADA_KW, 0); + rd_kw_type *nnc1_kw = + rd_file_view_iget_named_kw(nnc_view, NNA1_KW, 0); + rd_kw_type *nnc2_kw = + rd_file_view_iget_named_kw(nnc_view, NNA2_KW, 0); + int lgr_nr1 = rd_kw_iget_int(nncheada_kw, NNCHEADA_ILOC1_INDEX); + int lgr_nr2 = rd_kw_iget_int(nncheada_kw, NNCHEADA_ILOC2_INDEX); + + rd_grid_type *lgr1 = + rd_grid_get_lgr_from_lgr_nr(rd_grid, lgr_nr1); + for (int i = 0; i < rd_kw_get_size(nnc1_kw); i++) { + const int g1 = rd_kw_iget_int(nnc1_kw, i) - 1; + const int g2 = rd_kw_iget_int(nnc2_kw, i) - 1; + + const nnc_info_type *nnc_info = + rd_grid_get_cell_nnc_info1(lgr1, g1); + const std::vector &index_list = + nnc_info_get_grid_index_list(nnc_info, lgr_nr2); + test_assert_not_NULL(nnc_info); + test_assert_int_not_equal( + -1, vector_util_index(index_list, g2)); + } + } + } + + rd_file_view_free(nnc_view); + } +} + +int main(int argc, char **argv) { + int iarg; + for (iarg = 1; iarg < argc; iarg++) { + printf("Checking file: %s \n", argv[iarg]); + test_scan(argv[iarg]); + } + + exit(0); +} diff --git a/lib/ecl/tests/ecl_nnc_vector.cpp b/lib/resdata/tests/rd_nnc_vector.cpp similarity index 98% rename from lib/ecl/tests/ecl_nnc_vector.cpp rename to lib/resdata/tests/rd_nnc_vector.cpp index d7085cebdc..5a3595ceab 100644 --- a/lib/ecl/tests/ecl_nnc_vector.cpp +++ b/lib/resdata/tests/rd_nnc_vector.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include void test_basic() { int lgr_nr = 100; diff --git a/lib/resdata/tests/rd_path_access.cpp b/lib/resdata/tests/rd_path_access.cpp new file mode 100644 index 0000000000..bf8fb997cc --- /dev/null +++ b/lib/resdata/tests/rd_path_access.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +#include +#include +#include + +#include + +void test_relative_access() { + rd::util::TestArea ta("rd_access"); + test_assert_false(rd_path_access("No/directory/does/not/exist")); + + util_make_path("path"); + test_assert_true(rd_path_access("path")); + test_assert_true(rd_path_access("path/FILE_DOES_NOT_EXIST")); + + { + FILE *f = util_fopen("path/file", "w"); + fprintf(f, "Hello\n"); + fclose(f); + } + test_assert_true(rd_path_access("path/file")); + chmod("path/file", 0); + test_assert_false(rd_path_access("path/file")); + + test_assert_true(rd_path_access("ECLIPSE_CASE")); +} + +int main(int argc, char **argv) { test_relative_access(); } diff --git a/lib/resdata/tests/rd_region.cpp b/lib/resdata/tests/rd_region.cpp new file mode 100644 index 0000000000..6447b8d657 --- /dev/null +++ b/lib/resdata/tests/rd_region.cpp @@ -0,0 +1,49 @@ +#include +#include + +#include + +#include +#include + +void test_list(int volume, int nactive, rd_region_type *region) { + const int_vector_type *active_list; + const int_vector_type *global_list; + active_list = rd_region_get_active_list(region); + global_list = rd_region_get_global_list(region); + test_assert_int_equal(nactive, int_vector_size(active_list)); + test_assert_int_equal(volume, int_vector_size(global_list)); + + rd_region_deselect_all(region); + active_list = rd_region_get_active_list(region); + global_list = rd_region_get_global_list(region); + test_assert_int_equal(0, int_vector_size(active_list)); + test_assert_int_equal(0, int_vector_size(global_list)); +} + +void test_slice(const rd_grid_type *grid) { + int nx = rd_grid_get_nx(grid); + int ny = rd_grid_get_ny(grid); + int nz = rd_grid_get_nz(grid); + int nactive = rd_grid_get_nactive(grid); + rd_region_type *region = rd_region_alloc(grid, false); + + rd_region_select_i1i2(region, 0, nx - 1); + test_list(nx * ny * nz, nactive, region); + rd_region_select_j1j2(region, 0, ny - 1); + test_list(nx * ny * nz, nactive, region); + rd_region_select_k1k2(region, 0, nz - 1); + test_list(nx * ny * nz, nactive, region); + + rd_region_free(region); +} + +int main(int argc, char **argv) { + const char *grid_file = argv[1]; + rd_grid_type *grid = rd_grid_alloc(grid_file); + + test_slice(grid); + + rd_grid_free(grid); + exit(0); +} diff --git a/lib/resdata/tests/rd_region2region.cpp b/lib/resdata/tests/rd_region2region.cpp new file mode 100644 index 0000000000..87bb979ef7 --- /dev/null +++ b/lib/resdata/tests/rd_region2region.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include +#include + +void has_r2r_key(const rd_sum_type *rd_sum) { + test_assert_true(rd_sum_has_key(rd_sum, "RGF:393217")); + test_assert_true(rd_sum_has_key(rd_sum, "RGF:1-2")); + test_assert_true(rd_sum_has_key(rd_sum, "ROF:524291")); + test_assert_true(rd_sum_has_key(rd_sum, "RWF:393222")); + test_assert_true(rd_sum_has_key(rd_sum, "RWF:6-2")); + test_assert_true(rd_sum_has_key(rd_sum, "ROF:3-6")); + test_assert_true(rd_sum_has_key(rd_sum, "RNLF:458753")); + test_assert_true(rd_sum_has_key(rd_sum, "RNLF:1-4")); +} + +void get_unit(const rd_sum_type *rd_sum) { + test_assert_string_equal(rd_sum_get_unit(rd_sum, "RGF:1-2"), "GFLOW"); + test_assert_string_equal(rd_sum_get_unit(rd_sum, "ROF:3-6"), "OFLOW"); + test_assert_string_equal(rd_sum_get_unit(rd_sum, "RWF:6-2"), "WFLOW"); + test_assert_string_equal(rd_sum_get_unit(rd_sum, "RNLF:1-4"), "NLFLOW"); +} + +void get_var_params_index(const rd_sum_type *rd_sum) { + test_assert_int_equal( + rd_sum_get_general_var_params_index(rd_sum, "RGF:1-2"), 21917); + test_assert_int_equal( + rd_sum_get_general_var_params_index(rd_sum, "ROF:3-6"), 21918); + test_assert_int_equal( + rd_sum_get_general_var_params_index(rd_sum, "RWF:6-2"), 21919); + test_assert_int_equal( + rd_sum_get_general_var_params_index(rd_sum, "RNLF:1-4"), 21920); +} + +int main(int argc, char **argv) { + + const char *headerfile = argv[1]; + + rd_sum_type *rd_sum = rd_sum_fread_alloc_case(headerfile, ":"); + + if (rd_sum) { + has_r2r_key(rd_sum); + get_unit(rd_sum); + get_var_params_index(rd_sum); + } else + test_error_exit("rd_region2region_test: Test file not read correctly"); + + if (rd_sum) + rd_sum_free(rd_sum); + + exit(0); +} diff --git a/lib/ecl/tests/ecl_restart_test.cpp b/lib/resdata/tests/rd_restart_test.cpp similarity index 74% rename from lib/ecl/tests/ecl_restart_test.cpp rename to lib/resdata/tests/rd_restart_test.cpp index d590f79e6f..b8d669d89a 100644 --- a/lib/ecl/tests/ecl_restart_test.cpp +++ b/lib/resdata/tests/rd_restart_test.cpp @@ -3,12 +3,12 @@ #include -#include +#include -bool test_get(ecl_file_type *rst_file, int day, int month, int year, +bool test_get(rd_file_type *rst_file, int day, int month, int year, int expected_index) { - time_t sim_time = ecl_util_make_date(day, month, year); - int seqnum_index = ecl_file_get_restart_index(rst_file, sim_time); + time_t sim_time = rd_make_date(day, month, year); + int seqnum_index = rd_file_get_restart_index(rst_file, sim_time); if (seqnum_index == expected_index) return true; else { @@ -22,7 +22,7 @@ int main(int argc, char **argv) { bool OK = true; const char *unrst_file = argv[1]; - ecl_file_type *rst_file = ecl_file_open(unrst_file, 0); + rd_file_type *rst_file = rd_file_open(unrst_file, 0); OK = OK && test_get(rst_file, 1, 1, 1998, -1); OK = OK && test_get(rst_file, 17, 9, 2003, -1); diff --git a/lib/resdata/tests/rd_rft.cpp b/lib/resdata/tests/rd_rft.cpp new file mode 100644 index 0000000000..c2790112aa --- /dev/null +++ b/lib/resdata/tests/rd_rft.cpp @@ -0,0 +1,162 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +void test_rft_read_write(const char *rft_file) { + rd_rft_file_type *rft = rd_rft_file_alloc(rft_file); + rd_rft_node_type **nodes = + (rd_rft_node_type **)malloc(sizeof(rd_rft_node_type *) * 3); + int size = rd_rft_file_get_size(rft); + for (int i = 0; i < size; i++) { + rd_rft_node_type *rft_node = rd_rft_file_iget_node(rft, i); + nodes[i] = rft_node; + } + rd_rft_node_type *old_node = rd_rft_file_iget_node(rft, 0); + rd_rft_node_type *new_node = + rd_rft_node_alloc_new("DUMMY", "R", rd_rft_node_get_date(old_node), + rd_rft_node_get_days(old_node)); + nodes[2] = new_node; + rd::util::TestArea ta("rft"); + + rd_rft_file_update("eclipse.rft", nodes, 3, RD_METRIC_UNITS); + free(nodes); +} + +// Hardcoded GURBAT values +void test_rft(const char *rft_file) { + rd_rft_file_type *rft = rd_rft_file_alloc(rft_file); + rd_rft_node_type *rft_node = rd_rft_file_iget_node(rft, 0); + + test_assert_true(rd_rft_node_is_RFT(rft_node)); + test_assert_int_equal(14, rd_rft_node_get_size(rft_node)); + test_assert_false(rd_rft_node_is_MSW(rft_node)); + + test_assert_double_equal(260.6111, rd_rft_node_iget_pressure(rft_node, 0)); + test_assert_double_equal(0.0581993, rd_rft_node_iget_soil(rft_node, 0)); + test_assert_double_equal(0.9405648, rd_rft_node_iget_swat(rft_node, 0)); + test_assert_double_equal(0.00123579, rd_rft_node_iget_sgas(rft_node, 0)); + + { + int i, j, k; + + rd_rft_node_iget_ijk(rft_node, 0, &i, &j, &k); + test_assert_int_equal(32, i); + test_assert_int_equal(53, j); + test_assert_int_equal(0, k); + + rd_rft_node_iget_ijk(rft_node, 13, &i, &j, &k); + test_assert_int_equal(32, i); + test_assert_int_equal(54, j); + test_assert_int_equal(12, k); + + for (i = 0; i < rd_rft_node_get_size(rft_node); i++) { + const rd_rft_cell_type *cell1 = rd_rft_node_iget_cell(rft_node, i); + const rd_rft_cell_type *cell2 = + rd_rft_node_iget_cell_sorted(rft_node, i); + + test_assert_ptr_equal(cell1, cell2); + } + } + rd_rft_file_free(rft); +} + +void test_plt_msw(const char *plt_file) { + rd_rft_file_type *plt = rd_rft_file_alloc(plt_file); + rd_rft_node_type *plt_node = rd_rft_file_iget_node(plt, 11); + + test_assert_true(rd_rft_node_is_PLT(plt_node)); + test_assert_true(rd_rft_node_is_MSW(plt_node)); + test_assert_int_equal(22, rd_rft_node_get_size(plt_node)); + { + int i; + for (i = 1; i < rd_rft_node_get_size(plt_node); i++) { + const rd_rft_cell_type *prev_cell = + rd_rft_node_iget_cell(plt_node, i - 1); + const rd_rft_cell_type *this_cell = + rd_rft_node_iget_cell(plt_node, i); + + test_assert_true(rd_rft_cell_get_connection_start(prev_cell) < + rd_rft_cell_get_connection_start(this_cell)); + test_assert_true(rd_rft_cell_get_connection_end(prev_cell) < + rd_rft_cell_get_connection_end(this_cell)); + } + } + + rd_rft_file_free(plt); +} + +// Hardcoded values from a test case with a PLT. +void test_plt(const char *plt_file) { + rd_rft_file_type *plt = rd_rft_file_alloc(plt_file); + rd_rft_node_type *plt_node = rd_rft_file_iget_node(plt, 11); + + test_assert_true(rd_rft_node_is_PLT(plt_node)); + test_assert_false(rd_rft_node_is_MSW(plt_node)); + test_assert_int_equal(22, rd_rft_node_get_size(plt_node)); + + test_assert_double_equal(244.284, rd_rft_node_iget_pressure(plt_node, 0)); + test_assert_double_equal(167.473, rd_rft_node_iget_orat(plt_node, 0)); + test_assert_double_equal(41682.2, rd_rft_node_iget_grat(plt_node, 0)); + test_assert_double_equal(0.958927, rd_rft_node_iget_wrat(plt_node, 0)); + + { + int i, j, k; + + rd_rft_node_iget_ijk(plt_node, 0, &i, &j, &k); + test_assert_int_equal(39, i); + test_assert_int_equal(33, j); + test_assert_int_equal(16, k); + + rd_rft_node_iget_ijk(plt_node, 21, &i, &j, &k); + test_assert_int_equal(44, i); + test_assert_int_equal(34, j); + test_assert_int_equal(7, k); + + for (i = 0; i < rd_rft_node_get_size(plt_node); i++) { + const rd_rft_cell_type *cell1 = rd_rft_node_iget_cell(plt_node, i); + const rd_rft_cell_type *cell2 = + rd_rft_node_iget_cell_sorted(plt_node, i); + + test_assert_ptr_equal(cell1, cell2); + } + } + + rd_rft_file_free(plt); +} + +void test_simple_load_rft(const char *filename) { + rd_rft_file_type *rft_file = rd_rft_file_alloc_case(filename); + rd_rft_file_free(rft_file); +} + +int main(int argc, char **argv) { + const char *rft_file = argv[1]; + const char *mode_string = argv[2]; + util_install_signals(); + + if (strcmp(mode_string, "RFT") == 0) + test_rft(rft_file); + else if (strcmp(mode_string, "RFT_RW") == 0) + test_rft_read_write(rft_file); + else if (strcmp(mode_string, "PLT") == 0) + test_plt(rft_file); + else if (strcmp(mode_string, "MSW-PLT") == 0) + test_plt_msw(rft_file); + else if (strcmp(mode_string, "SIMPLE") == 0) + test_simple_load_rft(rft_file); + else + test_error_exit( + "Second argument:%s not recognized. Valid values are: RFT and PLT", + mode_string); + + exit(0); +} diff --git a/lib/resdata/tests/rd_rft_cell.cpp b/lib/resdata/tests/rd_rft_cell.cpp new file mode 100644 index 0000000000..c4a37afba8 --- /dev/null +++ b/lib/resdata/tests/rd_rft_cell.cpp @@ -0,0 +1,138 @@ +#include +#include + +#include +#include +#include + +#include +#include + +void test_rft_cell() { + const int i = 10; + const int j = 11; + const int k = 12; + + const double depth = 100; + const double pressure = 200; + const double swat = 0.25; + const double sgas = 0.35; + + rd_rft_cell_type *cell = + rd_rft_cell_alloc_RFT(i, j, k, depth, pressure, swat, sgas); + + test_assert_int_equal(i, rd_rft_cell_get_i(cell)); + test_assert_int_equal(j, rd_rft_cell_get_j(cell)); + test_assert_int_equal(k, rd_rft_cell_get_k(cell)); + + { + int ii, jj, kk; + rd_rft_cell_get_ijk(cell, &ii, &jj, &kk); + test_assert_int_equal(i, ii); + test_assert_int_equal(j, jj); + test_assert_int_equal(k, kk); + } + + test_assert_double_equal(depth, rd_rft_cell_get_depth(cell)); + test_assert_double_equal(pressure, rd_rft_cell_get_pressure(cell)); + test_assert_double_equal(swat, rd_rft_cell_get_swat(cell)); + test_assert_double_equal(sgas, rd_rft_cell_get_sgas(cell)); + test_assert_double_equal(1 - (swat + sgas), rd_rft_cell_get_soil(cell)); + + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_orat(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_grat(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_wrat(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_flowrate(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_connection_start(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_connection_end(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_oil_flowrate(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_gas_flowrate(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_water_flowrate(cell)); + + rd_rft_cell_free(cell); + { + rd_rft_cell_type *cell = + rd_rft_cell_alloc_RFT(i, j, k, depth, pressure, swat, sgas); + + test_assert_true(rd_rft_cell_ijk_equal(cell, i, j, k)); + test_assert_false(rd_rft_cell_ijk_equal(cell, i, j, k + 1)); + + rd_rft_cell_free__(cell); + } +} + +void test_plt_cell() { + const int i = 10; + const int j = 11; + const int k = 12; + + const double depth = 100; + const double pressure = 200; + const double orat = 0.25; + const double grat = 0.35; + const double wrat = 0.45; + const double flowrate = 100.0; + const double connection_start = 891; + const double connection_end = 979; + const double oil_flowrate = 0.891; + const double gas_flowrate = 7771; + const double water_flowrate = 77614; + + rd_rft_cell_type *cell = rd_rft_cell_alloc_PLT( + i, j, k, depth, pressure, orat, grat, wrat, connection_start, + connection_end, flowrate, oil_flowrate, gas_flowrate, water_flowrate); + + test_assert_int_equal(i, rd_rft_cell_get_i(cell)); + test_assert_int_equal(j, rd_rft_cell_get_j(cell)); + test_assert_int_equal(k, rd_rft_cell_get_k(cell)); + + { + int ii, jj, kk; + rd_rft_cell_get_ijk(cell, &ii, &jj, &kk); + test_assert_int_equal(i, ii); + test_assert_int_equal(j, jj); + test_assert_int_equal(k, kk); + } + + test_assert_double_equal(depth, rd_rft_cell_get_depth(cell)); + test_assert_double_equal(pressure, rd_rft_cell_get_pressure(cell)); + + test_assert_double_equal(orat, rd_rft_cell_get_orat(cell)); + test_assert_double_equal(grat, rd_rft_cell_get_grat(cell)); + test_assert_double_equal(wrat, rd_rft_cell_get_wrat(cell)); + test_assert_double_equal(connection_start, + rd_rft_cell_get_connection_start(cell)); + test_assert_double_equal(connection_end, + rd_rft_cell_get_connection_end(cell)); + test_assert_double_equal(flowrate, rd_rft_cell_get_flowrate(cell)); + + test_assert_double_equal(oil_flowrate, rd_rft_cell_get_oil_flowrate(cell)); + test_assert_double_equal(gas_flowrate, rd_rft_cell_get_gas_flowrate(cell)); + test_assert_double_equal(water_flowrate, + rd_rft_cell_get_water_flowrate(cell)); + + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_swat(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_sgas(cell)); + test_assert_double_equal(RD_RFT_CELL_INVALID_VALUE, + rd_rft_cell_get_soil(cell)); + + rd_rft_cell_free(cell); +} + +int main(int argc, char **argv) { + + test_rft_cell(); + test_plt_cell(); + exit(0); +} diff --git a/lib/resdata/tests/rd_rst_file.cpp b/lib/resdata/tests/rd_rst_file.cpp new file mode 100644 index 0000000000..94f47ee5fd --- /dev/null +++ b/lib/resdata/tests/rd_rst_file.cpp @@ -0,0 +1,145 @@ +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +void write_keyword(fortio_type *fortio, const char *kw, + rd_data_type data_type) { + rd_kw_type *rd_kw = rd_kw_alloc(kw, 1000, data_type); + rd_kw_fwrite(rd_kw, fortio); + rd_kw_free(rd_kw); +} + +void write_seqnum(fortio_type *fortio, int report_step) { + rd_kw_type *rd_kw = rd_kw_alloc(SEQNUM_KW, 1, RD_INT); + rd_kw_iset_int(rd_kw, 0, report_step); + rd_kw_fwrite(rd_kw, fortio); + rd_kw_free(rd_kw); +} + +void test_empty() { + rd_rst_file_type *rst_file = rd_rst_file_open_write_seek("EMPTY.UNRST", 0); + test_assert_int_equal(rd_rst_file_ftell(rst_file), 0); + rd_rst_file_close(rst_file); +} + +void test_file(const char *src_file, const char *target_file, int report_step, + offset_type expected_offset) { + util_copy_file(src_file, target_file); + { + rd_rst_file_type *rst_file = + rd_rst_file_open_write_seek(target_file, report_step); + test_assert_true(rd_rst_file_ftell(rst_file) == expected_offset); + rd_rst_file_close(rst_file); + test_assert_true(util_file_size(target_file) == + (size_t)expected_offset); + } +} + +void test_Xfile() { + rd::util::TestArea ta("xfile"); + { + fortio_type *f = + fortio_open_writer("TEST.X0010", false, RD_ENDIAN_FLIP); + + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + fortio_fclose(f); + } + test_file("TEST.X0010", "FILE.X0010", 10, 0); +} + +void test_UNRST0() { + rd::util::TestArea ta("rst-file"); + offset_type pos10; + offset_type pos20; + offset_type pos_end; + { + fortio_type *f = + fortio_open_writer("TEST.UNRST", false, RD_ENDIAN_FLIP); + write_seqnum(f, 0); + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + pos10 = fortio_ftell(f); + write_seqnum(f, 10); + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + pos20 = fortio_ftell(f); + write_seqnum(f, 20); + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + pos_end = fortio_ftell(f); + fortio_fclose(f); + } + test_file("TEST.UNRST", "FILE.UNRST", 0, 0); + test_file("TEST.UNRST", "FILE.UNRST", 5, pos10); + test_file("TEST.UNRST", "FILE.UNRST", 10, pos10); + test_file("TEST.UNRST", "FILE.UNRST", 15, pos20); + test_file("TEST.UNRST", "FILE.UNRST", 20, pos20); + test_file("TEST.UNRST", "FILE.UNRST", 25, pos_end); +} + +void test_UNRST1() { + rd::util::TestArea ta("rst-file"); + offset_type pos5; + offset_type pos10; + offset_type pos20; + offset_type pos_end; + { + fortio_type *f = + fortio_open_writer("TEST.UNRST", false, RD_ENDIAN_FLIP); + pos5 = fortio_ftell(f); + write_seqnum(f, 5); + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + pos10 = fortio_ftell(f); + write_seqnum(f, 10); + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + pos20 = fortio_ftell(f); + write_seqnum(f, 20); + write_keyword(f, "INTEHEAD", RD_INT); + write_keyword(f, "PRESSURE", RD_FLOAT); + write_keyword(f, "SWAT", RD_FLOAT); + + pos_end = fortio_ftell(f); + fortio_fclose(f); + } + test_file("TEST.UNRST", "FILE.UNRST", 0, 0); + test_file("TEST.UNRST", "FILE.UNRST", 1, 0); + test_file("TEST.UNRST", "FILE.UNRST", 5, pos5); + test_file("TEST.UNRST", "FILE.UNRST", 10, pos10); + test_file("TEST.UNRST", "FILE.UNRST", 15, pos20); + test_file("TEST.UNRST", "FILE.UNRST", 20, pos20); + test_file("TEST.UNRST", "FILE.UNRST", 25, pos_end); +} + +int main(int argc, char **argv) { + test_empty(); + test_Xfile(); + test_UNRST0(); + test_UNRST1(); +} diff --git a/lib/ecl/tests/ecl_rsthead.cpp b/lib/resdata/tests/rd_rsthead.cpp similarity index 60% rename from lib/ecl/tests/ecl_rsthead.cpp rename to lib/resdata/tests/rd_rsthead.cpp index 1eea183793..a3ea5bbb5b 100644 --- a/lib/ecl/tests/ecl_rsthead.cpp +++ b/lib/resdata/tests/rd_rsthead.cpp @@ -3,46 +3,46 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include void test_file(const char *filename, int occurence, bool exists, - const ecl_rsthead_type *true_header) { - int report_step = ecl_util_filename_report_nr(filename); - ecl_file_type *rst_file = ecl_file_open(filename, 0); - ecl_file_enum file_type = ecl_util_get_file_type(filename, NULL, NULL); - ecl_file_view_type *rst_view; - ecl_rsthead_type *rst_head; + const rd_rsthead_type *true_header) { + int report_step = rd_filename_report_nr(filename); + rd_file_type *rst_file = rd_file_open(filename, 0); + rd_file_enum file_type = rd_get_file_type(filename, NULL, NULL); + rd_file_view_type *rst_view; + rd_rsthead_type *rst_head; - if (file_type == ECL_RESTART_FILE) - rst_view = ecl_file_get_global_view(rst_file); + if (file_type == RD_RESTART_FILE) + rst_view = rd_file_get_global_view(rst_file); else - rst_view = ecl_file_get_restart_view(rst_file, occurence, -1, -1, -1); + rst_view = rd_file_get_restart_view(rst_file, occurence, -1, -1, -1); if (exists) { test_assert_not_NULL(rst_view); - rst_head = ecl_rsthead_alloc(rst_view, report_step); + rst_head = rd_rsthead_alloc(rst_view, report_step); test_assert_not_NULL(rst_head); if (occurence == 0) { - ecl_rsthead_type *rst_head0 = - ecl_rsthead_alloc(rst_view, report_step); + rd_rsthead_type *rst_head0 = + rd_rsthead_alloc(rst_view, report_step); - test_assert_true(ecl_rsthead_equal(rst_head, rst_head0)); - ecl_rsthead_free(rst_head0); + test_assert_true(rd_rsthead_equal(rst_head, rst_head0)); + rd_rsthead_free(rst_head0); } - test_assert_true(ecl_rsthead_equal(rst_head, true_header)); + test_assert_true(rd_rsthead_equal(rst_head, true_header)); - ecl_rsthead_free(rst_head); + rd_rsthead_free(rst_head); } else test_assert_NULL(rst_view); } int main(int argc, char **argv) { - ecl_rsthead_type true1; + rd_rsthead_type true1; true1.report_step = 1; true1.day = 1; true1.year = 2000; @@ -67,7 +67,7 @@ int main(int argc, char **argv) { true1.dualp = 0; true1.sim_days = 0; - ecl_rsthead_type true2; + rd_rsthead_type true2; true2.report_step = 5; true2.day = 22; true2.year = 1990; diff --git a/lib/resdata/tests/rd_smspec.cpp b/lib/resdata/tests/rd_smspec.cpp new file mode 100644 index 0000000000..71451537a4 --- /dev/null +++ b/lib/resdata/tests/rd_smspec.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include +#include +#include + +void test_copy(const rd_smspec_type *smspec1) { + rd_sum_type *rd_sum2 = + rd_sum_alloc_writer("CASE", false, true, ":", 0, true, 100, 100, 100); + const rd_smspec_type *smspec2 = rd_sum_get_smspec(rd_sum2); + for (int i = 0; i < rd_smspec_num_nodes(smspec1); i++) { + const rd::smspec_node &node = + rd_smspec_iget_node_w_node_index(smspec1, i); + rd_sum_add_smspec_node(rd_sum2, &node); + } + test_assert_true(rd_smspec_equal(smspec1, smspec2)); + rd_sum_free(rd_sum2); +} + +int main(int argc, char **argv) { + const char *case1 = argv[1]; + const char *case2 = argv[2]; + rd_smspec_type *smspec1 = rd_smspec_fread_alloc(case1, ":", false); + rd_smspec_type *smspec2 = rd_smspec_fread_alloc(case2, ":", false); + + test_assert_true(rd_smspec_equal(smspec2, smspec2)); + test_assert_true(rd_smspec_equal(smspec1, smspec1)); + + test_assert_false(rd_smspec_equal(smspec1, smspec2)); + test_assert_false(rd_smspec_equal(smspec2, smspec1)); + + rd_smspec_free(smspec1); + rd_smspec_free(smspec2); +} diff --git a/lib/ecl/tests/ecl_smspec_node.cpp b/lib/resdata/tests/rd_smspec_node.cpp similarity index 60% rename from lib/ecl/tests/ecl_smspec_node.cpp rename to lib/resdata/tests/rd_smspec_node.cpp index 921a340917..6ca5458fbb 100644 --- a/lib/ecl/tests/ecl_smspec_node.cpp +++ b/lib/resdata/tests/rd_smspec_node.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include static void test_identify_rate_variable() { /* @@ -105,93 +105,90 @@ static void test_identify_total_variable() { NOTE: Not all of the following vectors are actual Eclipse vectors, but they are patterns that are supposed to be recognized as (likely) totals. */ - test_assert_true(smspec_node_identify_total("ROPT", ECL_SMSPEC_REGION_VAR)); - test_assert_true(smspec_node_identify_total("WOIT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GOVPT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FOVIT", ECL_SMSPEC_FIELD_VAR)); + test_assert_true(smspec_node_identify_total("ROPT", RD_SMSPEC_REGION_VAR)); + test_assert_true(smspec_node_identify_total("WOIT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GOVPT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FOVIT", RD_SMSPEC_FIELD_VAR)); test_assert_true( - smspec_node_identify_total("COMT", ECL_SMSPEC_COMPLETION_VAR)); - - test_assert_true(smspec_node_identify_total("RGPT", ECL_SMSPEC_REGION_VAR)); - test_assert_true(smspec_node_identify_total("WGIT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GGVPT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FGVIT", ECL_SMSPEC_FIELD_VAR)); - test_assert_true(smspec_node_identify_total("WGMT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GWGPT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FWGPT", ECL_SMSPEC_FIELD_VAR)); - - test_assert_true(smspec_node_identify_total("RWPT", ECL_SMSPEC_REGION_VAR)); - test_assert_true(smspec_node_identify_total("WWIT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GWVPT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FWVIT", ECL_SMSPEC_FIELD_VAR)); - test_assert_true(smspec_node_identify_total("WWMT", ECL_SMSPEC_WELL_VAR)); - - test_assert_true(smspec_node_identify_total("RLPT", ECL_SMSPEC_REGION_VAR)); - test_assert_true(smspec_node_identify_total("GVPT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FVIT", ECL_SMSPEC_FIELD_VAR)); - - test_assert_true(smspec_node_identify_total("WRGT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GEGT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FEXGT", ECL_SMSPEC_FIELD_VAR)); + smspec_node_identify_total("COMT", RD_SMSPEC_COMPLETION_VAR)); + + test_assert_true(smspec_node_identify_total("RGPT", RD_SMSPEC_REGION_VAR)); + test_assert_true(smspec_node_identify_total("WGIT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GGVPT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FGVIT", RD_SMSPEC_FIELD_VAR)); + test_assert_true(smspec_node_identify_total("WGMT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GWGPT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FWGPT", RD_SMSPEC_FIELD_VAR)); + + test_assert_true(smspec_node_identify_total("RWPT", RD_SMSPEC_REGION_VAR)); + test_assert_true(smspec_node_identify_total("WWIT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GWVPT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FWVIT", RD_SMSPEC_FIELD_VAR)); + test_assert_true(smspec_node_identify_total("WWMT", RD_SMSPEC_WELL_VAR)); + + test_assert_true(smspec_node_identify_total("RLPT", RD_SMSPEC_REGION_VAR)); + test_assert_true(smspec_node_identify_total("GVPT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FVIT", RD_SMSPEC_FIELD_VAR)); + + test_assert_true(smspec_node_identify_total("WRGT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GEGT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FEXGT", RD_SMSPEC_FIELD_VAR)); test_assert_true( - smspec_node_identify_total("CSGT", ECL_SMSPEC_COMPLETION_VAR)); + smspec_node_identify_total("CSGT", RD_SMSPEC_COMPLETION_VAR)); test_assert_true( - smspec_node_identify_total("LWGST", ECL_SMSPEC_LOCAL_WELL_VAR)); + smspec_node_identify_total("LWGST", RD_SMSPEC_LOCAL_WELL_VAR)); test_assert_true( - smspec_node_identify_total("LCFGT", ECL_SMSPEC_LOCAL_COMPLETION_VAR)); - test_assert_true(smspec_node_identify_total("WGIMT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GGCT", ECL_SMSPEC_GROUP_VAR)); - - test_assert_true(smspec_node_identify_total("RNPT", ECL_SMSPEC_REGION_VAR)); - test_assert_true(smspec_node_identify_total("WNIT", ECL_SMSPEC_WELL_VAR)); - test_assert_true(smspec_node_identify_total("GCPT", ECL_SMSPEC_GROUP_VAR)); - test_assert_true(smspec_node_identify_total("FCIT", ECL_SMSPEC_FIELD_VAR)); + smspec_node_identify_total("LCFGT", RD_SMSPEC_LOCAL_COMPLETION_VAR)); + test_assert_true(smspec_node_identify_total("WGIMT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GGCT", RD_SMSPEC_GROUP_VAR)); + + test_assert_true(smspec_node_identify_total("RNPT", RD_SMSPEC_REGION_VAR)); + test_assert_true(smspec_node_identify_total("WNIT", RD_SMSPEC_WELL_VAR)); + test_assert_true(smspec_node_identify_total("GCPT", RD_SMSPEC_GROUP_VAR)); + test_assert_true(smspec_node_identify_total("FCIT", RD_SMSPEC_FIELD_VAR)); test_assert_true( - smspec_node_identify_total("CSIT", ECL_SMSPEC_COMPLETION_VAR)); + smspec_node_identify_total("CSIT", RD_SMSPEC_COMPLETION_VAR)); test_assert_true( - smspec_node_identify_total("LWSPT", ECL_SMSPEC_LOCAL_WELL_VAR)); + smspec_node_identify_total("LWSPT", RD_SMSPEC_LOCAL_WELL_VAR)); test_assert_true( - smspec_node_identify_total("LCTIT", ECL_SMSPEC_LOCAL_COMPLETION_VAR)); - test_assert_true(smspec_node_identify_total("WTPT", ECL_SMSPEC_WELL_VAR)); + smspec_node_identify_total("LCTIT", RD_SMSPEC_LOCAL_COMPLETION_VAR)); + test_assert_true(smspec_node_identify_total("WTPT", RD_SMSPEC_WELL_VAR)); - test_assert_true( - smspec_node_identify_total("SOFT", ECL_SMSPEC_SEGMENT_VAR)); - test_assert_true( - smspec_node_identify_total("SGFT", ECL_SMSPEC_SEGMENT_VAR)); - test_assert_true( - smspec_node_identify_total("SWFT", ECL_SMSPEC_SEGMENT_VAR)); + test_assert_true(smspec_node_identify_total("SOFT", RD_SMSPEC_SEGMENT_VAR)); + test_assert_true(smspec_node_identify_total("SGFT", RD_SMSPEC_SEGMENT_VAR)); + test_assert_true(smspec_node_identify_total("SWFT", RD_SMSPEC_SEGMENT_VAR)); test_assert_true( - smspec_node_identify_total("RGFT", ECL_SMSPEC_REGION_2_REGION_VAR)); + smspec_node_identify_total("RGFT", RD_SMSPEC_REGION_2_REGION_VAR)); test_assert_true( - smspec_node_identify_total("RWFT-", ECL_SMSPEC_REGION_2_REGION_VAR)); + smspec_node_identify_total("RWFT-", RD_SMSPEC_REGION_2_REGION_VAR)); test_assert_true( - smspec_node_identify_total("RNLFT", ECL_SMSPEC_REGION_2_REGION_VAR)); + smspec_node_identify_total("RNLFT", RD_SMSPEC_REGION_2_REGION_VAR)); test_assert_true( - smspec_node_identify_total("RNLFT+", ECL_SMSPEC_REGION_2_REGION_VAR)); + smspec_node_identify_total("RNLFT+", RD_SMSPEC_REGION_2_REGION_VAR)); - test_assert_false(smspec_node_identify_total("", ECL_SMSPEC_REGION_VAR)); - test_assert_false(smspec_node_identify_total("HEI", ECL_SMSPEC_WELL_VAR)); - test_assert_false(smspec_node_identify_total("GBHP", ECL_SMSPEC_GROUP_VAR)); - test_assert_false(smspec_node_identify_total("FOPR", ECL_SMSPEC_FIELD_VAR)); + test_assert_false(smspec_node_identify_total("", RD_SMSPEC_REGION_VAR)); + test_assert_false(smspec_node_identify_total("HEI", RD_SMSPEC_WELL_VAR)); + test_assert_false(smspec_node_identify_total("GBHP", RD_SMSPEC_GROUP_VAR)); + test_assert_false(smspec_node_identify_total("FOPR", RD_SMSPEC_FIELD_VAR)); test_assert_false( - smspec_node_identify_total("CWIR", ECL_SMSPEC_COMPLETION_VAR)); + smspec_node_identify_total("CWIR", RD_SMSPEC_COMPLETION_VAR)); test_assert_false( - smspec_node_identify_total("LWGPR", ECL_SMSPEC_LOCAL_WELL_VAR)); + smspec_node_identify_total("LWGPR", RD_SMSPEC_LOCAL_WELL_VAR)); test_assert_false( - smspec_node_identify_total("CWCT", ECL_SMSPEC_LOCAL_COMPLETION_VAR)); + smspec_node_identify_total("CWCT", RD_SMSPEC_LOCAL_COMPLETION_VAR)); test_assert_false( - smspec_node_identify_total("SGPT", ECL_SMSPEC_SEGMENT_VAR)); + smspec_node_identify_total("SGPT", RD_SMSPEC_SEGMENT_VAR)); test_assert_false( - smspec_node_identify_total("RFT", ECL_SMSPEC_REGION_2_REGION_VAR)); + smspec_node_identify_total("RFT", RD_SMSPEC_REGION_2_REGION_VAR)); test_assert_false( - smspec_node_identify_total("ROFR", ECL_SMSPEC_REGION_2_REGION_VAR)); + smspec_node_identify_total("ROFR", RD_SMSPEC_REGION_2_REGION_VAR)); } void test_nums_default() { - ecl::smspec_node field_node(0, "FOPT", "UNIT", 0); - ecl::smspec_node group_node(0, "GOPR", "G1", "UNIT", 0, ":"); - ecl::smspec_node well_node(0, "WOPR", "W1", "UNIT", 0, ":"); + rd::smspec_node field_node(0, "FOPT", "UNIT", 0); + rd::smspec_node group_node(0, "GOPR", "G1", "UNIT", 0, ":"); + rd::smspec_node well_node(0, "WOPR", "W1", "UNIT", 0, ":"); int default_nums = 0; /* @@ -207,15 +204,15 @@ void test_nums_default() { void test_cmp_types() { const int dims[3] = {10, 10, 10}; - ecl::smspec_node field_node(0, "FOPT", "UNIT", 0); - ecl::smspec_node region_node(0, "RPR", 10, "UNIT", dims, 0, ":"); - ecl::smspec_node group_node(0, "GOPR", "G1", "UNIT", 0, ":"); - ecl::smspec_node well_node(0, "WOPR", "W1", "UNIT", 0, ":"); - ecl::smspec_node block_node(0, "BPR", 10, "UNIT", dims, 0, ":"); - ecl::smspec_node aquifer_node(0, "AAQP", 10, "UNIT", dims, 0, ":"); - ecl::smspec_node segment_node(0, "SGOR", "W1", 10, "UNIT", dims, 0, ":"); - ecl::smspec_node misc_node1(0, "TIME", "UNIT", 0); - ecl::smspec_node misc_node2(0, "TCPU", "UNIT", 0); + rd::smspec_node field_node(0, "FOPT", "UNIT", 0); + rd::smspec_node region_node(0, "RPR", 10, "UNIT", dims, 0, ":"); + rd::smspec_node group_node(0, "GOPR", "G1", "UNIT", 0, ":"); + rd::smspec_node well_node(0, "WOPR", "W1", "UNIT", 0, ":"); + rd::smspec_node block_node(0, "BPR", 10, "UNIT", dims, 0, ":"); + rd::smspec_node aquifer_node(0, "AAQP", 10, "UNIT", dims, 0, ":"); + rd::smspec_node segment_node(0, "SGOR", "W1", 10, "UNIT", dims, 0, ":"); + rd::smspec_node misc_node1(0, "TIME", "UNIT", 0); + rd::smspec_node misc_node2(0, "TCPU", "UNIT", 0); test_assert_int_equal(field_node.cmp(field_node), 0); test_assert_int_equal(region_node.cmp(region_node), 0); @@ -239,10 +236,10 @@ void test_cmp_types() { } void test_cmp_well() { - ecl::smspec_node well_node1_1(0, "WOPR", "W1", "UNIT", 10, ":"); - ecl::smspec_node well_node1_2(0, "WOPR", "W2", "UNIT", 10, ":"); - ecl::smspec_node well_node2_1(0, "WWCT", "W1", "UNIT", 10, ":"); - ecl::smspec_node well_node2_2(0, "WWWT", "W2", "UNIT", 10, ":"); + rd::smspec_node well_node1_1(0, "WOPR", "W1", "UNIT", 10, ":"); + rd::smspec_node well_node1_2(0, "WOPR", "W2", "UNIT", 10, ":"); + rd::smspec_node well_node2_1(0, "WWCT", "W1", "UNIT", 10, ":"); + rd::smspec_node well_node2_2(0, "WWWT", "W2", "UNIT", 10, ":"); test_assert_int_equal(well_node1_1.cmp(well_node1_1), 0); test_assert_int_equal(well_node2_2.cmp(well_node2_2), 0); @@ -257,10 +254,10 @@ void test_cmp_well() { void test_cmp_region() { const int dims[3] = {10, 10, 10}; - ecl::smspec_node region_node1_1(0, "ROIP", 10, "UNIT", dims, 0, ":"); - ecl::smspec_node region_node1_2(0, "ROIP", 11, "UNIT", dims, 0, ":"); - ecl::smspec_node region_node2_1(0, "RPR", 10, "UNIT", dims, 0, ":"); - ecl::smspec_node region_node2_2(0, "RPR", 12, "UNIT", dims, 0, ":"); + rd::smspec_node region_node1_1(0, "ROIP", 10, "UNIT", dims, 0, ":"); + rd::smspec_node region_node1_2(0, "ROIP", 11, "UNIT", dims, 0, ":"); + rd::smspec_node region_node2_1(0, "RPR", 10, "UNIT", dims, 0, ":"); + rd::smspec_node region_node2_2(0, "RPR", 12, "UNIT", dims, 0, ":"); test_assert_true(region_node1_1.cmp(region_node1_2) < 0); test_assert_true(region_node1_1.cmp(region_node2_1) < 0); diff --git a/lib/resdata/tests/rd_sum_alloc_resampled_test.cpp b/lib/resdata/tests/rd_sum_alloc_resampled_test.cpp new file mode 100644 index 0000000000..e817f3f4ad --- /dev/null +++ b/lib/resdata/tests/rd_sum_alloc_resampled_test.cpp @@ -0,0 +1,138 @@ + +#include + +#include +#include +#include + +rd_sum_type *test_alloc_rd_sum() { + time_t start_time = util_make_date_utc(1, 1, 2010); + rd_sum_type *rd_sum = rd_sum_alloc_writer("/tmp/CASE", false, true, ":", + start_time, true, 10, 10, 10); + double sim_seconds = 0; + + int num_dates = 4; + double ministep_length = 86400; // seconds in a day + + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "FOPT", NULL, 0, "Barrels", 99.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 567, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_sum_add_var(rd_sum, "WWCT", "OP-1", 0, "(1)", 0.0); + + for (int report_step = 0; report_step < num_dates; report_step++) { + { + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, report_step * 2.0); + rd_sum_tstep_set_from_node(tstep, *node2, report_step * 4.0 + 2.0); + rd_sum_tstep_set_from_node(tstep, *node3, report_step * 6.0 + 4.0); + } + sim_seconds += ministep_length * 3; + } + return rd_sum; +} + +void test_correct_time_vector() { + + rd_sum_type *rd_sum = test_alloc_rd_sum(); + time_t_vector_type *t = time_t_vector_alloc(0, 0); + time_t_vector_append(t, util_make_date_utc(2, 1, 2010)); + time_t_vector_append(t, util_make_date_utc(4, 1, 2010)); + time_t_vector_append(t, util_make_date_utc(6, 1, 2010)); + time_t_vector_append(t, util_make_date_utc(8, 1, 2010)); + rd_sum_type *rd_sum_resampled = + rd_sum_alloc_resample(rd_sum, "kk", t, false, false); + test_assert_int_equal(rd_sum_get_report_time(rd_sum_resampled, 2), + util_make_date_utc(6, 1, 2010)); + + const rd_smspec_type *smspec_resampled = + rd_sum_get_smspec(rd_sum_resampled); + const rd::smspec_node &node1 = + rd_smspec_iget_node_w_params_index(smspec_resampled, 1); + const rd::smspec_node &node2 = + rd_smspec_iget_node_w_params_index(smspec_resampled, 2); + const rd::smspec_node &node3 = + rd_smspec_iget_node_w_params_index(smspec_resampled, 3); + test_assert_string_equal("BPR", smspec_node_get_keyword(&node2)); + test_assert_string_equal("BARS", smspec_node_get_unit(&node2)); + + test_assert_double_equal( + 3.33333, rd_sum_get_from_sim_time( + rd_sum_resampled, util_make_date_utc(6, 1, 2010), &node1)); + test_assert_double_equal( + 3.33333, rd_sum_get_from_sim_time( + rd_sum_resampled, util_make_date_utc(2, 1, 2010), &node2)); + test_assert_double_equal( + 10.0000, rd_sum_get_from_sim_time( + rd_sum_resampled, util_make_date_utc(4, 1, 2010), &node3)); + + rd_sum_free(rd_sum_resampled); + time_t_vector_free(t); + rd_sum_free(rd_sum); +} + +void test_resample_extrapolate_rate() { + + rd_sum_type *rd_sum = test_alloc_rd_sum(); + + time_t_vector_type *t = time_t_vector_alloc(0, 0); + time_t_vector_append(t, util_make_date_utc(1, 1, 2009)); + time_t_vector_append(t, util_make_date_utc(4, 1, 2010)); + time_t_vector_append(t, util_make_date_utc(12, 1, 2010)); + + rd_sum_type *rd_sum_resampled = + rd_sum_alloc_resample(rd_sum, "kk", t, true, true); + + const rd_smspec_type *smspec_resampled = + rd_sum_get_smspec(rd_sum_resampled); + const rd::smspec_node &node1 = + rd_smspec_iget_node_w_params_index(smspec_resampled, 1); + const rd::smspec_node &node3 = + rd_smspec_iget_node_w_params_index(smspec_resampled, 3); + + //testing extrapolation for rate wrt. 3 dates: lower, inside and upper + test_assert_double_equal( + 0, rd_sum_get_from_sim_time(rd_sum_resampled, + util_make_date_utc(1, 1, 2009), &node3)); + test_assert_double_equal( + 10.000, rd_sum_get_from_sim_time( + rd_sum_resampled, util_make_date_utc(4, 1, 2010), &node3)); + test_assert_double_equal( + 0, rd_sum_get_from_sim_time(rd_sum_resampled, + util_make_date_utc(12, 1, 2010), &node3)); + + //testing extrapolation for variable wrt. 3 dates: lower, inside and upper + test_assert_double_equal( + 0, rd_sum_get_from_sim_time(rd_sum_resampled, + util_make_date_utc(1, 1, 2009), &node1)); + test_assert_double_equal( + 2.000, rd_sum_get_from_sim_time( + rd_sum_resampled, util_make_date_utc(4, 1, 2010), &node1)); + test_assert_double_equal( + 6.000, rd_sum_get_from_sim_time( + rd_sum_resampled, util_make_date_utc(12, 1, 2010), &node1)); + + rd_sum_free(rd_sum_resampled); + time_t_vector_free(t); + rd_sum_free(rd_sum); +} + +void test_not_sorted() { + rd_sum_type *rd_sum = test_alloc_rd_sum(); + time_t_vector_type *t = time_t_vector_alloc(0, 0); + time_t_vector_append(t, util_make_date_utc(1, 1, 2010)); + time_t_vector_append(t, util_make_date_utc(3, 1, 2010)); + time_t_vector_append(t, util_make_date_utc(2, 1, 2010)); + test_assert_NULL(rd_sum_alloc_resample(rd_sum, "kk", t, false, false)); + time_t_vector_free(t); + rd_sum_free(rd_sum); +} + +int main() { + test_correct_time_vector(); + test_resample_extrapolate_rate(); + test_not_sorted(); + return 0; +} diff --git a/lib/ecl/tests/ecl_sum_case_exists.cpp b/lib/resdata/tests/rd_sum_case_exists.cpp similarity index 77% rename from lib/ecl/tests/ecl_sum_case_exists.cpp rename to lib/resdata/tests/rd_sum_case_exists.cpp index 09ef321a5d..2fc5eb826b 100644 --- a/lib/ecl/tests/ecl_sum_case_exists.cpp +++ b/lib/resdata/tests/rd_sum_case_exists.cpp @@ -7,12 +7,12 @@ #include #include -#include -#include -#include +#include +#include +#include void test_case(const char *sum_case, bool expected_exist) { - test_assert_bool_equal(expected_exist, ecl_sum_case_exists(sum_case)); + test_assert_bool_equal(expected_exist, rd_sum_case_exists(sum_case)); } void test_case_no_path(const char *sum_case, bool expected_exist) { @@ -24,7 +24,7 @@ void test_case_no_path(const char *sum_case, bool expected_exist) { util_alloc_file_components(sum_case, &path, &basename, NULL); if (path) chdir(path); - test_assert_bool_equal(expected_exist, ecl_sum_case_exists(basename)); + test_assert_bool_equal(expected_exist, rd_sum_case_exists(basename)); free(path); free(basename); @@ -37,7 +37,7 @@ int main(int argc, char **argv) { const char *existing_case = argv[1]; const char *missing_header = argv[2]; const char *missing_data = argv[3]; - test_assert_false(ecl_sum_case_exists("/does/not/exist")); + test_assert_false(rd_sum_case_exists("/does/not/exist")); test_case(existing_case, true); test_case_no_path(existing_case, true); diff --git a/lib/ecl/tests/ecl_sum_data_intermediate_test.cpp b/lib/resdata/tests/rd_sum_data_intermediate_test.cpp similarity index 50% rename from lib/ecl/tests/ecl_sum_data_intermediate_test.cpp rename to lib/resdata/tests/rd_sum_data_intermediate_test.cpp index 3f3e89ed6c..47e9d66d57 100644 --- a/lib/ecl/tests/ecl_sum_data_intermediate_test.cpp +++ b/lib/resdata/tests/rd_sum_data_intermediate_test.cpp @@ -5,12 +5,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /* @@ -54,11 +54,11 @@ Total CASE3: #define ieq(d, i, v) test_assert_double_equal(double_vector_iget(d, (i)), v) void verify_CASE1(int length) { - ecl_sum_type *sum = ecl_sum_fread_alloc_case("CASE1", ":"); + rd_sum_type *sum = rd_sum_fread_alloc_case("CASE1", ":"); int params_size = 4; // TIME, BPR:1, BPR:2, BPR:3 for (int i = 1; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i, false); test_assert_int_equal(length, double_vector_size(d)); for (int j = 0; j < length; j++) { test_assert_double_equal(double_vector_iget(d, j), @@ -66,50 +66,49 @@ void verify_CASE1(int length) { } double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); } void write_CASE1(bool unified) { time_t start_time = util_make_date_utc(1, 1, 2010); - ecl_sum_type *ecl_sum = ecl_sum_alloc_writer("CASE1", false, unified, ":", - start_time, true, 10, 10, 10); + rd_sum_type *rd_sum = rd_sum_alloc_writer("CASE1", false, unified, ":", + start_time, true, 10, 10, 10); double sim_seconds = 0; int num_dates = 100; double ministep_length = 86400; // seconds in a day - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 1, "BARS", 0.0); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 2, "BARS", 0.0); - const ecl::smspec_node *node3 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 3, "BARS", 0.0); + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "BPR", NULL, 1, "BARS", 0.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 2, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_sum_add_var(rd_sum, "BPR", NULL, 3, "BARS", 0.0); for (int report_step = 0; report_step < num_dates; report_step++) { { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, (1 + report_step) * 100); - ecl_sum_tstep_set_from_node(tstep, *node2, - (1 + report_step) * 100 + 10.0); - ecl_sum_tstep_set_from_node(tstep, *node3, - (1 + report_step) * 100 + 20.0); + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, (1 + report_step) * 100); + rd_sum_tstep_set_from_node(tstep, *node2, + (1 + report_step) * 100 + 10.0); + rd_sum_tstep_set_from_node(tstep, *node3, + (1 + report_step) * 100 + 20.0); } sim_seconds += ministep_length * 3; } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); verify_CASE1(num_dates); } void verify_CASE2(int length) { - ecl_sum_type *sum = - ecl_sum_fread_alloc_case2__("CASE2", ":", false, true, 0); + rd_sum_type *sum = rd_sum_fread_alloc_case2__("CASE2", ":", false, true, 0); const int params_size = 2; // TIME, BPR:2, BPR:1 for (int i = 0; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i + 1, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i + 1, false); test_assert_int_equal(length, double_vector_size(d)); for (int j = 1; j < length; j++) test_assert_double_equal(double_vector_iget(d, j - 1), @@ -117,11 +116,11 @@ void verify_CASE2(int length) { double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); - sum = ecl_sum_fread_alloc_case("CASE2", ":"); + sum = rd_sum_fread_alloc_case("CASE2", ":"); for (int i = 0; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i + 1, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i + 1, false); test_assert_int_equal(double_vector_size(d), 7); ieq(d, 0, (1 - i) * 10 + 100); ieq(d, 1, (1 - i) * 10 + 200); @@ -133,7 +132,7 @@ void verify_CASE2(int length) { double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); } void write_CASE2(bool unified) { @@ -143,37 +142,36 @@ void write_CASE2(bool unified) { int num_dates = 4; double ministep_length = 86400; // seconds in a day double sim_seconds = ministep_length * 2.5 * 3; - ecl_sum_type *ecl_sum = ecl_sum_alloc_restart_writer( + rd_sum_type *rd_sum = rd_sum_alloc_restart_writer( "CASE2", "CASE1", false, true, ":", start_time, true, 10, 10, 10); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 2, "BARS", 0.0); - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 1, "BARS", 0.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 2, "BARS", 0.0); + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "BPR", NULL, 1, "BARS", 0.0); for (int report_step = 1; report_step <= num_dates; report_step++) { { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 3, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, report_step * 1000); - ecl_sum_tstep_set_from_node(tstep, *node2, - report_step * 1000 + 100); + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 3, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, report_step * 1000); + rd_sum_tstep_set_from_node(tstep, *node2, + report_step * 1000 + 100); } sim_seconds += ministep_length * 3; } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); verify_CASE2(num_dates); } } void verify_CASE3(int length) { const int params_size = 3; - ecl_sum_type *sum = - ecl_sum_fread_alloc_case2__("CASE3", ":", false, true, 0); + rd_sum_type *sum = rd_sum_fread_alloc_case2__("CASE3", ":", false, true, 0); for (int i = 0; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i + 1, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i + 1, false); test_assert_int_equal(length, double_vector_size(d)); for (int j = 0; j < length; j++) { test_assert_double_equal(double_vector_iget(d, j), @@ -181,18 +179,18 @@ void verify_CASE3(int length) { } double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); - sum = ecl_sum_fread_alloc_case("CASE3", ":"); + sum = rd_sum_fread_alloc_case("CASE3", ":"); for (int i = 0; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i + 1, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i + 1, false); ieq(d, 0, (2 - i) * 10 + 100); ieq(d, 1, (2 - i) * 10 + 200); ieq(d, 2, (2 - i) * 10 + 300); if (i == 0) { - const ecl::smspec_node &node = - ecl_smspec_iget_node_w_params_index(ecl_sum_get_smspec(sum), i); + const rd::smspec_node &node = + rd_smspec_iget_node_w_params_index(rd_sum_get_smspec(sum), i); double default_value = node.get_default(); ieq(d, 3, default_value); ieq(d, 4, default_value); @@ -207,12 +205,12 @@ void verify_CASE3(int length) { double_vector_free(d); } - ecl_sum_vector_type *vector = ecl_sum_vector_alloc(sum, true); + rd_sum_vector_type *vector = rd_sum_vector_alloc(sum, true); double frame[27]; //3 vectors X 9 data points pr. vector - ecl_sum_init_double_frame(sum, vector, frame); - ecl_sum_vector_free(vector); + rd_sum_init_double_frame(sum, vector, frame); + rd_sum_vector_free(vector); - ecl_sum_free(sum); + rd_sum_free(sum); } void write_CASE3(bool unified) { @@ -222,111 +220,110 @@ void write_CASE3(bool unified) { int num_dates = 4; double ministep_length = 86400; // seconds in a day double sim_seconds = ministep_length * 4.0 * 3; - ecl_sum_type *ecl_sum = ecl_sum_alloc_restart_writer( + rd_sum_type *rd_sum = rd_sum_alloc_restart_writer( "CASE3", "CASE2", false, true, ":", start_time, true, 10, 10, 10); - const ecl::smspec_node *node3 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 3, "BARS", 0.0); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 2, "BARS", 0.0); - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 1, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_sum_add_var(rd_sum, "BPR", NULL, 3, "BARS", 0.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 2, "BARS", 0.0); + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "BPR", NULL, 1, "BARS", 0.0); for (int report_step = 1; report_step <= num_dates; report_step++) { { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 5, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, report_step * 10000); - ecl_sum_tstep_set_from_node(tstep, *node2, - report_step * 10000 + 1000); - ecl_sum_tstep_set_from_node(tstep, *node3, - report_step * 10000 + 2000); + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 5, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, report_step * 10000); + rd_sum_tstep_set_from_node(tstep, *node2, + report_step * 10000 + 1000); + rd_sum_tstep_set_from_node(tstep, *node3, + report_step * 10000 + 2000); } sim_seconds += ministep_length * 3; } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); verify_CASE3(num_dates); } } void verify_CASE4() { - ecl_sum_type *sum = ecl_sum_fread_alloc_case("CASE4", ":"); + rd_sum_type *sum = rd_sum_fread_alloc_case("CASE4", ":"); double_vector_type *d; - d = ecl_sum_alloc_data_vector(sum, 0, false); + d = rd_sum_alloc_data_vector(sum, 0, false); double_vector_free(d); - d = ecl_sum_alloc_data_vector(sum, 1, false); + d = rd_sum_alloc_data_vector(sum, 1, false); double_vector_free(d); - d = ecl_sum_alloc_data_vector(sum, 2, false); + d = rd_sum_alloc_data_vector(sum, 2, false); double_vector_free(d); - d = ecl_sum_alloc_data_vector(sum, 4, false); + d = rd_sum_alloc_data_vector(sum, 4, false); ieq(d, 0, -99); ieq(d, 4, -99); ieq(d, 5, 10000); ieq(d, 8, 40000); double_vector_free(d); - ecl_sum_vector_type *vector = ecl_sum_vector_alloc(sum, true); + rd_sum_vector_type *vector = rd_sum_vector_alloc(sum, true); double frame[27]; //3 vectors X 9 data points pr. vector - ecl_sum_init_double_frame(sum, vector, frame); + rd_sum_init_double_frame(sum, vector, frame); test_assert_double_equal(frame[26], 40000); - ecl_sum_vector_free(vector); + rd_sum_vector_free(vector); - ecl_sum_free(sum); + rd_sum_free(sum); } void write_CASE4(bool unified) { - ecl::util::TestArea ta("case4"); + rd::util::TestArea ta("case4"); write_CASE3(unified); { - ecl_file_type *sum_file = ecl_file_open("CASE3.UNSMRY", 0); - ecl_file_type *smspec_file = ecl_file_open("CASE3.SMSPEC", 0); - - ecl_kw_type *keywords = - ecl_file_iget_named_kw(smspec_file, "KEYWORDS", 0); - ecl_kw_resize(keywords, 5); - ecl_kw_iset_char_ptr(keywords, 3, "WTPRWI1"); - ecl_kw_iset_char_ptr(keywords, 4, "BPR"); - - ecl_kw_type *nums = ecl_file_iget_named_kw(smspec_file, "NUMS", 0); - ecl_kw_resize(nums, 5); - unsigned int *nums_ptr = (unsigned int *)ecl_kw_get_int_ptr(nums); + rd_file_type *sum_file = rd_file_open("CASE3.UNSMRY", 0); + rd_file_type *smspec_file = rd_file_open("CASE3.SMSPEC", 0); + + rd_kw_type *keywords = + rd_file_iget_named_kw(smspec_file, "KEYWORDS", 0); + rd_kw_resize(keywords, 5); + rd_kw_iset_char_ptr(keywords, 3, "WTPRWI1"); + rd_kw_iset_char_ptr(keywords, 4, "BPR"); + + rd_kw_type *nums = rd_file_iget_named_kw(smspec_file, "NUMS", 0); + rd_kw_resize(nums, 5); + unsigned int *nums_ptr = (unsigned int *)rd_kw_get_int_ptr(nums); nums_ptr[3] = 5; nums_ptr[4] = 8; //a different - ecl_kw_type *wgnames = - ecl_file_iget_named_kw(smspec_file, "WGNAMES", 0); - ecl_kw_resize(wgnames, 5); - ecl_kw_iset_char_ptr(wgnames, 4, ":+:+:+:+"); + rd_kw_type *wgnames = rd_file_iget_named_kw(smspec_file, "WGNAMES", 0); + rd_kw_resize(wgnames, 5); + rd_kw_iset_char_ptr(wgnames, 4, ":+:+:+:+"); - ecl_kw_type *units = ecl_file_iget_named_kw(smspec_file, "UNITS", 0); - ecl_kw_resize(units, 5); - ecl_kw_iset_char_ptr(units, 4, "BARS"); + rd_kw_type *units = rd_file_iget_named_kw(smspec_file, "UNITS", 0); + rd_kw_resize(units, 5); + rd_kw_iset_char_ptr(units, 4, "BARS"); - int num_params = ecl_file_get_num_named_kw(sum_file, "PARAMS"); + int num_params = rd_file_get_num_named_kw(sum_file, "PARAMS"); for (int i = 0; i < num_params; i++) { - ecl_kw_type *params_kw = - ecl_file_iget_named_kw(sum_file, "PARAMS", i); - ecl_kw_resize(params_kw, 5); - float *ptr = (float *)ecl_kw_get_void_ptr(params_kw); + rd_kw_type *params_kw = + rd_file_iget_named_kw(sum_file, "PARAMS", i); + rd_kw_resize(params_kw, 5); + float *ptr = (float *)rd_kw_get_void_ptr(params_kw); ptr[4] = ptr[3]; ptr[3] = -1; } fortio_type *f; const char *filename_sum = "CASE4.UNSMRY"; - f = fortio_open_writer(filename_sum, false, ECL_ENDIAN_FLIP); - ecl_file_fwrite_fortio(sum_file, f, 0); + f = fortio_open_writer(filename_sum, false, RD_ENDIAN_FLIP); + rd_file_fwrite_fortio(sum_file, f, 0); fortio_fclose(f); const char *filename_smspec = "CASE4.SMSPEC"; - f = fortio_open_writer(filename_smspec, false, ECL_ENDIAN_FLIP); - ecl_file_fwrite_fortio(smspec_file, f, 0); + f = fortio_open_writer(filename_smspec, false, RD_ENDIAN_FLIP); + rd_file_fwrite_fortio(smspec_file, f, 0); fortio_fclose(f); - ecl_file_close(smspec_file); - ecl_file_close(sum_file); + rd_file_close(smspec_file); + rd_file_close(sum_file); verify_CASE4(); } } diff --git a/lib/resdata/tests/rd_sum_report_step_compatible.cpp b/lib/resdata/tests/rd_sum_report_step_compatible.cpp new file mode 100644 index 0000000000..ceb38042d8 --- /dev/null +++ b/lib/resdata/tests/rd_sum_report_step_compatible.cpp @@ -0,0 +1,31 @@ +#include +#include + +#include +#include +#include + +#include + +int main(int argc, char **argv) { + const char *case1 = argv[1]; + const char *case2 = argv[2]; + const char *compatible_string = argv[3]; + rd_sum_type *rd_sum1 = rd_sum_fread_alloc_case(case1, ":"); + rd_sum_type *rd_sum2 = rd_sum_fread_alloc_case(case2, ":"); + + test_assert_true(rd_sum_is_instance(rd_sum1)); + test_assert_true(rd_sum_is_instance(rd_sum2)); + test_assert_true(rd_sum_report_step_compatible(rd_sum1, rd_sum1)); + test_assert_true(rd_sum_report_step_compatible(rd_sum2, rd_sum2)); + + { + bool compatible; + test_assert_true(util_sscanf_bool(compatible_string, &compatible)); + test_assert_bool_equal(compatible, + rd_sum_report_step_compatible(rd_sum1, rd_sum2)); + } + rd_sum_free(rd_sum1); + rd_sum_free(rd_sum2); + exit(0); +} diff --git a/lib/resdata/tests/rd_sum_report_step_equal.cpp b/lib/resdata/tests/rd_sum_report_step_equal.cpp new file mode 100644 index 0000000000..b6e13fe453 --- /dev/null +++ b/lib/resdata/tests/rd_sum_report_step_equal.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include +#include +#include + +#include + +int main(int argc, char **argv) { + const char *case1 = argv[1]; + const char *case2 = argv[2]; + const char *equal_string = argv[3]; + bool equal; + rd_sum_type *rd_sum1 = rd_sum_fread_alloc_case(case1, ":"); + rd_sum_type *rd_sum2 = rd_sum_fread_alloc_case(case2, ":"); + + test_assert_true(rd_sum_is_instance(rd_sum1)); + test_assert_true(rd_sum_is_instance(rd_sum2)); + test_assert_true(rd_sum_report_step_equal(rd_sum1, rd_sum1)); + test_assert_true(util_sscanf_bool(equal_string, &equal)); + + test_assert_true(rd_sum_report_step_equal(rd_sum1, rd_sum1)); + test_assert_true(rd_sum_report_step_equal(rd_sum2, rd_sum2)); + test_assert_bool_equal(equal, rd_sum_report_step_equal(rd_sum1, rd_sum2)); + + rd_sum_free(rd_sum1); + rd_sum_free(rd_sum2); + exit(0); +} diff --git a/lib/ecl/tests/ecl_sum_restart.cpp b/lib/resdata/tests/rd_sum_restart.cpp similarity index 59% rename from lib/ecl/tests/ecl_sum_restart.cpp rename to lib/resdata/tests/rd_sum_restart.cpp index 7471123944..7ae66d687e 100644 --- a/lib/ecl/tests/ecl_sum_restart.cpp +++ b/lib/resdata/tests/rd_sum_restart.cpp @@ -5,12 +5,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include /* @@ -54,11 +54,11 @@ Total CASE3: #define ieq(d, i, v) test_assert_double_equal(double_vector_iget(d, (i)), v) void verify_CASE1(int length) { - ecl_sum_type *sum = ecl_sum_fread_alloc_case("CASE1", ":"); + rd_sum_type *sum = rd_sum_fread_alloc_case("CASE1", ":"); int params_size = 4; // TIME, BPR:1, BPR:2, BPR:3 for (int i = 1; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i, false); test_assert_int_equal(length, double_vector_size(d)); for (int j = 0; j < length; j++) { test_assert_double_equal(double_vector_iget(d, j), @@ -66,16 +66,15 @@ void verify_CASE1(int length) { } double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); } void verify_CASE2(int length) { - ecl_sum_type *sum = - ecl_sum_fread_alloc_case2__("CASE2", ":", false, true, 0); + rd_sum_type *sum = rd_sum_fread_alloc_case2__("CASE2", ":", false, true, 0); const int params_size = 2; // TIME, BPR:2, BPR:1 for (int i = 0; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i + 1, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i + 1, false); test_assert_int_equal(length, double_vector_size(d)); for (int j = 1; j < length; j++) test_assert_double_equal(double_vector_iget(d, j - 1), @@ -83,11 +82,11 @@ void verify_CASE2(int length) { double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); - sum = ecl_sum_fread_alloc_case("CASE2", ":"); + sum = rd_sum_fread_alloc_case("CASE2", ":"); for (int i = 0; i < params_size; i++) { - double_vector_type *d = ecl_sum_alloc_data_vector(sum, i + 1, false); + double_vector_type *d = rd_sum_alloc_data_vector(sum, i + 1, false); test_assert_int_equal(double_vector_size(d), 4); ieq(d, 0, (1 - i) * 100 + 1000); ieq(d, 1, (1 - i) * 100 + 2000); @@ -96,39 +95,39 @@ void verify_CASE2(int length) { double_vector_free(d); } - ecl_sum_free(sum); + rd_sum_free(sum); } void write_CASE1(bool unified) { time_t start_time = util_make_date_utc(1, 1, 2010); - ecl_sum_type *ecl_sum = ecl_sum_alloc_writer("CASE1", false, unified, ":", - start_time, true, 10, 10, 10); + rd_sum_type *rd_sum = rd_sum_alloc_writer("CASE1", false, unified, ":", + start_time, true, 10, 10, 10); double sim_seconds = 0; int num_dates = 100; double ministep_length = 86400; // seconds in a day - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 1, "BARS", 0.0); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 2, "BARS", 0.0); - const ecl::smspec_node *node3 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 3, "BARS", 0.0); + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "BPR", NULL, 1, "BARS", 0.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 2, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_sum_add_var(rd_sum, "BPR", NULL, 3, "BARS", 0.0); for (int report_step = 0; report_step < num_dates; report_step++) { { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 1, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, (1 + report_step) * 100); - ecl_sum_tstep_set_from_node(tstep, *node2, - (1 + report_step) * 100 + 10.0); - ecl_sum_tstep_set_from_node(tstep, *node3, - (1 + report_step) * 100 + 20.0); + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, (1 + report_step) * 100); + rd_sum_tstep_set_from_node(tstep, *node2, + (1 + report_step) * 100 + 10.0); + rd_sum_tstep_set_from_node(tstep, *node3, + (1 + report_step) * 100 + 20.0); } sim_seconds += ministep_length * 3; } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); verify_CASE1(num_dates); } @@ -141,26 +140,26 @@ void write_CASE2() { int num_dates = 4; double ministep_length = 86400; // seconds in a day double sim_seconds = ministep_length * 2.5 * 3; - ecl_sum_type *ecl_sum = ecl_sum_alloc_restart_writer( + rd_sum_type *rd_sum = rd_sum_alloc_restart_writer( "CASE2", "CASE1", false, true, ":", start_time, true, 10, 10, 10); - const ecl::smspec_node *node2 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 2, "BARS", 0.0); - const ecl::smspec_node *node1 = - ecl_sum_add_var(ecl_sum, "BPR", NULL, 1, "BARS", 0.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 2, "BARS", 0.0); + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "BPR", NULL, 1, "BARS", 0.0); for (int report_step = 1; report_step <= num_dates; report_step++) { { - ecl_sum_tstep_type *tstep = - ecl_sum_add_tstep(ecl_sum, report_step + 3, sim_seconds); - ecl_sum_tstep_set_from_node(tstep, *node1, report_step * 1000); - ecl_sum_tstep_set_from_node(tstep, *node2, - report_step * 1000 + 100); + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 3, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, report_step * 1000); + rd_sum_tstep_set_from_node(tstep, *node2, + report_step * 1000 + 100); } sim_seconds += ministep_length * 3; } - ecl_sum_fwrite(ecl_sum); - ecl_sum_free(ecl_sum); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); util_unlink("CASE1.SMSPEC"); diff --git a/lib/resdata/tests/rd_sum_test.cpp b/lib/resdata/tests/rd_sum_test.cpp new file mode 100644 index 0000000000..e119cace2e --- /dev/null +++ b/lib/resdata/tests/rd_sum_test.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include +#include +#include + +#include + +void test_time_range(const rd_sum_type *rd_sum) { + // Hardcoded Gurbat case values + time_t start = rd_make_date(1, 1, 2000); + time_t end = rd_make_date(31, 12, 2004); + + test_assert_time_t_equal(rd_sum_get_start_time(rd_sum), start); + test_assert_time_t_equal(rd_sum_get_end_time(rd_sum), end); + test_assert_time_t_equal(rd_sum_get_data_start(rd_sum), start); +} + +void test_days(const rd_sum_type *rd_sum) { + time_t date1 = rd_make_date(1, 1, 2000); + time_t date2 = rd_make_date(31, 12, 2004); + time_t date3 = rd_make_date(2, 1, 2000); + + double days1 = rd_sum_time2days(rd_sum, date1); + double days2 = rd_sum_time2days(rd_sum, date2); + double days3 = rd_sum_time2days(rd_sum, date3); + + test_assert_double_equal(days1, 0); + test_assert_double_equal(days2, 1826); + test_assert_double_equal(days3, 1); +} + +void test_is_oil_producer(const rd_sum_type *rd_sum) { + test_assert_true(rd_sum_is_oil_producer(rd_sum, "OP_1")); + test_assert_false(rd_sum_is_oil_producer(rd_sum, "WI_1")); + test_assert_false(rd_sum_is_oil_producer(rd_sum, "DoesNotExist")); +} + +int main(int argc, char **argv) { + const char *case1 = argv[1]; + + rd_sum_type *rd_sum1 = rd_sum_fread_alloc_case(case1, ":"); + + test_assert_true(rd_sum_is_instance(rd_sum1)); + test_time_range(rd_sum1); + test_days(rd_sum1); + test_is_oil_producer(rd_sum1); + rd_sum_free(rd_sum1); + exit(0); +} diff --git a/lib/resdata/tests/rd_sum_writer.cpp b/lib/resdata/tests/rd_sum_writer.cpp new file mode 100644 index 0000000000..f4d95304dd --- /dev/null +++ b/lib/resdata/tests/rd_sum_writer.cpp @@ -0,0 +1,246 @@ +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +double write_summary(const char *name, time_t start_time, int nx, int ny, + int nz, int num_dates, int num_ministep, + double ministep_length) { + rd_sum_type *rd_sum = rd_sum_alloc_writer(name, false, true, ":", + start_time, true, nx, ny, nz); + double sim_seconds = 0; + rd_smspec_type *smspec = rd_sum_get_smspec(rd_sum); + + test_assert_int_equal(rd_smspec_get_params_size(smspec), 1); + const rd::smspec_node *node1 = + rd_smspec_add_node(smspec, "FOPT", "Barrels", 99.0); + const rd::smspec_node *node2 = + rd_smspec_add_node(smspec, "BPR", 567, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_smspec_add_node(smspec, "WWCT", "OP-1", "(1)", 0.0); + test_assert_int_equal(rd_smspec_get_params_size(smspec), 4); + + for (int report_step = 0; report_step < num_dates; report_step++) { + for (int step = 0; step < num_ministep; step++) { + /* Simulate .... */ + + { + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node2, 10 * sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node3, 100 * sim_seconds); + + test_assert_double_equal( + rd_sum_tstep_get_from_node(tstep, *node1), sim_seconds); + test_assert_double_equal( + rd_sum_tstep_get_from_node(tstep, *node2), + sim_seconds * 10); + test_assert_double_equal( + rd_sum_tstep_get_from_node(tstep, *node3), + sim_seconds * 100); + } + sim_seconds += ministep_length; + } + } + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); + return sim_seconds; +} + +int write_restart_summary(const char *name, const char *restart_name, + int start_report_step, double sim_seconds, + time_t start_time, int nx, int ny, int nz, + int num_dates, int num_ministep, + double ministep_length) { + rd_sum_type *rd_sum = rd_sum_alloc_restart_writer( + name, restart_name, false, true, ":", start_time, true, nx, ny, nz); + rd_smspec_type *smspec = rd_sum_get_smspec(rd_sum); + + const rd::smspec_node *node1 = + rd_smspec_add_node(smspec, "FOPT", "Barrels", 99.0); + const rd::smspec_node *node2 = + rd_smspec_add_node(smspec, "BPR", 567, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_smspec_add_node(smspec, "WWCT", "OP-1", "(1)", 0.0); + + int num_report_steps = start_report_step + num_dates; + for (int report_step = start_report_step; report_step < num_report_steps; + report_step++) { + for (int step = 0; step < num_ministep; step++) { + { + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node2, 10 * sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node3, 100 * sim_seconds); + } + sim_seconds += ministep_length; + } + } + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); + return sim_seconds; +} + +void test_write_read() { + const char *name = "CASE"; + time_t start_time = util_make_date_utc(1, 1, 2010); + time_t end_time = start_time; + int nx = 10; + int ny = 11; + int nz = 12; + int num_dates = 5; + int num_ministep = 10; + double ministep_length = + 86400; // Seconds - numerical value chosen to avoid rounding problems when converting between seconds and days. + { + rd::util::TestArea ta("write_read"); + rd_sum_type *rd_sum; + + write_summary(name, start_time, nx, ny, nz, num_dates, num_ministep, + ministep_length); + rd_sum = rd_sum_fread_alloc_case(name, ":"); + test_assert_true(rd_sum_is_instance(rd_sum)); + test_assert_true(rd_sum_get_start_time(rd_sum) == start_time); + + /* Time direction */ + test_assert_time_t_equal(start_time, rd_sum_get_start_time(rd_sum)); + test_assert_time_t_equal(start_time, rd_sum_get_data_start(rd_sum)); + util_inplace_forward_seconds_utc( + &end_time, (num_dates * num_ministep - 1) * ministep_length); + test_assert_time_t_equal(end_time, rd_sum_get_end_time(rd_sum)); + + /* Keys */ + test_assert_true(rd_sum_has_key(rd_sum, "FOPT")); + test_assert_true(rd_sum_has_key(rd_sum, "WWCT:OP-1")); + test_assert_true(rd_sum_has_key(rd_sum, "BPR:567")); + { + rd_grid_type *grid = + rd_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, NULL); + int i, j, k; + char *ijk_key; + rd_grid_get_ijk1(grid, 567 - 1, &i, &j, &k); + ijk_key = util_alloc_sprintf("BPR:%d,%d,%d", i + 1, j + 1, k + 1); + + free(ijk_key); + rd_grid_free(grid); + } + + test_assert_throw(rd_sum_get_general_var(rd_sum, 1, "NO_SUCH_KEY"), + std::out_of_range); + rd_sum_free(rd_sum); + } +} + +void test_rd_sum_alloc_restart_writer() { + rd::util::TestArea ta("sum_write_restart"); + { + const char *name1 = "CASE1"; + const char *name2 = "CASE2"; + time_t start_time = util_make_date_utc(1, 1, 2010); + int nx = 10; + int ny = 11; + int nz = 12; + int num_dates = 5; + int num_ministep = 10; + double ministep_length = 36000; // Seconds + + int sim_seconds = + write_summary(name1, start_time, nx, ny, nz, num_dates, + num_ministep, ministep_length); + sim_seconds = write_restart_summary( + name2, name1, num_dates, sim_seconds, start_time, nx, ny, nz, + num_dates, num_ministep, ministep_length); + + rd_sum_type *case1 = rd_sum_fread_alloc_case(name1, ":"); + rd_sum_type *case2 = rd_sum_fread_alloc_case(name2, ":"); + test_assert_true(rd_sum_is_instance(case2)); + + test_assert_true(rd_sum_has_key(case2, "FOPT")); + + rd_file_type *restart_file = rd_file_open("CASE2.SMSPEC", 0); + rd_file_view_type *view_file = rd_file_get_global_view(restart_file); + test_assert_true(rd_file_view_has_kw(view_file, RESTART_KW)); + rd_kw_type *restart_kw = + rd_file_view_iget_named_kw(view_file, "RESTART", 0); + test_assert_int_equal(8, rd_kw_get_size(restart_kw)); + test_assert_string_equal("CASE1 ", + (const char *)rd_kw_iget_ptr(restart_kw, 0)); + test_assert_string_equal(" ", + (const char *)rd_kw_iget_ptr(restart_kw, 1)); + + for (int time_index = 0; time_index < rd_sum_get_data_length(case1); + time_index++) + test_assert_double_equal( + rd_sum_get_general_var(case1, time_index, "FOPT"), + rd_sum_get_general_var(case2, time_index, "FOPT")); + + rd_sum_free(case2); + rd_sum_free(case1); + rd_file_close(restart_file); + } +} + +void test_long_restart_names() { + char restart_case[65] = {0}; + for (int n = 0; n < 8; n++) { + char s[9]; + sprintf(s, "WWWWGGG%d", n); + strcat(restart_case, s); + } + const char *name = "THE_CASE"; + rd::util::TestArea ta("suM_write_restart_long_name"); + { + int restart_step = 77; + time_t start_time = util_make_date_utc(1, 1, 2010); + rd_sum_type *rd_sum = rd_sum_alloc_restart_writer2( + name, restart_case, restart_step, false, true, ":", start_time, + true, 3, 3, 3); + rd_sum_fwrite(rd_sum); + rd_sum_free(rd_sum); + + rd_file_type *smspec_file = rd_file_open("THE_CASE.SMSPEC", 0); + rd_file_view_type *view_file = rd_file_get_global_view(smspec_file); + test_assert_true(rd_file_view_has_kw(view_file, RESTART_KW)); + rd_kw_type *restart_kw = + rd_file_view_iget_named_kw(view_file, "RESTART", 0); + test_assert_int_equal(8, rd_kw_get_size(restart_kw)); + + for (int n = 0; n < 8; n++) { + char s[9]; + sprintf(s, "WWWWGGG%d", n); + test_assert_string_equal(s, rd_kw_iget_char_ptr(restart_kw, n)); + } + rd_file_close(smspec_file); + { + rd_smspec_type *smspec = rd_smspec_alloc_restart_writer( + ":", + "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ" + "KLMNOPQRSTUVWXYZ", + 10, start_time, true, 3, 3, 3); + /* + Restart case is too long - it is ignored. + */ + test_assert_NULL(rd_smspec_get_restart_case(smspec)); + rd_smspec_free(smspec); + } + } +} + +int main(int argc, char **argv) { + util_install_signals(); + test_write_read(); + test_rd_sum_alloc_restart_writer(); + test_long_restart_names(); + exit(0); +} diff --git a/lib/resdata/tests/rd_unsmry_loader_test.cpp b/lib/resdata/tests/rd_unsmry_loader_test.cpp new file mode 100644 index 0000000000..976034667e --- /dev/null +++ b/lib/resdata/tests/rd_unsmry_loader_test.cpp @@ -0,0 +1,63 @@ +#include + +#include +#include + +#include + +#include "detail/resdata/rd_unsmry_loader.hpp" + +rd_sum_type *write_rd_sum() { + time_t start_time = util_make_date_utc(1, 1, 2010); + rd_sum_type *rd_sum = rd_sum_alloc_writer("CASE", false, true, ":", + start_time, true, 10, 10, 10); + double sim_seconds = 0; + + int num_dates = 4; + double ministep_length = 86400; // seconds in a day + + const rd::smspec_node *node1 = + rd_sum_add_var(rd_sum, "FOPT", NULL, 0, "Barrels", 99.0); + const rd::smspec_node *node2 = + rd_sum_add_var(rd_sum, "BPR", NULL, 567, "BARS", 0.0); + const rd::smspec_node *node3 = + rd_sum_add_var(rd_sum, "WWCT", "OP-1", 0, "(1)", 0.0); + + for (int report_step = 0; report_step < num_dates; report_step++) { + { + rd_sum_tstep_type *tstep = + rd_sum_add_tstep(rd_sum, report_step + 1, sim_seconds); + rd_sum_tstep_set_from_node(tstep, *node1, report_step * 2.0); + rd_sum_tstep_set_from_node(tstep, *node2, report_step * 4.0 + 2.0); + rd_sum_tstep_set_from_node(tstep, *node3, report_step * 6.0 + 4.0); + } + sim_seconds += ministep_length * 3; + } + rd_sum_fwrite(rd_sum); + return rd_sum; +} + +void test_load() { + rd::util::TestArea ta("rd_sum_loader"); + rd_sum_type *rd_sum = write_rd_sum(); + test_assert_true(util_file_exists("CASE.SMSPEC")); + test_assert_true(util_file_exists("CASE.UNSMRY")); + rd::unsmry_loader *loader = + new rd::unsmry_loader(rd_sum_get_smspec(rd_sum), "CASE.UNSMRY", 0); + + const std::vector FOPT_value = loader->get_vector(1); + const std::vector BPR_value = loader->get_vector(2); + const std::vector WWCT_value = loader->get_vector(3); + test_assert_int_equal(FOPT_value.size(), 4); + test_assert_double_equal(FOPT_value[3], 6.0); + test_assert_double_equal(BPR_value[2], 10.0); + test_assert_double_equal(WWCT_value[1], 10.0); + + delete loader; + rd_sum_free(rd_sum); +} + +int main() { + test_load(); + return 0; +} diff --git a/lib/resdata/tests/rd_valid_basename.cpp b/lib/resdata/tests/rd_valid_basename.cpp new file mode 100644 index 0000000000..b19e84e9ed --- /dev/null +++ b/lib/resdata/tests/rd_valid_basename.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main(int argc, char **argv) { + test_assert_true(rd_valid_basename_fmt("rd_%d.data")); + test_assert_true(rd_valid_basename_fmt("RD_%d.DATA")); + test_assert_true(rd_valid_basename_fmt("RD_%04d.DATA")); + test_assert_true(rd_valid_basename_fmt("mypath/RD_%04d.DATA")); + test_assert_true(rd_valid_basename_fmt("MYPATH/RD_%04d.DATA")); + test_assert_true(rd_valid_basename_fmt("MYPATH/RD_%04d.DATA")); + test_assert_true(rd_valid_basename_fmt("RD_%d.dATA")); + test_assert_false(rd_valid_basename_fmt("RD_%s.DATA")); + test_assert_false(rd_valid_basename_fmt("RD_%f.DATA")); + test_assert_true(rd_valid_basename_fmt("mypath/RD_%d.dATA")); + + exit(0); +} diff --git a/lib/resdata/tests/rdxx_filename.cpp b/lib/resdata/tests/rdxx_filename.cpp new file mode 100644 index 0000000000..6ce8138010 --- /dev/null +++ b/lib/resdata/tests/rdxx_filename.cpp @@ -0,0 +1,49 @@ +#include +#include + +void cmp(const char *expected, const std::string &value) { + test_assert_string_equal(expected, value.c_str()); +} + +int main(int argc, char **argv) { + cmp("BASE.X0067", ERT::RDFilename("BASE", RD_RESTART_FILE, 67)); + cmp("BASE.F0067", ERT::RDFilename("BASE", RD_RESTART_FILE, 67, true)); + + cmp("BASE.EGRID", ERT::RDFilename("BASE", RD_EGRID_FILE)); + cmp("BASE.FEGRID", ERT::RDFilename("BASE", RD_EGRID_FILE, true)); + + cmp("BASE.EGRID", ERT::RDFilename("BASE", RD_EGRID_FILE, 67)); + cmp("BASE.FEGRID", ERT::RDFilename("BASE", RD_EGRID_FILE, 67, true)); + + try { + ERT::RDFilename("BASE", RD_RESTART_FILE); + test_assert_true(false); + } catch (...) { + test_assert_true(true); + } + + cmp("PATH/BASE.X0067", + ERT::RDFilename("PATH", "BASE", RD_RESTART_FILE, 67)); + cmp("PATH/BASE.F0067", + ERT::RDFilename("PATH", "BASE", RD_RESTART_FILE, 67, true)); + + cmp("PATH/BASE.EGRID", ERT::RDFilename("PATH", "BASE", RD_EGRID_FILE)); + cmp("PATH/BASE.FEGRID", + ERT::RDFilename("PATH", "BASE", RD_EGRID_FILE, true)); + + cmp("PATH/BASE.EGRID", ERT::RDFilename("PATH", "BASE", RD_EGRID_FILE, 67)); + cmp("PATH/BASE.FEGRID", + ERT::RDFilename("PATH", "BASE", RD_EGRID_FILE, 67, true)); + + try { + ERT::RDFilename("PATH", "BASE", RD_RESTART_FILE); + test_assert_true(false); + } catch (...) { + test_assert_true(true); + } + + test_assert_int_equal(RD_EGRID_FILE, ERT::RDFiletype("CASE.EGRID")); + test_assert_int_equal(RD_RESTART_FILE, ERT::RDFiletype("CASE.F0098")); + test_assert_int_equal(RD_UNIFIED_RESTART_FILE, + ERT::RDFiletype("CASE.UNRST")); +} diff --git a/lib/ecl/tests/eclxx_fortio.cpp b/lib/resdata/tests/rdxx_fortio.cpp similarity index 90% rename from lib/ecl/tests/eclxx_fortio.cpp rename to lib/resdata/tests/rdxx_fortio.cpp index 114a3c0e57..fcb3b295f2 100644 --- a/lib/ecl/tests/eclxx_fortio.cpp +++ b/lib/resdata/tests/rdxx_fortio.cpp @@ -3,11 +3,11 @@ #include #include -#include -#include +#include +#include void test_open() { - ecl::util::TestArea ta("fortioxx"); + rd::util::TestArea ta("fortioxx"); ERT::FortIO fortio; fortio.open("new_file", std::fstream::out); @@ -53,7 +53,7 @@ void test_open() { } void test_fortio() { - ecl::util::TestArea ta("FORTIO"); + rd::util::TestArea ta("FORTIO"); ERT::FortIO fortio("new_file", std::fstream::out); { std::vector data; @@ -84,13 +84,13 @@ void test_fortio() { } void test_fortio_kw() { - ecl::util::TestArea ta("fortio_kw"); + rd::util::TestArea ta("fortio_kw"); std::vector vec(1000); for (size_t i = 0; i < vec.size(); i++) vec[i] = i; - ERT::EclKW kw("XYZ", vec); + ERT::ResdataKW kw("XYZ", vec); { ERT::FortIO fortio("new_file", std::fstream::out); @@ -100,7 +100,7 @@ void test_fortio_kw() { { ERT::FortIO fortio("new_file", std::fstream::in); - ERT::EclKW kw2 = ERT::EclKW::load(fortio); + ERT::ResdataKW kw2 = ERT::ResdataKW::load(fortio); fortio.close(); for (size_t i = 0; i < kw.size(); i++) test_assert_int_equal(kw.at(i), kw2.at(i)); diff --git a/lib/ecl/tests/eclxx_kw.cpp b/lib/resdata/tests/rdxx_kw.cpp similarity index 71% rename from lib/ecl/tests/eclxx_kw.cpp rename to lib/resdata/tests/rdxx_kw.cpp index fef9fa5798..773bc2ce06 100644 --- a/lib/ecl/tests/eclxx_kw.cpp +++ b/lib/resdata/tests/rdxx_kw.cpp @@ -3,15 +3,15 @@ #include -#include +#include -#include -#include +#include +#include #include void test_kw_name() { - ERT::EclKW kw1("short", 1); - ERT::EclKW kw2("verylong", 1); + ERT::ResdataKW kw1("short", 1); + ERT::ResdataKW kw2("verylong", 1); test_assert_string_equal(kw1.name(), "short"); test_assert_string_equal(kw2.name(), "verylong"); @@ -19,7 +19,7 @@ void test_kw_name() { void test_kw_vector_assign() { std::vector vec = {1, 2, 3, 4, 5}; - ERT::EclKW kw("XYZ", vec); + ERT::ResdataKW kw("XYZ", vec); test_assert_size_t_equal(kw.size(), vec.size()); @@ -38,7 +38,7 @@ void test_kw_vector_string() { std::vector vec = {"short", "sweet", "padded "}; std::vector too_long = {"1234567890"}; - ERT::EclKW kw("XYZ", vec); + ERT::ResdataKW kw("XYZ", vec); test_assert_size_t_equal(kw.size(), vec.size()); @@ -46,7 +46,7 @@ void test_kw_vector_string() { test_assert_string_equal(kw.at(1), "sweet "); test_assert_string_equal(kw.at(2), vec.at(2)); - test_assert_throw(ERT::EclKW("XY", too_long), + test_assert_throw(ERT::ResdataKW("XY", too_long), std::range_error); } @@ -57,7 +57,7 @@ void test_kw_vector_std_string() { "padded ", }; std::vector too_long = {"1234567890"}; - ERT::EclKW kw("XYZ", vec); + ERT::ResdataKW kw("XYZ", vec); test_assert_size_t_equal(kw.size(), vec.size()); @@ -65,13 +65,13 @@ void test_kw_vector_std_string() { test_assert_string_equal(kw.at(1).c_str(), "sweet "); test_assert_string_equal(kw.at(2).c_str(), vec.at(2)); - test_assert_throw(ERT::EclKW("XY", too_long), + test_assert_throw(ERT::ResdataKW("XY", too_long), std::range_error); } void test_logical() { //std::vector vec = {true,false,true,false}; - // ERT::EclKW kw("BOOL", vec); + // ERT::ResdataKW kw("BOOL", vec); // test_assert_int_equal(kw.size(), vec.size()); // for (size_t i=0; i < vec.size(); i++) @@ -80,25 +80,25 @@ void test_logical() { void test_move_semantics_no_crash() { std::vector vec = {1, 2, 3, 4, 5}; - ERT::EclKW kw1("XYZ", vec); + ERT::ResdataKW kw1("XYZ", vec); - ERT::EclKW kw2(std::move(kw1)); + ERT::ResdataKW kw2(std::move(kw1)); test_assert_true(kw1.get() == nullptr); } void test_exception_assing_ref_wrong_type() { - auto *ptr = ecl_kw_alloc("XYZ", 1, ECL_INT); + auto *ptr = rd_kw_alloc("XYZ", 1, RD_INT); try { - ERT::EclKW kw(ptr); + ERT::ResdataKW kw(ptr); test_assert_true(false); } catch (...) { - ERT::EclKW kw(ptr); + ERT::ResdataKW kw(ptr); } } void test_resize() { - ERT::EclKW kw1("short", 1); + ERT::ResdataKW kw1("short", 1); test_assert_int_equal(kw1.size(), 1); kw1.resize(100); @@ -112,27 +112,27 @@ void test_data() { std::vector b_data = {true, false}; std::vector s_data = {"S1", "S2", "S3"}; - ERT::EclKW d_kw("DOUBLE", d_data); + ERT::ResdataKW d_kw("DOUBLE", d_data); auto d_data2 = d_kw.data(); for (size_t i = 0; i < d_data.size(); i++) test_assert_true(d_data[i] == d_data2[i]); - ERT::EclKW f_kw("FLOATx", f_data); + ERT::ResdataKW f_kw("FLOATx", f_data); auto f_data2 = f_kw.data(); for (size_t i = 0; i < f_data.size(); i++) test_assert_true(f_data[i] == f_data2[i]); - ERT::EclKW i_kw("INT", i_data); + ERT::ResdataKW i_kw("INT", i_data); auto i_data2 = i_kw.data(); for (size_t i = 0; i < i_data.size(); i++) test_assert_true(i_data[i] == i_data2[i]); - //ERT::EclKW b_kw("bbb", b_data); + //ERT::ResdataKW b_kw("bbb", b_data); //auto b_data2 = b_kw.data(); //for (size_t i=0; i < b_data.size(); i++) // test_assert_true(b_data[i] == b_data2[i]); - ERT::EclKW s_kw("sss", s_data); + ERT::ResdataKW s_kw("sss", s_data); auto s_data2 = s_kw.data(); for (size_t i = 0; i < s_data.size(); i++) test_assert_true(s_data[i] == s_data2[i]); @@ -146,7 +146,7 @@ void test_read_write() { std::vector s_data = {"S1", "S2", "S3"}; { - ecl::util::TestArea ta("kw-read-write"); + rd::util::TestArea ta("kw-read-write"); { ERT::FortIO f("test_file", std::ios_base::out); ERT::write_kw(f, "DOUBLE", d_data); @@ -157,33 +157,33 @@ void test_read_write() { } { - ecl_file_type *f = ecl_file_open("test_file", 0); - ecl_kw_type *d_kw = ecl_file_iget_named_kw(f, "DOUBLE", 0); - ecl_kw_type *f_kw = ecl_file_iget_named_kw(f, "FLOAT", 0); - ecl_kw_type *i_kw = ecl_file_iget_named_kw(f, "INT", 0); - ecl_kw_type *b_kw = ecl_file_iget_named_kw(f, "BOOL", 0); - ecl_kw_type *s_kw = ecl_file_iget_named_kw(f, "STRING", 0); + rd_file_type *f = rd_file_open("test_file", 0); + rd_kw_type *d_kw = rd_file_iget_named_kw(f, "DOUBLE", 0); + rd_kw_type *f_kw = rd_file_iget_named_kw(f, "FLOAT", 0); + rd_kw_type *i_kw = rd_file_iget_named_kw(f, "INT", 0); + rd_kw_type *b_kw = rd_file_iget_named_kw(f, "BOOL", 0); + rd_kw_type *s_kw = rd_file_iget_named_kw(f, "STRING", 0); for (size_t i = 0; i < d_data.size(); i++) - test_assert_true(d_data[i] == ecl_kw_iget_double(d_kw, i)); + test_assert_true(d_data[i] == rd_kw_iget_double(d_kw, i)); for (size_t i = 0; i < f_data.size(); i++) - test_assert_true(f_data[i] == ecl_kw_iget_float(f_kw, i)); + test_assert_true(f_data[i] == rd_kw_iget_float(f_kw, i)); for (size_t i = 0; i < i_data.size(); i++) - test_assert_true(i_data[i] == ecl_kw_iget_int(i_kw, i)); + test_assert_true(i_data[i] == rd_kw_iget_int(i_kw, i)); for (size_t i = 0; i < b_data.size(); i++) - test_assert_true(b_data[i] == ecl_kw_iget_bool(b_kw, i)); + test_assert_true(b_data[i] == rd_kw_iget_bool(b_kw, i)); for (size_t i = 0; i < s_data.size(); i++) { - std::string s8 = ecl_kw_iget_char_ptr(s_kw, i); + std::string s8 = rd_kw_iget_char_ptr(s_kw, i); test_assert_int_equal(s8.size(), 8); s8.erase(s8.find_last_not_of(' ') + 1); test_assert_true(s_data[i] == s8); } - ecl_file_close(f); + rd_file_close(f); } } } diff --git a/lib/resdata/tests/rdxx_types.cpp b/lib/resdata/tests/rdxx_types.cpp new file mode 100644 index 0000000000..0d48e5cf23 --- /dev/null +++ b/lib/resdata/tests/rdxx_types.cpp @@ -0,0 +1,37 @@ +#include +#include + +#include +#include +#include + +void test_RD_INT() { + rd_data_type dt = RD_INT; + test_assert_int_equal(dt.element_size, sizeof(int)); + test_assert_int_equal(dt.type, RD_INT_TYPE); +} + +void test_RD_FLOAT() { + rd_data_type dt = RD_FLOAT; + test_assert_int_equal(dt.element_size, sizeof(float)); + test_assert_int_equal(dt.type, RD_FLOAT_TYPE); +} + +void test_RD_DOUBLE() { + rd_data_type dt = RD_DOUBLE; + test_assert_int_equal(dt.element_size, sizeof(double)); + test_assert_int_equal(dt.type, RD_DOUBLE_TYPE); +} + +void test_RD_CHAR() { + rd_data_type dt = RD_CHAR; + test_assert_int_equal(dt.element_size, RD_STRING8_LENGTH + 1); + test_assert_int_equal(dt.type, RD_CHAR_TYPE); +} + +int main(int argc, char **argv) { + test_RD_INT(); + test_RD_FLOAT(); + test_RD_DOUBLE(); + test_RD_CHAR(); +} diff --git a/lib/ecl/tests/rft_test.cpp b/lib/resdata/tests/rft_test.cpp similarity index 58% rename from lib/ecl/tests/rft_test.cpp rename to lib/resdata/tests/rft_test.cpp index 21123afe90..15fe4a7a8d 100644 --- a/lib/ecl/tests/rft_test.cpp +++ b/lib/resdata/tests/rft_test.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include @@ -8,8 +8,8 @@ int main(int argc, char **argv) { util_exit("I want one RFT file - try again \n"); { const char *filename = argv[1]; - ecl_rft_file_type *rft_file = ecl_rft_file_alloc(filename); - stringlist_type *wells = ecl_rft_file_alloc_well_list(rft_file); + rd_rft_file_type *rft_file = rd_rft_file_alloc(filename); + stringlist_type *wells = rd_rft_file_alloc_well_list(rft_file); printf("\n"); { @@ -20,11 +20,11 @@ int main(int argc, char **argv) { { int it; for (it = 0; - it < ecl_rft_file_get_well_occurences(rft_file, well); + it < rd_rft_file_get_well_occurences(rft_file, well); it++) { - const ecl_rft_node_type *node = - ecl_rft_file_iget_well_rft(rft_file, well, it); - time_t date = ecl_rft_node_get_date(node); + const rd_rft_node_type *node = + rd_rft_file_iget_well_rft(rft_file, well, it); + time_t date = rd_rft_node_get_date(node); { int mday, year, month; util_set_date_values(date, &mday, &month, &year); @@ -32,21 +32,20 @@ int main(int argc, char **argv) { printf(" %02d/%02d/%4d \n", mday, month, year); { - int num_cells = ecl_rft_node_get_size(node); + int num_cells = rd_rft_node_get_size(node); int icell; for (icell = 0; icell < num_cells; icell++) { int i, j, k; - ecl_rft_node_iget_ijk(node, icell, &i, &j, - &k); + rd_rft_node_iget_ijk(node, icell, &i, &j, + &k); printf(" \n"); - printf(" %g " - " \n", - ecl_rft_node_iget_pressure(node, - icell)); printf( - " %g " - " \n", - ecl_rft_node_iget_depth(node, icell)); + " %g " + " \n", + rd_rft_node_iget_pressure(node, icell)); + printf(" %g " + " \n", + rd_rft_node_iget_depth(node, icell)); printf(" %3d,%3d,%3d " " \n", i, j, k); @@ -61,6 +60,6 @@ int main(int argc, char **argv) { } } printf("\n"); - ecl_rft_file_free(rft_file); + rd_rft_file_free(rft_file); } } diff --git a/lib/resdata/tests/test_rd_file_index.cpp b/lib/resdata/tests/test_rd_file_index.cpp new file mode 100644 index 0000000000..145e791b7b --- /dev/null +++ b/lib/resdata/tests/test_rd_file_index.cpp @@ -0,0 +1,91 @@ +#include +#include + +#include +#include +#include + +#include +#include + +void test_load_nonexisting_file() { + rd_file_type *rd_file = + rd_file_fast_open("base_file", "a_file_that_does_not_exist_2384623", 0); + test_assert_NULL(rd_file); +} + +void test_create_and_load_index_file() { + + rd::util::TestArea ta("Load_index"); + { + const char *file_name = "initial_data_file"; + const char *index_file_name = "index_file"; + + //creating the data file + int data_size = 10; + rd_kw_type *kw1 = rd_kw_alloc("TEST1_KW", data_size, RD_INT); + for (int i = 0; i < data_size; ++i) + rd_kw_iset_int(kw1, i, 537 + i); + fortio_type *fortio = + fortio_open_writer(file_name, false, RD_ENDIAN_FLIP); + rd_kw_fwrite(kw1, fortio); + + data_size = 5; + rd_kw_type *kw2 = rd_kw_alloc("TEST2_KW", data_size, RD_FLOAT); + for (int i = 0; i < data_size; ++i) + rd_kw_iset_float(kw2, i, 0.15 * i); + rd_kw_fwrite(kw2, fortio); + fortio_fclose(fortio); + //finished creating data file + + //creating rd_file + rd_file_type *rd_file = rd_file_open(file_name, 0); + test_assert_true(rd_file_has_kw(rd_file, "TEST1_KW")); + rd_file_write_index(rd_file, index_file_name); + int rd_file_size = rd_file_get_size(rd_file); + rd_file_close(rd_file); + //finished using rd_file + + test_assert_false(rd_file_index_valid(file_name, "nofile")); + test_assert_false(rd_file_index_valid("nofile", index_file_name)); + + struct utimbuf tm1 = {1, 1}; + struct utimbuf tm2 = {2, 2}; + utime(file_name, &tm2); + utime(index_file_name, &tm1); + test_assert_false(rd_file_index_valid(file_name, index_file_name)); + utime(file_name, &tm1); + utime(index_file_name, &tm2); + test_assert_true(rd_file_index_valid(file_name, index_file_name)); + + rd_file_type *rd_file_index = + rd_file_fast_open(file_name, index_file_name, 0); + test_assert_true(rd_file_is_instance(rd_file_index)); + test_assert_true(rd_file_get_global_view(rd_file_index)); + + test_assert_int_equal(rd_file_size, rd_file_get_size(rd_file_index)); + + test_assert_true(rd_file_has_kw(rd_file_index, "TEST1_KW")); + test_assert_true(rd_file_has_kw(rd_file_index, "TEST2_KW")); + + rd_kw_type *kwi1 = rd_file_iget_kw(rd_file_index, 0); + test_assert_true(rd_kw_equal(kw1, kwi1)); + test_assert_double_equal(537.0, rd_kw_iget_as_double(kwi1, 0)); + test_assert_double_equal(546.0, rd_kw_iget_as_double(kwi1, 9)); + + rd_kw_type *kwi2 = rd_file_iget_kw(rd_file_index, 1); + test_assert_true(rd_kw_equal(kw2, kwi2)); + test_assert_double_equal(0.15, rd_kw_iget_as_double(kwi2, 1)); + test_assert_double_equal(0.60, rd_kw_iget_as_double(kwi2, 4)); + + rd_kw_free(kw1); + rd_kw_free(kw2); + rd_file_close(rd_file_index); + } +} + +int main(int argc, char **argv) { + util_install_signals(); + test_load_nonexisting_file(); + test_create_and_load_index_file(); +} diff --git a/lib/resdata/tests/test_rd_nnc_data.cpp b/lib/resdata/tests/test_rd_nnc_data.cpp new file mode 100644 index 0000000000..a9ed959598 --- /dev/null +++ b/lib/resdata/tests/test_rd_nnc_data.cpp @@ -0,0 +1,81 @@ +#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; +} diff --git a/lib/resdata/tests/test_transactions.cpp b/lib/resdata/tests/test_transactions.cpp new file mode 100644 index 0000000000..bd04f0632c --- /dev/null +++ b/lib/resdata/tests/test_transactions.cpp @@ -0,0 +1,97 @@ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* + This test is slightly awkward beacuse it tests quite internal implementation details. +*/ + +void test_transaction() { + + rd::util::TestArea ta("index_testing"); + { + const char *file_name = "data_file"; + fortio_type *fortio = + fortio_open_writer(file_name, false, RD_ENDIAN_FLIP); + + //creating the data file + int data_size = 10; + rd_kw_type *kw1 = rd_kw_alloc("TEST1_KW", data_size, RD_INT); + for (int i = 0; i < data_size; ++i) + rd_kw_iset_int(kw1, i, 537 + i); + rd_kw_fwrite(kw1, fortio); + + data_size = 5; + rd_kw_type *kw2 = rd_kw_alloc("TEST2_KW", data_size, RD_FLOAT); + for (int i = 0; i < data_size; ++i) + rd_kw_iset_float(kw2, i, 0.15 * i); + rd_kw_fwrite(kw2, fortio); + + data_size = 3; + rd_kw_type *kw3 = rd_kw_alloc("TEST3_KW", data_size, RD_FLOAT); + for (int i = 0; i < data_size; i++) + rd_kw_iset_float(kw3, i, 0.45 * i); + rd_kw_fwrite(kw3, fortio); + + fortio_fclose(fortio); + //finished creating data file + + rd_file_type *file = rd_file_open(file_name, 0); + rd_file_view_type *file_view = rd_file_get_global_view(file); + rd_file_kw_type *file_kw0 = rd_file_view_iget_file_kw(file_view, 0); + rd_file_kw_type *file_kw1 = rd_file_view_iget_file_kw(file_view, 1); + rd_file_kw_type *file_kw2 = rd_file_view_iget_file_kw(file_view, 2); + + rd_file_view_iget_kw(file_view, 0); + test_assert_true(rd_file_kw_get_kw_ptr(file_kw0)); + test_assert_false(rd_file_kw_get_kw_ptr(file_kw1)); + test_assert_false(rd_file_kw_get_kw_ptr(file_kw2)); + rd_file_transaction_type *t1 = + rd_file_view_start_transaction(file_view); + + rd_file_view_iget_kw(file_view, 0); + rd_file_view_iget_kw(file_view, 1); + rd_file_transaction_type *t2 = + rd_file_view_start_transaction(file_view); + + rd_file_view_iget_kw(file_view, 0); + rd_file_view_iget_kw(file_view, 1); + rd_file_view_iget_kw(file_view, 1); + rd_file_view_iget_kw(file_view, 2); + + rd_file_view_end_transaction(file_view, t2); + + test_assert_true(rd_file_kw_get_kw_ptr(file_kw0)); + test_assert_true(rd_file_kw_get_kw_ptr(file_kw1)); + test_assert_false(rd_file_kw_get_kw_ptr(file_kw2)); + rd_file_view_iget_kw(file_view, 2); + + rd_file_view_end_transaction(file_view, t1); + test_assert_true(rd_file_kw_get_kw_ptr(file_kw0)); + test_assert_false(rd_file_kw_get_kw_ptr(file_kw1)); + test_assert_false(rd_file_kw_get_kw_ptr(file_kw2)); + + rd_file_close(file); + rd_kw_free(kw1); + rd_kw_free(kw2); + rd_kw_free(kw3); + } +} + +int main(int argc, char **argv) { + util_install_signals(); + test_transaction(); + exit(0); +} diff --git a/lib/ecl/tests/well_branch_collection.cpp b/lib/resdata/tests/well_branch_collection.cpp similarity index 92% rename from lib/ecl/tests/well_branch_collection.cpp rename to lib/resdata/tests/well_branch_collection.cpp index d67e03b945..3644d4f1c9 100644 --- a/lib/ecl/tests/well_branch_collection.cpp +++ b/lib/resdata/tests/well_branch_collection.cpp @@ -5,11 +5,11 @@ #include #include -#include +#include -#include -#include -#include +#include +#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); diff --git a/lib/ecl/tests/well_conn.cpp b/lib/resdata/tests/well_conn.cpp similarity index 97% rename from lib/ecl/tests/well_conn.cpp rename to lib/resdata/tests/well_conn.cpp index 67a2b76a97..60612a1c37 100644 --- a/lib/ecl/tests/well_conn.cpp +++ b/lib/resdata/tests/well_conn.cpp @@ -5,10 +5,10 @@ #include #include -#include +#include -#include -#include +#include +#include void test_conn_rate() { int i = 10; diff --git a/lib/ecl/tests/well_conn_CF.cpp b/lib/resdata/tests/well_conn_CF.cpp similarity index 58% rename from lib/ecl/tests/well_conn_CF.cpp rename to lib/resdata/tests/well_conn_CF.cpp index 193f8f9145..c316289d83 100644 --- a/lib/ecl/tests/well_conn_CF.cpp +++ b/lib/resdata/tests/well_conn_CF.cpp @@ -5,18 +5,18 @@ #include #include -#include -#include -#include -#include - -#include -#include -#include - -void well_conn_test_CF(const ecl_kw_type *iwel_kw, const ecl_kw_type *icon_kw, - const ecl_kw_type *scon_kw, const ecl_kw_type *xcon_kw, - const ecl_rsthead_type *rst_head, int iwell, int iconn, +#include +#include +#include +#include + +#include +#include +#include + +void well_conn_test_CF(const rd_kw_type *iwel_kw, const rd_kw_type *icon_kw, + const rd_kw_type *scon_kw, const rd_kw_type *xcon_kw, + const rd_rsthead_type *rst_head, int iwell, int iconn, double CF) { well_conn_type *conn = well_conn_alloc_from_kw(icon_kw, scon_kw, xcon_kw, rst_head, iwell, iconn); @@ -26,13 +26,13 @@ void well_conn_test_CF(const ecl_kw_type *iwel_kw, const ecl_kw_type *icon_kw, int main(int argc, char **argv) { const char *Xfile = argv[1]; - ecl_file_type *rst_file = ecl_file_open(Xfile, 0); - ecl_rsthead_type *rst_head = ecl_rsthead_alloc( - ecl_file_get_global_view(rst_file), ecl_util_filename_report_nr(Xfile)); - const ecl_kw_type *iwel_kw = ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - const ecl_kw_type *icon_kw = ecl_file_iget_named_kw(rst_file, ICON_KW, 0); - const ecl_kw_type *scon_kw = ecl_file_iget_named_kw(rst_file, SCON_KW, 0); - const ecl_kw_type *xcon_kw = 0; + rd_file_type *rst_file = rd_file_open(Xfile, 0); + rd_rsthead_type *rst_head = rd_rsthead_alloc( + rd_file_get_global_view(rst_file), rd_filename_report_nr(Xfile)); + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + const rd_kw_type *icon_kw = rd_file_iget_named_kw(rst_file, ICON_KW, 0); + const rd_kw_type *scon_kw = rd_file_iget_named_kw(rst_file, SCON_KW, 0); + const rd_kw_type *xcon_kw = 0; well_conn_test_CF(iwel_kw, icon_kw, scon_kw, xcon_kw, rst_head, 0, 0, 32.948); @@ -55,7 +55,7 @@ int main(int argc, char **argv) { well_conn_test_CF(iwel_kw, icon_kw, scon_kw, xcon_kw, rst_head, 2, 2, 18.032); - ecl_file_close(rst_file); - ecl_rsthead_free(rst_head); + rd_file_close(rst_file); + rd_rsthead_free(rst_head); exit(0); } diff --git a/lib/ecl/tests/well_conn_collection.cpp b/lib/resdata/tests/well_conn_collection.cpp similarity index 86% rename from lib/ecl/tests/well_conn_collection.cpp rename to lib/resdata/tests/well_conn_collection.cpp index 67dd5278d9..7c1258a754 100644 --- a/lib/ecl/tests/well_conn_collection.cpp +++ b/lib/resdata/tests/well_conn_collection.cpp @@ -5,10 +5,10 @@ #include #include -#include +#include -#include -#include +#include +#include void test_empty() { well_conn_collection_type *wellcc = well_conn_collection_alloc(); diff --git a/lib/ecl/tests/well_conn_load.cpp b/lib/resdata/tests/well_conn_load.cpp similarity index 79% rename from lib/ecl/tests/well_conn_load.cpp rename to lib/resdata/tests/well_conn_load.cpp index 593dedf785..085ed9e7a6 100644 --- a/lib/ecl/tests/well_conn_load.cpp +++ b/lib/resdata/tests/well_conn_load.cpp @@ -5,21 +5,21 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include +#include +#include +#include int main(int argc, char **argv) { const char *Xfile = argv[1]; bool MSW; - ecl_file_type *rst_file = ecl_file_open(Xfile, 0); - ecl_rsthead_type *rst_head = ecl_rsthead_alloc( - ecl_file_get_global_view(rst_file), ecl_util_filename_report_nr(Xfile)); + rd_file_type *rst_file = rd_file_open(Xfile, 0); + rd_rsthead_type *rst_head = rd_rsthead_alloc( + rd_file_get_global_view(rst_file), rd_filename_report_nr(Xfile)); test_install_SIGNALS(); test_assert_true(util_sscanf_bool(argv[2], &MSW)); @@ -28,19 +28,17 @@ int main(int argc, char **argv) { { int iwell; - const ecl_kw_type *iwel_kw = - ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - const ecl_kw_type *icon_kw = - ecl_file_iget_named_kw(rst_file, ICON_KW, 0); - ecl_kw_type *scon_kw = NULL; - ecl_kw_type *xcon_kw = NULL; + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + const rd_kw_type *icon_kw = rd_file_iget_named_kw(rst_file, ICON_KW, 0); + rd_kw_type *scon_kw = NULL; + rd_kw_type *xcon_kw = NULL; bool caseMSW = false; for (iwell = 0; iwell < rst_head->nwells; iwell++) { const int iwel_offset = rst_head->niwelz * iwell; int num_connections = - ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_CONNECTIONS_INDEX); + rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_CONNECTIONS_INDEX); int iconn; well_conn_collection_type *wellcc = well_conn_collection_alloc(); well_conn_collection_type *wellcc_ref = diff --git a/lib/ecl/tests/well_dualp.cpp b/lib/resdata/tests/well_dualp.cpp similarity index 63% rename from lib/ecl/tests/well_dualp.cpp rename to lib/resdata/tests/well_dualp.cpp index 353161ecea..a7102c8288 100644 --- a/lib/ecl/tests/well_dualp.cpp +++ b/lib/resdata/tests/well_dualp.cpp @@ -5,19 +5,18 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include void test_rstfile(const char *filename, bool fracture_connection) { - ecl_file_type *rst_file = ecl_file_open(filename, 0); - const ecl_kw_type *iwel_kw = ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - ecl_rsthead_type *header = - ecl_rsthead_alloc(ecl_file_get_global_view(rst_file), - ecl_util_filename_report_nr(filename)); + rd_file_type *rst_file = rd_file_open(filename, 0); + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + rd_rsthead_type *header = rd_rsthead_alloc( + rd_file_get_global_view(rst_file), rd_filename_report_nr(filename)); well_conn_type *wellhead = well_conn_alloc_wellhead(iwel_kw, header, 0); @@ -31,9 +30,9 @@ void test_rstfile(const char *filename, bool fracture_connection) { test_assert_true(well_conn_get_k(wellhead) < header->nz); - ecl_rsthead_free(header); + rd_rsthead_free(header); well_conn_free(wellhead); - ecl_file_close(rst_file); + rd_file_close(rst_file); } int main(int argc, char **argv) { diff --git a/lib/ecl/tests/well_info.cpp b/lib/resdata/tests/well_info.cpp similarity index 74% rename from lib/ecl/tests/well_info.cpp rename to lib/resdata/tests/well_info.cpp index ba8c7f83b3..cc00e01e6a 100644 --- a/lib/ecl/tests/well_info.cpp +++ b/lib/resdata/tests/well_info.cpp @@ -5,16 +5,16 @@ #include #include -#include -#include +#include +#include -#include +#include int main(int argc, char **argv) { util_install_signals(); const char *grid_file = argv[1]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); + rd_grid_type *grid = rd_grid_alloc(grid_file); test_assert_not_NULL(grid); { well_info_type *well_info = well_info_alloc(grid); @@ -24,6 +24,6 @@ int main(int argc, char **argv) { well_info_free(well_info); } - ecl_grid_free(grid); + rd_grid_free(grid); exit(0); } diff --git a/lib/ecl/tests/well_lgr_load.cpp b/lib/resdata/tests/well_lgr_load.cpp similarity index 79% rename from lib/ecl/tests/well_lgr_load.cpp rename to lib/resdata/tests/well_lgr_load.cpp index bdf824384e..ebb43aa09b 100644 --- a/lib/ecl/tests/well_lgr_load.cpp +++ b/lib/resdata/tests/well_lgr_load.cpp @@ -6,15 +6,15 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { signal(SIGSEGV, util_abort_signal); /* Segmentation violation, @@ -26,7 +26,7 @@ int main(int argc, char **argv) { backtrace.*/ signal(SIGABRT, util_abort_signal); /* Signal abort. */ { - ecl_grid_type *grid = ecl_grid_alloc(argv[1]); + rd_grid_type *grid = rd_grid_alloc(argv[1]); well_info_type *well_info = well_info_alloc(grid); well_info_load_rstfile(well_info, argv[2], true); diff --git a/lib/ecl/tests/well_segment.cpp b/lib/resdata/tests/well_segment.cpp similarity index 97% rename from lib/ecl/tests/well_segment.cpp rename to lib/resdata/tests/well_segment.cpp index ce29c34c04..7639a74317 100644 --- a/lib/ecl/tests/well_segment.cpp +++ b/lib/resdata/tests/well_segment.cpp @@ -5,10 +5,10 @@ #include #include -#include +#include -#include -#include +#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); diff --git a/lib/ecl/tests/well_segment_branch_conn_load.cpp b/lib/resdata/tests/well_segment_branch_conn_load.cpp similarity index 78% rename from lib/ecl/tests/well_segment_branch_conn_load.cpp rename to lib/resdata/tests/well_segment_branch_conn_load.cpp index df959f57a3..f471c7754f 100644 --- a/lib/ecl/tests/well_segment_branch_conn_load.cpp +++ b/lib/resdata/tests/well_segment_branch_conn_load.cpp @@ -6,30 +6,30 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include int main(int argc, char **argv) { const char *Xfile = argv[1]; - ecl_file_type *rst_file = ecl_file_open(Xfile, 0); - ecl_file_view_type *rst_view = ecl_file_get_active_view(rst_file); - ecl_rsthead_type *rst_head = - ecl_rsthead_alloc(rst_view, ecl_util_filename_report_nr(Xfile)); - const ecl_kw_type *iwel_kw = ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - const ecl_kw_type *iseg_kw = ecl_file_iget_named_kw(rst_file, ISEG_KW, 0); + rd_file_type *rst_file = rd_file_open(Xfile, 0); + rd_file_view_type *rst_view = rd_file_get_active_view(rst_file); + rd_rsthead_type *rst_head = + rd_rsthead_alloc(rst_view, rd_filename_report_nr(Xfile)); + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + const rd_kw_type *iseg_kw = rd_file_iget_named_kw(rst_file, ISEG_KW, 0); well_rseg_loader_type *rseg_loader = well_rseg_loader_alloc(rst_view); - const ecl_kw_type *icon_kw = ecl_file_iget_named_kw(rst_file, ICON_KW, 0); - const ecl_kw_type *scon_kw = NULL; - const ecl_kw_type *xcon_kw = NULL; + const rd_kw_type *icon_kw = rd_file_iget_named_kw(rst_file, ICON_KW, 0); + const rd_kw_type *scon_kw = NULL; + const rd_kw_type *xcon_kw = NULL; test_install_SIGNALS(); test_assert_not_NULL(rst_file); @@ -99,7 +99,7 @@ int main(int argc, char **argv) { } } well_segment_collection_add_connections( - segments, ECL_GRID_GLOBAL_GRID, connections); + segments, RD_GRID_GLOBAL_GRID, connections); well_branch_collection_free(branches); } else test_assert_false( @@ -111,7 +111,7 @@ int main(int argc, char **argv) { } } - ecl_file_close(rst_file); - ecl_rsthead_free(rst_head); + rd_file_close(rst_file); + rd_rsthead_free(rst_head); exit(0); } diff --git a/lib/ecl/tests/well_segment_collection.cpp b/lib/resdata/tests/well_segment_collection.cpp similarity index 95% rename from lib/ecl/tests/well_segment_collection.cpp rename to lib/resdata/tests/well_segment_collection.cpp index 8b21937782..a6b8b28e39 100644 --- a/lib/ecl/tests/well_segment_collection.cpp +++ b/lib/resdata/tests/well_segment_collection.cpp @@ -5,10 +5,10 @@ #include #include -#include +#include -#include -#include +#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); diff --git a/lib/ecl/tests/well_segment_conn.cpp b/lib/resdata/tests/well_segment_conn.cpp similarity index 74% rename from lib/ecl/tests/well_segment_conn.cpp rename to lib/resdata/tests/well_segment_conn.cpp index cda41ee9f5..ec54918cc0 100644 --- a/lib/ecl/tests/well_segment_conn.cpp +++ b/lib/resdata/tests/well_segment_conn.cpp @@ -5,13 +5,13 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); @@ -31,18 +31,18 @@ int main(int argc, char **argv) { test_assert_false(well_segment_has_global_grid_connections(ws)); test_assert_true( - well_segment_add_connection(ws, ECL_GRID_GLOBAL_GRID, conn1)); + well_segment_add_connection(ws, RD_GRID_GLOBAL_GRID, conn1)); test_assert_false( - well_segment_add_connection(ws, ECL_GRID_GLOBAL_GRID, conn2)); + well_segment_add_connection(ws, RD_GRID_GLOBAL_GRID, conn2)); test_assert_true( - well_segment_has_grid_connections(ws, ECL_GRID_GLOBAL_GRID)); + well_segment_has_grid_connections(ws, RD_GRID_GLOBAL_GRID)); test_assert_true(well_segment_has_global_grid_connections(ws)); test_assert_false( well_segment_has_grid_connections(ws, "DoesNotExist")); test_assert_true(well_conn_collection_is_instance( - well_segment_get_connections(ws, ECL_GRID_GLOBAL_GRID))); + well_segment_get_connections(ws, RD_GRID_GLOBAL_GRID))); test_assert_true(well_conn_collection_is_instance( well_segment_get_global_connections(ws))); test_assert_NULL(well_segment_get_connections(ws, "doesNotExist")); diff --git a/lib/ecl/tests/well_segment_conn_load.cpp b/lib/resdata/tests/well_segment_conn_load.cpp similarity index 80% rename from lib/ecl/tests/well_segment_conn_load.cpp rename to lib/resdata/tests/well_segment_conn_load.cpp index a0ea9f0002..ee8567692c 100644 --- a/lib/ecl/tests/well_segment_conn_load.cpp +++ b/lib/resdata/tests/well_segment_conn_load.cpp @@ -6,25 +6,25 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { const char *Xfile = argv[1]; - ecl_file_type *rst_file = ecl_file_open(Xfile, 0); - ecl_rsthead_type *rst_head = ecl_rsthead_alloc(rst_file); - const ecl_kw_type *iwel_kw = ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - const ecl_kw_type *iseg_kw = ecl_file_iget_named_kw(rst_file, ISEG_KW, 0); - const ecl_kw_type *rseg_kw = ecl_file_iget_named_kw(rst_file, RSEG_KW, 0); - const ecl_kw_type *icon_kw = ecl_file_iget_named_kw(rst_file, ICON_KW, 0); + rd_file_type *rst_file = rd_file_open(Xfile, 0); + rd_rsthead_type *rst_head = rd_rsthead_alloc(rst_file); + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + const rd_kw_type *iseg_kw = rd_file_iget_named_kw(rst_file, ISEG_KW, 0); + const rd_kw_type *rseg_kw = rd_file_iget_named_kw(rst_file, RSEG_KW, 0); + const rd_kw_type *icon_kw = rd_file_iget_named_kw(rst_file, ICON_KW, 0); test_install_SIGNALS(); test_assert_not_NULL(rst_file); @@ -92,7 +92,7 @@ int main(int argc, char **argv) { } } well_segment_collection_add_connections( - segments, ECL_GRID_GLOBAL_GRID, connections); + segments, RD_GRID_GLOBAL_GRID, connections); well_branch_collection_free(branches); } else test_assert_false( @@ -104,7 +104,7 @@ int main(int argc, char **argv) { } } - ecl_file_close(rst_file); - ecl_rsthead_free(rst_head); + rd_file_close(rst_file); + rd_rsthead_free(rst_head); exit(0); } diff --git a/lib/ecl/tests/well_segment_load.cpp b/lib/resdata/tests/well_segment_load.cpp similarity index 76% rename from lib/ecl/tests/well_segment_load.cpp rename to lib/resdata/tests/well_segment_load.cpp index bdf6d876b3..dab23e7095 100644 --- a/lib/ecl/tests/well_segment_load.cpp +++ b/lib/resdata/tests/well_segment_load.cpp @@ -5,24 +5,24 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include int main(int argc, char **argv) { const char *Xfile = argv[1]; - ecl_file_type *rst_file = ecl_file_open(Xfile, 0); - ecl_file_view_type *rst_view = ecl_file_get_active_view(rst_file); - ecl_rsthead_type *rst_head = - ecl_rsthead_alloc(rst_view, ecl_util_filename_report_nr(Xfile)); - const ecl_kw_type *iwel_kw = ecl_file_iget_named_kw(rst_file, IWEL_KW, 0); - const ecl_kw_type *iseg_kw = ecl_file_iget_named_kw(rst_file, ISEG_KW, 0); + rd_file_type *rst_file = rd_file_open(Xfile, 0); + rd_file_view_type *rst_view = rd_file_get_active_view(rst_file); + rd_rsthead_type *rst_head = + rd_rsthead_alloc(rst_view, rd_filename_report_nr(Xfile)); + const rd_kw_type *iwel_kw = rd_file_iget_named_kw(rst_file, IWEL_KW, 0); + const rd_kw_type *iseg_kw = rd_file_iget_named_kw(rst_file, ISEG_KW, 0); well_rseg_loader_type *rseg_loader = well_rseg_loader_alloc(rst_view); test_install_SIGNALS(); @@ -37,8 +37,8 @@ int main(int argc, char **argv) { well_segment_collection_type *segments = well_segment_collection_alloc(); int seg_well_nr = - ecl_kw_iget_int(iwel_kw, - iwel_offset + IWEL_SEGMENTED_WELL_NR_INDEX) - + rd_kw_iget_int(iwel_kw, + iwel_offset + IWEL_SEGMENTED_WELL_NR_INDEX) - 1; // -1: Ordinary well. if (seg_well_nr >= 0) { int segment_index; @@ -90,7 +90,7 @@ int main(int argc, char **argv) { } } } - ecl_file_close(rst_file); - ecl_rsthead_free(rst_head); + rd_file_close(rst_file); + rd_rsthead_free(rst_head); exit(0); } diff --git a/lib/ecl/tests/well_state.cpp b/lib/resdata/tests/well_state.cpp similarity index 71% rename from lib/ecl/tests/well_state.cpp rename to lib/resdata/tests/well_state.cpp index b6a996128e..a4a0cac2b3 100644 --- a/lib/ecl/tests/well_state.cpp +++ b/lib/resdata/tests/well_state.cpp @@ -5,25 +5,23 @@ #include #include -#include +#include -#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); test_assert_int_equal( - well_state_translate_ecl_type_int(IWEL_UNDOCUMENTED_ZERO), - ECL_WELL_ZERO); - test_assert_int_equal(well_state_translate_ecl_type_int(IWEL_PRODUCER), - ECL_WELL_PRODUCER); - test_assert_int_equal( - well_state_translate_ecl_type_int(IWEL_WATER_INJECTOR), - ECL_WELL_WATER_INJECTOR); - test_assert_int_equal(well_state_translate_ecl_type_int(IWEL_GAS_INJECTOR), - ECL_WELL_GAS_INJECTOR); - test_assert_int_equal(well_state_translate_ecl_type_int(IWEL_OIL_INJECTOR), - ECL_WELL_OIL_INJECTOR); + well_state_translate_rd_type_int(IWEL_UNDOCUMENTED_ZERO), RD_WELL_ZERO); + test_assert_int_equal(well_state_translate_rd_type_int(IWEL_PRODUCER), + RD_WELL_PRODUCER); + test_assert_int_equal(well_state_translate_rd_type_int(IWEL_WATER_INJECTOR), + RD_WELL_WATER_INJECTOR); + test_assert_int_equal(well_state_translate_rd_type_int(IWEL_GAS_INJECTOR), + RD_WELL_GAS_INJECTOR); + test_assert_int_equal(well_state_translate_rd_type_int(IWEL_OIL_INJECTOR), + RD_WELL_OIL_INJECTOR); { const char *well_name = "WELL"; @@ -31,7 +29,7 @@ int main(int argc, char **argv) { int global_well_nr = 67; time_t valid_from = -1; bool open = false; - well_type_enum type = ECL_WELL_GAS_INJECTOR; + well_type_enum type = RD_WELL_GAS_INJECTOR; well_state_type *well_state = well_state_alloc( well_name, global_well_nr, open, type, report_nr, valid_from); diff --git a/lib/ecl/tests/well_state_load.cpp b/lib/resdata/tests/well_state_load.cpp similarity index 75% rename from lib/ecl/tests/well_state_load.cpp rename to lib/resdata/tests/well_state_load.cpp index 500fbd6378..444acf6a9e 100644 --- a/lib/ecl/tests/well_state_load.cpp +++ b/lib/resdata/tests/well_state_load.cpp @@ -5,12 +5,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); @@ -18,19 +18,19 @@ int main(int argc, char **argv) { const char *grid_file = argv[1]; const char *rst_file_name = argv[2]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); - ecl_file_type *rst_file = ecl_file_open(rst_file_name, 0); - ecl_rsthead_type *header = - ecl_rsthead_alloc(ecl_file_get_global_view(rst_file), - ecl_util_filename_report_nr(rst_file_name)); + rd_grid_type *grid = rd_grid_alloc(grid_file); + rd_file_type *rst_file = rd_file_open(rst_file_name, 0); + rd_rsthead_type *header = + rd_rsthead_alloc(rd_file_get_global_view(rst_file), + rd_filename_report_nr(rst_file_name)); const char *well_name = "WELL"; int report_nr = 100; time_t valid_from = -1; bool open = false; - well_type_enum type = ECL_WELL_GAS_INJECTOR; + well_type_enum type = RD_WELL_GAS_INJECTOR; int global_well_nr = 0; bool load_segment_information = true; - ecl_file_view_type *rst_view = ecl_file_get_global_view(rst_file); + rd_file_view_type *rst_view = rd_file_get_global_view(rst_file); for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) { @@ -40,7 +40,7 @@ int main(int argc, char **argv) { well_state_add_connections2(well_state, grid, rst_view, 0); test_assert_true(well_state_has_grid_connections( - well_state, ECL_GRID_GLOBAL_GRID)); + well_state, RD_GRID_GLOBAL_GRID)); test_assert_false( well_state_has_grid_connections(well_state, "???")); test_assert_true(well_state_has_global_connections(well_state)); @@ -54,7 +54,7 @@ int main(int argc, char **argv) { well_state_get_branches(well_state); if (well_state_is_MSW(well_state)) { - test_assert_true(ecl_file_has_kw(rst_file, ISEG_KW)); + test_assert_true(rd_file_has_kw(rst_file, ISEG_KW)); test_assert_int_not_equal( well_segment_collection_get_size(segments), 0); test_assert_int_not_equal( diff --git a/lib/ecl/tests/well_state_load_missing_RSEG.cpp b/lib/resdata/tests/well_state_load_missing_RSEG.cpp similarity index 68% rename from lib/ecl/tests/well_state_load_missing_RSEG.cpp rename to lib/resdata/tests/well_state_load_missing_RSEG.cpp index 10912c6d87..80bb85925c 100644 --- a/lib/ecl/tests/well_state_load_missing_RSEG.cpp +++ b/lib/resdata/tests/well_state_load_missing_RSEG.cpp @@ -5,12 +5,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include int main(int argc, char **argv) { test_install_SIGNALS(); @@ -18,16 +18,16 @@ int main(int argc, char **argv) { const char *grid_file = argv[1]; const char *rst_file_name = argv[2]; - ecl_grid_type *grid = ecl_grid_alloc(grid_file); - ecl_file_type *rst_file = ecl_file_open(rst_file_name, 0); - ecl_file_view_type *rst_view = ecl_file_get_active_view(rst_file); - ecl_rsthead_type *header = ecl_rsthead_alloc( - rst_view, ecl_util_filename_report_nr(rst_file_name)); + rd_grid_type *grid = rd_grid_alloc(grid_file); + rd_file_type *rst_file = rd_file_open(rst_file_name, 0); + rd_file_view_type *rst_view = rd_file_get_active_view(rst_file); + rd_rsthead_type *header = + rd_rsthead_alloc(rst_view, rd_filename_report_nr(rst_file_name)); const char *well_name = "WELL"; int report_nr = 100; time_t valid_from = -1; bool open = false; - well_type_enum type = ECL_WELL_GAS_INJECTOR; + well_type_enum type = RD_WELL_GAS_INJECTOR; int global_well_nr = 0; bool load_segment_information = false; @@ -44,7 +44,7 @@ int main(int argc, char **argv) { const well_segment_collection_type *segments = well_state_get_segments(well_state); - if (!ecl_file_view_has_kw(rst_view, RSEG_KW)) + if (!rd_file_view_has_kw(rst_view, RSEG_KW)) test_assert_int_equal( 0, well_segment_collection_get_size(segments)); } diff --git a/lib/ecl/tests/well_ts.cpp b/lib/resdata/tests/well_ts.cpp similarity index 85% rename from lib/ecl/tests/well_ts.cpp rename to lib/resdata/tests/well_ts.cpp index 1d6c377dab..3549884775 100644 --- a/lib/ecl/tests/well_ts.cpp +++ b/lib/resdata/tests/well_ts.cpp @@ -5,18 +5,17 @@ #include #include -#include -#include +#include +#include -#include +#include int main(int argc, char **argv) { const char *case_path = argv[1]; char *grid_file = util_alloc_filename(NULL, case_path, "EGRID"); stringlist_type *file_list = stringlist_alloc_new(); - ecl_grid_type *grid = ecl_grid_alloc(grid_file); - ecl_util_select_filelist(NULL, case_path, ECL_RESTART_FILE, false, - file_list); + rd_grid_type *grid = rd_grid_alloc(grid_file); + rd_select_filelist(NULL, case_path, RD_RESTART_FILE, false, file_list); printf("Searching in:%s \n", case_path); test_assert_int_equal(4, stringlist_get_size(file_list)); @@ -55,7 +54,7 @@ int main(int argc, char **argv) { true); well_info_free(well_info); } - ecl_grid_free(grid); + rd_grid_free(grid); free(grid_file); exit(0); diff --git a/lib/ecl/well_branch_collection.cpp b/lib/resdata/well_branch_collection.cpp similarity index 96% rename from lib/ecl/well_branch_collection.cpp rename to lib/resdata/well_branch_collection.cpp index b4f8d9393e..f18e0c8684 100644 --- a/lib/ecl/well_branch_collection.cpp +++ b/lib/resdata/well_branch_collection.cpp @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define WELL_BRANCH_COLLECTION_TYPE_ID 67177087 diff --git a/lib/ecl/well_conn.cpp b/lib/resdata/well_conn.cpp similarity index 84% rename from lib/ecl/well_conn.cpp rename to lib/resdata/well_conn.cpp index 9e665f2599..4ba70a29bd 100644 --- a/lib/ecl/well_conn.cpp +++ b/lib/resdata/well_conn.cpp @@ -4,14 +4,13 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include #define WELL_CONN_NORMAL_WELL_SEGMENT_ID -999 -//#define ECLIPSE_NORMAL_WELL_SEGMENT_ID -1 /* Observe that when the (ijk) values are initialized they are @@ -133,15 +132,15 @@ well_conn_type *well_conn_alloc_fracture_MSW(int i, int j, int k, Observe that the (ijk) and branch values are shifted to zero offset to be aligned with the rest of the ert libraries. */ -well_conn_type *well_conn_alloc_from_kw(const ecl_kw_type *icon_kw, - const ecl_kw_type *scon_kw, - const ecl_kw_type *xcon_kw, - const ecl_rsthead_type *header, +well_conn_type *well_conn_alloc_from_kw(const rd_kw_type *icon_kw, + const rd_kw_type *scon_kw, + const rd_kw_type *xcon_kw, + const rd_rsthead_type *header, int well_nr, int conn_nr) { const int icon_offset = header->niconz * (header->ncwmax * well_nr + conn_nr); - int IC = ecl_kw_iget_int(icon_kw, icon_offset + ICON_IC_INDEX); + int IC = rd_kw_iget_int(icon_kw, icon_offset + ICON_IC_INDEX); if (IC <= 0) return NULL; /* IC < 0: Connection not in current LGR. */ @@ -151,7 +150,7 @@ well_conn_type *well_conn_alloc_from_kw(const ecl_kw_type *icon_kw, case we just return NULL and forget about the connection - it seems to work. */ int int_direction = - ecl_kw_iget_int(icon_kw, icon_offset + ICON_DIRECTION_INDEX); + rd_kw_iget_int(icon_kw, icon_offset + ICON_DIRECTION_INDEX); if ((int_direction < 0) || (int_direction > ICON_FRACY)) { fprintf(stderr, "Invalid direction value:%d encountered for well - connection " @@ -160,13 +159,13 @@ well_conn_type *well_conn_alloc_from_kw(const ecl_kw_type *icon_kw, return NULL; } - int i = ecl_kw_iget_int(icon_kw, icon_offset + ICON_I_INDEX) - 1; - int j = ecl_kw_iget_int(icon_kw, icon_offset + ICON_J_INDEX) - 1; - int k = ecl_kw_iget_int(icon_kw, icon_offset + ICON_K_INDEX) - 1; + int i = rd_kw_iget_int(icon_kw, icon_offset + ICON_I_INDEX) - 1; + int j = rd_kw_iget_int(icon_kw, icon_offset + ICON_J_INDEX) - 1; + int k = rd_kw_iget_int(icon_kw, icon_offset + ICON_K_INDEX) - 1; double connection_factor = -1; bool matrix_connection = true; bool is_open = - (ecl_kw_iget_int(icon_kw, icon_offset + ICON_STATUS_INDEX) > 0); + (rd_kw_iget_int(icon_kw, icon_offset + ICON_STATUS_INDEX) > 0); well_conn_dir_enum dir = well_conn_fracX; /* Set the K value and fracture flag. */ @@ -206,12 +205,12 @@ well_conn_type *well_conn_alloc_from_kw(const ecl_kw_type *icon_kw, const int scon_offset = header->nsconz * (header->ncwmax * well_nr + conn_nr); connection_factor = - ecl_kw_iget_as_double(scon_kw, scon_offset + SCON_CF_INDEX); + rd_kw_iget_as_double(scon_kw, scon_offset + SCON_CF_INDEX); } { int segment_id = - ecl_kw_iget_int(icon_kw, icon_offset + ICON_SEGMENT_INDEX) - + rd_kw_iget_int(icon_kw, icon_offset + ICON_SEGMENT_INDEX) - ECLIPSE_WELL_SEGMENT_OFFSET + WELL_SEGMENT_OFFSET; well_conn_type *conn = well_conn_alloc__(i, j, k, connection_factor, dir, is_open, @@ -222,13 +221,13 @@ well_conn_type *well_conn_alloc_from_kw(const ecl_kw_type *icon_kw, header->nxconz * (header->ncwmax * well_nr + conn_nr); conn->water_rate = - ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_WRAT_INDEX); + rd_kw_iget_as_double(xcon_kw, xcon_offset + XCON_WRAT_INDEX); conn->gas_rate = - ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_GRAT_INDEX); + rd_kw_iget_as_double(xcon_kw, xcon_offset + XCON_GRAT_INDEX); conn->oil_rate = - ecl_kw_iget_as_double(xcon_kw, xcon_offset + XCON_ORAT_INDEX); + rd_kw_iget_as_double(xcon_kw, xcon_offset + XCON_ORAT_INDEX); conn->volume_rate = - ecl_kw_iget_double(xcon_kw, xcon_offset + XCON_QR_INDEX); + rd_kw_iget_double(xcon_kw, xcon_offset + XCON_QR_INDEX); } /** @@ -249,18 +248,18 @@ void well_conn_free__(void *arg) { well_conn_free(conn); } -well_conn_type *well_conn_alloc_wellhead(const ecl_kw_type *iwel_kw, - const ecl_rsthead_type *header, +well_conn_type *well_conn_alloc_wellhead(const rd_kw_type *iwel_kw, + const rd_rsthead_type *header, int well_nr) { const int iwel_offset = header->niwelz * well_nr; - int conn_i = ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_HEADI_INDEX) - 1; + int conn_i = rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_HEADI_INDEX) - 1; if (conn_i >= 0) { //well_conn_type * conn = util_malloc( sizeof * conn ); int conn_j = - ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_HEADJ_INDEX) - 1; + rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_HEADJ_INDEX) - 1; int conn_k = - ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_HEADK_INDEX) - 1; + rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_HEADK_INDEX) - 1; bool matrix_connection = true; bool open = true; double connection_factor = -1; diff --git a/lib/ecl/well_conn_collection.cpp b/lib/resdata/well_conn_collection.cpp similarity index 82% rename from lib/ecl/well_conn_collection.cpp rename to lib/resdata/well_conn_collection.cpp index 57c525d884..c21580c31d 100644 --- a/lib/ecl/well_conn_collection.cpp +++ b/lib/resdata/well_conn_collection.cpp @@ -5,12 +5,12 @@ #include #include -#include -#include +#include +#include -#include -#include -#include +#include +#include +#include #define WELL_CONN_COLLECTION_TYPE_ID 67150087 @@ -87,15 +87,15 @@ well_conn_collection_iget(const well_conn_collection_type *wellcc, int index) { } int well_conn_collection_load_from_kw(well_conn_collection_type *wellcc, - const ecl_kw_type *iwel_kw, - const ecl_kw_type *icon_kw, - const ecl_kw_type *scon_kw, - const ecl_kw_type *xcon_kw, int iwell, - const ecl_rsthead_type *rst_head) { + const rd_kw_type *iwel_kw, + const rd_kw_type *icon_kw, + const rd_kw_type *scon_kw, + const rd_kw_type *xcon_kw, int iwell, + const rd_rsthead_type *rst_head) { const int iwel_offset = rst_head->niwelz * iwell; int num_connections = - ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_CONNECTIONS_INDEX); + rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_CONNECTIONS_INDEX); int iconn; for (iconn = 0; iconn < num_connections; iconn++) { diff --git a/lib/ecl/well_info.cpp b/lib/resdata/well_info.cpp similarity index 79% rename from lib/ecl/well_info.cpp rename to lib/resdata/well_info.cpp index 58f20ad263..9ea69caa24 100644 --- a/lib/ecl/well_info.cpp +++ b/lib/resdata/well_info.cpp @@ -8,22 +8,22 @@ #include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include /* The library libwell contains functionality to read and interpret - some of the well related keywords from an ECLIPSE restart + some of the well related keywords from a restart file. Roughly speaking the implementation is spread between three six datatypes; users of the libwell library are mainly conserned with three first. @@ -112,7 +112,7 @@ [*] Observe that wells in LGR is quite constrained in ECLIPSE; the current libwell implementation handles the illustrated case - but - it might be too complex for ECLIPSE. + it might not be supported by ECLIPSE. Limitations @@ -137,8 +137,8 @@ 2. Add restart data - using one of the three functions: - - well_info_add_wells() - ecl_file: One report step - - well_info_add_UNRST_wells() - ecl_file: Many report steps + - well_info_add_wells() - rd_file: One report step + - well_info_add_UNRST_wells() - rd_file: Many report steps - well_info_load_rstfile() - Restart file name; single file or unified There are more details about this in a comment section above the @@ -164,7 +164,7 @@ struct well_info_struct { std::map wells; /* std::map of well_ts_type instances; indexed by well name. */ std::vector well_names; /* A list of all the well names. */ - const ecl_grid_type *grid; + const rd_grid_type *grid; }; /** @@ -172,7 +172,7 @@ struct well_info_struct { it to resolve lgr names. */ -well_info_type *well_info_alloc(const ecl_grid_type *grid) { +well_info_type *well_info_alloc(const rd_grid_type *grid) { well_info_type *well_info = new well_info_type(); well_info->grid = grid; return well_info; @@ -219,18 +219,18 @@ static void well_info_add_state(well_info_type *well_info, - well_info_add_UNRST_wells() - well_info_load_rstfile() - The two first functions expect an open ecl_file instance as input; + The two first functions expect an open rd_file instance as input; whereas the last funtion expects the name of a restart file as input. - If you need ecl_file access to the restart files for another reason + If you need rd_file access to the restart files for another reason it might be convenient to use one of the first functions; however - due to the workings of the ecl_file type it might not be entirely - obvious: The ecl_file structure will load the needed keywords on + due to the workings of the rd_file type it might not be entirely + obvious: The rd_file structure will load the needed keywords on demand; the keywords needed to initialize well structures will typically not be loaded for other purposes, so the only gain from - using an existing ecl_file instance is that you do not have to - rebuild the index. The disadvantage of using an existing ecl_file + using an existing rd_file instance is that you do not have to + rebuild the index. The disadvantage of using an existing rd_file instance is that after the call to add_wells() the well related kewywords will stay in (probaly unused) in memory. @@ -242,7 +242,7 @@ static void well_info_add_state(well_info_type *well_info, /** This function assumes that (sub)select_block() has been used on the - ecl_file instance @rst_file; and the function will load well + rd_file instance @rst_file; and the function will load well information from the first block available in the file only. To load all the well information from a unified restart file it is easier to use the well_info_add_UNRST_wells() function; which works @@ -257,11 +257,10 @@ static void well_info_add_state(well_info_type *well_info, */ void well_info_add_wells2(well_info_type *well_info, - ecl_file_view_type *rst_view, int report_nr, + rd_file_view_type *rst_view, int report_nr, bool load_segment_information) { - bool close_stream = - ecl_file_view_drop_flag(rst_view, ECL_FILE_CLOSE_STREAM); - ecl_rsthead_type *global_header = ecl_rsthead_alloc(rst_view, report_nr); + bool close_stream = rd_file_view_drop_flag(rst_view, RD_FILE_CLOSE_STREAM); + rd_rsthead_type *global_header = rd_rsthead_alloc(rst_view, report_nr); int well_nr; for (well_nr = 0; well_nr < global_header->nwells; well_nr++) { well_state_type *well_state = @@ -270,14 +269,14 @@ void well_info_add_wells2(well_info_type *well_info, if (well_state != NULL) well_info_add_state(well_info, well_state); } - ecl_rsthead_free(global_header); + rd_rsthead_free(global_header); if (close_stream) - ecl_file_view_add_flag(rst_view, ECL_FILE_CLOSE_STREAM); + rd_file_view_add_flag(rst_view, RD_FILE_CLOSE_STREAM); } -void well_info_add_wells(well_info_type *well_info, ecl_file_type *rst_file, +void well_info_add_wells(well_info_type *well_info, rd_file_type *rst_file, int report_nr, bool load_segment_information) { - well_info_add_wells2(well_info, ecl_file_get_active_view(rst_file), + well_info_add_wells2(well_info, rd_file_get_active_view(rst_file), report_nr, load_segment_information); } @@ -288,30 +287,29 @@ void well_info_add_wells(well_info_type *well_info, ecl_file_type *rst_file, */ void well_info_add_UNRST_wells2(well_info_type *well_info, - ecl_file_view_type *rst_view, + rd_file_view_type *rst_view, bool load_segment_information) { - int num_blocks = ecl_file_view_get_num_named_kw(rst_view, SEQNUM_KW); + int num_blocks = rd_file_view_get_num_named_kw(rst_view, SEQNUM_KW); int block_nr; for (block_nr = 0; block_nr < num_blocks; block_nr++) { - ecl_file_view_type *step_view = - ecl_file_view_add_restart_view(rst_view, block_nr, -1, -1, -1); - const ecl_kw_type *seqnum_kw = - ecl_file_view_iget_named_kw(step_view, SEQNUM_KW, 0); - int report_nr = ecl_kw_iget_int(seqnum_kw, 0); + rd_file_view_type *step_view = + rd_file_view_add_restart_view(rst_view, block_nr, -1, -1, -1); + const rd_kw_type *seqnum_kw = + rd_file_view_iget_named_kw(step_view, SEQNUM_KW, 0); + int report_nr = rd_kw_iget_int(seqnum_kw, 0); - ecl_file_transaction_type *t = - ecl_file_view_start_transaction(rst_view); + rd_file_transaction_type *t = rd_file_view_start_transaction(rst_view); well_info_add_wells2(well_info, step_view, report_nr, load_segment_information); - ecl_file_view_end_transaction(rst_view, t); + rd_file_view_end_transaction(rst_view, t); } } void well_info_add_UNRST_wells(well_info_type *well_info, - ecl_file_type *rst_file, + rd_file_type *rst_file, bool load_segment_information) { - well_info_add_UNRST_wells2(well_info, ecl_file_get_global_view(rst_file), + well_info_add_UNRST_wells2(well_info, rd_file_get_global_view(rst_file), load_segment_information); } @@ -323,25 +321,24 @@ void well_info_add_UNRST_wells(well_info_type *well_info, void well_info_load_rstfile(well_info_type *well_info, const char *filename, bool load_segment_information) { - ecl_file_type *ecl_file = ecl_file_open(filename, 0); - well_info_load_rst_eclfile(well_info, ecl_file, load_segment_information); - ecl_file_close(ecl_file); + rd_file_type *rd_file = rd_file_open(filename, 0); + well_info_load_rst_resfile(well_info, rd_file, load_segment_information); + rd_file_close(rd_file); } -void well_info_load_rst_eclfile(well_info_type *well_info, - ecl_file_type *ecl_file, +void well_info_load_rst_resfile(well_info_type *well_info, + rd_file_type *rd_file, bool load_segment_information) { int report_nr; - const char *filename = ecl_file_get_src_file(ecl_file); - ecl_file_enum file_type = - ecl_util_get_file_type(filename, NULL, &report_nr); - if ((file_type == ECL_RESTART_FILE) || - (file_type == ECL_UNIFIED_RESTART_FILE)) { - if (file_type == ECL_RESTART_FILE) - well_info_add_wells(well_info, ecl_file, report_nr, + const char *filename = rd_file_get_src_file(rd_file); + rd_file_enum file_type = rd_get_file_type(filename, NULL, &report_nr); + if ((file_type == RD_RESTART_FILE) || + (file_type == RD_UNIFIED_RESTART_FILE)) { + if (file_type == RD_RESTART_FILE) + well_info_add_wells(well_info, rd_file, report_nr, load_segment_information); else - well_info_add_UNRST_wells(well_info, ecl_file, + well_info_add_UNRST_wells(well_info, rd_file, load_segment_information); } else diff --git a/lib/ecl/well_rseg_loader.cpp b/lib/resdata/well_rseg_loader.cpp similarity index 76% rename from lib/ecl/well_rseg_loader.cpp rename to lib/resdata/well_rseg_loader.cpp index 81840a119d..a8203f0e19 100644 --- a/lib/ecl/well_rseg_loader.cpp +++ b/lib/resdata/well_rseg_loader.cpp @@ -3,24 +3,24 @@ #include #include -#include -#include -#include +#include +#include +#include -#include -#include +#include +#include -#include +#include struct well_rseg_loader_struct { - ecl_file_view_type *rst_view; + rd_file_view_type *rst_view; int_vector_type *relative_index_map; int_vector_type *absolute_index_map; char *buffer; const char *kw; }; -well_rseg_loader_type *well_rseg_loader_alloc(ecl_file_view_type *rst_view) { +well_rseg_loader_type *well_rseg_loader_alloc(rd_file_view_type *rst_view) { well_rseg_loader_type *loader = (well_rseg_loader_type *)util_malloc(sizeof *loader); @@ -47,8 +47,8 @@ int well_rseg_loader_element_count( void well_rseg_loader_free(well_rseg_loader_type *loader) { - if (ecl_file_view_flags_set(loader->rst_view, ECL_FILE_CLOSE_STREAM)) - ecl_file_view_fclose_stream(loader->rst_view); + if (rd_file_view_flags_set(loader->rst_view, RD_FILE_CLOSE_STREAM)) + rd_file_view_fclose_stream(loader->rst_view); int_vector_free(loader->relative_index_map); int_vector_free(loader->absolute_index_map); @@ -69,8 +69,8 @@ double *well_rseg_loader_load_values(const well_rseg_loader_type *loader, int_vector_iset(index_map, index, relative_index + rseg_offset); } - ecl_file_view_index_fload_kw(loader->rst_view, loader->kw, 0, index_map, - loader->buffer); + rd_file_view_index_fload_kw(loader->rst_view, loader->kw, 0, index_map, + loader->buffer); return (double *)loader->buffer; } diff --git a/lib/ecl/well_segment.cpp b/lib/resdata/well_segment.cpp similarity index 89% rename from lib/ecl/well_segment.cpp rename to lib/resdata/well_segment.cpp index d2fb823eb7..aa99a4e49e 100644 --- a/lib/ecl/well_segment.cpp +++ b/lib/resdata/well_segment.cpp @@ -5,14 +5,14 @@ #include -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #define WELL_SEGMENT_TYPE_ID 2209166 @@ -65,9 +65,9 @@ static UTIL_SAFE_CAST_FUNCTION(well_segment, WELL_SEGMENT_TYPE_ID) } well_segment_type * -well_segment_alloc_from_kw(const ecl_kw_type *iseg_kw, +well_segment_alloc_from_kw(const rd_kw_type *iseg_kw, const well_rseg_loader_type *rseg_loader, - const ecl_rsthead_type *header, int well_nr, + const rd_rsthead_type *header, int well_nr, int segment_index, int segment_id) { if (rseg_loader == NULL) { util_abort("%s: fatal internal error - tried to create well_segment " @@ -80,10 +80,10 @@ well_segment_alloc_from_kw(const ecl_kw_type *iseg_kw, const int rseg_offset = header->nrsegz * (header->nsegmx * well_nr + segment_index); int outlet_segment_id = - ecl_kw_iget_int(iseg_kw, iseg_offset + ISEG_OUTLET_INDEX) - + rd_kw_iget_int(iseg_kw, iseg_offset + ISEG_OUTLET_INDEX) - ECLIPSE_WELL_SEGMENT_OFFSET + WELL_SEGMENT_OFFSET; // -1 int branch_id = - ecl_kw_iget_int(iseg_kw, iseg_offset + ISEG_BRANCH_INDEX) - + rd_kw_iget_int(iseg_kw, iseg_offset + ISEG_BRANCH_INDEX) - ECLIPSE_WELL_BRANCH_OFFSET + WELL_BRANCH_OFFSET; // -1 const double *rseg_data = well_rseg_loader_load_values(rseg_loader, rseg_offset); @@ -199,7 +199,7 @@ bool well_segment_has_grid_connections(const well_segment_type *segment, bool well_segment_has_global_grid_connections( const well_segment_type *segment) { - return well_segment_has_grid_connections(segment, ECL_GRID_GLOBAL_GRID); + return well_segment_has_grid_connections(segment, RD_GRID_GLOBAL_GRID); } bool well_segment_add_connection(well_segment_type *segment, @@ -227,15 +227,14 @@ well_segment_get_connections(const well_segment_type *segment, const well_conn_collection_type * well_segment_get_global_connections(const well_segment_type *segment) { - return well_segment_get_connections(segment, ECL_GRID_GLOBAL_GRID); + return well_segment_get_connections(segment, RD_GRID_GLOBAL_GRID); } -bool well_segment_well_is_MSW(int well_nr, const ecl_kw_type *iwel_kw, - const ecl_rsthead_type *rst_head) { +bool well_segment_well_is_MSW(int well_nr, const rd_kw_type *iwel_kw, + const rd_rsthead_type *rst_head) { int iwel_offset = rst_head->niwelz * well_nr; int segment_well_nr = - ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_SEGMENTED_WELL_NR_INDEX) - - 1; + rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_SEGMENTED_WELL_NR_INDEX) - 1; if (segment_well_nr == IWEL_SEGMENTED_WELL_NR_NORMAL_VALUE) return false; diff --git a/lib/ecl/well_segment_collection.cpp b/lib/resdata/well_segment_collection.cpp similarity index 91% rename from lib/ecl/well_segment_collection.cpp rename to lib/resdata/well_segment_collection.cpp index 5deff46d9b..2549f69ced 100644 --- a/lib/ecl/well_segment_collection.cpp +++ b/lib/resdata/well_segment_collection.cpp @@ -5,15 +5,15 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include struct well_segment_collection_struct { std::vector segment_index_map; @@ -92,14 +92,13 @@ bool well_segment_collection_has_segment( int well_segment_collection_load_from_kw( well_segment_collection_type *segment_collection, int well_nr, - const ecl_kw_type *iwel_kw, const ecl_kw_type *iseg_kw, - const well_rseg_loader_type *rseg_loader, const ecl_rsthead_type *rst_head, + const rd_kw_type *iwel_kw, const rd_kw_type *iseg_kw, + const well_rseg_loader_type *rseg_loader, const rd_rsthead_type *rst_head, bool load_segments, bool *is_MSW_well) { int iwel_offset = rst_head->niwelz * well_nr; int segment_well_nr = - ecl_kw_iget_int(iwel_kw, iwel_offset + IWEL_SEGMENTED_WELL_NR_INDEX) - - 1; + rd_kw_iget_int(iwel_kw, iwel_offset + IWEL_SEGMENTED_WELL_NR_INDEX) - 1; int segments_added = 0; if (segment_well_nr != IWEL_SEGMENTED_WELL_NR_NORMAL_VALUE) { diff --git a/lib/ecl/well_state.cpp b/lib/resdata/well_state.cpp similarity index 71% rename from lib/ecl/well_state.cpp rename to lib/resdata/well_state.cpp index 042252cc13..e2d4cdcbcc 100644 --- a/lib/ecl/well_state.cpp +++ b/lib/resdata/well_state.cpp @@ -16,21 +16,21 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include /* @@ -66,11 +66,11 @@ Segment 5 \ The boxes show connections C0 - C7; the connections serve as sinks (or sources in the case of injectors) removing fluids from the -reservoir. As ind icated by the use of isolated boxes the ECLIPSE model +reservoir. As indicated by the use of isolated boxes the model contains no geomtric concept linking the different connections into a connected 'well-like' object. -Ordinary wells in the ECLIPSE model are just a collection of +Ordinary wells in the model are just a collection of connections like these illustrated boxes, and to draw a connected 1D object heuristics of some kind must be used to determine how the various connections should be connected. In particular for wells which @@ -116,7 +116,7 @@ coupledte implementation these objects are modelled as such: } The connections to the global grid are stored with the 'LGR' name - given by the symbole ECL_GRID_GLOBAL_GRID, or alternatively the + given by the symbole RD_GRID_GLOBAL_GRID, or alternatively the function well_state_get_global_connections( well_state ) can be used. @@ -159,7 +159,7 @@ struct well_state_struct { double gas_rate; double water_rate; double volume_rate; - ert_ecl_unit_enum unit_system; + ert_rd_unit_enum unit_system; std::map connections; // hash @@ -193,10 +193,10 @@ well_state_type *well_state_alloc(const char *well_name, int global_well_nr, well_state->gas_rate = 0; well_state->water_rate = 0; well_state->volume_rate = 0; - well_state->unit_system = ECL_METRIC_UNITS; + well_state->unit_system = RD_METRIC_UNITS; /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */ - if ((type == ECL_WELL_ZERO) && open) + if ((type == RD_WELL_ZERO) && open) util_abort("%s: Invalid type value for open wells.\n", __func__); return well_state; } @@ -220,12 +220,12 @@ double well_state_get_volume_rate(const well_state_type *well_state) { double well_state_get_oil_rate_si(const well_state_type *well_state) { double conversion_factor = 1; - if (well_state->unit_system == ECL_METRIC_UNITS) - conversion_factor = 1.0 / ECL_UNITS_TIME_DAY; - else if (well_state->unit_system == ECL_FIELD_UNITS) - conversion_factor = ECL_UNITS_VOLUME_BARREL / ECL_UNITS_TIME_DAY; - else if (well_state->unit_system == ECL_LAB_UNITS) - conversion_factor = ECL_UNITS_VOLUME_MILLI_LITER / ECL_UNITS_TIME_HOUR; + if (well_state->unit_system == RD_METRIC_UNITS) + conversion_factor = 1.0 / RD_UNITS_TIME_DAY; + else if (well_state->unit_system == RD_FIELD_UNITS) + conversion_factor = RD_UNITS_VOLUME_BARREL / RD_UNITS_TIME_DAY; + else if (well_state->unit_system == RD_LAB_UNITS) + conversion_factor = RD_UNITS_VOLUME_MILLI_LITER / RD_UNITS_TIME_HOUR; return well_state->oil_rate * conversion_factor; } @@ -233,12 +233,12 @@ double well_state_get_oil_rate_si(const well_state_type *well_state) { double well_state_get_gas_rate_si(const well_state_type *well_state) { double conversion_factor = 1; - if (well_state->unit_system == ECL_METRIC_UNITS) - conversion_factor = 1.0 / ECL_UNITS_TIME_DAY; - else if (well_state->unit_system == ECL_FIELD_UNITS) - conversion_factor = ECL_UNITS_VOLUME_GAS_FIELD / ECL_UNITS_TIME_DAY; - else if (well_state->unit_system == ECL_LAB_UNITS) - conversion_factor = ECL_UNITS_VOLUME_MILLI_LITER / ECL_UNITS_TIME_HOUR; + if (well_state->unit_system == RD_METRIC_UNITS) + conversion_factor = 1.0 / RD_UNITS_TIME_DAY; + else if (well_state->unit_system == RD_FIELD_UNITS) + conversion_factor = RD_UNITS_VOLUME_GAS_FIELD / RD_UNITS_TIME_DAY; + else if (well_state->unit_system == RD_LAB_UNITS) + conversion_factor = RD_UNITS_VOLUME_MILLI_LITER / RD_UNITS_TIME_HOUR; return well_state->gas_rate * conversion_factor; } @@ -246,12 +246,12 @@ double well_state_get_gas_rate_si(const well_state_type *well_state) { double well_state_get_water_rate_si(const well_state_type *well_state) { double conversion_factor = 1; - if (well_state->unit_system == ECL_METRIC_UNITS) - conversion_factor = 1.0 / ECL_UNITS_TIME_DAY; - else if (well_state->unit_system == ECL_FIELD_UNITS) - conversion_factor = ECL_UNITS_VOLUME_BARREL / ECL_UNITS_TIME_DAY; - else if (well_state->unit_system == ECL_LAB_UNITS) - conversion_factor = ECL_UNITS_VOLUME_MILLI_LITER / ECL_UNITS_TIME_HOUR; + if (well_state->unit_system == RD_METRIC_UNITS) + conversion_factor = 1.0 / RD_UNITS_TIME_DAY; + else if (well_state->unit_system == RD_FIELD_UNITS) + conversion_factor = RD_UNITS_VOLUME_BARREL / RD_UNITS_TIME_DAY; + else if (well_state->unit_system == RD_LAB_UNITS) + conversion_factor = RD_UNITS_VOLUME_MILLI_LITER / RD_UNITS_TIME_HOUR; return well_state->water_rate * conversion_factor; } @@ -261,8 +261,8 @@ double well_state_get_volume_rate_si(const well_state_type *well_state) { } void well_state_add_wellhead(well_state_type *well_state, - const ecl_rsthead_type *header, - const ecl_kw_type *iwel_kw, int well_nr, + const rd_rsthead_type *header, + const rd_kw_type *iwel_kw, int well_nr, const char *grid_name, int grid_nr) { well_conn_type *wellhead = well_conn_alloc_wellhead(iwel_kw, header, well_nr); @@ -276,53 +276,53 @@ void well_state_add_wellhead(well_state_type *well_state, } static bool well_state_add_rates(well_state_type *well_state, - ecl_file_view_type *rst_view, int well_nr) { + rd_file_view_type *rst_view, int well_nr) { - bool has_xwel_kw = ecl_file_view_has_kw(rst_view, XWEL_KW); + bool has_xwel_kw = rd_file_view_has_kw(rst_view, XWEL_KW); if (has_xwel_kw) { - const ecl_kw_type *xwel_kw = - ecl_file_view_iget_named_kw(rst_view, XWEL_KW, 0); - ecl_rsthead_type *header = ecl_rsthead_alloc(rst_view, -1); + const rd_kw_type *xwel_kw = + rd_file_view_iget_named_kw(rst_view, XWEL_KW, 0); + rd_rsthead_type *header = rd_rsthead_alloc(rst_view, -1); int offset = header->nxwelz * well_nr; well_state->unit_system = header->unit_system; well_state->oil_rate = - ecl_kw_iget_double(xwel_kw, offset + XWEL_RES_ORAT_ITEM); + rd_kw_iget_double(xwel_kw, offset + XWEL_RES_ORAT_ITEM); well_state->gas_rate = - ecl_kw_iget_double(xwel_kw, offset + XWEL_RES_GRAT_ITEM); + rd_kw_iget_double(xwel_kw, offset + XWEL_RES_GRAT_ITEM); well_state->water_rate = - ecl_kw_iget_double(xwel_kw, offset + XWEL_RES_WRAT_ITEM); + rd_kw_iget_double(xwel_kw, offset + XWEL_RES_WRAT_ITEM); well_state->volume_rate = - ecl_kw_iget_double(xwel_kw, offset + XWEL_RESV_ITEM); + rd_kw_iget_double(xwel_kw, offset + XWEL_RESV_ITEM); - ecl_rsthead_free(header); + rd_rsthead_free(header); } return has_xwel_kw; } /* - This function assumes that the ecl_file state has been restricted - to one LGR block with the ecl_file_subselect_block() function. + This function assumes that the rd_file state has been restricted + to one LGR block with the rd_file_subselect_block() function. Return value: -1 means that the well is not found in this LGR at all. */ static int well_state_get_lgr_well_nr(const well_state_type *well_state, - const ecl_file_view_type *file_view) { + const rd_file_view_type *file_view) { int well_nr = -1; - if (ecl_file_view_has_kw(file_view, ZWEL_KW)) { - ecl_rsthead_type *header = ecl_rsthead_alloc(file_view, -1); - const ecl_kw_type *zwel_kw = - ecl_file_view_iget_named_kw(file_view, ZWEL_KW, 0); + if (rd_file_view_has_kw(file_view, ZWEL_KW)) { + rd_rsthead_type *header = rd_rsthead_alloc(file_view, -1); + const rd_kw_type *zwel_kw = + rd_file_view_iget_named_kw(file_view, ZWEL_KW, 0); int num_wells = header->nwells; well_nr = 0; while (true) { bool found = false; { char *lgr_well_name = - (char *)util_alloc_strip_copy((const char *)ecl_kw_iget_ptr( + (char *)util_alloc_strip_copy((const char *)rd_kw_iget_ptr( zwel_kw, well_nr * header->nzwelz)); if (well_state->name == lgr_well_name) @@ -341,30 +341,30 @@ static int well_state_get_lgr_well_nr(const well_state_type *well_state, break; } } - ecl_rsthead_free(header); + rd_rsthead_free(header); } return well_nr; } -well_type_enum well_state_translate_ecl_type_int(int int_type) { - well_type_enum type = ECL_WELL_ZERO; +well_type_enum well_state_translate_rd_type_int(int int_type) { + well_type_enum type = RD_WELL_ZERO; switch (int_type) { /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */ case (IWEL_UNDOCUMENTED_ZERO): - type = ECL_WELL_ZERO; + type = RD_WELL_ZERO; break; case (IWEL_PRODUCER): - type = ECL_WELL_PRODUCER; + type = RD_WELL_PRODUCER; break; case (IWEL_OIL_INJECTOR): - type = ECL_WELL_OIL_INJECTOR; + type = RD_WELL_OIL_INJECTOR; break; case (IWEL_GAS_INJECTOR): - type = ECL_WELL_GAS_INJECTOR; + type = RD_WELL_GAS_INJECTOR; break; case (IWEL_WATER_INJECTOR): - type = ECL_WELL_WATER_INJECTOR; + type = RD_WELL_WATER_INJECTOR; break; default: util_abort("%s: Invalid type value %d\n", __func__, int_type); @@ -373,36 +373,36 @@ well_type_enum well_state_translate_ecl_type_int(int int_type) { } /* - This function assumes that the ecl_file state has been restricted - to one LGR block with the ecl_file_subselect_block() function. + This function assumes that the rd_file state has been restricted + to one LGR block with the rd_file_subselect_block() function. */ static void well_state_add_connections__(well_state_type *well_state, - const ecl_file_view_type *rst_view, + const rd_file_view_type *rst_view, const char *grid_name, int grid_nr, int well_nr) { - ecl_rsthead_type *header = ecl_rsthead_alloc(rst_view, -1); - const ecl_kw_type *iwel_kw = - ecl_file_view_iget_named_kw(rst_view, IWEL_KW, 0); + rd_rsthead_type *header = rd_rsthead_alloc(rst_view, -1); + const rd_kw_type *iwel_kw = + rd_file_view_iget_named_kw(rst_view, IWEL_KW, 0); well_state_add_wellhead(well_state, header, iwel_kw, well_nr, grid_name, grid_nr); - if (ecl_file_view_has_kw(rst_view, ICON_KW)) { - const ecl_kw_type *icon_kw = - ecl_file_view_iget_named_kw(rst_view, ICON_KW, 0); + if (rd_file_view_has_kw(rst_view, ICON_KW)) { + const rd_kw_type *icon_kw = + rd_file_view_iget_named_kw(rst_view, ICON_KW, 0); if (!well_state_has_grid_connections(well_state, grid_name)) well_state->connections[grid_name] = well_conn_collection_alloc(); { - ecl_kw_type *scon_kw = NULL; - if (ecl_file_view_has_kw(rst_view, SCON_KW)) - scon_kw = ecl_file_view_iget_named_kw(rst_view, SCON_KW, 0); + rd_kw_type *scon_kw = NULL; + if (rd_file_view_has_kw(rst_view, SCON_KW)) + scon_kw = rd_file_view_iget_named_kw(rst_view, SCON_KW, 0); - ecl_kw_type *xcon_kw = NULL; - if (ecl_file_view_has_kw(rst_view, XCON_KW)) { - xcon_kw = ecl_file_view_iget_named_kw(rst_view, XCON_KW, 0); + rd_kw_type *xcon_kw = NULL; + if (rd_file_view_has_kw(rst_view, XCON_KW)) { + xcon_kw = rd_file_view_iget_named_kw(rst_view, XCON_KW, 0); } well_conn_collection_type *wellcc = @@ -411,27 +411,26 @@ static void well_state_add_connections__(well_state_type *well_state, xcon_kw, well_nr, header); } } - ecl_rsthead_free(header); + rd_rsthead_free(header); } -static void -well_state_add_global_connections(well_state_type *well_state, - const ecl_file_view_type *rst_view, - int well_nr) { - well_state_add_connections__(well_state, rst_view, ECL_GRID_GLOBAL_GRID, 0, +static void well_state_add_global_connections(well_state_type *well_state, + const rd_file_view_type *rst_view, + int well_nr) { + well_state_add_connections__(well_state, rst_view, RD_GRID_GLOBAL_GRID, 0, well_nr); } static void well_state_add_LGR_connections(well_state_type *well_state, - const ecl_grid_type *grid, - ecl_file_view_type *file_view) { + const rd_grid_type *grid, + rd_file_view_type *file_view) { // Go through all the LGRs and add connections; both in the bulk // grid and as wellhead. - int num_lgr = ecl_grid_get_num_lgr(grid); + int num_lgr = rd_grid_get_num_lgr(grid); for (int lgr_index = 0; lgr_index < num_lgr; lgr_index++) { - ecl_file_view_type *lgr_view = - ecl_file_view_add_blockview(file_view, LGR_KW, lgr_index); + rd_file_view_type *lgr_view = + rd_file_view_add_blockview(file_view, LGR_KW, lgr_index); /* Even though the grid has LGR information the restart file is not required to have corresponding LGR information. This has for a long time been @@ -440,7 +439,7 @@ static void well_state_add_LGR_connections(well_state_type *well_state, information can also be found in the restart file. */ if (lgr_view) { - const char *grid_name = ecl_grid_iget_lgr_name(grid, lgr_index); + const char *grid_name = rd_grid_iget_lgr_name(grid, lgr_index); int well_nr = well_state_get_lgr_well_nr(well_state, lgr_view); if (well_nr >= 0) well_state_add_connections__(well_state, lgr_view, grid_name, @@ -450,45 +449,45 @@ static void well_state_add_LGR_connections(well_state_type *well_state, } void well_state_add_connections( - well_state_type *well_state, const ecl_grid_type *grid, - ecl_file_type * + well_state_type *well_state, const rd_grid_type *grid, + rd_file_type * rst_file, // Either an open .Xnnnn file or UNRST file restricted to one report step int well_nr) { well_state_add_connections2(well_state, grid, - ecl_file_get_active_view(rst_file), well_nr); + rd_file_get_active_view(rst_file), well_nr); } void well_state_add_connections2(well_state_type *well_state, - const ecl_grid_type *grid, - ecl_file_view_type *rst_view, int well_nr) { + const rd_grid_type *grid, + rd_file_view_type *rst_view, int well_nr) { well_state_add_global_connections(well_state, rst_view, well_nr); well_state_add_LGR_connections(well_state, grid, rst_view); } -bool well_state_add_MSW(well_state_type *well_state, ecl_file_type *rst_file, +bool well_state_add_MSW(well_state_type *well_state, rd_file_type *rst_file, int well_nr, bool load_segment_information) { - return well_state_add_MSW2(well_state, ecl_file_get_active_view(rst_file), + return well_state_add_MSW2(well_state, rd_file_get_active_view(rst_file), well_nr, load_segment_information); } bool well_state_add_MSW2(well_state_type *well_state, - ecl_file_view_type *rst_view, int well_nr, + rd_file_view_type *rst_view, int well_nr, bool load_segment_information) { - if (ecl_file_view_has_kw(rst_view, ISEG_KW)) { - ecl_rsthead_type *rst_head = ecl_rsthead_alloc(rst_view, -1); - const ecl_kw_type *iwel_kw = - ecl_file_view_iget_named_kw(rst_view, IWEL_KW, 0); - const ecl_kw_type *iseg_kw = - ecl_file_view_iget_named_kw(rst_view, ISEG_KW, 0); + if (rd_file_view_has_kw(rst_view, ISEG_KW)) { + rd_rsthead_type *rst_head = rd_rsthead_alloc(rst_view, -1); + const rd_kw_type *iwel_kw = + rd_file_view_iget_named_kw(rst_view, IWEL_KW, 0); + const rd_kw_type *iseg_kw = + rd_file_view_iget_named_kw(rst_view, ISEG_KW, 0); well_rseg_loader_type *rseg_loader = NULL; int segment_count; - if (ecl_file_view_has_kw(rst_view, RSEG_KW)) { + if (rd_file_view_has_kw(rst_view, RSEG_KW)) { if (load_segment_information) rseg_loader = well_rseg_loader_alloc(rst_view); @@ -509,7 +508,7 @@ bool well_state_add_MSW2(well_state_type *well_state, well_segment_collection_add_branches(well_state->segments, well_state->branches); } - ecl_rsthead_free(rst_head); + rd_rsthead_free(rst_head); if (rseg_loader != NULL) { well_rseg_loader_free(rseg_loader); @@ -532,35 +531,35 @@ bool well_state_has_segment_data(const well_state_type *well_state) { return false; } -well_state_type *well_state_alloc_from_file(ecl_file_type *ecl_file, - const ecl_grid_type *grid, +well_state_type *well_state_alloc_from_file(rd_file_type *rd_file, + const rd_grid_type *grid, int report_nr, int global_well_nr, bool load_segment_information) { - return well_state_alloc_from_file2(ecl_file_get_active_view(ecl_file), grid, + return well_state_alloc_from_file2(rd_file_get_active_view(rd_file), grid, report_nr, global_well_nr, load_segment_information); } -well_state_type *well_state_alloc_from_file2(ecl_file_view_type *file_view, - const ecl_grid_type *grid, +well_state_type *well_state_alloc_from_file2(rd_file_view_type *file_view, + const rd_grid_type *grid, int report_nr, int global_well_nr, bool load_segment_information) { - if (ecl_file_view_has_kw(file_view, IWEL_KW)) { + if (rd_file_view_has_kw(file_view, IWEL_KW)) { well_state_type *well_state = NULL; - ecl_rsthead_type *global_header = ecl_rsthead_alloc(file_view, -1); - const ecl_kw_type *global_iwel_kw = - ecl_file_view_iget_named_kw(file_view, IWEL_KW, 0); - const ecl_kw_type *global_zwel_kw = - ecl_file_view_iget_named_kw(file_view, ZWEL_KW, 0); + rd_rsthead_type *global_header = rd_rsthead_alloc(file_view, -1); + const rd_kw_type *global_iwel_kw = + rd_file_view_iget_named_kw(file_view, IWEL_KW, 0); + const rd_kw_type *global_zwel_kw = + rd_file_view_iget_named_kw(file_view, ZWEL_KW, 0); const int iwel_offset = global_header->niwelz * global_well_nr; { char *name; bool open; - well_type_enum type = ECL_WELL_ZERO; + well_type_enum type = RD_WELL_ZERO; { - int int_state = ecl_kw_iget_int( - global_iwel_kw, iwel_offset + IWEL_STATUS_INDEX); + int int_state = rd_kw_iget_int(global_iwel_kw, + iwel_offset + IWEL_STATUS_INDEX); if (int_state > 0) open = true; else @@ -568,15 +567,15 @@ well_state_type *well_state_alloc_from_file2(ecl_file_view_type *file_view, } { - int int_type = ecl_kw_iget_int(global_iwel_kw, - iwel_offset + IWEL_TYPE_INDEX); - type = well_state_translate_ecl_type_int(int_type); + int int_type = rd_kw_iget_int(global_iwel_kw, + iwel_offset + IWEL_TYPE_INDEX); + type = well_state_translate_rd_type_int(int_type); } { const int zwel_offset = global_header->nzwelz * global_well_nr; name = - (char *)util_alloc_strip_copy((const char *)ecl_kw_iget_ptr( + (char *)util_alloc_strip_copy((const char *)rd_kw_iget_ptr( global_zwel_kw, zwel_offset)); // Hardwired max 8 characters in Well Name } @@ -587,13 +586,13 @@ well_state_type *well_state_alloc_from_file2(ecl_file_view_type *file_view, well_state_add_connections2(well_state, grid, file_view, global_well_nr); - if (ecl_file_view_has_kw(file_view, ISEG_KW)) + if (rd_file_view_has_kw(file_view, ISEG_KW)) well_state_add_MSW2(well_state, file_view, global_well_nr, load_segment_information); well_state_add_rates(well_state, file_view, global_well_nr); } - ecl_rsthead_free(global_header); + rd_rsthead_free(global_header); return well_state; } else /* This seems a bit weird - have come over E300 restart files without the IWEL keyword. */ @@ -653,7 +652,7 @@ const well_conn_type *well_state_get_wellhead(const well_state_type *well_state, const well_conn_type * well_state_get_global_wellhead(const well_state_type *well_state) { - return well_state_get_wellhead(well_state, ECL_GRID_GLOBAL_GRID); + return well_state_get_wellhead(well_state, RD_GRID_GLOBAL_GRID); } well_type_enum well_state_get_type(const well_state_type *well_state) { @@ -683,7 +682,7 @@ well_state_get_grid_connections(const well_state_type *well_state, const well_conn_collection_type * well_state_get_global_connections(const well_state_type *well_state) { - return well_state_get_grid_connections(well_state, ECL_GRID_GLOBAL_GRID); + return well_state_get_grid_connections(well_state, RD_GRID_GLOBAL_GRID); } bool well_state_has_grid_connections(const well_state_type *well_state, @@ -696,7 +695,7 @@ bool well_state_has_grid_connections(const well_state_type *well_state, } bool well_state_has_global_connections(const well_state_type *well_state) { - return well_state_has_grid_connections(well_state, ECL_GRID_GLOBAL_GRID); + return well_state_has_grid_connections(well_state, RD_GRID_GLOBAL_GRID); } well_segment_collection_type * diff --git a/lib/ecl/well_ts.cpp b/lib/resdata/well_ts.cpp similarity index 98% rename from lib/ecl/well_ts.cpp rename to lib/resdata/well_ts.cpp index cb56270bae..a10267226d 100644 --- a/lib/ecl/well_ts.cpp +++ b/lib/resdata/well_ts.cpp @@ -49,9 +49,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define WELL_TS_TYPE_ID 6613005 #define WELL_NODE_TYPE_ID 1114652 diff --git a/lib/tests/test_ecl_grid.cpp b/lib/tests/test_rd_grid.cpp similarity index 62% rename from lib/tests/test_ecl_grid.cpp rename to lib/tests/test_rd_grid.cpp index 033d31f8b3..d3c9c7edf4 100644 --- a/lib/tests/test_ecl_grid.cpp +++ b/lib/tests/test_rd_grid.cpp @@ -1,7 +1,7 @@ #include -#include -#include -#include +#include +#include +#include #include #include "tmpdir.hpp" @@ -11,17 +11,17 @@ using namespace Matchers; TEST_CASE("Test unfractured grids", "[unittest]") { GIVEN("An unfractured grid") { - ecl_grid_type *grid = - ecl_grid_alloc_rectangular(21, 11, 12, 1, 2, 3, NULL); + rd_grid_type *grid = + rd_grid_alloc_rectangular(21, 11, 12, 1, 2, 3, NULL); - REQUIRE(ecl_grid_get_nactive_fracture(grid) == 0); + REQUIRE(rd_grid_get_nactive_fracture(grid) == 0); THEN("It should return -1 on any fracture index") { auto i = GENERATE(0, 1, 10, 20); - REQUIRE(ecl_grid_get_active_fracture_index1(grid, i) == -1); + REQUIRE(rd_grid_get_active_fracture_index1(grid, i) == -1); } - ecl_grid_free(grid); + rd_grid_free(grid); } } @@ -45,9 +45,9 @@ double center_of_cell(double cell_width, int index) { * all width the given x, y, and z dimensions. depth is set by * the depth function applied to the center of the cell. */ -ecl_grid_type *generate_dxv_dyv_dzv_depthz_grid(int num_x, int num_y, int num_z, - double x_width, double y_width, - double z_width) { +rd_grid_type *generate_dxv_dyv_dzv_depthz_grid(int num_x, int num_y, int num_z, + double x_width, double y_width, + double z_width) { auto x_widths = std::vector(num_x + 1, x_width); auto y_widths = std::vector(num_y + 1, y_width); auto z_widths = std::vector(num_z, z_width); @@ -61,7 +61,7 @@ ecl_grid_type *generate_dxv_dyv_dzv_depthz_grid(int num_x, int num_y, int num_z, } } - auto grid = ecl_grid_alloc_dxv_dyv_dzv_depthz( + auto grid = rd_grid_alloc_dxv_dyv_dzv_depthz( num_x, num_y, num_z, x_widths.data(), y_widths.data(), z_widths.data(), z_depths.data(), NULL); return grid; @@ -77,7 +77,7 @@ TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { double y_width = 1.0 / ny; double z_width = 3.0 / nz; - ecl_grid_type *grid = generate_dxv_dyv_dzv_depthz_grid( + rd_grid_type *grid = generate_dxv_dyv_dzv_depthz_grid( nx, ny, nz, x_width, y_width, z_width); AND_GIVEN("Any cell in that grid") { @@ -87,7 +87,7 @@ TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { THEN("get_xyz3 should return cell center in x, y plane") { double xc, yc, zc; - ecl_grid_get_xyz3(grid, i, j, k, &xc, &yc, &zc); + rd_grid_get_xyz3(grid, i, j, k, &xc, &yc, &zc); REQUIRE_THAT(xc, WithinAbs(center_of_cell(x_width, i), 0.000001)); @@ -96,7 +96,7 @@ TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { THEN("The top cell corner has z offset by depth function") { double xc, yc, zc; - ecl_grid_get_cell_corner_xyz3(grid, i, j, k, 0, &xc, &yc, &zc); + rd_grid_get_cell_corner_xyz3(grid, i, j, k, 0, &xc, &yc, &zc); double x_center = center_of_cell(x_width, i); double y_center = center_of_cell(y_width, j); @@ -109,7 +109,7 @@ TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { THEN("The bottom cell corner has z offset by depth function") { double xc, yc, zc; - ecl_grid_get_cell_corner_xyz3(grid, i, j, k, 4, &xc, &yc, &zc); + rd_grid_get_cell_corner_xyz3(grid, i, j, k, 4, &xc, &yc, &zc); double x_center = center_of_cell(x_width, i); double y_center = center_of_cell(y_width, j); @@ -120,25 +120,25 @@ TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { } THEN("The volume should be simple multiplication") { - double volume = ecl_grid_get_cell_volume3(grid, i, j, k); + double volume = rd_grid_get_cell_volume3(grid, i, j, k); REQUIRE_THAT(volume, WithinAbs(z_width * x_width * y_width, 1e-4)); } } AND_GIVEN("A grid constructed in the same way") { - ecl_grid_type *grid2 = generate_dxv_dyv_dzv_depthz_grid( + rd_grid_type *grid2 = generate_dxv_dyv_dzv_depthz_grid( nx, ny, nz, x_width, y_width, z_width); THEN("Those grids are equal") { - REQUIRE(ecl_grid_compare(grid, grid2, false, false, true)); + REQUIRE(rd_grid_compare(grid, grid2, false, false, true)); } - ecl_grid_free(grid2); + rd_grid_free(grid2); } - ecl_grid_free(grid); + rd_grid_free(grid); } } /** - * Generates a grid, using the ecl_grid_alloc_GRDECL_kw constructor, + * Generates a grid, using the rd_grid_alloc_GRDECL_kw constructor, * with the x,y,z coordinates of the 0th corner of the ijkth cel is * i,j,k. In other words this is a grid where the corners are on the * whole numbers. @@ -146,57 +146,57 @@ TEST_CASE("Test dxv_dyv_dzv grids", "[unittest]") { * Takes a vector of i,j,k,c,z tuples which changes the corner c of cell * at i,j,k z value. */ -ecl_grid_type *generate_coordkw_grid( +rd_grid_type *generate_coordkw_grid( int num_x, int num_y, int num_z, const std::vector> &z_vector) { - ecl_kw_type *coord_kw = - ecl_kw_alloc(COORD_KW, ECL_GRID_COORD_SIZE(num_x, num_y), ECL_FLOAT); - ecl_kw_type *zcorn_kw = ecl_kw_alloc( - ZCORN_KW, ECL_GRID_ZCORN_SIZE(num_x, num_y, num_z), ECL_FLOAT); + rd_kw_type *coord_kw = + rd_kw_alloc(COORD_KW, RD_GRID_COORD_SIZE(num_x, num_y), RD_FLOAT); + rd_kw_type *zcorn_kw = rd_kw_alloc( + ZCORN_KW, RD_GRID_ZCORN_SIZE(num_x, num_y, num_z), RD_FLOAT); for (int j = 0; j < num_y; j++) { for (int i = 0; i < num_x; i++) { int offset = 6 * (i + j * num_x); - ecl_kw_iset_float(coord_kw, offset, i); - ecl_kw_iset_float(coord_kw, offset + 1, j); - ecl_kw_iset_float(coord_kw, offset + 2, -1); + rd_kw_iset_float(coord_kw, offset, i); + rd_kw_iset_float(coord_kw, offset + 1, j); + rd_kw_iset_float(coord_kw, offset + 2, -1); - ecl_kw_iset_float(coord_kw, offset + 3, i); - ecl_kw_iset_float(coord_kw, offset + 4, j); - ecl_kw_iset_float(coord_kw, offset + 5, -1); + rd_kw_iset_float(coord_kw, offset + 3, i); + rd_kw_iset_float(coord_kw, offset + 4, j); + rd_kw_iset_float(coord_kw, offset + 5, -1); for (int k = 0; k < num_z; k++) { for (int c = 0; c < 4; c++) { - int zi1 = ecl_grid_zcorn_index__(num_x, num_y, i, j, k, c); + int zi1 = rd_grid_zcorn_index__(num_x, num_y, i, j, k, c); int zi2 = - ecl_grid_zcorn_index__(num_x, num_y, i, j, k, c + 4); + rd_grid_zcorn_index__(num_x, num_y, i, j, k, c + 4); double z1 = k; double z2 = k + 1; - ecl_kw_iset_float(zcorn_kw, zi1, z1); - ecl_kw_iset_float(zcorn_kw, zi2, z2); + rd_kw_iset_float(zcorn_kw, zi1, z1); + rd_kw_iset_float(zcorn_kw, zi2, z2); } } } } for (const auto &[i, j, k, c, z] : z_vector) { - auto index = ecl_grid_zcorn_index__(num_x, num_y, i, j, k, c); - ecl_kw_iset_float(zcorn_kw, index, z); + auto index = rd_grid_zcorn_index__(num_x, num_y, i, j, k, c); + rd_kw_iset_float(zcorn_kw, index, z); } - ecl_grid_type *grid = ecl_grid_alloc_GRDECL_kw( - num_x, num_y, num_z, zcorn_kw, coord_kw, NULL, NULL); - ecl_kw_free(coord_kw); - ecl_kw_free(zcorn_kw); + rd_grid_type *grid = rd_grid_alloc_GRDECL_kw(num_x, num_y, num_z, zcorn_kw, + coord_kw, NULL, NULL); + rd_kw_free(coord_kw); + rd_kw_free(zcorn_kw); return grid; } TEST_CASE("Test no twistedness", "[unittest]") { GIVEN("A grid with untwisted cells") { - ecl_grid_type *grid = generate_coordkw_grid(10, 7, 8, {}); + rd_grid_type *grid = generate_coordkw_grid(10, 7, 8, {}); AND_GIVEN("Any cell in that grid") { auto i = GENERATE(take(3, random(0, 9))); @@ -204,11 +204,11 @@ TEST_CASE("Test no twistedness", "[unittest]") { auto k = GENERATE(take(3, random(0, 7))); THEN("That cell should have a twist score of 0") { - REQUIRE(ecl_grid_get_cell_twist3(grid, i, j, k) == 0); + REQUIRE(rd_grid_get_cell_twist3(grid, i, j, k) == 0); } } - ecl_grid_free(grid); + rd_grid_free(grid); } } @@ -218,13 +218,13 @@ TEST_CASE("Test simple twistedness", "[unittest]") { {0, 0, 0, 0, 0.0}, {0, 0, 0, 4, -0.25}, }; - ecl_grid_type *grid = generate_coordkw_grid(10, 7, 8, z_vector); + rd_grid_type *grid = generate_coordkw_grid(10, 7, 8, z_vector); THEN("That cell should have a twist score of 1") { - REQUIRE(ecl_grid_get_cell_twist3(grid, 0, 0, 0) == 1); + REQUIRE(rd_grid_get_cell_twist3(grid, 0, 0, 0) == 1); } - ecl_grid_free(grid); + rd_grid_free(grid); } } @@ -236,43 +236,43 @@ TEST_CASE("Test double twistedness", "[unittest]") { {0, 0, 0, 3, 0.0}, {0, 0, 0, 7, -0.25}, }; - ecl_grid_type *grid = generate_coordkw_grid(10, 7, 8, z_vector); + rd_grid_type *grid = generate_coordkw_grid(10, 7, 8, z_vector); THEN("That cell should have a twist score of 2") { - REQUIRE(ecl_grid_get_cell_twist3(grid, 0, 0, 0) == 2); + REQUIRE(rd_grid_get_cell_twist3(grid, 0, 0, 0) == 2); } - ecl_grid_free(grid); + rd_grid_free(grid); } } TEST_CASE_METHOD(Tmpdir, "Test case loading", "[unittest]") { GIVEN("A grid on disc") { auto filename = dirname / "GRID.EGRID"; - ecl_grid_type *ecl_grid = - ecl_grid_alloc_rectangular(5, 5, 5, 1, 1, 1, nullptr); - ecl_grid_fwrite_EGRID2(ecl_grid, filename.c_str(), ECL_METRIC_UNITS); - ecl_grid_free(ecl_grid); + rd_grid_type *rd_grid = + rd_grid_alloc_rectangular(5, 5, 5, 1, 1, 1, nullptr); + rd_grid_fwrite_EGRID2(rd_grid, filename.c_str(), RD_METRIC_UNITS); + rd_grid_free(rd_grid); THEN("Loading that grid gives a non-null grid as a case") { - ecl_grid_type *grid = ecl_grid_load_case(filename.c_str()); + rd_grid_type *grid = rd_grid_load_case(filename.c_str()); REQUIRE(grid != NULL); - ecl_grid_free(grid); + rd_grid_free(grid); } THEN("Loading it as without extension also gives non-null grid") { auto no_ext_file_name = dirname / "GRID"; - ecl_grid_type *grid = ecl_grid_load_case(no_ext_file_name.c_str()); + rd_grid_type *grid = rd_grid_load_case(no_ext_file_name.c_str()); REQUIRE(grid != NULL); - ecl_grid_free(grid); + rd_grid_free(grid); } THEN("Loadinging a non-existent grid gives NULL") { auto does_not_exist = dirname / "DOES_NOT_EXIST.EGRID"; - ecl_grid_type *grid = ecl_grid_load_case(does_not_exist.c_str()); + rd_grid_type *grid = rd_grid_load_case(does_not_exist.c_str()); REQUIRE(grid == NULL); } THEN("Loading non-existent grid without extension gives NULL") { auto does_not_exist = dirname / "DOES_NOT_EXIST"; - ecl_grid_type *grid = ecl_grid_load_case(does_not_exist.c_str()); + rd_grid_type *grid = rd_grid_load_case(does_not_exist.c_str()); REQUIRE(grid == NULL); } } @@ -280,47 +280,46 @@ TEST_CASE_METHOD(Tmpdir, "Test case loading", "[unittest]") { TEST_CASE_METHOD(Tmpdir, "Test format writing grid", "[unittest]") { GIVEN("A Grid") { - ecl_grid_type *ecl_grid = - ecl_grid_alloc_rectangular(5, 5, 5, 1, 1, 1, nullptr); + rd_grid_type *rd_grid = + rd_grid_alloc_rectangular(5, 5, 5, 1, 1, 1, nullptr); THEN("Writing that file as a FEGRID is a formatted file") { - ecl_grid_fwrite_EGRID2(ecl_grid, (dirname / "CASE.FEGRID").c_str(), - ECL_METRIC_UNITS); + rd_grid_fwrite_EGRID2(rd_grid, (dirname / "CASE.FEGRID").c_str(), + RD_METRIC_UNITS); REQUIRE(util_fmt_bit8((dirname / "CASE.FEGRID").c_str())); } THEN("Writing that file as a EGRID is an unformatted file") { - ecl_grid_fwrite_EGRID2(ecl_grid, (dirname / "CASE.EGRID").c_str(), - ECL_METRIC_UNITS); + rd_grid_fwrite_EGRID2(rd_grid, (dirname / "CASE.EGRID").c_str(), + RD_METRIC_UNITS); REQUIRE(!util_fmt_bit8((dirname / "CASE.EGRID").c_str())); } THEN( "Writing that file with unknown extension is an unformatted file") { - ecl_grid_fwrite_EGRID2(ecl_grid, (dirname / "CASE.UNKNOWN").c_str(), - ECL_METRIC_UNITS); + rd_grid_fwrite_EGRID2(rd_grid, (dirname / "CASE.UNKNOWN").c_str(), + RD_METRIC_UNITS); REQUIRE(!util_fmt_bit8((dirname / "CASE.UNKNOWN").c_str())); } - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } } TEST_CASE_METHOD(Tmpdir, "Writing and reading grid", "[unittest]") { GIVEN("A Grid") { - ecl_grid_type *ecl_grid = - ecl_grid_alloc_rectangular(5, 5, 5, 1, 1, 1, nullptr); + rd_grid_type *rd_grid = + rd_grid_alloc_rectangular(5, 5, 5, 1, 1, 1, nullptr); THEN("Writing and reading that grid gives equal grid") { auto filename = (dirname / "CASE.EGRID"); - ecl_grid_fwrite_EGRID2(ecl_grid, filename.c_str(), - ECL_METRIC_UNITS); - ecl_grid_type *read_grid = ecl_grid_alloc(filename.c_str()); + rd_grid_fwrite_EGRID2(rd_grid, filename.c_str(), RD_METRIC_UNITS); + rd_grid_type *read_grid = rd_grid_alloc(filename.c_str()); - REQUIRE(ecl_grid_compare(ecl_grid, read_grid, false, false, true)); + REQUIRE(rd_grid_compare(rd_grid, read_grid, false, false, true)); - ecl_grid_free(read_grid); + rd_grid_free(read_grid); } - ecl_grid_free(ecl_grid); + rd_grid_free(rd_grid); } } diff --git a/lib/tests/test_ecl_util.cpp b/lib/tests/test_rd_util.cpp similarity index 63% rename from lib/tests/test_ecl_util.cpp rename to lib/tests/test_rd_util.cpp index e05c9dc0a9..9d24e853ba 100644 --- a/lib/tests/test_ecl_util.cpp +++ b/lib/tests/test_rd_util.cpp @@ -1,5 +1,5 @@ #include -#include +#include using namespace Catch; using namespace Matchers; @@ -7,27 +7,27 @@ using namespace Matchers; TEST_CASE("Test file type format check", "[unittest]") { bool is_fmt = false; SECTION("A FUNRST file is a formatted file") { - ecl_util_get_file_type("CASE.FUNRST", &is_fmt, NULL); + rd_get_file_type("CASE.FUNRST", &is_fmt, NULL); REQUIRE(is_fmt); } SECTION("A FMSPEC file is a formatted file") { - ecl_util_get_file_type("CASE.FMSPEC", &is_fmt, NULL); + rd_get_file_type("CASE.FMSPEC", &is_fmt, NULL); REQUIRE(is_fmt); } SECTION("A .F0001 file is a formatted file") { - ecl_util_get_file_type("CASE.F0001", &is_fmt, NULL); + rd_get_file_type("CASE.F0001", &is_fmt, NULL); REQUIRE(is_fmt); } SECTION("A .X1234 file is an unformatted file") { - ecl_util_get_file_type("CASE.X1234", &is_fmt, NULL); + rd_get_file_type("CASE.X1234", &is_fmt, NULL); REQUIRE(!is_fmt); } SECTION("A .UNSMRY file is an unformatted file") { - ecl_util_get_file_type("CASE.UNSMRY", &is_fmt, NULL); + rd_get_file_type("CASE.UNSMRY", &is_fmt, NULL); REQUIRE(!is_fmt); } } diff --git a/lib/tests/tmpdir.hpp b/lib/tests/tmpdir.hpp index ef70e18e61..d402ca2f4b 100644 --- a/lib/tests/tmpdir.hpp +++ b/lib/tests/tmpdir.hpp @@ -17,7 +17,7 @@ class Tmpdir { static bool delete_temporary_files; fs::path dirname; Tmpdir() { - auto parentdir = fs::temp_directory_path() / "ecl_test"; + auto parentdir = fs::temp_directory_path() / "rd_test"; do { dirname = parentdir / std::to_string(rand()); diff --git a/lib/util/cxx_string_util.cpp b/lib/util/cxx_string_util.cpp index 48cbe0db0b..f7f1afd733 100644 --- a/lib/util/cxx_string_util.cpp +++ b/lib/util/cxx_string_util.cpp @@ -1,7 +1,7 @@ #include #include -namespace ecl { +namespace rd { namespace util { std::string string_format(const char *fmt, ...) { @@ -23,4 +23,4 @@ std::string string_format(const char *fmt, ...) { return s; } } // namespace util -} // namespace ecl +} // namespace rd diff --git a/lib/util/ecl_version.cpp b/lib/util/ecl_version.cpp deleted file mode 100644 index 620b41bb7a..0000000000 --- a/lib/util/ecl_version.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -#define xstr(s) #s -#define str(s) xstr(s) - -const char *ecl_version_get_git_commit() { -#ifdef GIT_COMMIT - return str(GIT_COMMIT); -#else - return "Unknown git commit hash"; -#endif -} - -const char *ecl_version_get_git_commit_short() { -#ifdef GIT_COMMIT_SHORT - return str(GIT_COMMIT_SHORT); -#else - return "Unknown git short commit hash"; -#endif -} - -const char *ecl_version_get_build_time() { -#ifdef COMPILE_TIME_STAMP - return COMPILE_TIME_STAMP; -#else - return "Unknown build time"; -#endif -} - -int ecl_version_get_major_version() { return ECL_VERSION_MAJOR; } - -int ecl_version_get_minor_version() { return ECL_VERSION_MINOR; } - -const char *ecl_version_get_micro_version() { return str(ECL_VERSION_MICRO); } - -bool ecl_version_is_devel_version() { - return util_sscanf_int(str(ECL_VERSION_MICRO), NULL); -} diff --git a/lib/util/path.cpp b/lib/util/path.cpp index 1ee79d960a..6ca190cdb8 100644 --- a/lib/util/path.cpp +++ b/lib/util/path.cpp @@ -6,7 +6,7 @@ #include "detail/util/path.hpp" -namespace ecl { +namespace rd { namespace util { @@ -72,4 +72,4 @@ std::string extension(const std::string &fname) { } // namespace path } // namespace util -} // namespace ecl +} // namespace rd diff --git a/lib/util/rd_version.cpp b/lib/util/rd_version.cpp new file mode 100644 index 0000000000..0b187d77f1 --- /dev/null +++ b/lib/util/rd_version.cpp @@ -0,0 +1,39 @@ +#include +#include + +#define xstr(s) #s +#define str(s) xstr(s) + +const char *rd_version_get_git_commit() { +#ifdef GIT_COMMIT + return str(GIT_COMMIT); +#else + return "Unknown git commit hash"; +#endif +} + +const char *rd_version_get_git_commit_short() { +#ifdef GIT_COMMIT_SHORT + return str(GIT_COMMIT_SHORT); +#else + return "Unknown git short commit hash"; +#endif +} + +const char *rd_version_get_build_time() { +#ifdef COMPILE_TIME_STAMP + return COMPILE_TIME_STAMP; +#else + return "Unknown build time"; +#endif +} + +int rd_version_get_major_version() { return RD_VERSION_MAJOR; } + +int rd_version_get_minor_version() { return RD_VERSION_MINOR; } + +const char *rd_version_get_micro_version() { return str(RD_VERSION_MICRO); } + +bool rd_version_is_devel_version() { + return util_sscanf_int(str(RD_VERSION_MICRO), NULL); +} diff --git a/lib/util/test_work_area.cpp b/lib/util/test_work_area.cpp index fef6f48d04..f238c2ea69 100644 --- a/lib/util/test_work_area.cpp +++ b/lib/util/test_work_area.cpp @@ -100,7 +100,7 @@ static char *test_work_area_alloc_prefix() { #endif } -namespace ecl { +namespace rd { namespace util { static bool test_work_area_copy_parent__(const TestArea *work_area, @@ -169,7 +169,7 @@ TestArea::TestArea(const std::string &test_name, bool store_area) char *user_name = util_alloc_sprintf("ert-test-%08u", random_int); #endif - char *test_cwd = ecl::util::create_test_path(test_name, prefix, user_name); + char *test_cwd = rd::util::create_test_path(test_name, prefix, user_name); { char *cwd_tmp = util_alloc_cwd(); @@ -244,12 +244,12 @@ bool TestArea::copy_parent_content(const std::string input_path) const { } } // namespace util -} // namespace ecl +} // namespace rd test_work_area_type *test_work_area_alloc__(const char *test_name, bool store_area) { if (test_name) - return new ecl::util::TestArea(test_name, store_area); + return new rd::util::TestArea(test_name, store_area); else return NULL; } @@ -290,7 +290,7 @@ void test_work_area_install_file(const test_work_area_type *work_area, return; else { std::string src_file = work_area->original_path(input_src_file); - std::string src_path = ecl::util::path::dirname(input_src_file); + std::string src_path = rd::util::path::dirname(input_src_file); if (!util_entry_exists(src_path.c_str())) util_make_path(src_path.c_str()); diff --git a/lib/util/tests/ert_util_chdir.cpp b/lib/util/tests/ert_util_chdir.cpp index 500f67ec22..f44d4dda03 100644 --- a/lib/util/tests/ert_util_chdir.cpp +++ b/lib/util/tests/ert_util_chdir.cpp @@ -6,7 +6,7 @@ #include void test_chdir() { - ecl::util::TestArea ta("chdir"); + rd::util::TestArea ta("chdir"); const char *cwd = ta.test_cwd().c_str(); test_assert_false(util_chdir_file("/file/does/not/exist")); diff --git a/lib/util/tests/ert_util_copy_file.cpp b/lib/util/tests/ert_util_copy_file.cpp index 7cb93c58eb..73a22e12c0 100644 --- a/lib/util/tests/ert_util_copy_file.cpp +++ b/lib/util/tests/ert_util_copy_file.cpp @@ -17,7 +17,7 @@ void test_copy_file(const char *executable) { mode0 = stat_buf.st_mode; { - ecl::util::TestArea ta("copy_file"); + rd::util::TestArea ta("copy_file"); util_copy_file(executable, "test.x"); test_assert_true(util_file_exists("test.x")); diff --git a/lib/util/tests/ert_util_mkdir_p.cpp b/lib/util/tests/ert_util_mkdir_p.cpp index b1e5c8c10e..bfcdf13b91 100644 --- a/lib/util/tests/ert_util_mkdir_p.cpp +++ b/lib/util/tests/ert_util_mkdir_p.cpp @@ -6,7 +6,7 @@ #include int main(int argc, char **argv) { - ecl::util::TestArea ta("mkdir"); + rd::util::TestArea ta("mkdir"); // Regular use test_assert_true(util_mkdir_p("some/path/with/many/levels")); diff --git a/lib/util/tests/ert_util_normal_path.cpp b/lib/util/tests/ert_util_normal_path.cpp index 1eb9325502..5d9be97a7a 100644 --- a/lib/util/tests/ert_util_normal_path.cpp +++ b/lib/util/tests/ert_util_normal_path.cpp @@ -12,7 +12,7 @@ void test_path(const char *input_path, const char *expected_path) { } void test_relative() { - ecl::util::TestArea ta("relative_path"); + rd::util::TestArea ta("relative_path"); util_make_path("level0/level1/level2"); test_path("level0/level1/../", "level0"); @@ -32,7 +32,7 @@ void test_relative() { } void test_beyond_root() { - ecl::util::TestArea("beyond_root"); + rd::util::TestArea("beyond_root"); char *cwd = util_alloc_cwd(); char *backref_cwd1 = util_alloc_sprintf("../../../../../../../../../../../%s", cwd); diff --git a/lib/util/tests/ert_util_spawn.cpp b/lib/util/tests/ert_util_spawn.cpp index b0cf560625..9573dd7ecb 100644 --- a/lib/util/tests/ert_util_spawn.cpp +++ b/lib/util/tests/ert_util_spawn.cpp @@ -40,7 +40,7 @@ bool check_script(const char *script) { } void test_spawn_no_redirect() { - ecl::util::TestArea ta("spawn1"); + rd::util::TestArea ta("spawn1"); { int status; make_script("script", stdout_msg, stderr_msg); @@ -116,7 +116,7 @@ void *test_spawn_redirect__(const char *path) { } void test_spawn_redirect() { - ecl::util::TestArea ta("test_redirect"); + rd::util::TestArea ta("test_redirect"); { make_script("script", stdout_msg, stderr_msg); util_addmode_if_owner("script", S_IRUSR + S_IWUSR + S_IXUSR + S_IRGRP + @@ -132,7 +132,7 @@ void test_spawn_redirect_threaded() { const int num = 128; // Generate the scripts on disk first - ecl::util::TestArea("spawn1_threaded"); + rd::util::TestArea("spawn1_threaded"); int *path_codes = (int *)util_calloc(num, sizeof *path_codes); stringlist_type *script_fullpaths = stringlist_alloc_new(); for (int i = 0; i < num; i++) { diff --git a/lib/util/tests/ert_util_split_path.cpp b/lib/util/tests/ert_util_split_path.cpp index 7b08ef1bfc..468f97891b 100644 --- a/lib/util/tests/ert_util_split_path.cpp +++ b/lib/util/tests/ert_util_split_path.cpp @@ -2,7 +2,7 @@ #include "detail/util/path.hpp" -using namespace ecl::util; +using namespace rd::util; int main(int argc, char **argv) { diff --git a/lib/util/tests/ert_util_stringlist_test.cpp b/lib/util/tests/ert_util_stringlist_test.cpp index 9e54f2e621..218f9b479a 100644 --- a/lib/util/tests/ert_util_stringlist_test.cpp +++ b/lib/util/tests/ert_util_stringlist_test.cpp @@ -337,7 +337,7 @@ bool not_FILE_predicate(const char *name, const void *arg) { } void test_predicate_matching() { - ecl::util::TestArea ta("stringlist"); + rd::util::TestArea ta("stringlist"); stringlist_type *s = stringlist_alloc_new(); stringlist_append_copy(s, "s"); stringlist_select_files(s, "does/not/exist", NULL, NULL); diff --git a/lib/util/tests/test_area.cpp b/lib/util/tests/test_area.cpp index 3476d8d05a..6a3b07208d 100644 --- a/lib/util/tests/test_area.cpp +++ b/lib/util/tests/test_area.cpp @@ -4,7 +4,7 @@ #include void test_create() { - ecl::util::TestArea ta("Name"); + rd::util::TestArea ta("Name"); test_assert_true(ta.test_cwd() != ta.original_cwd()); } diff --git a/lib/util/util.cpp b/lib/util/util.cpp index 45e0f29d65..eb36008bbe 100644 --- a/lib/util/util.cpp +++ b/lib/util/util.cpp @@ -150,7 +150,7 @@ void util_endian_flip_vector(void *data, int element_size, int elements) { In the case of a 64 bit CPU the fastest way to swap 32 bit variables will be by swapping two elements in one operation; this is provided by the util_endian_convert32_64() function. In the case - of binary ECLIPSE files this case is quite common, and + of binary restart format files this case is quite common, and therefore worth supporting as a special case. */ uint64_t *tmp64 = (uint64_t *)data; diff --git a/lib/util/util_endian.cpp b/lib/util/util_endian.cpp index 4b57432f19..c3cb5a9a3c 100644 --- a/lib/util/util_endian.cpp +++ b/lib/util/util_endian.cpp @@ -82,7 +82,7 @@ void util_endian_flip_vector(void *data, int element_size, int elements) { In the case of a 64 bit CPU the fastest way to swap 32 bit variables will be by swapping two elements in one operation; this is provided by the util_endian_convert32_64() function. In the case - of binary ECLIPSE files this case is quite common, and + of binary restart format files this case is quite common, and therefore worth supporting as a special case. */ uint64_t *tmp64 = (uint64_t *)data; diff --git a/python/docs/CMakeLists.txt b/python/docs/CMakeLists.txt index 7de73b8ca4..32626b5804 100644 --- a/python/docs/CMakeLists.txt +++ b/python/docs/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(Sphinx REQUIRED) -set(DOC_INSTALL_PREFIX "share/libecl/docs") +set(DOC_INSTALL_PREFIX "share/resdata/docs") set(doc_build "${PROJECT_BINARY_DIR}/doc_build") file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/code" DESTINATION ${doc_build}) @@ -12,7 +12,7 @@ add_custom_target( COMMAND sphinx-apidoc -e -o "${doc_build}/api" ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} tests WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} - DEPENDS ecl) + DEPENDS resdata) add_custom_target( html-doc ALL @@ -58,11 +58,11 @@ if(PDFLATEX_COMPILER) # correctly. add_custom_target( pdf-doc ALL - COMMAND ${PDFLATEX_COMPILER} "libecl.tex" - COMMAND ${PDFLATEX_COMPILER} "libecl.tex" + COMMAND ${PDFLATEX_COMPILER} "resdata.tex" + COMMAND ${PDFLATEX_COMPILER} "resdata.tex" DEPENDS latex-doc WORKING_DIRECTORY ${latex_workdir}) - install(FILES ${latex_workdir}/libecl.pdf + install(FILES ${latex_workdir}/resdata.pdf DESTINATION ${CMAKE_INSTALL_PREFIX}/${DOC_INSTALL_PREFIX}/pdf) endif() diff --git a/python/docs/code/python/index.rst b/python/docs/code/python/index.rst index c48e272c63..f2cba6fa87 100644 --- a/python/docs/code/python/index.rst +++ b/python/docs/code/python/index.rst @@ -1,11 +1,11 @@ -The ert.ecl package +The resdata package =================== .. contents:: :depth: 2 :local: -The :code:`ert.ecl` package for working with Eclipse files is quite +The :code:`resdata` package for working with Eclipse files is quite extensive. There is some quite limited support for reading :code:`grdecl` formatted input files, but mainly the package is devoted to loading and interpreting the binary output files from @@ -13,10 +13,10 @@ Eclipse. This includes :code:`INIT, GRID/EGRID, RFT`, summary and restart files. .. _structure_binary_files -Structure of Eclipse binary files +Structure of Restart format binary files --------------------------------- -The binary files from ECLIPSE are built up with a common structure. +The restart format binary files are built up with a common structure. They consist of a collection of keywords [1]_, where each keyword has a header and a block of data. The header consist of three fields: @@ -37,10 +37,10 @@ formatted one can take a look: .. code:: bash - bash% convert.x ECLIPSE.INIT - converting ECLIPSE.INIT -> ECLIPSE.FINIT + bash% convert.x CASE.INIT + converting CASE.INIT -> CASE.FINIT -Looking at the formatted file ECLIPSE.FINIT, we can e.g. look at the +Looking at the formatted file CASE.FINIT, we can e.g. look at the PORV keyword from the INIT file: .. code:: bash @@ -56,14 +56,14 @@ Here we see that the name of keyword is 'PORV', and it consists of (BASE.SMSPEC / BASE.UNSMRY / BASE.Snnnn), restart (BASE.UNRST / BASE.Xnnnn), grid (BASE.EGRID / BASE.GRID), rft (BASE.RFT) and init (BASE.INIT) consist of collections of such keywords. In the -:code:`ert.ecl` code the classes :code:`EclKW` and :code:`Ecl3DKW` are +:code:`resdata` code the classes :code:`ResdataKW` and :code:`Resdata3DKW` are designed to work with *one* such keyword. FortIO - work with binary Eclipse IO ------------------------------------ -The binary files created by ECLIPSE are created according to a Fortran +The restart format binary files are created according to a Fortran IO convention, which is a bit special, when writing e.g. a block of 1000 bytes of data to disk the Fortran IO system will surround the block with a header and a tail denoting the size of the @@ -81,49 +81,50 @@ What actually hits the disk looks like this: | 400 | array ...... | 400 | The header and tail is a 4 byte integer, which value is the number of -bytes in the immediately following record. In addition the ECLIPSE +bytes in the immediately following record. In addition the files are ususally(?) written in the "the other" endianness. The :code:`FortIO` class should handle these matters transparently. For normal use of the library it should not be necessary to explicitly use the :code:`FortIO` class. The :code:`FortIO` class has quite good embedded documentation, and -you are advised to use :code:`pydoc ert.ecl.FortIO` or browse the API +you are advised to use :code:`pydoc resdata.resfile.FortIO` or browse the API documentation at :ref:`python_documentation` for further details. -EclKW/Ecl3DKW - work with one keyword +ResdataKW/Resdata3DKW - work with one keyword ------------------------------------- -The :code:`EclKW` class represents one keyword [1]_ from an Eclipse -result file. The :code:`EclKW` class is essentially a vector of data, +The :code:`ResdataKW` class represents one keyword [1]_ from an Eclipse +result file. The :code:`ResdataKW` class is essentially a vector of data, along with header with the size and type of data, and the name of the -vector. Mostly you will get :code:`EclKW` instances by querying a -:code:`EclFile` instance - but you can also instantiate -:code:`EclKW` instances manually. The :code:`Ecl3DKW` class is for +vector. Mostly you will get :code:`ResdataKW` instances by querying a +:code:`ResdataFile` instance - but you can also instantiate +:code:`ResdataKW` instances manually. The :code:`Resdata3DKW` class is for keywords which represent 3D properties like e.g. PRESSURE and PORO, this class requires a grid instance, and is documented with the -:code:`EclGrid` documentation. +:code:`Grid` documentation. Special methods - container ........................... -The :code:`EclKW` class implements the :code:`__getitem__()` and +The :code:`ResdataKW` class implements the :code:`__getitem__()` and :code:`__setitem__()` methods which are used to implement access using the :code:`[ ]` notation, and the :code:`__len__()` method which gives -the size of the :code:`EclKW` instance. In the example below we load +the size of the :code:`ResdataKW` instance. In the example below we load an INIT file and extract the PERMX and PORO keywords, we then forcefully set permeability to zero for all elements where the porosity is below a limit: .. code:: python - from ert.ecl import EclFile,EclGrid + from resdata.grid import Grid + from resdata.resfile import ResdataFile poro_limit = 0.05 - grid = EclGrid("CASE.EGRID") - init_file = EclFile("CASE.INIT") + grid = Grid("CASE.EGRID") + init_file = ResdataFile("CASE.INIT") permx = init_file["PERMX][0] poro = init_file["PORO"][0] @@ -135,22 +136,22 @@ porosity is below a limit: with open("permx.grdecl" , "w") as fileH: grid.write_grdecl( permx , fileH ) -In addition to the :code:`EclKW` class this example uses the classes -:code:`EclGrid` and :code:`EclFile` - see the documentation of them +In addition to the :code:`ResdataKW` class this example uses the classes +:code:`Grid` and :code:`ResdataFile` - see the documentation of them below. Furthermore this example demonstrates an important point: even -though the :code:`EclKW` class is an important "workhorse" - we mostly -get it from an :code:`EclFile` instance and do not instantiate it +though the :code:`ResdataKW` class is an important "workhorse" - we mostly +get it from an :code:`ResdataFile` instance and do not instantiate it directly. -For more details type :code:`pydoc ert.ecl.EclKW` or browse the API +For more details type :code:`pydoc resdata.resfile.ResdataKW` or browse the API documentation at :ref:`python_documentation`. Special methods - arithmetic ............................ -The :code:`EclKW` class implements all the arithmetic operators, -meaning that :code:`EclKW` instances can be added, multiplied and +The :code:`ResdataKW` class implements all the arithmetic operators, +meaning that :code:`ResdataKW` instances can be added, multiplied and shifted. In the example below we load all INIT files with a matching filename pattern and then calculate the mean and standard deviation of the permeability: @@ -159,19 +160,20 @@ the permeability: import glob import math - from ert.ecl import EclFile, EclTypeEnum + from resdata.resfile import ResdataFile + from resdata import ResdataTypeEnum initfile_pattern = "/path/to/files/real*/CASE-*.INIT" kw_list = [] for init_file in glob.glob(initfile_pattern): - ecl_file = EclFile(init_file) - kw_list.append( ecl_file["PERMX"][0] ) + rd_file = ResdataFile(init_file) + kw_list.append( rd_file["PERMX"][0] ) - mean = EclKW.create("AVG-PERMX" , len(kw_list[0]) , EclTypeEnum.ECL_FLOAT_TYPE) - std = EclKW.create("STD-PERMX" , len(kw_list[0]) , EclTypeEnum.ECL_FLOAT_TYPE) + mean = ResdataKW.create("AVG-PERMX" , len(kw_list[0]) , ResdataTypeEnum.RD_FLOAT_TYPE) + std = ResdataKW.create("STD-PERMX" , len(kw_list[0]) , ResdataTypeEnum.RD_FLOAT_TYPE) - # Here we do normal arithmetic calculations with the EclKW instances + # Here we do normal arithmetic calculations with the ResdataKW instances for kw in kw_list: mean += kw std += kw * kw @@ -187,28 +189,28 @@ the permeability: Observe that for the arithmetic operations you can also call the inplace methods (*without* leading 'i') :code:`add()`, :code:`mul()`, :code:`sub` and :code:`div()` directly - in this form the methods also -accept a *mask* parameter as an :code:`EclRegion` instance which can +accept a *mask* parameter as an :code:`ResdataRegion` instance which can limit the operation to only a subset of the elements. -EclFile - an arbitrary binary Eclipse file +ResdataFile - an arbitrary binary Eclipse file ------------------------------------------ -The :code:`EclFile` class loads an arbitrary binary Eclipse file, and +The :code:`ResdataFile` class loads an arbitrary binary Eclipse file, and creates an index of all the keywords in the file. The main reason for -opening an Eclipse file with an :code:`EclFile` instance is to look up -keywords in the file as :code:`EclKW` instances. The :code:`EclFile` +opening an Eclipse file with an :code:`ResdataFile` instance is to look up +keywords in the file as :code:`ResdataKW` instances. The :code:`ResdataFile` is general and can be used to open any file, but in addition there are -specialized classes :code:`EclInitFile` and :code:`EclRestartFile` +specialized classes :code:`ResdataInitFile` and :code:`ResdataRestartFile` which can be used to open :code:`INIT` and restart files respectively; -these are documented along with the :code:`Ecl3DKW` class after the -:code:`EclGrid` documentation. +these are documented along with the :code:`Resdata3DKW` class after the +:code:`Grid` documentation. Special method __contains__() ............................. -The :code:`EclFile` class implements the :code:`__contains__` method +The :code:`ResdataFile` class implements the :code:`__contains__` method which is typically used to check if a file contains a certain keyword. The following example is a small script which will load an Eclipse binary file given as a command line argument, and check if the @@ -216,22 +218,22 @@ file contains keywords also given on the command line: .. code:: bash - bash% scan_file.py ECLIPSE.UNRST SWAT SGAS SOIL + bash% scan_file.py CASE.UNRST SWAT SGAS SOIL -Will open the file :code:`ECLIPSE.UNRST` and check if it contains the +Will open the file :code:`CASE.UNRST` and check if it contains the keywords :code:`SWAT`, :code:`SGAS` and :code:`SOIL`: .. code:: python #!/usr/bin/env python import sys - from ert.ecl import EclFile + from resdata.resfile import ResdataFile - # Open the file, EclFile will raise the IOError exception + # Open the file, ResdataFile will raise the IOError exception # if the open fails. try: - file = EclFile( sys.argv[1] ) + file = ResdataFile( sys.argv[1] ) except IOError: sys.exit("Could not open file: %s" % sys.argv[1]) @@ -247,16 +249,16 @@ keywords :code:`SWAT`, :code:`SGAS` and :code:`SOIL`: Special method __getitem__() ............................ -The :code:`__getitem__()` method is used to get an :code:`EclKW` +The :code:`__getitem__()` method is used to get an :code:`ResdataKW` instance from a file through the :code:`[]` operator. The argument to the :code:`[]` operator can either be an integer to get a keywords by plain index order, or a keyword name. .. code:: python - from ert.ecl import EclFile + from resdata.resfile import ResdataFile - file = EclFile("CASE.UNRST") + file = ResdataFile("CASE.UNRST") first_kw = file[0] swat_kw = file["SWAT"] @@ -268,30 +270,30 @@ keywords with the same name in a file. Restart specials ................ -The :code:`EclFile` class has many specialized methods for to perform +The :code:`ResdataFile` class has many specialized methods for to perform queries on the time direction of restart files. These methods should -be moved to :code:`EclRestartFile` class, and are documented there. +be moved to :code:`ResdataRestartFile` class, and are documented there. -For more details type :code:`pydoc ert.ecl.EclFile` or browse the API +For more details type :code:`pydoc resdata.resfile.ResdataFile` or browse the API documentation at :ref:`python_documentation`. -EclGrid - load a grid +Grid - load a grid --------------------- -The :code:`EclGrid` class is used to load an Eclipse Grid, the main +The :code:`Grid` class is used to load an Eclipse Grid, the main way to load a grid is from a :code:`EGRID` or :code:`GRID` file, but as an alternative it is also possible to create a grid from a .grdecl formatted *input* file [3]_, or a simple rectangualar grid can be -*created* without an input file. In most cases the :code:`EclGrid` +*created* without an input file. In most cases the :code:`Grid` instance will be created as simple as: .. code:: python - from ert.ecl import EclGrid + from resdata.grid import Grid - grid = EclGrid("ECLIPSE.EGRID") + grid = Grid("CASE.EGRID") @@ -301,7 +303,7 @@ Active/inactive cells - index types For a typical reservoir model a large fraction of the cells are not active; i.e. they are ignored in the flow calculations. The bookkeeping of active/inactive cells is managed by grid. As a user of -the :code:`ert.ecl` Python package you must have some understanding of +the :code:`resdata` Python package you must have some understanding of these issues. Consider a 2D 3x3 grid model where only five of the cells are active: @@ -324,7 +326,7 @@ cells are active: The 0 or 1 in the upper left corner of each cell indicates whether the cell is active(1) or inactive(0) [4]_. When working with the -:code:`EclGrid` there are generally *three* different ways to refer to +:code:`Grid` there are generally *three* different ways to refer to a specific cell - these are: 1. A triplet of :code:`(i,j,k)` values - in the example above @@ -338,7 +340,7 @@ a specific cell - these are: uniquely identifies an *active* cell. In the figure above the active indices are the integers with a trailing 'a'. -All the methods on the :code:`EclGrid` object which evaluate +All the methods on the :code:`Grid` object which evaluate properties for a particular cell can take the cell coordinate in any of the three formats above. In addition there are conversion functions between the three. Observe that all the indexing methods assume that @@ -354,11 +356,12 @@ and then we print the (i,j,k) values for all the cells with .. code:: python - from ert.ecl import EclGrid,EclFile + from resdata.grid import Grid + from resdata.resfile import ResdataFile permx_limit = 1e-2 - grid = EclGrid( "CASE.EGRID" ) - init = EclFile( "CASE.INIT" ) + grid = Grid( "CASE.EGRID" ) + init = ResdataFile( "CASE.INIT" ) permx_kw = init["PERMX"][0] @@ -376,31 +379,31 @@ cells. When working interchangebly with properties defined over all cells or only the active cells it is very important to think straight. -Ecl3DKW - a grid aware EclKW class +Resdata3DKW - a grid aware ResdataKW class .................................. -The :code:`Ecl3DKW` class is derived from the :code:`EclKW` class, but -the instance has a :code:`EclGrid` and optionally a default value +The :code:`Resdata3DKW` class is derived from the :code:`ResdataKW` class, but +the instance has a :code:`Grid` and optionally a default value associated to it. The purpose of this is to be able to use :code:`(i,j,k)` as index when looking up values. When :code:`(i,j,k)` -is used to identify the cell the, :code:`Ecl3DKW` class can +is used to identify the cell the, :code:`Resdata3DKW` class can transparently handle the active/inactive cells issue - returning a default value in the case of undefined inactive cells. -When the :code:`[]` argument is a single integer the :code:`Ecl3DKW` +When the :code:`[]` argument is a single integer the :code:`Resdata3DKW` class can not know whether the index supplied is an active or a global index, and it will be a simple index lookup - which properties are determined by the length of the underlying data. -The :code:`Ecl3DKW` class is mainly convenience compared to the pure -:code:`EclKW` class - for performance reasons it should probably not +The :code:`Resdata3DKW` class is mainly convenience compared to the pure +:code:`ResdataKW` class - for performance reasons it should probably not be used if you wish to run through all the cells. Using the grid object ..................... -The :code:`EclGrid` object has a long range of methods for extracting +The :code:`Grid` object has a long range of methods for extracting grid properties: 1. Many different methods for working with cell data like position, @@ -411,23 +414,23 @@ grid properties: 3. *Some* functionality for working with LGRs, coarse groups and fractured grid. - 4. Methods for exporting a :code:`EclKW` defined over + 4. Methods for exporting a :code:`ResdataKW` defined over :code:`nactive` elements to a :code:`grdecl` formatted file with :code:`nx*ny*nz` elements. -In addition the :code:`EclGrid` is used as an input for the -:code:`Ecl3DKW` properties and also for the :code:`EclRegion` -class. For further details please type :code:`pydoc ert.ecl.EclGrid` +In addition the :code:`Grid` is used as an input for the +:code:`Resdata3DKW` properties and also for the :code:`ResdataRegion` +class. For further details please type :code:`pydoc resdata.resfile.Grid` or browse the API documentation at :ref:`python_documentation`. -EclInitFile and EclRestartFile - grid aware files +ResdataInitFile and ResdataRestartFile - grid aware files ------------------------------------------------- For restart and init files you can optionally choose to use -:code:`EclInitFile` and :code:`EclRestartFile` classes instead of the -basic :code:`EclFile` class. These two derived classes have a grid -attached, and will return a :code:`Ecl3DKW` instance instead of a -:code:`EclKW` instance for keywords with either :code:`nx*ny*nz` or +:code:`ResdataInitFile` and :code:`ResdataRestartFile` classes instead of the +basic :code:`ResdataFile` class. These two derived classes have a grid +attached, and will return a :code:`Resdata3DKW` instance instead of a +:code:`ResdataKW` instance for keywords with either :code:`nx*ny*nz` or :code:`nactive` elements. In the example below we have a list of :code:`(i,j,k)` triplets and we @@ -436,23 +439,24 @@ the :code:`(i,j,k) -> active_index` transformation: .. code:: python - from ert.ecl import EclGrid,EclInitFile + from resdata.grid import Grid + from resdata.resfile import ResdataInitFile - grid = EclGrid( "CASE.EGRID" ) - init = EclInitFile( "CASE.INIT" ) + grid = Grid( "CASE.EGRID" ) + init = ResdataInitFile( "CASE.INIT" ) cell_list = [(1,2,3), (1,4,5), (2,2,7)] - # The permx_kw will now be a Ecl3DKW instance + # The permx_kw will now be a Resdata3DKW instance permx_kw = init["PERMX"][0] for ijk in cell_list: print("permx : %g" % permx_kw[ijk]) -Time queries in EclRestartFile +Time queries in ResdataRestartFile .............................. -The :code:`EclRestartFile` class has many methods for queries on the +The :code:`ResdataRestartFile` class has many methods for queries on the temporal content of a restart file [5]_. Classmethods @@ -460,10 +464,10 @@ Classmethods Several of the methods giving temporal information on restart files are *classmethods* - which means that an be invoked *without* creating -the :code:`EclRestartFile` instance first: +the :code:`ResdataRestartFile` instance first: -EclRestartFile.file_report_list +ResdataRestartFile.file_report_list ******************************* The classmethod :code:`file_report_list` will scan through a file and @@ -473,28 +477,28 @@ file. .. code:: python - from ert.ecl import EclRestartFile + from resdata.resfile import ResdataRestartFile - report_list = EclRestartFile.file_report_list("ECLIPSE.UNRST") + report_list = ResdataRestartFile.file_report_list("CASE.UNRST") print("The file: %s contains the following report steps: ") print( ", ".join(report_list)) -EclRestartFile.contains_report_step +ResdataRestartFile.contains_report_step *********************************** The classmethod :code:`contains_report_step` will check if the file *filename* contains the report_step *report_step*: - if EclRestartFile.contains_report_step( "ECLIPSE.UNRST" , 100): + if ResdataRestartFile.contains_report_step( "CASE.UNRST" , 100): print("The file has a section for report step=100") else: print("No - the file does not have report_step = 100") -EclRestartFile.contains_sim_time +ResdataRestartFile.contains_sim_time ******************************** The classmethod :code:`contains_report_step` will check if the file @@ -503,24 +507,24 @@ be given as a normal Python :code:`datetime`: .. code:: python - from ert.ecl import EclRestartFile + from resdata.resfile import ResdataRestartFile import datetime sim_time = datetime.datetime( 2010 , 6 , 15 ) - if EclRestartFile.contains_sim_time( "ECLIPSE.UNRST" , sim_time ): + if ResdataRestartFile.contains_sim_time( "CASE.UNRST" , sim_time ): print("The file has a section date: %s" % sim_time) else: print("No - the file does not have data at: %s" % sim_time) -EclRegion - a method to select cells +ResdataRegion - a method to select cells ------------------------------------ -The purpose of the :code:`EclRegion` class is to build up a set of set +The purpose of the :code:`ResdataRegion` class is to build up a set of set cells in a *region* [6]_ based on various selection criteria. That selection is then typically used to update a set of cells in a -:code:`EclKW` instance, either as a :code:`mask=region` parameter in +:code:`ResdataKW` instance, either as a :code:`mask=region` parameter in one of the arithmetic operators or by directly looping through the index set. @@ -536,19 +540,23 @@ apply is: .. code:: python - from ert.ecl import EclGrid, EclRegion, EclKW, EclTypeEnum + from resdata.grid import ResdatGrid, ResdataRegio + from resdata.resfile import ResdataKW + from resdata import ResdataTypeEnum + + grid = Grid( "CASE.EGRID" ) grid = EclGrid( "CASE.EGRID" ) with open("poro.grdecl") as f: - poro = EclKW.read_grdecl( f , "PORO") + poro = ResdataKW.read_grdecl( f , "PORO") with open("permx.grdecl") as f: - permx = EclKW.read_grdecl( f , "PERMX") + permx = ResdataKW.read_grdecl( f , "PERMX") # Create an initially empty region, and select all the cells where # PORO is below 0.01 - reg1 = EclRegion( grid , False ) + reg1 = ResdataRegion( grid , False ) reg1.select_less( poro , 0.01 ) @@ -556,20 +564,20 @@ apply is: # PORO is above 0.01. Then we select all the cells where PERMX is # above 200. Since the flag intersect is True this second selection # is only among the already selected cells. - reg2 = EclRegion( grid , False ) + reg2 = ResdataRegion( grid , False ) reg2.select_more( poro , 0.01 ) reg2.select_more( permx , 200 , intersect = True ) # Create a region where all cells are initially selected, # then subtract the regions reg1 and reg2. - reg3 = EclRegion( grid , True ) + reg3 = ResdataRegion( grid , True ) reg3 -= (reg1 + reg2) # Create a new satnum keyword and use the assign() method with a # mask parameter. - satnum = EclKW.create( "SATNUM" , grid.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE) + satnum = ResdataKW.create( "SATNUM" , grid.getGlobalSize() , ResdataTypeEnum.RD_INT_TYPE) satnum.assign( 1, mask = reg1 ) satnum.assign( 2, mask = reg2 ) satnum.assign( 3, mask = reg3 ) @@ -578,7 +586,7 @@ apply is: satnum.write_grdecl( f ) -EclRegion - selectors +ResdataRegion - selectors ..................... A region can be constructed in many different ways: @@ -586,8 +594,8 @@ A region can be constructed in many different ways: 1. Based on slices of :code:`i,j,k` values. 2. Inside or outside a polygon; or alternatively "above" or "below" a line. - 3. Based on comparing a :code:`EclKW` instance with a scalar value. - 4. Based on comparing two :code:`EclKW` instances. + 3. Based on comparing a :code:`ResdataKW` instance with a scalar value. + 4. Based on comparing two :code:`ResdataKW` instances. 5. Based on cell geometry - i.e. size, depth or thickness. Observe the following: @@ -601,10 +609,10 @@ Observe the following: cells. -EclRegion - special methods +ResdataRegion - special methods ........................... -The :code:`EclRegion` class implements the special methods required to +The :code:`ResdataRegion` class implements the special methods required to view the regions as set; i.e. you can add and subtract regions and form the union and intersection of regions. @@ -628,41 +636,41 @@ form the union and intersection of regions. reg3 = reg1 & reg2 For further details, specially of the various select methods, please -type :code:`pydoc ert.ecl.EclRegion` or browse the API documentation +type :code:`pydoc resdata.region.ResdataRegion` or browse the API documentation at :ref:`python_documentation`. RFT --- -The support for RFT files in :code:`ert.ecl` is split among the three -classes :code:`EclRFTFile`, :code:`EclRFT` and :code:`EclRFTCell`. The -:code:`EclRFTFile` class is used to load an ECLIPSE RFT file. The RFT +The support for RFT files in :code:`resdata` is split among the three +classes :code:`ResdataRFTFile`, :code:`ResdataRFT` and :code:`ResdataRFTCell`. The +:code:`ResdataRFTFile` class is used to load an RFT file. The RFT files will generally contain results for several wells, and several -times, the :code:`EclRFTFile` class will load them all - and then +times, the :code:`ResdataRFTFile` class will load them all - and then supplies an interface to query for individual RFT results based on wellname and/or date; the individual RFT results will be in the form -of :code:`EclRFT` instances. +of :code:`ResdataRFT` instances. .. code:: python - from ert.ecl import EclRFTFile + from resdata.rft import ResdataRFTFile # Load the RFT file - rft_file = EclRFTFile("ECLIPSE.RFT") + rft_file = ResdataRFTFile("CASE.RFT") # Extract the RFT results for well 'OP-X' at date 2010-01-15; # will return None if no such RFT exists - should probably raise an # exception. rft = rft_file.get("OP-X" , datetime.date(2010,1,15)) -In addition to the main method: :code:`EclRFTFile.get()` the -:code:`EclRFTFile` class has utility methods to list all the well and +In addition to the main method: :code:`ResdataRFTFile.get()` the +:code:`ResdataRFTFile` class has utility methods to list all the well and date values present in the RFT file, the number of wells and so on. -EclRFT +ResdataRFT ...... -From the :code:`EclRFTFile.get()` method we get a :code:`EclRFT` +From the :code:`ResdataRFTFile.get()` method we get a :code:`ResdataRFT` instance. Observe that one RFT file can contain a lump of different data RFT types: @@ -674,19 +682,19 @@ data RFT types: SEGMENT: Not implemented. -The :code:`EclRFT` object has some metadata describing which type +The :code:`ResdataRFT` object has some metadata describing which type of data it represents, and there is some special functionality related -to MSW wells; but the main purpose of the :code:`EclRFT` class is to -serve as container holding a list of :code:`EclRFTCell` instances - -one for each perforated cell in the RFT. The :code:`EclRFT` class has +to MSW wells; but the main purpose of the :code:`ResdataRFT` class is to +serve as container holding a list of :code:`ResdataRFTCell` instances - +one for each perforated cell in the RFT. The :code:`ResdataRFT` class has implemented the :code:`__getitem__()` method, so the following code will loop identify an RFT from a file and then loop through all the cells for that RFT. .. code:: python - from ert.ecl import EclRFTFile - rft_file = EclRFTFile("ECLIPSE.RFT") + from resdata.rft import ResdataRFTFile + rft_file = ResdataRFTFile("CASE.RFT") rft = rft_file.get("OP-X" , datetime.date(2010,1,15)) for cell in rft: @@ -694,53 +702,53 @@ cells for that RFT. cell.get_i() , cell.get_j() , cell.get_k() , cell.depth , cell.pressure)) Depending on whether this is RFT or a PLT the exact type of the cell -object will be either :code:`EclRFTCell` or :code:`EclPLTCell`, the -:code:`EclPLTCell` has many extra properties not in the -:code:`EclRFTCell` class. For more detail use :code:`pydoc` to look at -the classes :code:`ert.ecl.EclRFTFile`, :code:`ert.ecl.EclRFT`, -:code:`ert.EclRFTCell` or :code:`ert.ecl.EclPLTCell` - or the API +object will be either :code:`ResdataRFTCell` or :code:`ResdataPLTCell`, the +:code:`ResdataPLTCell` has many extra properties not in the +:code:`ResdataRFTCell` class. For more detail use :code:`pydoc` to look at +the classes :code:`resdata.rft.ResdataRFTFile`, :code:`resdata.rft.ResdataRFT`, +:code:`resdata.rft.ResdataRFTCell` or :code:`resdata.rft.ResdataPLTCell` - or the API documentation at :ref:`python_documentation`. -EclSum - working with summary files +Summary - working with summary files ----------------------------------- -Summary files are loaded with the :code:`EclSum` class. The -:code:`EclSum` class is a quite complete implementation for working +Summary files are loaded with the :code:`Summary` class. The +:code:`Summary` class is a quite complete implementation for working with Eclipse summary data, but it should also be said the -:code:`EclSum` class is one of the oldest classes in the -:code:`ert.ecl` package and the api could have been cleaner. +:code:`Summary` class is one of the oldest classes in the +:code:`resdata` package and the api could have been cleaner. -Creating a :code:`EclSum` instance +Creating a :code:`Summary` instance .................................. In more than 99% of the cases the assumption is that we want to create -a :code:`EclSum` instance by loading read-only summary results from -disk, however it is also possible to assemble a :code:`EclSum` +a :code:`Summary` instance by loading read-only summary results from +disk, however it is also possible to assemble a :code:`Summary` instance using the api - that is not covered in this documentation. -The summary results from ECLIPSE come in two different types of files; -the :code:`ECLIPSE.SMSEPEC` file is a *header file* with all the -properties of the variables, and the :code:`ECLIPSE.UNSMRY` (or -alternatively :code:`ECLIPSE.S0000, ECLIPSE.S0001, ECLIPSE.S0002, -...`) file contains the actual values. Creating a :code:`EclSum` +The summary results come in two different types of files; +the :code:`CASE.SMSEPEC` file is a *header file* with all the +properties of the variables, and the :code:`CASE.UNSMRY` (or +alternatively :code:`CASE.S0000, CASE.S0001, CASE.S0002, +...`) file contains the actual values. Creating a :code:`Summary` instance from this is as simple as: .. code:: python - from ert.ecl import EclSum + from resdata.summary import Summary - ecl_sum = EclSum("ECLIPSE") + rd_sum = Summary("CASE") -As is clear from the example the :code:`EclSum` instance is created +As is clear from the example the :code:`Summary` instance is created based only on the basename of the simulation, you can optionally have -an extension like :code:`ecl_sum = EclSum("ECLIPSE.UNSMRY")` - but +an extension like :code:`rd_sum = Summary("ECLIPSE.UNSMRY")` - but that is *mostly* [7]_ ignored. -If your case is restarted from an another case the :code:`EclSum` +If your case is restarted from an another case the :code:`Summary` cconstructor will by default try to locate the historical case, and load the summary results from that as well. Alternatively you can pass -the argument :code:`include_restart = False` to the :code:`EclSum` +the argument :code:`include_restart = False` to the :code:`Summary` constructor. The loading of historical case will fail with an error message if: @@ -748,7 +756,7 @@ message if: 2. The :code:`SMSPEC` is not 100% identical to the current :code:`SMSPEC` setion; this will typically fail if you have modified - the :code:`SUMMARY` section of the ECLIPSE deck between the two + the :code:`SUMMARY` section of the simulator input between the two simulations. @@ -757,7 +765,7 @@ About summary keys The header file :code:`CASE.SMSPEC` has all the information *about* the summary data. The :code:`CASE.SMSPEC` file consists of several -:code:`EclKW` instances, where the three most important one are: +:code:`ResdataKW` instances, where the three most important one are: :code:`KEYWORDS` which contains the variable names like :code:`FOPT`, :code:`WGOR` and :code:`BPR`, the :code:`WGNAMES` vector which contains names of groups and wells, and :code:`NUMS` which @@ -806,7 +814,7 @@ following about the smspec index: tranforming the NUMS value to i,j,k are present. This is not the case for local grid properties, where only the i,j,k variety is used. For these keys the offset of :code:`(i,j,k)` is *one-based* - , which is slightly untypical for the :code:`ert` code. + , which is slightly untypical for the :code:`resdata` code. - All well variables are present for all wells - that means the summary file contains oil production rate :code:`WOPR` for an @@ -832,13 +840,13 @@ vectors; so to actually get the water cut in well 'OP_1' we look up the value of the PARAMS keyword at index 2. By default the SUMMARY data will be created and stored for every timestep of the simulator, i.e. the raw time resolution is directly given by the simulators -performance, in ECLIPSE parlance these are called ministeps. When the -:code:`EclSum` class loads a summary all the ECLIPSE ministeps are +performance, called ministeps. When the +:code:`Summary` class loads a summary all the ministeps are stacked together in one long vector, observe that e.g. when the -keyword RPTONLY is used in the ECLIPSE data file there can be "holes" +keyword RPTONLY is used there can be "holes" in the ministep sequence. -The ert.ecl summary implementation works with four different concepts +The resdata summary implementation works with four different concepts of time: time_index @@ -848,10 +856,10 @@ This is a plain index in the range :code:`[0,..num_timestep)`. Observe that :code:`num_timesteps` is the number of timesteps loaded, and not the total number of timesteps simulated. There can be holes in the ministep sequence, but there will never be holes in this range. It is -closely coupled to the simulator timestep and what the user of ECLIPSE -has chosen to store, so no further meaning should be attached to these -indices. Ultimately all lookups will be based on :code:`time_index`; in the C -code it is therefore often denoted :code:`internal_index`. +closely coupled to the simulator timestep and what is chosen to be stored, so +no further meaning should be attached to these indices. Ultimately all lookups +will be based on :code:`time_index`; in the C code it is therefore often +denoted :code:`internal_index`. ministep ,,,,,,,,, @@ -860,15 +868,15 @@ Each simulator timestep corresponds to one ministep, but an arbitrary summary dataset need not contain all ministeps. In the case of a restarted simulation the first ministeps might be missing completely, and there can also be holes in the series. Each block of summary data -is tagged with a MINISTEP number by ECLIPSE. The ministep indices are +is tagged with a MINISTEP number. The ministep indices are arbitrary properties of the simulation, and are not exported by the -:code:`ert.ecl` API. +:code:`resdata` API. report_step ,,,,,,,,,,,, -This is the ECLIPSE report step, there are functions to convert +This is the report step, there are functions to convert between report step and index, and you can use report step as time value when querying for values. @@ -896,8 +904,8 @@ summary or not: .. code:: python import sys - from ert.ecl import EclSum - sum = ecl.EclSum("ECLIPSE") + from resdata.summary import Summary + sum = Summary("CASE") for key in sys.argv[1:] if key in sum: @@ -918,8 +926,8 @@ variables for the group "NORTH" we can use the :code:`keys()` function as: .. code:: python - from ert.ecl import EclSum - sum = ecl.EclSum("ECLIPSE") + from resdata.summary import Summary + sum = Summary("CASE") matching = sum.keys( "BPR:*" ) + sum.keys( "G*H:NORTH" ) @@ -979,8 +987,8 @@ supplied. The date parameter is a normal python .. code:: python import datetime - import ert.ecl.ecl as ecl - sum = ecl.EclSum( case ) + from resdata.summary import Summary + sum = Summary( case ) print "FWCT after 1000 days: %g" % sum.get_interp( "FWCT" , days = 1000 ) print "Total oil production at 10.10.2010: %g" % sum.get_interp( "FOPT" , date = datetime.date( 2010 , 10 , 10) ) @@ -1007,8 +1015,8 @@ every 6 months: .. code:: python import datetime - import ert.ecl.ecl as ecl - sum = EclSum( "ECLIPSE" ) + from resdata.summary import Summary + sum = Summary( "CASE" ) # Building up the list of dates: date = sum.start_date @@ -1035,20 +1043,20 @@ Methods to get a vector of the complete time series get_vector( key , report_only = False) ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -The get_vector function will return a EclSumVector instance +The get_vector function will return a SummaryVector instance corresponding to key. The __getitem__ function is also implemented in terms of the get_vector function, i.e. the same -behaviour can be achieved with the [] operator: import ert.ecl as ecl +behaviour can be achieved with the [] operator: .. code:: python - sum = ecl.EclSum( "/path/simuluation/BASE" ) - wwct = ecl.get_vector("WWCT:C-1") - wopr = ecl["WOPR:C-1"] + sum = Summary( "/path/simuluation/BASE" ) + wwct = sum.get_vector("WWCT:C-1") + wopr = sum["WOPR:C-1"] If the summary variable key does not exist in the case the exception -KeyError will be raised. By default EclSumVector will have full +KeyError will be raised. By default SummaryVector will have full temporal resolution; but if the optional argument report_only is set to True the vector will only contain data from the report times. This option is not available when the [] operator is used. Properties @@ -1056,7 +1064,9 @@ option is not available when the [] operator is used. Properties length ,,,,,, -The length property is the number of data-points in the summary instance; this corresponds to the number of timesteps in the ECLIPSE simulation; alternatively you can use Python builtin function len(). +The length property is the number of data-points in the summary instance; this +corresponds to the number of timesteps in the simulation; alternatively you can +use Python builtin function len(). start_date / end_date The start_date and end_date properties are the starting date and @@ -1075,7 +1085,7 @@ This is similar to the start_date, end_date properties, but the return value is a Python datetime.datetime() instance instead. Only relevant if you need sub-days time resolution. (Sub-days time resolution is probably quite bug infested.) first_report / last_report The report -steps are the numbering ECLIPSE gives to the DATES keywords. The +steps are the numbering given to the DATES keywords. The properties first_report and last_report return the first and last report steps in the current summary instance. @@ -1086,7 +1096,7 @@ These two functions will return the index of the first "time" where the summary vector corresponding to key goes above (first_gt()) or falls below a limit (first_lt). If the limit is not reached the function will return -1; if the -1 is used as index in a subsequent -call to an EclSum method, it will fail hard. +call to an Summary method, it will fail hard. .. code:: python @@ -1120,9 +1130,9 @@ example below we fetch two vectors, and the simulation days from a summary, and then print it all to the screen: .. code:: python - from ert.ecl import EclSum + from resdata.summary import Summary - sum = EclSum( "/path/ECLIPSE.DATA" ) + sum = Summary( "/path/CASE.DATA" ) days = sum.days wwct = sum.numpy_value("WWCT:OP_1") wopr = sum.numpy_value("WOPR:OP_1") @@ -1134,71 +1144,71 @@ summary, and then print it all to the screen: Special functions/operators [] : get The [] operator is mapped to the get_vector() method and will -return the EclSumVector corresponding to the key entered, i.e. the -EclSum instance will behave much like a dictionary. I.e. to get a -EclSumVector corresponding to field oil production rate you can do: -sum = ecl.EclSum( "ECLIPSE" ) fopr = sum["FOPR"] If you give a key +return the SummaryVector corresponding to the key entered, i.e. the +Summary instance will behave much like a dictionary. I.e. to get a +SummaryVector corresponding to field oil production rate you can do: +sum = Summary( "CASE" ) fopr = sum["FOPR"] If you give a key which does not exist in the summary the KeyError exception will be raised. -EclSumVector +SummaryVector ............ -The EclSumVector class is a small convenience class to work with only -one summary vector. It is not necessary to use the EclSumVector -class - everything can be accessed directly from the EclSum -class. Many of the methods and properties of the EclSumVector are very -similar or actually identical to methods in the EclSum class: +The SummaryVector class is a small convenience class to work with only +one summary vector. It is not necessary to use the SummaryVector +class - everything can be accessed directly from the Summary +class. Many of the methods and properties of the SummaryVector are very +similar or actually identical to methods in the Summary class: The methods/properties which access the timeseries are the same. Many -of the methods which take key input argument in the EclSum case -obviously take no key argument in the case of EclSumVector; if there +of the methods which take key input argument in the Summary case +obviously take no key argument in the case of SummaryVector; if there are no arguments left these methods will typically be converted to read-only properties. Constructor -EclSumVector( parent , key , report_only ) The default constructor -EclSumVector() will create a new EclSumVector instance, but the -intentition is that the EclSumVector instances should be constructed -via the EclSum parent instance, and not explicitly by the user. +SummaryVector( parent , key , report_only ) The default constructor +SummaryVector() will create a new SummaryVector instance, but the +intentition is that the SummaryVector instances should be constructed +via the Summary parent instance, and not explicitly by the user. Methods -The EclSumVector class has all the same methods as the EclSum class; +The SummaryVector class has all the same methods as the Summary class; with the obvious exceptions of has_key() and keys(). The key argument -present in the methods ... is removed in the EclSumVector incarnation. +present in the methods ... is removed in the SummaryVector incarnation. Properties Special functions/operators [] : get -The EclSumVector implements the __getitem__() method to support +The SummaryVector implements the __getitem__() method to support iteration and the [] operator. The __getitem__ method supports negative indices and partly slicing. When slicing the returned value -will not be reduced EclSumVector instance, but rather a plain Python +will not be reduced SummaryVector instance, but rather a plain Python list with the correct set of elements. The elements returned from the -__getitem__ method are EclSumNode instances. +__getitem__ method are SummaryNode instances. .. code:: python - from ert.ecl import EclSum + from resdata.summary import Summary - eclsum = EclSum( "ECLIPSE" ) - wwct = eclsum["WWCT:OP-5"] + sum = Summary( "CASE" ) + wwct = sum["WWCT:OP-5"] print "First value element: " wwct[0].value print "Last value : " wwct[-1].value print "List of every third: " wwct[0::3] -EclSumNode +SummaryNode .......... -The EclSumNode class is very small, more like a C struct. It contains +The SummaryNode class is very small, more like a C struct. It contains 11the value, along with time in different units for one summary vector -at one point in time; the content of the EclSumNode is plain field -variables; no properties or anything fancy. The EclSumNode has the +at one point in time; the content of the SummaryNode is plain field +variables; no properties or anything fancy. The SummaryNode has the following fields: value : The actual value @@ -1208,15 +1218,15 @@ following fields: date : The simulation date mpl_date : A date format suitable for matplotlib -When iterating over a EclSumVector the return values will be in the -form EclSumNode instances. The EclSumNode instances are created on -demand by a EclSumVector instance. The example below show how the -EclSumNode instances arise when iterating over the content of a -EclSumVector: +When iterating over a SummaryVector the return values will be in the +form SummaryNode instances. The SummaryNode instances are created on +demand by a SummaryVector instance. The example below show how the +SummaryNode instances arise when iterating over the content of a +SummaryVector: .. code:: python - wwct = ecl_sum["WWCT:C-1A"] + wwct = rd_sum["WWCT:C-1A"] for node in wwct: print "Days:%g value:%g" % (node.days , node.value) @@ -1243,8 +1253,8 @@ EclSumVector: by Eclipse to denote active/inactive status. .. [5] The methods are currently implemented in the base class - :code:`EclFile` - but they should be moved to the - :code:`EclRestartFile` class. + :code:`ResdataFile` - but they should be moved to the + :code:`ResdataRestartFile` class. .. [6] Observe that the set of cells need *not* form a singly connected set. @@ -1252,9 +1262,9 @@ EclSumVector: .. [7] Since the summary files can be both formatted and unformatted, and also both unified and non-unified there can potentially be several datasets with the same basename present in the - directory. The :code:`EclSum` loader will by default use the + directory. The :code:`Summary` loader will by default use the latest version, but by supplying an extension you can control which files should be loaded; i.e. when calling as - :code:`EclSum("ECLIPSE.A0056")` the loader will *only* look for + :code:`Summary("CASE.A0056")` the loader will *only* look for multiple formatted files. diff --git a/python/docs/conf.py.in b/python/docs/conf.py.in index 7d57a51d49..ddcf5f8c01 100644 --- a/python/docs/conf.py.in +++ b/python/docs/conf.py.in @@ -47,7 +47,7 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'libecl' +project = u'resdata' copyright = u'2014, Equinor ASA' # The version info for the project you're documenting, acts as replacement for @@ -55,9 +55,9 @@ copyright = u'2014, Equinor ASA' # built documents. # # The short X.Y version. -version = '${LIBECL_VERSION_MAJOR}.${LIBECL_VERSION_MINOR}' +version = '${LIBRD_VERSION_MAJOR}.${LIBRD_VERSION_MINOR}' # The full version, including alpha/beta/rc tags. -release = '${LIBECL_VERSION_MAJOR}.${LIBECL_VERSION_MINOR}.${LIBECL_VERSION_MICRO}' +release = '${LIBRD_VERSION_MAJOR}.${LIBRD_VERSION_MINOR}.${LIBRD_VERSION_MICRO}' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -180,7 +180,7 @@ html_static_path = ['_static'] #html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'libecldoc' +htmlhelp_basename = 'resdatadoc' # -- Options for LaTeX output --------------------------------------------- @@ -200,7 +200,7 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'libecl.tex', u'libecl documentation', + ('index', 'resdata.tex', u'resdata documentation', u'Equinor ASA', 'manual'), ] @@ -230,7 +230,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'libecl', u'libecl documentation', + ('index', 'resdata', u'resdata documentation', [u'Equinor ASA'], 1) ] @@ -244,7 +244,7 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'libecl', u'libecl ocumentation', + ('index', 'resdata', u'resdata ocumentation', u'Equinor ASA', 'ert', 'One line description of project.', 'Miscellaneous'), ] diff --git a/python/docs/examples/avg_pressure.py b/python/docs/examples/avg_pressure.py index 1e45c1248e..7a0131dff4 100755 --- a/python/docs/examples/avg_pressure.py +++ b/python/docs/examples/avg_pressure.py @@ -1,10 +1,9 @@ #!/usr/bin/env python import sys -import matplotlib.pyplot as plt -# Import the required symbols from the ecl.ecl package. -from ecl.eclfile import EclFile, EclRestartFile -from ecl.grid import EclGrid, EclRegion +import matplotlib.pyplot as plt +from resdata.grid import Grid, ResdataRegion +from resdata.resfile import ResdataFile, ResdataRestartFile # Calculate the average pressure for all the cells in the region using @@ -46,9 +45,9 @@ def avg_pressure(p, sw, pv, region, region_id, result): if __name__ == "__main__": case = sys.argv[1] - grid = EclGrid("%s.EGRID" % case) - rst_file = EclRestartFile(grid, "%s.UNRST" % case) - init_file = EclFile("%s.INIT" % case) + grid = Grid("%s.EGRID" % case) + rst_file = ResdataRestartFile(grid, "%s.UNRST" % case) + init_file = ResdataFile("%s.INIT" % case) # Create PORV keyword where all the inactive cells have been removed. pv = grid.compressed_kw_copy(init_file["PORV"][0]) @@ -65,11 +64,11 @@ def avg_pressure(p, sw, pv, region, region_id, result): sw = rst_block["SWAT"][0] for region_id in range(region_kw.get_max() + 1): - region = EclRegion(grid, False) + region = ResdataRegion(grid, False) region.select_equal(region_kw, region_id) avg_pressure(p, sw, pv, region, region_id, result) - avg_pressure(p, sw, pv, EclRegion(grid, True), "field", result) + avg_pressure(p, sw, pv, ResdataRegion(grid, True), "field", result) sim_days.append(header.get_sim_days()) for key in result.keys(): diff --git a/python/docs/examples/cmp_nnc.py b/python/docs/examples/cmp_nnc.py index 098c553baa..4ca50e36fd 100755 --- a/python/docs/examples/cmp_nnc.py +++ b/python/docs/examples/cmp_nnc.py @@ -1,15 +1,15 @@ #!/usr/bin/env python import sys from operator import itemgetter -from ecl.eclfile import EclFile -from ecl.grid import EclGrid +from resdata.resfile import ResdataFile +from resdata.grid import Grid if __name__ == "__main__": case = sys.argv[1] - grid_file = EclFile(f"{case}.EGRID") - init_file = EclFile(f"{case}.INIT") - grid = EclGrid(f"{case}.EGRID") + grid_file = ResdataFile(f"{case}.EGRID") + init_file = ResdataFile(f"{case}.INIT") + grid = Grid(f"{case}.EGRID") nnc1 = grid_file["NNC1"][0] nnc2 = grid_file["NNC2"][0] diff --git a/python/docs/examples/grid_info.py b/python/docs/examples/grid_info.py index b569b18255..7e442412e4 100755 --- a/python/docs/examples/grid_info.py +++ b/python/docs/examples/grid_info.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import sys -from ecl.grid import EclRegion, EclGrid +from resdata.grid import ResdataRegion, Grid def volume_min_max(grid): @@ -12,7 +12,7 @@ def main(grid): vmin, vmax = volume_min_max(grid) dz_limit = 0.3 - region = EclRegion(grid, False) + region = ResdataRegion(grid, False) region.select_thin(dz_limit) print(f"Smallest cell : {vmin}") @@ -28,5 +28,5 @@ def main(grid): if len(sys.argv) < 2: exit("usage: grid_info.py path/to/file.EGRID") case = sys.argv[1] - grid = EclGrid(case) + grid = Grid(case) main(grid) diff --git a/python/ecl/ecl_lib_info_build.py.in b/python/ecl/ecl_lib_info_build.py.in deleted file mode 100644 index 7f80c68807..0000000000 --- a/python/ecl/ecl_lib_info_build.py.in +++ /dev/null @@ -1,9 +0,0 @@ - - -class EclLibInfo(object): - lib_path = "${LIBRARY_OUTPUT_PATH}" - so_version = "${ECL_BINARY_POSTFIX}" - __version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" - - def __init__(self): - pass diff --git a/python/ecl/ecl_lib_info_install.py.in b/python/ecl/ecl_lib_info_install.py.in deleted file mode 100644 index 12c6c69375..0000000000 --- a/python/ecl/ecl_lib_info_install.py.in +++ /dev/null @@ -1,9 +0,0 @@ - - -class EclLibInfo(object): - lib_path = "../../../../${CMAKE_INSTALL_LIBDIR}" - so_version = "${ECL_BINARY_POSTFIX}" - __version__ = "${ECL_VERSION_MAJOR}.${ECL_VERSION_MINOR}.${ECL_VERSION_MICRO}" - - def __init__(self): - pass diff --git a/python/ecl/ecl_type.py b/python/ecl/ecl_type.py deleted file mode 100644 index e978f58ae5..0000000000 --- a/python/ecl/ecl_type.py +++ /dev/null @@ -1,184 +0,0 @@ -from cwrap import BaseCClass, BaseCEnum -from ecl import EclPrototype - - -class EclTypeEnum(BaseCEnum): - TYPE_NAME = "ecl_type_enum" - ECL_CHAR_TYPE = None - ECL_FLOAT_TYPE = None - ECL_DOUBLE_TYPE = None - ECL_INT_TYPE = None - ECL_BOOL_TYPE = None - ECL_MESS_TYPE = None - ECL_STRING_TYPE = None - - -EclTypeEnum.addEnum("ECL_CHAR_TYPE", 0) -EclTypeEnum.addEnum("ECL_FLOAT_TYPE", 1) -EclTypeEnum.addEnum("ECL_DOUBLE_TYPE", 2) -EclTypeEnum.addEnum("ECL_INT_TYPE", 3) -EclTypeEnum.addEnum("ECL_BOOL_TYPE", 4) -EclTypeEnum.addEnum("ECL_MESS_TYPE", 5) -EclTypeEnum.addEnum("ECL_STRING_TYPE", 7) - -# ----------------------------------------------------------------- - - -class EclDataType(BaseCClass): - TYPE_NAME = "ecl_data_type" - - _alloc = EclPrototype( - "void* ecl_type_alloc_python(ecl_type_enum, size_t)", bind=False - ) - _alloc_from_type = EclPrototype( - "void* ecl_type_alloc_from_type_python(ecl_type_enum)", bind=False - ) - _alloc_from_name = EclPrototype( - "void* ecl_type_alloc_from_name_python(char*)", bind=False - ) - _free = EclPrototype("void ecl_type_free_python(ecl_data_type)") - _get_type = EclPrototype("ecl_type_enum ecl_type_get_type_python(ecl_data_type)") - _get_element_size = EclPrototype( - "size_t ecl_type_get_sizeof_iotype_python(ecl_data_type)" - ) - _is_int = EclPrototype("bool ecl_type_is_int_python(ecl_data_type)") - _is_char = EclPrototype("bool ecl_type_is_char_python(ecl_data_type)") - _is_float = EclPrototype("bool ecl_type_is_float_python(ecl_data_type)") - _is_double = EclPrototype("bool ecl_type_is_double_python(ecl_data_type)") - _is_mess = EclPrototype("bool ecl_type_is_mess_python(ecl_data_type)") - _is_bool = EclPrototype("bool ecl_type_is_bool_python(ecl_data_type)") - _is_string = EclPrototype("bool ecl_type_is_string_python(ecl_data_type)") - _get_name = EclPrototype("char* ecl_type_alloc_name_python(ecl_data_type)") - _is_numeric = EclPrototype("bool ecl_type_is_numeric_python(ecl_data_type)") - _is_equal = EclPrototype( - "bool ecl_type_is_equal_python(ecl_data_type, ecl_data_type)" - ) - - def __init__(self, type_enum=None, element_size=None, type_name=None): - self._assert_valid_arguments(type_enum, element_size, type_name) - - if type_name: - c_ptr = self._alloc_from_name(type_name) - elif element_size is None: - c_ptr = self._alloc_from_type(type_enum) - else: - c_ptr = self._alloc(type_enum, element_size) - - super(EclDataType, self).__init__(c_ptr) - - def _assert_valid_arguments(self, type_enum, element_size, type_name): - if type_name is not None: - if type_enum is not None or element_size is not None: - err_msg = ( - "Type name given (%s). Expected both " - + "type_enum and element_size to be None" - ) - raise ValueError(err_msg % type_name) - - elif type_enum is None: - raise ValueError("Both type_enum and type_name is None!") - - elif type_enum == EclTypeEnum.ECL_STRING_TYPE: - if element_size is None: - raise ValueError( - "When creating an ECL_STRING one must " + "provide an element size!" - ) - - if not (0 <= element_size <= 999): - raise ValueError( - "Expected element_size to be in the range " - + "[0, 999], was: %d" % element_size - ) - - @property - def type(self): - return self._get_type() - - @property - def element_size(self): - return self._get_element_size() - - @property - def type_name(self): - return self._get_name() - - def free(self): - self._free() - - def is_int(self): - return self._is_int() - - def is_char(self): - return self._is_char() - - def is_float(self): - return self._is_float() - - def is_double(self): - return self._is_double() - - def is_mess(self): - return self._is_mess() - - def is_bool(self): - return self._is_bool() - - def is_string(self): - return self._is_string() - - def is_numeric(self): - return self._is_numeric() - - def is_equal(self, other): - return self._is_equal(other) - - def __eq__(self, other): - if isinstance(other, self.__class__): - return self.is_equal(other) - return False - - def __ne__(self, other): - return not self.__eq__(other) - - def __hash__(self): - return hash((self.type, self.element_size)) - - @classmethod - def create_from_type_name(cls, name): - return EclDataType(type_name=name) - - # Enables one to fetch a type as EclDataType.ECL_XXXX - class classproperty(object): - def __init__(self, fget): - self.fget = fget - - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls) - - @classproperty - def ECL_INT(cls): - return EclDataType(EclTypeEnum.ECL_INT_TYPE) - - @classproperty - def ECL_FLOAT(cls): - return EclDataType(EclTypeEnum.ECL_FLOAT_TYPE) - - @classproperty - def ECL_DOUBLE(cls): - return EclDataType(EclTypeEnum.ECL_DOUBLE_TYPE) - - @classproperty - def ECL_BOOL(cls): - return EclDataType(EclTypeEnum.ECL_BOOL_TYPE) - - @classproperty - def ECL_MESS(cls): - return EclDataType(EclTypeEnum.ECL_MESS_TYPE) - - @classproperty - def ECL_CHAR(cls): - return EclDataType(EclTypeEnum.ECL_CHAR_TYPE) - - @classmethod - def ECL_STRING(cls, elem_size): - return EclDataType(EclTypeEnum.ECL_STRING_TYPE, elem_size) diff --git a/python/ecl/ecl_util.py b/python/ecl/ecl_util.py deleted file mode 100644 index cd018d5fa6..0000000000 --- a/python/ecl/ecl_util.py +++ /dev/null @@ -1,164 +0,0 @@ -""" -Constants from the header ecl_util.h - some stateless functions. - -This module does not contain any class definitions; it mostly consists -of enum definitions/values from ecl_util.h; the enum values are -extracted from the shared library in a semi-automagic manner using the -BaseCEnum class from cwrap. - -In addition to the enum definitions there are a few stateless -functions from ecl_util.c which are not bound to any class type. -""" -from __future__ import absolute_import -import ctypes - -from cwrap import BaseCEnum -from ecl.util.util import monkey_the_camel -from ecl import EclPrototype - - -class EclFileEnum(BaseCEnum): - TYPE_NAME = "ecl_file_enum" - ECL_OTHER_FILE = None - ECL_RESTART_FILE = None - ECL_UNIFIED_RESTART_FILE = None - ECL_SUMMARY_FILE = None - ECL_UNIFIED_SUMMARY_FILE = None - ECL_GRID_FILE = None - ECL_EGRID_FILE = None - ECL_INIT_FILE = None - ECL_RFT_FILE = None - ECL_DATA_FILE = None - - -EclFileEnum.addEnum("ECL_OTHER_FILE", 0) -EclFileEnum.addEnum("ECL_RESTART_FILE", 1) -EclFileEnum.addEnum("ECL_UNIFIED_RESTART_FILE", 2) -EclFileEnum.addEnum("ECL_SUMMARY_FILE", 4) -EclFileEnum.addEnum("ECL_UNIFIED_SUMMARY_FILE", 8) -EclFileEnum.addEnum("ECL_SUMMARY_HEADER_FILE", 16) -EclFileEnum.addEnum("ECL_GRID_FILE", 32) -EclFileEnum.addEnum("ECL_EGRID_FILE", 64) -EclFileEnum.addEnum("ECL_INIT_FILE", 128) -EclFileEnum.addEnum("ECL_RFT_FILE", 256) -EclFileEnum.addEnum("ECL_DATA_FILE", 512) - - -# ----------------------------------------------------------------- - - -class EclPhaseEnum(BaseCEnum): - TYPE_NAME = "ecl_phase_enum" - ECL_OIL_PHASE = None - ECL_GAS_PHASE = None - ECL_WATER_PHASE = None - - -EclPhaseEnum.addEnum("ECL_OIL_PHASE", 1) -EclPhaseEnum.addEnum("ECL_GAS_PHASE", 2) -EclPhaseEnum.addEnum("ECL_WATER_PHASE", 4) - - -# ----------------------------------------------------------------- - - -class EclUnitTypeEnum(BaseCEnum): - TYPE_NAME = "ecl_unit_enum" - - ECL_METRIC_UNITS = None - ECL_FIELD_UNITS = None - ECL_LAB_UNITS = None - ECL_PVT_M_UNITS = None - - -EclUnitTypeEnum.addEnum("ECL_METRIC_UNITS", 1) -EclUnitTypeEnum.addEnum("ECL_FIELD_UNITS", 2) -EclUnitTypeEnum.addEnum("ECL_LAB_UNITS", 3) -EclUnitTypeEnum.addEnum("ECL_PVT_M_UNITS", 4) - - -# ----------------------------------------------------------------- - - -class EclFileFlagEnum(BaseCEnum): - TYPE_NAME = "ecl_file_flag_enum" - ECL_FILE_DEFAULT = None - ECL_FILE_CLOSE_STREAM = None - ECL_FILE_WRITABLE = None - - -EclFileFlagEnum.addEnum("ECL_FILE_DEFAULT", 0) -EclFileFlagEnum.addEnum("ECL_FILE_CLOSE_STREAM", 1) -EclFileFlagEnum.addEnum("ECL_FILE_WRITABLE", 2) - - -# ----------------------------------------------------------------- - - -class EclUtil(object): - _get_num_cpu = EclPrototype("int ecl_util_get_num_cpu(char*)", bind=False) - _get_file_type = EclPrototype( - "ecl_file_enum ecl_util_get_file_type(char*, bool*, int*)", bind=False - ) - _get_start_date = EclPrototype("time_t ecl_util_get_start_date(char*)", bind=False) - _get_report_step = EclPrototype( - "int ecl_util_filename_report_nr(char*)", bind=False - ) - - @staticmethod - def get_num_cpu(datafile): - """ - Parse ECLIPSE datafile and determine how many CPUs are needed. - - Will look for the "PARALLELL" keyword, and then read off the - number of CPUs required. Will return one if no PARALLELL keyword - is found. - """ - return EclUtil._get_num_cpu(datafile) - - @staticmethod - def get_file_type(filename): - """ - Will inspect an ECLIPSE filename and return an integer type flag. - """ - file_type, fmt, step = EclUtil.inspectExtension(filename) - return file_type - - @staticmethod - def get_start_date(datafile): - return EclUtil._get_start_date(datafile).datetime() - - @staticmethod - def inspect_extension(filename): - """Will inspect an ECLIPSE filename and return a tuple consisting of - file type (EclFileEnum), a bool for formatted or not, and an - integer for the step number. - - """ - fmt_file = ctypes.c_bool() - report_step = ctypes.c_int(-1) - file_type = EclUtil._get_file_type( - filename, ctypes.byref(fmt_file), ctypes.byref(report_step) - ) - if report_step.value == -1: - step = None - else: - step = report_step.value - - return (file_type, fmt_file.value, step) - - @staticmethod - def report_step(filename): - report_step = EclUtil._get_report_step(filename) - if report_step < 0: - raise ValueError("Could not infer report step from: %s" % filename) - - return report_step - - -get_num_cpu = EclUtil.get_num_cpu -get_file_type = EclUtil.get_file_type -get_start_date = EclUtil.get_start_date - -monkey_the_camel(EclUtil, "inspectExtension", EclUtil.inspect_extension, staticmethod) -monkey_the_camel(EclUtil, "reportStep", EclUtil.report_step, staticmethod) diff --git a/python/ecl/eclfile/__init__.py b/python/ecl/eclfile/__init__.py deleted file mode 100644 index ee2ea9f7a4..0000000000 --- a/python/ecl/eclfile/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -The eclfile package contains several classes for working directly with ECLIPSE -files. - - fortio/FortIO: This is functionality to read and write binary - fortran files. - - ecl_kw/EclKW: This class holds one ECLIPSE keyword, like SWAT, in - restart format. - - ecl_type/EclDataType: This class is used to represent the data type - of the elements in EclKW. - - ecl_file/EclFile: This class is used to load an ECLIPSE file in - restart format, alternatively only parts of the file can be - loaded. Internally it consists of a collection of EclKW - instances. -""" - -import ecl.util.util - -from .fortio import FortIO, openFortIO -from .ecl_kw import EclKW -from .ecl_file_view import EclFileView -from .ecl_file import EclFile, openEclFile -from .ecl_3dkw import Ecl3DKW -from .ecl_3d_file import Ecl3DFile -from .ecl_init_file import EclInitFile -from .ecl_restart_file import EclRestartFile diff --git a/python/ecl/eclfile/ecl_init_file.py b/python/ecl/eclfile/ecl_init_file.py deleted file mode 100644 index 723ec1fc04..0000000000 --- a/python/ecl/eclfile/ecl_init_file.py +++ /dev/null @@ -1,15 +0,0 @@ -from ecl import EclFileEnum, EclFileFlagEnum -from ecl.eclfile import Ecl3DFile, EclFile - -ECL_FILE_DEFAULT = EclFileFlagEnum.ECL_FILE_DEFAULT - - -class EclInitFile(Ecl3DFile): - def __init__(self, grid, filename, flags=ECL_FILE_DEFAULT): - file_type, report_step, fmt_file = EclFile.getFileType(filename) - if file_type == EclFileEnum.ECL_INIT_FILE: - super(EclInitFile, self).__init__(grid, filename, flags) - else: - err = 'The input filename "%s" does not correspond to an init file.' - err += " Please follow the Eclipse naming conventions." - raise ValueError(err % filename) diff --git a/python/ecl/gravimetry/__init__.py b/python/ecl/gravimetry/__init__.py deleted file mode 100644 index e7532f14d7..0000000000 --- a/python/ecl/gravimetry/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -""" - ecl_grav/EclGrav: Class used to simplify evaluation of ECLIPSE - modelling time-lapse gravitational surveys. - - ecl_subsidence/EclSubsidence: Small class used to evaluate simulated - subsidence from ECLIPSE simulations; analogous to the EcLGrav - functionality. -""" - -from .ecl_grav import EclGrav -from .ecl_subsidence import EclSubsidence diff --git a/python/ecl/grid/__init__.py b/python/ecl/grid/__init__.py deleted file mode 100644 index 81e294a659..0000000000 --- a/python/ecl/grid/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -""" - ecl_grid/EclGrid: This will load an ECLIPSE GRID or EGRID file, and - can then subsequently be used for queries about the grid. - - ecl_region/EclRegion: Convenience class to support selecting cells - in a grid based on a wide range of criteria. Can be used as a - mask in operations on EclKW instances. - - ecl_grid_generator/EclGridGenerator: This can be used to generate various - grids. -""" - -import ecl.util.util -import ecl.util.geometry - -from .cell import Cell -from .ecl_grid import EclGrid -from .ecl_region import EclRegion -from .ecl_grid_generator import EclGridGenerator diff --git a/python/ecl/rft/__init__.py b/python/ecl/rft/__init__.py deleted file mode 100644 index d68d815af1..0000000000 --- a/python/ecl/rft/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -""" - ecl_rft/[EclRFTFile , EclRFT , EclRFTCell]: Loads an ECLIPSE RFT/PLT - file, and can afterwords be used to support various queries. -""" - -from .well_trajectory import WellTrajectory -from .ecl_rft_cell import EclPLTCell, EclRFTCell -from .ecl_rft import EclRFT, EclRFTFile diff --git a/python/ecl/summary/__init__.py b/python/ecl/summary/__init__.py deleted file mode 100644 index 064ac29c9e..0000000000 --- a/python/ecl/summary/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -""" - ecl_sum/EclSum: This will load summary results from an ECLIPSE run; - both data file(s) and the SMSPEC file. The EclSum object can be - used as basis for queries on summary vectors. -""" - - -import ecl.util.util -import ecl.util.geometry - -from .ecl_sum_var_type import EclSumVarType -from .ecl_sum_tstep import EclSumTStep -from .ecl_sum import EclSum # , EclSumVector, EclSumNode, EclSMSPECNode -from .ecl_sum_keyword_vector import EclSumKeyWordVector -from .ecl_sum_node import EclSumNode -from .ecl_sum_vector import EclSumVector -from .ecl_npv import EclNPV, NPVPriceVector -from .ecl_cmp import EclCmp diff --git a/python/ecl/summary/ecl_sum_keyword_vector.py b/python/ecl/summary/ecl_sum_keyword_vector.py deleted file mode 100644 index e8de2c09d7..0000000000 --- a/python/ecl/summary/ecl_sum_keyword_vector.py +++ /dev/null @@ -1,61 +0,0 @@ -import numpy -import datetime - -# Observe that there is some convention conflict with the C code -# regarding order of arguments: The C code generally takes the time -# index as the first argument and the key/key_index as second -# argument. In the python code this order has been reversed. - -from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl import EclPrototype - - -class EclSumKeyWordVector(BaseCClass): - TYPE_NAME = "ecl_sum_vector" - _alloc = EclPrototype("void* ecl_sum_vector_alloc(ecl_sum, bool)", bind=False) - _alloc_copy = EclPrototype( - "ecl_sum_vector_obj ecl_sum_vector_alloc_layout_copy(ecl_sum_vector, ecl_sum)" - ) - _free = EclPrototype("void ecl_sum_vector_free(ecl_sum_vector)") - _add = EclPrototype("bool ecl_sum_vector_add_key(ecl_sum_vector, char*)") - _add_multiple = EclPrototype("void ecl_sum_vector_add_keys(ecl_sum_vector, char*)") - _get_size = EclPrototype("int ecl_sum_vector_get_size(ecl_sum_vector)") - _iget_key = EclPrototype("char* ecl_sum_vector_iget_key(ecl_sum_vector, int)") - - def __init__(self, ecl_sum, add_keywords=False): - c_pointer = self._alloc(ecl_sum, add_keywords) - super(EclSumKeyWordVector, self).__init__(c_pointer) - - def __getitem__(self, index): - if index < 0: - index += len(self) - - if index >= len(self): - raise IndexError("Out of range") - - return self._iget_key(index) - - def __len__(self): - return self._get_size() - - def free(self): - self._free() - - def add_keyword(self, keyword): - success = self._add(keyword) - if not success: - raise KeyError("Failed to add keyword to vector") - - def add_keywords(self, keyword_pattern): - self._add_multiple(keyword_pattern) - - def __repr__(self): - return self._create_repr("len=%d" % len(self)) - - def copy(self, ecl_sum): - return self._alloc_copy(ecl_sum) - - -monkey_the_camel(EclSumKeyWordVector, "addKeyword", EclSumKeyWordVector.add_keyword) -monkey_the_camel(EclSumKeyWordVector, "addKeywords", EclSumKeyWordVector.add_keywords) diff --git a/python/ecl/summary/ecl_sum_var_type.py b/python/ecl/summary/ecl_sum_var_type.py deleted file mode 100644 index 5c38cbc0c3..0000000000 --- a/python/ecl/summary/ecl_sum_var_type.py +++ /dev/null @@ -1,37 +0,0 @@ -from cwrap import BaseCEnum - - -class EclSumVarType(BaseCEnum): - TYPE_NAME = "ecl_sum_var_type" - ECL_SMSPEC_INVALID_VAR = None - ECL_SMSPEC_FIELD_VAR = None - ECL_SMSPEC_REGION_VAR = None - ECL_SMSPEC_GROUP_VAR = None - ECL_SMSPEC_WELL_VAR = None - ECL_SMSPEC_SEGMENT_VAR = None - ECL_SMSPEC_BLOCK_VAR = None - ECL_SMSPEC_AQUIFER_VAR = None - ECL_SMSPEC_COMPLETION_VAR = None - ECL_SMSPEC_NETWORK_VAR = None - ECL_SMSPEC_REGION_2_REGION_VAR = None - ECL_SMSPEC_LOCAL_BLOCK_VAR = None - ECL_SMSPEC_LOCAL_COMPLETION_VAR = None - ECL_SMSPEC_LOCAL_WELL_VAR = None - ECL_SMSPEC_MISC_VAR = None - - -EclSumVarType.addEnum("ECL_SMSPEC_INVALID_VAR", 0) -EclSumVarType.addEnum("ECL_SMSPEC_FIELD_VAR", 1) -EclSumVarType.addEnum("ECL_SMSPEC_REGION_VAR", 2) -EclSumVarType.addEnum("ECL_SMSPEC_GROUP_VAR", 3) -EclSumVarType.addEnum("ECL_SMSPEC_WELL_VAR", 4) -EclSumVarType.addEnum("ECL_SMSPEC_SEGMENT_VAR", 5) -EclSumVarType.addEnum("ECL_SMSPEC_BLOCK_VAR", 6) -EclSumVarType.addEnum("ECL_SMSPEC_AQUIFER_VAR", 7) -EclSumVarType.addEnum("ECL_SMSPEC_COMPLETION_VAR", 8) -EclSumVarType.addEnum("ECL_SMSPEC_NETWORK_VAR", 9) -EclSumVarType.addEnum("ECL_SMSPEC_REGION_2_REGION_VAR", 10) -EclSumVarType.addEnum("ECL_SMSPEC_LOCAL_BLOCK_VAR", 11) -EclSumVarType.addEnum("ECL_SMSPEC_LOCAL_COMPLETION_VAR", 12) -EclSumVarType.addEnum("ECL_SMSPEC_LOCAL_WELL_VAR", 13) -EclSumVarType.addEnum("ECL_SMSPEC_MISC_VAR", 14) diff --git a/python/ecl/util/geometry/geo_pointset.py b/python/ecl/util/geometry/geo_pointset.py deleted file mode 100644 index cf41666cc1..0000000000 --- a/python/ecl/util/geometry/geo_pointset.py +++ /dev/null @@ -1,66 +0,0 @@ -from cwrap import BaseCClass -from ecl import EclPrototype - - -class GeoPointset(BaseCClass): - TYPE_NAME = "geo_pointset" - - _alloc = EclPrototype("void* geo_pointset_alloc(bool)", bind=False) - _free = EclPrototype("void geo_pointset_free(geo_pointset)") - # _add_xyz = EclPrototype("void geo_pointset_add_xyz(geo_pointset, double, double, double)") - _get_size = EclPrototype("int geo_pointset_get_size(geo_pointset)") - # _iget_xy = EclPrototype("void geo_pointset_iget_xy(geo_pointset, int, double*, double*)") - # _get_zcoord = EclPrototype("double* geo_pointset_get_zcoord(geo_pointset)") - _equal = EclPrototype("bool geo_pointset_equal(geo_pointset, geo_pointset)") - _iget_z = EclPrototype("double geo_pointset_iget_z(geo_pointset, int)") - # _iset_z = EclPrototype("void geo_pointset_iset_z(geo_pointset, int, double)") - # _memcpy = EclPrototype("void geo_pointset_memcpy(geo_pointset, geo_pointset, bool)") - # _shift_z = EclPrototype("void geo_pointset_shift_z(geo_pointset, double)") - # _assign_z = EclPrototype("void geo_pointset_assign_z(geo_pointset, double)") - # _scale_z = EclPrototype("void geo_pointset_scale_z(geo_pointset, double)") - # _imul = EclPrototype("void geo_pointset_imul(geo_pointset, geo_pointset)") - # _iadd = EclPrototype("void geo_pointset_iadd(geo_pointset, geo_pointset)") - # _isub = EclPrototype("void geo_pointset_isub(geo_pointset, geo_pointset)") - # _isqrt = EclPrototype("void geo_pointset_isqrt(geo_pointset)") - - def __init__(self, external_z=False): - c_ptr = self._alloc(external_z) - if c_ptr: - super(GeoPointset, self).__init__(c_ptr) - else: - ext = "external" if external_z else "internal" - raise ValueError("Failed to construct GeoPointset with %s_z." % ext) - - @staticmethod - def fromSurface(surface): - return surface.getPointset() - - def __eq__(self, other): - if isinstance(other, GeoPointset): - return self._equal(other) - return NotImplemented - - def __getitem__(self, key): - size = len(self) - if isinstance(key, int): - idx = key - if idx < 0: - idx += size - if 0 <= idx < size: - return self._iget_z(idx) - else: - raise IndexError( - "Invalid index, must be in [0, %d), was: %d." % (size, key) - ) - else: - # TODO implement slicing? - raise ValueError("Index must be int, not %s." % type(key)) - - def __len__(self): - return self._get_size() - - def __repr__(self): - return self._create_repr("len=%d" % len(self)) - - def free(self): - self._free() diff --git a/python/ecl/util/test/ecl_mock/__init__.py b/python/ecl/util/test/ecl_mock/__init__.py deleted file mode 100644 index eb49177fc0..0000000000 --- a/python/ecl/util/test/ecl_mock/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .ecl_sum_mock import createEclSum diff --git a/python/ecl/util/util/double_vector.py b/python/ecl/util/util/double_vector.py deleted file mode 100644 index 0d84597441..0000000000 --- a/python/ecl/util/util/double_vector.py +++ /dev/null @@ -1,95 +0,0 @@ -from ecl import EclPrototype -from ecl.util.util import VectorTemplate - - -class DoubleVector(VectorTemplate): - default_format = "%8.4f" - - _alloc = EclPrototype("void* double_vector_alloc( int , double )", bind=False) - _alloc_copy = EclPrototype( - "double_vector_obj double_vector_alloc_copy( double_vector )" - ) - _strided_copy = EclPrototype( - "double_vector_obj double_vector_alloc_strided_copy( double_vector , int , int , int)" - ) - _free = EclPrototype("void double_vector_free( double_vector )") - _iget = EclPrototype("double double_vector_iget( double_vector , int )") - _safe_iget = EclPrototype("double double_vector_safe_iget(double_vector , int )") - _iset = EclPrototype("double double_vector_iset( double_vector , int , double)") - _size = EclPrototype("int double_vector_size( double_vector )") - _append = EclPrototype("void double_vector_append( double_vector , double )") - _idel_block = EclPrototype( - "void double_vector_idel_block( double_vector , int , int )" - ) - _pop = EclPrototype("double double_vector_pop( double_vector )") - _idel = EclPrototype("void double_vector_idel( double_vector , int )") - _lshift = EclPrototype("void double_vector_lshift( double_vector , int )") - _rshift = EclPrototype("void double_vector_rshift( double_vector , int )") - _insert = EclPrototype("void double_vector_insert( double_vector , int , double)") - _fprintf = EclPrototype( - "void double_vector_fprintf( double_vector , FILE , char* , char*)" - ) - _sort = EclPrototype("void double_vector_sort( double_vector )") - _rsort = EclPrototype("void double_vector_rsort( double_vector )") - _reset = EclPrototype("void double_vector_reset( double_vector )") - _get_read_only = EclPrototype("bool double_vector_get_read_only( double_vector )") - _set_read_only = EclPrototype( - "void double_vector_set_read_only( double_vector , bool )" - ) - _get_max = EclPrototype("double double_vector_get_max( double_vector )") - _get_min = EclPrototype("double double_vector_get_min( double_vector )") - _get_max_index = EclPrototype( - "int double_vector_get_max_index( double_vector , bool)" - ) - _get_min_index = EclPrototype( - "int double_vector_get_min_index( double_vector , bool)" - ) - _shift = EclPrototype("void double_vector_shift( double_vector , double )") - _scale = EclPrototype("void double_vector_scale( double_vector , double )") - _div = EclPrototype("void double_vector_div( double_vector , double )") - _inplace_add = EclPrototype( - "void double_vector_inplace_add( double_vector , double_vector )" - ) - _inplace_mul = EclPrototype( - "void double_vector_inplace_mul( double_vector , double_vector )" - ) - _assign = EclPrototype("void double_vector_set_all( double_vector , double)") - _memcpy = EclPrototype( - "void double_vector_memcpy(double_vector , double_vector )" - ) - _set_default = EclPrototype( - "void double_vector_set_default( double_vector , double)" - ) - _get_default = EclPrototype("double double_vector_get_default( double_vector )") - _element_size = EclPrototype("int double_vector_element_size( double_vector )") - - _permute = EclPrototype( - "void double_vector_permute(double_vector, permutation_vector)" - ) - _sort_perm = EclPrototype( - "permutation_vector_obj double_vector_alloc_sort_perm(double_vector)" - ) - _rsort_perm = EclPrototype( - "permutation_vector_obj double_vector_alloc_rsort_perm(double_vector)" - ) - _contains = EclPrototype("bool double_vector_contains(double_vector, double)") - _select_unique = EclPrototype("void double_vector_select_unique(double_vector)") - _element_sum = EclPrototype("double double_vector_sum(double_vector)") - _get_data_ptr = EclPrototype("double* double_vector_get_ptr(double_vector)") - _count_equal = EclPrototype("int double_vector_count_equal(double_vector, double)") - _init_range = EclPrototype( - "void double_vector_init_range(double_vector, double , double , double)" - ) - _init_linear = EclPrototype( - "bool double_vector_init_linear(double_vector, double, double, int)" - ) - _equal = EclPrototype("bool double_vector_equal(double_vector, double_vector)") - _first_eq = EclPrototype( - "int double_vector_first_equal(double_vector, double_vector, int)" - ) - _first_neq = EclPrototype( - "int double_vector_first_not_equal(double_vector, double_vector, int)" - ) - - def __init__(self, default_value=0, initial_size=0): - super(DoubleVector, self).__init__(default_value, initial_size) diff --git a/python/ecl/util/util/install_abort_signals.py b/python/ecl/util/util/install_abort_signals.py deleted file mode 100644 index b71effd737..0000000000 --- a/python/ecl/util/util/install_abort_signals.py +++ /dev/null @@ -1,18 +0,0 @@ -from ecl import EclPrototype -import sys -import os - - -def installAbortSignals(): - if sys.version_info.major < 3 and not os.getenv("ECL_SKIP_SIGNAL"): - install_signals = EclPrototype("void util_install_signals()") - install_signals() - - -def updateAbortSignals(): - """ - Will install the util_abort_signal for all UNMODIFIED signals. - """ - if sys.version_info.major < 3 and not os.getenv("ECL_SKIP_SIGNAL"): - update_signals = EclPrototype("void util_update_signals()") - update_signals() diff --git a/python/ecl/util/util/int_vector.py b/python/ecl/util/util/int_vector.py deleted file mode 100644 index 62b453ccec..0000000000 --- a/python/ecl/util/util/int_vector.py +++ /dev/null @@ -1,120 +0,0 @@ -from ecl import EclPrototype -from ecl.util.util import VectorTemplate - - -class IntVector(VectorTemplate): - default_format = "%d" - - _alloc = EclPrototype("void* int_vector_alloc( int , int )", bind=False) - _create_active_list = EclPrototype( - "int_vector_obj string_util_alloc_active_list( char*)", bind=False - ) - _create_value_list = EclPrototype( - "int_vector_obj string_util_alloc_value_list( char*)", bind=False - ) - _alloc_copy = EclPrototype("int_vector_obj int_vector_alloc_copy( int_vector )") - _strided_copy = EclPrototype( - "int_vector_obj int_vector_alloc_strided_copy( int_vector , int , int , int)" - ) - _free = EclPrototype("void int_vector_free( int_vector )") - _iget = EclPrototype("int int_vector_iget( int_vector , int )") - _safe_iget = EclPrototype("int int_vector_safe_iget( int_vector , int )") - _iset = EclPrototype("int int_vector_iset( int_vector , int , int)") - _size = EclPrototype("int int_vector_size( int_vector )") - _append = EclPrototype("void int_vector_append( int_vector , int )") - _idel_block = EclPrototype("void int_vector_idel_block( int_vector , int , int )") - _pop = EclPrototype("int int_vector_pop( int_vector )") - _idel = EclPrototype("void int_vector_idel( int_vector , int )") - _insert = EclPrototype("void int_vector_insert( int_vector , int , int)") - _lshift = EclPrototype("void int_vector_lshift( int_vector , int )") - _rshift = EclPrototype("void int_vector_rshift( int_vector , int )") - _fprintf = EclPrototype( - "void int_vector_fprintf( int_vector , FILE , char* , char*)" - ) - _sort = EclPrototype("void int_vector_sort( int_vector )") - _rsort = EclPrototype("void int_vector_rsort( int_vector )") - _reset = EclPrototype("void int_vector_reset( int_vector )") - _set_read_only = EclPrototype( - "void int_vector_set_read_only( int_vector , bool )" - ) - _get_read_only = EclPrototype("bool int_vector_get_read_only( int_vector )") - _get_max = EclPrototype("int int_vector_get_max( int_vector )") - _get_min = EclPrototype("int int_vector_get_min( int_vector )") - _get_max_index = EclPrototype("int int_vector_get_max_index( int_vector , bool)") - _get_min_index = EclPrototype("int int_vector_get_min_index( int_vector , bool)") - _shift = EclPrototype("void int_vector_shift( int_vector , int )") - _scale = EclPrototype("void int_vector_scale( int_vector , int )") - _div = EclPrototype("void int_vector_div( int_vector , int )") - _inplace_add = EclPrototype( - "void int_vector_inplace_add( int_vector , int_vector )" - ) - _inplace_mul = EclPrototype( - "void int_vector_inplace_mul( int_vector , int_vector )" - ) - _assign = EclPrototype("void int_vector_set_all( int_vector , int)") - _memcpy = EclPrototype("void int_vector_memcpy(int_vector , int_vector )") - _set_default = EclPrototype("void int_vector_set_default( int_vector , int)") - _get_default = EclPrototype("int int_vector_get_default( int_vector )") - _element_size = EclPrototype("int int_vector_element_size( int_vector )") - - _permute = EclPrototype("void int_vector_permute(int_vector, permutation_vector)") - _sort_perm = EclPrototype( - "permutation_vector_obj int_vector_alloc_sort_perm(int_vector)" - ) - _rsort_perm = EclPrototype( - "permutation_vector_obj int_vector_alloc_rsort_perm(int_vector)" - ) - _contains = EclPrototype("bool int_vector_contains(int_vector, int)") - _select_unique = EclPrototype("void int_vector_select_unique(int_vector)") - _element_sum = EclPrototype("int int_vector_sum(int_vector)") - _get_data_ptr = EclPrototype("int* int_vector_get_ptr(int_vector)") - _count_equal = EclPrototype("int int_vector_count_equal(int_vector, int)") - _init_range = EclPrototype( - "void int_vector_init_range(int_vector, int , int , int)" - ) - _init_linear = EclPrototype( - "bool int_vector_init_linear(int_vector, int, int, int)" - ) - _equal = EclPrototype("bool int_vector_equal(int_vector, int_vector)") - _first_eq = EclPrototype("int int_vector_first_equal(int_vector, int_vector, int)") - _first_neq = EclPrototype( - "int int_vector_first_not_equal(int_vector, int_vector, int)" - ) - - def __init__(self, default_value=0, initial_size=0): - super(IntVector, self).__init__(default_value, initial_size) - - @classmethod - def active_list(cls, range_string): - """Will create a IntVector instance with the values from @range_string. - - The range_string input should be of the type "1,3-5,9,17", - i.e. integer values separated by commas, and dashes to - represent ranges. If the input string contains ANY invalid - characters the returned active list will be empty: - - "1,4-7,10" => {1,4,5,6,7,10} - "1,4-7,10X" => {} - - The empty list will evaluate to false. The values in the input - string are meant to indicate "active values", i.e. the output - values are sorted and repeated values are only counted once: - - "1,1,7,2" => {1,2,7} - - """ - return cls._create_active_list(range_string) - - @classmethod - def valueList(cls, range_string): - """Will create a IntVecter of all the values in the @range_string. - - Will not sort the values, and not uniquiefy - in contrast to - the active_list() method. - - """ - return cls._create_value_list(range_string) - - def count(self, value): - """@rtype: int""" - return self._count_equal(value) diff --git a/python/ecl/well/well_connection_direction_enum.py b/python/ecl/well/well_connection_direction_enum.py deleted file mode 100644 index a51df8f345..0000000000 --- a/python/ecl/well/well_connection_direction_enum.py +++ /dev/null @@ -1,17 +0,0 @@ -from cwrap import BaseCEnum - - -class WellConnectionDirectionEnum(BaseCEnum): - TYPE_NAME = "well_connection_dir_enum" - well_conn_dirX = None - well_conn_dirY = None - well_conn_dirZ = None - well_conn_fracX = None - well_conn_fracY = None - - -WellConnectionDirectionEnum.addEnum("well_conn_dirX", 1) -WellConnectionDirectionEnum.addEnum("well_conn_dirY", 2) -WellConnectionDirectionEnum.addEnum("well_conn_dirZ", 3) -WellConnectionDirectionEnum.addEnum("well_conn_fracX", 4) -WellConnectionDirectionEnum.addEnum("well_conn_fracY", 5) diff --git a/python/ecl/well/well_type_enum.py b/python/ecl/well/well_type_enum.py deleted file mode 100644 index adfc807ebb..0000000000 --- a/python/ecl/well/well_type_enum.py +++ /dev/null @@ -1,17 +0,0 @@ -from cwrap import BaseCEnum - - -class WellTypeEnum(BaseCEnum): - TYPE_NAME = "well_type_enum" - ECL_WELL_ZERO = None - ECL_WELL_PRODUCER = None - ECL_WELL_WATER_INJECTOR = None - ECL_WELL_GAS_INJECTOR = None - ECL_WELL_OIL_INJECTOR = None - - -WellTypeEnum.addEnum("ECL_WELL_ZERO", 0) -WellTypeEnum.addEnum("ECL_WELL_PRODUCER", 1) -WellTypeEnum.addEnum("ECL_WELL_OIL_INJECTOR", 2) -WellTypeEnum.addEnum("ECL_WELL_WATER_INJECTOR", 3) -WellTypeEnum.addEnum("ECL_WELL_GAS_INJECTOR", 4) diff --git a/python/ecl/__init__.py b/python/resdata/__init__.py similarity index 62% rename from python/ecl/__init__.py rename to python/resdata/__init__.py index 52a002218e..a78fe8d2c8 100644 --- a/python/ecl/__init__.py +++ b/python/resdata/__init__.py @@ -1,14 +1,5 @@ """ -ert - Ensemble Reservoir Tool - a package for reservoir modeling. - -The ert package itself has no code, but contains several subpackages: - -ecl.ecl: Package for working with ECLIPSE files. The far most mature - package in ert. - -ecl.util: - -The ert package is based on wrapping the libriaries from the ERT C +The resdata package is based on wrapping the libriaries from the C code with ctypes; an essential part of ctypes approach is to load the shared libraries with the ctypes.CDLL() function. The ctypes.CDLL() function uses the standard methods of the operating system, @@ -19,59 +10,58 @@ Python code should be able to locate the shared libraries without (necessarily) using the LD_LIBRARY_PATH variable. The default behaviour is to try to load from the library ../../lib64, but by using -the enviornment variable ERT_LIBRARY_PATH you can alter how ert looks +the enviornment variable RESDATA_LIBRARY_PATH you can alter how ert looks for shared libraries. 1. By default the code will try to load the shared libraries from '../../lib64' relative to the location of this file. - 2. Depending on the value of ERT_LIBRARY_PATH two different + 2. Depending on the value of RESDATA_LIBRARY_PATH two different behaviours can be imposed: Existing path: the package will look in the path pointed to - by ERT_LIBRARY_PATH for shared libraries. + by RESDATA_LIBRARY_PATH for shared libraries. Arbitrary value: the package will use standard load order for the operating system. -If the fixed path, given by the default ../../lib64 or ERT_LIBRARY_PATH +If the fixed path, given by the default ../../lib64 or RESDATA_LIBRARY_PATH alternative fails, the loader will try the default load behaviour before giving up completely. """ +import ctypes as ct import os.path import sys -import ctypes as ct - import warnings warnings.filterwarnings( action="always", category=DeprecationWarning, - module=r"ecl|ert", + module="resdata", ) from cwrap import Prototype -ECL_LEGACY_INSTALLED = not os.path.isdir( +RD_LEGACY_INSTALLED = not os.path.isdir( os.path.join(os.path.dirname(__file__), ".libs") ) -if not ECL_LEGACY_INSTALLED: +if not RD_LEGACY_INSTALLED: from .version import version as __version__ def get_include(): return os.path.join(os.path.dirname(__file__), ".include") - def dlopen_libecl(): + def dlopen_resdata(): import ctypes import platform path = os.path.join(os.path.dirname(__file__), ".libs") if platform.system() == "Linux": - path = os.path.join(path, "libecl.so") + path = os.path.join(path, "libresdata.so") elif platform.system() == "Darwin": - path = os.path.join(path, "libecl.dylib") + path = os.path.join(path, "libresdata.dylib") elif platform.system() == "Windows": - path = os.path.join(os.path.dirname(__file__), ".bin", "libecl.dll") + path = os.path.join(os.path.dirname(__file__), ".bin", "libresdata.dll") else: raise NotImplementedError("Invalid platform") @@ -101,13 +91,15 @@ def set_abort_handler(function): global _abort_handler _abort_handler = function - EclPrototype.lib.util_set_abort_handler(_c_abort_handler) + ResdataPrototype.lib.util_set_abort_handler(_c_abort_handler) - class EclPrototype(Prototype): - lib = dlopen_libecl() + class ResdataPrototype(Prototype): + lib = dlopen_resdata() def __init__(self, prototype, bind=True): - super(EclPrototype, self).__init__(EclPrototype.lib, prototype, bind=bind) + super(ResdataPrototype, self).__init__( + ResdataPrototype.lib, prototype, bind=bind + ) else: # @@ -122,84 +114,83 @@ def __init__(self, prototype, bind=True): required_version_hex = 0x02070000 - ecl_lib_path = None - ert_so_version = "" + resdata_path = None + resdata_so_version = "" __version__ = "0.0.0" - # 1. Try to load the __ecl_lib_info module; this module has been + # 1. Try to load the __resdata_info module; this module has been # configured by cmake during the build configuration process. The # module should contain the variable lib_path pointing to the # directory with shared object files. try: - from .__ecl_lib_info import EclLibInfo + from .__resdata_info import ResdataInfo - ecl_lib_path = EclLibInfo.lib_path - ert_so_version = EclLibInfo.so_version - __version__ = EclLibInfo.__version__ + resdata_path = ResdataInfo.lib_path + resdata_so_version = ResdataInfo.so_version + __version__ = ResdataInfo.__version__ except ImportError: pass except AttributeError: pass - # 2. Using the environment variable ERT_LIBRARY_PATH it is possible to - # override the default algorithms. If the ERT_LIBRARY_PATH is set + # 2. Using the environment variable RESDATA_LIBRARY_PATH it is possible to + # override the default algorithms. If the RESDATA_LIBRARY_PATH is set # to a non existing directory a warning will go to stderr and the # setting will be ignored. - env_lib_path = os.getenv("ERT_LIBRARY_PATH") + env_lib_path = os.getenv("RESDATA_LIBRARY_PATH") if env_lib_path: if os.path.isdir(env_lib_path): - ert_lib_path = os.getenv("ERT_LIBRARY_PATH") + ert_lib_path = os.getenv("RESDATA_LIBRARY_PATH") else: sys.stderr.write( - "Warning: Environment variable ERT_LIBRARY_PATH points to nonexisting directory:%s - ignored" + "Warning: Environment variable RESDATA_LIBRARY_PATH points to nonexisting directory:%s - ignored" % env_lib_path ) # Check that the final ert_lib_path setting corresponds to an existing # directory. - if ecl_lib_path: - if not os.path.isabs(ecl_lib_path): - ecl_lib_path = os.path.abspath( - os.path.join(os.path.dirname(__file__), ecl_lib_path) + if resdata_path: + if not os.path.isabs(resdata_path): + resdata_path = os.path.abspath( + os.path.join(os.path.dirname(__file__), resdata_path) ) - if not os.path.isdir(ecl_lib_path): - ecl_lib_path = None + if not os.path.isdir(resdata_path): + resdata_path = None if sys.hexversion < required_version_hex: raise Exception("ERT Python requires Python 2.7.") def load(name): try: - return cwrapload(name, path=ecl_lib_path, so_version=ert_so_version) + return cwrapload(name, path=resdata_path, so_version=resdata_so_version) except ImportError: # For pip installs, setup.py puts the shared lib in this directory own_dir = os.path.dirname(os.path.abspath(__file__)) - return cwrapload(name, path=own_dir, so_version=ert_so_version) + return cwrapload(name, path=own_dir, so_version=resdata_so_version) - class EclPrototype(Prototype): - lib = load("libecl") + class ResdataPrototype(Prototype): + lib = load("resdata") def __init__(self, prototype, bind=True): - super(EclPrototype, self).__init__(EclPrototype.lib, prototype, bind=bind) + super(ResdataPrototype, self).__init__( + ResdataPrototype.lib, prototype, bind=bind + ) # # Common # -from .ecl_type import EclTypeEnum, EclDataType -from .ecl_util import ( - EclFileEnum, - EclFileFlagEnum, - EclPhaseEnum, - EclUnitTypeEnum, - EclUtil, +from .rd_type import ResDataType, ResdataTypeEnum +from .rd_util import ( + FileType, + FileMode, + Phase, + UnitSystem, + ResdataUtil, ) - -from .util.util import EclVersion -from .util.util import updateAbortSignals - +from .util.util import ResdataVersion, updateAbortSignals updateAbortSignals() diff --git a/python/ecl/bin.py b/python/resdata/bin.py similarity index 100% rename from python/ecl/bin.py rename to python/resdata/bin.py diff --git a/python/ecl/util/geometry/__init__.py b/python/resdata/geometry/__init__.py similarity index 96% rename from python/ecl/util/geometry/__init__.py rename to python/resdata/geometry/__init__.py index 5ab3e170ba..83851e7d6e 100644 --- a/python/ecl/util/geometry/__init__.py +++ b/python/resdata/geometry/__init__.py @@ -2,7 +2,7 @@ Simple package for working with 2D geometry. """ -import ecl +import resdata from cwrap import Prototype from .geo_pointset import GeoPointset diff --git a/python/ecl/util/geometry/cpolyline.py b/python/resdata/geometry/cpolyline.py similarity index 85% rename from python/ecl/util/geometry/cpolyline.py rename to python/resdata/geometry/cpolyline.py index d77450d527..7806898074 100644 --- a/python/ecl/util/geometry/cpolyline.py +++ b/python/resdata/geometry/cpolyline.py @@ -5,35 +5,39 @@ import os.path from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype from .geometry_tools import GeometryTools class CPolyline(BaseCClass): TYPE_NAME = "geo_polygon" - _alloc_new = EclPrototype("void* geo_polygon_alloc( char* )", bind=False) - _fread_alloc_irap = EclPrototype( + _alloc_new = ResdataPrototype( + "void* geo_polygon_alloc( char* )", bind=False + ) + _fread_alloc_irap = ResdataPrototype( "geo_polygon_obj geo_polygon_fload_alloc_irap( char* )", bind=False ) - _add_point = EclPrototype( + _add_point = ResdataPrototype( "void geo_polygon_add_point( geo_polygon , double , double )" ) - _add_point_front = EclPrototype( + _add_point_front = ResdataPrototype( "void geo_polygon_add_point_front( geo_polygon , double , double )" ) - _free = EclPrototype("void geo_polygon_free( geo_polygon )") - _size = EclPrototype("int geo_polygon_get_size( geo_polygon )") - _iget_xy = EclPrototype( + _free = ResdataPrototype("void geo_polygon_free( geo_polygon )") + _size = ResdataPrototype("int geo_polygon_get_size( geo_polygon )") + _iget_xy = ResdataPrototype( "void geo_polygon_iget_xy( geo_polygon , int , double* , double* )" ) - _segment_intersects = EclPrototype( + _segment_intersects = ResdataPrototype( "bool geo_polygon_segment_intersects( geo_polygon , double , double, double , double)" ) - _get_name = EclPrototype("char* geo_polygon_get_name( geo_polygon )") - _set_name = EclPrototype("void geo_polygon_set_name( geo_polygon , char* )") - _segment_length = EclPrototype("double geo_polygon_get_length( geo_polygon)") - _equal = EclPrototype("bool geo_polygon_equal( geo_polygon , geo_polygon )") + _get_name = ResdataPrototype("char* geo_polygon_get_name( geo_polygon )") + _set_name = ResdataPrototype( + "void geo_polygon_set_name( geo_polygon , char* )" + ) + _segment_length = ResdataPrototype("double geo_polygon_get_length( geo_polygon)") + _equal = ResdataPrototype("bool geo_polygon_equal( geo_polygon , geo_polygon )") def __init__(self, name=None, init_points=()): c_ptr = self._alloc_new(name) diff --git a/python/ecl/util/geometry/cpolyline_collection.py b/python/resdata/geometry/cpolyline_collection.py similarity index 90% rename from python/ecl/util/geometry/cpolyline_collection.py rename to python/resdata/geometry/cpolyline_collection.py index 1d7a27259c..0c7ecf29c2 100644 --- a/python/ecl/util/geometry/cpolyline_collection.py +++ b/python/resdata/geometry/cpolyline_collection.py @@ -4,35 +4,35 @@ import ctypes from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.util.geometry import CPolyline +from resdata import ResdataPrototype +from resdata.geometry import CPolyline class CPolylineCollection(BaseCClass): TYPE_NAME = "geo_polygon_collection" - _alloc_new = EclPrototype( + _alloc_new = ResdataPrototype( "void* geo_polygon_collection_alloc( )", bind=False ) - _free = EclPrototype( + _free = ResdataPrototype( "void geo_polygon_collection_free( geo_polygon_collection )" ) - _size = EclPrototype( + _size = ResdataPrototype( "int geo_polygon_collection_size( geo_polygon_collection)" ) - _create_polyline = EclPrototype( + _create_polyline = ResdataPrototype( "geo_polygon_ref geo_polygon_collection_create_polygon(geo_polygon_collection , char*)" ) - _has_polyline = EclPrototype( + _has_polyline = ResdataPrototype( "bool geo_polygon_collection_has_polygon(geo_polygon_collection , char*)" ) - _iget = EclPrototype( + _iget = ResdataPrototype( "geo_polygon_ref geo_polygon_collection_iget_polygon(geo_polygon_collection , int)" ) - _get = EclPrototype( + _get = ResdataPrototype( "geo_polygon_ref geo_polygon_collection_get_polygon(geo_polygon_collection , char*)" ) - _add_polyline = EclPrototype( + _add_polyline = ResdataPrototype( "void geo_polygon_collection_add_polygon(geo_polygon_collection , geo_polygon , bool)" ) diff --git a/python/resdata/geometry/geo_pointset.py b/python/resdata/geometry/geo_pointset.py new file mode 100644 index 0000000000..64ac90b009 --- /dev/null +++ b/python/resdata/geometry/geo_pointset.py @@ -0,0 +1,66 @@ +from cwrap import BaseCClass +from resdata import ResdataPrototype + + +class GeoPointset(BaseCClass): + TYPE_NAME = "geo_pointset" + + _alloc = ResdataPrototype("void* geo_pointset_alloc(bool)", bind=False) + _free = ResdataPrototype("void geo_pointset_free(geo_pointset)") + # _add_xyz = ResdataPrototype("void geo_pointset_add_xyz(geo_pointset, double, double, double)") + _get_size = ResdataPrototype("int geo_pointset_get_size(geo_pointset)") + # _iget_xy = ResdataPrototype("void geo_pointset_iget_xy(geo_pointset, int, double*, double*)") + # _get_zcoord = ResdataPrototype("double* geo_pointset_get_zcoord(geo_pointset)") + _equal = ResdataPrototype("bool geo_pointset_equal(geo_pointset, geo_pointset)") + _iget_z = ResdataPrototype("double geo_pointset_iget_z(geo_pointset, int)") + # _iset_z = ResdataPrototype("void geo_pointset_iset_z(geo_pointset, int, double)") + # _memcpy = ResdataPrototype("void geo_pointset_memcpy(geo_pointset, geo_pointset, bool)") + # _shift_z = ResdataPrototype("void geo_pointset_shift_z(geo_pointset, double)") + # _assign_z = ResdataPrototype("void geo_pointset_assign_z(geo_pointset, double)") + # _scale_z = ResdataPrototype("void geo_pointset_scale_z(geo_pointset, double)") + # _imul = ResdataPrototype("void geo_pointset_imul(geo_pointset, geo_pointset)") + # _iadd = ResdataPrototype("void geo_pointset_iadd(geo_pointset, geo_pointset)") + # _isub = ResdataPrototype("void geo_pointset_isub(geo_pointset, geo_pointset)") + # _isqrt = ResdataPrototype("void geo_pointset_isqrt(geo_pointset)") + + def __init__(self, external_z=False): + c_ptr = self._alloc(external_z) + if c_ptr: + super(GeoPointset, self).__init__(c_ptr) + else: + ext = "external" if external_z else "internal" + raise ValueError("Failed to construct GeoPointset with %s_z." % ext) + + @staticmethod + def fromSurface(surface): + return surface.getPointset() + + def __eq__(self, other): + if isinstance(other, GeoPointset): + return self._equal(other) + return NotImplemented + + def __getitem__(self, key): + size = len(self) + if isinstance(key, int): + idx = key + if idx < 0: + idx += size + if 0 <= idx < size: + return self._iget_z(idx) + else: + raise IndexError( + "Invalid index, must be in [0, %d), was: %d." % (size, key) + ) + else: + # TODO implement slicing? + raise ValueError("Index must be int, not %s." % type(key)) + + def __len__(self): + return self._get_size() + + def __repr__(self): + return self._create_repr("len=%d" % len(self)) + + def free(self): + self._free() diff --git a/python/ecl/util/geometry/geo_region.py b/python/resdata/geometry/geo_region.py similarity index 83% rename from python/ecl/util/geometry/geo_region.py rename to python/resdata/geometry/geo_region.py index 7c03818187..21bb3f9545 100644 --- a/python/ecl/util/geometry/geo_region.py +++ b/python/resdata/geometry/geo_region.py @@ -1,6 +1,6 @@ from cwrap import BaseCClass -from ecl.util.util import IntVector -from ecl import EclPrototype +from resdata.util.util import IntVector +from resdata import ResdataPrototype from .cpolyline import CPolyline from ctypes import c_double @@ -10,34 +10,34 @@ class GeoRegion(BaseCClass): TYPE_NAME = "geo_region" - _alloc = EclPrototype("void* geo_region_alloc(geo_pointset, bool)", bind=False) - _free = EclPrototype("void geo_region_free(geo_region)") - _reset = EclPrototype("void geo_region_reset(geo_region)") - _get_index_list = EclPrototype( + _alloc = ResdataPrototype("void* geo_region_alloc(geo_pointset, bool)", bind=False) + _free = ResdataPrototype("void geo_region_free(geo_region)") + _reset = ResdataPrototype("void geo_region_reset(geo_region)") + _get_index_list = ResdataPrototype( "int_vector_ref geo_region_get_index_list(geo_region)" ) - _select_inside_polygon = EclPrototype( + _select_inside_polygon = ResdataPrototype( "void geo_region_select_inside_polygon(geo_region, geo_polygon)" ) - _select_outside_polygon = EclPrototype( + _select_outside_polygon = ResdataPrototype( "void geo_region_select_outside_polygon(geo_region, geo_polygon)" ) - _deselect_inside_polygon = EclPrototype( + _deselect_inside_polygon = ResdataPrototype( "void geo_region_deselect_inside_polygon(geo_region, geo_polygon)" ) - _deselect_outside_polygon = EclPrototype( + _deselect_outside_polygon = ResdataPrototype( "void geo_region_deselect_outside_polygon(geo_region, geo_polygon)" ) - _select_above_line = EclPrototype( + _select_above_line = ResdataPrototype( "void geo_region_select_above_line(geo_region, double*, double*)" ) - _select_below_line = EclPrototype( + _select_below_line = ResdataPrototype( "void geo_region_select_below_line(geo_region, double*, double*)" ) - _deselect_above_line = EclPrototype( + _deselect_above_line = ResdataPrototype( "void geo_region_deselect_above_line(geo_region, double*, double*)" ) - _deselect_below_line = EclPrototype( + _deselect_below_line = ResdataPrototype( "void geo_region_deselect_below_line(geo_region, double*, double*)" ) diff --git a/python/ecl/util/geometry/geometry_tools.py b/python/resdata/geometry/geometry_tools.py similarity index 100% rename from python/ecl/util/geometry/geometry_tools.py rename to python/resdata/geometry/geometry_tools.py diff --git a/python/ecl/util/geometry/polyline.py b/python/resdata/geometry/polyline.py similarity index 100% rename from python/ecl/util/geometry/polyline.py rename to python/resdata/geometry/polyline.py diff --git a/python/ecl/util/geometry/surface.py b/python/resdata/geometry/surface.py similarity index 83% rename from python/ecl/util/geometry/surface.py rename to python/resdata/geometry/surface.py index afa4da67cd..c6f1004ed7 100644 --- a/python/ecl/util/geometry/surface.py +++ b/python/resdata/geometry/surface.py @@ -7,42 +7,46 @@ import ctypes from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.util.geometry import GeoPointset +from resdata import ResdataPrototype +from resdata.geometry import GeoPointset class Surface(BaseCClass): TYPE_NAME = "surface" - _alloc = EclPrototype( + _alloc = ResdataPrototype( "void* geo_surface_fload_alloc_irap( char* , bool )", bind=False ) - _free = EclPrototype("void geo_surface_free( surface )") - _new = EclPrototype( + _free = ResdataPrototype("void geo_surface_free( surface )") + _new = ResdataPrototype( "void* geo_surface_alloc_new( int, int, double, double, double, double, double )", bind=False, ) - _get_nx = EclPrototype("int geo_surface_get_nx( surface )") - _get_ny = EclPrototype("int geo_surface_get_ny( surface )") - _iget_zvalue = EclPrototype("double geo_surface_iget_zvalue( surface , int)") - _iset_zvalue = EclPrototype( + _get_nx = ResdataPrototype("int geo_surface_get_nx( surface )") + _get_ny = ResdataPrototype("int geo_surface_get_ny( surface )") + _iget_zvalue = ResdataPrototype("double geo_surface_iget_zvalue( surface , int)") + _iset_zvalue = ResdataPrototype( "void geo_surface_iset_zvalue( surface , int , double)" ) - _write = EclPrototype("void geo_surface_fprintf_irap( surface , char* )") - _equal = EclPrototype("bool geo_surface_equal( surface , surface )") - _header_equal = EclPrototype("bool geo_surface_equal_header( surface , surface )") - _copy = EclPrototype("surface_obj geo_surface_alloc_copy( surface , bool )") - _assign = EclPrototype("void geo_surface_assign_value( surface , double )") - _scale = EclPrototype("void geo_surface_scale( surface , double )") - _shift = EclPrototype("void geo_surface_shift( surface , double )") - _iadd = EclPrototype("void geo_surface_iadd( surface , surface )") - _imul = EclPrototype("void geo_surface_imul( surface , surface )") - _isub = EclPrototype("void geo_surface_isub( surface , surface )") - _isqrt = EclPrototype("void geo_surface_isqrt( surface )") - _iget_xy = EclPrototype( + _write = ResdataPrototype("void geo_surface_fprintf_irap( surface , char* )") + _equal = ResdataPrototype("bool geo_surface_equal( surface , surface )") + _header_equal = ResdataPrototype( + "bool geo_surface_equal_header( surface , surface )" + ) + _copy = ResdataPrototype("surface_obj geo_surface_alloc_copy( surface , bool )") + _assign = ResdataPrototype("void geo_surface_assign_value( surface , double )") + _scale = ResdataPrototype("void geo_surface_scale( surface , double )") + _shift = ResdataPrototype("void geo_surface_shift( surface , double )") + _iadd = ResdataPrototype("void geo_surface_iadd( surface , surface )") + _imul = ResdataPrototype("void geo_surface_imul( surface , surface )") + _isub = ResdataPrototype("void geo_surface_isub( surface , surface )") + _isqrt = ResdataPrototype("void geo_surface_isqrt( surface )") + _iget_xy = ResdataPrototype( "void geo_surface_iget_xy(surface, int, double*, double*)" ) - _get_pointset = EclPrototype("geo_pointset_ref geo_surface_get_pointset(surface)") + _get_pointset = ResdataPrototype( + "geo_pointset_ref geo_surface_get_pointset(surface)" + ) def __init__( self, diff --git a/python/ecl/util/geometry/xyz_io.py b/python/resdata/geometry/xyz_io.py similarity index 100% rename from python/ecl/util/geometry/xyz_io.py rename to python/resdata/geometry/xyz_io.py diff --git a/python/resdata/gravimetry/__init__.py b/python/resdata/gravimetry/__init__.py new file mode 100644 index 0000000000..1035865aa3 --- /dev/null +++ b/python/resdata/gravimetry/__init__.py @@ -0,0 +1,11 @@ +""" + rd_grav/ResdataGrav: Class used to simplify evaluation of + modelling time-lapse gravitational surveys. + + rd_subsidence/ResdataSubsidence: Small class used to evaluate simulated + subsidence from simulations; analogous to the EcLGrav + functionality. +""" + +from .rd_grav import ResdataGrav +from .rd_subsidence import ResdataSubsidence diff --git a/python/ecl/gravimetry/ecl_grav.py b/python/resdata/gravimetry/rd_grav.py similarity index 68% rename from python/ecl/gravimetry/ecl_grav.py rename to python/resdata/gravimetry/rd_grav.py index 3d6eed22b2..5afb308e7c 100644 --- a/python/ecl/gravimetry/ecl_grav.py +++ b/python/resdata/gravimetry/rd_grav.py @@ -1,72 +1,74 @@ """ Calculate dynamic change in gravitational strength. -The ecl_grav module contains functionality to load time-lapse ECLIPSE +The rd_grav module contains functionality to load time-lapse ECLIPSE results and calculate the change in gravitational strength between the different surveys. The implementation is a thin wrapper around the -ecl_grav.c implementation in the libecl library. +rd_grav.c implementation in the resdata library. """ + from typing import Optional from cwrap import BaseCClass - -from ecl import EclPrototype -from ecl.grid import EclGrid, EclRegion -from ecl.eclfile import EclFileView, EclFile -from ecl.util.util import monkey_the_camel -from ecl import EclPhaseEnum +from resdata import Phase, ResdataPrototype +from resdata.grid import Grid, ResdataRegion +from resdata.resfile import ResdataFile, ResdataFileView +from resdata.util.util import monkey_the_camel -class EclGrav(BaseCClass): +class ResdataGrav(BaseCClass): """ Holding ECLIPSE results for calculating gravity changes. - The EclGrav class is a collection class holding the results from + The ResdataGrav class is a collection class holding the results from ECLIPSE forward modelling of gravity surveys. Observe that the class is focused on the ECLIPSE side of things, and does not have any notion of observed values or measurement locations; that - should be handled by the scope using the EclGrav class. + should be handled by the scope using the ResdataGrav class. - Typical use of the EclGrav class involves the following steps: + Typical use of the ResdataGrav class involves the following steps: - 1. Create the EclGrav instance. + 1. Create the ResdataGrav instance. 2. Add surveys with the add_survey_XXXX() methods. 3. Evalute the gravitational response with the eval() method. """ - TYPE_NAME = "ecl_grav" - _grav_alloc = EclPrototype("void* ecl_grav_alloc(ecl_grid, ecl_file)", bind=False) - _free = EclPrototype("void ecl_grav_free(ecl_grav)") - _add_survey_RPORV = EclPrototype( - "void* ecl_grav_add_survey_RPORV(ecl_grav, char*, ecl_file_view)" + TYPE_NAME = "rd_grav" + _grav_alloc = ResdataPrototype("void* rd_grav_alloc(rd_grid, rd_file)", bind=False) + _free = ResdataPrototype("void rd_grav_free(rd_grav)") + _add_survey_RPORV = ResdataPrototype( + "void* rd_grav_add_survey_RPORV(rd_grav, char*, rd_file_view)" ) - _add_survey_PORMOD = EclPrototype( - "void* ecl_grav_add_survey_PORMOD(ecl_grav, char*, ecl_file_view)" + _add_survey_PORMOD = ResdataPrototype( + "void* rd_grav_add_survey_PORMOD(rd_grav, char*, rd_file_view)" ) - _add_survey_FIP = EclPrototype( - "void* ecl_grav_add_survey_FIP(ecl_grav, char*, ecl_file_view)" + _add_survey_FIP = ResdataPrototype( + "void* rd_grav_add_survey_FIP(rd_grav, char*, rd_file_view)" ) - _add_survey_RFIP = EclPrototype( - "void* ecl_grav_add_survey_RFIP(ecl_grav, char*, ecl_file_view)" + _add_survey_RFIP = ResdataPrototype( + "void* rd_grav_add_survey_RFIP(rd_grav, char*, rd_file_view)" ) - _new_std_density = EclPrototype( - "void ecl_grav_new_std_density(ecl_grav, int, double)" + _new_std_density = ResdataPrototype( + "void rd_grav_new_std_density(rd_grav, int, double)" ) - _add_std_density = EclPrototype( - "void ecl_grav_add_std_density(ecl_grav, int, int, double)" + _add_std_density = ResdataPrototype( + "void rd_grav_add_std_density(rd_grav, int, int, double)" ) - _eval = EclPrototype( - "double ecl_grav_eval(ecl_grav, char*, char*, ecl_region, double, double, double, int)" + _eval = ResdataPrototype( + "double rd_grav_eval(rd_grav, char*, char*, rd_region, double, double, double, int)" ) - def __init__(self, grid: EclGrid, init_file: EclFile): + def __init__(self, grid: Grid, init_file: ResdataFile): """ - Creates a new EclGrav instance. + Creates a new ResdataGrav instance. + + The input arguments @grid and @init_file should be instances + of Grid and ResdataFile respectively. """ self.init_file = init_file # Inhibit premature garbage collection of init_file c_ptr = self._grav_alloc(grid, init_file) - super(EclGrav, self).__init__(c_ptr) + super(ResdataGrav, self).__init__(c_ptr) self.dispatch = { "FIP": self.add_survey_FIP, @@ -75,23 +77,23 @@ def __init__(self, grid: EclGrid, init_file: EclFile): "RPORV": self.add_survey_RPORV, } - def add_survey_RPORV(self, survey_name: str, restart_view: EclFileView): + def add_survey_RPORV(self, survey_name: str, restart_view: ResdataFileView): """ Add new survey based on RPORV keyword. Add a new survey; in this context a survey is the state of - reservoir, i.e. an ECLIPSE restart file. The @survey_name + reservoir, i.e. a restart file. The @survey_name input argument will be used when refering to this survey at a later stage. The @restart_view input argument should be an - EclFile instance with data from one report step. A typical way + ResdataFile instance with data from one report step. A typical way to load the @restart_view argument is: import datetime - from ecl.eclfile import EclFile + from resdata.resfil import ResdataRestartFile ... ... date = datetime.datetime(year, month, day) - rst_file = EclFile("ECLIPSE.UNRST") + rst_file = ResdataFile("CASE.UNRST") restart_view1 = rst_file.restartView(sim_time=date) restart_view2 = rst_file.restartView(report_step=67) @@ -102,7 +104,7 @@ def add_survey_RPORV(self, survey_name: str, restart_view: EclFileView): """ self._add_survey_RPORV(survey_name, restart_view) - def add_survey_PORMOD(self, survey_name: str, restart_view: EclFileView): + def add_survey_PORMOD(self, survey_name: str, restart_view: ResdataFileView): """ Add new survey based on PORMOD keyword. @@ -112,7 +114,7 @@ def add_survey_PORMOD(self, survey_name: str, restart_view: EclFileView): """ self._add_survey_PORMOD(survey_name, restart_view) - def add_survey_FIP(self, survey_name: str, restart_view: EclFileView): + def add_survey_FIP(self, survey_name: str, restart_view: ResdataFileView): """ Add new survey based on FIP keywords. @@ -127,7 +129,7 @@ def add_survey_FIP(self, survey_name: str, restart_view: EclFileView): """ self._add_survey_FIP(survey_name, restart_view) - def add_survey_RFIP(self, survey_name: str, restart_view: EclFileView): + def add_survey_RFIP(self, survey_name: str, restart_view: ResdataFileView): """ Add new survey based on RFIP keywords. @@ -138,7 +140,7 @@ def add_survey_RFIP(self, survey_name: str, restart_view: EclFileView): """ self._add_survey_RFIP(survey_name, restart_view) - def add_survey(self, name: str, restart_view: EclFileView, method): + def add_survey(self, name: str, restart_view: ResdataFileView, method): method = self.dispatch[method] return method(name, restart_view) @@ -147,10 +149,8 @@ def eval( base_survey, monitor_survey, pos, - region: Optional[EclRegion] = None, - phase_mask=EclPhaseEnum.ECL_OIL_PHASE - + EclPhaseEnum.ECL_GAS_PHASE - + EclPhaseEnum.ECL_WATER_PHASE, + region: Optional[ResdataRegion] = None, + phase_mask=Phase.OIL + Phase.GAS + Phase.WATER, ): """ Calculates the gravity change between two surveys. @@ -170,13 +170,13 @@ def eval( change in gravitational strength. If supplied the optional argument @region should be an - EclRegion() instance; this region will be used to limit the + ResdataRegion() instance; this region will be used to limit the part of the reserviour included in the gravity calculations. The optional argument @phase_mask is an integer flag to indicate which phases you are interested in. It should be a - sum of the relevant integer constants 'ECL_OIL_PHASE', - 'ECL_GAS_PHASE' and 'ECL_WATER_PHASE'. + sum of the relevant integer constants 'OIL', + 'GAS' and 'WATER'. """ return self._eval( base_survey, monitor_survey, region, pos[0], pos[1], pos[2], phase_mask @@ -186,9 +186,9 @@ def new_std_density(self, phase_enum, default_density): """ Adds a new phase with a corresponding density. - @phase_enum is one of the integer constants ECL_OIL_PHASE, - ECL_GAS_PHASE or ECL_WATER_PHASE, all available in the - ecl_util and also ecl modules. + @phase_enum is one of the integer constants OIL, + GAS or WATER, all available in the + rd_util and also ecl modules. @default_density is the density, at standard conditions, for this particular phase. By default @default_density will be @@ -226,4 +226,4 @@ def free(self): self._free() -monkey_the_camel(EclGrav, "addSurvey", EclGrav.add_survey) +monkey_the_camel(ResdataGrav, "addSurvey", ResdataGrav.add_survey) diff --git a/python/ecl/gravimetry/ecl_subsidence.py b/python/resdata/gravimetry/rd_subsidence.py similarity index 67% rename from python/ecl/gravimetry/ecl_subsidence.py rename to python/resdata/gravimetry/rd_subsidence.py index c89ff52c47..217443d87b 100644 --- a/python/ecl/gravimetry/ecl_subsidence.py +++ b/python/resdata/gravimetry/rd_subsidence.py @@ -1,65 +1,65 @@ """ Calculate dynamic change in gravitational strength. -The ecl_subsidence module contains functionality to load time-lapse ECLIPSE +The rd_subsidence module contains functionality to load time-lapse ECLIPSE results and calculate the change in seafloor subsidence between the different surveys. The implementation is a thin wrapper around the -ecl_subsidence.c implementation in the libecl library. +rd_subsidence.c implementation in the resdata library. """ from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.util.util import monkey_the_camel -import ecl.grid +from resdata import ResdataPrototype +from resdata.util.util import monkey_the_camel +import resdata.grid -class EclSubsidence(BaseCClass): +class ResdataSubsidence(BaseCClass): """ Holding ECLIPSE results for calculating subsidence changes. - The EclSubsidence class is a collection class holding the results from + The ResdataSubsidence class is a collection class holding the results from ECLIPSE forward modelling of subsidence surveys. Observe that the class is focused on the ECLIPSE side of things, and does not have any notion of observed values or measurement locations; that - should be handled by the scope using the EclSubsidence class. + should be handled by the scope using the ResdataSubsidence class. - Typical use of the EclSubsidence class involves the following steps: + Typical use of the ResdataSubsidence class involves the following steps: - 1. Create the EclSubsidence instance. + 1. Create the ResdataSubsidence instance. 2. Add surveys with the add_survey_XXXX() methods. 3. Evalute the subsidence response with the eval() method. """ - TYPE_NAME = "ecl_subsidence" - _alloc = EclPrototype( - "void* ecl_subsidence_alloc( ecl_grid , ecl_file )", bind=False + TYPE_NAME = "rd_subsidence" + _alloc = ResdataPrototype( + "void* rd_subsidence_alloc( rd_grid , rd_file )", bind=False ) - _free = EclPrototype("void ecl_subsidence_free( ecl_subsidence )") - _add_survey_PRESSURE = EclPrototype( - "void* ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file_view )" + _free = ResdataPrototype("void rd_subsidence_free( rd_subsidence )") + _add_survey_PRESSURE = ResdataPrototype( + "void* rd_subsidence_add_survey_PRESSURE( rd_subsidence , char* , rd_file_view )" ) - _eval = EclPrototype( - "double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double)" + _eval = ResdataPrototype( + "double rd_subsidence_eval( rd_subsidence , char* , char* , rd_region , double , double , double, double, double)" ) - _eval_geertsma = EclPrototype( - "double ecl_subsidence_eval_geertsma( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double, double)" + _eval_geertsma = ResdataPrototype( + "double rd_subsidence_eval_geertsma( rd_subsidence , char* , char* , rd_region , double , double , double, double, double, double)" ) - _eval_geertsma_rporv = EclPrototype( - "double ecl_subsidence_eval_geertsma_rporv( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double, double)" + _eval_geertsma_rporv = ResdataPrototype( + "double rd_subsidence_eval_geertsma_rporv( rd_subsidence , char* , char* , rd_region , double , double , double, double, double, double)" ) - _has_survey = EclPrototype( - "bool ecl_subsidence_has_survey( ecl_subsidence , char*)" + _has_survey = ResdataPrototype( + "bool rd_subsidence_has_survey( rd_subsidence , char*)" ) def __init__(self, grid, init_file): """ - Creates a new EclSubsidence instance. + Creates a new ResdataSubsidence instance. The input arguments @grid and @init_file should be instances - of EclGrid and EclFile respectively. + of Grid and ResdataFile respectively. """ self.init_file = init_file # Inhibit premature garbage collection of init_file c_ptr = self._alloc(grid, init_file) - super(EclSubsidence, self).__init__(c_ptr) + super(ResdataSubsidence, self).__init__(c_ptr) def __contains__(self, survey_name): return self._has_survey(survey_name) @@ -69,19 +69,15 @@ def add_survey_PRESSURE(self, survey_name, restart_file): Add new survey based on PRESSURE keyword. Add a new survey; in this context a survey is the state of - reservoir, i.e. an ECLIPSE restart file. The @survey_name + reservoir, i.e. a restart file. The @survey_name input argument will be used when refering to this survey at a later stage. The @restart_file input argument should be an - EclFile instance with data from one report step. A typical way + ResdataFile instance with data from one report step. A typical way to load the @restart_file argument is: - import datetime - import ecl.ecl.ecl as ecl - ... - ... - date = datetime.datetime( year , month , day ) - restart_file1 = ecl.EclFile.restart_block( "ECLIPSE.UNRST" , dtime = date) - restart_file2 = ecl.EclFile.restart_block( "ECLIPSE.UNRST" , report_step = 67 ) + >>> date = datetime.datetime( year , month , day ) + >>> restart_file1 = ResdataFile.restart_block( "CASE.UNRST" , dtime = date) + >>> restart_file2 = ResdataFile.restart_block( "CASE.UNRST" , report_step = 67 ) The pore volume is calculated from the initial pore volume and the PRESSURE keyword from the restart file. @@ -173,7 +169,7 @@ def eval( change in subsidence. If supplied the optional argument @region should be an - EclRegion() instance; this region will be used to limit the + ResdataRegion() instance; this region will be used to limit the part of the reserviour included in the subsidence calculations. The argument @compressibility is the total reservoir compressibility. @@ -199,4 +195,4 @@ def free(self): self._free() -monkey_the_camel(EclSubsidence, "evalGeertsma", EclSubsidence.eval_geertsma) +monkey_the_camel(ResdataSubsidence, "evalGeertsma", ResdataSubsidence.eval_geertsma) diff --git a/python/resdata/grid/__init__.py b/python/resdata/grid/__init__.py new file mode 100644 index 0000000000..9e88a4aa22 --- /dev/null +++ b/python/resdata/grid/__init__.py @@ -0,0 +1,19 @@ +""" + rd_grid/Grid: This will load a GRID or EGRID file, and + can then subsequently be used for queries about the grid. + + rd_region/ResdataRegion: Convenience class to support selecting cells + in a grid based on a wide range of criteria. Can be used as a + mask in operations on ResdataKW instances. + + rd_grid_generator/GridGenerator: This can be used to generate various + grids. +""" + +import resdata.util.util +import resdata.geometry + +from .cell import Cell +from .rd_grid import Grid +from .rd_grid_generator import GridGenerator +from .rd_region import ResdataRegion diff --git a/python/ecl/grid/cell.py b/python/resdata/grid/cell.py similarity index 100% rename from python/ecl/grid/cell.py rename to python/resdata/grid/cell.py diff --git a/python/ecl/grid/faults/__init__.py b/python/resdata/grid/faults/__init__.py similarity index 100% rename from python/ecl/grid/faults/__init__.py rename to python/resdata/grid/faults/__init__.py diff --git a/python/ecl/grid/faults/fault.py b/python/resdata/grid/faults/fault.py similarity index 99% rename from python/ecl/grid/faults/fault.py rename to python/resdata/grid/faults/fault.py index b5cf34ec7c..b25a427587 100644 --- a/python/ecl/grid/faults/fault.py +++ b/python/resdata/grid/faults/fault.py @@ -1,7 +1,7 @@ import numpy as np -from ecl.util.util import monkey_the_camel -from ecl.util.geometry import Polyline, CPolyline, GeometryTools +from resdata.util.util import monkey_the_camel +from resdata.geometry import Polyline, CPolyline, GeometryTools from .fault_line import FaultLine from .fault_segments import FaultSegment, SegmentMap diff --git a/python/ecl/grid/faults/fault_block.py b/python/resdata/grid/faults/fault_block.py similarity index 85% rename from python/ecl/grid/faults/fault_block.py rename to python/resdata/grid/faults/fault_block.py index ec460e3d99..3f4baaea4c 100644 --- a/python/ecl/grid/faults/fault_block.py +++ b/python/resdata/grid/faults/fault_block.py @@ -1,10 +1,10 @@ import ctypes from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl.util.util import DoubleVector, IntVector -from ecl import EclPrototype -from ecl.util.geometry import Polyline, GeometryTools, CPolylineCollection +from resdata.util.util import monkey_the_camel +from resdata.util.util import DoubleVector, IntVector +from resdata import ResdataPrototype +from resdata.geometry import Polyline, GeometryTools, CPolylineCollection class FaultBlockCell(object): @@ -24,32 +24,32 @@ def __str__(self): class FaultBlock(BaseCClass): TYPE_NAME = "fault_block" - _get_xc = EclPrototype("double fault_block_get_xc(fault_block)") - _get_yc = EclPrototype("double fault_block_get_yc(fault_block)") - _get_block_id = EclPrototype("int fault_block_get_id(fault_block)") - _get_size = EclPrototype("int fault_block_get_size(fault_block)") - _export_cell = EclPrototype( + _get_xc = ResdataPrototype("double fault_block_get_xc(fault_block)") + _get_yc = ResdataPrototype("double fault_block_get_yc(fault_block)") + _get_block_id = ResdataPrototype("int fault_block_get_id(fault_block)") + _get_size = ResdataPrototype("int fault_block_get_size(fault_block)") + _export_cell = ResdataPrototype( "void fault_block_export_cell(fault_block, int, int*, int*, int*, double*, double*, double*)" ) - _assign_to_region = EclPrototype( + _assign_to_region = ResdataPrototype( "void fault_block_assign_to_region(fault_block, int)" ) - _get_region_list = EclPrototype( + _get_region_list = ResdataPrototype( "int_vector_ref fault_block_get_region_list(fault_block)" ) - _add_cell = EclPrototype( + _add_cell = ResdataPrototype( "void fault_block_add_cell(fault_block, int, int)" ) - _get_global_index_list = EclPrototype( + _get_global_index_list = ResdataPrototype( "int_vector_ref fault_block_get_global_index_list(fault_block)" ) - _trace_edge = EclPrototype( + _trace_edge = ResdataPrototype( "void fault_block_trace_edge(fault_block, double_vector, double_vector, int_vector)" ) - _get_neighbours = EclPrototype( + _get_neighbours = ResdataPrototype( "void fault_block_list_neighbours(fault_block, bool, geo_polygon_collection, int_vector)" ) - _free = EclPrototype("void fault_block_free__(fault_block)") + _free = ResdataPrototype("void fault_block_free__(fault_block)") def __init__(self, *args, **kwargs): raise NotImplementedError("Class can not be instantiated directly!") diff --git a/python/ecl/grid/faults/fault_block_collection.py b/python/resdata/grid/faults/fault_block_collection.py similarity index 82% rename from python/ecl/grid/faults/fault_block_collection.py rename to python/resdata/grid/faults/fault_block_collection.py index 14d061e5f3..5b85769d23 100644 --- a/python/ecl/grid/faults/fault_block_collection.py +++ b/python/resdata/grid/faults/fault_block_collection.py @@ -1,20 +1,22 @@ from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl import EclPrototype +from resdata.util.util import monkey_the_camel +from resdata import ResdataPrototype class FaultBlockCollection(BaseCClass): TYPE_NAME = "fault_block_collection" - _alloc = EclPrototype("void* fault_block_collection_alloc(ecl_grid)", bind=False) - _free = EclPrototype("void fault_block_collection_free(fault_block_collection)") - _num_layers = EclPrototype( + _alloc = ResdataPrototype("void* fault_block_collection_alloc(rd_grid)", bind=False) + _free = ResdataPrototype( + "void fault_block_collection_free(fault_block_collection)" + ) + _num_layers = ResdataPrototype( "int fault_block_collection_num_layers(fault_block_collection)" ) - _scan_keyword = EclPrototype( - "bool fault_block_collection_scan_kw(fault_block_collection, ecl_kw)" + _scan_keyword = ResdataPrototype( + "bool fault_block_collection_scan_kw(fault_block_collection, rd_kw)" ) - _get_layer = EclPrototype( + _get_layer = ResdataPrototype( "fault_block_layer_ref fault_block_collection_get_layer(fault_block_collection, int)" ) diff --git a/python/ecl/grid/faults/fault_block_layer.py b/python/resdata/grid/faults/fault_block_layer.py similarity index 89% rename from python/ecl/grid/faults/fault_block_layer.py rename to python/resdata/grid/faults/fault_block_layer.py index 76b5082a89..3f81c57a77 100644 --- a/python/ecl/grid/faults/fault_block_layer.py +++ b/python/resdata/grid/faults/fault_block_layer.py @@ -1,56 +1,60 @@ from __future__ import print_function from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl import EclDataType -from ecl import EclPrototype -from ecl.grid.faults import Fault +from resdata.util.util import monkey_the_camel +from resdata import ResDataType +from resdata import ResdataPrototype +from resdata.grid.faults import Fault class FaultBlockLayer(BaseCClass): TYPE_NAME = "fault_block_layer" - _alloc = EclPrototype( - "void* fault_block_layer_alloc(ecl_grid, int)", bind=False + _alloc = ResdataPrototype( + "void* fault_block_layer_alloc(rd_grid, int)", bind=False ) - _free = EclPrototype("void fault_block_layer_free(fault_block_layer)") - _size = EclPrototype( + _free = ResdataPrototype( + "void fault_block_layer_free(fault_block_layer)" + ) + _size = ResdataPrototype( "int fault_block_layer_get_size(fault_block_layer)" ) - _iget_block = EclPrototype( + _iget_block = ResdataPrototype( "fault_block_ref fault_block_layer_iget_block(fault_block_layer, int)" ) - _add_block = EclPrototype( + _add_block = ResdataPrototype( "fault_block_ref fault_block_layer_add_block(fault_block_layer, int)" ) - _get_block = EclPrototype( + _get_block = ResdataPrototype( "fault_block_ref fault_block_layer_get_block(fault_block_layer, int)" ) - _del_block = EclPrototype( + _del_block = ResdataPrototype( "void fault_block_layer_del_block(fault_block_layer, int)" ) - _has_block = EclPrototype( + _has_block = ResdataPrototype( "bool fault_block_layer_has_block(fault_block_layer, int)" ) - _scan_keyword = EclPrototype( - "bool fault_block_layer_scan_kw(fault_block_layer, ecl_kw)" + _scan_keyword = ResdataPrototype( + "bool fault_block_layer_scan_kw(fault_block_layer, rd_kw)" + ) + _load_keyword = ResdataPrototype( + "bool fault_block_layer_load_kw(fault_block_layer, rd_kw)" ) - _load_keyword = EclPrototype( - "bool fault_block_layer_load_kw(fault_block_layer, ecl_kw)" + _getK = ResdataPrototype( + "int fault_block_layer_get_k(fault_block_layer)" ) - _getK = EclPrototype("int fault_block_layer_get_k(fault_block_layer)") - _get_next_id = EclPrototype( + _get_next_id = ResdataPrototype( "int fault_block_layer_get_next_id(fault_block_layer)" ) - _scan_layer = EclPrototype( + _scan_layer = ResdataPrototype( "void fault_block_layer_scan_layer(fault_block_layer, layer)" ) - _insert_block_content = EclPrototype( + _insert_block_content = ResdataPrototype( "void fault_block_layer_insert_block_content(fault_block_layer, fault_block)" ) - _export_kw = EclPrototype( - "bool fault_block_layer_export(fault_block_layer, ecl_kw)" + _export_kw = ResdataPrototype( + "bool fault_block_layer_export(fault_block_layer, rd_kw)" ) - _get_layer = EclPrototype( + _get_layer = ResdataPrototype( "layer_ref fault_block_layer_get_layer(fault_block_layer)" ) diff --git a/python/ecl/grid/faults/fault_collection.py b/python/resdata/grid/faults/fault_collection.py similarity index 96% rename from python/ecl/grid/faults/fault_collection.py rename to python/resdata/grid/faults/fault_collection.py index e6c76b5489..7930b3f611 100644 --- a/python/ecl/grid/faults/fault_collection.py +++ b/python/resdata/grid/faults/fault_collection.py @@ -1,7 +1,7 @@ import re -from ecl.util.util import monkey_the_camel -from ecl.grid import EclGrid +from resdata.util.util import monkey_the_camel +from resdata.grid import Grid from .fault import Fault comment_regexp = re.compile("--.*") @@ -24,7 +24,7 @@ def __init__(self, grid=None, *file_list): self.__grid = grid if self.__grid is not None: - if not isinstance(self.__grid, EclGrid): + if not isinstance(self.__grid, Grid): raise ValueError( "When supplying a list of files to load - you must have a grid" ) diff --git a/python/ecl/grid/faults/fault_line.py b/python/resdata/grid/faults/fault_line.py similarity index 98% rename from python/ecl/grid/faults/fault_line.py rename to python/resdata/grid/faults/fault_line.py index 35dc6334cf..45697e800f 100644 --- a/python/ecl/grid/faults/fault_line.py +++ b/python/resdata/grid/faults/fault_line.py @@ -1,8 +1,8 @@ import sys -from ecl.util.util import monkey_the_camel -from ecl.util.util import DoubleVector -from ecl.util.geometry import CPolyline +from resdata.util.util import monkey_the_camel +from resdata.util.util import DoubleVector +from resdata.geometry import CPolyline from .fault_segments import FaultSegment diff --git a/python/ecl/grid/faults/fault_segments.py b/python/resdata/grid/faults/fault_segments.py similarity index 98% rename from python/ecl/grid/faults/fault_segments.py rename to python/resdata/grid/faults/fault_segments.py index d42d760fe4..b5ff6e91a3 100644 --- a/python/ecl/grid/faults/fault_segments.py +++ b/python/resdata/grid/faults/fault_segments.py @@ -1,6 +1,6 @@ from __future__ import print_function -from ecl.util.util import monkey_the_camel +from resdata.util.util import monkey_the_camel class FaultSegment(object): diff --git a/python/ecl/grid/faults/layer.py b/python/resdata/grid/faults/layer.py similarity index 82% rename from python/ecl/grid/faults/layer.py rename to python/resdata/grid/faults/layer.py index 326680eea1..edfb3ac761 100644 --- a/python/ecl/grid/faults/layer.py +++ b/python/resdata/grid/faults/layer.py @@ -1,45 +1,49 @@ import ctypes -from ecl.grid import EclGrid +from resdata.grid import Grid from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl.util.util import IntVector -from ecl import EclPrototype +from resdata.util.util import monkey_the_camel +from resdata.util.util import IntVector +from resdata import ResdataPrototype class Layer(BaseCClass): TYPE_NAME = "layer" - _alloc = EclPrototype("void* layer_alloc(int, int)", bind=False) - _copy = EclPrototype("void layer_memcpy(layer, layer)") - _free = EclPrototype("void layer_free(layer)") - _get_nx = EclPrototype("int layer_get_nx(layer)") - _get_ny = EclPrototype("int layer_get_ny(layer)") - _set_cell = EclPrototype("void layer_iset_cell_value(layer, int, int, int)") - _get_cell = EclPrototype("int layer_iget_cell_value(layer, int, int)") - _get_bottom_barrier = EclPrototype( + _alloc = ResdataPrototype("void* layer_alloc(int, int)", bind=False) + _copy = ResdataPrototype("void layer_memcpy(layer, layer)") + _free = ResdataPrototype("void layer_free(layer)") + _get_nx = ResdataPrototype("int layer_get_nx(layer)") + _get_ny = ResdataPrototype("int layer_get_ny(layer)") + _set_cell = ResdataPrototype("void layer_iset_cell_value(layer, int, int, int)") + _get_cell = ResdataPrototype("int layer_iget_cell_value(layer, int, int)") + _get_bottom_barrier = ResdataPrototype( "bool layer_iget_bottom_barrier(layer, int, int)" ) - _get_left_barrier = EclPrototype("bool layer_iget_left_barrier(layer, int, int)") - _cell_contact = EclPrototype("bool layer_cell_contact(layer, int, int, int, int)") - _add_barrier = EclPrototype("void layer_add_barrier(layer, int, int)") - _add_ijbarrier = EclPrototype( + _get_left_barrier = ResdataPrototype( + "bool layer_iget_left_barrier(layer, int, int)" + ) + _cell_contact = ResdataPrototype( + "bool layer_cell_contact(layer, int, int, int, int)" + ) + _add_barrier = ResdataPrototype("void layer_add_barrier(layer, int, int)") + _add_ijbarrier = ResdataPrototype( "void layer_add_ijbarrier(layer, int, int, int, int)" ) - _add_interp_barrier = EclPrototype( + _add_interp_barrier = ResdataPrototype( "void layer_add_interp_barrier(layer, int, int)" ) - _clear_cells = EclPrototype("void layer_clear_cells(layer)") - _assign = EclPrototype("void layer_assign(layer, int)") - _cell_sum = EclPrototype("int layer_get_cell_sum(layer)") - _update_connected = EclPrototype( + _clear_cells = ResdataPrototype("void layer_clear_cells(layer)") + _assign = ResdataPrototype("void layer_assign(layer, int)") + _cell_sum = ResdataPrototype("int layer_get_cell_sum(layer)") + _update_connected = ResdataPrototype( "void layer_update_connected_cells(layer,int,int,int,int)" ) - _cells_equal = EclPrototype( + _cells_equal = ResdataPrototype( "void layer_cells_equal(layer, int,int_vector,int_vector)" ) - _count_equal = EclPrototype("int layer_count_equal(layer, int)") - _active_cell = EclPrototype("bool layer_iget_active(layer, int,int)") - _update_active = EclPrototype("bool layer_update_active(layer, ecl_grid, int)") + _count_equal = ResdataPrototype("int layer_count_equal(layer, int)") + _active_cell = ResdataPrototype("bool layer_iget_active(layer, int,int)") + _update_active = ResdataPrototype("bool layer_update_active(layer, rd_grid, int)") def __init__(self, nx, ny): c_ptr = self._alloc(nx, ny) diff --git a/python/ecl/grid/ecl_grid.py b/python/resdata/grid/rd_grid.py similarity index 75% rename from python/ecl/grid/ecl_grid.py rename to python/resdata/grid/rd_grid.py index b29901b015..849be64854 100644 --- a/python/ecl/grid/ecl_grid.py +++ b/python/resdata/grid/rd_grid.py @@ -1,11 +1,11 @@ """ -Module to load and query ECLIPSE GRID/EGRID files. +Module to load and query GRID/EGRID files. -The ecl_grid module contains functionality to load and query an -ECLIPSE grid file; it is currently not possible to manipulate or let -alone create a grid with ecl_grid module. The functionality is -implemented in the EclGrid class. The ecl_grid module is a thin -wrapper around the ecl_grid.c implementation from the libecl library. +The rd_grid module contains functionality to load and query an +grid file; it is currently not possible to manipulate or let +alone create a grid with rd_grid module. The functionality is +implemented in the Grid class. The rd_grid module is a thin +wrapper around the rd_grid.c implementation from the resdata library. """ import ctypes @@ -18,167 +18,177 @@ import itertools from cwrap import CFILE, BaseCClass, load, open as copen -from ecl import EclPrototype -from ecl.util.util import monkey_the_camel -from ecl.util.util import IntVector -from ecl import EclDataType, EclUnitTypeEnum, EclTypeEnum -from ecl.eclfile import EclKW, FortIO -from ecl.grid import Cell +from resdata import ResdataPrototype +from resdata.util.util import monkey_the_camel +from resdata.util.util import IntVector +from resdata import ResDataType, UnitSystem, ResdataTypeEnum +from resdata.resfile import ResdataKW, FortIO +from resdata.grid import Cell -class EclGrid(BaseCClass): +class Grid(BaseCClass): """ - Class for loading and internalizing ECLIPSE GRID/EGRID files. + Class for loading and internalizing GRID/EGRID files. """ - TYPE_NAME = "ecl_grid" - _fread_alloc = EclPrototype("void* ecl_grid_load_case__(char*, bool)", bind=False) - _grdecl_create = EclPrototype( - "ecl_grid_obj ecl_grid_alloc_GRDECL_kw(int, int, int, ecl_kw, ecl_kw, ecl_kw, ecl_kw)", + TYPE_NAME = "rd_grid" + _fread_alloc = ResdataPrototype( + "void* rd_grid_load_case__(char*, bool)", bind=False + ) + _grdecl_create = ResdataPrototype( + "rd_grid_obj rd_grid_alloc_GRDECL_kw(int, int, int, rd_kw, rd_kw, rd_kw, rd_kw)", bind=False, ) - _alloc_rectangular = EclPrototype( - "ecl_grid_obj ecl_grid_alloc_rectangular(int, int, int, double, double, double, int*)", + _alloc_rectangular = ResdataPrototype( + "rd_grid_obj rd_grid_alloc_rectangular(int, int, int, double, double, double, int*)", bind=False, ) - _exists = EclPrototype("bool ecl_grid_exists(char*)", bind=False) + _exists = ResdataPrototype("bool rd_grid_exists(char*)", bind=False) - _get_numbered_lgr = EclPrototype( - "ecl_grid_ref ecl_grid_get_lgr_from_lgr_nr(ecl_grid, int)" + _get_numbered_lgr = ResdataPrototype( + "rd_grid_ref rd_grid_get_lgr_from_lgr_nr(rd_grid, int)" + ) + _get_named_lgr = ResdataPrototype("rd_grid_ref rd_grid_get_lgr(rd_grid, char*)") + _get_cell_lgr = ResdataPrototype("rd_grid_ref rd_grid_get_cell_lgr1(rd_grid, int)") + _num_coarse_groups = ResdataPrototype("int rd_grid_get_num_coarse_groups(rd_grid)") + _in_coarse_group1 = ResdataPrototype( + "bool rd_grid_cell_in_coarse_group1(rd_grid, int)" + ) + _free = ResdataPrototype("void rd_grid_free(rd_grid)") + _get_nx = ResdataPrototype("int rd_grid_get_nx(rd_grid)") + _get_ny = ResdataPrototype("int rd_grid_get_ny(rd_grid)") + _get_nz = ResdataPrototype("int rd_grid_get_nz(rd_grid)") + _get_global_size = ResdataPrototype("int rd_grid_get_global_size(rd_grid)") + _get_active = ResdataPrototype("int rd_grid_get_active_size(rd_grid)") + _get_active_fracture = ResdataPrototype("int rd_grid_get_nactive_fracture(rd_grid)") + _get_name = ResdataPrototype("char* rd_grid_get_name(rd_grid)") + _ijk_valid = ResdataPrototype("bool rd_grid_ijk_valid(rd_grid, int, int, int)") + _get_active_index3 = ResdataPrototype( + "int rd_grid_get_active_index3(rd_grid, int, int, int)" + ) + _get_global_index3 = ResdataPrototype( + "int rd_grid_get_global_index3(rd_grid, int, int, int)" + ) + _get_active_index1 = ResdataPrototype("int rd_grid_get_active_index1(rd_grid, int)") + _get_active_fracture_index1 = ResdataPrototype( + "int rd_grid_get_active_fracture_index1(rd_grid, int)" ) - _get_named_lgr = EclPrototype("ecl_grid_ref ecl_grid_get_lgr(ecl_grid, char*)") - _get_cell_lgr = EclPrototype("ecl_grid_ref ecl_grid_get_cell_lgr1(ecl_grid, int)") - _num_coarse_groups = EclPrototype("int ecl_grid_get_num_coarse_groups(ecl_grid)") - _in_coarse_group1 = EclPrototype( - "bool ecl_grid_cell_in_coarse_group1(ecl_grid, int)" + _get_global_index1A = ResdataPrototype( + "int rd_grid_get_global_index1A(rd_grid, int)" ) - _free = EclPrototype("void ecl_grid_free(ecl_grid)") - _get_nx = EclPrototype("int ecl_grid_get_nx(ecl_grid)") - _get_ny = EclPrototype("int ecl_grid_get_ny(ecl_grid)") - _get_nz = EclPrototype("int ecl_grid_get_nz(ecl_grid)") - _get_global_size = EclPrototype("int ecl_grid_get_global_size(ecl_grid)") - _get_active = EclPrototype("int ecl_grid_get_active_size(ecl_grid)") - _get_active_fracture = EclPrototype("int ecl_grid_get_nactive_fracture(ecl_grid)") - _get_name = EclPrototype("char* ecl_grid_get_name(ecl_grid)") - _ijk_valid = EclPrototype("bool ecl_grid_ijk_valid(ecl_grid, int, int, int)") - _get_active_index3 = EclPrototype( - "int ecl_grid_get_active_index3(ecl_grid, int, int, int)" + _get_global_index1F = ResdataPrototype( + "int rd_grid_get_global_index1F(rd_grid, int)" ) - _get_global_index3 = EclPrototype( - "int ecl_grid_get_global_index3(ecl_grid, int, int, int)" + _get_ijk1 = ResdataPrototype( + "void rd_grid_get_ijk1(rd_grid, int, int*, int*, int*)" ) - _get_active_index1 = EclPrototype("int ecl_grid_get_active_index1(ecl_grid, int)") - _get_active_fracture_index1 = EclPrototype( - "int ecl_grid_get_active_fracture_index1(ecl_grid, int)" + _get_ijk1A = ResdataPrototype( + "void rd_grid_get_ijk1A(rd_grid, int, int*, int*, int*)" ) - _get_global_index1A = EclPrototype("int ecl_grid_get_global_index1A(ecl_grid, int)") - _get_global_index1F = EclPrototype("int ecl_grid_get_global_index1F(ecl_grid, int)") - _get_ijk1 = EclPrototype("void ecl_grid_get_ijk1(ecl_grid, int, int*, int*, int*)") - _get_ijk1A = EclPrototype( - "void ecl_grid_get_ijk1A(ecl_grid, int, int*, int*, int*)" + _get_xyz3 = ResdataPrototype( + "void rd_grid_get_xyz3(rd_grid, int, int, int, double*, double*, double*)" ) - _get_xyz3 = EclPrototype( - "void ecl_grid_get_xyz3(ecl_grid, int, int, int, double*, double*, double*)" + _get_xyz1 = ResdataPrototype( + "void rd_grid_get_xyz1(rd_grid, int, double*, double*, double*)" ) - _get_xyz1 = EclPrototype( - "void ecl_grid_get_xyz1(ecl_grid, int, double*, double*, double*)" + _get_cell_corner_xyz1 = ResdataPrototype( + "void rd_grid_get_cell_corner_xyz1(rd_grid, int, int, double*, double*, double*)" ) - _get_cell_corner_xyz1 = EclPrototype( - "void ecl_grid_get_cell_corner_xyz1(ecl_grid, int, int, double*, double*, double*)" + _get_corner_xyz = ResdataPrototype( + "void rd_grid_get_corner_xyz(rd_grid, int, int, int, double*, double*, double*)" ) - _get_corner_xyz = EclPrototype( - "void ecl_grid_get_corner_xyz(ecl_grid, int, int, int, double*, double*, double*)" + _get_xyz1A = ResdataPrototype( + "void rd_grid_get_xyz1A(rd_grid, int, double*, double*, double*)" ) - _get_xyz1A = EclPrototype( - "void ecl_grid_get_xyz1A(ecl_grid, int, double*, double*, double*)" + _get_ij_xy = ResdataPrototype( + "bool rd_grid_get_ij_from_xy(rd_grid, double, double, int, int*, int*)" ) - _get_ij_xy = EclPrototype( - "bool ecl_grid_get_ij_from_xy(ecl_grid, double, double, int, int*, int*)" + _get_ijk_xyz = ResdataPrototype( + "int rd_grid_get_global_index_from_xyz(rd_grid, double, double, double, int)" ) - _get_ijk_xyz = EclPrototype( - "int ecl_grid_get_global_index_from_xyz(ecl_grid, double, double, double, int)" + _cell_contains = ResdataPrototype( + "bool rd_grid_cell_contains_xyz1(rd_grid, int, double, double, double)" ) - _cell_contains = EclPrototype( - "bool ecl_grid_cell_contains_xyz1(ecl_grid, int, double, double, double)" + _cell_regular = ResdataPrototype("bool rd_grid_cell_regular1(rd_grid, int)") + _num_lgr = ResdataPrototype("int rd_grid_get_num_lgr(rd_grid)") + _has_numbered_lgr = ResdataPrototype("bool rd_grid_has_lgr_nr(rd_grid, int)") + _has_named_lgr = ResdataPrototype("bool rd_grid_has_lgr(rd_grid, char*)") + _grid_value = ResdataPrototype( + "double rd_grid_get_property(rd_grid, rd_kw, int, int, int)" ) - _cell_regular = EclPrototype("bool ecl_grid_cell_regular1(ecl_grid, int)") - _num_lgr = EclPrototype("int ecl_grid_get_num_lgr(ecl_grid)") - _has_numbered_lgr = EclPrototype("bool ecl_grid_has_lgr_nr(ecl_grid, int)") - _has_named_lgr = EclPrototype("bool ecl_grid_has_lgr(ecl_grid, char*)") - _grid_value = EclPrototype( - "double ecl_grid_get_property(ecl_grid, ecl_kw, int, int, int)" + _get_cell_volume = ResdataPrototype("double rd_grid_get_cell_volume1(rd_grid, int)") + _get_cell_thickness = ResdataPrototype( + "double rd_grid_get_cell_thickness1(rd_grid, int)" ) - _get_cell_volume = EclPrototype("double ecl_grid_get_cell_volume1(ecl_grid, int)") - _get_cell_thickness = EclPrototype( - "double ecl_grid_get_cell_thickness1(ecl_grid, int)" + _get_cell_dx = ResdataPrototype("double rd_grid_get_cell_dx1(rd_grid, int)") + _get_cell_dy = ResdataPrototype("double rd_grid_get_cell_dy1(rd_grid, int)") + _get_depth = ResdataPrototype("double rd_grid_get_cdepth1(rd_grid, int)") + _fwrite_grdecl = ResdataPrototype( + "void rd_grid_grdecl_fprintf_kw(rd_grid, rd_kw, char*, FILE, double)" ) - _get_cell_dx = EclPrototype("double ecl_grid_get_cell_dx1(ecl_grid, int)") - _get_cell_dy = EclPrototype("double ecl_grid_get_cell_dy1(ecl_grid, int)") - _get_depth = EclPrototype("double ecl_grid_get_cdepth1(ecl_grid, int)") - _fwrite_grdecl = EclPrototype( - "void ecl_grid_grdecl_fprintf_kw(ecl_grid, ecl_kw, char*, FILE, double)" + _load_column = ResdataPrototype( + "void rd_grid_get_column_property(rd_grid, rd_kw, int, int, double_vector)" ) - _load_column = EclPrototype( - "void ecl_grid_get_column_property(ecl_grid, ecl_kw, int, int, double_vector)" + _get_top = ResdataPrototype("double rd_grid_get_top2(rd_grid, int, int)") + _get_top1A = ResdataPrototype("double rd_grid_get_top1A(rd_grid, int)") + _get_bottom = ResdataPrototype("double rd_grid_get_bottom2(rd_grid, int, int)") + _locate_depth = ResdataPrototype( + "int rd_grid_locate_depth(rd_grid, double, int, int)" ) - _get_top = EclPrototype("double ecl_grid_get_top2(ecl_grid, int, int)") - _get_top1A = EclPrototype("double ecl_grid_get_top1A(ecl_grid, int)") - _get_bottom = EclPrototype("double ecl_grid_get_bottom2(ecl_grid, int, int)") - _locate_depth = EclPrototype( - "int ecl_grid_locate_depth(ecl_grid, double, int, int)" + _invalid_cell = ResdataPrototype("bool rd_grid_cell_invalid1(rd_grid, int)") + _valid_cell = ResdataPrototype("bool rd_grid_cell_valid1(rd_grid, int)") + _get_distance = ResdataPrototype( + "void rd_grid_get_distance(rd_grid, int, int, double*, double*, double*)" ) - _invalid_cell = EclPrototype("bool ecl_grid_cell_invalid1(ecl_grid, int)") - _valid_cell = EclPrototype("bool ecl_grid_cell_valid1(ecl_grid, int)") - _get_distance = EclPrototype( - "void ecl_grid_get_distance(ecl_grid, int, int, double*, double*, double*)" + _fprintf_grdecl2 = ResdataPrototype( + "void rd_grid_fprintf_grdecl2(rd_grid, FILE, rd_unit_enum) " ) - _fprintf_grdecl2 = EclPrototype( - "void ecl_grid_fprintf_grdecl2(ecl_grid, FILE, ecl_unit_enum) " + _fwrite_GRID2 = ResdataPrototype( + "void rd_grid_fwrite_GRID2(rd_grid, char*, rd_unit_enum)" ) - _fwrite_GRID2 = EclPrototype( - "void ecl_grid_fwrite_GRID2(ecl_grid, char*, ecl_unit_enum)" + _fwrite_EGRID2 = ResdataPrototype( + "void rd_grid_fwrite_EGRID2(rd_grid, char*, rd_unit_enum)" ) - _fwrite_EGRID2 = EclPrototype( - "void ecl_grid_fwrite_EGRID2(ecl_grid, char*, ecl_unit_enum)" + _equal = ResdataPrototype("bool rd_grid_compare(rd_grid, rd_grid, bool, bool)") + _dual_grid = ResdataPrototype("bool rd_grid_dual_grid(rd_grid)") + _init_actnum = ResdataPrototype("void rd_grid_init_actnum_data(rd_grid, int*)") + _compressed_kw_copy = ResdataPrototype( + "void rd_grid_compressed_kw_copy(rd_grid, rd_kw, rd_kw)" ) - _equal = EclPrototype("bool ecl_grid_compare(ecl_grid, ecl_grid, bool, bool)") - _dual_grid = EclPrototype("bool ecl_grid_dual_grid(ecl_grid)") - _init_actnum = EclPrototype("void ecl_grid_init_actnum_data(ecl_grid, int*)") - _compressed_kw_copy = EclPrototype( - "void ecl_grid_compressed_kw_copy(ecl_grid, ecl_kw, ecl_kw)" + _global_kw_copy = ResdataPrototype( + "void rd_grid_global_kw_copy(rd_grid, rd_kw, rd_kw)" ) - _global_kw_copy = EclPrototype( - "void ecl_grid_global_kw_copy(ecl_grid, ecl_kw, ecl_kw)" + _create_volume_keyword = ResdataPrototype( + "rd_kw_obj rd_grid_alloc_volume_kw(rd_grid, bool)" ) - _create_volume_keyword = EclPrototype( - "ecl_kw_obj ecl_grid_alloc_volume_kw(ecl_grid, bool)" + _use_mapaxes = ResdataPrototype("bool rd_grid_use_mapaxes(rd_grid)") + _export_coord = ResdataPrototype("rd_kw_obj rd_grid_alloc_coord_kw(rd_grid)") + _export_zcorn = ResdataPrototype("rd_kw_obj rd_grid_alloc_zcorn_kw(rd_grid)") + _export_actnum = ResdataPrototype("rd_kw_obj rd_grid_alloc_actnum_kw(rd_grid)") + _export_mapaxes = ResdataPrototype("rd_kw_obj rd_grid_alloc_mapaxes_kw(rd_grid)") + _get_unit_system = ResdataPrototype("rd_unit_enum rd_grid_get_unit_system(rd_grid)") + _export_index_frame = ResdataPrototype( + "void rd_grid_export_index(rd_grid, int*, int*, bool)" ) - _use_mapaxes = EclPrototype("bool ecl_grid_use_mapaxes(ecl_grid)") - _export_coord = EclPrototype("ecl_kw_obj ecl_grid_alloc_coord_kw(ecl_grid)") - _export_zcorn = EclPrototype("ecl_kw_obj ecl_grid_alloc_zcorn_kw(ecl_grid)") - _export_actnum = EclPrototype("ecl_kw_obj ecl_grid_alloc_actnum_kw(ecl_grid)") - _export_mapaxes = EclPrototype("ecl_kw_obj ecl_grid_alloc_mapaxes_kw(ecl_grid)") - _get_unit_system = EclPrototype("ecl_unit_enum ecl_grid_get_unit_system(ecl_grid)") - _export_index_frame = EclPrototype( - "void ecl_grid_export_index(ecl_grid, int*, int*, bool)" + _export_data_as_int = ResdataPrototype( + "void rd_grid_export_data_as_int(int, int*, rd_kw, int*)", bind=False ) - _export_data_as_int = EclPrototype( - "void ecl_grid_export_data_as_int(int, int*, ecl_kw, int*)", bind=False + _export_data_as_double = ResdataPrototype( + "void rd_grid_export_data_as_double(int, int*, rd_kw, double*)", bind=False ) - _export_data_as_double = EclPrototype( - "void ecl_grid_export_data_as_double(int, int*, ecl_kw, double*)", bind=False + _export_volume = ResdataPrototype( + "void rd_grid_export_volume(rd_grid, int, int*, double*)" ) - _export_volume = EclPrototype( - "void ecl_grid_export_volume(ecl_grid, int, int*, double*)" + _export_position = ResdataPrototype( + "void rd_grid_export_position(rd_grid, int, int*, double*)" ) - _export_position = EclPrototype( - "void ecl_grid_export_position(ecl_grid, int, int*, double*)" + _export_corners = ResdataPrototype( + "void export_corners(rd_grid, int, int*, double*)" ) - _export_corners = EclPrototype("void export_corners(ecl_grid, int, int*, double*)") @classmethod def load_from_grdecl(cls, filename): - """Will create a new EclGrid instance from grdecl file. + """Will create a new Grid instance from grdecl file. This function will scan the input file @filename and look for the keywords required to build a grid. The following keywords @@ -193,61 +203,61 @@ def load_from_grdecl(cls, filename): Slightly more exotic grid concepts like dual porosity, NNC mapping, LGR and coarsened cells will be completely ignored; if you need such concepts you must have an EGRID file and use - the default EclGrid() constructor - that is also considerably + the default Grid() constructor - that is also considerably faster. """ if os.path.isfile(filename): with copen(filename) as f: - specgrid = EclKW.read_grdecl( - f, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False + specgrid = ResdataKW.read_grdecl( + f, "SPECGRID", rd_type=ResDataType.RD_INT, strict=False ) - zcorn = EclKW.read_grdecl(f, "ZCORN") - coord = EclKW.read_grdecl(f, "COORD") + zcorn = ResdataKW.read_grdecl(f, "ZCORN") + coord = ResdataKW.read_grdecl(f, "COORD") try: - actnum = EclKW.read_grdecl( - f, "ACTNUM", ecl_type=EclDataType.ECL_INT + actnum = ResdataKW.read_grdecl( + f, "ACTNUM", rd_type=ResDataType.RD_INT ) except ValueError: actnum = None try: - mapaxes = EclKW.read_grdecl(f, "MAPAXES") + mapaxes = ResdataKW.read_grdecl(f, "MAPAXES") except ValueError: mapaxes = None - return EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes) + return Grid.create(specgrid, zcorn, coord, actnum, mapaxes) else: raise IOError("No such file:%s" % filename) @classmethod def load_from_file(cls, filename): """ - Will inspect the @filename argument and create a new EclGrid instance. + Will inspect the @filename argument and create a new Grid instance. """ if FortIO.isFortranFile(filename): - return EclGrid(filename) + return Grid(filename) else: - return EclGrid.loadFromGrdecl(filename) + return Grid.loadFromGrdecl(filename) @classmethod def create(cls, specgrid, zcorn, coord, actnum, mapaxes=None): """ Create a new grid instance from existing keywords. - This is a class method which can be used to create an EclGrid - instance based on the EclKW instances @specgrid, @zcorn, - @coord and @actnum. An ECLIPSE EGRID file contains the + This is a class method which can be used to create an Grid + instance based on the ResdataKW instances @specgrid, @zcorn, + @coord and @actnum. An EGRID file contains the SPECGRID, ZCORN, COORD and ACTNUM keywords, so a somewhat - involved way to create a EclGrid instance could be: + involved way to create a Grid instance could be: - file = ecl.EclFile("ECLIPSE.EGRID") - specgrid_kw = file.iget_named_kw("SPECGRID", 0) - zcorn_kw = file.iget_named_kw("ZCORN", 0) - coord_kw = file.iget_named_kw("COORD", 0) - actnum_kw = file.iget_named_kw("ACTNUM", 0) + >> file = resdata.ResdataFile("CASE.EGRID") + >> specgrid_kw = file.iget_named_kw("SPECGRID", 0) + >> zcorn_kw = file.iget_named_kw("ZCORN", 0) + >> coord_kw = file.iget_named_kw("COORD", 0) + >> actnum_kw = file.iget_named_kw("ACTNUM", 0) - grid = EclGrid.create(specgrid_kw, zcorn_kw, coord_kw, actnum_kw) + >> grid = Grid.create(specgrid_kw, zcorn_kw, coord_kw, actnum_kw) If you are so inclined ... """ @@ -264,13 +274,13 @@ def create_rectangular(cls, dims, dV, actnum=None): """ warnings.warn( - "EclGrid.createRectangular is deprecated. " - + "Please use the similar method: EclGridGenerator.createRectangular.", + "Grid.createRectangular is deprecated. " + + "Please use the similar method: GridGenerator.createRectangular.", DeprecationWarning, ) if actnum is None: - ecl_grid = cls._alloc_rectangular( + rd_grid = cls._alloc_rectangular( dims[0], dims[1], dims[2], dV[0], dV[1], dV[2], None ) else: @@ -285,16 +295,16 @@ def create_rectangular(cls, dims, dV, actnum=None): "ACTNUM size mismatch: len(ACTNUM):%d Expected:%d" % (len(actnum), dims[0] * dims[1] * dims[2]) ) - ecl_grid = cls._alloc_rectangular( + rd_grid = cls._alloc_rectangular( dims[0], dims[1], dims[2], dV[0], dV[1], dV[2], actnum.getDataPtr() ) # If we have not succeeded in creatin the grid we *assume* the # error is due to a failed malloc. - if ecl_grid is None: + if rd_grid is None: raise MemoryError("Failed to allocated regualar grid") - return ecl_grid + return rd_grid def __init__(self, filename, apply_mapaxes=True): """ @@ -302,7 +312,7 @@ def __init__(self, filename, apply_mapaxes=True): """ c_ptr = self._fread_alloc(filename, apply_mapaxes) if c_ptr: - super(EclGrid, self).__init__(c_ptr) + super(Grid, self).__init__(c_ptr) else: raise IOError("Loading grid from:%s failed" % filename) @@ -318,7 +328,7 @@ def _nicename(self): def __repr__(self): """Returns, e.g.: - EclGrid("NORNE_ATW2013.EGRID", 46x112x22, global_size=113344, active_size=44431) at 0x28c4a70 + Grid("NORNE_ATW2013.EGRID", 46x112x22, global_size=113344, active_size=44431) at 0x28c4a70 """ name = self._nicename() if name: @@ -340,8 +350,8 @@ def equal(self, other, include_lgr=True, include_nnc=False, verbose=False): """ Compare the current grid with the other grid. """ - if not isinstance(other, EclGrid): - raise TypeError("The other argument must be an EclGrid instance") + if not isinstance(other, Grid): + raise TypeError("The other argument must be an Grid instance") return self._equal(other, include_lgr, include_nnc, verbose) def dual_grid(self): @@ -502,7 +512,7 @@ def __global_index(self, active_index=None, global_index=None, ijk=None): index. Exactly one of the arguments @active_index, @global_index or @ijk must be supplied. - The method is used extensively internally in the EclGrid + The method is used extensively internally in the Grid class; most methods which take coordinate input pass through this method to normalize the coordinate representation. """ @@ -670,7 +680,7 @@ def get_xyz(self, active_index=None, global_index=None, ijk=None): active_index : A number in the range [0,nactive). - For many of the EclGrid methods a cell can be specified using + For many of the Grid methods a cell can be specified using any of these three methods. Observe that one and only method is allowed: @@ -682,7 +692,7 @@ def get_xyz(self, active_index=None, global_index=None, ijk=None): pos3 = grid.get_xyz(ijk=(10,20,7), global_index=10) pos4 = grid.get_xyz() - All the indices in the EclGrid() class are zero offset, this + All the indices in the Grid() class are zero offset, this is in contrast to ECLIPSE which has an offset 1 interface. """ gi = self.__global_index( @@ -955,7 +965,7 @@ def find_cell_corner_xy(self, x, y, k): def cell_regular(self, active_index=None, global_index=None, ijk=None): """ - The ECLIPSE grid models often contain various degenerate cells, + The grid models often contain various degenerate cells, which are twisted, have overlapping corners or what not. This function gives a moderate sanity check on a cell, essentially what the function does is to check if the cell contains it's @@ -1033,9 +1043,9 @@ def has_lgr(self, lgr_name): return False def get_lgr(self, lgr_key): - """Get EclGrid instance with LGR content. + """Get Grid instance with LGR content. - Return an EclGrid instance based on the LGR @lgr, the input + Return an Grid instance based on the LGR @lgr, the input argument can either be the name of an LGR or the grid number of the LGR. The LGR grid instance is mostly like an ordinary grid instance; the only difference is that it can not be used @@ -1061,7 +1071,7 @@ def get_lgr(self, lgr_key): def get_cell_lgr(self, active_index=None, global_index=None, ijk=None): """ - Get EclGrid instance located in cell. + Get Grid instance located in cell. Will query the current grid instance if the cell given by @active_index, @global_index or @ijk has been refined with an @@ -1084,7 +1094,7 @@ def grid_value(self, kw, i, j, k): """ Will evalute @kw in location (@i,@j,@k). - The ECLIPSE properties and solution vectors are stored in + The grid properties and solution vectors are stored in restart and init files as 1D vectors of length nx*nx*nz or nactive. The grid_value() method is a minor convenience function to convert the (@i,@j,@k) input values to an @@ -1115,10 +1125,10 @@ def load_column(self, kw, i, j, column): def create_kw(self, array, kw_name, pack): """ - Creates an EclKW instance based on existing 3D numpy object. + Creates an ResdataKW instance based on existing 3D numpy object. The method create3D() does the inverse operation; creating a - 3D numpy object from an EclKW instance. If the argument @pack + 3D numpy object from an ResdataKW instance. If the argument @pack is true the resulting keyword will have length 'nactive', otherwise the element will have length nx*ny*nz. """ @@ -1131,13 +1141,13 @@ def create_kw(self, array, kw_name, pack): ): dtype = array.dtype if dtype == numpy.int32: - type = EclDataType.ECL_INT + type = ResDataType.RD_INT elif dtype == numpy.float32: - type = EclDataType.ECL_FLOAT + type = ResDataType.RD_FLOAT elif dtype == numpy.float64: - type = EclDataType.ECL_DOUBLE + type = ResDataType.RD_DOUBLE else: - sys.exit("Do not know how to create ecl_kw from type:%s" % dtype) + sys.exit("Do not know how to create rd_kw from type:%s" % dtype) if pack: size = self.getNumActive() @@ -1145,10 +1155,10 @@ def create_kw(self, array, kw_name, pack): size = self.getGlobalSize() if len(kw_name) > 8: - # Silently truncate to length 8 - ECLIPSE has it's challenges. + # Silently truncate to length 8 kw_name = kw_name[0:8] - kw = EclKW(kw_name, size, type) + kw = ResdataKW(kw_name, size, type) active_index = 0 global_index = 0 for k in range(self.getNZ()): @@ -1183,29 +1193,29 @@ def in_coarse_group(self, global_index=None, ijk=None, active_index=None): ) return self._in_coarse_group1(global_index) - def create_3d(self, ecl_kw, default=0): + def create_3d(self, rd_kw, default=0): """ - Creates a 3D numpy array object with the data from @ecl_kw. + Creates a 3D numpy array object with the data from @rd_kw. Observe that 3D numpy object is a copy of the data in the - EclKW instance, i.e. modification to the numpy object will not - be reflected in the ECLIPSE keyword. + ResdataKW instance, i.e. modification to the numpy object will not + be reflected in the keyword. The methods createKW() does the inverse operation; creating an - EclKW instance from a 3D numpy object. + ResdataKW instance from a 3D numpy object. Alternative: Creating the numpy array object is not very efficient; if you only need a limited number of elements from - the ecl_kw instance it might be wiser to use the grid_value() + the rd_kw instance it might be wiser to use the grid_value() method: - value = grid.grid_value(ecl_kw, i, j, k) + value = grid.grid_value(rd_kw, i, j, k) """ - if len(ecl_kw) == self.getNumActive() or len(ecl_kw) == self.getGlobalSize(): - array = numpy.ones([self.getGlobalSize()], dtype=ecl_kw.dtype) * default - kwa = ecl_kw.array - if len(ecl_kw) == self.getGlobalSize(): + if len(rd_kw) == self.getNumActive() or len(rd_kw) == self.getGlobalSize(): + array = numpy.ones([self.getGlobalSize()], dtype=rd_kw.dtype) * default + kwa = rd_kw.array + if len(rd_kw) == self.getGlobalSize(): for i in range(kwa.size): array[i] = kwa[i] else: @@ -1218,14 +1228,14 @@ def create_3d(self, ecl_kw, default=0): else: err_msg_fmt = 'Keyword "%s" has invalid size %d; must be either nactive=%d or nx*ny*nz=%d' err_msg = err_msg_fmt % ( - ecl_kw, - len(ecl_kw), + rd_kw, + len(rd_kw), self.getNumActive(), self.getGlobalSize(), ) raise ValueError(err_msg) - def save_grdecl(self, pyfile, output_unit=EclUnitTypeEnum.ECL_METRIC_UNITS): + def save_grdecl(self, pyfile, output_unit=UnitSystem.METRIC): """ Will write the the grid content as grdecl formatted keywords. @@ -1239,22 +1249,22 @@ def save_EGRID(self, filename, output_unit=None): output_unit = self.unit_system self._fwrite_EGRID2(filename, output_unit) - def save_GRID(self, filename, output_unit=EclUnitTypeEnum.ECL_METRIC_UNITS): + def save_GRID(self, filename, output_unit=UnitSystem.METRIC): """ Will save the current grid as a GRID file. """ self._fwrite_GRID2(filename, output_unit) - def write_grdecl(self, ecl_kw, pyfile, special_header=None, default_value=0): + def write_grdecl(self, rd_kw, pyfile, special_header=None, default_value=0): """ - Writes an EclKW instance as an ECLIPSE grdecl formatted file. + Writes an ResdataKW instance as an ECLIPSE grdecl formatted file. - The input argument @ecl_kw must be an EclKW instance of size + The input argument @rd_kw must be an ResdataKW instance of size nactive or nx*ny*nz. If the size is nactive the inactive cells will be filled with @default_value; hence the function will always write nx*ny*nz elements. - The data in the @ecl_kw argument can be of type integer, + The data in the @rd_kw argument can be of type integer, float, double or bool. In the case of bool the default value must be specified as 1 (True) or 0 (False). @@ -1268,15 +1278,15 @@ def write_grdecl(self, ecl_kw, pyfile, special_header=None, default_value=0): """ - if len(ecl_kw) == self.getNumActive() or len(ecl_kw) == self.getGlobalSize(): + if len(rd_kw) == self.getNumActive() or len(rd_kw) == self.getGlobalSize(): cfile = CFILE(pyfile) - self._fwrite_grdecl(ecl_kw, special_header, cfile, default_value) + self._fwrite_grdecl(rd_kw, special_header, cfile, default_value) else: raise ValueError( "Keyword: %s has invalid size(%d), must be either nactive:%d or nx*ny*nz:%d" % ( - ecl_kw.getName(), - len(ecl_kw), + rd_kw.getName(), + len(rd_kw), self.getNumActive(), self.getGlobalSize(), ) @@ -1291,7 +1301,7 @@ def compressed_kw_copy(self, kw): if len(kw) == self.getNumActive(): return kw.copy() elif len(kw) == self.getGlobalSize(): - kw_copy = EclKW(kw.getName(), self.getNumActive(), kw.data_type) + kw_copy = ResdataKW(kw.getName(), self.getNumActive(), kw.data_type) self._compressed_kw_copy(kw_copy, kw) return kw_copy else: @@ -1304,7 +1314,7 @@ def global_kw_copy(self, kw, default_value): if len(kw) == self.getGlobalSize(): return kw.copy() elif len(kw) == self.getNumActive(): - kw_copy = EclKW(kw.getName(), self.getGlobalSize(), kw.data_type) + kw_copy = ResdataKW(kw.getName(), self.getGlobalSize(), kw.data_type) kw_copy.assign(default_value) self._global_kw_copy(kw_copy, kw) return kw_copy @@ -1315,14 +1325,14 @@ def global_kw_copy(self, kw, default_value): ) def export_ACTNUM_kw(self): - actnum = EclKW("ACTNUM", self.getGlobalSize(), EclDataType.ECL_INT) + actnum = ResdataKW("ACTNUM", self.getGlobalSize(), ResDataType.RD_INT) self._init_actnum(actnum.getDataPtr()) return actnum def create_volume_keyword(self, active_size=True): - """Will create a EclKW initialized with cell volumes. + """Will create a ResdataKW initialized with cell volumes. - The purpose of this method is to create a EclKW instance which + The purpose of this method is to create a ResdataKW instance which is initialized with all the cell volumes, this can then be used to perform volume summation; i.e. to calculate the total oil volume: @@ -1395,7 +1405,7 @@ def export_data(self, index_frame, kw, default=0): else: raise ValueError("The keyword must have a 3D compatible length") - if kw.type is EclTypeEnum.ECL_INT_TYPE: + if kw.type is ResdataTypeEnum.RD_INT_TYPE: data = numpy.full(len(index), default, dtype=numpy.int32) self._export_data_as_int( len(index), @@ -1405,8 +1415,8 @@ def export_data(self, index_frame, kw, default=0): ) return data elif ( - kw.type is EclTypeEnum.ECL_FLOAT_TYPE - or kw.type is EclTypeEnum.ECL_DOUBLE_TYPE + kw.type is ResdataTypeEnum.RD_FLOAT_TYPE + or kw.type is ResdataTypeEnum.RD_DOUBLE_TYPE ): data = numpy.full(len(index), default, dtype=numpy.float64) self._export_data_as_double( @@ -1515,31 +1525,31 @@ def unit_system(self): return self._get_unit_system() -monkey_the_camel(EclGrid, "loadFromGrdecl", EclGrid.load_from_grdecl, classmethod) -monkey_the_camel(EclGrid, "loadFromFile", EclGrid.load_from_file, classmethod) -monkey_the_camel(EclGrid, "createRectangular", EclGrid.create_rectangular, classmethod) -monkey_the_camel(EclGrid, "dualGrid", EclGrid.dual_grid) -monkey_the_camel(EclGrid, "getDims", EclGrid.get_dims) -monkey_the_camel(EclGrid, "getNX", EclGrid.get_nx) -monkey_the_camel(EclGrid, "getNY", EclGrid.get_ny) -monkey_the_camel(EclGrid, "getNZ", EclGrid.get_nz) -monkey_the_camel(EclGrid, "getGlobalSize", EclGrid.get_global_size) -monkey_the_camel(EclGrid, "getNumActive", EclGrid.get_num_active) -monkey_the_camel(EclGrid, "getNumActiveFracture", EclGrid.get_num_active_fracture) -monkey_the_camel(EclGrid, "getBoundingBox2D", EclGrid.get_bounding_box_2d) -monkey_the_camel(EclGrid, "getName", EclGrid.get_name) -monkey_the_camel(EclGrid, "validCellGeometry", EclGrid.valid_cell_geometry) -monkey_the_camel(EclGrid, "getNodePos", EclGrid.get_node_pos) -monkey_the_camel(EclGrid, "getCellCorner", EclGrid.get_cell_corner) -monkey_the_camel(EclGrid, "getNodeXYZ", EclGrid.get_node_xyz) -monkey_the_camel(EclGrid, "getLayerXYZ", EclGrid.get_layer_xyz) -monkey_the_camel(EclGrid, "findCellXY", EclGrid.find_cell_xy) -monkey_the_camel(EclGrid, "findCellCornerXY", EclGrid.find_cell_corner_xy) -monkey_the_camel(EclGrid, "getCellDims", EclGrid.get_cell_dims) -monkey_the_camel(EclGrid, "getNumLGR", EclGrid.get_num_lgr) -monkey_the_camel(EclGrid, "createKW", EclGrid.create_kw) -monkey_the_camel(EclGrid, "create3D", EclGrid.create_3d) -monkey_the_camel(EclGrid, "compressedKWCopy", EclGrid.compressed_kw_copy) -monkey_the_camel(EclGrid, "globalKWCopy", EclGrid.global_kw_copy) -monkey_the_camel(EclGrid, "exportACTNUMKw", EclGrid.export_ACTNUM_kw) -monkey_the_camel(EclGrid, "createVolumeKeyword", EclGrid.create_volume_keyword) +monkey_the_camel(Grid, "loadFromGrdecl", Grid.load_from_grdecl, classmethod) +monkey_the_camel(Grid, "loadFromFile", Grid.load_from_file, classmethod) +monkey_the_camel(Grid, "createRectangular", Grid.create_rectangular, classmethod) +monkey_the_camel(Grid, "dualGrid", Grid.dual_grid) +monkey_the_camel(Grid, "getDims", Grid.get_dims) +monkey_the_camel(Grid, "getNX", Grid.get_nx) +monkey_the_camel(Grid, "getNY", Grid.get_ny) +monkey_the_camel(Grid, "getNZ", Grid.get_nz) +monkey_the_camel(Grid, "getGlobalSize", Grid.get_global_size) +monkey_the_camel(Grid, "getNumActive", Grid.get_num_active) +monkey_the_camel(Grid, "getNumActiveFracture", Grid.get_num_active_fracture) +monkey_the_camel(Grid, "getBoundingBox2D", Grid.get_bounding_box_2d) +monkey_the_camel(Grid, "getName", Grid.get_name) +monkey_the_camel(Grid, "validCellGeometry", Grid.valid_cell_geometry) +monkey_the_camel(Grid, "getNodePos", Grid.get_node_pos) +monkey_the_camel(Grid, "getCellCorner", Grid.get_cell_corner) +monkey_the_camel(Grid, "getNodeXYZ", Grid.get_node_xyz) +monkey_the_camel(Grid, "getLayerXYZ", Grid.get_layer_xyz) +monkey_the_camel(Grid, "findCellXY", Grid.find_cell_xy) +monkey_the_camel(Grid, "findCellCornerXY", Grid.find_cell_corner_xy) +monkey_the_camel(Grid, "getCellDims", Grid.get_cell_dims) +monkey_the_camel(Grid, "getNumLGR", Grid.get_num_lgr) +monkey_the_camel(Grid, "createKW", Grid.create_kw) +monkey_the_camel(Grid, "create3D", Grid.create_3d) +monkey_the_camel(Grid, "compressedKWCopy", Grid.compressed_kw_copy) +monkey_the_camel(Grid, "globalKWCopy", Grid.global_kw_copy) +monkey_the_camel(Grid, "exportACTNUMKw", Grid.export_ACTNUM_kw) +monkey_the_camel(Grid, "createVolumeKeyword", Grid.create_volume_keyword) diff --git a/python/ecl/grid/ecl_grid_generator.py b/python/resdata/grid/rd_grid_generator.py similarity index 95% rename from python/ecl/grid/ecl_grid_generator.py rename to python/resdata/grid/rd_grid_generator.py index c730fb6c12..44f9a958fd 100644 --- a/python/ecl/grid/ecl_grid_generator.py +++ b/python/resdata/grid/rd_grid_generator.py @@ -1,12 +1,12 @@ import itertools, numpy from math import sqrt -from ecl import EclPrototype -from ecl.util.util import monkey_the_camel -from ecl.util.util import IntVector -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid +from resdata import ResdataPrototype +from resdata.util.util import monkey_the_camel +from resdata.util.util import IntVector +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid def flatten(l): @@ -22,7 +22,7 @@ def duplicate_inner(l): def construct_floatKW(name, values): - kw = EclKW(name, len(values), EclDataType.ECL_FLOAT) + kw = ResdataKW(name, len(values), ResDataType.RD_FLOAT) for i, value in enumerate(values): kw[i] = value return kw @@ -49,9 +49,9 @@ def pre_mapaxes_translation(translation, mapaxes): ) -class EclGridGenerator: - _alloc_rectangular = EclPrototype( - "ecl_grid_obj ecl_grid_alloc_rectangular(int, int, int, double, double, double, int*)", +class GridGenerator: + _alloc_rectangular = ResdataPrototype( + "rd_grid_obj rd_grid_alloc_rectangular(int, int, int, double, double, double, int*)", bind=False, ) @@ -63,7 +63,7 @@ def create_rectangular(cls, dims, dV, actnum=None): With the default value @actnum == None all cells will be active, """ if actnum is None: - ecl_grid = cls._alloc_rectangular( + rd_grid = cls._alloc_rectangular( dims[0], dims[1], dims[2], dV[0], dV[1], dV[2], None ) else: @@ -79,16 +79,16 @@ def create_rectangular(cls, dims, dV, actnum=None): % (len(actnum), dims[0] * dims[1] * dims[2]) ) - ecl_grid = cls._alloc_rectangular( + rd_grid = cls._alloc_rectangular( dims[0], dims[1], dims[2], dV[0], dV[1], dV[2], actnum.getDataPtr() ) # If we have not succeeded in creatin the grid we *assume* the # error is due to a failed malloc. - if ecl_grid is None: + if rd_grid is None: raise MemoryError("Failed to allocated regualar grid") - return ecl_grid + return rd_grid @classmethod def create_single_cell_grid(cls, corners): @@ -104,12 +104,12 @@ def create_single_cell_grid(cls, corners): coord = flatten(flatten(coord)) def construct_floatKW(name, values): - kw = EclKW(name, len(values), EclDataType.ECL_FLOAT) + kw = ResdataKW(name, len(values), ResDataType.RD_FLOAT) for i in range(len(values)): kw[i] = values[i] return kw - grid = EclGrid.create( + grid = Grid.create( (1, 1, 1), construct_floatKW("ZCORN", zcorn), construct_floatKW("COORD", coord), @@ -288,7 +288,7 @@ def create_grid( particular, if set to False, all cells of the grid will be concave. @escape_origo_shift is used to prevent any cell of having corners in (0,0,z) - as there is a heuristic in ecl_grid.c that marks such cells as tainted. + as there is a heuristic in rd_grid.c that marks such cells as tainted. @faults decides if there are to be faults in the grid. @@ -329,7 +329,7 @@ def create_grid( dims, dV, escape_origo_shift, scale, translation, rotate, misalign ) - return EclGrid.create(dims, zcorn, coord, None) + return Grid.create(dims, zcorn, coord, None) @classmethod def __create_faults(cls, nx, ny, nz, zcorn, drop): @@ -564,7 +564,7 @@ def extract_actnum(cls, dims, actnum, ijk_bounds): new_actnum = flatten(new_actnum) cls.assert_actnum(new_nx, new_ny, new_nz, new_actnum) - actnumkw = EclKW("ACTNUM", len(new_actnum), EclDataType.ECL_INT) + actnumkw = ResdataKW("ACTNUM", len(new_actnum), ResDataType.RD_INT) for i, value in enumerate(new_actnum): actnumkw[i] = value @@ -596,7 +596,7 @@ def extract_subgrid( NOTE: The given bounds are including endpoints. - @decomposition_change: Depending on the given ijk_bounds, libecl might + @decomposition_change: Depending on the given ijk_bounds, resdata might decompose the cells of the subgrid differently when extracted from grid. This is somewhat unexpected behaviour and if this event occur we give an exception together with an description for how to avoid this, @@ -637,7 +637,7 @@ def extract_subgrid( sdim = tuple([b - a + 1 for a, b in ijk_bounds]) sub_coord, sub_zcorn, sub_actnum = sub_data - return EclGrid.create(sdim, sub_zcorn, sub_coord, sub_actnum, mapaxes=mapaxes) + return Grid.create(sdim, sub_zcorn, sub_coord, sub_actnum, mapaxes=mapaxes) @classmethod def extract_subgrid_data( @@ -674,7 +674,7 @@ def extract_subgrid_data( @mapaxes The MAPAXES data of the grid. - @decomposition_change: Depending on the given ijk_bounds, libecl might + @decomposition_change: Depending on the given ijk_bounds, resdata might decompose the cells of the subgrid differently when extracted from grid. This is somewhat unexpected behaviour and if this event occur we give an exception together with an description for how to avoid this, @@ -757,8 +757,8 @@ def assert_decomposition_change(cls, ijk_bounds, decomposition_change): monkey_the_camel( - EclGridGenerator, + GridGenerator, "createRectangular", - EclGridGenerator.create_rectangular, + GridGenerator.create_rectangular, classmethod, ) diff --git a/python/ecl/grid/ecl_region.py b/python/resdata/grid/rd_region.py similarity index 60% rename from python/ecl/grid/ecl_region.py rename to python/resdata/grid/rd_region.py index 904c3efa18..eaf4144be8 100644 --- a/python/ecl/grid/ecl_region.py +++ b/python/resdata/grid/rd_region.py @@ -1,7 +1,7 @@ """ Module used to select cells based on many different criteria. -This module implements the class EclRegion which can be used to select +This module implements the class ResdataRegion which can be used to select cells in a grid matching a criteria. A wide range of different criteria are supported. Many of the special functions for implementing mathematical operations are implemented, so that regions can be @@ -15,15 +15,15 @@ from cwrap import BaseCClass -import ecl -from ecl.util.util import monkey_the_camel -from ecl.util.util import IntVector +import resdata +from resdata.util.util import monkey_the_camel +from resdata.util.util import IntVector -from ecl import EclPrototype -from ecl.grid.faults import Layer -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.util.geometry import CPolyline +from resdata import ResdataPrototype +from resdata.grid.faults import Layer +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.geometry import CPolyline def select_method(select): @@ -37,7 +37,7 @@ def select_method(select): Consider this example: - region = EclRegion( grid , False ) + region = ResdataRegion( grid , False ) region.select_islice(0, 5) # Selects all cells with i[0:5] region.select_jslice(0, 5) # Selects all cells with j[0:5] @@ -47,7 +47,7 @@ def select_method(select): second call the j selection will only be applied to the cells in i[0:5] interval: - region = EclRegion( grid , False ) + region = ResdataRegion( grid , False ) # Select all cells with i[0:5]: region.select_islice(0, 5) @@ -60,7 +60,7 @@ def select_method(select): def select_wrapper(self, *args, **kwargs): intersect = "intersect" in kwargs and kwargs["intersect"] if intersect: - new_region = EclRegion(self.grid, False) + new_region = ResdataRegion(self.grid, False) select(new_region, *args) self &= new_region @@ -70,241 +70,245 @@ def select_wrapper(self, *args, **kwargs): return select_wrapper -class EclRegion(BaseCClass): - TYPE_NAME = "ecl_region" - _alloc = EclPrototype("void* ecl_region_alloc( ecl_grid , bool )", bind=False) - _alloc_copy = EclPrototype("ecl_region_obj ecl_region_alloc_copy( ecl_region )") +class ResdataRegion(BaseCClass): + TYPE_NAME = "rd_region" + _alloc = ResdataPrototype("void* rd_region_alloc( rd_grid , bool )", bind=False) + _alloc_copy = ResdataPrototype("rd_region_obj rd_region_alloc_copy( rd_region )") - _set_kw_int = EclPrototype( - "void ecl_region_set_kw_int( ecl_region , ecl_kw , int, bool) " + _set_kw_int = ResdataPrototype( + "void rd_region_set_kw_int( rd_region , rd_kw , int, bool) " ) - _set_kw_float = EclPrototype( - "void ecl_region_set_kw_float( ecl_region , ecl_kw , float, bool ) " + _set_kw_float = ResdataPrototype( + "void rd_region_set_kw_float( rd_region , rd_kw , float, bool ) " ) - _set_kw_double = EclPrototype( - "void ecl_region_set_kw_double( ecl_region , ecl_kw , double , bool) " + _set_kw_double = ResdataPrototype( + "void rd_region_set_kw_double( rd_region , rd_kw , double , bool) " ) - _shift_kw_int = EclPrototype( - "void ecl_region_shift_kw_int( ecl_region , ecl_kw , int, bool) " + _shift_kw_int = ResdataPrototype( + "void rd_region_shift_kw_int( rd_region , rd_kw , int, bool) " ) - _shift_kw_float = EclPrototype( - "void ecl_region_shift_kw_float( ecl_region , ecl_kw , float, bool ) " + _shift_kw_float = ResdataPrototype( + "void rd_region_shift_kw_float( rd_region , rd_kw , float, bool ) " ) - _shift_kw_double = EclPrototype( - "void ecl_region_shift_kw_double( ecl_region , ecl_kw , double , bool) " + _shift_kw_double = ResdataPrototype( + "void rd_region_shift_kw_double( rd_region , rd_kw , double , bool) " ) - _scale_kw_int = EclPrototype( - "void ecl_region_scale_kw_int( ecl_region , ecl_kw , int, bool) " + _scale_kw_int = ResdataPrototype( + "void rd_region_scale_kw_int( rd_region , rd_kw , int, bool) " ) - _scale_kw_float = EclPrototype( - "void ecl_region_scale_kw_float( ecl_region , ecl_kw , float, bool ) " + _scale_kw_float = ResdataPrototype( + "void rd_region_scale_kw_float( rd_region , rd_kw , float, bool ) " ) - _scale_kw_double = EclPrototype( - "void ecl_region_scale_kw_double( ecl_region , ecl_kw , double , bool) " + _scale_kw_double = ResdataPrototype( + "void rd_region_scale_kw_double( rd_region , rd_kw , double , bool) " ) - _sum_kw_int = EclPrototype( - "int ecl_region_sum_kw_int( ecl_region , ecl_kw , bool) " + _sum_kw_int = ResdataPrototype( + "int rd_region_sum_kw_int( rd_region , rd_kw , bool) " ) - _sum_kw_float = EclPrototype( - "float ecl_region_sum_kw_float( ecl_region , ecl_kw , bool ) " + _sum_kw_float = ResdataPrototype( + "float rd_region_sum_kw_float( rd_region , rd_kw , bool ) " ) - _sum_kw_double = EclPrototype( - "double ecl_region_sum_kw_double( ecl_region , ecl_kw , bool) " + _sum_kw_double = ResdataPrototype( + "double rd_region_sum_kw_double( rd_region , rd_kw , bool) " ) - _sum_kw_bool = EclPrototype( - "int ecl_region_sum_kw_int( ecl_region , ecl_kw , bool) " + _sum_kw_bool = ResdataPrototype( + "int rd_region_sum_kw_int( rd_region , rd_kw , bool) " ) - _free = EclPrototype("void ecl_region_free( ecl_region )") - _reset = EclPrototype("void ecl_region_reset( ecl_region )") - _select_all = EclPrototype("void ecl_region_select_all( ecl_region )") - _deselect_all = EclPrototype("void ecl_region_deselect_all( ecl_region )") - _select_equal = EclPrototype( - "void ecl_region_select_equal( ecl_region , ecl_kw , int )" + _free = ResdataPrototype("void rd_region_free( rd_region )") + _reset = ResdataPrototype("void rd_region_reset( rd_region )") + _select_all = ResdataPrototype("void rd_region_select_all( rd_region )") + _deselect_all = ResdataPrototype("void rd_region_deselect_all( rd_region )") + _select_equal = ResdataPrototype( + "void rd_region_select_equal( rd_region , rd_kw , int )" ) - _deselect_equal = EclPrototype( - "void ecl_region_deselect_equal( ecl_region , ecl_kw , int)" + _deselect_equal = ResdataPrototype( + "void rd_region_deselect_equal( rd_region , rd_kw , int)" ) - _select_less = EclPrototype( - "void ecl_region_select_smaller( ecl_region , ecl_kw , float )" + _select_less = ResdataPrototype( + "void rd_region_select_smaller( rd_region , rd_kw , float )" ) - _deselect_less = EclPrototype( - "void ecl_region_deselect_smaller( ecl_region , ecl_kw , float )" + _deselect_less = ResdataPrototype( + "void rd_region_deselect_smaller( rd_region , rd_kw , float )" ) - _select_more = EclPrototype( - "void ecl_region_select_larger( ecl_region , ecl_kw , float )" + _select_more = ResdataPrototype( + "void rd_region_select_larger( rd_region , rd_kw , float )" ) - _deselect_more = EclPrototype( - "void ecl_region_deselect_larger( ecl_region , ecl_kw , float )" + _deselect_more = ResdataPrototype( + "void rd_region_deselect_larger( rd_region , rd_kw , float )" ) - _select_in_interval = EclPrototype( - "void ecl_region_select_in_interval( ecl_region, ecl_kw , float , float )" + _select_in_interval = ResdataPrototype( + "void rd_region_select_in_interval( rd_region, rd_kw , float , float )" ) - _deselect_in_interval = EclPrototype( - "void ecl_region_deselect_in_interval( ecl_region, ecl_kw, float , float )" + _deselect_in_interval = ResdataPrototype( + "void rd_region_deselect_in_interval( rd_region, rd_kw, float , float )" ) - _invert_selection = EclPrototype("void ecl_region_invert_selection( ecl_region )") + _invert_selection = ResdataPrototype("void rd_region_invert_selection( rd_region )") - _select_box = EclPrototype( - "void ecl_region_select_from_ijkbox(ecl_region , int , int , int , int , int , int)" + _select_box = ResdataPrototype( + "void rd_region_select_from_ijkbox(rd_region , int , int , int , int , int , int)" ) - _deselect_box = EclPrototype( - "void ecl_region_deselect_from_ijkbox(ecl_region , int , int , int , int , int , int)" + _deselect_box = ResdataPrototype( + "void rd_region_deselect_from_ijkbox(rd_region , int , int , int , int , int , int)" ) - _imul_kw = EclPrototype( - "void ecl_region_kw_imul( ecl_region , ecl_kw , ecl_kw , bool)" + _imul_kw = ResdataPrototype( + "void rd_region_kw_imul( rd_region , rd_kw , rd_kw , bool)" ) - _idiv_kw = EclPrototype( - "void ecl_region_kw_idiv( ecl_region , ecl_kw , ecl_kw , bool)" + _idiv_kw = ResdataPrototype( + "void rd_region_kw_idiv( rd_region , rd_kw , rd_kw , bool)" ) - _iadd_kw = EclPrototype( - "void ecl_region_kw_iadd( ecl_region , ecl_kw , ecl_kw , bool)" + _iadd_kw = ResdataPrototype( + "void rd_region_kw_iadd( rd_region , rd_kw , rd_kw , bool)" ) - _isub_kw = EclPrototype( - "void ecl_region_kw_isub( ecl_region , ecl_kw , ecl_kw , bool)" + _isub_kw = ResdataPrototype( + "void rd_region_kw_isub( rd_region , rd_kw , rd_kw , bool)" ) - _copy_kw = EclPrototype( - "void ecl_region_kw_copy( ecl_region , ecl_kw , ecl_kw , bool)" + _copy_kw = ResdataPrototype( + "void rd_region_kw_copy( rd_region , rd_kw , rd_kw , bool)" ) - _intersect = EclPrototype("void ecl_region_intersection( ecl_region , ecl_region )") - _combine = EclPrototype("void ecl_region_union( ecl_region , ecl_region )") - _subtract = EclPrototype("void ecl_region_subtract( ecl_region , ecl_region )") - _xor = EclPrototype("void ecl_region_xor( ecl_region , ecl_region )") - _get_kw_index_list = EclPrototype( - "int_vector_ref ecl_region_get_kw_index_list( ecl_region , ecl_kw , bool )" + _intersect = ResdataPrototype( + "void rd_region_intersection( rd_region , rd_region )" ) - _get_active_list = EclPrototype( - "int_vector_ref ecl_region_get_active_list( ecl_region )" + _combine = ResdataPrototype("void rd_region_union( rd_region , rd_region )") + _subtract = ResdataPrototype("void rd_region_subtract( rd_region , rd_region )") + _xor = ResdataPrototype("void rd_region_xor( rd_region , rd_region )") + _get_kw_index_list = ResdataPrototype( + "int_vector_ref rd_region_get_kw_index_list( rd_region , rd_kw , bool )" ) - _get_global_list = EclPrototype( - "int_vector_ref ecl_region_get_global_list( ecl_region )" + _get_active_list = ResdataPrototype( + "int_vector_ref rd_region_get_active_list( rd_region )" ) - _get_active_global = EclPrototype( - "int_vector_ref ecl_region_get_global_active_list( ecl_region )" + _get_global_list = ResdataPrototype( + "int_vector_ref rd_region_get_global_list( rd_region )" ) - _select_cmp_less = EclPrototype( - "void ecl_region_cmp_select_less( ecl_region , ecl_kw , ecl_kw)" + _get_active_global = ResdataPrototype( + "int_vector_ref rd_region_get_global_active_list( rd_region )" ) - _select_cmp_more = EclPrototype( - "void ecl_region_cmp_select_more( ecl_region , ecl_kw , ecl_kw)" + _select_cmp_less = ResdataPrototype( + "void rd_region_cmp_select_less( rd_region , rd_kw , rd_kw)" ) - _deselect_cmp_less = EclPrototype( - "void ecl_region_cmp_deselect_less( ecl_region , ecl_kw , ecl_kw)" + _select_cmp_more = ResdataPrototype( + "void rd_region_cmp_select_more( rd_region , rd_kw , rd_kw)" ) - _deselect_cmp_more = EclPrototype( - "void ecl_region_cmp_deselect_more( ecl_region , ecl_kw , ecl_kw)" + _deselect_cmp_less = ResdataPrototype( + "void rd_region_cmp_deselect_less( rd_region , rd_kw , rd_kw)" ) - _select_islice = EclPrototype( - "void ecl_region_select_i1i2( ecl_region , int , int )" + _deselect_cmp_more = ResdataPrototype( + "void rd_region_cmp_deselect_more( rd_region , rd_kw , rd_kw)" ) - _deselect_islice = EclPrototype( - "void ecl_region_deselect_i1i2( ecl_region , int , int )" + _select_islice = ResdataPrototype( + "void rd_region_select_i1i2( rd_region , int , int )" ) - _select_jslice = EclPrototype( - "void ecl_region_select_j1j2( ecl_region , int , int )" + _deselect_islice = ResdataPrototype( + "void rd_region_deselect_i1i2( rd_region , int , int )" ) - _deselect_jslice = EclPrototype( - "void ecl_region_deselect_j1j2( ecl_region , int , int )" + _select_jslice = ResdataPrototype( + "void rd_region_select_j1j2( rd_region , int , int )" ) - _select_kslice = EclPrototype( - "void ecl_region_select_k1k2( ecl_region , int , int )" + _deselect_jslice = ResdataPrototype( + "void rd_region_deselect_j1j2( rd_region , int , int )" ) - _deselect_kslice = EclPrototype( - "void ecl_region_deselect_k1k2( ecl_region , int , int )" + _select_kslice = ResdataPrototype( + "void rd_region_select_k1k2( rd_region , int , int )" ) - _select_deep_cells = EclPrototype( - "void ecl_region_select_deep_cells( ecl_region , double )" + _deselect_kslice = ResdataPrototype( + "void rd_region_deselect_k1k2( rd_region , int , int )" ) - _deselect_deep_cells = EclPrototype( - "void ecl_region_select_deep_cells( ecl_region , double )" + _select_deep_cells = ResdataPrototype( + "void rd_region_select_deep_cells( rd_region , double )" ) - _select_shallow_cells = EclPrototype( - "void ecl_region_select_shallow_cells( ecl_region , double )" + _deselect_deep_cells = ResdataPrototype( + "void rd_region_select_deep_cells( rd_region , double )" ) - _deselect_shallow_cells = EclPrototype( - "void ecl_region_select_shallow_cells( ecl_region , double )" + _select_shallow_cells = ResdataPrototype( + "void rd_region_select_shallow_cells( rd_region , double )" ) - _select_small = EclPrototype( - "void ecl_region_select_small_cells( ecl_region , double )" + _deselect_shallow_cells = ResdataPrototype( + "void rd_region_select_shallow_cells( rd_region , double )" ) - _deselect_small = EclPrototype( - "void ecl_region_deselect_small_cells( ecl_region , double )" + _select_small = ResdataPrototype( + "void rd_region_select_small_cells( rd_region , double )" ) - _select_large = EclPrototype( - "void ecl_region_select_large_cells( ecl_region , double )" + _deselect_small = ResdataPrototype( + "void rd_region_deselect_small_cells( rd_region , double )" ) - _deselect_large = EclPrototype( - "void ecl_region_deselect_large_cells( ecl_region , double )" + _select_large = ResdataPrototype( + "void rd_region_select_large_cells( rd_region , double )" ) - _select_thin = EclPrototype( - "void ecl_region_select_thin_cells( ecl_region , double )" + _deselect_large = ResdataPrototype( + "void rd_region_deselect_large_cells( rd_region , double )" ) - _deselect_thin = EclPrototype( - "void ecl_region_deselect_thin_cells( ecl_region , double )" + _select_thin = ResdataPrototype( + "void rd_region_select_thin_cells( rd_region , double )" ) - _select_thick = EclPrototype( - "void ecl_region_select_thick_cells( ecl_region , double )" + _deselect_thin = ResdataPrototype( + "void rd_region_deselect_thin_cells( rd_region , double )" ) - _deselect_thick = EclPrototype( - "void ecl_region_deselect_thick_cells( ecl_region , double )" + _select_thick = ResdataPrototype( + "void rd_region_select_thick_cells( rd_region , double )" ) - _select_active = EclPrototype("void ecl_region_select_active_cells( ecl_region )") - _select_inactive = EclPrototype( - "void ecl_region_select_inactive_cells( ecl_region )" + _deselect_thick = ResdataPrototype( + "void rd_region_deselect_thick_cells( rd_region , double )" ) - _deselect_active = EclPrototype( - "void ecl_region_deselect_active_cells( ecl_region )" + _select_active = ResdataPrototype("void rd_region_select_active_cells( rd_region )") + _select_inactive = ResdataPrototype( + "void rd_region_select_inactive_cells( rd_region )" ) - _deselect_inactive = EclPrototype( - "void ecl_region_deselect_inactive_cells( ecl_region )" + _deselect_active = ResdataPrototype( + "void rd_region_deselect_active_cells( rd_region )" ) - _select_above_plane = EclPrototype( - "void ecl_region_select_above_plane( ecl_region , double* , double* )" + _deselect_inactive = ResdataPrototype( + "void rd_region_deselect_inactive_cells( rd_region )" ) - _select_below_plane = EclPrototype( - "void ecl_region_select_below_plane( ecl_region , double* , double* )" + _select_above_plane = ResdataPrototype( + "void rd_region_select_above_plane( rd_region , double* , double* )" ) - _deselect_above_plane = EclPrototype( - "void ecl_region_deselect_above_plane( ecl_region, double* , double* )" + _select_below_plane = ResdataPrototype( + "void rd_region_select_below_plane( rd_region , double* , double* )" ) - _deselect_below_plane = EclPrototype( - "void ecl_region_deselect_below_plane( ecl_region, double* , double* )" + _deselect_above_plane = ResdataPrototype( + "void rd_region_deselect_above_plane( rd_region, double* , double* )" ) - _select_inside_polygon = EclPrototype( - "void ecl_region_select_inside_polygon( ecl_region , geo_polygon)" + _deselect_below_plane = ResdataPrototype( + "void rd_region_deselect_below_plane( rd_region, double* , double* )" ) - _select_outside_polygon = EclPrototype( - "void ecl_region_select_outside_polygon( ecl_region , geo_polygon)" + _select_inside_polygon = ResdataPrototype( + "void rd_region_select_inside_polygon( rd_region , geo_polygon)" ) - _deselect_inside_polygon = EclPrototype( - "void ecl_region_deselect_inside_polygon( ecl_region , geo_polygon)" + _select_outside_polygon = ResdataPrototype( + "void rd_region_select_outside_polygon( rd_region , geo_polygon)" ) - _deselect_outside_polygon = EclPrototype( - "void ecl_region_deselect_outside_polygon( ecl_region , geo_polygon)" + _deselect_inside_polygon = ResdataPrototype( + "void rd_region_deselect_inside_polygon( rd_region , geo_polygon)" ) - _set_name = EclPrototype("void ecl_region_set_name( ecl_region , char*)") - _get_name = EclPrototype("char* ecl_region_get_name( ecl_region )") - _contains_ijk = EclPrototype( - "void ecl_region_contains_ijk( ecl_region , int , int , int)" + _deselect_outside_polygon = ResdataPrototype( + "void rd_region_deselect_outside_polygon( rd_region , geo_polygon)" ) - _contains_global = EclPrototype( - "void ecl_region_contains_global( ecl_region, int )" + _set_name = ResdataPrototype("void rd_region_set_name( rd_region , char*)") + _get_name = ResdataPrototype("char* rd_region_get_name( rd_region )") + _contains_ijk = ResdataPrototype( + "void rd_region_contains_ijk( rd_region , int , int , int)" ) - _contains_active = EclPrototype( - "void ecl_region_contains_active( ecl_region , int )" + _contains_global = ResdataPrototype( + "void rd_region_contains_global( rd_region, int )" ) - _equal = EclPrototype("bool ecl_region_equal( ecl_region , ecl_region )") - _select_true = EclPrototype("void ecl_region_select_true( ecl_region , ecl_kw)") - _select_false = EclPrototype("void ecl_region_select_false( ecl_region , ecl_kw)") - _deselect_true = EclPrototype("void ecl_region_deselect_true( ecl_region , ecl_kw)") - _deselect_false = EclPrototype( - "void ecl_region_deselect_false( ecl_region , ecl_kw)" + _contains_active = ResdataPrototype( + "void rd_region_contains_active( rd_region , int )" ) - _select_from_layer = EclPrototype( - "void ecl_region_select_from_layer( ecl_region , layer , int , int)" + _equal = ResdataPrototype("bool rd_region_equal( rd_region , rd_region )") + _select_true = ResdataPrototype("void rd_region_select_true( rd_region , rd_kw)") + _select_false = ResdataPrototype("void rd_region_select_false( rd_region , rd_kw)") + _deselect_true = ResdataPrototype( + "void rd_region_deselect_true( rd_region , rd_kw)" ) - _deselect_from_layer = EclPrototype( - "void ecl_region_deselect_from_layer( ecl_region , layer , int , int)" + _deselect_false = ResdataPrototype( + "void rd_region_deselect_false( rd_region , rd_kw)" + ) + _select_from_layer = ResdataPrototype( + "void rd_region_select_from_layer( rd_region , layer , int , int)" + ) + _deselect_from_layer = ResdataPrototype( + "void rd_region_deselect_from_layer( rd_region , layer , int , int)" ) def __init__(self, grid, preselect): @@ -313,7 +317,7 @@ def __init__(self, grid, preselect): Will create a new region selector to select and deselect the cells in the grid given by @grid. The input argument @grid - should be a EclGrid instance. You can start with either all + should be a Grid instance. You can start with either all cells, or no cells, selected, depending on the value of @preselect. """ @@ -321,7 +325,7 @@ def __init__(self, grid, preselect): self.grid = grid self.active_index = False c_ptr = self._alloc(grid, preselect) - super(EclRegion, self).__init__(c_ptr) + super(ResdataRegion, self).__init__(c_ptr) def free(self): self._free() @@ -357,11 +361,11 @@ def __iand__(self, other): will eventually call this method. """ - if isinstance(other, EclRegion): + if isinstance(other, ResdataRegion): self._intersect(other) else: raise TypeError( - "Ecl region can only intersect with other EclRegion instances" + "Resdata region can only intersect with other ResdataRegion instances" ) return self @@ -372,11 +376,11 @@ def __isub__(self, other): Bound to reg -= reg2 """ - if isinstance(other, EclRegion): + if isinstance(other, ResdataRegion): self._subtract(other) else: raise TypeError( - "Ecl region can only subtract with other EclRegion instances" + "Resdata region can only subtract with other ResdataRegion instances" ) return self @@ -393,11 +397,11 @@ def __ior__(self, other): to update reg1 with the selections from reg2. """ - if isinstance(other, EclRegion): + if isinstance(other, ResdataRegion): self._combine(other) else: raise TypeError( - "Ecl region can only be combined with other EclRegion instances" + "Resdata region can only be combined with other ResdataRegion instances" ) return self @@ -486,142 +490,142 @@ def reset(self): ################################################################## @select_method - def select_more(self, ecl_kw, limit, intersect=False): + def select_more(self, rd_kw, limit, intersect=False): """ - Select all cells where keyword @ecl_kw is above @limit. + Select all cells where keyword @rd_kw is above @limit. This method is used to select all the cells where an arbitrary - field, contained in @ecl_kw, is above a limiting value - @limit. The EclKW instance must have either nactive or + field, contained in @rd_kw, is above a limiting value + @limit. The ResdataKW instance must have either nactive or nx*ny*nz elements; if this is not satisfied method will fail - hard. The datatype of @ecl_kw must be numeric, - i.e. ECL_INT_TYPE, ECL_DOUBLE_TYPE or ECL_FLOAT_TYPE. In the + hard. The datatype of @rd_kw must be numeric, + i.e. RD_INT_TYPE, RD_DOUBLE_TYPE or RD_FLOAT_TYPE. In the example below we select all the cells with water saturation above 0.85: - restart_file = ecl.EclFile( "ECLIPSE.X0067" ) - swat_kw = restart_file["SWAT"][0] - grid = ecl.EclGrid( "ECLIPSE.EGRID" ) - region = ecl.EclRegion( grid , False ) + >>> restart_file = ResdataFile( "CASE.X0067" ) + >>> swat_kw = restart_file["SWAT"][0] + >>> grid = Grid( "CASE.EGRID" ) + >>> region = ResdataRegion( grid , False ) - region.select_more( swat_kw , 0.85 ) + >>> region.select_more( swat_kw , 0.85 ) """ - self._select_more(ecl_kw, limit) + self._select_more(rd_kw, limit) - def deselect_more(self, ecl_kw, limit): + def deselect_more(self, rd_kw, limit): """ Deselects cells with value above limit. See select_more() for further documentation. """ - self._deselect_more(ecl_kw, limit) + self._deselect_more(rd_kw, limit) @select_method - def select_less(self, ecl_kw, limit, intersect=False): + def select_less(self, rd_kw, limit, intersect=False): """ - Select all cells where keyword @ecl_kw is below @limit. + Select all cells where keyword @rd_kw is below @limit. See select_more() for further documentation. """ - self._select_less(ecl_kw, limit) + self._select_less(rd_kw, limit) - def deselect_less(self, ecl_kw, limit): + def deselect_less(self, rd_kw, limit): """ - Deselect all cells where keyword @ecl_kw is below @limit. + Deselect all cells where keyword @rd_kw is below @limit. See select_more() for further documentation. """ - self._deselect_less(ecl_kw, limit) + self._deselect_less(rd_kw, limit) @select_method - def select_equal(self, ecl_kw, value, intersect=False): + def select_equal(self, rd_kw, value, intersect=False): """ - Select all cells where @ecl_kw is equal to @value. + Select all cells where @rd_kw is equal to @value. - The EclKW instance @ecl_kw must be of size nactive or + The ResdataKW instance @rd_kw must be of size nactive or nx*ny*nz, and it must be of integer type; testing for equality is not supported for floating point numbers. In the example below we select all the cells in PVT regions 2 and 4: - init_file = ecl.EclFile( "ECLIPSE.INIT" ) - pvtnum_kw = init_file.iget_named_kw( "PVTNUM" , 0 ) - grid = ecl.EclGrid( "ECLIPSE.GRID" ) - region = ecl.EclRegion( grid , False ) + >>> init_file = ResdataFile( "CASE.INIT" ) + >>> pvtnum_kw = init_file.iget_named_kw( "PVTNUM" , 0 ) + >>> grid = Grid( "CASE.GRID" ) + >>> region = ResdataRegion( grid , False ) - region.select_equal( pvtnum_kw , 2 ) - region.select_equal( pvtnum_kw , 4 ) + >>> region.select_equal( pvtnum_kw , 2 ) + >>> region.select_equal( pvtnum_kw , 4 ) """ - if not ecl_kw.data_type.is_int(): + if not rd_kw.data_type.is_int(): raise ValueError( "The select_equal method must have an integer valued keyword - got:%s" - % ecl_kw.typeName() + % rd_kw.typeName() ) - self._select_equal(ecl_kw, value) + self._select_equal(rd_kw, value) - def deselect_equal(self, ecl_kw, value): + def deselect_equal(self, rd_kw, value): """ - Select all cells where @ecl_kw is equal to @value. + Select all cells where @rd_kw is equal to @value. See select_equal() for further documentation. """ - if not ecl_kw.data_type.is_int(): + if not rd_kw.data_type.is_int(): raise ValueError( "The select_equal method must have an integer valued keyword - got:%s" - % ecl_kw.typeName() + % rd_kw.typeName() ) - self._deselect_equal(ecl_kw, value) + self._deselect_equal(rd_kw, value) @select_method - def select_in_range(self, ecl_kw, lower_limit, upper_limit, select=False): + def select_in_range(self, rd_kw, lower_limit, upper_limit, select=False): """ - Select all cells where @ecl_kw is in the half-open interval [ , ). + Select all cells where @rd_kw is in the half-open interval [ , ). - Will select all the cells where EclKW instance @ecl_kw has + Will select all the cells where ResdataKW instance @rd_kw has value in the half-open interval [@lower_limit , - @upper_limit). The input argument @ecl_kw must have size - nactive or nx*ny*nz, and it must be of type ECL_FLOAT_TYPE. + @upper_limit). The input argument @rd_kw must have size + nactive or nx*ny*nz, and it must be of type RD_FLOAT_TYPE. The following example will select all cells with porosity in the range [0.15,0.20): - init_file = ecl.EclFile( "ECLIPSE.INIT" ) - poro_kw = init_file.iget_named_kw( "PORO" , 0 ) - grid = ecl.EclGrid( "ECLIPSE.GRID" ) - region = ecl.EclRegion( grid , False ) + >>> init_file = resdata.ResdataFile( "CASE.INIT" ) + >>> poro_kw = init_file.iget_named_kw( "PORO" , 0 ) + >>> grid = resdata.Grid( "CASE.GRID" ) + >>> region = resdata.ResdataRegion( grid , False ) - region.select_in_range( poro_kw , 0.15, 0.20 ) + >>> region.select_in_range( poro_kw , 0.15, 0.20 ) """ - self._select_in_interval(ecl_kw, lower_limit, upper_limit) + self._select_in_interval(rd_kw, lower_limit, upper_limit) - def deselect_in_range(self, ecl_kw, lower_limit, upper_limit): + def deselect_in_range(self, rd_kw, lower_limit, upper_limit): """ - Deselect all cells where @ecl_kw is in the half-open interval [ , ). + Deselect all cells where @rd_kw is in the half-open interval [ , ). See select_in_range() for further documentation. """ - self._deselect_in_interval(ecl_kw, lower_limit, upper_limit) + self._deselect_in_interval(rd_kw, lower_limit, upper_limit) @select_method def select_cmp_less(self, kw1, kw2, intersect=False): """ Will select all cells where kw2 < kw1. - Will compare the ECLIPSE keywords @kw1 and @kw2, and select + Will compare the keywords @kw1 and @kw2, and select all the cells where the numerical value of @kw1 is less than - the numerical value of @kw2. The ECLIPSE keywords @kw1 and + the numerical value of @kw2. The keywords @kw1 and @kw2 must both be of the same size, nactive or nx*ny*nz. In - addition they must both be of type type ECL_FLOAT_TYPE. In the + addition they must both be of type type RD_FLOAT_TYPE. In the example below we select all the cells where the pressure has dropped: - restart_file = ecl.EclFile("ECLIPSE.UNRST") - pressure1 = restart_file.iget_named_kw( "PRESSURE" , 0) - pressure2 = restart_file.iget_named_kw( "PRESSURE" , 100) + >>> restart_file = resdata.ResdataFile("CASE.UNRST") + >>> pressure1 = restart_file.iget_named_kw( "PRESSURE" , 0) + >>> pressure2 = restart_file.iget_named_kw( "PRESSURE" , 100) - region.select_cmp_less( pressure2 , pressure1) + >>> region.select_cmp_less( pressure2 , pressure1) """ self._select_cmp_less(kw1, kw2) @@ -941,18 +945,18 @@ def deselect_outside_polygon(self, points): self._deselect_outside_polygon(CPolyline(init_points=points)) @select_method - def select_true(self, ecl_kw, intersect=False): + def select_true(self, rd_kw, intersect=False): """ - Assume that input ecl_kw is a boolean mask. + Assume that input rd_kw is a boolean mask. """ - self._select_true(ecl_kw) + self._select_true(rd_kw) @select_method - def select_false(self, ecl_kw, intersect=False): + def select_false(self, rd_kw, intersect=False): """ - Assume that input ecl_kw is a boolean mask. + Assume that input rd_kw is a boolean mask. """ - self._select_false(ecl_kw) + self._select_false(rd_kw) @select_method def select_from_layer(self, layer, k, value, intersect=False): @@ -1001,14 +1005,14 @@ def iadd_kw(self, target_kw, delta_kw, force_active=False): """ The functions iadd_kw(), copy_kw(), set_kw(), scale_kw() and shift_kw() are not meant to be used as methods of the - EclRegion class (altough that is of course perfectly OK) - - rather a EclRegion instance is passed as an argument to an - EclKW method, and then that method "flips things around" and - calls one of these methods with the EclKW instance as - argument. This applies to all the EclKW methods which take an + ResdataRegion class (altough that is of course perfectly OK) - + rather a ResdataRegion instance is passed as an argument to an + ResdataKW method, and then that method "flips things around" and + calls one of these methods with the ResdataKW instance as + argument. This applies to all the ResdataKW methods which take an optional "mask" argument. """ - if isinstance(delta_kw, EclKW): + if isinstance(delta_kw, ResdataKW): if target_kw.assert_binary(delta_kw): self._iadd_kw(target_kw, delta_kw, force_active) else: @@ -1016,23 +1020,23 @@ def iadd_kw(self, target_kw, delta_kw, force_active=False): else: self.shift_kw(target_kw, delta_kw, force_active=force_active) - def shift_kw(self, ecl_kw, shift, force_active=False): + def shift_kw(self, rd_kw, shift, force_active=False): """ See usage documentation on iadd_kw(). """ self.scalar_apply_kw( - ecl_kw, + rd_kw, shift, { - EclDataType.ECL_INT: self._shift_kw_int, - EclDataType.ECL_FLOAT: self._shift_kw_float, - EclDataType.ECL_DOUBLE: self._shift_kw_double, + ResDataType.RD_INT: self._shift_kw_int, + ResDataType.RD_FLOAT: self._shift_kw_float, + ResDataType.RD_DOUBLE: self._shift_kw_double, }, force_active, ) def isub_kw(self, target_kw, delta_kw, force_active=False): - if isinstance(delta_kw, EclKW): + if isinstance(delta_kw, ResdataKW): if target_kw.assert_binary(delta_kw): self._isub_kw(target_kw, delta_kw, force_active) else: @@ -1040,23 +1044,23 @@ def isub_kw(self, target_kw, delta_kw, force_active=False): else: self.shift_kw(target_kw, -delta_kw, force_active=force_active) - def scale_kw(self, ecl_kw, scale, force_active=False): + def scale_kw(self, rd_kw, scale, force_active=False): """ See usage documentation on iadd_kw(). """ self.scalar_apply_kw( - ecl_kw, + rd_kw, scale, { - EclDataType.ECL_INT: self._scale_kw_int, - EclDataType.ECL_FLOAT: self._scale_kw_float, - EclDataType.ECL_DOUBLE: self._scale_kw_double, + ResDataType.RD_INT: self._scale_kw_int, + ResDataType.RD_FLOAT: self._scale_kw_float, + ResDataType.RD_DOUBLE: self._scale_kw_double, }, force_active, ) def imul_kw(self, target_kw, other, force_active=False): - if isinstance(other, EclKW): + if isinstance(other, ResdataKW): if target_kw.assert_binary(other): self._imul_kw(target_kw, other) else: @@ -1065,7 +1069,7 @@ def imul_kw(self, target_kw, other, force_active=False): self.scale_kw(target_kw, other, force_active) def idiv_kw(self, target_kw, other, force_active=False): - if isinstance(other, EclKW): + if isinstance(other, ResdataKW): if target_kw.assert_binary(other): self._idiv_kw(target_kw, other) else: @@ -1086,40 +1090,40 @@ def copy_kw(self, target_kw, src_kw, force_active=False): else: raise TypeError("Type mismatch") - def set_kw(self, ecl_kw, value, force_active=False): + def set_kw(self, rd_kw, value, force_active=False): """ See usage documentation on iadd_kw(). """ self.scalar_apply_kw( - ecl_kw, + rd_kw, value, { - EclDataType.ECL_INT: self._set_kw_int, - EclDataType.ECL_FLOAT: self._set_kw_float, - EclDataType.ECL_DOUBLE: self._set_kw_double, + ResDataType.RD_INT: self._set_kw_int, + ResDataType.RD_FLOAT: self._set_kw_float, + ResDataType.RD_DOUBLE: self._set_kw_double, }, force_active, ) def sum_kw(self, kw, force_active=False): data_type = kw.data_type - if data_type == EclDataType.ECL_FLOAT: + if data_type == ResDataType.RD_FLOAT: return self._sum_kw_float(kw, force_active) - if data_type == EclDataType.ECL_INT: + if data_type == ResDataType.RD_INT: return self._sum_kw_int(kw, force_active) - if data_type == EclDataType.ECL_DOUBLE: + if data_type == ResDataType.RD_DOUBLE: return self._sum_kw_double(kw, force_active) - if data_type == EclDataType.ECL_BOOL: + if data_type == ResDataType.RD_BOOL: return self._sum_kw_bool(kw, force_active) raise ValueError("sum_kw only supported for; INT/FLOAT/DOUBLE/BOOL") ################################################################# - def ecl_region_instance(self): + def rd_region_instance(self): """ Helper function (attribute) to support run-time typechecking. """ @@ -1176,8 +1180,8 @@ def contains_active(self, active_index): """ return self._contains_active(active_index) - def kw_index_list(self, ecl_kw, force_active): - c_ptr = self._get_kw_index_list(ecl_kw, force_active) + def kw_index_list(self, rd_kw, force_active): + c_ptr = self._get_kw_index_list(rd_kw, force_active) index_list = IntVector.createCReference(c_ptr, self) return index_list @@ -1192,11 +1196,11 @@ def set_name(self, name): self._set_name(name) -monkey_the_camel(EclRegion, "selectTrue", EclRegion.select_true) -monkey_the_camel(EclRegion, "selectFalse", EclRegion.select_false) -monkey_the_camel(EclRegion, "selectFromLayer", EclRegion.select_from_layer) -monkey_the_camel(EclRegion, "getActiveList", EclRegion.get_active_list) -monkey_the_camel(EclRegion, "getGlobalList", EclRegion.get_global_list) -monkey_the_camel(EclRegion, "getIJKList", EclRegion.get_ijk_list) -monkey_the_camel(EclRegion, "getName", EclRegion.get_name) -monkey_the_camel(EclRegion, "setName", EclRegion.set_name) +monkey_the_camel(ResdataRegion, "selectTrue", ResdataRegion.select_true) +monkey_the_camel(ResdataRegion, "selectFalse", ResdataRegion.select_false) +monkey_the_camel(ResdataRegion, "selectFromLayer", ResdataRegion.select_from_layer) +monkey_the_camel(ResdataRegion, "getActiveList", ResdataRegion.get_active_list) +monkey_the_camel(ResdataRegion, "getGlobalList", ResdataRegion.get_global_list) +monkey_the_camel(ResdataRegion, "getIJKList", ResdataRegion.get_ijk_list) +monkey_the_camel(ResdataRegion, "getName", ResdataRegion.get_name) +monkey_the_camel(ResdataRegion, "setName", ResdataRegion.set_name) diff --git a/python/resdata/rd_type.py b/python/resdata/rd_type.py new file mode 100644 index 0000000000..7af86c47e7 --- /dev/null +++ b/python/resdata/rd_type.py @@ -0,0 +1,184 @@ +from cwrap import BaseCClass, BaseCEnum +from resdata import ResdataPrototype + + +class ResdataTypeEnum(BaseCEnum): + TYPE_NAME = "rd_type_enum" + RD_CHAR_TYPE = None + RD_FLOAT_TYPE = None + RD_DOUBLE_TYPE = None + RD_INT_TYPE = None + RD_BOOL_TYPE = None + RD_MESS_TYPE = None + RD_STRING_TYPE = None + + +ResdataTypeEnum.addEnum("RD_CHAR_TYPE", 0) +ResdataTypeEnum.addEnum("RD_FLOAT_TYPE", 1) +ResdataTypeEnum.addEnum("RD_DOUBLE_TYPE", 2) +ResdataTypeEnum.addEnum("RD_INT_TYPE", 3) +ResdataTypeEnum.addEnum("RD_BOOL_TYPE", 4) +ResdataTypeEnum.addEnum("RD_MESS_TYPE", 5) +ResdataTypeEnum.addEnum("RD_STRING_TYPE", 7) + +# ----------------------------------------------------------------- + + +class ResDataType(BaseCClass): + TYPE_NAME = "rd_data_type" + + _alloc = ResdataPrototype( + "void* rd_type_alloc_python(rd_type_enum, size_t)", bind=False + ) + _alloc_from_type = ResdataPrototype( + "void* rd_type_alloc_from_type_python(rd_type_enum)", bind=False + ) + _alloc_from_name = ResdataPrototype( + "void* rd_type_alloc_from_name_python(char*)", bind=False + ) + _free = ResdataPrototype("void rd_type_free_python(rd_data_type)") + _get_type = ResdataPrototype("rd_type_enum rd_type_get_type_python(rd_data_type)") + _get_element_size = ResdataPrototype( + "size_t rd_type_get_sizeof_iotype_python(rd_data_type)" + ) + _is_int = ResdataPrototype("bool rd_type_is_int_python(rd_data_type)") + _is_char = ResdataPrototype("bool rd_type_is_char_python(rd_data_type)") + _is_float = ResdataPrototype("bool rd_type_is_float_python(rd_data_type)") + _is_double = ResdataPrototype("bool rd_type_is_double_python(rd_data_type)") + _is_mess = ResdataPrototype("bool rd_type_is_mess_python(rd_data_type)") + _is_bool = ResdataPrototype("bool rd_type_is_bool_python(rd_data_type)") + _is_string = ResdataPrototype("bool rd_type_is_string_python(rd_data_type)") + _get_name = ResdataPrototype("char* rd_type_alloc_name_python(rd_data_type)") + _is_numeric = ResdataPrototype("bool rd_type_is_numeric_python(rd_data_type)") + _is_equal = ResdataPrototype( + "bool rd_type_is_equal_python(rd_data_type, rd_data_type)" + ) + + def __init__(self, type_enum=None, element_size=None, type_name=None): + self._assert_valid_arguments(type_enum, element_size, type_name) + + if type_name: + c_ptr = self._alloc_from_name(type_name) + elif element_size is None: + c_ptr = self._alloc_from_type(type_enum) + else: + c_ptr = self._alloc(type_enum, element_size) + + super(ResDataType, self).__init__(c_ptr) + + def _assert_valid_arguments(self, type_enum, element_size, type_name): + if type_name is not None: + if type_enum is not None or element_size is not None: + err_msg = ( + "Type name given (%s). Expected both " + + "type_enum and element_size to be None" + ) + raise ValueError(err_msg % type_name) + + elif type_enum is None: + raise ValueError("Both type_enum and type_name is None!") + + elif type_enum == ResdataTypeEnum.RD_STRING_TYPE: + if element_size is None: + raise ValueError( + "When creating an RD_STRING one must " + "provide an element size!" + ) + + if not (0 <= element_size <= 999): + raise ValueError( + "Expected element_size to be in the range " + + "[0, 999], was: %d" % element_size + ) + + @property + def type(self): + return self._get_type() + + @property + def element_size(self): + return self._get_element_size() + + @property + def type_name(self): + return self._get_name() + + def free(self): + self._free() + + def is_int(self): + return self._is_int() + + def is_char(self): + return self._is_char() + + def is_float(self): + return self._is_float() + + def is_double(self): + return self._is_double() + + def is_mess(self): + return self._is_mess() + + def is_bool(self): + return self._is_bool() + + def is_string(self): + return self._is_string() + + def is_numeric(self): + return self._is_numeric() + + def is_equal(self, other): + return self._is_equal(other) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.is_equal(other) + return False + + def __ne__(self, other): + return not self.__eq__(other) + + def __hash__(self): + return hash((self.type, self.element_size)) + + @classmethod + def create_from_type_name(cls, name): + return ResDataType(type_name=name) + + # Enables one to fetch a type as ResDataType.RD_XXXX + class classproperty(object): + def __init__(self, fget): + self.fget = fget + + def __get__(self, owner_self, owner_cls): + return self.fget(owner_cls) + + @classproperty + def RD_INT(cls): + return ResDataType(ResdataTypeEnum.RD_INT_TYPE) + + @classproperty + def RD_FLOAT(cls): + return ResDataType(ResdataTypeEnum.RD_FLOAT_TYPE) + + @classproperty + def RD_DOUBLE(cls): + return ResDataType(ResdataTypeEnum.RD_DOUBLE_TYPE) + + @classproperty + def RD_BOOL(cls): + return ResDataType(ResdataTypeEnum.RD_BOOL_TYPE) + + @classproperty + def RD_MESS(cls): + return ResDataType(ResdataTypeEnum.RD_MESS_TYPE) + + @classproperty + def RD_CHAR(cls): + return ResDataType(ResdataTypeEnum.RD_CHAR_TYPE) + + @classmethod + def RD_STRING(cls, elem_size): + return ResDataType(ResdataTypeEnum.RD_STRING_TYPE, elem_size) diff --git a/python/resdata/rd_util.py b/python/resdata/rd_util.py new file mode 100644 index 0000000000..0b91cf80d0 --- /dev/null +++ b/python/resdata/rd_util.py @@ -0,0 +1,165 @@ +""" +Constants from the header rd_util.h - some stateless functions. + +This module does not contain any class definitions; it mostly consists +of enum definitions/values from rd_util.h; the enum values are +extracted from the shared library in a semi-automagic manner using the +BaseCEnum class from cwrap. + +In addition to the enum definitions there are a few stateless +functions from rd_util.c which are not bound to any class type. +""" +from __future__ import absolute_import + +import ctypes + +from cwrap import BaseCEnum +from resdata import ResdataPrototype +from resdata.util.util import monkey_the_camel + + +class FileType(BaseCEnum): + TYPE_NAME = "rd_file_enum" + OTHER = None + RESTART = None + UNIFIED_RESTART = None + SUMMARY = None + UNIFIED_SUMMARY = None + SUMMARY_HEADER = None + GRID = None + EGRID = None + INIT = None + RFT = None + DATA = None + + +FileType.addEnum("OTHER", 0) +FileType.addEnum("RESTART", 1) +FileType.addEnum("UNIFIED_RESTART", 2) +FileType.addEnum("SUMMARY", 4) +FileType.addEnum("UNIFIED_SUMMARY", 8) +FileType.addEnum("SUMMARY_HEADER", 16) +FileType.addEnum("GRID", 32) +FileType.addEnum("EGRID", 64) +FileType.addEnum("INIT", 128) +FileType.addEnum("RFT", 256) +FileType.addEnum("DATA", 512) + + +# ----------------------------------------------------------------- + + +class Phase(BaseCEnum): + TYPE_NAME = "rd_phase_enum" + OIL = None + GAS = None + WATER = None + + +Phase.addEnum("OIL", 1) +Phase.addEnum("GAS", 2) +Phase.addEnum("WATER", 4) + + +# ----------------------------------------------------------------- + + +class UnitSystem(BaseCEnum): + TYPE_NAME = "rd_unit_enum" + + METRIC = None + FIELD = None + LAB = None + PVT_M = None + + +UnitSystem.addEnum("METRIC", 1) +UnitSystem.addEnum("FIELD", 2) +UnitSystem.addEnum("LAB", 3) +UnitSystem.addEnum("PVT_M", 4) + + +# ----------------------------------------------------------------- + + +class FileMode(BaseCEnum): + TYPE_NAME = "rd_file_flag_enum" + DEFAULT = None + CLOSE_STREAM = None + WRITABLE = None + + +FileMode.addEnum("DEFAULT", 0) +FileMode.addEnum("CLOSE_STREAM", 1) +FileMode.addEnum("WRITABLE", 2) + + +# ----------------------------------------------------------------- + + +class ResdataUtil(object): + _get_num_cpu = ResdataPrototype("int rd_get_num_cpu(char*)", bind=False) + _get_file_type = ResdataPrototype( + "rd_file_enum rd_get_file_type(char*, bool*, int*)", bind=False + ) + _get_start_date = ResdataPrototype("time_t rd_get_start_date(char*)", bind=False) + _get_report_step = ResdataPrototype("int rd_filename_report_nr(char*)", bind=False) + + @staticmethod + def get_num_cpu(datafile): + """ + Parse ECLIPSE datafile and determine how many CPUs are needed. + + Will look for the "PARALLELL" keyword, and then read off the + number of CPUs required. Will return one if no PARALLELL keyword + is found. + """ + return ResdataUtil._get_num_cpu(datafile) + + @staticmethod + def get_file_type(filename): + """ + Will inspect an ECLIPSE filename and return an integer type flag. + """ + file_type, fmt, step = ResdataUtil.inspectExtension(filename) + return file_type + + @staticmethod + def get_start_date(datafile): + return ResdataUtil._get_start_date(datafile).datetime() + + @staticmethod + def inspect_extension(filename): + """Will inspect a filename and return a tuple consisting of + a FileType, a bool for formatted or not, and an + integer for the step number. + """ + fmt_file = ctypes.c_bool() + report_step = ctypes.c_int(-1) + file_type = ResdataUtil._get_file_type( + filename, ctypes.byref(fmt_file), ctypes.byref(report_step) + ) + if report_step.value == -1: + step = None + else: + step = report_step.value + + return (file_type, fmt_file.value, step) + + @staticmethod + def report_step(filename): + report_step = ResdataUtil._get_report_step(filename) + if report_step < 0: + raise ValueError("Could not infer report step from: %s" % filename) + + return report_step + + +get_num_cpu = ResdataUtil.get_num_cpu +get_file_type = ResdataUtil.get_file_type +get_start_date = ResdataUtil.get_start_date + +monkey_the_camel( + ResdataUtil, "inspectExtension", ResdataUtil.inspect_extension, staticmethod +) +monkey_the_camel(ResdataUtil, "reportStep", ResdataUtil.report_step, staticmethod) diff --git a/python/resdata/resdata_info_build.py.in b/python/resdata/resdata_info_build.py.in new file mode 100644 index 0000000000..55b5ac2cf0 --- /dev/null +++ b/python/resdata/resdata_info_build.py.in @@ -0,0 +1,9 @@ + + +class ResdataInfo(object): + lib_path = "${LIBRARY_OUTPUT_PATH}" + so_version = "${RD_BINARY_POSTFIX}" + __version__ = "${RD_VERSION_MAJOR}.${RD_VERSION_MINOR}.${RD_VERSION_MICRO}" + + def __init__(self): + pass diff --git a/python/resdata/resdata_info_install.py.in b/python/resdata/resdata_info_install.py.in new file mode 100644 index 0000000000..29c317cc63 --- /dev/null +++ b/python/resdata/resdata_info_install.py.in @@ -0,0 +1,9 @@ + + +class ResdataInfo(object): + lib_path = "../../../../${CMAKE_INSTALL_LIBDIR}" + so_version = "${RD_BINARY_POSTFIX}" + __version__ = "${RD_VERSION_MAJOR}.${RD_VERSION_MINOR}.${RD_VERSION_MICRO}" + + def __init__(self): + pass diff --git a/python/resdata/resfile/__init__.py b/python/resdata/resfile/__init__.py new file mode 100644 index 0000000000..6b1093e204 --- /dev/null +++ b/python/resdata/resfile/__init__.py @@ -0,0 +1,29 @@ +""" +The resfile package contains several classes for working directly with restart +format files. + + fortio/FortIO: This is functionality to read and write binary + fortran files. + + rd_kw/ResdataKW: This class holds one keyword, like SWAT, in + restart format. + + rd_type/ResDataType: This class is used to represent the data type + of the elements in ResdataKW. + + rd_file/ResdataFile: This class is used to load a file in + restart format, alternatively only parts of the file can be + loaded. Internally it consists of a collection of ResdataKW + instances. +""" + +import resdata.util.util + +from .fortio import FortIO, openFortIO +from .rd_kw import ResdataKW +from .rd_file_view import ResdataFileView +from .rd_file import ResdataFile, openResdataFile +from .rd_3dkw import Resdata3DKW +from .rd_3d_file import Resdata3DFile +from .rd_init_file import ResdataInitFile +from .rd_restart_file import ResdataRestartFile diff --git a/python/ecl/eclfile/fortio.py b/python/resdata/resfile/fortio.py similarity index 87% rename from python/ecl/eclfile/fortio.py rename to python/resdata/resfile/fortio.py index b489e59b1d..2262f3f706 100644 --- a/python/ecl/eclfile/fortio.py +++ b/python/resdata/resfile/fortio.py @@ -25,8 +25,8 @@ import os from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl import EclPrototype +from resdata.util.util import monkey_the_camel +from resdata import ResdataPrototype class FortIO(BaseCClass): @@ -37,28 +37,28 @@ class FortIO(BaseCClass): READ_AND_WRITE_MODE = 3 APPEND_MODE = 4 - _open_reader = EclPrototype( + _open_reader = ResdataPrototype( "void* fortio_open_reader(char*, bool, bool)", bind=False ) - _open_writer = EclPrototype( + _open_writer = ResdataPrototype( "void* fortio_open_writer(char*, bool, bool)", bind=False ) - _open_readwrite = EclPrototype( + _open_readwrite = ResdataPrototype( "void* fortio_open_readwrite(char*, bool, bool)", bind=False ) - _open_append = EclPrototype( + _open_append = ResdataPrototype( "void* fortio_open_append(char*, bool, bool)", bind=False ) - _guess_fortran = EclPrototype( + _guess_fortran = ResdataPrototype( "bool fortio_looks_like_fortran_file(char*, bool)", bind=False ) - _write_record = EclPrototype("void fortio_fwrite_record(fortio, char*, int)") - _get_position = EclPrototype("long fortio_ftell(fortio)") - _seek = EclPrototype("void fortio_fseek(fortio, long, int)") - _close = EclPrototype("bool fortio_fclose(fortio)") - _truncate = EclPrototype("bool fortio_ftruncate(fortio, long)") - _filename = EclPrototype("char* fortio_filename_ref(fortio)") + _write_record = ResdataPrototype("void fortio_fwrite_record(fortio, char*, int)") + _get_position = ResdataPrototype("long fortio_ftell(fortio)") + _seek = ResdataPrototype("void fortio_fseek(fortio, long, int)") + _close = ResdataPrototype("bool fortio_fclose(fortio)") + _truncate = ResdataPrototype("bool fortio_ftruncate(fortio, long)") + _filename = ResdataPrototype("char* fortio_filename_ref(fortio)") def __init__( self, file_name, mode=READ_MODE, fmt_file=False, endian_flip_header=True @@ -82,9 +82,9 @@ def __init__( all the pressure keywords to another file: import sys - from ecl.ecl import FortIO, EclFile + from resdata.ecl import FortIO, ResdataFile - rst_file = EclFile(sys.argv[1]) + rst_file = ResdataFile(sys.argv[1]) fortio = FortIO("PRESSURE", mode=FortIO.WRITE_MODE) for kw in rst_file: @@ -183,9 +183,9 @@ def openFortIO( the situation where you need to ensure resource cleanup. import sys - from ecl.ecl import FortIO, EclFile + from resdata.ecl import FortIO, ResdataFile - rst_file = EclFile(sys.argv[1]) + rst_file = ResdataFile(sys.argv[1]) with openFortIO("PRESSURE", mode=FortIO.WRITE_MODE) as fortio: for kw in rst_file: if kw.name() == "PRESSURE": diff --git a/python/ecl/eclfile/ecl_3d_file.py b/python/resdata/resfile/rd_3d_file.py similarity index 59% rename from python/ecl/eclfile/ecl_3d_file.py rename to python/resdata/resfile/rd_3d_file.py index 430f992ae9..0feed60ff5 100644 --- a/python/ecl/eclfile/ecl_3d_file.py +++ b/python/resdata/resfile/rd_3d_file.py @@ -1,22 +1,22 @@ -from ecl.eclfile import EclFile, Ecl3DKW +from resdata.resfile import ResdataFile, Resdata3DKW -class Ecl3DFile(EclFile): +class Resdata3DFile(ResdataFile): def __init__(self, grid, filename, flags=0): self.grid = grid - super(Ecl3DFile, self).__init__(filename, flags) + super(Resdata3DFile, self).__init__(filename, flags) def __getitem__(self, index): - return_arg = super(Ecl3DFile, self).__getitem__(index) + return_arg = super(Resdata3DFile, self).__getitem__(index) if isinstance(return_arg, list): kw_list = return_arg else: kw_list = [return_arg] - # Go through all the keywords and try inplace promotion to Ecl3DKW + # Go through all the keywords and try inplace promotion to Resdata3DKW for kw in kw_list: try: - Ecl3DKW.castFromKW(kw, self.grid) + Resdata3DKW.castFromKW(kw, self.grid) except ValueError: pass diff --git a/python/ecl/eclfile/ecl_3dkw.py b/python/resdata/resfile/rd_3dkw.py similarity index 63% rename from python/ecl/eclfile/ecl_3dkw.py rename to python/resdata/resfile/rd_3dkw.py index fa54781f33..791ae8d22f 100644 --- a/python/ecl/eclfile/ecl_3dkw.py +++ b/python/resdata/resfile/rd_3dkw.py @@ -1,40 +1,40 @@ -from ecl.util.util import monkey_the_camel -from .ecl_kw import EclKW +from resdata.util.util import monkey_the_camel +from .rd_kw import ResdataKW -class Ecl3DKW(EclKW): +class Resdata3DKW(ResdataKW): """ Class for working with Eclipse keywords defined over a grid - The Ecl3DKW class is derived from the EclKW class, and most of the - methods are implemented in the EclKW base class. The purpose of - the Ecl3DKW class is to simplify working with 3D properties like + The Resdata3DKW class is derived from the ResdataKW class, and most of the + methods are implemented in the ResdataKW base class. The purpose of + the Resdata3DKW class is to simplify working with 3D properties like PORO or SATNUM. - The Ecl3DKW class has an attached EclGrid which is used to support + The Resdata3DKW class has an attached Grid which is used to support [i,j,k] indexing, and a defined default value which is used when - reading an inactive value. The Ecl3DKW keyword instances are - returned from the EclInitFile and EclRestartFile classes, in - addition you can excplicitly \"cast\" a EclKW keyword to Ecl3DKW - with the Ecl3DKW.castFromKW() classmethod. + reading an inactive value. The Resdata3DKW keyword instances are + returned from the ResdataInitFile and ResdataRestartFile classes, in + addition you can excplicitly \"cast\" a ResdataKW keyword to Resdata3DKW + with the Resdata3DKW.castFromKW() classmethod. Usage example: - from ecl.ecl import EclInitFile,EclGrid + from resdata.ecl import ResdataInitFile,Grid - grid = EclGrid("ECLIPSE.EGRID") - file = EclInitFile(grid , "ECLIPSE.INIT") + >>> grid = Grid("CASE.EGRID") + >>> file = ResdataInitFile(grid, "CASE.INIT") - permx_kw = file["PORO"][0] - porv_kw = file["PORV"][0] + >>> permx_kw = file["PORO"][0] + >>> porv_kw = file["PORV"][0] - permx_kw.setDefault( -1 ) - for k in range(grid.getNZ()): - for j in range(grid.getNY()): - for i in range(grid.getNX()): - print('"(%d,%d,%d) Permx:%g Porv:%g"' % (i,j,k,permx_kw[i,j,k] , porv_kw[i,j,k])) + >>> permx_kw.setDefault( -1 ) + >>> for k in range(grid.getNZ()): + >>> for j in range(grid.getNY()): + >>> for i in range(grid.getNX()): + >>> print('"(%d,%d,%d) Permx:%g Porv:%g"' % (i,j,k,permx_kw[i,j,k] , porv_kw[i,j,k])) - In the example we open an ECLIPSE INIT file and extract the PERMX + In the example we open an INIT file and extract the PERMX and PORV properties, and then iterate over all the cells in the grid. @@ -55,25 +55,25 @@ def __init__(self, kw, grid, value_type, default_value=0, global_active=False): size = grid.getGlobalSize() else: size = grid.getNumActive() - super(Ecl3DKW, self).__init__(kw, size, value_type) + super(Resdata3DKW, self).__init__(kw, size, value_type) self.grid = grid self.global_active = global_active self.setDefault(default_value) @classmethod def create(cls, kw, grid, value_type, default_value=0, global_active=False): - new_kw = Ecl3DKW(kw, grid, value_type, default_value, global_active) + new_kw = Resdata3DKW(kw, grid, value_type, default_value, global_active) return new_kw @classmethod - def read_grdecl(cls, grid, fileH, kw, strict=True, ecl_type=None): + def read_grdecl(cls, grid, fileH, kw, strict=True, rd_type=None): """ - Will load an Ecl3DKW instance from a grdecl formatted filehandle. + Will load an Resdata3DKW instance from a grdecl formatted filehandle. - See the base class EclKW.read_grdecl() for more documentation. + See the base class ResdataKW.read_grdecl() for more documentation. """ - kw = super(Ecl3DKW, cls).read_grdecl(fileH, kw, strict, ecl_type) - Ecl3DKW.castFromKW(kw, grid) + kw = super(Resdata3DKW, cls).read_grdecl(fileH, kw, strict, rd_type) + Resdata3DKW.castFromKW(kw, grid) return kw def __getitem__(self, index): @@ -99,7 +99,7 @@ def __getitem__(self, index): else: index = self.grid.get_active_index(ijk=index) - return super(Ecl3DKW, self).__getitem__(index) + return super(Resdata3DKW, self).__getitem__(index) def __setitem__(self, index, value): """Set the value of at index [g] or [i,j,k]. @@ -124,13 +124,13 @@ def __setitem__(self, index, value): else: index = self.grid.get_active_index(ijk=index) - return super(Ecl3DKW, self).__setitem__(index, value) + return super(Resdata3DKW, self).__setitem__(index, value) @classmethod def cast_from_kw(cls, kw, grid, default_value=0): - """Will convert a normal EclKW to a Ecl3DKW. + """Will convert a normal ResdataKW to a Resdata3DKW. - The method will convert a normal EclKW instance to Ecl3DKw + The method will convert a normal ResdataKW instance to Resdata3DKw instance with an attached grid and a default value. The method will check that size of the keyword is compatible @@ -145,13 +145,13 @@ def cast_from_kw(cls, kw, grid, default_value=0): 2. Convert the keyword to a 3D keyword. - from ecl.ecl import EclGrid,EclKW,Ecl3DKW + from resdata.ecl import Grid,ResdataKW,Resdata3DKW - grid = EclGrid("ECLIPSE.EGRID") - poro = EclKW.read_grdecl(open("poro.grdecl") , "PORO") - Ecl3DKW.castFromKW( poro , grid ) + >>> grid = Grid("CASE.EGRID") + >>> poro = ResdataKW.read_grdecl(open("poro.grdecl") , "PORO") + >>> Resdata3DKW.castFromKW( poro , grid ) - print('Porosity in cell (10,11,12):%g' % poro[10,11,12]) + >>> print('Porosity in cell (10,11,12):%g' % poro[10,11,12]) """ if len(kw) == grid.getGlobalSize(): kw.global_active = True @@ -174,9 +174,9 @@ def cast_from_kw(cls, kw, grid, default_value=0): return kw def compressed_copy(self): - """Will return a EclKW copy with nactive elements. + """Will return a ResdataKW copy with nactive elements. - The returned copy will be of type EclKW; i.e. no default + The returned copy will be of type ResdataKW; i.e. no default interpolation and only linear access in the [] operator. The main purpose of this is to facilitate iteration over the active index, and for writing binary files. @@ -184,9 +184,9 @@ def compressed_copy(self): return self.grid.compressedKWCopy(self) def global_copy(self): - """Will return a EclKW copy with nx*ny*nz elements. + """Will return a ResdataKW copy with nx*ny*nz elements. - The returned copy will be of type EclKW; i.e. no default + The returned copy will be of type ResdataKW; i.e. no default interpolation and only linear access in the [] operator. The main purpose of this is to facilitate iteration over the global index, and for writing binary files. @@ -203,8 +203,8 @@ def get_default(self): return self.default_value -monkey_the_camel(Ecl3DKW, "castFromKW", Ecl3DKW.cast_from_kw, classmethod) -monkey_the_camel(Ecl3DKW, "compressedCopy", Ecl3DKW.compressed_copy) -monkey_the_camel(Ecl3DKW, "globalCopy", Ecl3DKW.global_copy) -monkey_the_camel(Ecl3DKW, "setDefault", Ecl3DKW.set_default) -monkey_the_camel(Ecl3DKW, "getDefault", Ecl3DKW.get_default) +monkey_the_camel(Resdata3DKW, "castFromKW", Resdata3DKW.cast_from_kw, classmethod) +monkey_the_camel(Resdata3DKW, "compressedCopy", Resdata3DKW.compressed_copy) +monkey_the_camel(Resdata3DKW, "globalCopy", Resdata3DKW.global_copy) +monkey_the_camel(Resdata3DKW, "setDefault", Resdata3DKW.set_default) +monkey_the_camel(Resdata3DKW, "getDefault", Resdata3DKW.get_default) diff --git a/python/ecl/eclfile/ecl_file.py b/python/resdata/resfile/rd_file.py similarity index 67% rename from python/ecl/eclfile/ecl_file.py rename to python/resdata/resfile/rd_file.py index 10f6c20ff7..2920e1de10 100644 --- a/python/ecl/eclfile/ecl_file.py +++ b/python/resdata/resfile/rd_file.py @@ -1,80 +1,75 @@ """ -The ecl_file module contains functionality to load a an ECLIPSE file +The rd_file module contains functionality to load a file in 'restart format'. Files of 'restart format' include restart files, init files, grid files, summary files and RFT files. -The ecl_file implementation is agnostic[1] to the content and -structure of the file; more specialized classes like EclSum and -EclGrid use the EclFile functionality for low level file loading. +The rd_file implementation is agnostic[1] to the content and +structure of the file; more specialized classes like Summary and +Grid use the ResdataFile functionality for low level file loading. The typical usage involves loading a complete file, and then subsequently querying for various keywords. In the example below we load a restart file, and ask for the SWAT keyword: - file = EclFile( "ECLIPSE.X0067" ) + file = ResdataFile( "CASE.X0067" ) swat_kw = file.iget_named_kw( "SWAT" , 0 ) -The ecl_file module is a thin wrapper around the ecl_file.c -implementation from the libecl library. +The rd_file module is a thin wrapper around the rd_file.c +implementation from the resdata library. [1]: In particular for restart files, which do not have a special RestartFile class, there is some specialized functionality. """ +import ctypes +import datetime import re import types -import datetime -import ctypes from cwrap import BaseCClass +from resdata import FileMode, FileType, ResdataPrototype +from resdata.resfile import ResdataFileView, ResdataKW +from resdata.util.util import CTime, monkey_the_camel -from ecl import EclPrototype -from ecl.util.util import CTime -from ecl.util.util import monkey_the_camel -from ecl import EclFileFlagEnum, EclFileEnum -from ecl.eclfile import EclKW, EclFileView - -ECL_FILE_DEFAULT = EclFileFlagEnum.ECL_FILE_DEFAULT - -class EclFile(BaseCClass): - TYPE_NAME = "ecl_file" - _open = EclPrototype( - "void* ecl_file_open( char* , ecl_file_flag_enum )", bind=False +class ResdataFile(BaseCClass): + TYPE_NAME = "rd_file" + _open = ResdataPrototype( + "void* rd_file_open( char* , rd_file_flag_enum )", bind=False ) - _get_file_type = EclPrototype( - "ecl_file_enum ecl_util_get_file_type( char* , bool* , int*)", bind=False + _get_file_type = ResdataPrototype( + "rd_file_enum rd_get_file_type( char* , bool* , int*)", bind=False ) - _writable = EclPrototype("bool ecl_file_writable( ecl_file )") - _save_kw = EclPrototype("void ecl_file_save_kw( ecl_file , ecl_kw )") - _close = EclPrototype("void ecl_file_close( ecl_file )") - _iget_restart_time = EclPrototype( - "time_t ecl_file_iget_restart_sim_date( ecl_file , int )" + _writable = ResdataPrototype("bool rd_file_writable( rd_file )") + _save_kw = ResdataPrototype("void rd_file_save_kw( rd_file , rd_kw )") + _close = ResdataPrototype("void rd_file_close( rd_file )") + _iget_restart_time = ResdataPrototype( + "time_t rd_file_iget_restart_sim_date( rd_file , int )" ) - _iget_restart_days = EclPrototype( - "double ecl_file_iget_restart_sim_days( ecl_file , int )" + _iget_restart_days = ResdataPrototype( + "double rd_file_iget_restart_sim_days( rd_file , int )" ) - _get_restart_index = EclPrototype( - "int ecl_file_get_restart_index( ecl_file , time_t)" + _get_restart_index = ResdataPrototype( + "int rd_file_get_restart_index( rd_file , time_t)" ) - _get_src_file = EclPrototype("char* ecl_file_get_src_file( ecl_file )") - _replace_kw = EclPrototype( - "void ecl_file_replace_kw( ecl_file , ecl_kw , ecl_kw , bool)" + _get_src_file = ResdataPrototype("char* rd_file_get_src_file( rd_file )") + _replace_kw = ResdataPrototype( + "void rd_file_replace_kw( rd_file , rd_kw , rd_kw , bool)" ) - _fwrite = EclPrototype( - "void ecl_file_fwrite_fortio( ecl_file , fortio , int)" + _fwrite = ResdataPrototype( + "void rd_file_fwrite_fortio( rd_file , fortio , int)" ) - _has_report_step = EclPrototype( - "bool ecl_file_has_report_step( ecl_file , int)" + _has_report_step = ResdataPrototype( + "bool rd_file_has_report_step( rd_file , int)" ) - _has_sim_time = EclPrototype( - "bool ecl_file_has_sim_time( ecl_file , time_t )" + _has_sim_time = ResdataPrototype( + "bool rd_file_has_sim_time( rd_file , time_t )" ) - _get_global_view = EclPrototype( - "ecl_file_view_ref ecl_file_get_global_view( ecl_file )" + _get_global_view = ResdataPrototype( + "rd_file_view_ref rd_file_get_global_view( rd_file )" ) - _write_index = EclPrototype("bool ecl_file_write_index( ecl_file , char*)") - _fast_open = EclPrototype( - "void* ecl_file_fast_open( char* , char* , int )", bind=False + _write_index = ResdataPrototype("bool rd_file_write_index( rd_file , char*)") + _fast_open = ResdataPrototype( + "void* rd_file_fast_open( char* , char* , int )", bind=False ) @staticmethod @@ -82,15 +77,18 @@ def get_filetype(filename): fmt_file = ctypes.c_bool() report_step = ctypes.c_int() - file_type = EclFile._get_file_type( + file_type = ResdataFile._get_file_type( filename, ctypes.byref(fmt_file), ctypes.byref(report_step) ) - if file_type in [EclFileEnum.ECL_RESTART_FILE, EclFileEnum.ECL_SUMMARY_FILE]: + if file_type in [ + FileType.RESTART, + FileType.SUMMARY, + ]: report_step = report_step.value else: report_step = None - if file_type in [EclFileEnum.ECL_OTHER_FILE, EclFileEnum.ECL_DATA_FILE]: + if file_type in [FileType.OTHER, FileType.DATA]: fmt_file = None else: fmt_file = fmt_file.value @@ -100,7 +98,7 @@ def get_filetype(filename): @classmethod def restart_block(cls, filename, dtime=None, report_step=None): raise NotImplementedError( - "The restart_block implementation has been removed - open file normally and use EclFileView." + "The restart_block implementation has been removed - open file normally and use ResdataFileView." ) @classmethod @@ -109,21 +107,13 @@ def contains_report_step(cls, filename, report_step): Will check if the @filename contains @report_step. This classmethod works by opening the file @filename and - searching through linearly to see if an ecl_kw with value - corresponding to @report_step can be found. Since this is a - classmethod it is invoked like this: - - import ecl.ecl.ecl as ecl - .... - if ecl.EclFile.contains_report_step("ECLIPSE.UNRST" , 20): - print "OK - file contains report step 20" - else: - print "File does not contain report step 20" - - If you have already loaded the file into an EclFile instance + searching through linearly to see if an rd_kw with value + corresponding to @report_step can be found. + + If you have already loaded the file into an ResdataFile instance you should use the has_report_step() method instead. """ - obj = EclFile(filename) + obj = ResdataFile(filename) return obj.has_report_step(report_step) @classmethod @@ -133,20 +123,12 @@ def contains_sim_time(cls, filename, dtime): This classmethod works by opening the file @filename and searching through linearly to see if a result block at the - time corresponding to @dtime can be found. Since this is a - classmethod it is invoked like this: + time corresponding to @dtime can be found. - import ecl.ecl.ecl as ecl - .... - if ecl.EclFile.contains_sim_time("ECLIPSE.UNRST" , datetime.datetime( 2007 , 10 , 10) ): - print "OK - file contains 10th of October 2007" - else: - print "File does not contain 10th of October 2007" - - If you have already loaded the file into an EclFile instance + If you have already loaded the file into an ResdataFile instance you should use the has_sim_time() method instead. """ - obj = EclFile(filename) + obj = ResdataFile(filename) return obj.has_sim_time(dtime) @property @@ -178,7 +160,7 @@ def file_report_list(cls, filename): Will identify the available report_steps from @filename. """ - file = EclFile(filename) + file = ResdataFile(filename) return file.report_list def __repr__(self): @@ -186,27 +168,27 @@ def __repr__(self): wr = ", read/write" if self._writable() else "" return self._create_repr('"%s"%s' % (fn, wr)) - def __init__(self, filename, flags=ECL_FILE_DEFAULT, index_filename=None): + def __init__(self, filename, flags=FileMode.DEFAULT, index_filename=None): """ Loads the complete file @filename. - Will create a new EclFile instance with the content of file + Will create a new ResdataFile instance with the content of file @filename. The file @filename must be in 'restart format' - otherwise it will be crash and burn. The optional argument flags can be an or'ed combination of the flags: - ecl.ECL_FILE_WRITABLE : It is possible to update the + WRITABLE : It is possible to update the content of the keywords in the file. - ecl.ECL_FILE_CLOSE_STREAM : The underlying FILE * is closed + CLOSE_STREAM : The underlying FILE * is closed when not used; to save number of open file descriptors - in cases where a high number of EclFile instances are + in cases where a high number of ResdataFile instances are open concurrently. - When the file has been loaded the EclFile instance can be used - to query for and get reference to the EclKW instances + When the file has been loaded the ResdataFile instance can be used + to query for and get reference to the ResdataKW instances constituting the file, like e.g. SWAT from a restart file or FIPNUM from an INIT file. """ @@ -218,7 +200,7 @@ def __init__(self, filename, flags=ECL_FILE_DEFAULT, index_filename=None): if c_ptr is None: raise IOError('Failed to open file "%s"' % filename) else: - super(EclFile, self).__init__(c_ptr) + super(ResdataFile, self).__init__(c_ptr) self.global_view = self._get_global_view() self.global_view.setParent(self) @@ -228,13 +210,13 @@ def save_kw(self, kw): This function should typically be used in situations like this: - 1. Create an EclFile instance around an ECLIPSE output file. + 1. Create an ResdataFile instance around a restart format file. 2. Extract a keyword of interest and modify it. 3. Call this method to save the modifications to disk. There are several restrictions to the use of this function: - 1. The EclFile instance must have been created with the + 1. The ResdataFile instance must have been created with the optional read_only flag set to False. 2. You can only modify the content of the keyword; if you @@ -242,7 +224,7 @@ def save_kw(self, kw): or name) the function will fail. 3. The keyword you are trying to save must be exactly the - keyword you got from this EclFile instance, otherwise the + keyword you got from this ResdataFile instance, otherwise the function will fail. """ if self._writable(): @@ -288,17 +270,17 @@ def restart_view( def select_block(self, kw, kw_index): raise NotImplementedError( - "The select_block implementation has been removed - use EclFileView" + "The select_block implementation has been removed - use ResdataFileView" ) def select_global(self): raise NotImplementedError( - "The select_global implementation has been removed - use EclFileView" + "The select_global implementation has been removed - use ResdataFileView" ) def select_restart_section(self, index=None, report_step=None, sim_time=None): raise NotImplementedError( - "The select_restart_section implementation has been removed - use EclFileView" + "The select_restart_section implementation has been removed - use ResdataFileView" ) """ Will select a restart section as the active section. @@ -324,7 +306,7 @@ def select_restart_section(self, index=None, report_step=None, sim_time=None): def select_last_restart(self): raise NotImplementedError( - "The select_restart_section implementation has been removed - use EclFileView" + "The select_restart_section implementation has been removed - use ResdataFileView" ) """ Will select the last SEQNUM block in restart file. @@ -339,18 +321,18 @@ def __getitem__(self, index): """ Implements [] operator; index can be integer or key. - Will look up EclKW instances from the current EclFile + Will look up ResdataKW instances from the current ResdataFile instance. The @index argument can either be an integer, in - which case the method will return EclKW number @index, or + which case the method will return ResdataKW number @index, or alternatively a keyword string, in which case the method will - return a list of EclKW instances with that keyword: + return a list of ResdataKW instances with that keyword: - restart_file = ecl_file.EclFile("ECLIPSE.UNRST") + restart_file = rd_file.ResdataFile("CASE.UNRST") kw9 = restart_file[9] swat_list = restart_file["SWAT"] The keyword based lookup can be combined with an extra [] to - get EclKW instance nr: + get ResdataKW instance nr: swat9 = restart_file["SWAT"][9] @@ -358,7 +340,7 @@ def __getitem__(self, index): following example will iterate over all the SWAT keywords in a restart file: - restart_file = ecl_file.EclFile("ECLIPSE.UNRST") + restart_file = rd_file.ResdataFile("CASE.UNRST") for swat in restart_file["SWAT"]: .... """ @@ -375,10 +357,10 @@ def __getitem__(self, index): def iget_kw(self, index, copy=False): """ - Will return EclKW instance nr @index. + Will return ResdataKW instance nr @index. - In the files loaded with the EclFile implementation the - ECLIPSE keywords come sequentially in a long series, an INIT + In the files loaded with the ResdataFile implementation the + keywords come sequentially in a long series, an INIT file might have the following keywords: INTEHEAD @@ -395,16 +377,16 @@ def iget_kw(self, index, copy=False): MULTY ..... - The iget_kw() method will give you a EclKW reference to + The iget_kw() method will give you a ResdataKW reference to keyword nr @index. This functionality is also available through the index operator []: - file = EclFile( "ECLIPSE.INIT" ) + file = ResdataFile( "CASE.INIT" ) permx = file.iget_kw( 7 ) permz = file[ 9 ] - Observe that the returned EclKW instance is only a reference - to the data owned by the EclFile instance. + Observe that the returned ResdataKW instance is only a reference + to the data owned by the ResdataFile instance. The method iget_named_kw() which lets you specify the name of the keyword you are interested in is in general more useful @@ -412,7 +394,7 @@ def iget_kw(self, index, copy=False): """ kw = self[index] if copy: - return EclKW.copy(kw) + return ResdataKW.copy(kw) else: return kw @@ -420,19 +402,19 @@ def iget_named_kw(self, kw_name, index, copy=False): return self.global_view.iget_named_kw(kw_name, index) def restart_get_kw(self, kw_name, dtime, copy=False): - """Will return EclKW @kw_name from restart file at time @dtime. + """Will return ResdataKW @kw_name from restart file at time @dtime. - This function assumes that the current EclFile instance + This function assumes that the current ResdataFile instance represents a restart file. It will then look for keyword @kw_name exactly at the time @dtime; @dtime is a datetime instance: - file = EclFile( "ECLIPSE.UNRST" ) + file = ResdataFile( "CASE.UNRST" ) swat2010 = file.restart_get_kw( "SWAT" , datetime.datetime( 2000 , 1 , 1 )) By default the returned kw instance is a reference to the - ecl_kw still contained in the EclFile instance; i.e. the kw - will become a dangling reference if the EclFile instance goes + rd_kw still contained in the ResdataFile instance; i.e. the kw + will become a dangling reference if the ResdataFile instance goes out of scope. If the optional argument @copy is True the returned kw will be a true copy. @@ -445,7 +427,7 @@ def restart_get_kw(self, kw_name, dtime, copy=False): if self.num_named_kw(kw_name) > index: kw = self.iget_named_kw(kw_name, index) if copy: - return EclKW.copy(kw) + return ResdataKW.copy(kw) else: return kw else: @@ -462,14 +444,14 @@ def restart_get_kw(self, kw_name, dtime, copy=False): def replace_kw(self, old_kw, new_kw): """ - Will replace @old_kw with @new_kw in current EclFile instance. + Will replace @old_kw with @new_kw in current ResdataFile instance. - This method can be used to replace one of the EclKW instances - in the current EclFile. The @old_kw reference must be to the - actual EclKW instance in the current EclFile instance (the + This method can be used to replace one of the ResdataKW instances + in the current ResdataFile. The @old_kw reference must be to the + actual ResdataKW instance in the current ResdataFile instance (the final comparison is based on C pointer equality!), i.e. it must be a reference (not a copy) from one of the ??get_kw?? - methods of the EclFile class. In the example below we replace + methods of the ResdataFile class. In the example below we replace the SWAT keyword from a restart file: swat = file.iget_named_kw( "SWAT" , 0 ) @@ -477,34 +459,34 @@ def replace_kw(self, old_kw, new_kw): file.replace_kw( swat , new_swat ) - The C-level ecl_file_type structure takes full ownership of - all installed ecl_kw instances; mixing the garbage collector + The C-level rd_file_type structure takes full ownership of + all installed rd_kw instances; mixing the garbage collector into it means that this is quite low level - and potentially dangerous! """ # We ensure that this scope owns the new_kw instance; the - # new_kw will be handed over to the ecl_file instance, and we + # new_kw will be handed over to the rd_file instance, and we # can not give away something we do not alreeady own. if not new_kw.data_owner: - new_kw = EclKW.copy(new_kw) + new_kw = ResdataKW.copy(new_kw) - # The ecl_file instance will take responsability for freeing - # this ecl_kw instance. + # The rd_file instance will take responsability for freeing + # this rd_kw instance. new_kw.data_owner = False self._replace_kw(old_kw, new_kw, False) @property def size(self): """ - The number of keywords in the current EclFile object. + The number of keywords in the current ResdataFile object. """ return len(self) @property def unique_size(self): """ - The number of unique keyword (names) in the current EclFile object. + The number of unique keyword (names) in the current ResdataFile object. """ return self.global_view.uniqueSize() @@ -535,7 +517,7 @@ def report_steps(self): Will return a list of all report steps. The method works by iterating through the whole restart file - looking for 'SEQNUM' keywords; if the current EclFile instance + looking for 'SEQNUM' keywords; if the current ResdataFile instance is not a restart file it will not contain any 'SEQNUM' keywords and the method will simply return an empty list. """ @@ -561,7 +543,7 @@ def report_dates(self): dates.append(self.iget_restart_sim_time(index)) return dates elif "INTEHEAD" in self: - # This is a uber-hack; should export the ecl_rsthead + # This is a uber-hack; should export the rd_rsthead # object as ctypes structure. intehead = self["INTEHEAD"][0] year = intehead[66] @@ -580,16 +562,16 @@ def dates(self): def num_named_kw(self, kw): """ - The number of keywords with name == @kw in the current EclFile object. + The number of keywords with name == @kw in the current ResdataFile object. """ return self.global_view.numKeywords(kw) def has_kw(self, kw, num=0): """ - Check if current EclFile instance has a keyword @kw. + Check if current ResdataFile instance has a keyword @kw. If the optional argument @num is given it will check if the - EclFile has at least @num occurences of @kw. + ResdataFile has at least @num occurences of @kw. """ return self.num_named_kw(kw) > num @@ -602,9 +584,9 @@ def __contains__(self, kw): def has_report_step(self, report_step): """ - Checks if the current EclFile has report step @report_step. + Checks if the current ResdataFile has report step @report_step. - If the EclFile in question is not a restart file, you will + If the ResdataFile in question is not a restart file, you will just get False. If you want to check if the file contains the actual report_step before loading the file, you should use the classmethod contains_report_step() instead. @@ -625,11 +607,11 @@ def num_report_steps(self): def has_sim_time(self, dtime): """ - Checks if the current EclFile has data for time @dtime. + Checks if the current ResdataFile has data for time @dtime. The implementation goes through all the INTEHEAD headers in - the EclFile, i.e. it can be fooled (and probably crash and - burn) if the EclFile instance in question is has INTEHEAD + the ResdataFile, i.e. it can be fooled (and probably crash and + burn) if the ResdataFile instance in question is has INTEHEAD keyword(s), but is still not a restart file. The @dtime argument should be a normal python datetime instance. """ @@ -660,18 +642,18 @@ def get_filename(self): def fwrite(self, fortio): """ - Will write current EclFile instance to fortio stream. + Will write current ResdataFile instance to fortio stream. ECLIPSE is written in Fortran; and a "special" handle for Fortran IO must be used when reading and writing these files. - This method will write the current EclFile instance to a + This method will write the current ResdataFile instance to a FortIO stream already opened for writing: - import ecl.ecl.ecl as ecl - ... - fortio = ecl.FortIO( "FILE.XX" ) - file.fwrite( fortio ) - fortio.close() + >>> from resdata.resfile import FortIO + + >>> fortio = FortIO( "FILE.XX" ) + >>> file.fwrite( fortio ) + >>> fortio.close() """ self._fwrite(fortio, 0) @@ -681,29 +663,29 @@ def write_index(self, index_file_name): raise IOError("Failed to write index file:%s" % index_file_name) -class EclFileContextManager(object): - def __init__(self, ecl_file): - self.__ecl_file = ecl_file +class ResdataFileContextManager(object): + def __init__(self, rd_file): + self.__rd_file = rd_file def __enter__(self): - return self.__ecl_file + return self.__rd_file def __exit__(self, exc_type, exc_val, exc_tb): - self.__ecl_file.close() + self.__rd_file.close() return False -def openEclFile(file_name, flags=ECL_FILE_DEFAULT): - print("The function openEclFile is deprecated, use open_ecl_file.") - return open_ecl_file(file_name, flags) +def openResdataFile(file_name, flags=FileMode.DEFAULT): + print("The function openResdataFile is deprecated, use open_rd_file.") + return open_rd_file(file_name, flags) -def open_ecl_file(file_name, flags=ECL_FILE_DEFAULT): - return EclFileContextManager(EclFile(file_name, flags)) +def open_rd_file(file_name, flags=FileMode.DEFAULT): + return ResdataFileContextManager(ResdataFile(file_name, flags)) -monkey_the_camel(EclFile, "getFileType", EclFile.get_filetype, staticmethod) -monkey_the_camel(EclFile, "blockView", EclFile.block_view) -monkey_the_camel(EclFile, "blockView2", EclFile.block_view2) -monkey_the_camel(EclFile, "restartView", EclFile.restart_view) -monkey_the_camel(EclFile, "getFilename", EclFile.get_filename) +monkey_the_camel(ResdataFile, "getFileType", ResdataFile.get_filetype, staticmethod) +monkey_the_camel(ResdataFile, "blockView", ResdataFile.block_view) +monkey_the_camel(ResdataFile, "blockView2", ResdataFile.block_view2) +monkey_the_camel(ResdataFile, "restartView", ResdataFile.restart_view) +monkey_the_camel(ResdataFile, "getFilename", ResdataFile.get_filename) diff --git a/python/ecl/eclfile/ecl_file_view.py b/python/resdata/resfile/rd_file_view.py similarity index 69% rename from python/ecl/eclfile/ecl_file_view.py rename to python/resdata/resfile/rd_file_view.py index 0a59b06a94..048c795f15 100644 --- a/python/ecl/eclfile/ecl_file_view.py +++ b/python/resdata/resfile/rd_file_view.py @@ -1,35 +1,37 @@ from __future__ import absolute_import, division, print_function, unicode_literals from six import string_types from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl.util.util import CTime -from ecl import EclPrototype +from resdata.util.util import monkey_the_camel +from resdata.util.util import CTime +from resdata import ResdataPrototype -class EclFileView(BaseCClass): - TYPE_NAME = "ecl_file_view" - _iget_kw = EclPrototype("ecl_kw_ref ecl_file_view_iget_kw( ecl_file_view , int)") - _iget_named_kw = EclPrototype( - "ecl_kw_ref ecl_file_view_iget_named_kw( ecl_file_view , char* , int)" +class ResdataFileView(BaseCClass): + TYPE_NAME = "rd_file_view" + _iget_kw = ResdataPrototype( + "rd_kw_ref rd_file_view_iget_kw( rd_file_view , int)" ) - _get_unique_kw = EclPrototype( - "char* ecl_file_view_iget_distinct_kw( ecl_file_view, int )" + _iget_named_kw = ResdataPrototype( + "rd_kw_ref rd_file_view_iget_named_kw( rd_file_view , char* , int)" ) - _get_size = EclPrototype("int ecl_file_view_get_size( ecl_file_view )") - _get_num_named_kw = EclPrototype( - "int ecl_file_view_get_num_named_kw( ecl_file_view , char* )" + _get_unique_kw = ResdataPrototype( + "char* rd_file_view_iget_distinct_kw( rd_file_view, int )" ) - _get_unique_size = EclPrototype( - "int ecl_file_view_get_num_distinct_kw( ecl_file_view )" + _get_size = ResdataPrototype("int rd_file_view_get_size( rd_file_view )") + _get_num_named_kw = ResdataPrototype( + "int rd_file_view_get_num_named_kw( rd_file_view , char* )" ) - _create_block_view = EclPrototype( - "ecl_file_view_ref ecl_file_view_add_blockview( ecl_file_view , char*, int )" + _get_unique_size = ResdataPrototype( + "int rd_file_view_get_num_distinct_kw( rd_file_view )" ) - _create_block_view2 = EclPrototype( - "ecl_file_view_ref ecl_file_view_add_blockview2( ecl_file_view , char*, char*, int )" + _create_block_view = ResdataPrototype( + "rd_file_view_ref rd_file_view_add_blockview( rd_file_view , char*, int )" ) - _restart_view = EclPrototype( - "ecl_file_view_ref ecl_file_view_add_restart_view( ecl_file_view , int, int, time_t, double )" + _create_block_view2 = ResdataPrototype( + "rd_file_view_ref rd_file_view_add_blockview2( rd_file_view , char*, char*, int )" + ) + _restart_view = ResdataPrototype( + "rd_file_view_ref rd_file_view_add_restart_view( rd_file_view , int, int, time_t, double )" ) def __init__(self): @@ -39,7 +41,7 @@ def __iget(self, index): return self._iget_kw(index).setParent(parent=self) def __repr__(self): - return "EclFileView(size=%d) %s" % (len(self), self._ad_str()) + return "ResdataFileView(size=%d) %s" % (len(self), self._ad_str()) def iget_named_kw(self, kw_name, index): if not kw_name in self: @@ -54,18 +56,18 @@ def __getitem__(self, index): """ Implements [] operator; index can be integer or key. - Will look up EclKW instances from the current EclFile + Will look up ResdataKW instances from the current ResdataFile instance. The @index argument can either be an integer, in - which case the method will return EclKW number @index, or + which case the method will return ResdataKW number @index, or alternatively a keyword string, in which case the method will - return a list of EclKW instances with that keyword: + return a list of ResdataKW instances with that keyword: - restart_file = ecl_file.EclFile("ECLIPSE.UNRST") + restart_file = rd_file.ResdataFile("CASE.UNRST") kw9 = restart_file[9] swat_list = restart_file["SWAT"] The keyword based lookup can be combined with an extra [] to - get EclKW instance nr: + get ResdataKW instance nr: swat9 = restart_file["SWAT"][9] @@ -73,7 +75,7 @@ def __getitem__(self, index): following example will iterate over all the SWAT keywords in a restart file: - restart_file = ecl_file.EclFile("ECLIPSE.UNRST") + restart_file = rd_file.ResdataFile("CASE.UNRST") for swat in restart_file["SWAT"]: .... """ @@ -189,8 +191,8 @@ def restart_view( return view -monkey_the_camel(EclFileView, "numKeywords", EclFileView.num_keywords) -monkey_the_camel(EclFileView, "uniqueSize", EclFileView.unique_size) -monkey_the_camel(EclFileView, "blockView2", EclFileView.block_view2) -monkey_the_camel(EclFileView, "blockView", EclFileView.block_view) -monkey_the_camel(EclFileView, "restartView", EclFileView.restart_view) +monkey_the_camel(ResdataFileView, "numKeywords", ResdataFileView.num_keywords) +monkey_the_camel(ResdataFileView, "uniqueSize", ResdataFileView.unique_size) +monkey_the_camel(ResdataFileView, "blockView2", ResdataFileView.block_view2) +monkey_the_camel(ResdataFileView, "blockView", ResdataFileView.block_view) +monkey_the_camel(ResdataFileView, "restartView", ResdataFileView.restart_view) diff --git a/python/resdata/resfile/rd_init_file.py b/python/resdata/resfile/rd_init_file.py new file mode 100644 index 0000000000..8771c45f40 --- /dev/null +++ b/python/resdata/resfile/rd_init_file.py @@ -0,0 +1,13 @@ +from resdata import FileMode, FileType +from resdata.resfile import Resdata3DFile, ResdataFile + + +class ResdataInitFile(Resdata3DFile): + def __init__(self, grid, filename, flags=FileMode.DEFAULT): + file_type, report_step, fmt_file = ResdataFile.getFileType(filename) + if file_type == FileType.INIT: + super(ResdataInitFile, self).__init__(grid, filename, flags) + else: + err = 'The input filename "%s" does not correspond to an init file.' + err += " Please follow the Eclipse naming conventions." + raise ValueError(err % filename) diff --git a/python/ecl/eclfile/ecl_kw.py b/python/resdata/resfile/rd_kw.py similarity index 73% rename from python/ecl/eclfile/ecl_kw.py rename to python/resdata/resfile/rd_kw.py index db29b89e01..42260babcd 100644 --- a/python/ecl/eclfile/ecl_kw.py +++ b/python/resdata/resfile/rd_kw.py @@ -1,7 +1,7 @@ """ -Support for working with one keyword from ECLIPSE file. +Support for working with one keyword. -ECLIPSE files in "restart format" are organized in keywords consisting +Files in "restart format" are organized in keywords consisting of a simple header and blocks of data. A keyword typically looks like: 'SWAT ' 10000 'REAL' @@ -19,70 +19,67 @@ files. This module also has (some) support for working with GRDECL 'formatted' files. -The ecl_kw.py implementation wraps the ecl_kw.c implementation from -the libecl library. +The rd_kw.py implementation wraps the rd_kw.c implementation from +the resdata library. """ import ctypes import warnings -import numpy +import numpy from cwrap import CFILE, BaseCClass - -from ecl import EclPrototype -from ecl.util.util import monkey_the_camel -from ecl import EclDataType -from ecl import EclTypeEnum, EclUtil +from resdata import ResdataPrototype, ResDataType, ResdataTypeEnum, ResdataUtil +from resdata.util.util import monkey_the_camel from .fortio import FortIO def dump_type_deprecation_warning(): warnings.warn( - "EclTypeEnum is deprecated. " + "You should instead provide an EclDataType", + "ResdataTypeEnum is deprecated. You should instead provide an ResDataType", DeprecationWarning, ) -def constant_size_data_type(ecl_type): - return ecl_type in [ - EclTypeEnum.ECL_CHAR_TYPE, - EclTypeEnum.ECL_FLOAT_TYPE, - EclTypeEnum.ECL_DOUBLE_TYPE, - EclTypeEnum.ECL_INT_TYPE, - EclTypeEnum.ECL_BOOL_TYPE, - EclTypeEnum.ECL_MESS_TYPE, +def constant_size_data_type(rd_type): + return rd_type in [ + ResdataTypeEnum.RD_CHAR_TYPE, + ResdataTypeEnum.RD_FLOAT_TYPE, + ResdataTypeEnum.RD_DOUBLE_TYPE, + ResdataTypeEnum.RD_INT_TYPE, + ResdataTypeEnum.RD_BOOL_TYPE, + ResdataTypeEnum.RD_MESS_TYPE, ] def warn_and_cast_data_type(data_type): - if isinstance(data_type, EclDataType): + if isinstance(data_type, ResDataType): return data_type - if isinstance(data_type, EclTypeEnum): + if isinstance(data_type, ResdataTypeEnum): if not constant_size_data_type(data_type): raise ValueError( - "Cannot cast EclTypeEnum (%d) to EclDataType due " - "to non-constant size. Please provide an EclDataType instead." + "Cannot cast ResdataTypeEnum (%d) to ResDataType due " + "to non-constant size. Please provide an ResDataType instead." ) dump_type_deprecation_warning() - return EclDataType(data_type) + return ResDataType(data_type) -class EclKW(BaseCClass): +class ResdataKW(BaseCClass): """ - The EclKW class contains the information from one ECLIPSE keyword. + The ResdataKW class contains the information from one keyword. - The ecl_kw type is the lowest level type in the libecl C library, - and all the other datatypes like e.g. ecl_grid and ecl_sum are - based on collections of ecl_kw instances, and interpreting the - content of the ecl_kw keywords. + The rd_kw type is the lowest level type in the resdata C library, + and all the other datatypes like e.g. rd_grid and rd_sum are + based on collections of rd_kw instances, and interpreting the + content of the rd_kw keywords. Many of the special __xxx___() functions have been implemented, so - that the EclKW class supports both numerical operations and also + that the ResdataKW class supports both numerical operations and also [] based lookup. Many of the methods accept an optional @mask - argument; this should be a EclRegion instance which can be used to - limit the operation to a part of the EclKW. + argument; this should be a ResdataRegion instance which can be used to + limit the operation to a part of the ResdataKW. """ int_kw_set = set( @@ -98,116 +95,120 @@ class EclKW(BaseCClass): ] ) - TYPE_NAME = "ecl_kw" - _alloc_new = EclPrototype( - "void* ecl_kw_alloc_python(char*, int, ecl_data_type)", bind=False + TYPE_NAME = "rd_kw" + _alloc_new = ResdataPrototype( + "void* rd_kw_alloc_python(char*, int, rd_data_type)", bind=False ) - _fread_alloc = EclPrototype("ecl_kw_obj ecl_kw_fread_alloc(fortio)", bind=False) - _load_grdecl = EclPrototype( - "ecl_kw_obj ecl_kw_fscanf_alloc_grdecl_dynamic_python(FILE, char*, bool, ecl_data_type)", + _fread_alloc = ResdataPrototype("rd_kw_obj rd_kw_fread_alloc(fortio)", bind=False) + _load_grdecl = ResdataPrototype( + "rd_kw_obj rd_kw_fscanf_alloc_grdecl_dynamic_python(FILE, char*, bool, rd_data_type)", bind=False, ) - _fseek_grdecl = EclPrototype( - "bool ecl_kw_grdecl_fseek_kw(char*, bool, FILE)", bind=False + _fseek_grdecl = ResdataPrototype( + "bool rd_kw_grdecl_fseek_kw(char*, bool, FILE)", bind=False ) - _sub_copy = EclPrototype( - "ecl_kw_obj ecl_kw_alloc_sub_copy(ecl_kw, char*, int, int)" + _sub_copy = ResdataPrototype( + "rd_kw_obj rd_kw_alloc_sub_copy(rd_kw, char*, int, int)" ) - _copyc = EclPrototype("ecl_kw_obj ecl_kw_alloc_copy(ecl_kw)") - _slice_copyc = EclPrototype( - "ecl_kw_obj ecl_kw_alloc_slice_copy(ecl_kw, int, int, int)" + _copyc = ResdataPrototype("rd_kw_obj rd_kw_alloc_copy(rd_kw)") + _slice_copyc = ResdataPrototype( + "rd_kw_obj rd_kw_alloc_slice_copy(rd_kw, int, int, int)" ) - _global_copy = EclPrototype("ecl_kw_obj ecl_kw_alloc_global_copy(ecl_kw, ecl_kw)") - _fprintf_grdecl = EclPrototype("void ecl_kw_fprintf_grdecl(ecl_kw, FILE)") - _fprintf_data = EclPrototype("void ecl_kw_fprintf_data(ecl_kw, char*, FILE)") - - _get_size = EclPrototype("int ecl_kw_get_size(ecl_kw)") - _get_fortio_size = EclPrototype("size_t ecl_kw_fortio_size(ecl_kw)") - _get_type = EclPrototype("ecl_type_enum ecl_kw_get_type(ecl_kw)") - _iget_char_ptr = EclPrototype("char* ecl_kw_iget_char_ptr(ecl_kw, int)") - _iset_char_ptr = EclPrototype("void ecl_kw_iset_char_ptr(ecl_kw, int, char*)") - _iget_string_ptr = EclPrototype("char* ecl_kw_iget_string_ptr(ecl_kw, int)") - _iset_string_ptr = EclPrototype( - "void ecl_kw_iset_string_ptr(ecl_kw, int, char*)" + _global_copy = ResdataPrototype("rd_kw_obj rd_kw_alloc_global_copy(rd_kw, rd_kw)") + _fprintf_grdecl = ResdataPrototype("void rd_kw_fprintf_grdecl(rd_kw, FILE)") + _fprintf_data = ResdataPrototype("void rd_kw_fprintf_data(rd_kw, char*, FILE)") + + _get_size = ResdataPrototype("int rd_kw_get_size(rd_kw)") + _get_fortio_size = ResdataPrototype("size_t rd_kw_fortio_size(rd_kw)") + _get_type = ResdataPrototype("rd_type_enum rd_kw_get_type(rd_kw)") + _iget_char_ptr = ResdataPrototype("char* rd_kw_iget_char_ptr(rd_kw, int)") + _iset_char_ptr = ResdataPrototype("void rd_kw_iset_char_ptr(rd_kw, int, char*)") + _iget_string_ptr = ResdataPrototype("char* rd_kw_iget_string_ptr(rd_kw, int)") + _iset_string_ptr = ResdataPrototype( + "void rd_kw_iset_string_ptr(rd_kw, int, char*)" ) - _iget_bool = EclPrototype("bool ecl_kw_iget_bool(ecl_kw, int)") - _iset_bool = EclPrototype("bool ecl_kw_iset_bool(ecl_kw, int, bool)") - _iget_int = EclPrototype("int ecl_kw_iget_int(ecl_kw, int)") - _iget_double = EclPrototype("double ecl_kw_iget_double(ecl_kw, int)") - _iget_float = EclPrototype("float ecl_kw_iget_float(ecl_kw, int)") - _float_ptr = EclPrototype("float* ecl_kw_get_float_ptr(ecl_kw)") - _int_ptr = EclPrototype("int* ecl_kw_get_int_ptr(ecl_kw)") - _double_ptr = EclPrototype("double* ecl_kw_get_double_ptr(ecl_kw)") - _free = EclPrototype("void ecl_kw_free(ecl_kw)") - _fwrite = EclPrototype("void ecl_kw_fwrite(ecl_kw, fortio)") - _get_header = EclPrototype("char* ecl_kw_get_header (ecl_kw)") - _set_header = EclPrototype("void ecl_kw_set_header_name (ecl_kw, char*)") - _get_data_type = EclPrototype( - "ecl_data_type_obj ecl_kw_get_data_type_python(ecl_kw)" + _iget_bool = ResdataPrototype("bool rd_kw_iget_bool(rd_kw, int)") + _iset_bool = ResdataPrototype("bool rd_kw_iset_bool(rd_kw, int, bool)") + _iget_int = ResdataPrototype("int rd_kw_iget_int(rd_kw, int)") + _iget_double = ResdataPrototype("double rd_kw_iget_double(rd_kw, int)") + _iget_float = ResdataPrototype("float rd_kw_iget_float(rd_kw, int)") + _float_ptr = ResdataPrototype("float* rd_kw_get_float_ptr(rd_kw)") + _int_ptr = ResdataPrototype("int* rd_kw_get_int_ptr(rd_kw)") + _double_ptr = ResdataPrototype("double* rd_kw_get_double_ptr(rd_kw)") + _free = ResdataPrototype("void rd_kw_free(rd_kw)") + _fwrite = ResdataPrototype("void rd_kw_fwrite(rd_kw, fortio)") + _get_header = ResdataPrototype("char* rd_kw_get_header (rd_kw)") + _set_header = ResdataPrototype("void rd_kw_set_header_name (rd_kw, char*)") + _get_data_type = ResdataPrototype( + "rd_data_type_obj rd_kw_get_data_type_python(rd_kw)" ) - _int_sum = EclPrototype("int ecl_kw_element_sum_int(ecl_kw)") - _float_sum = EclPrototype("double ecl_kw_element_sum_float(ecl_kw)") - _iadd_squared = EclPrototype("void ecl_kw_inplace_add_squared(ecl_kw, ecl_kw)") - _isqrt = EclPrototype("void ecl_kw_inplace_sqrt(ecl_kw)") - _iadd = EclPrototype("void ecl_kw_inplace_add(ecl_kw, ecl_kw)") - _imul = EclPrototype("void ecl_kw_inplace_mul(ecl_kw, ecl_kw)") - _idiv = EclPrototype("void ecl_kw_inplace_div(ecl_kw, ecl_kw)") - _isub = EclPrototype("void ecl_kw_inplace_sub(ecl_kw, ecl_kw)") - _iabs = EclPrototype("void ecl_kw_inplace_abs(ecl_kw)") - _equal = EclPrototype("bool ecl_kw_equal(ecl_kw, ecl_kw)") - _equal_numeric = EclPrototype( - "bool ecl_kw_numeric_equal(ecl_kw, ecl_kw, double, double)" + _int_sum = ResdataPrototype("int rd_kw_element_sum_int(rd_kw)") + _float_sum = ResdataPrototype("double rd_kw_element_sum_float(rd_kw)") + _iadd_squared = ResdataPrototype("void rd_kw_inplace_add_squared(rd_kw, rd_kw)") + _isqrt = ResdataPrototype("void rd_kw_inplace_sqrt(rd_kw)") + _iadd = ResdataPrototype("void rd_kw_inplace_add(rd_kw, rd_kw)") + _imul = ResdataPrototype("void rd_kw_inplace_mul(rd_kw, rd_kw)") + _idiv = ResdataPrototype("void rd_kw_inplace_div(rd_kw, rd_kw)") + _isub = ResdataPrototype("void rd_kw_inplace_sub(rd_kw, rd_kw)") + _iabs = ResdataPrototype("void rd_kw_inplace_abs(rd_kw)") + _equal = ResdataPrototype("bool rd_kw_equal(rd_kw, rd_kw)") + _equal_numeric = ResdataPrototype( + "bool rd_kw_numeric_equal(rd_kw, rd_kw, double, double)" ) - _assert_binary = EclPrototype( - "bool ecl_kw_size_and_numeric_type_equal(ecl_kw, ecl_kw)" + _assert_binary = ResdataPrototype( + "bool rd_kw_size_and_numeric_type_equal(rd_kw, rd_kw)" + ) + _scale_int = ResdataPrototype("void rd_kw_scale_int(rd_kw, int)") + _scale_float = ResdataPrototype( + "void rd_kw_scale_float_or_double(rd_kw, double)" + ) + _shift_int = ResdataPrototype("void rd_kw_shift_int(rd_kw, int)") + _shift_float = ResdataPrototype( + "void rd_kw_shift_float_or_double(rd_kw, double)" ) - _scale_int = EclPrototype("void ecl_kw_scale_int(ecl_kw, int)") - _scale_float = EclPrototype("void ecl_kw_scale_float_or_double(ecl_kw, double)") - _shift_int = EclPrototype("void ecl_kw_shift_int(ecl_kw, int)") - _shift_float = EclPrototype("void ecl_kw_shift_float_or_double(ecl_kw, double)") - _copy_data = EclPrototype("void ecl_kw_memcpy_data(ecl_kw, ecl_kw)") - _set_int = EclPrototype("void ecl_kw_scalar_set_int(ecl_kw, int)") - _set_float = EclPrototype( - "void ecl_kw_scalar_set_float_or_double(ecl_kw, double)" + _copy_data = ResdataPrototype("void rd_kw_memcpy_data(rd_kw, rd_kw)") + _set_int = ResdataPrototype("void rd_kw_scalar_set_int(rd_kw, int)") + _set_float = ResdataPrototype( + "void rd_kw_scalar_set_float_or_double(rd_kw, double)" ) - _max_min_int = EclPrototype("void ecl_kw_max_min_int(ecl_kw, int*, int*)") - _max_min_float = EclPrototype( - "void ecl_kw_max_min_float(ecl_kw, float*, float*)" + _max_min_int = ResdataPrototype("void rd_kw_max_min_int(rd_kw, int*, int*)") + _max_min_float = ResdataPrototype( + "void rd_kw_max_min_float(rd_kw, float*, float*)" ) - _max_min_double = EclPrototype( - "void ecl_kw_max_min_double(ecl_kw, double*, double*)" + _max_min_double = ResdataPrototype( + "void rd_kw_max_min_double(rd_kw, double*, double*)" ) - _fix_uninitialized = EclPrototype( - "void ecl_kw_fix_uninitialized(ecl_kw,int, int, int, int*)" + _fix_uninitialized = ResdataPrototype( + "void rd_kw_fix_uninitialized(rd_kw,int, int, int, int*)" ) - _create_actnum = EclPrototype("ecl_kw_obj ecl_kw_alloc_actnum(ecl_kw, float)") - _first_different = EclPrototype( - "int ecl_kw_first_different(ecl_kw, ecl_kw, int, double, double)" + _create_actnum = ResdataPrototype("rd_kw_obj rd_kw_alloc_actnum(rd_kw, float)") + _first_different = ResdataPrototype( + "int rd_kw_first_different(rd_kw, rd_kw, int, double, double)" ) - _resize = EclPrototype("void ecl_kw_resize(ecl_kw, int)") - _safe_div = EclPrototype("bool ecl_kw_inplace_safe_div(ecl_kw,ecl_kw)") + _resize = ResdataPrototype("void rd_kw_resize(rd_kw, int)") + _safe_div = ResdataPrototype("bool rd_kw_inplace_safe_div(rd_kw,rd_kw)") @classmethod def createCReference(cls, c_ptr, parent=None): - ecl_kw = super(EclKW, cls).createCReference(c_ptr, parent=parent) - if ecl_kw is None: - raise ValueError("Failed to create EclKW instance") + rd_kw = super(ResdataKW, cls).createCReference(c_ptr, parent=parent) + if rd_kw is None: + raise ValueError("Failed to create ResdataKW instance") - ecl_kw.__private_init() - return ecl_kw + rd_kw.__private_init() + return rd_kw @classmethod def createPythonObject(cls, c_ptr): - ecl_kw = super(EclKW, cls).createPythonObject(c_ptr) - if ecl_kw is None: - raise ValueError("Failed to create EclKW instance") + rd_kw = super(ResdataKW, cls).createPythonObject(c_ptr) + if rd_kw is None: + raise ValueError("Failed to create ResdataKW instance") - ecl_kw.__private_init() - return ecl_kw + rd_kw.__private_init() + return rd_kw @classmethod def add_int_kw(cls, kw): @@ -238,11 +239,11 @@ def copy(self): return self._copyc() @classmethod - def read_grdecl(cls, fileH, kw, strict=True, ecl_type=None): + def read_grdecl(cls, fileH, kw, strict=True, rd_type=None): """ - Function to load an EclKW instance from a grdecl formatted filehandle. + Function to load an ResdataKW instance from a grdecl formatted filehandle. - This constructor can be used to load an EclKW instance from a + This constructor can be used to load an ResdataKW instance from a grdecl formatted file; the input files for petrophysical properties are typically given as grdecl files. @@ -270,32 +271,32 @@ def read_grdecl(cls, fileH, kw, strict=True, ecl_type=None): reading the file. The algorithm for specifying type, in order of presedence, is as follows: - 1. The optional argument @ecl_type can be used to specify + 1. The optional argument @rd_type can be used to specify the type: - special_int_kw = EclKW.read_grdecl(fileH, 'INTKW', ecl_type=ECL_INT) + special_int_kw = ResdataKW.read_grdecl(fileH, 'INTKW', rd_type=RD_INT) - If ecl_type is different from ECL_INT or - ECL_FLOAT a TypeError exception will be raised. + If rd_type is different from RD_INT or + RD_FLOAT a TypeError exception will be raised. - If ecl_type == None (the default), the method will continue + If rd_type == None (the default), the method will continue to point 2. or 3. to determine the correct type. 2. If the keyword is included in the set built in set - 'int_kw_set' the type will be ECL_INT_TYPE. + 'int_kw_set' the type will be RD_INT_TYPE. - pvtnum_kw = EclKW.read_grdecl(fileH, 'PVTNUM') + pvtnum_kw = ResdataKW.read_grdecl(fileH, 'PVTNUM') Observe that (currently) no case conversions take place when checking the 'int_kw_set'. The current built in set is accesible through the int_kw property. - 3. Otherwise the default is float, i.e. ECL_FLOAT. + 3. Otherwise the default is float, i.e. RD_FLOAT. - EclKw reads grdecl with EclDataType - poro_kw = EclKW.read_grdecl(fileH, 'PORO') + ResdataKw reads grdecl with ResDataType + poro_kw = ResdataKW.read_grdecl(fileH, 'PORO') Observe that since the grdecl files are quite weakly @@ -316,24 +317,24 @@ def read_grdecl(cls, fileH, kw, strict=True, ecl_type=None): % kw ) - if ecl_type is None: + if rd_type is None: if cls.int_kw_set.__contains__(kw): - ecl_type = EclDataType.ECL_INT + rd_type = ResDataType.RD_INT else: - ecl_type = EclDataType.ECL_FLOAT + rd_type = ResDataType.RD_FLOAT - ecl_type = warn_and_cast_data_type(ecl_type) + rd_type = warn_and_cast_data_type(rd_type) - if not isinstance(ecl_type, EclDataType): - raise TypeError("Expected EclDataType, was: %s" % type(ecl_type)) + if not isinstance(rd_type, ResDataType): + raise TypeError("Expected ResDataType, was: %s" % type(rd_type)) - if not ecl_type in [EclDataType.ECL_FLOAT, EclDataType.ECL_INT]: + if not rd_type in [ResDataType.RD_FLOAT, ResDataType.RD_INT]: raise ValueError( "The type:%s is invalid when loading keyword:%s" - % (ecl_type.type_name, kw) + % (rd_type.type_name, kw) ) - return cls._load_grdecl(cfile, kw, strict, ecl_type) + return cls._load_grdecl(cfile, kw, strict, rd_type) @classmethod def fseek_grdecl(cls, fileH, kw, rewind=False): @@ -366,7 +367,7 @@ def fseek_grdecl(cls, fileH, kw, rewind=False): @classmethod def fread(cls, fortio): """ - Will read a new EclKW instance from the open FortIO file. + Will read a new ResdataKW instance from the open FortIO file. """ return cls._fread_alloc(fortio) @@ -381,18 +382,18 @@ def __repr__(self): mi, ma = self.getMinMax() mm = "min=%.2f, max=%.2f" % (mi, ma) ad = self._ad_str() - fmt = 'EclKW(size=%d, name="%s", %s) %s' + fmt = 'ResdataKW(size=%d, name="%s", %s) %s' return fmt % (si, nm, mm, ad) def __init__(self, name, size, data_type): - """Creates a brand new EclKW instance. + """Creates a brand new ResdataKW instance. - This method will create a grand spanking new EclKW + This method will create a grand spanking new ResdataKW instance. The instance will get name @name @size elements and datatype @data_type. Using this method you could create a SOIL keyword with: - soil_kw = EclKW("SOIL", 10000, ECL_FLOAT_TYPE) + soil_kw = ResdataKW("SOIL", 10000, RD_FLOAT_TYPE) """ if len(name) > 8: @@ -400,11 +401,11 @@ def __init__(self, name, size, data_type): data_type = warn_and_cast_data_type(data_type) - if not isinstance(data_type, EclDataType): - raise TypeError("Expected an EclDataType, received: %s" % type(data_type)) + if not isinstance(data_type, ResDataType): + raise TypeError("Expected an ResDataType, received: %s" % type(data_type)) c_ptr = self._alloc_new(name, size, data_type) - super(EclKW, self).__init__(c_ptr) + super(ResdataKW, self).__init__(c_ptr) self.__private_init() def __private_init(self): @@ -435,7 +436,7 @@ def __private_init(self): elif self.data_type.is_string(): self.str_fmt = "%" + str(self.data_type.element_size) + "s" else: - raise ValueError("Unknown EclDataType (%s)!" % self.data_type.type_name) + raise ValueError("Unknown ResDataType (%s)!" % self.data_type.type_name) def sub_copy(self, offset, count, new_header=None): """ @@ -471,7 +472,7 @@ def is_numeric(self): """ return self.data_type.is_numeric() - def ecl_kw_instance(self): + def rd_kw_instance(self): return True def __len__(self): @@ -484,8 +485,8 @@ def __deep_copy__(self, memo): """ Python special routine used to perform deep copy. """ - ecl_kw = self.copy() - return ecl_kw + rd_kw = self.copy() + return rd_kw def __getitem__(self, index): """ @@ -553,7 +554,7 @@ def __setitem__(self, index, value): def __IMUL__(self, factor, mul=True): if self.isNumeric(): - if hasattr(factor, "ecl_kw_instance"): + if hasattr(factor, "rd_kw_instance"): if self.assert_binary(factor): if mul: self._imul(factor) @@ -724,31 +725,31 @@ def assign(self, value, mask=None, force_active=False): """ Assign a value to current kw instance. - This method is used to assign value(s) to the current EclKW + This method is used to assign value(s) to the current ResdataKW instance. The @value parameter can either be a scalar, or - another EclKW instance. To set all elements of a keyword to + another ResdataKW instance. To set all elements of a keyword to 1.0: kw.assign(1.0) The numerical type of @value must be compatible with the current keyword. The optional @mask argument should be an - EclRegion instance which can be used to limit the assignment - to only parts of the EclKW. In the example below we select all + ResdataRegion instance which can be used to limit the assignment + to only parts of the ResdataKW. In the example below we select all the elements with PORO below 0.10, and then assign EQLNUM value 88 to those cells: - grid = ecl.EclGrid("ECLIPSE.EGRID") - reg = ecl.EclRegion(grid, false) - init = ecl.EclFile("ECLIPSE.INIT") + >>> grid = Grid("CASE.EGRID") + >>> reg = ResdataRegion(grid, false) + >>> init = ResdataFile("CASE.INIT") - poro = init["PORO"][0] - eqlnum = init["EQLNUM"][0] - reg.select_below(poro, 0.10) + >>> poro = init["PORO"][0] + >>> eqlnum = init["EQLNUM"][0] + >>> reg.select_below(poro, 0.10) - eqlnum.assign(88, mask = reg) + >>> eqlnum.assign(88, mask = reg) - The EclRegion instance has two equivalent sets of selected + The ResdataRegion instance has two equivalent sets of selected indices; one consisting of active indices and one consisting of global indices. By default the assign() method will select the global indices if the keyword has nx*ny*nz elements and @@ -826,7 +827,7 @@ def apply(self, func, arg=None, mask=None, force_active=False): """ Will apply the function @func on the keyword - inplace. - The function @func should take a scalar value from the ecl_kw + The function @func should take a scalar value from the rd_kw vector as input, and return a scalar value of the same type; optionally you can supply a second argument with the @arg attribute: @@ -868,10 +869,10 @@ def equal(self, other): The check is based on the content of the keywords, and not pointer comparison. """ - if isinstance(other, EclKW): + if isinstance(other, ResdataKW): return self._equal(other) else: - raise TypeError("Can only compare with another EclKW") + raise TypeError("Can only compare with another ResdataKW") def __eq__(self, other): return self.equal(other) @@ -890,7 +891,7 @@ def equal_numeric(self, other, epsilon=1e-6, abs_epsilon=None, rel_epsilon=None) ignored in the test. """ - if isinstance(other, EclKW): + if isinstance(other, ResdataKW): if abs_epsilon is None: abs_epsilon = epsilon @@ -899,13 +900,13 @@ def equal_numeric(self, other, epsilon=1e-6, abs_epsilon=None, rel_epsilon=None) return self._equal_numeric(other, abs_epsilon, rel_epsilon) else: - raise TypeError("Can only compare with another EclKW") + raise TypeError("Can only compare with another ResdataKW") ################################################################# def deep_copy(self): - ecl_kw = self.__deep_copy__({}) - return ecl_kw + rd_kw = self.__deep_copy__({}) + return rd_kw def fort_io_size(self): """ @@ -979,7 +980,7 @@ def get_min(self): @property def type(self): - warnings.warn("ecl_kw.type is deprecated, use .data_type", DeprecationWarning) + warnings.warn("rd_kw.type is deprecated, use .data_type", DeprecationWarning) return self._get_type() @property @@ -993,9 +994,10 @@ def type_name(self): def type_name(self): return self.data_type.type_name - def get_ecl_type(self): + def get_rd_type(self): warnings.warn( - "EclTypeEnum is deprecated. " + "You should instead provide an EclDataType", + "ResdataTypeEnum is deprecated. " + + "You should instead provide an ResDataType", DeprecationWarning, ) @@ -1069,7 +1071,7 @@ def __str__(self): def numpy_view(self): """Will return a numpy view to the underlying data. - The data in this numpy array is *shared* with the EclKW + The data in this numpy array is *shared* with the ResdataKW instance, meaning that updates in one will be reflected in the other. """ @@ -1089,12 +1091,12 @@ def numpy_view(self): return numpy.frombuffer(ap.contents, dtype=self.dtype) def numpy_copy(self): - """Will return a numpy array which contains a copy of the EclKW data. + """Will return a numpy array which contains a copy of the ResdataKW data. The numpy array has a separate copy of the data, so that - changes to either the numpy array or the EclKW will *not* be + changes to either the numpy array or the ResdataKW will *not* be reflected in the other datastructure. This is in contrast to - the EclKW.numpyView() method where the underlying data is + the ResdataKW.numpyView() method where the underlying data is shared. """ view = self.numpyView() @@ -1113,16 +1115,16 @@ def write_grdecl(self, file): existing GRDECL file, set all poro values below 0.05 to 0.00 and write back an updated GRDECL file. - poro = ecl.EclKW.read_grdecl(open("poro1.grdecl", "r"), "PORO") - grid = ecl.EclGrid("ECLIPSE.EGRID") - reg = ecl.EclRegion(grid, False) + >>> poro = ResdataKW.read_grdecl(open("poro1.grdecl", "r"), "PORO") + >>> grid = Grid("CASE.EGRID") + >>> reg = ResdataRegion(grid, False) - reg.select_below(poro, 0.05) - poro.assign(0.0, mask=reg) + >>> reg.select_below(poro, 0.05) + >>> poro.assign(0.0, mask=reg) - fileH = open("poro2.grdecl", "w") - poro.write_grdecl(fileH) - fileH.close() + >>> fileH = open("poro2.grdecl", "w") + >>> poro.write_grdecl(fileH) + >>> fileH.close() """ cfile = CFILE(file) @@ -1207,8 +1209,8 @@ def first_different( return self._first_different(other, offset, abs_epsilon, rel_epsilon) def scatter_copy(self, actnum): - if not isinstance(actnum, EclKW): - raise TypeError("The actnum argument must be of type EclKW") + if not isinstance(actnum, ResdataKW): + raise TypeError("The actnum argument must be of type ResdataKW") return self._global_copy(actnum) @@ -1231,18 +1233,18 @@ def safe_div(self, divisor): ) -monkey_the_camel(EclKW, "intKeywords", EclKW.int_keywords, classmethod) -monkey_the_camel(EclKW, "isNumeric", EclKW.is_numeric) -monkey_the_camel(EclKW, "fortIOSize", EclKW.fort_io_size) -monkey_the_camel(EclKW, "setName", EclKW.set_name) -monkey_the_camel(EclKW, "getName", EclKW.get_name) -monkey_the_camel(EclKW, "getMinMax", EclKW.get_min_max) -monkey_the_camel(EclKW, "getMax", EclKW.get_max) -monkey_the_camel(EclKW, "getMin", EclKW.get_min) -monkey_the_camel(EclKW, "typeName", EclKW.type_name) -monkey_the_camel(EclKW, "getEclType", EclKW.get_ecl_type) -monkey_the_camel(EclKW, "numpyView", EclKW.numpy_view) -monkey_the_camel(EclKW, "numpyCopy", EclKW.numpy_copy) -monkey_the_camel(EclKW, "fixUninitialized", EclKW.fix_uninitialized) -monkey_the_camel(EclKW, "getDataPtr", EclKW.get_data_ptr) -monkey_the_camel(EclKW, "firstDifferent", EclKW.first_different) +monkey_the_camel(ResdataKW, "intKeywords", ResdataKW.int_keywords, classmethod) +monkey_the_camel(ResdataKW, "isNumeric", ResdataKW.is_numeric) +monkey_the_camel(ResdataKW, "fortIOSize", ResdataKW.fort_io_size) +monkey_the_camel(ResdataKW, "setName", ResdataKW.set_name) +monkey_the_camel(ResdataKW, "getName", ResdataKW.get_name) +monkey_the_camel(ResdataKW, "getMinMax", ResdataKW.get_min_max) +monkey_the_camel(ResdataKW, "getMax", ResdataKW.get_max) +monkey_the_camel(ResdataKW, "getMin", ResdataKW.get_min) +monkey_the_camel(ResdataKW, "typeName", ResdataKW.type_name) +monkey_the_camel(ResdataKW, "getResdataType", ResdataKW.get_rd_type) +monkey_the_camel(ResdataKW, "numpyView", ResdataKW.numpy_view) +monkey_the_camel(ResdataKW, "numpyCopy", ResdataKW.numpy_copy) +monkey_the_camel(ResdataKW, "fixUninitialized", ResdataKW.fix_uninitialized) +monkey_the_camel(ResdataKW, "getDataPtr", ResdataKW.get_data_ptr) +monkey_the_camel(ResdataKW, "firstDifferent", ResdataKW.first_different) diff --git a/python/ecl/eclfile/ecl_restart_file.py b/python/resdata/resfile/rd_restart_file.py similarity index 59% rename from python/ecl/eclfile/ecl_restart_file.py rename to python/resdata/resfile/rd_restart_file.py index 1063d0bded..00c2cc9b52 100644 --- a/python/ecl/eclfile/ecl_restart_file.py +++ b/python/resdata/resfile/rd_restart_file.py @@ -1,26 +1,28 @@ from cwrap import BaseCClass -from ecl import EclFileEnum, EclFileFlagEnum, EclPrototype -from ecl.eclfile import Ecl3DFile, EclFile -from ecl.util.util import CTime, monkey_the_camel +from resdata import FileMode, FileType, ResdataPrototype +from resdata.resfile import Resdata3DFile, ResdataFile +from resdata.util.util import CTime, monkey_the_camel -class EclRestartHead(BaseCClass): - TYPE_NAME = "ecl_rsthead" - _alloc = EclPrototype("void* ecl_rsthead_alloc(ecl_file_view , int )", bind=False) - _alloc_from_kw = EclPrototype( - "void* ecl_rsthead_alloc_from_kw(int , ecl_kw , ecl_kw , ecl_kw )", bind=False +class ResdataRestartHead(BaseCClass): + TYPE_NAME = "rd_rsthead" + _alloc = ResdataPrototype( + "void* rd_rsthead_alloc(rd_file_view , int )", bind=False ) - _free = EclPrototype("void ecl_rsthead_free(ecl_rsthead)") - _get_report_step = EclPrototype("int ecl_rsthead_get_report_step(ecl_rsthead)") - _get_sim_time = EclPrototype("time_t ecl_rsthead_get_sim_time(ecl_rsthead)") - _get_sim_days = EclPrototype("double ecl_rsthead_get_sim_days(ecl_rsthead)") - _get_nxconz = EclPrototype("int ecl_rsthead_get_nxconz(ecl_rsthead)") - _get_ncwmax = EclPrototype("int ecl_rsthead_get_ncwmax(ecl_rsthead)") + _alloc_from_kw = ResdataPrototype( + "void* rd_rsthead_alloc_from_kw(int , rd_kw , rd_kw , rd_kw )", bind=False + ) + _free = ResdataPrototype("void rd_rsthead_free(rd_rsthead)") + _get_report_step = ResdataPrototype("int rd_rsthead_get_report_step(rd_rsthead)") + _get_sim_time = ResdataPrototype("time_t rd_rsthead_get_sim_time(rd_rsthead)") + _get_sim_days = ResdataPrototype("double rd_rsthead_get_sim_days(rd_rsthead)") + _get_nxconz = ResdataPrototype("int rd_rsthead_get_nxconz(rd_rsthead)") + _get_ncwmax = ResdataPrototype("int rd_rsthead_get_ncwmax(rd_rsthead)") def __init__(self, kw_arg=None, rst_view=None): if kw_arg is None and rst_view is None: raise ValueError( - "Cannot construct EclRestartHead without one of kw_arg and rst_view, both were None!" + "Cannot construct ResdataRestartHead without one of kw_arg and rst_view, both were None!" ) if not kw_arg is None: @@ -31,7 +33,7 @@ def __init__(self, kw_arg=None, rst_view=None): else: c_ptr = self._alloc(rst_view, -1) - super(EclRestartHead, self).__init__(c_ptr) + super(ResdataRestartHead, self).__init__(c_ptr) def free(self): self._free() @@ -50,37 +52,34 @@ def well_details(self): return {"NXCONZ": self._get_nxconz(), "NCWMAX": self._get_ncwmax()} -ECL_FILE_DEFAULT = EclFileFlagEnum.ECL_FILE_DEFAULT - - -class EclRestartFile(Ecl3DFile): - def __init__(self, grid, filename, flags=ECL_FILE_DEFAULT): +class ResdataRestartFile(Resdata3DFile): + def __init__(self, grid, filename, flags=FileMode.DEFAULT): """Will open an Eclipse restart file. - The EclRestartFile class will open an eclipse restart file, in + The ResdataRestartFile class will open an eclipse restart file, in unified or non unified format. The constructor will infer the file type based on the filename, and will raise a ValueError - exception if the file type is not ECL_RESTART_FILE or - ECL_UNIFIED_RESTART_FILE. + exception if the file type is not RESTART or + UNIFIED_RESTART. - The EclRestartFile will use a grid reference to create Ecl3DKw + The ResdataRestartFile will use a grid reference to create Resdata3DKw instances for all the keyword elements which have either 'nactive' or 'nx*ny*nz' elements. """ - file_type, report_step, fmt_file = EclFile.getFileType(filename) + file_type, report_step, fmt_file = ResdataFile.getFileType(filename) if not file_type in [ - EclFileEnum.ECL_RESTART_FILE, - EclFileEnum.ECL_UNIFIED_RESTART_FILE, + FileType.RESTART, + FileType.UNIFIED_RESTART, ]: raise ValueError( 'The input filename "%s" does not correspond to a restart file. Please follow the Eclipse naming conventions' % filename ) - super(EclRestartFile, self).__init__(grid, filename, flags) + super(ResdataRestartFile, self).__init__(grid, filename, flags) self.rst_headers = None - if file_type == EclFileEnum.ECL_RESTART_FILE: + if file_type == FileType.RESTART: self.is_unified = False self.report_step = report_step else: @@ -98,7 +97,9 @@ def assert_headers(self): if self.unified(): for index in range(self.num_named_kw("SEQNUM")): self.rst_headers.append( - EclRestartHead(rst_view=self.restartView(seqnum_index=index)) + ResdataRestartHead( + rst_view=self.restartView(seqnum_index=index) + ) ) else: intehead_kw = self["INTEHEAD"][0] @@ -109,7 +110,7 @@ def assert_headers(self): logihead_kw = None self.rst_headers.append( - EclRestartHead( + ResdataRestartHead( kw_arg=(self.report_step, intehead_kw, doubhead_kw, logihead_kw) ) ) @@ -145,9 +146,11 @@ def get_header(self, index): return self.rst_headers[index] -monkey_the_camel(EclRestartHead, "getReportStep", EclRestartHead.get_report_step) -monkey_the_camel(EclRestartHead, "getSimDate", EclRestartHead.get_sim_date) -monkey_the_camel(EclRestartHead, "getSimDays", EclRestartHead.get_sim_days) +monkey_the_camel( + ResdataRestartHead, "getReportStep", ResdataRestartHead.get_report_step +) +monkey_the_camel(ResdataRestartHead, "getSimDate", ResdataRestartHead.get_sim_date) +monkey_the_camel(ResdataRestartHead, "getSimDays", ResdataRestartHead.get_sim_days) -monkey_the_camel(EclRestartFile, "assertHeaders", EclRestartFile.assert_headers) -monkey_the_camel(EclRestartFile, "timeList", EclRestartFile.time_list) +monkey_the_camel(ResdataRestartFile, "assertHeaders", ResdataRestartFile.assert_headers) +monkey_the_camel(ResdataRestartFile, "timeList", ResdataRestartFile.time_list) diff --git a/python/resdata/rft/__init__.py b/python/resdata/rft/__init__.py new file mode 100644 index 0000000000..03686f0162 --- /dev/null +++ b/python/resdata/rft/__init__.py @@ -0,0 +1,8 @@ +""" + rd_rft/[ResdataRFTFile , ResdataRFT , ResdataRFTCell]: Loads an RFT/PLT + file, and can afterwords be used to support various queries. +""" + +from .well_trajectory import WellTrajectory +from .rd_rft_cell import ResdataPLTCell, ResdataRFTCell +from .rd_rft import ResdataRFT, ResdataRFTFile diff --git a/python/ecl/rft/ecl_rft.py b/python/resdata/rft/rd_rft.py similarity index 59% rename from python/ecl/rft/ecl_rft.py rename to python/resdata/rft/rd_rft.py index 58ec88d63e..9a64c72e47 100644 --- a/python/ecl/rft/ecl_rft.py +++ b/python/resdata/rft/rd_rft.py @@ -1,20 +1,18 @@ """ -Module for loading ECLIPSE RFT files. +Module for loading RFT files. """ from cwrap import BaseCClass +from resdata import ResdataPrototype +from resdata.rft import ResdataPLTCell, ResdataRFTCell +from resdata.util.util import CTime, monkey_the_camel -from ecl import EclPrototype -from ecl.util.util import monkey_the_camel -from ecl.util.util import CTime -from ecl.rft import EclRFTCell, EclPLTCell +class ResdataRFT(BaseCClass): + """The ResdataRFT class contains the information for *one* RFT. -class EclRFT(BaseCClass): - """The EclRFT class contains the information for *one* RFT. - - The ECLIPSE RFT file can contain three different types of RFT like - objects which are lumped together; the EclRFTClass is a container + The RFT file can contain three different types of RFT like + objects which are lumped together; the ResdataRFTClass is a container for such objects. The three different object types which can be found in an RFT file are: @@ -30,37 +28,37 @@ class EclRFT(BaseCClass): has coordinates, pressure and depth. """ - TYPE_NAME = "ecl_rft" - _alloc = EclPrototype( - "void* ecl_rft_node_alloc_new( char* , char* , time_t , double)", bind=False + TYPE_NAME = "rd_rft" + _alloc = ResdataPrototype( + "void* rd_rft_node_alloc_new( char* , char* , time_t , double)", bind=False ) - _free = EclPrototype("void ecl_rft_node_free( ecl_rft )") - _get_type = EclPrototype("int ecl_rft_node_get_type( ecl_rft )") - _get_well = EclPrototype("char* ecl_rft_node_get_well_name( ecl_rft )") - _get_date = EclPrototype("time_t ecl_rft_node_get_date( ecl_rft )") - _get_size = EclPrototype("int ecl_rft_node_get_size( ecl_rft )") - _iget_cell = EclPrototype("void* ecl_rft_node_iget_cell( ecl_rft )") - _iget_depth = EclPrototype("double ecl_rft_node_iget_depth( ecl_rft )") - _iget_pressure = EclPrototype("double ecl_rft_node_iget_pressure(ecl_rft)") - _iget_ijk = EclPrototype( - "void ecl_rft_node_iget_ijk( ecl_rft , int , int*, int*, int*)" + _free = ResdataPrototype("void rd_rft_node_free( rd_rft )") + _get_type = ResdataPrototype("int rd_rft_node_get_type( rd_rft )") + _get_well = ResdataPrototype("char* rd_rft_node_get_well_name( rd_rft )") + _get_date = ResdataPrototype("time_t rd_rft_node_get_date( rd_rft )") + _get_size = ResdataPrototype("int rd_rft_node_get_size( rd_rft )") + _iget_cell = ResdataPrototype("void* rd_rft_node_iget_cell( rd_rft )") + _iget_depth = ResdataPrototype("double rd_rft_node_iget_depth( rd_rft )") + _iget_pressure = ResdataPrototype("double rd_rft_node_iget_pressure(rd_rft)") + _iget_ijk = ResdataPrototype( + "void rd_rft_node_iget_ijk( rd_rft , int , int*, int*, int*)" ) - _iget_swat = EclPrototype("double ecl_rft_node_iget_swat(ecl_rft)") - _iget_sgas = EclPrototype("double ecl_rft_node_iget_sgas(ecl_rft)") - _iget_orat = EclPrototype("double ecl_rft_node_iget_orat(ecl_rft)") - _iget_wrat = EclPrototype("double ecl_rft_node_iget_wrat(ecl_rft)") - _iget_grat = EclPrototype("double ecl_rft_node_iget_grat(ecl_rft)") - _lookup_ijk = EclPrototype( - "void* ecl_rft_node_lookup_ijk( ecl_rft , int , int , int)" + _iget_swat = ResdataPrototype("double rd_rft_node_iget_swat(rd_rft)") + _iget_sgas = ResdataPrototype("double rd_rft_node_iget_sgas(rd_rft)") + _iget_orat = ResdataPrototype("double rd_rft_node_iget_orat(rd_rft)") + _iget_wrat = ResdataPrototype("double rd_rft_node_iget_wrat(rd_rft)") + _iget_grat = ResdataPrototype("double rd_rft_node_iget_grat(rd_rft)") + _lookup_ijk = ResdataPrototype( + "void* rd_rft_node_lookup_ijk( rd_rft , int , int , int)" ) - _is_RFT = EclPrototype("bool ecl_rft_node_is_RFT( ecl_rft )") - _is_PLT = EclPrototype("bool ecl_rft_node_is_PLT( ecl_rft )") - _is_SEGMENT = EclPrototype("bool ecl_rft_node_is_SEGMENT( ecl_rft )") - _is_MSW = EclPrototype("bool ecl_rft_node_is_MSW( ecl_rft )") + _is_RFT = ResdataPrototype("bool rd_rft_node_is_RFT( rd_rft )") + _is_PLT = ResdataPrototype("bool rd_rft_node_is_PLT( rd_rft )") + _is_SEGMENT = ResdataPrototype("bool rd_rft_node_is_SEGMENT( rd_rft )") + _is_MSW = ResdataPrototype("bool rd_rft_node_is_MSW( rd_rft )") def __init__(self, name, type_string, date, days): c_ptr = self._alloc(name, type_string, CTime(date), days) - super(EclRFT, self).__init__(c_ptr) + super(ResdataRFT, self).__init__(c_ptr) def free(self): self._free() @@ -88,13 +86,13 @@ def __len__(self): def is_RFT(self): """ - Is instance an RFT; in that case all the cells will be EclRFTCell instances. + Is instance an RFT; in that case all the cells will be ResdataRFTCell instances. """ return self._is_RFT() def is_PLT(self): """ - Is instance a PLT; in that case all the cells will be EclPLTCell instances. + Is instance a PLT; in that case all the cells will be ResdataPLTCell instances. """ return self._is_PLT() @@ -125,9 +123,9 @@ def get_date(self): def __cell_ref(self, cell_ptr): if self.is_RFT(): - return EclRFTCell.createCReference(cell_ptr, self) + return ResdataRFTCell.createCReference(cell_ptr, self) elif self.is_PLT(): - return EclPLTCell.createCReference(cell_ptr, self) + return ResdataPLTCell.createCReference(cell_ptr, self) else: raise NotImplementedError("Only RFT and PLT cells are implemented") @@ -147,7 +145,7 @@ def __getitem__(self, index): cell = rft[4] The return value from the __getitem__() method is either an - EclRFTCell instance or a EclPLTCell instance, depending on the + ResdataRFTCell instance or a ResdataPLTCell instance, depending on the type of this particular RFT object. For MSW wells the cells will come in sorted order along the wellpath, @@ -176,37 +174,37 @@ def ijkget(self, ijk): return None -class EclRFTFile(BaseCClass): - TYPE_NAME = "ecl_rft_file" - _load = EclPrototype("void* ecl_rft_file_alloc_case( char* )", bind=False) - _iget = EclPrototype("ecl_rft_ref ecl_rft_file_iget_node( ecl_rft_file , int )") - _get_rft = EclPrototype( - "ecl_rft_ref ecl_rft_file_get_well_time_rft( ecl_rft_file , char* , time_t)" +class ResdataRFTFile(BaseCClass): + TYPE_NAME = "rd_rft_file" + _load = ResdataPrototype("void* rd_rft_file_alloc_case( char* )", bind=False) + _iget = ResdataPrototype("rd_rft_ref rd_rft_file_iget_node( rd_rft_file , int )") + _get_rft = ResdataPrototype( + "rd_rft_ref rd_rft_file_get_well_time_rft( rd_rft_file , char* , time_t)" ) - _has_rft = EclPrototype("bool ecl_rft_file_case_has_rft( char* )", bind=False) - _free = EclPrototype("void ecl_rft_file_free( ecl_rft_file )") - _get_size = EclPrototype( - "int ecl_rft_file_get_size__( ecl_rft_file , char* , time_t)" + _has_rft = ResdataPrototype("bool rd_rft_file_case_has_rft( char* )", bind=False) + _free = ResdataPrototype("void rd_rft_file_free( rd_rft_file )") + _get_size = ResdataPrototype( + "int rd_rft_file_get_size__( rd_rft_file , char* , time_t)" ) - _get_num_wells = EclPrototype("int ecl_rft_file_get_num_wells( ecl_rft_file )") + _get_num_wells = ResdataPrototype("int rd_rft_file_get_num_wells( rd_rft_file )") """ - The EclRFTFile class is used to load an ECLIPSE RFT file. + The ResdataRFTFile class is used to load an RFT file. - The EclRFTFile serves as a container which can load and hold the - content of an ECLIPSE RFT file. The RFT files will in general + The ResdataRFTFile serves as a container which can load and hold the + content of an RFT file. The RFT files will in general contain data for several wells and several times in one large - container. The EclRFTClass class contains methods get the the RFT + container. The ResdataRFTClass class contains methods get the the RFT results for a specific time and/or well. - The EclRFTFile class can in general contain a mix of RFT and PLT + The ResdataRFTFile class can in general contain a mix of RFT and PLT measurements. The class does not really differentiate between these. """ def __init__(self, case): c_ptr = self._load(case) - super(EclRFTFile, self).__init__(c_ptr) + super(ResdataRFTFile, self).__init__(c_ptr) def __len__(self): return self._get_size(None, CTime(-1)) @@ -226,7 +224,7 @@ def __getitem__(self, index): def size(self, well=None, date=None): """ - The number of elements in EclRFTFile container. + The number of elements in ResdataRFTFile container. By default the size() method will return the total number of RFTs/PLTs in the container, but by specifying the optional @@ -234,10 +232,10 @@ def size(self, well=None, date=None): number of well measurements matching that time or well name. The well argument can contain wildcards. - rftFile = ecl.EclRFTFile( "ECLIPSE.RFT" ) - print "Total number of RFTs : %d" % rftFile.size( ) - print "RFTs matching OP* : %d" % rftFile.size( well = "OP*" ) - print "RFTs at 01/01/2010 : %d" % rftFile.size( date = datetime.date( 2010 , 1 , 1 )) + >>> rftFile = resdata.ResdataRFTFile( "CASE.RFT" ) + >>> print "Total number of RFTs : %d" % rftFile.size( ) + >>> print "RFTs matching OP* : %d" % rftFile.size( well = "OP*" ) + >>> print "RFTs at 01/01/2010 : %d" % rftFile.size( date = datetime.date( 2010 , 1 , 1 )) """ if date: @@ -290,8 +288,8 @@ def __repr__(self): return self._create_repr("wells = %d" % w) -monkey_the_camel(EclRFT, "getWellName", EclRFT.get_well_name) -monkey_the_camel(EclRFT, "getDate", EclRFT.get_date) +monkey_the_camel(ResdataRFT, "getWellName", ResdataRFT.get_well_name) +monkey_the_camel(ResdataRFT, "getDate", ResdataRFT.get_date) -monkey_the_camel(EclRFTFile, "getNumWells", EclRFTFile.get_num_wells) -monkey_the_camel(EclRFTFile, "getHeaders", EclRFTFile.get_headers) +monkey_the_camel(ResdataRFTFile, "getNumWells", ResdataRFTFile.get_num_wells) +monkey_the_camel(ResdataRFTFile, "getHeaders", ResdataRFTFile.get_headers) diff --git a/python/ecl/rft/ecl_rft_cell.py b/python/resdata/rft/rd_rft_cell.py similarity index 63% rename from python/ecl/rft/ecl_rft_cell.py rename to python/resdata/rft/rd_rft_cell.py index d367815f5a..0e9f45bf2e 100644 --- a/python/ecl/rft/ecl_rft_cell.py +++ b/python/resdata/rft/rd_rft_cell.py @@ -1,5 +1,5 @@ from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype class RFTCell(BaseCClass): @@ -8,7 +8,7 @@ class RFTCell(BaseCClass): The RFTCell class contains the elements which are common to both RFT and PLT. The list of common elements include the corrdinates (i,j,k) the pressure and the depth of the cell. Actual user access - should be based on the derived classes EclRFTCell and EclPLTCell. + should be based on the derived classes ResdataRFTCell and ResdataPLTCell. Observe that from june 2013 the properties i,j and k which return offset 1 coordinate values are deprecated, and you should rather @@ -17,12 +17,12 @@ class RFTCell(BaseCClass): """ TYPE_NAME = "rft_cell" - _free = EclPrototype("void ecl_rft_cell_free(rft_cell)") - _get_pressure = EclPrototype("double ecl_rft_cell_get_pressure(rft_cell)") - _get_depth = EclPrototype("double ecl_rft_cell_get_depth(rft_cell)") - _get_i = EclPrototype("int ecl_rft_cell_get_i(rft_cell)") - _get_j = EclPrototype("int ecl_rft_cell_get_j(rft_cell)") - _get_k = EclPrototype("int ecl_rft_cell_get_k(rft_cell)") + _free = ResdataPrototype("void rd_rft_cell_free(rft_cell)") + _get_pressure = ResdataPrototype("double rd_rft_cell_get_pressure(rft_cell)") + _get_depth = ResdataPrototype("double rd_rft_cell_get_depth(rft_cell)") + _get_i = ResdataPrototype("int rd_rft_cell_get_i(rft_cell)") + _get_j = ResdataPrototype("int rd_rft_cell_get_j(rft_cell)") + _get_k = ResdataPrototype("int rd_rft_cell_get_k(rft_cell)") def free(self): self._free() @@ -51,19 +51,19 @@ def depth(self): ################################################################# -class EclRFTCell(RFTCell): - TYPE_NAME = "ecl_rft_cell" - _alloc_RFT = EclPrototype( - "void* ecl_rft_cell_alloc_RFT(int, int, int, double, double, double, double)", +class ResdataRFTCell(RFTCell): + TYPE_NAME = "rd_rft_cell" + _alloc_RFT = ResdataPrototype( + "void* rd_rft_cell_alloc_RFT(int, int, int, double, double, double, double)", bind=False, ) - _get_swat = EclPrototype("double ecl_rft_cell_get_swat(ecl_rft_cell)") - _get_soil = EclPrototype("double ecl_rft_cell_get_soil(ecl_rft_cell)") - _get_sgas = EclPrototype("double ecl_rft_cell_get_sgas(ecl_rft_cell)") + _get_swat = ResdataPrototype("double rd_rft_cell_get_swat(rd_rft_cell)") + _get_soil = ResdataPrototype("double rd_rft_cell_get_soil(rd_rft_cell)") + _get_sgas = ResdataPrototype("double rd_rft_cell_get_sgas(rd_rft_cell)") def __init__(self, i, j, k, depth, pressure, swat, sgas): c_ptr = self._alloc_RFT(i, j, k, depth, pressure, swat, sgas) - super(EclRFTCell, self).__init__(c_ptr) + super(ResdataRFTCell, self).__init__(c_ptr) @property def swat(self): @@ -81,31 +81,33 @@ def soil(self): ################################################################# -class EclPLTCell(RFTCell): - TYPE_NAME = "ecl_plt_cell" - _alloc_PLT = EclPrototype( - "void* ecl_rft_cell_alloc_PLT(int, int, int, double, double, double, double, double, double, double, double, double, double, double)", +class ResdataPLTCell(RFTCell): + TYPE_NAME = "rd_plt_cell" + _alloc_PLT = ResdataPrototype( + "void* rd_rft_cell_alloc_PLT(int, int, int, double, double, double, double, double, double, double, double, double, double, double)", bind=False, ) - _get_orat = EclPrototype("double ecl_rft_cell_get_orat(ecl_plt_cell)") - _get_grat = EclPrototype("double ecl_rft_cell_get_grat(ecl_plt_cell)") - _get_wrat = EclPrototype("double ecl_rft_cell_get_wrat(ecl_plt_cell)") + _get_orat = ResdataPrototype("double rd_rft_cell_get_orat(rd_plt_cell)") + _get_grat = ResdataPrototype("double rd_rft_cell_get_grat(rd_plt_cell)") + _get_wrat = ResdataPrototype("double rd_rft_cell_get_wrat(rd_plt_cell)") - _get_flowrate = EclPrototype("double ecl_rft_cell_get_flowrate(ecl_plt_cell)") - _get_oil_flowrate = EclPrototype( - "double ecl_rft_cell_get_oil_flowrate(ecl_plt_cell)" + _get_flowrate = ResdataPrototype("double rd_rft_cell_get_flowrate(rd_plt_cell)") + _get_oil_flowrate = ResdataPrototype( + "double rd_rft_cell_get_oil_flowrate(rd_plt_cell)" ) - _get_gas_flowrate = EclPrototype( - "double ecl_rft_cell_get_gas_flowrate(ecl_plt_cell)" + _get_gas_flowrate = ResdataPrototype( + "double rd_rft_cell_get_gas_flowrate(rd_plt_cell)" ) - _get_water_flowrate = EclPrototype( - "double ecl_rft_cell_get_water_flowrate(ecl_plt_cell)" + _get_water_flowrate = ResdataPrototype( + "double rd_rft_cell_get_water_flowrate(rd_plt_cell)" ) - _get_conn_start = EclPrototype( - "double ecl_rft_cell_get_connection_start(ecl_plt_cell)" + _get_conn_start = ResdataPrototype( + "double rd_rft_cell_get_connection_start(rd_plt_cell)" + ) + _get_conn_end = ResdataPrototype( + "double rd_rft_cell_get_connection_end(rd_plt_cell)" ) - _get_conn_end = EclPrototype("double ecl_rft_cell_get_connection_end(ecl_plt_cell)") def __init__( self, @@ -140,7 +142,7 @@ def __init__( gas_flowrate, water_flowrate, ) - super(EclPLTCell, self).__init__(c_ptr) + super(ResdataPLTCell, self).__init__(c_ptr) @property def orat(self): diff --git a/python/ecl/rft/well_trajectory.py b/python/resdata/rft/well_trajectory.py similarity index 100% rename from python/ecl/rft/well_trajectory.py rename to python/resdata/rft/well_trajectory.py diff --git a/python/resdata/summary/__init__.py b/python/resdata/summary/__init__.py new file mode 100644 index 0000000000..4805d1d323 --- /dev/null +++ b/python/resdata/summary/__init__.py @@ -0,0 +1,18 @@ +""" + rd_sum/Summary: This will load summary results; + both data file(s) and the SMSPEC file. The RdSum object can be + used as basis for queries on summary vectors. +""" + + +import resdata.util.util +import resdata.geometry + +from .rd_cmp import ResdataCmp +from .rd_npv import NPVPriceVector, ResdataNPV +from .rd_sum import Summary # , SummaryVector, SummaryNode, ResdataSMSPECNode +from .rd_sum_keyword_vector import SummaryKeyWordVector +from .rd_sum_node import SummaryNode +from .rd_sum_tstep import SummaryTStep +from .rd_sum_var_type import SummaryVarType +from .rd_sum_vector import SummaryVector diff --git a/python/ecl/summary/ecl_cmp.py b/python/resdata/summary/rd_cmp.py similarity index 79% rename from python/ecl/summary/ecl_cmp.py rename to python/resdata/summary/rd_cmp.py index e91b86cf99..9eba124c56 100644 --- a/python/ecl/summary/ecl_cmp.py +++ b/python/resdata/summary/rd_cmp.py @@ -1,8 +1,8 @@ -from ecl.util.util import monkey_the_camel -from ecl.summary import EclSum +from resdata.util.util import monkey_the_camel +from .rd_sum import Summary -class EclCase(object): +class ResdataCase(object): def __init__(self, case): self.case = case @@ -23,7 +23,7 @@ def wells(self): return self.summary.wells() def load_summary(self): - self.summary = EclSum(self.case) + self.summary = Summary(self.case) def start_time_equal(self, other): if self.summary.getDataStartTime() == other.summary.getDataStartTime(): @@ -56,7 +56,7 @@ def cmp_summary_vector(self, other, key, sample=100): raise KeyError("Key:%s was not present in both cases" % key) -class EclCmp(object): +class ResdataCmp(object): def __init__(self, test_case, ref_case): """Class to compare to simulation cases with Eclipse formatted result files. @@ -68,8 +68,8 @@ def __init__(self, test_case, ref_case): The constructor will start be calling the method initCheck() to check that the two cases are 'in the same ballpark'. """ - self.test_case = EclCase(test_case) - self.ref_case = EclCase(ref_case) + self.test_case = ResdataCase(test_case) + self.ref_case = ResdataCase(ref_case) self.initCheck() @@ -111,7 +111,7 @@ def cmp_summary_vector(self, key, sample=100): So that a natural way to evaluate the check for numerical equality, based on the relative error could be: - delta, scale = ecl_cmp.cmpSummaryVector("WWCT:OP_1") + delta, scale = rd_cmp.cmpSummaryVector("WWCT:OP_1") if delta/scale < 0.0001: print("Equal enough") @@ -142,14 +142,14 @@ def test_wells(self): return self.test_case.wells() -monkey_the_camel(EclCase, "loadSummary", EclCase.load_summary) -monkey_the_camel(EclCase, "startTimeEqual", EclCase.start_time_equal) -monkey_the_camel(EclCase, "endTimeEqual", EclCase.end_time_equal) -monkey_the_camel(EclCase, "cmpSummaryVector", EclCase.cmp_summary_vector) +monkey_the_camel(ResdataCase, "loadSummary", ResdataCase.load_summary) +monkey_the_camel(ResdataCase, "startTimeEqual", ResdataCase.start_time_equal) +monkey_the_camel(ResdataCase, "endTimeEqual", ResdataCase.end_time_equal) +monkey_the_camel(ResdataCase, "cmpSummaryVector", ResdataCase.cmp_summary_vector) -monkey_the_camel(EclCmp, "initCheck", EclCmp.init_check) -monkey_the_camel(EclCmp, "hasSummaryVector", EclCmp.has_summary_vector) -monkey_the_camel(EclCmp, "endTimeEqual", EclCmp.end_time_equal) -monkey_the_camel(EclCmp, "cmpSummaryVector", EclCmp.cmp_summary_vector) -monkey_the_camel(EclCmp, "testKeys", EclCmp.test_keys) -monkey_the_camel(EclCmp, "testWells", EclCmp.test_wells) +monkey_the_camel(ResdataCmp, "initCheck", ResdataCmp.init_check) +monkey_the_camel(ResdataCmp, "hasSummaryVector", ResdataCmp.has_summary_vector) +monkey_the_camel(ResdataCmp, "endTimeEqual", ResdataCmp.end_time_equal) +monkey_the_camel(ResdataCmp, "cmpSummaryVector", ResdataCmp.cmp_summary_vector) +monkey_the_camel(ResdataCmp, "testKeys", ResdataCmp.test_keys) +monkey_the_camel(ResdataCmp, "testWells", ResdataCmp.test_wells) diff --git a/python/ecl/summary/ecl_npv.py b/python/resdata/summary/rd_npv.py similarity index 90% rename from python/ecl/summary/ecl_npv.py rename to python/resdata/summary/rd_npv.py index 39952f7d2a..f6f0dd8d8b 100644 --- a/python/ecl/summary/ecl_npv.py +++ b/python/resdata/summary/rd_npv.py @@ -2,8 +2,8 @@ import datetime import numbers -from ecl.util.util import monkey_the_camel -from ecl.summary import EclSum +from resdata.util.util import monkey_the_camel +from .rd_sum import Summary class NPVParseKey(object): @@ -111,15 +111,15 @@ def eval(self, date): raise ValueError("Input date:%s before start of vector" % date) -class EclNPV(object): +class ResdataNPV(object): sumKeyRE = re.compile("[\[]([\w:,]+)[\]]") def __init__(self, baseCase): - sum = EclSum(baseCase) + sum = Summary(baseCase) if sum: self.baseCase = sum else: - raise Error("Failed to open ECLIPSE sumamry case:%s" % baseCase) + raise Error("Failed to open summary case:%s" % baseCase) self.expression = None self.keyList = {} self.start = None @@ -187,9 +187,9 @@ def eval_npv(self): monkey_the_camel(NPVPriceVector, "assertDate", NPVPriceVector.assert_date, staticmethod) monkey_the_camel(NPVPriceVector, "evalDate", NPVPriceVector.eval_date) -monkey_the_camel(EclNPV, "getExpression", EclNPV.get_expression) -monkey_the_camel(EclNPV, "setExpression", EclNPV.set_expression) -monkey_the_camel(EclNPV, "getKeyList", EclNPV.get_key_list) -monkey_the_camel(EclNPV, "addKey", EclNPV.add_key) -monkey_the_camel(EclNPV, "parseExpression", EclNPV.parse_expression) -monkey_the_camel(EclNPV, "evalNPV", EclNPV.eval_npv) +monkey_the_camel(ResdataNPV, "getExpression", ResdataNPV.get_expression) +monkey_the_camel(ResdataNPV, "setExpression", ResdataNPV.set_expression) +monkey_the_camel(ResdataNPV, "getKeyList", ResdataNPV.get_key_list) +monkey_the_camel(ResdataNPV, "addKey", ResdataNPV.add_key) +monkey_the_camel(ResdataNPV, "parseExpression", ResdataNPV.parse_expression) +monkey_the_camel(ResdataNPV, "evalNPV", ResdataNPV.eval_npv) diff --git a/python/ecl/summary/ecl_smspec_node.py b/python/resdata/summary/rd_smspec_node.py similarity index 69% rename from python/ecl/summary/ecl_smspec_node.py rename to python/resdata/summary/rd_smspec_node.py index 3af23ae4a7..ef46699f08 100644 --- a/python/ecl/summary/ecl_smspec_node.py +++ b/python/resdata/summary/rd_smspec_node.py @@ -1,9 +1,9 @@ from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl import EclPrototype +from resdata.util.util import monkey_the_camel +from resdata import ResdataPrototype -class EclSMSPECNode(BaseCClass): +class ResdataSMSPECNode(BaseCClass): """ Small class with some meta information about a summary variable. @@ -15,29 +15,33 @@ class EclSMSPECNode(BaseCClass): """ TYPE_NAME = "smspec_node" - _node_is_total = EclPrototype("bool smspec_node_is_total( smspec_node )") - _node_is_historical = EclPrototype("bool smspec_node_is_historical( smspec_node )") - _node_is_rate = EclPrototype("bool smspec_node_is_rate( smspec_node )") - _node_unit = EclPrototype("char* smspec_node_get_unit( smspec_node )") - _node_wgname = EclPrototype("char* smspec_node_get_wgname( smspec_node )") - _node_keyword = EclPrototype("char* smspec_node_get_keyword( smspec_node )") - _node_num = EclPrototype("int smspec_node_get_num( smspec_node )") - _node_need_num = EclPrototype("bool smspec_node_need_nums( smspec_node )") - _gen_key1 = EclPrototype("char* smspec_node_get_gen_key1( smspec_node )") - _gen_key2 = EclPrototype("char* smspec_node_get_gen_key2( smspec_node )") - _var_type = EclPrototype("ecl_sum_var_type smspec_node_get_var_type( smspec_node )") - _cmp = EclPrototype("int smspec_node_cmp( smspec_node , smspec_node)") - _get_default = EclPrototype("float smspec_node_get_default(smspec_node)") + _node_is_total = ResdataPrototype("bool smspec_node_is_total( smspec_node )") + _node_is_historical = ResdataPrototype( + "bool smspec_node_is_historical( smspec_node )" + ) + _node_is_rate = ResdataPrototype("bool smspec_node_is_rate( smspec_node )") + _node_unit = ResdataPrototype("char* smspec_node_get_unit( smspec_node )") + _node_wgname = ResdataPrototype("char* smspec_node_get_wgname( smspec_node )") + _node_keyword = ResdataPrototype("char* smspec_node_get_keyword( smspec_node )") + _node_num = ResdataPrototype("int smspec_node_get_num( smspec_node )") + _node_need_num = ResdataPrototype("bool smspec_node_need_nums( smspec_node )") + _gen_key1 = ResdataPrototype("char* smspec_node_get_gen_key1( smspec_node )") + _gen_key2 = ResdataPrototype("char* smspec_node_get_gen_key2( smspec_node )") + _var_type = ResdataPrototype( + "rd_sum_var_type smspec_node_get_var_type( smspec_node )" + ) + _cmp = ResdataPrototype("int smspec_node_cmp( smspec_node , smspec_node)") + _get_default = ResdataPrototype("float smspec_node_get_default(smspec_node)") def __init__(self): - super(EclSMSPECNode, self).__init__(0) # null pointer + super(ResdataSMSPECNode, self).__init__(0) # null pointer raise NotImplementedError("Class can not be instantiated directly!") def cmp(self, other): - if isinstance(other, EclSMSPECNode): + if isinstance(other, ResdataSMSPECNode): return self._cmp(other) else: - raise TypeError("Other argument must be of type EclSMSPECNode") + raise TypeError("Other argument must be of type ResdataSMSPECNode") def __lt__(self, other): return self.cmp(other) < 0 @@ -66,7 +70,7 @@ def wgname(self): Many variables do not have the WGNAME property, i.e. the field related variables like FOPT and the block properties like BPR:10,10,10. For these variables the function will return - None, and not the ECLIPSE dummy value: ":+:+:+:+". + None, and not the dummy value: ":+:+:+:+". """ return self._node_wgname() @@ -76,7 +80,7 @@ def keyword(self): Returns the KEYWORD property for this node. The KEYWORD property is the main classification property in - the ECLIPSE SMSPEC file. The properties of a variable can be + the SMSPEC file. The properties of a variable can be read from the KEWYORD value; see table 3.4 in the ECLIPSE file format reference manual. """ @@ -173,10 +177,10 @@ def is_historical(self): return self._node_is_historical() -monkey_the_camel(EclSMSPECNode, "getKey1", EclSMSPECNode.get_key1) -monkey_the_camel(EclSMSPECNode, "getKey2", EclSMSPECNode.get_key2) -monkey_the_camel(EclSMSPECNode, "varType", EclSMSPECNode.var_type) -monkey_the_camel(EclSMSPECNode, "getNum", EclSMSPECNode.get_num) -monkey_the_camel(EclSMSPECNode, "isRate", EclSMSPECNode.is_rate) -monkey_the_camel(EclSMSPECNode, "isTotal", EclSMSPECNode.is_total) -monkey_the_camel(EclSMSPECNode, "isHistorical", EclSMSPECNode.is_historical) +monkey_the_camel(ResdataSMSPECNode, "getKey1", ResdataSMSPECNode.get_key1) +monkey_the_camel(ResdataSMSPECNode, "getKey2", ResdataSMSPECNode.get_key2) +monkey_the_camel(ResdataSMSPECNode, "varType", ResdataSMSPECNode.var_type) +monkey_the_camel(ResdataSMSPECNode, "getNum", ResdataSMSPECNode.get_num) +monkey_the_camel(ResdataSMSPECNode, "isRate", ResdataSMSPECNode.is_rate) +monkey_the_camel(ResdataSMSPECNode, "isTotal", ResdataSMSPECNode.is_total) +monkey_the_camel(ResdataSMSPECNode, "isHistorical", ResdataSMSPECNode.is_historical) diff --git a/python/ecl/summary/ecl_sum.py b/python/resdata/summary/rd_sum.py similarity index 80% rename from python/ecl/summary/ecl_sum.py rename to python/resdata/summary/rd_sum.py index c8bbf4a24c..ca32ac5d9a 100644 --- a/python/ecl/summary/ecl_sum.py +++ b/python/resdata/summary/rd_sum.py @@ -2,8 +2,8 @@ Module for loading and querying summary data. The low-level organisation of summary data is extensively documented -in the C source files ecl_sum.c, ecl_smspec.c and ecl_sum_data in the -libecl/src directory. +in the C source files rd_sum.c, rd_smspec.c and rd_sum_data in the +resdata/src directory. """ import warnings @@ -20,19 +20,19 @@ # argument. In the python code this order has been reversed. from cwrap import BaseCClass, CFILE -from ecl.util.util import monkey_the_camel -from ecl.util.util import StringList, CTime, DoubleVector, TimeVector, IntVector +from resdata.util.util import monkey_the_camel +from resdata.util.util import StringList, CTime, DoubleVector, TimeVector, IntVector -from ecl.summary import EclSumTStep -from ecl.summary import EclSumVarType -from ecl.summary.ecl_sum_vector import EclSumVector -from ecl.summary.ecl_smspec_node import EclSMSPECNode -from ecl import EclPrototype, EclUnitTypeEnum +from .rd_sum_tstep import SummaryTStep +from .rd_sum_var_type import SummaryVarType +from .rd_sum_vector import SummaryVector +from .rd_smspec_node import ResdataSMSPECNode +from resdata import ResdataPrototype, UnitSystem -# , EclSumKeyWordVector +# , SummaryKeyWordVector -# import ecl.ecl_plot.sum_plot as sum_plot +# import resdata.rd_plot.sum_plot as sum_plot # The date2num function is a verbatim copy of the _to_ordinalf() # function from the matplotlib.dates module. Inserted here only to @@ -74,133 +74,139 @@ def date2num(dt): return base -class EclSum(BaseCClass): - TYPE_NAME = "ecl_sum" - _fread_alloc_case2 = EclPrototype( - "void* ecl_sum_fread_alloc_case2__(char*, char*, bool, bool, int)", +class Summary(BaseCClass): + TYPE_NAME = "rd_sum" + _fread_alloc_case2 = ResdataPrototype( + "void* rd_sum_fread_alloc_case2__(char*, char*, bool, bool, int)", bind=False, ) - _fread_alloc = EclPrototype( - "void* ecl_sum_fread_alloc(char*, stringlist, char*, bool)", bind=False + _fread_alloc = ResdataPrototype( + "void* rd_sum_fread_alloc(char*, stringlist, char*, bool)", bind=False ) - _create_restart_writer = EclPrototype( - "ecl_sum_obj ecl_sum_alloc_restart_writer2(char*, char*, int, bool, bool, char*, time_t, bool, int, int, int)", + _create_restart_writer = ResdataPrototype( + "rd_sum_obj rd_sum_alloc_restart_writer2(char*, char*, int, bool, bool, char*, time_t, bool, int, int, int)", bind=False, ) - _create_writer = EclPrototype( - "ecl_sum_obj ecl_sum_alloc_writer(char*, bool, bool, char*, time_t, bool, int, int, int)", + _create_writer = ResdataPrototype( + "rd_sum_obj rd_sum_alloc_writer(char*, bool, bool, char*, time_t, bool, int, int, int)", bind=False, ) - _resample = EclPrototype( - "ecl_sum_obj ecl_sum_alloc_resample( ecl_sum, char*, time_t_vector, bool, bool)" + _resample = ResdataPrototype( + "rd_sum_obj rd_sum_alloc_resample( rd_sum, char*, time_t_vector, bool, bool)" ) - _iiget = EclPrototype("double ecl_sum_iget(ecl_sum, int, int)") - _free = EclPrototype("void ecl_sum_free(ecl_sum)") - _data_length = EclPrototype("int ecl_sum_get_data_length(ecl_sum)") - _iget_sim_days = EclPrototype("double ecl_sum_iget_sim_days(ecl_sum, int) ") - _iget_report_step = EclPrototype("int ecl_sum_iget_report_step(ecl_sum, int) ") - _iget_sim_time = EclPrototype("time_t ecl_sum_iget_sim_time(ecl_sum, int) ") - _get_report_end = EclPrototype("int ecl_sum_iget_report_end(ecl_sum, int)") - _get_general_var = EclPrototype( - "double ecl_sum_get_general_var(ecl_sum, int, char*)" + _iiget = ResdataPrototype("double rd_sum_iget(rd_sum, int, int)") + _free = ResdataPrototype("void rd_sum_free(rd_sum)") + _data_length = ResdataPrototype("int rd_sum_get_data_length(rd_sum)") + _iget_sim_days = ResdataPrototype("double rd_sum_iget_sim_days(rd_sum, int) ") + _iget_report_step = ResdataPrototype( + "int rd_sum_iget_report_step(rd_sum, int) " ) - _get_general_var_index = EclPrototype( - "int ecl_sum_get_general_var_params_index(ecl_sum, char*)" + _iget_sim_time = ResdataPrototype("time_t rd_sum_iget_sim_time(rd_sum, int) ") + _get_report_end = ResdataPrototype("int rd_sum_iget_report_end(rd_sum, int)") + _get_general_var = ResdataPrototype( + "double rd_sum_get_general_var(rd_sum, int, char*)" ) - _get_general_var_from_sim_days = EclPrototype( - "double ecl_sum_get_general_var_from_sim_days(ecl_sum, double, char*)" + _get_general_var_index = ResdataPrototype( + "int rd_sum_get_general_var_params_index(rd_sum, char*)" ) - _get_general_var_from_sim_time = EclPrototype( - "double ecl_sum_get_general_var_from_sim_time(ecl_sum, time_t, char*)" + _get_general_var_from_sim_days = ResdataPrototype( + "double rd_sum_get_general_var_from_sim_days(rd_sum, double, char*)" ) - _solve_days = EclPrototype( - "double_vector_obj ecl_sum_alloc_days_solution(ecl_sum, char*, double, bool)" + _get_general_var_from_sim_time = ResdataPrototype( + "double rd_sum_get_general_var_from_sim_time(rd_sum, time_t, char*)" ) - _solve_dates = EclPrototype( - "time_t_vector_obj ecl_sum_alloc_time_solution(ecl_sum, char*, double, bool)" + _solve_days = ResdataPrototype( + "double_vector_obj rd_sum_alloc_days_solution(rd_sum, char*, double, bool)" ) - _get_first_gt = EclPrototype("int ecl_sum_get_first_gt(ecl_sum, int, double)") - _get_first_lt = EclPrototype("int ecl_sum_get_first_lt(ecl_sum, int, double)") - _get_start_date = EclPrototype("time_t ecl_sum_get_start_time(ecl_sum)") - _get_end_date = EclPrototype("time_t ecl_sum_get_end_time(ecl_sum)") - _get_last_report_step = EclPrototype( - "int ecl_sum_get_last_report_step(ecl_sum)" + _solve_dates = ResdataPrototype( + "time_t_vector_obj rd_sum_alloc_time_solution(rd_sum, char*, double, bool)" ) - _get_first_report_step = EclPrototype( - "int ecl_sum_get_first_report_step(ecl_sum)" + _get_first_gt = ResdataPrototype( + "int rd_sum_get_first_gt(rd_sum, int, double)" ) - _select_matching_keys = EclPrototype( - "void ecl_sum_select_matching_general_var_list(ecl_sum, char*, stringlist)" + _get_first_lt = ResdataPrototype( + "int rd_sum_get_first_lt(rd_sum, int, double)" ) - _has_key = EclPrototype("bool ecl_sum_has_general_var(ecl_sum, char*)") - _check_sim_time = EclPrototype("bool ecl_sum_check_sim_time(ecl_sum, time_t)") - _check_sim_days = EclPrototype("bool ecl_sum_check_sim_days(ecl_sum, double)") - _sim_length = EclPrototype("double ecl_sum_get_sim_length(ecl_sum)") - _get_first_day = EclPrototype("double ecl_sum_get_first_day(ecl_sum)") - _get_data_start = EclPrototype("time_t ecl_sum_get_data_start(ecl_sum)") - _get_unit = EclPrototype("char* ecl_sum_get_unit(ecl_sum, char*)") - _get_restart_case = EclPrototype("ecl_sum_ref ecl_sum_get_restart_case(ecl_sum)") - _get_restart_step = EclPrototype("int ecl_sum_get_restart_step(ecl_sum)") - _get_simcase = EclPrototype("char* ecl_sum_get_case(ecl_sum)") - _get_unit_system = EclPrototype("ecl_unit_enum ecl_sum_get_unit_system(ecl_sum)") - _get_base = EclPrototype("char* ecl_sum_get_base(ecl_sum)") - _get_path = EclPrototype("char* ecl_sum_get_path(ecl_sum)") - _get_abs_path = EclPrototype("char* ecl_sum_get_abs_path(ecl_sum)") - _get_report_step_from_time = EclPrototype( - "int ecl_sum_get_report_step_from_time(ecl_sum, time_t)" + _get_start_date = ResdataPrototype("time_t rd_sum_get_start_time(rd_sum)") + _get_end_date = ResdataPrototype("time_t rd_sum_get_end_time(rd_sum)") + _get_last_report_step = ResdataPrototype( + "int rd_sum_get_last_report_step(rd_sum)" ) - _get_report_step_from_days = EclPrototype( - "int ecl_sum_get_report_step_from_days(ecl_sum, double)" + _get_first_report_step = ResdataPrototype( + "int rd_sum_get_first_report_step(rd_sum)" ) - _get_report_time = EclPrototype("time_t ecl_sum_get_report_time(ecl_sum, int)") - _fwrite_sum = EclPrototype("void ecl_sum_fwrite(ecl_sum)") - _can_write = EclPrototype("bool ecl_sum_can_write(ecl_sum)") - _set_case = EclPrototype("void ecl_sum_set_case(ecl_sum, char*)") - _alloc_time_vector = EclPrototype( - "time_t_vector_obj ecl_sum_alloc_time_vector(ecl_sum, bool)" + _select_matching_keys = ResdataPrototype( + "void rd_sum_select_matching_general_var_list(rd_sum, char*, stringlist)" ) - _alloc_data_vector = EclPrototype( - "double_vector_obj ecl_sum_alloc_data_vector(ecl_sum, int, bool)" + _has_key = ResdataPrototype("bool rd_sum_has_general_var(rd_sum, char*)") + _check_sim_time = ResdataPrototype("bool rd_sum_check_sim_time(rd_sum, time_t)") + _check_sim_days = ResdataPrototype("bool rd_sum_check_sim_days(rd_sum, double)") + _sim_length = ResdataPrototype("double rd_sum_get_sim_length(rd_sum)") + _get_first_day = ResdataPrototype("double rd_sum_get_first_day(rd_sum)") + _get_data_start = ResdataPrototype("time_t rd_sum_get_data_start(rd_sum)") + _get_unit = ResdataPrototype("char* rd_sum_get_unit(rd_sum, char*)") + _get_restart_case = ResdataPrototype("rd_sum_ref rd_sum_get_restart_case(rd_sum)") + _get_restart_step = ResdataPrototype("int rd_sum_get_restart_step(rd_sum)") + _get_simcase = ResdataPrototype("char* rd_sum_get_case(rd_sum)") + _get_unit_system = ResdataPrototype("rd_unit_enum rd_sum_get_unit_system(rd_sum)") + _get_base = ResdataPrototype("char* rd_sum_get_base(rd_sum)") + _get_path = ResdataPrototype("char* rd_sum_get_path(rd_sum)") + _get_abs_path = ResdataPrototype("char* rd_sum_get_abs_path(rd_sum)") + _get_report_step_from_time = ResdataPrototype( + "int rd_sum_get_report_step_from_time(rd_sum, time_t)" ) - _get_var_node = EclPrototype( - "smspec_node_ref ecl_sum_get_general_var_node(ecl_sum, char*)" + _get_report_step_from_days = ResdataPrototype( + "int rd_sum_get_report_step_from_days(rd_sum, double)" ) - _create_well_list = EclPrototype( - "stringlist_obj ecl_sum_alloc_well_list(ecl_sum, char*)" + _get_report_time = ResdataPrototype("time_t rd_sum_get_report_time(rd_sum, int)") + _fwrite_sum = ResdataPrototype("void rd_sum_fwrite(rd_sum)") + _can_write = ResdataPrototype("bool rd_sum_can_write(rd_sum)") + _set_case = ResdataPrototype("void rd_sum_set_case(rd_sum, char*)") + _alloc_time_vector = ResdataPrototype( + "time_t_vector_obj rd_sum_alloc_time_vector(rd_sum, bool)" ) - _create_group_list = EclPrototype( - "stringlist_obj ecl_sum_alloc_group_list(ecl_sum, char*)" + _alloc_data_vector = ResdataPrototype( + "double_vector_obj rd_sum_alloc_data_vector(rd_sum, int, bool)" ) - _add_variable = EclPrototype( - "smspec_node_ref ecl_sum_add_var(ecl_sum, char*, char*, int, char*, double)" + _get_var_node = ResdataPrototype( + "smspec_node_ref rd_sum_get_general_var_node(rd_sum, char*)" ) - _add_tstep = EclPrototype( - "ecl_sum_tstep_ref ecl_sum_add_tstep(ecl_sum, int, double)" + _create_well_list = ResdataPrototype( + "stringlist_obj rd_sum_alloc_well_list(rd_sum, char*)" ) - _export_csv = EclPrototype( - "void ecl_sum_export_csv(ecl_sum, char*, stringlist, char*, char*)" + _create_group_list = ResdataPrototype( + "stringlist_obj rd_sum_alloc_group_list(rd_sum, char*)" ) - _identify_var_type = EclPrototype( - "ecl_sum_var_type ecl_sum_identify_var_type(char*)", bind=False + _add_variable = ResdataPrototype( + "smspec_node_ref rd_sum_add_var(rd_sum, char*, char*, int, char*, double)" ) - _is_rate = EclPrototype("bool smspec_node_identify_rate(char*)", bind=False) - _is_total = EclPrototype( - "bool smspec_node_identify_total(char*, ecl_sum_var_type)", bind=False + _add_tstep = ResdataPrototype( + "rd_sum_tstep_ref rd_sum_add_tstep(rd_sum, int, double)" ) - _get_last_value = EclPrototype( - "double ecl_sum_get_last_value_gen_key(ecl_sum, char*)" + _export_csv = ResdataPrototype( + "void rd_sum_export_csv(rd_sum, char*, stringlist, char*, char*)" ) - _get_first_value = EclPrototype( - "double ecl_sum_get_first_value_gen_key(ecl_sum, char*)" + _identify_var_type = ResdataPrototype( + "rd_sum_var_type rd_sum_identify_var_type(char*)", bind=False ) - _init_numpy_vector = EclPrototype( - "void ecl_sum_init_double_vector(ecl_sum, char*, double*)" + _is_rate = ResdataPrototype("bool smspec_node_identify_rate(char*)", bind=False) + _is_total = ResdataPrototype( + "bool smspec_node_identify_total(char*, rd_sum_var_type)", bind=False ) - _init_numpy_vector_interp = EclPrototype( - "void ecl_sum_init_double_vector_interp(ecl_sum, char*, time_t_vector, double*)" + _get_last_value = ResdataPrototype( + "double rd_sum_get_last_value_gen_key(rd_sum, char*)" ) - _init_numpy_datetime64 = EclPrototype( - "void ecl_sum_init_datetime64_vector(ecl_sum, int64*, int)" + _get_first_value = ResdataPrototype( + "double rd_sum_get_first_value_gen_key(rd_sum, char*)" + ) + _init_numpy_vector = ResdataPrototype( + "void rd_sum_init_double_vector(rd_sum, char*, double*)" + ) + _init_numpy_vector_interp = ResdataPrototype( + "void rd_sum_init_double_vector_interp(rd_sum, char*, time_t_vector, double*)" + ) + _init_numpy_datetime64 = ResdataPrototype( + "void rd_sum_init_datetime64_vector(rd_sum, int64*, int)" ) def __init__( @@ -211,10 +217,10 @@ def __init__( lazy_load=True, file_options=0, ): - """Loads a new EclSum instance with summary data. + """Loads a new Summary instance with summary data. - Loads a new summary results from the ECLIPSE case given by - argument @load_case; @load_case should be the basename of the ECLIPSE + Loads a new summary results from the case given by + argument @load_case; @load_case should be the basename of the simulation you want to load. @load_case can contain a leading path component, and also an extension - the latter will be ignored. @@ -247,7 +253,7 @@ def __init__( "Failed to create summary instance from argument:%s" % load_case ) - super(EclSum, self).__init__(c_pointer) + super(Summary, self).__init__(c_pointer) self._load_case = load_case @classmethod @@ -266,31 +272,31 @@ def load(cls, smspec_file, unsmry_file, key_join_string=":", include_restart=Tru if c_ptr is None: raise IOError("Failed to create summary instance") - ecl_sum = cls.createPythonObject(c_ptr) - ecl_sum._load_case = smspec_file - return ecl_sum + rd_sum = cls.createPythonObject(c_ptr) + rd_sum._load_case = smspec_file + return rd_sum @classmethod def createCReference(cls, c_pointer, parent=None): - result = super(EclSum, cls).createCReference(c_pointer, parent) + result = super(Summary, cls).createCReference(c_pointer, parent) return result @classmethod def createPythonObject(cls, c_pointer): - result = super(EclSum, cls).createPythonObject(c_pointer) + result = super(Summary, cls).createPythonObject(c_pointer) return result @staticmethod def var_type(keyword): - return EclSum._identify_var_type(keyword) + return Summary._identify_var_type(keyword) @staticmethod def is_rate(keyword): - return EclSum._is_rate(keyword) + return Summary._is_rate(keyword) @staticmethod def is_total(keyword): - return EclSum._is_total(keyword, EclSum.var_type(keyword)) + return Summary._is_total(keyword, Summary.var_type(keyword)) @staticmethod def writer( @@ -306,12 +312,12 @@ def writer( ): """ The writer is not generally usable. - @rtype: EclSum + @rtype: Summary """ start = CTime(start_time) - smry = EclSum._create_writer( + smry = Summary._create_writer( case, fmt_output, unified, key_join_string, start, time_in_days, nx, ny, nz ) smry._load_case = "writer" @@ -333,12 +339,12 @@ def restart_writer( ): """ The writer is not generally usable. - @rtype: EclSum + @rtype: Summary """ start = CTime(start_time) - smry = EclSum._create_restart_writer( + smry = Summary._create_restart_writer( case, restart_case, restart_step, @@ -360,7 +366,7 @@ def add_variable(self, variable, wgname=None, num=0, unit="None", default_value= ) def add_t_step(self, report_step, sim_days): - """@rtype: EclSumTStep""" + """@rtype: SummaryTStep""" # report_step int if not isinstance(report_step, int): raise TypeError("Parameter report_step should be int, was %r" % report_step) @@ -375,7 +381,7 @@ def add_t_step(self, report_step, sim_days): def get_vector(self, key, report_only=False): """ - Will return EclSumVector according to @key. + Will return SummaryVector according to @key. Will raise exception KeyError if the summary object does not have @key. @@ -386,9 +392,9 @@ def get_vector(self, key, report_only=False): ) self.assertKeyValid(key) if report_only: - return EclSumVector(self, key, report_only=True) + return SummaryVector(self, key, report_only=True) else: - return EclSumVector(self, key) + return SummaryVector(self, key) def report_index_list(self): """ @@ -428,7 +434,7 @@ def get_values(self, key, report_only=False): If the optional argument report_only is true only the values corresponding to report steps are included. The method is - also available as the 'values' property of an EclSumVector + also available as the 'values' property of an SummaryVector instance. """ warnings.warn( @@ -557,7 +563,7 @@ def pandas_frame(self, time_index=None, column_keys=None): summary keys you will get a ValueError exception. - sum = EclSum(case) + sum = Summary(case) monthly_dates = sum.time_range(interval="1M") data = sum.pandas_frame(time_index = monthly_dates, column_keys=["F*PT"]) @@ -568,12 +574,12 @@ def pandas_frame(self, time_index=None, column_keys=None): 2010-04-01 672.7 620.4 78.7 .... """ - from ecl.summary import EclSumKeyWordVector + from resdata.summary import SummaryKeyWordVector if column_keys is None: - keywords = EclSumKeyWordVector(self, add_keywords=True) + keywords = SummaryKeyWordVector(self, add_keywords=True) else: - keywords = EclSumKeyWordVector(self) + keywords = SummaryKeyWordVector(self) for key in column_keys: keywords.add_keywords(key) @@ -583,13 +589,13 @@ def pandas_frame(self, time_index=None, column_keys=None): if time_index is None: time_index = self.dates data = numpy.zeros([len(time_index), len(keywords)]) - EclSum._init_pandas_frame( + Summary._init_pandas_frame( self, keywords, data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) ) else: time_points = self._make_time_vector(time_index) data = numpy.zeros([len(time_points), len(keywords)]) - EclSum._init_pandas_frame_interp( + Summary._init_pandas_frame_interp( self, keywords, time_points, @@ -644,25 +650,25 @@ def from_pandas(cls, case, frame, dims=None, headers=None): var_list = [] if headers is None: - header_list = EclSum._compile_headers_list(frame.columns.values, dims) + header_list = Summary._compile_headers_list(frame.columns.values, dims) else: - header_list = EclSum._compile_headers_list(headers, dims) + header_list = Summary._compile_headers_list(headers, dims) if dims is None: dims = [1, 1, 1] - ecl_sum = EclSum.writer(case, start_time, dims[0], dims[1], dims[2]) + rd_sum = Summary.writer(case, start_time, dims[0], dims[1], dims[2]) for kw, wgname, num, unit in header_list: var_list.append( - ecl_sum.addVariable(kw, wgname=wgname, num=num, unit=unit).getKey1() + rd_sum.addVariable(kw, wgname=wgname, num=num, unit=unit).getKey1() ) for i, time in enumerate(frame.index): days = (time - start_time).days - t_step = ecl_sum.addTStep(i + 1, days) + t_step = rd_sum.addTStep(i + 1, days) for var in var_list: t_step[var] = frame.iloc[i][var] - return ecl_sum + return rd_sum def get_key_index(self, key): """ @@ -675,13 +681,13 @@ def get_key_index(self, key): minor optimization in the case of many lookups of the same key: - sum = ecl.EclSum(case) - key_index = sum.get_key_index(key) - for time_index in range(sum.length): - value = sum.iiget(time_index, key_index) + >>> sum = Summary(case) + >>> key_index = sum.get_key_index(key) + >>> for time_index in range(sum.length): + >>> value = sum.iiget(time_index, key_index) Quite low-level function, should probably rather use a - EclSumVector based function? + SummaryVector based function? """ index = self._get_general_var_index(key) if index >= 0: @@ -698,7 +704,7 @@ def last_value(self, key): total_production = sum.last_value("FOPT") - The alternative method 'last' will return a EclSumNode + The alternative method 'last' will return a SummaryNode instance with some extra time related information. """ if not key in self: @@ -724,7 +730,7 @@ def get_last_value(self, key): def get_last(self, key): """ - Will return the last EclSumNode corresponding to @key. + Will return the last SummaryNode corresponding to @key. If you are only interested in the final value, you can use the last_value() method. @@ -743,7 +749,7 @@ def iiget(self, time_index, key_index): with the get_key_index() method first. This is a quite low level function, in most cases it will be - natural to go via e.g. an EclSumVector instance. + natural to go via e.g. an SummaryVector instance. """ return self._iiget(time_index, key_index) @@ -759,7 +765,7 @@ def iget(self, key, time_index): wwct = sum.iget("WWCT:W5", time_index) This is a quite low level function, in most cases it will be - natural to go via e.g. an EclSumVector instance. + natural to go via e.g. an SummaryVector instance. """ return self._get_general_var(time_index, key) @@ -788,7 +794,7 @@ def __getitem__(self, key): """ Implements [] operator - @key should be a summary key. - The returned value will be a EclSumVector instance. + The returned value will be a SummaryVector instance. """ warnings.warn( "The method the [] operator will change behaviour in the future. It will then return a plain numpy vector. You are advised to change to use the numpy_vector() method right away", @@ -797,20 +803,20 @@ def __getitem__(self, key): return self.get_vector(key) def scale_vector(self, key, scalar): - msg = """The function EclSum.scale_vector has been removed. As an alternative you + msg = """The function Summary.scale_vector has been removed. As an alternative you are advised to fetch vector as a numpy vector and then scale that yourself: - vec = ecl_sum.numpy_vector(key) + vec = rd_sum.numpy_vector(key) vec *= scalar """ raise NotImplementedError(msg) def shift_vector(self, key, addend): - msg = """The function EclSum.shift_vector has been removed. As an alternative you + msg = """The function Summary.shift_vector has been removed. As an alternative you are advised to fetch vector as a numpy vector and then scale that yourself: - vec = ecl_sum.numpy_vector(key) + vec = rd_sum.numpy_vector(key) vec += scalar """ @@ -840,7 +846,7 @@ def get_interp(self, key, days=None, date=None): time limits of the simulation; if else the method will raise exception ValueError. - Also available as method get_interp() on the EclSumVector + Also available as method get_interp() on the SummaryVector class. """ self.assertKeyValid(key) @@ -867,7 +873,7 @@ def get_interp(self, key, days=None, date=None): def get_interp_row(self, key_list, sim_time, invalid_value=-1): ctime = CTime(sim_time) data = DoubleVector(initial_size=len(key_list), default_value=invalid_value) - EclSum._get_interp_vector(self, ctime, key_list, data) + Summary._get_interp_vector(self, ctime, key_list, data) return data def time_range( @@ -1006,7 +1012,7 @@ def get_interp_vector(self, key, days_list=None, date_list=None): exception ValueError. Also available as method get_interp_vector() on the - EclSumVector class. + SummaryVector class. """ self.assertKeyValid(key) if days_list: @@ -1055,9 +1061,9 @@ def has_key(self, key): def smspec_node(self, key): """ - Will return a EclSMSPECNode instance corresponding to @key. + Will return a ResdataSMSPECNode instance corresponding to @key. - The returned EclSMPECNode instance can then be used to ask for + The returned ResdataSMPECNode instance can then be used to ask for various properties of the variable; i.e. if it is a rate variable, what is the unit, if it is a total variable and so on. @@ -1380,14 +1386,14 @@ def first_lt_index(self, key, limit): def first_gt(self, key, limit): """ - First EclSumNode of @key which is above @limit. + First SummaryNode of @key which is above @limit. """ vector = self[key] return vector.first_gt(limit) def first_lt(self, key, limit): """ - First EclSumNode of @key which is below @limit. + First SummaryNode of @key which is below @limit. """ vector = self[key] return vector.first_lt(limit) @@ -1412,7 +1418,7 @@ def solve_days(self, key, value, rates_clamp_lower=True): where the vector @key is equal @value. The method will return a list of values, which can have zero, one or multiple values: - case = EclSum("CASE") + case = Summary("CASE") days = case.solveDays("RPR:2", 200) if len(days) == 0: @@ -1515,14 +1521,14 @@ def keys(self, pattern=None): def can_write(self): return self._can_write() - def fwrite(self, ecl_case=None): + def fwrite(self, rd_case=None): if not self.can_write(): raise NotImplementedError( "Write method is not implemented for this case. lazy_load=True??" ) - if ecl_case: - self._set_case(ecl_case) + if rd_case: + self._set_case(rd_case) self._fwrite_sum() @@ -1549,7 +1555,7 @@ def _nicename(self): def __repr__(self): """Returns, e.g. - EclSum("NORNE_ATW2013.UNSMRY", [1997-11-06 00:00:00, 2006-12-01 00:00:00], keys=3781) at 0x1609e20 + Summary("NORNE_ATW2013.UNSMRY", [1997-11-06 00:00:00, 2006-12-01 00:00:00], keys=3781) at 0x1609e20 """ name = self._nicename() s_time = self.getStartTime() @@ -1565,7 +1571,7 @@ def dump_csv_line(self, time, keywords, pfile): """ cfile = CFILE(pfile) ctime = CTime(time) - EclSum._dump_csv_line(self, ctime, keywords, cfile) + Summary._dump_csv_line(self, ctime, keywords, cfile) def export_csv(self, filename, keys=None, date_format="%Y-%m-%d", sep=";"): """Will create a CSV file with summary data. @@ -1574,8 +1580,8 @@ def export_csv(self, filename, keys=None, date_format="%Y-%m-%d", sep=";"): exported, but by using the optional keys parameter you can limit the keys which are exported: - ecl_sum = EclSum("CASE") - ecl_sum.exportCSV("case.csv", keys=["W*:OP1", "W*:OP2", "F*T"]) + rd_sum = Summary("CASE") + rd_sum.exportCSV("case.csv", keys=["W*:OP1", "W*:OP2", "F*T"]) Will export all well related variables for wells 'OP1' and 'OP2' and all total field vectors. @@ -1607,36 +1613,36 @@ def resample( return new_case -import ecl.summary.ecl_sum_keyword_vector +import resdata.summary.rd_sum_keyword_vector -EclSum._dump_csv_line = EclPrototype( - "void ecl_sum_fwrite_interp_csv_line(ecl_sum, time_t, ecl_sum_vector, FILE)", +Summary._dump_csv_line = ResdataPrototype( + "void rd_sum_fwrite_interp_csv_line(rd_sum, time_t, rd_sum_vector, FILE)", bind=False, ) -EclSum._get_interp_vector = EclPrototype( - "void ecl_sum_get_interp_vector(ecl_sum, time_t, ecl_sum_vector, double_vector)", +Summary._get_interp_vector = ResdataPrototype( + "void rd_sum_get_interp_vector(rd_sum, time_t, rd_sum_vector, double_vector)", bind=False, ) -EclSum._init_pandas_frame = EclPrototype( - "void ecl_sum_init_double_frame(ecl_sum, ecl_sum_vector, double*)", bind=False +Summary._init_pandas_frame = ResdataPrototype( + "void rd_sum_init_double_frame(rd_sum, rd_sum_vector, double*)", bind=False ) -EclSum._init_pandas_frame_interp = EclPrototype( - "void ecl_sum_init_double_frame_interp(ecl_sum, ecl_sum_vector, time_t_vector, double*)", +Summary._init_pandas_frame_interp = ResdataPrototype( + "void rd_sum_init_double_frame_interp(rd_sum, rd_sum_vector, time_t_vector, double*)", bind=False, ) -monkey_the_camel(EclSum, "varType", EclSum.var_type, classmethod) -monkey_the_camel(EclSum, "addVariable", EclSum.add_variable) -monkey_the_camel(EclSum, "addTStep", EclSum.add_t_step) -monkey_the_camel(EclSum, "assertKeyValid", EclSum.assert_key_valid) -monkey_the_camel(EclSum, "scaleVector", EclSum.scale_vector) -monkey_the_camel(EclSum, "shiftVector", EclSum.shift_vector) -monkey_the_camel(EclSum, "timeRange", EclSum.time_range) -monkey_the_camel(EclSum, "blockedProduction", EclSum.blocked_production) -monkey_the_camel(EclSum, "getDataStartTime", EclSum.get_data_start_time) -monkey_the_camel(EclSum, "getStartTime", EclSum.get_start_time) -monkey_the_camel(EclSum, "getEndTime", EclSum.get_end_time) -monkey_the_camel(EclSum, "solveDates", EclSum.solve_dates) -monkey_the_camel(EclSum, "solveDays", EclSum.solve_days) -monkey_the_camel(EclSum, "dumpCSVLine", EclSum.dump_csv_line) -monkey_the_camel(EclSum, "exportCSV", EclSum.export_csv) +monkey_the_camel(Summary, "varType", Summary.var_type, classmethod) +monkey_the_camel(Summary, "addVariable", Summary.add_variable) +monkey_the_camel(Summary, "addTStep", Summary.add_t_step) +monkey_the_camel(Summary, "assertKeyValid", Summary.assert_key_valid) +monkey_the_camel(Summary, "scaleVector", Summary.scale_vector) +monkey_the_camel(Summary, "shiftVector", Summary.shift_vector) +monkey_the_camel(Summary, "timeRange", Summary.time_range) +monkey_the_camel(Summary, "blockedProduction", Summary.blocked_production) +monkey_the_camel(Summary, "getDataStartTime", Summary.get_data_start_time) +monkey_the_camel(Summary, "getStartTime", Summary.get_start_time) +monkey_the_camel(Summary, "getEndTime", Summary.get_end_time) +monkey_the_camel(Summary, "solveDates", Summary.solve_dates) +monkey_the_camel(Summary, "solveDays", Summary.solve_days) +monkey_the_camel(Summary, "dumpCSVLine", Summary.dump_csv_line) +monkey_the_camel(Summary, "exportCSV", Summary.export_csv) diff --git a/python/resdata/summary/rd_sum_keyword_vector.py b/python/resdata/summary/rd_sum_keyword_vector.py new file mode 100644 index 0000000000..fa2ca308ef --- /dev/null +++ b/python/resdata/summary/rd_sum_keyword_vector.py @@ -0,0 +1,63 @@ +import numpy +import datetime + +# Observe that there is some convention conflict with the C code +# regarding order of arguments: The C code generally takes the time +# index as the first argument and the key/key_index as second +# argument. In the python code this order has been reversed. + +from cwrap import BaseCClass +from resdata.util.util import monkey_the_camel +from resdata import ResdataPrototype + + +class SummaryKeyWordVector(BaseCClass): + TYPE_NAME = "rd_sum_vector" + _alloc = ResdataPrototype("void* rd_sum_vector_alloc(rd_sum, bool)", bind=False) + _alloc_copy = ResdataPrototype( + "rd_sum_vector_obj rd_sum_vector_alloc_layout_copy(rd_sum_vector, rd_sum)" + ) + _free = ResdataPrototype("void rd_sum_vector_free(rd_sum_vector)") + _add = ResdataPrototype("bool rd_sum_vector_add_key(rd_sum_vector, char*)") + _add_multiple = ResdataPrototype( + "void rd_sum_vector_add_keys(rd_sum_vector, char*)" + ) + _get_size = ResdataPrototype("int rd_sum_vector_get_size(rd_sum_vector)") + _iget_key = ResdataPrototype("char* rd_sum_vector_iget_key(rd_sum_vector, int)") + + def __init__(self, rd_sum, add_keywords=False): + c_pointer = self._alloc(rd_sum, add_keywords) + super(SummaryKeyWordVector, self).__init__(c_pointer) + + def __getitem__(self, index): + if index < 0: + index += len(self) + + if index >= len(self): + raise IndexError("Out of range") + + return self._iget_key(index) + + def __len__(self): + return self._get_size() + + def free(self): + self._free() + + def add_keyword(self, keyword): + success = self._add(keyword) + if not success: + raise KeyError("Failed to add keyword to vector") + + def add_keywords(self, keyword_pattern): + self._add_multiple(keyword_pattern) + + def __repr__(self): + return self._create_repr("len=%d" % len(self)) + + def copy(self, rd_sum): + return self._alloc_copy(rd_sum) + + +monkey_the_camel(SummaryKeyWordVector, "addKeyword", SummaryKeyWordVector.add_keyword) +monkey_the_camel(SummaryKeyWordVector, "addKeywords", SummaryKeyWordVector.add_keywords) diff --git a/python/ecl/summary/ecl_sum_node.py b/python/resdata/summary/rd_sum_node.py similarity index 54% rename from python/ecl/summary/ecl_sum_node.py rename to python/resdata/summary/rd_sum_node.py index f5188e21fb..024bb661f0 100644 --- a/python/ecl/summary/ecl_sum_node.py +++ b/python/resdata/summary/rd_sum_node.py @@ -1,12 +1,12 @@ -class EclSumNode(object): +class SummaryNode(object): def __init__(self, report_step, days, date, mpl_date, value): """ - EclSumNode is a 'struct' with a summary value and time. + SummaryNode is a 'struct' with a summary value and time. - EclSumNode - a small 'struct' with a summary value and time in - several formats. When iterating over a EclSumVector instance - you will get EclSumNode instances. The content of the - EclSumNode type is stored as plain attributes: + SummaryNode - a small 'struct' with a summary value and time in + several formats. When iterating over a SummaryVector instance + you will get SummaryNode instances. The content of the + SummaryNode type is stored as plain attributes: value : The actual value report_step : The report step @@ -22,4 +22,4 @@ def __init__(self, report_step, days, date, mpl_date, value): self.mpl_date = mpl_date def __repr__(self): - return "EclSumNode(days=%d, value=%g)" % (self.days, self.value) + return "SummaryNode(days=%d, value=%g)" % (self.days, self.value) diff --git a/python/ecl/summary/ecl_sum_tstep.py b/python/resdata/summary/rd_sum_tstep.py similarity index 50% rename from python/ecl/summary/ecl_sum_tstep.py rename to python/resdata/summary/rd_sum_tstep.py index ff460d20e9..c85a88c90d 100644 --- a/python/ecl/summary/ecl_sum_tstep.py +++ b/python/resdata/summary/rd_sum_tstep.py @@ -1,32 +1,32 @@ from cwrap import BaseCClass -from ecl.util.util import monkey_the_camel -from ecl.util.util import CTime -from ecl import EclPrototype +from resdata.util.util import monkey_the_camel +from resdata.util.util import CTime +from resdata import ResdataPrototype -class EclSumTStep(BaseCClass): - TYPE_NAME = "ecl_sum_tstep" - _alloc = EclPrototype( - "void* ecl_sum_tstep_alloc_new(int, int, float, void*)", bind=False +class SummaryTStep(BaseCClass): + TYPE_NAME = "rd_sum_tstep" + _alloc = ResdataPrototype( + "void* rd_sum_tstep_alloc_new(int, int, float, void*)", bind=False ) - _free = EclPrototype("void ecl_sum_tstep_free(ecl_sum_tstep)") - _get_sim_days = EclPrototype("double ecl_sum_tstep_get_sim_days(ecl_sum_tstep)") - _get_sim_time = EclPrototype("time_t ecl_sum_tstep_get_sim_time(ecl_sum_tstep)") - _get_report = EclPrototype("int ecl_sum_tstep_get_report(ecl_sum_tstep)") - _get_ministep = EclPrototype("int ecl_sum_tstep_get_ministep(ecl_sum_tstep)") - _set_from_key = EclPrototype( - "void ecl_sum_tstep_set_from_key(ecl_sum_tstep, char*, float)" + _free = ResdataPrototype("void rd_sum_tstep_free(rd_sum_tstep)") + _get_sim_days = ResdataPrototype("double rd_sum_tstep_get_sim_days(rd_sum_tstep)") + _get_sim_time = ResdataPrototype("time_t rd_sum_tstep_get_sim_time(rd_sum_tstep)") + _get_report = ResdataPrototype("int rd_sum_tstep_get_report(rd_sum_tstep)") + _get_ministep = ResdataPrototype("int rd_sum_tstep_get_ministep(rd_sum_tstep)") + _set_from_key = ResdataPrototype( + "void rd_sum_tstep_set_from_key(rd_sum_tstep, char*, float)" ) - _get_from_key = EclPrototype( - "double ecl_sum_tstep_get_from_key(ecl_sum_tstep, char*)" + _get_from_key = ResdataPrototype( + "double rd_sum_tstep_get_from_key(rd_sum_tstep, char*)" ) - _has_key = EclPrototype("bool ecl_sum_tstep_has_key(ecl_sum_tstep, char*)") + _has_key = ResdataPrototype("bool rd_sum_tstep_has_key(rd_sum_tstep, char*)") def __init__(self, report_step, mini_step, sim_days, smspec): sim_seconds = sim_days * 24 * 60 * 60 c_pointer = self._alloc(report_step, mini_step, sim_seconds, smspec) - super(EclSumTStep, self).__init__(c_pointer) + super(SummaryTStep, self).__init__(c_pointer) def get_sim_days(self): """@rtype: double""" @@ -72,7 +72,7 @@ def __repr__(self): return self._create_repr(cnt.format(d, t, r, m)) -monkey_the_camel(EclSumTStep, "getSimDays", EclSumTStep.get_sim_days) -monkey_the_camel(EclSumTStep, "getReport", EclSumTStep.get_report) -monkey_the_camel(EclSumTStep, "getMiniStep", EclSumTStep.get_mini_step) -monkey_the_camel(EclSumTStep, "getSimTime", EclSumTStep.get_sim_time) +monkey_the_camel(SummaryTStep, "getSimDays", SummaryTStep.get_sim_days) +monkey_the_camel(SummaryTStep, "getReport", SummaryTStep.get_report) +monkey_the_camel(SummaryTStep, "getMiniStep", SummaryTStep.get_mini_step) +monkey_the_camel(SummaryTStep, "getSimTime", SummaryTStep.get_sim_time) diff --git a/python/resdata/summary/rd_sum_var_type.py b/python/resdata/summary/rd_sum_var_type.py new file mode 100644 index 0000000000..1c65403d39 --- /dev/null +++ b/python/resdata/summary/rd_sum_var_type.py @@ -0,0 +1,37 @@ +from cwrap import BaseCEnum + + +class SummaryVarType(BaseCEnum): + TYPE_NAME = "rd_sum_var_type" + RD_SMSPEC_INVALID_VAR = None + RD_SMSPEC_FIELD_VAR = None + RD_SMSPEC_REGION_VAR = None + RD_SMSPEC_GROUP_VAR = None + RD_SMSPEC_WELL_VAR = None + RD_SMSPEC_SEGMENT_VAR = None + RD_SMSPEC_BLOCK_VAR = None + RD_SMSPEC_AQUIFER_VAR = None + RD_SMSPEC_COMPLETION_VAR = None + RD_SMSPEC_NETWORK_VAR = None + RD_SMSPEC_REGION_2_REGION_VAR = None + RD_SMSPEC_LOCAL_BLOCK_VAR = None + RD_SMSPEC_LOCAL_COMPLETION_VAR = None + RD_SMSPEC_LOCAL_WELL_VAR = None + RD_SMSPEC_MISC_VAR = None + + +SummaryVarType.addEnum("RD_SMSPEC_INVALID_VAR", 0) +SummaryVarType.addEnum("RD_SMSPEC_FIELD_VAR", 1) +SummaryVarType.addEnum("RD_SMSPEC_REGION_VAR", 2) +SummaryVarType.addEnum("RD_SMSPEC_GROUP_VAR", 3) +SummaryVarType.addEnum("RD_SMSPEC_WELL_VAR", 4) +SummaryVarType.addEnum("RD_SMSPEC_SEGMENT_VAR", 5) +SummaryVarType.addEnum("RD_SMSPEC_BLOCK_VAR", 6) +SummaryVarType.addEnum("RD_SMSPEC_AQUIFER_VAR", 7) +SummaryVarType.addEnum("RD_SMSPEC_COMPLETION_VAR", 8) +SummaryVarType.addEnum("RD_SMSPEC_NETWORK_VAR", 9) +SummaryVarType.addEnum("RD_SMSPEC_REGION_2_REGION_VAR", 10) +SummaryVarType.addEnum("RD_SMSPEC_LOCAL_BLOCK_VAR", 11) +SummaryVarType.addEnum("RD_SMSPEC_LOCAL_COMPLETION_VAR", 12) +SummaryVarType.addEnum("RD_SMSPEC_LOCAL_WELL_VAR", 13) +SummaryVarType.addEnum("RD_SMSPEC_MISC_VAR", 14) diff --git a/python/ecl/summary/ecl_sum_vector.py b/python/resdata/summary/rd_sum_vector.py similarity index 88% rename from python/ecl/summary/ecl_sum_vector.py rename to python/resdata/summary/rd_sum_vector.py index 3d8aa303ae..5a136e5fdb 100644 --- a/python/ecl/summary/ecl_sum_vector.py +++ b/python/resdata/summary/rd_sum_vector.py @@ -1,9 +1,9 @@ from __future__ import print_function import warnings -from ecl.summary.ecl_sum_node import EclSumNode +from .rd_sum_node import SummaryNode -class EclSumVector(object): +class SummaryVector(object): def __init__(self, parent, key, report_only=False): """ A summary vector with a vector of values and time. @@ -11,15 +11,15 @@ def __init__(self, parent, key, report_only=False): A summary vector contains the the full time history of one key, along with the corresponding time vectors in several different time formats. Depending on the report_only argument - the data vectors in the EclSumVector can either contain all + the data vectors in the SummaryVector can either contain all the time values, or only those corresponding to report_steps. - The EclSumVector contains a reference to the parent EclSum + The SummaryVector contains a reference to the parent Summary structure and this is used to implement several of the - properties and methods of the object; the EclSum vector + properties and methods of the object; the Summary vector instances should therefore only be instantiated through the - EclSum.get_vector() method, and not manually with the - EclSumVector() constructor. + Summary.get_vector() method, and not manually with the + SummaryVector() constructor. """ self.parent = parent self.key = key @@ -27,7 +27,7 @@ def __init__(self, parent, key, report_only=False): if report_only: warnings.warn( - "The report_only flag to the EclSumVector will be removed", + "The report_only flag to the SummaryVector will be removed", DeprecationWarning, ) @@ -41,7 +41,7 @@ def __str__(self): return "" % self.key def __repr__(self): - return "EclSumVector(key = %s, size = %d, unit = %s)" % ( + return "SummaryVector(key = %s, size = %d, unit = %s)" % ( self.key, len(self), self.unit, @@ -118,11 +118,11 @@ def report_step(self): def __iget(self, index): """ - Will return an EclSumNode for element @index; should be called + Will return an SummaryNode for element @index; should be called through the [] operator, otherwise you can come across unitialized data. """ - return EclSumNode( + return SummaryNode( self.__report_step[index], self.__days[index], self.__dates[index], @@ -140,14 +140,14 @@ def __getitem__(self, index): """ Implements the [] operator. - Will return EclSumNode instance according to @index. The index + Will return SummaryNode instance according to @index. The index value will be interpreted as in a normal python [] lookup, i.e. negative values will be interpreted as starting from the right and also slice notation is allowed[*]. [*] Observe that in the case of slices the return value will - not be a proper EclSumVector instance, but rather a normal - Python list of EclSumNode instances. + not be a proper SummaryVector instance, but rather a normal + Python list of SummaryNode instances. """ self.assert_values() length = len(self.values) @@ -160,8 +160,8 @@ def __getitem__(self, index): return self.__iget(index) elif isinstance(index, slice): # Observe that the slice based lookup does __not__ return - # a proper EclSumVector instance; it will merely return - # a simple Python list with EclSumNode instances. + # a proper SummaryVector instance; it will merely return + # a simple Python list with SummaryNode instances. (start, stop, step) = index.indices(length) index = start sub_vector = [] @@ -175,7 +175,7 @@ def __getitem__(self, index): @property def first(self): """ - Will return the first EclSumNode in this vector. + Will return the first SummaryNode in this vector. """ self.assert_values() return self.__iget(0) @@ -183,7 +183,7 @@ def first(self): @property def last(self): """ - Will return the last EclSumNode in this vector. + Will return the last SummaryNode in this vector. """ self.assert_values() @@ -251,7 +251,7 @@ def first_gt_index(self, limit): def first_gt(self, limit): """ - Locate the first EclSumNode where value is above @limit. + Locate the first SummaryNode where value is above @limit. vec = sum["WWCT:A-3"] w = vec.first_gt(0.50) diff --git a/python/ecl/util/__init__.py b/python/resdata/util/__init__.py similarity index 100% rename from python/ecl/util/__init__.py rename to python/resdata/util/__init__.py diff --git a/python/ecl/util/enums/__init__.py b/python/resdata/util/enums/__init__.py similarity index 100% rename from python/ecl/util/enums/__init__.py rename to python/resdata/util/enums/__init__.py diff --git a/python/ecl/util/enums/rng_alg_type_enum.py b/python/resdata/util/enums/rng_alg_type_enum.py similarity index 100% rename from python/ecl/util/enums/rng_alg_type_enum.py rename to python/resdata/util/enums/rng_alg_type_enum.py diff --git a/python/ecl/util/enums/rng_init_mode_enum.py b/python/resdata/util/enums/rng_init_mode_enum.py similarity index 100% rename from python/ecl/util/enums/rng_init_mode_enum.py rename to python/resdata/util/enums/rng_init_mode_enum.py diff --git a/python/ecl/util/test/__init__.py b/python/resdata/util/test/__init__.py similarity index 87% rename from python/ecl/util/test/__init__.py rename to python/resdata/util/test/__init__.py index 4e9dbe9e8f..d42c8527bf 100644 --- a/python/ecl/util/test/__init__.py +++ b/python/resdata/util/test/__init__.py @@ -3,7 +3,7 @@ from .extended_testcase import ExtendedTestCase from .source_enumerator import SourceEnumerator from .test_area import TestArea, TestAreaContext -from .ert_test_runner import ErtTestRunner +from .resdata_test_runner import ResdataTestRunner from .path_context import PathContext from .lint_test_case import LintTestCase from .import_test_case import ImportTestCase diff --git a/python/ecl/util/test/debug_msg.py b/python/resdata/util/test/debug_msg.py similarity index 100% rename from python/ecl/util/test/debug_msg.py rename to python/resdata/util/test/debug_msg.py diff --git a/python/ecl/util/test/ert_test_context.py b/python/resdata/util/test/ert_test_context.py similarity index 100% rename from python/ecl/util/test/ert_test_context.py rename to python/resdata/util/test/ert_test_context.py diff --git a/python/ecl/util/test/extended_testcase.py b/python/resdata/util/test/extended_testcase.py similarity index 98% rename from python/ecl/util/test/extended_testcase.py rename to python/resdata/util/test/extended_testcase.py index fa3ce7334b..d1c1e1caf4 100644 --- a/python/ecl/util/test/extended_testcase.py +++ b/python/resdata/util/test/extended_testcase.py @@ -10,8 +10,8 @@ from unittest import TestCase from .source_enumerator import SourceEnumerator -from ecl.util.util import installAbortSignals -from ecl.util.util import Version +from resdata.util.util import installAbortSignals +from resdata.util.util import Version # Function wrapper which can be used to add decorator @log_test to test diff --git a/python/ecl/util/test/import_test_case.py b/python/resdata/util/test/import_test_case.py similarity index 100% rename from python/ecl/util/test/import_test_case.py rename to python/resdata/util/test/import_test_case.py diff --git a/python/ecl/util/test/lint_test_case.py b/python/resdata/util/test/lint_test_case.py similarity index 100% rename from python/ecl/util/test/lint_test_case.py rename to python/resdata/util/test/lint_test_case.py diff --git a/python/resdata/util/test/mock/__init__.py b/python/resdata/util/test/mock/__init__.py new file mode 100644 index 0000000000..01d5fc1ea1 --- /dev/null +++ b/python/resdata/util/test/mock/__init__.py @@ -0,0 +1 @@ +from .rd_sum_mock import createSummary diff --git a/python/ecl/util/test/ecl_mock/ecl_sum_mock.py b/python/resdata/util/test/mock/rd_sum_mock.py similarity index 78% rename from python/ecl/util/test/ecl_mock/ecl_sum_mock.py rename to python/resdata/util/test/mock/rd_sum_mock.py index 95402f7ac5..86ff9cb4b3 100644 --- a/python/ecl/util/test/ecl_mock/ecl_sum_mock.py +++ b/python/resdata/util/test/mock/rd_sum_mock.py @@ -1,12 +1,12 @@ import datetime -from ecl.summary import EclSum +from resdata.summary import Summary -def mock_func(ecl_sum, key, days): +def mock_func(rd_sum, key, days): return days * 10 -def createEclSum( +def createSummary( case, keys, sim_start=datetime.date(2010, 1, 1), @@ -19,12 +19,12 @@ def createEclSum( restart_case=None, restart_step=-1, ): - ecl_sum = EclSum.restart_writer( + rd_sum = Summary.restart_writer( case, restart_case, restart_step, sim_start, dims[0], dims[1], dims[2] ) var_list = [] for kw, wgname, num, unit in keys: - var_list.append(ecl_sum.addVariable(kw, wgname=wgname, num=num, unit=unit)) + var_list.append(rd_sum.addVariable(kw, wgname=wgname, num=num, unit=unit)) # This is a bug! This should not be integer division, but tests are written # around that assumption. @@ -44,7 +44,7 @@ def createEclSum( + report_step * report_step_length + mini_step * mini_step_length ) - t_step = ecl_sum.addTStep(report_step + 1, sim_days=days) + t_step = rd_sum.addTStep(report_step + 1, sim_days=days) for var in var_list: key = var.getKey1() @@ -53,6 +53,6 @@ def createEclSum( func = func_table[key] t_step[key] = func(days) else: - t_step[key] = mock_func(ecl_sum, key, days) + t_step[key] = mock_func(rd_sum, key, days) - return ecl_sum + return rd_sum diff --git a/python/ecl/util/test/path_context.py b/python/resdata/util/test/path_context.py similarity index 100% rename from python/ecl/util/test/path_context.py rename to python/resdata/util/test/path_context.py diff --git a/python/ecl/util/test/ert_test_runner.py b/python/resdata/util/test/resdata_test_runner.py similarity index 82% rename from python/ecl/util/test/ert_test_runner.py rename to python/resdata/util/test/resdata_test_runner.py index 712460ddb7..d6e0c60e62 100644 --- a/python/ecl/util/test/ert_test_runner.py +++ b/python/resdata/util/test/resdata_test_runner.py @@ -6,7 +6,7 @@ from unittest import TestLoader, TextTestRunner -class ErtTestRunner(object): +class ResdataTestRunner(object): @staticmethod def runTestSuite(tests, test_verbosity=3): test_runner = TextTestRunner(verbosity=test_verbosity) @@ -22,7 +22,7 @@ def findTestsInDirectory(path, recursive=True, pattern="test*.py"): for root, dirnames, filenames in os.walk(path): for directory in dirnames: test_suite.addTests( - ErtTestRunner.findTestsInDirectory( + ResdataTestRunner.findTestsInDirectory( os.path.join(root, directory), recursive, pattern ) ) @@ -31,12 +31,12 @@ def findTestsInDirectory(path, recursive=True, pattern="test*.py"): @staticmethod def runTestsInDirectory(path=".", recursive=True, test_verbosity=3): - test_suite = ErtTestRunner.findTestsInDirectory(path, recursive) - return ErtTestRunner.runTestSuite(test_suite) + test_suite = ResdataTestRunner.findTestsInDirectory(path, recursive) + return ResdataTestRunner.runTestSuite(test_suite) @staticmethod def runTestsInClass(classpath, test_verbosity=3): - klass = ErtTestRunner.importClass(classpath) + klass = ResdataTestRunner.importClass(classpath) loader = TestLoader() tests = loader.loadTestsFromTestCase(klass) testRunner = TextTestRunner(verbosity=test_verbosity) @@ -55,7 +55,7 @@ def importClass(classpath): @staticmethod def getTestsFromTestClass(test_class_path, argv=None): - klass = ErtTestRunner.importClass(test_class_path) + klass = ResdataTestRunner.importClass(test_class_path) klass.argv = argv loader = TestLoader() return loader.loadTestsFromTestCase(klass) diff --git a/python/ecl/util/test/source_enumerator.py b/python/resdata/util/test/source_enumerator.py similarity index 100% rename from python/ecl/util/test/source_enumerator.py rename to python/resdata/util/test/source_enumerator.py diff --git a/python/ecl/util/test/test_area.py b/python/resdata/util/test/test_area.py similarity index 86% rename from python/ecl/util/test/test_area.py rename to python/resdata/util/test/test_area.py index 0e0159b141..29c75c0c20 100644 --- a/python/ecl/util/test/test_area.py +++ b/python/resdata/util/test/test_area.py @@ -1,34 +1,34 @@ import os.path from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype class TestArea(BaseCClass): __test__ = False - _test_area_alloc = EclPrototype( + _test_area_alloc = ResdataPrototype( "void* test_work_area_alloc__( char*, bool )", bind=False ) - _free = EclPrototype("void test_work_area_free( test_area )") - _install_file = EclPrototype( + _free = ResdataPrototype("void test_work_area_free( test_area )") + _install_file = ResdataPrototype( "void test_work_area_install_file( test_area , char* )" ) - _copy_directory = EclPrototype( + _copy_directory = ResdataPrototype( "void test_work_area_copy_directory( test_area , char* )" ) - _copy_file = EclPrototype("void test_work_area_copy_file( test_area , char* )") - _copy_directory_content = EclPrototype( + _copy_file = ResdataPrototype("void test_work_area_copy_file( test_area , char* )") + _copy_directory_content = ResdataPrototype( "void test_work_area_copy_directory_content( test_area , char* )" ) - _copy_parent_directory = EclPrototype( + _copy_parent_directory = ResdataPrototype( "void test_work_area_copy_parent_directory( test_area , char* )" ) - _copy_parent_content = EclPrototype( + _copy_parent_content = ResdataPrototype( "void test_work_area_copy_parent_content( test_area , char* )" ) - _get_cwd = EclPrototype("char* test_work_area_get_cwd( test_area )") - _get_original_cwd = EclPrototype( + _get_cwd = ResdataPrototype("char* test_work_area_get_cwd( test_area )") + _get_original_cwd = ResdataPrototype( "char* test_work_area_get_original_cwd( test_area )" ) diff --git a/python/ecl/util/test/test_run.py b/python/resdata/util/test/test_run.py similarity index 100% rename from python/ecl/util/test/test_run.py rename to python/resdata/util/test/test_run.py diff --git a/python/ecl/util/util/__init__.py b/python/resdata/util/util/__init__.py similarity index 83% rename from python/ecl/util/util/__init__.py rename to python/resdata/util/util/__init__.py index d7bb263303..a3b20cb432 100644 --- a/python/ecl/util/util/__init__.py +++ b/python/resdata/util/util/__init__.py @@ -23,13 +23,13 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import ecl +import resdata from cwrap import Prototype -from .version import Version, EclVersion +from .version import Version, ResdataVersion -from ecl.util.enums import RngAlgTypeEnum, RngInitModeEnum +from resdata.util.enums import RngAlgTypeEnum, RngInitModeEnum from .ctime import CTime @@ -49,18 +49,18 @@ ### -### monkey_the_camel is a function temporarily added to libecl while we are in +### monkey_the_camel is a function temporarily added to resdata while we are in ### the process of changing camelCase function names to snake_case function ### names. ### -### See https://github.com/Equinor/libecl/issues/142 for a discussion and for +### See https://github.com/Equinor/resdata/issues/142 for a discussion and for ### usage. ### import os import warnings -__cc = os.environ.get("ECLWARNING", None) # __cc in (None, 'user', 'dev', 'hard') +__cc = os.environ.get("RDWARNING", None) # __cc in (None, 'user', 'dev', 'hard') def __silencio(msg): @@ -79,13 +79,13 @@ def __hard_warning(msg): raise UserWarning("CamelCase exception: " + msg) -__ecl_camel_case_warning = __silencio +__rd_camel_case_warning = __silencio if __cc == "user": - __ecl_camel_case_warning = __user_warning + __rd_camel_case_warning = __user_warning elif __cc == "dev": - __ecl_camel_case_warning = __dev_warning + __rd_camel_case_warning = __dev_warning elif __cc == "hard": - __ecl_camel_case_warning = __hard_warning + __rd_camel_case_warning = __hard_warning def monkey_the_camel(class_, camel, method_, method_type=None): @@ -98,7 +98,7 @@ def shift(*args): return args if (method_type != classmethod) else args[1:] def warned_method(*args, **kwargs): - __ecl_camel_case_warning( + __rd_camel_case_warning( "Warning, %s is deprecated, use %s" % (camel, str(method_)) ) return method_(*shift(*args), **kwargs) diff --git a/python/ecl/util/util/arg_pack.py b/python/resdata/util/util/arg_pack.py similarity index 61% rename from python/ecl/util/util/arg_pack.py rename to python/resdata/util/util/arg_pack.py index a4135ba599..f4af42d0ba 100644 --- a/python/ecl/util/util/arg_pack.py +++ b/python/resdata/util/util/arg_pack.py @@ -1,17 +1,17 @@ from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype class ArgPack(BaseCClass): TYPE_NAME = "arg_pack" - _alloc = EclPrototype("void* arg_pack_alloc()", bind=False) - _append_int = EclPrototype("void arg_pack_append_int(arg_pack, int)") - _append_double = EclPrototype("void arg_pack_append_double(arg_pack, double)") - _append_ptr = EclPrototype("void arg_pack_append_ptr(arg_pack, void*)") + _alloc = ResdataPrototype("void* arg_pack_alloc()", bind=False) + _append_int = ResdataPrototype("void arg_pack_append_int(arg_pack, int)") + _append_double = ResdataPrototype("void arg_pack_append_double(arg_pack, double)") + _append_ptr = ResdataPrototype("void arg_pack_append_ptr(arg_pack, void*)") - _size = EclPrototype("int arg_pack_size(arg_pack)") - _free = EclPrototype("void arg_pack_free(arg_pack)") + _size = ResdataPrototype("int arg_pack_size(arg_pack)") + _free = ResdataPrototype("void arg_pack_free(arg_pack)") def __init__(self, *args): c_ptr = self._alloc() diff --git a/python/ecl/util/util/bool_vector.py b/python/resdata/util/util/bool_vector.py similarity index 52% rename from python/ecl/util/util/bool_vector.py rename to python/resdata/util/util/bool_vector.py index 4a0f3c2b54..015d05482b 100644 --- a/python/ecl/util/util/bool_vector.py +++ b/python/resdata/util/util/bool_vector.py @@ -1,91 +1,97 @@ -from ecl import EclPrototype -from ecl.util.util import VectorTemplate +from resdata import ResdataPrototype +from resdata.util.util import VectorTemplate class BoolVector(VectorTemplate): default_format = "%8d" - _alloc = EclPrototype("void* bool_vector_alloc( int , bool )", bind=False) - _create_active_mask = EclPrototype( + _alloc = ResdataPrototype("void* bool_vector_alloc( int , bool )", bind=False) + _create_active_mask = ResdataPrototype( "bool_vector_obj string_util_alloc_active_mask( char* )", bind=False ) - _active_list = EclPrototype( + _active_list = ResdataPrototype( "int_vector_obj bool_vector_alloc_active_list(bool_vector)" ) - _alloc_copy = EclPrototype("bool_vector_obj bool_vector_alloc_copy( bool_vector )") - _update_active_mask = EclPrototype( + _alloc_copy = ResdataPrototype( + "bool_vector_obj bool_vector_alloc_copy( bool_vector )" + ) + _update_active_mask = ResdataPrototype( "bool string_util_update_active_mask(char*, bool_vector)", bind=False ) - _strided_copy = EclPrototype( + _strided_copy = ResdataPrototype( "bool_vector_obj bool_vector_alloc_strided_copy( bool_vector , int , int , int)" ) - _free = EclPrototype("void bool_vector_free( bool_vector )") - _iget = EclPrototype("bool bool_vector_iget( bool_vector , int )") - _safe_iget = EclPrototype("bool bool_vector_safe_iget( bool_vector , int )") - _iset = EclPrototype("void bool_vector_iset( bool_vector , int , bool)") - _size = EclPrototype("int bool_vector_size( bool_vector )") - _append = EclPrototype("void bool_vector_append( bool_vector , bool )") - _idel_block = EclPrototype( + _free = ResdataPrototype("void bool_vector_free( bool_vector )") + _iget = ResdataPrototype("bool bool_vector_iget( bool_vector , int )") + _safe_iget = ResdataPrototype("bool bool_vector_safe_iget( bool_vector , int )") + _iset = ResdataPrototype("void bool_vector_iset( bool_vector , int , bool)") + _size = ResdataPrototype("int bool_vector_size( bool_vector )") + _append = ResdataPrototype("void bool_vector_append( bool_vector , bool )") + _idel_block = ResdataPrototype( "void bool_vector_idel_block( bool_vector , bool , bool )" ) - _idel = EclPrototype("void bool_vector_idel( bool_vector , int )") - _pop = EclPrototype("bool bool_vector_pop( bool_vector )") - _lshift = EclPrototype("void bool_vector_lshift( bool_vector , int )") - _rshift = EclPrototype("void bool_vector_rshift( bool_vector , int )") - _insert = EclPrototype("void bool_vector_insert( bool_vector , int , bool)") - _fprintf = EclPrototype( + _idel = ResdataPrototype("void bool_vector_idel( bool_vector , int )") + _pop = ResdataPrototype("bool bool_vector_pop( bool_vector )") + _lshift = ResdataPrototype("void bool_vector_lshift( bool_vector , int )") + _rshift = ResdataPrototype("void bool_vector_rshift( bool_vector , int )") + _insert = ResdataPrototype("void bool_vector_insert( bool_vector , int , bool)") + _fprintf = ResdataPrototype( "void bool_vector_fprintf( bool_vector , FILE , char* , char*)" ) - _sort = EclPrototype("void bool_vector_sort( bool_vector )") - _rsort = EclPrototype("void bool_vector_rsort( bool_vector )") - _reset = EclPrototype("void bool_vector_reset( bool_vector )") - _set_read_only = EclPrototype( + _sort = ResdataPrototype("void bool_vector_sort( bool_vector )") + _rsort = ResdataPrototype("void bool_vector_rsort( bool_vector )") + _reset = ResdataPrototype("void bool_vector_reset( bool_vector )") + _set_read_only = ResdataPrototype( "void bool_vector_set_read_only( bool_vector , bool )" ) - _get_read_only = EclPrototype("bool bool_vector_get_read_only( bool_vector )") - _get_max = EclPrototype("bool bool_vector_get_max( bool_vector )") - _get_min = EclPrototype("bool bool_vector_get_min( bool_vector )") - _get_max_index = EclPrototype( + _get_read_only = ResdataPrototype("bool bool_vector_get_read_only( bool_vector )") + _get_max = ResdataPrototype("bool bool_vector_get_max( bool_vector )") + _get_min = ResdataPrototype("bool bool_vector_get_min( bool_vector )") + _get_max_index = ResdataPrototype( "int bool_vector_get_max_index( bool_vector , bool)" ) - _get_min_index = EclPrototype( + _get_min_index = ResdataPrototype( "int bool_vector_get_min_index( bool_vector , bool)" ) - _shift = EclPrototype("void bool_vector_shift( bool_vector , bool )") - _scale = EclPrototype("void bool_vector_scale( bool_vector , bool )") - _div = EclPrototype("void bool_vector_div( bool_vector , bool )") - _inplace_add = EclPrototype( + _shift = ResdataPrototype("void bool_vector_shift( bool_vector , bool )") + _scale = ResdataPrototype("void bool_vector_scale( bool_vector , bool )") + _div = ResdataPrototype("void bool_vector_div( bool_vector , bool )") + _inplace_add = ResdataPrototype( "void bool_vector_inplace_add( bool_vector , bool_vector )" ) - _inplace_mul = EclPrototype( + _inplace_mul = ResdataPrototype( "void bool_vector_inplace_mul( bool_vector , bool_vector )" ) - _assign = EclPrototype("void bool_vector_set_all( bool_vector , bool)") - _memcpy = EclPrototype("void bool_vector_memcpy(bool_vector , bool_vector )") - _set_default = EclPrototype("void bool_vector_set_default( bool_vector , bool)") - _get_default = EclPrototype("bool bool_vector_get_default( bool_vector )") - _element_size = EclPrototype("int bool_vector_element_size( bool_vector )") + _assign = ResdataPrototype("void bool_vector_set_all( bool_vector , bool)") + _memcpy = ResdataPrototype("void bool_vector_memcpy(bool_vector , bool_vector )") + _set_default = ResdataPrototype( + "void bool_vector_set_default( bool_vector , bool)" + ) + _get_default = ResdataPrototype("bool bool_vector_get_default( bool_vector )") + _element_size = ResdataPrototype("int bool_vector_element_size( bool_vector )") - _permute = EclPrototype("void bool_vector_permute(bool_vector, permutation_vector)") - _sort_perm = EclPrototype( + _permute = ResdataPrototype( + "void bool_vector_permute(bool_vector, permutation_vector)" + ) + _sort_perm = ResdataPrototype( "permutation_vector_obj bool_vector_alloc_sort_perm(bool_vector)" ) - _rsort_perm = EclPrototype( + _rsort_perm = ResdataPrototype( "permutation_vector_obj bool_vector_alloc_rsort_perm(bool_vector)" ) - _contains = EclPrototype("bool bool_vector_contains(bool_vector, bool)") - _select_unique = EclPrototype("void bool_vector_select_unique(bool_vector)") - _element_sum = EclPrototype("bool bool_vector_sum(bool_vector)") - _get_data_ptr = EclPrototype("bool* bool_vector_get_ptr(bool_vector)") - _count_equal = EclPrototype("int bool_vector_count_equal(bool_vector, bool)") + _contains = ResdataPrototype("bool bool_vector_contains(bool_vector, bool)") + _select_unique = ResdataPrototype("void bool_vector_select_unique(bool_vector)") + _element_sum = ResdataPrototype("bool bool_vector_sum(bool_vector)") + _get_data_ptr = ResdataPrototype("bool* bool_vector_get_ptr(bool_vector)") + _count_equal = ResdataPrototype("int bool_vector_count_equal(bool_vector, bool)") _init_linear = None - _equal = EclPrototype("bool bool_vector_equal(bool_vector, bool_vector)") - _first_eq = EclPrototype( + _equal = ResdataPrototype("bool bool_vector_equal(bool_vector, bool_vector)") + _first_eq = ResdataPrototype( "int bool_vector_first_equal(bool_vector, bool_vector, int)" ) - _first_neq = EclPrototype( + _first_neq = ResdataPrototype( "int bool_vector_first_not_equal(bool_vector, bool_vector, int)" ) @@ -138,7 +144,7 @@ def createFromList(cls, size, source_list): return bool_vector def createActiveList(self): - """@rtype: ecl.util.IntVector""" + """@rtype: resdata.util.IntVector""" return self._active_list() def _tostr(self, arr=None): diff --git a/python/ecl/util/util/cthread_pool.py b/python/resdata/util/util/cthread_pool.py similarity index 82% rename from python/ecl/util/util/cthread_pool.py rename to python/resdata/util/util/cthread_pool.py index ec846cf6df..e3aaac6768 100644 --- a/python/ecl/util/util/cthread_pool.py +++ b/python/resdata/util/util/cthread_pool.py @@ -1,7 +1,7 @@ import ctypes from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype import weakref @@ -9,10 +9,10 @@ class CThreadPool(BaseCClass): TYPE_NAME = "thread_pool" - _alloc = EclPrototype("void* thread_pool_alloc(int, bool)", bind=False) - _free = EclPrototype("void thread_pool_free(thread_pool)") - _add_job = EclPrototype("void thread_pool_add_job(thread_pool, void*, void*)") - _join = EclPrototype("void thread_pool_join(thread_pool)") + _alloc = ResdataPrototype("void* thread_pool_alloc(int, bool)", bind=False) + _free = ResdataPrototype("void thread_pool_free(thread_pool)") + _add_job = ResdataPrototype("void thread_pool_add_job(thread_pool, void*, void*)") + _join = ResdataPrototype("void thread_pool_join(thread_pool)") def __init__(self, pool_size, start=True): c_ptr = self._alloc(pool_size, start) diff --git a/python/ecl/util/util/ctime.py b/python/resdata/util/util/ctime.py similarity index 96% rename from python/ecl/util/util/ctime.py rename to python/resdata/util/util/ctime.py index 1500c3247a..53037b1b17 100644 --- a/python/ecl/util/util/ctime.py +++ b/python/resdata/util/util/ctime.py @@ -3,14 +3,14 @@ import time from cwrap import BaseCValue -from ecl import EclPrototype +from resdata import ResdataPrototype class CTime(BaseCValue): TYPE_NAME = "time_t" DATA_TYPE = ctypes.c_long - _timezone = EclPrototype("char* util_get_timezone()", bind=False) - _timegm = EclPrototype( + _timezone = ResdataPrototype("char* util_get_timezone()", bind=False) + _timegm = ResdataPrototype( "long util_make_datetime_utc(int, int, int, int, int, int)", bind=False ) diff --git a/python/ecl/util/util/cwd_context.py b/python/resdata/util/util/cwd_context.py similarity index 100% rename from python/ecl/util/util/cwd_context.py rename to python/resdata/util/util/cwd_context.py diff --git a/python/resdata/util/util/double_vector.py b/python/resdata/util/util/double_vector.py new file mode 100644 index 0000000000..c027bfb950 --- /dev/null +++ b/python/resdata/util/util/double_vector.py @@ -0,0 +1,105 @@ +from resdata import ResdataPrototype +from resdata.util.util import VectorTemplate + + +class DoubleVector(VectorTemplate): + default_format = "%8.4f" + + _alloc = ResdataPrototype("void* double_vector_alloc( int , double )", bind=False) + _alloc_copy = ResdataPrototype( + "double_vector_obj double_vector_alloc_copy( double_vector )" + ) + _strided_copy = ResdataPrototype( + "double_vector_obj double_vector_alloc_strided_copy( double_vector , int , int , int)" + ) + _free = ResdataPrototype("void double_vector_free( double_vector )") + _iget = ResdataPrototype("double double_vector_iget( double_vector , int )") + _safe_iget = ResdataPrototype( + "double double_vector_safe_iget(double_vector , int )" + ) + _iset = ResdataPrototype("double double_vector_iset( double_vector , int , double)") + _size = ResdataPrototype("int double_vector_size( double_vector )") + _append = ResdataPrototype("void double_vector_append( double_vector , double )") + _idel_block = ResdataPrototype( + "void double_vector_idel_block( double_vector , int , int )" + ) + _pop = ResdataPrototype("double double_vector_pop( double_vector )") + _idel = ResdataPrototype("void double_vector_idel( double_vector , int )") + _lshift = ResdataPrototype("void double_vector_lshift( double_vector , int )") + _rshift = ResdataPrototype("void double_vector_rshift( double_vector , int )") + _insert = ResdataPrototype( + "void double_vector_insert( double_vector , int , double)" + ) + _fprintf = ResdataPrototype( + "void double_vector_fprintf( double_vector , FILE , char* , char*)" + ) + _sort = ResdataPrototype("void double_vector_sort( double_vector )") + _rsort = ResdataPrototype("void double_vector_rsort( double_vector )") + _reset = ResdataPrototype("void double_vector_reset( double_vector )") + _get_read_only = ResdataPrototype( + "bool double_vector_get_read_only( double_vector )" + ) + _set_read_only = ResdataPrototype( + "void double_vector_set_read_only( double_vector , bool )" + ) + _get_max = ResdataPrototype("double double_vector_get_max( double_vector )") + _get_min = ResdataPrototype("double double_vector_get_min( double_vector )") + _get_max_index = ResdataPrototype( + "int double_vector_get_max_index( double_vector , bool)" + ) + _get_min_index = ResdataPrototype( + "int double_vector_get_min_index( double_vector , bool)" + ) + _shift = ResdataPrototype("void double_vector_shift( double_vector , double )") + _scale = ResdataPrototype("void double_vector_scale( double_vector , double )") + _div = ResdataPrototype("void double_vector_div( double_vector , double )") + _inplace_add = ResdataPrototype( + "void double_vector_inplace_add( double_vector , double_vector )" + ) + _inplace_mul = ResdataPrototype( + "void double_vector_inplace_mul( double_vector , double_vector )" + ) + _assign = ResdataPrototype("void double_vector_set_all( double_vector , double)") + _memcpy = ResdataPrototype( + "void double_vector_memcpy(double_vector , double_vector )" + ) + _set_default = ResdataPrototype( + "void double_vector_set_default( double_vector , double)" + ) + _get_default = ResdataPrototype("double double_vector_get_default( double_vector )") + _element_size = ResdataPrototype( + "int double_vector_element_size( double_vector )" + ) + + _permute = ResdataPrototype( + "void double_vector_permute(double_vector, permutation_vector)" + ) + _sort_perm = ResdataPrototype( + "permutation_vector_obj double_vector_alloc_sort_perm(double_vector)" + ) + _rsort_perm = ResdataPrototype( + "permutation_vector_obj double_vector_alloc_rsort_perm(double_vector)" + ) + _contains = ResdataPrototype("bool double_vector_contains(double_vector, double)") + _select_unique = ResdataPrototype("void double_vector_select_unique(double_vector)") + _element_sum = ResdataPrototype("double double_vector_sum(double_vector)") + _get_data_ptr = ResdataPrototype("double* double_vector_get_ptr(double_vector)") + _count_equal = ResdataPrototype( + "int double_vector_count_equal(double_vector, double)" + ) + _init_range = ResdataPrototype( + "void double_vector_init_range(double_vector, double , double , double)" + ) + _init_linear = ResdataPrototype( + "bool double_vector_init_linear(double_vector, double, double, int)" + ) + _equal = ResdataPrototype("bool double_vector_equal(double_vector, double_vector)") + _first_eq = ResdataPrototype( + "int double_vector_first_equal(double_vector, double_vector, int)" + ) + _first_neq = ResdataPrototype( + "int double_vector_first_not_equal(double_vector, double_vector, int)" + ) + + def __init__(self, default_value=0, initial_size=0): + super(DoubleVector, self).__init__(default_value, initial_size) diff --git a/python/ecl/util/util/hash.py b/python/resdata/util/util/hash.py similarity index 72% rename from python/ecl/util/util/hash.py rename to python/resdata/util/util/hash.py index b0f78a3093..3f2a5509f7 100644 --- a/python/ecl/util/util/hash.py +++ b/python/resdata/util/util/hash.py @@ -1,18 +1,18 @@ from ctypes import c_void_p from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.util.util import StringList +from resdata import ResdataPrototype +from resdata.util.util import StringList class Hash(BaseCClass): - _alloc = EclPrototype("void* hash_alloc()", bind=False) - _free = EclPrototype("void hash_free(hash)") - _size = EclPrototype("int hash_get_size(hash)") - _keys = EclPrototype("stringlist_obj hash_alloc_stringlist(hash)") - _has_key = EclPrototype("bool hash_has_key(hash, char*)") - _get = EclPrototype("void* hash_get(hash, char*)") - _insert_ref = EclPrototype("void hash_insert_ref(hash, char*, void*)") + _alloc = ResdataPrototype("void* hash_alloc()", bind=False) + _free = ResdataPrototype("void hash_free(hash)") + _size = ResdataPrototype("int hash_get_size(hash)") + _keys = ResdataPrototype("stringlist_obj hash_alloc_stringlist(hash)") + _has_key = ResdataPrototype("bool hash_has_key(hash, char*)") + _get = ResdataPrototype("void* hash_get(hash, char*)") + _insert_ref = ResdataPrototype("void hash_insert_ref(hash, char*, void*)") """ Base hash class that supports string:void* values @@ -57,8 +57,8 @@ def __str__(self): class StringHash(Hash): - _get_string = EclPrototype("char* hash_get_string(hash, char*)") - _insert_string = EclPrototype("void hash_insert_string(hash, char*, char*)") + _get_string = ResdataPrototype("char* hash_get_string(hash, char*)") + _insert_string = ResdataPrototype("void hash_insert_string(hash, char*, char*)") def __init__(self): super(StringHash, self).__init__() @@ -77,8 +77,8 @@ def __getitem__(self, key): class IntegerHash(Hash): - _get_int = EclPrototype("int hash_get_int(hash, char*)") - _insert_int = EclPrototype("void hash_insert_int(hash, char*, int)") + _get_int = ResdataPrototype("int hash_get_int(hash, char*)") + _insert_int = ResdataPrototype("void hash_insert_int(hash, char*, int)") def __init__(self): super(IntegerHash, self).__init__() @@ -97,8 +97,8 @@ def __getitem__(self, key): class DoubleHash(Hash): - _get_double = EclPrototype("double hash_get_double(hash, char*)") - _insert_double = EclPrototype("void hash_insert_double(hash, char*, double)") + _get_double = ResdataPrototype("double hash_get_double(hash, char*)") + _insert_double = ResdataPrototype("void hash_insert_double(hash, char*, double)") def __init__(self): super(DoubleHash, self).__init__() diff --git a/python/resdata/util/util/install_abort_signals.py b/python/resdata/util/util/install_abort_signals.py new file mode 100644 index 0000000000..56439e8708 --- /dev/null +++ b/python/resdata/util/util/install_abort_signals.py @@ -0,0 +1,18 @@ +from resdata import ResdataPrototype +import sys +import os + + +def installAbortSignals(): + if sys.version_info.major < 3 and not os.getenv("RD_SKIP_SIGNAL"): + install_signals = ResdataPrototype("void util_install_signals()") + install_signals() + + +def updateAbortSignals(): + """ + Will install the util_abort_signal for all UNMODIFIED signals. + """ + if sys.version_info.major < 3 and not os.getenv("RD_SKIP_SIGNAL"): + update_signals = ResdataPrototype("void util_update_signals()") + update_signals() diff --git a/python/resdata/util/util/int_vector.py b/python/resdata/util/util/int_vector.py new file mode 100644 index 0000000000..666e2a5bc5 --- /dev/null +++ b/python/resdata/util/util/int_vector.py @@ -0,0 +1,130 @@ +from resdata import ResdataPrototype +from resdata.util.util import VectorTemplate + + +class IntVector(VectorTemplate): + default_format = "%d" + + _alloc = ResdataPrototype("void* int_vector_alloc( int , int )", bind=False) + _create_active_list = ResdataPrototype( + "int_vector_obj string_util_alloc_active_list( char*)", bind=False + ) + _create_value_list = ResdataPrototype( + "int_vector_obj string_util_alloc_value_list( char*)", bind=False + ) + _alloc_copy = ResdataPrototype("int_vector_obj int_vector_alloc_copy( int_vector )") + _strided_copy = ResdataPrototype( + "int_vector_obj int_vector_alloc_strided_copy( int_vector , int , int , int)" + ) + _free = ResdataPrototype("void int_vector_free( int_vector )") + _iget = ResdataPrototype("int int_vector_iget( int_vector , int )") + _safe_iget = ResdataPrototype("int int_vector_safe_iget( int_vector , int )") + _iset = ResdataPrototype("int int_vector_iset( int_vector , int , int)") + _size = ResdataPrototype("int int_vector_size( int_vector )") + _append = ResdataPrototype("void int_vector_append( int_vector , int )") + _idel_block = ResdataPrototype( + "void int_vector_idel_block( int_vector , int , int )" + ) + _pop = ResdataPrototype("int int_vector_pop( int_vector )") + _idel = ResdataPrototype("void int_vector_idel( int_vector , int )") + _insert = ResdataPrototype("void int_vector_insert( int_vector , int , int)") + _lshift = ResdataPrototype("void int_vector_lshift( int_vector , int )") + _rshift = ResdataPrototype("void int_vector_rshift( int_vector , int )") + _fprintf = ResdataPrototype( + "void int_vector_fprintf( int_vector , FILE , char* , char*)" + ) + _sort = ResdataPrototype("void int_vector_sort( int_vector )") + _rsort = ResdataPrototype("void int_vector_rsort( int_vector )") + _reset = ResdataPrototype("void int_vector_reset( int_vector )") + _set_read_only = ResdataPrototype( + "void int_vector_set_read_only( int_vector , bool )" + ) + _get_read_only = ResdataPrototype("bool int_vector_get_read_only( int_vector )") + _get_max = ResdataPrototype("int int_vector_get_max( int_vector )") + _get_min = ResdataPrototype("int int_vector_get_min( int_vector )") + _get_max_index = ResdataPrototype( + "int int_vector_get_max_index( int_vector , bool)" + ) + _get_min_index = ResdataPrototype( + "int int_vector_get_min_index( int_vector , bool)" + ) + _shift = ResdataPrototype("void int_vector_shift( int_vector , int )") + _scale = ResdataPrototype("void int_vector_scale( int_vector , int )") + _div = ResdataPrototype("void int_vector_div( int_vector , int )") + _inplace_add = ResdataPrototype( + "void int_vector_inplace_add( int_vector , int_vector )" + ) + _inplace_mul = ResdataPrototype( + "void int_vector_inplace_mul( int_vector , int_vector )" + ) + _assign = ResdataPrototype("void int_vector_set_all( int_vector , int)") + _memcpy = ResdataPrototype("void int_vector_memcpy(int_vector , int_vector )") + _set_default = ResdataPrototype("void int_vector_set_default( int_vector , int)") + _get_default = ResdataPrototype("int int_vector_get_default( int_vector )") + _element_size = ResdataPrototype("int int_vector_element_size( int_vector )") + + _permute = ResdataPrototype( + "void int_vector_permute(int_vector, permutation_vector)" + ) + _sort_perm = ResdataPrototype( + "permutation_vector_obj int_vector_alloc_sort_perm(int_vector)" + ) + _rsort_perm = ResdataPrototype( + "permutation_vector_obj int_vector_alloc_rsort_perm(int_vector)" + ) + _contains = ResdataPrototype("bool int_vector_contains(int_vector, int)") + _select_unique = ResdataPrototype("void int_vector_select_unique(int_vector)") + _element_sum = ResdataPrototype("int int_vector_sum(int_vector)") + _get_data_ptr = ResdataPrototype("int* int_vector_get_ptr(int_vector)") + _count_equal = ResdataPrototype("int int_vector_count_equal(int_vector, int)") + _init_range = ResdataPrototype( + "void int_vector_init_range(int_vector, int , int , int)" + ) + _init_linear = ResdataPrototype( + "bool int_vector_init_linear(int_vector, int, int, int)" + ) + _equal = ResdataPrototype("bool int_vector_equal(int_vector, int_vector)") + _first_eq = ResdataPrototype( + "int int_vector_first_equal(int_vector, int_vector, int)" + ) + _first_neq = ResdataPrototype( + "int int_vector_first_not_equal(int_vector, int_vector, int)" + ) + + def __init__(self, default_value=0, initial_size=0): + super(IntVector, self).__init__(default_value, initial_size) + + @classmethod + def active_list(cls, range_string): + """Will create a IntVector instance with the values from @range_string. + + The range_string input should be of the type "1,3-5,9,17", + i.e. integer values separated by commas, and dashes to + represent ranges. If the input string contains ANY invalid + characters the returned active list will be empty: + + "1,4-7,10" => {1,4,5,6,7,10} + "1,4-7,10X" => {} + + The empty list will evaluate to false. The values in the input + string are meant to indicate "active values", i.e. the output + values are sorted and repeated values are only counted once: + + "1,1,7,2" => {1,2,7} + + """ + return cls._create_active_list(range_string) + + @classmethod + def valueList(cls, range_string): + """Will create a IntVecter of all the values in the @range_string. + + Will not sort the values, and not uniquiefy - in contrast to + the active_list() method. + + """ + return cls._create_value_list(range_string) + + def count(self, value): + """@rtype: int""" + return self._count_equal(value) diff --git a/python/ecl/util/util/lookup_table.py b/python/resdata/util/util/lookup_table.py similarity index 69% rename from python/ecl/util/util/lookup_table.py rename to python/resdata/util/util/lookup_table.py index 61ce2d72be..65e8292c9a 100644 --- a/python/ecl/util/util/lookup_table.py +++ b/python/resdata/util/util/lookup_table.py @@ -1,25 +1,29 @@ from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype class LookupTable(BaseCClass): - _alloc = EclPrototype("void* lookup_table_alloc_empty()", bind=False) - _max = EclPrototype("double lookup_table_get_max_value( lookup_table )") - _min = EclPrototype("double lookup_table_get_min_value( lookup_table )") - _arg_max = EclPrototype("double lookup_table_get_max_arg( lookup_table )") - _arg_min = EclPrototype("double lookup_table_get_min_arg( lookup_table )") - _append = EclPrototype("void lookup_table_append( lookup_table , double , double )") - _size = EclPrototype("int lookup_table_get_size( lookup_table )") - _interp = EclPrototype("double lookup_table_interp( lookup_table , double)") - _free = EclPrototype("void lookup_table_free( lookup_table )") - _set_low_limit = EclPrototype( + _alloc = ResdataPrototype("void* lookup_table_alloc_empty()", bind=False) + _max = ResdataPrototype("double lookup_table_get_max_value( lookup_table )") + _min = ResdataPrototype("double lookup_table_get_min_value( lookup_table )") + _arg_max = ResdataPrototype("double lookup_table_get_max_arg( lookup_table )") + _arg_min = ResdataPrototype("double lookup_table_get_min_arg( lookup_table )") + _append = ResdataPrototype( + "void lookup_table_append( lookup_table , double , double )" + ) + _size = ResdataPrototype("int lookup_table_get_size( lookup_table )") + _interp = ResdataPrototype("double lookup_table_interp( lookup_table , double)") + _free = ResdataPrototype("void lookup_table_free( lookup_table )") + _set_low_limit = ResdataPrototype( "void lookup_table_set_low_limit( lookup_table , double)" ) - _set_high_limit = EclPrototype( + _set_high_limit = ResdataPrototype( "void lookup_table_set_high_limit( lookup_table , double)" ) - _has_low_limit = EclPrototype("bool lookup_table_has_low_limit( lookup_table)") - _has_high_limit = EclPrototype("bool lookup_table_has_high_limit( lookup_table)") + _has_low_limit = ResdataPrototype("bool lookup_table_has_low_limit( lookup_table)") + _has_high_limit = ResdataPrototype( + "bool lookup_table_has_high_limit( lookup_table)" + ) def __init__(self, lower_limit=None, upper_limit=None): super(LookupTable, self).__init__(self._alloc()) diff --git a/python/ecl/util/util/permutation_vector.py b/python/resdata/util/util/permutation_vector.py similarity index 71% rename from python/ecl/util/util/permutation_vector.py rename to python/resdata/util/util/permutation_vector.py index 60ae241d2c..16016a47d9 100644 --- a/python/ecl/util/util/permutation_vector.py +++ b/python/resdata/util/util/permutation_vector.py @@ -1,12 +1,12 @@ from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype class PermutationVector(BaseCClass): TYPE_NAME = "permutation_vector" - _free = EclPrototype("void perm_vector_free( permutation_vector )") - _size = EclPrototype("int perm_vector_get_size( permutation_vector )") - _iget = EclPrototype("int perm_vector_iget( permutation_vector , int)") + _free = ResdataPrototype("void perm_vector_free( permutation_vector )") + _size = ResdataPrototype("int perm_vector_get_size( permutation_vector )") + _iget = ResdataPrototype("int perm_vector_iget( permutation_vector , int)") def __init__(self): raise NotImplementedError("Can not instantiate PermutationVector directly") diff --git a/python/ecl/util/util/rng.py b/python/resdata/util/util/rng.py similarity index 69% rename from python/ecl/util/util/rng.py rename to python/resdata/util/util/rng.py index 09933522d2..426568f5fd 100644 --- a/python/ecl/util/util/rng.py +++ b/python/resdata/util/util/rng.py @@ -1,25 +1,25 @@ import os.path from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.util.enums import RngInitModeEnum, RngAlgTypeEnum +from resdata import ResdataPrototype +from resdata.util.enums import RngInitModeEnum, RngAlgTypeEnum class RandomNumberGenerator(BaseCClass): TYPE_NAME = "rng" - _rng_alloc = EclPrototype( + _rng_alloc = ResdataPrototype( "void* rng_alloc(rng_alg_type_enum, rng_init_mode_enum)", bind=False ) - _free = EclPrototype("void rng_free(rng)") - _get_double = EclPrototype("double rng_get_double(rng)") - _get_int = EclPrototype("int rng_get_int(rng, int)") - _forward = EclPrototype("uint rng_forward(rng)") - _get_max_int = EclPrototype("uint rng_get_max_int(rng)") - _state_size = EclPrototype("int rng_state_size(rng)") - _set_state = EclPrototype("void rng_set_state(rng , char*)") - _load_state = EclPrototype("void rng_load_state(rng , char*)") - _save_state = EclPrototype("void rng_save_state(rng , char*)") + _free = ResdataPrototype("void rng_free(rng)") + _get_double = ResdataPrototype("double rng_get_double(rng)") + _get_int = ResdataPrototype("int rng_get_int(rng, int)") + _forward = ResdataPrototype("uint rng_forward(rng)") + _get_max_int = ResdataPrototype("uint rng_get_max_int(rng)") + _state_size = ResdataPrototype("int rng_state_size(rng)") + _set_state = ResdataPrototype("void rng_set_state(rng , char*)") + _load_state = ResdataPrototype("void rng_load_state(rng , char*)") + _save_state = ResdataPrototype("void rng_save_state(rng , char*)") def __init__( self, alg_type=RngAlgTypeEnum.MZRAN, init_mode=RngInitModeEnum.INIT_CLOCK diff --git a/python/ecl/util/util/stringlist.py b/python/resdata/util/util/stringlist.py similarity index 87% rename from python/ecl/util/util/stringlist.py rename to python/resdata/util/util/stringlist.py index 5130c98097..91cf383ee0 100644 --- a/python/ecl/util/util/stringlist.py +++ b/python/resdata/util/util/stringlist.py @@ -15,28 +15,28 @@ return a normal python list of string objects, used in this way you hardly need to notice that the StringList class is at play. """ -from ecl import EclPrototype +from resdata import ResdataPrototype from cwrap import BaseCClass class StringList(BaseCClass): TYPE_NAME = "stringlist" - _alloc = EclPrototype("void* stringlist_alloc_new( )", bind=False) - _free = EclPrototype("void stringlist_free(stringlist )") - _append = EclPrototype("void stringlist_append_copy(stringlist , char* )") - _iget = EclPrototype("char* stringlist_iget(stringlist , int )") - _front = EclPrototype("char* stringlist_front( stringlist )") - _back = EclPrototype("char* stringlist_back( stringlist )") - _iget_copy = EclPrototype("char* stringlist_iget_copy(stringlist, int)") - _iset = EclPrototype("void stringlist_iset_copy( stringlist , int , char* )") - _get_size = EclPrototype("int stringlist_get_size( stringlist )") - _contains = EclPrototype("bool stringlist_contains(stringlist , char*)") - _equal = EclPrototype("bool stringlist_equal(stringlist , stringlist)") - _sort = EclPrototype("void stringlist_python_sort( stringlist , int)") - _pop = EclPrototype("char* stringlist_pop(stringlist)") - _last = EclPrototype("char* stringlist_get_last(stringlist)") - _find_first = EclPrototype("int stringlist_find_first(stringlist, char*)") + _alloc = ResdataPrototype("void* stringlist_alloc_new( )", bind=False) + _free = ResdataPrototype("void stringlist_free(stringlist )") + _append = ResdataPrototype("void stringlist_append_copy(stringlist , char* )") + _iget = ResdataPrototype("char* stringlist_iget(stringlist , int )") + _front = ResdataPrototype("char* stringlist_front( stringlist )") + _back = ResdataPrototype("char* stringlist_back( stringlist )") + _iget_copy = ResdataPrototype("char* stringlist_iget_copy(stringlist, int)") + _iset = ResdataPrototype("void stringlist_iset_copy( stringlist , int , char* )") + _get_size = ResdataPrototype("int stringlist_get_size( stringlist )") + _contains = ResdataPrototype("bool stringlist_contains(stringlist , char*)") + _equal = ResdataPrototype("bool stringlist_equal(stringlist , stringlist)") + _sort = ResdataPrototype("void stringlist_python_sort( stringlist , int)") + _pop = ResdataPrototype("char* stringlist_pop(stringlist)") + _last = ResdataPrototype("char* stringlist_get_last(stringlist)") + _find_first = ResdataPrototype("int stringlist_find_first(stringlist, char*)") def __init__(self, initial=None): """ diff --git a/python/ecl/util/util/thread_pool.py b/python/resdata/util/util/thread_pool.py similarity index 100% rename from python/ecl/util/util/thread_pool.py rename to python/resdata/util/util/thread_pool.py diff --git a/python/ecl/util/util/time_vector.py b/python/resdata/util/util/time_vector.py similarity index 63% rename from python/ecl/util/util/time_vector.py rename to python/resdata/util/util/time_vector.py index c8eb09084b..7109932dce 100644 --- a/python/ecl/util/util/time_vector.py +++ b/python/resdata/util/util/time_vector.py @@ -1,100 +1,114 @@ import datetime import re -from ecl import EclPrototype -from ecl.util.util import VectorTemplate, CTime +from resdata import ResdataPrototype +from resdata.util.util import VectorTemplate, CTime class TimeVector(VectorTemplate): TYPE_NAME = "time_t_vector" default_format = "%d" - _alloc = EclPrototype("void* time_t_vector_alloc(int, time_t )", bind=False) - _alloc_copy = EclPrototype( + _alloc = ResdataPrototype("void* time_t_vector_alloc(int, time_t )", bind=False) + _alloc_copy = ResdataPrototype( "time_t_vector_obj time_t_vector_alloc_copy(time_t_vector )" ) - _strided_copy = EclPrototype( + _strided_copy = ResdataPrototype( "time_t_vector_obj time_t_vector_alloc_strided_copy(time_t_vector , int , int , int)" ) - _free = EclPrototype("void time_t_vector_free( time_t_vector )") - _iget = EclPrototype("time_t time_t_vector_iget( time_t_vector , int )") - _safe_iget = EclPrototype("time_t time_t_vector_safe_iget( time_t_vector , int )") - _iset = EclPrototype("time_t time_t_vector_iset( time_t_vector , int , time_t)") - _size = EclPrototype("int time_t_vector_size( time_t_vector )") - _append = EclPrototype("void time_t_vector_append( time_t_vector , time_t )") - _idel_block = EclPrototype( + _free = ResdataPrototype("void time_t_vector_free( time_t_vector )") + _iget = ResdataPrototype("time_t time_t_vector_iget( time_t_vector , int )") + _safe_iget = ResdataPrototype( + "time_t time_t_vector_safe_iget( time_t_vector , int )" + ) + _iset = ResdataPrototype( + "time_t time_t_vector_iset( time_t_vector , int , time_t)" + ) + _size = ResdataPrototype("int time_t_vector_size( time_t_vector )") + _append = ResdataPrototype( + "void time_t_vector_append( time_t_vector , time_t )" + ) + _idel_block = ResdataPrototype( "void time_t_vector_idel_block( time_t_vector , int , int )" ) - _idel = EclPrototype("void time_t_vector_idel( time_t_vector , int )") - _pop = EclPrototype("time_t time_t_vector_pop( time_t_vector )") - _lshift = EclPrototype("void time_t_vector_lshift( time_t_vector , int )") - _rshift = EclPrototype("void time_t_vector_rshift( time_t_vector , int )") - _insert = EclPrototype( + _idel = ResdataPrototype("void time_t_vector_idel( time_t_vector , int )") + _pop = ResdataPrototype("time_t time_t_vector_pop( time_t_vector )") + _lshift = ResdataPrototype("void time_t_vector_lshift( time_t_vector , int )") + _rshift = ResdataPrototype("void time_t_vector_rshift( time_t_vector , int )") + _insert = ResdataPrototype( "void time_t_vector_insert( time_t_vector , int , time_t)" ) - _fprintf = EclPrototype( + _fprintf = ResdataPrototype( "void time_t_vector_fprintf( time_t_vector , FILE , char* , char*)" ) - _sort = EclPrototype("void time_t_vector_sort( time_t_vector )") - _rsort = EclPrototype("void time_t_vector_rsort( time_t_vector )") - _reset = EclPrototype("void time_t_vector_reset( time_t_vector )") - _set_read_only = EclPrototype( + _sort = ResdataPrototype("void time_t_vector_sort( time_t_vector )") + _rsort = ResdataPrototype("void time_t_vector_rsort( time_t_vector )") + _reset = ResdataPrototype("void time_t_vector_reset( time_t_vector )") + _set_read_only = ResdataPrototype( "void time_t_vector_set_read_only( time_t_vector , bool )" ) - _get_read_only = EclPrototype( + _get_read_only = ResdataPrototype( "bool time_t_vector_get_read_only( time_t_vector )" ) - _get_max = EclPrototype("time_t time_t_vector_get_max( time_t_vector )") - _get_min = EclPrototype("time_t time_t_vector_get_min( time_t_vector )") - _get_max_index = EclPrototype( + _get_max = ResdataPrototype("time_t time_t_vector_get_max( time_t_vector )") + _get_min = ResdataPrototype("time_t time_t_vector_get_min( time_t_vector )") + _get_max_index = ResdataPrototype( "int time_t_vector_get_max_index( time_t_vector , bool)" ) - _get_min_index = EclPrototype( + _get_min_index = ResdataPrototype( "int time_t_vector_get_min_index( time_t_vector , bool)" ) - _shift = EclPrototype("void time_t_vector_shift( time_t_vector , time_t )") - _scale = EclPrototype("void time_t_vector_scale( time_t_vector , time_t )") - _div = EclPrototype("void time_t_vector_div( time_t_vector , time_t )") - _inplace_add = EclPrototype( + _shift = ResdataPrototype("void time_t_vector_shift( time_t_vector , time_t )") + _scale = ResdataPrototype("void time_t_vector_scale( time_t_vector , time_t )") + _div = ResdataPrototype("void time_t_vector_div( time_t_vector , time_t )") + _inplace_add = ResdataPrototype( "void time_t_vector_inplace_add( time_t_vector , time_t_vector )" ) - _inplace_mul = EclPrototype( + _inplace_mul = ResdataPrototype( "void time_t_vector_inplace_mul( time_t_vector , time_t_vector )" ) - _assign = EclPrototype("void time_t_vector_set_all( time_t_vector , time_t)") - _memcpy = EclPrototype( + _assign = ResdataPrototype( + "void time_t_vector_set_all( time_t_vector , time_t)" + ) + _memcpy = ResdataPrototype( "void time_t_vector_memcpy(time_t_vector , time_t_vector )" ) - _set_default = EclPrototype( + _set_default = ResdataPrototype( "void time_t_vector_set_default( time_t_vector , time_t)" ) - _get_default = EclPrototype("time_t time_t_vector_get_default( time_t_vector )") - _element_size = EclPrototype("int time_t_vector_element_size( time_t_vector )") + _get_default = ResdataPrototype( + "time_t time_t_vector_get_default( time_t_vector )" + ) + _element_size = ResdataPrototype( + "int time_t_vector_element_size( time_t_vector )" + ) - _permute = EclPrototype( + _permute = ResdataPrototype( "void time_t_vector_permute(time_t_vector, permutation_vector)" ) - _sort_perm = EclPrototype( + _sort_perm = ResdataPrototype( "permutation_vector_obj time_t_vector_alloc_sort_perm(time_t_vector)" ) - _rsort_perm = EclPrototype( + _rsort_perm = ResdataPrototype( "permutation_vector_obj time_t_vector_alloc_rsort_perm(time_t_vector)" ) - _contains = EclPrototype("bool time_t_vector_contains(time_t_vector, time_t)") - _select_unique = EclPrototype("void time_t_vector_select_unique(time_t_vector)") - _element_sum = EclPrototype("time_t time_t_vector_sum(time_t_vector)") - _count_equal = EclPrototype("int time_t_vector_count_equal(time_t_vector, time_t)") - _init_range = EclPrototype( + _contains = ResdataPrototype("bool time_t_vector_contains(time_t_vector, time_t)") + _select_unique = ResdataPrototype("void time_t_vector_select_unique(time_t_vector)") + _element_sum = ResdataPrototype("time_t time_t_vector_sum(time_t_vector)") + _count_equal = ResdataPrototype( + "int time_t_vector_count_equal(time_t_vector, time_t)" + ) + _init_range = ResdataPrototype( "void time_t_vector_init_range(time_t_vector, time_t , time_t , time_t)" ) - _init_linear = EclPrototype( + _init_linear = ResdataPrototype( "bool time_t_vector_init_linear(time_t_vector, time_t, time_t, int)" ) - _equal = EclPrototype("bool time_t_vector_equal(time_t_vector, time_t_vector)") - _first_eq = EclPrototype( + _equal = ResdataPrototype("bool time_t_vector_equal(time_t_vector, time_t_vector)") + _first_eq = ResdataPrototype( "int time_t_vector_first_equal(time_t_vector, time_t_vector, int)" ) - _first_neq = EclPrototype( + _first_neq = ResdataPrototype( "int time_t_vector_first_not_equal(time_t_vector, time_t_vector, int)" ) diff --git a/python/ecl/util/util/util_func.py b/python/resdata/util/util/util_func.py similarity index 84% rename from python/ecl/util/util/util_func.py rename to python/resdata/util/util/util_func.py index 8094ef6006..8af0ff2cd9 100644 --- a/python/ecl/util/util/util_func.py +++ b/python/resdata/util/util/util_func.py @@ -2,9 +2,9 @@ Module with utility functions from util.c """ -from ecl import EclPrototype +from resdata import ResdataPrototype -strcmp_int = EclPrototype("int util_strcmp_int( char* , char* )") +strcmp_int = ResdataPrototype("int util_strcmp_int( char* , char* )") """ Function to compare strings with embedded integers. @@ -30,7 +30,7 @@ @type: (str, str) -> int """ -strcmp_float = EclPrototype("int util_strcmp_float( char* , char* )") +strcmp_float = ResdataPrototype("int util_strcmp_float( char* , char* )") """ Function to compare strings with embedded numbers. diff --git a/python/ecl/util/util/vector_template.py b/python/resdata/util/util/vector_template.py similarity index 99% rename from python/ecl/util/util/vector_template.py rename to python/resdata/util/util/vector_template.py index f9a004c3e6..a519f1f1d8 100644 --- a/python/ecl/util/util/vector_template.py +++ b/python/resdata/util/util/vector_template.py @@ -154,7 +154,7 @@ def str_data(self, width, index1, index2, fmt): return s # The str() method is a verbatim copy of the implementation in - # ecl_kw.py. + # rd_kw.py. def str(self, width=5, max_lines=10, fmt=None): """ Return string representation of vector for pretty printing. diff --git a/python/ecl/util/util/version.py b/python/resdata/util/util/version.py similarity index 77% rename from python/ecl/util/util/version.py rename to python/resdata/util/util/version.py index 3a75b7cb0d..cd32d6e712 100644 --- a/python/ecl/util/util/version.py +++ b/python/resdata/util/util/version.py @@ -1,6 +1,6 @@ from functools import wraps -from ecl import EclPrototype +from resdata import ResdataPrototype def cmp_method(method): @@ -63,7 +63,7 @@ def __hash__(self): # All development versions are compared with micro version == -1; # i.e. the two versions version(1,2,"Alpha") and - # ecl_version(1,2,"Beta") compare as equal in the >= and <= tests - + # rd_version(1,2,"Beta") compare as equal in the >= and <= tests - # but not in the == test. @cmp_method @@ -98,13 +98,15 @@ def getGitCommit(self, short=False): return self.git_commit -class EclVersion(Version): - _build_time = EclPrototype("char* ecl_version_get_build_time()", bind=False) - _git_commit = EclPrototype("char* ecl_version_get_git_commit()", bind=False) - _major_version = EclPrototype("int ecl_version_get_major_version()", bind=False) - _minor_version = EclPrototype("int ecl_version_get_minor_version()", bind=False) - _micro_version = EclPrototype("char* ecl_version_get_micro_version()", bind=False) - _is_devel = EclPrototype("bool ecl_version_is_devel_version()", bind=False) +class ResdataVersion(Version): + _build_time = ResdataPrototype("char* rd_version_get_build_time()", bind=False) + _git_commit = ResdataPrototype("char* rd_version_get_git_commit()", bind=False) + _major_version = ResdataPrototype("int rd_version_get_major_version()", bind=False) + _minor_version = ResdataPrototype("int rd_version_get_minor_version()", bind=False) + _micro_version = ResdataPrototype( + "char* rd_version_get_micro_version()", bind=False + ) + _is_devel = ResdataPrototype("bool rd_version_is_devel_version()", bind=False) def __init__(self): major = self._major_version() @@ -112,4 +114,6 @@ def __init__(self): micro = self._micro_version() git_commit = self._git_commit() build_time = self._build_time() - super(EclVersion, self).__init__(major, minor, micro, git_commit, build_time) + super(ResdataVersion, self).__init__( + major, minor, micro, git_commit, build_time + ) diff --git a/python/ecl/well/__init__.py b/python/resdata/well/__init__.py similarity index 72% rename from python/ecl/well/__init__.py rename to python/resdata/well/__init__.py index 71a0ebd3be..6a3710037c 100644 --- a/python/ecl/well/__init__.py +++ b/python/resdata/well/__init__.py @@ -1,11 +1,11 @@ -import ecl -import ecl.util.util -import ecl.util.geometry +import resdata +import resdata.util.util +import resdata.geometry from cwrap import Prototype -from .well_type_enum import WellTypeEnum -from .well_connection_direction_enum import WellConnectionDirectionEnum +from .well_type_enum import WellType +from .well_connection_direction_enum import WellConnectionDirection from .well_connection import WellConnection from .well_segment import WellSegment from .well_state import WellState diff --git a/python/ecl/well/well_connection.py b/python/resdata/well/well_connection.py similarity index 63% rename from python/ecl/well/well_connection.py rename to python/resdata/well/well_connection.py index 67a3504a4a..648ed4af0f 100644 --- a/python/ecl/well/well_connection.py +++ b/python/resdata/well/well_connection.py @@ -1,37 +1,41 @@ from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.well import WellConnectionDirectionEnum +from resdata import ResdataPrototype +from resdata.well import WellConnectionDirection class WellConnection(BaseCClass): TYPE_NAME = "well_connection" - _i = EclPrototype("int well_conn_get_i(well_connection)") - _j = EclPrototype("int well_conn_get_j(well_connection)") - _k = EclPrototype("int well_conn_get_k(well_connection)") - _segment_id = EclPrototype("int well_conn_get_segment_id(well_connection)") - _is_open = EclPrototype("bool well_conn_open(well_connection)") - _is_msw = EclPrototype("bool well_conn_MSW(well_connection)") - _fracture_connection = EclPrototype( + _i = ResdataPrototype("int well_conn_get_i(well_connection)") + _j = ResdataPrototype("int well_conn_get_j(well_connection)") + _k = ResdataPrototype("int well_conn_get_k(well_connection)") + _segment_id = ResdataPrototype("int well_conn_get_segment_id(well_connection)") + _is_open = ResdataPrototype("bool well_conn_open(well_connection)") + _is_msw = ResdataPrototype("bool well_conn_MSW(well_connection)") + _fracture_connection = ResdataPrototype( "bool well_conn_fracture_connection(well_connection)" ) - _matrix_connection = EclPrototype( + _matrix_connection = ResdataPrototype( "bool well_conn_matrix_connection(well_connection)" ) - _connection_factor = EclPrototype( + _connection_factor = ResdataPrototype( "double well_conn_get_connection_factor(well_connection)" ) - _equal = EclPrototype("bool well_conn_equal(well_connection, well_connection)") - _get_dir = EclPrototype("void* well_conn_get_dir(well_connection)") - _oil_rate = EclPrototype("double well_conn_get_oil_rate(well_connection)") - _gas_rate = EclPrototype("double well_conn_get_gas_rate(well_connection)") - _water_rate = EclPrototype("double well_conn_get_water_rate(well_connection)") - _volume_rate = EclPrototype("double well_conn_get_volume_rate(well_connection)") - - _oil_rate_si = EclPrototype("double well_conn_get_oil_rate_si(well_connection)") - _gas_rate_si = EclPrototype("double well_conn_get_gas_rate_si(well_connection)") - _water_rate_si = EclPrototype("double well_conn_get_water_rate_si(well_connection)") - _volume_rate_si = EclPrototype( + _equal = ResdataPrototype( + "bool well_conn_equal(well_connection, well_connection)" + ) + _get_dir = ResdataPrototype("void* well_conn_get_dir(well_connection)") + _oil_rate = ResdataPrototype("double well_conn_get_oil_rate(well_connection)") + _gas_rate = ResdataPrototype("double well_conn_get_gas_rate(well_connection)") + _water_rate = ResdataPrototype("double well_conn_get_water_rate(well_connection)") + _volume_rate = ResdataPrototype("double well_conn_get_volume_rate(well_connection)") + + _oil_rate_si = ResdataPrototype("double well_conn_get_oil_rate_si(well_connection)") + _gas_rate_si = ResdataPrototype("double well_conn_get_gas_rate_si(well_connection)") + _water_rate_si = ResdataPrototype( + "double well_conn_get_water_rate_si(well_connection)" + ) + _volume_rate_si = ResdataPrototype( "double well_conn_get_volume_rate_si(well_connection)" ) @@ -50,7 +54,7 @@ def ijk(self): return i, j, k def direction(self): - """@rtype: WellConnectionDirectionEnum""" + """@rtype: WellConnectionDirection""" return self._get_dir() def segmentId(self): @@ -90,7 +94,7 @@ def __repr__(self): frac = "fracture " if self.isFractureConnection() else "" open_ = "open " if self.isOpen() else "shut " msw = " (multi segment)" if self.isMultiSegmentWell() else "" - dir = WellConnectionDirectionEnum(self.direction()) + dir = WellConnectionDirection(self.direction()) addr = self._address() return ( "WellConnection(%s %s%s%s, rates = (O:%s,G:%s,W:%s), direction = %s) at 0x%x" diff --git a/python/resdata/well/well_connection_direction_enum.py b/python/resdata/well/well_connection_direction_enum.py new file mode 100644 index 0000000000..e8ab46787e --- /dev/null +++ b/python/resdata/well/well_connection_direction_enum.py @@ -0,0 +1,17 @@ +from cwrap import BaseCEnum + + +class WellConnectionDirection(BaseCEnum): + TYPE_NAME = "well_connection_dir_enum" + well_conn_dirX = None + well_conn_dirY = None + well_conn_dirZ = None + well_conn_fracX = None + well_conn_fracY = None + + +WellConnectionDirection.addEnum("well_conn_dirX", 1) +WellConnectionDirection.addEnum("well_conn_dirY", 2) +WellConnectionDirection.addEnum("well_conn_dirZ", 3) +WellConnectionDirection.addEnum("well_conn_fracX", 4) +WellConnectionDirection.addEnum("well_conn_fracY", 5) diff --git a/python/ecl/well/well_info.py b/python/resdata/well/well_info.py similarity index 67% rename from python/ecl/well/well_info.py rename to python/resdata/well/well_info.py index 536d6c6988..115dac4168 100644 --- a/python/ecl/well/well_info.py +++ b/python/resdata/well/well_info.py @@ -1,29 +1,31 @@ from os.path import isfile from cwrap import BaseCClass -from ecl.grid import EclGrid -from ecl.eclfile.ecl_file import EclFile -from ecl.well import WellTimeLine -from ecl import EclPrototype +from resdata.grid import Grid +from resdata.resfile.rd_file import ResdataFile +from resdata.well import WellTimeLine +from resdata import ResdataPrototype class WellInfo(BaseCClass): TYPE_NAME = "well_info" - _alloc = EclPrototype("void* well_info_alloc(ecl_grid)", bind=False) - _free = EclPrototype("void well_info_free(well_info)") - _load_rstfile = EclPrototype("void well_info_load_rstfile(well_info, char*, bool)") - _load_rst_eclfile = EclPrototype( - "void well_info_load_rst_eclfile(well_info, ecl_file, bool)" + _alloc = ResdataPrototype("void* well_info_alloc(rd_grid)", bind=False) + _free = ResdataPrototype("void well_info_free(well_info)") + _load_rstfile = ResdataPrototype( + "void well_info_load_rstfile(well_info, char*, bool)" ) - _get_well_count = EclPrototype("int well_info_get_num_wells(well_info)") - _iget_well_name = EclPrototype("char* well_info_iget_well_name(well_info, int)") - _has_well = EclPrototype("bool well_info_has_well(well_info, char*)") - _get_ts = EclPrototype("well_time_line_ref well_info_get_ts(well_info, char*)") + _load_rst_resfile = ResdataPrototype( + "void well_info_load_rst_resfile(well_info, rd_file, bool)" + ) + _get_well_count = ResdataPrototype("int well_info_get_num_wells(well_info)") + _iget_well_name = ResdataPrototype("char* well_info_iget_well_name(well_info, int)") + _has_well = ResdataPrototype("bool well_info_has_well(well_info, char*)") + _get_ts = ResdataPrototype("well_time_line_ref well_info_get_ts(well_info, char*)") def __init__(self, grid, rst_file=None, load_segment_information=True): """ - @type grid: EclGrid - @type rst_file: str or EclFile or list of str or list of EclFile + @type grid: Grid + @type rst_file: str or ResdataFile or list of str or list of ResdataFile """ c_ptr = self._alloc(grid) super(WellInfo, self).__init__(c_ptr) @@ -88,15 +90,15 @@ def _assert_file_exists(self, rst_file): raise IOError("No such file %s" % rst_file) def addWellFile(self, rst_file, load_segment_information): - """@type rstfile: str or EclFile""" + """@type rstfile: str or ResdataFile""" if isinstance(rst_file, str): self._assert_file_exists(rst_file) self._load_rstfile(rst_file, load_segment_information) - elif isinstance(rst_file, EclFile): - self._load_rst_eclfile(rst_file, load_segment_information) + elif isinstance(rst_file, ResdataFile): + self._load_rst_resfile(rst_file, load_segment_information) else: raise TypeError( - "Expected the RST file to be a filename or an EclFile instance." + "Expected the RST file to be a filename or an ResdataFile instance." ) def hasWell(self, well_name): diff --git a/python/ecl/well/well_segment.py b/python/resdata/well/well_segment.py similarity index 61% rename from python/ecl/well/well_segment.py rename to python/resdata/well/well_segment.py index e3560f56f7..2e34e921a0 100644 --- a/python/ecl/well/well_segment.py +++ b/python/resdata/well/well_segment.py @@ -1,21 +1,25 @@ from cwrap import BaseCClass -from ecl import EclPrototype +from resdata import ResdataPrototype class WellSegment(BaseCClass): TYPE_NAME = "well_segment" - _active = EclPrototype("bool well_segment_active(well_segment)") - _main_stem = EclPrototype("bool well_segment_main_stem(well_segment)") - _nearest_wellhead = EclPrototype("bool well_segment_nearest_wellhead(well_segment)") - _id = EclPrototype("int well_segment_get_id(well_segment)") - _link_count = EclPrototype("int well_segment_get_link_count(well_segment)") - _branch_id = EclPrototype("int well_segment_get_branch_id(well_segment)") - _outlet_id = EclPrototype("int well_segment_get_outlet_id(well_segment)") - _depth = EclPrototype("double well_segment_get_depth(well_segment)") - _length = EclPrototype("double well_segment_get_length(well_segment)") - _total_length = EclPrototype("double well_segment_get_total_length(well_segment)") - _diameter = EclPrototype("double well_segment_get_diameter(well_segment)") + _active = ResdataPrototype("bool well_segment_active(well_segment)") + _main_stem = ResdataPrototype("bool well_segment_main_stem(well_segment)") + _nearest_wellhead = ResdataPrototype( + "bool well_segment_nearest_wellhead(well_segment)" + ) + _id = ResdataPrototype("int well_segment_get_id(well_segment)") + _link_count = ResdataPrototype("int well_segment_get_link_count(well_segment)") + _branch_id = ResdataPrototype("int well_segment_get_branch_id(well_segment)") + _outlet_id = ResdataPrototype("int well_segment_get_outlet_id(well_segment)") + _depth = ResdataPrototype("double well_segment_get_depth(well_segment)") + _length = ResdataPrototype("double well_segment_get_length(well_segment)") + _total_length = ResdataPrototype( + "double well_segment_get_total_length(well_segment)" + ) + _diameter = ResdataPrototype("double well_segment_get_diameter(well_segment)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly") diff --git a/python/ecl/well/well_state.py b/python/resdata/well/well_state.py similarity index 68% rename from python/ecl/well/well_state.py rename to python/resdata/well/well_state.py index a40d847dee..29fdd4a799 100644 --- a/python/ecl/well/well_state.py +++ b/python/resdata/well/well_state.py @@ -1,51 +1,57 @@ from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.well import WellTypeEnum, WellConnection -from ecl.util.util import CTime +from resdata import ResdataPrototype +from resdata.well import WellType, WellConnection +from resdata.util.util import CTime class WellState(BaseCClass): TYPE_NAME = "well_state" - _global_connections_size = EclPrototype( + _global_connections_size = ResdataPrototype( "int well_conn_collection_get_size(void*)", bind=False ) - _global_connections_iget = EclPrototype( + _global_connections_iget = ResdataPrototype( "well_connection_ref well_conn_collection_iget(void*, int)", bind=False ) - _segment_collection_size = EclPrototype( + _segment_collection_size = ResdataPrototype( "int well_segment_collection_get_size(void*)", bind=False ) - _segment_collection_iget = EclPrototype( + _segment_collection_iget = ResdataPrototype( "well_segment_ref well_segment_collection_iget(void*, int)", bind=False ) - _has_global_connections = EclPrototype( + _has_global_connections = ResdataPrototype( "bool well_state_has_global_connections(well_state)" ) - _get_global_connections = EclPrototype( + _get_global_connections = ResdataPrototype( "void* well_state_get_global_connections(well_state)" ) - _get_segment_collection = EclPrototype("void* well_state_get_segments(well_state)") - _branches = EclPrototype("void* well_state_get_branches(well_state)") - _segments = EclPrototype("void* well_state_get_segments(well_state)") - _get_name = EclPrototype("char* well_state_get_name(well_state)") - _is_open = EclPrototype("bool well_state_is_open(well_state)") - _is_msw = EclPrototype("bool well_state_is_MSW(well_state)") - _well_number = EclPrototype("int well_state_get_well_nr(well_state)") - _report_number = EclPrototype("int well_state_get_report_nr(well_state)") - _has_segment_data = EclPrototype("bool well_state_has_segment_data(well_state)") - _sim_time = EclPrototype("time_t well_state_get_sim_time(well_state)") - _well_type = EclPrototype("well_type_enum well_state_get_type(well_state)") - _oil_rate = EclPrototype("double well_state_get_oil_rate(well_state)") - _gas_rate = EclPrototype("double well_state_get_gas_rate(well_state)") - _water_rate = EclPrototype("double well_state_get_water_rate(well_state)") - _volume_rate = EclPrototype("double well_state_get_volume_rate(well_state)") - _oil_rate_si = EclPrototype("double well_state_get_oil_rate_si(well_state)") - _gas_rate_si = EclPrototype("double well_state_get_gas_rate_si(well_state)") - _water_rate_si = EclPrototype("double well_state_get_water_rate_si(well_state)") - _volume_rate_si = EclPrototype("double well_state_get_volume_rate_si(well_state)") - _get_global_well_head = EclPrototype( + _get_segment_collection = ResdataPrototype( + "void* well_state_get_segments(well_state)" + ) + _branches = ResdataPrototype("void* well_state_get_branches(well_state)") + _segments = ResdataPrototype("void* well_state_get_segments(well_state)") + _get_name = ResdataPrototype("char* well_state_get_name(well_state)") + _is_open = ResdataPrototype("bool well_state_is_open(well_state)") + _is_msw = ResdataPrototype("bool well_state_is_MSW(well_state)") + _well_number = ResdataPrototype("int well_state_get_well_nr(well_state)") + _report_number = ResdataPrototype("int well_state_get_report_nr(well_state)") + _has_segment_data = ResdataPrototype( + "bool well_state_has_segment_data(well_state)" + ) + _sim_time = ResdataPrototype("time_t well_state_get_sim_time(well_state)") + _well_type = ResdataPrototype("well_type_enum well_state_get_type(well_state)") + _oil_rate = ResdataPrototype("double well_state_get_oil_rate(well_state)") + _gas_rate = ResdataPrototype("double well_state_get_gas_rate(well_state)") + _water_rate = ResdataPrototype("double well_state_get_water_rate(well_state)") + _volume_rate = ResdataPrototype("double well_state_get_volume_rate(well_state)") + _oil_rate_si = ResdataPrototype("double well_state_get_oil_rate_si(well_state)") + _gas_rate_si = ResdataPrototype("double well_state_get_gas_rate_si(well_state)") + _water_rate_si = ResdataPrototype("double well_state_get_water_rate_si(well_state)") + _volume_rate_si = ResdataPrototype( + "double well_state_get_volume_rate_si(well_state)" + ) + _get_global_well_head = ResdataPrototype( "well_connection_ref well_state_get_global_wellhead(well_state)" ) @@ -81,7 +87,7 @@ def simulationTime(self): return self._sim_time() def wellType(self): - """@rtype: WellTypeEnum""" + """@rtype: WellType""" return self._well_type() def hasGlobalConnections(self): diff --git a/python/ecl/well/well_time_line.py b/python/resdata/well/well_time_line.py similarity index 74% rename from python/ecl/well/well_time_line.py rename to python/resdata/well/well_time_line.py index 3cbeee5166..cd5cb325b4 100644 --- a/python/ecl/well/well_time_line.py +++ b/python/resdata/well/well_time_line.py @@ -1,13 +1,13 @@ from cwrap import BaseCClass -from ecl import EclPrototype -from ecl.well import WellState +from resdata import ResdataPrototype +from resdata.well import WellState class WellTimeLine(BaseCClass): TYPE_NAME = "well_time_line" - _size = EclPrototype("int well_ts_get_size(well_time_line)") - _name = EclPrototype("char* well_ts_get_name(well_time_line)") - _iget = EclPrototype("well_state_ref well_ts_iget_state(well_time_line, int)") + _size = ResdataPrototype("int well_ts_get_size(well_time_line)") + _name = ResdataPrototype("char* well_ts_get_name(well_time_line)") + _iget = ResdataPrototype("well_state_ref well_ts_iget_state(well_time_line, int)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly") diff --git a/python/resdata/well/well_type_enum.py b/python/resdata/well/well_type_enum.py new file mode 100644 index 0000000000..c757db0beb --- /dev/null +++ b/python/resdata/well/well_type_enum.py @@ -0,0 +1,17 @@ +from cwrap import BaseCEnum + + +class WellType(BaseCEnum): + TYPE_NAME = "well_type_enum" + ZERO = None + PRODUCER = None + WATER_INJECTOR = None + GAS_INJECTOR = None + OIL_INJECTOR = None + + +WellType.addEnum("ZERO", 0) +WellType.addEnum("PRODUCER", 1) +WellType.addEnum("OIL_INJECTOR", 2) +WellType.addEnum("WATER_INJECTOR", 3) +WellType.addEnum("GAS_INJECTOR", 4) diff --git a/python/tests/__init__.py b/python/tests/__init__.py index c6002e0af0..709e3de3f5 100644 --- a/python/tests/__init__.py +++ b/python/tests/__init__.py @@ -1,6 +1,6 @@ import os.path import types -from ecl.util.test import ExtendedTestCase +from resdata.util.test import ExtendedTestCase from functools import wraps from functools import partial import unittest @@ -29,7 +29,7 @@ def source_root(): # # Ideally the equinor_test() implementation should just be a suitable wrapper of: # -# skipUnless(EclTest.EQUINOR_DATA, "Missing Equinor testdata") +# skipUnless(ResdataTest.EQUINOR_DATA, "Missing Equinor testdata") # # but that has been surprisingly difficult to achieve. The current # implemenation is based on the skip() function from the unittest/case.py @@ -44,12 +44,12 @@ def source_root(): # # # @equinor_test() -# class EquinorTest(EclTest): +# class EquinorTest(ResdataTest): # # This test class will be skipped entirely if we do not have access to # # Equinor testdata. # # -# class XTest(EclTest): +# class XTest(ResdataTest): # # @equinor_test # def test_method(self): @@ -62,7 +62,7 @@ def equinor_test(): def decorator(test_item): if not isinstance(test_item, type): - if not EclTest.EQUINOR_DATA: + if not ResdataTest.EQUINOR_DATA: @functools.wraps(test_item) def skip_wrapper(*args, **kwargs): @@ -70,7 +70,7 @@ def skip_wrapper(*args, **kwargs): test_item = skip_wrapper - if not EclTest.EQUINOR_DATA: + if not ResdataTest.EQUINOR_DATA: test_item.__unittest_skip__ = True test_item.__unittest_skip_why__ = "Missing Equinor testdata" return test_item @@ -78,7 +78,7 @@ def skip_wrapper(*args, **kwargs): return decorator -class EclTest(ExtendedTestCase): +class ResdataTest(ExtendedTestCase): SOURCE_ROOT = source_root() TESTDATA_ROOT = os.path.join(SOURCE_ROOT, "test-data") EQUINOR_DATA = os.path.islink(os.path.join(TESTDATA_ROOT, "Equinor")) diff --git a/python/tests/bin_tests/test_summary_resample.py b/python/tests/bin_tests/test_summary_resample.py index 57e749c264..307ef0cf88 100644 --- a/python/tests/bin_tests/test_summary_resample.py +++ b/python/tests/bin_tests/test_summary_resample.py @@ -2,11 +2,11 @@ import subprocess from subprocess import CalledProcessError as CallError -from ecl.grid import Cell, EclGrid -from ecl.summary import EclSum -from tests import EclTest -from ecl.util.test.ecl_mock import createEclSum -from ecl.util.test import TestAreaContext +from resdata.grid import Cell, Grid +from resdata.summary import Summary +from resdata.util.test import TestAreaContext +from resdata.util.test.mock import createSummary +from tests import ResdataTest def fopr(days): @@ -26,7 +26,7 @@ def fgpt(days): def create_case(num_mini_step=10, case="CSV"): length = 100 - return createEclSum( + return createSummary( case, [ ("FOPT", None, 0, "SM3"), @@ -40,7 +40,7 @@ def create_case(num_mini_step=10, case="CSV"): ) -class SummaryResampleTest(EclTest): +class SummaryResampleTest(ResdataTest): @classmethod def setUpClass(cls): cls.script = os.path.join(cls.SOURCE_ROOT, "bin/summary_resample") @@ -64,7 +64,7 @@ def test_run_default(self): # Should run OK: subprocess.check_call([self.script, "CSV", "OUTPUT"]) - output_case = EclSum("OUTPUT") + output_case = Summary("OUTPUT") self.assertEqual( output_case.get_data_start_time(), self.case.get_data_start_time() ) @@ -78,7 +78,7 @@ def test_run_default(self): refcase = create_case(num_mini_step=7, case="REFCASE") refcase.fwrite() subprocess.check_call([self.script, "CSV", "OUTPUT", "--refcase=REFCASE"]) - output_case = EclSum("OUTPUT") + output_case = Summary("OUTPUT") self.assertEqual( output_case.get_data_start_time(), refcase.get_data_start_time() ) diff --git a/python/tests/ecl_tests/test_deprecation.py b/python/tests/ecl_tests/test_deprecation.py deleted file mode 100644 index f2216068db..0000000000 --- a/python/tests/ecl_tests/test_deprecation.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -import warnings -import time -import datetime - -from ecl.util.test import TestAreaContext -from ecl import EclDataType -from ecl.eclfile import EclFile, EclKW, FortIO, openFortIO -from ecl.grid import EclGrid, EclGrid, EclRegion, EclGridGenerator -from ecl.rft import EclRFT -from ecl.util.test.ecl_mock import createEclSum -from ecl.util.util import BoolVector -from tests import EclTest - -# The class Deprecation_1_9_Test contains methods which will be marked -# as deprecated in the 1.9.x versions. - -warnings.simplefilter("error", DeprecationWarning) - - -class Deprecation_2_1_Test(EclTest): - pass - - -class Deprecation_2_0_Test(EclTest): - def test_EclFile_name_property(self): - with TestAreaContext("name") as t: - kw = EclKW("TEST", 3, EclDataType.ECL_INT) - with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f: - kw.fwrite(f) - - f = EclFile("TEST") - - -class Deprecation_1_9_Test(EclTest): - def test_EclRegion_properties(self): - grid = EclGridGenerator.createRectangular((10, 10, 10), (1, 1, 1)) - region = EclRegion(grid, False) diff --git a/python/tests/ecl_tests/test_ecl_cmp.py b/python/tests/ecl_tests/test_ecl_cmp.py deleted file mode 100644 index 3690936777..0000000000 --- a/python/tests/ecl_tests/test_ecl_cmp.py +++ /dev/null @@ -1,49 +0,0 @@ -from ecl.util.test import TestAreaContext -from ecl.util.test.ecl_mock import createEclSum -from ecl.summary import EclCmp -from tests import EclTest, equinor_test - - -@equinor_test() -class EclCmpTest(EclTest): - def setUp(self): - self.root1 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE") - self.root2 = self.createTestPath("Equinor/ECLIPSE/Oseberg/F8MLT/F8MLT-F4") - - def test_not_existing(self): - with self.assertRaises(IOError): - ecl_cmp = EclCmp("missing/case1", "missing/case2") - - with self.assertRaises(IOError): - ecl_cmp = EclCmp("missing/case1", self.root1) - - with self.assertRaises(IOError): - ecl_cmp = EclCmp(self.root1, "missing/case1") - - ecl_cmp = EclCmp(self.root1, self.root1) - ecl_cmp = EclCmp(self.root2, self.root2) - - def test_different_start(self): - with self.assertRaises(ValueError): - ecl_cmp = EclCmp(self.root1, self.root2) - - def test_summary_cmp(self): - ecl_cmp = EclCmp(self.root1, self.root1) - self.assertEqual((False, False), ecl_cmp.hasSummaryVector("MISSING")) - self.assertEqual((True, True), ecl_cmp.hasSummaryVector("FOPT")) - - with self.assertRaises(KeyError): - diff = ecl_cmp.cmpSummaryVector("MISSING") - - diff_sum, ref_sum = ecl_cmp.cmpSummaryVector("FOPT") - self.assertEqual(diff_sum, 0.0) - self.assertTrue(ecl_cmp.endTimeEqual()) - - def test_wells(self): - ecl_cmp = EclCmp(self.root1, self.root1) - wells = ecl_cmp.testWells() - - well_set = set(["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"]) - self.assertEqual(len(wells), len(well_set)) - for well in wells: - self.assertTrue(well in well_set) diff --git a/python/tests/ecl_tests/test_ecl_init_file.py b/python/tests/ecl_tests/test_ecl_init_file.py deleted file mode 100644 index 6df1fd7340..0000000000 --- a/python/tests/ecl_tests/test_ecl_init_file.py +++ /dev/null @@ -1,29 +0,0 @@ -from tests import EclTest, equinor_test -from ecl import EclFileFlagEnum -from ecl.eclfile import Ecl3DKW, EclKW, EclInitFile, EclFile, FortIO -from ecl.grid import EclGrid - - -@equinor_test() -class InitFileTest(EclTest): - def setUp(self): - self.grid_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") - self.init_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.INIT") - - def test_wrong_type(self): - g = EclGrid(self.grid_file) - with self.assertRaises(ValueError): - f = EclInitFile(g, self.grid_file) - - def test_load(self): - g = EclGrid(self.grid_file) - f = EclInitFile(g, self.init_file) - - head = f["INTEHEAD"][0] - self.assertTrue(isinstance(head, EclKW)) - - porv = f["PORV"][0] - self.assertTrue(isinstance(porv, Ecl3DKW)) - - poro = f["PORO"][0] - self.assertTrue(isinstance(poro, Ecl3DKW)) diff --git a/python/tests/ecl_tests/test_ecl_type.py b/python/tests/ecl_tests/test_ecl_type.py deleted file mode 100644 index 5cf4b4ea23..0000000000 --- a/python/tests/ecl_tests/test_ecl_type.py +++ /dev/null @@ -1,139 +0,0 @@ -from ecl.util.test import TestAreaContext -from tests import EclTest - -from ecl import EclDataType, EclTypeEnum - - -def get_const_size_types(): - return EclTypeEnum.enums()[:-1:] - - -class EclDataTypeTest(EclTest): - # All of the below should list their elements in the same order as - # EclTypeEnum! - # [char, float, double, int, bool, mess] - - CONST_SIZES = [8, 4, 8, 4, 4, 0] - - CONST_VERIFIERS = [ - EclDataType.is_char, - EclDataType.is_float, - EclDataType.is_double, - EclDataType.is_int, - EclDataType.is_bool, - EclDataType.is_mess, - ] - - CONST_NAMES = ["CHAR", "REAL", "DOUB", "INTE", "LOGI", "MESS"] - - STRING_NAMES = ["C000", "C010", "C020", "C042", "C999"] - - STRING_SIZES = [0, 10, 20, 42, 999] - - TYPES = get_const_size_types() + len(STRING_SIZES) * [EclTypeEnum.ECL_STRING_TYPE] - - SIZES = CONST_SIZES + STRING_SIZES - - NAMES = CONST_NAMES + STRING_NAMES - - def test_alloc_from_type(self): - types, sizes = get_const_size_types(), self.CONST_SIZES - for ecl_type, element_size in zip(types, sizes): - data_type = EclDataType(ecl_type) - self.assertEqual(ecl_type, data_type.type) - self.assertEqual(element_size, data_type.element_size) - - def test_invalid_string_alloc(self): - with self.assertRaises(ValueError): - data_type = EclDataType(EclTypeEnum.ECL_STRING_TYPE) - - with self.assertRaises(ValueError): - data_type = EclDataType(EclTypeEnum.ECL_STRING_TYPE, -1) - - with self.assertRaises(ValueError): - data_type = EclDataType(EclTypeEnum.ECL_STRING_TYPE, 1000) - - def test_alloc(self): - for ecl_type, element_size in zip(self.TYPES, self.SIZES): - data_type = EclDataType(ecl_type, element_size) - self.assertEqual(ecl_type, data_type.type) - self.assertEqual(element_size, data_type.element_size) - - def test_type_verifiers(self): - test_base = zip(self.TYPES, self.SIZES, self.CONST_VERIFIERS) - for ecl_type, elem_size, verifier in test_base: - data_type = EclDataType(ecl_type, elem_size) - self.assertTrue(verifier(data_type)) - - def test_get_type_name(self): - test_base = zip(self.TYPES, self.SIZES, self.NAMES) - for ecl_type, elem_size, type_name in test_base: - data_type = EclDataType(ecl_type, elem_size) - self.assertEqual(type_name, data_type.type_name) - - def test_initialization_validation(self): - invalid_args = [ - (None, 0, self.CONST_NAMES[0]), - (1, None, self.CONST_NAMES[0]), - (1, 0, self.CONST_NAMES[0]), - (None, None, None), - (None, 12, None), - ] - - for inv_arg in invalid_args: - with self.assertRaises(ValueError): - EclDataType(inv_arg[0], inv_arg[1], inv_arg[2]) - - def test_create_from_type_name(self): - test_base = zip(self.TYPES, self.SIZES, self.NAMES) - for ecl_type, elem_size, type_name in test_base: - data_type = EclDataType.create_from_type_name(type_name) - self.assertEqual(ecl_type, data_type.type) - self.assertEqual(elem_size, data_type.element_size) - self.assertEqual(type_name, data_type.type_name) - - def test_is_numeric(self): - numeric_types = [ - EclTypeEnum.ECL_INT_TYPE, - EclTypeEnum.ECL_FLOAT_TYPE, - EclTypeEnum.ECL_DOUBLE_TYPE, - ] - - for ecl_type in numeric_types: - self.assertTrue(EclDataType(ecl_type).is_numeric()) - - for ecl_type in set(get_const_size_types()) - set(numeric_types): - self.assertFalse(EclDataType(ecl_type).is_numeric()) - - for elem_size in self.STRING_SIZES: - data_type = EclDataType(EclTypeEnum.ECL_STRING_TYPE, elem_size) - self.assertFalse(data_type.is_numeric()) - - def test_equals(self): - test_base = zip(self.TYPES, self.SIZES) - for ecl_type, elem_size in test_base: - a = EclDataType(ecl_type, elem_size) - b = EclDataType(ecl_type, elem_size) - - self.assertTrue(a.is_equal(b)) - self.assertEqual(a, b) - - for otype, osize in set(test_base) - set([(ecl_type, elem_size)]): - self.assertFalse(a.is_equal(EclDataType(otype, osize))) - self.assertNotEqual(a, EclDataType(otype, osize)) - - def test_hash(self): - all_types = set() - test_base = list(zip(self.TYPES, self.SIZES)) - - for index, (ecl_type, elem_size) in enumerate(test_base): - all_types.add(EclDataType(ecl_type, elem_size)) - self.assertEqual(index + 1, len(all_types)) - - for index, (ecl_type, elem_size) in enumerate(test_base): - all_types.add(EclDataType(ecl_type, elem_size)) - - for index, ecl_type in enumerate(get_const_size_types()): - all_types.add(EclDataType(ecl_type)) - - self.assertEqual(len(test_base), len(all_types)) diff --git a/python/tests/ecl_tests/test_ecl_util.py b/python/tests/ecl_tests/test_ecl_util.py deleted file mode 100644 index 7baf9226bf..0000000000 --- a/python/tests/ecl_tests/test_ecl_util.py +++ /dev/null @@ -1,27 +0,0 @@ -from ecl import EclTypeEnum, EclFileEnum, EclPhaseEnum, EclUnitTypeEnum, EclUtil -from ecl.grid import EclGrid -from tests import EclTest - - -class EclUtilTest(EclTest): - def test_enums(self): - source_file_path = "lib/include/ert/ecl/ecl_util.hpp" - self.assertEnumIsFullyDefined(EclFileEnum, "ecl_file_enum", source_file_path) - self.assertEnumIsFullyDefined(EclPhaseEnum, "ecl_phase_enum", source_file_path) - self.assertEnumIsFullyDefined( - EclUnitTypeEnum, "ert_ecl_unit_enum", source_file_path - ) - - source_file_path = "lib/include/ert/ecl/ecl_type.hpp" - self.assertEnumIsFullyDefined(EclTypeEnum, "ecl_type_enum", source_file_path) - - def test_file_type(self): - file_type, fmt, report = EclUtil.inspectExtension("CASE.X0078") - self.assertEqual(file_type, EclFileEnum.ECL_RESTART_FILE) - - def test_file_report_nr(self): - report_nr = EclUtil.reportStep("CASE.X0080") - self.assertEqual(report_nr, 80) - - with self.assertRaises(ValueError): - EclUtil.reportStep("CASE.EGRID") diff --git a/python/tests/ecl_tests/test_grav.py b/python/tests/ecl_tests/test_grav.py deleted file mode 100644 index 5522236e50..0000000000 --- a/python/tests/ecl_tests/test_grav.py +++ /dev/null @@ -1,24 +0,0 @@ -import time -from ecl import EclDataType -from ecl.eclfile import EclKW, EclFile, openFortIO, FortIO -from ecl.grid import EclGrid -from ecl.gravimetry import EclGrav -from ecl.util.test import TestAreaContext -from tests import EclTest - - -class EclGravTest(EclTest): - def setUp(self): - self.grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) - - def test_create(self): - # The init file created here only contains a PORO field. More - # properties must be added to this before it can be used for - # any usefull gravity calculations. - poro = EclKW("PORO", self.grid.getGlobalSize(), EclDataType.ECL_FLOAT) - with TestAreaContext("grav_init"): - with openFortIO("TEST.INIT", mode=FortIO.WRITE_MODE) as f: - poro.fwrite(f) - self.init = EclFile("TEST.INIT") - - grav = EclGrav(self.grid, self.init) diff --git a/python/tests/ecl_tests/test_grdecl_equinor.py b/python/tests/ecl_tests/test_grdecl_equinor.py deleted file mode 100755 index 547b43cf75..0000000000 --- a/python/tests/ecl_tests/test_grdecl_equinor.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python -import os -from ecl.eclfile import EclKW, Ecl3DKW -from ecl.grid import EclGrid -from tests import EclTest, equinor_test - -from cwrap import open as copen - - -@equinor_test() -class GRDECLEquinorTest(EclTest): - def setUp(self): - self.src_file = self.createTestPath( - "Equinor/ECLIPSE/Gurbat/include/example_permx.GRDECL" - ) - self.file_list = [] - - def addFile(self, filename): - self.file_list.append(filename) - - def tearDown(self): - for f in self.file_list: - if os.path.exists(f): - os.unlink(f) - - def test_Load(self): - kw = EclKW.read_grdecl(copen(self.src_file, "r"), "PERMX") - self.assertTrue(kw) - - grid = EclGrid(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE")) - kw = Ecl3DKW.read_grdecl(grid, copen(self.src_file, "r"), "PERMX") - self.assertTrue(isinstance(kw, Ecl3DKW)) - - def test_reload(self): - kw = EclKW.read_grdecl(copen(self.src_file, "r"), "PERMX") - tmp_file1 = "/tmp/permx1.grdecl" - tmp_file2 = "/tmp/permx2.grdecl" - self.addFile(tmp_file1) - self.addFile(tmp_file2) - - fileH = copen(tmp_file1, "w") - kw.write_grdecl(fileH) - fileH.close() - - kw1 = EclKW.read_grdecl(copen(tmp_file1, "r"), "PERMX") - - fileH = copen(tmp_file2, "w") - kw1.write_grdecl(fileH) - fileH.close() - - self.assertFilesAreEqual(tmp_file1, tmp_file2) - - def test_fseek(self): - file = copen(self.src_file, "r") - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) - self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) - file.close() - - file = copen(self.src_file, "r") - kw1 = EclKW.read_grdecl(file, "PERMX") - self.assertFalse(EclKW.fseek_grdecl(file, "PERMX")) - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) - file.close() - - def test_fseek2(self): - test_src = self.createTestPath("local/ECLIPSE/grdecl-test/test.grdecl") - # Test kw at the the very start - file = copen(test_src, "r") - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) - - # Test commented out kw: - self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) - self.assertFalse(EclKW.fseek_grdecl(file, "PERMZ")) - - # Test ignore not start of line: - self.assertTrue(EclKW.fseek_grdecl(file, "MARKER")) - self.assertFalse(EclKW.fseek_grdecl(file, "PERMXYZ")) - - # Test rewind - self.assertFalse(EclKW.fseek_grdecl(file, "PERMX", rewind=False)) - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) - - # Test multiline comments + blanks - self.assertTrue(EclKW.fseek_grdecl(file, "LASTKW")) - - def test_fseek_dos(self): - test_src = self.createTestPath( - "local/ECLIPSE/grdecl-test/test.grdecl_dos" - ) # File formatted with \r\n line endings. - # Test kw at the the very start - file = copen(test_src, "r") - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) - - # Test commented out kw: - self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) - self.assertFalse(EclKW.fseek_grdecl(file, "PERMZ")) - - # Test ignore not start of line: - self.assertTrue(EclKW.fseek_grdecl(file, "MARKER")) - self.assertFalse(EclKW.fseek_grdecl(file, "PERMXYZ")) - - # Test rewind - self.assertFalse(EclKW.fseek_grdecl(file, "PERMX", rewind=False)) - self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) - - # Test multiline comments + blanks - self.assertTrue(EclKW.fseek_grdecl(file, "LASTKW")) diff --git a/python/tests/ecl_tests/test_rft.py b/python/tests/ecl_tests/test_rft.py deleted file mode 100644 index 177fd804a4..0000000000 --- a/python/tests/ecl_tests/test_rft.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -import datetime -from ecl.util.util import CTime -from ecl.rft import EclRFTFile, EclRFTCell, EclPLTCell, EclRFT, WellTrajectory -from tests import EclTest - - -class RFTTest(EclTest): - def test_create(self): - rft = EclRFT("WELL", "RFT", datetime.date(2015, 10, 1), 100) - self.assertEqual(len(rft), 0) - - with self.assertRaises(IndexError): - cell = rft[5] - - def test_repr(self): - rft = EclRFT("WELL", "RFT", datetime.date(2015, 10, 1), 100) - pfx = "EclRFT(completed_cells = 0, date = 2015-10-01, RFT)" - self.assertEqual(pfx, repr(rft)[: len(pfx)]) diff --git a/python/tests/geometry_tests/test_convex_hull.py b/python/tests/geometry_tests/test_convex_hull.py index df25197429..e58d6ca916 100644 --- a/python/tests/geometry_tests/test_convex_hull.py +++ b/python/tests/geometry_tests/test_convex_hull.py @@ -1,8 +1,8 @@ -from ecl.util.geometry.geometry_tools import GeometryTools -from tests import EclTest +from resdata.geometry.geometry_tools import GeometryTools +from tests import ResdataTest -class ConvexHullTest(EclTest): +class ConvexHullTest(ResdataTest): def test_ccw(self): p1 = (0, 0) p2 = (1, 0) diff --git a/python/tests/geometry_tests/test_cpolyline.py b/python/tests/geometry_tests/test_cpolyline.py index 02768296cc..9868ac91dc 100644 --- a/python/tests/geometry_tests/test_cpolyline.py +++ b/python/tests/geometry_tests/test_cpolyline.py @@ -1,12 +1,12 @@ import math -from ecl.util.geometry import CPolyline, Polyline -from ecl.util.geometry.xyz_io import XYZIo -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.geometry import CPolyline, Polyline +from resdata.geometry.xyz_io import XYZIo +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class CPolylineTest(EclTest): +class CPolylineTest(ResdataTest): def setUp(self): self.polyline1 = self.createTestPath("local/geometry/pol11.xyz") self.polyline2 = self.createTestPath("local/geometry/pol8.xyz") diff --git a/python/tests/geometry_tests/test_cpolyline_collection.py b/python/tests/geometry_tests/test_cpolyline_collection.py index 93c61cca05..037ddc2291 100644 --- a/python/tests/geometry_tests/test_cpolyline_collection.py +++ b/python/tests/geometry_tests/test_cpolyline_collection.py @@ -1,13 +1,13 @@ import gc -from ecl.util.geometry import CPolylineCollection, CPolyline -from ecl.util.geometry.xyz_io import XYZIo -from ecl.util.test import TestAreaContext -from tests import EclTest -from ecl.util.util import DoubleVector +from resdata.geometry import CPolylineCollection, CPolyline +from resdata.geometry.xyz_io import XYZIo +from resdata.util.test import TestAreaContext +from tests import ResdataTest +from resdata.util.util import DoubleVector -class CPolylineCollectionTest(EclTest): +class CPolylineCollectionTest(ResdataTest): def test_construction(self): pc = CPolylineCollection() self.assertEqual(len(pc), 0) diff --git a/python/tests/geometry_tests/test_geo_pointset.py b/python/tests/geometry_tests/test_geo_pointset.py index 5734bf9618..de0c4a6d4e 100644 --- a/python/tests/geometry_tests/test_geo_pointset.py +++ b/python/tests/geometry_tests/test_geo_pointset.py @@ -1,9 +1,9 @@ -from ecl.util.geometry import GeoPointset, Surface -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.geometry import GeoPointset, Surface +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class GeoPointsetTest(EclTest): +class GeoPointsetTest(ResdataTest): def test_init(self): gp = GeoPointset() self.assertEqual(0, len(gp)) diff --git a/python/tests/geometry_tests/test_geo_region.py b/python/tests/geometry_tests/test_geo_region.py index b1145076f7..cfcc12ee21 100644 --- a/python/tests/geometry_tests/test_geo_region.py +++ b/python/tests/geometry_tests/test_geo_region.py @@ -1,9 +1,9 @@ -from ecl.util.geometry import GeoRegion, GeoPointset, CPolyline, Surface -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.geometry import GeoRegion, GeoPointset, CPolyline, Surface +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class GeoRegionTest(EclTest): +class GeoRegionTest(ResdataTest): def test_init(self): pointset = GeoPointset() georegion = GeoRegion(pointset) diff --git a/python/tests/geometry_tests/test_geometry_tools.py b/python/tests/geometry_tests/test_geometry_tools.py index 21bb6bfc7b..7c72edad78 100644 --- a/python/tests/geometry_tests/test_geometry_tools.py +++ b/python/tests/geometry_tests/test_geometry_tools.py @@ -1,12 +1,12 @@ import math -from ecl.util.geometry import Polyline, GeometryTools, CPolyline -from ecl.util.geometry.xyz_io import XYZIo -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.geometry import Polyline, GeometryTools, CPolyline +from resdata.geometry.xyz_io import XYZIo +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class GeometryToolsTest(EclTest): +class GeometryToolsTest(ResdataTest): def test_distance(self): p1 = (1, 1) p2 = (1, 2, 3) diff --git a/python/tests/geometry_tests/test_intersection.py b/python/tests/geometry_tests/test_intersection.py index 7b18a63c45..04398d1983 100644 --- a/python/tests/geometry_tests/test_intersection.py +++ b/python/tests/geometry_tests/test_intersection.py @@ -1,8 +1,8 @@ -from ecl.util.geometry import GeometryTools -from tests import EclTest +from resdata.geometry import GeometryTools +from tests import ResdataTest -class IntersectionTest(EclTest): +class IntersectionTest(ResdataTest): def test_intersection(self): p1 = (0.0, 0.0) p2 = (10.0, 0.0) diff --git a/python/tests/geometry_tests/test_point_in_polygon.py b/python/tests/geometry_tests/test_point_in_polygon.py index dbbadaae3f..a2e22863ae 100644 --- a/python/tests/geometry_tests/test_point_in_polygon.py +++ b/python/tests/geometry_tests/test_point_in_polygon.py @@ -1,9 +1,9 @@ -from ecl.util.geometry.geometry_tools import GeometryTools -from ecl.util.geometry.polyline import Polyline -from tests import EclTest +from resdata.geometry.geometry_tools import GeometryTools +from resdata.geometry.polyline import Polyline +from tests import ResdataTest -class PointInPolygonTest(EclTest): +class PointInPolygonTest(ResdataTest): def test_point_in_polygon(self): p1 = (0.5, 0.5) p2 = (2, 2) diff --git a/python/tests/geometry_tests/test_polygon_slicing.py b/python/tests/geometry_tests/test_polygon_slicing.py index 2b9fba92dd..30af14f25f 100644 --- a/python/tests/geometry_tests/test_polygon_slicing.py +++ b/python/tests/geometry_tests/test_polygon_slicing.py @@ -1,9 +1,9 @@ from math import sqrt -from ecl.util.geometry.geometry_tools import GeometryTools -from tests import EclTest +from resdata.geometry.geometry_tools import GeometryTools +from tests import ResdataTest -class PolygonSlicingTest(EclTest): +class PolygonSlicingTest(ResdataTest): def test_slicing_internal_hull(self): polygon = [(2, 2), (2, 1), (1, 1), (1, 5), (5, 5), (5, 4), (4, 4)] edge = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)] diff --git a/python/tests/geometry_tests/test_polyline.py b/python/tests/geometry_tests/test_polyline.py index 88796e7748..df39ccb4e8 100644 --- a/python/tests/geometry_tests/test_polyline.py +++ b/python/tests/geometry_tests/test_polyline.py @@ -1,10 +1,10 @@ -from ecl.util.geometry import Polyline, GeometryTools -from ecl.util.geometry.xyz_io import XYZIo -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.geometry import Polyline, GeometryTools +from resdata.geometry.xyz_io import XYZIo +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class PolylineTest(EclTest): +class PolylineTest(ResdataTest): def setUp(self): self.polyline = self.createTestPath("local/geometry/pol11.xyz") self.closed_polyline = self.createTestPath("local/geometry/pol8.xyz") diff --git a/python/tests/geometry_tests/test_surface.py b/python/tests/geometry_tests/test_surface.py index 01302e9809..e23691a073 100644 --- a/python/tests/geometry_tests/test_surface.py +++ b/python/tests/geometry_tests/test_surface.py @@ -1,10 +1,10 @@ import random -from ecl.util.geometry import Surface -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.geometry import Surface +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class SurfaceTest(EclTest): +class SurfaceTest(ResdataTest): def setUp(self): self.surface_valid = self.createTestPath( "local/geometry/surface/valid_ascii.irap" diff --git a/python/tests/global_tests/test_pylint.py b/python/tests/global_tests/test_pylint.py index b2a60477f7..9b700ff27f 100644 --- a/python/tests/global_tests/test_pylint.py +++ b/python/tests/global_tests/test_pylint.py @@ -1,20 +1,20 @@ -from ecl.util.test import LintTestCase +from resdata.util.test import LintTestCase class LintErt(LintTestCase): """Tests that no file in ert needs linting""" def test_lint_ecl(self): - # white = ['ecl_kw.py', 'ecl_type.py', 'ecl_sum.py', 'ecl_grid.py', 'ecl_npv.py'] # TODO fix issues and remove - # self.assertLinted('ecl/ecl', whitelist=white) + # white = ['rd_kw.py', 'rd_type.py', 'rd_sum.py', 'rd_grid.py', 'rd_npv.py'] # TODO fix issues and remove + # self.assertLinted('resdata/ecl', whitelist=white) pass # temporarily disable linting due to monkey patching def test_lint_geo(self): - self.assertLinted("ecl/geo") + self.assertLinted("resdata/geo") def test_lint_util(self): self.assertLinted( - "ecl/util", + "resdata/util", whitelist=[ "vector_template.py", "test_area.py", @@ -30,4 +30,4 @@ def test_lint_util(self): ) def test_lint_well(self): - self.assertLinted("ecl/well") + self.assertLinted("resdata/well") diff --git a/python/tests/ecl_tests/__init__.py b/python/tests/rd_tests/__init__.py similarity index 100% rename from python/tests/ecl_tests/__init__.py rename to python/tests/rd_tests/__init__.py diff --git a/python/tests/ecl_tests/test_cell.py b/python/tests/rd_tests/test_cell.py similarity index 95% rename from python/tests/ecl_tests/test_cell.py rename to python/tests/rd_tests/test_cell.py index f2304c45ea..4bea8a6a65 100644 --- a/python/tests/ecl_tests/test_cell.py +++ b/python/tests/rd_tests/test_cell.py @@ -1,13 +1,13 @@ #!/usr/bin/env python -from ecl.grid import Cell, EclGrid -from tests import EclTest +from resdata.grid import Cell, Grid +from tests import ResdataTest from unittest import skipUnless -class CellTest(EclTest): +class CellTest(ResdataTest): def setUp(self): fk = self.createTestPath("local/ECLIPSE/faarikaal/faarikaal1.EGRID") - self.grid = EclGrid(fk) + self.grid = Grid(fk) self.cell = self.grid[3455] self.actives = [c for c in self.grid if c.active] diff --git a/python/tests/ecl_tests/test_debug.py b/python/tests/rd_tests/test_debug.py similarity index 58% rename from python/tests/ecl_tests/test_debug.py rename to python/tests/rd_tests/test_debug.py index f6df9addd5..d836cf296e 100644 --- a/python/tests/ecl_tests/test_debug.py +++ b/python/tests/rd_tests/test_debug.py @@ -1,8 +1,8 @@ -from ecl.util.test import debug_msg -from tests import EclTest +from resdata.util.test import debug_msg +from tests import ResdataTest -class DebugTest(EclTest): +class DebugTest(ResdataTest): def test_create(self): msg = debug_msg("DEBUG") self.assertIn(__file__[:-1], msg) diff --git a/python/tests/rd_tests/test_deprecation.py b/python/tests/rd_tests/test_deprecation.py new file mode 100644 index 0000000000..d754f1b5ff --- /dev/null +++ b/python/tests/rd_tests/test_deprecation.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import datetime +import time +import warnings + +from resdata import ResDataType +from resdata.grid import Grid, GridGenerator, ResdataRegion +from resdata.resfile import FortIO, ResdataFile, ResdataKW, openFortIO +from resdata.rft import ResdataRFT +from resdata.util.test import TestAreaContext +from resdata.util.test.mock import createSummary +from resdata.util.util import BoolVector +from tests import ResdataTest + +# The class Deprecation_1_9_Test contains methods which will be marked +# as deprecated in the 1.9.x versions. + +warnings.simplefilter("error", DeprecationWarning) + + +class Deprecation_2_1_Test(ResdataTest): + pass + + +class Deprecation_2_0_Test(ResdataTest): + def test_ResdataFile_name_property(self): + with TestAreaContext("name") as t: + kw = ResdataKW("TEST", 3, ResDataType.RD_INT) + with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f: + kw.fwrite(f) + + f = ResdataFile("TEST") + + +class Deprecation_1_9_Test(ResdataTest): + def test_ResdataRegion_properties(self): + grid = GridGenerator.createRectangular((10, 10, 10), (1, 1, 1)) + region = ResdataRegion(grid, False) diff --git a/python/tests/ecl_tests/test_equinor_faults.py b/python/tests/rd_tests/test_equinor_faults.py similarity index 86% rename from python/tests/ecl_tests/test_equinor_faults.py rename to python/tests/rd_tests/test_equinor_faults.py index 8d42c953f9..15baad8be9 100644 --- a/python/tests/ecl_tests/test_equinor_faults.py +++ b/python/tests/rd_tests/test_equinor_faults.py @@ -7,26 +7,26 @@ from cwrap import open as copen import time -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid -from ecl.grid.faults import FaultCollection, Fault, FaultLine, FaultSegment -from tests import EclTest, equinor_test +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid +from resdata.grid.faults import FaultCollection, Fault, FaultLine, FaultSegment +from tests import ResdataTest, equinor_test @equinor_test() -class EquinorFaultTest(EclTest): +class EquinorFaultTest(ResdataTest): def loadGrid(self): grid_file = self.createTestPath("Equinor/ECLIPSE/Faults/grid.grdecl") fileH = copen(grid_file, "r") - specgrid = EclKW.read_grdecl( - fileH, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False + specgrid = ResdataKW.read_grdecl( + fileH, "SPECGRID", rd_type=ResDataType.RD_INT, strict=False ) - zcorn = EclKW.read_grdecl(fileH, "ZCORN") - coord = EclKW.read_grdecl(fileH, "COORD") - actnum = EclKW.read_grdecl(fileH, "ACTNUM", ecl_type=EclDataType.ECL_INT) + zcorn = ResdataKW.read_grdecl(fileH, "ZCORN") + coord = ResdataKW.read_grdecl(fileH, "COORD") + actnum = ResdataKW.read_grdecl(fileH, "ACTNUM", rd_type=ResDataType.RD_INT) - return EclGrid.create(specgrid, zcorn, coord, actnum) + return Grid.create(specgrid, zcorn, coord, actnum) def test_load(self): grid = self.loadGrid() diff --git a/python/tests/ecl_tests/test_fault_blocks.py b/python/tests/rd_tests/test_fault_blocks.py similarity index 86% rename from python/tests/ecl_tests/test_fault_blocks.py rename to python/tests/rd_tests/test_fault_blocks.py index acdbeddbbb..44f1bebef7 100644 --- a/python/tests/ecl_tests/test_fault_blocks.py +++ b/python/tests/rd_tests/test_fault_blocks.py @@ -2,22 +2,22 @@ from unittest import skipIf import cwrap -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid, EclRegion -from ecl.grid.faults import FaultBlock, FaultBlockLayer, FaultCollection -from ecl.util.geometry import Polyline, CPolylineCollection -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid, ResdataRegion +from resdata.grid.faults import FaultBlock, FaultBlockLayer, FaultCollection +from resdata.geometry import Polyline, CPolylineCollection +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class FaultBlockTest(EclTest): +class FaultBlockTest(ResdataTest): def setUp(self): - self.grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) - self.kw = EclKW("FAULTBLK", self.grid.getGlobalSize(), EclDataType.ECL_INT) + self.grid = Grid.createRectangular((10, 10, 10), (1, 1, 1)) + self.kw = ResdataKW("FAULTBLK", self.grid.getGlobalSize(), ResDataType.RD_INT) self.kw.assign(1) - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) for k in range(self.grid.getNZ()): reg.clear() @@ -26,8 +26,8 @@ def setUp(self): self.kw[k * self.grid.getNX() * self.grid.getNY() + 7] = 177 def test_fault_block(self): - grid = EclGrid.createRectangular((5, 5, 1), (1, 1, 1)) - kw = EclKW("FAULTBLK", grid.getGlobalSize(), EclDataType.ECL_INT) + grid = Grid.createRectangular((5, 5, 1), (1, 1, 1)) + kw = ResdataKW("FAULTBLK", grid.getGlobalSize(), ResDataType.RD_INT) kw.assign(0) for j in range(1, 4): for i in range(1, 4): @@ -53,9 +53,9 @@ def test_get_ijk(self): fileH.write("4 4 4 0 5\n") fileH.write("/\n") with cwrap.open("kw.grdecl") as f: - kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) + kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT) - grid = EclGrid.createRectangular((5, 5, 1), (1, 1, 1)) + grid = Grid.createRectangular((5, 5, 1), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) layer.loadKeyword(kw) @@ -83,9 +83,9 @@ def test_neighbours(self): fileH.write("/\n") with cwrap.open("kw.grdecl") as f: - kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) + kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT) - grid = EclGrid.createRectangular((5, 5, 1), (1, 1, 1)) + grid = Grid.createRectangular((5, 5, 1), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) layer.loadKeyword(kw) @@ -125,7 +125,7 @@ def test_neighbours2(self): nx = 8 ny = 8 nz = 1 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) with TestAreaContext("python/FaultBlocks/neighbours"): with open("faultblock.grdecl", "w") as fileH: @@ -141,7 +141,7 @@ def test_neighbours2(self): fileH.write("/\n") with cwrap.open("faultblock.grdecl") as f: - kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) + kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") @@ -189,7 +189,7 @@ def test_neighbours3(self): nx = 8 ny = 8 nz = 1 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) with TestAreaContext("python/FaultBlocks/neighbours"): with open("faultblock.grdecl", "w") as fileH: @@ -205,7 +205,7 @@ def test_neighbours3(self): fileH.write("/\n") with cwrap.open("faultblock.grdecl") as f: - kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) + kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") f.write("'FX' 4 4 1 4 1 1 'X' /\n") @@ -225,8 +225,8 @@ def test_neighbours3(self): self.assertTrue(b2 in nb) def test_fault_block_edge(self): - grid = EclGrid.createRectangular((5, 5, 1), (1, 1, 1)) - kw = EclKW("FAULTBLK", grid.getGlobalSize(), EclDataType.ECL_INT) + grid = Grid.createRectangular((5, 5, 1), (1, 1, 1)) + kw = ResdataKW("FAULTBLK", grid.getGlobalSize(), ResDataType.RD_INT) kw.assign(0) for j in range(1, 4): for i in range(1, 4): @@ -247,7 +247,7 @@ def test_fault_block_layer(self): layer = FaultBlockLayer(self.grid, 1) self.assertEqual(1, layer.getK()) - kw = EclKW("FAULTBLK", self.grid.getGlobalSize(), EclDataType.ECL_FLOAT) + kw = ResdataKW("FAULTBLK", self.grid.getGlobalSize(), ResDataType.RD_FLOAT) with self.assertRaises(ValueError): layer.scanKeyword(kw) @@ -326,7 +326,7 @@ def test_fault_block_layer(self): self.assertEqual([1, 2, 3], list(fault_block.getRegionList())) def test_add_polyline_barrier1(self): - grid = EclGrid.createRectangular((4, 1, 1), (1, 1, 1)) + grid = Grid.createRectangular((4, 1, 1), (1, 1, 1)) layer = FaultBlockLayer(self.grid, 0) polyline = Polyline(init_points=[(1.99, 0.001), (2.01, 0.99)]) @@ -342,7 +342,7 @@ def test_add_polyline_barrier1(self): self.assertFalse(geo_layer.cellContact(p1, p2)) def test_add_polyline_barrier2(self): - grid = EclGrid.createRectangular((10, 10, 1), (1, 1, 1)) + grid = Grid.createRectangular((10, 10, 1), (1, 1, 1)) layer = FaultBlockLayer(self.grid, 0) polyline = Polyline(init_points=[(0.1, 0.9), (8.9, 0.9), (8.9, 8.9)]) @@ -370,11 +370,11 @@ def test_add_polyline_barrier2(self): def test_fault_block_layer_export(self): layer = FaultBlockLayer(self.grid, 1) - kw1 = EclKW("FAULTBLK", self.grid.getGlobalSize() + 1, EclDataType.ECL_INT) + kw1 = ResdataKW("FAULTBLK", self.grid.getGlobalSize() + 1, ResDataType.RD_INT) with self.assertRaises(ValueError): layer.exportKeyword(kw1) - kw2 = EclKW("FAULTBLK", self.grid.getGlobalSize(), EclDataType.ECL_FLOAT) + kw2 = ResdataKW("FAULTBLK", self.grid.getGlobalSize(), ResDataType.RD_FLOAT) with self.assertRaises(TypeError): layer.exportKeyword(kw2) @@ -382,7 +382,7 @@ def test_internal_blocks(self): nx = 8 ny = 8 nz = 1 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) layer = FaultBlockLayer(grid, 0) with TestAreaContext("python/FaultBlocks/internal_blocks"): with open("faultblock.grdecl", "w") as fileH: @@ -398,7 +398,7 @@ def test_internal_blocks(self): fileH.write("/\n") with cwrap.open("faultblock.grdecl") as f: - kw = EclKW.read_grdecl(f, "FAULTBLK", ecl_type=EclDataType.ECL_INT) + kw = ResdataKW.read_grdecl(f, "FAULTBLK", rd_type=ResDataType.RD_INT) with open("faults.grdecl", "w") as f: f.write("FAULTS\n") diff --git a/python/tests/ecl_tests/test_fault_blocks_equinor.py b/python/tests/rd_tests/test_fault_blocks_equinor.py similarity index 56% rename from python/tests/ecl_tests/test_fault_blocks_equinor.py rename to python/tests/rd_tests/test_fault_blocks_equinor.py index 9da3fc3985..3ab3b203b7 100644 --- a/python/tests/ecl_tests/test_fault_blocks_equinor.py +++ b/python/tests/rd_tests/test_fault_blocks_equinor.py @@ -4,23 +4,21 @@ except ImportError: from unittest import skipIf -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid -from tests import EclTest, equinor_test -from ecl.grid.faults import FaultBlock, FaultBlockLayer +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid +from tests import ResdataTest, equinor_test +from resdata.grid.faults import FaultBlock, FaultBlockLayer from cwrap import open as copen @equinor_test() -class FaultBlockTest(EclTest): +class FaultBlockTest(ResdataTest): def setUp(self): - self.grid = EclGrid( - self.createTestPath("Equinor/ECLIPSE/Mariner/MARINER.EGRID") - ) + self.grid = Grid(self.createTestPath("Equinor/ECLIPSE/Mariner/MARINER.EGRID")) fileH = copen(self.createTestPath("Equinor/ECLIPSE/Mariner/faultblock.grdecl")) - self.kw = EclKW.read_grdecl(fileH, "FAULTBLK", ecl_type=EclDataType.ECL_INT) + self.kw = ResdataKW.read_grdecl(fileH, "FAULTBLK", rd_type=ResDataType.RD_INT) def test_load(self): for k in range(self.grid.getNZ()): diff --git a/python/tests/ecl_tests/test_faults.py b/python/tests/rd_tests/test_faults.py similarity index 94% rename from python/tests/ecl_tests/test_faults.py rename to python/tests/rd_tests/test_faults.py index 0aced05095..abf5dab6a5 100644 --- a/python/tests/ecl_tests/test_faults.py +++ b/python/tests/rd_tests/test_faults.py @@ -1,27 +1,27 @@ #!/usr/bin/env python from unittest import skipIf import time -from ecl import util +from resdata import util -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid -from ecl.grid.faults import ( +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid +from resdata.grid.faults import ( FaultCollection, Fault, FaultLine, FaultSegment, FaultBlockLayer, ) -from ecl.util.test import TestAreaContext -from ecl.util.geometry import Polyline, CPolyline -from tests import EclTest +from resdata.util.test import TestAreaContext +from resdata.geometry import Polyline, CPolyline +from tests import ResdataTest -class FaultTest(EclTest): +class FaultTest(ResdataTest): @classmethod def setUpClass(cls): - cls.grid = EclGrid.createRectangular((151, 100, 50), (1, 1, 1)) + cls.grid = Grid.createRectangular((151, 100, 50), (1, 1, 1)) def setUp(self): self.faults1 = self.createTestPath("local/ECLIPSE/FAULTS/fault1.grdecl") @@ -31,7 +31,7 @@ def test_PolylineIJ(self): nx = 10 ny = 10 nz = 10 - grid = EclGrid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1)) + grid = Grid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1)) f = Fault(grid, "F") f.addRecord(0, 1, 0, 0, 0, 0, "Y-") f.addRecord(2, 2, 0, 1, 0, 0, "X-") @@ -112,7 +112,7 @@ def test_faultLine_center(self): nx = 10 ny = 10 nz = 2 - grid = EclGrid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1)) + grid = Grid.createRectangular((nx, ny, nz), (0.1, 0.1, 0.1)) fl = FaultLine(grid, 0) C1 = (nx + 1) * 5 + 3 C2 = C1 + 2 @@ -191,7 +191,7 @@ def test_load(self): faults.load(self.grid, "No/this/does/not/exist") def test_connect_faults(self): - grid = EclGrid.createRectangular((100, 100, 10), (1, 1, 1)) + grid = Grid.createRectangular((100, 100, 10), (1, 1, 1)) # Fault1 Fault4 # | | @@ -342,7 +342,7 @@ def test_intersect_intRays(self): self.assertEqual(join, [p1, p2]) def test_join_faults(self): - grid = EclGrid.createRectangular((100, 100, 10), (1, 1, 1)) + grid = Grid.createRectangular((100, 100, 10), (1, 1, 1)) # Fault1 Fault4 # | | @@ -373,7 +373,7 @@ def test_join_faults(self): self.assertEqual(extra, [(2, 10), (2, 6), (5, 6)]) def test_contact(self): - grid = EclGrid.createRectangular((100, 100, 10), (1, 1, 1)) + grid = Grid.createRectangular((100, 100, 10), (1, 1, 1)) # Fault1 Fault4 # | | @@ -471,7 +471,7 @@ def test_fault_line_order(self): nx = 120 ny = 60 nz = 43 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl", "w") as f: f.write( @@ -509,7 +509,7 @@ def test_neighbour_cells(self): nx = 10 ny = 8 nz = 7 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) faults_file = self.createTestPath("local/ECLIPSE/FAULTS/faults_nb.grdecl") faults = FaultCollection(grid, faults_file) @@ -570,7 +570,7 @@ def test_neighbour_cells(self): self.assertListEqual(nb_cells1, true_nb_cells1) def test_polyline_intersection(self): - grid = EclGrid.createRectangular((100, 100, 10), (0.25, 0.25, 1)) + grid = Grid.createRectangular((100, 100, 10), (0.25, 0.25, 1)) # Fault1 Fault4 # | | @@ -609,7 +609,7 @@ def test_num_linesegment(self): nx = 10 ny = 10 nz = 1 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl", "w") as f: f.write( @@ -628,7 +628,7 @@ def test_num_linesegment(self): self.assertEqual(1, f2.numLines(0)) def test_extend_to_polyline(self): - grid = EclGrid.createRectangular((3, 3, 1), (1, 1, 1)) + grid = Grid.createRectangular((3, 3, 1), (1, 1, 1)) # o o o o # @@ -655,7 +655,7 @@ def test_extend_to_polyline(self): self.assertIsNone(end_join) def test_extend_polyline_on(self): - grid = EclGrid.createRectangular((3, 3, 1), (1, 1, 1)) + grid = Grid.createRectangular((3, 3, 1), (1, 1, 1)) # o o o o # @@ -686,13 +686,13 @@ def test_extend_polyline_on(self): self.assertIsNone(points) def test_stepped(self): - grid = EclGrid.createRectangular((6, 1, 4), (1, 1, 1)) + grid = Grid.createRectangular((6, 1, 4), (1, 1, 1)) f = Fault(grid, "F") f.addRecord(4, 4, 0, 0, 0, 1, "X") f.addRecord(2, 2, 0, 0, 1, 1, "Z") f.addRecord(1, 1, 0, 0, 2, 3, "X") - block_kw = EclKW("FAULTBLK", grid.getGlobalSize(), EclDataType.ECL_INT) + block_kw = ResdataKW("FAULTBLK", grid.getGlobalSize(), ResDataType.RD_INT) block_kw.assign(1) block_kw[5] = 2 block_kw[11] = 2 @@ -725,7 +725,7 @@ def test_stepped(self): self.assertFalse(layer3.cellContact((1, 0), (2, 0))) def test_connectWithPolyline(self): - grid = EclGrid.createRectangular((4, 4, 1), (1, 1, 1)) + grid = Grid.createRectangular((4, 4, 1), (1, 1, 1)) # o o o o o # diff --git a/python/tests/ecl_tests/test_fk_user_data.py b/python/tests/rd_tests/test_fk_user_data.py similarity index 85% rename from python/tests/ecl_tests/test_fk_user_data.py rename to python/tests/rd_tests/test_fk_user_data.py index b96e6368d3..f468cc71df 100644 --- a/python/tests/ecl_tests/test_fk_user_data.py +++ b/python/tests/rd_tests/test_fk_user_data.py @@ -1,10 +1,10 @@ #!/usr/bin/env python -from ecl.grid import EclGrid -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.grid import Grid +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class FKTest(EclTest): +class FKTest(ResdataTest): def test_cell_containment(self): grid_location = "local/ECLIPSE/faarikaal/faarikaal%d.EGRID" well_location = "local/ECLIPSE/faarikaal/faarikaal%d.txt" @@ -13,7 +13,7 @@ def test_cell_containment(self): grid_file = self.createTestPath(grid_location % i) well_file = self.createTestPath(well_location % i) - grid = EclGrid(grid_file) + grid = Grid(grid_file) # Load well data with open(well_file, "r") as f: diff --git a/python/tests/ecl_tests/test_fortio.py b/python/tests/rd_tests/test_fortio.py similarity index 80% rename from python/tests/ecl_tests/test_fortio.py rename to python/tests/rd_tests/test_fortio.py index ff413c32b3..e2161a0df9 100755 --- a/python/tests/ecl_tests/test_fortio.py +++ b/python/tests/rd_tests/test_fortio.py @@ -2,13 +2,13 @@ import os import cwrap from random import randint -from ecl import EclDataType -from ecl.eclfile import FortIO, EclKW, openFortIO, EclFile -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata import ResDataType +from resdata.resfile import FortIO, ResdataKW, openFortIO, ResdataFile +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class FortIOTest(EclTest): +class FortIOTest(ResdataTest): def test_open_write(self): with TestAreaContext("python/fortio/write"): f = FortIO("newfile", FortIO.WRITE_MODE) @@ -19,8 +19,8 @@ def test_noex(self): f = FortIO("odes_not_exist", FortIO.READ_MODE) def test_kw(self): - kw1 = EclKW("KW1", 2, EclDataType.ECL_INT) - kw2 = EclKW("KW2", 2, EclDataType.ECL_INT) + kw1 = ResdataKW("KW1", 2, ResDataType.RD_INT) + kw2 = ResdataKW("KW2", 2, ResDataType.RD_INT) kw1[0] = 99 kw1[1] = 77 @@ -35,15 +35,15 @@ def test_kw(self): kw2.fwrite(f) f = FortIO("test", fmt_file=False) - k1 = EclKW.fread(f) - k2 = EclKW.fread(f) + k1 = ResdataKW.fread(f) + k2 = ResdataKW.fread(f) self.assertTrue(k1.equal(kw1)) self.assertTrue(k2.equal(kw2)) def test_truncate(self): - kw1 = EclKW("KW1", 2, EclDataType.ECL_INT) - kw2 = EclKW("KW2", 2, EclDataType.ECL_INT) + kw1 = ResdataKW("KW1", 2, ResDataType.RD_INT) + kw2 = ResdataKW("KW2", 2, ResDataType.RD_INT) kw1[0] = 99 kw1[1] = 77 @@ -65,7 +65,7 @@ def test_truncate(self): f.seek(pos1) f.truncate() - f = EclFile("file") + f = ResdataFile("file") self.assertEqual(len(f), 1) kw1_ = f[0] self.assertEqual(kw1, kw1_) @@ -82,7 +82,7 @@ def test_fortio_creation(self): def test_context(self): with TestAreaContext("python/fortio/context") as t: - kw1 = EclKW("KW", 2456, EclDataType.ECL_FLOAT) + kw1 = ResdataKW("KW", 2456, ResDataType.RD_FLOAT) for i in range(len(kw1)): kw1[i] = randint(0, 1000) @@ -91,13 +91,13 @@ def test_context(self): self.assertEqual(f.filename(), "file") with openFortIO("file") as f: - kw2 = EclKW.fread(f) + kw2 = ResdataKW.fread(f) self.assertTrue(kw1 == kw2) def test_is_fortran_file(self): with TestAreaContext("python/fortio/guess"): - kw1 = EclKW("KW", 12345, EclDataType.ECL_FLOAT) + kw1 = ResdataKW("KW", 12345, ResDataType.RD_FLOAT) with openFortIO("fortran_file", mode=FortIO.WRITE_MODE) as f: kw1.fwrite(f) diff --git a/python/tests/ecl_tests/test_geertsma.py b/python/tests/rd_tests/test_geertsma.py similarity index 77% rename from python/tests/ecl_tests/test_geertsma.py rename to python/tests/rd_tests/test_geertsma.py index e5d1994fe6..0485721ccb 100644 --- a/python/tests/ecl_tests/test_geertsma.py +++ b/python/tests/rd_tests/test_geertsma.py @@ -1,17 +1,17 @@ import datetime -from ecl import EclDataType -from ecl.eclfile import EclKW, openFortIO, FortIO, EclFile -from ecl.grid import EclGrid -from ecl.gravimetry import EclSubsidence +from resdata import ResDataType +from resdata.resfile import ResdataKW, openFortIO, FortIO, ResdataFile +from resdata.grid import Grid +from resdata.gravimetry import ResdataSubsidence -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.test import TestAreaContext +from tests import ResdataTest import numpy as np def create_init(grid, case): - poro = EclKW("PORO", grid.getNumActive(), EclDataType.ECL_FLOAT) + poro = ResdataKW("PORO", grid.getNumActive(), ResDataType.RD_FLOAT) porv = poro.copy() porv.setName("PORV") for g in range(grid.getGlobalSize()): @@ -24,13 +24,13 @@ def create_init(grid, case): def create_restart(grid, case, p1, p2=None, rporv1=None, rporv2=None): with openFortIO("%s.UNRST" % case, mode=FortIO.WRITE_MODE) as f: - seq_hdr = EclKW("SEQNUM", 1, EclDataType.ECL_FLOAT) + seq_hdr = ResdataKW("SEQNUM", 1, ResDataType.RD_FLOAT) seq_hdr[0] = 10 - p = EclKW("PRESSURE", grid.getNumActive(), EclDataType.ECL_FLOAT) + p = ResdataKW("PRESSURE", grid.getNumActive(), ResDataType.RD_FLOAT) for i in range(len(p1)): p[i] = p1[i] - header = EclKW("INTEHEAD", 67, EclDataType.ECL_INT) + header = ResdataKW("INTEHEAD", 67, ResDataType.RD_INT) header[64] = 1 header[65] = 1 header[66] = 2000 @@ -40,7 +40,7 @@ def create_restart(grid, case, p1, p2=None, rporv1=None, rporv2=None): p.fwrite(f) if rporv1: - rp = EclKW("RPORV", grid.getNumActive(), EclDataType.ECL_FLOAT) + rp = ResdataKW("RPORV", grid.getNumActive(), ResDataType.RD_FLOAT) for idx, val in enumerate(rporv1): rp[idx] = val @@ -57,28 +57,28 @@ def create_restart(grid, case, p1, p2=None, rporv1=None, rporv2=None): p.fwrite(f) if rporv2: - rp = EclKW("RPORV", grid.getNumActive(), EclDataType.ECL_FLOAT) + rp = ResdataKW("RPORV", grid.getNumActive(), ResDataType.RD_FLOAT) for idx, val in enumerate(rporv2): rp[idx] = val rp.fwrite(f) -class GeertsmaTest(EclTest): +class GeertsmaTest(ResdataTest): @staticmethod def test_geertsma_kernel(): - grid = EclGrid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) + grid = Grid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) with TestAreaContext("Subsidence"): p1 = [1] create_restart(grid, "TEST", p1) create_init(grid, "TEST") - init = EclFile("TEST.INIT") - restart_file = EclFile("TEST.UNRST") + init = ResdataFile("TEST.INIT") + restart_file = ResdataFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) - subsidence = EclSubsidence(grid, init) + subsidence = ResdataSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) youngs_modulus = 5e8 @@ -102,7 +102,7 @@ def test_geertsma_kernel(): @staticmethod def test_geertsma_kernel_2_source_points_2_vintages(): - grid = EclGrid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100)) + grid = Grid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100)) with TestAreaContext("Subsidence"): p1 = [1, 10] @@ -110,13 +110,13 @@ def test_geertsma_kernel_2_source_points_2_vintages(): create_restart(grid, "TEST", p1, p2) create_init(grid, "TEST") - init = EclFile("TEST.INIT") - restart_file = EclFile("TEST.UNRST") + init = ResdataFile("TEST.INIT") + restart_file = ResdataFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) restart_view2 = restart_file.restartView(sim_time=datetime.date(2010, 1, 1)) - subsidence = EclSubsidence(grid, init) + subsidence = ResdataSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) subsidence.add_survey_PRESSURE("S2", restart_view2) @@ -144,18 +144,18 @@ def test_geertsma_kernel_2_source_points_2_vintages(): @staticmethod def test_geertsma_kernel_seabed(): - grid = EclGrid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) + grid = Grid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) with TestAreaContext("Subsidence"): p1 = [1] create_restart(grid, "TEST", p1) create_init(grid, "TEST") - init = EclFile("TEST.INIT") - restart_file = EclFile("TEST.UNRST") + init = ResdataFile("TEST.INIT") + restart_file = ResdataFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) - subsidence = EclSubsidence(grid, init) + subsidence = ResdataSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) youngs_modulus = 5e8 @@ -172,18 +172,18 @@ def test_geertsma_kernel_seabed(): @staticmethod def test_geertsma_kernel_seabed(): - grid = EclGrid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) + grid = Grid.createRectangular(dims=(1, 1, 1), dV=(50, 50, 50)) with TestAreaContext("Subsidence"): p1 = [1] create_restart(grid, "TEST", p1) create_init(grid, "TEST") - init = EclFile("TEST.INIT") - restart_file = EclFile("TEST.UNRST") + init = ResdataFile("TEST.INIT") + restart_file = ResdataFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) - subsidence = EclSubsidence(grid, init) + subsidence = ResdataSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) youngs_modulus = 5e8 @@ -199,7 +199,7 @@ def test_geertsma_kernel_seabed(): np.testing.assert_almost_equal(dz, 5.819790154474284e-08) def test_geertsma_rporv_kernel_2_source_points_2_vintages(self): - grid = EclGrid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100)) + grid = Grid.createRectangular(dims=(2, 1, 1), dV=(100, 100, 100)) with TestAreaContext("Subsidence"): p1 = [1, 10] @@ -214,13 +214,13 @@ def test_geertsma_rporv_kernel_2_source_points_2_vintages(self): ) create_init(grid, "TEST") - init = EclFile("TEST.INIT") - restart_file = EclFile("TEST.UNRST") + init = ResdataFile("TEST.INIT") + restart_file = ResdataFile("TEST.UNRST") restart_view1 = restart_file.restartView(sim_time=datetime.date(2000, 1, 1)) restart_view2 = restart_file.restartView(sim_time=datetime.date(2010, 1, 1)) - subsidence = EclSubsidence(grid, init) + subsidence = ResdataSubsidence(grid, init) subsidence.add_survey_PRESSURE("S1", restart_view1) subsidence.add_survey_PRESSURE("S2", restart_view2) diff --git a/python/tests/rd_tests/test_grav.py b/python/tests/rd_tests/test_grav.py new file mode 100644 index 0000000000..149a647315 --- /dev/null +++ b/python/tests/rd_tests/test_grav.py @@ -0,0 +1,24 @@ +import time +from resdata import ResDataType +from resdata.resfile import ResdataKW, ResdataFile, openFortIO, FortIO +from resdata.grid import Grid +from resdata.gravimetry import ResdataGrav +from resdata.util.test import TestAreaContext +from tests import ResdataTest + + +class ResdataGravTest(ResdataTest): + def setUp(self): + self.grid = Grid.createRectangular((10, 10, 10), (1, 1, 1)) + + def test_create(self): + # The init file created here only contains a PORO field. More + # properties must be added to this before it can be used for + # any usefull gravity calculations. + poro = ResdataKW("PORO", self.grid.getGlobalSize(), ResDataType.RD_FLOAT) + with TestAreaContext("grav_init"): + with openFortIO("TEST.INIT", mode=FortIO.WRITE_MODE) as f: + poro.fwrite(f) + self.init = ResdataFile("TEST.INIT") + + grav = ResdataGrav(self.grid, self.init) diff --git a/python/tests/ecl_tests/test_grdecl.py b/python/tests/rd_tests/test_grdecl.py similarity index 85% rename from python/tests/ecl_tests/test_grdecl.py rename to python/tests/rd_tests/test_grdecl.py index 8621f0c15c..2d22a54892 100644 --- a/python/tests/ecl_tests/test_grdecl.py +++ b/python/tests/rd_tests/test_grdecl.py @@ -1,7 +1,7 @@ from numpy import allclose import cwrap -from ecl.eclfile import EclKW +from resdata.resfile import ResdataKW def test_eclkw_read_grdecl(tmp_path): @@ -15,7 +15,7 @@ def test_eclkw_read_grdecl(tmp_path): f.write("/\n") with cwrap.open(str(tmp_path / "test.grdecl")) as f: - kw = EclKW.read_grdecl(f, "COORD") + kw = ResdataKW.read_grdecl(f, "COORD") assert kw.get_name() == "COORD" assert len(kw.numpy_view()) == block_size * num_blocks diff --git a/python/tests/rd_tests/test_grdrd_equinor.py b/python/tests/rd_tests/test_grdrd_equinor.py new file mode 100755 index 0000000000..05113ad4c1 --- /dev/null +++ b/python/tests/rd_tests/test_grdrd_equinor.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python +import os +from resdata.resfile import ResdataKW, Resdata3DKW +from resdata.grid import Grid +from tests import ResdataTest, equinor_test + +from cwrap import open as copen + + +@equinor_test() +class GRDECLEquinorTest(ResdataTest): + def setUp(self): + self.src_file = self.createTestPath( + "Equinor/ECLIPSE/Gurbat/include/example_permx.GRDECL" + ) + self.file_list = [] + + def addFile(self, filename): + self.file_list.append(filename) + + def tearDown(self): + for f in self.file_list: + if os.path.exists(f): + os.unlink(f) + + def test_Load(self): + kw = ResdataKW.read_grdecl(copen(self.src_file, "r"), "PERMX") + self.assertTrue(kw) + + grid = Grid(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE")) + kw = Resdata3DKW.read_grdecl(grid, copen(self.src_file, "r"), "PERMX") + self.assertTrue(isinstance(kw, Resdata3DKW)) + + def test_reload(self): + kw = ResdataKW.read_grdecl(copen(self.src_file, "r"), "PERMX") + tmp_file1 = "/tmp/permx1.grdecl" + tmp_file2 = "/tmp/permx2.grdecl" + self.addFile(tmp_file1) + self.addFile(tmp_file2) + + fileH = copen(tmp_file1, "w") + kw.write_grdecl(fileH) + fileH.close() + + kw1 = ResdataKW.read_grdecl(copen(tmp_file1, "r"), "PERMX") + + fileH = copen(tmp_file2, "w") + kw1.write_grdecl(fileH) + fileH.close() + + self.assertFilesAreEqual(tmp_file1, tmp_file2) + + def test_fseek(self): + file = copen(self.src_file, "r") + self.assertTrue(ResdataKW.fseek_grdecl(file, "PERMX")) + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMY")) + file.close() + + file = copen(self.src_file, "r") + kw1 = ResdataKW.read_grdecl(file, "PERMX") + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMX")) + self.assertTrue(ResdataKW.fseek_grdecl(file, "PERMX", rewind=True)) + file.close() + + def test_fseek2(self): + test_src = self.createTestPath("local/ECLIPSE/grdecl-test/test.grdecl") + # Test kw at the the very start + file = copen(test_src, "r") + self.assertTrue(ResdataKW.fseek_grdecl(file, "PERMX")) + + # Test commented out kw: + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMY")) + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMZ")) + + # Test ignore not start of line: + self.assertTrue(ResdataKW.fseek_grdecl(file, "MARKER")) + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMXYZ")) + + # Test rewind + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMX", rewind=False)) + self.assertTrue(ResdataKW.fseek_grdecl(file, "PERMX", rewind=True)) + + # Test multiline comments + blanks + self.assertTrue(ResdataKW.fseek_grdecl(file, "LASTKW")) + + def test_fseek_dos(self): + test_src = self.createTestPath( + "local/ECLIPSE/grdecl-test/test.grdecl_dos" + ) # File formatted with \r\n line endings. + # Test kw at the the very start + file = copen(test_src, "r") + self.assertTrue(ResdataKW.fseek_grdecl(file, "PERMX")) + + # Test commented out kw: + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMY")) + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMZ")) + + # Test ignore not start of line: + self.assertTrue(ResdataKW.fseek_grdecl(file, "MARKER")) + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMXYZ")) + + # Test rewind + self.assertFalse(ResdataKW.fseek_grdecl(file, "PERMX", rewind=False)) + self.assertTrue(ResdataKW.fseek_grdecl(file, "PERMX", rewind=True)) + + # Test multiline comments + blanks + self.assertTrue(ResdataKW.fseek_grdecl(file, "LASTKW")) diff --git a/python/tests/ecl_tests/test_grid.py b/python/tests/rd_tests/test_grid.py similarity index 93% rename from python/tests/ecl_tests/test_grid.py rename to python/tests/rd_tests/test_grid.py index 91a0269e72..5ebe59635f 100644 --- a/python/tests/ecl_tests/test_grid.py +++ b/python/tests/rd_tests/test_grid.py @@ -6,13 +6,13 @@ import six from numpy import linspace, allclose -from ecl.util.util import IntVector -from ecl import EclDataType, EclUnitTypeEnum -from ecl.eclfile import EclKW, EclFile -from ecl.grid import EclGrid -from ecl.grid import EclGridGenerator as GridGen -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.util import IntVector +from resdata import ResDataType, UnitSystem +from resdata.resfile import ResdataKW, ResdataFile +from resdata.grid import Grid +from resdata.grid import GridGenerator as GridGen +from resdata.util.test import TestAreaContext +from tests import ResdataTest # This dict is used to verify that corners are mapped to the correct # cell with respect to containment. @@ -186,7 +186,7 @@ def average(points): # This test class should only have test cases which do not require # external test data. Tests involving Equinor test data are in the # test_grid_equinor module. -class GridTest(EclTest): +class GridTest(ResdataTest): def test_oom_grid(self): nx = 2000 ny = 2000 @@ -251,7 +251,7 @@ def test_create(self): def test_all_iters(self): fk = self.createTestPath("local/ECLIPSE/faarikaal/faarikaal1.EGRID") - grid = EclGrid(fk) + grid = Grid(fk) cell = grid[3455] self.assertEqual(3455, cell.global_index) cell = grid[(4, 1, 82)] @@ -274,14 +274,14 @@ def test_repr_and_name(self): grid = GridGen.createRectangular( (2, 2, 2), (10, 10, 10), actnum=[0, 0, 0, 0, 1, 1, 1, 1] ) - pfx = "EclGrid(" + pfx = "Grid(" rep = repr(grid) self.assertEqual(pfx, rep[: len(pfx)]) self.assertEqual(type(rep), type("")) self.assertEqual(type(grid.getName()), type("")) - with TestAreaContext("python/ecl_grid/repr"): + with TestAreaContext("python/rd_grid/repr"): grid.save_EGRID("CASE.EGRID") - g2 = EclGrid("CASE.EGRID") + g2 = Grid("CASE.EGRID") r2 = repr(g2) self.assertEqual(pfx, r2[: len(pfx)]) self.assertEqual(type(r2), type("")) @@ -301,13 +301,13 @@ def test_node_pos(self): p7 = grid.getNodePos(10, 20, 30) self.assertEqual(p7, (10, 20, 30)) - # The broken file was previously handled by the ecl_file_open() call internally - # in the ecl_grid implementation. That will now not fail for a broken file, and then + # The broken file was previously handled by the rd_file_open() call internally + # in the rd_grid implementation. That will now not fail for a broken file, and then # the grid class needs to do more/better checking itself. - @skip("Needs better error checking inside in the ecl_grid") + @skip("Needs better error checking inside in the rd_grid") def test_truncated_file(self): grid = GridGen.createRectangular((10, 20, 30), (1, 1, 1)) - with TestAreaContext("python/ecl_grid/truncated"): + with TestAreaContext("python/rd_grid/truncated"): grid.save_EGRID("TEST.EGRID") size = os.path.getsize("TEST.EGRID") @@ -315,7 +315,7 @@ def test_truncated_file(self): f.truncate(size / 2) with self.assertRaises(IOError): - EclGrid("TEST.EGRID") + Grid("TEST.EGRID") def test_posXY1(self): nx = 4 @@ -390,7 +390,7 @@ def test_compressed_copy(self): ny = 10 nz = 10 grid = GridGen.createRectangular((nx, ny, nz), (1, 1, 1)) - kw1 = EclKW("KW", 1001, EclDataType.ECL_INT) + kw1 = ResdataKW("KW", 1001, ResDataType.RD_INT) with self.assertRaises(ValueError): cp = grid.compressedKWCopy(kw1) @@ -410,7 +410,7 @@ def test_create_3d_is_create_kw_inverse(self): ny = 7 nz = 5 grid = GridGen.create_rectangular((nx, ny, nz), (1, 1, 1)) - kw1 = EclKW("SWAT", nx * ny * nz, EclDataType.ECL_FLOAT) + kw1 = ResdataKW("SWAT", nx * ny * nz, ResDataType.RD_FLOAT) for k, j, i in itertools.product(range(nz), range(ny), range(nx)): kw1[i + j * nx + nx * ny * k] = i * j * k numpy_3d = grid.create3D(kw1) @@ -423,7 +423,7 @@ def test_create_3d_agrees_with_get_value(self): ny = 3 nz = 2 grid = GridGen.createRectangular((nx, ny, nz), (1, 1, 1)) - kw = EclKW("SWAT", nx * ny * nz, EclDataType.ECL_FLOAT) + kw = ResdataKW("SWAT", nx * ny * nz, ResDataType.RD_FLOAT) for k, j, i in itertools.product(range(nz), range(ny), range(nx)): kw[i + j * nx + nx * ny * k] = i * j * k numpy_3d = grid.create3D(kw) @@ -434,7 +434,7 @@ def test_len(self): nx = 10 ny = 11 nz = 12 - actnum = EclKW("ACTNUM", nx * ny * nz, EclDataType.ECL_INT) + actnum = ResdataKW("ACTNUM", nx * ny * nz, ResDataType.RD_INT) actnum[0] = 1 actnum[1] = 1 actnum[2] = 1 @@ -449,7 +449,7 @@ def test_export(self): coord = GridGen.create_coord(dims, (1, 1, 1)) zcorn = GridGen.create_zcorn(dims, (1, 1, 1), offset=0) - grid = EclGrid.create(dims, zcorn, coord, None) + grid = Grid.create(dims, zcorn, coord, None) self.assertEqual(zcorn, grid.export_zcorn()) self.assertEqual(coord, grid.export_coord()) @@ -459,26 +459,26 @@ def test_output_units(self): a = 1 grid = GridGen.createRectangular((n, n, n), (a, a, a)) - with TestAreaContext("python/ecl_grid/units"): - grid.save_EGRID("CASE.EGRID", output_unit=EclUnitTypeEnum.ECL_FIELD_UNITS) - f = EclFile("CASE.EGRID") + with TestAreaContext("python/rd_grid/units"): + grid.save_EGRID("CASE.EGRID", output_unit=UnitSystem.FIELD) + f = ResdataFile("CASE.EGRID") g = f["GRIDUNIT"][0] self.assertEqual(g[0].strip(), "FEET") - g2 = EclGrid("CASE.EGRID") + g2 = Grid("CASE.EGRID") self.assertFloatEqual( g2.cell_volume(global_index=0), 3.28084 * 3.28084 * 3.28084 ) grid.save_EGRID("CASE.EGRID") - f = EclFile("CASE.EGRID") + f = ResdataFile("CASE.EGRID") g = f["GRIDUNIT"][0] self.assertEqual(g[0].strip(), "METRES") - grid.save_EGRID("CASE.EGRID", output_unit=EclUnitTypeEnum.ECL_LAB_UNITS) - f = EclFile("CASE.EGRID") + grid.save_EGRID("CASE.EGRID", output_unit=UnitSystem.LAB) + f = ResdataFile("CASE.EGRID") g = f["GRIDUNIT"][0] self.assertEqual(g[0].strip(), "CM") - g2 = EclGrid("CASE.EGRID") + g2 = Grid("CASE.EGRID") self.assertFloatEqual(g2.cell_volume(global_index=0), 100 * 100 * 100) def test_volume(self): diff --git a/python/tests/ecl_tests/test_grid_equinor.py b/python/tests/rd_tests/test_grid_equinor.py similarity index 81% rename from python/tests/ecl_tests/test_grid_equinor.py rename to python/tests/rd_tests/test_grid_equinor.py index a105f7c33c..d433fa8a38 100755 --- a/python/tests/ecl_tests/test_grid_equinor.py +++ b/python/tests/rd_tests/test_grid_equinor.py @@ -10,16 +10,16 @@ from cwrap import open as copen import time -from ecl import EclDataType, EclUnitTypeEnum -from ecl.eclfile import EclKW, EclFile, openEclFile -from ecl.grid import EclGrid -from ecl.util.util import DoubleVector, IntVector -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata import ResDataType, UnitSystem +from resdata.resfile import ResdataKW, ResdataFile, openResdataFile +from resdata.grid import Grid +from resdata.util.util import DoubleVector, IntVector +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test @equinor_test() -class GridTest(EclTest): +class GridTest(ResdataTest): def egrid_file(self): return self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") @@ -32,14 +32,14 @@ def grdecl_file(self): ) def test_loadFromFile(self): - g1 = EclGrid.loadFromFile(self.egrid_file()) - g2 = EclGrid.loadFromFile(self.grdecl_file()) + g1 = Grid.loadFromFile(self.egrid_file()) + g2 = Grid.loadFromFile(self.grdecl_file()) - self.assertTrue(isinstance(g1, EclGrid)) - self.assertTrue(isinstance(g2, EclGrid)) + self.assertTrue(isinstance(g1, Grid)) + self.assertTrue(isinstance(g2, Grid)) def test_corner(self): - grid = EclGrid(self.egrid_file()) + grid = Grid(self.egrid_file()) nx = grid.getNX() ny = grid.getNY() nz = grid.getNZ() @@ -87,11 +87,11 @@ def test_corner(self): grid.getLayerXYZ(0, nz + 1) def test_GRID(self): - grid = EclGrid(self.grid_file()) + grid = Grid(self.grid_file()) self.assertTrue(grid) def test_EGRID(self): - grid = EclGrid(self.egrid_file()) + grid = Grid(self.egrid_file()) self.assertTrue(grid) dims = grid.getDims() self.assertEqual(dims[0], grid.getNX()) @@ -100,18 +100,18 @@ def test_EGRID(self): def create(self, filename, load_actnum=True): fileH = copen(filename, "r") - specgrid = EclKW.read_grdecl( - fileH, "SPECGRID", ecl_type=EclDataType.ECL_INT, strict=False + specgrid = ResdataKW.read_grdecl( + fileH, "SPECGRID", rd_type=ResDataType.RD_INT, strict=False ) - zcorn = EclKW.read_grdecl(fileH, "ZCORN") - coord = EclKW.read_grdecl(fileH, "COORD") + zcorn = ResdataKW.read_grdecl(fileH, "ZCORN") + coord = ResdataKW.read_grdecl(fileH, "COORD") if load_actnum: - actnum = EclKW.read_grdecl(fileH, "ACTNUM", ecl_type=EclDataType.ECL_INT) + actnum = ResdataKW.read_grdecl(fileH, "ACTNUM", rd_type=ResDataType.RD_INT) else: actnum = None - mapaxes = EclKW.read_grdecl(fileH, "MAPAXES") - grid = EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes=mapaxes) + mapaxes = ResdataKW.read_grdecl(fileH, "MAPAXES") + grid = Grid.create(specgrid, zcorn, coord, actnum, mapaxes=mapaxes) return grid def test_rect(self): @@ -119,9 +119,9 @@ def test_rect(self): a1 = 1.0 a2 = 2.0 a3 = 3.0 - grid = EclGrid.createRectangular((9, 9, 9), (a1, a2, a3)) + grid = Grid.createRectangular((9, 9, 9), (a1, a2, a3)) grid.save_EGRID("rect.EGRID") - grid2 = EclGrid("rect.EGRID") + grid2 = Grid("rect.EGRID") self.assertTrue(grid) self.assertTrue(grid2) @@ -152,18 +152,18 @@ def test_create(self): def test_grdecl_load(self): with self.assertRaises(IOError): - grid = EclGrid.loadFromGrdecl("/file/does/not/exists") + grid = Grid.loadFromGrdecl("/file/does/not/exists") with TestAreaContext("python/grid-test/grdeclLoad"): with open("grid.grdecl", "w") as f: f.write("Hei ...") with self.assertRaises(ValueError): - grid = EclGrid.loadFromGrdecl("grid.grdecl") + grid = Grid.loadFromGrdecl("grid.grdecl") actnum = IntVector(default_value=1, initial_size=1000) actnum[0] = 0 - g1 = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + g1 = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) self.assertEqual(g1.getNumActive(), actnum.elementSum()) g1.save_EGRID("G.EGRID") @@ -171,7 +171,7 @@ def test_grdecl_load(self): f2.write("SPECGRID\n") f2.write(" 10 10 10 'F' /\n") - with openEclFile("G.EGRID") as f: + with openResdataFile("G.EGRID") as f: with copen("grid.grdecl", "a") as f2: coord_kw = f["COORD"][0] coord_kw.write_grdecl(f2) @@ -182,7 +182,7 @@ def test_grdecl_load(self): actnum_kw = f["ACTNUM"][0] actnum_kw.write_grdecl(f2) - g2 = EclGrid.loadFromGrdecl("grid.grdecl") + g2 = Grid.loadFromGrdecl("grid.grdecl") self.assertTrue(g1.equal(g2)) def test_ACTNUM(self): @@ -192,21 +192,21 @@ def test_ACTNUM(self): def test_time(self): t0 = time.perf_counter() - g1 = EclGrid(self.egrid_file()) + g1 = Grid(self.egrid_file()) t1 = time.perf_counter() t = t1 - t0 self.assertTrue(t < 1.0) def test_save(self): with TestAreaContext("python/grid-test/testSave"): - g1 = EclGrid(self.egrid_file()) + g1 = Grid(self.egrid_file()) g1.save_EGRID("test.EGRID") - g2 = EclGrid("test.EGRID") + g2 = Grid("test.EGRID") self.assertTrue(g1.equal(g2)) g1.save_GRID("test.GRID") - g2 = EclGrid("test.GRID") + g2 = Grid("test.GRID") self.assertTrue(g1.equal(g2)) fileH = copen("test.grdecl", "w") @@ -217,10 +217,10 @@ def test_save(self): def test_raise_IO_error(self): with self.assertRaises(IOError): - g = EclGrid("/does/not/exist.EGRID") + g = Grid("/does/not/exist.EGRID") def test_boundingBox(self): - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1)) with self.assertRaises(ValueError): bbox = grid.getBoundingBox2D(layer=-1) @@ -246,7 +246,8 @@ def test_boundingBox(self): self.assertEqual(bbox, ((3, 3), (7, 3), (7, 7), (3, 7))) @skipIf( - EclTest.slowTestShouldNotRun(), "Slow test of numActive large memory skipped!" + ResdataTest.slowTestShouldNotRun(), + "Slow test of numActive large memory skipped!", ) def test_num_active_large_memory(self): case = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE") @@ -256,8 +257,8 @@ def test_num_active_large_memory(self): vec[81920] = 0 vecList.append(vec) - grid1 = EclGrid(case) - grid2 = EclGrid(case) + grid1 = Grid(case) + grid2 = Grid(case) self.assertEqual(grid1.getNumActive(), grid2.getNumActive()) self.assertEqual(grid1.getNumActive(), 34770) @@ -269,7 +270,7 @@ def test_no_mapaxes_check_for_nan(self): for grid_path in grid_paths: test_grid_path = self.createTestPath(grid_path) - grid = EclGrid(test_grid_path) + grid = Grid(test_grid_path) xyz = grid.get_xyz(ijk=(0, 0, 0)) self.assertFalse(math.isnan(xyz[0])) @@ -282,7 +283,7 @@ def test_no_mapaxes_check_for_nan(self): self.assertFalse(math.isnan(xyz[2])) def test_valid_geometry(self): - grid = EclGrid( + grid = Grid( self.createTestPath( "Equinor/ECLIPSE/GRID_INVALID_CELL/PRED_RESEST_0_R_13_0.GRID" ) @@ -291,7 +292,7 @@ def test_valid_geometry(self): self.assertFalse(grid.validCellGeometry(ijk=(0, 0, 0))) def test_volume_kw(self): - grid = EclGrid(self.egrid_file()) + grid = Grid(self.egrid_file()) vol = grid.createVolumeKeyword() self.assertEqual(len(vol), grid.getNumActive()) for active_index, volume in enumerate(vol): @@ -303,7 +304,7 @@ def test_volume_kw(self): self.assertEqual(volume, grid.cell_volume(global_index=global_index)) def test_lgr_get(self): - grid = EclGrid( + grid = Grid( self.createTestPath( "Equinor/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID" ) diff --git a/python/tests/ecl_tests/test_grid_equinor_coarse.py b/python/tests/rd_tests/test_grid_equinor_coarse.py similarity index 81% rename from python/tests/ecl_tests/test_grid_equinor_coarse.py rename to python/tests/rd_tests/test_grid_equinor_coarse.py index 29f3aa10e3..7c63731052 100644 --- a/python/tests/ecl_tests/test_grid_equinor_coarse.py +++ b/python/tests/rd_tests/test_grid_equinor_coarse.py @@ -1,20 +1,18 @@ import itertools -from ecl.eclfile import EclRestartFile -from ecl.grid import EclGrid -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata.resfile import ResdataRestartFile +from resdata.grid import Grid +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test @equinor_test() -class GridCoarceTest(EclTest): +class GridCoarceTest(ResdataTest): def lgc_grid(self): - return EclGrid( - self.createTestPath("Equinor/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID") - ) + return Grid(self.createTestPath("Equinor/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID")) def lgc_restart(self, grid): - return EclRestartFile( + return ResdataRestartFile( grid, self.createTestPath("Equinor/ECLIPSE/LGCcase/LGC_TESTCASE2.UNRST") ) @@ -23,7 +21,7 @@ def test_save_roundtrip(self): g1 = self.lgc_grid() g1.save_EGRID("LGC.EGRID") - g2 = EclGrid("LGC.EGRID") + g2 = Grid("LGC.EGRID") self.assertTrue(g1.equal(g2, verbose=True)) self.assertEqual(g1.coarse_groups(), g2.coarse_groups()) diff --git a/python/tests/ecl_tests/test_grid_equinor_dual.py b/python/tests/rd_tests/test_grid_equinor_dual.py similarity index 85% rename from python/tests/ecl_tests/test_grid_equinor_dual.py rename to python/tests/rd_tests/test_grid_equinor_dual.py index 2f64175a68..731abd31f3 100644 --- a/python/tests/ecl_tests/test_grid_equinor_dual.py +++ b/python/tests/rd_tests/test_grid_equinor_dual.py @@ -1,13 +1,13 @@ import math -from ecl.util.test import TestAreaContext -from ecl.grid import EclGrid +from resdata.util.test import TestAreaContext +from resdata.grid import Grid -from tests import EclTest, equinor_test +from tests import ResdataTest, equinor_test @equinor_test() -class GridDualTest(EclTest): +class GridDualTest(ResdataTest): def egrid_file(self): return self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") @@ -16,21 +16,21 @@ def grid_file(self): def test_dual(self): with TestAreaContext("python/grid-test/testDual"): - grid = EclGrid(self.egrid_file()) + grid = Grid(self.egrid_file()) self.assertFalse(grid.dualGrid()) self.assertTrue(grid.getNumActiveFracture() == 0) - grid2 = EclGrid(self.grid_file()) + grid2 = Grid(self.grid_file()) self.assertFalse(grid.dualGrid()) self.assertTrue(grid.getNumActiveFracture() == 0) - dgrid = EclGrid( + dgrid = Grid( self.createTestPath("Equinor/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID") ) self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture()) self.assertTrue(dgrid.getNumActive() == 46118) - dgrid2 = EclGrid( + dgrid2 = Grid( self.createTestPath("Equinor/ECLIPSE/DualPoro/DUALPOR_MSW.GRID") ) self.assertTrue(dgrid.getNumActive() == dgrid.getNumActiveFracture()) @@ -40,7 +40,7 @@ def test_dual(self): # The DUAL_DIFF grid has been manipulated to create a # situation where some cells are only matrix active, and some # cells are only fracture active. - dgrid = EclGrid( + dgrid = Grid( self.createTestPath("Equinor/ECLIPSE/DualPoro/DUAL_DIFF.EGRID") ) self.assertTrue(dgrid.getNumActive() == 106) @@ -57,5 +57,5 @@ def test_dual(self): self.assertTrue(dgrid.get_global_index1F(2) == 5) dgrid.save_EGRID("DUAL_DIFF.EGRID") - dgrid2 = EclGrid("DUAL_DIFF.EGRID") + dgrid2 = Grid("DUAL_DIFF.EGRID") self.assertTrue(dgrid.equal(dgrid2, verbose=True)) diff --git a/python/tests/ecl_tests/test_grid_generator.py b/python/tests/rd_tests/test_grid_generator.py similarity index 92% rename from python/tests/ecl_tests/test_grid_generator.py rename to python/tests/rd_tests/test_grid_generator.py index 52d232b942..613f8ad8ed 100644 --- a/python/tests/ecl_tests/test_grid_generator.py +++ b/python/tests/rd_tests/test_grid_generator.py @@ -5,12 +5,12 @@ import numpy import six -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid -from ecl.grid import EclGridGenerator as GridGen -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid +from resdata.grid import GridGenerator as GridGen +from resdata.util.test import TestAreaContext +from tests import ResdataTest def generate_ijk_bounds(dims): @@ -24,7 +24,7 @@ def decomposition_preserving(ijk_bound): return sum(list(zip(*ijk_bound))[0]) % 2 is 0 -class GridGeneratorTest(EclTest): +class GridGeneratorTest(ResdataTest): def setUp(self): self.test_base = [ ( @@ -130,7 +130,7 @@ def test_validate_cells(self): grid_dims, coord, zcorn, ijk_bound ) - subgrid = EclGrid.create(sub_dims, sub_zcorn, sub_coord, None) + subgrid = Grid.create(sub_dims, sub_zcorn, sub_coord, None) self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) self.assertSubgrid(grid, subgrid, ijk_bound) @@ -140,14 +140,14 @@ def test_actnum_extraction(self): coord = GridGen.create_coord(dims, (1, 1, 1)) zcorn = GridGen.create_zcorn(dims, (1, 1, 1), offset=0) - actnum = EclKW( - "ACTNUM", six.functools.reduce(operator.mul, dims), EclDataType.ECL_INT + actnum = ResdataKW( + "ACTNUM", six.functools.reduce(operator.mul, dims), ResDataType.RD_INT ) random.seed(1337) for i in range(len(actnum)): actnum[i] = random.randint(0, 1) - grid = EclGrid.create(dims, zcorn, coord, actnum) + grid = Grid.create(dims, zcorn, coord, actnum) ijk_bounds = generate_ijk_bounds(dims) for ijk_bound in ijk_bounds: @@ -160,7 +160,7 @@ def test_actnum_extraction(self): sub_coord, sub_zcorn, sub_actnum = sub sub_dims = tuple([u - l + 1 for l, u in ijk_bound]) - subgrid = EclGrid.create(sub_dims, sub_zcorn, sub_coord, sub_actnum) + subgrid = Grid.create(sub_dims, sub_zcorn, sub_coord, sub_actnum) self.assertEqual(sub_dims, subgrid.getDims()[:-1:]) self.assertSubgrid(grid, subgrid, ijk_bound) @@ -169,7 +169,7 @@ def test_translation(self): coord = GridGen.create_coord(dims, (1, 1, 1)) zcorn = GridGen.create_zcorn(dims, (1, 1, 1), offset=0) - grid = EclGrid.create(dims, zcorn, coord, None) + grid = Grid.create(dims, zcorn, coord, None) ijk_bound = [(0, d - 1) for d in dims] translation = (1, 2, 3) @@ -177,7 +177,7 @@ def test_translation(self): dims, coord, zcorn, ijk_bound, translation=translation ) - tgrid = EclGrid.create(dims, sub_zcorn, sub_coord, None) + tgrid = Grid.create(dims, sub_zcorn, sub_coord, None) self.assertEqual(grid.getGlobalSize(), tgrid.getGlobalSize()) for gi in range(grid.getGlobalSize()): @@ -215,11 +215,11 @@ def test_subgrid_translation(self): ) # Create grid with MAPAXES - mapaxes = EclKW("MAPAXES", 6, EclDataType.ECL_FLOAT) + mapaxes = ResdataKW("MAPAXES", 6, ResDataType.RD_FLOAT) for i, val in enumerate([1200, 1400, 2500, 2500, 3700, 4000]): mapaxes[i] = val - grid = EclGrid.create( + grid = Grid.create( grid.getDims(), grid.export_zcorn(), grid.export_coord(), diff --git a/python/tests/ecl_tests/test_grid_large_case.py b/python/tests/rd_tests/test_grid_large_case.py similarity index 95% rename from python/tests/ecl_tests/test_grid_large_case.py rename to python/tests/rd_tests/test_grid_large_case.py index 5c028108cd..b08ed8d6fc 100644 --- a/python/tests/ecl_tests/test_grid_large_case.py +++ b/python/tests/rd_tests/test_grid_large_case.py @@ -1,7 +1,7 @@ import itertools import pytest -from ecl.grid import EclGrid +from resdata.grid import Grid def write_zero_grdecl(file_path, num_x, num_y, num_z): @@ -54,7 +54,7 @@ def test_large_case(tmp_path): write_zero_grdecl(big_grdecl, num_x, num_y, num_z) - grid = EclGrid.load_from_grdecl(str(big_grdecl)) + grid = Grid.load_from_grdecl(str(big_grdecl)) assert grid.get_nx() == num_x assert grid.get_ny() == num_y assert grid.get_nz() == num_z diff --git a/python/tests/ecl_tests/test_grid_pandas.py b/python/tests/rd_tests/test_grid_pandas.py similarity index 90% rename from python/tests/ecl_tests/test_grid_pandas.py rename to python/tests/rd_tests/test_grid_pandas.py index 6332592b73..15158d08e3 100644 --- a/python/tests/ecl_tests/test_grid_pandas.py +++ b/python/tests/rd_tests/test_grid_pandas.py @@ -2,27 +2,25 @@ import numpy as np import pandas as pd -from ecl import EclTypeEnum +from resdata import ResdataTypeEnum -from ecl.eclfile import EclKW +from resdata.resfile import ResdataKW -from ecl.grid import EclGrid +from resdata.grid import Grid -from tests import EclTest +from tests import ResdataTest -class GridPandasTest(EclTest): +class GridPandasTest(ResdataTest): def test_dataframe_actnum(self): - grid = EclGrid.create_rectangular( - (2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1] - ) + grid = Grid.create_rectangular((2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1]) df = grid.export_index(True) index_matrix = np.array( [[0, 0, 0, 0], [1, 0, 0, 1], [0, 2, 0, 2], [1, 2, 0, 3]] ) assert np.array_equal(df.values, index_matrix) - kw_int_active = EclKW("int_act", 4, EclTypeEnum.ECL_INT_TYPE) + kw_int_active = ResdataKW("int_act", 4, ResdataTypeEnum.RD_INT_TYPE) kw_int_active[0] = 9 kw_int_active[1] = 8 kw_int_active[2] = 7 @@ -31,7 +29,7 @@ def test_dataframe_actnum(self): assert len(data) == 4 assert np.array_equal(data, np.array([9, 8, 7, 6])) - kw_float_active = EclKW("float_at", 4, EclTypeEnum.ECL_FLOAT_TYPE) + kw_float_active = ResdataKW("float_at", 4, ResdataTypeEnum.RD_FLOAT_TYPE) kw_float_active[0] = 10.5 kw_float_active[1] = 9.25 kw_float_active[2] = 2.0 @@ -40,7 +38,7 @@ def test_dataframe_actnum(self): assert len(data) == 4 assert np.array_equal(data, np.array([10.5, 9.25, 2.0, 1.625])) - kw_int_global = EclKW("int_glob", 6, EclTypeEnum.ECL_INT_TYPE) + kw_int_global = ResdataKW("int_glob", 6, ResdataTypeEnum.RD_INT_TYPE) kw_int_global[0] = 0 kw_int_global[1] = 2 kw_int_global[2] = 4 @@ -51,7 +49,7 @@ def test_dataframe_actnum(self): assert len(data) == 4 assert np.array_equal(data, np.array([0, 2, 8, 9])) - kw_double_global = EclKW("double_g", 6, EclTypeEnum.ECL_DOUBLE_TYPE) + kw_double_global = ResdataKW("double_g", 6, ResdataTypeEnum.RD_DOUBLE_TYPE) kw_double_global[0] = 1.1 kw_double_global[1] = 2.2 kw_double_global[2] = 3.3 @@ -72,9 +70,7 @@ def test_dataframe_actnum(self): assert np.array_equal(data, np.array([10.5, 9.25, 2222.0, 2222.0, 2.0, 1.625])) def test_dataframe_grid_data(self): - grid = EclGrid.create_rectangular( - (2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1] - ) + grid = Grid.create_rectangular((2, 3, 1), (1, 1, 1), actnum=[1, 1, 0, 0, 1, 1]) index_frame = grid.export_index() volume_data = grid.export_volume(index_frame) assert len(volume_data) == 6 diff --git a/python/tests/ecl_tests/test_indexed_read.py b/python/tests/rd_tests/test_indexed_read.py similarity index 61% rename from python/tests/ecl_tests/test_indexed_read.py rename to python/tests/rd_tests/test_indexed_read.py index 2952f3aa7c..76d6dcf71d 100644 --- a/python/tests/ecl_tests/test_indexed_read.py +++ b/python/tests/rd_tests/test_indexed_read.py @@ -1,44 +1,44 @@ import ctypes -import ecl +import resdata -from ecl import EclPrototype -from ecl import EclDataType -from ecl.eclfile import EclKW, EclFile, FortIO -from ecl.util.test import TestAreaContext -from tests import EclTest -from ecl.util.util import IntVector +from resdata import ResdataPrototype +from resdata import ResDataType +from resdata.resfile import ResdataKW, ResdataFile, FortIO +from resdata.util.test import TestAreaContext +from tests import ResdataTest +from resdata.util.util import IntVector -class EclIndexedReadTest(EclTest): - _freadIndexedData = EclPrototype( - "void ecl_kw_fread_indexed_data_python(fortio, int, ecl_data_type, int, int_vector, char*)", +class ResdataIndexedReadTest(ResdataTest): + _freadIndexedData = ResdataPrototype( + "void rd_kw_fread_indexed_data_python(fortio, int, rd_data_type, int, int_vector, char*)", bind=False, ) # fortio, offset, type, count, index_map, buffer - _eclFileIndexedRead = EclPrototype( - "void ecl_file_indexed_read(ecl_file, char*, int, int_vector, char*)", + _resFileIndexedRead = ResdataPrototype( + "void rd_file_indexed_read(rd_file, char*, int, int_vector, char*)", bind=False, - ) # ecl_file, kw, index, index_map, buffer + ) # rd_file, kw, index, index_map, buffer - def test_ecl_kw_indexed_read(self): - with TestAreaContext("ecl_kw_indexed_read") as area: + def test_rd_kw_indexed_read(self): + with TestAreaContext("rd_kw_indexed_read") as area: fortio = FortIO("index_test", mode=FortIO.WRITE_MODE) element_count = 100000 - ecl_kw = EclKW("TEST", element_count, EclDataType.ECL_INT) + rd_kw = ResdataKW("TEST", element_count, ResDataType.RD_INT) for index in range(element_count): - ecl_kw[index] = index + rd_kw[index] = index - ecl_kw.fwrite(fortio) + rd_kw.fwrite(fortio) fortio.close() fortio = FortIO("index_test", mode=FortIO.READ_MODE) - new_ecl_kw = EclKW.fread(fortio) + new_rd_kw = ResdataKW.fread(fortio) for index in range(element_count): - self.assertEqual(new_ecl_kw[index], index) + self.assertEqual(new_rd_kw[index], index) index_map = IntVector() index_map.append(2) @@ -65,7 +65,12 @@ def test_ecl_kw_indexed_read(self): ) self._freadIndexedData( - fortio, 24, EclDataType.ECL_INT, element_count, index_map, char_buffer + fortio, + 24, + ResDataType.RD_INT, + element_count, + index_map, + char_buffer, ) int_buffer = ctypes.cast(char_buffer, ctypes.POINTER(ctypes.c_int)) @@ -73,24 +78,24 @@ def test_ecl_kw_indexed_read(self): for index, index_map_value in enumerate(index_map): self.assertEqual(index_map_value, int_buffer[index]) - def test_ecl_file_indexed_read(self): - with TestAreaContext("ecl_file_indexed_read") as area: - fortio = FortIO("ecl_file_index_test", mode=FortIO.WRITE_MODE) + def test_rd_file_indexed_read(self): + with TestAreaContext("rd_file_indexed_read") as area: + fortio = FortIO("rd_file_index_test", mode=FortIO.WRITE_MODE) element_count = 100000 - ecl_kw_1 = EclKW("TEST1", element_count, EclDataType.ECL_INT) - ecl_kw_2 = EclKW("TEST2", element_count, EclDataType.ECL_INT) + rd_kw_1 = ResdataKW("TEST1", element_count, ResDataType.RD_INT) + rd_kw_2 = ResdataKW("TEST2", element_count, ResDataType.RD_INT) for index in range(element_count): - ecl_kw_1[index] = index - ecl_kw_2[index] = index + 3 + rd_kw_1[index] = index + rd_kw_2[index] = index + 3 - ecl_kw_1.fwrite(fortio) - ecl_kw_2.fwrite(fortio) + rd_kw_1.fwrite(fortio) + rd_kw_2.fwrite(fortio) fortio.close() - ecl_file = EclFile("ecl_file_index_test") + rd_file = ResdataFile("rd_file_index_test") index_map = IntVector() index_map.append(2) @@ -119,8 +124,8 @@ def test_ecl_file_indexed_read(self): len(index_map) * ctypes.sizeof(ctypes.c_int) ) - self._eclFileIndexedRead(ecl_file, "TEST2", 0, index_map, char_buffer_2) - self._eclFileIndexedRead(ecl_file, "TEST1", 0, index_map, char_buffer_1) + self._resFileIndexedRead(rd_file, "TEST2", 0, index_map, char_buffer_2) + self._resFileIndexedRead(rd_file, "TEST1", 0, index_map, char_buffer_1) int_buffer_1 = ctypes.cast(char_buffer_1, ctypes.POINTER(ctypes.c_int)) int_buffer_2 = ctypes.cast(char_buffer_2, ctypes.POINTER(ctypes.c_int)) diff --git a/python/tests/ecl_tests/test_kw_function.py b/python/tests/rd_tests/test_kw_function.py similarity index 69% rename from python/tests/ecl_tests/test_kw_function.py rename to python/tests/rd_tests/test_kw_function.py index b44f36ff91..dc1158b199 100644 --- a/python/tests/ecl_tests/test_kw_function.py +++ b/python/tests/rd_tests/test_kw_function.py @@ -1,14 +1,14 @@ #!/usr/bin/env python import os import random -from ecl import EclDataType -from ecl.eclfile import EclKW, Ecl3DKW -from ecl.grid import EclGrid -from ecl.util.util import IntVector -from tests import EclTest +from resdata import ResDataType +from resdata.resfile import ResdataKW, Resdata3DKW +from resdata.grid import Grid +from resdata.util.util import IntVector +from tests import ResdataTest -class KWFunctionTest(EclTest): +class KWFunctionTest(ResdataTest): def test_region_filter(self): nx = 10 ny = 10 @@ -16,10 +16,10 @@ def test_region_filter(self): actnum = IntVector(initial_size=nx * ny * nz, default_value=1) actnum[nx * ny - 1] = 0 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1), actnum=actnum) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1), actnum=actnum) self.assertEqual(grid.getNumActive(), nx * ny * nz - 1) - kw = Ecl3DKW.create("REGIONS", grid, EclDataType.ECL_INT, global_active=True) + kw = Resdata3DKW.create("REGIONS", grid, ResDataType.RD_INT, global_active=True) kw.assign(0) kw[0 : int(nx * ny / 2)] = 1 kw[5, 2, 0] = 0 @@ -43,15 +43,15 @@ def test_region_filter(self): self.assertEqual(kw[i, 7, 0], 1) def test_porv_kw(self): - porv_int = EclKW("PORV", 100, EclDataType.ECL_INT) + porv_int = ResdataKW("PORV", 100, ResDataType.RD_INT) with self.assertRaises(TypeError): actnum = porv_int.create_actnum() - prv = EclKW("PRV", 100, EclDataType.ECL_FLOAT) + prv = ResdataKW("PRV", 100, ResDataType.RD_FLOAT) with self.assertRaises(ValueError): actnum = prv.create_actnum() - porv = EclKW("PORV", 4, EclDataType.ECL_FLOAT) + porv = ResdataKW("PORV", 4, ResDataType.RD_FLOAT) porv[0] = 0 porv[1] = 0.50 porv[2] = 0.50 diff --git a/python/tests/ecl_tests/test_layer.py b/python/tests/rd_tests/test_layer.py similarity index 91% rename from python/tests/ecl_tests/test_layer.py rename to python/tests/rd_tests/test_layer.py index 028b02c34e..62e790c9d9 100644 --- a/python/tests/ecl_tests/test_layer.py +++ b/python/tests/rd_tests/test_layer.py @@ -2,15 +2,15 @@ from unittest import skipIf import time -from ecl.util.util import IntVector -from ecl.grid import EclGrid -from ecl.util.geometry import CPolyline -from ecl.grid.faults import Layer, FaultCollection -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.util import IntVector +from resdata.grid import Grid +from resdata.geometry import CPolyline +from resdata.grid.faults import Layer, FaultCollection +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class LayerTest(EclTest): +class LayerTest(ResdataTest): def setUp(self): pass @@ -36,7 +36,7 @@ def test_contact(self): nx = 20 ny = 10 layer = Layer(nx, ny) - grid = EclGrid.createRectangular((nx, ny, 1), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, 1), (1, 1, 1)) with self.assertRaises(IndexError): layer.cellContact((-1, 0), (1, 1)) @@ -90,7 +90,7 @@ def test_fault_barrier(self): nx = 120 ny = 60 nz = 43 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) with TestAreaContext("python/faults/line_order"): with open("faults.grdecl", "w") as f: f.write( @@ -149,7 +149,7 @@ def test_contact2(self): nx = 10 ny = 10 layer = Layer(nx, ny) - grid = EclGrid.createRectangular((nx, ny, 1), (1, 1, 1)) + grid = Grid.createRectangular((nx, ny, 1), (1, 1, 1)) # Too short with self.assertRaises(ValueError): @@ -228,7 +228,7 @@ def test_matching(self): def test_add_polyline_barrier(self): d = 10 layer = Layer(d, d) - grid = EclGrid.createRectangular((d, d, 1), (1, 1, 1)) + grid = Grid.createRectangular((d, d, 1), (1, 1, 1)) pl = CPolyline(init_points=[(0, 0), (d / 2, d / 2), (d, d)]) layer.addPolylineBarrier(pl, grid, 0) for i in range(d): @@ -244,17 +244,17 @@ def test_active(self): self.assertTrue(layer.activeCell(1, 2)) - grid = EclGrid.createRectangular((d, d + 1, 1), (1, 1, 1)) + grid = Grid.createRectangular((d, d + 1, 1), (1, 1, 1)) with self.assertRaises(ValueError): layer.updateActive(grid, 0) - grid = EclGrid.createRectangular((d, d, 1), (1, 1, 1)) + grid = Grid.createRectangular((d, d, 1), (1, 1, 1)) with self.assertRaises(ValueError): layer.updateActive(grid, 10) actnum = IntVector(initial_size=d * d * 1, default_value=1) actnum[0] = 0 - grid = EclGrid.createRectangular((d, d, 1), (1, 1, 1), actnum=actnum) + grid = Grid.createRectangular((d, d, 1), (1, 1, 1), actnum=actnum) layer.updateActive(grid, 0) self.assertTrue(layer.activeCell(1, 2)) self.assertFalse(layer.activeCell(0, 0)) diff --git a/python/tests/ecl_tests/test_npv.py b/python/tests/rd_tests/test_npv.py similarity index 90% rename from python/tests/ecl_tests/test_npv.py rename to python/tests/rd_tests/test_npv.py index a3e6a57b42..d69fd60266 100644 --- a/python/tests/ecl_tests/test_npv.py +++ b/python/tests/rd_tests/test_npv.py @@ -8,12 +8,12 @@ except ImportError: from unittest import skipIf, skipUnless, skipIf -from ecl.summary import EclSum -from ecl.summary import EclNPV, NPVPriceVector +from resdata.summary import Summary +from resdata.summary import ResdataNPV, NPVPriceVector -from ecl.util.util import StringList, TimeVector, DoubleVector, CTime -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata.util.util import StringList, TimeVector, DoubleVector, CTime +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test base = "ECLIPSE" @@ -34,23 +34,23 @@ def linear2(x): @equinor_test() -class NPVTest(EclTest): +class NPVTest(ResdataTest): def setUp(self): self.case = self.createTestPath(case) def test_create(self): with self.assertRaises(Exception): - npv = EclNPV("/does/not/exist") + npv = ResdataNPV("/does/not/exist") - npv = EclNPV(self.case) + npv = ResdataNPV(self.case) def test_eval_npv(self): - npv = EclNPV(self.case) + npv = ResdataNPV(self.case) with self.assertRaises(ValueError): npv.eval() def test_expression(self): - npv = EclNPV(self.case) + npv = ResdataNPV(self.case) self.assertIsNone(npv.getExpression()) npv.setExpression("[FOPT]*$OIL_PRICE - [FGIT]*$GAS_PRICE") self.assertEqual(npv.getExpression(), "[FOPT]*$OIL_PRICE - [FGIT]*$GAS_PRICE") @@ -82,18 +82,18 @@ def test_expression(self): self.assertIn("WOPT:OP_1", keyList) def test_period(self): - npv = EclNPV(self.case) + npv = ResdataNPV(self.case) self.assertIsNone(npv.start) self.assertIsNone(npv.end) self.assertEqual("1Y", npv.interval) def test_eval(self): - npv = EclNPV(self.case) + npv = ResdataNPV(self.case) npv.compile("[FOPT]") npv1 = npv.evalNPV() npv2 = 0 - sum = EclSum(self.case) + sum = Summary(self.case) trange = sum.timeRange() fopr = sum.blockedProduction("FOPT", trange) for v in fopr: diff --git a/python/tests/ecl_tests/test_ecl_3dkw.py b/python/tests/rd_tests/test_rd_3dkw.py similarity index 61% rename from python/tests/ecl_tests/test_ecl_3dkw.py rename to python/tests/rd_tests/test_rd_3dkw.py index 758ad791c7..1ae1f8b9d0 100644 --- a/python/tests/ecl_tests/test_ecl_3dkw.py +++ b/python/tests/rd_tests/test_rd_3dkw.py @@ -2,22 +2,22 @@ import os import random -from ecl.util.util import IntVector -from ecl import EclDataType, EclFileFlagEnum -from ecl.eclfile import Ecl3DKW, EclKW, EclFile, FortIO -from ecl.grid import EclGrid -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.util import IntVector +from resdata import ResDataType, FileMode +from resdata.resfile import Resdata3DKW, ResdataKW, ResdataFile, FortIO +from resdata.grid import Grid +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class Ecl3DKWTest(EclTest): +class Resdata3DKWTest(ResdataTest): def test_create(self): actnum = IntVector(default_value=1, initial_size=1000) for i in range(100): actnum[i] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw = Resdata3DKW("KW", grid, ResDataType.RD_FLOAT) self.assertEqual(len(kw), grid.getNumActive()) self.assertEqual((10, 10, 10), kw.dims()) @@ -27,8 +27,8 @@ def test_create_global_size(self): for i in range(100): actnum[i] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT, global_active=True) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw = Resdata3DKW("KW", grid, ResDataType.RD_FLOAT, global_active=True) self.assertEqual(len(kw), grid.getGlobalSize()) kw.assign(50) @@ -41,8 +41,8 @@ def test_fix_uninitialized(self): nx = 10 ny = 11 nz = 12 - grid = EclGrid.createRectangular((nx, ny, nz), (1, 1, 1)) - kw = Ecl3DKW("REGIONS", grid, EclDataType.ECL_INT, global_active=True) + grid = Grid.createRectangular((nx, ny, nz), (1, 1, 1)) + kw = Resdata3DKW("REGIONS", grid, ResDataType.RD_INT, global_active=True) kw.assign(3) self.assertEqual(3 * nx * ny * nz, sum(kw)) @@ -59,8 +59,8 @@ def test_getitem(self): for i in range(100): actnum[i] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT, default_value=77) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw = Resdata3DKW("KW", grid, ResDataType.RD_FLOAT, default_value=77) with self.assertRaises(IndexError): kw[1000] @@ -84,8 +84,8 @@ def test_setitem(self): for i in range(100): actnum[i] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT, default_value=77) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw = Resdata3DKW("KW", grid, ResDataType.RD_FLOAT, default_value=77) with self.assertRaises(IndexError): kw[1000] @@ -114,27 +114,27 @@ def test_cast(self): for i in range(100): actnum[i] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw_wrong_size = EclKW("KW", 27, EclDataType.ECL_FLOAT) - kw_global_size = EclKW("KW", grid.getGlobalSize(), EclDataType.ECL_FLOAT) - kw_active_size = EclKW("KW", grid.getNumActive(), EclDataType.ECL_FLOAT) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw_wrong_size = ResdataKW("KW", 27, ResDataType.RD_FLOAT) + kw_global_size = ResdataKW("KW", grid.getGlobalSize(), ResDataType.RD_FLOAT) + kw_active_size = ResdataKW("KW", grid.getNumActive(), ResDataType.RD_FLOAT) with self.assertRaises(ValueError): - Ecl3DKW.castFromKW(kw_wrong_size, grid) + Resdata3DKW.castFromKW(kw_wrong_size, grid) - Ecl3DKW.castFromKW(kw_global_size, grid) - self.assertTrue(isinstance(kw_global_size, Ecl3DKW)) + Resdata3DKW.castFromKW(kw_global_size, grid) + self.assertTrue(isinstance(kw_global_size, Resdata3DKW)) - Ecl3DKW.castFromKW(kw_active_size, grid, default_value=66) - self.assertTrue(isinstance(kw_active_size, Ecl3DKW)) + Resdata3DKW.castFromKW(kw_active_size, grid, default_value=66) + self.assertTrue(isinstance(kw_active_size, Resdata3DKW)) self.assertEqual(kw_active_size[0, 0, 0], 66) with self.assertRaises(ValueError): kw_active_size[0, 0, 0] = 88 def test_default(self): - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1)) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_FLOAT) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1)) + kw = Resdata3DKW("KW", grid, ResDataType.RD_FLOAT) kw.setDefault(55) self.assertTrue(55, kw.getDefault()) @@ -143,13 +143,13 @@ def test_compressed_copy(self): for i in range(500): actnum[2 * i + 1] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_INT, global_active=True) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw = Resdata3DKW("KW", grid, ResDataType.RD_INT, global_active=True) for i in range(len(kw)): kw[i] = i kw_copy = kw.compressedCopy() - self.assertTrue(isinstance(kw_copy, EclKW)) + self.assertTrue(isinstance(kw_copy, ResdataKW)) self.assertEqual(len(kw_copy), 500) for i in range(len(kw_copy)): @@ -160,14 +160,14 @@ def test_global_copy(self): for i in range(500): actnum[2 * i + 1] = 0 - grid = EclGrid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) - kw = Ecl3DKW("KW", grid, EclDataType.ECL_INT, global_active=False) + grid = Grid.createRectangular((10, 10, 10), (1, 1, 1), actnum=actnum) + kw = Resdata3DKW("KW", grid, ResDataType.RD_INT, global_active=False) for i in range(len(kw)): kw[i] = i kw.setDefault(177) kw_copy = kw.globalCopy() - self.assertTrue(isinstance(kw_copy, EclKW)) + self.assertTrue(isinstance(kw_copy, ResdataKW)) self.assertEqual(len(kw_copy), 1000) for i in range(len(kw)): diff --git a/python/tests/rd_tests/test_rd_cmp.py b/python/tests/rd_tests/test_rd_cmp.py new file mode 100644 index 0000000000..13f1d20299 --- /dev/null +++ b/python/tests/rd_tests/test_rd_cmp.py @@ -0,0 +1,49 @@ +from resdata.summary import ResdataCmp +from resdata.util.test import TestAreaContext +from resdata.util.test.mock import createSummary +from tests import ResdataTest, equinor_test + + +@equinor_test() +class ResdataCmpTest(ResdataTest): + def setUp(self): + self.root1 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE") + self.root2 = self.createTestPath("Equinor/ECLIPSE/Oseberg/F8MLT/F8MLT-F4") + + def test_not_existing(self): + with self.assertRaises(IOError): + rd_cmp = ResdataCmp("missing/case1", "missing/case2") + + with self.assertRaises(IOError): + rd_cmp = ResdataCmp("missing/case1", self.root1) + + with self.assertRaises(IOError): + rd_cmp = ResdataCmp(self.root1, "missing/case1") + + rd_cmp = ResdataCmp(self.root1, self.root1) + rd_cmp = ResdataCmp(self.root2, self.root2) + + def test_different_start(self): + with self.assertRaises(ValueError): + rd_cmp = ResdataCmp(self.root1, self.root2) + + def test_summary_cmp(self): + rd_cmp = ResdataCmp(self.root1, self.root1) + self.assertEqual((False, False), rd_cmp.hasSummaryVector("MISSING")) + self.assertEqual((True, True), rd_cmp.hasSummaryVector("FOPT")) + + with self.assertRaises(KeyError): + diff = rd_cmp.cmpSummaryVector("MISSING") + + diff_sum, ref_sum = rd_cmp.cmpSummaryVector("FOPT") + self.assertEqual(diff_sum, 0.0) + self.assertTrue(rd_cmp.endTimeEqual()) + + def test_wells(self): + rd_cmp = ResdataCmp(self.root1, self.root1) + wells = rd_cmp.testWells() + + well_set = set(["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"]) + self.assertEqual(len(wells), len(well_set)) + for well in wells: + self.assertTrue(well in well_set) diff --git a/python/tests/ecl_tests/test_ecl_file.py b/python/tests/rd_tests/test_rd_file.py similarity index 53% rename from python/tests/ecl_tests/test_ecl_file.py rename to python/tests/rd_tests/test_rd_file.py index 8d8656d08f..ec699d0665 100644 --- a/python/tests/ecl_tests/test_ecl_file.py +++ b/python/tests/rd_tests/test_rd_file.py @@ -4,11 +4,11 @@ import gc from unittest import skipIf -from ecl import EclFileFlagEnum, EclDataType, EclFileEnum -from ecl.eclfile import EclFile, FortIO, EclKW, openFortIO, openEclFile -from ecl.util.util import CWDContext -from ecl.util.test import TestAreaContext, PathContext -from tests import EclTest +from resdata import FileMode, ResDataType, FileType +from resdata.resfile import ResdataFile, FortIO, ResdataKW, openFortIO, openResdataFile +from resdata.util.util import CWDContext +from resdata.util.test import TestAreaContext, PathContext +from tests import ResdataTest def createFile(name, kw_list): @@ -19,86 +19,84 @@ def createFile(name, kw_list): def loadKeywords(name): kw_list = [] - f = EclFile(name) + f = ResdataFile(name) for kw in f: kw_list.append(kw) return kw_list -class EclFileTest(EclTest): +class ResdataFileTest(ResdataTest): def assertFileType(self, filename, expected): - file_type, step, fmt_file = EclFile.getFileType(filename) + file_type, step, fmt_file = ResdataFile.getFileType(filename) self.assertEqual(file_type, expected[0]) self.assertEqual(fmt_file, expected[1]) self.assertEqual(step, expected[2]) def test_file_type(self): - self.assertFileType( - "ECLIPSE.UNRST", (EclFileEnum.ECL_UNIFIED_RESTART_FILE, False, None) - ) - self.assertFileType("ECLIPSE.X0030", (EclFileEnum.ECL_RESTART_FILE, False, 30)) - self.assertFileType("ECLIPSE.DATA", (EclFileEnum.ECL_DATA_FILE, None, None)) - self.assertFileType("ECLIPSE.FINIT", (EclFileEnum.ECL_INIT_FILE, True, None)) - self.assertFileType("ECLIPSE.A0010", (EclFileEnum.ECL_SUMMARY_FILE, True, 10)) - self.assertFileType("ECLIPSE.EGRID", (EclFileEnum.ECL_EGRID_FILE, False, None)) + self.assertFileType("ECLIPSE.UNRST", (FileType.UNIFIED_RESTART, False, None)) + self.assertFileType("ECLIPSE.X0030", (FileType.RESTART, False, 30)) + self.assertFileType("ECLIPSE.DATA", (FileType.DATA, None, None)) + self.assertFileType("ECLIPSE.FINIT", (FileType.INIT, True, None)) + self.assertFileType("ECLIPSE.A0010", (FileType.SUMMARY, True, 10)) + self.assertFileType("ECLIPSE.EGRID", (FileType.EGRID, False, None)) def test_IOError(self): with self.assertRaises(IOError): - EclFile("No/Does/not/exist") + ResdataFile("No/Does/not/exist") def test_context(self): - with TestAreaContext("python/ecl_file/context"): - kw1 = EclKW("KW1", 100, EclDataType.ECL_INT) - kw2 = EclKW("KW2", 100, EclDataType.ECL_INT) + with TestAreaContext("python/rd_file/context"): + kw1 = ResdataKW("KW1", 100, ResDataType.RD_INT) + kw2 = ResdataKW("KW2", 100, ResDataType.RD_INT) with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f: kw1.fwrite(f) kw2.fwrite(f) - with openEclFile("TEST") as ecl_file: - self.assertEqual(len(ecl_file), 2) - self.assertTrue(ecl_file.has_kw("KW1")) - self.assertTrue(ecl_file.has_kw("KW2")) - self.assertEqual(ecl_file[1], ecl_file[-1]) - - def test_ecl_index(self): - with TestAreaContext("python/ecl_file/context"): - kw1 = EclKW("KW1", 100, EclDataType.ECL_INT) - kw2 = EclKW("KW2", 100, EclDataType.ECL_FLOAT) - kw3 = EclKW("KW3", 100, EclDataType.ECL_CHAR) - kw4 = EclKW("KW4", 100, EclDataType.ECL_STRING(23)) + with openResdataFile("TEST") as rd_file: + self.assertEqual(len(rd_file), 2) + self.assertTrue(rd_file.has_kw("KW1")) + self.assertTrue(rd_file.has_kw("KW2")) + self.assertEqual(rd_file[1], rd_file[-1]) + + def test_rd_index(self): + with TestAreaContext("python/rd_file/context"): + kw1 = ResdataKW("KW1", 100, ResDataType.RD_INT) + kw2 = ResdataKW("KW2", 100, ResDataType.RD_FLOAT) + kw3 = ResdataKW("KW3", 100, ResDataType.RD_CHAR) + kw4 = ResdataKW("KW4", 100, ResDataType.RD_STRING(23)) with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f: kw1.fwrite(f) kw2.fwrite(f) kw3.fwrite(f) kw4.fwrite(f) - ecl_file = EclFile("TEST") - ecl_file.write_index("INDEX_FILE") - ecl_file.close() + rd_file = ResdataFile("TEST") + rd_file.write_index("INDEX_FILE") + rd_file.close() - ecl_file_index = EclFile("TEST", 0, "INDEX_FILE") + rd_file_index = ResdataFile("TEST", 0, "INDEX_FILE") for kw in ["KW1", "KW2", "KW3", "KW4"]: - self.assertIn(kw, ecl_file_index) + self.assertIn(kw, rd_file_index) with self.assertRaises(IOError): - ecl_file.write_index("does-not-exist/INDEX") + rd_file.write_index("does-not-exist/INDEX") with self.assertRaises(IOError): - ecl_file_index = EclFile("TEST", 0, "index_does_not_exist") + rd_file_index = ResdataFile("TEST", 0, "index_does_not_exist") os.mkdir("path") shutil.copyfile("TEST", "path/TEST") - ecl_file = EclFile("path/TEST") - ecl_file.write_index("path/index") + rd_file = ResdataFile("path/TEST") + rd_file.write_index("path/index") with CWDContext("path"): - ecl_file = EclFile("TEST", 0, "index") + rd_file = ResdataFile("TEST", 0, "index") def test_save_kw(self): - with TestAreaContext("python/ecl_file/save_kw"): + with TestAreaContext("python/rd_file/save_kw"): data = range(1000) - kw = EclKW("MY_KEY", len(data), EclDataType.ECL_INT) + kw = ResdataKW("MY_KEY", len(data), ResDataType.RD_INT) for index, val in enumerate(data): kw[index] = val @@ -114,23 +112,23 @@ def test_save_kw(self): self.assertFilesAreEqual(clean_dump, test_file) - ecl_file = EclFile(test_file, flags=EclFileFlagEnum.ECL_FILE_WRITABLE) - loaded_kw = ecl_file["MY_KEY"][0] + rd_file = ResdataFile(test_file, flags=FileMode.WRITABLE) + loaded_kw = rd_file["MY_KEY"][0] self.assertTrue(kw.equal(loaded_kw)) - ecl_file.save_kw(loaded_kw) - ecl_file.close() + rd_file.save_kw(loaded_kw) + rd_file.close() self.assertFilesAreEqual(clean_dump, test_file) - ecl_file = EclFile(test_file) - loaded_kw = ecl_file["MY_KEY"][0] + rd_file = ResdataFile(test_file) + loaded_kw = rd_file["MY_KEY"][0] self.assertTrue(kw.equal(loaded_kw)) def test_gc(self): - kw1 = EclKW("KW1", 100, EclDataType.ECL_INT) - kw2 = EclKW("KW2", 100, EclDataType.ECL_INT) - kw3 = EclKW("KW3", 100, EclDataType.ECL_INT) + kw1 = ResdataKW("KW1", 100, ResDataType.RD_INT) + kw2 = ResdataKW("KW2", 100, ResDataType.RD_INT) + kw3 = ResdataKW("KW3", 100, ResDataType.RD_INT) for i in range(len(kw1)): kw1[i] = i @@ -151,12 +149,12 @@ def test_broken_file(self): with TestAreaContext("test_broken_file"): with open("CASE.FINIT", "w") as f: f.write( - "This - is not a ECLISPE file\nsdlcblhcdbjlwhc\naschscbasjhcasc\nascasck c s s aiasic asc" + "This - is not a RDISPE file\nsdlcblhcdbjlwhc\naschscbasjhcasc\nascasck c s s aiasic asc" ) - f = EclFile("CASE.FINIT") + f = ResdataFile("CASE.FINIT") self.assertEqual(len(f), 0) - kw = EclKW("HEADER", 100, EclDataType.ECL_INT) + kw = ResdataKW("HEADER", 100, ResDataType.RD_INT) with openFortIO("FILE", mode=FortIO.WRITE_MODE) as f: kw.fwrite(f) kw.fwrite(f) @@ -164,7 +162,7 @@ def test_broken_file(self): with open("FILE", "a+") as f: f.write("Seom random gibberish") - f = EclFile("FILE") + f = ResdataFile("FILE") self.assertEqual(len(f), 2) with openFortIO("FILE", mode=FortIO.WRITE_MODE) as f: @@ -175,42 +173,42 @@ def test_broken_file(self): with open("FILE", "a+") as f: f.truncate(int(file_size * 0.75)) - f = EclFile("FILE") + f = ResdataFile("FILE") self.assertEqual(len(f), 1) def test_block_view(self): - with TestAreaContext("python/ecl_file/view"): + with TestAreaContext("python/rd_file/view"): with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f: for i in range(5): - header = EclKW("HEADER", 1, EclDataType.ECL_INT) + header = ResdataKW("HEADER", 1, ResDataType.RD_INT) header[0] = i - data1 = EclKW("DATA1", 100, EclDataType.ECL_INT) + data1 = ResdataKW("DATA1", 100, ResDataType.RD_INT) data1.assign(i) - data2 = EclKW("DATA2", 100, EclDataType.ECL_INT) + data2 = ResdataKW("DATA2", 100, ResDataType.RD_INT) data2.assign(i * 10) header.fwrite(f) data1.fwrite(f) data2.fwrite(f) - ecl_file = EclFile("TEST") - pfx = "EclFile(" - self.assertEqual(pfx, repr(ecl_file)[: len(pfx)]) + rd_file = ResdataFile("TEST") + pfx = "ResdataFile(" + self.assertEqual(pfx, repr(rd_file)[: len(pfx)]) with self.assertRaises(KeyError): - ecl_file.blockView("NO", 1) + rd_file.blockView("NO", 1) with self.assertRaises(IndexError): - ecl_file.blockView("HEADER", 100) + rd_file.blockView("HEADER", 100) with self.assertRaises(IndexError): - ecl_file.blockView("HEADER", 1000) + rd_file.blockView("HEADER", 1000) - bv = ecl_file.blockView("HEADER", -1) + bv = rd_file.blockView("HEADER", -1) for i in range(5): - view = ecl_file.blockView("HEADER", i) + view = rd_file.blockView("HEADER", i) self.assertEqual(len(view), 3) header = view["HEADER"][0] data1 = view["DATA1"][0] @@ -221,7 +219,7 @@ def test_block_view(self): self.assertEqual(data2[99], i * 10) for i in range(5): - view = ecl_file.blockView2("HEADER", "DATA2", i) + view = rd_file.blockView2("HEADER", "DATA2", i) self.assertEqual(len(view), 2) header = view["HEADER"][0] data1 = view["DATA1"][0] @@ -231,10 +229,10 @@ def test_block_view(self): self.assertFalse("DATA2" in view) - view = ecl_file.blockView2("HEADER", None, 0) - self.assertEqual(len(view), len(ecl_file)) + view = rd_file.blockView2("HEADER", None, 0) + self.assertEqual(len(view), len(rd_file)) - view = ecl_file.blockView2(None, "DATA2", 0) + view = rd_file.blockView2(None, "DATA2", 0) # self.assertEqual( len(view) , 2) # self.assertTrue( "HEADER" in view ) # self.assertTrue( "DATA1" in view ) diff --git a/python/tests/ecl_tests/test_ecl_file_equinor.py b/python/tests/rd_tests/test_rd_file_equinor.py similarity index 90% rename from python/tests/ecl_tests/test_ecl_file_equinor.py rename to python/tests/rd_tests/test_rd_file_equinor.py index 2dbe668397..a374b51493 100755 --- a/python/tests/ecl_tests/test_ecl_file_equinor.py +++ b/python/tests/rd_tests/test_rd_file_equinor.py @@ -3,15 +3,15 @@ import os.path from unittest import skipIf -from ecl import EclFileFlagEnum, EclFileEnum -from ecl.eclfile import EclFile, FortIO, EclKW, openFortIO, openEclFile +from resdata import FileMode, FileType +from resdata.resfile import ResdataFile, FortIO, ResdataKW, openFortIO, openResdataFile -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test @equinor_test() -class EclFileEquinorTest(EclTest): +class ResdataFileEquinorTest(ResdataTest): def setUp(self): self.test_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") self.test_fmt_file = self.createTestPath( @@ -19,21 +19,21 @@ def setUp(self): ) def assertFileType(self, filename, expected): - file_type, step, fmt_file = EclFile.getFileType(filename) + file_type, step, fmt_file = ResdataFile.getFileType(filename) self.assertEqual(file_type, expected[0]) self.assertEqual(fmt_file, expected[1]) self.assertEqual(step, expected[2]) def test_fast_open(self): with TestAreaContext("index"): - f0 = EclFile(self.test_file) + f0 = ResdataFile(self.test_file) f0.write_index("index") - f1 = EclFile(self.test_file, 0, "index") + f1 = ResdataFile(self.test_file, 0, "index") for kw0, kw1 in zip(f0, f1): self.assertEqual(kw0, kw1) def test_restart_days(self): - rst_file = EclFile(self.test_file) + rst_file = ResdataFile(self.test_file) self.assertAlmostEqual(0.0, rst_file.iget_restart_sim_days(0)) self.assertAlmostEqual(31.0, rst_file.iget_restart_sim_days(1)) self.assertAlmostEqual(274.0, rst_file.iget_restart_sim_days(10)) @@ -45,37 +45,35 @@ def test_restart_days(self): rst_file.restart_get_kw("SWAT", dtime=datetime.date(1985, 1, 1)) def test_iget_named(self): - f = EclFile(self.test_file) + f = ResdataFile(self.test_file) N = f.num_named_kw("SWAT") with self.assertRaises(IndexError): s = f.iget_named_kw("SWAT", N + 1) def test_fwrite(self): - # work_area = TestArea("python/ecl_file/fwrite") - with TestAreaContext("python/ecl_file/fwrite"): - rst_file = EclFile(self.test_file) + # work_area = TestArea("python/rd_file/fwrite") + with TestAreaContext("python/rd_file/fwrite"): + rst_file = ResdataFile(self.test_file) fortio = FortIO("ECLIPSE.UNRST", FortIO.WRITE_MODE) rst_file.fwrite(fortio) fortio.close() rst_file.close() self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file) - @skipIf(EclTest.slowTestShouldNotRun(), "Slow file test skipped!") + @skipIf(ResdataTest.slowTestShouldNotRun(), "Slow file test skipped!") def test_save(self): - # work_area = TestArea("python/ecl_file/save") - with TestAreaContext("python/ecl_file/save", store_area=False) as work_area: + # work_area = TestArea("python/rd_file/save") + with TestAreaContext("python/rd_file/save", store_area=False) as work_area: work_area.copy_file(self.test_file) - rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) + rst_file = ResdataFile("ECLIPSE.UNRST", flags=FileMode.WRITABLE) swat0 = rst_file["SWAT"][0] swat0.assign(0.75) rst_file.save_kw(swat0) rst_file.close() self.assertFilesAreNotEqual("ECLIPSE.UNRST", self.test_file) - rst_file1 = EclFile(self.test_file) - rst_file2 = EclFile( - "ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE - ) + rst_file1 = ResdataFile(self.test_file) + rst_file2 = ResdataFile("ECLIPSE.UNRST", flags=FileMode.WRITABLE) swat1 = rst_file1["SWAT"][0] swat2 = rst_file2["SWAT"][0] @@ -89,24 +87,20 @@ def test_save(self): # Random failure .... self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file) - @skipIf(EclTest.slowTestShouldNotRun(), "Slow file test skipped!") + @skipIf(ResdataTest.slowTestShouldNotRun(), "Slow file test skipped!") def test_save_fmt(self): - # work_area = TestArea("python/ecl_file/save_fmt") - with TestAreaContext("python/ecl_file/save_fmt") as work_area: + # work_area = TestArea("python/rd_file/save_fmt") + with TestAreaContext("python/rd_file/save_fmt") as work_area: work_area.copy_file(self.test_fmt_file) - rst_file = EclFile( - "ECLIPSE.FUNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE - ) + rst_file = ResdataFile("ECLIPSE.FUNRST", flags=FileMode.WRITABLE) swat0 = rst_file["SWAT"][0] swat0.assign(0.75) rst_file.save_kw(swat0) rst_file.close() self.assertFilesAreNotEqual("ECLIPSE.FUNRST", self.test_fmt_file) - rst_file1 = EclFile(self.test_fmt_file) - rst_file2 = EclFile( - "ECLIPSE.FUNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE - ) + rst_file1 = ResdataFile(self.test_fmt_file) + rst_file2 = ResdataFile("ECLIPSE.FUNRST", flags=FileMode.WRITABLE) swat1 = rst_file1["SWAT"][0] swat2 = rst_file2["SWAT"][0] @@ -121,7 +115,7 @@ def test_save_fmt(self): self.assertFilesAreEqual("ECLIPSE.FUNRST", self.test_fmt_file) def test_restart_view(self): - f = EclFile(self.test_file) + f = ResdataFile(self.test_file) with self.assertRaises(ValueError): v = f.restartView() @@ -131,16 +125,16 @@ def test_restart_view(self): v = f.restartView(seqnum_index=30) def test_index(self): - with TestAreaContext("python/ecl_file/truncated"): - f0 = EclFile(self.test_file) + with TestAreaContext("python/rd_file/truncated"): + f0 = ResdataFile(self.test_file) f0.write_index("index") - f1 = EclFile(self.test_file, index_filename="index") + f1 = ResdataFile(self.test_file, index_filename="index") for kw0, kw1 in zip(f0, f1): self.assertEqual(kw0, kw1) def test_ix_case(self): - f = EclFile( + f = ResdataFile( self.createTestPath( "Equinor/ECLIPSE/ix/summary/Create_Region_Around_Well.SMSPEC" ) diff --git a/python/tests/rd_tests/test_rd_init_file.py b/python/tests/rd_tests/test_rd_init_file.py new file mode 100644 index 0000000000..bf1404961c --- /dev/null +++ b/python/tests/rd_tests/test_rd_init_file.py @@ -0,0 +1,29 @@ +from tests import ResdataTest, equinor_test +from resdata import FileMode +from resdata.resfile import Resdata3DKW, ResdataKW, ResdataInitFile, ResdataFile, FortIO +from resdata.grid import Grid + + +@equinor_test() +class InitFileTest(ResdataTest): + def setUp(self): + self.grid_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") + self.init_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.INIT") + + def test_wrong_type(self): + g = Grid(self.grid_file) + with self.assertRaises(ValueError): + f = ResdataInitFile(g, self.grid_file) + + def test_load(self): + g = Grid(self.grid_file) + f = ResdataInitFile(g, self.init_file) + + head = f["INTEHEAD"][0] + self.assertTrue(isinstance(head, ResdataKW)) + + porv = f["PORV"][0] + self.assertTrue(isinstance(porv, Resdata3DKW)) + + poro = f["PORO"][0] + self.assertTrue(isinstance(poro, Resdata3DKW)) diff --git a/python/tests/ecl_tests/test_ecl_kw.py b/python/tests/rd_tests/test_rd_kw.py similarity index 67% rename from python/tests/ecl_tests/test_ecl_kw.py rename to python/tests/rd_tests/test_rd_kw.py index f3d6d86183..c99c0554e8 100644 --- a/python/tests/ecl_tests/test_ecl_kw.py +++ b/python/tests/rd_tests/test_rd_kw.py @@ -4,27 +4,27 @@ import cwrap import random -from ecl import EclDataType, EclTypeEnum, EclFileFlagEnum -from ecl.eclfile import EclKW, EclFile, FortIO, openFortIO +from resdata import ResDataType, ResdataTypeEnum, FileMode +from resdata.resfile import ResdataKW, ResdataFile, FortIO, openFortIO -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.test import TestAreaContext +from tests import ResdataTest def copy_long(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) + src = ResdataKW("NAME", 100, ResDataType.RD_FLOAT) copy = src.sub_copy(0, 2000) def copy_offset(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) + src = ResdataKW("NAME", 100, ResDataType.RD_FLOAT) copy = src.sub_copy(200, 100) -class KWTest(EclTest): +class KWTest(ResdataTest): def test_name(self): - kw = EclKW("TEST", 3, EclDataType.ECL_INT) + kw = ResdataKW("TEST", 3, ResDataType.RD_INT) self.assertEqual(kw.name, "TEST") self.assertIn("TEST", repr(kw)) kw.name = "SCHMEST" @@ -32,7 +32,7 @@ def test_name(self): self.assertIn("SCHMEST", repr(kw)) def test_min_max(self): - kw = EclKW("TEST", 3, EclDataType.ECL_INT) + kw = ResdataKW("TEST", 3, ResDataType.RD_INT) kw[0] = 10 kw[1] = 5 kw[2] = 0 @@ -44,23 +44,23 @@ def test_min_max(self): def test_deprecated_datatypes(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - kw = EclKW("Test", 10, EclTypeEnum.ECL_INT_TYPE) + kw = ResdataKW("Test", 10, ResdataTypeEnum.RD_INT_TYPE) self.assertTrue(len(w) > 0) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - kw = EclKW("Test", 10, EclDataType.ECL_INT) + kw = ResdataKW("Test", 10, ResDataType.RD_INT) self.assertTrue(len(w) == 0) - self.assertEqual(EclTypeEnum.ECL_INT_TYPE, kw.type) + self.assertEqual(ResdataTypeEnum.RD_INT_TYPE, kw.type) self.assertTrue(len(w) == 1) def kw_test(self, data_type, data, fmt): name1 = "file1.txt" name2 = "file2.txt" - kw = EclKW("TEST", len(data), data_type) + kw = ResdataKW("TEST", len(data), data_type) for i, d in enumerate(data): kw[i] = d @@ -77,36 +77,36 @@ def kw_test(self, data_type, data, fmt): def test_create(self): with self.assertRaises(ValueError): - EclKW("ThisIsTooLong", 100, EclDataType.ECL_CHAR) + ResdataKW("ThisIsTooLong", 100, ResDataType.RD_CHAR) def test_sum(self): - for ecl_type in [EclDataType.ECL_CHAR, EclDataType.ECL_STRING(42)]: - kw_string = EclKW("STRING", 100, ecl_type) + for rd_type in [ResDataType.RD_CHAR, ResDataType.RD_STRING(42)]: + kw_string = ResdataKW("STRING", 100, rd_type) with self.assertRaises(ValueError): kw_string.sum() - kw_int = EclKW("INT", 4, EclDataType.ECL_INT) + kw_int = ResdataKW("INT", 4, ResDataType.RD_INT) kw_int[0] = 1 kw_int[1] = 2 kw_int[2] = 3 kw_int[3] = 4 self.assertEqual(kw_int.sum(), 10) - kw_d = EclKW("D", 4, EclDataType.ECL_DOUBLE) + kw_d = ResdataKW("D", 4, ResDataType.RD_DOUBLE) kw_d[0] = 1 kw_d[1] = 2 kw_d[2] = 3 kw_d[3] = 4 self.assertEqual(kw_d.sum(), 10) - kw_f = EclKW("F", 4, EclDataType.ECL_FLOAT) + kw_f = ResdataKW("F", 4, ResDataType.RD_FLOAT) kw_f[0] = 1 kw_f[1] = 2 kw_f[2] = 3 kw_f[3] = 4 self.assertEqual(kw_f.sum(), 10) - kw_b = EclKW("F", 4, EclDataType.ECL_BOOL) + kw_b = ResdataKW("F", 4, ResDataType.RD_BOOL) kw_b[0] = False kw_b[1] = True kw_b[2] = False @@ -114,71 +114,71 @@ def test_sum(self): self.assertEqual(kw_b.sum(), 2) def test_fprintf(self): - with TestAreaContext("python.ecl_kw"): - self.kw_test(EclDataType.ECL_INT, [0, 1, 2, 3, 4, 5], "%4d\n") + with TestAreaContext("python.rd_kw"): + self.kw_test(ResDataType.RD_INT, [0, 1, 2, 3, 4, 5], "%4d\n") self.kw_test( - EclDataType.ECL_FLOAT, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n" + ResDataType.RD_FLOAT, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n" ) self.kw_test( - EclDataType.ECL_DOUBLE, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n" + ResDataType.RD_DOUBLE, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n" ) - self.kw_test(EclDataType.ECL_BOOL, [True, True, True, False, True], "%4d\n") + self.kw_test(ResDataType.RD_BOOL, [True, True, True, False, True], "%4d\n") self.kw_test( - EclDataType.ECL_CHAR, + ResDataType.RD_CHAR, ["1", "22", "4444", "666666", "88888888"], "%-8s\n", ) for str_len in range(1000): self.kw_test( - EclDataType.ECL_STRING(str_len), + ResDataType.RD_STRING(str_len), [str(i) * str_len for i in range(10)], "%s\n", ) def test_kw_write(self): - with TestAreaContext("python/ecl_kw/writing"): + with TestAreaContext("python/rd_kw/writing"): data = [random.random() for i in range(10000)] - kw = EclKW("TEST", len(data), EclDataType.ECL_DOUBLE) + kw = ResdataKW("TEST", len(data), ResDataType.RD_DOUBLE) i = 0 for d in data: kw[i] = d i += 1 - pfx = "EclKW(" + pfx = "ResdataKW(" self.assertEqual(pfx, repr(kw)[: len(pfx)]) - fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE) + fortio = FortIO("RD_KW_TEST", FortIO.WRITE_MODE) kw.fwrite(fortio) fortio.close() - fortio = FortIO("ECL_KW_TEST") + fortio = FortIO("RD_KW_TEST") - kw2 = EclKW.fread(fortio) + kw2 = ResdataKW.fread(fortio) self.assertTrue(kw.equal(kw2)) - ecl_file = EclFile("ECL_KW_TEST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) - kw3 = ecl_file["TEST"][0] + rd_file = ResdataFile("RD_KW_TEST", flags=FileMode.WRITABLE) + kw3 = rd_file["TEST"][0] self.assertTrue(kw.equal(kw3)) - ecl_file.save_kw(kw3) - ecl_file.close() + rd_file.save_kw(kw3) + rd_file.close() - fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE) - kw4 = EclKW.fread(fortio) + fortio = FortIO("RD_KW_TEST", FortIO.READ_AND_WRITE_MODE) + kw4 = ResdataKW.fread(fortio) self.assertTrue(kw.equal(kw4)) fortio.seek(0) kw4.fwrite(fortio) fortio.close() - ecl_file = EclFile("ECL_KW_TEST") - kw5 = ecl_file["TEST"][0] + rd_file = ResdataFile("RD_KW_TEST") + kw5 = rd_file["TEST"][0] self.assertTrue(kw.equal(kw5)) def test_fprintf_data(self): with TestAreaContext("kw_no_header"): - kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) + kw = ResdataKW("REGIONS", 10, ResDataType.RD_INT) for i in range(len(kw)): kw[i] = i @@ -197,7 +197,7 @@ def test_fprintf_data(self): self.assertEqual(v1, v2) def test_sliced_set(self): - kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) + kw = ResdataKW("REGIONS", 10, ResDataType.RD_INT) kw.assign(99) kw[0:5] = 66 self.assertEqual(kw[0], 66) @@ -206,23 +206,23 @@ def test_sliced_set(self): def test_long_name(self): with self.assertRaises(ValueError): - EclKW("LONGLONGNAME", 10, EclDataType.ECL_INT) + ResdataKW("LONGLONGNAME", 10, ResDataType.RD_INT) - kw = EclKW("REGIONS", 10, EclDataType.ECL_INT) + kw = ResdataKW("REGIONS", 10, ResDataType.RD_INT) with self.assertRaises(ValueError): kw.name = "LONGLONGNAME" def test_abs(self): - for ecl_type in [ - EclDataType.ECL_CHAR, - EclDataType.ECL_BOOL, - EclDataType.ECL_STRING(32), + for rd_type in [ + ResDataType.RD_CHAR, + ResDataType.RD_BOOL, + ResDataType.RD_STRING(32), ]: - kw = EclKW("NAME", 10, ecl_type) + kw = ResdataKW("NAME", 10, rd_type) with self.assertRaises(TypeError): abs_kw = abs(kw) - kw = EclKW("NAME", 10, EclDataType.ECL_INT) + kw = ResdataKW("NAME", 10, ResDataType.RD_INT) for i in range(len(kw)): kw[i] = -i @@ -232,44 +232,44 @@ def test_abs(self): self.assertEqual(abs_kw[i], i) def test_fmt(self): - kw1 = EclKW("NAME1", 100, EclDataType.ECL_INT) - kw2 = EclKW("NAME2", 100, EclDataType.ECL_INT) + kw1 = ResdataKW("NAME1", 100, ResDataType.RD_INT) + kw2 = ResdataKW("NAME2", 100, ResDataType.RD_INT) for i in range(len(kw1)): kw1[i] = i + 1 kw2[i] = len(kw1) - kw1[i] - with TestAreaContext("ecl_kw/fmt") as ta: + with TestAreaContext("rd_kw/fmt") as ta: with openFortIO("TEST.FINIT", FortIO.WRITE_MODE, fmt_file=True) as f: kw1.fwrite(f) kw2.fwrite(f) with openFortIO("TEST.FINIT", fmt_file=True) as f: - kw1b = EclKW.fread(f) - kw2b = EclKW.fread(f) + kw1b = ResdataKW.fread(f) + kw2b = ResdataKW.fread(f) self.assertTrue(kw1 == kw1b) self.assertTrue(kw2 == kw2b) - f = EclFile("TEST.FINIT") + f = ResdataFile("TEST.FINIT") self.assertTrue(kw1 == f[0]) self.assertTrue(kw2 == f[1]) def test_first_different(self): - kw1 = EclKW("NAME1", 100, EclDataType.ECL_INT) - kw2 = EclKW("NAME2", 100, EclDataType.ECL_INT) - kw3 = EclKW("NAME2", 200, EclDataType.ECL_INT) - kw4 = EclKW("NAME2", 100, EclDataType.ECL_FLOAT) - kw5 = EclKW("NAME2", 100, EclDataType.ECL_FLOAT) + kw1 = ResdataKW("NAME1", 100, ResDataType.RD_INT) + kw2 = ResdataKW("NAME2", 100, ResDataType.RD_INT) + kw3 = ResdataKW("NAME2", 200, ResDataType.RD_INT) + kw4 = ResdataKW("NAME2", 100, ResDataType.RD_FLOAT) + kw5 = ResdataKW("NAME2", 100, ResDataType.RD_FLOAT) with self.assertRaises(IndexError): - EclKW.firstDifferent(kw1, kw2, offset=100) + ResdataKW.firstDifferent(kw1, kw2, offset=100) with self.assertRaises(ValueError): - EclKW.firstDifferent(kw1, kw3) + ResdataKW.firstDifferent(kw1, kw3) with self.assertRaises(TypeError): - EclKW.firstDifferent(kw1, kw4) + ResdataKW.firstDifferent(kw1, kw4) with self.assertRaises(IndexError): kw1.firstDifferent(kw2, offset=100) @@ -302,8 +302,8 @@ def test_first_different(self): self.assertEqual(kw4.firstDifferent(kw5, epsilon=0.0000001), 10) def test_numeric_equal(self): - kw1 = EclKW("Name1", 10, EclDataType.ECL_DOUBLE) - kw2 = EclKW("Name1", 10, EclDataType.ECL_DOUBLE) + kw1 = ResdataKW("Name1", 10, ResDataType.RD_DOUBLE) + kw2 = ResdataKW("Name1", 10, ResDataType.RD_DOUBLE) shift = 0.0001 value = 1000 @@ -336,10 +336,10 @@ def test_numeric_equal(self): ) def test_mul(self): - kw1 = EclKW("Name1", 10, EclDataType.ECL_INT) + kw1 = ResdataKW("Name1", 10, ResDataType.RD_INT) kw1.assign(10) - kw2 = EclKW("Name1", 10, EclDataType.ECL_INT) + kw2 = ResdataKW("Name1", 10, ResDataType.RD_INT) kw2.assign(2) kw3 = kw1 * kw2 @@ -353,7 +353,7 @@ def test_mul(self): self.assertEqual(v, 12) def test_numpy(self): - kw1 = EclKW("DOUBLE", 10, EclDataType.ECL_DOUBLE) + kw1 = ResdataKW("DOUBLE", 10, ResDataType.RD_DOUBLE) view = kw1.numpyView() copy = kw1.numpyCopy() @@ -365,18 +365,18 @@ def test_numpy(self): self.assertTrue(view[0] == kw1[0]) self.assertTrue(copy[0] == kw1[0] - 1) - for ecl_type in [ - EclDataType.ECL_CHAR, - EclDataType.ECL_BOOL, - EclDataType.ECL_STRING(19), + for rd_type in [ + ResDataType.RD_CHAR, + ResDataType.RD_BOOL, + ResDataType.RD_STRING(19), ]: - kw2 = EclKW("TEST_KW", 10, ecl_type) + kw2 = ResdataKW("TEST_KW", 10, rd_type) with self.assertRaises(ValueError): kw2.numpyView() def test_slice(self): N = 100 - kw = EclKW("KW", N, EclDataType.ECL_INT) + kw = ResdataKW("KW", N, ResDataType.RD_INT) for i in range(len(kw)): kw[i] = i @@ -392,7 +392,7 @@ def test_slice(self): def test_resize(self): N = 4 - kw = EclKW("KW", N, EclDataType.ECL_INT) + kw = ResdataKW("KW", N, ResDataType.RD_INT) for i in range(N): kw[i] = i @@ -407,12 +407,12 @@ def test_resize(self): self.assertEqual(kw[i], i) def test_typename(self): - kw = EclKW("KW", 100, EclDataType.ECL_INT) + kw = ResdataKW("KW", 100, ResDataType.RD_INT) self.assertEqual(kw.typeName(), "INTE") def test_string_alloc(self): - kw = EclKW("KW", 10, EclDataType.ECL_STRING(30)) + kw = ResdataKW("KW", 10, ResDataType.RD_STRING(30)) for i in range(10): kw[i] = str(i) * 30 @@ -423,64 +423,64 @@ def test_string_alloc(self): def test_string_write_read_unformatted(self): for str_len in range(1000): with TestAreaContext("my_space"): - kw = EclKW("TEST_KW", 10, EclDataType.ECL_STRING(str_len)) + kw = ResdataKW("TEST_KW", 10, ResDataType.RD_STRING(str_len)) for i in range(10): kw[i] = str(i) * str_len - file_name = "ecl_kw_test" + file_name = "rd_kw_test" with openFortIO(file_name, mode=FortIO.WRITE_MODE) as fortio: kw.fwrite(fortio) with openFortIO(file_name) as fortio: - loaded_kw = EclKW.fread(fortio) + loaded_kw = ResdataKW.fread(fortio) self.assertEqual(kw, loaded_kw) def test_string_write_read_formatted(self): for str_len in range(1000): with TestAreaContext("my_space"): - kw = EclKW("TEST_KW", 10, EclDataType.ECL_STRING(str_len)) + kw = ResdataKW("TEST_KW", 10, ResDataType.RD_STRING(str_len)) for i in range(10): kw[i] = str(i) * str_len - file_name = "ecl_kw_test" + file_name = "rd_kw_test" with openFortIO( file_name, mode=FortIO.WRITE_MODE, fmt_file=True ) as fortio: kw.fwrite(fortio) with openFortIO(file_name, fmt_file=True) as fortio: - loaded_kw = EclKW.fread(fortio) + loaded_kw = ResdataKW.fread(fortio) self.assertEqual(kw, loaded_kw) def test_string_padding(self): - kw = EclKW("TEST_KW", 1, EclDataType.ECL_STRING(4)) + kw = ResdataKW("TEST_KW", 1, ResDataType.RD_STRING(4)) kw[0] = "AB" self.assertEqual(kw[0], "AB ") - kw = EclKW("TEST_KW", 1, EclDataType.ECL_CHAR) + kw = ResdataKW("TEST_KW", 1, ResDataType.RD_CHAR) kw[0] = "ABCD" self.assertEqual(kw[0], "ABCD ") def test_add_squared(self): - kw1 = EclKW("TEST_KW", 3, EclDataType.ECL_STRING(4)) - kw2 = EclKW("TEST_KW", 3, EclDataType.ECL_STRING(4)) + kw1 = ResdataKW("TEST_KW", 3, ResDataType.RD_STRING(4)) + kw2 = ResdataKW("TEST_KW", 3, ResDataType.RD_STRING(4)) with self.assertRaises(TypeError): kw1.add_squared(kw2) - kw1 = EclKW("T1", 10, EclDataType.ECL_INT) - kw2 = EclKW("T2", 11, EclDataType.ECL_INT) + kw1 = ResdataKW("T1", 10, ResDataType.RD_INT) + kw2 = ResdataKW("T2", 11, ResDataType.RD_INT) with self.assertRaises(ValueError): kw1.add_squared(kw2) - kw2 = EclKW("T", 10, EclDataType.ECL_FLOAT) + kw2 = ResdataKW("T", 10, ResDataType.RD_FLOAT) with self.assertRaises(ValueError): kw1.add_squared(kw2) - kw2 = EclKW("T2", 10, EclDataType.ECL_INT) + kw2 = ResdataKW("T2", 10, ResDataType.RD_INT) kw2.assign(2) kw1.add_squared(kw2) @@ -488,15 +488,15 @@ def test_add_squared(self): self.assertEqual(elm, 4) def test_scatter_copy(self): - source = EclKW("SOURCE", 4, EclDataType.ECL_INT) + source = ResdataKW("SOURCE", 4, ResDataType.RD_INT) with self.assertRaises(TypeError): copy = source.scatter_copy([1, 1, 1, 1]) - actnum = EclKW("ACTNUM", 6, EclDataType.ECL_FLOAT) + actnum = ResdataKW("ACTNUM", 6, ResDataType.RD_FLOAT) with self.assertRaises(ValueError): copy = source.scatter_copy(actnum) - actnum = EclKW("ACTNUM", 8, EclDataType.ECL_INT) + actnum = ResdataKW("ACTNUM", 8, ResDataType.RD_INT) actnum[0] = 1 actnum[1] = 1 with self.assertRaises(ValueError): @@ -518,16 +518,16 @@ def test_scatter_copy(self): self.assertEqual(copy[2 * i + 1], i + 1) def test_safe_div(self): - kw1 = EclKW("SOURCE", 10, EclDataType.ECL_INT) - kw2 = EclKW("XXX", 11, EclDataType.ECL_INT) + kw1 = ResdataKW("SOURCE", 10, ResDataType.RD_INT) + kw2 = ResdataKW("XXX", 11, ResDataType.RD_INT) with self.assertRaises(ValueError): kw1.safe_div(kw2) - kw1 = EclKW("SOURCE", 2, EclDataType.ECL_FLOAT) + kw1 = ResdataKW("SOURCE", 2, ResDataType.RD_FLOAT) kw1.assign(10) - kw2 = EclKW("DIV", 2, EclDataType.ECL_INT) + kw2 = ResdataKW("DIV", 2, ResDataType.RD_INT) kw2[0] = 0 kw2[1] = 2 @@ -541,9 +541,9 @@ def test_fmu_stat_workflow(self): active_size = 50 with TestAreaContext("FMU_FILES"): for i in range(N): - permx = EclKW("PERMX", active_size, EclDataType.ECL_FLOAT) - poro = EclKW("PORO", active_size, EclDataType.ECL_FLOAT) - porv = EclKW("PORV", global_size, EclDataType.ECL_FLOAT) + permx = ResdataKW("PERMX", active_size, ResDataType.RD_FLOAT) + poro = ResdataKW("PORO", active_size, ResDataType.RD_FLOAT) + porv = ResdataKW("PORV", global_size, ResDataType.RD_FLOAT) porv.assign(0) for g in random.sample(range(global_size), active_size): @@ -557,14 +557,14 @@ def test_fmu_stat_workflow(self): poro.fwrite(f) porv.fwrite(f) - mean_permx = EclKW("PERMX", global_size, EclDataType.ECL_FLOAT) - std_permx = EclKW("PERMX", global_size, EclDataType.ECL_FLOAT) - mean_poro = EclKW("PORO", global_size, EclDataType.ECL_FLOAT) - std_poro = EclKW("PORO", global_size, EclDataType.ECL_FLOAT) + mean_permx = ResdataKW("PERMX", global_size, ResDataType.RD_FLOAT) + std_permx = ResdataKW("PERMX", global_size, ResDataType.RD_FLOAT) + mean_poro = ResdataKW("PORO", global_size, ResDataType.RD_FLOAT) + std_poro = ResdataKW("PORO", global_size, ResDataType.RD_FLOAT) - count = EclKW("COUNT", global_size, EclDataType.ECL_INT) + count = ResdataKW("COUNT", global_size, ResDataType.RD_INT) for i in range(N): - f = EclFile("TEST%d.INIT" % i) + f = ResdataFile("TEST%d.INIT" % i) porv = f["PORV"][0] permx = f["PERMX"][0] diff --git a/python/tests/ecl_tests/test_ecl_kw_equinor.py b/python/tests/rd_tests/test_rd_kw_equinor.py similarity index 79% rename from python/tests/ecl_tests/test_ecl_kw_equinor.py rename to python/tests/rd_tests/test_rd_kw_equinor.py index 1c3d0f276c..12afd83cb8 100755 --- a/python/tests/ecl_tests/test_ecl_kw_equinor.py +++ b/python/tests/rd_tests/test_rd_kw_equinor.py @@ -1,28 +1,28 @@ #!/usr/bin/env python import os import random -from ecl import EclDataType, EclFileFlagEnum -from ecl.eclfile import EclKW, EclFile, FortIO +from resdata import ResDataType, FileMode +from resdata.resfile import ResdataKW, ResdataFile, FortIO -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test def copy_long(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) + src = ResdataKW("NAME", 100, ResDataType.RD_FLOAT) copy = src.sub_copy(0, 2000) def copy_offset(): - src = EclKW("NAME", 100, EclDataType.ECL_FLOAT) + src = ResdataKW("NAME", 100, ResDataType.RD_FLOAT) copy = src.sub_copy(200, 100) @equinor_test() -class KWTest(EclTest): +class KWTest(ResdataTest): def test_fortio_size(self): unrst_file_path = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") - unrst_file = EclFile(unrst_file_path) + unrst_file = ResdataFile(unrst_file_path) size = 0 for kw in unrst_file: size += kw.fortIOSize() @@ -32,7 +32,7 @@ def test_fortio_size(self): def test_sub_copy(self): unrst_file_path = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") - unrst_file = EclFile(unrst_file_path) + unrst_file = ResdataFile(unrst_file_path) swat = unrst_file["SWAT"][0] swat1 = swat.sub_copy(0, -1) @@ -54,12 +54,12 @@ def test_sub_copy(self): self.assertRaises(IndexError, copy_offset) def test_equal(self): - kw1 = EclKW("TEST", 3, EclDataType.ECL_CHAR) + kw1 = ResdataKW("TEST", 3, ResDataType.RD_CHAR) kw1[0] = "Test1" kw1[1] = "Test13" kw1[2] = "Test15" - kw2 = EclKW("TEST", 3, EclDataType.ECL_CHAR) + kw2 = ResdataKW("TEST", 3, ResDataType.RD_CHAR) kw2[0] = "Test1" kw2[1] = "Test13" kw2[2] = "Test15" @@ -72,7 +72,7 @@ def test_equal(self): self.assertFalse(kw1.equal_numeric(kw2)) unrst_file_path = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") - unrst_file = EclFile(unrst_file_path) + unrst_file = ResdataFile(unrst_file_path) kw1 = unrst_file["PRESSURE"][0] kw2 = kw1.deep_copy() diff --git a/python/tests/ecl_tests/test_ecl_restart_file.py b/python/tests/rd_tests/test_rd_restart_file.py similarity index 58% rename from python/tests/ecl_tests/test_ecl_restart_file.py rename to python/tests/rd_tests/test_rd_restart_file.py index 4799a6a506..3b60c4e864 100644 --- a/python/tests/ecl_tests/test_ecl_restart_file.py +++ b/python/tests/rd_tests/test_rd_restart_file.py @@ -1,13 +1,19 @@ import datetime -from tests import EclTest, equinor_test -from ecl import EclFileFlagEnum -from ecl.eclfile import Ecl3DKW, EclKW, EclRestartFile, EclFile, FortIO -from ecl.grid import EclGrid +from tests import ResdataTest, equinor_test +from resdata import FileMode +from resdata.resfile import ( + Resdata3DKW, + ResdataKW, + ResdataRestartFile, + ResdataFile, + FortIO, +) +from resdata.grid import Grid @equinor_test() -class RestartFileTest(EclTest): +class RestartFileTest(ResdataTest): def setUp(self): self.grid_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") self.unrst_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") @@ -16,29 +22,29 @@ def setUp(self): self.xrst_file20 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.X0020") def test_load(self): - g = EclGrid(self.grid_file) - f = EclRestartFile(g, self.unrst_file) + g = Grid(self.grid_file) + f = ResdataRestartFile(g, self.unrst_file) head = f["INTEHEAD"][0] - self.assertTrue(isinstance(head, EclKW)) + self.assertTrue(isinstance(head, ResdataKW)) swat = f["SWAT"][0] - self.assertTrue(isinstance(swat, Ecl3DKW)) + self.assertTrue(isinstance(swat, Resdata3DKW)) pressure = f["PRESSURE"][0] - self.assertTrue(isinstance(pressure, Ecl3DKW)) + self.assertTrue(isinstance(pressure, Resdata3DKW)) def test_type(self): - g = EclGrid(self.grid_file) + g = Grid(self.grid_file) with self.assertRaises(ValueError): - f = EclRestartFile(g, "NOT_A_RESTART_FILE") + f = ResdataRestartFile(g, "NOT_A_RESTART_FILE") def test_unified(self): - g = EclGrid(self.grid_file) - f_unrst = EclRestartFile(g, self.unrst_file) - f_x0 = EclRestartFile(g, self.xrst_file0) - f_x10 = EclRestartFile(g, self.xrst_file10) - f_x20 = EclRestartFile(g, self.xrst_file20) + g = Grid(self.grid_file) + f_unrst = ResdataRestartFile(g, self.unrst_file) + f_x0 = ResdataRestartFile(g, self.xrst_file0) + f_x10 = ResdataRestartFile(g, self.xrst_file10) + f_x20 = ResdataRestartFile(g, self.xrst_file20) self.assertTrue(f_unrst.unified()) self.assertFalse(f_x0.unified()) diff --git a/python/tests/ecl_tests/test_ecl_sum.py b/python/tests/rd_tests/test_rd_sum.py similarity index 66% rename from python/tests/ecl_tests/test_ecl_sum.py rename to python/tests/rd_tests/test_rd_sum.py index cfd1495dbf..7d701b9749 100644 --- a/python/tests/ecl_tests/test_ecl_sum.py +++ b/python/tests/rd_tests/test_rd_sum.py @@ -7,17 +7,17 @@ from cwrap import CFILE from cwrap import Prototype, load, open as copen -from ecl.eclfile import EclFile, FortIO, openFortIO, openEclFile, EclKW -from ecl.summary import EclSum, EclSumKeyWordVector -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata.resfile import ResdataFile, FortIO, openFortIO, openResdataFile, ResdataKW +from resdata.summary import Summary, SummaryKeyWordVector +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test def test_write_repr(): - """repr(EclSum) used to segfault when there is only a startdate""" - writer = EclSum.writer("TEST", datetime.date(2000, 2, 3), 10, 10, 10) + """repr(Summary) used to segfault when there is only a startdate""" + writer = Summary.writer("TEST", datetime.date(2000, 2, 3), 10, 10, 10) assert repr(writer).startswith( - 'EclSum(name="writer", time=[2000-02-03 00:00:00, 2000-02-03 00:00:00], keys=0) at 0x' + 'Summary(name="writer", time=[2000-02-03 00:00:00, 2000-02-03 00:00:00], keys=0) at 0x' ) @@ -25,7 +25,7 @@ def test_that_year2263_through_pandas_works(): """Date 2262-04-11 is the upper limit for nanosecond 64-bit timestamps, which is what pandas<2 prefers. """ - eclsum = EclSum.from_pandas( + eclsum = Summary.from_pandas( "TESTCASE", pd.DataFrame( [ @@ -44,42 +44,42 @@ def test_that_year2263_through_pandas_works(): @equinor_test() -class EclSumTest(EclTest): +class SummaryTest(ResdataTest): def setUp(self): self.test_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") - self.ecl_sum = EclSum(self.test_file) + self.rd_sum = Summary(self.test_file) def test_time_range_year(self): - real_range = self.ecl_sum.timeRange(interval="1y", extend_end=False) - extended_range = self.ecl_sum.timeRange(interval="1y", extend_end=True) + real_range = self.rd_sum.timeRange(interval="1y", extend_end=False) + extended_range = self.rd_sum.timeRange(interval="1y", extend_end=True) assert real_range[-1] < extended_range[-1] def test_time_range_day(self): - real_range = self.ecl_sum.timeRange(interval="1d", extend_end=False) - extended_range = self.ecl_sum.timeRange(interval="1d", extend_end=True) + real_range = self.rd_sum.timeRange(interval="1d", extend_end=False) + extended_range = self.rd_sum.timeRange(interval="1d", extend_end=True) assert real_range[-1] == extended_range[-1] def test_time_range_month(self): - real_range = self.ecl_sum.timeRange(interval="1m", extend_end=False) - extended_range = self.ecl_sum.timeRange(interval="1m", extend_end=True) + real_range = self.rd_sum.timeRange(interval="1m", extend_end=False) + extended_range = self.rd_sum.timeRange(interval="1m", extend_end=True) assert real_range[-1] < extended_range[-1] def test_dump_csv_line(self): - ecl_sum_vector = EclSumKeyWordVector(self.ecl_sum) - ecl_sum_vector.addKeywords("F*") + rd_sum_vector = SummaryKeyWordVector(self.rd_sum) + rd_sum_vector.addKeywords("F*") with self.assertRaises(KeyError): - ecl_sum_vector.addKeyword("MISSING") + rd_sum_vector.addKeyword("MISSING") dtime = datetime.datetime(2002, 1, 1, 0, 0, 0) - with TestAreaContext("EclSum/csv_dump"): + with TestAreaContext("Summary/csv_dump"): test_file_name = self.createTestPath("dump.csv") outputH = copen(test_file_name, "w") - self.ecl_sum.dumpCSVLine(dtime, ecl_sum_vector, outputH) + self.rd_sum.dumpCSVLine(dtime, rd_sum_vector, outputH) assert os.path.isfile(test_file_name) def test_truncated_smspec(self): - with TestAreaContext("EclSum/truncated_smspec") as ta: + with TestAreaContext("Summary/truncated_smspec") as ta: ta.copy_file(self.test_file) ta.copy_file(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) @@ -88,10 +88,10 @@ def test_truncated_smspec(self): f.truncate(file_size / 2) with self.assertRaises(IOError): - EclSum("ECLIPSE") + Summary("ECLIPSE") def test_truncated_data(self): - with TestAreaContext("EclSum/truncated_data") as ta: + with TestAreaContext("Summary/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) @@ -100,17 +100,17 @@ def test_truncated_data(self): f.truncate(file_size / 2) with self.assertRaises(IOError): - EclSum("ECLIPSE") + Summary("ECLIPSE") def test_missing_smspec_keyword(self): - with TestAreaContext("EclSum/truncated_data") as ta: + with TestAreaContext("Summary/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) - with openEclFile("ECLIPSE.SMSPEC") as f: + with openResdataFile("ECLIPSE.SMSPEC") as f: kw_list = [] for kw in f: - kw_list.append(EclKW.copy(kw)) + kw_list.append(ResdataKW.copy(kw)) with openFortIO("ECLIPSE.SMSPEC", mode=FortIO.WRITE_MODE) as f: for kw in kw_list: @@ -119,17 +119,17 @@ def test_missing_smspec_keyword(self): kw.fwrite(f) with self.assertRaises(IOError): - EclSum("ECLIPSE") + Summary("ECLIPSE") def test_missing_unsmry_keyword(self): - with TestAreaContext("EclSum/truncated_data") as ta: + with TestAreaContext("Summary/truncated_data") as ta: ta.copy_file(self.test_file) ta.copy_file(self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNSMRY")) - with openEclFile("ECLIPSE.UNSMRY") as f: + with openResdataFile("ECLIPSE.UNSMRY") as f: kw_list = [] for kw in f: - kw_list.append(EclKW.copy(kw)) + kw_list.append(ResdataKW.copy(kw)) with openFortIO("ECLIPSE.UNSMRY", mode=FortIO.WRITE_MODE) as f: c = 0 @@ -141,16 +141,16 @@ def test_missing_unsmry_keyword(self): kw.fwrite(f) with self.assertRaises(IOError): - EclSum("ECLIPSE") + Summary("ECLIPSE") def test_labscale(self): case = self.createTestPath("Equinor/ECLIPSE/LabScale/HDMODEL") - sum = EclSum(case, lazy_load=True) + sum = Summary(case, lazy_load=True) self.assertEqual(sum.getStartTime(), datetime.datetime(2013, 1, 1, 0, 0, 0)) self.assertEqual(sum.getEndTime(), datetime.datetime(2013, 1, 1, 19, 30, 0)) self.assertFloatEqual(sum.getSimulationLength(), 19.50) - sum = EclSum(case, lazy_load=False) + sum = Summary(case, lazy_load=False) self.assertEqual(sum.getStartTime(), datetime.datetime(2013, 1, 1, 0, 0, 0)) self.assertEqual(sum.getEndTime(), datetime.datetime(2013, 1, 1, 19, 30, 0)) self.assertFloatEqual(sum.getSimulationLength(), 19.50) diff --git a/python/tests/ecl_tests/test_ecl_sum_vector.py b/python/tests/rd_tests/test_rd_sum_vector.py similarity index 54% rename from python/tests/ecl_tests/test_ecl_sum_vector.py rename to python/tests/rd_tests/test_rd_sum_vector.py index 1317d7eb2a..de9d030166 100644 --- a/python/tests/ecl_tests/test_ecl_sum_vector.py +++ b/python/tests/rd_tests/test_rd_sum_vector.py @@ -6,32 +6,32 @@ import warnings -from ecl.summary import EclSumVector, EclSum -from tests import EclTest, equinor_test +from resdata.summary import SummaryVector, Summary +from tests import ResdataTest, equinor_test @equinor_test() -class EclSumVectorTest(EclTest): +class SummaryVectorTest(ResdataTest): def setUp(self): self.test_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") - self.ecl_sum = EclSum(self.test_file) + self.rd_sum = Summary(self.test_file) def test_reportOnly_warns(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - vector = EclSumVector(self.ecl_sum, "FOPT", True) + vector = SummaryVector(self.rd_sum, "FOPT", True) self.assertEqual(len(w), 1) assert issubclass(w[-1].category, DeprecationWarning) def test_basic(self): - self.assertEqual(512, len(self.ecl_sum.keys())) - pfx = "EclSum(name" - self.assertEqual(pfx, repr(self.ecl_sum)[: len(pfx)]) - it = iter(self.ecl_sum) - # t = self.ecl_sum[it.next()] # EclSumVector - t = self.ecl_sum[next(it)] # EclSumVector + self.assertEqual(512, len(self.rd_sum.keys())) + pfx = "Summary(name" + self.assertEqual(pfx, repr(self.rd_sum)[: len(pfx)]) + it = iter(self.rd_sum) + # t = self.rd_sum[it.next()] # SummaryVector + t = self.rd_sum[next(it)] # SummaryVector self.assertEqual(63, len(t)) self.assertEqual("BARSA", t.unit) - pfx = "EclSumVector(key = " + pfx = "SummaryVector(key = " self.assertEqual(pfx, repr(t)[: len(pfx)]) diff --git a/python/tests/rd_tests/test_rd_type.py b/python/tests/rd_tests/test_rd_type.py new file mode 100644 index 0000000000..adad89d9ae --- /dev/null +++ b/python/tests/rd_tests/test_rd_type.py @@ -0,0 +1,141 @@ +from resdata.util.test import TestAreaContext +from tests import ResdataTest + +from resdata import ResDataType, ResdataTypeEnum + + +def get_const_size_types(): + return ResdataTypeEnum.enums()[:-1:] + + +class ResDataTypeTest(ResdataTest): + # All of the below should list their elements in the same order as + # ResdataTypeEnum! + # [char, float, double, int, bool, mess] + + CONST_SIZES = [8, 4, 8, 4, 4, 0] + + CONST_VERIFIERS = [ + ResDataType.is_char, + ResDataType.is_float, + ResDataType.is_double, + ResDataType.is_int, + ResDataType.is_bool, + ResDataType.is_mess, + ] + + CONST_NAMES = ["CHAR", "REAL", "DOUB", "INTE", "LOGI", "MESS"] + + STRING_NAMES = ["C000", "C010", "C020", "C042", "C999"] + + STRING_SIZES = [0, 10, 20, 42, 999] + + TYPES = get_const_size_types() + len(STRING_SIZES) * [ + ResdataTypeEnum.RD_STRING_TYPE + ] + + SIZES = CONST_SIZES + STRING_SIZES + + NAMES = CONST_NAMES + STRING_NAMES + + def test_alloc_from_type(self): + types, sizes = get_const_size_types(), self.CONST_SIZES + for rd_type, element_size in zip(types, sizes): + data_type = ResDataType(rd_type) + self.assertEqual(rd_type, data_type.type) + self.assertEqual(element_size, data_type.element_size) + + def test_invalid_string_alloc(self): + with self.assertRaises(ValueError): + data_type = ResDataType(ResdataTypeEnum.RD_STRING_TYPE) + + with self.assertRaises(ValueError): + data_type = ResDataType(ResdataTypeEnum.RD_STRING_TYPE, -1) + + with self.assertRaises(ValueError): + data_type = ResDataType(ResdataTypeEnum.RD_STRING_TYPE, 1000) + + def test_alloc(self): + for rd_type, element_size in zip(self.TYPES, self.SIZES): + data_type = ResDataType(rd_type, element_size) + self.assertEqual(rd_type, data_type.type) + self.assertEqual(element_size, data_type.element_size) + + def test_type_verifiers(self): + test_base = zip(self.TYPES, self.SIZES, self.CONST_VERIFIERS) + for rd_type, elem_size, verifier in test_base: + data_type = ResDataType(rd_type, elem_size) + self.assertTrue(verifier(data_type)) + + def test_get_type_name(self): + test_base = zip(self.TYPES, self.SIZES, self.NAMES) + for rd_type, elem_size, type_name in test_base: + data_type = ResDataType(rd_type, elem_size) + self.assertEqual(type_name, data_type.type_name) + + def test_initialization_validation(self): + invalid_args = [ + (None, 0, self.CONST_NAMES[0]), + (1, None, self.CONST_NAMES[0]), + (1, 0, self.CONST_NAMES[0]), + (None, None, None), + (None, 12, None), + ] + + for inv_arg in invalid_args: + with self.assertRaises(ValueError): + ResDataType(inv_arg[0], inv_arg[1], inv_arg[2]) + + def test_create_from_type_name(self): + test_base = zip(self.TYPES, self.SIZES, self.NAMES) + for rd_type, elem_size, type_name in test_base: + data_type = ResDataType.create_from_type_name(type_name) + self.assertEqual(rd_type, data_type.type) + self.assertEqual(elem_size, data_type.element_size) + self.assertEqual(type_name, data_type.type_name) + + def test_is_numeric(self): + numeric_types = [ + ResdataTypeEnum.RD_INT_TYPE, + ResdataTypeEnum.RD_FLOAT_TYPE, + ResdataTypeEnum.RD_DOUBLE_TYPE, + ] + + for rd_type in numeric_types: + self.assertTrue(ResDataType(rd_type).is_numeric()) + + for rd_type in set(get_const_size_types()) - set(numeric_types): + self.assertFalse(ResDataType(rd_type).is_numeric()) + + for elem_size in self.STRING_SIZES: + data_type = ResDataType(ResdataTypeEnum.RD_STRING_TYPE, elem_size) + self.assertFalse(data_type.is_numeric()) + + def test_equals(self): + test_base = zip(self.TYPES, self.SIZES) + for rd_type, elem_size in test_base: + a = ResDataType(rd_type, elem_size) + b = ResDataType(rd_type, elem_size) + + self.assertTrue(a.is_equal(b)) + self.assertEqual(a, b) + + for otype, osize in set(test_base) - set([(rd_type, elem_size)]): + self.assertFalse(a.is_equal(ResDataType(otype, osize))) + self.assertNotEqual(a, ResDataType(otype, osize)) + + def test_hash(self): + all_types = set() + test_base = list(zip(self.TYPES, self.SIZES)) + + for index, (rd_type, elem_size) in enumerate(test_base): + all_types.add(ResDataType(rd_type, elem_size)) + self.assertEqual(index + 1, len(all_types)) + + for index, (rd_type, elem_size) in enumerate(test_base): + all_types.add(ResDataType(rd_type, elem_size)) + + for index, rd_type in enumerate(get_const_size_types()): + all_types.add(ResDataType(rd_type)) + + self.assertEqual(len(test_base), len(all_types)) diff --git a/python/tests/rd_tests/test_rd_util.py b/python/tests/rd_tests/test_rd_util.py new file mode 100644 index 0000000000..2845048aa4 --- /dev/null +++ b/python/tests/rd_tests/test_rd_util.py @@ -0,0 +1,20 @@ +from resdata import FileType, ResdataTypeEnum, ResdataUtil +from resdata.grid import Grid +from tests import ResdataTest + + +class ResdataUtilTest(ResdataTest): + def test_enums(self): + source_file_path = "lib/include/resdata/rd_type.hpp" + self.assertEnumIsFullyDefined(ResdataTypeEnum, "rd_type_enum", source_file_path) + + def test_file_type(self): + file_type, fmt, report = ResdataUtil.inspectExtension("CASE.X0078") + self.assertEqual(file_type, FileType.RESTART) + + def test_file_report_nr(self): + report_nr = ResdataUtil.reportStep("CASE.X0080") + self.assertEqual(report_nr, 80) + + with self.assertRaises(ValueError): + ResdataUtil.reportStep("CASE.EGRID") diff --git a/python/tests/ecl_tests/test_region.py b/python/tests/rd_tests/test_region.py similarity index 57% rename from python/tests/ecl_tests/test_region.py rename to python/tests/rd_tests/test_region.py index f6ef6af1e5..540bd17b0a 100644 --- a/python/tests/ecl_tests/test_region.py +++ b/python/tests/rd_tests/test_region.py @@ -1,19 +1,19 @@ -from ecl import EclDataType -from ecl.eclfile import EclKW -from ecl.grid import EclGrid, EclRegion -from ecl.grid.faults import Layer -from ecl.util.util import IntVector -from tests import EclTest +from resdata import ResDataType +from resdata.resfile import ResdataKW +from resdata.grid import Grid, ResdataRegion +from resdata.grid.faults import Layer +from resdata.util.util import IntVector +from tests import ResdataTest -class RegionTest(EclTest): +class RegionTest(ResdataTest): def test_equal(self): - grid = EclGrid.createRectangular((10, 10, 1), (1, 1, 1)) - kw_int = EclKW("INT", grid.getGlobalSize(), EclDataType.ECL_INT) - kw_float = EclKW("FLOAT", grid.getGlobalSize(), EclDataType.ECL_FLOAT) + grid = Grid.createRectangular((10, 10, 1), (1, 1, 1)) + kw_int = ResdataKW("INT", grid.getGlobalSize(), ResDataType.RD_INT) + kw_float = ResdataKW("FLOAT", grid.getGlobalSize(), ResDataType.RD_FLOAT) kw_int[0:49] = 1 - region = EclRegion(grid, False) + region = ResdataRegion(grid, False) region.select_equal(kw_int, 1) glist = region.getGlobalList() for g in glist: @@ -23,12 +23,12 @@ def test_equal(self): region.select_equal(kw_float, 1) def test_sum(self): - grid = EclGrid.createRectangular((10, 10, 1), (1, 1, 1)) - kw_mask = EclKW("INT", grid.getGlobalSize(), EclDataType.ECL_INT) - int_value = EclKW("INT", grid.getGlobalSize(), EclDataType.ECL_INT) - float_value = EclKW("FLOAT", grid.getGlobalSize(), EclDataType.ECL_FLOAT) - double_value = EclKW("DOUBLE", grid.getGlobalSize(), EclDataType.ECL_DOUBLE) - bool_value = EclKW("BOOL", grid.getGlobalSize(), EclDataType.ECL_BOOL) + grid = Grid.createRectangular((10, 10, 1), (1, 1, 1)) + kw_mask = ResdataKW("INT", grid.getGlobalSize(), ResDataType.RD_INT) + int_value = ResdataKW("INT", grid.getGlobalSize(), ResDataType.RD_INT) + float_value = ResdataKW("FLOAT", grid.getGlobalSize(), ResDataType.RD_FLOAT) + double_value = ResdataKW("DOUBLE", grid.getGlobalSize(), ResDataType.RD_DOUBLE) + bool_value = ResdataKW("BOOL", grid.getGlobalSize(), ResDataType.RD_BOOL) kw_mask[0:50] = 1 @@ -38,7 +38,7 @@ def test_sum(self): int_value[i] = i bool_value[i] = True - region = EclRegion(grid, False) + region = ResdataRegion(grid, False) region.select_equal(kw_mask, 1) self.assertEqual(int_value.sum(), 99 * 100 / 2) @@ -50,8 +50,8 @@ def test_sum(self): def test_truth_and_size(self): actnum = IntVector(initial_size=100, default_value=0) actnum[0:50] = 1 - grid = EclGrid.createRectangular((10, 10, 1), (1, 1, 1), actnum=actnum) - region = EclRegion(grid, False) + grid = Grid.createRectangular((10, 10, 1), (1, 1, 1), actnum=actnum) + region = ResdataRegion(grid, False) self.assertFalse(region) self.assertEqual(0, region.active_size()) @@ -67,7 +67,7 @@ def test_truth_and_size(self): self.assertEqual(0, region.active_size()) self.assertEqual(0, region.global_size()) - region = EclRegion(grid, False) + region = ResdataRegion(grid, False) region.select_inactive() self.assertTrue(region) self.assertEqual(0, region.active_size()) diff --git a/python/tests/ecl_tests/test_region_equinor.py b/python/tests/rd_tests/test_region_equinor.py similarity index 83% rename from python/tests/ecl_tests/test_region_equinor.py rename to python/tests/rd_tests/test_region_equinor.py index afa9239c3b..dc84dd95c9 100755 --- a/python/tests/ecl_tests/test_region_equinor.py +++ b/python/tests/rd_tests/test_region_equinor.py @@ -1,24 +1,24 @@ #!/usr/bin/env python -from ecl.eclfile import EclFile -from ecl.grid import EclGrid, EclRegion -from ecl.grid.faults import Layer -from tests import EclTest, equinor_test +from resdata.resfile import ResdataFile +from resdata.grid import Grid, ResdataRegion +from resdata.grid.faults import Layer +from tests import ResdataTest, equinor_test @equinor_test() -class RegionTest(EclTest): +class RegionTest(ResdataTest): def setUp(self): case = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE") - self.grid = EclGrid(case) - self.rst_file = EclFile("%s.UNRST" % case) - self.init_file = EclFile("%s.INIT" % case) + self.grid = Grid(case) + self.rst_file = ResdataFile("%s.UNRST" % case) + self.init_file = ResdataFile("%s.INIT" % case) def test_kw_imul(self): P = self.rst_file["PRESSURE"][5] fipnum = self.init_file["FIPNUM"][0] fipnum_copy = fipnum.deep_copy() - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) reg.select_more(P, 260) fipnum.mul(-1, mask=reg) self.assertFalse(fipnum.equal(fipnum_copy)) @@ -27,8 +27,8 @@ def test_kw_imul(self): self.assertTrue(fipnum.equal(fipnum_copy)) def test_equal(self): - reg1 = EclRegion(self.grid, False) - reg2 = EclRegion(self.grid, False) + reg1 = ResdataRegion(self.grid, False) + reg2 = ResdataRegion(self.grid, False) self.assertTrue(reg1 == reg2) @@ -44,7 +44,7 @@ def test_kw_idiv(self): fipnum = self.init_file["FIPNUM"][0] fipnum_copy = fipnum.deep_copy() - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) reg.select_more(P, 260) fipnum.div(-1, mask=reg) self.assertFalse(fipnum.equal(fipnum_copy)) @@ -57,7 +57,7 @@ def test_kw_iadd(self): fipnum = self.init_file["FIPNUM"][0] fipnum_copy = fipnum.deep_copy() - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) reg.select_more(P, 260) fipnum.add(1, mask=reg) self.assertFalse(fipnum.equal(fipnum_copy)) @@ -73,7 +73,7 @@ def test_kw_isub(self): fipnum = self.init_file["FIPNUM"][0] fipnum_copy = fipnum.deep_copy() - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) reg.select_more(P, 260) fipnum.sub(1, mask=reg) self.assertFalse(fipnum.equal(fipnum_copy)) @@ -81,7 +81,7 @@ def test_kw_isub(self): self.assertTrue(fipnum.equal(fipnum_copy)) def test_slice(self): - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) reg.select_islice(0, 5) OK = True @@ -110,7 +110,7 @@ def test_slice(self): self.assertTrue(OK) self.assertTrue(2 * self.grid.getNZ() * 6 == len(reg.getGlobalList())) - reg2 = EclRegion(self.grid, False) + reg2 = ResdataRegion(self.grid, False) reg2.select_kslice(3, 5) reg &= reg2 OK = True @@ -129,13 +129,13 @@ def test_slice(self): self.assertTrue(2 * 3 * 6 == len(reg.getGlobalList())) def test_index_list(self): - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) reg.select_islice(0, 5) active_list = reg.getActiveList() global_list = reg.getGlobalList() def test_polygon(self): - reg = EclRegion(self.grid, False) + reg = ResdataRegion(self.grid, False) (x, y, z) = self.grid.get_xyz(ijk=(10, 10, 0)) dx = 0.1 dy = 0.1 @@ -146,7 +146,7 @@ def test_polygon(self): def test_heidrun(self): root = self.createTestPath("Equinor/ECLIPSE/Heidrun") - grid = EclGrid("%s/FF12_2013B2_AMAP_AOP-J15_NO62_MOVEX.EGRID" % root) + grid = Grid("%s/FF12_2013B2_AMAP_AOP-J15_NO62_MOVEX.EGRID" % root) polygon = [] with open("%s/polygon.ply" % root) as fileH: @@ -155,12 +155,12 @@ def test_heidrun(self): polygon.append((float(tmp[0]), float(tmp[1]))) self.assertEqual(len(polygon), 11) - reg = EclRegion(grid, False) + reg = ResdataRegion(grid, False) reg.select_inside_polygon(polygon) self.assertEqual(0, len(reg.getGlobalList()) % grid.getNZ()) def test_layer(self): - region = EclRegion(self.grid, False) + region = ResdataRegion(self.grid, False) layer = Layer(self.grid.getNX(), self.grid.getNY() + 1) with self.assertRaises(ValueError): region.selectFromLayer(layer, 0, 1) diff --git a/python/tests/ecl_tests/test_removed.py b/python/tests/rd_tests/test_removed.py similarity index 62% rename from python/tests/ecl_tests/test_removed.py rename to python/tests/rd_tests/test_removed.py index 2fea80ca50..fc186de1a0 100644 --- a/python/tests/ecl_tests/test_removed.py +++ b/python/tests/rd_tests/test_removed.py @@ -1,20 +1,20 @@ import time import datetime -from ecl.util.test import TestAreaContext -from tests import EclTest -from ecl import EclDataType -from ecl.eclfile import EclFile, EclKW, openFortIO, FortIO +from resdata.util.test import TestAreaContext +from tests import ResdataTest +from resdata import ResDataType +from resdata.resfile import ResdataFile, ResdataKW, openFortIO, FortIO -class Removed_2_1_Test(EclTest): - def test_ecl_file_block(self): +class Removed_2_1_Test(ResdataTest): + def test_rd_file_block(self): with TestAreaContext("name") as t: - kw = EclKW("TEST", 3, EclDataType.ECL_INT) + kw = ResdataKW("TEST", 3, ResDataType.RD_INT) with openFortIO("TEST", mode=FortIO.WRITE_MODE) as f: kw.fwrite(f) - f = EclFile("TEST") + f = ResdataFile("TEST") with self.assertRaises(NotImplementedError): f.select_block("KW", 100) @@ -28,4 +28,4 @@ def test_ecl_file_block(self): f.select_restart_section() with self.assertRaises(NotImplementedError): - EclFile.restart_block("TEST") + ResdataFile.restart_block("TEST") diff --git a/python/tests/ecl_tests/test_restart.py b/python/tests/rd_tests/test_restart.py similarity index 69% rename from python/tests/ecl_tests/test_restart.py rename to python/tests/rd_tests/test_restart.py index 1845abbc98..a327536c72 100755 --- a/python/tests/ecl_tests/test_restart.py +++ b/python/tests/rd_tests/test_restart.py @@ -2,12 +2,12 @@ from _ctypes import ArgumentError import os import datetime -from ecl.eclfile import EclFile -from tests import EclTest, equinor_test +from resdata.resfile import ResdataFile +from tests import ResdataTest, equinor_test @equinor_test() -class RestartTest(EclTest): +class RestartTest(ResdataTest): def setUp(self): self.xfile0 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.X0000") self.u_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") @@ -24,13 +24,13 @@ def tearDown(self): os.unlink(f) def report_file_test(self, fname): - self.assertTrue(EclFile.contains_report_step(fname, 4)) - self.assertTrue(EclFile.contains_report_step(fname, 0)) - self.assertTrue(EclFile.contains_report_step(fname, 62)) - self.assertFalse(EclFile.contains_report_step(fname, -1)) - self.assertFalse(EclFile.contains_report_step(fname, 100)) + self.assertTrue(ResdataFile.contains_report_step(fname, 4)) + self.assertTrue(ResdataFile.contains_report_step(fname, 0)) + self.assertTrue(ResdataFile.contains_report_step(fname, 62)) + self.assertFalse(ResdataFile.contains_report_step(fname, -1)) + self.assertFalse(ResdataFile.contains_report_step(fname, 100)) - f = EclFile(fname) + f = ResdataFile(fname) self.assertTrue(f.has_report_step(4)) self.assertTrue(f.has_report_step(0)) self.assertTrue(f.has_report_step(62)) @@ -42,30 +42,30 @@ def test_report(self): self.report_file_test(self.u_file) def test_date(self): - f = EclFile(self.u_file) + f = ResdataFile(self.u_file) self.assertTrue(f.has_sim_time(datetime.datetime(2001, 6, 1))) self.assertFalse(f.has_sim_time(datetime.datetime(2005, 6, 1))) self.assertFalse(f.has_sim_time(datetime.datetime(1999, 6, 1))) self.assertFalse(f.has_sim_time(datetime.datetime(2001, 6, 11))) self.assertTrue( - EclFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 1)) + ResdataFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 1)) ) self.assertFalse( - EclFile.contains_sim_time(self.u_file, datetime.datetime(2005, 6, 1)) + ResdataFile.contains_sim_time(self.u_file, datetime.datetime(2005, 6, 1)) ) self.assertFalse( - EclFile.contains_sim_time(self.u_file, datetime.datetime(1999, 6, 1)) + ResdataFile.contains_sim_time(self.u_file, datetime.datetime(1999, 6, 1)) ) self.assertFalse( - EclFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 11)) + ResdataFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 11)) ) def report_list_file_test(self, fname, rlist0): - rlist = EclFile.file_report_list(fname) + rlist = ResdataFile.file_report_list(fname) self.assertListEqual(rlist, rlist0) - f = EclFile(fname) + f = ResdataFile(fname) rlist = f.report_list self.assertListEqual(rlist, rlist0) @@ -77,24 +77,24 @@ def test_report_list(self): self.report_list_file_test(self.xfile0, rlist0) def test_dates(self): - f = EclFile(self.u_file) + f = ResdataFile(self.u_file) dates = f.dates self.assertTrue(len(dates) == 63) - f = EclFile(self.xfile0) + f = ResdataFile(self.xfile0) dates = f.dates self.assertTrue(len(dates) == 1) self.assertTrue(dates[0] == datetime.datetime(2000, 1, 1)) def test_name(self): - f = EclFile(self.u_file) + f = ResdataFile(self.u_file) self.assertTrue(f.getFilename() == self.u_file) - f = EclFile(self.xfile0) + f = ResdataFile(self.xfile0) self.assertTrue(f.getFilename() == self.xfile0) def test_kw(self): - f = EclFile(self.u_file) + f = ResdataFile(self.u_file) kw1 = f["SWAT"][40] kw2 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1)) kw3 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1), copy=True) diff --git a/python/tests/ecl_tests/test_restart_head.py b/python/tests/rd_tests/test_restart_head.py similarity index 65% rename from python/tests/ecl_tests/test_restart_head.py rename to python/tests/rd_tests/test_restart_head.py index db0150fd7b..a0c2836fed 100644 --- a/python/tests/ecl_tests/test_restart_head.py +++ b/python/tests/rd_tests/test_restart_head.py @@ -1,21 +1,27 @@ import datetime -from tests import EclTest, equinor_test -from ecl import EclFileFlagEnum -from ecl.eclfile import Ecl3DKW, EclKW, EclRestartFile, EclFile, FortIO -from ecl.grid import EclGrid +from tests import ResdataTest, equinor_test +from resdata import FileMode +from resdata.resfile import ( + Resdata3DKW, + ResdataKW, + ResdataRestartFile, + ResdataFile, + FortIO, +) +from resdata.grid import Grid @equinor_test() -class RestartHeadTest(EclTest): +class RestartHeadTest(ResdataTest): def setUp(self): self.grid_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") self.unrst_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") self.xrst_file0 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.X0000") def test_headers(self): - g = EclGrid(self.grid_file) - f = EclRestartFile(g, self.unrst_file) + g = Grid(self.grid_file) + f = ResdataRestartFile(g, self.unrst_file) headers = f.headers() self.assertEqual(len(headers), 63) diff --git a/python/tests/rd_tests/test_rft.py b/python/tests/rd_tests/test_rft.py new file mode 100644 index 0000000000..7ffab89327 --- /dev/null +++ b/python/tests/rd_tests/test_rft.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +import datetime +from resdata.util.util import CTime +from resdata.rft import ( + ResdataRFTFile, + ResdataRFTCell, + ResdataPLTCell, + ResdataRFT, + WellTrajectory, +) +from tests import ResdataTest + + +class RFTTest(ResdataTest): + def test_create(self): + rft = ResdataRFT("WELL", "RFT", datetime.date(2015, 10, 1), 100) + self.assertEqual(len(rft), 0) + + with self.assertRaises(IndexError): + cell = rft[5] + + def test_repr(self): + rft = ResdataRFT("WELL", "RFT", datetime.date(2015, 10, 1), 100) + pfx = "ResdataRFT(completed_cells = 0, date = 2015-10-01, RFT)" + self.assertEqual(pfx, repr(rft)[: len(pfx)]) diff --git a/python/tests/ecl_tests/test_rft_cell.py b/python/tests/rd_tests/test_rft_cell.py similarity index 88% rename from python/tests/ecl_tests/test_rft_cell.py rename to python/tests/rd_tests/test_rft_cell.py index 6be5463161..1dff5931a1 100644 --- a/python/tests/ecl_tests/test_rft_cell.py +++ b/python/tests/rd_tests/test_rft_cell.py @@ -1,14 +1,9 @@ #!/usr/bin/env python -from ecl.rft import EclRFTCell, EclPLTCell -from tests import EclTest +from resdata.rft import ResdataPLTCell, ResdataRFTCell +from tests import ResdataTest -# def out_of_range(): -# rftFile = ecl.EclRFTFile(RFT_file) -# rft = rftFile[100] - - -class RFTCellTest(EclTest): +class RFTCellTest(ResdataTest): def setUp(self): self.RFT_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.RFT") self.PLT_file = self.createTestPath("Equinor/ECLIPSE/RFT/TEST1_1A.RFT") @@ -21,7 +16,7 @@ def test_RFT_cell(self): pressure = 65 swat = 0.56 sgas = 0.10 - cell = EclRFTCell(i, j, k, depth, pressure, swat, sgas) + cell = ResdataRFTCell(i, j, k, depth, pressure, swat, sgas) self.assertEqual(i, cell.get_i()) self.assertEqual(j, cell.get_j()) @@ -49,7 +44,7 @@ def test_PLT_cell(self): gas_flowrate = 132 water_flowrate = 13344 - cell = EclPLTCell( + cell = ResdataPLTCell( i, j, k, diff --git a/python/tests/ecl_tests/test_rft_equinor.py b/python/tests/rd_tests/test_rft_equinor.py similarity index 87% rename from python/tests/ecl_tests/test_rft_equinor.py rename to python/tests/rd_tests/test_rft_equinor.py index 9c62fe1dae..ef76a3738c 100644 --- a/python/tests/ecl_tests/test_rft_equinor.py +++ b/python/tests/rd_tests/test_rft_equinor.py @@ -1,22 +1,22 @@ #!/usr/bin/env python from __future__ import print_function import datetime -from ecl.rft import EclRFTFile, EclRFTCell, EclPLTCell, WellTrajectory -from tests import EclTest, equinor_test +from resdata.rft import ResdataRFTFile, ResdataRFTCell, ResdataPLTCell, WellTrajectory +from tests import ResdataTest, equinor_test @equinor_test() -class RFTTest(EclTest): +class RFTTest(ResdataTest): def setUp(self): self.RFT_file = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.RFT") self.PLT_file = self.createTestPath("Equinor/ECLIPSE/RFT/TEST1_1A.RFT") def test_RFT_load(self): - rftFile = EclRFTFile(self.RFT_file) + rftFile = ResdataRFTFile(self.RFT_file) rft = rftFile[0] cell = rft.ijkget((32, 53, 0)) - self.assertIsInstance(cell, EclRFTCell) + self.assertIsInstance(cell, ResdataRFTCell) self.assertEqual(2, rftFile.size()) self.assertEqual(0, rftFile.size(well="OP*")) @@ -34,14 +34,14 @@ def test_RFT_load(self): self.assertFalse(rft.is_MSW()) for cell in rft: - self.assertIsInstance(cell, EclRFTCell) + self.assertIsInstance(cell, ResdataRFTCell) for h in rftFile.getHeaders(): print(h) self.assertIsInstance(h[1], datetime.date) def test_PLT_load(self): - pltFile = EclRFTFile(self.PLT_file) + pltFile = ResdataRFTFile(self.PLT_file) plt = pltFile[11] self.assertTrue(plt.is_PLT()) self.assertFalse(plt.is_SEGMENT()) @@ -49,11 +49,11 @@ def test_PLT_load(self): self.assertFalse(plt.is_MSW()) for cell in plt: - self.assertIsInstance(cell, EclPLTCell) + self.assertIsInstance(cell, ResdataPLTCell) def test_exceptions(self): with self.assertRaises(IndexError): - rftFile = EclRFTFile(self.RFT_file) + rftFile = ResdataRFTFile(self.RFT_file) rft = rftFile[100] def test_basics(self): @@ -101,7 +101,7 @@ def test_trajectory(self): self.assertEqual(p37, pm1) def test_PLT(self): - rft_file = EclRFTFile( + rft_file = ResdataRFTFile( self.createTestPath("Equinor/ECLIPSE/Heidrun/RFT/2C3_MR61.RFT") ) diff --git a/python/tests/ecl_tests/test_sum.py b/python/tests/rd_tests/test_sum.py similarity index 81% rename from python/tests/ecl_tests/test_sum.py rename to python/tests/rd_tests/test_sum.py index 0508f72589..ab6ac8d448 100644 --- a/python/tests/ecl_tests/test_sum.py +++ b/python/tests/rd_tests/test_sum.py @@ -1,11 +1,12 @@ -import os.path -import os -import inspect -import datetime import csv +import datetime +import inspect +import os +import os.path import shutil -import cwrap import stat + +import cwrap import pandas @@ -22,13 +23,12 @@ def assert_frame_equal(a, b): from contextlib import contextmanager from unittest import skipIf, skipUnless -from ecl import EclUnitTypeEnum -from ecl import EclDataType -from ecl.eclfile import FortIO, openFortIO, EclKW, EclFile -from ecl.summary import EclSum, EclSumVarType, EclSumKeyWordVector -from ecl.util.test import TestAreaContext -from tests import EclTest -from ecl.util.test.ecl_mock import createEclSum +from resdata import ResDataType, UnitSystem +from resdata.resfile import FortIO, ResdataFile, ResdataKW, openFortIO +from resdata.summary import Summary, SummaryKeyWordVector, SummaryVarType +from resdata.util.test import TestAreaContext +from resdata.util.test.mock import createSummary +from tests import ResdataTest @contextmanager @@ -73,7 +73,7 @@ def fgpt(days): def create_case(case="CSV", restart_case=None, restart_step=-1, data_start=None): length = 100 - return createEclSum( + return createSummary( case, [ ("FOPT", None, 0, "SM3"), @@ -92,7 +92,7 @@ def create_case(case="CSV", restart_case=None, restart_step=-1, data_start=None) def create_case2(case="CSV", restart_case=None, restart_step=-1, data_start=None): length = 100 - return createEclSum( + return createSummary( case, [ ("WOPT", "OPX", 0, "SM3"), @@ -111,16 +111,16 @@ def create_case2(case="CSV", restart_case=None, restart_step=-1, data_start=None ) -class SumTest(EclTest): +class SumTest(ResdataTest): def test_mock(self): - case = createEclSum( + case = createSummary( "CSV", [("FOPT", None, 0, "SM3"), ("FOPR", None, 0, "SM3/DAY")] ) self.assertTrue("FOPT" in case) self.assertFalse("WWCT:OPX" in case) def test_TIME_special_case(self): - case = createEclSum( + case = createSummary( "CSV", [("FOPT", None, 0, "SM3"), ("FOPR", None, 0, "SM3/DAY")] ) keys = case.keys() @@ -135,28 +135,32 @@ def test_TIME_special_case(self): def test_identify_var_type(self): self.assertEnumIsFullyDefined( - EclSumVarType, "ecl_smspec_var_type", "lib/include/ert/ecl/smspec_node.h" + SummaryVarType, "rd_smspec_var_type", "lib/include/resdata/smspec_node.h" + ) + self.assertEqual( + Summary.varType("WWCT:OP_X"), SummaryVarType.RD_SMSPEC_WELL_VAR + ) + self.assertEqual(Summary.varType("RPR"), SummaryVarType.RD_SMSPEC_REGION_VAR) + self.assertEqual(Summary.varType("WNEWTON"), SummaryVarType.RD_SMSPEC_MISC_VAR) + self.assertEqual( + Summary.varType("AARQ:4"), SummaryVarType.RD_SMSPEC_AQUIFER_VAR ) - self.assertEqual(EclSum.varType("WWCT:OP_X"), EclSumVarType.ECL_SMSPEC_WELL_VAR) - self.assertEqual(EclSum.varType("RPR"), EclSumVarType.ECL_SMSPEC_REGION_VAR) - self.assertEqual(EclSum.varType("WNEWTON"), EclSumVarType.ECL_SMSPEC_MISC_VAR) - self.assertEqual(EclSum.varType("AARQ:4"), EclSumVarType.ECL_SMSPEC_AQUIFER_VAR) self.assertEqual( - EclSum.varType("RXFT"), EclSumVarType.ECL_SMSPEC_REGION_2_REGION_VAR + Summary.varType("RXFT"), SummaryVarType.RD_SMSPEC_REGION_2_REGION_VAR ) self.assertEqual( - EclSum.varType("RxxFT"), EclSumVarType.ECL_SMSPEC_REGION_2_REGION_VAR + Summary.varType("RxxFT"), SummaryVarType.RD_SMSPEC_REGION_2_REGION_VAR ) self.assertEqual( - EclSum.varType("RXFR"), EclSumVarType.ECL_SMSPEC_REGION_2_REGION_VAR + Summary.varType("RXFR"), SummaryVarType.RD_SMSPEC_REGION_2_REGION_VAR ) self.assertEqual( - EclSum.varType("RxxFR"), EclSumVarType.ECL_SMSPEC_REGION_2_REGION_VAR + Summary.varType("RxxFR"), SummaryVarType.RD_SMSPEC_REGION_2_REGION_VAR ) - self.assertEqual(EclSum.varType("RORFR"), EclSumVarType.ECL_SMSPEC_REGION_VAR) + self.assertEqual(Summary.varType("RORFR"), SummaryVarType.RD_SMSPEC_REGION_VAR) - case = createEclSum( + case = createSummary( "CSV", [ ("FOPT", None, 0, "SM3"), @@ -167,15 +171,15 @@ def test_identify_var_type(self): ) node1 = case.smspec_node("FOPT") - self.assertEqual(node1.varType(), EclSumVarType.ECL_SMSPEC_FIELD_VAR) + self.assertEqual(node1.varType(), SummaryVarType.RD_SMSPEC_FIELD_VAR) self.assertIsNone(node1.wgname) node2 = case.smspec_node("AARQ:10") - self.assertEqual(node2.varType(), EclSumVarType.ECL_SMSPEC_AQUIFER_VAR) + self.assertEqual(node2.varType(), SummaryVarType.RD_SMSPEC_AQUIFER_VAR) self.assertEqual(node2.getNum(), 10) node3 = case.smspec_node("RGPT:1") - self.assertEqual(node3.varType(), EclSumVarType.ECL_SMSPEC_REGION_VAR) + self.assertEqual(node3.varType(), SummaryVarType.RD_SMSPEC_REGION_VAR) self.assertEqual(node3.getNum(), 1) self.assertTrue(node3.isTotal()) @@ -188,11 +192,11 @@ def test_identify_var_type(self): a = node1 < 1 def test_csv_export(self): - case = createEclSum( + case = createSummary( "CSV", [("FOPT", None, 0, "SM3"), ("FOPR", None, 0, "SM3/DAY")] ) sep = ";" - with TestAreaContext("ecl/csv"): + with TestAreaContext("resdata/csv"): case.exportCSV("file.csv", sep=sep) self.assertTrue(os.path.isfile("file.csv")) input_file = csv.DictReader(open("file.csv"), delimiter=sep) @@ -206,7 +210,7 @@ def test_csv_export(self): self.assertEqual(case.unit("FOPT"), "SM3") - with TestAreaContext("ecl/csv"): + with TestAreaContext("resdata/csv"): case.exportCSV("file.csv", keys=["FOPT"], sep=sep) self.assertTrue(os.path.isfile("file.csv")) input_file = csv.DictReader(open("file.csv"), delimiter=sep) @@ -217,7 +221,7 @@ def test_csv_export(self): self.assertEqual(len(row), 3) break - with TestAreaContext("ecl/csv"): + with TestAreaContext("resdata/csv"): date_format = "%y-%m-%d" sep = "," case.exportCSV("file.csv", keys=["F*"], sep=sep, date_format=date_format) @@ -292,12 +296,12 @@ def test_different_names(self): case.fwrite() shutil.move("CSV.SMSPEC", "CSVX.SMSPEC") with self.assertRaises(IOError): - case2 = EclSum.load("Does/not/exist", "CSV.UNSMRY") + case2 = Summary.load("Does/not/exist", "CSV.UNSMRY") with self.assertRaises(IOError): - case2 = EclSum.load("CSVX.SMSPEC", "CSVX.UNSMRY") + case2 = Summary.load("CSVX.SMSPEC", "CSVX.UNSMRY") - case2 = EclSum.load("CSVX.SMSPEC", "CSV.UNSMRY") + case2 = Summary.load("CSVX.SMSPEC", "CSV.UNSMRY") self.assert_solve(case2) self.assertEqual(case.unit("FOPR"), "SM3/DAY") @@ -306,30 +310,30 @@ def test_invalid(self): with TestAreaContext("sum_invalid"): case.fwrite() with open("CASE.txt", "w") as f: - f.write("No - this is not EclKW file ....") + f.write("No - this is not ResdataKW file ....") with self.assertRaises(IOError): - case2 = EclSum.load("CSV.SMSPEC", "CASE.txt") + case2 = Summary.load("CSV.SMSPEC", "CASE.txt") with self.assertRaises(IOError): - case2 = EclSum.load("CASE.txt", "CSV.UNSMRY") + case2 = Summary.load("CASE.txt", "CSV.UNSMRY") - kw1 = EclKW("TEST1", 30, EclDataType.ECL_INT) - kw2 = EclKW("TEST2", 30, EclDataType.ECL_INT) + kw1 = ResdataKW("TEST1", 30, ResDataType.RD_INT) + kw2 = ResdataKW("TEST2", 30, ResDataType.RD_INT) with openFortIO("CASE.KW", FortIO.WRITE_MODE) as f: kw1.fwrite(f) kw2.fwrite(f) with self.assertRaises(IOError): - case2 = EclSum.load("CSV.SMSPEC", "CASE.KW") + case2 = Summary.load("CSV.SMSPEC", "CASE.KW") with self.assertRaises(IOError): - case2 = EclSum.load("CASE.KW", "CSV.UNSMRY") + case2 = Summary.load("CASE.KW", "CSV.UNSMRY") def test_kw_vector(self): case1 = create_case() - case2 = createEclSum( + case2 = createSummary( "CSV", [ ("FOPR", None, 0, "SM3/DAY"), @@ -342,7 +346,7 @@ def test_kw_vector(self): func_table={"FOPT": fopt, "FOPR": fopr, "FWPT": fgpt}, ) - kw_list = EclSumKeyWordVector(case1) + kw_list = SummaryKeyWordVector(case1) kw_list.add_keyword("FOPT") kw_list.add_keyword("FGPT") kw_list.add_keyword("FOPR") @@ -395,11 +399,11 @@ def test_kw_vector(self): def test_vector_select_all(self): case = create_case() - ecl_sum_vector = EclSumKeyWordVector(case, True) + rd_sum_vector = SummaryKeyWordVector(case, True) keys = case.keys() - self.assertEqual(len(keys), len(ecl_sum_vector)) + self.assertEqual(len(keys), len(rd_sum_vector)) for key in keys: - self.assertIn(key, ecl_sum_vector) + self.assertIn(key, rd_sum_vector) def test_first_last(self): case = create_case() @@ -455,12 +459,12 @@ def test_restart_abs_path(self): pred_path = "prediction" create_prediction(history, pred_path) - pred = EclSum(os.path.join(pred_path, "PREDICTION")) + pred = Summary(os.path.join(pred_path, "PREDICTION")) # The restart case has a maximum length of 72 characters, depending # on the path used for $TMP and so on we do not really know here if # the restart_case has been set or not. if pred.restart_case: - self.assertTrue(isinstance(pred.restart_case, EclSum)) + self.assertTrue(isinstance(pred.restart_case, Summary)) self.assertEqual( pred.restart_case.case, os.path.join(os.getcwd(), history.case) ) @@ -483,7 +487,7 @@ def test_restart_too_long_history_path(self): pred_path = "prediction" create_prediction(history, pred_path) - pred = EclSum(os.path.join(pred_path, "PREDICTION")) + pred = Summary(os.path.join(pred_path, "PREDICTION")) self.assertIsNone(pred.restart_case) def test_restart_perm_denied(self): @@ -503,13 +507,13 @@ def test_restart_perm_denied(self): # This just tests that we can create a summary instance even if we do not # have access to load the history case. - pred = EclSum("PREDICTION") + pred = Summary("PREDICTION") os.chmod("history", stat.S_IRWXU) def test_units(self): case = create_case() - self.assertEqual(case.unit_system, EclUnitTypeEnum.ECL_METRIC_UNITS) + self.assertEqual(case.unit_system, UnitSystem.METRIC) # We do not really have support for writing anything else than the # default MERIC unit system. To be able to test the read functionality @@ -517,10 +521,10 @@ def test_units(self): with TestAreaContext("unit_test"): case = create_case("UNITS") case.fwrite() - case2 = EclSum("UNITS") + case2 = Summary("UNITS") kw_list = [] - f = EclFile("UNITS.SMSPEC") + f = ResdataFile("UNITS.SMSPEC") for kw in f: if kw.name == "INTEHEAD": kw[0] = 3 @@ -531,8 +535,8 @@ def test_units(self): for kw in kw_list: kw.fwrite(f) - case = EclSum("UNITS") - self.assertEqual(case.unit_system, EclUnitTypeEnum.ECL_LAB_UNITS) + case = Summary("UNITS") + self.assertEqual(case.unit_system, UnitSystem.LAB) def test_numpy_vector(self): case = create_case() @@ -614,15 +618,15 @@ def test_pandas(self): def test_csv_load(self): case = create_case2() frame = case.pandas_frame() - ecl_sum = EclSum.from_pandas("PANDAS", frame, dims=[20, 10, 5]) + rd_sum = Summary.from_pandas("PANDAS", frame, dims=[20, 10, 5]) for key in frame.columns: - self.assertTrue(key in ecl_sum) + self.assertTrue(key in rd_sum) - df = ecl_sum.pandas_frame() + df = rd_sum.pandas_frame() assert_frame_equal(frame, df) - ecl_sum_less = EclSum.from_pandas( + rd_sum_less = Summary.from_pandas( "PANDAS", frame, dims=[20, 10, 5], @@ -630,23 +634,23 @@ def test_csv_load(self): ) del frame["WOPT:OPX"] del frame["FOPR"] - df_less = ecl_sum_less.pandas_frame() + df_less = rd_sum_less.pandas_frame() assert_frame_equal(frame, df_less) def test_total_and_rate(self): - self.assertTrue(EclSum.is_total("FOPT")) - self.assertTrue(EclSum.is_total("WWPT:OP_3")) - self.assertFalse(EclSum.is_total("RPR:2")) + self.assertTrue(Summary.is_total("FOPT")) + self.assertTrue(Summary.is_total("WWPT:OP_3")) + self.assertFalse(Summary.is_total("RPR:2")) - self.assertTrue(EclSum.is_rate("WOPR:OP_4")) - self.assertFalse(EclSum.is_rate("BPR:123")) - self.assertTrue(EclSum.is_rate("FWIR")) + self.assertTrue(Summary.is_rate("WOPR:OP_4")) + self.assertFalse(Summary.is_rate("BPR:123")) + self.assertTrue(Summary.is_rate("FWIR")) def test_load_case(self): path = os.path.join( self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3" ) - case = EclSum(path) + case = Summary(path) self.assertFloatEqual(case.sim_length, 545.0) fopr = case.numpy_vector("FOPR") @@ -655,8 +659,8 @@ def test_load_case(self): def test_load_case_lazy_and_eager(self): path = os.path.join(self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SHORT.UNSMRY") - lazy_dates = EclSum(path, lazy_load=True).numpy_dates - eager_dates = EclSum(path, lazy_load=False).numpy_dates + lazy_dates = Summary(path, lazy_load=True).numpy_dates + eager_dates = Summary(path, lazy_load=False).numpy_dates self.assertEqual(len(lazy_dates), 107) self.assertEqual(len(eager_dates), 107) for l, e in zip(lazy_dates, eager_dates): @@ -666,7 +670,7 @@ def test_write_not_implemented(self): path = os.path.join( self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3" ) - case = EclSum(path, lazy_load=True) + case = Summary(path, lazy_load=True) self.assertFalse(case.can_write()) with self.assertRaises(NotImplementedError): case.fwrite() @@ -676,23 +680,23 @@ def test_directory_conflict(self): case = create_case("UNITS") case.fwrite() os.mkdir("UNITS") - case2 = EclSum("./UNITS") + case2 = Summary("./UNITS") def test_resample_extrapolate(self): """ Test resampling of summary with extrapolate option of lower and upper boundaries enabled """ - from ecl.util.util import TimeVector, CTime + from resdata.util.util import CTime, TimeVector time_points = TimeVector() path = os.path.join( self.TESTDATA_ROOT, "local/ECLIPSE/cp_simple3/SIMPLE_SUMMARY3" ) - ecl_sum = EclSum(path, lazy_load=True) + rd_sum = Summary(path, lazy_load=True) - start_time = ecl_sum.get_data_start_time() - datetime.timedelta(seconds=86400) - end_time = ecl_sum.get_end_time() + datetime.timedelta(seconds=86400) + start_time = rd_sum.get_data_start_time() - datetime.timedelta(seconds=86400) + end_time = rd_sum.get_end_time() + datetime.timedelta(seconds=86400) delta = end_time - start_time N = 25 @@ -702,47 +706,47 @@ def test_resample_extrapolate(self): CTime(int(delta.total_seconds() / (N - 1))), ) time_points.append(CTime(end_time)) - resampled = ecl_sum.resample( + resampled = rd_sum.resample( "OUTPUT_CASE", time_points, lower_extrapolation=True, upper_extrapolation=True, ) - for key in ecl_sum.keys(): + for key in rd_sum.keys(): self.assertIn(key, resampled) self.assertEqual( - ecl_sum.get_data_start_time() - datetime.timedelta(seconds=86400), + rd_sum.get_data_start_time() - datetime.timedelta(seconds=86400), resampled.get_data_start_time(), ) key_not_rate = "FOPT" for time_index, t in enumerate(time_points): - if t < ecl_sum.get_data_start_time(): + if t < rd_sum.get_data_start_time(): self.assertFloatEqual( resampled.iget(key_not_rate, time_index), - ecl_sum._get_first_value(key_not_rate), + rd_sum._get_first_value(key_not_rate), ) - elif t > ecl_sum.get_end_time(): + elif t > rd_sum.get_end_time(): self.assertFloatEqual( resampled.iget(key_not_rate, time_index), - ecl_sum.get_last_value(key_not_rate), + rd_sum.get_last_value(key_not_rate), ) else: self.assertFloatEqual( resampled.iget(key_not_rate, time_index), - ecl_sum.get_interp_direct(key_not_rate, t), + rd_sum.get_interp_direct(key_not_rate, t), ) key_rate = "FOPR" for time_index, t in enumerate(time_points): - if t < ecl_sum.get_data_start_time(): + if t < rd_sum.get_data_start_time(): self.assertFloatEqual(resampled.iget(key_rate, time_index), 0) - elif t > ecl_sum.get_end_time(): + elif t > rd_sum.get_end_time(): self.assertFloatEqual(resampled.iget(key_rate, time_index), 0) else: self.assertFloatEqual( resampled.iget(key_rate, time_index), - ecl_sum.get_interp_direct(key_rate, t), + rd_sum.get_interp_direct(key_rate, t), ) diff --git a/python/tests/ecl_tests/test_sum_equinor.py b/python/tests/rd_tests/test_sum_equinor.py similarity index 82% rename from python/tests/ecl_tests/test_sum_equinor.py rename to python/tests/rd_tests/test_sum_equinor.py index 7a16581b7d..10044b8259 100755 --- a/python/tests/ecl_tests/test_sum_equinor.py +++ b/python/tests/rd_tests/test_sum_equinor.py @@ -3,14 +3,14 @@ from unittest import skipIf, skipUnless, skipIf -from ecl.eclfile import EclFile -from ecl.summary import EclSum -from ecl import EclUnitTypeEnum +from resdata.resfile import ResdataFile +from resdata.summary import Summary +from resdata import UnitSystem -from ecl.util.util import StringList, TimeVector, DoubleVector, CTime +from resdata.util.util import StringList, TimeVector, DoubleVector, CTime -from ecl.util.test import TestAreaContext -from tests import EclTest, equinor_test +from resdata.util.test import TestAreaContext +from tests import ResdataTest, equinor_test import csv base = "ECLIPSE" @@ -25,22 +25,22 @@ def sum_get(*args): @equinor_test() -class SumTest(EclTest): +class SumTest(ResdataTest): def setUp(self): self.case = self.createTestPath(case) - self.ecl_sum = EclSum(self.case) + self.rd_sum = Summary(self.case) - self.assertIsInstance(self.ecl_sum, EclSum) + self.assertIsInstance(self.rd_sum, Summary) def test_load(self): - self.assertIsNotNone(self.ecl_sum, "Load failed") + self.assertIsNotNone(self.rd_sum, "Load failed") def test_invalid(self): with self.assertRaises(IOError): - sum = EclSum("Does/not/exist") + sum = Summary("Does/not/exist") def test_KeyError(self): - sum = self.ecl_sum + sum = self.rd_sum with self.assertRaises(KeyError): v = sum.numpy_vector("KeyMissing") @@ -51,11 +51,11 @@ def test_KeyError(self): v = sum.get_interp_vector("Missing", days_list=[750]) def test_contains(self): - self.assertTrue("FOPT" in self.ecl_sum) - self.assertFalse("MISSING" in self.ecl_sum) + self.assertTrue("FOPT" in self.rd_sum) + self.assertFalse("MISSING" in self.rd_sum) def test_interp(self): - sum = self.ecl_sum + sum = self.rd_sum self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", days=750), 0.11719122) self.assertAlmostEqual( @@ -98,7 +98,7 @@ def test_interp(self): sum.get_interp("WOPR:OP_1", days=10, date=datetime.date(2000, 1, 1)) def test_LLINEAR(self): - sum = EclSum( + sum = Summary( self.createTestPath( "Equinor/ECLIPSE/Heidrun/LGRISSUE/EM-LTAA-ISEG_CARFIN_NWPROPS" ) @@ -106,32 +106,32 @@ def test_LLINEAR(self): self.assertTrue(sum.has_key("LLINEARS")) def test_wells(self): - wells = self.ecl_sum.wells() + wells = self.rd_sum.wells() wells.sort() self.assertListEqual( [well for well in wells], ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"], ) - wells = self.ecl_sum.wells(pattern="*_3") + wells = self.rd_sum.wells(pattern="*_3") wells.sort() self.assertListEqual([well for well in wells], ["OP_3", "WI_3"]) - groups = self.ecl_sum.groups() + groups = self.rd_sum.groups() groups.sort() self.assertListEqual([group for group in groups], ["GMWIN", "OP", "WI"]) def test_last(self): - last = self.ecl_sum.get_last("FOPT") + last = self.rd_sum.get_last("FOPT") self.assertFloatEqual(last.value, 38006336.0) self.assertFloatEqual(last.days, 1826.0) self.assertEqual(last.date, datetime.datetime(2004, 12, 31, 0, 0, 0)) - self.assertFloatEqual(self.ecl_sum.last_value("FGPT"), 6605249024.0) - self.assertEqual(len(self.ecl_sum), 63) + self.assertFloatEqual(self.rd_sum.last_value("FGPT"), 6605249024.0) + self.assertEqual(len(self.rd_sum), 63) def test_dates(self): - sum = self.ecl_sum + sum = self.rd_sum d = sum.dates self.assertEqual(d[0], datetime.datetime(2000, 1, 1, 0, 0, 0)) @@ -152,23 +152,23 @@ def test_dates(self): self.assertEqual(sum.end_date, datetime.date(2004, 12, 31)) def test_dates2(self): - sum = EclSum(self.createTestPath("Equinor/ECLIPSE/FF12/FF12_2013B3_AMAP2")) + sum = Summary(self.createTestPath("Equinor/ECLIPSE/FF12/FF12_2013B3_AMAP2")) self.assertEqual(sum.end_date, datetime.date(2045, 1, 1)) def test_keys(self): - sum = self.ecl_sum + sum = self.rd_sum self.assertRaises(KeyError, sum.__getitem__, "BJARNE") v = sum["FOPT"] self.assertEqual(len(v), 63) def test_index(self): - sum = self.ecl_sum + sum = self.rd_sum index = sum.get_key_index("TCPUDAY") self.assertEqual(index, 10239) def test_report(self): - sum = self.ecl_sum + sum = self.rd_sum self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 1)), 10) self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 3)), -1) self.assertEqual(sum.get_report(date=datetime.date(1980, 10, 3)), -1) @@ -187,27 +187,27 @@ def test_report(self): self.assertFloatEqual(sum.get_from_report("FOPT", 10), 6.67447e06) def test_fwrite(self): - ecl_sum = EclSum(self.case, lazy_load=False) + rd_sum = Summary(self.case, lazy_load=False) with TestAreaContext("python/sum-test/fwrite") as work_area: - ecl_sum.fwrite(ecl_case="CASE") + rd_sum.fwrite(rd_case="CASE") self.assertTrue(True) def test_block(self): - sum = self.ecl_sum + sum = self.rd_sum index_ijk = sum.get_key_index("BPR:15,28,1") index_num = sum.get_key_index("BPR:1095") self.assertEqual(index_ijk, index_num) def test_restart(self): - hist = EclSum( + hist = Summary( self.createTestPath( "Equinor/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1" ) ) - base = EclSum( + base = Summary( self.createTestPath("Equinor/ECLIPSE/sum-restart/prediction/BASECASE") ) - pred = EclSum( + pred = Summary( self.createTestPath("Equinor/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False, ) @@ -217,15 +217,15 @@ def test_restart(self): self.assertIsNotNone(pred) def test_case1(self): - self.assertTrue(self.ecl_sum.path == self.createTestPath(path)) - self.assertTrue(self.ecl_sum.base == base) - self.assertTrue(self.ecl_sum.case == self.createTestPath(case)) - self.assertTrue(self.ecl_sum.abs_path == self.createTestPath(path)) + self.assertTrue(self.rd_sum.path == self.createTestPath(path)) + self.assertTrue(self.rd_sum.base == base) + self.assertTrue(self.rd_sum.case == self.createTestPath(case)) + self.assertTrue(self.rd_sum.abs_path == self.createTestPath(path)) def test_case2(self): cwd = os.getcwd() os.chdir(self.createTestPath(path)) - sum = EclSum(base) + sum = Summary(base) self.assertIsNone(sum.path) self.assertTrue(sum.base == base) self.assertTrue(sum.case == base) @@ -233,7 +233,7 @@ def test_case2(self): os.chdir(cwd) def test_var_properties(self): - sum = self.ecl_sum + sum = self.rd_sum self.assertRaises(KeyError, sum.smspec_node, "BJARNE") node = sum.smspec_node("FOPT") @@ -273,14 +273,14 @@ def test_var_properties(self): self.assertEqual(node.num, 1095) def test_stringlist_gc(self): - sum = EclSum(self.case) + sum = Summary(self.case) wells = sum.wells() well1 = wells[0] del wells self.assertTrue(well1 == "OP_1") def test_stringlist_reference(self): - sum = EclSum(self.case) + sum = Summary(self.case) wells = sum.wells() self.assertListEqual( [well for well in wells], @@ -289,7 +289,7 @@ def test_stringlist_reference(self): self.assertIsInstance(wells, StringList) def test_stringlist_setitem(self): - sum = EclSum(self.case) + sum = Summary(self.case) wells = sum.wells() wells[0] = "Bjarne" well0 = wells[0] @@ -300,7 +300,7 @@ def test_stringlist_setitem(self): self.assertTrue(wells[0] == "XXX") def test_segment(self): - sum = EclSum(self.createTestPath("Equinor/ECLIPSE/Oseberg/F8MLT/F8MLT-F4")) + sum = Summary(self.createTestPath("Equinor/ECLIPSE/Oseberg/F8MLT/F8MLT-F4")) segment_vars = sum.keys("SOFR:F-8:*") self.assertIn("SOFR:F-8:1", segment_vars) for var in segment_vars: @@ -309,14 +309,14 @@ def test_segment(self): self.assertTrue(nr >= 0) def test_return_types(self): - self.assertIsInstance(self.ecl_sum.alloc_time_vector(True), TimeVector) - key_index = self.ecl_sum.get_general_var_index("FOPT") + self.assertIsInstance(self.rd_sum.alloc_time_vector(True), TimeVector) + key_index = self.rd_sum.get_general_var_index("FOPT") self.assertIsInstance( - self.ecl_sum.alloc_data_vector(key_index, True), DoubleVector + self.rd_sum.alloc_data_vector(key_index, True), DoubleVector ) def test_timeRange(self): - sum = EclSum(self.case) + sum = Summary(self.case) with self.assertRaises(TypeError): trange = sum.timeRange(interval="1") trange = sum.timeRange(interval="1X") @@ -364,7 +364,7 @@ def test_timeRange(self): # Loading this dataset is a test of loading a case where one report step is missing. def test_Heidrun(self): - sum = EclSum( + sum = Summary( self.createTestPath("Equinor/ECLIPSE/Heidrun/Summary/FF12_2013B3_CLEAN_RS") ) self.assertEqual(452, len(sum)) @@ -376,7 +376,7 @@ def test_Heidrun(self): sum.get_interp("FOPT", date=t) def test_regularProduction(self): - sum = EclSum(self.case) + sum = Summary(self.case) with self.assertRaises(TypeError): trange = TimeVector.createRegular(sum.start_time, sum.end_time, "1M") prod = sum.blockedProduction("FOPR", trange) @@ -408,8 +408,8 @@ def test_regularProduction(self): self.assertFloatEqual(w, g) def test_writer(self): - writer = EclSum.writer("CASE", datetime.date(2000, 1, 1), 10, 10, 5) - self.assertIsInstance(self.ecl_sum, EclSum) + writer = Summary.writer("CASE", datetime.date(2000, 1, 1), 10, 10, 5) + self.assertIsInstance(self.rd_sum, Summary) writer.addVariable("FOPT") self.assertTrue(writer.has_key("FOPT")) @@ -417,16 +417,18 @@ def test_writer(self): writer.addTStep(1, 100) def test_aquifer(self): - case = EclSum(self.createTestPath("Equinor/ECLIPSE/Aquifer/06_PRESSURE_R009-0")) + case = Summary( + self.createTestPath("Equinor/ECLIPSE/Aquifer/06_PRESSURE_R009-0") + ) self.assertTrue("AAQR:2" in case) def test_restart_mapping(self): - history = EclSum( + history = Summary( self.createTestPath( "Equinor/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0" ) ) - total = EclSum( + total = Summary( self.createTestPath( "Equinor/ECLIPSE/SummaryRestart/Prediction/NOR-2013A_R007_PRED-0" ), @@ -451,7 +453,7 @@ def test_restart_mapping(self): def test_write(self): with TestAreaContext("my_space") as area: - intersect_summary = EclSum( + intersect_summary = Summary( self.createTestPath( "Equinor/ECLIPSE/SummaryRestart/iter-1/NOR-2013A_R007-0" ), @@ -460,13 +462,13 @@ def test_write(self): self.assertIsNotNone(intersect_summary) write_location = os.path.join(os.getcwd(), "CASE") - intersect_summary.fwrite(ecl_case=write_location) + intersect_summary.fwrite(rd_case=write_location) - reloaded_summary = EclSum(write_location) + reloaded_summary = Summary(write_location) self.assertEqual(intersect_summary.keys(), reloaded_summary.keys()) def test_ix_case(self): - intersect_summary = EclSum( + intersect_summary = Summary( self.createTestPath("Equinor/ECLIPSE/ix/summary/CREATE_REGION_AROUND_WELL") ) self.assertIsNotNone(intersect_summary) @@ -479,9 +481,9 @@ def test_ix_case(self): ] ) - eclipse_summary = EclSum( + eclipse_summary = Summary( self.createTestPath( - "Equinor/ECLIPSE/ix/summary/ECL100/E100_CREATE_REGION_AROUND_WELL" + "Equinor/ECLIPSE/ix/summary/RD100/E100_CREATE_REGION_AROUND_WELL" ) ) self.assertIsNotNone(eclipse_summary) @@ -500,21 +502,21 @@ def test_ix_write(self): "Equinor/ECLIPSE/ix/troll/IX_NOPH3_R04_75X75X1_GRID2.SMSPEC", ]: with TestAreaContext("my_space" + data_set.split("/")[-1]) as area: - intersect_summary = EclSum( + intersect_summary = Summary( self.createTestPath(data_set), lazy_load=False ) self.assertIsNotNone(intersect_summary) write_location = os.path.join(os.getcwd(), "CASE") - intersect_summary.fwrite(ecl_case=write_location) + intersect_summary.fwrite(rd_case=write_location) - reloaded_summary = EclSum(write_location) + reloaded_summary = Summary(write_location) self.assertEqual( list(intersect_summary.keys()), list(reloaded_summary.keys()) ) def test_ix_caseII(self): - troll_summary = EclSum( + troll_summary = Summary( self.createTestPath( "Equinor/ECLIPSE/ix/troll/IX_NOPH3_R04_75X75X1_GRID2.SMSPEC" ) @@ -524,8 +526,8 @@ def test_ix_caseII(self): def test_resample(self): time_points = TimeVector() - start_time = self.ecl_sum.get_data_start_time() - end_time = self.ecl_sum.get_end_time() + start_time = self.rd_sum.get_data_start_time() + end_time = self.rd_sum.get_end_time() delta = end_time - start_time N = 25 time_points.initRange( @@ -534,15 +536,15 @@ def test_resample(self): CTime(int(delta.total_seconds() / (N - 1))), ) time_points.append(CTime(end_time)) - resampled = self.ecl_sum.resample("OUTPUT_CASE", time_points) + resampled = self.rd_sum.resample("OUTPUT_CASE", time_points) - for key in self.ecl_sum.keys(): + for key in self.rd_sum.keys(): self.assertIn(key, resampled) self.assertEqual( - self.ecl_sum.get_data_start_time(), resampled.get_data_start_time() + self.rd_sum.get_data_start_time(), resampled.get_data_start_time() ) - delta = self.ecl_sum.get_end_time() - resampled.get_end_time() + delta = self.rd_sum.get_end_time() - resampled.get_end_time() self.assertTrue(delta.total_seconds() <= 1) keys = ["FOPT", "FOPR", "BPR:15,28,1", "WGOR:OP_1"] @@ -550,17 +552,17 @@ def test_resample(self): for time_index, t in enumerate(time_points): self.assertFloatEqual( resampled.iget(key, time_index), - self.ecl_sum.get_interp_direct(key, t), + self.rd_sum.get_interp_direct(key, t), ) def test_summary_units(self): - self.assertEqual(self.ecl_sum.unit_system, EclUnitTypeEnum.ECL_METRIC_UNITS) + self.assertEqual(self.rd_sum.unit_system, UnitSystem.METRIC) # The case loaded in this test originates in a simulation # which was shut down brutally. This test verifies that we - # can create a valid ecl_sum instance from what we find. + # can create a valid rd_sum instance from what we find. def test_broken_case(self): - ecl_sum = EclSum( + rd_sum = Summary( self.createTestPath( "Equinor/ECLIPSE/SummaryFail3/COMBINED-AUTUMN2018_CARBSENS-0" ) diff --git a/python/tests/test_bin.py b/python/tests/test_bin.py index e0741a1767..40fcf5f297 100644 --- a/python/tests/test_bin.py +++ b/python/tests/test_bin.py @@ -12,8 +12,8 @@ [ ("CF_dump", -signal.SIGSEGV, b""), ("convert.x", 1, b"Usage: convert.x"), - ("ecl_pack.x", 0, b""), - ("ecl_unpack.x", 1, b"ecl_unpack UNIFIED_FILE1"), + ("rd_pack.x", 0, b""), + ("rd_unpack.x", 1, b"rd_unpack UNIFIED_FILE1"), ("grdecl_grid", -signal.SIGABRT, b"util_fopen: failed to open:(null)"), ("grdecl_test.x", -signal.SIGABRT, b"util_fopen: failed to open:(null)"), ("grid_dump.x", 1, b"grid_dump.x: filename"), diff --git a/python/tests/util_tests/test_ctime.py b/python/tests/util_tests/test_ctime.py index efe38ac8e3..141bb0bb13 100644 --- a/python/tests/util_tests/test_ctime.py +++ b/python/tests/util_tests/test_ctime.py @@ -1,7 +1,7 @@ import time from datetime import datetime, date -from ecl.util.util import CTime +from resdata.util.util import CTime try: diff --git a/python/tests/util_tests/test_hash.py b/python/tests/util_tests/test_hash.py index a8111a164f..285432efec 100644 --- a/python/tests/util_tests/test_hash.py +++ b/python/tests/util_tests/test_hash.py @@ -1,10 +1,10 @@ from ctypes import c_void_p -from tests import EclTest -from ecl.util.util import Hash, StringHash, DoubleHash, IntegerHash +from tests import ResdataTest +from resdata.util.util import Hash, StringHash, DoubleHash, IntegerHash -class HashTest(EclTest): +class HashTest(ResdataTest): def test_string_hash(self): hash = StringHash() diff --git a/python/tests/util_tests/test_lookup_table.py b/python/tests/util_tests/test_lookup_table.py index 48d7c827f7..e9370dcb22 100644 --- a/python/tests/util_tests/test_lookup_table.py +++ b/python/tests/util_tests/test_lookup_table.py @@ -3,7 +3,7 @@ except ImportError: from unittest import TestCase -from ecl.util.util import LookupTable +from resdata.util.util import LookupTable class LookupTableTest(TestCase): diff --git a/python/tests/util_tests/test_path_context.py b/python/tests/util_tests/test_path_context.py index 4ebba75ab4..acd181ddce 100644 --- a/python/tests/util_tests/test_path_context.py +++ b/python/tests/util_tests/test_path_context.py @@ -1,9 +1,9 @@ import os -from ecl.util.test import PathContext, TestAreaContext -from tests import EclTest +from resdata.util.test import PathContext, TestAreaContext +from tests import ResdataTest -class PathContextTest(EclTest): +class PathContextTest(ResdataTest): def test_error(self): with TestAreaContext("pathcontext"): # Test failure on creating PathContext with an existing path diff --git a/python/tests/util_tests/test_rng.py b/python/tests/util_tests/test_rng.py index 40d634e733..8674302a75 100644 --- a/python/tests/util_tests/test_rng.py +++ b/python/tests/util_tests/test_rng.py @@ -1,10 +1,10 @@ -from ecl.util.enums import RngAlgTypeEnum, RngInitModeEnum -from ecl.util.util import RandomNumberGenerator -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.enums import RngAlgTypeEnum, RngInitModeEnum +from resdata.util.util import RandomNumberGenerator +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class RngTest(EclTest): +class RngTest(ResdataTest): def test_enums(self): self.assertEnumIsFullyDefined( RngAlgTypeEnum, "rng_alg_type", "lib/include/ert/util/rng.hpp" diff --git a/python/tests/util_tests/test_spawn.py b/python/tests/util_tests/test_spawn.py index 8830dfc8b5..a1d7b4a309 100644 --- a/python/tests/util_tests/test_spawn.py +++ b/python/tests/util_tests/test_spawn.py @@ -2,16 +2,16 @@ import stat import sys -import ecl -from ecl import EclPrototype -from tests import EclTest -from ecl.util.test.test_area import TestAreaContext +import resdata +from resdata import ResdataPrototype +from tests import ResdataTest +from resdata.util.test.test_area import TestAreaContext from cwrap import Prototype class _TestSpawnPrototype(Prototype): - lib = EclPrototype.lib + lib = ResdataPrototype.lib def __init__(self, prototype, bind=True): super(_TestSpawnPrototype, self).__init__( @@ -19,7 +19,7 @@ def __init__(self, prototype, bind=True): ) -class SpawnTest(EclTest): +class SpawnTest(ResdataTest): _spawn = _TestSpawnPrototype( "int util_spawn_blocking(char*, int, void*, char*, char*)", bind=False ) diff --git a/python/tests/util_tests/test_string_list.py b/python/tests/util_tests/test_string_list.py index 5c4c13c1de..b4c6119834 100644 --- a/python/tests/util_tests/test_string_list.py +++ b/python/tests/util_tests/test_string_list.py @@ -1,6 +1,6 @@ from unittest import TestCase -from ecl.util.util import StringList +from resdata.util.util import StringList class StringListTest(TestCase): diff --git a/python/tests/util_tests/test_thread_pool.py b/python/tests/util_tests/test_thread_pool.py index 327b52a369..8e3b2aa1a2 100644 --- a/python/tests/util_tests/test_thread_pool.py +++ b/python/tests/util_tests/test_thread_pool.py @@ -1,10 +1,10 @@ import time -from ecl.util.util import ThreadPool -from ecl.util.util.thread_pool import Task -from tests import EclTest +from resdata.util.util import ThreadPool +from resdata.util.util.thread_pool import Task +from tests import ResdataTest -class ThreadPoolTest(EclTest): +class ThreadPoolTest(ResdataTest): def sleepTask(self, *args, **kwargs): time.sleep(args[0]) diff --git a/python/tests/util_tests/test_vectors.py b/python/tests/util_tests/test_vectors.py index 42141e3101..602e898075 100755 --- a/python/tests/util_tests/test_vectors.py +++ b/python/tests/util_tests/test_vectors.py @@ -8,7 +8,7 @@ except ImportError: from unittest import TestCase -from ecl.util.util import ( +from resdata.util.util import ( DoubleVector, IntVector, BoolVector, diff --git a/python/tests/util_tests/test_version.py b/python/tests/util_tests/test_version.py index 2125f77b1c..33e2142fae 100644 --- a/python/tests/util_tests/test_version.py +++ b/python/tests/util_tests/test_version.py @@ -1,11 +1,9 @@ -import os.path +import resdata +from resdata.util.util import ResdataVersion, Version +from tests import ResdataTest -import ecl -from tests import EclTest -from ecl.util.util import Version, EclVersion - -class VersionTest(EclTest): +class VersionTest(ResdataTest): def setUp(self): pass @@ -77,11 +75,11 @@ def test_ge(self): self.assertNotEqual(repr(v1), repr(v2)) def test_current(self): - current = EclVersion() + current = ResdataVersion() self.assertTrue(current > (0, 0, 0)) pfx = "Version(major=" self.assertEqual(pfx, repr(current)[: len(pfx)]) def test_root_version(self): - cv = EclVersion() - self.assertEqual(ecl.__version__, cv.versionString()) + cv = ResdataVersion() + self.assertEqual(resdata.__version__, cv.versionString()) diff --git a/python/tests/util_tests/test_work_area.py b/python/tests/util_tests/test_work_area.py index 8a429a3c3f..8b9f2124a5 100644 --- a/python/tests/util_tests/test_work_area.py +++ b/python/tests/util_tests/test_work_area.py @@ -7,11 +7,11 @@ except ImportError: from unittest import skipIf -from ecl.util.test import TestAreaContext -from tests import EclTest +from resdata.util.test import TestAreaContext +from tests import ResdataTest -class WorkAreaTest(EclTest): +class WorkAreaTest(ResdataTest): def test_full_path(self): with TestAreaContext("TestArea") as test_area: with open("test_file", "w") as fileH: diff --git a/python/tests/well_tests/test_ecl_well.py b/python/tests/well_tests/test_rd_well.py similarity index 91% rename from python/tests/well_tests/test_ecl_well.py rename to python/tests/well_tests/test_rd_well.py index 8a75812e86..319a8468e9 100644 --- a/python/tests/well_tests/test_ecl_well.py +++ b/python/tests/well_tests/test_rd_well.py @@ -1,20 +1,20 @@ import datetime -from ecl import EclFileFlagEnum -from ecl.eclfile import EclFile -from ecl.grid import EclGrid -from tests import EclTest, equinor_test -from ecl.util.util.ctime import CTime -from ecl.well import ( +from resdata import FileMode +from resdata.resfile import ResdataFile +from resdata.grid import Grid +from tests import ResdataTest, equinor_test +from resdata.util.util.ctime import CTime +from resdata.well import ( WellInfo, WellConnection, - WellTypeEnum, - WellConnectionDirectionEnum, + WellConnectionDirection, WellSegment, + WellType, ) @equinor_test() -class EclWellTest(EclTest): +class ResdataWellTest(ResdataTest): ALL_WELLS = [ "E5H", "G1H", @@ -242,12 +242,12 @@ class EclWellTest(EclTest): @classmethod def setUpClass(cls): - EclWellTest.__well_info = None - EclWellTest.__well_info_with_no_well_segments = None + ResdataWellTest.__well_info = None + ResdataWellTest.__well_info_with_no_well_segments = None def getWellInfoWithNoWellSegments(self): """@rtype: WellInfo""" - if EclWellTest.__well_info_with_no_well_segments is None: + if ResdataWellTest.__well_info_with_no_well_segments is None: grid_path = self.createTestPath( "Equinor/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.EGRID" ) @@ -255,19 +255,19 @@ def getWellInfoWithNoWellSegments(self): "Equinor/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.X0135" ) - grid = EclGrid(grid_path) + grid = Grid(grid_path) - rst_file = EclFile(rst_path_1, EclFileFlagEnum.ECL_FILE_CLOSE_STREAM) + rst_file = ResdataFile(rst_path_1, FileMode.CLOSE_STREAM) - EclWellTest.__well_info_with_no_well_segments = WellInfo( + ResdataWellTest.__well_info_with_no_well_segments = WellInfo( grid, rst_file, False ) - return EclWellTest.__well_info_with_no_well_segments + return ResdataWellTest.__well_info_with_no_well_segments def getWellInfo(self): """@rtype: WellInfo""" - if EclWellTest.__well_info is None: + if ResdataWellTest.__well_info is None: grid_path = self.createTestPath( "Equinor/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.EGRID" ) @@ -275,19 +275,19 @@ def getWellInfo(self): "Equinor/ECLIPSE/Troll/MSW/T07-4A-W2012-16-F3.X0135" ) - grid = EclGrid(grid_path) + grid = Grid(grid_path) - rst_file = EclFile(rst_path_1, EclFileFlagEnum.ECL_FILE_CLOSE_STREAM) + rst_file = ResdataFile(rst_path_1, FileMode.CLOSE_STREAM) - EclWellTest.__well_info = WellInfo(grid, rst_file) + ResdataWellTest.__well_info = WellInfo(grid, rst_file) - return EclWellTest.__well_info + return ResdataWellTest.__well_info def test_no_such_well(self): grid_path = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.EGRID") rst_path1 = self.createTestPath("nosuch/path/ECLIPSE.X001") rst_path2 = self.createTestPath("nosuch/path/ECLIPSE.X002") - grid = EclGrid(grid_path) + grid = Grid(grid_path) with self.assertRaises(IOError): _ = WellInfo(grid, rst_path1) with self.assertRaises(IOError): @@ -300,7 +300,7 @@ def test_construction(self): rst_path_3 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.X0035") rst_path_4 = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.X0061") - grid = EclGrid(grid_path) + grid = Grid(grid_path) def checkWellInfo(well_info, well_count, report_step_count): self.assertEqual(len(well_info), well_count) @@ -311,7 +311,7 @@ def checkWellInfo(well_info, well_count, report_step_count): well_info = WellInfo(grid, rst_path_1) checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) - well_info = WellInfo(grid, EclFile(rst_path_1)) + well_info = WellInfo(grid, ResdataFile(rst_path_1)) checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) well_info = WellInfo(grid, [rst_path_1, rst_path_2, rst_path_3]) @@ -321,7 +321,12 @@ def checkWellInfo(well_info, well_count, report_step_count): well_info = WellInfo( grid, - [EclFile(rst_path_1), EclFile(rst_path_2), rst_path_3, EclFile(rst_path_4)], + [ + ResdataFile(rst_path_1), + ResdataFile(rst_path_2), + rst_path_3, + ResdataFile(rst_path_4), + ], ) checkWellInfo( well_info, well_count=8, report_step_count=[4, 4, 4, 4, 4, 3, 3, 3] @@ -332,12 +337,12 @@ def checkWellInfo(well_info, well_count, report_step_count): checkWellInfo(well_info, well_count=5, report_step_count=[1, 1, 1, 1, 1]) - well_info.addWellFile(EclFile(rst_path_2), True) + well_info.addWellFile(ResdataFile(rst_path_2), True) checkWellInfo( well_info, well_count=8, report_step_count=[2, 2, 2, 2, 2, 1, 1, 1] ) - well_info.addWellFile(EclFile(rst_path_3), True) + well_info.addWellFile(ResdataFile(rst_path_3), True) checkWellInfo( well_info, well_count=8, report_step_count=[3, 3, 3, 3, 3, 2, 2, 2] ) @@ -348,14 +353,14 @@ def checkWellInfo(well_info, well_count, report_step_count): ) def test_well_type_enum(self): - source_file_path = "lib/include/ert/ecl_well/well_conn.hpp" + source_file_path = "lib/include/resdata/well/well_conn.hpp" # The header file has duplicated symbols, so the simple test fails. - # self.assertEnumIsFullyDefined(WellTypeEnum, "well_type_enum", source_file_path) + # self.assertEnumIsFullyDefined(WellType, "well_type_enum", source_file_path) def test_well_connection_direction_enum(self): - source_file_path = "lib/include/ert/ecl_well/well_conn.hpp" + source_file_path = "lib/include/resdata/well/well_conn.hpp" self.assertEnumIsFullyDefined( - WellConnectionDirectionEnum, "well_conn_dir_enum", source_file_path + WellConnectionDirection, "well_conn_dir_enum", source_file_path ) def test_well_info(self): @@ -365,7 +370,7 @@ def test_well_info(self): all_well_names = well_info.allWellNames() self.assertEqual(len(well_info), len(all_well_names)) - self.assertEqual(EclWellTest.ALL_WELLS, all_well_names) + self.assertEqual(ResdataWellTest.ALL_WELLS, all_well_names) for well_name in all_well_names: self.assertTrue(well_name in well_info) @@ -392,14 +397,14 @@ def test_well_time_line(self): self.assertEqual(len(well_time_line), 1) well_states = set() - for well_name in EclWellTest.ALL_WELLS: + for well_name in ResdataWellTest.ALL_WELLS: well_time_line = well_info[well_name] well_states.add(well_time_line[0]) with self.assertRaises(IndexError): err = well_time_line[1] - self.assertEqual(len(well_states), len(EclWellTest.ALL_WELLS)) + self.assertEqual(len(well_states), len(ResdataWellTest.ALL_WELLS)) # testing name and repr info = self.getWellInfo() @@ -413,7 +418,7 @@ def test_well_time_line(self): # testing __getitem__ and its well state ws = wtl[0] self.assertTrue(ws.isOpen()) - self.assertEqual(ws.wellType(), WellTypeEnum.ECL_WELL_PRODUCER) + self.assertEqual(ws.wellType(), WellType.PRODUCER) self.assertTrue(ws.isMultiSegmentWell()) pfx = "WellState(" self.assertEqual(pfx, repr(ws)[: len(pfx)]) @@ -425,11 +430,11 @@ def test_well_state(self): open_states = {True: 0, False: 0} msw_states = {True: 0, False: 0} well_types = { - WellTypeEnum.ECL_WELL_ZERO: 0, - WellTypeEnum.ECL_WELL_PRODUCER: 0, - WellTypeEnum.ECL_WELL_GAS_INJECTOR: 0, - WellTypeEnum.ECL_WELL_OIL_INJECTOR: 0, - WellTypeEnum.ECL_WELL_WATER_INJECTOR: 0, + WellType.ZERO: 0, + WellType.PRODUCER: 0, + WellType.GAS_INJECTOR: 0, + WellType.OIL_INJECTOR: 0, + WellType.WATER_INJECTOR: 0, } segments = set() @@ -437,7 +442,7 @@ def test_well_state(self): connections = set() connections_count = 0 - for index, well_name in enumerate(EclWellTest.ALL_WELLS): + for index, well_name in enumerate(ResdataWellTest.ALL_WELLS): well_time_line = well_info[well_name] well_state = well_time_line[0] @@ -467,11 +472,11 @@ def test_well_state(self): self.assertEqual(msw_states[True], 169) self.assertEqual(msw_states[False], 53) - self.assertEqual(well_types[WellTypeEnum.ECL_WELL_ZERO], 0) - self.assertEqual(well_types[WellTypeEnum.ECL_WELL_WATER_INJECTOR], 0) - self.assertEqual(well_types[WellTypeEnum.ECL_WELL_OIL_INJECTOR], 0) - self.assertEqual(well_types[WellTypeEnum.ECL_WELL_GAS_INJECTOR], 1) - self.assertEqual(well_types[WellTypeEnum.ECL_WELL_PRODUCER], 221) + self.assertEqual(well_types[WellType.ZERO], 0) + self.assertEqual(well_types[WellType.WATER_INJECTOR], 0) + self.assertEqual(well_types[WellType.OIL_INJECTOR], 0) + self.assertEqual(well_types[WellType.GAS_INJECTOR], 1) + self.assertEqual(well_types[WellType.PRODUCER], 221) self.assertEqual(len(connections), connections_count) @@ -1188,7 +1193,7 @@ def test_well_connections(self): connection.connectionFactor(), well_connection_factors[index] ) self.assertEqual( - connection.direction(), WellConnectionDirectionEnum.well_conn_dirX + connection.direction(), WellConnectionDirection.well_conn_dirX ) self.assertNotEqual(global_connections[0], global_connections[1]) @@ -1272,7 +1277,7 @@ def test_well_connections_msw(self): self.assertFalse(connection.isFractureConnection()) self.assertTrue(connection.isMatrixConnection()) self.assertEqual( - connection.direction(), WellConnectionDirectionEnum.well_conn_dirY + connection.direction(), WellConnectionDirection.well_conn_dirY ) def test_well_connections_msw_do_not_load_segments(self): @@ -1354,7 +1359,7 @@ def test_well_connections_msw_do_not_load_segments(self): self.assertFalse(connection.isFractureConnection()) self.assertTrue(connection.isMatrixConnection()) self.assertEqual( - connection.direction(), WellConnectionDirectionEnum.well_conn_dirY + connection.direction(), WellConnectionDirection.well_conn_dirY ) def test_load_broken_direction(self): @@ -1364,5 +1369,5 @@ def test_load_broken_direction(self): rst_path = self.createTestPath( "Equinor/ECLIPSE/icon-invalid-value/R6_HM2016B_FFP_BASE.UNRST" ) - grid = EclGrid(grid_path) + grid = Grid(grid_path) well_info = WellInfo(grid, rst_path) diff --git a/python/tests/well_tests/test_ecl_well2.py b/python/tests/well_tests/test_rd_well2.py similarity index 76% rename from python/tests/well_tests/test_ecl_well2.py rename to python/tests/well_tests/test_rd_well2.py index d27f409391..842cc4ecc8 100644 --- a/python/tests/well_tests/test_ecl_well2.py +++ b/python/tests/well_tests/test_rd_well2.py @@ -1,33 +1,33 @@ import datetime import os.path -from ecl import EclFileFlagEnum -from ecl.eclfile import EclFile -from ecl.grid import EclGrid -from tests import EclTest, equinor_test -from ecl.util.util.ctime import CTime -from ecl.well import ( +from resdata import FileMode +from resdata.resfile import ResdataFile +from resdata.grid import Grid +from tests import ResdataTest, equinor_test +from resdata.util.util.ctime import CTime +from resdata.well import ( WellInfo, WellConnection, - WellTypeEnum, - WellConnectionDirectionEnum, + WellType, + WellConnectionDirection, WellSegment, ) @equinor_test() -class EclWellTest2(EclTest): +class ResdataWellTest2(ResdataTest): grid = None def getGrid(self): - if EclWellTest2.grid is None: - EclWellTest2.grid = EclGrid( + if ResdataWellTest2.grid is None: + ResdataWellTest2.grid = Grid( self.createTestPath( "Equinor/ECLIPSE/Troll/Ref2014/T07-4A-W2014-06.EGRID" ) ) - return EclWellTest2.grid + return ResdataWellTest2.grid def checkWell(self, rst_file): segment_length = [ diff --git a/python/tests/well_tests/test_ecl_well3.py b/python/tests/well_tests/test_rd_well3.py similarity index 87% rename from python/tests/well_tests/test_ecl_well3.py rename to python/tests/well_tests/test_rd_well3.py index 16056fb6f2..3e46df2b65 100644 --- a/python/tests/well_tests/test_ecl_well3.py +++ b/python/tests/well_tests/test_rd_well3.py @@ -1,22 +1,22 @@ import datetime import os.path -from ecl.eclfile import EclFile -from ecl.grid import EclGrid -from ecl.summary import EclSum -from tests import EclTest, equinor_test -from ecl.util.util.ctime import CTime -from ecl.well import ( +from resdata.resfile import ResdataFile +from resdata.grid import Grid +from resdata.summary import Summary +from tests import ResdataTest, equinor_test +from resdata.util.util.ctime import CTime +from resdata.well import ( WellInfo, WellConnection, - WellTypeEnum, - WellConnectionDirectionEnum, + WellType, + WellConnectionDirection, WellSegment, ) @equinor_test() -class EclWellTest3(EclTest): +class ResdataWellTest3(ResdataTest): grid = None def test_rates(self): @@ -24,9 +24,9 @@ def test_rates(self): rst_path = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.UNRST") sum_path = self.createTestPath("Equinor/ECLIPSE/Gurbat/ECLIPSE.SMSPEC") - grid = EclGrid(grid_path) + grid = Grid(grid_path) well_info = WellInfo(grid, rst_path) - sum = EclSum(sum_path) + sum = Summary(sum_path) for wtl in well_info: for well_state in wtl: diff --git a/python/tests/well_tests/test_well_missing_ICON.py b/python/tests/well_tests/test_well_missing_ICON.py index 3f269f2882..15976e8530 100644 --- a/python/tests/well_tests/test_well_missing_ICON.py +++ b/python/tests/well_tests/test_well_missing_ICON.py @@ -1,18 +1,18 @@ import datetime -from tests import EclTest -from ecl.grid import EclGridGenerator -from ecl.well import ( +from tests import ResdataTest +from resdata.grid import GridGenerator +from resdata.well import ( WellInfo, WellConnection, - WellTypeEnum, - WellConnectionDirectionEnum, + WellType, + WellConnectionDirection, WellSegment, ) -class EclWellICONTest(EclTest): +class ResdataWellICONTest(ResdataTest): def setUp(self): - self.grid = EclGridGenerator.create_rectangular((46, 112, 22), (1, 1, 1)) + self.grid = GridGenerator.create_rectangular((46, 112, 22), (1, 1, 1)) self.rst_file_ICON0 = self.createTestPath( "local/ECLIPSE/well/missing-ICON/ICON0.X0027" ) diff --git a/release-notes.txt b/release-notes.txt index e76392fe11..9fe7f6e94b 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -26,7 +26,7 @@ Build & testing: - Started to support Python3 syntax [150, 161] - Add support for paralell builds on Travis [149] -libecl now fully supports OSX. On Travis it is compiled with +resdata now fully supports OSX. On Travis it is compiled with -Werror=all which should protect against future warnings. C++: diff --git a/setup.py b/setup.py index ce048a0df0..6279b0eda7 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,11 @@ import os import sys -import skbuild + import setuptools +import skbuild from setuptools_scm import get_version - -version = get_version(relative_to=__file__, write_to="python/ecl/version.py") +version = get_version(relative_to=__file__, write_to="python/resdata/version.py") # Corporate networks tend to be behind a proxy server with their own non-public @@ -25,19 +25,19 @@ def utility_wrappers(): """ - Wrappers around ecl's "application" utilities. These are only supported on + Wrappers around resdata's "application" utilities. These are only supported on Linux at this time so only create the wrapper when on Linux. """ if sys.platform != "linux": return [] return [ - name + " = ecl.bin:main" + name + " = resdata.bin:main" for name in ( "CF_dump", "convert.x", - "ecl_pack.x", - "ecl_unpack.x", + "rd_pack.x", + "rd_unpack.x", "grdecl_grid", "grdecl_test.x", "grid_dump.x", @@ -56,13 +56,13 @@ def utility_wrappers(): skbuild.setup( - name="ecl", + name="resdata", author="Equinor ASA", author_email="fg_sib-scout@equinor.com", - description="Package for reading and writing the result files from the ECLIPSE reservoir simulator", + description="Package for reading and writing the fortran result files from reservoir simulators", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/equinor/ecl", + url="https://github.com/equinor/resdata", packages=setuptools.find_packages( where="python", exclude=["*.tests", "*.tests.*", "tests.*", "tests", "ert.*", "ert"], @@ -77,12 +77,12 @@ def utility_wrappers(): ], entry_points={"console_scripts": utility_wrappers()}, cmake_args=[ - "-DECL_VERSION=" + version, + "-DRD_VERSION=" + version, "-DBUILD_APPLICATIONS=" + ("ON" if sys.platform == "linux" else "OFF"), "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", - "-DCMAKE_INSTALL_BINDIR=python/ecl/.bin", - "-DCMAKE_INSTALL_LIBDIR=python/ecl/.libs", - "-DCMAKE_INSTALL_INCLUDEDIR=python/ecl/.include", + "-DCMAKE_INSTALL_BINDIR=python/resdata/.bin", + "-DCMAKE_INSTALL_LIBDIR=python/resdata/.libs", + "-DCMAKE_INSTALL_INCLUDEDIR=python/resdata/.include", # we can safely pass OSX_DEPLOYMENT_TARGET as it's ignored on # everything not OS X. We depend on C++11, which makes our minimum # supported OS X release 10.9